1
/* Nautilus Actions configuration tool
2
4
* Copyright (C) 2005 The GNOME Foundation
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)
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>
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"
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 );
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);
41
63
static NautilusActionsConfigGconfWriter *config = NULL;
43
gint actions_list_sort_by_label (gconstpointer a1, gconstpointer a2)
66
on_ActionsList_button_press_event( GtkWidget *widget, GdkEventButton *event, gpointer data )
68
if( event->type == GDK_2BUTTON_PRESS ){
69
edit_button_clicked_cb( NULL, NULL );
72
/* unmanaged event: let the framework do its job */
77
get_profiles_count( const NautilusActionsConfigAction *action )
79
return( nautilus_actions_config_action_get_profiles_count( action ));
83
actions_list_sort_by_label (gconstpointer a1, gconstpointer a2)
45
85
NautilusActionsConfigAction* action1 = (NautilusActionsConfigAction*)a1;
46
86
NautilusActionsConfigAction* action2 = (NautilusActionsConfigAction*)a2;
48
88
return g_utf8_collate (action1->label, action2->label);
51
void nact_fill_actions_list (GtkWidget *list)
92
fill_actions_list (GtkWidget *list)
53
94
GSList *actions, *l;
54
95
GtkListStore *model = GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW (list)));
73
114
GError* error = NULL;
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);
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,
92
133
nautilus_actions_config_free_actions_list (actions);
137
* creating a new action
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
96
144
add_button_clicked_cb (GtkButton *button, gpointer user_data)
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" ));
151
* editing an existing action
153
* I don't want the profiles feature spread wide while I'm not convinced
154
* that it is useful and actually used.
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
103
162
edit_button_clicked_cb (GtkButton *button, gpointer user_data)
118
177
gtk_tree_model_get (model, &iter, UUID_COLUMN, &uuid, -1);
120
179
action = nautilus_actions_config_get_action (NAUTILUS_ACTIONS_CONFIG (config), uuid);
122
if (nact_editor_edit_action (action))
123
nact_fill_actions_list (nact_actions_list);
181
guint count = get_profiles_count( action );
183
if (nact_editor_edit_action (action))
184
fill_actions_list (nact_actions_list);
186
if( nact_action_editor_edit( action ))
187
fill_actions_list( nact_actions_list );
142
207
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (nact_actions_list));
144
if (gtk_tree_selection_get_selected (selection, &model, &iter))
209
if (gtk_tree_selection_get_selected (selection, &model, &iter))
147
212
NautilusActionsConfigAction *action;
152
217
action = nautilus_actions_config_get_action (NAUTILUS_ACTIONS_CONFIG (config), uuid);
153
218
new_action = nautilus_actions_config_action_dup_new (action);
156
221
if (nautilus_actions_config_add_action (NAUTILUS_ACTIONS_CONFIG (config), new_action, &error))
158
nact_fill_actions_list (nact_actions_list);
223
fill_actions_list (nact_actions_list);
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);
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);
197
void im_export_button_clicked_cb (GtkButton *button, gpointer user_data)
262
im_export_button_clicked_cb (GtkButton *button, gpointer user_data)
199
264
GtkWidget *nact_actions_list;
201
266
if (nact_import_export_actions ())
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);
209
274
dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer user_data)
276
GtkWidget* nact_about_dialog;
277
GtkWidget *nact_prof_paste_button = nact_get_glade_widget_from ("PasteProfileButton", GLADE_EDIT_DIALOG_WIDGET);
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"));
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 ();
218
292
gtk_widget_destroy (GTK_WIDGET (dialog));
219
293
nact_destroy_glade_objects ();
220
g_object_unref (config);
221
294
gtk_main_quit ();
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);
231
311
GtkWidget *nact_edit_button;
232
312
GtkWidget *nact_delete_button;
233
313
GtkWidget *nact_duplicate_button;
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");
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);
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);
287
369
g_error (_("Could not load interface for Nautilus Actions Config Tool"));
293
375
nact_dialog = nact_get_glade_widget ("ActionsDialog");
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);
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);
303
385
gtk_window_resize (GTK_WINDOW (nact_dialog), width, height);
305
387
/* Get the default position */
310
392
gtk_window_move (GTK_WINDOW (nact_dialog), x, y);
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");
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);
320
408
/* display the dialog */
321
409
gtk_widget_show (nact_dialog);
322
410
g_object_unref (gui);