1
/* Nautilus Actions configuration tool
2
4
* Copyright (C) 2005 The GNOME Foundation
5
* Frederic Ruaudel (grumz@grumz.net)
6
* Rodrigo Moya (rodrigo@gnome-db.org)
5
* Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
6
* Copyright (C) 2009 Pierre Wieser and others (see AUTHORS)
8
8
* This Program is free software; you can redistribute it and/or
9
9
* modify it under the terms of the GNU General Public License as
10
* published by the Free Software Foundation; either version 2 of the
11
* License, or (at your option) any later version.
10
* published by the Free Software Foundation; either version 2 of
11
* the License, or (at your option) any later version.
13
13
* This Program is distributed in the hope that it will be useful,
14
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* General Public License for more details.
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
18
* You should have received a copy of the GNU General Public
19
19
* License along with this Library; see the file COPYING. If not,
20
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
* Boston, MA 02111-1307, USA.
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)
24
30
#include <config.h>
31
37
#include <libnautilus-actions/nautilus-actions-config-schema-reader.h>
32
38
#include <libnautilus-actions/nautilus-actions-config-schema-writer.h>
33
39
#include <libnautilus-actions/nautilus-actions-config-gconf-writer.h>
34
#include <libnautilus-actions/nautilus-actions-config-xml.h>
35
40
#include "nact-utils.h"
36
41
#include "nact-import-export.h"
37
42
#include "nact-prefs.h"
40
void mode_toggled_cb (GtkWidget* widget, gpointer user_data)
45
/* gui callback functions */
46
void import_browse_button_clicked_cb (GtkWidget* widget, gpointer data);
47
void export_browse_button_clicked_cb (GtkWidget* widget, gpointer data);
48
void mode_toggled_cb (GtkWidget* widget, gpointer user_data);
50
static gboolean nact_import_actions (void);
51
static gboolean nact_export_actions (void);
54
mode_toggled_cb (GtkWidget* widget, gpointer user_data)
42
56
GtkWidget* import_radio = nact_get_glade_widget_from ("ImportRadioButton", GLADE_IM_EX_PORT_DIALOG_WIDGET);
56
void import_all_config_toggled_cb (GtkWidget* check_button, gpointer data)
58
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_button)))
60
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (nact_get_glade_widget_from ("XMLRadioButton",
61
GLADE_IM_EX_PORT_DIALOG_WIDGET)), TRUE);
62
gtk_widget_set_sensitive (nact_get_glade_widget_from ("FileHBox", GLADE_IM_EX_PORT_DIALOG_WIDGET), FALSE);
63
gtk_widget_set_sensitive (nact_get_glade_widget_from ("TypeConfigVBox", GLADE_IM_EX_PORT_DIALOG_WIDGET), FALSE);
67
gtk_widget_set_sensitive (nact_get_glade_widget_from ("FileHBox", GLADE_IM_EX_PORT_DIALOG_WIDGET), TRUE);
68
gtk_widget_set_sensitive (nact_get_glade_widget_from ("TypeConfigVBox", GLADE_IM_EX_PORT_DIALOG_WIDGET), TRUE);
72
void import_browse_button_clicked_cb (GtkWidget* widget, gpointer data)
71
import_browse_button_clicked_cb (GtkWidget* widget, gpointer data)
140
140
case GTK_RESPONSE_CANCEL:
141
141
case GTK_RESPONSE_DELETE_EVENT:
142
142
gtk_widget_hide (folderchooser);
148
147
list_selection_changed_cb (GtkTreeSelection *selection, gpointer user_data)
151
150
GtkWidget *nact_edit_button;
152
151
GtkWidget *nact_delete_button;
154
153
nact_edit_button = nact_get_glade_widget ("EditActionButton");
155
154
nact_delete_button = nact_get_glade_widget ("DeleteActionButton");
189
188
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list));
190
189
gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
192
191
/* set up selection */
193
192
g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (list))), "changed",
194
193
G_CALLBACK (list_selection_changed_cb), NULL);
198
gboolean nact_import_actions (void)
198
nact_import_actions (void)
200
200
gboolean retv = FALSE;
201
GtkWidget* check_button;
203
202
NautilusActionsConfigGconfWriter *config;
204
203
NautilusActionsConfigSchemaReader *schema_reader;
205
NautilusActionsConfigXml* xml_reader;
206
204
NautilusActionsConfig* generic_reader = NULL;
207
205
gchar* error_message;
208
206
GError* error = NULL;
212
210
config = nautilus_actions_config_gconf_writer_get ();
213
211
schema_reader = nautilus_actions_config_schema_reader_get ();
214
nautilus_actions_config_clear (schema_reader);
215
xml_reader = nautilus_actions_config_xml_get ();
216
nautilus_actions_config_clear (xml_reader);
218
check_button = nact_get_glade_widget_from ("ImportAllCheckButton", GLADE_IM_EX_PORT_DIALOG_WIDGET);
220
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_button)))
222
nautilus_actions_config_xml_load_list (xml_reader);
223
generic_reader = NAUTILUS_ACTIONS_CONFIG (xml_reader);
225
else if (file_path != NULL && strlen (file_path) > 0)
227
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (nact_get_glade_widget_from ("XMLRadioButton",
228
GLADE_IM_EX_PORT_DIALOG_WIDGET))))
230
if (nautilus_actions_config_xml_parse_file (xml_reader, file_path, &error))
232
generic_reader = NAUTILUS_ACTIONS_CONFIG (xml_reader);
236
error_message = g_strdup_printf (_("Can't parse file '%s' as old XML config file !"), file_path);
237
nautilus_actions_display_error (error_message, error->message);
238
g_error_free (error);
239
g_free (error_message);
242
else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (nact_get_glade_widget_from ("GConfRadioButton",
243
GLADE_IM_EX_PORT_DIALOG_WIDGET))))
245
if (nautilus_actions_config_schema_reader_parse_file (schema_reader, file_path, &error))
247
generic_reader = NAUTILUS_ACTIONS_CONFIG (schema_reader);
251
error_message = g_strdup_printf (_("Can't parse file '%s' as GConf schema description file !"), file_path);
252
nautilus_actions_display_error (error_message, error->message);
253
g_error_free (error);
254
g_free (error_message);
257
else /* Automatic detection asked */
259
//--> we are ignoring the first error because if it fails here it will not in the next
260
// or if both fails, we kept the current GConf config format as the most important
261
if (nautilus_actions_config_xml_parse_file (xml_reader, file_path, NULL))
263
generic_reader = NAUTILUS_ACTIONS_CONFIG (xml_reader);
265
else if (nautilus_actions_config_schema_reader_parse_file (schema_reader, file_path, &error))
267
generic_reader = NAUTILUS_ACTIONS_CONFIG (schema_reader);
271
error_message = g_strdup_printf (_("Can't parse file '%s' !"), file_path);
272
nautilus_actions_display_error (error_message, error->message);
273
g_error_free (error);
274
g_free (error_message);
212
nautilus_actions_config_clear(( NautilusActionsConfig * ) schema_reader );
214
if (file_path != NULL && strlen (file_path) > 0)
216
if (nautilus_actions_config_schema_reader_parse_file (schema_reader, file_path, &error))
218
generic_reader = NAUTILUS_ACTIONS_CONFIG (schema_reader);
222
error_message = g_strdup_printf (_("Can't parse file '%s' as GConf schema description file!"), file_path);
223
nautilus_actions_display_error (error_message, error->message);
224
g_error_free (error);
225
g_free (error_message);
292
// i18n notes: %s is the label of the action (eg, 'Mount ISO')
293
error_message = g_strdup_printf (_("Action '%s' importation failed !"), action->label);
242
/* i18n notes: %s is the label of the action (eg, 'Mount ISO') */
243
error_message = g_strdup_printf (_("Action '%s' importation failed!"), action->label);
294
244
nautilus_actions_display_error (error_message, error->message);
295
245
g_error_free (error);
296
246
g_free (error_message);
304
gboolean nact_export_actions (void)
254
nact_export_actions (void)
306
256
gboolean retv = FALSE;
307
257
GtkTreeSelection *selection;
334
284
gtk_tree_model_get (model, &iter, UUID_COLUMN, &uuid, -1);
336
286
action = nautilus_actions_config_get_action (NAUTILUS_ACTIONS_CONFIG (config), uuid);
337
// TODO: Better error handling: deal with the GError param
287
/* TODO: Better error handling: deal with the GError param */
338
288
if (nautilus_actions_config_add_action (NAUTILUS_ACTIONS_CONFIG (schema_writer), action, NULL))
340
nautilus_actions_config_schema_writer_get_saved_filename (schema_writer, action->uuid);
290
/*nautilus_actions_config_schema_writer_get_saved_filename (schema_writer, action->uuid);*/
380
330
g_error (_("Could not load interface for Nautilus Actions Config Tool"));
384
334
glade_xml_signal_autoconnect (gui);
386
336
nact_action_list_tree = nact_get_glade_widget_from ("ExportTreeView", GLADE_IM_EX_PORT_DIALOG_WIDGET);
387
337
nact_setup_actions_list (nact_action_list_tree);
389
339
aligned_widgets = nact_get_glade_widget_prefix_from ("IELabelAlign", GLADE_IM_EX_PORT_DIALOG_WIDGET);
390
340
label_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
391
341
for (iter = aligned_widgets; iter; iter = iter->next)
393
343
gtk_size_group_add_widget (label_size_group, GTK_WIDGET (iter->data));
395
345
button_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
396
gtk_size_group_add_widget (button_size_group,
397
nact_get_glade_widget_from ("ImportBrowseButton",
346
gtk_size_group_add_widget (button_size_group,
347
nact_get_glade_widget_from ("ImportBrowseButton",
398
348
GLADE_IM_EX_PORT_DIALOG_WIDGET));
399
gtk_size_group_add_widget (button_size_group,
400
nact_get_glade_widget_from ("ExportBrowseButton",
349
gtk_size_group_add_widget (button_size_group,
350
nact_get_glade_widget_from ("ExportBrowseButton",
401
351
GLADE_IM_EX_PORT_DIALOG_WIDGET));
402
352
/* free memory */
403
353
g_object_unref (gui);
414
364
/* Get the default dialog size */
415
365
gtk_window_get_default_size (GTK_WINDOW (import_export_dialog), &width, &height);
417
367
/* Override with preferred one, if any */
418
368
nact_prefs_get_im_ex_dialog_size (&width, &height);
420
370
gtk_window_resize (GTK_WINDOW (import_export_dialog), width, height);
422
372
if (nact_prefs_get_im_ex_dialog_position (&x, &y))
427
377
last_dir = nact_prefs_get_export_last_browsed_dir ();
428
378
gtk_entry_set_text (GTK_ENTRY (nact_get_glade_widget_from ("ExportEntry", GLADE_IM_EX_PORT_DIALOG_WIDGET)), last_dir);
429
gtk_entry_select_region (GTK_ENTRY (nact_get_glade_widget_from ("ExportEntry", GLADE_IM_EX_PORT_DIALOG_WIDGET)), 0, -1);
379
gtk_editable_select_region (GTK_EDITABLE (nact_get_glade_widget_from ("ExportEntry", GLADE_IM_EX_PORT_DIALOG_WIDGET)), 0, -1);
431
381
/* run the dialog */
432
switch (gtk_dialog_run (GTK_DIALOG (import_export_dialog)))
382
switch (gtk_dialog_run (GTK_DIALOG (import_export_dialog)))
434
384
case GTK_RESPONSE_OK :
435
385
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (import_radio)))