File: | baul-sendto-command.c |
Warning: | line 671, column 3 Potential leak of memory pointed to by 'p' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ | |||
2 | ||||
3 | /* | |||
4 | * Copyright (C) 2004 Roberto Majadas | |||
5 | * | |||
6 | * This program is free software; you can redistribute it and/or | |||
7 | * modify it under the terms of the GNU General Public License as | |||
8 | * published by the Free Software Foundation; either version 2 of the | |||
9 | * License, or (at your option) any later version. | |||
10 | * | |||
11 | * This program is distributed in the hope that it will be useful, | |||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
14 | * General Public License for more av. | |||
15 | * | |||
16 | * You should have received a copy of the GNU General Public | |||
17 | * License along with this program; if not, write to the | |||
18 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |||
19 | * Boston, MA 02110-1301 USA. | |||
20 | * | |||
21 | * Author: Roberto Majadas <roberto.majadas@openshine.com> | |||
22 | */ | |||
23 | ||||
24 | #include "config.h" | |||
25 | #include <string.h> | |||
26 | #include <stdlib.h> | |||
27 | #include <glib/gi18n.h> | |||
28 | #include <glib/gstdio.h> | |||
29 | #include <ctk/ctk.h> | |||
30 | #include "baul-sendto-plugin.h" | |||
31 | ||||
32 | #define BAUL_SENDTO_LAST_MEDIUM"last-medium" "last-medium" | |||
33 | #define BAUL_SENDTO_LAST_COMPRESS"last-compress" "last-compress" | |||
34 | #define BAUL_SENDTO_STATUS_LABEL_TIMEOUT_SECONDS10 10 | |||
35 | ||||
36 | #define UNINSTALLED_PLUGINDIR"plugins/removable-devices" "plugins/removable-devices" | |||
37 | #define UNINSTALLED_SOURCE"baul-sendto-command.c" "baul-sendto-command.c" | |||
38 | ||||
39 | #define SOEXT("." "so") ("." G_MODULE_SUFFIX"so") | |||
40 | #define SOEXT_LEN(strlen (("." "so"))) (strlen (SOEXT("." "so"))) | |||
41 | ||||
42 | enum { | |||
43 | COLUMN_ICON, | |||
44 | COLUMN_DESCRIPTION, | |||
45 | NUM_COLUMNS, | |||
46 | }; | |||
47 | ||||
48 | /* Options */ | |||
49 | static char **filenames = NULL((void*)0); | |||
50 | ||||
51 | GList *file_list = NULL((void*)0); | |||
52 | gboolean has_dirs = FALSE(0); | |||
53 | GList *plugin_list = NULL((void*)0); | |||
54 | GHashTable *hash ; | |||
55 | guint option = 0; | |||
56 | ||||
57 | static GSettings *settings = NULL((void*)0); | |||
58 | ||||
59 | typedef struct _NS_ui NS_ui; | |||
60 | ||||
61 | struct _NS_ui { | |||
62 | CtkWidget *dialog; | |||
63 | CtkWidget *options_combobox; | |||
64 | CtkWidget *send_to_label; | |||
65 | CtkWidget *hbox_contacts_ws; | |||
66 | CtkWidget *cancel_button; | |||
67 | CtkWidget *send_button; | |||
68 | CtkWidget *pack_combobox; | |||
69 | CtkWidget *pack_checkbutton; | |||
70 | CtkWidget *pack_entry; | |||
71 | GList *contact_widgets; | |||
72 | ||||
73 | CtkWidget *status_box; | |||
74 | CtkWidget *status_image; | |||
75 | CtkWidget *status_label; | |||
76 | guint status_timeoutid; | |||
77 | }; | |||
78 | ||||
79 | static const GOptionEntry entries[] = { | |||
80 | { G_OPTION_REMAINING"", '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, "Files to send", "[FILES...]" }, | |||
81 | { NULL((void*)0) } | |||
82 | }; | |||
83 | ||||
84 | static void | |||
85 | destroy_dialog (CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
86 | gpointer data G_GNUC_UNUSED__attribute__ ((__unused__))) | |||
87 | { | |||
88 | ctk_main_quit (); | |||
89 | } | |||
90 | ||||
91 | static char * | |||
92 | get_filename_from_list (void) | |||
93 | { | |||
94 | GList *l; | |||
95 | GString *common_part = NULL((void*)0); | |||
96 | gboolean matches = TRUE(!(0)); | |||
97 | guint offset = 0; | |||
98 | const char *encoding; | |||
99 | gboolean use_utf8 = TRUE(!(0)); | |||
100 | ||||
101 | encoding = g_getenv ("G_FILENAME_ENCODING"); | |||
102 | ||||
103 | if (encoding != NULL((void*)0) && strcasecmp(encoding, "UTF-8") != 0) | |||
104 | use_utf8 = FALSE(0); | |||
105 | ||||
106 | if (file_list == NULL((void*)0)) | |||
107 | return NULL((void*)0); | |||
108 | ||||
109 | common_part = g_string_new(""); | |||
110 | ||||
111 | while (TRUE(!(0))) { | |||
112 | gunichar cur_char = '\0'; | |||
113 | for (l = file_list; l ; l = l->next) { | |||
114 | char *path = NULL((void*)0), *name = NULL((void*)0); | |||
115 | char *offset_name = NULL((void*)0); | |||
116 | ||||
117 | path = g_filename_from_uri ((char *) l->data, | |||
118 | NULL((void*)0), NULL((void*)0)); | |||
119 | if (!path) | |||
120 | break; | |||
121 | ||||
122 | name = g_path_get_basename (path); | |||
123 | ||||
124 | if (!use_utf8) { | |||
125 | char *tmp; | |||
126 | ||||
127 | tmp = g_filename_to_utf8 (name, -1, | |||
128 | NULL((void*)0), NULL((void*)0), NULL((void*)0)); | |||
129 | g_free (name); | |||
130 | name = tmp; | |||
131 | } | |||
132 | ||||
133 | if (!name) { | |||
134 | g_free (path); | |||
135 | break; | |||
136 | } | |||
137 | ||||
138 | if (offset >= g_utf8_strlen (name, -1)) { | |||
139 | g_free(name); | |||
140 | g_free(path); | |||
141 | matches = FALSE(0); | |||
142 | break; | |||
143 | } | |||
144 | ||||
145 | offset_name = g_utf8_offset_to_pointer (name, offset); | |||
146 | ||||
147 | if (offset_name == g_utf8_strrchr (name, -1, '.')) { | |||
148 | g_free (name); | |||
149 | g_free (path); | |||
150 | matches = FALSE(0); | |||
151 | break; | |||
152 | } | |||
153 | if (cur_char == '\0') { | |||
154 | cur_char = g_utf8_get_char (offset_name); | |||
155 | } else if (cur_char != g_utf8_get_char (offset_name)) { | |||
156 | g_free (name); | |||
157 | g_free (path); | |||
158 | matches = FALSE(0); | |||
159 | break; | |||
160 | } | |||
161 | g_free (name); | |||
162 | g_free (path); | |||
163 | } | |||
164 | if (matches == TRUE(!(0)) && cur_char != '\0') { | |||
165 | offset++; | |||
166 | common_part = g_string_append_unichar (common_part, | |||
167 | cur_char); | |||
168 | } else { | |||
169 | break; | |||
170 | } | |||
171 | } | |||
172 | ||||
173 | if (g_utf8_strlen (common_part->str, -1) < 4) { | |||
174 | g_string_free (common_part, TRUE)(__builtin_constant_p ((!(0))) ? (((!(0))) ? (g_string_free) ( (common_part), ((!(0)))) : g_string_free_and_steal (common_part )) : (g_string_free) ((common_part), ((!(0))))); | |||
175 | return NULL((void*)0); | |||
176 | } | |||
177 | ||||
178 | return g_string_free (common_part, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((common_part ), ((0))) : g_string_free_and_steal (common_part)) : (g_string_free ) ((common_part), ((0)))); | |||
179 | } | |||
180 | ||||
181 | static char * | |||
182 | pack_files (NS_ui *ui) | |||
183 | { | |||
184 | char *grapa_cmd; | |||
185 | const char *filename; | |||
186 | GList *l; | |||
187 | GString *cmd, *tmp; | |||
188 | char *pack_type, *tmp_dir, *tmp_work_dir, *packed_file; | |||
189 | ||||
190 | grapa_cmd = g_find_program_in_path ("grapa"); | |||
191 | filename = ctk_entry_get_text(CTK_ENTRY(ui->pack_entry)((((CtkEntry*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->pack_entry)), ((ctk_entry_get_type ()))))))); | |||
192 | ||||
193 | g_assert (filename != NULL && *filename != '\0')do { if (filename != ((void*)0) && *filename != '\0') ; else g_assertion_message_expr (((gchar*) 0), "baul-sendto-command.c" , 193, ((const char*) (__func__)), "filename != NULL && *filename != '\\0'" ); } while (0); | |||
194 | ||||
195 | tmp_dir = g_strdup_printf ("%s/baul-sendto-%s", | |||
196 | g_get_tmp_dir(), g_get_user_name()); | |||
197 | g_mkdirmkdir (tmp_dir, 0700); | |||
198 | tmp_work_dir = g_strdup_printf ("%s/baul-sendto-%s/%li", | |||
199 | g_get_tmp_dir(), g_get_user_name(), | |||
200 | time(NULL((void*)0))); | |||
201 | g_mkdirmkdir (tmp_work_dir, 0700); | |||
202 | g_free (tmp_dir); | |||
203 | ||||
204 | if (ctk_combo_box_get_active (CTK_COMBO_BOX(ui->pack_combobox)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->pack_combobox)), ((ctk_combo_box_get_type ()))))) )) != 0) { | |||
205 | pack_type = ctk_combo_box_text_get_active_text (CTK_COMBO_BOX_TEXT(ui->pack_combobox)((((CtkComboBoxText*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->pack_combobox)), ((ctk_combo_box_text_get_type () ))))))); | |||
206 | } else { | |||
207 | pack_type = NULL((void*)0); | |||
208 | g_assert_not_reached ()do { g_assertion_message_expr (((gchar*) 0), "baul-sendto-command.c" , 208, ((const char*) (__func__)), ((void*)0)); } while (0); | |||
209 | } | |||
210 | ||||
211 | g_settings_set_int (settings, | |||
212 | BAUL_SENDTO_LAST_COMPRESS"last-compress", | |||
213 | ctk_combo_box_get_active(CTK_COMBO_BOX(ui->pack_combobox)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->pack_combobox)), ((ctk_combo_box_get_type ()))))) ))); | |||
214 | ||||
215 | cmd = g_string_new (""); | |||
216 | g_string_printf (cmd, "%s --add-to=\"%s/%s%s\"", | |||
217 | grapa_cmd, tmp_work_dir, | |||
218 | filename, | |||
219 | pack_type); | |||
220 | g_free (grapa_cmd); | |||
221 | ||||
222 | /* grapa doesn't understand URIs */ | |||
223 | for (l = file_list ; l; l=l->next){ | |||
224 | char *file; | |||
225 | ||||
226 | file = g_filename_from_uri (l->data, NULL((void*)0), NULL((void*)0)); | |||
227 | g_string_append_printf (cmd," \"%s\"", file); | |||
228 | g_free (file); | |||
229 | } | |||
230 | ||||
231 | g_spawn_command_line_sync (cmd->str, NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0)); | |||
232 | g_string_free (cmd, TRUE)(__builtin_constant_p ((!(0))) ? (((!(0))) ? (g_string_free) ( (cmd), ((!(0)))) : g_string_free_and_steal (cmd)) : (g_string_free ) ((cmd), ((!(0))))); | |||
233 | tmp = g_string_new(""); | |||
234 | g_string_printf (tmp,"%s/%s%s", tmp_work_dir, | |||
235 | filename, | |||
236 | pack_type); | |||
237 | g_free (pack_type); | |||
238 | g_free (tmp_work_dir); | |||
239 | packed_file = g_filename_to_uri (tmp->str, NULL((void*)0), NULL((void*)0)); | |||
240 | g_string_free(tmp, TRUE)(__builtin_constant_p ((!(0))) ? (((!(0))) ? (g_string_free) ( (tmp), ((!(0)))) : g_string_free_and_steal (tmp)) : (g_string_free ) ((tmp), ((!(0))))); | |||
241 | return packed_file; | |||
242 | } | |||
243 | ||||
244 | static gboolean | |||
245 | status_label_clear (gpointer data) | |||
246 | { | |||
247 | NS_ui *ui = (NS_ui *) data; | |||
248 | ctk_label_set_label (CTK_LABEL (ui->status_label)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->status_label)), ((ctk_label_get_type ())))))), ""); | |||
249 | ctk_widget_hide (ui->status_image); | |||
250 | ||||
251 | ui->status_timeoutid = 0; | |||
252 | ||||
253 | return FALSE(0); | |||
254 | } | |||
255 | ||||
256 | static void | |||
257 | send_button_cb (CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
258 | NS_ui *ui) | |||
259 | { | |||
260 | char *error; | |||
261 | NstPlugin *p; | |||
262 | CtkWidget *w; | |||
263 | ||||
264 | ctk_widget_set_sensitive (ui->dialog, FALSE(0)); | |||
265 | ||||
266 | p = (NstPlugin *) g_list_nth_data (plugin_list, option); | |||
267 | w = (CtkWidget *) g_list_nth_data (ui->contact_widgets, option); | |||
268 | ||||
269 | if (ui->status_timeoutid != 0) { | |||
270 | g_source_remove (ui->status_timeoutid); | |||
271 | status_label_clear (ui); | |||
272 | } | |||
273 | ||||
274 | if (p == NULL((void*)0)) | |||
275 | return; | |||
276 | ||||
277 | if (p->info->validate_destination != NULL((void*)0)) { | |||
278 | error = NULL((void*)0); | |||
279 | if (p->info->validate_destination (p, w, &error) == FALSE(0)) { | |||
280 | char *message; | |||
281 | ||||
282 | message = g_strdup_printf ("<b>%s</b>", error); | |||
283 | g_free (error); | |||
284 | ctk_label_set_markup (CTK_LABEL (ui->status_label)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->status_label)), ((ctk_label_get_type ())))))), message); | |||
285 | g_free (message); | |||
286 | ui->status_timeoutid = g_timeout_add_seconds (BAUL_SENDTO_STATUS_LABEL_TIMEOUT_SECONDS10, | |||
287 | status_label_clear, | |||
288 | ui); | |||
289 | ctk_widget_show (ui->status_image); | |||
290 | ctk_widget_show (ui->status_box); | |||
291 | ctk_widget_set_sensitive (ui->dialog, TRUE(!(0))); | |||
292 | return; | |||
293 | } | |||
294 | } | |||
295 | ||||
296 | g_settings_set_string (settings, | |||
297 | BAUL_SENDTO_LAST_MEDIUM"last-medium", | |||
298 | p->info->id); | |||
299 | ||||
300 | if (ctk_toggle_button_get_active(CTK_TOGGLE_BUTTON(ui->pack_checkbutton)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->pack_checkbutton)), ((ctk_toggle_button_get_type ( ))))))))){ | |||
301 | char *f; | |||
302 | ||||
303 | f = pack_files (ui); | |||
304 | if (f != NULL((void*)0)) { | |||
305 | GList *packed_file = NULL((void*)0); | |||
306 | packed_file = g_list_append (packed_file, f); | |||
307 | if (!p->info->send_files (p, w, packed_file)) { | |||
308 | g_free (f); | |||
309 | g_list_free (packed_file); | |||
310 | return; | |||
311 | } | |||
312 | g_list_free (packed_file); | |||
313 | } else { | |||
314 | ctk_widget_set_sensitive (ui->dialog, TRUE(!(0))); | |||
315 | return; | |||
316 | } | |||
317 | g_free (f); | |||
318 | } else { | |||
319 | if (!p->info->send_files (p, w, file_list)) { | |||
320 | g_list_foreach (file_list, (GFunc) g_free, NULL((void*)0)); | |||
321 | g_list_free (file_list); | |||
322 | file_list = NULL((void*)0); | |||
323 | return; | |||
324 | } | |||
325 | g_list_free (file_list); | |||
326 | file_list = NULL((void*)0); | |||
327 | } | |||
328 | destroy_dialog (NULL((void*)0),NULL((void*)0)); | |||
329 | } | |||
330 | ||||
331 | static void | |||
332 | send_if_no_pack_cb (CtkWidget *widget, NS_ui *ui) | |||
333 | { | |||
334 | if (ctk_toggle_button_get_active (CTK_TOGGLE_BUTTON (ui->pack_checkbutton)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->pack_checkbutton)), ((ctk_toggle_button_get_type ( ))))))))) { | |||
335 | if (ctk_widget_is_sensitive (ui->pack_entry)) { | |||
336 | ctk_widget_grab_focus (ui->pack_entry); | |||
337 | } else { | |||
338 | ctk_widget_grab_focus (ui->pack_checkbutton); | |||
339 | } | |||
340 | } else { | |||
341 | send_button_cb (widget, ui); | |||
342 | } | |||
343 | } | |||
344 | ||||
345 | static void | |||
346 | toggle_pack_check (CtkWidget *widget, NS_ui *ui) | |||
347 | { | |||
348 | CtkToggleButton *t = CTK_TOGGLE_BUTTON (widget)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_toggle_button_get_type ())))))); | |||
349 | gboolean enabled, send_enabled; | |||
350 | ||||
351 | enabled = ctk_toggle_button_get_active (CTK_TOGGLE_BUTTON (t)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((t)), ((ctk_toggle_button_get_type ()))))))); | |||
352 | ctk_widget_set_sensitive (ui->pack_combobox, enabled); | |||
353 | ctk_widget_set_sensitive (ui->pack_entry, enabled); | |||
354 | ||||
355 | send_enabled = TRUE(!(0)); | |||
356 | ||||
357 | if (enabled) { | |||
358 | const char *filename; | |||
359 | ||||
360 | filename = ctk_entry_get_text(CTK_ENTRY(ui->pack_entry)((((CtkEntry*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->pack_entry)), ((ctk_entry_get_type ()))))))); | |||
361 | if (filename == NULL((void*)0) || *filename == '\0') | |||
362 | send_enabled = FALSE(0); | |||
363 | } | |||
364 | ||||
365 | ctk_widget_set_sensitive (ui->send_button, send_enabled); | |||
366 | } | |||
367 | ||||
368 | static void | |||
369 | option_changed (CtkComboBox *cb, NS_ui *ui) | |||
370 | { | |||
371 | CtkWidget *w; | |||
372 | NstPlugin *p; | |||
373 | gboolean supports_dirs = FALSE(0); | |||
374 | ||||
375 | w = g_list_nth_data (ui->contact_widgets, option); | |||
376 | option = ctk_combo_box_get_active (CTK_COMBO_BOX(cb)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((cb)), ((ctk_combo_box_get_type ()))))))); | |||
377 | ctk_widget_hide (w); | |||
378 | w = g_list_nth_data (ui->contact_widgets, option); | |||
379 | ctk_widget_show (w); | |||
380 | ||||
381 | ctk_label_set_mnemonic_widget (CTK_LABEL (ui->send_to_label)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->send_to_label)), ((ctk_label_get_type ())))))), w); | |||
382 | ||||
383 | p = (NstPlugin *) g_list_nth_data (plugin_list, option); | |||
384 | supports_dirs = (p->info->capabilities & BAUL_CAPS_SEND_DIRECTORIES); | |||
385 | ||||
386 | if (has_dirs == FALSE(0) || supports_dirs != FALSE(0)) { | |||
387 | gboolean toggle; | |||
388 | ||||
389 | toggle = ctk_toggle_button_get_active (CTK_TOGGLE_BUTTON (ui->pack_checkbutton)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->pack_checkbutton)), ((ctk_toggle_button_get_type ( )))))))); | |||
390 | ctk_widget_set_sensitive (ui->pack_combobox, toggle); | |||
391 | ctk_widget_set_sensitive (ui->pack_entry, toggle); | |||
392 | ctk_widget_set_sensitive (ui->pack_checkbutton, TRUE(!(0))); | |||
393 | } else { | |||
394 | ctk_toggle_button_set_active (CTK_TOGGLE_BUTTON (ui->pack_checkbutton)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->pack_checkbutton)), ((ctk_toggle_button_get_type ( ))))))), TRUE(!(0))); | |||
395 | ctk_widget_set_sensitive (ui->pack_checkbutton, FALSE(0)); | |||
396 | } | |||
397 | } | |||
398 | ||||
399 | static void | |||
400 | set_contact_widgets (NS_ui *ui) | |||
401 | { | |||
402 | GList *aux ; | |||
403 | CtkWidget *w; | |||
404 | NstPlugin *p; | |||
405 | ||||
406 | ui->contact_widgets = NULL((void*)0); | |||
407 | ||||
408 | for (aux = plugin_list; aux; aux = aux->next){ | |||
409 | p = (NstPlugin *) aux->data; | |||
410 | w = p->info->get_contacts_widget(p); | |||
411 | ctk_box_pack_end (CTK_BOX(ui->hbox_contacts_ws)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->hbox_contacts_ws)), ((ctk_box_get_type ())))))),w, TRUE(!(0)), TRUE(!(0)), 0); | |||
412 | ctk_widget_hide (CTK_WIDGET(w)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((w)), ((ctk_widget_get_type ()))))))); | |||
413 | ui->contact_widgets = g_list_append (ui->contact_widgets, w); | |||
414 | if (CTK_IS_ENTRY (w)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (w)); GType __t = ((ctk_entry_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst ->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) { | |||
415 | g_signal_connect_after (G_OBJECT (w), "activate",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((w)), (((GType) ((20) << (2)))))))) ), ("activate"), (((GCallback) (send_if_no_pack_cb))), (ui), ( (void*)0), G_CONNECT_AFTER) | |||
416 | G_CALLBACK (send_if_no_pack_cb), ui)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((w)), (((GType) ((20) << (2)))))))) ), ("activate"), (((GCallback) (send_if_no_pack_cb))), (ui), ( (void*)0), G_CONNECT_AFTER); | |||
417 | } | |||
418 | } | |||
419 | } | |||
420 | ||||
421 | static gboolean | |||
422 | set_model_for_options_combobox (NS_ui *ui) | |||
423 | { | |||
424 | GdkPixbuf *pixbuf; | |||
425 | CtkTreeIter iter; | |||
426 | CtkListStore *model; | |||
427 | CtkIconTheme *it; | |||
428 | CtkCellRenderer *renderer; | |||
429 | CtkWidget *widget; | |||
430 | GList *aux; | |||
431 | NstPlugin *p; | |||
432 | char *last_used = NULL((void*)0); | |||
433 | int i = 0; | |||
434 | gboolean last_used_support_dirs = FALSE(0); | |||
435 | ||||
436 | it = ctk_icon_theme_get_default (); | |||
437 | ||||
438 | model = ctk_list_store_new (NUM_COLUMNS, GDK_TYPE_PIXBUF(gdk_pixbuf_get_type ()), G_TYPE_STRING((GType) ((16) << (2)))); | |||
439 | ||||
440 | last_used = g_settings_get_string (settings, | |||
441 | BAUL_SENDTO_LAST_MEDIUM"last-medium"); | |||
442 | ||||
443 | for (aux = plugin_list; aux; aux = aux->next) { | |||
444 | p = (NstPlugin *) aux->data; | |||
445 | pixbuf = ctk_icon_theme_load_icon (it, p->info->icon, 16, | |||
446 | CTK_ICON_LOOKUP_USE_BUILTIN, NULL((void*)0)); | |||
447 | ctk_list_store_append (model, &iter); | |||
448 | ctk_list_store_set (model, &iter, | |||
449 | COLUMN_ICON, pixbuf, | |||
450 | COLUMN_DESCRIPTION, dgettext(p->info->gettext_package, p->info->description), | |||
451 | -1); | |||
452 | if (last_used != NULL((void*)0) && !strcmp(last_used, p->info->id)) { | |||
453 | option = i; | |||
454 | last_used_support_dirs = (p->info->capabilities & BAUL_CAPS_SEND_DIRECTORIES); | |||
455 | } | |||
456 | i++; | |||
457 | } | |||
458 | g_free(last_used); | |||
459 | ||||
460 | ctk_combo_box_set_model (CTK_COMBO_BOX(ui->options_combobox)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->options_combobox)), ((ctk_combo_box_get_type ())) )))), | |||
461 | CTK_TREE_MODEL (model)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((ctk_tree_model_get_type ()))))))); | |||
462 | renderer = ctk_cell_renderer_pixbuf_new (); | |||
463 | ctk_cell_layout_pack_start (CTK_CELL_LAYOUT (ui->options_combobox)((((CtkCellLayout*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->options_combobox)), ((ctk_cell_layout_get_type () )))))), | |||
464 | renderer, | |||
465 | FALSE(0)); | |||
466 | ctk_cell_layout_set_attributes (CTK_CELL_LAYOUT (ui->options_combobox)((((CtkCellLayout*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->options_combobox)), ((ctk_cell_layout_get_type () )))))), | |||
467 | renderer, | |||
468 | "pixbuf", COLUMN_ICON, | |||
469 | NULL((void*)0)); | |||
470 | renderer = ctk_cell_renderer_text_new (); | |||
471 | g_object_set (G_OBJECT (renderer)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((renderer)), (((GType) ((20) << (2)))))))), "ellipsize", PANGO_ELLIPSIZE_END, NULL((void*)0)); | |||
472 | ctk_cell_layout_pack_start (CTK_CELL_LAYOUT (ui->options_combobox)((((CtkCellLayout*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->options_combobox)), ((ctk_cell_layout_get_type () )))))), | |||
473 | renderer, | |||
474 | TRUE(!(0))); | |||
475 | ctk_cell_layout_set_attributes (CTK_CELL_LAYOUT (ui->options_combobox)((((CtkCellLayout*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->options_combobox)), ((ctk_cell_layout_get_type () )))))), | |||
476 | renderer, | |||
477 | "text", COLUMN_DESCRIPTION, | |||
478 | NULL((void*)0)); | |||
479 | ||||
480 | g_signal_connect (G_OBJECT (ui->options_combobox), "changed",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((ui->options_combobox)), (((GType) ((20 ) << (2))))))))), ("changed"), (((GCallback) (option_changed ))), (ui), ((void*)0), (GConnectFlags) 0) | |||
481 | G_CALLBACK (option_changed), ui)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((ui->options_combobox)), (((GType) ((20 ) << (2))))))))), ("changed"), (((GCallback) (option_changed ))), (ui), ((void*)0), (GConnectFlags) 0); | |||
482 | ||||
483 | ctk_combo_box_set_active (CTK_COMBO_BOX (ui->options_combobox)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->options_combobox)), ((ctk_combo_box_get_type ())) )))), option); | |||
484 | ||||
485 | /* Grab the focus for the most recently used widget */ | |||
486 | widget = g_list_nth_data (ui->contact_widgets, option); | |||
487 | ctk_widget_grab_focus (widget); | |||
488 | ||||
489 | return last_used_support_dirs; | |||
490 | } | |||
491 | ||||
492 | static void | |||
493 | pack_entry_changed_cb (GObject *object G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
494 | GParamSpec *spec G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
495 | NS_ui *ui) | |||
496 | { | |||
497 | gboolean send_enabled; | |||
498 | ||||
499 | send_enabled = TRUE(!(0)); | |||
500 | ||||
501 | if (ctk_toggle_button_get_active (CTK_TOGGLE_BUTTON (ui->pack_checkbutton)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->pack_checkbutton)), ((ctk_toggle_button_get_type ( ))))))))) { | |||
502 | const char *filename; | |||
503 | ||||
504 | filename = ctk_entry_get_text(CTK_ENTRY(ui->pack_entry)((((CtkEntry*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->pack_entry)), ((ctk_entry_get_type ()))))))); | |||
505 | if (filename == NULL((void*)0) || *filename == '\0') | |||
506 | send_enabled = FALSE(0); | |||
507 | } | |||
508 | ||||
509 | ctk_widget_set_sensitive (ui->send_button, send_enabled); | |||
510 | } | |||
511 | ||||
512 | static void | |||
513 | update_button_image (CtkSettings *settings, | |||
514 | GParamSpec *spec G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
515 | CtkWidget *widget) | |||
516 | { | |||
517 | gboolean show_images; | |||
518 | ||||
519 | g_object_get (settings, "ctk-button-images", &show_images, NULL((void*)0)); | |||
520 | if (show_images == FALSE(0)) | |||
521 | ctk_widget_hide (widget); | |||
522 | else | |||
523 | ctk_widget_show (widget); | |||
524 | } | |||
525 | ||||
526 | static void | |||
527 | baul_sendto_create_ui (void) | |||
528 | { | |||
529 | CtkBuilder *app; | |||
530 | GError* error = NULL((void*)0); | |||
531 | NS_ui *ui; | |||
532 | gboolean one_file = FALSE(0); | |||
533 | gboolean supports_dirs; | |||
534 | CtkSettings *ctk_settings; | |||
535 | CtkWidget *button_image; | |||
536 | ||||
537 | app = ctk_builder_new (); | |||
538 | if (ctk_builder_add_from_resource (app, "/org/cafe/baul/extensions/sendto/baul-sendto.ui", &error) == 0) { | |||
539 | g_warning ("Could not parse UI definition: %s", error->message); | |||
540 | g_error_free (error); | |||
541 | } | |||
542 | ||||
543 | ui = g_new0 (NS_ui, 1)((NS_ui *) g_malloc0_n ((1), sizeof (NS_ui))); | |||
544 | ||||
545 | ui->hbox_contacts_ws = CTK_WIDGET (ctk_builder_get_object (app, "hbox_contacts_widgets"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object (app, "hbox_contacts_widgets"))), ((ctk_widget_get_type ())))))); | |||
546 | ui->send_to_label = CTK_WIDGET (ctk_builder_get_object (app, "send_to_label"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object (app, "send_to_label"))), ((ctk_widget_get_type ())))))); | |||
547 | ui->options_combobox = CTK_WIDGET (ctk_builder_get_object (app, "options_combobox"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object (app, "options_combobox"))), ((ctk_widget_get_type ())))))); | |||
548 | ui->dialog = CTK_WIDGET (ctk_builder_get_object (app, "baul_sendto_dialog"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object (app, "baul_sendto_dialog"))), (( ctk_widget_get_type ())))))); | |||
549 | ui->cancel_button = CTK_WIDGET (ctk_builder_get_object (app, "cancel_button"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object (app, "cancel_button"))), ((ctk_widget_get_type ())))))); | |||
550 | ui->send_button = CTK_WIDGET (ctk_builder_get_object (app, "send_button"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object (app, "send_button"))), ((ctk_widget_get_type ())))))); | |||
551 | ui->pack_combobox = CTK_WIDGET (ctk_builder_get_object (app, "pack_combobox"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object (app, "pack_combobox"))), ((ctk_widget_get_type ())))))); | |||
552 | ui->pack_entry = CTK_WIDGET (ctk_builder_get_object (app, "pack_entry"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object (app, "pack_entry"))), ((ctk_widget_get_type ())))))); | |||
553 | ui->pack_checkbutton = CTK_WIDGET (ctk_builder_get_object (app, "pack_checkbutton"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object (app, "pack_checkbutton"))), ((ctk_widget_get_type ())))))); | |||
554 | ui->status_box = CTK_WIDGET (ctk_builder_get_object (app, "status_box"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object (app, "status_box"))), ((ctk_widget_get_type ())))))); | |||
555 | ui->status_label = CTK_WIDGET (ctk_builder_get_object (app, "status_label"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object (app, "status_label"))), ((ctk_widget_get_type ())))))); | |||
556 | ui->status_image = CTK_WIDGET (ctk_builder_get_object (app, "status_image"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object (app, "status_image"))), ((ctk_widget_get_type ())))))); | |||
557 | ||||
558 | ctk_settings = ctk_settings_get_default (); | |||
559 | button_image = CTK_WIDGET (ctk_builder_get_object (app, "image1"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object (app, "image1"))), ((ctk_widget_get_type ())))))); | |||
560 | g_signal_connect (G_OBJECT (ctk_settings), "notify::ctk-button-images",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((ctk_settings)), (((GType) ((20) << (2))))))))), ("notify::ctk-button-images"), (((GCallback) (update_button_image ))), (button_image), ((void*)0), (GConnectFlags) 0) | |||
561 | G_CALLBACK (update_button_image), button_image)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((ctk_settings)), (((GType) ((20) << (2))))))))), ("notify::ctk-button-images"), (((GCallback) (update_button_image ))), (button_image), ((void*)0), (GConnectFlags) 0); | |||
562 | update_button_image (ctk_settings, NULL((void*)0), button_image); | |||
563 | ||||
564 | ctk_combo_box_set_active (CTK_COMBO_BOX(ui->pack_combobox)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->pack_combobox)), ((ctk_combo_box_get_type ()))))) ), | |||
565 | g_settings_get_int (settings, | |||
566 | BAUL_SENDTO_LAST_COMPRESS"last-compress")); | |||
567 | ||||
568 | if (file_list != NULL((void*)0) && file_list->next != NULL((void*)0)) | |||
569 | one_file = FALSE(0); | |||
570 | else if (file_list != NULL((void*)0)) | |||
571 | one_file = TRUE(!(0)); | |||
572 | ||||
573 | ctk_entry_set_text (CTK_ENTRY (ui->pack_entry)((((CtkEntry*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->pack_entry)), ((ctk_entry_get_type ())))))), _("Files")gettext ("Files")); | |||
574 | ||||
575 | if (one_file) { | |||
576 | char *filepath = NULL((void*)0), *filename = NULL((void*)0); | |||
577 | ||||
578 | filepath = g_filename_from_uri ((char *)file_list->data, | |||
579 | NULL((void*)0), NULL((void*)0)); | |||
580 | ||||
581 | if (filepath != NULL((void*)0)) | |||
582 | filename = g_path_get_basename (filepath); | |||
583 | if (filename != NULL((void*)0) && filename[0] != '\0') | |||
584 | ctk_entry_set_text (CTK_ENTRY (ui->pack_entry)((((CtkEntry*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->pack_entry)), ((ctk_entry_get_type ())))))), filename); | |||
585 | ||||
586 | g_free (filename); | |||
587 | g_free (filepath); | |||
588 | } else { | |||
589 | char *filename = get_filename_from_list (); | |||
590 | if (filename != NULL((void*)0) && filename[0] != '\0') { | |||
591 | ctk_entry_set_text (CTK_ENTRY (ui->pack_entry)((((CtkEntry*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->pack_entry)), ((ctk_entry_get_type ())))))), | |||
592 | filename); | |||
593 | } | |||
594 | g_free (filename); | |||
595 | } | |||
596 | ||||
597 | set_contact_widgets (ui); | |||
598 | supports_dirs = set_model_for_options_combobox (ui); | |||
599 | g_signal_connect (G_OBJECT (ui->dialog), "destroy",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((ui->dialog)), (((GType) ((20) << (2))))))))), ("destroy"), (((GCallback) (destroy_dialog))), ( ((void*)0)), ((void*)0), (GConnectFlags) 0) | |||
600 | G_CALLBACK (destroy_dialog), NULL)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((ui->dialog)), (((GType) ((20) << (2))))))))), ("destroy"), (((GCallback) (destroy_dialog))), ( ((void*)0)), ((void*)0), (GConnectFlags) 0); | |||
601 | g_signal_connect (G_OBJECT (ui->cancel_button), "clicked",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((ui->cancel_button)), (((GType) ((20) << (2))))))))), ("clicked"), (((GCallback) (destroy_dialog))), ( ((void*)0)), ((void*)0), (GConnectFlags) 0) | |||
602 | G_CALLBACK (destroy_dialog), NULL)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((ui->cancel_button)), (((GType) ((20) << (2))))))))), ("clicked"), (((GCallback) (destroy_dialog))), ( ((void*)0)), ((void*)0), (GConnectFlags) 0); | |||
603 | g_signal_connect (G_OBJECT (ui->send_button), "clicked",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((ui->send_button)), (((GType) ((20) << (2))))))))), ("clicked"), (((GCallback) (send_button_cb))), ( ui), ((void*)0), (GConnectFlags) 0) | |||
604 | G_CALLBACK (send_button_cb), ui)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((ui->send_button)), (((GType) ((20) << (2))))))))), ("clicked"), (((GCallback) (send_button_cb))), ( ui), ((void*)0), (GConnectFlags) 0); | |||
605 | g_signal_connect (G_OBJECT (ui->pack_entry), "activate",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((ui->pack_entry)), (((GType) ((20) << (2))))))))), ("activate"), (((GCallback) (send_button_cb))), (ui), ((void*)0), (GConnectFlags) 0) | |||
606 | G_CALLBACK (send_button_cb), ui)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((ui->pack_entry)), (((GType) ((20) << (2))))))))), ("activate"), (((GCallback) (send_button_cb))), (ui), ((void*)0), (GConnectFlags) 0); | |||
607 | g_signal_connect (G_OBJECT (ui->pack_entry), "notify::text",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((ui->pack_entry)), (((GType) ((20) << (2))))))))), ("notify::text"), (((GCallback) (pack_entry_changed_cb ))), (ui), ((void*)0), (GConnectFlags) 0) | |||
608 | G_CALLBACK (pack_entry_changed_cb), ui)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((ui->pack_entry)), (((GType) ((20) << (2))))))))), ("notify::text"), (((GCallback) (pack_entry_changed_cb ))), (ui), ((void*)0), (GConnectFlags) 0); | |||
609 | g_signal_connect (G_OBJECT (ui->pack_checkbutton), "toggled",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((ui->pack_checkbutton)), (((GType) ((20 ) << (2))))))))), ("toggled"), (((GCallback) (toggle_pack_check ))), (ui), ((void*)0), (GConnectFlags) 0) | |||
610 | G_CALLBACK (toggle_pack_check), ui)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((ui->pack_checkbutton)), (((GType) ((20 ) << (2))))))))), ("toggled"), (((GCallback) (toggle_pack_check ))), (ui), ((void*)0), (GConnectFlags) 0); | |||
611 | ||||
612 | if (has_dirs == FALSE(0) || supports_dirs != FALSE(0)) { | |||
613 | gboolean toggle; | |||
614 | ||||
615 | toggle = ctk_toggle_button_get_active (CTK_TOGGLE_BUTTON (ui->pack_checkbutton)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->pack_checkbutton)), ((ctk_toggle_button_get_type ( )))))))); | |||
616 | ctk_widget_set_sensitive (ui->pack_combobox, toggle); | |||
617 | ctk_widget_set_sensitive (ui->pack_entry, toggle); | |||
618 | } else { | |||
619 | ctk_toggle_button_set_active (CTK_TOGGLE_BUTTON (ui->pack_checkbutton)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ui->pack_checkbutton)), ((ctk_toggle_button_get_type ( ))))))), TRUE(!(0))); | |||
620 | ctk_widget_set_sensitive (ui->pack_checkbutton, FALSE(0)); | |||
621 | } | |||
622 | ||||
623 | ctk_widget_show (ui->dialog); | |||
624 | ||||
625 | } | |||
626 | ||||
627 | static void | |||
628 | baul_sendto_plugin_dir_process (const char *plugindir) | |||
629 | { | |||
630 | GDir *dir; | |||
631 | const char *item; | |||
632 | NstPlugin *p = NULL((void*)0); | |||
633 | gboolean (*nst_init_plugin)(NstPlugin *p); | |||
634 | GError *err = NULL((void*)0); | |||
635 | ||||
636 | dir = g_dir_open (plugindir, 0, &err); | |||
637 | ||||
638 | if (dir == NULL((void*)0)) { | |||
639 | g_warning ("Can't open the plugins dir: %s", err ? err->message : "No reason"); | |||
640 | if (err) | |||
641 | g_error_free (err); | |||
642 | } else { | |||
643 | while ((item = g_dir_read_name(dir))) { | |||
644 | if (g_str_has_suffix (item, SOEXT)(__builtin_constant_p (("." "so"))? __extension__ ({ const char * const __str = (item); const char * const __suffix = (("." "so" )); gboolean __result = (0); if (__str == ((void*)0) || __suffix == ((void*)0)) __result = (g_str_has_suffix) (__str, __suffix ); else { const size_t __str_len = strlen (((__str) + !(__str ))); const size_t __suffix_len = strlen (((__suffix) + !(__suffix ))); if (__str_len >= __suffix_len) __result = memcmp (__str + __str_len - __suffix_len, ((__suffix) + !(__suffix)), __suffix_len ) == 0; } __result; }) : (g_str_has_suffix) (item, ("." "so") ) )) { | |||
645 | char *module_path; | |||
646 | ||||
647 | p = g_new0(NstPlugin, 1)((NstPlugin *) g_malloc0_n ((1), sizeof (NstPlugin))); | |||
648 | module_path = g_module_build_path (plugindir, item); | |||
649 | p->module = g_module_open (module_path, 0); | |||
650 | if (!p->module) { | |||
651 | g_warning ("error opening %s: %s", module_path, g_module_error ()); | |||
652 | g_free (module_path); | |||
653 | continue; | |||
654 | } | |||
655 | g_free (module_path); | |||
656 | ||||
657 | if (!g_module_symbol (p->module, "nst_init_plugin", (gpointer *) &nst_init_plugin)) { | |||
658 | g_warning ("error: %s", g_module_error ()); | |||
659 | g_module_close (p->module); | |||
660 | continue; | |||
661 | } | |||
662 | ||||
663 | nst_init_plugin (p); | |||
664 | if (p->info->init(p)) { | |||
665 | plugin_list = g_list_append (plugin_list, p); | |||
666 | } else { | |||
667 | g_free (p); | |||
668 | } | |||
669 | } | |||
670 | } | |||
671 | g_dir_close (dir); | |||
| ||||
672 | } | |||
673 | } | |||
674 | ||||
675 | static gboolean | |||
676 | baul_sendto_plugin_init (void) | |||
677 | { | |||
678 | if (g_file_test (UNINSTALLED_PLUGINDIR"plugins/removable-devices", G_FILE_TEST_IS_DIR) != FALSE(0)) { | |||
| ||||
679 | /* Try to load the local plugins */ | |||
680 | GError *err = NULL((void*)0); | |||
681 | GDir *dir; | |||
682 | const char *item; | |||
683 | ||||
684 | dir = g_dir_open ("plugins/", 0, &err); | |||
685 | if (dir == NULL((void*)0)) { | |||
686 | g_warning ("Can't open the plugins dir: %s", err ? err->message : "No reason"); | |||
687 | if (err) | |||
688 | g_error_free (err); | |||
689 | return FALSE(0); | |||
690 | } | |||
691 | while ((item = g_dir_read_name(dir))) { | |||
692 | char *plugindir; | |||
693 | ||||
694 | plugindir = g_strdup_printf ("plugins/%s/.libs/", item); | |||
695 | if (g_file_test (plugindir, G_FILE_TEST_IS_DIR) != FALSE(0)) | |||
696 | baul_sendto_plugin_dir_process (plugindir); | |||
697 | g_free (plugindir); | |||
698 | } | |||
699 | g_dir_close (dir); | |||
700 | } | |||
701 | ||||
702 | if (g_list_length (plugin_list) == 0) | |||
703 | baul_sendto_plugin_dir_process (PLUGINDIR"/usr/lib/baul-sendto/plugins"); | |||
704 | ||||
705 | return g_list_length (plugin_list) != 0; | |||
706 | } | |||
707 | ||||
708 | static char * | |||
709 | escape_ampersands_and_commas (const char *url) | |||
710 | { | |||
711 | int i; | |||
712 | char *str, *ptr; | |||
713 | ||||
714 | /* Count the number of ampersands & commas */ | |||
715 | i = 0; | |||
716 | ptr = (char *) url; | |||
717 | while ((ptr = strchr (ptr, '&')) != NULL((void*)0)) { | |||
718 | i++; | |||
719 | ptr++; | |||
720 | } | |||
721 | ptr = (char *) url; | |||
722 | while ((ptr = strchr (ptr, ',')) != NULL((void*)0)) { | |||
723 | i++; | |||
724 | ptr++; | |||
725 | } | |||
726 | ||||
727 | /* No ampersands or commas ? */ | |||
728 | if (i == 0) | |||
729 | return NULL((void*)0); | |||
730 | ||||
731 | /* Replace the '&' */ | |||
732 | str = g_malloc0 (strlen (url) - i + 3 * i + 1); | |||
733 | ptr = str; | |||
734 | for (i = 0; url[i] != '\0'; i++) { | |||
735 | if (url[i] == '&') { | |||
736 | *ptr++ = '%'; | |||
737 | *ptr++ = '2'; | |||
738 | *ptr++ = '6'; | |||
739 | } else if (url[i] == ',') { | |||
740 | *ptr++ = '%'; | |||
741 | *ptr++ = '2'; | |||
742 | *ptr++ = 'C'; | |||
743 | } else { | |||
744 | *ptr++ = url[i]; | |||
745 | } | |||
746 | } | |||
747 | ||||
748 | return str; | |||
749 | } | |||
750 | ||||
751 | static void | |||
752 | baul_sendto_init (void) | |||
753 | { | |||
754 | int i; | |||
755 | ||||
756 | if (g_module_supported() == FALSE(0)) | |||
757 | g_error ("Could not initialize gmodule support"); | |||
758 | ||||
759 | for (i = 0; filenames != NULL((void*)0) && filenames[i] != NULL((void*)0); i++) { | |||
760 | GFile *file; | |||
761 | char *filename, *escaped, *uri; | |||
762 | ||||
763 | file = g_file_new_for_commandline_arg (filenames[i]); | |||
764 | filename = g_file_get_path (file); | |||
765 | g_object_unref (file); | |||
766 | if (filename == NULL((void*)0)) | |||
767 | continue; | |||
768 | ||||
769 | if (g_file_test (filename, G_FILE_TEST_IS_DIR) != FALSE(0)) | |||
770 | has_dirs = TRUE(!(0)); | |||
771 | ||||
772 | uri = g_filename_to_uri (filename, NULL((void*)0), NULL((void*)0)); | |||
773 | g_free (filename); | |||
774 | escaped = escape_ampersands_and_commas (uri); | |||
775 | ||||
776 | if (escaped == NULL((void*)0)) { | |||
777 | file_list = g_list_prepend (file_list, uri); | |||
778 | } else { | |||
779 | file_list = g_list_prepend (file_list, escaped); | |||
780 | g_free (uri); | |||
781 | } | |||
782 | } | |||
783 | ||||
784 | if (file_list == NULL((void*)0)) { | |||
785 | g_print (_("Expects URIs or filenames to be passed as options\n")gettext ("Expects URIs or filenames to be passed as options\n" )); | |||
786 | exit (1); | |||
787 | } | |||
788 | ||||
789 | file_list = g_list_reverse (file_list); | |||
790 | } | |||
791 | ||||
792 | int main (int argc, char **argv) | |||
793 | { | |||
794 | GOptionContext *context; | |||
795 | GError *error = NULL((void*)0); | |||
796 | ||||
797 | bindtextdomain (GETTEXT_PACKAGE"baul-extensions", LOCALEDIR"/usr/share/locale"); | |||
798 | bind_textdomain_codeset (GETTEXT_PACKAGE"baul-extensions", "UTF-8"); | |||
799 | textdomain (GETTEXT_PACKAGE"baul-extensions"); | |||
800 | ||||
801 | context = g_option_context_new (""); | |||
802 | g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE"baul-extensions"); | |||
803 | g_option_context_add_group (context, ctk_get_option_group (TRUE(!(0)))); | |||
804 | if (g_option_context_parse (context, &argc, &argv, &error) == FALSE(0)) { | |||
805 | g_print (_("Could not parse command-line options: %s\n")gettext ("Could not parse command-line options: %s\n"), error->message); | |||
806 | g_error_free (error); | |||
807 | return 1; | |||
808 | } | |||
809 | ||||
810 | settings = g_settings_new ("org.cafe.Baul.Sendto"); | |||
811 | baul_sendto_init (); | |||
812 | if (baul_sendto_plugin_init () == FALSE(0)) { | |||
813 | CtkWidget *error_dialog; | |||
814 | ||||
815 | error_dialog = | |||
816 | ctk_message_dialog_new (NULL((void*)0), | |||
817 | CTK_DIALOG_MODAL, | |||
818 | CTK_MESSAGE_ERROR, | |||
819 | CTK_BUTTONS_OK, | |||
820 | _("Could not load any plugins.")gettext ("Could not load any plugins.")); | |||
821 | ctk_message_dialog_format_secondary_text | |||
822 | (CTK_MESSAGE_DIALOG (error_dialog)((((CtkMessageDialog*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((error_dialog)), ((ctk_message_dialog_get_type ())))))), | |||
823 | _("Please verify your installation")gettext ("Please verify your installation")); | |||
824 | ||||
825 | ctk_window_set_title (CTK_WINDOW (error_dialog)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((error_dialog)), ((ctk_window_get_type ())))))), ""); /* as per HIG */ | |||
826 | ctk_container_set_border_width (CTK_CONTAINER (error_dialog)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((error_dialog)), ((ctk_container_get_type ())))))), 5); | |||
827 | ctk_dialog_set_default_response (CTK_DIALOG (error_dialog)((((CtkDialog*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((error_dialog)), ((ctk_dialog_get_type ())))))), | |||
828 | CTK_RESPONSE_OK); | |||
829 | ctk_dialog_run (CTK_DIALOG (error_dialog)((((CtkDialog*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((error_dialog)), ((ctk_dialog_get_type ()))))))); | |||
830 | return 1; | |||
831 | } | |||
832 | baul_sendto_create_ui (); | |||
833 | ||||
834 | ctk_main (); | |||
835 | g_object_unref(settings); | |||
836 | ||||
837 | return 0; | |||
838 | } | |||
839 |