Mercurial > geeqie.yaz
annotate src/utilops.c @ 546:f852eb277913
Explode exif_get_formatted_by_key() in smaller functions prefixed "exif_build_f".
An helper macro was added to call them.
author | zas_ |
---|---|
date | Fri, 02 May 2008 21:34:26 +0000 |
parents | 985fdfebd89e |
children | 905688aa2317 |
rev | line source |
---|---|
1 | 1 /* |
196 | 2 * Geeqie |
67
f63ecca6c087
Fri Oct 13 05:22:43 2006 John Ellis <johne@verizon.net>
gqview
parents:
66
diff
changeset
|
3 * (C) 2006 John Ellis |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
1 | 5 * |
6 * Author: John Ellis | |
7 * | |
9 | 8 * This software is released under the GNU General Public License (GNU GPL). |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
1 | 11 */ |
12 | |
9 | 13 |
281 | 14 #include "main.h" |
9 | 15 #include "utilops.h" |
16 | |
17 | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
18 #include "cache.h" |
9 | 19 #include "cache_maint.h" |
20 #include "collect.h" | |
507 | 21 #include "debug.h" |
9 | 22 #include "dupe.h" |
23 #include "filelist.h" | |
24 #include "image.h" | |
25 #include "img-view.h" | |
26 #include "layout.h" | |
27 #include "search.h" | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
28 #include "thumb_standard.h" |
9 | 29 #include "ui_bookmark.h" |
30 #include "ui_fileops.h" | |
31 #include "ui_misc.h" | |
32 #include "ui_tabcomp.h" | |
140 | 33 #include "editors.h" |
9 | 34 |
35 /* | |
36 *-------------------------------------------------------------------------- | |
37 * call these when names change, files move, deleted, etc. | |
38 * so that any open windows are also updated | |
39 *-------------------------------------------------------------------------- | |
40 */ | |
41 | |
138 | 42 |
43 void file_maint_renamed(FileData *fd) | |
9 | 44 { |
138 | 45 cache_maint_moved(fd); |
46 collection_maint_renamed(fd); | |
47 | |
48 layout_maint_renamed(fd); | |
49 view_window_maint_moved(fd); | |
50 dupe_maint_renamed(fd); | |
51 search_maint_renamed(fd); | |
9 | 52 } |
53 | |
54 /* under most cases ignore_list should be NULL */ | |
138 | 55 void file_maint_removed(FileData *fd, GList *ignore_list) |
9 | 56 { |
138 | 57 layout_maint_removed(fd, ignore_list); |
58 view_window_maint_removed(fd, ignore_list); | |
59 dupe_maint_removed(fd); | |
60 search_maint_removed(fd); | |
61 | |
62 collection_maint_removed(fd); | |
63 cache_maint_removed(fd); | |
9 | 64 } |
65 | |
66 /* special case for correct main window behavior */ | |
138 | 67 void file_maint_moved(FileData *fd, GList *ignore_list) |
9 | 68 { |
138 | 69 cache_maint_moved(fd); |
70 collection_maint_renamed(fd); | |
71 | |
72 layout_maint_moved(fd, ignore_list); | |
73 view_window_maint_moved(fd); | |
74 dupe_maint_renamed(fd); | |
75 search_maint_renamed(fd); | |
9 | 76 } |
77 | |
138 | 78 void file_maint_copied(FileData *fd) |
9 | 79 { |
138 | 80 cache_maint_copied(fd); |
9 | 81 } |
82 | |
83 /* | |
84 *-------------------------------------------------------------------------- | |
85 * The file manipulation dialogs | |
86 *-------------------------------------------------------------------------- | |
87 */ | |
88 | |
1 | 89 |
90 enum { | |
91 DIALOG_NEW_DIR, | |
92 DIALOG_COPY, | |
93 DIALOG_MOVE, | |
94 DIALOG_DELETE, | |
95 DIALOG_RENAME | |
96 }; | |
97 | |
98 typedef struct _FileDataMult FileDataMult; | |
99 struct _FileDataMult | |
100 { | |
101 gint confirm_all; | |
102 gint confirmed; | |
103 gint skip; | |
104 GList *source_list; | |
105 GList *source_next; | |
106 gchar *dest_base; | |
138 | 107 FileData *source_fd; |
1 | 108 gchar *dest; |
109 gint copy; | |
9 | 110 |
111 gint rename; | |
112 gint rename_auto; | |
113 gint rename_all; | |
114 | |
115 GtkWidget *rename_box; | |
116 GtkWidget *rename_entry; | |
117 GtkWidget *rename_auto_box; | |
118 | |
119 GtkWidget *yes_all_button; | |
1 | 120 }; |
121 | |
122 typedef struct _FileDataSingle FileDataSingle; | |
123 struct _FileDataSingle | |
124 { | |
125 gint confirmed; | |
138 | 126 FileData *source_fd; |
1 | 127 gchar *dest; |
128 gint copy; | |
9 | 129 |
130 gint rename; | |
131 gint rename_auto; | |
132 | |
133 GtkWidget *rename_box; | |
134 GtkWidget *rename_entry; | |
135 GtkWidget *rename_auto_box; | |
1 | 136 }; |
137 | |
9 | 138 /* |
139 *-------------------------------------------------------------------------- | |
140 * Adds 1 or 2 images (if 2, side by side) to a GenericDialog | |
141 *-------------------------------------------------------------------------- | |
142 */ | |
143 | |
144 #define DIALOG_DEF_IMAGE_DIM_X 200 | |
145 #define DIALOG_DEF_IMAGE_DIM_Y 150 | |
146 | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
147 static void generic_dialog_add_image(GenericDialog *gd, GtkWidget *box, |
138 | 148 FileData *fd1, const gchar *header1, |
149 FileData *fd2, const gchar *header2, | |
9 | 150 gint show_filename) |
151 { | |
152 ImageWindow *imd; | |
153 GtkWidget *hbox = NULL; | |
154 GtkWidget *vbox; | |
155 GtkWidget *label = NULL; | |
156 | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
157 if (!box) box = gd->vbox; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
158 |
138 | 159 if (fd2) |
9 | 160 { |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
161 hbox = pref_box_new(box, TRUE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE); |
9 | 162 } |
163 | |
164 /* image 1 */ | |
165 | |
166 vbox = gtk_vbox_new(FALSE, PREF_PAD_GAP); | |
167 if (hbox) | |
168 { | |
169 GtkWidget *sep; | |
170 | |
171 gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0); | |
172 | |
173 sep = gtk_vseparator_new(); | |
174 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
175 gtk_widget_show(sep); | |
176 } | |
177 else | |
178 { | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
179 gtk_box_pack_start(GTK_BOX(box), vbox, TRUE, TRUE, PREF_PAD_GAP); |
9 | 180 } |
181 gtk_widget_show(vbox); | |
182 | |
183 if (header1) | |
184 { | |
185 GtkWidget *head; | |
186 | |
187 head = pref_label_new(vbox, header1); | |
188 pref_label_bold(head, TRUE, FALSE); | |
189 gtk_misc_set_alignment(GTK_MISC(head), 0.0, 0.5); | |
190 } | |
191 | |
192 imd = image_new(FALSE); | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
193 g_object_set(G_OBJECT(imd->pr), "zoom_expand", FALSE, NULL); |
9 | 194 gtk_widget_set_size_request(imd->widget, DIALOG_DEF_IMAGE_DIM_X, DIALOG_DEF_IMAGE_DIM_Y); |
195 gtk_box_pack_start(GTK_BOX(vbox), imd->widget, TRUE, TRUE, 0); | |
138 | 196 image_change_fd(imd, fd1, 0.0); |
9 | 197 gtk_widget_show(imd->widget); |
198 | |
199 if (show_filename) | |
200 { | |
138 | 201 label = pref_label_new(vbox, (fd1 == NULL) ? "" : fd1->name); |
9 | 202 } |
203 | |
204 /* only the first image is stored (for use in gd_image_set) */ | |
205 g_object_set_data(G_OBJECT(gd->dialog), "img_image", imd); | |
206 g_object_set_data(G_OBJECT(gd->dialog), "img_label", label); | |
442 | 207 |
9 | 208 |
209 /* image 2 */ | |
210 | |
138 | 211 if (hbox && fd2) |
9 | 212 { |
213 vbox = pref_box_new(hbox, TRUE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP); | |
214 | |
215 if (header2) | |
216 { | |
217 GtkWidget *head; | |
218 | |
219 head = pref_label_new(vbox, header2); | |
220 pref_label_bold(head, TRUE, FALSE); | |
221 gtk_misc_set_alignment(GTK_MISC(head), 0.0, 0.5); | |
222 } | |
223 | |
224 imd = image_new(FALSE); | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
225 g_object_set(G_OBJECT(imd->pr), "zoom_expand", FALSE, NULL); |
9 | 226 gtk_widget_set_size_request(imd->widget, DIALOG_DEF_IMAGE_DIM_X, DIALOG_DEF_IMAGE_DIM_Y); |
227 gtk_box_pack_start(GTK_BOX(vbox), imd->widget, TRUE, TRUE, 0); | |
138 | 228 image_change_fd(imd, fd2, 0.0); |
9 | 229 gtk_widget_show(imd->widget); |
230 | |
138 | 231 pref_label_new(vbox, fd2->name); |
9 | 232 } |
233 } | |
234 | |
138 | 235 static void generic_dialog_image_set(GenericDialog *gd, FileData *fd) |
9 | 236 { |
237 ImageWindow *imd; | |
238 GtkWidget *label; | |
442 | 239 |
9 | 240 imd = g_object_get_data(G_OBJECT(gd->dialog), "img_image"); |
241 label = g_object_get_data(G_OBJECT(gd->dialog), "img_label"); | |
242 | |
243 if (!imd) return; | |
244 | |
138 | 245 image_change_fd(imd, fd, 0.0); |
246 if (label) gtk_label_set_text(GTK_LABEL(label), fd->name); | |
9 | 247 } |
248 | |
249 /* | |
250 *-------------------------------------------------------------------------- | |
251 * Wrappers to aid in setting additional dialog properties (unde mouse, etc.) | |
252 *-------------------------------------------------------------------------- | |
253 */ | |
254 | |
255 GenericDialog *file_util_gen_dlg(const gchar *title, | |
256 const gchar *wmclass, const gchar *wmsubclass, | |
257 GtkWidget *parent, gint auto_close, | |
258 void (*cancel_cb)(GenericDialog *, gpointer), gpointer data) | |
259 { | |
260 GenericDialog *gd; | |
261 | |
262 gd = generic_dialog_new(title, wmclass, wmsubclass, parent, auto_close, cancel_cb, data); | |
318 | 263 if (options->place_dialogs_under_mouse) |
9 | 264 { |
265 gtk_window_set_position(GTK_WINDOW(gd->dialog), GTK_WIN_POS_MOUSE); | |
266 } | |
267 | |
268 return gd; | |
269 } | |
270 | |
271 FileDialog *file_util_file_dlg(const gchar *title, | |
272 const gchar *wmclass, const gchar *wmsubclass, | |
273 GtkWidget *parent, | |
274 void (*cancel_cb)(FileDialog *, gpointer), gpointer data) | |
275 { | |
138 | 276 FileDialog *fdlg; |
277 | |
278 fdlg = file_dialog_new(title, wmclass, wmsubclass, parent, cancel_cb, data); | |
318 | 279 if (options->place_dialogs_under_mouse) |
9 | 280 { |
138 | 281 gtk_window_set_position(GTK_WINDOW(GENERIC_DIALOG(fdlg)->dialog), GTK_WIN_POS_MOUSE); |
9 | 282 } |
283 | |
138 | 284 return fdlg; |
9 | 285 } |
286 | |
287 /* this warning dialog is copied from SLIK's ui_utildg.c, | |
288 * because it does not have a mouse center option, | |
289 * and we must center it before show, implement it here. | |
290 */ | |
291 static void file_util_warning_dialog_ok_cb(GenericDialog *gd, gpointer data) | |
292 { | |
293 /* no op */ | |
294 } | |
295 | |
296 GenericDialog *file_util_warning_dialog(const gchar *heading, const gchar *message, | |
297 const gchar *icon_stock_id, GtkWidget *parent) | |
298 { | |
299 GenericDialog *gd; | |
300 | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
223
diff
changeset
|
301 gd = file_util_gen_dlg(heading, GQ_WMCLASS, "warning", parent, TRUE, NULL, NULL); |
9 | 302 generic_dialog_add_message(gd, icon_stock_id, heading, message); |
303 generic_dialog_add_button(gd, GTK_STOCK_OK, NULL, file_util_warning_dialog_ok_cb, TRUE); | |
318 | 304 if (options->place_dialogs_under_mouse) |
9 | 305 { |
306 gtk_window_set_position(GTK_WINDOW(gd->dialog), GTK_WIN_POS_MOUSE); | |
307 } | |
308 gtk_widget_show(gd->dialog); | |
309 | |
310 return gd; | |
311 } | |
1 | 312 |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
313 static gint filename_base_length(const gchar *name) |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
314 { |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
315 gint n; |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
316 |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
317 if (!name) return 0; |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
318 |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
319 n = strlen(name); |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
320 |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
321 if (filter_name_exists(name)) |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
322 { |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
323 const gchar *ext; |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
324 |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
325 ext = extension_from_path(name); |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
326 if (ext) n -= strlen(ext); |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
327 } |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
328 |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
329 return n; |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
330 } |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
331 |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
332 |
1 | 333 /* |
334 *-------------------------------------------------------------------------- | |
335 * Move and Copy routines | |
336 *-------------------------------------------------------------------------- | |
337 */ | |
338 | |
140 | 339 static gint copy_file_ext_cb(gpointer ed, gint flags, GList *list, gpointer data) |
340 { | |
341 if ((flags & EDITOR_ERROR_MASK) && !(flags & EDITOR_ERROR_SKIPPED)) | |
342 { | |
343 FileData *fd = list->data; | |
344 gchar *title = _("Error copying file"); | |
442 | 345 gchar *text = g_strdup_printf(_("%s\nUnable to copy file:\n%s\nto:\n%s"), editor_get_error_str(flags), fd->name, fd->change->dest); |
140 | 346 file_util_warning_dialog(title, text, GTK_STOCK_DIALOG_ERROR, NULL); |
347 g_free(text); | |
348 } | |
349 while (list) | |
350 { | |
351 FileData *fd = list->data; | |
352 if (!(flags & EDITOR_ERROR_MASK)) | |
353 file_maint_copied(fd); | |
354 file_data_change_info_free(NULL, fd); | |
355 list = list->next; | |
356 } | |
357 return EDITOR_CB_CONTINUE; | |
358 } | |
359 | |
360 | |
138 | 361 gint copy_file_ext(FileData *fd) |
136 | 362 { |
140 | 363 gint ok; |
138 | 364 g_assert(fd->change); |
318 | 365 if (options->editor_command[CMD_COPY]) |
140 | 366 { |
367 ok = !start_editor_from_file_full(CMD_COPY, fd, copy_file_ext_cb, NULL); | |
368 if (ok) return ok; /* that's all for now, let's continue in callback */ | |
369 } | |
138 | 370 else |
140 | 371 ok = copy_file(fd->change->source, fd->change->dest); |
372 | |
373 if (ok) | |
138 | 374 { |
375 file_maint_copied(fd); | |
376 } | |
377 | |
378 file_data_change_info_free(NULL, fd); | |
442 | 379 |
140 | 380 return ok; |
136 | 381 } |
382 | |
140 | 383 static gint move_file_ext_cb(gpointer ed, gint flags, GList *list, gpointer data) |
384 { | |
385 if ((flags & EDITOR_ERROR_MASK) && !(flags & EDITOR_ERROR_SKIPPED)) | |
386 { | |
387 FileData *fd = list->data; | |
388 gchar *title = _("Error moving file"); | |
442 | 389 gchar *text = g_strdup_printf(_("%s\nUnable to move file:\n%s\nto:\n%s"), editor_get_error_str(flags), fd->name, fd->change->dest); |
140 | 390 file_util_warning_dialog(title, text, GTK_STOCK_DIALOG_ERROR, NULL); |
391 g_free(text); | |
392 } | |
393 while (list) | |
394 { | |
395 FileData *fd = list->data; | |
396 if (!(flags & EDITOR_ERROR_MASK)) | |
397 { | |
398 file_data_do_change(fd); | |
399 file_maint_moved(fd, NULL); | |
400 } | |
401 file_data_change_info_free(NULL, fd); | |
402 list = list->next; | |
403 } | |
404 return EDITOR_CB_CONTINUE; | |
405 | |
406 } | |
407 | |
408 | |
138 | 409 gint move_file_ext(FileData *fd) |
136 | 410 { |
140 | 411 gint ok; |
138 | 412 g_assert(fd->change); |
318 | 413 if (options->editor_command[CMD_MOVE]) |
140 | 414 { |
442 | 415 ok = !start_editor_from_file_full(CMD_MOVE, fd, move_file_ext_cb, NULL); |
416 if (ok) return ok; /* that's all for now, let's continue in callback */ | |
140 | 417 } |
138 | 418 else |
140 | 419 ok = move_file(fd->change->source, fd->change->dest); |
420 | |
421 if (ok) | |
138 | 422 { |
423 file_data_do_change(fd); | |
424 file_maint_moved(fd, NULL); | |
425 } | |
426 | |
427 file_data_change_info_free(NULL, fd); | |
442 | 428 |
140 | 429 return ok; |
430 } | |
431 | |
432 static gint rename_file_ext_cb(gpointer ed, gint flags, GList *list, gpointer data) | |
433 { | |
434 if ((flags & EDITOR_ERROR_MASK) && !(flags & EDITOR_ERROR_SKIPPED)) | |
435 { | |
436 FileData *fd = list->data; | |
437 gchar *title = _("Error renaming file"); | |
442 | 438 gchar *text = g_strdup_printf(_("%s\nUnable to rename file:\n%s\nto:\n%s"), editor_get_error_str(flags), fd->name, fd->change->dest); |
140 | 439 file_util_warning_dialog(title, text, GTK_STOCK_DIALOG_ERROR, NULL); |
440 g_free(text); | |
441 } | |
442 while (list) | |
443 { | |
444 FileData *fd = list->data; | |
445 if (!(flags & EDITOR_ERROR_MASK)) | |
446 { | |
447 file_data_do_change(fd); | |
448 file_maint_renamed(fd); | |
449 } | |
450 file_data_change_info_free(NULL, fd); | |
451 list = list->next; | |
452 } | |
453 return EDITOR_CB_CONTINUE; | |
136 | 454 } |
455 | |
138 | 456 gint rename_file_ext(FileData *fd) |
136 | 457 { |
140 | 458 gint ok; |
138 | 459 g_assert(fd->change); |
318 | 460 if (options->editor_command[CMD_RENAME]) |
140 | 461 { |
462 ok = !start_editor_from_file_full(CMD_RENAME, fd, rename_file_ext_cb, NULL); | |
463 if (ok) return ok; /* that's all for now, let's continue in callback */ | |
464 } | |
138 | 465 else |
140 | 466 ok = rename_file(fd->change->source, fd->change->dest); |
442 | 467 |
140 | 468 if (ok) |
138 | 469 { |
470 file_data_do_change(fd); | |
471 file_maint_renamed(fd); | |
472 } | |
442 | 473 |
138 | 474 file_data_change_info_free(NULL, fd); |
442 | 475 |
140 | 476 return ok; |
136 | 477 } |
478 | |
479 | |
1 | 480 /* |
481 * Multi file move | |
482 */ | |
483 | |
9 | 484 static FileDataMult *file_data_multiple_new(GList *source_list, const gchar *dest, gint copy) |
1 | 485 { |
486 FileDataMult *fdm = g_new0(FileDataMult, 1); | |
487 fdm->confirm_all = FALSE; | |
488 fdm->confirmed = FALSE; | |
489 fdm->skip = FALSE; | |
490 fdm->source_list = source_list; | |
491 fdm->source_next = fdm->source_list; | |
492 fdm->dest_base = g_strdup(dest); | |
138 | 493 fdm->source_fd = NULL; |
1 | 494 fdm->dest = NULL; |
495 fdm->copy = copy; | |
496 return fdm; | |
497 } | |
498 | |
499 static void file_data_multiple_free(FileDataMult *fdm) | |
500 { | |
138 | 501 filelist_free(fdm->source_list); |
1 | 502 g_free(fdm->dest_base); |
503 g_free(fdm->dest); | |
504 g_free(fdm); | |
505 } | |
506 | |
9 | 507 static void file_util_move_multiple(FileDataMult *fdm); |
508 | |
509 static void file_util_move_multiple_ok_cb(GenericDialog *gd, gpointer data) | |
1 | 510 { |
511 FileDataMult *fdm = data; | |
9 | 512 |
1 | 513 fdm->confirmed = TRUE; |
9 | 514 |
515 if (fdm->rename_auto) | |
516 { | |
517 gchar *buf; | |
518 | |
519 buf = unique_filename_simple(fdm->dest); | |
520 if (buf) | |
521 { | |
522 g_free(fdm->dest); | |
523 fdm->dest = buf; | |
524 } | |
525 else | |
526 { | |
527 /* unique failed? well, return to the overwrite prompt :( */ | |
528 fdm->confirmed = FALSE; | |
529 } | |
530 } | |
531 else if (fdm->rename) | |
532 { | |
533 const gchar *name; | |
534 | |
535 name = gtk_entry_get_text(GTK_ENTRY(fdm->rename_entry)); | |
536 if (strlen(name) == 0 || | |
138 | 537 strcmp(name, fdm->source_fd->name) == 0) |
9 | 538 { |
539 fdm->confirmed = FALSE; | |
540 } | |
541 else | |
542 { | |
543 g_free(fdm->dest); | |
544 fdm->dest = concat_dir_and_file(fdm->dest_base, name); | |
545 fdm->confirmed = !isname(fdm->dest); | |
546 } | |
547 } | |
548 | |
1 | 549 file_util_move_multiple(fdm); |
550 } | |
551 | |
9 | 552 static void file_util_move_multiple_all_cb(GenericDialog *gd, gpointer data) |
1 | 553 { |
554 FileDataMult *fdm = data; | |
9 | 555 |
556 fdm->confirm_all = TRUE; | |
557 | |
558 if (fdm->rename_auto) fdm->rename_all = TRUE; | |
559 | |
560 file_util_move_multiple(fdm); | |
561 } | |
562 | |
563 static void file_util_move_multiple_skip_cb(GenericDialog *gd, gpointer data) | |
564 { | |
565 FileDataMult *fdm = data; | |
566 | |
567 fdm->skip = TRUE; | |
568 fdm->confirmed = TRUE; | |
569 | |
570 file_util_move_multiple(fdm); | |
571 } | |
572 | |
573 static void file_util_move_multiple_skip_all_cb(GenericDialog *gd, gpointer data) | |
574 { | |
575 FileDataMult *fdm = data; | |
576 | |
577 fdm->skip = TRUE; | |
1 | 578 fdm->confirm_all = TRUE; |
579 file_util_move_multiple(fdm); | |
580 } | |
581 | |
9 | 582 static void file_util_move_multiple_continue_cb(GenericDialog *gd, gpointer data) |
1 | 583 { |
584 FileDataMult *fdm = data; | |
9 | 585 |
586 fdm->confirmed = TRUE; | |
1 | 587 file_util_move_multiple(fdm); |
588 } | |
589 | |
9 | 590 static void file_util_move_multiple_cancel_cb(GenericDialog *gd, gpointer data) |
1 | 591 { |
592 FileDataMult *fdm = data; | |
9 | 593 |
1 | 594 file_data_multiple_free(fdm); |
595 } | |
596 | |
9 | 597 /* rename option */ |
598 | |
599 static void file_util_move_multiple_rename_auto_cb(GtkWidget *widget, gpointer data) | |
600 { | |
601 GenericDialog *gd = data; | |
602 FileDataMult *fdm; | |
603 | |
604 fdm = gd->data; | |
605 | |
606 fdm->rename_auto = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | |
607 gtk_widget_set_sensitive(fdm->rename_box, !fdm->rename_auto); | |
608 gtk_widget_set_sensitive(fdm->rename_entry, (!fdm->rename_auto && fdm->rename)); | |
609 | |
610 if (fdm->rename_auto) | |
611 { | |
612 gchar *preview; | |
613 | |
614 preview = unique_filename_simple(fdm->dest); | |
615 if (preview) gtk_entry_set_text(GTK_ENTRY(fdm->rename_entry), filename_from_path(preview)); | |
616 g_free(preview); | |
617 } | |
618 | |
619 gtk_widget_set_sensitive(fdm->yes_all_button, (fdm->rename_auto || !fdm->rename)); | |
620 } | |
621 | |
622 static void file_util_move_multiple_rename_cb(GtkWidget *widget, gpointer data) | |
623 { | |
624 GenericDialog *gd = data; | |
625 FileDataMult *fdm; | |
626 | |
627 fdm = gd->data; | |
628 | |
629 fdm->rename = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | |
630 gtk_widget_set_sensitive(fdm->rename_entry, fdm->rename); | |
631 gtk_widget_set_sensitive(fdm->yes_all_button, !fdm->rename); | |
632 | |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
633 if (fdm->rename) |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
634 { |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
635 const gchar *name; |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
636 |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
637 gtk_widget_grab_focus(fdm->rename_entry); |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
638 |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
639 name = gtk_entry_get_text(GTK_ENTRY(fdm->rename_entry)); |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
640 gtk_editable_select_region(GTK_EDITABLE(fdm->rename_entry), 0, filename_base_length(name)); |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
641 } |
9 | 642 } |
643 | |
644 static GenericDialog *file_util_move_multiple_confirm_dialog(FileDataMult *fdm) | |
645 { | |
646 GenericDialog *gd; | |
647 GtkWidget *hbox; | |
648 | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
223
diff
changeset
|
649 gd = file_util_gen_dlg(_("Overwrite file"), GQ_WMCLASS, "dlg_confirm", |
9 | 650 NULL, TRUE, |
651 file_util_move_multiple_cancel_cb, fdm); | |
652 | |
653 generic_dialog_add_message(gd, GTK_STOCK_DIALOG_QUESTION, | |
654 _("Overwrite file?"), | |
655 _("Replace existing file with new file.")); | |
656 pref_spacer(gd->vbox, 0); | |
657 | |
658 generic_dialog_add_button(gd, GTK_STOCK_YES, _("_Overwrite"), file_util_move_multiple_ok_cb, TRUE); | |
659 fdm->yes_all_button = generic_dialog_add_button(gd, NULL, _("Overwrite _all"), | |
660 file_util_move_multiple_all_cb, FALSE); | |
661 generic_dialog_add_button(gd, GTK_STOCK_GOTO_LAST, _("S_kip all"), file_util_move_multiple_skip_all_cb, FALSE); | |
662 generic_dialog_add_button(gd, GTK_STOCK_GO_FORWARD, _("_Skip"), file_util_move_multiple_skip_cb, FALSE); | |
138 | 663 generic_dialog_add_image(gd, NULL, file_data_new_simple(fdm->dest), _("Existing file"), fdm->source_fd, _("New file"), TRUE); |
9 | 664 |
665 /* rename option */ | |
666 | |
667 fdm->rename = FALSE; | |
668 fdm->rename_all = FALSE; | |
669 fdm->rename_auto = FALSE; | |
670 | |
671 hbox = pref_box_new(gd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP); | |
672 | |
673 fdm->rename_auto_box = gtk_check_button_new_with_label(_("Auto rename")); | |
674 g_signal_connect(G_OBJECT(fdm->rename_auto_box), "clicked", | |
675 G_CALLBACK(file_util_move_multiple_rename_auto_cb), gd); | |
676 gtk_box_pack_start(GTK_BOX(hbox), fdm->rename_auto_box, FALSE, FALSE, 0); | |
677 gtk_widget_show(fdm->rename_auto_box); | |
678 | |
679 hbox = pref_box_new(gd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP); | |
680 | |
681 fdm->rename_box = gtk_check_button_new_with_label(_("Rename")); | |
682 g_signal_connect(G_OBJECT(fdm->rename_box), "clicked", | |
683 G_CALLBACK(file_util_move_multiple_rename_cb), gd); | |
684 gtk_box_pack_start(GTK_BOX(hbox), fdm->rename_box, FALSE, FALSE, 0); | |
685 gtk_widget_show(fdm->rename_box); | |
686 | |
687 fdm->rename_entry = gtk_entry_new(); | |
688 gtk_entry_set_text(GTK_ENTRY(fdm->rename_entry), filename_from_path(fdm->dest)); | |
689 gtk_widget_set_sensitive(fdm->rename_entry, FALSE); | |
690 gtk_box_pack_start(GTK_BOX(hbox), fdm->rename_entry, TRUE, TRUE, 0); | |
691 gtk_widget_show(fdm->rename_entry); | |
692 | |
693 return gd; | |
694 } | |
695 | |
1 | 696 static void file_util_move_multiple(FileDataMult *fdm) |
697 { | |
698 while (fdm->dest || fdm->source_next) | |
699 { | |
9 | 700 gint success = FALSE; |
701 gint skip_file = FALSE; | |
702 | |
1 | 703 if (!fdm->dest) |
704 { | |
705 GList *work = fdm->source_next; | |
138 | 706 fdm->source_fd = work->data; |
707 fdm->dest = concat_dir_and_file(fdm->dest_base, fdm->source_fd->name); | |
1 | 708 fdm->source_next = work->next; |
9 | 709 fdm->confirmed = FALSE; |
1 | 710 } |
711 | |
138 | 712 if (fdm->dest && fdm->source_fd && strcmp(fdm->dest, fdm->source_fd->name) == 0) |
3 | 713 { |
9 | 714 if (!fdm->confirmed) |
3 | 715 { |
9 | 716 GenericDialog *gd; |
717 const gchar *title; | |
718 gchar *text; | |
719 | |
720 if (fdm->copy) | |
721 { | |
722 title = _("Source to copy matches destination"); | |
723 text = g_strdup_printf(_("Unable to copy file:\n%s\nto itself."), fdm->dest); | |
724 } | |
725 else | |
726 { | |
727 title = _("Source to move matches destination"); | |
728 text = g_strdup_printf(_("Unable to move file:\n%s\nto itself."), fdm->dest); | |
729 } | |
730 | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
223
diff
changeset
|
731 gd = file_util_gen_dlg(title, GQ_WMCLASS, "dlg_confirm", |
9 | 732 NULL, TRUE, |
733 file_util_move_multiple_cancel_cb, fdm); | |
734 generic_dialog_add_message(gd, GTK_STOCK_DIALOG_WARNING, title, text); | |
735 g_free(text); | |
736 generic_dialog_add_button(gd, GTK_STOCK_GO_FORWARD, _("Co_ntinue"), | |
737 file_util_move_multiple_continue_cb, TRUE); | |
738 | |
739 gtk_widget_show(gd->dialog); | |
740 return; | |
3 | 741 } |
9 | 742 skip_file = TRUE; |
3 | 743 } |
9 | 744 else if (isfile(fdm->dest)) |
1 | 745 { |
9 | 746 if (!fdm->confirmed && !fdm->confirm_all) |
747 { | |
748 GenericDialog *gd; | |
749 | |
750 gd = file_util_move_multiple_confirm_dialog(fdm); | |
751 gtk_widget_show(gd->dialog); | |
752 return; | |
753 } | |
754 if (fdm->skip) skip_file = TRUE; | |
755 } | |
756 | |
757 if (skip_file) | |
758 { | |
759 success = TRUE; | |
760 if (!fdm->confirm_all) fdm->skip = FALSE; | |
1 | 761 } |
762 else | |
763 { | |
9 | 764 gint try = TRUE; |
765 | |
766 if (fdm->confirm_all && fdm->rename_all && isfile(fdm->dest)) | |
1 | 767 { |
9 | 768 gchar *buf; |
769 buf = unique_filename_simple(fdm->dest); | |
770 if (buf) | |
771 { | |
772 g_free(fdm->dest); | |
773 fdm->dest = buf; | |
774 } | |
775 else | |
776 { | |
777 try = FALSE; | |
778 } | |
1 | 779 } |
9 | 780 if (try) |
1 | 781 { |
782 if (fdm->copy) | |
783 { | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
784 if (file_data_add_change_info(fdm->source_fd, FILEDATA_CHANGE_COPY, fdm->source_fd->path, fdm->dest) && |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
785 copy_file_ext(fdm->source_fd)) |
9 | 786 { |
787 success = TRUE; | |
788 } | |
1 | 789 } |
790 else | |
791 { | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
792 if (file_data_add_change_info(fdm->source_fd, FILEDATA_CHANGE_MOVE, fdm->source_fd->path, fdm->dest) && |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
793 move_file_ext(fdm->source_fd)) |
1 | 794 { |
795 success = TRUE; | |
796 } | |
797 } | |
138 | 798 |
1 | 799 } |
9 | 800 } |
801 if (!success) | |
802 { | |
803 GenericDialog *gd; | |
804 const gchar *title; | |
805 gchar *text; | |
806 | |
807 if (fdm->copy) | |
808 { | |
809 title = _("Error copying file"); | |
138 | 810 text = g_strdup_printf(_("Unable to copy file:\n%s\nto:\n%s\nduring multiple file copy."), fdm->source_fd->path, fdm->dest); |
9 | 811 } |
812 else | |
1 | 813 { |
9 | 814 title = _("Error moving file"); |
138 | 815 text = g_strdup_printf(_("Unable to move file:\n%s\nto:\n%s\nduring multiple file move."), fdm->source_fd->path, fdm->dest); |
1 | 816 } |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
223
diff
changeset
|
817 gd = file_util_gen_dlg(title, GQ_WMCLASS, "dlg_confirm", |
9 | 818 NULL, TRUE, |
819 file_util_move_multiple_cancel_cb, fdm); | |
820 generic_dialog_add_message(gd, GTK_STOCK_DIALOG_WARNING, title, text); | |
821 g_free(text); | |
822 | |
823 generic_dialog_add_button(gd, GTK_STOCK_GO_FORWARD, _("Co_ntinue"), | |
824 file_util_move_multiple_continue_cb, TRUE); | |
825 gtk_widget_show(gd->dialog); | |
1 | 826 } |
9 | 827 |
828 g_free(fdm->dest); | |
829 fdm->dest = NULL; | |
830 | |
831 if (!success) return; | |
1 | 832 } |
138 | 833 /* |
834 if (fdm->source_list) | |
835 file_util_do_move_list(fdm->source_list, fdm->copy); | |
836 else | |
837 { | |
838 GList *list = g_list_append(NULL, file_data_ref(fdm->source_fd)); | |
839 file_util_do_move_list(list, fdm->copy); | |
840 filelist_free(list); | |
841 } | |
842 */ | |
1 | 843 file_data_multiple_free(fdm); |
844 } | |
845 | |
846 /* | |
847 * Single file move | |
848 */ | |
849 | |
138 | 850 static FileDataSingle *file_data_single_new(FileData *source_fd, const gchar *dest, gint copy) |
1 | 851 { |
852 FileDataSingle *fds = g_new0(FileDataSingle, 1); | |
853 fds->confirmed = FALSE; | |
138 | 854 fds->source_fd = file_data_ref(source_fd); |
1 | 855 fds->dest = g_strdup(dest); |
856 fds->copy = copy; | |
857 return fds; | |
858 } | |
859 | |
860 static void file_data_single_free(FileDataSingle *fds) | |
861 { | |
138 | 862 file_data_unref(fds->source_fd); |
1 | 863 g_free(fds->dest); |
864 g_free(fds); | |
865 } | |
866 | |
9 | 867 static void file_util_move_single(FileDataSingle *fds); |
868 | |
869 static void file_util_move_single_ok_cb(GenericDialog *gd, gpointer data) | |
1 | 870 { |
871 FileDataSingle *fds = data; | |
9 | 872 |
1 | 873 fds->confirmed = TRUE; |
9 | 874 |
875 if (fds->rename_auto) | |
876 { | |
877 gchar *buf; | |
878 | |
879 buf = unique_filename_simple(fds->dest); | |
880 if (buf) | |
881 { | |
882 g_free(fds->dest); | |
883 fds->dest = buf; | |
884 } | |
885 else | |
886 { | |
887 /* unique failed? well, return to the overwrite prompt :( */ | |
888 fds->confirmed = FALSE; | |
889 } | |
890 } | |
891 else if (fds->rename) | |
892 { | |
893 const gchar *name; | |
894 | |
895 name = gtk_entry_get_text(GTK_ENTRY(fds->rename_entry)); | |
896 if (strlen(name) == 0 || | |
138 | 897 strcmp(name, fds->source_fd->name) == 0) |
9 | 898 { |
899 fds->confirmed = FALSE; | |
900 } | |
901 else | |
902 { | |
903 gchar *base; | |
904 | |
905 base = remove_level_from_path(fds->dest); | |
906 g_free(fds->dest); | |
907 fds->dest = concat_dir_and_file(base, name); | |
908 fds->confirmed = !isname(fds->dest); | |
909 | |
910 g_free(base); | |
911 } | |
912 } | |
913 | |
1 | 914 file_util_move_single(fds); |
915 } | |
916 | |
9 | 917 static void file_util_move_single_cancel_cb(GenericDialog *gd, gpointer data) |
1 | 918 { |
919 FileDataSingle *fds = data; | |
9 | 920 |
1 | 921 file_data_single_free(fds); |
922 } | |
923 | |
9 | 924 static void file_util_move_single_rename_auto_cb(GtkWidget *widget, gpointer data) |
925 { | |
926 GenericDialog *gd = data; | |
927 FileDataSingle *fds; | |
928 | |
929 fds = gd->data; | |
930 | |
931 fds->rename_auto = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | |
932 gtk_widget_set_sensitive(fds->rename_box, !fds->rename_auto); | |
933 gtk_widget_set_sensitive(fds->rename_entry, (!fds->rename_auto && fds->rename)); | |
934 | |
935 if (fds->rename_auto) | |
936 { | |
937 gchar *preview; | |
938 | |
939 preview = unique_filename_simple(fds->dest); | |
940 if (preview) gtk_entry_set_text(GTK_ENTRY(fds->rename_entry), filename_from_path(preview)); | |
941 g_free(preview); | |
942 } | |
943 } | |
944 | |
945 static void file_util_move_single_rename_cb(GtkWidget *widget, gpointer data) | |
946 { | |
947 GenericDialog *gd = data; | |
948 FileDataSingle *fds; | |
949 | |
950 fds = gd->data; | |
951 | |
952 fds->rename = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | |
953 gtk_widget_set_sensitive(fds->rename_entry, fds->rename); | |
954 | |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
955 if (fds->rename) |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
956 { |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
957 const gchar *name; |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
958 |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
959 gtk_widget_grab_focus(fds->rename_entry); |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
960 |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
961 name = gtk_entry_get_text(GTK_ENTRY(fds->rename_entry)); |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
962 gtk_editable_select_region(GTK_EDITABLE(fds->rename_entry), 0, filename_base_length(name)); |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
963 } |
9 | 964 } |
965 | |
1 | 966 static void file_util_move_single(FileDataSingle *fds) |
967 { | |
138 | 968 if (fds->dest && fds->source_fd && strcmp(fds->dest, fds->source_fd->name) == 0) |
3 | 969 { |
9 | 970 file_util_warning_dialog(_("Source matches destination"), |
971 _("Source and destination are the same, operation cancelled."), | |
972 GTK_STOCK_DIALOG_INFO, NULL); | |
3 | 973 } |
974 else if (isfile(fds->dest) && !fds->confirmed) | |
1 | 975 { |
9 | 976 GenericDialog *gd; |
977 GtkWidget *hbox; | |
978 | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
223
diff
changeset
|
979 gd = file_util_gen_dlg(_("Overwrite file"), GQ_WMCLASS, "dlg_confirm", |
9 | 980 NULL, TRUE, |
981 file_util_move_single_cancel_cb, fds); | |
982 | |
983 generic_dialog_add_message(gd, GTK_STOCK_DIALOG_QUESTION, | |
984 _("Overwrite file?"), | |
985 _("Replace existing file with new file.")); | |
986 pref_spacer(gd->vbox, 0); | |
987 | |
988 generic_dialog_add_button(gd, GTK_STOCK_OK, _("_Overwrite"), file_util_move_single_ok_cb, TRUE); | |
138 | 989 generic_dialog_add_image(gd, NULL, file_data_new_simple(fds->dest), _("Existing file"), fds->source_fd, _("New file"), TRUE); |
9 | 990 |
991 /* rename option */ | |
992 | |
993 fds->rename = FALSE; | |
994 fds->rename_auto = FALSE; | |
995 | |
996 hbox = pref_box_new(gd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP); | |
997 | |
998 fds->rename_auto_box = gtk_check_button_new_with_label(_("Auto rename")); | |
999 g_signal_connect(G_OBJECT(fds->rename_auto_box), "clicked", | |
1000 G_CALLBACK(file_util_move_single_rename_auto_cb), gd); | |
1001 gtk_box_pack_start(GTK_BOX(hbox), fds->rename_auto_box, FALSE, FALSE, 0); | |
1002 gtk_widget_show(fds->rename_auto_box); | |
1003 | |
1004 hbox = pref_box_new(gd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP); | |
1005 | |
1006 fds->rename_box = gtk_check_button_new_with_label(_("Rename")); | |
1007 g_signal_connect(G_OBJECT(fds->rename_box), "clicked", | |
1008 G_CALLBACK(file_util_move_single_rename_cb), gd); | |
1009 gtk_box_pack_start(GTK_BOX(hbox), fds->rename_box, FALSE, FALSE, 0); | |
1010 gtk_widget_show(fds->rename_box); | |
1011 | |
1012 fds->rename_entry = gtk_entry_new(); | |
1013 gtk_entry_set_text(GTK_ENTRY(fds->rename_entry), filename_from_path(fds->dest)); | |
1014 gtk_widget_set_sensitive(fds->rename_entry, FALSE); | |
1015 gtk_box_pack_start(GTK_BOX(hbox), fds->rename_entry, TRUE, TRUE, 0); | |
1016 gtk_widget_show(fds->rename_entry); | |
1017 | |
1018 gtk_widget_show(gd->dialog); | |
1 | 1019 return; |
1020 } | |
1021 else | |
1022 { | |
1023 gint success = FALSE; | |
1024 if (fds->copy) | |
1025 { | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1026 if (file_data_add_change_info(fds->source_fd, FILEDATA_CHANGE_COPY, fds->source_fd->path, fds->dest) && |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1027 copy_file_ext(fds->source_fd)) |
9 | 1028 { |
1029 success = TRUE; | |
1030 } | |
1 | 1031 } |
1032 else | |
1033 { | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1034 if (file_data_add_change_info(fds->source_fd, FILEDATA_CHANGE_MOVE, fds->source_fd->path, fds->dest) && |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1035 move_file_ext(fds->source_fd)) |
1 | 1036 { |
1037 success = TRUE; | |
1038 } | |
1039 } | |
1040 if (!success) | |
1041 { | |
1042 gchar *title; | |
1043 gchar *text; | |
1044 if (fds->copy) | |
1045 { | |
1046 title = _("Error copying file"); | |
138 | 1047 text = g_strdup_printf(_("Unable to copy file:\n%s\nto:\n%s"), fds->source_fd->name, fds->dest); |
1 | 1048 } |
1049 else | |
1050 { | |
1051 title = _("Error moving file"); | |
138 | 1052 text = g_strdup_printf(_("Unable to move file:\n%s\nto:\n%s"), fds->source_fd->name, fds->dest); |
1 | 1053 } |
9 | 1054 file_util_warning_dialog(title, text, GTK_STOCK_DIALOG_ERROR, NULL); |
1 | 1055 g_free(text); |
1056 } | |
1057 } | |
3 | 1058 |
1059 file_data_single_free(fds); | |
1 | 1060 } |
1061 | |
1062 /* | |
1063 * file move dialog | |
1064 */ | |
1065 | |
138 | 1066 static void file_util_move_do(FileDialog *fdlg) |
1 | 1067 { |
138 | 1068 file_dialog_sync_history(fdlg, TRUE); |
1069 | |
1070 if (fdlg->multiple_files) | |
1 | 1071 { |
138 | 1072 file_util_move_multiple(file_data_multiple_new(fdlg->source_list, fdlg->dest_path, fdlg->type)); |
1073 fdlg->source_list = NULL; | |
1 | 1074 } |
1075 else | |
1076 { | |
138 | 1077 if (isdir(fdlg->dest_path)) |
1 | 1078 { |
138 | 1079 gchar *buf = concat_dir_and_file(fdlg->dest_path, fdlg->source_fd->name); |
1080 gtk_entry_set_text(GTK_ENTRY(fdlg->entry), buf); | |
9 | 1081 g_free(buf); |
1 | 1082 } |
138 | 1083 file_util_move_single(file_data_single_new(fdlg->source_fd, fdlg->dest_path, fdlg->type)); |
1 | 1084 } |
1085 | |
138 | 1086 file_dialog_close(fdlg); |
1 | 1087 } |
1088 | |
138 | 1089 static void file_util_move_check(FileDialog *fdlg) |
1 | 1090 { |
138 | 1091 if (fdlg->dest_path && strcmp(fdlg->dest_path, "~") == 0) |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
1092 { |
138 | 1093 gtk_entry_set_text(GTK_ENTRY(fdlg->entry), homedir()); |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
1094 } |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
1095 |
138 | 1096 if (fdlg->multiple_files && !isdir(fdlg->dest_path)) |
1 | 1097 { |
138 | 1098 if (isfile(fdlg->dest_path)) |
9 | 1099 { |
1100 file_util_warning_dialog(_("Invalid destination"), | |
1101 _("When operating with multiple files, please select\na folder, not a file."), | |
1102 GTK_STOCK_DIALOG_INFO, NULL); | |
1103 } | |
1 | 1104 else |
9 | 1105 file_util_warning_dialog(_("Invalid folder"), |
1106 _("Please select an existing folder."), | |
1107 GTK_STOCK_DIALOG_INFO, NULL); | |
1 | 1108 return; |
1109 } | |
1110 | |
138 | 1111 if (!fdlg->dest_path || fdlg->dest_path[0] != '/') |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
1112 { |
138 | 1113 if (fdlg->source_fd) |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
1114 { |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
1115 gchar *base; |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
1116 gchar *path; |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
1117 |
138 | 1118 base = remove_level_from_path(fdlg->source_fd->path); |
1119 path = concat_dir_and_file(base, fdlg->dest_path); | |
1120 | |
1121 gtk_entry_set_text(GTK_ENTRY(fdlg->entry), path); | |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
1122 |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
1123 g_free(path); |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
1124 g_free(base); |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
1125 } |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
1126 return; |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
1127 } |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
1128 |
138 | 1129 file_util_move_do(fdlg); |
1 | 1130 } |
1131 | |
138 | 1132 static void file_util_move_cb(FileDialog *fdlg, gpointer data) |
1 | 1133 { |
138 | 1134 file_util_move_check(fdlg); |
1 | 1135 } |
1136 | |
138 | 1137 static void file_util_move_cancel_cb(FileDialog *fdlg, gpointer data) |
1 | 1138 { |
138 | 1139 file_dialog_close(fdlg); |
1 | 1140 } |
1141 | |
138 | 1142 static void real_file_util_move(FileData *source_fd, GList *source_list, |
9 | 1143 const gchar *dest_path, gint copy, GtkWidget *parent) |
1 | 1144 { |
138 | 1145 FileDialog *fdlg; |
9 | 1146 GtkWidget *label; |
138 | 1147 FileData *fd = NULL; |
1 | 1148 gint multiple; |
9 | 1149 const gchar *text; |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1150 gchar *title; |
9 | 1151 const gchar *op_text; |
1152 const gchar *stock_id; | |
1 | 1153 |
138 | 1154 if (!source_fd && !source_list) return; |
1155 | |
1156 if (source_fd) | |
1 | 1157 { |
138 | 1158 fd = file_data_ref(source_fd); |
1 | 1159 multiple = FALSE; |
1160 } | |
1161 else if (source_list->next) | |
1162 { | |
1163 multiple = TRUE; | |
1164 } | |
1165 else | |
1166 { | |
138 | 1167 fd = file_data_ref(source_list->data); |
1168 filelist_free(source_list); | |
1 | 1169 source_list = NULL; |
1170 multiple = FALSE; | |
1171 } | |
1172 | |
1173 if (copy) | |
1174 { | |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1175 title = g_strdup_printf("%s -%s", _("Copy"), GQ_APPNAME); |
9 | 1176 op_text = _("_Copy"); |
138 | 1177 if (fd) |
9 | 1178 { |
1179 text = _("Copy file"); | |
1180 } | |
1 | 1181 else |
9 | 1182 { |
1183 text = _("Copy multiple files"); | |
1184 } | |
1185 stock_id = GTK_STOCK_COPY; | |
1 | 1186 } |
1187 else | |
1188 { | |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1189 title = g_strdup_printf("%s -%s", _("Move"), GQ_APPNAME); |
9 | 1190 op_text = _("_Move"); |
138 | 1191 if (fd) |
9 | 1192 { |
1193 text = _("Move file"); | |
1194 } | |
1 | 1195 else |
9 | 1196 { |
1197 text = _("Move multiple files"); | |
1198 } | |
1199 stock_id = GTK_STOCK_OK; | |
1 | 1200 } |
1201 | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
223
diff
changeset
|
1202 fdlg = file_util_file_dlg(title, GQ_WMCLASS, "dlg_copymove", parent, |
9 | 1203 file_util_move_cancel_cb, NULL); |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1204 g_free(title); |
138 | 1205 generic_dialog_add_message(GENERIC_DIALOG(fdlg), NULL, text, NULL); |
1206 | |
1207 if (fd) | |
9 | 1208 { |
1209 GtkWidget *box; | |
1210 | |
138 | 1211 box = pref_box_new(GENERIC_DIALOG(fdlg)->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE); |
9 | 1212 pref_label_new(box, _("File name:")); |
138 | 1213 pref_label_new(box, fd->name); |
9 | 1214 } |
1215 | |
138 | 1216 label = pref_label_new(GENERIC_DIALOG(fdlg)->vbox, _("Choose the destination folder.")); |
9 | 1217 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); |
138 | 1218 pref_spacer(GENERIC_DIALOG(fdlg)->vbox, 0); |
1219 | |
1220 file_dialog_add_button(fdlg, stock_id, op_text, file_util_move_cb, TRUE); | |
1221 | |
1222 file_dialog_add_path_widgets(fdlg, NULL, dest_path, "move_copy", NULL, NULL); | |
1223 | |
1224 fdlg->type = copy; | |
1225 fdlg->source_fd = fd; | |
1226 fdlg->source_list = source_list; | |
1227 fdlg->multiple_files = multiple; | |
1228 | |
1229 gtk_widget_show(GENERIC_DIALOG(fdlg)->dialog); | |
9 | 1230 } |
1231 | |
138 | 1232 void file_util_move(FileData *source_fd, GList *source_list, const gchar *dest_path, GtkWidget *parent) |
9 | 1233 { |
138 | 1234 real_file_util_move(source_fd, source_list, dest_path, FALSE, parent); |
9 | 1235 } |
1236 | |
138 | 1237 void file_util_copy(FileData *source_fd, GList *source_list, const gchar *dest_path, GtkWidget *parent) |
9 | 1238 { |
138 | 1239 real_file_util_move(source_fd, source_list, dest_path, TRUE, parent); |
9 | 1240 } |
1241 | |
497 | 1242 void file_util_copy_path_to_clipboard(FileData *fd) |
1243 { | |
1244 GtkClipboard *clipboard; | |
1245 | |
1246 if (!fd || !*fd->path) return; | |
1247 | |
1248 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); | |
1249 gtk_clipboard_set_text(clipboard, g_shell_quote(fd->path), -1); | |
1250 } | |
1251 | |
1252 void file_util_copy_path_list_to_clipboard(GList *list) | |
1253 { | |
1254 GtkClipboard *clipboard; | |
1255 GList *work; | |
1256 GString *new; | |
1257 | |
1258 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); | |
1259 | |
1260 new = g_string_new(""); | |
1261 work = list; | |
1262 while (work) { | |
1263 FileData *fd = work->data; | |
1264 work = work->next; | |
1265 | |
1266 if (!fd || !*fd->path) continue; | |
1267 | |
1268 g_string_append(new, g_shell_quote(fd->path)); | |
1269 if (work) g_string_append_c(new, ' '); | |
1270 } | |
1271 | |
1272 gtk_clipboard_set_text(clipboard, new->str, new->len); | |
1273 g_string_free(new, TRUE); | |
1274 } | |
1275 | |
9 | 1276 void file_util_move_simple(GList *list, const gchar *dest_path) |
1277 { | |
1278 if (!list) return; | |
1279 if (!dest_path) | |
1280 { | |
138 | 1281 filelist_free(list); |
9 | 1282 return; |
1283 } | |
1284 | |
1285 if (!list->next) | |
1286 { | |
138 | 1287 FileData *source_fd; |
9 | 1288 gchar *dest; |
1289 | |
138 | 1290 source_fd = list->data; |
1291 dest = concat_dir_and_file(dest_path, source_fd->name); | |
1292 | |
1293 file_util_move_single(file_data_single_new(source_fd, dest, FALSE)); | |
9 | 1294 g_free(dest); |
138 | 1295 filelist_free(list); |
9 | 1296 return; |
1297 } | |
1298 | |
1299 file_util_move_multiple(file_data_multiple_new(list, dest_path, FALSE)); | |
1300 } | |
1301 | |
1302 void file_util_copy_simple(GList *list, const gchar *dest_path) | |
1303 { | |
1304 if (!list) return; | |
1305 if (!dest_path) | |
1 | 1306 { |
138 | 1307 filelist_free(list); |
9 | 1308 return; |
1309 } | |
1310 | |
1311 if (!list->next) | |
1312 { | |
138 | 1313 FileData *source_fd; |
9 | 1314 gchar *dest; |
1315 | |
138 | 1316 source_fd = list->data; |
1317 dest = concat_dir_and_file(dest_path, source_fd->name); | |
1318 | |
1319 file_util_move_single(file_data_single_new(source_fd, dest, TRUE)); | |
9 | 1320 g_free(dest); |
138 | 1321 filelist_free(list); |
9 | 1322 return; |
1 | 1323 } |
9 | 1324 |
1325 file_util_move_multiple(file_data_multiple_new(list, dest_path, TRUE)); | |
1326 } | |
1327 | |
1328 /* | |
1329 *-------------------------------------------------------------------------- | |
1330 * Safe Delete | |
1331 *-------------------------------------------------------------------------- | |
1332 */ | |
1333 | |
1334 static gint file_util_safe_number(gint64 free_space) | |
1335 { | |
1336 gint n = 0; | |
1337 gint64 total = 0; | |
1338 GList *list; | |
1339 GList *work; | |
1340 gint sorted = FALSE; | |
1341 gint warned = FALSE; | |
1342 | |
341
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
318
diff
changeset
|
1343 if (!filelist_read(options->file_ops.safe_delete_path, &list, NULL)) return 0; |
9 | 1344 |
1345 work = list; | |
1346 while (work) | |
1 | 1347 { |
9 | 1348 FileData *fd; |
1349 gint v; | |
442 | 1350 |
9 | 1351 fd = work->data; |
1352 work = work->next; | |
1353 | |
1354 v = (gint)strtol(fd->name, NULL, 10); | |
1355 if (v >= n) n = v + 1; | |
1356 | |
1357 total += fd->size; | |
1 | 1358 } |
9 | 1359 |
341
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
318
diff
changeset
|
1360 while (options->file_ops.safe_delete_folder_maxsize > 0 && list && |
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
318
diff
changeset
|
1361 (free_space < 0 || total + free_space > (gint64)options->file_ops.safe_delete_folder_maxsize * 1048576) ) |
9 | 1362 { |
1363 FileData *fd; | |
1364 | |
1365 if (!sorted) | |
1366 { | |
1367 list = filelist_sort(list, SORT_NAME, TRUE); | |
1368 sorted = TRUE; | |
1369 } | |
1370 | |
1371 fd = list->data; | |
1372 list = g_list_remove(list, fd); | |
1373 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
497
diff
changeset
|
1374 DEBUG_1("expunging from trash for space: %s", fd->name); |
9 | 1375 if (!unlink_file(fd->path) && !warned) |
1376 { | |
1377 file_util_warning_dialog(_("Delete failed"), | |
1378 _("Unable to remove old file from trash folder"), | |
1379 GTK_STOCK_DIALOG_WARNING, NULL); | |
1380 warned = TRUE; | |
1381 } | |
1382 total -= fd->size; | |
138 | 1383 file_data_unref(fd); |
9 | 1384 } |
1385 | |
1386 filelist_free(list); | |
1387 | |
1388 return n; | |
1389 } | |
1390 | |
1391 void file_util_trash_clear(void) | |
1392 { | |
1393 file_util_safe_number(-1); | |
1394 } | |
1395 | |
1396 static gchar *file_util_safe_dest(const gchar *path) | |
1397 { | |
1398 gint n; | |
1399 | |
1400 n = file_util_safe_number(filesize(path)); | |
341
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
318
diff
changeset
|
1401 return g_strdup_printf("%s/%06d_%s", options->file_ops.safe_delete_path, n, filename_from_path(path)); |
9 | 1402 } |
1403 | |
1404 static void file_util_safe_del_toggle_cb(GtkWidget *button, gpointer data) | |
1405 { | |
341
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
318
diff
changeset
|
1406 options->file_ops.safe_delete_enable = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)); |
9 | 1407 } |
1408 | |
1409 static void file_util_safe_del_close_cb(GtkWidget *dialog, gpointer data) | |
1410 { | |
1411 GenericDialog **gd = data; | |
1412 | |
1413 *gd = NULL; | |
1 | 1414 } |
1415 | |
138 | 1416 static gint file_util_unlink(FileData *fd) |
1 | 1417 { |
9 | 1418 static GenericDialog *gd = NULL; |
1419 gchar *result = NULL; | |
1420 gint success = TRUE; | |
1421 | |
138 | 1422 if (!isfile(fd->path)) return FALSE; |
9 | 1423 |
134
9009856628f7
started implementation of external commands; external Delete should work
nadvornik
parents:
115
diff
changeset
|
1424 |
341
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
318
diff
changeset
|
1425 if (!options->file_ops.safe_delete_enable) |
9 | 1426 { |
138 | 1427 return unlink_file(fd->path); |
9 | 1428 } |
1429 | |
341
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
318
diff
changeset
|
1430 if (!isdir(options->file_ops.safe_delete_path)) |
9 | 1431 { |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
497
diff
changeset
|
1432 DEBUG_1("creating trash: %s", options->file_ops.safe_delete_path); |
341
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
318
diff
changeset
|
1433 if (!options->file_ops.safe_delete_path || !mkdir_utf8(options->file_ops.safe_delete_path, 0755)) |
9 | 1434 { |
1435 result = _("Could not create folder"); | |
1436 success = FALSE; | |
1437 } | |
1438 } | |
1439 | |
1440 if (success) | |
1441 { | |
1442 gchar *dest; | |
1443 | |
138 | 1444 dest = file_util_safe_dest(fd->path); |
9 | 1445 if (dest) |
1446 { | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
497
diff
changeset
|
1447 DEBUG_1("safe deleting %s to %s", fd->path, dest); |
138 | 1448 success = move_file(fd->path, dest); |
9 | 1449 } |
1450 else | |
1451 { | |
1452 success = FALSE; | |
1453 } | |
1454 | |
138 | 1455 if (!success && !access_file(fd->path, W_OK)) |
9 | 1456 { |
1457 result = _("Permission denied"); | |
1458 } | |
1459 g_free(dest); | |
1460 } | |
1461 | |
1462 if (result && !gd) | |
1463 { | |
1464 GtkWidget *button; | |
1465 gchar *buf; | |
1466 | |
341
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
318
diff
changeset
|
1467 buf = g_strdup_printf(_("Unable to access or create the trash folder.\n\"%s\""), options->file_ops.safe_delete_path); |
9 | 1468 gd = file_util_warning_dialog(result, buf, GTK_STOCK_DIALOG_WARNING, NULL); |
1469 g_free(buf); | |
1470 | |
1471 button = gtk_check_button_new_with_label(_("Turn off safe delete")); | |
1472 g_signal_connect(G_OBJECT(button), "toggled", | |
1473 G_CALLBACK(file_util_safe_del_toggle_cb), NULL); | |
1474 gtk_box_pack_start(GTK_BOX(gd->vbox), button, FALSE, FALSE, 0); | |
1475 gtk_widget_show(button); | |
1476 | |
1477 g_signal_connect(G_OBJECT(gd->dialog), "destroy", | |
1478 G_CALLBACK(file_util_safe_del_close_cb), &gd); | |
1479 } | |
1480 | |
1481 return success; | |
1 | 1482 } |
1483 | |
9 | 1484 static void box_append_safe_delete_status(GenericDialog *gd) |
1 | 1485 { |
9 | 1486 GtkWidget *label; |
1487 gchar *buf; | |
1488 | |
318 | 1489 if (options->editor_command[CMD_DELETE]) |
223
73efc1ba150f
Setting no limit size to trash directory is now possible using zero as value.
zas_
parents:
196
diff
changeset
|
1490 { |
73efc1ba150f
Setting no limit size to trash directory is now possible using zero as value.
zas_
parents:
196
diff
changeset
|
1491 buf = g_strdup(_("Deletion by external command")); |
73efc1ba150f
Setting no limit size to trash directory is now possible using zero as value.
zas_
parents:
196
diff
changeset
|
1492 } |
73efc1ba150f
Setting no limit size to trash directory is now possible using zero as value.
zas_
parents:
196
diff
changeset
|
1493 else |
73efc1ba150f
Setting no limit size to trash directory is now possible using zero as value.
zas_
parents:
196
diff
changeset
|
1494 { |
341
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
318
diff
changeset
|
1495 if (options->file_ops.safe_delete_enable) |
223
73efc1ba150f
Setting no limit size to trash directory is now possible using zero as value.
zas_
parents:
196
diff
changeset
|
1496 { |
73efc1ba150f
Setting no limit size to trash directory is now possible using zero as value.
zas_
parents:
196
diff
changeset
|
1497 gchar *buf2; |
341
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
318
diff
changeset
|
1498 if (options->file_ops.safe_delete_folder_maxsize > 0) |
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
318
diff
changeset
|
1499 buf2 = g_strdup_printf(_(" (max. %d MB)"), options->file_ops.safe_delete_folder_maxsize); |
223
73efc1ba150f
Setting no limit size to trash directory is now possible using zero as value.
zas_
parents:
196
diff
changeset
|
1500 else |
73efc1ba150f
Setting no limit size to trash directory is now possible using zero as value.
zas_
parents:
196
diff
changeset
|
1501 buf2 = g_strdup(""); |
73efc1ba150f
Setting no limit size to trash directory is now possible using zero as value.
zas_
parents:
196
diff
changeset
|
1502 |
341
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
318
diff
changeset
|
1503 buf = g_strdup_printf(_("Safe delete: %s%s\nTrash: %s"), _("on"), buf2, options->file_ops.safe_delete_path); |
223
73efc1ba150f
Setting no limit size to trash directory is now possible using zero as value.
zas_
parents:
196
diff
changeset
|
1504 g_free(buf2); |
73efc1ba150f
Setting no limit size to trash directory is now possible using zero as value.
zas_
parents:
196
diff
changeset
|
1505 } |
73efc1ba150f
Setting no limit size to trash directory is now possible using zero as value.
zas_
parents:
196
diff
changeset
|
1506 else |
73efc1ba150f
Setting no limit size to trash directory is now possible using zero as value.
zas_
parents:
196
diff
changeset
|
1507 { |
73efc1ba150f
Setting no limit size to trash directory is now possible using zero as value.
zas_
parents:
196
diff
changeset
|
1508 buf = g_strdup_printf(_("Safe delete: %s"), _("off")); |
73efc1ba150f
Setting no limit size to trash directory is now possible using zero as value.
zas_
parents:
196
diff
changeset
|
1509 } |
73efc1ba150f
Setting no limit size to trash directory is now possible using zero as value.
zas_
parents:
196
diff
changeset
|
1510 } |
73efc1ba150f
Setting no limit size to trash directory is now possible using zero as value.
zas_
parents:
196
diff
changeset
|
1511 |
9 | 1512 label = pref_label_new(gd->vbox, buf); |
1513 g_free(buf); | |
1514 | |
1515 gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5); | |
1516 gtk_widget_set_sensitive(label, FALSE); | |
1 | 1517 } |
1518 | |
1519 /* | |
1520 *-------------------------------------------------------------------------- | |
1521 * Delete routines | |
1522 *-------------------------------------------------------------------------- | |
1523 */ | |
1524 | |
1525 /* | |
1526 * delete multiple files | |
1527 */ | |
1528 | |
9 | 1529 static void file_util_delete_multiple_ok_cb(GenericDialog *gd, gpointer data); |
1530 static void file_util_delete_multiple_cancel_cb(GenericDialog *gd, gpointer data); | |
1531 | |
140 | 1532 static void file_util_delete_ext_ok_cb(GenericDialog *gd, gpointer data) |
1533 { | |
1534 editor_resume(data); | |
1535 } | |
1536 | |
1537 static void file_util_delete_ext_cancel_cb(GenericDialog *gd, gpointer data) | |
1538 { | |
1539 editor_skip(data); | |
1540 } | |
1541 | |
1542 | |
1543 static gint file_util_delete_ext_cb(gpointer resume_data, gint flags, GList *list, gpointer data) | |
1544 { | |
1545 gint ret = EDITOR_CB_CONTINUE; | |
1546 if ((flags & EDITOR_ERROR_MASK) && !(flags & EDITOR_ERROR_SKIPPED)) | |
1547 { | |
1548 GString *msg = g_string_new(editor_get_error_str(flags)); | |
442 | 1549 g_string_append(msg,_("\nUnable to delete file by external command:\n")); |
140 | 1550 GenericDialog *d; |
1551 while (list) | |
1552 { | |
1553 FileData *fd = list->data; | |
442 | 1554 |
140 | 1555 g_string_append(msg, fd->path); |
1556 g_string_append(msg, "\n"); | |
1557 list = list->next; | |
1558 } | |
1559 if (resume_data) | |
1560 { | |
1561 g_string_append(msg, _("\n Continue multiple delete operation?")); | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
223
diff
changeset
|
1562 d = file_util_gen_dlg(_("Delete failed"), GQ_WMCLASS, "dlg_confirm", |
140 | 1563 NULL, TRUE, |
1564 file_util_delete_ext_cancel_cb, resume_data); | |
1565 | |
1566 generic_dialog_add_message(d, GTK_STOCK_DIALOG_WARNING, NULL, msg->str); | |
1567 | |
1568 generic_dialog_add_button(d, GTK_STOCK_GO_FORWARD, _("Co_ntinue"), | |
1569 file_util_delete_ext_ok_cb, TRUE); | |
1570 gtk_widget_show(d->dialog); | |
1571 ret = EDITOR_CB_SUSPEND; | |
1572 } | |
1573 else | |
1574 { | |
1575 file_util_warning_dialog(_("Delete failed"), msg->str, GTK_STOCK_DIALOG_ERROR, NULL); | |
1576 } | |
1577 g_string_free(msg, TRUE); | |
1578 } | |
442 | 1579 |
1580 | |
140 | 1581 { |
1582 while (list) | |
1583 { | |
1584 FileData *fd = list->data; | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1585 if (flags & EDITOR_ERROR_MASK) |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1586 /* an error occured -> no change -> delete change info */ |
442 | 1587 file_data_change_info_free(NULL, fd); |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1588 else |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1589 /* files were successfully deleted, call the maint functions and keep the change info forever */ |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1590 file_maint_removed(fd, list); |
140 | 1591 list = list->next; |
1592 } | |
1593 } | |
1594 return ret; | |
1595 } | |
1596 | |
9 | 1597 static void file_util_delete_multiple_ok_cb(GenericDialog *gd, gpointer data) |
1 | 1598 { |
1599 GList *source_list = data; | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1600 GList *work = source_list; |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1601 gboolean ok = TRUE; |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1602 |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1603 while (work) |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1604 { |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1605 FileData *fd = work->data; |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1606 if (fd->change) ok = FALSE; /* another operation in progress */ |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1607 work = work->next; |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1608 } |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1609 |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1610 if (!ok) |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1611 { |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1612 file_util_warning_dialog(_("File deletion failed"), _("Another operation in progress.\n"), GTK_STOCK_DIALOG_ERROR, NULL); |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1613 filelist_free(source_list); |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1614 return; |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1615 } |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1616 |
1 | 1617 |
318 | 1618 if (options->editor_command[CMD_DELETE]) |
135 | 1619 { |
140 | 1620 gint flags; |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1621 work = source_list; |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1622 while (work) |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1623 { |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1624 FileData *fd = work->data; |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1625 file_data_add_change_info(fd, FILEDATA_CHANGE_DELETE, NULL, NULL); |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1626 work = work->next; |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1627 } |
442 | 1628 |
140 | 1629 if ((flags = start_editor_from_filelist_full(CMD_DELETE, source_list, file_util_delete_ext_cb, NULL))) |
135 | 1630 { |
442 | 1631 gchar *text = g_strdup_printf(_("%s\nUnable to delete files by external command.\n"), editor_get_error_str(flags)); |
140 | 1632 file_util_warning_dialog(_("File deletion failed"), text, GTK_STOCK_DIALOG_ERROR, NULL); |
1633 g_free(text); | |
135 | 1634 } |
442 | 1635 |
140 | 1636 filelist_free(source_list); |
135 | 1637 return; |
1638 } | |
1639 | |
1640 | |
9 | 1641 while (source_list) |
1 | 1642 { |
138 | 1643 FileData *fd = source_list->data; |
1644 | |
1645 source_list = g_list_remove(source_list, fd); | |
1646 | |
1647 if (!file_util_unlink(fd)) | |
1 | 1648 { |
1649 if (source_list) | |
1650 { | |
9 | 1651 GenericDialog *d; |
1652 gchar *text; | |
1653 | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
223
diff
changeset
|
1654 d = file_util_gen_dlg(_("Delete failed"), GQ_WMCLASS, "dlg_confirm", |
9 | 1655 NULL, TRUE, |
1656 file_util_delete_multiple_cancel_cb, source_list); | |
1657 | |
138 | 1658 text = g_strdup_printf(_("Unable to delete file:\n %s\n Continue multiple delete operation?"), fd->path); |
9 | 1659 generic_dialog_add_message(d, GTK_STOCK_DIALOG_WARNING, NULL, text); |
1660 g_free(text); | |
1661 | |
1662 generic_dialog_add_button(d, GTK_STOCK_GO_FORWARD, _("Co_ntinue"), | |
1663 file_util_delete_multiple_ok_cb, TRUE); | |
1664 gtk_widget_show(d->dialog); | |
1 | 1665 } |
1666 else | |
1667 { | |
9 | 1668 gchar *text; |
442 | 1669 |
138 | 1670 text = g_strdup_printf(_("Unable to delete file:\n%s"), fd->path); |
9 | 1671 file_util_warning_dialog(_("Delete failed"), text, GTK_STOCK_DIALOG_ERROR, NULL); |
1672 g_free(text); | |
1 | 1673 } |
138 | 1674 file_data_unref(fd); |
1 | 1675 return; |
1676 } | |
1677 else | |
1678 { | |
138 | 1679 file_maint_removed(fd, source_list); |
1 | 1680 } |
138 | 1681 file_data_unref(fd); |
1 | 1682 } |
1683 } | |
1684 | |
9 | 1685 static void file_util_delete_multiple_cancel_cb(GenericDialog *gd, gpointer data) |
1 | 1686 { |
1687 GList *source_list = data; | |
9 | 1688 |
138 | 1689 filelist_free(source_list); |
1 | 1690 } |
1691 | |
9 | 1692 static void file_util_delete_multiple_review_skip(GenericDialog *gd, gint next) |
1693 { | |
1694 GtkWidget *button_back; | |
1695 GtkWidget *button_next; | |
1696 GtkWidget *button_label; | |
1697 GList *list; | |
1698 GList *list_point; | |
138 | 1699 FileData *fd; |
9 | 1700 gchar *buf; |
1701 | |
1702 list = gd->data; | |
1703 button_back = g_object_get_data(G_OBJECT(gd->dialog), "button_back"); | |
1704 button_next = g_object_get_data(G_OBJECT(gd->dialog), "button_next"); | |
1705 button_label = g_object_get_data(G_OBJECT(gd->dialog), "button_label"); | |
1706 list_point = g_object_get_data(G_OBJECT(gd->dialog), "list_point"); | |
1707 | |
1708 if (!list || !button_label) return; | |
1709 | |
1710 if (list_point) | |
1711 { | |
1712 if (next) | |
1713 { | |
1714 if (list_point->next) list_point = list_point->next; | |
1715 } | |
1716 else | |
1717 { | |
1718 if (list_point->prev) list_point = list_point->prev; | |
1719 } | |
1720 } | |
1721 else | |
1722 { | |
1723 list_point = list; | |
1724 } | |
1725 | |
1726 if (!list_point) return; | |
1727 | |
138 | 1728 fd = list_point->data; |
9 | 1729 buf = g_strdup_printf(_("File %d of %d"), |
138 | 1730 g_list_index(list, (gpointer)fd) + 1, |
9 | 1731 g_list_length(list)); |
1732 gtk_label_set_text(GTK_LABEL(button_label), buf); | |
1733 g_free(buf); | |
1734 | |
1735 gtk_widget_set_sensitive(button_back, (list_point->prev != NULL) ); | |
1736 gtk_widget_set_sensitive(button_next, (list_point->next != NULL) ); | |
1737 | |
138 | 1738 generic_dialog_image_set(gd, fd); |
9 | 1739 |
1740 g_object_set_data(G_OBJECT(gd->dialog), "list_point", list_point); | |
1741 } | |
1742 | |
1743 static void file_util_delete_multiple_review_back(GtkWidget *button, gpointer data) | |
1744 { | |
1745 GenericDialog *gd = data; | |
1746 | |
1747 file_util_delete_multiple_review_skip(gd, FALSE); | |
1748 } | |
1749 | |
1750 static void file_util_delete_multiple_review_next(GtkWidget *button, gpointer data) | |
1751 { | |
1752 GenericDialog *gd = data; | |
1753 | |
1754 file_util_delete_multiple_review_skip(gd, TRUE); | |
1755 } | |
1756 | |
1757 static void file_util_delete_multiple_review_button_cb(ImageWindow *imd, gint button, guint32 time, | |
1758 gdouble x, gdouble y, guint state, gpointer data) | |
1759 { | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1760 if (button == MOUSE_BUTTON_LEFT) |
9 | 1761 { |
1762 file_util_delete_multiple_review_next(NULL, data); | |
1763 } | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1764 else if (button == MOUSE_BUTTON_MIDDLE || button == MOUSE_BUTTON_RIGHT) |
9 | 1765 { |
1766 file_util_delete_multiple_review_back(NULL, data); | |
1767 } | |
1768 } | |
1769 | |
1770 static void file_util_delete_multiple_review_scroll_cb(ImageWindow *imd, GdkScrollDirection direction, guint32 time, | |
1771 gdouble x, gdouble y, guint state, gpointer data) | |
1772 { | |
1773 if (direction == GDK_SCROLL_UP) | |
1774 { | |
1775 file_util_delete_multiple_review_back(NULL, data); | |
1776 } | |
1777 else if (direction == GDK_SCROLL_DOWN) | |
1778 { | |
1779 file_util_delete_multiple_review_next(NULL, data); | |
1780 } | |
1781 } | |
1782 | |
1783 static void file_util_delete_multiple(GList *source_list, GtkWidget *parent) | |
1 | 1784 { |
341
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
318
diff
changeset
|
1785 if (!options->file_ops.confirm_delete) |
1 | 1786 { |
1787 file_util_delete_multiple_ok_cb(NULL, source_list); | |
1788 } | |
1789 else | |
1790 { | |
9 | 1791 GenericDialog *gd; |
1792 GtkWidget *hbox; | |
1793 GtkWidget *button; | |
1794 GtkWidget *label; | |
1795 ImageWindow *imd; | |
1796 gchar *buf; | |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1797 gchar *title = g_strdup_printf("%s -%s", _("Delete files"), GQ_APPNAME); |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1798 |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1799 gd = file_util_gen_dlg(title, GQ_WMCLASS, "dlg_confirm", parent, TRUE, |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1800 file_util_delete_multiple_cancel_cb, source_list); |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1801 g_free(title); |
442 | 1802 |
9 | 1803 generic_dialog_add_message(gd, NULL, _("Delete multiple files"), NULL); |
1804 | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
1805 generic_dialog_add_image(gd, NULL, NULL, NULL, NULL, NULL, TRUE); |
9 | 1806 imd = g_object_get_data(G_OBJECT(gd->dialog), "img_image"); |
1807 image_set_button_func(imd, file_util_delete_multiple_review_button_cb, gd); | |
1808 image_set_scroll_func(imd, file_util_delete_multiple_review_scroll_cb, gd); | |
1809 | |
1810 hbox = pref_box_new(gd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_BUTTON_GAP); | |
1811 | |
1812 button = pref_button_new(hbox, GTK_STOCK_GO_BACK, NULL, TRUE, | |
1813 G_CALLBACK(file_util_delete_multiple_review_back), gd); | |
1814 gtk_widget_set_sensitive(button, FALSE); | |
1815 g_object_set_data(G_OBJECT(gd->dialog), "button_back", button); | |
1816 | |
1817 button = pref_button_new(hbox, GTK_STOCK_GO_FORWARD, NULL, TRUE, | |
1818 G_CALLBACK(file_util_delete_multiple_review_next), gd); | |
1819 g_object_set_data(G_OBJECT(gd->dialog), "button_next", button); | |
1820 | |
1821 buf = g_strdup_printf(_("Review %d files"), g_list_length(source_list) ); | |
1822 label = pref_label_new(hbox, buf); | |
1823 g_free(buf); | |
1824 g_object_set_data(G_OBJECT(gd->dialog), "button_label", label); | |
1825 | |
1826 box_append_safe_delete_status(gd); | |
1827 | |
1828 generic_dialog_add_button(gd, GTK_STOCK_DELETE, NULL, file_util_delete_multiple_ok_cb, TRUE); | |
1829 | |
1830 gtk_widget_show(gd->dialog); | |
1 | 1831 } |
1832 } | |
1833 | |
1834 /* | |
1835 * delete single file | |
1836 */ | |
1837 | |
9 | 1838 static void file_util_delete_ok_cb(GenericDialog *gd, gpointer data) |
1 | 1839 { |
138 | 1840 FileData *fd = data; |
1 | 1841 |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1842 if (!file_data_add_change_info(fd, FILEDATA_CHANGE_DELETE, NULL, NULL)) |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1843 { |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1844 file_util_warning_dialog(_("File deletion failed"), _("Another operation in progress.\n"), GTK_STOCK_DIALOG_ERROR, NULL); |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1845 file_data_unref(fd); |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1846 return; |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1847 } |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1848 |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1849 |
318 | 1850 if (options->editor_command[CMD_DELETE]) |
135 | 1851 { |
140 | 1852 gint flags; |
1853 if ((flags = start_editor_from_file_full(CMD_DELETE, fd, file_util_delete_ext_cb, NULL))) | |
135 | 1854 { |
140 | 1855 gchar *text = g_strdup_printf(_("%s\nUnable to delete file by external command:\n%s"), editor_get_error_str(flags), fd->path); |
135 | 1856 file_util_warning_dialog(_("File deletion failed"), text, GTK_STOCK_DIALOG_ERROR, NULL); |
1857 g_free(text); | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1858 file_data_change_info_free(NULL, fd); |
135 | 1859 } |
1860 } | |
138 | 1861 else if (!file_util_unlink(fd)) |
1 | 1862 { |
138 | 1863 gchar *text = g_strdup_printf(_("Unable to delete file:\n%s"), fd->path); |
9 | 1864 file_util_warning_dialog(_("File deletion failed"), text, GTK_STOCK_DIALOG_ERROR, NULL); |
1 | 1865 g_free(text); |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
1866 file_data_change_info_free(NULL, fd); |
1 | 1867 } |
1868 else | |
1869 { | |
138 | 1870 file_maint_removed(fd, NULL); |
1 | 1871 } |
1872 | |
138 | 1873 file_data_unref(fd); |
1 | 1874 } |
1875 | |
9 | 1876 static void file_util_delete_cancel_cb(GenericDialog *gd, gpointer data) |
1 | 1877 { |
138 | 1878 FileData *fd = data; |
1879 | |
1880 file_data_unref(fd); | |
1 | 1881 } |
1882 | |
138 | 1883 static void file_util_delete_single(FileData *fd, GtkWidget *parent) |
1 | 1884 { |
341
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
318
diff
changeset
|
1885 if (!options->file_ops.confirm_delete) |
1 | 1886 { |
138 | 1887 file_util_delete_ok_cb(NULL, file_data_ref(fd)); |
1 | 1888 } |
1889 else | |
1890 { | |
9 | 1891 GenericDialog *gd; |
1892 GtkWidget *table; | |
1893 gchar *base; | |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1894 gchar *title = g_strdup_printf("%s -%s", _("Delete file"), GQ_APPNAME); |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1895 |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1896 gd = file_util_gen_dlg(title, GQ_WMCLASS, "dlg_confirm", parent, TRUE, |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1897 file_util_delete_cancel_cb, file_data_ref(fd)); |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1898 g_free(title); |
9 | 1899 |
1900 generic_dialog_add_message(gd, NULL, _("Delete file?"), NULL); | |
1901 | |
1902 table = pref_table_new(gd->vbox, 2, 2, FALSE, FALSE); | |
1903 | |
1904 pref_table_label(table, 0, 0, _("File name:"), 1.0); | |
138 | 1905 pref_table_label(table, 1, 0, fd->name, 0.0); |
9 | 1906 |
1907 pref_table_label(table, 0, 1, _("Location:"), 1.0); | |
1908 | |
138 | 1909 base = remove_level_from_path(fd->path); |
9 | 1910 pref_table_label(table, 1, 1, base, 0.0); |
1911 g_free(base); | |
1912 | |
138 | 1913 generic_dialog_add_image(gd, NULL, fd, NULL, NULL, NULL, FALSE); |
9 | 1914 |
1915 box_append_safe_delete_status(gd); | |
1916 | |
1917 generic_dialog_add_button(gd, GTK_STOCK_DELETE, NULL, file_util_delete_ok_cb, TRUE); | |
1918 | |
1919 gtk_widget_show(gd->dialog); | |
1 | 1920 } |
1921 } | |
1922 | |
138 | 1923 void file_util_delete(FileData *source_fd, GList *source_list, GtkWidget *parent) |
1 | 1924 { |
138 | 1925 if (!source_fd && !source_list) return; |
1926 | |
1927 if (source_fd) | |
1 | 1928 { |
138 | 1929 file_util_delete_single(source_fd, parent); |
1 | 1930 } |
1931 else if (!source_list->next) | |
1932 { | |
9 | 1933 file_util_delete_single(source_list->data, parent); |
138 | 1934 filelist_free(source_list); |
1 | 1935 } |
1936 else | |
1937 { | |
9 | 1938 file_util_delete_multiple(source_list, parent); |
1 | 1939 } |
1940 } | |
1941 | |
1942 /* | |
1943 *-------------------------------------------------------------------------- | |
1944 * Rename routines | |
1945 *-------------------------------------------------------------------------- | |
1946 */ | |
1947 | |
1948 /* | |
1949 * rename multiple files | |
1950 */ | |
1951 | |
9 | 1952 enum { |
138 | 1953 RENAME_COLUMN_FD = 0, |
1954 RENAME_COLUMN_PATH, | |
9 | 1955 RENAME_COLUMN_NAME, |
1956 RENAME_COLUMN_PREVIEW, | |
1957 RENAME_COLUMN_COUNT | |
1958 }; | |
1959 | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1960 typedef enum { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1961 RENAME_TYPE_MANUAL = 0, |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1962 RENAME_TYPE_FORMATTED, |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1963 RENAME_TYPE_AUTO |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1964 } RenameType; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1965 |
9 | 1966 typedef struct _RenameDataMult RenameDataMult; |
1967 struct _RenameDataMult | |
1 | 1968 { |
138 | 1969 FileDialog *fdlg; |
9 | 1970 |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1971 RenameType rename_type; |
9 | 1972 |
1973 GtkWidget *listview; | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1974 GtkWidget *combo_type; |
9 | 1975 |
1976 GtkWidget *rename_box; | |
1977 GtkWidget *rename_label; | |
1978 GtkWidget *rename_entry; | |
1979 | |
1980 GtkWidget *auto_box; | |
1981 GtkWidget *auto_entry_front; | |
1982 GtkWidget *auto_spin_start; | |
1983 GtkWidget *auto_spin_pad; | |
1984 GtkWidget *auto_entry_end; | |
1985 | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1986 GtkWidget *format_box; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1987 GtkWidget *format_entry; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1988 GtkWidget *format_spin; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1989 |
9 | 1990 ImageWindow *imd; |
1991 | |
1992 gint update_idle_id; | |
1993 }; | |
1994 | |
1995 static void file_util_rename_multiple(RenameDataMult *rd); | |
1996 | |
1997 static void file_util_rename_multiple_ok_cb(GenericDialog *gd, gpointer data) | |
1998 { | |
1999 RenameDataMult *rd = data; | |
2000 GtkWidget *dialog; | |
2001 | |
138 | 2002 dialog = GENERIC_DIALOG(rd->fdlg)->dialog; |
9 | 2003 if (!GTK_WIDGET_VISIBLE(dialog)) gtk_widget_show(dialog); |
2004 | |
138 | 2005 rd->fdlg->type = TRUE; |
9 | 2006 file_util_rename_multiple(rd); |
1 | 2007 } |
2008 | |
9 | 2009 static void file_util_rename_multiple_cancel_cb(GenericDialog *gd, gpointer data) |
2010 { | |
2011 RenameDataMult *rd = data; | |
2012 GtkWidget *dialog; | |
2013 | |
138 | 2014 dialog = GENERIC_DIALOG(rd->fdlg)->dialog; |
9 | 2015 if (!GTK_WIDGET_VISIBLE(dialog)) gtk_widget_show(dialog); |
2016 } | |
2017 | |
138 | 2018 static gint file_util_rename_multiple_find_row(RenameDataMult *rd, FileData *fd, GtkTreeIter *iter) |
1 | 2019 { |
9 | 2020 GtkTreeModel *store; |
2021 gint valid; | |
2022 gint row = 0; | |
2023 | |
2024 store = gtk_tree_view_get_model(GTK_TREE_VIEW(rd->listview)); | |
2025 valid = gtk_tree_model_get_iter_first(store, iter); | |
2026 while (valid) | |
2027 { | |
138 | 2028 FileData *fd_n; |
9 | 2029 gint ret; |
2030 | |
138 | 2031 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, RENAME_COLUMN_FD, &fd_n, -1); |
2032 ret = (fd_n == fd); | |
2033 // file_data_unref(fd_n); | |
9 | 2034 if (ret) return row; |
2035 | |
2036 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), iter); | |
2037 row++; | |
2038 } | |
2039 | |
2040 return -1; | |
1 | 2041 } |
2042 | |
9 | 2043 static void file_util_rename_multiple(RenameDataMult *rd) |
1 | 2044 { |
138 | 2045 FileDialog *fdlg; |
2046 | |
2047 fdlg = rd->fdlg; | |
2048 | |
2049 if (isfile(fdlg->dest_path) && !fdlg->type) | |
1 | 2050 { |
9 | 2051 GenericDialog *gd; |
2052 | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
223
diff
changeset
|
2053 gd = file_util_gen_dlg(_("Overwrite file"), GQ_WMCLASS, "dlg_confirm", |
9 | 2054 NULL, TRUE, |
2055 file_util_rename_multiple_cancel_cb, rd); | |
2056 | |
2057 generic_dialog_add_message(gd, GTK_STOCK_DIALOG_QUESTION, | |
2058 _("Overwrite file?"), | |
2059 _("Replace existing file by renaming new file.")); | |
2060 pref_spacer(gd->vbox, 0); | |
2061 | |
2062 generic_dialog_add_button(gd, GTK_STOCK_OK, _("_Overwrite"), file_util_rename_multiple_ok_cb, TRUE); | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
2063 generic_dialog_add_image(gd, NULL, |
138 | 2064 file_data_new_simple(fdlg->dest_path), _("Existing file"), |
2065 fdlg->source_fd, _("New file"), TRUE); | |
2066 | |
2067 gtk_widget_hide(GENERIC_DIALOG(fdlg)->dialog); | |
9 | 2068 |
2069 gtk_widget_show(gd->dialog); | |
1 | 2070 return; |
2071 } | |
2072 else | |
2073 { | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
2074 if (!file_data_add_change_info(fdlg->source_fd, FILEDATA_CHANGE_RENAME, fdlg->source_fd->path, fdlg->dest_path) || |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
2075 !rename_file_ext(fdlg->source_fd)) |
1 | 2076 { |
9 | 2077 gchar *text = g_strdup_printf(_("Unable to rename file:\n%s\n to:\n%s"), |
138 | 2078 fdlg->source_fd->name, |
2079 filename_from_path(fdlg->dest_path)); | |
9 | 2080 file_util_warning_dialog(_("Error renaming file"), text, GTK_STOCK_DIALOG_ERROR, NULL); |
1 | 2081 g_free(text); |
2082 } | |
2083 else | |
2084 { | |
9 | 2085 GtkTreeModel *store; |
2086 GtkTreeIter iter; | |
2087 GtkTreeIter next; | |
1 | 2088 gint row; |
9 | 2089 |
2090 store = gtk_tree_view_get_model(GTK_TREE_VIEW(rd->listview)); | |
138 | 2091 row = file_util_rename_multiple_find_row(rd, rd->fdlg->source_fd, &iter); |
9 | 2092 |
2093 if (row >= 0 && | |
2094 (gtk_tree_model_iter_nth_child(store, &next, NULL, row + 1) || | |
2095 (row > 0 && gtk_tree_model_iter_nth_child(store, &next, NULL, row - 1)) ) ) | |
1 | 2096 { |
9 | 2097 GtkTreeSelection *selection; |
2098 | |
2099 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(rd->listview)); | |
2100 gtk_tree_selection_select_iter(selection, &next); | |
2101 gtk_list_store_remove(GTK_LIST_STORE(store), &iter); | |
1 | 2102 } |
2103 else | |
2104 { | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
497
diff
changeset
|
2105 DEBUG_1("closed by #%d", row); |
9 | 2106 |
138 | 2107 file_dialog_close(rd->fdlg); |
1 | 2108 } |
2109 } | |
2110 } | |
2111 } | |
2112 | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2113 /* format: * = filename without extension, ## = number position, extension is kept */ |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2114 static gchar *file_util_rename_multiple_auto_format_name(const gchar *format, const gchar *name, gint n) |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2115 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2116 gchar *new_name; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2117 gchar *parsed; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2118 const gchar *ext; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2119 gchar *middle; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2120 gchar *tmp; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2121 gchar *pad_start; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2122 gchar *pad_end; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2123 gint padding; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2124 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2125 if (!format || !name) return NULL; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2126 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2127 tmp = g_strdup(format); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2128 pad_start = strchr(tmp, '#'); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2129 if (pad_start) |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2130 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2131 pad_end = pad_start; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2132 padding = 0; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2133 while (*pad_end == '#') |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2134 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2135 pad_end++; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2136 padding++; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2137 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2138 *pad_start = '\0'; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2139 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2140 parsed = g_strdup_printf("%s%0*d%s", tmp, padding, n, pad_end); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2141 g_free(tmp); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2142 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2143 else |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2144 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2145 parsed = tmp; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2146 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2147 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2148 ext = extension_from_path(name); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2149 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2150 middle = strchr(parsed, '*'); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2151 if (middle) |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2152 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2153 gchar *base; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2154 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2155 *middle = '\0'; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2156 middle++; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2157 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2158 base = remove_extension_from_path(name); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2159 new_name = g_strconcat(parsed, base, middle, ext, NULL); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2160 g_free(base); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2161 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2162 else |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2163 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2164 new_name = g_strconcat(parsed, ext, NULL); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2165 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2166 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2167 g_free(parsed); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2168 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2169 return new_name; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2170 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2171 |
9 | 2172 static void file_util_rename_multiple_auto(RenameDataMult *rd) |
1 | 2173 { |
9 | 2174 const gchar *front; |
2175 const gchar *end; | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2176 const gchar *format; |
9 | 2177 gint start_n; |
2178 gint padding; | |
2179 gint n; | |
2180 GtkTreeModel *store; | |
2181 GtkTreeIter iter; | |
2182 gint valid; | |
2183 gint success; | |
2184 | |
2185 front = gtk_entry_get_text(GTK_ENTRY(rd->auto_entry_front)); | |
2186 end = gtk_entry_get_text(GTK_ENTRY(rd->auto_entry_end)); | |
2187 padding = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(rd->auto_spin_pad)); | |
2188 | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2189 format = gtk_entry_get_text(GTK_ENTRY(rd->format_entry)); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2190 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2191 if (rd->rename_type == RENAME_TYPE_FORMATTED) |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2192 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2193 start_n = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(rd->format_spin)); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2194 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2195 if (!format || |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2196 (strchr(format, '*') == NULL && strchr(format, '#') == NULL)) |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2197 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2198 file_util_warning_dialog(_("Auto rename"), |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2199 _("Format must include at least one of the symbol characters '*' or '#'.\n"), |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2200 GTK_STOCK_DIALOG_WARNING, NULL); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2201 return; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2202 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2203 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2204 history_combo_append_history(rd->format_entry, NULL); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2205 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2206 else |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2207 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2208 start_n = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(rd->auto_spin_start)); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2209 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2210 history_combo_append_history(rd->auto_entry_front, NULL); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2211 history_combo_append_history(rd->auto_entry_end, NULL); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2212 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2213 |
9 | 2214 store = gtk_tree_view_get_model(GTK_TREE_VIEW(rd->listview)); |
2215 | |
2216 /* first check for name conflicts */ | |
2217 success = TRUE; | |
2218 n = start_n; | |
2219 valid = gtk_tree_model_get_iter_first(store, &iter); | |
2220 while (valid && success) | |
2221 { | |
2222 gchar *dest; | |
2223 gchar *base; | |
138 | 2224 FileData *fd; |
2225 | |
2226 gtk_tree_model_get(store, &iter, RENAME_COLUMN_FD, &fd, -1); | |
2227 base = remove_level_from_path(fd->path); | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2228 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2229 if (rd->rename_type == RENAME_TYPE_FORMATTED) |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2230 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2231 gchar *new_name; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2232 |
138 | 2233 new_name = file_util_rename_multiple_auto_format_name(format, fd->name, n); |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2234 dest = g_strconcat(base, "/", new_name, NULL); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2235 g_free(new_name); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2236 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2237 else |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2238 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2239 dest = g_strdup_printf("%s/%s%0*d%s", base, front, padding, n, end); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2240 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2241 |
9 | 2242 if (isname(dest)) success = FALSE; |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2243 |
9 | 2244 g_free(dest); |
2245 g_free(base); | |
138 | 2246 // file_data_unref(fd); |
9 | 2247 |
2248 n++; | |
2249 valid = gtk_tree_model_iter_next(store, &iter); | |
2250 } | |
2251 | |
2252 if (!success) | |
2253 { | |
2254 file_util_warning_dialog(_("Auto rename"), | |
2255 _("Can not auto rename with the selected\nnumber set, one or more files exist that\nmatch the resulting name list.\n"), | |
2256 GTK_STOCK_DIALOG_WARNING, NULL); | |
2257 return; | |
2258 } | |
2259 | |
2260 /* select the first iter, so that on fail the correct info is given to user */ | |
2261 if (gtk_tree_model_get_iter_first(store, &iter)) | |
2262 { | |
2263 GtkTreeSelection *selection; | |
2264 | |
2265 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(rd->listview)); | |
2266 gtk_tree_selection_select_iter(selection, &iter); | |
2267 } | |
2268 | |
2269 /* now do it for real */ | |
2270 success = TRUE; | |
2271 n = start_n; | |
2272 while (success && gtk_tree_model_get_iter_first(store, &iter)) | |
2273 { | |
2274 gchar *dest; | |
2275 gchar *base; | |
138 | 2276 FileData *fd; |
2277 | |
2278 gtk_tree_model_get(store, &iter, RENAME_COLUMN_FD, &fd, -1); | |
2279 base = remove_level_from_path(fd->path); | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2280 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2281 if (rd->rename_type == RENAME_TYPE_FORMATTED) |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2282 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2283 gchar *new_name; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2284 |
138 | 2285 new_name = file_util_rename_multiple_auto_format_name(format, fd->name, n); |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2286 dest = g_strconcat(base, "/", new_name, NULL); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2287 g_free(new_name); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2288 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2289 else |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2290 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2291 dest = g_strdup_printf("%s/%s%0*d%s", base, front, padding, n, end); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2292 } |
442 | 2293 |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
2294 if (!file_data_add_change_info(fd, FILEDATA_CHANGE_RENAME, fd->path, dest) || |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
2295 !rename_file_ext(fd)) |
9 | 2296 { |
2297 success = FALSE; | |
2298 } | |
2299 | |
2300 g_free(dest); | |
2301 g_free(base); | |
138 | 2302 // file_data_unref(fd); |
9 | 2303 |
2304 if (success) | |
2305 { | |
2306 gtk_list_store_remove(GTK_LIST_STORE(store), &iter); | |
2307 if (gtk_tree_model_get_iter_first(store, &iter)) | |
2308 { | |
2309 GtkTreeSelection *selection; | |
2310 | |
2311 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(rd->listview)); | |
2312 gtk_tree_selection_select_iter(selection, &iter); | |
2313 } | |
2314 } | |
2315 | |
2316 n++; | |
2317 } | |
2318 | |
2319 if (!success) | |
2320 { | |
2321 gchar *buf; | |
2322 | |
2323 n--; | |
15
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
2324 gtk_spin_button_set_value(GTK_SPIN_BUTTON(rd->auto_spin_start), (gdouble)n); |
9 | 2325 |
138 | 2326 buf = g_strdup_printf(_("Failed to rename\n%s\nThe number was %d."), rd->fdlg->source_fd->name, n); |
9 | 2327 file_util_warning_dialog(_("Auto rename"), buf, GTK_STOCK_DIALOG_ERROR, NULL); |
2328 g_free(buf); | |
2329 | |
2330 return; | |
2331 } | |
2332 | |
138 | 2333 file_dialog_close(rd->fdlg); |
9 | 2334 } |
2335 | |
138 | 2336 static void file_util_rename_multiple_cb(FileDialog *fdlg, gpointer data) |
9 | 2337 { |
2338 RenameDataMult *rd = data; | |
1 | 2339 gchar *base; |
9 | 2340 const gchar *name; |
2341 | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2342 if (rd->rename_type != RENAME_TYPE_MANUAL) |
9 | 2343 { |
2344 file_util_rename_multiple_auto(rd); | |
2345 return; | |
2346 } | |
2347 | |
2348 name = gtk_entry_get_text(GTK_ENTRY(rd->rename_entry)); | |
138 | 2349 base = remove_level_from_path(fdlg->source_fd->path); |
2350 | |
2351 g_free(fdlg->dest_path); | |
2352 fdlg->dest_path = concat_dir_and_file(base, name); | |
1 | 2353 g_free(base); |
2354 | |
138 | 2355 if (strlen(name) == 0 || strcmp(fdlg->source_fd->path, fdlg->dest_path) == 0) |
1 | 2356 { |
2357 return; | |
2358 } | |
2359 | |
138 | 2360 fdlg->type = FALSE; |
9 | 2361 file_util_rename_multiple(rd); |
2362 } | |
2363 | |
138 | 2364 static void file_util_rename_multiple_close_cb(FileDialog *fdlg, gpointer data) |
9 | 2365 { |
2366 RenameDataMult *rd = data; | |
2367 | |
138 | 2368 file_dialog_close(rd->fdlg); |
1 | 2369 } |
2370 | |
9 | 2371 static gboolean file_util_rename_multiple_select_cb(GtkTreeSelection *selection, GtkTreeModel *store, GtkTreePath *tpath, |
2372 gboolean path_currently_selected, gpointer data) | |
2373 { | |
2374 RenameDataMult *rd = data; | |
2375 GtkTreeIter iter; | |
2376 const gchar *name; | |
138 | 2377 FileData *fd = NULL; |
9 | 2378 |
2379 if (path_currently_selected || | |
2380 !gtk_tree_model_get_iter(store, &iter, tpath)) return TRUE; | |
138 | 2381 gtk_tree_model_get(store, &iter, RENAME_COLUMN_FD, &fd, -1); |
2382 | |
2383 file_data_unref(rd->fdlg->source_fd); | |
2384 rd->fdlg->source_fd = file_data_ref(fd); | |
2385 | |
2386 name = rd->fdlg->source_fd->name; | |
9 | 2387 gtk_label_set_text(GTK_LABEL(rd->rename_label), name); |
2388 gtk_entry_set_text(GTK_ENTRY(rd->rename_entry), name); | |
2389 | |
138 | 2390 image_change_fd(rd->imd, rd->fdlg->source_fd, 0.0); |
9 | 2391 |
2392 if (GTK_WIDGET_VISIBLE(rd->rename_box)) | |
2393 { | |
2394 gtk_widget_grab_focus(rd->rename_entry); | |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
2395 gtk_editable_select_region(GTK_EDITABLE(rd->rename_entry), 0, filename_base_length(name)); |
9 | 2396 } |
2397 | |
2398 return TRUE; | |
2399 } | |
2400 | |
2401 static void file_util_rename_multiple_preview_update(RenameDataMult *rd) | |
1 | 2402 { |
9 | 2403 GtkTreeModel *store; |
2404 GtkTreeIter iter; | |
2405 const gchar *front; | |
2406 const gchar *end; | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2407 const gchar *format; |
9 | 2408 gint valid; |
2409 gint start_n; | |
2410 gint padding; | |
2411 gint n; | |
2412 | |
2413 front = gtk_entry_get_text(GTK_ENTRY(rd->auto_entry_front)); | |
2414 end = gtk_entry_get_text(GTK_ENTRY(rd->auto_entry_end)); | |
2415 padding = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(rd->auto_spin_pad)); | |
2416 | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2417 format = gtk_entry_get_text(GTK_ENTRY(rd->format_entry)); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2418 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2419 if (rd->rename_type == RENAME_TYPE_FORMATTED) |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2420 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2421 start_n = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(rd->format_spin)); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2422 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2423 else |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2424 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2425 start_n = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(rd->auto_spin_start)); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2426 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2427 |
9 | 2428 store = gtk_tree_view_get_model(GTK_TREE_VIEW(rd->listview)); |
2429 n = start_n; | |
2430 valid = gtk_tree_model_get_iter_first(store, &iter); | |
2431 while (valid) | |
2432 { | |
2433 gchar *dest; | |
2434 | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2435 if (rd->rename_type == RENAME_TYPE_FORMATTED) |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2436 { |
138 | 2437 FileData *fd; |
442 | 2438 |
138 | 2439 gtk_tree_model_get(store, &iter, RENAME_COLUMN_FD, &fd, -1); |
2440 dest = file_util_rename_multiple_auto_format_name(format, fd->name, n); | |
2441 // file_data_unref(fd); | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2442 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2443 else |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2444 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2445 dest = g_strdup_printf("%s%0*d%s", front, padding, n, end); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2446 } |
9 | 2447 gtk_list_store_set(GTK_LIST_STORE(store), &iter, RENAME_COLUMN_PREVIEW, dest, -1); |
2448 g_free(dest); | |
2449 | |
2450 n++; | |
2451 valid = gtk_tree_model_iter_next(store, &iter); | |
2452 } | |
2453 | |
1 | 2454 } |
2455 | |
9 | 2456 static gboolean file_util_rename_multiple_idle_cb(gpointer data) |
2457 { | |
2458 RenameDataMult *rd = data; | |
2459 | |
2460 file_util_rename_multiple_preview_update(rd); | |
2461 | |
2462 rd->update_idle_id = -1; | |
2463 return FALSE; | |
2464 } | |
2465 | |
2466 static void file_util_rename_multiple_preview_order_cb(GtkTreeModel *treemodel, GtkTreePath *tpath, | |
2467 GtkTreeIter *iter, gpointer data) | |
2468 { | |
2469 RenameDataMult *rd = data; | |
2470 | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2471 if (rd->rename_type != RENAME_TYPE_MANUAL && rd->update_idle_id == -1) |
9 | 2472 { |
2473 rd->update_idle_id = g_idle_add(file_util_rename_multiple_idle_cb, rd); | |
2474 } | |
2475 } | |
2476 | |
2477 static void file_util_rename_multiple_preview_entry_cb(GtkWidget *entry, gpointer data) | |
2478 { | |
2479 RenameDataMult *rd = data; | |
2480 file_util_rename_multiple_preview_update(rd); | |
2481 } | |
2482 | |
2483 static void file_util_rename_multiple_preview_adj_cb(GtkWidget *spin, gpointer data) | |
2484 { | |
2485 RenameDataMult *rd = data; | |
2486 file_util_rename_multiple_preview_update(rd); | |
2487 } | |
2488 | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2489 static void file_util_rename_multiple_auto_change(GtkWidget *widget, gpointer data) |
1 | 2490 { |
9 | 2491 RenameDataMult *rd = data; |
2492 GtkTreeViewColumn *column; | |
2493 | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2494 rd->rename_type = gtk_combo_box_get_active(GTK_COMBO_BOX(rd->combo_type)); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2495 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2496 switch (rd->rename_type) |
9 | 2497 { |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2498 case RENAME_TYPE_FORMATTED: |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2499 if (GTK_WIDGET_VISIBLE(rd->rename_box)) gtk_widget_hide(rd->rename_box); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2500 if (GTK_WIDGET_VISIBLE(rd->auto_box)) gtk_widget_hide(rd->auto_box); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2501 if (!GTK_WIDGET_VISIBLE(rd->format_box)) gtk_widget_show(rd->format_box); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2502 file_util_rename_multiple_preview_update(rd); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2503 break; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2504 case RENAME_TYPE_AUTO: |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2505 if (GTK_WIDGET_VISIBLE(rd->format_box)) gtk_widget_hide(rd->format_box); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2506 if (GTK_WIDGET_VISIBLE(rd->rename_box)) gtk_widget_hide(rd->rename_box); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2507 if (!GTK_WIDGET_VISIBLE(rd->auto_box)) gtk_widget_show(rd->auto_box); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2508 file_util_rename_multiple_preview_update(rd); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2509 break; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2510 case RENAME_TYPE_MANUAL: |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2511 default: |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2512 if (GTK_WIDGET_VISIBLE(rd->format_box)) gtk_widget_hide(rd->format_box); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2513 if (GTK_WIDGET_VISIBLE(rd->auto_box)) gtk_widget_hide(rd->auto_box); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2514 if (!GTK_WIDGET_VISIBLE(rd->rename_box)) gtk_widget_show(rd->rename_box); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2515 break; |
9 | 2516 } |
2517 | |
2518 column = gtk_tree_view_get_column(GTK_TREE_VIEW(rd->listview), RENAME_COLUMN_PREVIEW - 1); | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2519 gtk_tree_view_column_set_visible(column, (rd->rename_type != RENAME_TYPE_MANUAL)); |
9 | 2520 } |
2521 | |
2522 static GtkWidget *furm_simple_vlabel(GtkWidget *box, const gchar *text, gint expand) | |
2523 { | |
2524 GtkWidget *vbox; | |
2525 GtkWidget *label; | |
2526 | |
2527 vbox = gtk_vbox_new(FALSE, 0); | |
2528 gtk_box_pack_start(GTK_BOX(box), vbox, expand, expand, 0); | |
2529 gtk_widget_show(vbox); | |
2530 | |
2531 label = gtk_label_new(text); | |
2532 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
2533 gtk_widget_show(label); | |
2534 | |
2535 return vbox; | |
2536 } | |
2537 | |
2538 static GtkTreeViewColumn *file_util_rename_multiple_add_column(RenameDataMult *rd, const gchar *text, gint n) | |
2539 { | |
2540 GtkTreeViewColumn *column; | |
2541 GtkCellRenderer *renderer; | |
2542 | |
2543 column = gtk_tree_view_column_new(); | |
442 | 2544 gtk_tree_view_column_set_title(column, text); |
2545 gtk_tree_view_column_set_min_width(column, 4); | |
2546 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
2547 renderer = gtk_cell_renderer_text_new(); | |
2548 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
2549 gtk_tree_view_column_add_attribute(column, renderer, "text", n); | |
2550 gtk_tree_view_append_column(GTK_TREE_VIEW(rd->listview), column); | |
9 | 2551 |
2552 return column; | |
2553 } | |
2554 | |
2555 static void file_util_rename_multiple_destroy_cb(GtkWidget *widget, gpointer data) | |
2556 { | |
2557 RenameDataMult *rd = data; | |
2558 | |
2559 if (rd->update_idle_id != -1) g_source_remove(rd->update_idle_id); | |
2560 | |
2561 g_free(rd); | |
2562 } | |
2563 | |
2564 static void file_util_rename_multiple_do(GList *source_list, GtkWidget *parent) | |
2565 { | |
2566 RenameDataMult *rd; | |
2567 GtkWidget *pane; | |
1 | 2568 GtkWidget *scrolled; |
9 | 2569 GtkListStore *store; |
2570 GtkTreeSelection *selection; | |
2571 GtkTreeViewColumn *column; | |
2572 GtkWidget *hbox; | |
2573 GtkWidget *vbox; | |
2574 GtkWidget *box2; | |
2575 GtkWidget *table; | |
2576 GtkWidget *combo; | |
1 | 2577 GList *work; |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
2578 const gchar *name; |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
2579 gchar *title; |
1 | 2580 |
9 | 2581 rd = g_new0(RenameDataMult, 1); |
442 | 2582 |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
2583 title = g_strdup_printf("%s -%s", _("Rename"), GQ_APPNAME); |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
2584 rd->fdlg = file_util_file_dlg(title, GQ_WMCLASS, "dlg_rename", parent, |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
2585 file_util_rename_multiple_close_cb, rd); |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
2586 g_free(title); |
138 | 2587 generic_dialog_add_message(GENERIC_DIALOG(rd->fdlg), NULL, _("Rename multiple files"), NULL); |
2588 file_dialog_add_button(rd->fdlg, GTK_STOCK_OK, _("_Rename"), file_util_rename_multiple_cb, TRUE); | |
2589 | |
2590 rd->fdlg->source_fd = file_data_ref(source_list->data); | |
2591 rd->fdlg->dest_path = NULL; | |
9 | 2592 |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2593 rd->rename_type = RENAME_TYPE_MANUAL; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2594 |
9 | 2595 rd->update_idle_id = -1; |
2596 | |
138 | 2597 vbox = GENERIC_DIALOG(rd->fdlg)->vbox; |
9 | 2598 |
2599 pane = gtk_hpaned_new(); | |
2600 gtk_box_pack_start(GTK_BOX(vbox), pane, TRUE, TRUE, 0); | |
2601 gtk_widget_show(pane); | |
442 | 2602 |
1 | 2603 scrolled = gtk_scrolled_window_new(NULL, NULL); |
9 | 2604 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
507
diff
changeset
|
2605 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), |
9 | 2606 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); |
2607 gtk_paned_pack1(GTK_PANED(pane), scrolled, TRUE, TRUE); | |
1 | 2608 gtk_widget_show(scrolled); |
2609 | |
138 | 2610 store = gtk_list_store_new(4, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); |
9 | 2611 rd->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); |
2612 g_object_unref(store); | |
2613 | |
2614 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(rd->listview), TRUE); | |
2615 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(rd->listview), FALSE); | |
2616 | |
2617 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(rd->listview)); | |
2618 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_SINGLE); | |
2619 gtk_tree_selection_set_select_function(selection, file_util_rename_multiple_select_cb, rd, NULL); | |
2620 | |
2621 file_util_rename_multiple_add_column(rd, _("Original Name"), RENAME_COLUMN_NAME); | |
2622 column = file_util_rename_multiple_add_column(rd, _("Preview"), RENAME_COLUMN_PREVIEW); | |
2623 gtk_tree_view_column_set_visible(column, FALSE); | |
442 | 2624 |
9 | 2625 gtk_tree_view_set_reorderable(GTK_TREE_VIEW(rd->listview), TRUE); |
2626 g_signal_connect(G_OBJECT(store), "row_changed", | |
2627 G_CALLBACK(file_util_rename_multiple_preview_order_cb), rd); | |
2628 gtk_widget_set_size_request(rd->listview, 250, 150); | |
2629 | |
2630 gtk_container_add(GTK_CONTAINER(scrolled), rd->listview); | |
2631 gtk_widget_show(rd->listview); | |
1 | 2632 |
2633 work = source_list; | |
9 | 2634 while (work) |
1 | 2635 { |
138 | 2636 FileData *fd = work->data; |
9 | 2637 GtkTreeIter iter; |
2638 | |
2639 gtk_list_store_append(store, &iter); | |
138 | 2640 gtk_list_store_set(store, &iter, RENAME_COLUMN_FD, fd, RENAME_COLUMN_PATH, fd->path, RENAME_COLUMN_NAME, fd->name, -1); |
9 | 2641 |
1 | 2642 work = work->next; |
2643 } | |
2644 | |
138 | 2645 filelist_free(source_list); |
9 | 2646 |
2647 rd->imd = image_new(TRUE); | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
2648 g_object_set(G_OBJECT(rd->imd->pr), "zoom_expand", FALSE, NULL); |
9 | 2649 gtk_widget_set_size_request(rd->imd->widget, DIALOG_DEF_IMAGE_DIM_X, DIALOG_DEF_IMAGE_DIM_Y); |
2650 gtk_paned_pack2(GTK_PANED(pane), rd->imd->widget, FALSE, TRUE); | |
2651 gtk_widget_show(rd->imd->widget); | |
2652 | |
2653 hbox = gtk_hbox_new(FALSE, 0); | |
2654 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
2655 gtk_widget_show(hbox); | |
2656 | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2657 rd->combo_type = gtk_combo_box_new_text(); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2658 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2659 gtk_combo_box_append_text(GTK_COMBO_BOX(rd->combo_type), _("Manual rename")); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2660 gtk_combo_box_append_text(GTK_COMBO_BOX(rd->combo_type), _("Formatted rename")); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2661 gtk_combo_box_append_text(GTK_COMBO_BOX(rd->combo_type), _("Auto rename")); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2662 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2663 gtk_combo_box_set_active(GTK_COMBO_BOX(rd->combo_type), rd->rename_type); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2664 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2665 g_signal_connect(G_OBJECT(rd->combo_type), "changed", |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2666 G_CALLBACK(file_util_rename_multiple_auto_change), rd); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2667 gtk_box_pack_end(GTK_BOX(hbox), rd->combo_type, FALSE, FALSE, 0); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2668 gtk_widget_show(rd->combo_type); |
9 | 2669 |
2670 rd->rename_box = pref_box_new(vbox, FALSE, GTK_ORIENTATION_VERTICAL, 0); | |
2671 table = pref_table_new(rd->rename_box, 2, 2, FALSE, FALSE); | |
2672 | |
2673 pref_table_label(table, 0, 0, _("Original name:"), 1.0); | |
138 | 2674 rd->rename_label = pref_table_label(table, 1, 0, rd->fdlg->source_fd->name, 0.0); |
9 | 2675 |
2676 pref_table_label(table, 0, 1, _("New name:"), 1.0); | |
2677 | |
2678 rd->rename_entry = gtk_entry_new(); | |
115
53b2bfdcff69
Tue Nov 28 11:54:30 2006 John Ellis <johne@verizon.net>
gqview
parents:
112
diff
changeset
|
2679 gtk_table_attach(GTK_TABLE(table), rd->rename_entry, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 0, 0); |
138 | 2680 generic_dialog_attach_default(GENERIC_DIALOG(rd->fdlg), rd->rename_entry); |
9 | 2681 gtk_widget_grab_focus(rd->rename_entry); |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
2682 |
138 | 2683 name = rd->fdlg->source_fd->name; |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
2684 gtk_entry_set_text(GTK_ENTRY(rd->rename_entry), name); |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
2685 gtk_editable_select_region(GTK_EDITABLE(rd->rename_entry), 0, filename_base_length(name)); |
9 | 2686 gtk_widget_show(rd->rename_entry); |
2687 | |
2688 rd->auto_box = gtk_vbox_new(FALSE, PREF_PAD_GAP); | |
2689 gtk_box_pack_start(GTK_BOX(vbox), rd->auto_box, FALSE, FALSE, 0); | |
2690 /* do not show it here */ | |
2691 | |
2692 hbox = pref_box_new(rd->auto_box, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP); | |
2693 | |
2694 box2 = furm_simple_vlabel(hbox, _("Begin text"), TRUE); | |
2695 | |
2696 combo = history_combo_new(&rd->auto_entry_front, "", "numerical_rename_prefix", -1); | |
2697 g_signal_connect(G_OBJECT(rd->auto_entry_front), "changed", | |
2698 G_CALLBACK(file_util_rename_multiple_preview_entry_cb), rd); | |
2699 gtk_box_pack_start(GTK_BOX(box2), combo, TRUE, TRUE, 0); | |
2700 gtk_widget_show(combo); | |
442 | 2701 |
9 | 2702 box2 = furm_simple_vlabel(hbox, _("Start #"), FALSE); |
2703 | |
2704 rd->auto_spin_start = pref_spin_new(box2, NULL, NULL, | |
80
a10fc0308c12
Thu Oct 19 07:42:38 2006 John Ellis <johne@verizon.net>
gqview
parents:
71
diff
changeset
|
2705 0.0, 1000000.0, 1.0, 0, 1.0, |
9 | 2706 G_CALLBACK(file_util_rename_multiple_preview_adj_cb), rd); |
2707 | |
2708 box2 = furm_simple_vlabel(hbox, _("End text"), TRUE); | |
2709 | |
2710 combo = history_combo_new(&rd->auto_entry_end, "", "numerical_rename_suffix", -1); | |
2711 g_signal_connect(G_OBJECT(rd->auto_entry_end), "changed", | |
2712 G_CALLBACK(file_util_rename_multiple_preview_entry_cb), rd); | |
2713 gtk_box_pack_start(GTK_BOX(box2), combo, TRUE, TRUE, 0); | |
2714 gtk_widget_show(combo); | |
2715 | |
2716 rd->auto_spin_pad = pref_spin_new(rd->auto_box, _("Padding:"), NULL, | |
2717 1.0, 8.0, 1.0, 0, 1.0, | |
2718 G_CALLBACK(file_util_rename_multiple_preview_adj_cb), rd); | |
2719 | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2720 rd->format_box = gtk_vbox_new(FALSE, PREF_PAD_GAP); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2721 gtk_box_pack_start(GTK_BOX(vbox), rd->format_box, FALSE, FALSE, 0); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2722 /* do not show it here */ |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2723 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2724 hbox = pref_box_new(rd->format_box, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2725 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2726 box2 = furm_simple_vlabel(hbox, _("Format (* = original name, ## = numbers)"), TRUE); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2727 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2728 combo = history_combo_new(&rd->format_entry, "", "auto_rename_format", -1); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2729 g_signal_connect(G_OBJECT(rd->format_entry), "changed", |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2730 G_CALLBACK(file_util_rename_multiple_preview_entry_cb), rd); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2731 gtk_box_pack_start(GTK_BOX(box2), combo, TRUE, TRUE, 0); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2732 gtk_widget_show(combo); |
442 | 2733 |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2734 box2 = furm_simple_vlabel(hbox, _("Start #"), FALSE); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2735 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2736 rd->format_spin = pref_spin_new(box2, NULL, NULL, |
80
a10fc0308c12
Thu Oct 19 07:42:38 2006 John Ellis <johne@verizon.net>
gqview
parents:
71
diff
changeset
|
2737 0.0, 1000000.0, 1.0, 0, 1.0, |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2738 G_CALLBACK(file_util_rename_multiple_preview_adj_cb), rd); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
2739 |
138 | 2740 image_change_fd(rd->imd, rd->fdlg->source_fd, 0.0); |
2741 | |
2742 g_signal_connect(G_OBJECT(GENERIC_DIALOG(rd->fdlg)->dialog), "destroy", | |
9 | 2743 G_CALLBACK(file_util_rename_multiple_destroy_cb), rd); |
2744 | |
138 | 2745 gtk_widget_show(GENERIC_DIALOG(rd->fdlg)->dialog); |
1 | 2746 } |
2747 | |
2748 /* | |
2749 * rename single file | |
2750 */ | |
2751 | |
9 | 2752 static void file_util_rename_single(FileDataSingle *fds); |
2753 | |
2754 static void file_util_rename_single_ok_cb(GenericDialog *gd, gpointer data) | |
1 | 2755 { |
2756 FileDataSingle *fds = data; | |
2757 fds->confirmed = TRUE; | |
2758 file_util_rename_single(fds); | |
2759 } | |
2760 | |
9 | 2761 static void file_util_rename_single_cancel_cb(GenericDialog *gd, gpointer data) |
1 | 2762 { |
2763 FileDataSingle *fds = data; | |
2764 file_data_single_free(fds); | |
2765 } | |
2766 | |
2767 static void file_util_rename_single(FileDataSingle *fds) | |
2768 { | |
2769 if (isfile(fds->dest) && !fds->confirmed) | |
2770 { | |
9 | 2771 GenericDialog *gd; |
2772 | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
223
diff
changeset
|
2773 gd = file_util_gen_dlg(_("Overwrite file"), GQ_WMCLASS, "dlg_confirm", |
9 | 2774 NULL, TRUE, |
2775 file_util_rename_single_cancel_cb, fds); | |
2776 | |
2777 generic_dialog_add_message(gd, GTK_STOCK_DIALOG_QUESTION, | |
2778 _("Overwrite file?"), | |
2779 _("Replace existing file by renaming new file.")); | |
2780 pref_spacer(gd->vbox, 0); | |
2781 | |
2782 generic_dialog_add_button(gd, GTK_STOCK_OK, _("_Overwrite"), file_util_rename_single_ok_cb, TRUE); | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
2783 generic_dialog_add_image(gd, NULL, |
138 | 2784 file_data_new_simple(fds->dest), _("Existing file"), |
2785 fds->source_fd, _("New file"), TRUE); | |
9 | 2786 |
2787 gtk_widget_show(gd->dialog); | |
2788 | |
1 | 2789 return; |
2790 } | |
2791 else | |
2792 { | |
138 | 2793 /* |
2794 GList *list = g_list_append(NULL, file_data_ref(fds->source_fd)); | |
2795 file_util_do_move_list(list, FALSE, TRUE); | |
2796 filelist_free(list); | |
2797 */ | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
2798 if (!file_data_add_change_info(fds->source_fd, FILEDATA_CHANGE_RENAME, fds->source_fd->path, fds->dest) || |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
2799 !rename_file_ext(fds->source_fd)) |
1 | 2800 { |
138 | 2801 gchar *text = g_strdup_printf(_("Unable to rename file:\n%s\nto:\n%s"), fds->source_fd->name, filename_from_path(fds->dest)); |
9 | 2802 file_util_warning_dialog(_("Error renaming file"), text, GTK_STOCK_DIALOG_ERROR, NULL); |
1 | 2803 g_free(text); |
2804 } | |
138 | 2805 |
1 | 2806 } |
2807 file_data_single_free(fds); | |
2808 } | |
2809 | |
138 | 2810 static void file_util_rename_single_cb(FileDialog *fdlg, gpointer data) |
1 | 2811 { |
9 | 2812 const gchar *name; |
2813 gchar *path; | |
2814 | |
138 | 2815 name = gtk_entry_get_text(GTK_ENTRY(fdlg->entry)); |
2816 path = concat_dir_and_file(fdlg->dest_path, name); | |
2817 | |
2818 if (strlen(name) == 0 || strcmp(fdlg->source_fd->path, path) == 0) | |
1 | 2819 { |
9 | 2820 g_free(path); |
1 | 2821 return; |
2822 } | |
2823 | |
138 | 2824 file_util_rename_single(file_data_single_new(fdlg->source_fd, path, fdlg->type)); |
9 | 2825 |
2826 g_free(path); | |
138 | 2827 file_dialog_close(fdlg); |
1 | 2828 } |
2829 | |
138 | 2830 static void file_util_rename_single_close_cb(FileDialog *fdlg, gpointer data) |
9 | 2831 { |
138 | 2832 file_dialog_close(fdlg); |
9 | 2833 } |
2834 | |
138 | 2835 static void file_util_rename_single_do(FileData *source_fd, GtkWidget *parent) |
1 | 2836 { |
138 | 2837 FileDialog *fdlg; |
9 | 2838 GtkWidget *table; |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
2839 const gchar *name; |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
2840 gchar *title; |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
2841 |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
2842 title = g_strdup_printf("%s -%s", _("Rename"), GQ_APPNAME); |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
2843 fdlg = file_util_file_dlg(title, GQ_WMCLASS, "dlg_rename", parent, |
442 | 2844 file_util_rename_single_close_cb, NULL); |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
2845 g_free(title); |
9 | 2846 |
138 | 2847 generic_dialog_add_message(GENERIC_DIALOG(fdlg), NULL, _("Rename file"), NULL); |
2848 generic_dialog_add_image(GENERIC_DIALOG(fdlg), NULL, source_fd, NULL, NULL, NULL, FALSE); | |
2849 | |
2850 file_dialog_add_button(fdlg, GTK_STOCK_OK, _("_Rename"), file_util_rename_single_cb, TRUE); | |
2851 | |
2852 fdlg->source_fd = file_data_ref(source_fd); | |
2853 fdlg->dest_path = remove_level_from_path(source_fd->path); | |
2854 | |
2855 table = pref_table_new(GENERIC_DIALOG(fdlg)->vbox, 2, 2, FALSE, FALSE); | |
9 | 2856 |
2857 pref_table_label(table, 0, 0, _("Original name:"), 1.0); | |
138 | 2858 pref_table_label(table, 1, 0, fdlg->source_fd->name, 0.0); |
9 | 2859 |
2860 pref_table_label(table, 0, 1, _("New name:"), 1.0); | |
2861 | |
138 | 2862 fdlg->entry = gtk_entry_new(); |
2863 gtk_table_attach(GTK_TABLE(table), fdlg->entry, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 0, 0); | |
2864 generic_dialog_attach_default(GENERIC_DIALOG(fdlg), fdlg->entry); | |
2865 gtk_widget_grab_focus(fdlg->entry); | |
2866 | |
2867 name = fdlg->source_fd->name; | |
2868 gtk_entry_set_text(GTK_ENTRY(fdlg->entry), name); | |
2869 gtk_editable_select_region(GTK_EDITABLE(fdlg->entry), 0, filename_base_length(name)); | |
2870 gtk_widget_show(fdlg->entry); | |
2871 | |
2872 gtk_widget_show(GENERIC_DIALOG(fdlg)->dialog); | |
1 | 2873 } |
2874 | |
138 | 2875 void file_util_rename(FileData *source_fd, GList *source_list, GtkWidget *parent) |
1 | 2876 { |
138 | 2877 if (!source_fd && !source_list) return; |
2878 | |
2879 if (source_fd) | |
1 | 2880 { |
138 | 2881 file_util_rename_single_do(source_fd, parent); |
1 | 2882 } |
2883 else if (!source_list->next) | |
2884 { | |
9 | 2885 file_util_rename_single_do(source_list->data, parent); |
138 | 2886 filelist_free(source_list); |
1 | 2887 } |
2888 else | |
2889 { | |
9 | 2890 file_util_rename_multiple_do(source_list, parent); |
1 | 2891 } |
2892 } | |
2893 | |
2894 /* | |
2895 *-------------------------------------------------------------------------- | |
2896 * Create directory routines | |
2897 *-------------------------------------------------------------------------- | |
2898 */ | |
2899 | |
9 | 2900 static void file_util_create_dir_do(const gchar *base, const gchar *name) |
1 | 2901 { |
9 | 2902 gchar *path; |
2903 | |
2904 path = concat_dir_and_file(base, name); | |
2905 | |
2906 if (isdir(path)) | |
1 | 2907 { |
9 | 2908 gchar *text = g_strdup_printf(_("The folder:\n%s\nalready exists."), name); |
2909 file_util_warning_dialog(_("Folder exists"), text, GTK_STOCK_DIALOG_INFO, NULL); | |
1 | 2910 g_free(text); |
2911 } | |
9 | 2912 else if (isname(path)) |
1 | 2913 { |
9 | 2914 gchar *text = g_strdup_printf(_("The path:\n%s\nalready exists as a file."), name); |
2915 file_util_warning_dialog(_("Could not create folder"), text, GTK_STOCK_DIALOG_INFO, NULL); | |
1 | 2916 g_free(text); |
2917 } | |
2918 else | |
2919 { | |
9 | 2920 if (!mkdir_utf8(path, 0755)) |
1 | 2921 { |
9 | 2922 gchar *text = g_strdup_printf(_("Unable to create folder:\n%s"), name); |
2923 file_util_warning_dialog(_("Error creating folder"), text, GTK_STOCK_DIALOG_ERROR, NULL); | |
1 | 2924 g_free(text); |
2925 } | |
2926 } | |
9 | 2927 |
2928 g_free(path); | |
1 | 2929 } |
2930 | |
138 | 2931 static void file_util_create_dir_cb(FileDialog *fdlg, gpointer data) |
1 | 2932 { |
9 | 2933 const gchar *name; |
2934 | |
138 | 2935 name = gtk_entry_get_text(GTK_ENTRY(fdlg->entry)); |
1 | 2936 |
2937 if (strlen(name) == 0) return; | |
2938 | |
9 | 2939 if (name[0] == '/') |
2940 { | |
2941 gchar *buf; | |
2942 buf = remove_level_from_path(name); | |
2943 file_util_create_dir_do(buf, filename_from_path(name)); | |
2944 g_free(buf); | |
2945 } | |
2946 else | |
2947 { | |
138 | 2948 file_util_create_dir_do(fdlg->dest_path, name); |
9 | 2949 } |
2950 | |
138 | 2951 file_dialog_close(fdlg); |
1 | 2952 } |
2953 | |
138 | 2954 static void file_util_create_dir_close_cb(FileDialog *fdlg, gpointer data) |
9 | 2955 { |
138 | 2956 file_dialog_close(fdlg); |
9 | 2957 } |
2958 | |
2959 void file_util_create_dir(const gchar *path, GtkWidget *parent) | |
1 | 2960 { |
138 | 2961 FileDialog *fdlg; |
1 | 2962 gchar *text; |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
2963 gchar *title; |
1 | 2964 |
2965 if (!isdir(path)) return; | |
9 | 2966 |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
2967 title = g_strdup_printf("%s -%s", _("New folder"), GQ_APPNAME); |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
2968 fdlg = file_util_file_dlg(title, GQ_WMCLASS, "dlg_newdir", parent, |
442 | 2969 file_util_create_dir_close_cb, NULL); |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
2970 g_free(title); |
9 | 2971 |
2972 text = g_strdup_printf(_("Create folder in:\n%s\nnamed:"), path); | |
138 | 2973 generic_dialog_add_message(GENERIC_DIALOG(fdlg), NULL, NULL, text); |
1 | 2974 g_free(text); |
2975 | |
138 | 2976 file_dialog_add_button(fdlg, GTK_STOCK_OK, NULL, file_util_create_dir_cb, TRUE); |
2977 | |
2978 fdlg->dest_path = g_strdup(path); | |
2979 | |
2980 fdlg->entry = gtk_entry_new(); | |
2981 gtk_box_pack_start(GTK_BOX(GENERIC_DIALOG(fdlg)->vbox), fdlg->entry, FALSE, FALSE, 0); | |
2982 generic_dialog_attach_default(GENERIC_DIALOG(fdlg), fdlg->entry); | |
2983 gtk_widget_grab_focus(fdlg->entry); | |
2984 gtk_widget_show(fdlg->entry); | |
2985 | |
2986 gtk_widget_show(GENERIC_DIALOG(fdlg)->dialog); | |
1 | 2987 } |
2988 | |
138 | 2989 gint file_util_rename_dir(FileData *old_fd, const gchar *new_path, GtkWidget *parent) |
44
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
2990 { |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
2991 const gchar *old_name; |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
2992 const gchar *new_name; |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
2993 |
138 | 2994 if (!old_fd || !new_path || !isdir(old_fd->path)) return FALSE; |
2995 | |
2996 old_name = old_fd->name; | |
44
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
2997 new_name = filename_from_path(new_path); |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
2998 |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
2999 if (isdir(new_path)) |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3000 { |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3001 gchar *text = g_strdup_printf(_("The folder:\n%s\nalready exists."), new_name); |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3002 file_util_warning_dialog(_("Folder exists"), text, GTK_STOCK_DIALOG_INFO, parent); |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3003 g_free(text); |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3004 |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3005 return FALSE; |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3006 } |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3007 |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3008 if (isname(new_path)) |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3009 { |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3010 gchar *text = g_strdup_printf(_("The path:\n%s\nalready exists as a file."), new_name); |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3011 file_util_warning_dialog(_("Rename failed"), text, GTK_STOCK_DIALOG_INFO,parent); |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3012 g_free(text); |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3013 |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3014 return FALSE; |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3015 } |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
3016 if (!file_data_add_change_info(old_fd, FILEDATA_CHANGE_RENAME, old_fd->path, new_path) || |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
3017 !rename_file_ext(old_fd)) |
44
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3018 { |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3019 gchar *text = g_strdup_printf(_("Failed to rename %s to %s."), old_name, new_name); |
71
7425cb0aeb03
Sat Oct 14 05:18:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
67
diff
changeset
|
3020 file_util_warning_dialog(_("Rename failed"), text, GTK_STOCK_DIALOG_ERROR, parent); |
44
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3021 g_free(text); |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3022 |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3023 return FALSE; |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3024 } |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3025 |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3026 return TRUE; |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3027 } |
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
3028 |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3029 /* |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3030 *-------------------------------------------------------------------------- |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3031 * Delete directory routines |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3032 *-------------------------------------------------------------------------- |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3033 */ |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3034 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3035 /* The plan is to eventually make all of utilops.c |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3036 * use UtilityData and UtilityType. |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3037 * And clean up the above mess someday. |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3038 */ |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3039 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3040 typedef enum { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3041 UTILITY_TYPE_NONE = 0, |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3042 UTILITY_TYPE_COPY, |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3043 UTILITY_TYPE_MOVE, |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3044 UTILITY_TYPE_RENAME, |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3045 UTILITY_TYPE_DELETE, |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3046 UTILITY_TYPE_DELETE_LINK, |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3047 UTILITY_TYPE_DELETE_FOLDER |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3048 } UtilityType; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3049 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3050 typedef struct _UtilityData UtilityData; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3051 struct _UtilityData { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3052 UtilityType type; |
138 | 3053 FileData *source_fd; |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3054 GList *dlist; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3055 GList *flist; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3056 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3057 GenericDialog *gd; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3058 }; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3059 |
138 | 3060 enum { |
3061 UTILITY_COLUMN_FD = 0, | |
3062 UTILITY_COLUMN_PATH, | |
3063 UTILITY_COLUMN_NAME, | |
3064 UTILITY_COLUMN_COUNT | |
3065 }; | |
3066 | |
3067 | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3068 #define UTILITY_LIST_MIN_WIDTH 250 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3069 #define UTILITY_LIST_MIN_HEIGHT 150 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3070 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3071 /* thumbnail spec has a max depth of 4 (.thumb??/fail/appname/??.png) */ |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3072 #define UTILITY_DELETE_MAX_DEPTH 5 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3073 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3074 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3075 static void file_util_data_free(UtilityData *ud) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3076 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3077 if (!ud) return; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3078 |
138 | 3079 file_data_unref(ud->source_fd); |
3080 filelist_free(ud->dlist); | |
3081 filelist_free(ud->flist); | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3082 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3083 if (ud->gd) generic_dialog_close(ud->gd); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3084 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3085 g_free(ud); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3086 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3087 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3088 static GtkTreeViewColumn *file_util_dialog_add_list_column(GtkWidget *view, const gchar *text, gint n) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3089 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3090 GtkTreeViewColumn *column; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3091 GtkCellRenderer *renderer; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3092 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3093 column = gtk_tree_view_column_new(); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3094 gtk_tree_view_column_set_title(column, text); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3095 gtk_tree_view_column_set_min_width(column, 4); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3096 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3097 renderer = gtk_cell_renderer_text_new(); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3098 gtk_tree_view_column_pack_start(column, renderer, TRUE); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3099 gtk_tree_view_column_add_attribute(column, renderer, "text", n); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3100 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3101 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3102 return column; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3103 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3104 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3105 static GtkWidget *file_util_dialog_add_list(GtkWidget *box, GList *list, gint full_paths) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3106 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3107 GtkWidget *scrolled; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3108 GtkWidget *view; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3109 GtkListStore *store; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3110 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3111 scrolled = gtk_scrolled_window_new(NULL, NULL); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3112 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
507
diff
changeset
|
3113 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3114 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3115 gtk_box_pack_start(GTK_BOX(box), scrolled, TRUE, TRUE, 0); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3116 gtk_widget_show(scrolled); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3117 |
138 | 3118 store = gtk_list_store_new(UTILITY_COLUMN_COUNT, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3119 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3120 g_object_unref(store); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3121 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3122 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), TRUE); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3123 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(view), FALSE); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3124 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3125 if (full_paths) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3126 { |
138 | 3127 file_util_dialog_add_list_column(view, _("Location"), UTILITY_COLUMN_PATH); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3128 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3129 else |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3130 { |
138 | 3131 file_util_dialog_add_list_column(view, _("Name"), UTILITY_COLUMN_NAME); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3132 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3133 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3134 gtk_widget_set_size_request(view, UTILITY_LIST_MIN_WIDTH, UTILITY_LIST_MIN_HEIGHT); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3135 gtk_container_add(GTK_CONTAINER(scrolled), view); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3136 gtk_widget_show(view); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3137 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3138 while (list) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3139 { |
138 | 3140 FileData *fd = list->data; |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3141 GtkTreeIter iter; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3142 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3143 gtk_list_store_append(store, &iter); |
138 | 3144 gtk_list_store_set(store, &iter, UTILITY_COLUMN_FD, fd, |
3145 UTILITY_COLUMN_PATH, fd->path, | |
3146 UTILITY_COLUMN_NAME, fd->name, -1); | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3147 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3148 list = list->next; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3149 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3150 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3151 return view; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3152 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3153 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3154 static gboolean file_util_delete_dir_preview_cb(GtkTreeSelection *selection, GtkTreeModel *store, |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3155 GtkTreePath *tpath, gboolean path_currently_selected, |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3156 gpointer data) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3157 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3158 UtilityData *ud = data; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3159 GtkTreeIter iter; |
138 | 3160 FileData *fd = NULL; |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3161 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3162 if (path_currently_selected || |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3163 !gtk_tree_model_get_iter(store, &iter, tpath)) return TRUE; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3164 |
138 | 3165 gtk_tree_model_get(store, &iter, UTILITY_COLUMN_FD, &fd, -1); |
3166 generic_dialog_image_set(ud->gd, fd); | |
3167 // file_data_unref(fd); | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3168 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3169 return TRUE; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3170 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3171 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3172 static void file_util_delete_dir_cancel_cb(GenericDialog *gd, gpointer data) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3173 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3174 UtilityData *ud = data; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3175 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3176 ud->gd = NULL; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3177 file_util_data_free(ud); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3178 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3179 |
138 | 3180 FileData *file_util_delete_dir_empty_path(FileData *fd, gint real_content, gint level) |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3181 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3182 GList *dlist = NULL; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3183 GList *flist = NULL; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3184 GList *work; |
138 | 3185 FileData *fail = NULL; |
3186 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
497
diff
changeset
|
3187 DEBUG_1("deltree into: %s", fd->path); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3188 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3189 level++; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3190 if (level > UTILITY_DELETE_MAX_DEPTH) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3191 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3192 printf("folder recursion depth past %d, giving up\n", UTILITY_DELETE_MAX_DEPTH); |
138 | 3193 return file_data_ref(fd); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3194 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3195 |
138 | 3196 if (!filelist_read_lstat(fd->path, &flist, &dlist)) file_data_ref(fd); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3197 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3198 work = dlist; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3199 while (work && !fail) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3200 { |
138 | 3201 FileData *lfd; |
3202 | |
3203 lfd = work->data; | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3204 work = work->next; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3205 |
138 | 3206 fail = file_util_delete_dir_empty_path(lfd, real_content, level); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3207 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3208 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3209 work = flist; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3210 while (work && !fail) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3211 { |
138 | 3212 FileData *lfd; |
3213 | |
3214 lfd = work->data; | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3215 work = work->next; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3216 |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
497
diff
changeset
|
3217 DEBUG_1("deltree child: %s", lfd->path); |
138 | 3218 |
3219 if (real_content && !islink(lfd->path)) | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3220 { |
138 | 3221 if (!file_util_unlink(lfd)) fail = file_data_ref(lfd); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3222 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3223 else |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3224 { |
138 | 3225 if (!unlink_file(lfd->path)) fail = file_data_ref(lfd); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3226 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3227 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3228 |
138 | 3229 filelist_free(dlist); |
3230 filelist_free(flist); | |
3231 | |
3232 if (!fail && !rmdir_utf8(fd->path)) | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3233 { |
138 | 3234 fail = file_data_ref(fd); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3235 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3236 |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
497
diff
changeset
|
3237 DEBUG_1("deltree done: %s", fd->path); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3238 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3239 return fail; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3240 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3241 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3242 static void file_util_delete_dir_ok_cb(GenericDialog *gd, gpointer data) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3243 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3244 UtilityData *ud = data; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3245 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3246 ud->gd = NULL; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3247 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3248 if (ud->type == UTILITY_TYPE_DELETE_LINK) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3249 { |
138 | 3250 if (!unlink_file(ud->source_fd->path)) |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3251 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3252 gchar *text; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3253 |
138 | 3254 text = g_strdup_printf("Unable to remove symbolic link:\n %s", ud->source_fd->path); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3255 file_util_warning_dialog(_("Delete failed"), text, |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3256 GTK_STOCK_DIALOG_ERROR, NULL); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3257 g_free(text); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3258 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3259 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3260 else |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3261 { |
138 | 3262 FileData *fail = NULL; |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3263 GList *work; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3264 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3265 work = ud->dlist; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3266 while (work && !fail) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3267 { |
138 | 3268 FileData *fd; |
3269 | |
3270 fd = work->data; | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3271 work = work->next; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3272 |
138 | 3273 fail = file_util_delete_dir_empty_path(fd, FALSE, 0); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3274 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3275 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3276 work = ud->flist; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3277 while (work && !fail) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3278 { |
138 | 3279 FileData *fd; |
3280 | |
3281 fd = work->data; | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3282 work = work->next; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3283 |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
497
diff
changeset
|
3284 DEBUG_1("deltree unlink: %s", fd->path); |
138 | 3285 |
3286 if (islink(fd->path)) | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3287 { |
138 | 3288 if (!unlink_file(fd->path)) fail = file_data_ref(fd); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3289 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3290 else |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3291 { |
138 | 3292 if (!file_util_unlink(fd)) fail = file_data_ref(fd); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3293 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3294 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3295 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3296 if (!fail) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3297 { |
138 | 3298 if (!rmdir_utf8(ud->source_fd->path)) fail = file_data_ref(ud->source_fd); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3299 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3300 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3301 if (fail) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3302 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3303 gchar *text; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3304 |
138 | 3305 text = g_strdup_printf(_("Unable to delete folder:\n\n%s"), ud->source_fd->path); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3306 gd = file_util_warning_dialog(_("Delete failed"), text, GTK_STOCK_DIALOG_ERROR, NULL); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3307 g_free(text); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3308 |
138 | 3309 if (fail != ud->source_fd) |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3310 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3311 pref_spacer(gd->vbox, PREF_PAD_GROUP); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3312 text = g_strdup_printf(_("Removal of folder contents failed at this file:\n\n%s"), |
138 | 3313 fail->path); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3314 pref_label_new(gd->vbox, text); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3315 g_free(text); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3316 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3317 |
138 | 3318 file_data_unref(fail); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3319 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3320 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3321 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3322 file_util_data_free(ud); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3323 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3324 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3325 static GList *file_util_delete_dir_remaining_folders(GList *dlist) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3326 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3327 GList *rlist = NULL; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3328 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3329 while (dlist) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3330 { |
138 | 3331 FileData *fd; |
3332 | |
3333 fd = dlist->data; | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3334 dlist = dlist->next; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3335 |
138 | 3336 if (!fd->name || |
3337 (strcmp(fd->name, THUMB_FOLDER_GLOBAL) != 0 && | |
3338 strcmp(fd->name, THUMB_FOLDER_LOCAL) != 0 && | |
283 | 3339 strcmp(fd->name, GQ_CACHE_LOCAL_METADATA) != 0) ) |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3340 { |
138 | 3341 rlist = g_list_prepend(rlist, fd); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3342 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3343 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3344 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3345 return g_list_reverse(rlist); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3346 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3347 |
138 | 3348 void file_util_delete_dir(FileData *fd, GtkWidget *parent) |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3349 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3350 GList *dlist = NULL; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3351 GList *flist = NULL; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3352 GList *rlist; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3353 |
138 | 3354 if (!isdir(fd->path)) return; |
3355 | |
3356 if (islink(fd->path)) | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3357 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3358 UtilityData *ud; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3359 gchar *text; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3360 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3361 ud = g_new0(UtilityData, 1); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3362 ud->type = UTILITY_TYPE_DELETE_LINK; |
138 | 3363 ud->source_fd = file_data_ref(fd); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3364 ud->dlist = NULL; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3365 ud->flist = NULL; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3366 |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
223
diff
changeset
|
3367 ud->gd = file_util_gen_dlg(_("Delete folder"), GQ_WMCLASS, "dlg_confirm", |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3368 parent, TRUE, |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3369 file_util_delete_dir_cancel_cb, ud); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3370 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3371 text = g_strdup_printf(_("This will delete the symbolic link:\n\n%s\n\n" |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3372 "The folder this link points to will not be deleted."), |
138 | 3373 fd->path); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3374 generic_dialog_add_message(ud->gd, GTK_STOCK_DIALOG_QUESTION, |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3375 _("Delete symbolic link to folder?"), |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3376 text); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3377 g_free(text); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3378 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3379 generic_dialog_add_button(ud->gd, GTK_STOCK_DELETE, NULL, file_util_delete_dir_ok_cb, TRUE); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3380 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3381 gtk_widget_show(ud->gd->dialog); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3382 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3383 return; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3384 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3385 |
138 | 3386 if (!access_file(fd->path, W_OK | X_OK)) |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3387 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3388 gchar *text; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3389 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3390 text = g_strdup_printf(_("Unable to remove folder %s\n" |
138 | 3391 "Permissions do not allow writing to the folder."), fd->path); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3392 file_util_warning_dialog(_("Delete failed"), text, GTK_STOCK_DIALOG_ERROR, parent); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3393 g_free(text); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3394 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3395 return; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3396 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3397 |
138 | 3398 if (!filelist_read_lstat(fd->path, &flist, &dlist)) |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3399 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3400 gchar *text; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3401 |
138 | 3402 text = g_strdup_printf(_("Unable to list contents of folder %s"), fd->path); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3403 file_util_warning_dialog(_("Delete failed"), text, GTK_STOCK_DIALOG_ERROR, parent); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3404 g_free(text); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3405 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3406 return; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3407 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3408 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3409 rlist = file_util_delete_dir_remaining_folders(dlist); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3410 if (rlist) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3411 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3412 GenericDialog *gd; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3413 GtkWidget *box; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3414 gchar *text; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3415 |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
223
diff
changeset
|
3416 gd = file_util_gen_dlg(_("Folder contains subfolders"), GQ_WMCLASS, "dlg_warning", |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3417 parent, TRUE, NULL, NULL); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3418 generic_dialog_add_button(gd, GTK_STOCK_CLOSE, NULL, NULL, TRUE); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3419 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3420 text = g_strdup_printf(_("Unable to delete the folder:\n\n%s\n\n" |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3421 "This folder contains subfolders which must be moved before it can be deleted."), |
138 | 3422 fd->path); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3423 box = generic_dialog_add_message(gd, GTK_STOCK_DIALOG_WARNING, |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3424 _("Folder contains subfolders"), |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3425 text); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3426 g_free(text); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3427 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3428 box = pref_group_new(box, TRUE, _("Subfolders:"), GTK_ORIENTATION_VERTICAL); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3429 |
138 | 3430 rlist = filelist_sort_path(rlist); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3431 file_util_dialog_add_list(box, rlist, FALSE); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3432 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3433 gtk_widget_show(gd->dialog); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3434 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3435 else |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3436 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3437 UtilityData *ud; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3438 GtkWidget *box; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3439 GtkWidget *view; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3440 GtkTreeSelection *selection; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3441 gchar *text; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3442 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3443 ud = g_new0(UtilityData, 1); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3444 ud->type = UTILITY_TYPE_DELETE_FOLDER; |
138 | 3445 ud->source_fd = file_data_ref(fd); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3446 ud->dlist = dlist; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3447 dlist = NULL; |
138 | 3448 ud->flist = filelist_sort_path(flist); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3449 flist = NULL; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3450 |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
223
diff
changeset
|
3451 ud->gd = file_util_gen_dlg(_("Delete folder"), GQ_WMCLASS, "dlg_confirm", |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3452 parent, TRUE, file_util_delete_dir_cancel_cb, ud); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3453 generic_dialog_add_button(ud->gd, GTK_STOCK_DELETE, NULL, file_util_delete_dir_ok_cb, TRUE); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3454 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3455 text = g_strdup_printf(_("This will delete the folder:\n\n%s\n\n" |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3456 "The contents of this folder will also be deleted."), |
138 | 3457 fd->path); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3458 box = generic_dialog_add_message(ud->gd, GTK_STOCK_DIALOG_QUESTION, |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3459 _("Delete folder?"), |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3460 text); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3461 g_free(text); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3462 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3463 box = pref_group_new(box, TRUE, _("Contents:"), GTK_ORIENTATION_HORIZONTAL); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3464 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3465 view = file_util_dialog_add_list(box, ud->flist, FALSE); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3466 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3467 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3468 gtk_tree_selection_set_select_function(selection, file_util_delete_dir_preview_cb, ud, NULL); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3469 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3470 generic_dialog_add_image(ud->gd, box, NULL, NULL, NULL, NULL, FALSE); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3471 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3472 box_append_safe_delete_status(ud->gd); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3473 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3474 gtk_widget_show(ud->gd->dialog); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3475 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3476 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3477 g_list_free(rlist); |
138 | 3478 filelist_free(dlist); |
3479 filelist_free(flist); | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
3480 } |