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