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

« back to all changes in this revision

Viewing changes to nact/nact.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
 
 *       Rodrigo Moya (rodrigo@gnome-db.org)
6
 
 *  Frederic Ruaudel (grumz@grumz.net)
 
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>
37
43
#include "nact-editor.h"
38
44
#include "nact-import-export.h"
39
45
#include "nact-prefs.h"
 
46
#include "nact-action-editor.h"
 
47
 
 
48
/* gui callback functions */
 
49
void     dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer user_data);
 
50
void     add_button_clicked_cb (GtkButton *button, gpointer user_data);
 
51
void     delete_button_clicked_cb (GtkButton *button, gpointer user_data);
 
52
void     duplicate_button_clicked_cb (GtkButton *button, gpointer user_data);
 
53
void     edit_button_clicked_cb (GtkButton *button, gpointer user_data);
 
54
void     im_export_button_clicked_cb (GtkButton *button, gpointer user_data);
 
55
gboolean on_ActionsList_button_press_event( GtkWidget *widget, GdkEventButton *event, gpointer data );
 
56
 
 
57
static gint  actions_list_sort_by_label (gconstpointer a1, gconstpointer a2);
 
58
static guint get_profiles_count( const NautilusActionsConfigAction *action );
 
59
static void  list_selection_changed_cb (GtkTreeSelection *selection, gpointer user_data);
 
60
static void  fill_actions_list (GtkWidget *list);
 
61
static void  setup_actions_list (GtkWidget *list);
40
62
 
41
63
static NautilusActionsConfigGconfWriter *config = NULL;
42
64
 
43
 
gint actions_list_sort_by_label (gconstpointer a1, gconstpointer a2)
 
65
gboolean
 
66
on_ActionsList_button_press_event( GtkWidget *widget, GdkEventButton *event, gpointer data )
 
67
{
 
68
        if( event->type == GDK_2BUTTON_PRESS ){
 
69
                edit_button_clicked_cb( NULL, NULL );
 
70
                return( TRUE );
 
71
        }
 
72
        /* unmanaged event: let the framework do its job */
 
73
        return( FALSE );
 
74
}
 
75
 
 
76
static guint
 
77
get_profiles_count( const NautilusActionsConfigAction *action )
 
78
{
 
79
        return( nautilus_actions_config_action_get_profiles_count( action ));
 
80
}
 
81
 
 
82
static gint
 
83
actions_list_sort_by_label (gconstpointer a1, gconstpointer a2)
44
84
{
45
85
        NautilusActionsConfigAction* action1 = (NautilusActionsConfigAction*)a1;
46
86
        NautilusActionsConfigAction* action2 = (NautilusActionsConfigAction*)a2;
48
88
        return g_utf8_collate (action1->label, action2->label);
49
89
}
50
90
 
51
 
void nact_fill_actions_list (GtkWidget *list)
 
91
static void
 
92
fill_actions_list (GtkWidget *list)
52
93
{
53
94
        GSList *actions, *l;
54
95
        GtkListStore *model = GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW (list)));
71
112
                                gint width;
72
113
                                gint height;
73
114
                                GError* error = NULL;
74
 
                                
 
115
 
75
116
                                gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
76
117
                                icon = gdk_pixbuf_new_from_file_at_size (action->icon, width, height, &error);
77
118
                                if (error)
82
123
                        }
83
124
                }
84
125
                gtk_list_store_append (model, &iter);
85
 
                gtk_list_store_set (model, &iter, 
86
 
                                    MENU_ICON_COLUMN, icon, 
 
126
                gtk_list_store_set (model, &iter,
 
127
                                    MENU_ICON_COLUMN, icon,
87
128
                                    MENU_LABEL_COLUMN, action->label,
88
129
                                    UUID_COLUMN, action->uuid,
89
130
                                    -1);
92
133
        nautilus_actions_config_free_actions_list (actions);
93
134
}
94
135
 
 
136
/*
 
137
 * creating a new action
 
138
 * pwi 2009-05-19
 
139
 * I don't want the profiles feature spread wide while I'm not convinced
 
140
 * that it is useful and actually used.
 
141
 * so the new action is silently created with a default profile name
 
142
 */
95
143
void
96
144
add_button_clicked_cb (GtkButton *button, gpointer user_data)
97
145
{
98
 
        if (nact_editor_new_action ())
99
 
                nact_fill_actions_list (nact_get_glade_widget ("ActionsList"));
 
146
        if( nact_action_editor_new())
 
147
                fill_actions_list( nact_get_glade_widget( "ActionsList" ));
100
148
}
101
149
 
 
150
/*
 
151
 * editing an existing action
 
152
 * pwi 2009-05-19
 
153
 * I don't want the profiles feature spread wide while I'm not convinced
 
154
 * that it is useful and actually used.
 
155
 * so :
 
156
 * - if there is only one profile, the user will be directed to a dialog
 
157
 *   box which includes all needed fields, but without any profile notion
 
158
 * - if there are more than one profile, one can assume that the user has
 
159
 *   found a use to the profiles, and let him edit them
 
160
 */
102
161
void
103
162
edit_button_clicked_cb (GtkButton *button, gpointer user_data)
104
163
{
118
177
                gtk_tree_model_get (model, &iter, UUID_COLUMN, &uuid, -1);
119
178
 
120
179
                action = nautilus_actions_config_get_action (NAUTILUS_ACTIONS_CONFIG (config), uuid);
121
 
                if (action) {
122
 
                        if (nact_editor_edit_action (action))
123
 
                                nact_fill_actions_list (nact_actions_list);
 
180
                if( action ){
 
181
                        guint count = get_profiles_count( action );
 
182
                        if( count > 1 ){
 
183
                                if (nact_editor_edit_action (action))
 
184
                                        fill_actions_list (nact_actions_list);
 
185
                        } else {
 
186
                                if( nact_action_editor_edit( action ))
 
187
                                        fill_actions_list( nact_actions_list );
 
188
                        }
124
189
                }
125
190
 
126
191
                g_free (uuid);
141
206
 
142
207
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (nact_actions_list));
143
208
 
144
 
        if (gtk_tree_selection_get_selected (selection, &model, &iter)) 
 
209
        if (gtk_tree_selection_get_selected (selection, &model, &iter))
145
210
        {
146
211
                gchar *uuid;
147
212
                NautilusActionsConfigAction *action;
151
216
 
152
217
                action = nautilus_actions_config_get_action (NAUTILUS_ACTIONS_CONFIG (config), uuid);
153
218
                new_action = nautilus_actions_config_action_dup_new (action);
154
 
                if (new_action) 
 
219
                if (new_action)
155
220
                {
156
221
                        if (nautilus_actions_config_add_action (NAUTILUS_ACTIONS_CONFIG (config), new_action, &error))
157
222
                        {
158
 
                                nact_fill_actions_list (nact_actions_list);
 
223
                                fill_actions_list (nact_actions_list);
159
224
                        }
160
225
                        else
161
226
                        {
162
 
                                // i18n notes: will be displayed in a dialog
163
 
                                tmp = g_strdup_printf (_("Can't duplicate action '%s' !"), action->label);
 
227
                                /* i18n notes: will be displayed in a dialog */
 
228
                                tmp = g_strdup_printf (_("Can't duplicate action '%s'!"), action->label);
164
229
                                nautilus_actions_display_error (tmp, error->message);
165
230
                                g_error_free (error);
166
231
                                g_free (tmp);
167
232
                        }
168
233
                }
169
 
 
170
234
                g_free (uuid);
171
235
        }
172
236
}
188
252
 
189
253
                gtk_tree_model_get (model, &iter, UUID_COLUMN, &uuid, -1);
190
254
                nautilus_actions_config_remove_action (NAUTILUS_ACTIONS_CONFIG (config), uuid);
191
 
                nact_fill_actions_list (nact_actions_list);
 
255
                fill_actions_list (nact_actions_list);
192
256
 
193
257
                g_free (uuid);
194
258
        }
195
259
}
196
260
 
197
 
void im_export_button_clicked_cb (GtkButton *button, gpointer user_data)
 
261
void
 
262
im_export_button_clicked_cb (GtkButton *button, gpointer user_data)
198
263
{
199
264
        GtkWidget *nact_actions_list;
200
265
 
201
266
        if (nact_import_export_actions ())
202
267
        {
203
268
                nact_actions_list = nact_get_glade_widget ("ActionsList");
204
 
                nact_fill_actions_list (nact_actions_list);
 
269
                fill_actions_list (nact_actions_list);
205
270
        }
206
271
}
207
272
 
208
273
void
209
274
dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer user_data)
210
275
{
 
276
        GtkWidget* nact_about_dialog;
 
277
        GtkWidget *nact_prof_paste_button = nact_get_glade_widget_from ("PasteProfileButton", GLADE_EDIT_DIALOG_WIDGET);
 
278
 
211
279
        switch (response_id) {
212
280
        case GTK_RESPONSE_NONE :
213
281
        case GTK_RESPONSE_DELETE_EVENT :
214
282
        case GTK_RESPONSE_CLOSE :
 
283
                /* Free any profile in the clipboard */
 
284
                nautilus_actions_config_action_profile_free (g_object_steal_data (G_OBJECT (nact_prof_paste_button), "profile"));
 
285
 
 
286
                /* FIXME : update pref settings
215
287
                nact_prefs_set_main_dialog_size (GTK_WINDOW (dialog));
216
288
                nact_prefs_set_main_dialog_position (GTK_WINDOW (dialog));
217
289
                nact_prefs_save_preferences ();
 
290
                */
 
291
 
218
292
                gtk_widget_destroy (GTK_WIDGET (dialog));
219
293
                nact_destroy_glade_objects ();
220
 
                g_object_unref (config);
221
294
                gtk_main_quit ();
222
295
                break;
223
296
        case GTK_RESPONSE_HELP :
 
297
#if ((GTK_MAJOR_VERSION == 2) && (GTK_MINOR_VERSION >= 6))
 
298
                nact_about_dialog = nact_get_glade_widget_from ("AboutDialog", GLADE_ABOUT_DIALOG_WIDGET);
 
299
                gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (nact_about_dialog), PACKAGE_VERSION);
 
300
                gtk_about_dialog_set_logo_icon_name (GTK_ABOUT_DIALOG (nact_about_dialog), "nautilus-actions");
 
301
                gtk_dialog_run (GTK_DIALOG (nact_about_dialog));
 
302
                gtk_widget_hide (nact_about_dialog);
 
303
#endif
224
304
                break;
225
305
        }
226
306
}
231
311
        GtkWidget *nact_edit_button;
232
312
        GtkWidget *nact_delete_button;
233
313
        GtkWidget *nact_duplicate_button;
234
 
        
 
314
 
235
315
        nact_edit_button = nact_get_glade_widget ("EditActionButton");
236
316
        nact_delete_button = nact_get_glade_widget ("DeleteActionButton");
237
317
        nact_duplicate_button = nact_get_glade_widget ("DuplicateActionButton");
247
327
        }
248
328
}
249
329
 
250
 
static void nact_setup_actions_list (GtkWidget *list)
 
330
static void
 
331
setup_actions_list (GtkWidget *list)
251
332
{
252
333
        GtkListStore *model;
253
334
        GtkTreeViewColumn *column;
255
336
        /* create the model */
256
337
        model = gtk_list_store_new (N_COLUMN, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
257
338
        gtk_tree_view_set_model (GTK_TREE_VIEW (list), GTK_TREE_MODEL (model));
258
 
        nact_fill_actions_list (list);
 
339
        fill_actions_list( list );
259
340
        g_object_unref (model);
260
341
 
261
342
        /* create columns on the tree view */
281
362
        gint width, height, x, y;
282
363
        GtkWidget *nact_dialog;
283
364
        GtkWidget *nact_actions_list;
284
 
        GtkWidget* nact_edit_button;
 
365
        /*GtkWidget* nact_edit_button;*/
 
366
        GtkWidget* nact_about_button;
285
367
        GladeXML *gui = nact_get_glade_xml_object (GLADE_MAIN_WIDGET);
286
368
        if (!gui) {
287
369
                g_error (_("Could not load interface for Nautilus Actions Config Tool"));
293
375
        nact_dialog = nact_get_glade_widget ("ActionsDialog");
294
376
 
295
377
        nact_actions_list = nact_get_glade_widget ("ActionsList");
296
 
        nact_setup_actions_list (nact_actions_list);
 
378
        setup_actions_list (nact_actions_list);
297
379
 
298
380
        /* Get the default dialog size */
299
381
        gtk_window_get_default_size (GTK_WINDOW (nact_dialog), &width, &height);
300
382
        /* Override with preferred one, if any */
301
383
        nact_prefs_get_main_dialog_size (&width, &height);
302
 
        
 
384
 
303
385
        gtk_window_resize (GTK_WINDOW (nact_dialog), width, height);
304
386
 
305
387
        /* Get the default position */
309
391
 
310
392
        gtk_window_move (GTK_WINDOW (nact_dialog), x, y);
311
393
 
312
 
#if ((GTK_MAJOR_VERSION == 2) && (GTK_MINOR_VERSION == 4))      
 
394
#if ((GTK_MAJOR_VERSION == 2) && (GTK_MINOR_VERSION == 4))
313
395
        /* Fix a stock icon bug with GTK+ 2.4 */
314
396
        nact_edit_button = nact_get_glade_widget ("EditActionButton");
315
397
        gtk_button_set_use_stock (GTK_BUTTON (nact_edit_button), FALSE);
317
399
        gtk_button_set_label (GTK_BUTTON (nact_edit_button), "_Edit");
318
400
#endif
319
401
 
 
402
#if ((GTK_MAJOR_VERSION == 2) && (GTK_MINOR_VERSION >= 6))
 
403
        /* Add about dialog for GTK+ >= 2.6 */
 
404
        nact_about_button = nact_get_glade_widget ("AboutButton");
 
405
        gtk_widget_show (nact_about_button);
 
406
#endif
 
407
 
320
408
        /* display the dialog */
321
409
        gtk_widget_show (nact_dialog);
322
410
        g_object_unref (gui);
347
435
        gtk_main ();
348
436
        return 0;
349
437
}
350
 
 
351
 
// vim:ts=3:sw=3:tw=1024:cin