4
* Copyright (C) 2005 The GNOME Foundation
5
* Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
6
* Copyright (C) 2009 Pierre Wieser and others (see AUTHORS)
8
* This Program is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU General Public License as
10
* published by the Free Software Foundation; either version 2 of
11
* the License, or (at your option) any later version.
13
* This Program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public
19
* License along with this Library; see the file COPYING. If not,
20
* write to the Free Software Foundation, Inc., 59 Temple Place,
21
* Suite 330, Boston, MA 02111-1307, USA.
24
* Frederic Ruaudel <grumz@grumz.net>
25
* Rodrigo Moya <rodrigo@gnome-db.org>
26
* Pierre Wieser <pwieser@trychlos.org>
27
* ... and many others (see AUTHORS)
33
#include <glib/gi18n.h>
34
#include <glib/gstdio.h>
36
#include <libnautilus-actions/nautilus-actions-config.h>
37
#include <libnautilus-actions/nautilus-actions-config-schema-writer.h>
38
#include "nautilus-actions-tools-utils.h"
40
static gchar* label = "";
41
static gchar* tooltip = "";
42
static gchar* icon = "";
43
static gchar* command = "";
44
static gchar* params = "";
45
static gchar** matches = NULL;
46
static gboolean match_case = FALSE;
47
static gchar** mimetypes = NULL;
48
static gboolean isfile = FALSE;
49
static gboolean isdir = FALSE;
50
static gboolean accept_multiple_files = FALSE;
51
static gchar** schemes = NULL;
52
static gchar* output_file = NULL;
54
static GOptionEntry entries[] =
56
{ "label", 'l', 0, G_OPTION_ARG_STRING, &label, N_("The label of the menu item"), N_("LABEL") },
57
{ "tooltip", 't', 0, G_OPTION_ARG_STRING, &tooltip, N_("The tooltip of the menu item"), N_("TOOLTIP") },
58
{ "icon", 'i', 0, G_OPTION_ARG_STRING, &icon, N_("The icon of the menu item (filename or GTK stock ID)"), N_("ICON") },
59
{ "command", 'c', 0, G_OPTION_ARG_FILENAME, &command, N_("The path of the command"), N_("PATH") },
60
{ "parameters", 'p', 0, G_OPTION_ARG_STRING, ¶ms, N_("The parameters of the command"), N_("PARAMS") },
61
{ "match", 'm', 0, G_OPTION_ARG_STRING_ARRAY, &matches, N_("A pattern to match selected files against. May include wildcards (* or ?) (you must set one option for each pattern you need)"), N_("EXPR") },
62
{ "match-case", 'C', 0, G_OPTION_ARG_NONE, &match_case, N_("The path of the command"), N_("PATH") },
63
{ "mimetypes", 'T', 0, G_OPTION_ARG_STRING_ARRAY, &mimetypes, N_("A pattern to match selected files' mimetype against. May include wildcards (* or ?) (you must set one option for each pattern you need)"), N_("EXPR") },
64
{ "accept-files", 'f', 0, G_OPTION_ARG_NONE, &isfile, N_("Set it if the selection can contain files"), NULL },
65
{ "accept-dirs", 'd', 0, G_OPTION_ARG_NONE, &isdir, N_("Set it if the selection can contain folders"), NULL },
66
{ "accept-multiple-files", 'M', 0, G_OPTION_ARG_NONE, &accept_multiple_files, N_("Set it if the selection can have several items"), NULL },
67
{ "scheme", 's', 0, G_OPTION_ARG_STRING_ARRAY, &schemes, N_("A GnomeVFS scheme where the selected files should be located (you must set it for each scheme you need)"), N_("SCHEME") },
68
{ "output-file", 'o', 0, G_OPTION_ARG_FILENAME, &output_file, N_("The path of the file where to save the new GConf schema definition file [default: /tmp/config_UUID.schemas]"), N_("PATH") },
72
int main (int argc, char** argv)
75
GError * error = NULL;
76
GOptionContext* context;
78
gboolean success = FALSE;
79
gchar* contents = NULL;
81
NautilusActionsConfigAction* action;
82
NautilusActionsConfigActionProfile* action_profile;
83
GSList* basenames = NULL;
84
GSList* mimetypes_list = NULL;
85
GSList* schemes_list = NULL;
90
context = g_option_context_new ("");
93
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
94
# ifdef HAVE_BIND_TEXTDOMAIN_CODESET
95
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
97
textdomain (GETTEXT_PACKAGE);
98
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
100
g_option_context_add_main_entries (context, entries, NULL);
103
g_option_context_parse (context, &argc, &argv, &error);
107
fprintf (stderr, _("Syntax error:\n\t- %s\nTry %s --help\n"), error->message, g_get_prgname ());
108
g_error_free (error);
112
action = nautilus_actions_config_action_new_default ();
113
action_profile = nautilus_actions_config_action_get_profile (action, NULL);
114
nautilus_actions_config_action_set_label (action, label);
115
nautilus_actions_config_action_set_tooltip (action, tooltip);
116
nautilus_actions_config_action_set_icon (action, icon);
117
nautilus_actions_config_action_profile_set_path (action_profile, command);
118
nautilus_actions_config_action_profile_set_parameters (action_profile, params);
121
while (matches != NULL && matches[i] != NULL)
123
basenames = g_slist_append (basenames, g_strdup (matches[i]));
126
nautilus_actions_config_action_profile_set_basenames (action_profile, basenames);
127
g_slist_foreach (basenames, (GFunc) g_free, NULL);
128
g_slist_free (basenames);
130
nautilus_actions_config_action_profile_set_match_case (action_profile, match_case);
133
while (mimetypes != NULL && mimetypes[i] != NULL)
135
mimetypes_list = g_slist_append (mimetypes_list, g_strdup (mimetypes[i]));
138
nautilus_actions_config_action_profile_set_mimetypes (action_profile, mimetypes_list);
139
g_slist_foreach (mimetypes_list, (GFunc) g_free, NULL);
140
g_slist_free (mimetypes_list);
142
nautilus_actions_config_action_profile_set_is_file (action_profile, isfile);
143
nautilus_actions_config_action_profile_set_is_dir (action_profile, isdir);
144
nautilus_actions_config_action_profile_set_accept_multiple (action_profile, accept_multiple_files);
147
while (schemes != NULL && schemes[i] != NULL)
149
schemes_list = g_slist_append (schemes_list, g_strdup (schemes[i]));
152
nautilus_actions_config_action_profile_set_schemes (action_profile, schemes_list);
153
g_slist_foreach (schemes_list, (GFunc) g_free, NULL);
154
g_slist_free (schemes_list);
156
NautilusActionsConfigSchemaWriter* schema_configs = nautilus_actions_config_schema_writer_get ();
157
g_object_set (G_OBJECT (schema_configs), "save-path", "/tmp", NULL);
159
printf (_("Creating %s..."), action->label);
160
if (nautilus_actions_config_add_action (NAUTILUS_ACTIONS_CONFIG (schema_configs), action, &error))
163
path = nautilus_actions_config_schema_writer_get_saved_filename (schema_configs, action->uuid);
166
/* Copy the content of the temporary file into the one asked by the user */
167
if ((success = g_file_get_contents (path, &contents, &length, &error)))
169
success = nautilus_actions_file_set_contents (output_file, contents, length, &error);
173
/* --> Remove the temporary file */
178
printf (_(" Failed: Can't create %s: %s\n"), output_file, error->message);
179
g_error_free (error);
187
printf (_(" OK, saved in %s\n"), path);
192
printf (_(" Failed: %s\n"), error->message);
193
g_error_free (error);
196
nautilus_actions_config_action_free (action);
197
g_option_context_free (context);