[gthumb] Implemented the confirm deletion option



commit 8cbde58ed702e762c37b8b34f82cc6ea5ce36521
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Tue Jun 22 16:17:38 2010 +0200

    Implemented the confirm deletion option
    
    [bug #622386]

 data/gthumb.schemas.in            |   26 ++++++------
 extensions/catalogs/actions.c     |   61 ++++++++++++++++++++++++----
 extensions/file_manager/actions.c |   81 +++++++++++++++++++++++++++++++------
 gthumb/dlg-preferences.c          |   13 ++++++
 gthumb/gth-preferences.h          |    3 +-
 5 files changed, 149 insertions(+), 35 deletions(-)
---
diff --git a/data/gthumb.schemas.in b/data/gthumb.schemas.in
index 3986bc6..46a73be 100644
--- a/data/gthumb.schemas.in
+++ b/data/gthumb.schemas.in
@@ -177,19 +177,6 @@
       </schema>
 
       <schema>
-	<key>/schemas/apps/gthumb/browser/confirm_deletion</key>
-	<applyto>/apps/gthumb/browser/confirm_deletion</applyto>
-	<owner>gthumb</owner>
-	<type>bool</type>
-	<default>true</default>
-	<locale name="C">
-	  <short></short>
-	  <long>
-	  </long>
-	</locale>
-      </schema>
-
-      <schema>
 	<key>/schemas/apps/gthumb/browser/sort_type</key>
 	<applyto>/apps/gthumb/browser/sort_type</applyto>
 	<owner>gthumb</owner>
@@ -506,6 +493,19 @@
       </schema>
 
       <schema>
+	<key>/schemas/apps/gthumb/dialogs/messages/confirm_deletion</key>
+	<applyto>/apps/gthumb/dialogs/messages/confirm_deletion</applyto>
+	<owner>gthumb</owner>
+	<type>bool</type>
+	<default>true</default>
+	<locale name="C">
+	  <short></short>
+	  <long>
+	  </long>
+	</locale>
+      </schema>
+
+      <schema>
 	<key>/schemas/apps/gthumb/dialogs/add_to_catalog/view</key>
 	<applyto>/apps/gthumb/general/add_to_catalog/view</applyto>
 	<owner>gthumb</owner>
diff --git a/extensions/catalogs/actions.c b/extensions/catalogs/actions.c
index e24edc9..edfc170 100644
--- a/extensions/catalogs/actions.c
+++ b/extensions/catalogs/actions.c
@@ -305,15 +305,13 @@ gth_browser_activate_action_catalog_new_library (GtkAction  *action,
 }
 
 
-void
-gth_browser_activate_action_catalog_remove (GtkAction  *action,
-					    GthBrowser *browser)
+static void
+remove_catalog (GtkWindow   *window,
+		GthFileData *file_data)
 {
-	GthFileData *file_data;
-	GFile       *gio_file;
-	GError      *error = NULL;
+	GFile  *gio_file;
+	GError *error = NULL;
 
-	file_data = gth_browser_get_folder_popup_file_data (browser);
 	gio_file = gth_main_get_gio_file (file_data->file);
 	if (g_file_delete (gio_file, NULL, &error)) {
 		GFile *parent;
@@ -330,16 +328,63 @@ gth_browser_activate_action_catalog_remove (GtkAction  *action,
 		_g_object_unref (parent);
 	}
 	else
-		_gtk_error_dialog_from_gerror_show (GTK_WINDOW (browser),
+		_gtk_error_dialog_from_gerror_show (window,
 						    _("Could not remove the catalog"),
 						    &error);
 
 	g_object_unref (gio_file);
+}
+
+
+static void
+remove_catalog_response_cb (GtkDialog *dialog,
+			    int        response_id,
+			    gpointer   user_data)
+{
+	GthFileData *file_data = user_data;
+
+	if (response_id == GTK_RESPONSE_YES)
+		remove_catalog (gtk_window_get_transient_for (GTK_WINDOW (dialog)), file_data);
+
+	gtk_widget_destroy (GTK_WIDGET (dialog));
 	g_object_unref (file_data);
 }
 
 
 void
+gth_browser_activate_action_catalog_remove (GtkAction  *action,
+					    GthBrowser *browser)
+{
+	GthFileData *file_data;
+
+	file_data = gth_browser_get_folder_popup_file_data (browser);
+
+	if (eel_gconf_get_boolean (PREF_MSG_CONFIRM_DELETION, DEFAULT_MSG_CONFIRM_DELETION)) {
+		char      *prompt;
+		GtkWidget *d;
+
+		prompt = g_strdup_printf (_("Are you sure you want to remove \"%s\"?"), g_file_info_get_display_name (file_data->info));
+		d = _gtk_message_dialog_new (GTK_WINDOW (browser),
+					     GTK_DIALOG_MODAL,
+					     GTK_STOCK_DIALOG_QUESTION,
+					     prompt,
+					     NULL,
+					     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+					     GTK_STOCK_REMOVE, GTK_RESPONSE_YES,
+					     NULL);
+		g_signal_connect (d, "response", G_CALLBACK (remove_catalog_response_cb), file_data);
+		gtk_widget_show (d);
+
+		g_free (prompt);
+	}
+	else {
+		remove_catalog (GTK_WINDOW (browser), file_data);
+		g_object_unref (file_data);
+	}
+}
+
+
+void
 gth_browser_activate_action_catalog_rename (GtkAction  *action,
 					    GthBrowser *browser)
 {
diff --git a/extensions/file_manager/actions.c b/extensions/file_manager/actions.c
index d279607..0659edc 100644
--- a/extensions/file_manager/actions.c
+++ b/extensions/file_manager/actions.c
@@ -415,18 +415,13 @@ delete_permanently_response_cb (GtkDialog *dialog,
 }
 
 
-void
-gth_browser_activate_action_edit_trash (GtkAction  *action,
-					GthBrowser *browser)
+static void
+trash_files (GtkWindow *window,
+	     GList     *file_list)
 {
-	GList    *items;
-	GList    *file_list = NULL;
 	GList    *scan;
-	GError   *error = NULL;
 	gboolean  moved_to_trash = TRUE;
-
-	items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
-	file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
+	GError   *error = NULL;
 
 	for (scan = file_list; scan; scan = scan->next) {
 		GthFileData *file_data = scan->data;
@@ -438,7 +433,7 @@ gth_browser_activate_action_edit_trash (GtkAction  *action,
 
 				g_clear_error (&error);
 
-				d = _gtk_yesno_dialog_new (GTK_WINDOW (browser),
+				d = _gtk_yesno_dialog_new (window,
 							   GTK_DIALOG_MODAL,
 							   _("The files cannot be moved to the Trash. Do you want to delete them permanently?"),
 							   GTK_STOCK_CANCEL,
@@ -451,7 +446,7 @@ gth_browser_activate_action_edit_trash (GtkAction  *action,
 
 				break;
 			}
-			_gtk_error_dialog_from_gerror_show (GTK_WINDOW (browser), _("Could not move the files to the Trash"), &error);
+			_gtk_error_dialog_from_gerror_show (window, _("Could not move the files to the Trash"), &error);
 			break;
 		}
 	}
@@ -460,12 +455,73 @@ gth_browser_activate_action_edit_trash (GtkAction  *action,
 		GList  *files;
 
 		files = gth_file_data_list_to_file_list (file_list);
-		notify_files_delete (GTK_WINDOW (browser), files);
+		notify_files_delete (window, files);
 
 		_g_object_list_unref (files);
 	}
+}
+
+
+static void
+trash_files_response_cb (GtkDialog *dialog,
+			 int        response_id,
+			 gpointer   user_data)
+{
+	GList *file_list = user_data;
+
+	if (response_id == GTK_RESPONSE_YES)
+		trash_files (gtk_window_get_transient_for (GTK_WINDOW (dialog)), file_list);
 
+	gtk_widget_destroy (GTK_WIDGET (dialog));
 	_g_object_list_unref (file_list);
+}
+
+
+void
+gth_browser_activate_action_edit_trash (GtkAction  *action,
+					GthBrowser *browser)
+{
+	GList *items;
+	GList *file_list = NULL;
+
+	items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
+	file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
+
+	if (eel_gconf_get_boolean (PREF_MSG_CONFIRM_DELETION, DEFAULT_MSG_CONFIRM_DELETION)) {
+		int        file_count;
+		char      *prompt;
+		GtkWidget *d;
+
+		file_count = g_list_length (file_list);
+		if (file_count == 1) {
+			GthFileData *file_data = file_list->data;
+			prompt = g_strdup_printf (_("Are you sure you want to move \"%s\" to trash?"), g_file_info_get_display_name (file_data->info));
+		}
+		else
+			prompt = g_strdup_printf (ngettext("Are you sure you want to move to trash "
+							   "the %'d selected file?",
+							   "Are you sure you want to move to trash "
+							   "the %'d selected files?", file_count),
+						  file_count);
+
+		d = _gtk_message_dialog_new (GTK_WINDOW (browser),
+					     GTK_DIALOG_MODAL,
+					     GTK_STOCK_DIALOG_QUESTION,
+					     prompt,
+					     NULL,
+					     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+					     _("Mo_ve to Trash"), GTK_RESPONSE_YES,
+					     NULL);
+		g_signal_connect (d, "response", G_CALLBACK (trash_files_response_cb), file_list);
+		gtk_widget_show (d);
+
+		g_free (prompt);
+	}
+	else {
+		trash_files (GTK_WINDOW (browser), file_list);
+		_g_object_list_unref (file_list);
+	}
+
 	_gtk_tree_path_list_free (items);
 }
 
@@ -486,7 +542,6 @@ gth_browser_activate_action_edit_delete (GtkAction  *action,
 	file_count = g_list_length (file_list);
 	if (file_count == 1) {
 		GthFileData *file_data = file_list->data;
-
 		prompt = g_strdup_printf (_("Are you sure you want to permanently delete \"%s\"?"), g_file_info_get_display_name (file_data->info));
 	}
 	else
diff --git a/gthumb/dlg-preferences.c b/gthumb/dlg-preferences.c
index 8740cdd..ed6638e 100644
--- a/gthumb/dlg-preferences.c
+++ b/gthumb/dlg-preferences.c
@@ -152,6 +152,14 @@ toolbar_style_changed_cb (GtkWidget  *widget,
 
 
 static void
+confirm_deletion_toggled_cb (GtkToggleButton *button,
+			     DialogData      *data)
+{
+	eel_gconf_set_boolean (PREF_MSG_CONFIRM_DELETION, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("confirm_deletion_checkbutton"))));
+}
+
+
+static void
 ask_to_save_toggled_cb (GtkToggleButton *button,
 			DialogData      *data)
 {
@@ -267,6 +275,7 @@ dlg_preferences (GthBrowser *browser)
 	g_object_unref (file_source);
 	g_free (startup_location);
 
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("confirm_deletion_checkbutton")), eel_gconf_get_boolean (PREF_MSG_CONFIRM_DELETION, DEFAULT_MSG_CONFIRM_DELETION));
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("ask_to_save_checkbutton")), eel_gconf_get_boolean (PREF_MSG_SAVE_MODIFIED_IMAGE, DEFAULT_MSG_SAVE_MODIFIED_IMAGE));
 	gtk_combo_box_set_active (GTK_COMBO_BOX (data->toolbar_style_combobox), eel_gconf_get_enum (PREF_UI_TOOLBAR_STYLE, GTH_TYPE_TOOLBAR_STYLE, GTH_TOOLBAR_STYLE_SYSTEM));
 
@@ -308,6 +317,10 @@ dlg_preferences (GthBrowser *browser)
 			  "clicked",
 			  G_CALLBACK (set_to_current_cb),
 			  data);
+	g_signal_connect (G_OBJECT (GET_WIDGET ("confirm_deletion_checkbutton")),
+			  "toggled",
+			  G_CALLBACK (confirm_deletion_toggled_cb),
+			  data);
 	g_signal_connect (G_OBJECT (GET_WIDGET ("ask_to_save_checkbutton")),
 			  "toggled",
 			  G_CALLBACK (ask_to_save_toggled_cb),
diff --git a/gthumb/gth-preferences.h b/gthumb/gth-preferences.h
index cdb5584..a45d186 100644
--- a/gthumb/gth-preferences.h
+++ b/gthumb/gth-preferences.h
@@ -75,6 +75,7 @@ G_BEGIN_DECLS
 
 #define PREF_MSG_CANNOT_MOVE_TO_TRASH       "/apps/gthumb/dialogs/messages/cannot_move_to_trash"
 #define PREF_MSG_SAVE_MODIFIED_IMAGE        "/apps/gthumb/dialogs/messages/save_modified_image"
+#define PREF_MSG_CONFIRM_DELETION           "/apps/gthumb/dialogs/messages/confirm_deletion"
 
 /* default values */
 
@@ -86,7 +87,7 @@ G_BEGIN_DECLS
 #define DEFAULT_THUMBNAIL_SIZE 128
 #define DEFAULT_CONFIRM_DELETION TRUE
 #define DEFAULT_MSG_SAVE_MODIFIED_IMAGE TRUE
-
+#define DEFAULT_MSG_CONFIRM_DELETION TRUE
 
 void             gth_pref_initialize                   (void);
 void             gth_pref_release                      (void);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]