~ubuntu-branches/ubuntu/trusty/nautilus-actions/trusty-proposed

« back to all changes in this revision

Viewing changes to nact/nact-import-export.c

  • Committer: Bazaar Package Importer
  • Author(s): Christine Spang
  • Date: 2009-05-30 10:15:52 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090530101552-5nicx1db3luh9n7e
Tags: 1.10.1-1
* New upstream release.
  - Do not search through actions when the Nautilus-provided list of
    selected files is empty
  - Remove deprecated functions
  - All sources are now ansi-compliant, though not (yet) pedantic
  - Double-click on an action opens the editor
  - Enable the OK button as soon as required fields are filled
  - Enable syslog'ed debug messages when in maintainer mode
  - Use NACT_GNOME_COMPILE_WARNINGS (see Gnome bugzilla bug #582860)
  - Replace configure.in with configure.ac, updating all Makefile.am
    accordingly
  - Fix make distcheck
  - create nautilus-actions.doap
  - Gnome bugzilla bug #574919 fixed (Closes: #523854)
  - Gnome bugzilla bugs #522605, #573365, and #568366 fixed
  - translations updated
* Added Homepage: field to debian/control
* Bump to Standards-Version 3.8.1
* update GNOME_DOWNLOAD_URL in debian/rules
* add full list of contributors to debian/copyright
* Bump debhelper compat to 7
* Fix categories in .desktop file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Nautilus Actions configuration tool
 
1
/*
 
2
 * Nautilus Actions
 
3
 *
2
4
 * Copyright (C) 2005 The GNOME Foundation
3
 
 *
4
 
 * Authors:
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)
7
7
 *
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.
12
12
 *
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.
17
17
 *
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.
 
22
 *
 
23
 * Authors:
 
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)
22
28
 */
23
29
 
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"
38
43
#include "nact.h"
39
44
 
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);
 
49
 
 
50
static gboolean nact_import_actions (void);
 
51
static gboolean nact_export_actions (void);
 
52
 
 
53
void
 
54
mode_toggled_cb (GtkWidget* widget, gpointer user_data)
41
55
{
42
56
        GtkWidget* import_radio = nact_get_glade_widget_from ("ImportRadioButton", GLADE_IM_EX_PORT_DIALOG_WIDGET);
43
57
 
53
67
        }
54
68
}
55
69
 
56
 
void import_all_config_toggled_cb (GtkWidget* check_button, gpointer data) 
57
 
{
58
 
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_button)))
59
 
        {
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);
64
 
        }
65
 
        else
66
 
        {
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);
69
 
        }
70
 
}
71
 
 
72
 
void import_browse_button_clicked_cb (GtkWidget* widget, gpointer data)
 
70
void
 
71
import_browse_button_clicked_cb (GtkWidget* widget, gpointer data)
73
72
{
74
73
        gchar* last_dir;
75
74
        gchar* filename;
82
81
        {
83
82
                set_current_location = gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (filechooser), filename);
84
83
        }
85
 
        
 
84
 
86
85
        if (!set_current_location)
87
86
        {
88
87
                last_dir = nact_prefs_get_import_last_browsed_dir ();
90
89
                g_free (last_dir);
91
90
        }
92
91
 
93
 
        switch (gtk_dialog_run (GTK_DIALOG (filechooser))) 
 
92
        switch (gtk_dialog_run (GTK_DIALOG (filechooser)))
94
93
        {
95
94
                case GTK_RESPONSE_OK :
96
95
                        last_dir = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (filechooser));
103
102
                case GTK_RESPONSE_CANCEL:
104
103
                case GTK_RESPONSE_DELETE_EVENT:
105
104
                        gtk_widget_hide (filechooser);
106
 
        }       
 
105
        }
107
106
}
108
107
 
109
 
void export_browse_button_clicked_cb (GtkWidget* widget, gpointer data) 
 
108
void
 
109
export_browse_button_clicked_cb (GtkWidget* widget, gpointer data)
110
110
{
111
111
        gchar* last_dir;
112
112
        gchar* foldername;
119
119
        {
120
120
                set_current_location = gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (folderchooser), foldername);
121
121
        }
122
 
        
 
122
 
123
123
        if (!set_current_location)
124
124
        {
125
125
                last_dir = nact_prefs_get_export_last_browsed_dir ();
127
127
                g_free (last_dir);
128
128
        }
129
129
 
130
 
        switch (gtk_dialog_run (GTK_DIALOG (folderchooser))) 
 
130
        switch (gtk_dialog_run (GTK_DIALOG (folderchooser)))
131
131
        {
132
132
                case GTK_RESPONSE_OK :
133
133
                        last_dir = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (folderchooser));
140
140
                case GTK_RESPONSE_CANCEL:
141
141
                case GTK_RESPONSE_DELETE_EVENT:
142
142
                        gtk_widget_hide (folderchooser);
143
 
        }       
 
143
        }
144
144
}
145
145
 
146
 
 
147
146
static void
148
147
list_selection_changed_cb (GtkTreeSelection *selection, gpointer user_data)
149
148
{
150
149
/*
151
150
        GtkWidget *nact_edit_button;
152
151
        GtkWidget *nact_delete_button;
153
 
        
 
152
 
154
153
        nact_edit_button = nact_get_glade_widget ("EditActionButton");
155
154
        nact_delete_button = nact_get_glade_widget ("DeleteActionButton");
156
155
 
188
187
 
189
188
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list));
190
189
        gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
191
 
        
 
190
 
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);
195
194
 
196
195
}
197
196
 
198
 
gboolean nact_import_actions (void)
 
197
static gboolean
 
198
nact_import_actions (void)
199
199
{
200
200
        gboolean retv = FALSE;
201
 
        GtkWidget* check_button;
202
201
        GSList* iter;
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;
211
209
 
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);
217
 
 
218
 
        check_button = nact_get_glade_widget_from ("ImportAllCheckButton", GLADE_IM_EX_PORT_DIALOG_WIDGET);
219
 
 
220
 
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_button)))
221
 
        {
222
 
                nautilus_actions_config_xml_load_list (xml_reader);
223
 
                generic_reader = NAUTILUS_ACTIONS_CONFIG (xml_reader);
224
 
        }
225
 
        else if (file_path != NULL && strlen (file_path) > 0)
226
 
        {
227
 
                if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (nact_get_glade_widget_from ("XMLRadioButton", 
228
 
                                                                                                                                                        GLADE_IM_EX_PORT_DIALOG_WIDGET))))
229
 
                {
230
 
                        if (nautilus_actions_config_xml_parse_file (xml_reader, file_path, &error))
231
 
                        {
232
 
                                generic_reader = NAUTILUS_ACTIONS_CONFIG (xml_reader);
233
 
                        }
234
 
                        else
235
 
                        {
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);
240
 
                        }
241
 
                }
242
 
                else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (nact_get_glade_widget_from ("GConfRadioButton", 
243
 
                                                                                                                                                        GLADE_IM_EX_PORT_DIALOG_WIDGET))))
244
 
                {
245
 
                        if (nautilus_actions_config_schema_reader_parse_file (schema_reader, file_path, &error))
246
 
                        {
247
 
                                generic_reader = NAUTILUS_ACTIONS_CONFIG (schema_reader);
248
 
                        }
249
 
                        else
250
 
                        {
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);
255
 
                        }
256
 
                }
257
 
                else /* Automatic detection asked */
258
 
                {
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))
262
 
                        {
263
 
                                generic_reader = NAUTILUS_ACTIONS_CONFIG (xml_reader);
264
 
                        }
265
 
                        else if (nautilus_actions_config_schema_reader_parse_file (schema_reader, file_path, &error))
266
 
                        {
267
 
                                generic_reader = NAUTILUS_ACTIONS_CONFIG (schema_reader);
268
 
                        }
269
 
                        else
270
 
                        {
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);
275
 
                        }
 
212
        nautilus_actions_config_clear(( NautilusActionsConfig * ) schema_reader );
 
213
 
 
214
        if (file_path != NULL && strlen (file_path) > 0)
 
215
        {
 
216
                if (nautilus_actions_config_schema_reader_parse_file (schema_reader, file_path, &error))
 
217
                {
 
218
                        generic_reader = NAUTILUS_ACTIONS_CONFIG (schema_reader);
 
219
                }
 
220
                else
 
221
                {
 
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);
276
226
                }
277
227
        }
278
228
 
289
239
                        }
290
240
                        else
291
241
                        {
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);
297
247
                        }
298
248
                }
299
249
        }
300
 
 
301
250
        return retv;
302
251
}
303
252
 
304
 
gboolean nact_export_actions (void)
 
253
static gboolean
 
254
nact_export_actions (void)
305
255
{
306
256
        gboolean retv = FALSE;
307
257
        GtkTreeSelection *selection;
334
284
                        gtk_tree_model_get (model, &iter, UUID_COLUMN, &uuid, -1);
335
285
 
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))
339
289
                        {
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);*/
341
291
                        }
342
292
 
343
293
                        g_free (uuid);
347
297
                g_list_free (selection_list);
348
298
                retv = TRUE;
349
299
        }
350
 
        
 
300
 
351
301
        if (retv)
352
302
        {
353
303
                gchar* command = g_strdup_printf ("nautilus %s", save_path);
380
330
                        g_error (_("Could not load interface for Nautilus Actions Config Tool"));
381
331
                        return FALSE;
382
332
                }
383
 
                
 
333
 
384
334
                glade_xml_signal_autoconnect (gui);
385
335
 
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);
388
 
                
 
338
 
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));
394
344
                }
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);
413
363
 
414
364
        /* Get the default dialog size */
415
365
        gtk_window_get_default_size (GTK_WINDOW (import_export_dialog), &width, &height);
416
 
        
 
366
 
417
367
        /* Override with preferred one, if any */
418
368
        nact_prefs_get_im_ex_dialog_size (&width, &height);
419
 
        
 
369
 
420
370
        gtk_window_resize (GTK_WINDOW (import_export_dialog), width, height);
421
371
 
422
372
        if (nact_prefs_get_im_ex_dialog_position (&x, &y))
426
376
 
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);
430
 
        
 
379
        gtk_editable_select_region (GTK_EDITABLE (nact_get_glade_widget_from ("ExportEntry", GLADE_IM_EX_PORT_DIALOG_WIDGET)), 0, -1);
 
380
 
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)))
433
383
        {
434
384
                case GTK_RESPONSE_OK :
435
385
                        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (import_radio)))
456
406
 
457
407
        return retv;
458
408
}
459
 
 
460
 
// vim:ts=3:sw=3:tw=1024:cin