2 * Copyright (C) 2006 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 #include "filefilter.h"
38 #include "thumb-standard.h"
40 #include "ui-bookmark.h"
41 #include "ui-fileops.h"
54 GdkPixbuf *file_util_get_error_icon(FileData *fd, GList *list, GtkWidget *widget)
56 static PixmapErrors pe = [widget]() -> PixmapErrors
58 GtkIconTheme *icon_theme = gtk_icon_theme_get_default();
61 if (!gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &size, &size))
66 GdkPixbuf *pb_error = gq_gtk_icon_theme_load_icon_copy(icon_theme, GQ_ICON_DIALOG_ERROR, size, GTK_ICON_LOOKUP_USE_BUILTIN);
67 GdkPixbuf *pb_warning = gq_gtk_icon_theme_load_icon_copy(icon_theme, GQ_ICON_DIALOG_WARNING, size, GTK_ICON_LOOKUP_USE_BUILTIN);
68 GdkPixbuf *pb_apply = gq_gtk_icon_theme_load_icon_copy(icon_theme, GQ_ICON_APPLY, size, GTK_ICON_LOOKUP_USE_BUILTIN);
69 return {pb_error, pb_warning, pb_apply};
72 gint error = file_data_sc_verify_ci(fd, list);
74 if (error & CHANGE_ERROR_MASK)
93 enum ClipboardDestination {
94 CLIPBOARD_TEXT_PLAIN = 0,
95 CLIPBOARD_TEXT_URI_LIST = 1,
96 CLIPBOARD_X_SPECIAL_GNOME_COPIED_FILES = 2,
97 CLIPBOARD_UTF8_STRING = 3
100 static GtkTargetEntry target_types[] =
102 {const_cast<gchar *>("text/plain"), 0, CLIPBOARD_TEXT_PLAIN},
103 {const_cast<gchar *>("text/uri-list"), 0, CLIPBOARD_TEXT_URI_LIST},
104 {const_cast<gchar *>("x-special/gnome-copied-files"), 0, CLIPBOARD_X_SPECIAL_GNOME_COPIED_FILES},
105 {const_cast<gchar *>("UTF8_STRING"), 0, CLIPBOARD_UTF8_STRING},
107 static gint target_types_n = 4;
111 GList *path_list; /**< g_strdup(fd->path) */
116 *--------------------------------------------------------------------------
117 * Adds 1 or 2 images (if 2, side by side) to a GenericDialog
118 *--------------------------------------------------------------------------
122 DIALOG_DEF_IMAGE_DIM_X = 150,
123 DIALOG_DEF_IMAGE_DIM_Y = 100
126 static void generic_dialog_add_image(GenericDialog *gd, GtkWidget *box,
127 FileData *fd1, const gchar *header1,
128 gboolean second_image,
129 FileData *fd2, const gchar *header2,
130 gboolean show_filename)
133 GtkWidget *preview_box = nullptr;
135 GtkWidget *label = nullptr;
137 if (!box) box = gd->vbox;
141 preview_box = pref_box_new(box, FALSE, GTK_ORIENTATION_VERTICAL, PREF_PAD_SPACE);
146 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
151 gq_gtk_box_pack_start(GTK_BOX(preview_box), vbox, FALSE, TRUE, 0);
153 sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
154 gq_gtk_box_pack_start(GTK_BOX(preview_box), sep, FALSE, FALSE, 0);
155 gtk_widget_show(sep);
159 gq_gtk_box_pack_start(GTK_BOX(box), vbox, FALSE, TRUE, PREF_PAD_GAP);
161 gtk_widget_show(vbox);
167 head = pref_label_new(vbox, header1);
168 pref_label_bold(head, TRUE, FALSE);
169 gtk_label_set_xalign(GTK_LABEL(head), 0.0);
170 gtk_label_set_yalign(GTK_LABEL(head), 0.5);
173 imd = image_new(FALSE);
174 g_object_set(G_OBJECT(imd->pr), "zoom_expand", FALSE, NULL);
175 gtk_widget_set_size_request(imd->widget, DIALOG_DEF_IMAGE_DIM_X, DIALOG_DEF_IMAGE_DIM_Y);
176 gq_gtk_box_pack_start(GTK_BOX(vbox), imd->widget, TRUE, TRUE, 0);
177 image_change_fd(imd, fd1, 0.0);
178 gtk_widget_show(imd->widget);
182 label = pref_label_new(vbox, (fd1 == nullptr) ? "" : fd1->name);
185 /* only the first image is stored (for use in gd_image_set) */
186 g_object_set_data(G_OBJECT(gd->dialog), "img_image", imd);
187 g_object_set_data(G_OBJECT(gd->dialog), "img_label", label);
194 vbox = pref_box_new(preview_box, TRUE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
200 head = pref_label_new(vbox, header2);
201 pref_label_bold(head, TRUE, FALSE);
202 gtk_label_set_xalign(GTK_LABEL(head), 0.0);
203 gtk_label_set_yalign(GTK_LABEL(head), 0.5);
206 imd = image_new(FALSE);
207 g_object_set(G_OBJECT(imd->pr), "zoom_expand", FALSE, NULL);
208 gtk_widget_set_size_request(imd->widget, DIALOG_DEF_IMAGE_DIM_X, DIALOG_DEF_IMAGE_DIM_Y);
209 gq_gtk_box_pack_start(GTK_BOX(vbox), imd->widget, TRUE, TRUE, 0);
210 if (fd2) image_change_fd(imd, fd2, 0.0);
211 gtk_widget_show(imd->widget);
215 label = pref_label_new(vbox, (fd2 == nullptr) ? "" : fd2->name);
217 g_object_set_data(G_OBJECT(gd->dialog), "img_image2", imd);
218 g_object_set_data(G_OBJECT(gd->dialog), "img_label2", label);
223 *--------------------------------------------------------------------------
224 * Wrappers to aid in setting additional dialog properties (unde mouse, etc.)
225 *--------------------------------------------------------------------------
238 * \image html file_util_gen_dlg.png "Typical implementation" width=200
240 GenericDialog *file_util_gen_dlg(const gchar *title,
242 GtkWidget *parent, gboolean auto_close,
243 void (*cancel_cb)(GenericDialog *, gpointer), gpointer data)
247 gd = generic_dialog_new(title, role, parent, auto_close, cancel_cb, data);
248 if (options->place_dialogs_under_mouse)
250 gq_gtk_window_set_position(GTK_WINDOW(gd->dialog), GTK_WIN_POS_MOUSE);
265 * \image html file_util_file_dlg.png "Typical implementation including optional filter, buttons and path widgets" width=300
267 FileDialog *file_util_file_dlg(const gchar *title,
270 void (*cancel_cb)(FileDialog *, gpointer), gpointer data)
274 fdlg = file_dialog_new(title, role, parent, cancel_cb, data);
275 if (options->place_dialogs_under_mouse)
277 gq_gtk_window_set_position(GTK_WINDOW(GENERIC_DIALOG(fdlg)->dialog), GTK_WIN_POS_MOUSE);
280 gtk_window_set_modal(GTK_WINDOW(fdlg->gd.dialog), TRUE);
285 /* this warning dialog is copied from SLIK's ui_utildg.c,
286 * because it does not have a mouse center option,
287 * and we must center it before show, implement it here.
289 static void file_util_warning_dialog_ok_cb(GenericDialog *, gpointer)
294 GenericDialog *file_util_warning_dialog(const gchar *heading, const gchar *message,
295 const gchar *icon_name, GtkWidget *parent)
299 gd = file_util_gen_dlg(heading, "warning", parent, TRUE, nullptr, nullptr);
300 generic_dialog_add_message(gd, icon_name, heading, message, TRUE);
301 generic_dialog_add_button(gd, GQ_ICON_OK, "OK", file_util_warning_dialog_ok_cb, TRUE);
302 if (options->place_dialogs_under_mouse)
304 gq_gtk_window_set_position(GTK_WINDOW(gd->dialog), GTK_WIN_POS_MOUSE);
306 gtk_widget_show(gd->dialog);
311 static gint filename_base_length(const gchar *name)
319 if (filter_name_exists(name))
323 ext = registered_extension_from_path(name);
324 if (ext) n -= strlen(ext);
337 UTILITY_TYPE_RENAME_FOLDER,
341 UTILITY_TYPE_DELETE_LINK,
342 UTILITY_TYPE_DELETE_FOLDER,
343 UTILITY_TYPE_CREATE_FOLDER,
344 UTILITY_TYPE_WRITE_METADATA
348 UTILITY_PHASE_START = 0,
349 UTILITY_PHASE_INTERMEDIATE,
350 UTILITY_PHASE_ENTERING,
351 UTILITY_PHASE_CHECKED,
353 UTILITY_PHASE_CANCEL,
354 UTILITY_PHASE_DISCARD
360 UTILITY_RENAME_FORMATTED
363 struct UtilityDataMessages {
365 const gchar *question;
366 const gchar *desc_flist;
367 const gchar *desc_source_fd;
385 guint update_idle_id; /* event source id */
386 guint perform_idle_id; /* event source id */
388 gboolean with_sidecars; /* operate on grouped or single files; TRUE = use file_data_sc_, FALSE = use file_data_ functions */
390 /* alternative dialog parts */
393 UtilityDataMessages messages;
395 /* helper entries for various modes */
396 GtkWidget *rename_entry;
397 GtkWidget *rename_label;
398 GtkWidget *auto_entry_front;
399 GtkWidget *auto_entry_end;
400 GtkWidget *auto_spin_start;
401 GtkWidget *auto_spin_pad;
402 GtkWidget *format_entry;
403 GtkWidget *format_spin;
410 /* data for the operation itself, internal or external */
411 gboolean external; /* TRUE for external command, FALSE for internal */
413 gchar *external_command;
414 gpointer resume_data;
415 gboolean show_rename_button;
417 FileUtilDoneFunc done_func;
418 void (*details_func)(UtilityData *ud, FileData *fd);
419 gboolean (*finalize_func)(FileData *fd);
420 gboolean (*discard_func)(FileData *fd);
425 UTILITY_COLUMN_FD = 0,
426 UTILITY_COLUMN_PIXBUF,
429 UTILITY_COLUMN_SIDECARS,
430 UTILITY_COLUMN_DEST_PATH,
431 UTILITY_COLUMN_DEST_NAME,
435 struct UtilityDelayData {
442 guint idle_id; /* event source id */
445 static void generic_dialog_image_set(UtilityData *ud, FileData *fd)
449 FileData *fd2 = nullptr;
452 imd = static_cast<ImageWindow *>(g_object_get_data(G_OBJECT(ud->gd->dialog), "img_image"));
453 label = static_cast<GtkWidget *>(g_object_get_data(G_OBJECT(ud->gd->dialog), "img_label"));
457 image_change_fd(imd, fd, 0.0);
458 buf = g_strjoin("\n", text_from_time(fd->date), text_from_size(fd->size), NULL);
459 if (label) gtk_label_set_text(GTK_LABEL(label), buf);
462 if (ud->type == UTILITY_TYPE_RENAME || ud->type == UTILITY_TYPE_COPY || ud->type == UTILITY_TYPE_MOVE)
464 imd = static_cast<ImageWindow *>(g_object_get_data(G_OBJECT(ud->gd->dialog), "img_image2"));
465 label = static_cast<GtkWidget *>(g_object_get_data(G_OBJECT(ud->gd->dialog), "img_label2"));
469 if (isfile(fd->change->dest))
471 fd2 = file_data_new_group(fd->change->dest);
472 image_change_fd(imd, fd2, 0.0);
473 buf = g_strjoin("\n", text_from_time(fd2->date), text_from_size(fd2->size), NULL);
474 if (label && fd->change->dest) gtk_label_set_text(GTK_LABEL(label), buf);
475 file_data_unref(fd2);
480 image_change_fd(imd, nullptr, 0.0);
481 if (label) gtk_label_set_text(GTK_LABEL(label), "");
487 static gboolean file_util_write_metadata_first(UtilityType type, UtilityPhase phase, GList *flist, const gchar *dest_path, const gchar *editor_key, GtkWidget *parent);
490 UTILITY_LIST_MIN_WIDTH = 250,
491 UTILITY_LIST_MIN_HEIGHT = 150
494 /* thumbnail spec has a max depth of 4 (.thumb??/fail/appname/??.png) */
496 UTILITY_DELETE_MAX_DEPTH = 5
499 static UtilityData *file_util_data_new(UtilityType type)
503 ud = g_new0(UtilityData, 1);
506 ud->phase = UTILITY_PHASE_START;
508 if (type == UTILITY_TYPE_CREATE_FOLDER)
510 ud->show_rename_button = FALSE;
514 ud->show_rename_button = TRUE;
520 static void file_util_data_free(UtilityData *ud)
524 if (ud->update_idle_id) g_source_remove(ud->update_idle_id);
525 if (ud->perform_idle_id) g_source_remove(ud->perform_idle_id);
527 file_data_unref(ud->dir_fd);
528 filelist_free(ud->content_list);
529 filelist_free(ud->flist);
531 if (ud->gd) generic_dialog_close(ud->gd);
533 g_free(ud->dest_path);
534 g_free(ud->external_command);
539 static GtkTreeViewColumn *file_util_dialog_add_list_column(GtkWidget *view, const gchar *text, gboolean image, gint n)
541 GtkTreeViewColumn *column;
542 GtkCellRenderer *renderer;
544 column = gtk_tree_view_column_new();
545 gtk_tree_view_column_set_title(column, text);
546 gtk_tree_view_column_set_min_width(column, 4);
549 gtk_tree_view_column_set_min_width(column, 20);
550 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
551 renderer = gtk_cell_renderer_pixbuf_new();
552 gtk_tree_view_column_pack_start(column, renderer, TRUE);
553 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", n);
557 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
558 renderer = gtk_cell_renderer_text_new();
559 gtk_tree_view_column_pack_start(column, renderer, TRUE);
560 gtk_tree_view_column_add_attribute(column, renderer, "text", n);
562 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
567 static void file_util_dialog_list_select(GtkWidget *view, gint n)
571 GtkTreeSelection *selection;
573 store = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
574 if (gtk_tree_model_iter_nth_child(store, &iter, nullptr, n))
576 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
577 gtk_tree_selection_select_iter(selection, &iter);
581 static GtkWidget *file_util_dialog_add_list(GtkWidget *box, GList *list, gboolean full_paths, gboolean with_sidecars)
587 scrolled = gq_gtk_scrolled_window_new(nullptr, nullptr);
588 gq_gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
589 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
590 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
591 gq_gtk_box_pack_start(GTK_BOX(box), scrolled, TRUE, TRUE, 0);
592 gtk_widget_show(scrolled);
594 store = gtk_list_store_new(UTILITY_COLUMN_COUNT, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
595 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
596 g_object_unref(store);
598 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), TRUE);
599 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(view), FALSE);
601 file_util_dialog_add_list_column(view, "", TRUE, UTILITY_COLUMN_PIXBUF);
605 file_util_dialog_add_list_column(view, _("Path"), FALSE, UTILITY_COLUMN_PATH);
609 file_util_dialog_add_list_column(view, _("Name"), FALSE, UTILITY_COLUMN_NAME);
612 gtk_widget_set_size_request(view, UTILITY_LIST_MIN_WIDTH, UTILITY_LIST_MIN_HEIGHT);
613 gq_gtk_container_add(GTK_WIDGET(scrolled), view);
614 gtk_widget_show(view);
618 auto fd = static_cast<FileData *>(list->data);
622 sidecars = with_sidecars ? file_data_sc_list_to_string(fd) : nullptr;
623 GdkPixbuf *icon = file_util_get_error_icon(fd, list, view);
624 gtk_list_store_append(store, &iter);
625 gtk_list_store_set(store, &iter,
626 UTILITY_COLUMN_FD, fd,
627 UTILITY_COLUMN_PIXBUF, icon,
628 UTILITY_COLUMN_PATH, fd->path,
629 UTILITY_COLUMN_NAME, fd->name,
630 UTILITY_COLUMN_SIDECARS, sidecars,
631 UTILITY_COLUMN_DEST_PATH, fd->change ? fd->change->dest : "error",
632 UTILITY_COLUMN_DEST_NAME, fd->change ? filename_from_path(fd->change->dest) : "error",
643 static gboolean file_util_perform_ci_internal(gpointer data);
644 void file_util_dialog_run(UtilityData *ud);
645 static gint file_util_perform_ci_cb(gpointer resume_data, EditorFlags flags, GList *list, gpointer data);
647 /* call file_util_perform_ci_internal or start_editor_from_filelist_full */
650 static void file_util_resume_cb(GenericDialog *, gpointer data)
652 auto ud = static_cast<UtilityData *>(data);
654 editor_resume(ud->resume_data);
656 file_util_perform_ci_internal(ud);
659 static void file_util_abort_cb(GenericDialog *, gpointer data)
661 auto ud = static_cast<UtilityData *>(data);
663 editor_skip(ud->resume_data);
665 file_util_perform_ci_cb(nullptr, EDITOR_ERROR_SKIPPED, ud->flist, ud);
670 static gint file_util_perform_ci_cb(gpointer resume_data, EditorFlags flags, GList *list, gpointer data)
672 auto ud = static_cast<UtilityData *>(data);
673 gint ret = EDITOR_CB_CONTINUE;
675 ud->resume_data = resume_data;
677 if (EDITOR_ERRORS_BUT_SKIPPED(flags))
679 GString *msg = g_string_new(editor_get_error_str(flags));
681 g_string_append(msg, "\n");
682 g_string_append(msg, ud->messages.fail);
683 g_string_append(msg, "\n");
686 auto fd = static_cast<FileData *>(list->data);
688 g_string_append(msg, fd->path);
689 g_string_append(msg, "\n");
694 g_string_append(msg, _("\n Continue multiple file operation?"));
695 d = file_util_gen_dlg(ud->messages.fail, "dlg_confirm",
697 file_util_abort_cb, ud);
699 generic_dialog_add_message(d, GQ_ICON_DIALOG_WARNING, nullptr, msg->str, TRUE);
701 generic_dialog_add_button(d, GQ_ICON_GO_NEXT, _("Co_ntinue"),
702 file_util_resume_cb, TRUE);
703 gtk_widget_show(d->dialog);
704 ret = EDITOR_CB_SUSPEND;
708 file_util_warning_dialog(ud->messages.fail, msg->str, GQ_ICON_DIALOG_ERROR, nullptr);
710 g_string_free(msg, TRUE);
714 while (list) /* be careful, file_util_perform_ci_internal can pass ud->flist as list */
716 auto fd = static_cast<FileData *>(list->data);
719 if (!EDITOR_ERRORS(flags)) /* files were successfully deleted, call the maint functions */
721 if (ud->with_sidecars)
722 file_data_sc_apply_ci(fd);
724 file_data_apply_ci(fd);
727 ud->flist = g_list_remove(ud->flist, fd);
729 if (ud->finalize_func)
731 ud->finalize_func(fd);
734 if (ud->with_sidecars)
735 file_data_sc_free_ci(fd);
737 file_data_free_ci(fd);
741 if (!resume_data) /* end of the list */
743 ud->phase = UTILITY_PHASE_DONE;
744 file_util_dialog_run(ud);
752 * Perform the operation described by FileDataChangeInfo on all files in the list
753 * it is an alternative to start_editor_from_filelist_full, it should use similar interface
757 static gboolean file_util_perform_ci_internal(gpointer data)
759 auto ud = static_cast<UtilityData *>(data);
761 if (!ud->perform_idle_id)
763 /* this function was called directly
764 just setup idle callback and wait until we are called again
767 /* this is removed when ud is destroyed */
768 ud->perform_idle_id = g_idle_add(file_util_perform_ci_internal, ud);
769 return G_SOURCE_CONTINUE;
778 /* take a single entry each time, this allows better control over the operation */
779 GList *single_entry = g_list_append(nullptr, ud->flist->data);
780 gboolean last = !ud->flist->next;
781 EditorFlags status = EDITOR_ERROR_STATUS;
783 if (ud->with_sidecars ? file_data_sc_perform_ci(static_cast<FileData *>(single_entry->data))
784 : file_data_perform_ci(static_cast<FileData *>(single_entry->data)))
785 status = static_cast<EditorFlags>(0); /* OK */
787 ret = file_util_perform_ci_cb(GINT_TO_POINTER(!last), status, single_entry, ud);
788 g_list_free(single_entry);
790 if (ret == EDITOR_CB_SUSPEND || last) return G_SOURCE_REMOVE;
792 if (ret == EDITOR_CB_SKIP)
794 file_util_perform_ci_cb(nullptr, EDITOR_ERROR_SKIPPED, ud->flist, ud);
795 return G_SOURCE_REMOVE;
799 return G_SOURCE_CONTINUE;
802 static void file_util_perform_ci_dir(UtilityData *ud, gboolean internal, gboolean ext_result)
806 case UTILITY_TYPE_DELETE_LINK:
808 g_assert(ud->dir_fd->sidecar_files == nullptr); // directories should not have sidecars
809 if ((internal && file_data_perform_ci(ud->dir_fd)) ||
810 (!internal && ext_result))
812 file_data_apply_ci(ud->dir_fd);
818 text = g_strdup_printf("%s:\n\n%s", ud->messages.fail, ud->dir_fd->path);
819 file_util_warning_dialog(ud->messages.fail, text, GQ_ICON_DIALOG_ERROR, nullptr);
822 file_data_free_ci(ud->dir_fd);
825 case UTILITY_TYPE_DELETE_FOLDER:
827 FileData *fail = nullptr;
829 work = ud->content_list;
834 fd = static_cast<FileData *>(work->data);
839 if ((internal && file_data_sc_perform_ci(fd)) ||
840 (!internal && ext_result))
842 file_data_sc_apply_ci(fd);
846 if (internal) fail = file_data_ref(fd);
849 file_data_sc_free_ci(fd);
854 g_assert(ud->dir_fd->sidecar_files == nullptr); // directories should not have sidecars
855 if ((internal && file_data_sc_perform_ci(ud->dir_fd)) ||
856 (!internal && ext_result))
858 file_data_apply_ci(ud->dir_fd);
862 fail = file_data_ref(ud->dir_fd);
871 text = g_strdup_printf("%s:\n\n%s", ud->messages.fail, ud->dir_fd->path);
872 gd = file_util_warning_dialog(ud->messages.fail, text, GQ_ICON_DIALOG_ERROR, nullptr);
875 if (fail != ud->dir_fd)
877 pref_spacer(gd->vbox, PREF_PAD_GROUP);
878 text = g_strdup_printf(_("Removal of folder contents failed at this file:\n\n%s"),
880 pref_label_new(gd->vbox, text);
884 file_data_unref(fail);
888 case UTILITY_TYPE_RENAME_FOLDER:
890 FileData *fail = nullptr;
892 g_assert(ud->dir_fd->sidecar_files == nullptr); // directories should not have sidecars
894 if ((internal && file_data_sc_perform_ci(ud->dir_fd)) ||
895 (!internal && ext_result))
897 file_data_sc_apply_ci(ud->dir_fd);
901 fail = file_data_ref(ud->dir_fd);
905 work = ud->content_list;
910 fd = static_cast<FileData *>(work->data);
915 file_data_sc_apply_ci(fd);
917 file_data_sc_free_ci(fd);
924 text = g_strdup_printf("%s:\n\n%s", ud->messages.fail, ud->dir_fd->path);
925 file_util_warning_dialog(ud->messages.fail, text, GQ_ICON_DIALOG_ERROR, nullptr);
928 file_data_unref(fail);
932 case UTILITY_TYPE_CREATE_FOLDER:
934 if ((internal && mkdir_utf8(ud->dir_fd->path, 0755)) ||
935 (!internal && ext_result))
937 file_data_check_changed_files(ud->dir_fd); /* this will update the FileData and send notification */
943 text = g_strdup_printf("%s:\n\n%s", ud->messages.fail, ud->dir_fd->path);
944 file_util_warning_dialog(ud->messages.fail, text, GQ_ICON_DIALOG_ERROR, nullptr);
951 g_warning("unhandled operation");
953 ud->phase = UTILITY_PHASE_DONE;
954 file_util_dialog_run(ud);
957 static gint file_util_perform_ci_dir_cb(gpointer, EditorFlags flags, GList *, gpointer data)
959 auto ud = static_cast<UtilityData *>(data);
960 file_util_perform_ci_dir(ud, FALSE, !EDITOR_ERRORS_BUT_SKIPPED(flags));
961 return EDITOR_CB_CONTINUE; /* does not matter, there was just single directory */
964 void file_util_perform_ci(UtilityData *ud)
968 case UTILITY_TYPE_COPY:
969 ud->external_command = g_strdup(CMD_COPY);
971 case UTILITY_TYPE_MOVE:
972 ud->external_command = g_strdup(CMD_MOVE);
974 case UTILITY_TYPE_RENAME:
975 case UTILITY_TYPE_RENAME_FOLDER:
976 ud->external_command = g_strdup(CMD_RENAME);
978 case UTILITY_TYPE_DELETE:
979 case UTILITY_TYPE_DELETE_LINK:
980 case UTILITY_TYPE_DELETE_FOLDER:
981 ud->external_command = g_strdup(CMD_DELETE);
983 case UTILITY_TYPE_CREATE_FOLDER:
984 ud->external_command = g_strdup(CMD_FOLDER);
986 case UTILITY_TYPE_FILTER:
987 case UTILITY_TYPE_EDITOR:
988 g_assert(ud->external_command != nullptr); /* it should be already set */
990 case UTILITY_TYPE_WRITE_METADATA:
991 ud->external_command = nullptr;
994 if (is_valid_editor_command(ud->external_command))
1002 flags = start_editor_from_file_full(ud->external_command, ud->dir_fd, file_util_perform_ci_dir_cb, ud);
1006 if (editor_blocks_file(ud->external_command))
1008 DEBUG_1("Starting %s and waiting for results", ud->external_command);
1009 flags = start_editor_from_filelist_full(ud->external_command, ud->flist, nullptr, file_util_perform_ci_cb, ud);
1013 /* start the editor without callback and finish the operation internally */
1014 DEBUG_1("Starting %s and finishing the operation", ud->external_command);
1015 flags = start_editor_from_filelist(ud->external_command, ud->flist);
1016 file_util_perform_ci_internal(ud);
1020 if (EDITOR_ERRORS(flags))
1022 gchar *text = g_strdup_printf(_("%s\nUnable to start external command.\n"), editor_get_error_str(flags));
1023 file_util_warning_dialog(ud->messages.fail, text, GQ_ICON_DIALOG_ERROR, nullptr);
1027 ud->phase = UTILITY_PHASE_CANCEL;
1028 file_util_dialog_run(ud);
1033 ud->external = FALSE;
1036 file_util_perform_ci_dir(ud, TRUE, FALSE);
1040 file_util_perform_ci_internal(ud);
1045 static void file_util_check_resume_cb(GenericDialog *, gpointer data)
1047 auto ud = static_cast<UtilityData *>(data);
1048 ud->phase = UTILITY_PHASE_CHECKED;
1049 file_util_dialog_run(ud);
1052 static void file_util_check_abort_cb(GenericDialog *, gpointer data)
1054 auto ud = static_cast<UtilityData *>(data);
1055 ud->phase = UTILITY_PHASE_START;
1056 file_util_dialog_run(ud);
1059 void file_util_check_ci(UtilityData *ud)
1061 gint error = CHANGE_OK;
1062 gchar *desc = nullptr;
1064 if (ud->type != UTILITY_TYPE_CREATE_FOLDER &&
1065 ud->type != UTILITY_TYPE_RENAME_FOLDER)
1067 if (ud->dest_path && !isdir(ud->dest_path))
1069 error = CHANGE_GENERIC_ERROR;
1070 desc = g_strdup_printf(_("%s is not a directory"), ud->dest_path);
1072 else if (ud->dir_fd)
1074 g_assert(ud->dir_fd->sidecar_files == nullptr); // directories should not have sidecars
1075 error = file_data_verify_ci(ud->dir_fd, ud->flist);
1076 if (error) desc = file_data_get_error_string(error);
1080 error = file_data_verify_ci_list(ud->flist, &desc, ud->with_sidecars);
1085 if (ud->type == UTILITY_TYPE_CREATE_FOLDER || ud->type == UTILITY_TYPE_RENAME_FOLDER)
1087 if (isdir(ud->dest_path) || isfile(ud->dest_path))
1089 error = CHANGE_DEST_EXISTS;
1090 desc = g_strdup_printf(_("%s already exists"), ud->dest_path);
1097 ud->phase = UTILITY_PHASE_CHECKED;
1098 file_util_dialog_run(ud);
1102 if (!(error & CHANGE_ERROR_MASK))
1104 /* just a warning */
1107 d = file_util_gen_dlg(ud->messages.title, "dlg_confirm",
1109 file_util_check_abort_cb, ud);
1111 generic_dialog_add_message(d, GQ_ICON_DIALOG_WARNING, _("Really continue?"), desc, TRUE);
1113 generic_dialog_add_button(d, GQ_ICON_GO_NEXT, _("Co_ntinue"),
1114 file_util_check_resume_cb, TRUE);
1115 gtk_widget_show(d->dialog);
1122 d = file_util_gen_dlg(ud->messages.title, "dlg_confirm",
1124 file_util_check_abort_cb, ud);
1125 generic_dialog_add_message(d, GQ_ICON_DIALOG_WARNING, _("This operation can't continue:"), desc, TRUE);
1127 gtk_widget_show(d->dialog);
1136 static void file_util_cancel_cb(GenericDialog *gd, gpointer data)
1138 auto ud = static_cast<UtilityData *>(data);
1140 generic_dialog_close(gd);
1144 ud->phase = UTILITY_PHASE_CANCEL;
1145 file_util_dialog_run(ud);
1148 static void file_util_discard_cb(GenericDialog *gd, gpointer data)
1150 auto ud = static_cast<UtilityData *>(data);
1152 generic_dialog_close(gd);
1156 ud->phase = UTILITY_PHASE_DISCARD;
1157 file_util_dialog_run(ud);
1160 static void file_util_ok_cb(GenericDialog *gd, gpointer data)
1162 auto ud = static_cast<UtilityData *>(data);
1164 generic_dialog_close(gd);
1168 file_util_dialog_run(ud);
1171 static void file_util_fdlg_cancel_cb(FileDialog *fdlg, gpointer data)
1173 auto ud = static_cast<UtilityData *>(data);
1175 file_dialog_close(fdlg);
1179 ud->phase = UTILITY_PHASE_CANCEL;
1180 file_util_dialog_run(ud);
1183 static void file_util_dest_folder_update_path(UtilityData *ud)
1185 g_free(ud->dest_path);
1186 ud->dest_path = g_strdup(gq_gtk_entry_get_text(GTK_ENTRY(ud->fdlg->entry)));
1190 case UTILITY_TYPE_COPY:
1191 file_data_sc_update_ci_copy_list(ud->flist, ud->dest_path);
1193 case UTILITY_TYPE_MOVE:
1194 file_data_sc_update_ci_move_list(ud->flist, ud->dest_path);
1196 case UTILITY_TYPE_FILTER:
1197 case UTILITY_TYPE_EDITOR:
1198 file_data_sc_update_ci_unspecified_list(ud->flist, ud->dest_path);
1200 case UTILITY_TYPE_CREATE_FOLDER:
1201 file_data_unref(ud->dir_fd);
1202 ud->dir_fd = file_data_new_dir(ud->dest_path);
1204 case UTILITY_TYPE_DELETE:
1205 case UTILITY_TYPE_DELETE_LINK:
1206 case UTILITY_TYPE_DELETE_FOLDER:
1207 case UTILITY_TYPE_RENAME:
1208 case UTILITY_TYPE_RENAME_FOLDER:
1209 case UTILITY_TYPE_WRITE_METADATA:
1210 g_warning("unhandled operation");
1214 static void file_util_fdlg_rename_cb(FileDialog *fdlg, gpointer data)
1216 auto ud = static_cast<UtilityData *>(data);
1217 gchar *desc = nullptr;
1218 GenericDialog *d = nullptr;
1220 file_util_dest_folder_update_path(ud);
1221 if (isdir(ud->dest_path))
1223 file_dialog_sync_history(fdlg, TRUE);
1224 file_dialog_close(fdlg);
1226 file_util_dialog_run(ud);
1230 /* During copy/move operations it is necessary to ensure that the
1231 * target directory exists before continuing with the next step.
1232 * If not revert to the select directory dialog
1234 desc = g_strdup_printf(_("%s is not a directory"), ud->dest_path);
1236 d = file_util_gen_dlg(ud->messages.title, "dlg_confirm",
1238 file_util_check_abort_cb, ud);
1239 generic_dialog_add_message(d, GQ_ICON_DIALOG_WARNING, _("This operation can't continue:"), desc, TRUE);
1241 gtk_widget_show(d->dialog);
1242 ud->phase = UTILITY_PHASE_START;
1244 file_dialog_close(fdlg);
1250 static void file_util_fdlg_ok_cb(FileDialog *fdlg, gpointer data)
1252 auto ud = static_cast<UtilityData *>(data);
1254 file_util_dest_folder_update_path(ud);
1255 if (isdir(ud->dest_path)) file_dialog_sync_history(fdlg, TRUE);
1256 file_dialog_close(fdlg);
1259 ud->phase = UTILITY_PHASE_ENTERING;
1261 file_util_dialog_run(ud);
1264 static void file_util_dest_folder_entry_cb(GtkWidget *, gpointer data)
1266 auto ud = static_cast<UtilityData *>(data);
1267 file_util_dest_folder_update_path(ud);
1270 /* format: * = filename without extension, ## = number position, extension is kept */
1271 static gchar *file_util_rename_multiple_auto_format_name(const gchar *format, const gchar *name, gint n)
1282 if (!format || !name) return nullptr;
1284 tmp = g_strdup(format);
1285 pad_start = strchr(tmp, '#');
1288 pad_end = pad_start;
1290 while (*pad_end == '#')
1297 parsed = g_strdup_printf("%s%0*d%s", tmp, padding, n, pad_end);
1305 ext = registered_extension_from_path(name);
1307 middle = strchr(parsed, '*');
1315 base = remove_extension_from_path(name);
1316 new_name = g_strconcat(parsed, base, middle, ext, NULL);
1321 new_name = g_strconcat(parsed, ext, NULL);
1330 static void file_util_rename_preview_update(UtilityData *ud)
1332 GtkTreeModel *store;
1333 GtkTreeSelection *selection;
1335 GtkTreeIter iter_selected;
1336 GtkTreePath *path_iter;
1337 GtkTreePath *path_selected;
1340 const gchar *format;
1349 mode = gtk_notebook_get_current_page(GTK_NOTEBOOK(ud->notebook));
1351 if (mode == UTILITY_RENAME)
1353 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ud->listview));
1354 if (gtk_tree_selection_get_selected(selection, &store, &iter))
1357 const gchar *dest = gq_gtk_entry_get_text(GTK_ENTRY(ud->rename_entry));
1359 gtk_tree_model_get(store, &iter, UTILITY_COLUMN_FD, &fd, -1);
1360 g_assert(ud->with_sidecars); /* sidecars must be renamed too, it would break the pairing otherwise */
1362 dirname = g_path_get_dirname(fd->change->dest);
1363 destname = g_build_filename(dirname, dest, NULL);
1366 case UTILITY_TYPE_RENAME:
1367 file_data_sc_update_ci_rename(fd, dest);
1369 case UTILITY_TYPE_COPY:
1370 file_data_sc_update_ci_copy(fd, destname);
1372 case UTILITY_TYPE_MOVE:
1373 file_data_sc_update_ci_move(fd, destname);
1377 generic_dialog_image_set(ud, fd);
1379 gtk_list_store_set(GTK_LIST_STORE(store), &iter,
1380 UTILITY_COLUMN_DEST_PATH, fd->change->dest,
1381 UTILITY_COLUMN_DEST_NAME, filename_from_path(fd->change->dest),
1387 front = gq_gtk_entry_get_text(GTK_ENTRY(ud->auto_entry_front));
1388 end = gq_gtk_entry_get_text(GTK_ENTRY(ud->auto_entry_end));
1389 padding = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ud->auto_spin_pad));
1391 format = gq_gtk_entry_get_text(GTK_ENTRY(ud->format_entry));
1393 g_free(options->cp_mv_rn.auto_end);
1394 options->cp_mv_rn.auto_end = g_strdup(end);
1395 options->cp_mv_rn.auto_padding = padding;
1397 if (mode == UTILITY_RENAME_FORMATTED)
1399 start_n = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ud->format_spin));
1400 options->cp_mv_rn.formatted_start = start_n;
1404 start_n = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ud->auto_spin_start));
1405 options->cp_mv_rn.auto_start = start_n;
1408 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ud->listview));
1410 valid = gtk_tree_model_get_iter_first(store, &iter);
1415 gtk_tree_model_get(store, &iter, UTILITY_COLUMN_FD, &fd, -1);
1417 if (mode == UTILITY_RENAME_FORMATTED)
1419 dest = file_util_rename_multiple_auto_format_name(format, fd->name, n);
1423 dest = g_strdup_printf("%s%0*d%s", front, padding, n, end);
1426 g_assert(ud->with_sidecars); /* sidecars must be renamed too, it would break the pairing otherwise */
1428 dirname = g_path_get_dirname(fd->change->dest);
1429 destname = g_build_filename(dirname, dest, NULL);
1433 case UTILITY_TYPE_RENAME:
1434 file_data_sc_update_ci_rename(fd, dest);
1436 case UTILITY_TYPE_COPY:
1437 file_data_sc_update_ci_copy(fd, destname);
1439 case UTILITY_TYPE_MOVE:
1440 file_data_sc_update_ci_move(fd, destname);
1449 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ud->listview));
1450 gtk_tree_selection_get_selected(selection, &store, &iter_selected);
1451 path_iter=gtk_tree_model_get_path(store,&iter);
1452 path_selected=gtk_tree_model_get_path(store,&iter_selected);
1453 if (!gtk_tree_path_compare(path_iter,path_selected))
1455 generic_dialog_image_set(ud, fd);
1457 gtk_tree_path_free(path_iter);
1458 gtk_tree_path_free(path_selected);
1460 gtk_list_store_set(GTK_LIST_STORE(store), &iter,
1461 UTILITY_COLUMN_DEST_PATH, fd->change->dest,
1462 UTILITY_COLUMN_DEST_NAME, filename_from_path(fd->change->dest),
1465 valid = gtk_tree_model_iter_next(store, &iter);
1469 /* Check the other entries in the list - if there are
1470 * multiple destination filenames with the same name the
1471 * error icons must be updated
1473 valid = gtk_tree_model_get_iter_first(store, &iter);
1477 gtk_tree_model_get(store, &iter, UTILITY_COLUMN_FD, &fd, -1);
1479 gtk_list_store_set(GTK_LIST_STORE(store), &iter,
1480 UTILITY_COLUMN_PIXBUF, file_util_get_error_icon(fd, ud->flist, ud->listview),
1482 valid = gtk_tree_model_iter_next(store, &iter);
1487 static void file_util_rename_preview_entry_cb(GtkWidget *, gpointer data)
1489 auto ud = static_cast<UtilityData *>(data);
1490 file_util_rename_preview_update(ud);
1493 static void file_util_rename_preview_adj_cb(GtkWidget *, gpointer data)
1495 auto ud = static_cast<UtilityData *>(data);
1496 file_util_rename_preview_update(ud);
1499 static gboolean file_util_rename_idle_cb(gpointer data)
1501 auto ud = static_cast<UtilityData *>(data);
1503 file_util_rename_preview_update(ud);
1505 ud->update_idle_id = 0;
1506 return G_SOURCE_REMOVE;
1509 static void file_util_rename_preview_order_cb(GtkTreeModel *, GtkTreePath *, GtkTreeIter *, gpointer data)
1511 auto ud = static_cast<UtilityData *>(data);
1513 if (ud->update_idle_id) return;
1515 ud->update_idle_id = g_idle_add(file_util_rename_idle_cb, ud);
1519 static gboolean file_util_preview_cb(GtkTreeSelection *, GtkTreeModel *store,
1520 GtkTreePath *tpath, gboolean path_currently_selected,
1523 auto ud = static_cast<UtilityData *>(data);
1525 FileData *fd = nullptr;
1527 if (path_currently_selected ||
1528 !gtk_tree_model_get_iter(store, &iter, tpath)) return TRUE;
1530 gtk_tree_model_get(store, &iter, UTILITY_COLUMN_FD, &fd, -1);
1531 generic_dialog_image_set(ud, fd);
1535 if (ud->type == UTILITY_TYPE_RENAME || ud->type == UTILITY_TYPE_COPY || ud->type == UTILITY_TYPE_MOVE)
1537 const gchar *name = filename_from_path(fd->change->dest);
1539 gtk_widget_grab_focus(ud->rename_entry);
1540 gtk_label_set_text(GTK_LABEL(ud->rename_label), fd->name);
1541 g_signal_handlers_block_by_func(ud->rename_entry, (gpointer)(file_util_rename_preview_entry_cb), ud);
1542 gq_gtk_entry_set_text(GTK_ENTRY(ud->rename_entry), name);
1543 gtk_editable_select_region(GTK_EDITABLE(ud->rename_entry), 0, filename_base_length(name));
1544 g_signal_handlers_unblock_by_func(ud->rename_entry, (gpointer)file_util_rename_preview_entry_cb, ud);
1552 static void box_append_safe_delete_status(GenericDialog *gd)
1557 buf = file_util_safe_delete_status();
1558 label = pref_label_new(gd->vbox, buf);
1561 gtk_label_set_xalign(GTK_LABEL(label), 1.0);
1562 gtk_label_set_yalign(GTK_LABEL(label), 0.5);
1563 gtk_widget_set_sensitive(label, FALSE);
1566 static void file_util_details_cb(GenericDialog *, gpointer data)
1568 auto ud = static_cast<UtilityData *>(data);
1569 if (ud->details_func && ud->sel_fd)
1571 ud->details_func(ud, ud->sel_fd);
1575 static void file_util_dialog_init_simple_list(UtilityData *ud)
1578 GtkTreeSelection *selection;
1581 const gchar *icon_name;
1584 /** @FIXME use ud->stock_id */
1585 if (ud->type == UTILITY_TYPE_DELETE ||
1586 ud->type == UTILITY_TYPE_DELETE_LINK ||
1587 ud->type == UTILITY_TYPE_DELETE_FOLDER)
1589 icon_name = GQ_ICON_DELETE;
1594 icon_name = GQ_ICON_OK;
1598 ud->gd = file_util_gen_dlg(ud->messages.title, "dlg_confirm",
1599 ud->parent, FALSE, file_util_cancel_cb, ud);
1600 if (ud->discard_func) generic_dialog_add_button(ud->gd, GQ_ICON_REVERT, _("Discard changes"), file_util_discard_cb, FALSE);
1601 if (ud->details_func) generic_dialog_add_button(ud->gd, GQ_ICON_DIALOG_INFO, _("File details"), file_util_details_cb, FALSE);
1603 generic_dialog_add_button(ud->gd, icon_name, msg, file_util_ok_cb, TRUE);
1607 dir_msg = g_strdup_printf("%s\n\n%s\n", ud->messages.desc_source_fd, ud->dir_fd->path);
1611 dir_msg = g_strdup("");
1614 box = generic_dialog_add_message(ud->gd, GQ_ICON_DIALOG_QUESTION,
1615 ud->messages.question,
1620 box = pref_group_new(box, TRUE, ud->messages.desc_flist, GTK_ORIENTATION_HORIZONTAL);
1622 ud->listview = file_util_dialog_add_list(box, ud->flist, FALSE, ud->with_sidecars);
1623 if (ud->with_sidecars) file_util_dialog_add_list_column(ud->listview, _("Sidecars"), FALSE, UTILITY_COLUMN_SIDECARS);
1625 if (ud->type == UTILITY_TYPE_WRITE_METADATA) file_util_dialog_add_list_column(ud->listview, _("Write to file"), FALSE, UTILITY_COLUMN_DEST_NAME);
1627 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ud->listview));
1628 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
1629 gtk_tree_selection_set_select_function(selection, file_util_preview_cb, ud, nullptr);
1631 generic_dialog_add_image(ud->gd, box, nullptr, nullptr, FALSE, nullptr, nullptr, FALSE);
1633 if (ud->type == UTILITY_TYPE_DELETE ||
1634 ud->type == UTILITY_TYPE_DELETE_LINK ||
1635 ud->type == UTILITY_TYPE_DELETE_FOLDER)
1636 box_append_safe_delete_status(ud->gd);
1638 gtk_widget_show(ud->gd->dialog);
1640 file_util_dialog_list_select(ud->listview, 0);
1643 static void file_util_dialog_init_dest_folder(UtilityData *ud)
1647 const gchar *icon_name;
1649 if (ud->type == UTILITY_TYPE_COPY)
1651 icon_name = GQ_ICON_COPY;
1655 icon_name = GQ_ICON_OK;
1658 fdlg = file_util_file_dlg(ud->messages.title, "dlg_dest_folder", ud->parent,
1659 file_util_fdlg_cancel_cb, ud);
1663 generic_dialog_add_message(GENERIC_DIALOG(fdlg), nullptr, ud->messages.question, nullptr, FALSE);
1665 label = pref_label_new(GENERIC_DIALOG(fdlg)->vbox, _("Choose the destination folder."));
1666 gtk_label_set_xalign(GTK_LABEL(label), 0.0);
1667 gtk_label_set_yalign(GTK_LABEL(label), 0.5);
1669 pref_spacer(GENERIC_DIALOG(fdlg)->vbox, 0);
1671 if (ud->show_rename_button == TRUE)
1673 if (options->with_rename)
1675 file_dialog_add_button(fdlg, icon_name, ud->messages.title, file_util_fdlg_ok_cb, TRUE);
1676 file_dialog_add_button(fdlg, GQ_ICON_EDIT, _("With Rename"), file_util_fdlg_rename_cb, TRUE);
1680 file_dialog_add_button(fdlg, GQ_ICON_EDIT, _("With Rename"), file_util_fdlg_rename_cb, TRUE);
1681 file_dialog_add_button(fdlg, icon_name, ud->messages.title, file_util_fdlg_ok_cb, TRUE);
1686 file_dialog_add_button(fdlg, icon_name, ud->messages.title, file_util_fdlg_ok_cb, TRUE);
1689 file_dialog_add_path_widgets(fdlg, nullptr, ud->dest_path, "move_copy", nullptr, nullptr);
1691 g_signal_connect(G_OBJECT(fdlg->entry), "changed",
1692 G_CALLBACK(file_util_dest_folder_entry_cb), ud);
1694 gtk_widget_show(GENERIC_DIALOG(fdlg)->dialog);
1698 static GtkWidget *furm_simple_vlabel(GtkWidget *box, const gchar *text, gboolean expand)
1703 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
1704 gq_gtk_box_pack_start(GTK_BOX(box), vbox, expand, expand, 0);
1705 gtk_widget_show(vbox);
1707 label = gtk_label_new(text);
1708 gq_gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
1709 gtk_widget_show(label);
1715 static void file_util_dialog_init_source_dest(UtilityData *ud, gboolean second_image)
1717 GtkTreeModel *store;
1718 GtkTreeSelection *selection;
1725 gchar *destination_message;
1727 ud->gd = file_util_gen_dlg(ud->messages.title, "dlg_confirm",
1728 ud->parent, FALSE, file_util_cancel_cb, ud);
1730 box = generic_dialog_add_message(ud->gd, nullptr, ud->messages.question, nullptr, TRUE);
1732 if (ud->discard_func) generic_dialog_add_button(ud->gd, GQ_ICON_REVERT, _("Discard changes"), file_util_discard_cb, FALSE);
1733 if (ud->details_func) generic_dialog_add_button(ud->gd, GQ_ICON_DIALOG_INFO, _("File details"), file_util_details_cb, FALSE);
1735 generic_dialog_add_button(ud->gd, GQ_ICON_OK, ud->messages.title, file_util_ok_cb, TRUE);
1737 if (ud->type == UTILITY_TYPE_COPY || ud->type == UTILITY_TYPE_MOVE)
1739 destination_message = g_strconcat(ud->messages.desc_flist," to: ", ud->dest_path, NULL);
1743 destination_message = g_strdup(ud->messages.desc_flist);
1746 box = pref_group_new(box, TRUE, destination_message, GTK_ORIENTATION_HORIZONTAL);
1747 g_free(destination_message);
1749 ud->listview = file_util_dialog_add_list(box, ud->flist, FALSE, ud->with_sidecars);
1750 file_util_dialog_add_list_column(ud->listview, _("Sidecars"), FALSE, UTILITY_COLUMN_SIDECARS);
1752 file_util_dialog_add_list_column(ud->listview, _("New name"), FALSE, UTILITY_COLUMN_DEST_NAME);
1754 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ud->listview));
1755 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_SINGLE);
1756 gtk_tree_selection_set_select_function(selection, file_util_preview_cb, ud, nullptr);
1758 gtk_tree_view_set_reorderable(GTK_TREE_VIEW(ud->listview), TRUE);
1760 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ud->listview));
1761 g_signal_connect(G_OBJECT(store), "row_changed",
1762 G_CALLBACK(file_util_rename_preview_order_cb), ud);
1763 gtk_widget_set_size_request(ud->listview, 300, 150);
1767 generic_dialog_add_image(ud->gd, box, nullptr, "Source", TRUE, nullptr, "Destination", TRUE);
1771 generic_dialog_add_image(ud->gd, box, nullptr, nullptr, FALSE, nullptr, nullptr, FALSE);
1774 gtk_widget_show(ud->gd->dialog);
1777 ud->notebook = gtk_notebook_new();
1779 gq_gtk_box_pack_start(GTK_BOX(ud->gd->vbox), ud->notebook, FALSE, FALSE, 0);
1780 gtk_widget_show(ud->notebook);
1783 page = gtk_box_new(GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
1784 gtk_notebook_append_page(GTK_NOTEBOOK(ud->notebook), page, gtk_label_new(_("Manual rename")));
1785 gtk_widget_show(page);
1787 table = pref_table_new(page, 2, 2, FALSE, FALSE);
1789 pref_table_label(table, 0, 0, _("Original name:"), GTK_ALIGN_END);
1790 ud->rename_label = pref_table_label(table, 1, 0, "", GTK_ALIGN_START);
1792 pref_table_label(table, 0, 1, _("New name:"), GTK_ALIGN_END);
1794 ud->rename_entry = gtk_entry_new();
1795 gq_gtk_grid_attach(GTK_GRID(table), ud->rename_entry, 1, 2, 1, 2, static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), static_cast<GtkAttachOptions>(0), 0, 0);
1796 generic_dialog_attach_default(GENERIC_DIALOG(ud->gd), ud->rename_entry);
1797 gtk_widget_grab_focus(ud->rename_entry);
1799 g_signal_connect(G_OBJECT(ud->rename_entry), "changed",
1800 G_CALLBACK(file_util_rename_preview_entry_cb), ud);
1802 gtk_widget_show(ud->rename_entry);
1804 page = gtk_box_new(GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
1805 gtk_notebook_append_page(GTK_NOTEBOOK(ud->notebook), page, gtk_label_new(_("Auto rename")));
1806 gtk_widget_show(page);
1809 hbox = pref_box_new(page, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP);
1811 box2 = furm_simple_vlabel(hbox, _("Begin text"), TRUE);
1813 combo = history_combo_new(&ud->auto_entry_front, "", "numerical_rename_prefix", -1);
1814 g_signal_connect(G_OBJECT(ud->auto_entry_front), "changed",
1815 G_CALLBACK(file_util_rename_preview_entry_cb), ud);
1816 gq_gtk_box_pack_start(GTK_BOX(box2), combo, TRUE, TRUE, 0);
1817 gtk_widget_show(combo);
1819 box2 = furm_simple_vlabel(hbox, _("Start #"), FALSE);
1821 ud->auto_spin_start = pref_spin_new(box2, nullptr, nullptr,
1822 0.0, 1000000.0, 1.0, 0, options->cp_mv_rn.auto_start,
1823 G_CALLBACK(file_util_rename_preview_adj_cb), ud);
1825 box2 = furm_simple_vlabel(hbox, _("End text"), TRUE);
1827 combo = history_combo_new(&ud->auto_entry_end, options->cp_mv_rn.auto_end, "numerical_rename_suffix", -1);
1828 g_signal_connect(G_OBJECT(ud->auto_entry_end), "changed",
1829 G_CALLBACK(file_util_rename_preview_entry_cb), ud);
1830 gq_gtk_box_pack_start(GTK_BOX(box2), combo, TRUE, TRUE, 0);
1831 gtk_widget_show(combo);
1833 ud->auto_spin_pad = pref_spin_new(page, _("Padding:"), nullptr,
1834 1.0, 8.0, 1.0, 0, options->cp_mv_rn.auto_padding,
1835 G_CALLBACK(file_util_rename_preview_adj_cb), ud);
1837 page = gtk_box_new(GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
1838 gtk_notebook_append_page(GTK_NOTEBOOK(ud->notebook), page, gtk_label_new(_("Formatted rename")));
1839 gtk_widget_show(page);
1841 hbox = pref_box_new(page, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP);
1843 box2 = furm_simple_vlabel(hbox, _("Format (* = original name, ## = numbers)"), TRUE);
1845 combo = history_combo_new(&ud->format_entry, "", "auto_rename_format", -1);
1846 g_signal_connect(G_OBJECT(ud->format_entry), "changed",
1847 G_CALLBACK(file_util_rename_preview_entry_cb), ud);
1848 gq_gtk_box_pack_start(GTK_BOX(box2), combo, TRUE, TRUE, 0);
1849 gtk_widget_show(combo);
1851 box2 = furm_simple_vlabel(hbox, _("Start #"), FALSE);
1853 ud->format_spin = pref_spin_new(box2, nullptr, nullptr,
1854 0.0, 1000000.0, 1.0, 0, options->cp_mv_rn.formatted_start,
1855 G_CALLBACK(file_util_rename_preview_adj_cb), ud);
1857 file_util_dialog_list_select(ud->listview, 0);
1860 static void file_util_finalize_all(UtilityData *ud)
1862 GList *work = ud->flist;
1864 if (ud->phase == UTILITY_PHASE_CANCEL) return;
1865 if (ud->phase == UTILITY_PHASE_DONE && !ud->finalize_func) return;
1866 if (ud->phase == UTILITY_PHASE_DISCARD && !ud->discard_func) return;
1870 auto fd = static_cast<FileData *>(work->data);
1872 if (ud->phase == UTILITY_PHASE_DONE) ud->finalize_func(fd);
1873 else if (ud->phase == UTILITY_PHASE_DISCARD) ud->discard_func(fd);
1877 static gboolean file_util_exclude_fd(UtilityData *ud, FileData *fd)
1879 GtkTreeModel *store;
1883 if (!g_list_find(ud->flist, fd)) return FALSE;
1885 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ud->listview));
1886 valid = gtk_tree_model_get_iter_first(store, &iter);
1890 gtk_tree_model_get(store, &iter, UTILITY_COLUMN_FD, &store_fd, -1);
1894 gtk_list_store_remove(GTK_LIST_STORE(store), &iter);
1897 valid = gtk_tree_model_iter_next(store, &iter);
1900 ud->flist = g_list_remove(ud->flist, fd);
1902 if (ud->with_sidecars)
1903 file_data_sc_free_ci(fd);
1905 file_data_free_ci(fd);
1907 file_data_unref(fd);
1911 void file_util_dialog_run(UtilityData *ud)
1915 case UTILITY_PHASE_START:
1916 /* create the dialogs */
1919 case UTILITY_TYPE_DELETE:
1920 case UTILITY_TYPE_DELETE_LINK:
1921 case UTILITY_TYPE_DELETE_FOLDER:
1922 case UTILITY_TYPE_EDITOR:
1923 case UTILITY_TYPE_WRITE_METADATA:
1924 file_util_dialog_init_simple_list(ud);
1925 ud->phase = UTILITY_PHASE_ENTERING;
1927 case UTILITY_TYPE_RENAME:
1928 file_util_dialog_init_source_dest(ud, TRUE);
1929 ud->phase = UTILITY_PHASE_ENTERING;
1931 case UTILITY_TYPE_COPY:
1932 case UTILITY_TYPE_MOVE:
1933 file_util_dialog_init_dest_folder(ud);
1934 ud->phase = UTILITY_PHASE_INTERMEDIATE;
1936 case UTILITY_TYPE_FILTER:
1937 case UTILITY_TYPE_CREATE_FOLDER:
1938 file_util_dialog_init_dest_folder(ud);
1939 ud->phase = UTILITY_PHASE_ENTERING;
1941 case UTILITY_TYPE_RENAME_FOLDER:
1942 ud->phase = UTILITY_PHASE_CANCEL; /**< @FIXME not handled for now */
1943 file_util_dialog_run(ud);
1947 case UTILITY_PHASE_INTERMEDIATE:
1950 case UTILITY_TYPE_COPY:
1951 case UTILITY_TYPE_MOVE:
1952 file_util_dialog_init_source_dest(ud, TRUE);
1956 ud->phase = UTILITY_PHASE_ENTERING;
1958 case UTILITY_PHASE_ENTERING:
1959 file_util_check_ci(ud);
1961 case UTILITY_PHASE_CHECKED:
1962 file_util_perform_ci(ud);
1964 case UTILITY_PHASE_CANCEL:
1965 case UTILITY_PHASE_DONE:
1966 case UTILITY_PHASE_DISCARD:
1968 file_util_finalize_all(ud);
1970 /* both DISCARD and DONE finishes the operation for good */
1972 ud->done_func((ud->phase != UTILITY_PHASE_CANCEL), ud->dest_path, ud->done_data);
1974 if (ud->with_sidecars)
1975 file_data_sc_free_ci_list(ud->flist);
1977 file_data_free_ci_list(ud->flist);
1979 /* directory content is always handled including sidecars */
1980 file_data_sc_free_ci_list(ud->content_list);
1982 if (ud->dir_fd) file_data_free_ci(ud->dir_fd);
1983 file_util_data_free(ud);
1991 static void file_util_warn_op_in_progress(const gchar *title)
1993 file_util_warning_dialog(title, _("Another operation in progress.\n"), GQ_ICON_DIALOG_ERROR, nullptr);
1996 static void file_util_details_dialog_close_cb(GtkWidget *, gpointer data)
1998 g_object_unref(GTK_WIDGET(data));
2002 static void file_util_details_dialog_destroy_cb(GtkWidget *widget, gpointer data)
2004 auto ud = static_cast<UtilityData *>(data);
2005 g_signal_handlers_disconnect_by_func(ud->gd->dialog, (gpointer)(file_util_details_dialog_close_cb), widget);
2009 static void file_util_details_dialog_ok_cb(GenericDialog *, gpointer)
2014 static void file_util_details_dialog_exclude(GenericDialog *gd, gpointer data, gboolean discard)
2016 auto ud = static_cast<UtilityData *>(data);
2017 auto fd = static_cast<FileData *>(g_object_get_data(G_OBJECT(gd->dialog), "file_data"));
2020 file_util_exclude_fd(ud, fd);
2022 if (discard && ud->discard_func) ud->discard_func(fd);
2024 /* all files were excluded, this has the same effect as pressing the cancel button in the confirmation dialog*/
2027 /* both dialogs will be closed anyway, the signals would cause duplicate calls */
2028 g_signal_handlers_disconnect_by_func(ud->gd->dialog, (gpointer)(file_util_details_dialog_close_cb), gd->dialog);
2029 g_signal_handlers_disconnect_by_func(gd->dialog, (gpointer)(file_util_details_dialog_destroy_cb), ud);
2031 file_util_cancel_cb(ud->gd, ud);
2035 static void file_util_details_dialog_exclude_cb(GenericDialog *gd, gpointer data)
2037 file_util_details_dialog_exclude(gd, data, FALSE);
2040 static void file_util_details_dialog_discard_cb(GenericDialog *gd, gpointer data)
2042 file_util_details_dialog_exclude(gd, data, TRUE);
2045 static gchar *file_util_details_get_message(UtilityData *ud, FileData *fd, const gchar **icon_name)
2047 GString *message = g_string_new("");
2049 g_string_append_printf(message, _("File: '%s'\n"), fd->path);
2051 if (ud->with_sidecars && fd->sidecar_files)
2053 GList *work = fd->sidecar_files;
2054 g_string_append(message, _("with sidecar files:\n"));
2058 auto sfd = static_cast<FileData *>(work->data);
2060 g_string_append_printf(message, _(" '%s'\n"), sfd->path);
2064 g_string_append(message, _("\nStatus: "));
2066 error = ud->with_sidecars ? file_data_sc_verify_ci(fd, ud->flist) : file_data_verify_ci(fd, ud->flist);
2070 gchar *err_msg = file_data_get_error_string(error);
2071 g_string_append(message, err_msg);
2072 if (icon_name) *icon_name = (error & CHANGE_ERROR_MASK) ? GQ_ICON_DIALOG_ERROR : GQ_ICON_DIALOG_WARNING;
2077 g_string_append(message, _("no problem detected"));
2078 if (icon_name) *icon_name = GQ_ICON_DIALOG_INFO;
2081 return g_string_free(message, FALSE);;
2084 static void file_util_details_dialog(UtilityData *ud, FileData *fd)
2089 const gchar *icon_name;
2091 gd = file_util_gen_dlg(_("File details"), "details", ud->gd->dialog, TRUE, nullptr, ud);
2092 generic_dialog_add_button(gd, GQ_ICON_CLOSE, _("Close"), file_util_details_dialog_ok_cb, TRUE);
2093 generic_dialog_add_button(gd, GQ_ICON_REMOVE, _("Exclude file"), file_util_details_dialog_exclude_cb, FALSE);
2095 g_object_set_data(G_OBJECT(gd->dialog), "file_data", fd);
2097 g_signal_connect(G_OBJECT(gd->dialog), "destroy",
2098 G_CALLBACK(file_util_details_dialog_destroy_cb), ud);
2100 /* in case the ud->gd->dialog is closed during editing */
2101 g_signal_connect(G_OBJECT(ud->gd->dialog), "destroy",
2102 G_CALLBACK(file_util_details_dialog_close_cb), gd->dialog);
2105 message = file_util_details_get_message(ud, fd, &icon_name);
2107 box = generic_dialog_add_message(gd, icon_name, _("File details"), message, TRUE);
2109 generic_dialog_add_image(gd, box, fd, nullptr, FALSE, nullptr, nullptr, FALSE);
2111 gtk_widget_show(gd->dialog);
2116 static void file_util_write_metadata_details_dialog(UtilityData *ud, FileData *fd)
2123 GList *keys = nullptr;
2128 const gchar *icon_name;
2130 if (fd && fd->modified_xmp)
2132 keys = g_hash_table_get_keys(fd->modified_xmp);
2138 gd = file_util_gen_dlg(_("Overview of changed metadata"), "details", ud->gd->dialog, TRUE, nullptr, ud);
2139 generic_dialog_add_button(gd, GQ_ICON_CLOSE, _("Close"), file_util_details_dialog_ok_cb, TRUE);
2140 generic_dialog_add_button(gd, GQ_ICON_REMOVE, _("Exclude file"), file_util_details_dialog_exclude_cb, FALSE);
2141 generic_dialog_add_button(gd, GQ_ICON_REVERT, _("Discard changes"), file_util_details_dialog_discard_cb, FALSE);
2143 g_object_set_data(G_OBJECT(gd->dialog), "file_data", fd);
2145 g_signal_connect(G_OBJECT(gd->dialog), "destroy",
2146 G_CALLBACK(file_util_details_dialog_destroy_cb), ud);
2148 /* in case the ud->gd->dialog is closed during editing */
2149 g_signal_connect(G_OBJECT(ud->gd->dialog), "destroy",
2150 G_CALLBACK(file_util_details_dialog_close_cb), gd->dialog);
2152 message1 = file_util_details_get_message(ud, fd, &icon_name);
2154 if (fd->change && fd->change->dest)
2156 message2 = g_strdup_printf(_("The following metadata tags will be written to\n'%s'."), fd->change->dest);
2160 message2 = g_strdup_printf(_("The following metadata tags will be written to the image file itself."));
2163 box = generic_dialog_add_message(gd, icon_name, _("Overview of changed metadata"), message1, TRUE);
2165 box = pref_group_new(box, TRUE, message2, GTK_ORIENTATION_HORIZONTAL);
2167 frame = pref_frame_new(box, TRUE, nullptr, GTK_ORIENTATION_HORIZONTAL, 2);
2168 table = pref_table_new(frame, 2, g_list_length(keys), FALSE, TRUE);
2174 auto key = static_cast<const gchar *>(work->data);
2175 gchar *title = exif_get_description_by_key(key);
2176 gchar *title_f = g_strdup_printf("%s:", title);
2177 gchar *value = metadata_read_string(fd, key, METADATA_FORMATTED);
2181 label = gtk_label_new(title_f);
2182 gtk_label_set_xalign(GTK_LABEL(label), 1.0);
2183 gtk_label_set_yalign(GTK_LABEL(label), 0.0);
2185 pref_label_bold(label, TRUE, FALSE);
2186 gq_gtk_grid_attach(GTK_GRID(table), label, 0, 1, i, i + 1, GTK_FILL, GTK_FILL, 2, 2);
2187 gtk_widget_show(label);
2189 label = gtk_label_new(value);
2191 gtk_label_set_xalign(GTK_LABEL(label), 0.0);
2192 gtk_label_set_yalign(GTK_LABEL(label), 0.0);
2194 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
2195 gq_gtk_grid_attach(GTK_GRID(table), label, 1, 2, i, i + 1, GTK_FILL, GTK_FILL, 2, 2);
2196 gtk_widget_show(label);
2204 generic_dialog_add_image(gd, box, fd, nullptr, FALSE, nullptr, nullptr, FALSE);
2206 gtk_widget_set_size_request(gd->dialog, DIALOG_WIDTH, -1);
2207 gtk_widget_show(gd->dialog);
2215 static void file_util_mark_ungrouped_files(GList *work)
2219 auto fd = static_cast<FileData *>(work->data);
2220 file_data_set_regroup_when_finished(fd, TRUE);
2225 static void file_util_delete_full(FileData *source_fd, GList *flist, GtkWidget *parent, UtilityPhase phase, FileUtilDoneFunc done_func, gpointer done_data)
2228 GList *ungrouped = nullptr;
2232 flist = g_list_append(flist, file_data_ref(source_fd));
2236 flist = file_data_process_groups_in_selection(flist, TRUE, &ungrouped);
2238 if (!file_data_sc_add_ci_delete_list(flist))
2240 file_util_warn_op_in_progress(_("File deletion failed"));
2241 file_data_disable_grouping_list(ungrouped, FALSE);
2242 filelist_free(flist);
2243 filelist_free(ungrouped);
2247 file_util_mark_ungrouped_files(ungrouped);
2248 filelist_free(ungrouped);
2250 ud = file_util_data_new(UTILITY_TYPE_DELETE);
2254 ud->with_sidecars = TRUE;
2256 ud->dir_fd = nullptr;
2258 ud->content_list = nullptr;
2259 ud->parent = parent;
2260 ud->done_data = done_data;
2261 ud->done_func = done_func;
2263 ud->details_func = file_util_details_dialog;
2264 if(options->file_ops.safe_delete_enable)
2266 message = _("This will move the following files to the Trash bin");
2270 message = _("This will permanently delete the following files");
2272 ud->messages.title = _("Delete");
2273 ud->messages.question = _("Delete files?");
2274 ud->messages.desc_flist = message;
2275 ud->messages.desc_source_fd = "";
2276 ud->messages.fail = _("File deletion failed");
2278 file_util_dialog_run(ud);
2282 static void file_util_write_metadata_full(FileData *source_fd, GList *flist, GtkWidget *parent, UtilityPhase phase, FileUtilDoneFunc done_func, gpointer done_data)
2287 flist = g_list_append(flist, file_data_ref(source_fd));
2291 if (!file_data_add_ci_write_metadata_list(flist))
2293 file_util_warn_op_in_progress(_("Can't write metadata"));
2294 filelist_free(flist);
2298 ud = file_util_data_new(UTILITY_TYPE_WRITE_METADATA);
2302 ud->with_sidecars = FALSE; /* operate on individual files, not groups */
2304 ud->dir_fd = nullptr;
2306 ud->content_list = nullptr;
2307 ud->parent = parent;
2309 ud->done_func = done_func;
2310 ud->done_data = done_data;
2312 ud->details_func = file_util_write_metadata_details_dialog;
2313 ud->finalize_func = metadata_write_queue_remove;
2314 ud->discard_func = metadata_write_queue_remove;
2316 ud->messages.title = _("Write metadata");
2317 ud->messages.question = _("Write metadata?");
2318 ud->messages.desc_flist = _("This will write the changed metadata into the following files");
2319 ud->messages.desc_source_fd = "";
2320 ud->messages.fail = _("Metadata writing failed");
2322 file_util_dialog_run(ud);
2325 static void file_util_move_full(FileData *source_fd, GList *flist, const gchar *dest_path, GtkWidget *parent, UtilityPhase phase)
2328 GList *ungrouped = nullptr;
2331 flist = g_list_append(flist, file_data_ref(source_fd));
2335 flist = file_data_process_groups_in_selection(flist, TRUE, &ungrouped);
2337 if (!file_data_sc_add_ci_move_list(flist, dest_path))
2339 file_util_warn_op_in_progress(_("Move failed"));
2340 file_data_disable_grouping_list(ungrouped, FALSE);
2341 filelist_free(flist);
2342 filelist_free(ungrouped);
2346 file_util_mark_ungrouped_files(ungrouped);
2347 filelist_free(ungrouped);
2349 ud = file_util_data_new(UTILITY_TYPE_MOVE);
2353 ud->with_sidecars = TRUE;
2355 ud->dir_fd = nullptr;
2357 ud->content_list = nullptr;
2358 ud->parent = parent;
2359 ud->details_func = file_util_details_dialog;
2361 if (dest_path) ud->dest_path = g_strdup(dest_path);
2363 ud->messages.title = _("Move");
2364 ud->messages.question = _("Move files?");
2365 ud->messages.desc_flist = _("This will move the following files");
2366 ud->messages.desc_source_fd = "";
2367 ud->messages.fail = _("Move failed");
2369 file_util_dialog_run(ud);
2372 static void file_util_copy_full(FileData *source_fd, GList *flist, const gchar *dest_path, GtkWidget *parent, UtilityPhase phase)
2375 GList *ungrouped = nullptr;
2378 flist = g_list_append(flist, file_data_ref(source_fd));
2382 if (file_util_write_metadata_first(UTILITY_TYPE_COPY, phase, flist, dest_path, nullptr, parent))
2385 flist = file_data_process_groups_in_selection(flist, TRUE, &ungrouped);
2387 if (!file_data_sc_add_ci_copy_list(flist, dest_path))
2389 file_util_warn_op_in_progress(_("Copy failed"));
2390 file_data_disable_grouping_list(ungrouped, FALSE);
2391 filelist_free(flist);
2392 filelist_free(ungrouped);
2396 file_util_mark_ungrouped_files(ungrouped);
2397 filelist_free(ungrouped);
2399 ud = file_util_data_new(UTILITY_TYPE_COPY);
2403 ud->with_sidecars = TRUE;
2405 ud->dir_fd = nullptr;
2407 ud->content_list = nullptr;
2408 ud->parent = parent;
2409 ud->details_func = file_util_details_dialog;
2411 if (dest_path) ud->dest_path = g_strdup(dest_path);
2413 ud->messages.title = _("Copy");
2414 ud->messages.question = _("Copy files?");
2415 ud->messages.desc_flist = _("This will copy the following files");
2416 ud->messages.desc_source_fd = "";
2417 ud->messages.fail = _("Copy failed");
2419 file_util_dialog_run(ud);
2422 static void file_util_rename_full(FileData *source_fd, GList *flist, const gchar *dest_path, GtkWidget *parent, UtilityPhase phase)
2425 GList *ungrouped = nullptr;
2428 flist = g_list_append(flist, file_data_ref(source_fd));
2432 flist = file_data_process_groups_in_selection(flist, TRUE, &ungrouped);
2434 if (!file_data_sc_add_ci_rename_list(flist, dest_path))
2436 file_util_warn_op_in_progress(_("Rename failed"));
2437 file_data_disable_grouping_list(ungrouped, FALSE);
2438 filelist_free(flist);
2439 filelist_free(ungrouped);
2443 file_util_mark_ungrouped_files(ungrouped);
2444 filelist_free(ungrouped);
2446 ud = file_util_data_new(UTILITY_TYPE_RENAME);
2450 ud->with_sidecars = TRUE;
2452 ud->dir_fd = nullptr;
2454 ud->content_list = nullptr;
2455 ud->parent = parent;
2457 ud->details_func = file_util_details_dialog;
2459 ud->messages.title = _("Rename");
2460 ud->messages.question = _("Rename files?");
2461 ud->messages.desc_flist = _("This will rename the following files");
2462 ud->messages.desc_source_fd = "";
2463 ud->messages.fail = _("Rename failed");
2465 file_util_dialog_run(ud);
2468 static void file_util_start_editor_full(const gchar *key, FileData *source_fd, GList *flist, const gchar *dest_path, const gchar *working_directory, GtkWidget *parent, UtilityPhase phase)
2471 GList *ungrouped = nullptr;
2473 if (editor_no_param(key))
2475 gchar *file_directory = nullptr;
2476 if (!working_directory)
2478 /* working directory was not specified, try to extract it from the files */
2480 file_directory = remove_level_from_path(source_fd->path);
2482 if (!file_directory && flist)
2483 file_directory = remove_level_from_path((static_cast<FileData *>(flist->data))->path);
2484 working_directory = file_directory;
2487 /* just start the editor, don't care about files */
2488 start_editor(key, working_directory);
2489 g_free(file_directory);
2490 filelist_free(flist);
2497 /* flist is most probably NULL
2498 operate on source_fd and it's sidecars
2500 flist = g_list_concat(filelist_copy(source_fd->sidecar_files), flist);
2501 flist = g_list_append(flist, file_data_ref(source_fd));
2506 if (file_util_write_metadata_first(UTILITY_TYPE_FILTER, phase, flist, dest_path, key, parent))
2509 flist = file_data_process_groups_in_selection(flist, TRUE, &ungrouped);
2511 if (!file_data_sc_add_ci_unspecified_list(flist, dest_path))
2513 file_util_warn_op_in_progress(_("Can't run external editor"));
2514 file_data_disable_grouping_list(ungrouped, FALSE);
2515 filelist_free(flist);
2516 filelist_free(ungrouped);
2520 file_util_mark_ungrouped_files(ungrouped);
2521 filelist_free(ungrouped);
2523 if (editor_is_filter(key))
2524 ud = file_util_data_new(UTILITY_TYPE_FILTER);
2526 ud = file_util_data_new(UTILITY_TYPE_EDITOR);
2529 /* ask for destination if we don't have it */
2530 if (ud->type == UTILITY_TYPE_FILTER && dest_path == nullptr) phase = UTILITY_PHASE_START;
2534 ud->with_sidecars = TRUE;
2536 ud->external_command = g_strdup(key);
2538 ud->dir_fd = nullptr;
2540 ud->content_list = nullptr;
2541 ud->parent = parent;
2543 ud->details_func = file_util_details_dialog;
2545 if (dest_path) ud->dest_path = g_strdup(dest_path);
2547 ud->messages.title = _("Editor");
2548 ud->messages.question = _("Run editor?");
2549 ud->messages.desc_flist = _("This will copy the following files");
2550 ud->messages.desc_source_fd = "";
2551 ud->messages.fail = _("External command failed");
2553 file_util_dialog_run(ud);
2556 static GList *file_util_delete_dir_remaining_folders(GList *dlist)
2558 GList *rlist = nullptr;
2564 fd = static_cast<FileData *>(dlist->data);
2565 dlist = dlist->next;
2568 (strcmp(fd->name, THUMB_FOLDER_GLOBAL) != 0 &&
2569 strcmp(fd->name, THUMB_FOLDER_LOCAL) != 0 &&
2570 strcmp(fd->name, GQ_CACHE_LOCAL_METADATA) != 0) )
2572 rlist = g_list_prepend(rlist, fd);
2576 return g_list_reverse(rlist);
2579 static gboolean file_util_delete_dir_empty_path(UtilityData *ud, FileData *fd, gint level)
2587 DEBUG_1("deltree into: %s", fd->path);
2590 if (level > UTILITY_DELETE_MAX_DEPTH)
2592 log_printf("folder recursion depth past %d, giving up\n", UTILITY_DELETE_MAX_DEPTH);
2597 if (!filelist_read_lstat(fd, &flist, &dlist))
2605 ok = file_data_sc_add_ci_delete(fd);
2608 ud->content_list = g_list_prepend(ud->content_list, fd);
2618 lfd = static_cast<FileData *>(work->data);
2621 ok = file_util_delete_dir_empty_path(ud, lfd, level);
2629 lfd = static_cast<FileData *>(work->data);
2632 DEBUG_1("deltree child: %s", lfd->path);
2634 ok = file_data_sc_add_ci_delete(lfd);
2637 ud->content_list = g_list_prepend(ud->content_list, lfd);
2642 filelist_free(dlist);
2643 filelist_free(flist);
2646 DEBUG_1("deltree done: %s", fd->path);
2651 static gboolean file_util_delete_dir_prepare(UtilityData *ud, GList *flist, GList *dlist)
2662 fd = static_cast<FileData *>(work->data);
2665 ok = file_util_delete_dir_empty_path(ud, fd, 0);
2669 if (ok && file_data_sc_add_ci_delete_list(flist))
2671 ud->content_list = g_list_concat(filelist_copy(flist), ud->content_list);
2680 ok = file_data_sc_add_ci_delete(ud->dir_fd);
2685 work = ud->content_list;
2690 fd = static_cast<FileData *>(work->data);
2692 file_data_sc_free_ci(fd);
2699 static void file_util_delete_dir_full(FileData *fd, GtkWidget *parent, UtilityPhase phase)
2705 if (!isdir(fd->path)) return;
2707 if (islink(fd->path))
2710 ud = file_util_data_new(UTILITY_TYPE_DELETE_LINK);
2713 ud->with_sidecars = TRUE;
2714 ud->dir_fd = file_data_ref(fd);
2715 ud->content_list = nullptr;
2716 ud->flist = nullptr;
2718 ud->parent = parent;
2720 ud->messages.title = _("Delete folder");
2721 ud->messages.question = _("Delete symbolic link?");
2722 ud->messages.desc_flist = "";
2723 ud->messages.desc_source_fd = _("This will delete the symbolic link.\n"
2724 "The folder this link points to will not be deleted.");
2725 ud->messages.fail = _("Link deletion failed");
2727 file_util_dialog_run(ud);
2731 if (!access_file(fd->path, W_OK | X_OK))
2735 text = g_strdup_printf(_("Unable to remove folder %s\n"
2736 "Permissions do not allow writing to the folder."), fd->path);
2737 file_util_warning_dialog(_("Delete failed"), text, GQ_ICON_DIALOG_ERROR, parent);
2743 if (!filelist_read_lstat(fd, &flist, &dlist))
2747 text = g_strdup_printf(_("Unable to list contents of folder %s"), fd->path);
2748 file_util_warning_dialog(_("Delete failed"), text, GQ_ICON_DIALOG_ERROR, parent);
2754 rlist = file_util_delete_dir_remaining_folders(dlist);
2761 gd = file_util_gen_dlg(_("Folder contains subfolders"), "dlg_warning",
2762 parent, TRUE, nullptr, nullptr);
2763 generic_dialog_add_button(gd, GQ_ICON_CLOSE, _("Close"), nullptr, TRUE);
2765 text = g_strdup_printf(_("Unable to delete the folder:\n\n%s\n\n"
2766 "This folder contains subfolders which must be moved before it can be deleted."),
2768 box = generic_dialog_add_message(gd, GQ_ICON_DIALOG_WARNING,
2769 _("Folder contains subfolders"),
2773 box = pref_group_new(box, TRUE, _("Subfolders:"), GTK_ORIENTATION_VERTICAL);
2775 rlist = filelist_sort_path(rlist);
2776 file_util_dialog_add_list(box, rlist, FALSE, FALSE);
2778 gtk_widget_show(gd->dialog);
2783 ud = file_util_data_new(UTILITY_TYPE_DELETE_FOLDER);
2786 ud->with_sidecars = TRUE;
2787 ud->dir_fd = file_data_ref(fd);
2788 ud->content_list = nullptr; /* will be filled by file_util_delete_dir_prepare */
2789 ud->flist = flist = filelist_sort_path(flist);
2791 ud->parent = parent;
2793 ud->messages.title = _("Delete folder");
2794 ud->messages.question = _("Delete folder?");
2795 ud->messages.desc_flist = _("The folder contains these files:");
2796 ud->messages.desc_source_fd = _("This will delete the folder.\n"
2797 "The contents of this folder will also be deleted.");
2798 ud->messages.fail = _("File deletion failed");
2800 if (!file_util_delete_dir_prepare(ud, flist, dlist))
2804 text = g_strdup_printf(_("Unable to list contents of folder %s"), fd->path);
2805 file_util_warning_dialog(_("Delete failed"), text, GQ_ICON_DIALOG_ERROR, parent);
2807 file_data_unref(ud->dir_fd);
2808 file_util_data_free(ud);
2812 filelist_free(dlist);
2813 file_util_dialog_run(ud);
2819 filelist_free(dlist);
2820 filelist_free(flist);
2823 static gboolean file_util_rename_dir_scan(UtilityData *ud, FileData *fd)
2831 if (!filelist_read_lstat(fd, &flist, &dlist))
2837 ud->content_list = g_list_concat(flist, ud->content_list);
2844 lfd = static_cast<FileData *>(work->data);
2847 ud->content_list = g_list_prepend(ud->content_list, file_data_ref(lfd));
2848 ok = file_util_rename_dir_scan(ud, lfd);
2851 filelist_free(dlist);
2856 static gboolean file_util_rename_dir_prepare(UtilityData *ud, const gchar *new_path)
2860 gint orig_len = strlen(ud->dir_fd->path);
2862 ok = file_util_rename_dir_scan(ud, ud->dir_fd);
2864 work = ud->content_list;
2871 fd = static_cast<FileData *>(work->data);
2874 g_assert(strncmp(fd->path, ud->dir_fd->path, orig_len) == 0);
2876 np = g_strconcat(new_path, fd->path + orig_len, NULL);
2878 ok = file_data_sc_add_ci_rename(fd, np);
2880 DEBUG_1("Dir rename: %s -> %s", fd->path, np);
2886 ok = file_data_sc_add_ci_rename(ud->dir_fd, new_path);
2891 work = ud->content_list;
2896 fd = static_cast<FileData *>(work->data);
2898 file_data_sc_free_ci(fd);
2906 static void file_util_rename_dir_full(FileData *fd, const gchar *new_path, GtkWidget *parent, UtilityPhase phase, FileUtilDoneFunc done_func, gpointer done_data)
2910 ud = file_util_data_new(UTILITY_TYPE_RENAME_FOLDER);
2913 ud->with_sidecars = TRUE; /* does not matter, the directory should not have sidecars
2914 and the content must be handled including sidecars */
2916 ud->dir_fd = file_data_ref(fd);
2917 ud->flist = nullptr;
2918 ud->content_list = nullptr;
2919 ud->parent = parent;
2921 ud->done_func = done_func;
2922 ud->done_data = done_data;
2923 ud->dest_path = g_strdup(new_path);
2925 ud->messages.title = _("Rename");
2926 ud->messages.question = _("Rename folder?");
2927 ud->messages.desc_flist = _("The folder contains the following files");
2928 ud->messages.desc_source_fd = "";
2929 ud->messages.fail = _("Rename failed");
2931 if (!file_util_rename_dir_prepare(ud, new_path))
2933 file_util_warn_op_in_progress(ud->messages.fail);
2934 file_util_data_free(ud);
2938 file_util_dialog_run(ud);
2941 static void file_util_create_dir_full(const gchar *path, const gchar *dest_path, GtkWidget *parent, UtilityPhase phase, FileUtilDoneFunc done_func, gpointer done_data)
2945 ud = file_util_data_new(UTILITY_TYPE_CREATE_FOLDER);
2948 ud->with_sidecars = TRUE;
2950 ud->dir_fd = nullptr;
2951 ud->flist = nullptr;
2952 ud->content_list = nullptr;
2953 ud->parent = parent;
2957 g_assert_not_reached(); // not used in current design
2958 ud->dest_path = g_strdup(dest_path);
2962 gchar *buf = g_build_filename(path, _("New folder"), nullptr);
2963 ud->dest_path = unique_filename(buf, nullptr, " ", FALSE);
2967 ud->done_func = done_func;
2968 ud->done_data = done_data;
2970 ud->messages.title = _("Create Folder");
2971 ud->messages.question = _("Create folder?");
2972 ud->messages.desc_flist = "";
2973 ud->messages.desc_source_fd = "";
2974 ud->messages.fail = _("Can't create folder");
2976 file_util_dialog_run(ud);
2979 static gboolean file_util_write_metadata_first_after_done(gpointer data)
2981 auto dd = static_cast<UtilityDelayData *>(data);
2983 /* start the delayed operation with original arguments */
2986 case UTILITY_TYPE_FILTER:
2987 case UTILITY_TYPE_EDITOR:
2988 file_util_start_editor_full(dd->editor_key, nullptr, dd->flist, dd->dest_path, nullptr, dd->parent, dd->phase);
2990 case UTILITY_TYPE_COPY:
2991 file_util_copy_full(nullptr, dd->flist, dd->dest_path, dd->parent, dd->phase);
2994 g_warning("unsupported type");
2996 g_free(dd->dest_path);
2997 g_free(dd->editor_key);
2999 return G_SOURCE_REMOVE;
3002 static void file_util_write_metadata_first_done(gboolean success, const gchar *, gpointer data)
3004 auto dd = static_cast<UtilityDelayData *>(data);
3008 dd->idle_id = g_idle_add(file_util_write_metadata_first_after_done, dd);
3012 /* the operation was cancelled */
3013 filelist_free(dd->flist);
3014 g_free(dd->dest_path);
3015 g_free(dd->editor_key);
3019 static gboolean file_util_write_metadata_first(UtilityType type, UtilityPhase phase, GList *flist, const gchar *dest_path, const gchar *editor_key, GtkWidget *parent)
3021 GList *unsaved = nullptr;
3022 UtilityDelayData *dd;
3029 auto fd = static_cast<FileData *>(work->data);
3034 filelist_free(unsaved);
3035 return FALSE; /* another op. in progress, let the caller handle it */
3038 if (fd->modified_xmp) /* has unsaved metadata */
3040 unsaved = g_list_prepend(unsaved, file_data_ref(fd));
3044 if (!unsaved) return FALSE;
3046 /* save arguments of the original operation */
3048 dd = g_new0(UtilityDelayData, 1);
3053 dd->dest_path = g_strdup(dest_path);
3054 dd->editor_key = g_strdup(editor_key);
3055 dd->parent = parent;
3057 file_util_write_metadata(nullptr, unsaved, parent, FALSE, file_util_write_metadata_first_done, dd);
3062 /* full-featured entry points
3065 void file_util_delete(FileData *source_fd, GList *source_list, GtkWidget *parent)
3067 if (options->file_ops.safe_delete_enable == FALSE)
3069 file_util_delete_full(source_fd, source_list, parent, options->file_ops.confirm_delete ? UTILITY_PHASE_START : UTILITY_PHASE_ENTERING, nullptr, nullptr);
3073 file_util_delete_full(source_fd, source_list, parent, options->file_ops.confirm_move_to_trash ? UTILITY_PHASE_START : UTILITY_PHASE_ENTERING, nullptr, nullptr);
3077 void file_util_delete_notify_done(FileData *source_fd, GList *source_list, GtkWidget *parent, FileUtilDoneFunc done_func, gpointer done_data)
3079 file_util_delete_full(source_fd, source_list, parent, options->file_ops.confirm_delete ? UTILITY_PHASE_START : UTILITY_PHASE_ENTERING, done_func, done_data);
3082 void file_util_write_metadata(FileData *source_fd, GList *source_list, GtkWidget *parent, gboolean force_dialog, FileUtilDoneFunc done_func, gpointer done_data)
3084 file_util_write_metadata_full(source_fd, source_list, parent,
3085 ((options->metadata.save_in_image_file && options->metadata.confirm_write) || force_dialog) ? UTILITY_PHASE_START : UTILITY_PHASE_ENTERING,
3086 done_func, done_data);
3089 void file_util_copy(FileData *source_fd, GList *source_list, const gchar *dest_path, GtkWidget *parent)
3091 file_util_copy_full(source_fd, source_list, dest_path, parent, UTILITY_PHASE_START);
3094 void file_util_move(FileData *source_fd, GList *source_list, const gchar *dest_path, GtkWidget *parent)
3096 file_util_move_full(source_fd, source_list, dest_path, parent, UTILITY_PHASE_START);
3099 void file_util_rename(FileData *source_fd, GList *source_list, GtkWidget *parent)
3101 file_util_rename_full(source_fd, source_list, nullptr, parent, UTILITY_PHASE_START);
3104 /* these avoid the location entry dialog unless there is an error, list must be files only and
3105 * dest_path must be a valid directory path
3107 void file_util_move_simple(GList *list, const gchar *dest_path, GtkWidget *parent)
3109 file_util_move_full(nullptr, list, dest_path, parent, UTILITY_PHASE_ENTERING);
3112 void file_util_copy_simple(GList *list, const gchar *dest_path, GtkWidget *parent)
3114 file_util_copy_full(nullptr, list, dest_path, parent, UTILITY_PHASE_ENTERING);
3117 void file_util_rename_simple(FileData *fd, const gchar *dest_path, GtkWidget *parent)
3119 file_util_rename_full(fd, nullptr, dest_path, parent, UTILITY_PHASE_ENTERING);
3123 void file_util_start_editor_from_file(const gchar *key, FileData *fd, GtkWidget *parent)
3125 file_util_start_editor_full(key, fd, nullptr, nullptr, nullptr, parent, UTILITY_PHASE_ENTERING);
3128 void file_util_start_editor_from_filelist(const gchar *key, GList *list, const gchar *working_directory, GtkWidget *parent)
3130 file_util_start_editor_full(key, nullptr, list, nullptr, working_directory, parent, UTILITY_PHASE_ENTERING);
3133 #pragma GCC diagnostic push
3134 #pragma GCC diagnostic ignored "-Wunused-function"
3135 void file_util_start_filter_from_file_unused(const gchar *key, FileData *fd, const gchar *dest_path, GtkWidget *parent)
3137 file_util_start_editor_full(key, fd, nullptr, dest_path, nullptr, parent, UTILITY_PHASE_ENTERING);
3139 #pragma GCC diagnostic pop
3141 void file_util_start_filter_from_filelist(const gchar *key, GList *list, const gchar *dest_path, GtkWidget *parent)
3143 file_util_start_editor_full(key, nullptr, list, dest_path, nullptr, parent, UTILITY_PHASE_ENTERING);
3146 void file_util_delete_dir(FileData *fd, GtkWidget *parent)
3148 file_util_delete_dir_full(fd, parent, UTILITY_PHASE_START);
3151 void file_util_create_dir(const gchar *path, GtkWidget *parent, FileUtilDoneFunc done_func, gpointer done_data)
3153 file_util_create_dir_full(path, nullptr, parent, UTILITY_PHASE_START, done_func, done_data);
3156 void file_util_rename_dir(FileData *source_fd, const gchar *new_path, GtkWidget *parent, FileUtilDoneFunc done_func, gpointer done_data)
3158 file_util_rename_dir_full(source_fd, new_path, parent, UTILITY_PHASE_ENTERING, done_func, done_data);
3164 * @param selection_data
3166 * @param data #_ClipboardData
3171 static void clipboard_get_func(GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, gpointer data)
3173 /* @FIXME GTK4 stub */
3176 static void clipboard_get_func(GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, gpointer data)
3178 auto cbd = static_cast<ClipboardData *>(data);
3180 gchar *file_path_quoted = nullptr;
3181 gchar *file_path_uri;
3182 GString *path_list_str;
3185 path_list_str = g_string_new("");
3186 work = cbd->path_list;
3188 if (clipboard == gtk_clipboard_get(GDK_SELECTION_CLIPBOARD) && info == CLIPBOARD_X_SPECIAL_GNOME_COPIED_FILES)
3190 g_string_append(path_list_str, "copy");
3194 file_path = static_cast<gchar *>(work->data);
3197 file_path_uri = g_filename_to_uri(file_path, nullptr, nullptr);
3198 g_string_append(path_list_str, "\n");
3199 g_string_append(path_list_str, file_path_uri);
3200 g_free(file_path_uri);
3207 file_path = static_cast<gchar *>(work->data);
3212 file_path_quoted = g_shell_quote(file_path);
3213 g_string_append(path_list_str, file_path_quoted);
3214 g_free(file_path_quoted);
3218 g_string_append(path_list_str, file_path);
3223 g_string_append_c(path_list_str, ' ');
3228 gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data), 8, reinterpret_cast<guchar *>(path_list_str->str), path_list_str->len);
3230 g_string_free(path_list_str, TRUE);
3237 * @param data _ClipboardData
3241 static void clipboard_clear_func(GtkClipboard *, gpointer data)
3243 auto cbd = static_cast<ClipboardData *>(data);
3245 g_list_free_full(cbd->path_list, g_free);
3249 void file_util_copy_path_to_clipboard(FileData *fd, gboolean quoted)
3253 if (!fd || !*fd->path) return;
3256 if (options->clipboard_selection == CLIPBOARD_PRIMARY || options->clipboard_selection == CLIPBOARD_BOTH)
3258 cbd = g_new0(ClipboardData, 1);
3259 cbd->path_list = nullptr;
3260 cbd->quoted = quoted;
3261 cbd->path_list = g_list_append(cbd->path_list, g_strdup(fd->path));
3263 gtk_clipboard_set_with_data(gtk_clipboard_get(GDK_SELECTION_PRIMARY), target_types, target_types_n, clipboard_get_func, clipboard_clear_func, cbd);
3266 if (options->clipboard_selection == CLIPBOARD_CLIPBOARD || options->clipboard_selection == CLIPBOARD_BOTH)
3268 cbd = g_new0(ClipboardData, 1);
3269 cbd->path_list = nullptr;
3270 cbd->quoted = quoted;
3271 cbd->path_list = g_list_append(cbd->path_list, g_strdup(fd->path));
3273 gtk_clipboard_set_with_data(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), target_types, target_types_n, clipboard_get_func, clipboard_clear_func, cbd);
3279 * @param fd_list List of fd
3284 void file_util_copy_path_list_to_clipboard(GList *fd_list, gboolean quoted)
3290 if (options->clipboard_selection == CLIPBOARD_PRIMARY || options->clipboard_selection == CLIPBOARD_BOTH)
3292 cbd = g_new0(ClipboardData, 1);
3293 cbd->path_list = nullptr;
3294 cbd->quoted = quoted;
3299 fd = static_cast<FileData *>(work->data);
3302 if (!fd || !*fd->path) continue;
3304 cbd->path_list = g_list_append(cbd->path_list, g_strdup(fd->path));
3307 gtk_clipboard_set_with_data(gtk_clipboard_get(GDK_SELECTION_PRIMARY), target_types, target_types_n, clipboard_get_func, clipboard_clear_func, cbd);
3310 if (options->clipboard_selection == CLIPBOARD_CLIPBOARD || options->clipboard_selection == CLIPBOARD_BOTH)
3312 cbd = g_new0(ClipboardData, 1);
3313 cbd->path_list = nullptr;
3314 cbd->quoted = quoted;
3319 fd = static_cast<FileData *>(work->data);
3322 if (!fd || !*fd->path) continue;
3324 cbd->path_list = g_list_append(cbd->path_list, g_strdup(fd->path));
3327 gtk_clipboard_set_with_data(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), target_types, target_types_n, clipboard_get_func, clipboard_clear_func, cbd);
3330 filelist_free(fd_list);
3333 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */