[gthumb/ext: 69/79] Ask whether to overwrite a file during a copy operation
- From: Paolo Bacchilega <paobac src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gthumb/ext: 69/79] Ask whether to overwrite a file during a copy operation
- Date: Sun, 2 Aug 2009 20:31:58 +0000 (UTC)
commit 86bf640eaa1d7b3a3c1566669c1dac2d9ff8547e
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sat Jul 25 11:23:11 2009 +0200
Ask whether to overwrite a file during a copy operation
data/ui/overwrite-dialog.ui | 109 +++++++++++++++++++++++++++++++++++++++-
gthumb/gio-utils.c | 113 +++++++++++++++++++++++++++++++++++------
gthumb/gth-main.c | 5 ++-
gthumb/gth-overwrite-dialog.c | 32 ++++++------
4 files changed, 227 insertions(+), 32 deletions(-)
---
diff --git a/data/ui/overwrite-dialog.ui b/data/ui/overwrite-dialog.ui
index 0bdb162..483a77b 100644
--- a/data/ui/overwrite-dialog.ui
+++ b/data/ui/overwrite-dialog.ui
@@ -74,6 +74,7 @@
<object class="GtkTable" id="table15">
<property name="visible">True</property>
<property name="n_rows">3</property>
+ <property name="n_columns">2</property>
<property name="column_spacing">12</property>
<property name="row_spacing">6</property>
<child>
@@ -82,6 +83,8 @@
<property name="xalign">0</property>
</object>
<packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options"></property>
@@ -93,6 +96,8 @@
<property name="xalign">0</property>
</object>
<packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="y_options"></property>
@@ -110,10 +115,55 @@
</child>
</object>
<packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Filename:</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="x_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Size:</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label3">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Modified:</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options">GTK_FILL</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
@@ -171,6 +221,7 @@
<object class="GtkTable" id="table16">
<property name="visible">True</property>
<property name="n_rows">3</property>
+ <property name="n_columns">2</property>
<property name="column_spacing">12</property>
<property name="row_spacing">6</property>
<child>
@@ -179,6 +230,8 @@
<property name="xalign">0</property>
</object>
<packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options"></property>
@@ -190,6 +243,8 @@
<property name="xalign">0</property>
</object>
<packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="y_options"></property>
@@ -207,10 +262,55 @@
</child>
</object>
<packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
+ <child>
+ <object class="GtkLabel" id="label4">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Filename:</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="x_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label5">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Size:</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label6">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Modified:</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options">GTK_FILL</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
@@ -229,8 +329,15 @@
</packing>
</child>
<child>
- <object class="GtkHSeparator" id="hseparator1">
+ <object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
+ <property name="top_padding">6</property>
+ <property name="bottom_padding">6</property>
+ <child>
+ <object class="GtkHSeparator" id="hseparator1">
+ <property name="visible">True</property>
+ </object>
+ </child>
</object>
<packing>
<property name="expand">False</property>
diff --git a/gthumb/gio-utils.c b/gthumb/gio-utils.c
index 5032e2f..c50a044 100644
--- a/gthumb/gio-utils.c
+++ b/gthumb/gio-utils.c
@@ -26,6 +26,7 @@
#include <gio/gio.h>
#include "gth-file-data.h"
#include "gth-hook.h"
+#include "gth-overwrite-dialog.h"
#include "glib-utils.h"
#include "gio-utils.h"
@@ -1010,6 +1011,7 @@ typedef struct {
gsize copied_files;
char *message;
+ int default_response;
gboolean move;
GFileCopyFlags flags;
@@ -1176,6 +1178,54 @@ copy_data__copy_current_sidecar (CopyData *copy_data)
}
+static void copy_data__copy_current_file_to_destination (CopyData *copy_data, GFile *destination, GFileCopyFlags flags);
+
+
+static void
+overwrite_dialog_response_cb (GtkDialog *dialog,
+ int response_id,
+ gpointer user_data)
+{
+ CopyData *copy_data = user_data;
+
+ if (response_id != GTK_RESPONSE_OK)
+ copy_data->default_response = GTH_OVERWRITE_RESPONSE_UNSPECIFIED;
+ else
+ copy_data->default_response = gth_overwrite_dialog_get_response (GTH_OVERWRITE_DIALOG (dialog));
+
+ gtk_widget_hide (GTK_WIDGET (dialog));
+
+ switch (copy_data->default_response) {
+ case GTH_OVERWRITE_RESPONSE_NO:
+ case GTH_OVERWRITE_RESPONSE_ALWAYS_NO:
+ case GTH_OVERWRITE_RESPONSE_UNSPECIFIED:
+ copy_data__copy_next_file (copy_data);
+ break;
+
+ case GTH_OVERWRITE_RESPONSE_YES:
+ case GTH_OVERWRITE_RESPONSE_ALWAYS_YES:
+ copy_data__copy_current_file_to_destination (copy_data, copy_data->current_destination, G_FILE_COPY_OVERWRITE);
+ break;
+
+ case GTH_OVERWRITE_RESPONSE_RENAME:
+ {
+ GFile *parent;
+ GFile *new_destination;
+
+ parent = g_file_get_parent (copy_data->current_destination);
+ new_destination = g_file_get_child_for_display_name (parent, gth_overwrite_dialog_get_filename (GTH_OVERWRITE_DIALOG (dialog)), NULL);
+ copy_data__copy_current_file_to_destination (copy_data, new_destination, 0);
+
+ g_object_unref (new_destination);
+ g_object_unref (parent);
+ }
+ break;
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+
static void
copy_data__copy_current_file_ready_cb (GObject *source_object,
GAsyncResult *result,
@@ -1185,13 +1235,29 @@ copy_data__copy_current_file_ready_cb (GObject *source_object,
GError *error = NULL;
GthFileData *source;
+ source = (GthFileData *) copy_data->current->data;
+
if (! g_file_copy_finish ((GFile *) source_object, result, &error)) {
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
+ GtkWidget *dialog;
+
+ dialog = gth_overwrite_dialog_new (source->file,
+ copy_data->current_destination,
+ copy_data->default_response,
+ copy_data->tot_files == 1);
+ g_signal_connect (dialog,
+ "response",
+ G_CALLBACK (overwrite_dialog_response_cb),
+ copy_data);
+ gtk_widget_show (dialog);
+
+ return;
+ }
copy_data->done_callback (error, copy_data->user_data);
copy_data_free (copy_data);
return;
}
- source = (GthFileData *) copy_data->current->data;
if (g_hash_table_lookup (copy_data->source_hash, source->file) == NULL) {
copy_data__copy_next_file (copy_data);
return;
@@ -1231,7 +1297,7 @@ copy_data__copy_current_file_progress_cb (goffset current_num_bytes,
s1 = g_format_size_for_display (copy_data->copied_size + current_num_bytes);
s2 = g_format_size_for_display (copy_data->tot_size);
- /* This is a progress size indicator, for example: 230.4 MB of 512.8 MB */
+ /* For translators: This is a progress size indicator, for example: 230.4 MB of 512.8 MB */
details = g_strdup_printf (_("%s of %s"), s1, s2);
copy_data->progress_callback (NULL,
@@ -1248,23 +1314,17 @@ copy_data__copy_current_file_progress_cb (goffset current_num_bytes,
static void
-copy_data__copy_current_file (CopyData *copy_data)
+copy_data__copy_current_file_to_destination (CopyData *copy_data,
+ GFile *destination,
+ GFileCopyFlags flags)
{
GthFileData *source;
- if (copy_data->current == NULL) {
- copy_data__delete_source (copy_data);
- return;
- }
+ source = (GthFileData *) copy_data->current->data;
+ _g_object_ref (destination);
_g_object_unref (copy_data->current_destination);
-
- source = (GthFileData *) copy_data->current->data;
- if (g_hash_table_lookup (copy_data->source_hash, source->file) != NULL) {
- _g_object_unref (copy_data->source_base);
- copy_data->source_base = g_file_get_parent (source->file);
- }
- copy_data->current_destination = get_destination_file (source->file, copy_data->source_base, copy_data->destination);
+ copy_data->current_destination = destination;
if (copy_data->progress_callback != NULL) {
GFile *destination_parent;
@@ -1296,7 +1356,7 @@ copy_data__copy_current_file (CopyData *copy_data)
else
g_file_copy_async (source->file,
copy_data->current_destination,
- copy_data->flags,
+ copy_data->flags | flags,
copy_data->io_priority,
copy_data->cancellable,
copy_data__copy_current_file_progress_cb,
@@ -1307,6 +1367,29 @@ copy_data__copy_current_file (CopyData *copy_data)
static void
+copy_data__copy_current_file (CopyData *copy_data)
+{
+ GthFileData *source;
+ GFile *destination;
+
+ if (copy_data->current == NULL) {
+ copy_data__delete_source (copy_data);
+ return;
+ }
+
+ source = (GthFileData *) copy_data->current->data;
+ if (g_hash_table_lookup (copy_data->source_hash, source->file) != NULL) {
+ _g_object_unref (copy_data->source_base);
+ copy_data->source_base = g_file_get_parent (source->file);
+ }
+ destination = get_destination_file (source->file, copy_data->source_base, copy_data->destination);
+ copy_data__copy_current_file_to_destination (copy_data, destination, 0);
+
+ g_object_unref (destination);
+}
+
+
+static void
copy_files__sources_info_ready_cb (GList *files,
GError *error,
gpointer user_data)
diff --git a/gthumb/gth-main.c b/gthumb/gth-main.c
index 8fff5ce..0a09452 100644
--- a/gthumb/gth-main.c
+++ b/gthumb/gth-main.c
@@ -728,7 +728,10 @@ gth_main_register_file_loader (FileLoader loader,
FileLoader
gth_main_get_file_loader (const char *mime_type)
{
- return (FileLoader) g_hash_table_lookup (Main->priv->loaders, mime_type);
+ if (mime_type != NULL)
+ return (FileLoader) g_hash_table_lookup (Main->priv->loaders, mime_type);
+ else
+ return NULL;
}
diff --git a/gthumb/gth-overwrite-dialog.c b/gthumb/gth-overwrite-dialog.c
index 89f9990..43f226b 100644
--- a/gthumb/gth-overwrite-dialog.c
+++ b/gthumb/gth-overwrite-dialog.c
@@ -33,11 +33,11 @@ static gpointer gth_overwrite_dialog_parent_class = NULL;
struct _GthOverwriteDialogPrivate {
- GtkBuilder *builder;
- GFile *source;
- GFile *destination;
- GtkWidget *old_image_viewer;
- GtkWidget *new_image_viewer;
+ GtkBuilder *builder;
+ GFile *source;
+ GFile *destination;
+ GtkWidget *old_image_viewer;
+ GtkWidget *new_image_viewer;
};
@@ -119,44 +119,46 @@ info_ready_cb (GList *files,
return;
}
- /* source */
+ /* new image */
source = files->data;
- gtk_label_set_text (GTK_LABEL (_gtk_builder_get_widget (self->priv->builder, "old_image_filename_label")), g_file_info_get_display_name (source->info));
+ gtk_label_set_text (GTK_LABEL (_gtk_builder_get_widget (self->priv->builder, "new_image_filename_label")), g_file_info_get_display_name (source->info));
text = g_format_size_for_display (g_file_info_get_size (source->info));
- gtk_label_set_text (GTK_LABEL (_gtk_builder_get_widget (self->priv->builder, "old_image_size_label")), text);
+ gtk_label_set_text (GTK_LABEL (_gtk_builder_get_widget (self->priv->builder, "new_image_size_label")), text);
g_free (text);
timeval = gth_file_data_get_modification_time (source);
text = _g_time_val_to_exif_date (timeval);
- gtk_label_set_text (GTK_LABEL (_gtk_builder_get_widget (self->priv->builder, "old_image_time_label")), text);
+ gtk_label_set_text (GTK_LABEL (_gtk_builder_get_widget (self->priv->builder, "new_image_time_label")), text);
g_free (text);
icon = (GIcon*) g_file_info_get_attribute_object (source->info, "preview::icon");
pixbuf = _g_icon_get_pixbuf (icon, 256, gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (self))));
if (pixbuf != NULL) {
- gth_image_viewer_set_pixbuf (GTH_IMAGE_VIEWER (self->priv->old_image_viewer), pixbuf);
+ gth_image_viewer_set_pixbuf (GTH_IMAGE_VIEWER (self->priv->new_image_viewer), pixbuf);
g_object_unref (pixbuf);
}
- /* destination */
+ gth_image_viewer_load (GTH_IMAGE_VIEWER (self->priv->new_image_viewer), source);
+
+ /* old image */
destination = files->next->data;
- gtk_label_set_text (GTK_LABEL (_gtk_builder_get_widget (self->priv->builder, "new_image_filename_label")), g_file_info_get_display_name (destination->info));
+ gtk_label_set_text (GTK_LABEL (_gtk_builder_get_widget (self->priv->builder, "old_image_filename_label")), g_file_info_get_display_name (destination->info));
text = g_format_size_for_display (g_file_info_get_size (destination->info));
- gtk_label_set_text (GTK_LABEL (_gtk_builder_get_widget (self->priv->builder, "new_image_size_label")), text);
+ gtk_label_set_text (GTK_LABEL (_gtk_builder_get_widget (self->priv->builder, "old_image_size_label")), text);
g_free (text);
timeval = gth_file_data_get_modification_time (destination);
text = _g_time_val_to_exif_date (timeval);
- gtk_label_set_text (GTK_LABEL (_gtk_builder_get_widget (self->priv->builder, "new_image_time_label")), text);
+ gtk_label_set_text (GTK_LABEL (_gtk_builder_get_widget (self->priv->builder, "old_image_time_label")), text);
g_free (text);
- /**/
+ gth_image_viewer_load (GTH_IMAGE_VIEWER (self->priv->old_image_viewer), destination);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]