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