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

« back to all changes in this revision

Viewing changes to nact/nact-utils.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)
 
5
 * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
 
6
 * Copyright (C) 2009 Pierre Wieser and others (see AUTHORS)
6
7
 *
7
8
 * This Program is free software; you can redistribute it and/or
8
9
 * modify it under the terms of the GNU General Public License as
9
 
 * published by the Free Software Foundation; either version 2 of the
10
 
 * 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.
11
12
 *
12
13
 * This Program is distributed in the hope that it will be useful,
13
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
 * General Public License for more details.
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
16
17
 *
17
18
 * You should have received a copy of the GNU General Public
18
19
 * License along with this Library; see the file COPYING.  If not,
19
 
 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
 
 * 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)
21
28
 */
22
29
 
23
30
#include <config.h>
98
105
        }
99
106
 
100
107
   error_dialog = nact_get_glade_widget_from ("ErrorDialog", GLADE_ERROR_DIALOG_WIDGET);
101
 
        
 
108
 
102
109
        error_label = nact_get_glade_widget_from ("ErrorLabel", GLADE_ERROR_DIALOG_WIDGET);
103
110
 
104
111
        tmp = g_markup_printf_escaped (label_text_template, primary_msg, secondary_msg);
111
118
   g_object_unref (gui);
112
119
}
113
120
 
114
 
gboolean nact_utils_get_action_schemes_list (GtkTreeModel* scheme_model, GtkTreePath *path, 
 
121
gboolean nact_utils_get_action_schemes_list (GtkTreeModel* scheme_model, GtkTreePath *path,
115
122
                                                                                                          GtkTreeIter* iter, gpointer data)
116
123
{
 
124
        static const char *thisfn = "nact_utils_get_action_schemes_list";
117
125
        GSList** list = data;
118
126
        gboolean toggle_state;
119
127
        gchar* scheme;
120
128
 
121
 
        gtk_tree_model_get (scheme_model, iter, SCHEMES_CHECKBOX_COLUMN, &toggle_state, 
 
129
        gtk_tree_model_get (scheme_model, iter, SCHEMES_CHECKBOX_COLUMN, &toggle_state,
122
130
                                                                                                                 SCHEMES_KEYWORD_COLUMN, &scheme, -1);
123
131
 
124
132
        if (toggle_state)
125
133
        {
 
134
                g_debug( "%s: adding '%s' scheme", thisfn, scheme );
126
135
                (*list) = g_slist_append ((*list), scheme);
127
136
        }
128
137
        else
130
139
                g_free (scheme);
131
140
        }
132
141
 
133
 
        return FALSE; // Don't stop looping
 
142
        return FALSE; /* Don't stop looping */
134
143
}
135
144
 
136
145
static gchar* nact_utils_joinv (const gchar* start, const gchar* separator, gchar** list)
149
158
        {
150
159
                tmp_string = g_string_append (tmp_string, _(list[0]));
151
160
        }
152
 
        
 
161
 
153
162
        for (i = 1; list[i] != NULL; i++)
154
163
        {
155
164
                if (separator)
162
171
        return g_string_free (tmp_string, FALSE);
163
172
}
164
173
 
165
 
gchar* nact_utils_parse_parameter (void)
 
174
gchar *
 
175
nact_utils_parse_parameter( const gchar *dialog )
166
176
{
167
177
        /*
168
178
         * Valid parameters :
169
 
         * 
 
179
         *
170
180
         * %u : gnome-vfs URI
171
181
         * %d : base dir of the selected file(s)/folder(s)
172
182
         * %f : the name of the selected file/folder or the 1st one if many are selected
180
190
         */
181
191
        gchar* retv = NULL;
182
192
        GString* tmp_string = g_string_new ("");
183
 
        
 
193
 
184
194
        /* i18n notes: example strings for the command preview */
185
195
        gchar* ex_path = _("/path/to");
186
196
        gchar* ex_files[] = { N_("file1.txt"), N_("file2.txt"), NULL };
190
200
        gchar* ex_host_default = _("test.example.net");
191
201
        gchar* ex_one_file = _("file.txt");
192
202
        gchar* ex_one_dir = _("folder");
193
 
        gchar* ex_one;
194
 
        gchar* ex_list;
195
 
        gchar* ex_path_list;
 
203
        gchar* ex_one = NULL;
 
204
        gchar* ex_list = NULL;
 
205
        gchar* ex_path_list = NULL;
196
206
        gchar* ex_scheme;
197
207
        gchar* ex_host;
198
208
 
199
 
        const gchar* param_template = gtk_entry_get_text (GTK_ENTRY (nact_get_glade_widget_from ("CommandParamsEntry", 
200
 
                                                                                                                                                                                                                GLADE_EDIT_DIALOG_WIDGET)));
 
209
        const gchar* param_template = gtk_entry_get_text (GTK_ENTRY (nact_get_glade_widget_from ("CommandParamsEntry", dialog )));
201
210
        gchar* iter = g_strdup (param_template);
202
211
        gchar* old_iter = iter;
203
212
        gchar* tmp;
205
214
        gchar* start;
206
215
        GSList* scheme_list = NULL;
207
216
 
208
 
        const gchar* command = gtk_entry_get_text (GTK_ENTRY (nact_get_glade_widget_from ("CommandPathEntry", 
209
 
                                                                                                                                                                                                GLADE_EDIT_DIALOG_WIDGET)));
 
217
        const gchar* command = gtk_entry_get_text (GTK_ENTRY (nact_get_glade_widget_from ("CommandPathEntry", dialog )));
210
218
 
211
219
        g_string_append_printf (tmp_string, "%s ", command);
212
220
 
213
 
        gboolean is_file = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (nact_get_glade_widget_from ("OnlyFilesButton", 
214
 
                                                                                                                                                                                                                                GLADE_EDIT_DIALOG_WIDGET)));
215
 
        gboolean is_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (nact_get_glade_widget_from ("OnlyFoldersButton", 
216
 
                                                                                                                                                                                                                                GLADE_EDIT_DIALOG_WIDGET)));
217
 
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (nact_get_glade_widget_from ("BothButton", 
218
 
                                                                                                                                                                                        GLADE_EDIT_DIALOG_WIDGET))))
 
221
        gboolean is_file = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (nact_get_glade_widget_from ("OnlyFilesButton", dialog )));
 
222
        gboolean is_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (nact_get_glade_widget_from ("OnlyFoldersButton", dialog )));
 
223
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (nact_get_glade_widget_from ("BothButton", dialog ))))
219
224
        {
220
225
                is_file = TRUE;
221
226
                is_dir = TRUE;
222
227
        }
223
 
        gboolean accept_multiple = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (nact_get_glade_widget_from ("AcceptMultipleButton", 
224
 
                                                                                                                                                                                                                                                        GLADE_EDIT_DIALOG_WIDGET)));
225
 
        
226
 
        GtkTreeModel* scheme_model = gtk_tree_view_get_model (GTK_TREE_VIEW (nact_get_glade_widget_from ("SchemesTreeView", 
227
 
                                                                                                                                                                                                                                        GLADE_EDIT_DIALOG_WIDGET)));
 
228
        gboolean accept_multiple = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (nact_get_glade_widget_from ("AcceptMultipleButton", dialog )));
 
229
 
 
230
        GtkTreeModel* scheme_model = gtk_tree_view_get_model (GTK_TREE_VIEW (nact_get_glade_widget_from ("SchemesTreeView", dialog )));
228
231
        gtk_tree_model_foreach (scheme_model, (GtkTreeModelForeachFunc)nact_utils_get_action_schemes_list, &scheme_list);
229
232
 
230
233
        separator = g_strdup_printf (" %s/", ex_path);
265
268
        }
266
269
        g_free (start);
267
270
        g_free (separator);
268
 
        
 
271
 
269
272
        if (scheme_list != NULL)
270
273
        {
271
274
                ex_scheme = (gchar*)scheme_list->data;
291
294
                ex_scheme = ex_scheme_default;
292
295
                ex_host = "";
293
296
        }
294
 
        
 
297
 
295
298
        while ((iter = g_strstr_len (iter, strlen (iter), "%")))
296
299
        {
297
300
                tmp_string = g_string_append_len (tmp_string, old_iter, strlen (old_iter) - strlen (iter));
298
301
                switch (iter[1])
299
302
                {
300
 
                        case 'u': // gnome-vfs URI
 
303
                        case 'u': /* gnome-vfs URI */
301
304
                                tmp = g_strjoin (NULL, ex_scheme, "://", ex_path, "/", ex_one, NULL);
302
305
                                tmp_string = g_string_append (tmp_string, tmp);
303
306
                                g_free (tmp);
304
307
                                break;
305
 
                        case 'd': // base dir of the selected file(s)/folder(s)
 
308
                        case 'd': /* base dir of the selected file(s)/folder(s) */
306
309
                                tmp_string = g_string_append (tmp_string, ex_path);
307
310
                                break;
308
 
                        case 'f': // the basename of the selected file/folder or the 1st one if many are selected
 
311
                        case 'f': /* the basename of the selected file/folder or the 1st one if many are selected */
309
312
                                tmp_string = g_string_append (tmp_string, ex_one);
310
313
                                break;
311
 
                        case 'm': // list of the basename of the selected files/directories separated by space
 
314
                        case 'm': /* list of the basename of the selected files/directories separated by space */
312
315
                                tmp_string = g_string_append (tmp_string, ex_list);
313
316
                                break;
314
 
                        case 'M': // list of the selected files/directories with their complete path separated by space.
 
317
                        case 'M': /* list of the selected files/directories with their complete path separated by space. */
315
318
                                tmp_string = g_string_append (tmp_string, ex_path_list);
316
319
                                break;
317
 
                        case 's': // scheme of the gnome-vfs URI
 
320
                        case 's': /* scheme of the gnome-vfs URI */
318
321
                                tmp_string = g_string_append (tmp_string, ex_scheme);
319
322
                                break;
320
 
                        case 'h': // hostname of the gnome-vfs URI
 
323
                        case 'h': /* hostname of the gnome-vfs URI */
321
324
                                tmp_string = g_string_append (tmp_string, ex_host);
322
325
                                break;
323
 
                        case 'U': // username of the gnome-vfs URI
 
326
                        case 'U': /* username of the gnome-vfs URI */
324
327
                                tmp_string = g_string_append (tmp_string, "root");
325
328
                                break;
326
 
                        case '%': // a percent sign
 
329
                        case '%': /* a percent sign */
327
330
                                tmp_string = g_string_append_c (tmp_string, '%');
328
331
                                break;
329
332
                }
330
 
                iter+=2; // skip the % sign and the character after.
331
 
                old_iter = iter; // store the new start of the string
 
333
                iter+=2; /* skip the % sign and the character after. */
 
334
                old_iter = iter; /* store the new start of the string */
332
335
        }
333
336
        tmp_string = g_string_append_len (tmp_string, old_iter, strlen (old_iter));
334
 
        
 
337
 
335
338
        g_free (ex_list);
336
339
        g_free (ex_path_list);
337
340
        g_free (iter);
338
341
 
339
 
        retv = g_string_free (tmp_string, FALSE); // return the content of the GString
340
 
        
 
342
        retv = g_string_free (tmp_string, FALSE); /* return the content of the GString */
 
343
 
341
344
        return retv;
342
345
}
343
 
 
344
 
// vim:ts=3:sw=3:tw=1024:cin