struct _UtilityData {
UtilityType type;
UtilityPhase phase;
-
+
FileData *dir_fd;
GList *content_list;
GList *flist;
-
+
FileData *sel_fd;
GtkWidget *parent;
GenericDialog *gd;
FileDialog *fdlg;
-
+
guint update_idle_id; /* event source id */
guint perform_idle_id; /* event source id */
gboolean with_sidecars; /* operate on grouped or single files; TRUE = use file_data_sc_, FALSE = use file_data_ functions */
-
+
/* alternative dialog parts */
GtkWidget *notebook;
/* data for the operation itself, internal or external */
gboolean external; /* TRUE for external command, FALSE for internal */
-
+
gchar *external_command;
gpointer resume_data;
-
+
FileUtilDoneFunc done_func;
void (*details_func)(UtilityData *ud, FileData *fd);
gboolean (*finalize_func)(FileData *fd);
UtilityData *ud;
ud = g_new0(UtilityData, 1);
-
+
ud->type = type;
ud->phase = UTILITY_PHASE_START;
-
+
return ud;
}
filelist_free(ud->flist);
if (ud->gd) generic_dialog_close(ud->gd);
-
+
g_free(ud->dest_path);
g_free(ud->external_command);
FileData *fd = list->data;
GtkTreeIter iter;
gchar *sidecars;
-
+
sidecars = with_sidecars ? file_data_sc_list_to_string(fd) : NULL;
GdkPixbuf *icon = file_util_get_error_icon(fd, view);
gtk_list_store_append(store, &iter);
gint ret = EDITOR_CB_CONTINUE;
ud->resume_data = resume_data;
-
+
if (EDITOR_ERRORS_BUT_SKIPPED(flags))
{
GString *msg = g_string_new(editor_get_error_str(flags));
else
file_data_apply_ci(fd);
}
-
+
ud->flist = g_list_remove(ud->flist, fd);
-
+
if (ud->finalize_func)
{
ud->finalize_func(fd);
file_data_free_ci(fd);
file_data_unref(fd);
}
-
+
if (!resume_data) /* end of the list */
{
ud->phase = UTILITY_PHASE_DONE;
file_util_dialog_run(ud);
}
-
+
return ret;
}
/* this function was called directly
just setup idle callback and wait until we are called again
*/
-
+
/* this is removed when ud is destroyed */
ud->perform_idle_id = g_idle_add(file_util_perform_ci_internal, ud);
return TRUE;
}
g_assert(ud->flist);
-
+
if (ud->flist)
{
gint ret;
-
+
/* take a single entry each time, this allows better control over the operation */
GList *single_entry = g_list_append(NULL, ud->flist->data);
gboolean last = !ud->flist->next;
EditorFlags status = EDITOR_ERROR_STATUS;
-
+
if (ud->with_sidecars ? file_data_sc_perform_ci(single_entry->data)
: file_data_perform_ci(single_entry->data))
status = 0; /* OK */
-
+
ret = file_util_perform_ci_cb(GINT_TO_POINTER(!last), status, single_entry, ud);
g_list_free(single_entry);
-
+
if (ret == EDITOR_CB_SUSPEND || last) return FALSE;
-
+
if (ret == EDITOR_CB_SKIP)
{
file_util_perform_ci_cb(NULL, EDITOR_ERROR_SKIPPED, ud->flist, ud);
return FALSE;
}
}
-
+
return TRUE;
}
fd = work->data;
work = work->next;
-
+
if (!fail)
{
if ((internal && file_data_sc_perform_ci(fd)) ||
fail = file_data_ref(ud->dir_fd);
}
}
-
+
if (fail)
{
gchar *text;
{
fail = file_data_ref(ud->dir_fd);
}
-
+
work = ud->content_list;
while (work)
fd = work->data;
work = work->next;
-
+
if (!fail)
{
file_data_sc_apply_ci(fd);
}
file_data_sc_free_ci(fd);
}
-
+
if (fail)
{
gchar *text;
(void) file_util_warning_dialog(ud->messages.fail, text, GTK_STOCK_DIALOG_ERROR, NULL);
g_free(text);
}
-
+
break;
}
default:
if (is_valid_editor_command(ud->external_command))
{
EditorFlags flags;
-
+
ud->external = TRUE;
-
+
if (ud->dir_fd)
{
flags = start_editor_from_file_full(ud->external_command, ud->dir_fd, file_util_perform_ci_dir_cb, ud);
static GdkPixbuf *pb_error;
static GdkPixbuf *pb_apply;
gint error;
-
+
if (!pb_warning)
{
pb_warning = gtk_widget_render_icon(widget, GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_MENU, NULL);
{
pb_apply = gtk_widget_render_icon(widget, GTK_STOCK_APPLY, GTK_ICON_SIZE_MENU, NULL);
}
-
+
error = file_data_sc_verify_ci(fd);
-
+
if (!error) return pb_apply;
if (error & CHANGE_ERROR_MASK)
{
gint error = CHANGE_OK;
gchar *desc = NULL;
-
+
if (ud->type != UTILITY_TYPE_CREATE_FOLDER &&
ud->type != UTILITY_TYPE_RENAME_FOLDER)
{
static void file_util_cancel_cb(GenericDialog *gd, gpointer data)
{
UtilityData *ud = data;
-
+
generic_dialog_close(gd);
ud->gd = NULL;
-
+
ud->phase = UTILITY_PHASE_CANCEL;
file_util_dialog_run(ud);
}
static void file_util_discard_cb(GenericDialog *gd, gpointer data)
{
UtilityData *ud = data;
-
+
generic_dialog_close(gd);
ud->gd = NULL;
-
+
ud->phase = UTILITY_PHASE_DISCARD;
file_util_dialog_run(ud);
}
static void file_util_ok_cb(GenericDialog *gd, gpointer data)
{
UtilityData *ud = data;
-
+
generic_dialog_close(gd);
-
+
ud->gd = NULL;
file_util_dialog_run(ud);
static void file_util_fdlg_cancel_cb(FileDialog *fdlg, gpointer data)
{
UtilityData *ud = data;
-
+
file_dialog_close(fdlg);
ud->fdlg = NULL;
-
+
ud->phase = UTILITY_PHASE_CANCEL;
file_util_dialog_run(ud);
}
{
g_free(ud->dest_path);
ud->dest_path = g_strdup(gtk_entry_get_text(GTK_ENTRY(ud->fdlg->entry)));
-
+
switch (ud->type)
{
case UTILITY_TYPE_COPY:
static void file_util_fdlg_ok_cb(FileDialog *fdlg, gpointer data)
{
UtilityData *ud = data;
-
+
file_util_dest_folder_update_path(ud);
if (isdir(ud->dest_path)) file_dialog_sync_history(fdlg, TRUE);
file_dialog_close(fdlg);
-
+
ud->fdlg = NULL;
file_util_dialog_run(ud);
{
FileData *fd;
const gchar *dest = gtk_entry_get_text(GTK_ENTRY(ud->rename_entry));
-
+
gtk_tree_model_get(store, &iter, UTILITY_COLUMN_FD, &fd, -1);
g_assert(ud->with_sidecars); /* sidecars must be renamed too, it would break the pairing otherwise */
file_data_sc_update_ci_rename(fd, dest);
gtk_tree_model_get(store, &iter, UTILITY_COLUMN_FD, &fd, -1);
generic_dialog_image_set(ud->gd, fd);
-
+
ud->sel_fd = fd;
-
+
if (ud->type == UTILITY_TYPE_RENAME)
{
const gchar *name = filename_from_path(fd->change->dest);
{
dir_msg = g_strdup("");
}
-
+
box = generic_dialog_add_message(ud->gd, GTK_STOCK_DIALOG_QUESTION,
ud->messages.question,
dir_msg);
g_free(dir_msg);
-
+
box = pref_group_new(box, TRUE, ud->messages.desc_flist, GTK_ORIENTATION_HORIZONTAL);
ud->listview = file_util_dialog_add_list(box, ud->flist, FALSE, ud->with_sidecars);
fdlg = file_util_file_dlg(ud->messages.title, "dlg_dest_folder", ud->parent,
file_util_fdlg_cancel_cb, ud);
-
+
ud->fdlg = fdlg;
-
+
generic_dialog_add_message(GENERIC_DIALOG(fdlg), NULL, ud->messages.question, NULL);
label = pref_label_new(GENERIC_DIALOG(fdlg)->vbox, _("Choose the destination folder."));
// gtk_tree_view_column_set_visible(column, FALSE);
gtk_tree_view_set_reorderable(GTK_TREE_VIEW(ud->listview), TRUE);
-
+
store = gtk_tree_view_get_model(GTK_TREE_VIEW(ud->listview));
g_signal_connect(G_OBJECT(store), "row_changed",
G_CALLBACK(file_util_rename_preview_order_cb), ud);
ud->notebook = gtk_notebook_new();
-
+
gtk_box_pack_start(GTK_BOX(ud->gd->vbox), ud->notebook, FALSE, FALSE, 0);
gtk_widget_show(ud->notebook);
-
+
page = gtk_vbox_new(FALSE, PREF_PAD_GAP);
gtk_notebook_append_page(GTK_NOTEBOOK(ud->notebook), page, gtk_label_new(_("Manual rename")));
gtk_widget_show(page);
-
+
table = pref_table_new(page, 2, 2, FALSE, FALSE);
pref_table_label(table, 0, 0, _("Original name:"), 1.0);
static void file_util_finalize_all(UtilityData *ud)
{
GList *work = ud->flist;
-
+
if (ud->phase == UTILITY_PHASE_CANCEL) return;
if (ud->phase == UTILITY_PHASE_DONE && !ud->finalize_func) return;
if (ud->phase == UTILITY_PHASE_DISCARD && !ud->discard_func) return;
-
+
while (work)
{
FileData *fd = work->data;
file_data_sc_free_ci(fd);
else
file_data_free_ci(fd);
-
+
file_data_unref(fd);
return TRUE;
}
case UTILITY_PHASE_ENTERING:
file_util_check_ci(ud);
break;
-
+
ud->phase = UTILITY_PHASE_CHECKED;
case UTILITY_PHASE_CHECKED:
file_util_perform_ci(ud);
case UTILITY_PHASE_DISCARD:
file_util_finalize_all(ud);
-
+
/* both DISCARD and DONE finishes the operation for good */
if (ud->done_func)
ud->done_func((ud->phase != UTILITY_PHASE_CANCEL), ud->dest_path, ud->done_data);
-
+
if (ud->with_sidecars)
file_data_sc_free_ci_list(ud->flist);
else
file_data_free_ci_list(ud->flist);
-
+
/* directory content is always handled including sidecars */
file_data_sc_free_ci_list(ud->content_list);
-
+
if (ud->dir_fd) file_data_free_ci(ud->dir_fd);
file_util_data_free(ud);
break;
{
UtilityData *ud = data;
FileData *fd = g_object_get_data(G_OBJECT(gd->dialog), "file_data");
-
+
if (!fd) return;
file_util_exclude_fd(ud, fd);
-
+
if (discard && ud->discard_func) ud->discard_func(fd);
-
+
/* all files were excluded, this has the same effect as pressing the cancel button in the confirmation dialog*/
if (!ud->flist)
{
GString *message = g_string_new("");
gint error;
g_string_append_printf(message, _("File: '%s'\n"), fd->path);
-
+
if (ud->with_sidecars && fd->sidecar_files)
{
GList *work = fd->sidecar_files;
g_string_append(message, _("with sidecar files:\n"));
-
+
while (work)
{
FileData *sfd = work->data;
g_string_append_printf(message, _(" '%s'\n"), sfd->path);
}
}
-
+
g_string_append(message, _("\nStatus: "));
-
+
error = ud->with_sidecars ? file_data_sc_verify_ci(fd) : file_data_verify_ci(fd);
if (error)
GtkWidget *box;
gchar *message;
const gchar *stock_id;
-
+
gd = file_util_gen_dlg(_("File details"), "details", ud->gd->dialog, TRUE, NULL, ud);
generic_dialog_add_button(gd, GTK_STOCK_CLOSE, NULL, file_util_details_dialog_ok_cb, TRUE);
generic_dialog_add_button(gd, GTK_STOCK_REMOVE, _("Exclude file"), file_util_details_dialog_exclude_cb, FALSE);
generic_dialog_add_image(gd, box, fd, NULL, NULL, NULL, FALSE);
gtk_widget_show(gd->dialog);
-
+
g_free(message);
}
gchar *message2;
gint i;
const gchar *stock_id;
-
+
if (fd && fd->modified_xmp)
{
keys = g_hash_table_get_keys(fd->modified_xmp);
}
-
+
g_assert(keys);
-
-
+
+
gd = file_util_gen_dlg(_("Overview of changed metadata"), "details", ud->gd->dialog, TRUE, NULL, ud);
generic_dialog_add_button(gd, GTK_STOCK_CLOSE, NULL, file_util_details_dialog_ok_cb, TRUE);
generic_dialog_add_button(gd, GTK_STOCK_REMOVE, _("Exclude file"), file_util_details_dialog_exclude_cb, FALSE);
gchar *title_f = g_strdup_printf("%s:", title);
gchar *value = metadata_read_string(fd, key, METADATA_FORMATTED);
work = work->next;
-
-
+
+
label = gtk_label_new(title_f);
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.0);
pref_label_bold(label, TRUE, FALSE);
gtk_widget_show(label);
label = gtk_label_new(value);
-
+
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
gtk_table_attach(GTK_TABLE(table), label,
gtk_widget_set_size_request(gd->dialog, DIALOG_WIDTH, -1);
gtk_widget_show(gd->dialog);
-
+
g_list_free(keys);
g_free(message1);
g_free(message2);
{
UtilityData *ud;
GList *ungrouped = NULL;
-
+
if (source_fd)
flist = g_list_append(flist, file_data_ref(source_fd));
if (!flist) return;
-
+
flist = file_data_process_groups_in_selection(flist, TRUE, &ungrouped);
-
+
if (!file_data_sc_add_ci_delete_list(flist))
{
file_util_warn_op_in_progress(_("File deletion failed"));
filelist_free(ungrouped);
return;
}
-
+
file_util_mark_ungrouped_files(ungrouped);
filelist_free(ungrouped);
ud = file_util_data_new(UTILITY_TYPE_DELETE);
-
+
ud->phase = phase;
-
+
ud->with_sidecars = TRUE;
ud->dir_fd = NULL;
ud->flist = flist;
ud->content_list = NULL;
ud->parent = parent;
-
+
ud->details_func = file_util_details_dialog;
ud->messages.title = _("Delete");
static void file_util_write_metadata_full(FileData *source_fd, GList *flist, GtkWidget *parent, UtilityPhase phase, FileUtilDoneFunc done_func, gpointer done_data)
{
UtilityData *ud;
-
+
if (source_fd)
flist = g_list_append(flist, file_data_ref(source_fd));
if (!flist) return;
-
+
if (!file_data_add_ci_write_metadata_list(flist))
{
file_util_warn_op_in_progress(_("Can't write metadata"));
}
ud = file_util_data_new(UTILITY_TYPE_WRITE_METADATA);
-
+
ud->phase = phase;
ud->with_sidecars = FALSE; /* operate on individual files, not groups */
ud->flist = flist;
ud->content_list = NULL;
ud->parent = parent;
-
+
ud->done_func = done_func;
ud->done_data = done_data;
-
+
ud->details_func = file_util_write_metadata_details_dialog;
ud->finalize_func = metadata_write_queue_remove;
ud->discard_func = metadata_write_queue_remove;
-
+
ud->messages.title = _("Write metadata");
ud->messages.question = _("Write metadata?");
ud->messages.desc_flist = _("This will write the changed metadata into the following files");
{
UtilityData *ud;
GList *ungrouped = NULL;
-
+
if (source_fd)
flist = g_list_append(flist, file_data_ref(source_fd));
filelist_free(ungrouped);
return;
}
-
+
file_util_mark_ungrouped_files(ungrouped);
filelist_free(ungrouped);
ud->parent = parent;
if (dest_path) ud->dest_path = g_strdup(dest_path);
-
+
ud->messages.title = _("Move");
ud->messages.question = _("Move files?");
ud->messages.desc_flist = _("This will move the following files");
{
UtilityData *ud;
GList *ungrouped = NULL;
-
+
if (source_fd)
flist = g_list_append(flist, file_data_ref(source_fd));
ud->parent = parent;
if (dest_path) ud->dest_path = g_strdup(dest_path);
-
+
ud->messages.title = _("Copy");
ud->messages.question = _("Copy files?");
ud->messages.desc_flist = _("This will copy the following files");
{
UtilityData *ud;
GList *ungrouped = NULL;
-
+
if (source_fd)
flist = g_list_append(flist, file_data_ref(source_fd));
ud->parent = parent;
ud->details_func = file_util_details_dialog;
-
+
ud->messages.title = _("Rename");
ud->messages.question = _("Rename files?");
ud->messages.desc_flist = _("This will rename the following files");
{
UtilityData *ud;
GList *ungrouped = NULL;
-
+
if (editor_no_param(key))
{
gchar *file_directory = NULL;
file_directory = remove_level_from_path(((FileData *)flist->data)->path);
working_directory = file_directory;
}
-
+
/* just start the editor, don't care about files */
start_editor(key, working_directory);
g_free(file_directory);
filelist_free(flist);
return;
}
-
-
+
+
if (source_fd)
{
/* flist is most probably NULL
}
if (!flist) return;
-
+
if (file_util_write_metadata_first(UTILITY_TYPE_FILTER, phase, flist, dest_path, key, parent))
return;
ud = file_util_data_new(UTILITY_TYPE_FILTER);
else
ud = file_util_data_new(UTILITY_TYPE_EDITOR);
-
-
+
+
/* ask for destination if we don't have it */
if (ud->type == UTILITY_TYPE_FILTER && dest_path == NULL) phase = UTILITY_PHASE_START;
-
+
ud->phase = phase;
ud->with_sidecars = TRUE;
-
+
ud->external_command = g_strdup(key);
ud->dir_fd = NULL;
ud->details_func = file_util_details_dialog;
if (dest_path) ud->dest_path = g_strdup(dest_path);
-
+
ud->messages.title = _("Editor");
ud->messages.question = _("Run editor?");
ud->messages.desc_flist = _("This will copy the following files");
GList *dlist;
GList *flist;
GList *work;
-
+
gboolean ok = TRUE;
DEBUG_1("deltree into: %s", fd->path);
{
ok = file_data_sc_add_ci_delete(ud->dir_fd);
}
-
+
if (!ok)
{
work = ud->content_list;
file_data_sc_free_ci(fd);
}
}
-
+
return ok;
}
ud->flist = NULL;
ud->parent = parent;
-
+
ud->messages.title = _("Delete folder");
ud->messages.question = _("Delete symbolic link?");
ud->messages.desc_flist = "";
ud->flist = flist = filelist_sort_path(flist);
ud->parent = parent;
-
+
ud->messages.title = _("Delete folder");
ud->messages.question = _("Delete folder?");
ud->messages.desc_flist = _("The folder contains these files:");
ud->messages.desc_source_fd = _("This will delete the folder.\n"
"The contents of this folder will also be deleted.");
ud->messages.fail = _("File deletion failed");
-
+
if (!file_util_delete_dir_prepare(ud, flist, dlist))
{
gchar *text;
GList *dlist;
GList *flist;
GList *work;
-
+
gboolean ok = TRUE;
if (!filelist_read_lstat(fd, &flist, &dlist))
gboolean ok;
GList *work;
gint orig_len = strlen(ud->dir_fd->path);
-
+
ok = file_util_rename_dir_scan(ud, ud->dir_fd);
-
+
work = ud->content_list;
-
+
while (ok && work)
{
gchar *np;
fd = work->data;
work = work->next;
-
+
g_assert(strncmp(fd->path, ud->dir_fd->path, orig_len) == 0);
-
+
np = g_strconcat(new_path, fd->path + orig_len, NULL);
-
+
ok = file_data_sc_add_ci_rename(fd, np);
-
+
DEBUG_1("Dir rename: %s -> %s", fd->path, np);
g_free(np);
}
-
+
if (ok)
{
ok = file_data_sc_add_ci_rename(ud->dir_fd, new_path);
}
-
+
if (!ok)
{
work = ud->content_list;
return ok;
}
-
+
static void file_util_rename_dir_full(FileData *fd, const gchar *new_path, GtkWidget *parent, UtilityPhase phase, FileUtilDoneFunc done_func, gpointer done_data)
{
ud->done_func = done_func;
ud->done_data = done_data;
ud->dest_path = g_strdup(new_path);
-
+
ud->messages.title = _("Rename");
ud->messages.question = _("Rename folder?");
ud->messages.desc_flist = _("The folder contains the following files");
ud->dest_path = unique_filename(buf, NULL, " ", FALSE);
g_free(buf);
}
-
+
ud->dir_fd = file_data_new_dir(ud->dest_path);
ud->done_func = done_func;
ud->done_data = done_data;
-
+
ud->messages.title = _("Create Folder");
ud->messages.question = _("Create folder?");
ud->messages.desc_flist = "";
static gboolean file_util_write_metadata_first_after_done(gpointer data)
{
UtilityDelayData *dd = data;
-
+
/* start the delayed operation with original arguments */
switch (dd->type)
{
dd->idle_id = g_idle_add(file_util_write_metadata_first_after_done, dd);
return;
}
-
+
/* the operation was cancelled */
filelist_free(dd->flist);
g_free(dd->dest_path);
{
GList *unsaved = NULL;
UtilityDelayData *dd;
-
+
GList *work;
-
+
work = flist;
while (work)
{
FileData *fd = work->data;
work = work->next;
-
+
if (fd->change)
{
filelist_free(unsaved);
return FALSE; /* another op. in progress, let the caller handle it */
}
-
+
if (fd->modified_xmp) /* has unsaved metadata */
{
unsaved = g_list_prepend(unsaved, file_data_ref(fd));
}
}
-
+
if (!unsaved) return FALSE;
-
+
/* save arguments of the original operation */
-
+
dd = g_new0(UtilityDelayData, 1);
-
+
dd->type = type;
dd->phase = phase;
dd->flist = flist;
dd->dest_path = g_strdup(dest_path);
dd->editor_key = g_strdup(editor_key);
dd->parent = parent;
-
+
file_util_write_metadata(NULL, unsaved, parent, FALSE, file_util_write_metadata_first_done, dd);
return TRUE;
}
GString *new;
clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
-
+
new = g_string_new("");
work = list;
while (work) {
work = work->next;
if (!fd || !*fd->path) continue;
-
+
g_string_append(new, g_shell_quote(fd->path));
if (work) g_string_append_c(new, ' ');
}
-
+
gtk_clipboard_set_text(clipboard, new->str, new->len);
g_string_free(new, TRUE);
filelist_free(list);