/*
* Geeqie
* (C) 2006 John Ellis
- * Copyright (C) 2008 - 2009 The Geeqie Team
+ * Copyright (C) 2008 - 2012 The Geeqie Team
*
* Author: John Ellis
*
#include "metadata.h"
#include "exif.h"
+#define DIALOG_WIDTH 750
+
static GdkPixbuf *file_util_get_error_icon(FileData *fd, GtkWidget *widget);
/*
UTILITY_COLUMN_COUNT
};
+typedef struct _UtilityDelayData UtilityDelayData;
+
+struct _UtilityDelayData {
+ UtilityType type;
+ UtilityPhase phase;
+ GList *flist;
+ gchar *dest_path;
+ gchar *editor_key;
+ GtkWidget *parent;
+ guint idle_id; /* event source id */
+ };
+
+static gboolean file_util_write_metadata_first(UtilityType type, UtilityPhase phase, GList *flist, const gchar *dest_path, const gchar *editor_key, GtkWidget *parent);
+
#define UTILITY_LIST_MIN_WIDTH 250
#define UTILITY_LIST_MIN_HEIGHT 150
scrolled = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_box_pack_start(GTK_BOX(box), scrolled, TRUE, TRUE, 0);
gtk_widget_show(scrolled);
if (full_paths)
{
- file_util_dialog_add_list_column(view, pgettext("filesystem","Location"), FALSE, UTILITY_COLUMN_PATH);
+ file_util_dialog_add_list_column(view, _("Path"), FALSE, UTILITY_COLUMN_PATH);
}
else
{
if (!EDITOR_ERRORS(flags)) /* files were successfully deleted, call the maint functions */
{
- if (ud->with_sidecars)
+ if (ud->with_sidecars)
file_data_sc_apply_ci(fd);
else
file_data_apply_ci(fd);
ud->finalize_func(fd);
}
- if (ud->with_sidecars)
+ if (ud->with_sidecars)
file_data_sc_free_ci(fd);
else
file_data_free_ci(fd);
{
UtilityData *ud = data;
- if (!ud->perform_idle_id)
+ if (!ud->perform_idle_id)
{
/* this function was called directly
just setup idle callback and wait until we are called again
gboolean last = !ud->flist->next;
EditorFlags status = EDITOR_ERROR_STATUS;
- if (ud->with_sidecars ? file_data_sc_perform_ci(single_entry->data)
+ if (ud->with_sidecars ? file_data_sc_perform_ci(single_entry->data)
: file_data_perform_ci(single_entry->data))
status = 0; /* OK */
if (fail)
{
gchar *text;
- GenericDialog *gd;
text = g_strdup_printf("%s:\n\n%s", ud->messages.fail, ud->dir_fd->path);
- gd = file_util_warning_dialog(ud->messages.fail, text, GTK_STOCK_DIALOG_ERROR, NULL);
+ (void) file_util_warning_dialog(ud->messages.fail, text, GTK_STOCK_DIALOG_ERROR, NULL);
g_free(text);
file_data_unref(fail);
else
{
gchar *text;
- GenericDialog *gd;
text = g_strdup_printf("%s:\n\n%s", ud->messages.fail, ud->dir_fd->path);
- gd = file_util_warning_dialog(ud->messages.fail, text, GTK_STOCK_DIALOG_ERROR, NULL);
+ (void) file_util_warning_dialog(ud->messages.fail, text, GTK_STOCK_DIALOG_ERROR, NULL);
g_free(text);
}
}
else
{
- flags = start_editor_from_filelist_full(ud->external_command, ud->flist, file_util_perform_ci_cb, ud);
+ if (editor_blocks_file(ud->external_command))
+ {
+ DEBUG_1("Starting %s and waiting for results", ud->external_command);
+ flags = start_editor_from_filelist_full(ud->external_command, ud->flist, NULL, file_util_perform_ci_cb, ud);
+ }
+ else
+ {
+ /* start the editor without callback and finish the operation internally */
+ DEBUG_1("Starting %s and finishing the operation", ud->external_command);
+ flags = start_editor_from_filelist(ud->external_command, ud->flist);
+ file_util_perform_ci_internal(ud);
+ }
}
- if (flags)
+ if (EDITOR_ERRORS(flags))
{
gchar *text = g_strdup_printf(_("%s\nUnable to start external command.\n"), editor_get_error_str(flags));
file_util_warning_dialog(ud->messages.fail, text, GTK_STOCK_DIALOG_ERROR, NULL);
gint error = CHANGE_OK;
gchar *desc = NULL;
- if (ud->type != UTILITY_TYPE_CREATE_FOLDER)
+ if (ud->type != UTILITY_TYPE_CREATE_FOLDER &&
+ ud->type != UTILITY_TYPE_RENAME_FOLDER)
{
if (ud->dest_path && !isdir(ud->dest_path))
{
break;
case UTILITY_TYPE_CREATE_FOLDER:
file_data_unref(ud->dir_fd);
- ud->dir_fd = file_data_new_simple(ud->dest_path);
+ ud->dir_fd = file_data_new_dir(ud->dest_path);
break;
case UTILITY_TYPE_DELETE:
case UTILITY_TYPE_DELETE_LINK:
file_util_warning_dialog(title, _("Another operation in progress.\n"), GTK_STOCK_DIALOG_ERROR, NULL);
}
-static void file_util_disable_grouping_sc_list(GList *list)
-{
- GList *work = list;
-
- while (work)
- {
- FileData *fd = work->data;
- work = work->next;
-
- if (fd->parent) file_data_disable_grouping(fd, TRUE);
- }
-
-}
-
static void file_util_details_dialog_close_cb(GtkWidget *widget, gpointer data)
{
gtk_widget_destroy(data);
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)
+ if (!ud->flist)
{
/* both dialogs will be closed anyway, the signals would cause duplicate calls */
g_signal_handlers_disconnect_by_func(ud->gd->dialog, G_CALLBACK(file_util_details_dialog_close_cb), gd->dialog);
GtkWidget *box;
GtkWidget *table;
GtkWidget *frame;
+ GtkWidget *label;
GList *keys = NULL;
GList *work;
gchar *message1;
if (fd->change && fd->change->dest)
{
- message2 = g_strdup_printf(_("The following metadata tags will be written to '%s'."), fd->change->dest);
+ message2 = g_strdup_printf(_("The following metadata tags will be written to\n'%s'."), fd->change->dest);
}
else
{
i = 0;
while (work)
{
- GtkWidget *label;
const gchar *key = work->data;
gchar *title = exif_get_description_by_key(key);
gchar *title_f = g_strdup_printf("%s:", title);
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,
1, 2, i, i + 1,
GTK_FILL, GTK_FILL,
generic_dialog_add_image(gd, box, fd, NULL, NULL, NULL, FALSE);
+ gtk_widget_set_size_request(gd->dialog, DIALOG_WIDTH, -1);
gtk_widget_show(gd->dialog);
g_list_free(keys);
g_free(message2);
}
-static void file_util_delete_full(FileData *source_fd, GList *source_list, GtkWidget *parent, UtilityPhase phase)
+
+static void file_util_mark_ungrouped_files(GList *work)
+{
+ while (work)
+ {
+ FileData *fd = work->data;
+ file_data_set_regroup_when_finished(fd, TRUE);
+ work = work->next;
+ }
+}
+
+
+static void file_util_delete_full(FileData *source_fd, GList *flist, GtkWidget *parent, UtilityPhase phase)
{
UtilityData *ud;
- GList *flist = filelist_copy(source_list);
+ GList *ungrouped = NULL;
if (source_fd)
flist = g_list_append(flist, file_data_ref(source_fd));
if (!flist) return;
- file_util_disable_grouping_sc_list(flist);
+ 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"));
+ file_data_disable_grouping_list(ungrouped, FALSE);
filelist_free(flist);
+ filelist_free(ungrouped);
return;
}
+
+ file_util_mark_ungrouped_files(ungrouped);
+ filelist_free(ungrouped);
ud = file_util_data_new(UTILITY_TYPE_DELETE);
ud->details_func = file_util_details_dialog;
- ud->messages.title = (gchar *)pgettext("physical","Delete");
+ ud->messages.title = _("Delete");
ud->messages.question = _("Delete files?");
ud->messages.desc_flist = _("This will delete the following files");
ud->messages.desc_source_fd = "";
}
-static void file_util_write_metadata_full(FileData *source_fd, GList *source_list, GtkWidget *parent, UtilityPhase phase, FileUtilDoneFunc done_func, gpointer done_data)
+static void file_util_write_metadata_full(FileData *source_fd, GList *flist, GtkWidget *parent, UtilityPhase phase, FileUtilDoneFunc done_func, gpointer done_data)
{
UtilityData *ud;
- GList *flist = filelist_copy(source_list);
if (source_fd)
flist = g_list_append(flist, file_data_ref(source_fd));
ud->messages.question = _("Write metadata?");
ud->messages.desc_flist = _("This will write the changed metadata into the following files");
ud->messages.desc_source_fd = "";
- ud->messages.fail = _("Metadata writting failed");
+ ud->messages.fail = _("Metadata writing failed");
file_util_dialog_run(ud);
}
-
-static void file_util_move_full(FileData *source_fd, GList *source_list, const gchar *dest_path, GtkWidget *parent, UtilityPhase phase)
+static void file_util_move_full(FileData *source_fd, GList *flist, const gchar *dest_path, GtkWidget *parent, UtilityPhase phase)
{
UtilityData *ud;
- GList *flist = filelist_copy(source_list);
+ GList *ungrouped = NULL;
if (source_fd)
flist = g_list_append(flist, file_data_ref(source_fd));
if (!flist) return;
- file_util_disable_grouping_sc_list(flist);
+ flist = file_data_process_groups_in_selection(flist, TRUE, &ungrouped);
if (!file_data_sc_add_ci_move_list(flist, dest_path))
{
file_util_warn_op_in_progress(_("Move failed"));
+ file_data_disable_grouping_list(ungrouped, FALSE);
filelist_free(flist);
+ filelist_free(ungrouped);
return;
}
+
+ file_util_mark_ungrouped_files(ungrouped);
+ filelist_free(ungrouped);
ud = file_util_data_new(UTILITY_TYPE_MOVE);
file_util_dialog_run(ud);
}
-static void file_util_copy_full(FileData *source_fd, GList *source_list, const gchar *dest_path, GtkWidget *parent, UtilityPhase phase)
+static void file_util_copy_full(FileData *source_fd, GList *flist, const gchar *dest_path, GtkWidget *parent, UtilityPhase phase)
{
UtilityData *ud;
- GList *flist = filelist_copy(source_list);
+ GList *ungrouped = NULL;
if (source_fd)
flist = g_list_append(flist, file_data_ref(source_fd));
if (!flist) return;
- file_util_disable_grouping_sc_list(flist);
+ if (file_util_write_metadata_first(UTILITY_TYPE_COPY, phase, flist, dest_path, NULL, parent))
+ return;
+
+ flist = file_data_process_groups_in_selection(flist, TRUE, &ungrouped);
if (!file_data_sc_add_ci_copy_list(flist, dest_path))
{
file_util_warn_op_in_progress(_("Copy failed"));
+ file_data_disable_grouping_list(ungrouped, FALSE);
filelist_free(flist);
+ filelist_free(ungrouped);
return;
}
+ file_util_mark_ungrouped_files(ungrouped);
+ filelist_free(ungrouped);
+
ud = file_util_data_new(UTILITY_TYPE_COPY);
ud->phase = phase;
file_util_dialog_run(ud);
}
-static void file_util_rename_full(FileData *source_fd, GList *source_list, const gchar *dest_path, GtkWidget *parent, UtilityPhase phase)
+static void file_util_rename_full(FileData *source_fd, GList *flist, const gchar *dest_path, GtkWidget *parent, UtilityPhase phase)
{
UtilityData *ud;
- GList *flist = filelist_copy(source_list);
+ GList *ungrouped = NULL;
if (source_fd)
flist = g_list_append(flist, file_data_ref(source_fd));
if (!flist) return;
- file_util_disable_grouping_sc_list(flist);
+ flist = file_data_process_groups_in_selection(flist, TRUE, &ungrouped);
if (!file_data_sc_add_ci_rename_list(flist, dest_path))
{
file_util_warn_op_in_progress(_("Rename failed"));
+ file_data_disable_grouping_list(ungrouped, FALSE);
filelist_free(flist);
+ filelist_free(ungrouped);
return;
}
+ file_util_mark_ungrouped_files(ungrouped);
+ filelist_free(ungrouped);
+
ud = file_util_data_new(UTILITY_TYPE_RENAME);
ud->phase = phase;
file_util_dialog_run(ud);
}
-static void file_util_start_editor_full(const gchar *key, FileData *source_fd, GList *source_list, const gchar *dest_path, GtkWidget *parent, UtilityPhase phase)
+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)
{
UtilityData *ud;
- GList *flist = filelist_copy(source_list);
+ GList *ungrouped = NULL;
+
+ if (editor_no_param(key))
+ {
+ gchar *file_directory = NULL;
+ if (!working_directory)
+ {
+ /* working directory was not specified, try to extract it from the files */
+ if (source_fd)
+ file_directory = remove_level_from_path(source_fd->path);
+
+ if (!file_directory && flist)
+ 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
+ operate on source_fd and it's sidecars
+ */
+ flist = g_list_concat(filelist_copy(source_fd->sidecar_files), flist);
flist = g_list_append(flist, file_data_ref(source_fd));
+ }
if (!flist) return;
+
+ if (file_util_write_metadata_first(UTILITY_TYPE_FILTER, phase, flist, dest_path, key, parent))
+ return;
- file_util_disable_grouping_sc_list(flist);
+ flist = file_data_process_groups_in_selection(flist, TRUE, &ungrouped);
if (!file_data_sc_add_ci_unspecified_list(flist, dest_path))
{
file_util_warn_op_in_progress(_("Can't run external editor"));
+ file_data_disable_grouping_list(ungrouped, FALSE);
filelist_free(flist);
+ filelist_free(ungrouped);
return;
}
+ file_util_mark_ungrouped_files(ungrouped);
+ filelist_free(ungrouped);
+
if (editor_is_filter(key))
ud = file_util_data_new(UTILITY_TYPE_FILTER);
else
}
-static void file_util_rename_dir_full(FileData *fd, const gchar *new_path, GtkWidget *parent, UtilityPhase phase)
+static void file_util_rename_dir_full(FileData *fd, const gchar *new_path, GtkWidget *parent, UtilityPhase phase, FileUtilDoneFunc done_func, gpointer done_data)
{
UtilityData *ud;
ud = file_util_data_new(UTILITY_TYPE_RENAME_FOLDER);
ud->phase = phase;
- ud->with_sidecars = TRUE; /* does not matter, the directory should not have sidecars
+ ud->with_sidecars = TRUE; /* does not matter, the directory should not have sidecars
and the content must be handled including sidecars */
ud->dir_fd = file_data_ref(fd);
ud->flist = NULL;
ud->content_list = NULL;
ud->parent = parent;
+
+ 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?");
static void file_util_create_dir_full(FileData *fd, const gchar *dest_path, GtkWidget *parent, UtilityPhase phase, FileUtilDoneFunc done_func, gpointer done_data)
{
- UtilityData *ud;
+ UtilityData *ud;
ud = file_util_data_new(UTILITY_TYPE_CREATE_FOLDER);
g_free(buf);
}
- ud->dir_fd = file_data_new_simple(ud->dest_path);
+ ud->dir_fd = file_data_new_dir(ud->dest_path);
ud->done_func = done_func;
ud->done_data = done_data;
}
+static gboolean file_util_write_metadata_first_after_done(gpointer data)
+{
+ UtilityDelayData *dd = data;
+
+ /* start the delayed operation with original arguments */
+ switch (dd->type)
+ {
+ case UTILITY_TYPE_FILTER:
+ case UTILITY_TYPE_EDITOR:
+ file_util_start_editor_full(dd->editor_key, NULL, dd->flist, dd->dest_path, NULL, dd->parent, dd->phase);
+ break;
+ case UTILITY_TYPE_COPY:
+ file_util_copy_full(NULL, dd->flist, dd->dest_path, dd->parent, dd->phase);
+ break;
+ default:
+ g_warning("unsupported type");
+ }
+ g_free(dd->dest_path);
+ g_free(dd->editor_key);
+ g_free(dd);
+ return FALSE;
+}
+
+static void file_util_write_metadata_first_done(gboolean success, const gchar *done_path, gpointer data)
+{
+ UtilityDelayData *dd = data;
+
+ if (success)
+ {
+ 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);
+ g_free(dd->editor_key);
+ g_free(dd);
+}
+
+static gboolean file_util_write_metadata_first(UtilityType type, UtilityPhase phase, GList *flist, const gchar *dest_path, const gchar *editor_key, GtkWidget *parent)
+{
+ 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;
+}
+
+
/* full-featured entry points
*/
file_util_delete_full(source_fd, source_list, parent, options->file_ops.confirm_delete ? UTILITY_PHASE_START : UTILITY_PHASE_ENTERING);
}
-void file_util_write_metadata(FileData *source_fd, GList *source_list, GtkWidget *parent, FileUtilDoneFunc done_func, gpointer done_data)
+void file_util_write_metadata(FileData *source_fd, GList *source_list, GtkWidget *parent, gboolean force_dialog, FileUtilDoneFunc done_func, gpointer done_data)
{
- file_util_write_metadata_full(source_fd, source_list, parent,
- (options->metadata.save_in_image_file && options->metadata.confirm_write) ? UTILITY_PHASE_START : UTILITY_PHASE_ENTERING,
+ file_util_write_metadata_full(source_fd, source_list, parent,
+ ((options->metadata.save_in_image_file && options->metadata.confirm_write) || force_dialog) ? UTILITY_PHASE_START : UTILITY_PHASE_ENTERING,
done_func, done_data);
}
void file_util_start_editor_from_file(const gchar *key, FileData *fd, GtkWidget *parent)
{
- file_util_start_editor_full(key, fd, NULL, NULL, parent, UTILITY_PHASE_ENTERING);
+ file_util_start_editor_full(key, fd, NULL, NULL, NULL, parent, UTILITY_PHASE_ENTERING);
}
-void file_util_start_editor_from_filelist(const gchar *key, GList *list, GtkWidget *parent)
+void file_util_start_editor_from_filelist(const gchar *key, GList *list, const gchar *working_directory, GtkWidget *parent)
{
- file_util_start_editor_full(key, NULL, list, NULL, parent, UTILITY_PHASE_ENTERING);
+ file_util_start_editor_full(key, NULL, list, NULL, working_directory, parent, UTILITY_PHASE_ENTERING);
}
void file_util_start_filter_from_file(const gchar *key, FileData *fd, const gchar *dest_path, GtkWidget *parent)
{
- file_util_start_editor_full(key, fd, NULL, dest_path, parent, UTILITY_PHASE_ENTERING);
+ file_util_start_editor_full(key, fd, NULL, dest_path, NULL, parent, UTILITY_PHASE_ENTERING);
}
void file_util_start_filter_from_filelist(const gchar *key, GList *list, const gchar *dest_path, GtkWidget *parent)
{
- file_util_start_editor_full(key, NULL, list, dest_path, parent, UTILITY_PHASE_ENTERING);
+ file_util_start_editor_full(key, NULL, list, dest_path, NULL, parent, UTILITY_PHASE_ENTERING);
}
void file_util_delete_dir(FileData *fd, GtkWidget *parent)
file_util_create_dir_full(dir_fd, NULL, parent, UTILITY_PHASE_ENTERING, done_func, done_data);
}
-void file_util_rename_dir(FileData *source_fd, const gchar *new_path, GtkWidget *parent)
+void file_util_rename_dir(FileData *source_fd, const gchar *new_path, GtkWidget *parent, FileUtilDoneFunc done_func, gpointer done_data)
{
- file_util_rename_dir_full(source_fd, new_path, parent, UTILITY_PHASE_ENTERING);
+ file_util_rename_dir_full(source_fd, new_path, parent, UTILITY_PHASE_ENTERING, done_func, done_data);
}
gtk_clipboard_set_text(clipboard, new->str, new->len);
g_string_free(new, TRUE);
+ filelist_free(list);
}
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */