Mercurial > geeqie
annotate src/utilops.c @ 905:b945b83e8108
Update POTFILES.in.
author | zas_ |
---|---|
date | Sun, 20 Jul 2008 15:21:06 +0000 |
parents | ae75cd2b4d76 |
children | ca8022a156ec |
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 | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
17 #include "cache.h" |
9 | 18 #include "cache_maint.h" |
19 #include "collect.h" | |
20 #include "dupe.h" | |
586 | 21 #include "filedata.h" |
22 #include "filefilter.h" | |
9 | 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" |
597 | 28 #include "trash.h" |
9 | 29 #include "ui_bookmark.h" |
30 #include "ui_fileops.h" | |
31 #include "ui_misc.h" | |
32 #include "ui_tabcomp.h" | |
140 | 33 #include "editors.h" |
9 | 34 |
35 /* | |
36 *-------------------------------------------------------------------------- | |
37 * Adds 1 or 2 images (if 2, side by side) to a GenericDialog | |
38 *-------------------------------------------------------------------------- | |
39 */ | |
40 | |
41 #define DIALOG_DEF_IMAGE_DIM_X 200 | |
42 #define DIALOG_DEF_IMAGE_DIM_Y 150 | |
43 | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
44 static void generic_dialog_add_image(GenericDialog *gd, GtkWidget *box, |
138 | 45 FileData *fd1, const gchar *header1, |
46 FileData *fd2, const gchar *header2, | |
9 | 47 gint show_filename) |
48 { | |
49 ImageWindow *imd; | |
50 GtkWidget *hbox = NULL; | |
51 GtkWidget *vbox; | |
52 GtkWidget *label = NULL; | |
53 | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
54 if (!box) box = gd->vbox; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
55 |
138 | 56 if (fd2) |
9 | 57 { |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
58 hbox = pref_box_new(box, TRUE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE); |
9 | 59 } |
60 | |
61 /* image 1 */ | |
62 | |
63 vbox = gtk_vbox_new(FALSE, PREF_PAD_GAP); | |
64 if (hbox) | |
65 { | |
66 GtkWidget *sep; | |
67 | |
68 gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0); | |
69 | |
70 sep = gtk_vseparator_new(); | |
71 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
72 gtk_widget_show(sep); | |
73 } | |
74 else | |
75 { | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
76 gtk_box_pack_start(GTK_BOX(box), vbox, TRUE, TRUE, PREF_PAD_GAP); |
9 | 77 } |
78 gtk_widget_show(vbox); | |
79 | |
80 if (header1) | |
81 { | |
82 GtkWidget *head; | |
83 | |
84 head = pref_label_new(vbox, header1); | |
85 pref_label_bold(head, TRUE, FALSE); | |
86 gtk_misc_set_alignment(GTK_MISC(head), 0.0, 0.5); | |
87 } | |
88 | |
89 imd = image_new(FALSE); | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
90 g_object_set(G_OBJECT(imd->pr), "zoom_expand", FALSE, NULL); |
9 | 91 gtk_widget_set_size_request(imd->widget, DIALOG_DEF_IMAGE_DIM_X, DIALOG_DEF_IMAGE_DIM_Y); |
92 gtk_box_pack_start(GTK_BOX(vbox), imd->widget, TRUE, TRUE, 0); | |
138 | 93 image_change_fd(imd, fd1, 0.0); |
9 | 94 gtk_widget_show(imd->widget); |
95 | |
96 if (show_filename) | |
97 { | |
138 | 98 label = pref_label_new(vbox, (fd1 == NULL) ? "" : fd1->name); |
9 | 99 } |
100 | |
101 /* only the first image is stored (for use in gd_image_set) */ | |
102 g_object_set_data(G_OBJECT(gd->dialog), "img_image", imd); | |
103 g_object_set_data(G_OBJECT(gd->dialog), "img_label", label); | |
442 | 104 |
9 | 105 |
106 /* image 2 */ | |
107 | |
138 | 108 if (hbox && fd2) |
9 | 109 { |
110 vbox = pref_box_new(hbox, TRUE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP); | |
111 | |
112 if (header2) | |
113 { | |
114 GtkWidget *head; | |
115 | |
116 head = pref_label_new(vbox, header2); | |
117 pref_label_bold(head, TRUE, FALSE); | |
118 gtk_misc_set_alignment(GTK_MISC(head), 0.0, 0.5); | |
119 } | |
120 | |
121 imd = image_new(FALSE); | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
122 g_object_set(G_OBJECT(imd->pr), "zoom_expand", FALSE, NULL); |
9 | 123 gtk_widget_set_size_request(imd->widget, DIALOG_DEF_IMAGE_DIM_X, DIALOG_DEF_IMAGE_DIM_Y); |
124 gtk_box_pack_start(GTK_BOX(vbox), imd->widget, TRUE, TRUE, 0); | |
138 | 125 image_change_fd(imd, fd2, 0.0); |
9 | 126 gtk_widget_show(imd->widget); |
127 | |
138 | 128 pref_label_new(vbox, fd2->name); |
9 | 129 } |
130 } | |
131 | |
138 | 132 static void generic_dialog_image_set(GenericDialog *gd, FileData *fd) |
9 | 133 { |
134 ImageWindow *imd; | |
135 GtkWidget *label; | |
442 | 136 |
9 | 137 imd = g_object_get_data(G_OBJECT(gd->dialog), "img_image"); |
138 label = g_object_get_data(G_OBJECT(gd->dialog), "img_label"); | |
139 | |
140 if (!imd) return; | |
141 | |
138 | 142 image_change_fd(imd, fd, 0.0); |
143 if (label) gtk_label_set_text(GTK_LABEL(label), fd->name); | |
9 | 144 } |
145 | |
146 /* | |
147 *-------------------------------------------------------------------------- | |
148 * Wrappers to aid in setting additional dialog properties (unde mouse, etc.) | |
149 *-------------------------------------------------------------------------- | |
150 */ | |
151 | |
152 GenericDialog *file_util_gen_dlg(const gchar *title, | |
153 const gchar *wmclass, const gchar *wmsubclass, | |
154 GtkWidget *parent, gint auto_close, | |
155 void (*cancel_cb)(GenericDialog *, gpointer), gpointer data) | |
156 { | |
157 GenericDialog *gd; | |
158 | |
159 gd = generic_dialog_new(title, wmclass, wmsubclass, parent, auto_close, cancel_cb, data); | |
318 | 160 if (options->place_dialogs_under_mouse) |
9 | 161 { |
162 gtk_window_set_position(GTK_WINDOW(gd->dialog), GTK_WIN_POS_MOUSE); | |
163 } | |
164 | |
165 return gd; | |
166 } | |
167 | |
168 FileDialog *file_util_file_dlg(const gchar *title, | |
169 const gchar *wmclass, const gchar *wmsubclass, | |
170 GtkWidget *parent, | |
171 void (*cancel_cb)(FileDialog *, gpointer), gpointer data) | |
172 { | |
138 | 173 FileDialog *fdlg; |
174 | |
175 fdlg = file_dialog_new(title, wmclass, wmsubclass, parent, cancel_cb, data); | |
318 | 176 if (options->place_dialogs_under_mouse) |
9 | 177 { |
138 | 178 gtk_window_set_position(GTK_WINDOW(GENERIC_DIALOG(fdlg)->dialog), GTK_WIN_POS_MOUSE); |
9 | 179 } |
180 | |
138 | 181 return fdlg; |
9 | 182 } |
183 | |
184 /* this warning dialog is copied from SLIK's ui_utildg.c, | |
185 * because it does not have a mouse center option, | |
186 * and we must center it before show, implement it here. | |
187 */ | |
188 static void file_util_warning_dialog_ok_cb(GenericDialog *gd, gpointer data) | |
189 { | |
190 /* no op */ | |
191 } | |
192 | |
193 GenericDialog *file_util_warning_dialog(const gchar *heading, const gchar *message, | |
194 const gchar *icon_stock_id, GtkWidget *parent) | |
195 { | |
196 GenericDialog *gd; | |
197 | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
223
diff
changeset
|
198 gd = file_util_gen_dlg(heading, GQ_WMCLASS, "warning", parent, TRUE, NULL, NULL); |
9 | 199 generic_dialog_add_message(gd, icon_stock_id, heading, message); |
200 generic_dialog_add_button(gd, GTK_STOCK_OK, NULL, file_util_warning_dialog_ok_cb, TRUE); | |
318 | 201 if (options->place_dialogs_under_mouse) |
9 | 202 { |
203 gtk_window_set_position(GTK_WINDOW(gd->dialog), GTK_WIN_POS_MOUSE); | |
204 } | |
205 gtk_widget_show(gd->dialog); | |
206 | |
207 return gd; | |
208 } | |
1 | 209 |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
210 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
|
211 { |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
212 gint n; |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
213 |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
214 if (!name) return 0; |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
215 |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
216 n = strlen(name); |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
217 |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
218 if (filter_name_exists(name)) |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
219 { |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
220 const gchar *ext; |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
221 |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
222 ext = extension_from_path(name); |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
223 if (ext) n -= strlen(ext); |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
224 } |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
225 |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
226 return n; |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
227 } |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
228 |
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
229 |
753 | 230 |
140 | 231 |
753 | 232 typedef enum { |
233 UTILITY_TYPE_COPY, | |
234 UTILITY_TYPE_MOVE, | |
235 UTILITY_TYPE_RENAME, | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
236 UTILITY_TYPE_RENAME_FOLDER, |
753 | 237 UTILITY_TYPE_EDITOR, |
238 UTILITY_TYPE_FILTER, | |
239 UTILITY_TYPE_DELETE, | |
240 UTILITY_TYPE_DELETE_LINK, | |
901 | 241 UTILITY_TYPE_DELETE_FOLDER, |
242 UTILITY_TYPE_CREATE_FOLDER | |
753 | 243 } UtilityType; |
244 | |
245 typedef enum { | |
246 UTILITY_PHASE_START = 0, | |
247 UTILITY_PHASE_ENTERING, | |
248 UTILITY_PHASE_CHECKED, | |
249 UTILITY_PHASE_DONE, | |
250 UTILITY_PHASE_CANCEL | |
251 } UtilityPhase; | |
252 | |
253 enum { | |
254 UTILITY_RENAME = 0, | |
255 UTILITY_RENAME_AUTO, | |
256 UTILITY_RENAME_FORMATTED | |
257 }; | |
258 | |
259 typedef struct _UtilityDataMessages UtilityDataMessages; | |
260 struct _UtilityDataMessages { | |
261 gchar *title; | |
262 gchar *question; | |
263 gchar *desc_flist; | |
264 gchar *desc_dlist; | |
265 gchar *desc_source_fd; | |
266 gchar *fail; | |
267 }; | |
268 | |
269 typedef struct _UtilityData UtilityData; | |
270 | |
271 struct _UtilityData { | |
272 UtilityType type; | |
273 UtilityPhase phase; | |
274 | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
275 FileData *dir_fd; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
276 GList *content_list; |
753 | 277 GList *flist; |
278 | |
279 GtkWidget *parent; | |
280 GenericDialog *gd; | |
281 FileDialog *fdlg; | |
282 | |
283 gint update_idle_id; | |
284 | |
285 /* alternative dialog parts */ | |
286 GtkWidget *notebook; | |
287 | |
288 UtilityDataMessages messages; | |
289 | |
290 /* helper entries for various modes */ | |
291 GtkWidget *rename_entry; | |
292 GtkWidget *rename_label; | |
293 GtkWidget *auto_entry_front; | |
294 GtkWidget *auto_entry_end; | |
295 GtkWidget *auto_spin_start; | |
296 GtkWidget *auto_spin_pad; | |
297 GtkWidget *format_entry; | |
298 GtkWidget *format_spin; | |
299 | |
300 GtkWidget *listview; | |
301 | |
302 | |
303 gchar *dest_path; | |
304 | |
305 /* data for the operation itself, internal or external */ | |
755 | 306 gboolean external; /* TRUE for external command, FALSE for internal */ |
753 | 307 |
308 gint external_command; | |
309 gpointer resume_data; | |
310 }; | |
311 | |
312 enum { | |
313 UTILITY_COLUMN_FD = 0, | |
314 UTILITY_COLUMN_PATH, | |
315 UTILITY_COLUMN_NAME, | |
316 UTILITY_COLUMN_SIDECARS, | |
317 UTILITY_COLUMN_DEST_PATH, | |
318 UTILITY_COLUMN_DEST_NAME, | |
319 UTILITY_COLUMN_COUNT | |
320 }; | |
321 | |
322 #define UTILITY_LIST_MIN_WIDTH 250 | |
323 #define UTILITY_LIST_MIN_HEIGHT 150 | |
324 | |
325 /* thumbnail spec has a max depth of 4 (.thumb??/fail/appname/??.png) */ | |
326 #define UTILITY_DELETE_MAX_DEPTH 5 | |
327 | |
328 static UtilityData *file_util_data_new(UtilityType type) | |
136 | 329 { |
753 | 330 UtilityData *ud; |
331 | |
332 ud = g_new0(UtilityData, 1); | |
333 ud->type = type; | |
334 ud->phase = UTILITY_PHASE_START; | |
335 ud->update_idle_id = -1; | |
336 ud->external_command = -1; | |
337 return ud; | |
338 } | |
339 | |
340 static void file_util_data_free(UtilityData *ud) | |
341 { | |
342 if (!ud) return; | |
343 | |
344 if (ud->update_idle_id != -1) g_source_remove(ud->update_idle_id); | |
345 | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
346 file_data_unref(ud->dir_fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
347 filelist_free(ud->content_list); |
753 | 348 filelist_free(ud->flist); |
349 | |
350 if (ud->gd) generic_dialog_close(ud->gd); | |
351 | |
352 g_free(ud->dest_path); | |
353 | |
354 g_free(ud); | |
355 } | |
356 | |
357 static GtkTreeViewColumn *file_util_dialog_add_list_column(GtkWidget *view, const gchar *text, gint n) | |
358 { | |
359 GtkTreeViewColumn *column; | |
360 GtkCellRenderer *renderer; | |
361 | |
362 column = gtk_tree_view_column_new(); | |
363 gtk_tree_view_column_set_title(column, text); | |
364 gtk_tree_view_column_set_min_width(column, 4); | |
365 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
366 renderer = gtk_cell_renderer_text_new(); | |
367 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
368 gtk_tree_view_column_add_attribute(column, renderer, "text", n); | |
369 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); | |
370 | |
371 return column; | |
372 } | |
373 | |
374 static void file_util_dialog_list_select(GtkWidget *view, gint n) | |
375 { | |
376 GtkTreeModel *store; | |
377 GtkTreeIter iter; | |
378 GtkTreeSelection *selection; | |
379 | |
380 store = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); | |
381 if (gtk_tree_model_iter_nth_child(store, &iter, NULL, n)) | |
140 | 382 { |
753 | 383 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); |
384 gtk_tree_selection_select_iter(selection, &iter); | |
385 } | |
386 } | |
387 | |
388 static GtkWidget *file_util_dialog_add_list(GtkWidget *box, GList *list, gint full_paths) | |
389 { | |
390 GtkWidget *scrolled; | |
391 GtkWidget *view; | |
392 GtkListStore *store; | |
393 | |
394 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
395 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
396 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
397 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
398 gtk_box_pack_start(GTK_BOX(box), scrolled, TRUE, TRUE, 0); | |
399 gtk_widget_show(scrolled); | |
400 | |
401 store = gtk_list_store_new(UTILITY_COLUMN_COUNT, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); | |
402 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
403 g_object_unref(store); | |
404 | |
405 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), TRUE); | |
406 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(view), FALSE); | |
407 | |
408 if (full_paths) | |
409 { | |
410 file_util_dialog_add_list_column(view, _("Location"), UTILITY_COLUMN_PATH); | |
140 | 411 } |
138 | 412 else |
413 { | |
753 | 414 file_util_dialog_add_list_column(view, _("Name"), UTILITY_COLUMN_NAME); |
138 | 415 } |
416 | |
753 | 417 gtk_widget_set_size_request(view, UTILITY_LIST_MIN_WIDTH, UTILITY_LIST_MIN_HEIGHT); |
418 gtk_container_add(GTK_CONTAINER(scrolled), view); | |
419 gtk_widget_show(view); | |
136 | 420 |
140 | 421 while (list) |
422 { | |
423 FileData *fd = list->data; | |
753 | 424 GtkTreeIter iter; |
425 gchar *sidecars; | |
426 | |
427 sidecars = file_data_sc_list_to_string(fd); | |
428 | |
429 gtk_list_store_append(store, &iter); | |
757 | 430 gtk_list_store_set(store, &iter, |
431 UTILITY_COLUMN_FD, fd, | |
432 UTILITY_COLUMN_PATH, fd->path, | |
433 UTILITY_COLUMN_NAME, fd->name, | |
434 UTILITY_COLUMN_SIDECARS, sidecars, | |
435 UTILITY_COLUMN_DEST_PATH, fd->change ? fd->change->dest : "error", | |
436 UTILITY_COLUMN_DEST_NAME, fd->change ? filename_from_path(fd->change->dest) : "error", | |
437 -1); | |
753 | 438 g_free(sidecars); |
439 | |
140 | 440 list = list->next; |
441 } | |
753 | 442 |
443 return view; | |
444 } | |
445 | |
446 | |
897 | 447 static void file_util_perform_ci_internal(UtilityData *ud); |
753 | 448 void file_util_dialog_run(UtilityData *ud); |
449 static gint file_util_perform_ci_cb(gpointer resume_data, gint flags, GList *list, gpointer data); | |
450 | |
451 /* call file_util_perform_ci_internal or start_editor_from_filelist_full */ | |
452 | |
453 | |
454 static void file_util_resume_cb(GenericDialog *gd, gpointer data) | |
455 { | |
456 UtilityData *ud = data; | |
457 if (ud->external) | |
458 editor_resume(ud->resume_data); | |
459 else | |
460 file_util_perform_ci_internal(ud); | |
461 } | |
462 | |
463 static void file_util_abort_cb(GenericDialog *gd, gpointer data) | |
464 { | |
465 UtilityData *ud = data; | |
466 if (ud->external) | |
467 editor_skip(ud->resume_data); | |
468 else | |
469 file_util_perform_ci_cb(NULL, EDITOR_ERROR_SKIPPED, ud->flist, ud); | |
140 | 470 |
471 } | |
472 | |
473 | |
753 | 474 static gint file_util_perform_ci_cb(gpointer resume_data, gint flags, GList *list, gpointer data) |
1 | 475 { |
753 | 476 UtilityData *ud = data; |
477 ud->resume_data = resume_data; | |
497 | 478 |
140 | 479 gint ret = EDITOR_CB_CONTINUE; |
480 if ((flags & EDITOR_ERROR_MASK) && !(flags & EDITOR_ERROR_SKIPPED)) | |
481 { | |
757 | 482 GString *msg = g_string_new(editor_get_error_str(flags)); |
483 GenericDialog *d; | |
484 g_string_append(msg, "\n"); | |
485 g_string_append(msg, ud->messages.fail); | |
486 g_string_append(msg, "\n"); | |
487 while (list) | |
488 { | |
489 FileData *fd = list->data; | |
442 | 490 |
757 | 491 g_string_append(msg, fd->path); |
492 g_string_append(msg, "\n"); | |
493 list = list->next; | |
494 } | |
495 if (resume_data) | |
496 { | |
497 g_string_append(msg, _("\n Continue multiple file operation?")); | |
498 d = file_util_gen_dlg(ud->messages.fail, GQ_WMCLASS, "dlg_confirm", | |
499 NULL, TRUE, | |
500 file_util_abort_cb, ud); | |
140 | 501 |
757 | 502 generic_dialog_add_message(d, GTK_STOCK_DIALOG_WARNING, NULL, msg->str); |
140 | 503 |
757 | 504 generic_dialog_add_button(d, GTK_STOCK_GO_FORWARD, _("Co_ntinue"), |
505 file_util_resume_cb, TRUE); | |
506 gtk_widget_show(d->dialog); | |
507 ret = EDITOR_CB_SUSPEND; | |
508 } | |
509 else | |
510 { | |
511 file_util_warning_dialog(ud->messages.fail, msg->str, GTK_STOCK_DIALOG_ERROR, NULL); | |
512 } | |
513 g_string_free(msg, TRUE); | |
140 | 514 } |
442 | 515 |
516 | |
753 | 517 while (list) /* be careful, file_util_perform_ci_internal can pass ud->flist as list */ |
140 | 518 { |
753 | 519 FileData *fd = list->data; |
520 list = list->next; | |
521 | |
522 if (!(flags & EDITOR_ERROR_MASK)) /* files were successfully deleted, call the maint functions */ | |
761 | 523 { |
524 file_data_sc_apply_ci(fd); | |
525 } | |
753 | 526 |
527 ud->flist = g_list_remove(ud->flist, fd); | |
528 file_data_sc_free_ci(fd); | |
529 file_data_unref(fd); | |
140 | 530 } |
753 | 531 |
532 if (!resume_data) /* end of the list */ | |
533 { | |
534 ud->phase = UTILITY_PHASE_DONE; | |
535 file_util_dialog_run(ud); | |
536 } | |
537 | |
140 | 538 return ret; |
539 } | |
540 | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
541 |
753 | 542 /* |
756 | 543 * Perform the operation described by FileDataChangeInfo on all files in the list |
753 | 544 * it is an alternative to start_editor_from_filelist_full, it should use similar interface |
545 */ | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
140
diff
changeset
|
546 |
1 | 547 |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
548 static void file_util_perform_ci_internal(UtilityData *ud) |
753 | 549 { |
550 | |
551 while (ud->flist) | |
1 | 552 { |
753 | 553 gint ret; |
554 | |
555 /* take a single entry each time, this allows better control over the operation */ | |
556 GList *single_entry = g_list_append(NULL, ud->flist->data); | |
557 gboolean last = !ud->flist->next; | |
757 | 558 gint status = EDITOR_ERROR_STATUS; |
559 | |
753 | 560 if (file_data_sc_perform_ci(single_entry->data)) |
757 | 561 status = 0; /* OK */ |
562 | |
563 ret = file_util_perform_ci_cb(GINT_TO_POINTER(!last), status, single_entry, ud); | |
753 | 564 g_list_free(single_entry); |
565 | |
566 if (ret == EDITOR_CB_SUSPEND || last) return; | |
567 | |
568 if (ret == EDITOR_CB_SKIP) | |
569 { | |
570 file_util_perform_ci_cb(NULL, EDITOR_ERROR_SKIPPED, ud->flist, ud); | |
571 } | |
572 | |
573 /* FIXME: convert the loop to idle call */ | |
574 | |
1 | 575 } |
576 } | |
577 | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
578 static void file_util_perform_ci_dir(UtilityData *ud, gboolean internal, gboolean ext_result) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
579 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
580 switch (ud->type) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
581 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
582 case UTILITY_TYPE_DELETE_LINK: |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
583 { |
897 | 584 if ((internal && file_data_sc_perform_ci(ud->dir_fd)) || |
585 (!internal && ext_result)) | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
586 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
587 file_data_sc_apply_ci(ud->dir_fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
588 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
589 else |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
590 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
591 gchar *text; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
592 |
901 | 593 text = g_strdup_printf("%s:\n\n%s", ud->messages.fail, ud->dir_fd->path); |
594 file_util_warning_dialog(ud->messages.fail, text, GTK_STOCK_DIALOG_ERROR, NULL); | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
595 g_free(text); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
596 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
597 file_data_sc_free_ci(ud->dir_fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
598 break; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
599 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
600 case UTILITY_TYPE_DELETE_FOLDER: |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
601 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
602 FileData *fail = NULL; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
603 GList *work; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
604 work = ud->content_list; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
605 while (work) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
606 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
607 FileData *fd; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
608 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
609 fd = work->data; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
610 work = work->next; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
611 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
612 if (!fail) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
613 { |
897 | 614 if ((internal && file_data_sc_perform_ci(fd)) || |
615 (!internal && ext_result)) | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
616 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
617 file_data_sc_apply_ci(fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
618 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
619 else |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
620 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
621 if (internal) fail = file_data_ref(fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
622 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
623 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
624 file_data_sc_free_ci(fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
625 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
626 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
627 if (!fail) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
628 { |
897 | 629 if ((internal && file_data_sc_perform_ci(ud->dir_fd)) || |
630 (!internal && ext_result)) | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
631 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
632 file_data_sc_apply_ci(ud->dir_fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
633 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
634 else |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
635 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
636 fail = file_data_ref(ud->dir_fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
637 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
638 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
639 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
640 if (fail) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
641 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
642 gchar *text; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
643 GenericDialog *gd; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
644 |
901 | 645 text = g_strdup_printf("%s:\n\n%s", ud->messages.fail, ud->dir_fd->path); |
646 gd = file_util_warning_dialog(ud->messages.fail, text, GTK_STOCK_DIALOG_ERROR, NULL); | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
647 g_free(text); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
648 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
649 if (fail != ud->dir_fd) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
650 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
651 pref_spacer(gd->vbox, PREF_PAD_GROUP); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
652 text = g_strdup_printf(_("Removal of folder contents failed at this file:\n\n%s"), |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
653 fail->path); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
654 pref_label_new(gd->vbox, text); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
655 g_free(text); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
656 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
657 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
658 file_data_unref(fail); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
659 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
660 break; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
661 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
662 case UTILITY_TYPE_RENAME_FOLDER: |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
663 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
664 FileData *fail = NULL; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
665 GList *work; |
897 | 666 if ((internal && file_data_sc_perform_ci(ud->dir_fd)) || |
667 (!internal && ext_result)) | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
668 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
669 file_data_sc_apply_ci(ud->dir_fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
670 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
671 else |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
672 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
673 fail = file_data_ref(ud->dir_fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
674 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
675 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
676 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
677 work = ud->content_list; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
678 while (work) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
679 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
680 FileData *fd; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
681 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
682 fd = work->data; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
683 work = work->next; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
684 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
685 if (!fail) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
686 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
687 file_data_sc_apply_ci(fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
688 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
689 file_data_sc_free_ci(fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
690 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
691 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
692 if (fail) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
693 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
694 gchar *text; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
695 GenericDialog *gd; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
696 |
901 | 697 text = g_strdup_printf("%s:\n\n%s", ud->messages.fail, ud->dir_fd->path); |
698 gd = file_util_warning_dialog(ud->messages.fail, text, GTK_STOCK_DIALOG_ERROR, NULL); | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
699 g_free(text); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
700 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
701 file_data_unref(fail); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
702 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
703 break; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
704 } |
901 | 705 case UTILITY_TYPE_CREATE_FOLDER: |
706 { | |
707 if ((internal && mkdir_utf8(ud->dir_fd->path, 0755)) || | |
708 (!internal && ext_result)) | |
709 { | |
710 file_data_send_notification(ud->dir_fd, NOTIFY_TYPE_REREAD); | |
711 } | |
712 else | |
713 { | |
714 gchar *text; | |
715 GenericDialog *gd; | |
716 | |
717 text = g_strdup_printf("%s:\n\n%s", ud->messages.fail, ud->dir_fd->path); | |
718 gd = file_util_warning_dialog(ud->messages.fail, text, GTK_STOCK_DIALOG_ERROR, NULL); | |
719 g_free(text); | |
720 } | |
721 | |
722 break; | |
723 } | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
724 default: |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
725 g_warning("unhandled operation"); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
726 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
727 ud->phase = UTILITY_PHASE_DONE; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
728 file_util_dialog_run(ud); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
729 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
730 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
731 static gint file_util_perform_ci_dir_cb(gpointer resume_data, gint flags, GList *list, gpointer data) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
732 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
733 UtilityData *ud = data; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
734 file_util_perform_ci_dir(ud, FALSE, !((flags & EDITOR_ERROR_MASK) && !(flags & EDITOR_ERROR_SKIPPED))); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
735 return EDITOR_CB_CONTINUE; /* does not matter, there was just single directory */ |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
736 } |
9 | 737 |
753 | 738 void file_util_perform_ci(UtilityData *ud) |
739 { | |
740 switch (ud->type) | |
741 { | |
742 case UTILITY_TYPE_COPY: | |
743 ud->external_command = CMD_COPY; | |
744 break; | |
745 case UTILITY_TYPE_MOVE: | |
746 ud->external_command = CMD_MOVE; | |
747 break; | |
748 case UTILITY_TYPE_RENAME: | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
749 case UTILITY_TYPE_RENAME_FOLDER: |
753 | 750 ud->external_command = CMD_RENAME; |
751 break; | |
752 case UTILITY_TYPE_DELETE: | |
753 case UTILITY_TYPE_DELETE_LINK: | |
754 case UTILITY_TYPE_DELETE_FOLDER: | |
755 ud->external_command = CMD_DELETE; | |
756 break; | |
901 | 757 case UTILITY_TYPE_CREATE_FOLDER: |
758 ud->external_command = CMD_FOLDER; | |
759 break; | |
753 | 760 case UTILITY_TYPE_FILTER: |
761 case UTILITY_TYPE_EDITOR: | |
762 g_assert(ud->external_command != -1); /* it should be already set */ | |
763 break; | |
764 } | |
9 | 765 |
766
7148e125bf23
Check for existing editor command using is_valid_editor_command().
zas_
parents:
761
diff
changeset
|
766 if (is_valid_editor_command(ud->external_command)) |
9 | 767 { |
753 | 768 gint flags; |
757 | 769 |
753 | 770 ud->external = TRUE; |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
771 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
772 if (ud->dir_fd) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
773 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
774 flags = start_editor_from_file_full(ud->external_command, ud->dir_fd, file_util_perform_ci_dir_cb, ud); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
775 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
776 else |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
777 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
778 flags = start_editor_from_filelist_full(ud->external_command, ud->flist, file_util_perform_ci_cb, ud); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
779 } |
757 | 780 |
781 if (flags) | |
9 | 782 { |
753 | 783 gchar *text = g_strdup_printf(_("%s\nUnable to start external command.\n"), editor_get_error_str(flags)); |
784 file_util_warning_dialog(ud->messages.fail, text, GTK_STOCK_DIALOG_ERROR, NULL); | |
785 g_free(text); | |
9 | 786 } |
787 } | |
788 else | |
789 { | |
753 | 790 ud->external = FALSE; |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
791 if (ud->dir_fd) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
792 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
793 file_util_perform_ci_dir(ud, TRUE, FALSE); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
794 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
795 else |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
796 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
797 file_util_perform_ci_internal(ud); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
798 } |
1 | 799 } |
800 } | |
801 | |
757 | 802 static void file_util_cancel_cb(GenericDialog *gd, gpointer data) |
753 | 803 { |
804 UtilityData *ud = data; | |
805 | |
806 generic_dialog_close(gd); | |
1 | 807 |
753 | 808 ud->gd = NULL; |
809 | |
810 ud->phase = UTILITY_PHASE_CANCEL; | |
811 file_util_dialog_run(ud); | |
1 | 812 } |
813 | |
757 | 814 static void file_util_ok_cb(GenericDialog *gd, gpointer data) |
1 | 815 { |
753 | 816 UtilityData *ud = data; |
817 | |
818 generic_dialog_close(gd); | |
819 | |
820 ud->gd = NULL; | |
138 | 821 |
753 | 822 file_util_dialog_run(ud); |
1 | 823 } |
824 | |
757 | 825 static void file_util_fdlg_cancel_cb(FileDialog *fdlg, gpointer data) |
1 | 826 { |
753 | 827 UtilityData *ud = data; |
675 | 828 |
753 | 829 file_dialog_close(fdlg); |
9 | 830 |
753 | 831 ud->fdlg = NULL; |
832 | |
833 ud->phase = UTILITY_PHASE_CANCEL; | |
834 file_util_dialog_run(ud); | |
835 } | |
9 | 836 |
900 | 837 static void file_util_dest_folder_update_path(UtilityData *ud) |
753 | 838 { |
839 g_free(ud->dest_path); | |
900 | 840 ud->dest_path = g_strdup(gtk_entry_get_text(GTK_ENTRY(ud->fdlg->entry))); |
753 | 841 |
842 switch (ud->type) | |
1 | 843 { |
753 | 844 case UTILITY_TYPE_COPY: |
845 file_data_sc_update_ci_copy_list(ud->flist, ud->dest_path); | |
846 break; | |
847 case UTILITY_TYPE_MOVE: | |
848 file_data_sc_update_ci_move_list(ud->flist, ud->dest_path); | |
849 break; | |
850 case UTILITY_TYPE_FILTER: | |
851 case UTILITY_TYPE_EDITOR: | |
852 file_data_sc_update_ci_unspecified_list(ud->flist, ud->dest_path); | |
853 break; | |
901 | 854 case UTILITY_TYPE_CREATE_FOLDER: |
855 file_data_unref(ud->dir_fd); | |
856 ud->dir_fd = file_data_new_simple(ud->dest_path); | |
857 break; | |
753 | 858 case UTILITY_TYPE_DELETE: |
859 case UTILITY_TYPE_DELETE_LINK: | |
860 case UTILITY_TYPE_DELETE_FOLDER: | |
861 case UTILITY_TYPE_RENAME: | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
862 case UTILITY_TYPE_RENAME_FOLDER: |
753 | 863 g_warning("unhandled operation"); |
1 | 864 } |
865 } | |
866 | |
900 | 867 static void file_util_fdlg_ok_cb(FileDialog *fdlg, gpointer data) |
868 { | |
869 UtilityData *ud = data; | |
870 | |
871 file_util_dest_folder_update_path(ud); | |
872 file_dialog_close(fdlg); | |
873 | |
874 ud->fdlg = NULL; | |
875 | |
876 file_util_dialog_run(ud); | |
877 } | |
878 | |
879 | |
880 static void file_util_dest_folder_entry_cb(GtkWidget *entry, gpointer data) | |
881 { | |
882 UtilityData *ud = data; | |
883 file_util_dest_folder_update_path(ud); | |
884 } | |
1 | 885 |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
886 /* 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
|
887 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
|
888 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
889 gchar *new_name; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
890 gchar *parsed; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
891 const gchar *ext; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
892 gchar *middle; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
893 gchar *tmp; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
894 gchar *pad_start; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
895 gchar *pad_end; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
896 gint padding; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
897 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
898 if (!format || !name) return NULL; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
899 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
900 tmp = g_strdup(format); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
901 pad_start = strchr(tmp, '#'); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
902 if (pad_start) |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
903 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
904 pad_end = pad_start; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
905 padding = 0; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
906 while (*pad_end == '#') |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
907 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
908 pad_end++; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
909 padding++; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
910 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
911 *pad_start = '\0'; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
912 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
913 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
|
914 g_free(tmp); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
915 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
916 else |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
917 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
918 parsed = tmp; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
919 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
920 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
921 ext = extension_from_path(name); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
922 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
923 middle = strchr(parsed, '*'); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
924 if (middle) |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
925 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
926 gchar *base; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
927 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
928 *middle = '\0'; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
929 middle++; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
930 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
931 base = remove_extension_from_path(name); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
932 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
|
933 g_free(base); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
934 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
935 else |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
936 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
937 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
|
938 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
939 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
940 g_free(parsed); |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
941 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
942 return new_name; |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
943 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
944 |
9 | 945 |
753 | 946 static void file_util_rename_preview_update(UtilityData *ud) |
1 | 947 { |
9 | 948 GtkTreeModel *store; |
753 | 949 GtkTreeSelection *selection; |
9 | 950 GtkTreeIter iter; |
951 const gchar *front; | |
952 const gchar *end; | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
953 const gchar *format; |
9 | 954 gint valid; |
955 gint start_n; | |
956 gint padding; | |
957 gint n; | |
753 | 958 gint mode; |
9 | 959 |
753 | 960 mode = gtk_notebook_get_current_page(GTK_NOTEBOOK(ud->notebook)); |
9 | 961 |
753 | 962 if (mode == UTILITY_RENAME) |
963 { | |
964 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ud->listview)); | |
965 if (gtk_tree_selection_get_selected(selection, &store, &iter)) | |
966 { | |
967 FileData *fd; | |
968 const gchar *dest = gtk_entry_get_text(GTK_ENTRY(ud->rename_entry)); | |
969 | |
970 gtk_tree_model_get(store, &iter, UTILITY_COLUMN_FD, &fd, -1); | |
971 file_data_sc_update_ci_rename(fd, dest); | |
972 gtk_list_store_set(GTK_LIST_STORE(store), &iter, | |
973 UTILITY_COLUMN_DEST_PATH, fd->change->dest, | |
974 UTILITY_COLUMN_DEST_NAME, filename_from_path(fd->change->dest), | |
975 -1); | |
976 } | |
977 return; | |
978 } | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
979 |
753 | 980 |
981 front = gtk_entry_get_text(GTK_ENTRY(ud->auto_entry_front)); | |
982 end = gtk_entry_get_text(GTK_ENTRY(ud->auto_entry_end)); | |
983 padding = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ud->auto_spin_pad)); | |
984 | |
985 format = gtk_entry_get_text(GTK_ENTRY(ud->format_entry)); | |
986 | |
987 if (mode == UTILITY_RENAME_FORMATTED) | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
988 { |
753 | 989 start_n = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ud->format_spin)); |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
990 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
991 else |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
992 { |
753 | 993 start_n = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ud->auto_spin_start)); |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
994 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
995 |
753 | 996 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ud->listview)); |
9 | 997 n = start_n; |
998 valid = gtk_tree_model_get_iter_first(store, &iter); | |
999 while (valid) | |
1000 { | |
1001 gchar *dest; | |
753 | 1002 FileData *fd; |
1003 gtk_tree_model_get(store, &iter, UTILITY_COLUMN_FD, &fd, -1); | |
9 | 1004 |
753 | 1005 if (mode == UTILITY_RENAME_FORMATTED) |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1006 { |
138 | 1007 dest = 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
|
1008 } |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1009 else |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1010 { |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1011 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
|
1012 } |
753 | 1013 |
1014 file_data_sc_update_ci_rename(fd, dest); | |
1015 gtk_list_store_set(GTK_LIST_STORE(store), &iter, | |
1016 UTILITY_COLUMN_DEST_PATH, fd->change->dest, | |
1017 UTILITY_COLUMN_DEST_NAME, filename_from_path(fd->change->dest), | |
1018 -1); | |
9 | 1019 g_free(dest); |
1020 | |
1021 n++; | |
1022 valid = gtk_tree_model_iter_next(store, &iter); | |
1023 } | |
1024 | |
1 | 1025 } |
1026 | |
753 | 1027 static void file_util_rename_preview_entry_cb(GtkWidget *entry, gpointer data) |
9 | 1028 { |
753 | 1029 UtilityData *ud = data; |
1030 file_util_rename_preview_update(ud); | |
1031 } | |
9 | 1032 |
753 | 1033 static void file_util_rename_preview_adj_cb(GtkWidget *spin, gpointer data) |
1034 { | |
1035 UtilityData *ud = data; | |
1036 file_util_rename_preview_update(ud); | |
1037 } | |
9 | 1038 |
753 | 1039 static gboolean file_util_rename_idle_cb(gpointer data) |
1040 { | |
1041 UtilityData *ud = data; | |
1042 | |
1043 file_util_rename_preview_update(ud); | |
1044 | |
1045 ud->update_idle_id = -1; | |
9 | 1046 return FALSE; |
1047 } | |
1048 | |
753 | 1049 static void file_util_rename_preview_order_cb(GtkTreeModel *treemodel, GtkTreePath *tpath, |
9 | 1050 GtkTreeIter *iter, gpointer data) |
1051 { | |
753 | 1052 UtilityData *ud = data; |
9 | 1053 |
757 | 1054 if (ud->update_idle_id != -1) return; |
1055 | |
1056 ud->update_idle_id = g_idle_add(file_util_rename_idle_cb, ud); | |
9 | 1057 } |
1058 | |
753 | 1059 |
1060 static gboolean file_util_preview_cb(GtkTreeSelection *selection, GtkTreeModel *store, | |
1061 GtkTreePath *tpath, gboolean path_currently_selected, | |
1062 gpointer data) | |
9 | 1063 { |
753 | 1064 UtilityData *ud = data; |
1065 GtkTreeIter iter; | |
1066 FileData *fd = NULL; | |
1067 | |
1068 if (path_currently_selected || | |
1069 !gtk_tree_model_get_iter(store, &iter, tpath)) return TRUE; | |
1070 | |
1071 gtk_tree_model_get(store, &iter, UTILITY_COLUMN_FD, &fd, -1); | |
1072 generic_dialog_image_set(ud->gd, fd); | |
1073 | |
1074 if (ud->type == UTILITY_TYPE_RENAME) | |
1075 { | |
1076 const gchar *name = filename_from_path(fd->change->dest); | |
757 | 1077 |
753 | 1078 gtk_widget_grab_focus(ud->rename_entry); |
1079 gtk_label_set_text(GTK_LABEL(ud->rename_label), fd->name); | |
1080 g_signal_handlers_block_by_func(ud->rename_entry, G_CALLBACK(file_util_rename_preview_entry_cb), ud); | |
1081 gtk_entry_set_text(GTK_ENTRY(ud->rename_entry), name); | |
1082 gtk_editable_select_region(GTK_EDITABLE(ud->rename_entry), 0, filename_base_length(name)); | |
1083 g_signal_handlers_unblock_by_func(ud->rename_entry, G_CALLBACK(file_util_rename_preview_entry_cb), ud); | |
1084 } | |
1085 | |
1086 return TRUE; | |
9 | 1087 } |
1088 | |
753 | 1089 |
1090 | |
1091 static void box_append_safe_delete_status(GenericDialog *gd) | |
9 | 1092 { |
753 | 1093 GtkWidget *label; |
1094 gchar *buf; | |
1095 | |
1096 buf = file_util_safe_delete_status(); | |
1097 label = pref_label_new(gd->vbox, buf); | |
1098 g_free(buf); | |
1099 | |
1100 gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5); | |
1101 gtk_widget_set_sensitive(label, FALSE); | |
9 | 1102 } |
1103 | |
753 | 1104 |
1105 static void file_util_dialog_init_simple_list(UtilityData *ud) | |
1 | 1106 { |
753 | 1107 GtkWidget *box; |
1108 GtkTreeSelection *selection; | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1109 gchar *dir_msg; |
757 | 1110 |
753 | 1111 ud->gd = file_util_gen_dlg(ud->messages.title, GQ_WMCLASS, "dlg_confirm", |
757 | 1112 ud->parent, FALSE, file_util_cancel_cb, ud); |
753 | 1113 generic_dialog_add_button(ud->gd, GTK_STOCK_DELETE, NULL, file_util_ok_cb, TRUE); |
1114 | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1115 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1116 if (ud->dir_fd) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1117 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1118 dir_msg = g_strdup_printf("%s\n\n%s\n", ud->messages.desc_source_fd, ud->dir_fd->path); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1119 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1120 else |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1121 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1122 dir_msg = g_strdup(""); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1123 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1124 |
753 | 1125 box = generic_dialog_add_message(ud->gd, GTK_STOCK_DIALOG_QUESTION, |
757 | 1126 ud->messages.question, |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1127 dir_msg); |
753 | 1128 |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1129 g_free(dir_msg); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1130 |
753 | 1131 box = pref_group_new(box, TRUE, ud->messages.desc_flist, GTK_ORIENTATION_HORIZONTAL); |
1132 | |
1133 ud->listview = file_util_dialog_add_list(box, ud->flist, FALSE); | |
1134 file_util_dialog_add_list_column(ud->listview, _("Sidecars"), UTILITY_COLUMN_SIDECARS); | |
9 | 1135 |
753 | 1136 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ud->listview)); |
1137 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); | |
1138 gtk_tree_selection_set_select_function(selection, file_util_preview_cb, ud, NULL); | |
1139 | |
1140 generic_dialog_add_image(ud->gd, box, NULL, NULL, NULL, NULL, FALSE); | |
1141 | |
1142 box_append_safe_delete_status(ud->gd); | |
1143 | |
1144 gtk_widget_show(ud->gd->dialog); | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1145 |
753 | 1146 file_util_dialog_list_select(ud->listview, 0); |
1147 } | |
1148 | |
1149 static void file_util_dialog_init_dest_folder(UtilityData *ud) | |
1150 { | |
1151 FileDialog *fdlg; | |
1152 GtkWidget *label; | |
1153 const gchar *stock_id; | |
1154 | |
1155 if (ud->type == UTILITY_TYPE_COPY) | |
9 | 1156 { |
753 | 1157 stock_id = GTK_STOCK_COPY; |
1158 } | |
1159 else | |
1160 { | |
1161 stock_id = GTK_STOCK_OK; | |
9 | 1162 } |
1163 | |
753 | 1164 fdlg = file_util_file_dlg(ud->messages.title, GQ_WMCLASS, "dlg_dest_folder", ud->parent, |
757 | 1165 file_util_fdlg_cancel_cb, ud); |
753 | 1166 |
1167 ud->fdlg = fdlg; | |
1168 | |
1169 generic_dialog_add_message(GENERIC_DIALOG(fdlg), NULL, ud->messages.question, NULL); | |
1170 | |
1171 label = pref_label_new(GENERIC_DIALOG(fdlg)->vbox, _("Choose the destination folder.")); | |
1172 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); | |
1173 pref_spacer(GENERIC_DIALOG(fdlg)->vbox, 0); | |
1174 | |
1175 file_dialog_add_button(fdlg, stock_id, ud->messages.title, file_util_fdlg_ok_cb, TRUE); | |
1176 | |
1177 file_dialog_add_path_widgets(fdlg, NULL, ud->dest_path, "move_copy", NULL, NULL); | |
1178 | |
1179 g_signal_connect(G_OBJECT(fdlg->entry), "changed", | |
1180 G_CALLBACK(file_util_dest_folder_entry_cb), ud); | |
1181 | |
1182 gtk_widget_show(GENERIC_DIALOG(fdlg)->dialog); | |
9 | 1183 } |
1184 | |
753 | 1185 |
9 | 1186 static GtkWidget *furm_simple_vlabel(GtkWidget *box, const gchar *text, gint expand) |
1187 { | |
1188 GtkWidget *vbox; | |
1189 GtkWidget *label; | |
1190 | |
1191 vbox = gtk_vbox_new(FALSE, 0); | |
1192 gtk_box_pack_start(GTK_BOX(box), vbox, expand, expand, 0); | |
1193 gtk_widget_show(vbox); | |
1194 | |
1195 label = gtk_label_new(text); | |
1196 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
1197 gtk_widget_show(label); | |
1198 | |
1199 return vbox; | |
1200 } | |
1201 | |
753 | 1202 |
1203 static void file_util_dialog_init_source_dest(UtilityData *ud) | |
9 | 1204 { |
753 | 1205 GtkTreeModel *store; |
9 | 1206 GtkTreeSelection *selection; |
753 | 1207 GtkWidget *box; |
9 | 1208 GtkWidget *hbox; |
1209 GtkWidget *box2; | |
1210 GtkWidget *table; | |
1211 GtkWidget *combo; | |
753 | 1212 GtkWidget *page; |
1 | 1213 |
753 | 1214 ud->gd = file_util_gen_dlg(ud->messages.title, GQ_WMCLASS, "dlg_confirm", |
757 | 1215 ud->parent, FALSE, file_util_cancel_cb, ud); |
138 | 1216 |
753 | 1217 box = generic_dialog_add_message(ud->gd, NULL, ud->messages.question, NULL); |
1218 generic_dialog_add_button(ud->gd, GTK_STOCK_OK, ud->messages.title, file_util_ok_cb, TRUE); | |
9 | 1219 |
753 | 1220 box = pref_group_new(box, TRUE, ud->messages.desc_flist, GTK_ORIENTATION_HORIZONTAL); |
9 | 1221 |
753 | 1222 ud->listview = file_util_dialog_add_list(box, ud->flist, FALSE); |
1223 file_util_dialog_add_list_column(ud->listview, _("Sidecars"), UTILITY_COLUMN_SIDECARS); | |
442 | 1224 |
753 | 1225 file_util_dialog_add_list_column(ud->listview, _("New name"), UTILITY_COLUMN_DEST_NAME); |
1 | 1226 |
753 | 1227 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ud->listview)); |
1228 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_SINGLE); | |
1229 gtk_tree_selection_set_select_function(selection, file_util_preview_cb, ud, NULL); | |
9 | 1230 |
1231 | |
753 | 1232 // column = file_util_rename_multiple_add_column(rd, _("Preview"), RENAME_COLUMN_PREVIEW); |
1233 // gtk_tree_view_column_set_visible(column, FALSE); | |
442 | 1234 |
753 | 1235 gtk_tree_view_set_reorderable(GTK_TREE_VIEW(ud->listview), TRUE); |
1236 | |
1237 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ud->listview)); | |
9 | 1238 g_signal_connect(G_OBJECT(store), "row_changed", |
753 | 1239 G_CALLBACK(file_util_rename_preview_order_cb), ud); |
1240 gtk_widget_set_size_request(ud->listview, 300, 150); | |
1 | 1241 |
753 | 1242 generic_dialog_add_image(ud->gd, box, NULL, NULL, NULL, NULL, FALSE); |
9 | 1243 |
753 | 1244 // gtk_container_add(GTK_CONTAINER(scrolled), view); |
1245 gtk_widget_show(ud->gd->dialog); | |
9 | 1246 |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1247 |
753 | 1248 ud->notebook = gtk_notebook_new(); |
1249 | |
1250 gtk_box_pack_start(GTK_BOX(ud->gd->vbox), ud->notebook, FALSE, FALSE, 0); | |
1251 gtk_widget_show(ud->notebook); | |
1252 | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1253 |
753 | 1254 page = gtk_vbox_new(FALSE, PREF_PAD_GAP); |
1255 gtk_notebook_append_page(GTK_NOTEBOOK(ud->notebook), page, gtk_label_new(_("Manual rename"))); | |
1256 gtk_widget_show(page); | |
1257 | |
1258 table = pref_table_new(page, 2, 2, FALSE, FALSE); | |
9 | 1259 |
1260 pref_table_label(table, 0, 0, _("Original name:"), 1.0); | |
753 | 1261 ud->rename_label = pref_table_label(table, 1, 0, "", 0.0); |
9 | 1262 |
1263 pref_table_label(table, 0, 1, _("New name:"), 1.0); | |
1264 | |
753 | 1265 ud->rename_entry = gtk_entry_new(); |
1266 gtk_table_attach(GTK_TABLE(table), ud->rename_entry, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 0, 0); | |
1267 generic_dialog_attach_default(GENERIC_DIALOG(ud->gd), ud->rename_entry); | |
1268 gtk_widget_grab_focus(ud->rename_entry); | |
1269 | |
1270 g_signal_connect(G_OBJECT(ud->rename_entry), "changed", | |
1271 G_CALLBACK(file_util_rename_preview_entry_cb), ud); | |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
1272 |
753 | 1273 gtk_widget_show(ud->rename_entry); |
9 | 1274 |
753 | 1275 page = gtk_vbox_new(FALSE, PREF_PAD_GAP); |
1276 gtk_notebook_append_page(GTK_NOTEBOOK(ud->notebook), page, gtk_label_new(_("Auto rename"))); | |
1277 gtk_widget_show(page); | |
9 | 1278 |
753 | 1279 |
1280 hbox = pref_box_new(page, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP); | |
9 | 1281 |
1282 box2 = furm_simple_vlabel(hbox, _("Begin text"), TRUE); | |
1283 | |
753 | 1284 combo = history_combo_new(&ud->auto_entry_front, "", "numerical_rename_prefix", -1); |
1285 g_signal_connect(G_OBJECT(ud->auto_entry_front), "changed", | |
1286 G_CALLBACK(file_util_rename_preview_entry_cb), ud); | |
9 | 1287 gtk_box_pack_start(GTK_BOX(box2), combo, TRUE, TRUE, 0); |
1288 gtk_widget_show(combo); | |
442 | 1289 |
9 | 1290 box2 = furm_simple_vlabel(hbox, _("Start #"), FALSE); |
1291 | |
753 | 1292 ud->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
|
1293 0.0, 1000000.0, 1.0, 0, 1.0, |
753 | 1294 G_CALLBACK(file_util_rename_preview_adj_cb), ud); |
9 | 1295 |
1296 box2 = furm_simple_vlabel(hbox, _("End text"), TRUE); | |
1297 | |
753 | 1298 combo = history_combo_new(&ud->auto_entry_end, "", "numerical_rename_suffix", -1); |
1299 g_signal_connect(G_OBJECT(ud->auto_entry_end), "changed", | |
1300 G_CALLBACK(file_util_rename_preview_entry_cb), ud); | |
9 | 1301 gtk_box_pack_start(GTK_BOX(box2), combo, TRUE, TRUE, 0); |
1302 gtk_widget_show(combo); | |
1303 | |
753 | 1304 ud->auto_spin_pad = pref_spin_new(page, _("Padding:"), NULL, |
9 | 1305 1.0, 8.0, 1.0, 0, 1.0, |
753 | 1306 G_CALLBACK(file_util_rename_preview_adj_cb), ud); |
9 | 1307 |
753 | 1308 page = gtk_vbox_new(FALSE, PREF_PAD_GAP); |
1309 gtk_notebook_append_page(GTK_NOTEBOOK(ud->notebook), page, gtk_label_new(_("Formatted rename"))); | |
1310 gtk_widget_show(page); | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1311 |
753 | 1312 hbox = pref_box_new(page, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP); |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1313 |
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1314 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
|
1315 |
753 | 1316 combo = history_combo_new(&ud->format_entry, "", "auto_rename_format", -1); |
1317 g_signal_connect(G_OBJECT(ud->format_entry), "changed", | |
1318 G_CALLBACK(file_util_rename_preview_entry_cb), ud); | |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1319 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
|
1320 gtk_widget_show(combo); |
442 | 1321 |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1322 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
|
1323 |
753 | 1324 ud->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
|
1325 0.0, 1000000.0, 1.0, 0, 1.0, |
753 | 1326 G_CALLBACK(file_util_rename_preview_adj_cb), ud); |
66
ebbff299ad0d
Fri Sep 1 02:12:45 2006 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1327 |
753 | 1328 // gtk_combo_box_set_active(GTK_COMBO_BOX(ud->combo_type), 0); /* callback will take care of the rest */ |
138 | 1329 |
753 | 1330 file_util_dialog_list_select(ud->listview, 0); |
1 | 1331 } |
1332 | |
9 | 1333 |
753 | 1334 void file_util_dialog_run(UtilityData *ud) |
1 | 1335 { |
753 | 1336 switch (ud->phase) |
1337 { | |
1338 case UTILITY_PHASE_START: | |
1339 /* create the dialogs */ | |
1340 switch (ud->type) | |
1341 { | |
1342 case UTILITY_TYPE_DELETE: | |
1343 case UTILITY_TYPE_DELETE_LINK: | |
1344 case UTILITY_TYPE_DELETE_FOLDER: | |
1345 case UTILITY_TYPE_EDITOR: | |
1346 file_util_dialog_init_simple_list(ud); | |
1347 break; | |
1348 case UTILITY_TYPE_RENAME: | |
1349 file_util_dialog_init_source_dest(ud); | |
1350 break; | |
1351 case UTILITY_TYPE_COPY: | |
1352 case UTILITY_TYPE_MOVE: | |
1353 case UTILITY_TYPE_FILTER: | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1354 case UTILITY_TYPE_RENAME_FOLDER: |
901 | 1355 case UTILITY_TYPE_CREATE_FOLDER: |
753 | 1356 file_util_dialog_init_dest_folder(ud); |
1357 break; | |
1358 } | |
1359 ud->phase = UTILITY_PHASE_ENTERING; | |
1360 break; | |
1361 case UTILITY_PHASE_ENTERING: | |
1362 /* FIXME use file_data_sc_check_ci_dest to detect problems and eventually go back to PHASE_START | |
1363 or to PHASE_CANCEL */ | |
1364 | |
1365 ud->phase = UTILITY_PHASE_CHECKED; | |
1366 case UTILITY_PHASE_CHECKED: | |
1367 file_util_perform_ci(ud); | |
1368 break; | |
1369 case UTILITY_PHASE_CANCEL: | |
1370 case UTILITY_PHASE_DONE: | |
1371 file_data_sc_free_ci_list(ud->flist); | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1372 file_data_sc_free_ci_list(ud->content_list); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1373 if (ud->dir_fd) file_data_sc_free_ci(ud->dir_fd); |
753 | 1374 file_util_data_free(ud); |
1375 break; | |
1376 } | |
1 | 1377 } |
1378 | |
753 | 1379 |
1380 | |
1381 | |
757 | 1382 static void file_util_warn_op_in_progress(const gchar *title) |
1383 { | |
1384 file_util_warning_dialog(title, _("Another operation in progress.\n"), GTK_STOCK_DIALOG_ERROR, NULL); | |
1385 } | |
9 | 1386 |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1387 static void file_util_disable_grouping_sc_list(GList *list) |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1388 { |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1389 GList *work = list; |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1390 |
855 | 1391 while (work) |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1392 { |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1393 FileData *fd = work->data; |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1394 work = work->next; |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1395 |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1396 if (fd->parent) file_data_disable_grouping(fd, TRUE); |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1397 } |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1398 |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1399 } |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1400 |
753 | 1401 static void file_util_delete_full(FileData *source_fd, GList *source_list, GtkWidget *parent, UtilityPhase phase) |
1402 { | |
1403 UtilityData *ud; | |
1404 GList *flist = filelist_copy(source_list); | |
1405 | |
1406 if (source_fd) | |
1407 flist = g_list_append(flist, file_data_ref(source_fd)); | |
9 | 1408 |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1409 file_util_disable_grouping_sc_list(flist); |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1410 |
753 | 1411 if (!file_data_sc_add_ci_delete_list(flist)) |
1412 { | |
757 | 1413 file_util_warn_op_in_progress(_("File deletion failed")); |
753 | 1414 filelist_free(flist); |
1 | 1415 return; |
1416 } | |
753 | 1417 |
1418 ud = file_util_data_new(UTILITY_TYPE_DELETE); | |
1419 | |
1420 ud->phase = phase; | |
138 | 1421 |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1422 ud->dir_fd = NULL; |
753 | 1423 ud->flist = flist; |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1424 ud->content_list = NULL; |
753 | 1425 ud->parent = parent; |
1426 | |
1427 ud->messages.title = _("Delete"); | |
1428 ud->messages.question = _("Delete files?"); | |
1429 ud->messages.desc_flist = _("This will delete the following files"); | |
1430 ud->messages.desc_dlist = ""; | |
1431 ud->messages.desc_source_fd = ""; | |
1432 ud->messages.fail = _("File deletion failed"); | |
1433 | |
1434 file_util_dialog_run(ud); | |
1 | 1435 } |
1436 | |
753 | 1437 static void file_util_move_full(FileData *source_fd, GList *source_list, const gchar *dest_path, GtkWidget *parent, UtilityPhase phase) |
1 | 1438 { |
753 | 1439 UtilityData *ud; |
1440 GList *flist = filelist_copy(source_list); | |
1441 | |
1442 if (source_fd) | |
1443 flist = g_list_append(flist, file_data_ref(source_fd)); | |
1444 | |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1445 file_util_disable_grouping_sc_list(flist); |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1446 |
753 | 1447 if (!file_data_sc_add_ci_move_list(flist, dest_path)) |
1448 { | |
757 | 1449 file_util_warn_op_in_progress(_("Move failed")); |
753 | 1450 filelist_free(flist); |
1451 return; | |
1452 } | |
1453 | |
1454 ud = file_util_data_new(UTILITY_TYPE_MOVE); | |
1455 | |
1456 ud->phase = phase; | |
1457 | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1458 ud->dir_fd = NULL; |
753 | 1459 ud->flist = flist; |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1460 ud->content_list = NULL; |
753 | 1461 ud->parent = parent; |
9 | 1462 |
900 | 1463 if (dest_path) ud->dest_path = g_strdup(dest_path); |
753 | 1464 |
1465 ud->messages.title = _("Move"); | |
1466 ud->messages.question = _("Move files?"); | |
1467 ud->messages.desc_flist = _("This will move the following files"); | |
1468 ud->messages.desc_dlist = ""; | |
1469 ud->messages.desc_source_fd = ""; | |
1470 ud->messages.fail = _("Move failed"); | |
138 | 1471 |
753 | 1472 file_util_dialog_run(ud); |
1473 } | |
1474 static void file_util_copy_full(FileData *source_fd, GList *source_list, const gchar *dest_path, GtkWidget *parent, UtilityPhase phase) | |
1475 { | |
1476 UtilityData *ud; | |
1477 GList *flist = filelist_copy(source_list); | |
1478 | |
1479 if (source_fd) | |
1480 flist = g_list_append(flist, file_data_ref(source_fd)); | |
1481 | |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1482 file_util_disable_grouping_sc_list(flist); |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1483 |
753 | 1484 if (!file_data_sc_add_ci_copy_list(flist, dest_path)) |
1 | 1485 { |
757 | 1486 file_util_warn_op_in_progress(_("Copy failed")); |
753 | 1487 filelist_free(flist); |
1 | 1488 return; |
1489 } | |
1490 | |
753 | 1491 ud = file_util_data_new(UTILITY_TYPE_COPY); |
1492 | |
1493 ud->phase = phase; | |
1494 | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1495 ud->dir_fd = NULL; |
753 | 1496 ud->flist = flist; |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1497 ud->content_list = NULL; |
753 | 1498 ud->parent = parent; |
9 | 1499 |
900 | 1500 if (dest_path) ud->dest_path = g_strdup(dest_path); |
753 | 1501 |
1502 ud->messages.title = _("Copy"); | |
1503 ud->messages.question = _("Copy files?"); | |
1504 ud->messages.desc_flist = _("This will copy the following files"); | |
1505 ud->messages.desc_dlist = ""; | |
1506 ud->messages.desc_source_fd = ""; | |
1507 ud->messages.fail = _("Copy failed"); | |
1 | 1508 |
753 | 1509 file_util_dialog_run(ud); |
9 | 1510 } |
1511 | |
753 | 1512 static void file_util_rename_full(FileData *source_fd, GList *source_list, const gchar *dest_path, GtkWidget *parent, UtilityPhase phase) |
1 | 1513 { |
753 | 1514 UtilityData *ud; |
1515 GList *flist = filelist_copy(source_list); | |
1516 | |
1517 if (source_fd) | |
1518 flist = g_list_append(flist, file_data_ref(source_fd)); | |
138 | 1519 |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1520 file_util_disable_grouping_sc_list(flist); |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1521 |
753 | 1522 if (!file_data_sc_add_ci_rename_list(flist, dest_path)) |
1523 { | |
757 | 1524 file_util_warn_op_in_progress(_("Rename failed")); |
753 | 1525 filelist_free(flist); |
1526 return; | |
1527 } | |
9 | 1528 |
753 | 1529 ud = file_util_data_new(UTILITY_TYPE_RENAME); |
138 | 1530 |
753 | 1531 ud->phase = phase; |
1 | 1532 |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1533 ud->dir_fd = NULL; |
753 | 1534 ud->flist = flist; |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1535 ud->content_list = NULL; |
753 | 1536 ud->parent = parent; |
1537 | |
1538 ud->messages.title = _("Rename"); | |
1539 ud->messages.question = _("Rename files?"); | |
1540 ud->messages.desc_flist = _("This will rename the following files"); | |
1541 ud->messages.desc_dlist = ""; | |
1542 ud->messages.desc_source_fd = ""; | |
1543 ud->messages.fail = _("Rename failed"); | |
138 | 1544 |
753 | 1545 file_util_dialog_run(ud); |
1 | 1546 } |
1547 | |
753 | 1548 static void file_util_start_editor_full(gint n, FileData *source_fd, GList *source_list, const gchar *dest_path, GtkWidget *parent, UtilityPhase phase) |
1549 { | |
1550 UtilityData *ud; | |
1551 GList *flist = filelist_copy(source_list); | |
1552 | |
1553 if (source_fd) | |
1554 flist = g_list_append(flist, file_data_ref(source_fd)); | |
1 | 1555 |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1556 file_util_disable_grouping_sc_list(flist); |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
800
diff
changeset
|
1557 |
753 | 1558 if (!file_data_sc_add_ci_unspecified_list(flist, dest_path)) |
1 | 1559 { |
757 | 1560 file_util_warn_op_in_progress(_("Can't run external editor")); |
753 | 1561 filelist_free(flist); |
1562 return; | |
1 | 1563 } |
9 | 1564 |
753 | 1565 if (editor_is_filter(n)) |
1566 ud = file_util_data_new(UTILITY_TYPE_FILTER); | |
1567 else | |
1568 ud = file_util_data_new(UTILITY_TYPE_EDITOR); | |
1569 | |
1570 | |
1571 /* ask for destination if we don't have it */ | |
1572 if (ud->type == UTILITY_TYPE_FILTER && dest_path == NULL) phase = UTILITY_PHASE_START; | |
1573 | |
1574 ud->phase = phase; | |
1575 | |
1576 ud->external_command = n; | |
1577 | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1578 ud->dir_fd = NULL; |
753 | 1579 ud->flist = flist; |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1580 ud->content_list = NULL; |
753 | 1581 ud->parent = parent; |
1582 | |
900 | 1583 if (dest_path) ud->dest_path = g_strdup(dest_path); |
753 | 1584 |
1585 ud->messages.title = _("Editor"); | |
1586 ud->messages.question = _("Run editor?"); | |
1587 ud->messages.desc_flist = _("This will copy the following files"); | |
1588 ud->messages.desc_dlist = ""; | |
1589 ud->messages.desc_source_fd = ""; | |
1590 ud->messages.fail = _("External command failed"); | |
1591 | |
1592 file_util_dialog_run(ud); | |
1 | 1593 } |
1594 | |
901 | 1595 static GList *file_util_delete_dir_remaining_folders(GList *dlist) |
1596 { | |
1597 GList *rlist = NULL; | |
1598 | |
1599 while (dlist) | |
1600 { | |
1601 FileData *fd; | |
1602 | |
1603 fd = dlist->data; | |
1604 dlist = dlist->next; | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1605 |
901 | 1606 if (!fd->name || |
1607 (strcmp(fd->name, THUMB_FOLDER_GLOBAL) != 0 && | |
1608 strcmp(fd->name, THUMB_FOLDER_LOCAL) != 0 && | |
1609 strcmp(fd->name, GQ_CACHE_LOCAL_METADATA) != 0) ) | |
1610 { | |
1611 rlist = g_list_prepend(rlist, fd); | |
1612 } | |
1613 } | |
1614 | |
1615 return g_list_reverse(rlist); | |
1616 } | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1617 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1618 static gboolean file_util_delete_dir_empty_path(UtilityData *ud, FileData *fd, gint level) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1619 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1620 GList *dlist; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1621 GList *flist; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1622 GList *work; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1623 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1624 gboolean ok = TRUE; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1625 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1626 DEBUG_1("deltree into: %s", fd->path); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1627 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1628 level++; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1629 if (level > UTILITY_DELETE_MAX_DEPTH) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1630 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1631 log_printf("folder recursion depth past %d, giving up\n", UTILITY_DELETE_MAX_DEPTH); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1632 // ud->fail_fd = fd |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1633 return 0; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1634 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1635 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1636 if (!filelist_read_lstat(fd, &flist, &dlist)) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1637 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1638 // ud->fail_fd = fd |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1639 return 0; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1640 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1641 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1642 if (ok) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1643 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1644 if ((ok = file_data_sc_add_ci_delete(fd))) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1645 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1646 ud->content_list = g_list_prepend(ud->content_list, fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1647 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1648 // ud->fail_fd = fd |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1649 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1650 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1651 work = dlist; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1652 while (work && ok) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1653 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1654 FileData *lfd; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1655 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1656 lfd = work->data; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1657 work = work->next; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1658 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1659 ok = file_util_delete_dir_empty_path(ud, lfd, level); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1660 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1661 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1662 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1663 work = flist; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1664 while (work && ok) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1665 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1666 FileData *lfd; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1667 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1668 lfd = work->data; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1669 work = work->next; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1670 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1671 DEBUG_1("deltree child: %s", lfd->path); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1672 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1673 if ((ok = file_data_sc_add_ci_delete(lfd))) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1674 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1675 ud->content_list = g_list_prepend(ud->content_list, lfd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1676 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1677 // ud->fail_fd = fd |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1678 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1679 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1680 filelist_free(dlist); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1681 filelist_free(flist); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1682 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1683 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1684 DEBUG_1("deltree done: %s", fd->path); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1685 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1686 return ok; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1687 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1688 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1689 static gboolean file_util_delete_dir_prepare(UtilityData *ud, GList *flist, GList *dlist) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1690 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1691 gboolean ok = TRUE; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1692 GList *work; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1693 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1694 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1695 work = dlist; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1696 while (work && ok) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1697 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1698 FileData *fd; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1699 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1700 fd = work->data; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1701 work = work->next; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1702 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1703 ok = file_util_delete_dir_empty_path(ud, fd, 0); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1704 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1705 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1706 work = flist; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1707 if (ok && file_data_sc_add_ci_delete_list(flist)) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1708 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1709 ud->content_list = g_list_concat(filelist_copy(flist), ud->content_list); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1710 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1711 else |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1712 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1713 ok = FALSE; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1714 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1715 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1716 if (ok) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1717 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1718 ok = file_data_sc_add_ci_delete(ud->dir_fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1719 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1720 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1721 if (!ok) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1722 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1723 work = ud->content_list; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1724 while (work) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1725 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1726 FileData *fd; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1727 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1728 fd = work->data; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1729 work = work->next; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1730 file_data_sc_free_ci(fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1731 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1732 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1733 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1734 return ok; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1735 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1736 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1737 static void file_util_delete_dir_full(FileData *fd, GtkWidget *parent, UtilityPhase phase) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1738 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1739 GList *dlist; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1740 GList *flist; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1741 GList *rlist; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1742 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1743 if (!isdir(fd->path)) return; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1744 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1745 if (islink(fd->path)) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1746 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1747 UtilityData *ud; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1748 ud = file_util_data_new(UTILITY_TYPE_DELETE_LINK); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1749 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1750 ud->phase = phase; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1751 ud->dir_fd = file_data_ref(fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1752 ud->content_list = NULL; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1753 ud->flist = NULL; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1754 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1755 ud->parent = parent; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1756 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1757 ud->messages.title = _("Delete folder"); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1758 ud->messages.question = _("Delete symbolic link?"); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1759 ud->messages.desc_flist = ""; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1760 ud->messages.desc_dlist = ""; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1761 ud->messages.desc_source_fd = _("This will delete the symbolic link.\n" |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1762 "The folder this link points to will not be deleted."); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1763 ud->messages.fail = _("Link deletion failed"); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1764 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1765 file_util_dialog_run(ud); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1766 return; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1767 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1768 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1769 if (!access_file(fd->path, W_OK | X_OK)) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1770 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1771 gchar *text; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1772 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1773 text = g_strdup_printf(_("Unable to remove folder %s\n" |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1774 "Permissions do not allow writing to the folder."), fd->path); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1775 file_util_warning_dialog(_("Delete failed"), text, GTK_STOCK_DIALOG_ERROR, parent); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1776 g_free(text); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1777 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1778 return; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1779 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1780 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1781 if (!filelist_read_lstat(fd, &flist, &dlist)) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1782 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1783 gchar *text; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1784 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1785 text = g_strdup_printf(_("Unable to list contents of folder %s"), fd->path); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1786 file_util_warning_dialog(_("Delete failed"), text, GTK_STOCK_DIALOG_ERROR, parent); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1787 g_free(text); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1788 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1789 return; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1790 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1791 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1792 rlist = file_util_delete_dir_remaining_folders(dlist); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1793 if (rlist) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1794 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1795 GenericDialog *gd; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1796 GtkWidget *box; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1797 gchar *text; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1798 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1799 gd = file_util_gen_dlg(_("Folder contains subfolders"), GQ_WMCLASS, "dlg_warning", |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1800 parent, TRUE, NULL, NULL); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1801 generic_dialog_add_button(gd, GTK_STOCK_CLOSE, NULL, NULL, TRUE); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1802 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1803 text = g_strdup_printf(_("Unable to delete the folder:\n\n%s\n\n" |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1804 "This folder contains subfolders which must be moved before it can be deleted."), |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1805 fd->path); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1806 box = generic_dialog_add_message(gd, GTK_STOCK_DIALOG_WARNING, |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1807 _("Folder contains subfolders"), |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1808 text); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1809 g_free(text); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1810 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1811 box = pref_group_new(box, TRUE, _("Subfolders:"), GTK_ORIENTATION_VERTICAL); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1812 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1813 rlist = filelist_sort_path(rlist); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1814 file_util_dialog_add_list(box, rlist, FALSE); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1815 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1816 gtk_widget_show(gd->dialog); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1817 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1818 else |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1819 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1820 UtilityData *ud; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1821 ud = file_util_data_new(UTILITY_TYPE_DELETE_FOLDER); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1822 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1823 ud->phase = phase; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1824 ud->dir_fd = file_data_ref(fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1825 ud->content_list = NULL; /* will be filled by file_util_delete_dir_prepare */ |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1826 ud->flist = flist = filelist_sort_path(flist); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1827 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1828 ud->parent = parent; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1829 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1830 ud->messages.title = _("Delete folder"); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1831 ud->messages.question = _("Delete folder?"); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1832 ud->messages.desc_flist = _("The folder contains these files:"); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1833 ud->messages.desc_source_fd = _("This will delete the folder.\n" |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1834 "The contents of this folder will also be deleted."); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1835 ud->messages.fail = _("File deletion failed"); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1836 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1837 if (!file_util_delete_dir_prepare(ud, flist, dlist)) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1838 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1839 gchar *text; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1840 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1841 text = g_strdup_printf(_("Unable to list contents of folder %s"), fd->path); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1842 file_util_warning_dialog(_("Delete failed"), text, GTK_STOCK_DIALOG_ERROR, parent); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1843 g_free(text); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1844 file_data_unref(ud->dir_fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1845 file_util_data_free(ud); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1846 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1847 else |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1848 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1849 filelist_free(dlist); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1850 file_util_dialog_run(ud); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1851 return; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1852 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1853 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1854 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1855 g_list_free(rlist); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1856 filelist_free(dlist); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1857 filelist_free(flist); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1858 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1859 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1860 static gboolean file_util_rename_dir_scan(UtilityData *ud, FileData *fd) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1861 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1862 GList *dlist; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1863 GList *flist; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1864 GList *work; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1865 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1866 gboolean ok = TRUE; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1867 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1868 if (!filelist_read_lstat(fd, &flist, &dlist)) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1869 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1870 // ud->fail_fd = fd |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1871 return 0; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1872 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1873 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1874 ud->content_list = g_list_concat(flist, ud->content_list); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1875 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1876 work = dlist; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1877 while (work && ok) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1878 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1879 FileData *lfd; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1880 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1881 lfd = work->data; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1882 work = work->next; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1883 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1884 ud->content_list = g_list_prepend(ud->content_list, file_data_ref(lfd)); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1885 ok = file_util_rename_dir_scan(ud, lfd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1886 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1887 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1888 filelist_free(dlist); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1889 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1890 return ok; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1891 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1892 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1893 static gboolean file_util_rename_dir_prepare(UtilityData *ud, const char *new_path) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1894 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1895 gboolean ok; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1896 GList *work; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1897 gint orig_len = strlen(ud->dir_fd->path); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1898 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1899 ok = file_util_rename_dir_scan(ud, ud->dir_fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1900 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1901 work = ud->content_list; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1902 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1903 while (ok && work) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1904 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1905 gchar *np; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1906 FileData *fd; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1907 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1908 fd = work->data; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1909 work = work->next; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1910 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1911 g_assert(strncmp(fd->path, ud->dir_fd->path, orig_len) == 0); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1912 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1913 np = g_strdup_printf("%s%s", new_path, fd->path + orig_len); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1914 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1915 ok = file_data_sc_add_ci_rename(fd, np); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1916 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1917 DEBUG_1("Dir rename: %s -> %s", fd->path, np); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1918 g_free(np); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1919 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1920 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1921 if (ok) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1922 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1923 ok = file_data_sc_add_ci_rename(ud->dir_fd, new_path); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1924 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1925 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1926 if (!ok) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1927 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1928 work = ud->content_list; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1929 while (work) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1930 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1931 FileData *fd; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1932 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1933 fd = work->data; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1934 work = work->next; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1935 file_data_sc_free_ci(fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1936 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1937 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1938 return ok; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1939 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1940 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1941 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1942 static void file_util_rename_dir_full(FileData *fd, const char *new_path, GtkWidget *parent, UtilityPhase phase) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1943 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1944 UtilityData *ud; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1945 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1946 ud = file_util_data_new(UTILITY_TYPE_RENAME_FOLDER); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1947 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1948 ud->phase = phase; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1949 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1950 ud->dir_fd = file_data_ref(fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1951 ud->flist = NULL; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1952 ud->content_list = NULL; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1953 ud->parent = parent; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1954 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1955 ud->messages.title = _("Rename"); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1956 ud->messages.question = _("Rename folder?"); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1957 ud->messages.desc_flist = _("The folder contains the following files"); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1958 ud->messages.desc_dlist = ""; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1959 ud->messages.desc_source_fd = ""; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1960 ud->messages.fail = _("Rename failed"); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1961 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1962 if (!file_util_rename_dir_prepare(ud, new_path)) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1963 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1964 file_util_warn_op_in_progress(ud->messages.fail); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1965 file_util_data_free(ud); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1966 return; |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1967 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1968 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1969 // ud->flist = filelist_recursive(fd); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1970 |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1971 file_util_dialog_run(ud); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
1972 } |
753 | 1973 |
901 | 1974 static void file_util_create_dir_full(FileData *fd, const char *dest_path, GtkWidget *parent, UtilityPhase phase) |
1 | 1975 { |
901 | 1976 UtilityData *ud; |
1977 | |
1978 ud = file_util_data_new(UTILITY_TYPE_CREATE_FOLDER); | |
1979 | |
1980 ud->phase = phase; | |
1981 | |
1982 ud->dir_fd = NULL; | |
1983 ud->flist = NULL; | |
1984 ud->content_list = NULL; | |
1985 ud->parent = parent; | |
1986 | |
1987 if (dest_path) | |
1988 { | |
1989 ud->dest_path = g_strdup(dest_path); | |
1990 } | |
1991 else | |
1992 { | |
1993 gchar *buf = g_build_filename(fd->path, _("New folder"), NULL); | |
1994 ud->dest_path = unique_filename(buf, NULL, " ", FALSE); | |
1995 g_free(buf); | |
1996 } | |
1997 | |
1998 ud->dir_fd = file_data_new_simple(ud->dest_path); | |
1999 | |
2000 ud->messages.title = _("Create Folder"); | |
2001 ud->messages.question = _("Create folder?"); | |
2002 ud->messages.desc_flist = ""; | |
2003 ud->messages.desc_dlist = ""; | |
2004 ud->messages.desc_source_fd = ""; | |
2005 ud->messages.fail = _("Can't create folder"); | |
2006 | |
2007 file_util_dialog_run(ud); | |
1 | 2008 } |
757 | 2009 |
9 | 2010 |
757 | 2011 /* full-featured entry points |
753 | 2012 */ |
1 | 2013 |
753 | 2014 void file_util_delete(FileData *source_fd, GList *source_list, GtkWidget *parent) |
2015 { | |
2016 file_util_delete_full(source_fd, source_list, parent, UTILITY_PHASE_START); | |
2017 } | |
9 | 2018 |
753 | 2019 void file_util_copy(FileData *source_fd, GList *source_list, const gchar *dest_path, GtkWidget *parent) |
2020 { | |
2021 file_util_copy_full(source_fd, source_list, dest_path, parent, UTILITY_PHASE_START); | |
2022 } | |
757 | 2023 |
753 | 2024 void file_util_move(FileData *source_fd, GList *source_list, const gchar *dest_path, GtkWidget *parent) |
2025 { | |
2026 file_util_move_full(source_fd, source_list, dest_path, parent, UTILITY_PHASE_START); | |
2027 } | |
757 | 2028 |
753 | 2029 void file_util_rename(FileData *source_fd, GList *source_list, GtkWidget *parent) |
2030 { | |
2031 file_util_rename_full(source_fd, source_list, NULL, parent, UTILITY_PHASE_START); | |
1 | 2032 } |
2033 | |
753 | 2034 /* these avoid the location entry dialog unless there is an error, list must be files only and |
2035 * dest_path must be a valid directory path | |
757 | 2036 */ |
753 | 2037 void file_util_move_simple(GList *list, const gchar *dest_path, GtkWidget *parent) |
44
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
2038 { |
753 | 2039 file_util_move_full(NULL, list, dest_path, parent, UTILITY_PHASE_ENTERING); |
2040 } | |
757 | 2041 |
753 | 2042 void file_util_copy_simple(GList *list, const gchar *dest_path, GtkWidget *parent) |
2043 { | |
2044 file_util_copy_full(NULL, list, dest_path, parent, UTILITY_PHASE_ENTERING); | |
2045 } | |
757 | 2046 |
753 | 2047 void file_util_rename_simple(FileData *fd, const gchar *dest_path, GtkWidget *parent) |
2048 { | |
2049 file_util_rename_full(fd, NULL, dest_path, parent, UTILITY_PHASE_ENTERING); | |
2050 } | |
138 | 2051 |
44
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
2052 |
753 | 2053 void file_util_start_editor_from_file(gint n, FileData *fd, GtkWidget *parent) |
2054 { | |
2055 file_util_start_editor_full(n, fd, NULL, NULL, parent, UTILITY_PHASE_ENTERING); | |
2056 } | |
2057 | |
2058 void file_util_start_editor_from_filelist(gint n, GList *list, GtkWidget *parent) | |
2059 { | |
2060 file_util_start_editor_full(n, NULL, list, NULL, parent, UTILITY_PHASE_ENTERING); | |
2061 } | |
44
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
2062 |
753 | 2063 void file_util_start_filter_from_file(gint n, FileData *fd, const gchar *dest_path, GtkWidget *parent) |
2064 { | |
2065 file_util_start_editor_full(n, fd, NULL, dest_path, parent, UTILITY_PHASE_ENTERING); | |
2066 } | |
44
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
2067 |
753 | 2068 void file_util_start_filter_from_filelist(gint n, GList *list, const gchar *dest_path, GtkWidget *parent) |
2069 { | |
2070 file_util_start_editor_full(n, NULL, list, dest_path, parent, UTILITY_PHASE_ENTERING); | |
2071 } | |
44
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
2072 |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
2073 void file_util_delete_dir(FileData *fd, GtkWidget *parent) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
2074 { |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
2075 file_util_delete_dir_full(fd, parent, UTILITY_PHASE_START); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
2076 } |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
855
diff
changeset
|
2077 |
901 | 2078 void file_util_create_dir(FileData *dir_fd, GtkWidget *parent) |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
2079 { |
901 | 2080 file_util_create_dir_full(dir_fd, NULL, parent, UTILITY_PHASE_ENTERING); |
2081 } | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
2082 |
901 | 2083 gint file_util_rename_dir(FileData *source_fd, const gchar *new_path, GtkWidget *parent) |
2084 { | |
2085 file_util_rename_dir_full(source_fd, new_path, parent, UTILITY_PHASE_ENTERING); | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
2086 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
80
diff
changeset
|
2087 |
753 | 2088 |
2089 void file_util_copy_path_to_clipboard(FileData *fd) | |
2090 { | |
2091 GtkClipboard *clipboard; | |
2092 | |
2093 if (!fd || !*fd->path) return; | |
2094 | |
2095 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); | |
2096 gtk_clipboard_set_text(clipboard, g_shell_quote(fd->path), -1); | |
2097 } | |
2098 | |
2099 void file_util_copy_path_list_to_clipboard(GList *list) | |
2100 { | |
2101 GtkClipboard *clipboard; | |
2102 GList *work; | |
2103 GString *new; | |
2104 | |
2105 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); | |
2106 | |
2107 new = g_string_new(""); | |
2108 work = list; | |
2109 while (work) { | |
2110 FileData *fd = work->data; | |
2111 work = work->next; | |
2112 | |
2113 if (!fd || !*fd->path) continue; | |
2114 | |
2115 g_string_append(new, g_shell_quote(fd->path)); | |
2116 if (work) g_string_append_c(new, ' '); | |
2117 } | |
2118 | |
2119 gtk_clipboard_set_text(clipboard, new->str, new->len); | |
2120 g_string_free(new, TRUE); | |
2121 } |