[gthumb] moved the delete files and trash files functions to gth-file-source-vfs
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] moved the delete files and trash files functions to gth-file-source-vfs
- Date: Sun, 22 May 2011 12:41:26 +0000 (UTC)
commit 0b4f713502332d48b43f5987db356d723ec09766
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun May 22 13:15:11 2011 +0200
moved the delete files and trash files functions to gth-file-source-vfs
extensions/file_manager/actions.c | 186 +-----------------
extensions/file_manager/actions.h | 3 -
extensions/file_manager/callbacks.c | 20 ++-
extensions/find_duplicates/Makefile.am | 2 +-
.../find_duplicates.extension.in.in | 2 +-
gthumb/gth-file-source-vfs.c | 207 ++++++++++++++++++++
gthumb/gth-file-source-vfs.h | 8 +-
gthumb/gth-file-source.c | 28 ++-
gthumb/gth-file-source.h | 8 +-
9 files changed, 257 insertions(+), 207 deletions(-)
---
diff --git a/extensions/file_manager/actions.c b/extensions/file_manager/actions.c
index 5aaacbe..99458dd 100644
--- a/extensions/file_manager/actions.c
+++ b/extensions/file_manager/actions.c
@@ -394,209 +394,29 @@ gth_browser_activate_action_edit_duplicate (GtkAction *action,
}
-static void
-notify_files_delete (GtkWindow *window,
- GList *files)
-{
- GFile *parent;
-
- parent = g_file_get_parent ((GFile*) files->data);
- gth_monitor_folder_changed (gth_main_get_default_monitor (),
- parent,
- files,
- GTH_MONITOR_EVENT_DELETED);
-
- g_object_unref (parent);
-}
-
-
-static void
-delete_file_permanently (GtkWindow *window,
- GList *file_list)
-{
- GList *files;
- GError *error = NULL;
-
- files = gth_file_data_list_to_file_list (file_list);
- if (! _g_delete_files (files, TRUE, &error))
- _gtk_error_dialog_from_gerror_show (window, _("Could not delete the files"), &error);
- else
- notify_files_delete (window, files);
-
- _g_object_list_unref (files);
-}
-
-
-static void
-delete_permanently_response_cb (GtkDialog *dialog,
- int response_id,
- gpointer user_data)
-{
- GList *file_list = user_data;
-
- if (response_id == GTK_RESPONSE_YES)
- delete_file_permanently (gtk_window_get_transient_for (GTK_WINDOW (dialog)), file_list);
-
- gtk_widget_destroy (GTK_WIDGET (dialog));
- _g_object_list_unref (file_list);
-}
-
-
-static void
-trash_files (GtkWindow *window,
- GList *file_list)
-{
- GList *scan;
- gboolean moved_to_trash = TRUE;
- GError *error = NULL;
-
- for (scan = file_list; scan; scan = scan->next) {
- GthFileData *file_data = scan->data;
-
- if (! g_file_trash (file_data->file, NULL, &error)) {
- moved_to_trash = FALSE;
- if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED)) {
- GtkWidget *d;
-
- g_clear_error (&error);
-
- 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,
- GTK_STOCK_DELETE);
- g_signal_connect (d,
- "response",
- G_CALLBACK (delete_permanently_response_cb),
- gth_file_data_list_dup (file_list));
- gtk_widget_show (d);
-
- break;
- }
- _gtk_error_dialog_from_gerror_show (window, _("Could not move the files to the Trash"), &error);
- break;
- }
- }
-
- if (moved_to_trash) {
- GList *files;
-
- files = gth_file_data_list_to_file_list (file_list);
- 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;
+ GList *file_list;
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);
+ gth_file_mananger_trash_files (GTK_WINDOW (browser), file_list);
- 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);
- }
-
+ _g_object_list_unref (file_list);
_gtk_tree_path_list_free (items);
}
void
-gth_file_mananger_delete_files (GtkWindow *window,
- GList *file_list /* GthFileData list */)
-{
- int file_count;
- char *prompt;
- GtkWidget *d;
-
- file_list = _g_object_list_ref (file_list);
- 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
- prompt = g_strdup_printf (ngettext("Are you sure you want to permanently delete "
- "the %'d selected file?",
- "Are you sure you want to permanently delete "
- "the %'d selected files?", file_count),
- file_count);
-
- d = _gtk_message_dialog_new (window,
- GTK_DIALOG_MODAL,
- GTK_STOCK_DIALOG_QUESTION,
- prompt,
- _("If you delete a file, it will be permanently lost."),
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_DELETE, GTK_RESPONSE_YES,
- NULL);
- g_signal_connect (d, "response", G_CALLBACK (delete_permanently_response_cb), file_list);
- gtk_widget_show (d);
-
- g_free (prompt);
-}
-
-
-void
gth_browser_activate_action_edit_delete (GtkAction *action,
GthBrowser *browser)
{
GList *items;
GList *file_list;
-
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);
gth_file_mananger_delete_files (GTK_WINDOW (browser), file_list);
diff --git a/extensions/file_manager/actions.h b/extensions/file_manager/actions.h
index 1b259ba..1518cef 100644
--- a/extensions/file_manager/actions.h
+++ b/extensions/file_manager/actions.h
@@ -45,7 +45,4 @@ DEFINE_ACTION(gth_browser_activate_action_folder_delete)
DEFINE_ACTION(gth_browser_activate_action_tool_copy_to_folder)
DEFINE_ACTION(gth_browser_activate_action_tool_move_to_folder)
-void gth_file_mananger_delete_files (GtkWindow *window,
- GList *file_list /* GthFileData list */);
-
#endif /* ACTIONS_H */
diff --git a/extensions/file_manager/callbacks.c b/extensions/file_manager/callbacks.c
index 1ea2c19..f4b8502 100644
--- a/extensions/file_manager/callbacks.c
+++ b/extensions/file_manager/callbacks.c
@@ -1070,13 +1070,19 @@ fm__gth_browser_file_list_key_press_cb (GthBrowser *browser,
break;
case GDK_Delete:
- if ((event->state & modifiers) == 0) {
- gth_browser_activate_action_edit_trash (NULL, browser);
- result = GINT_TO_POINTER (1);
- }
- else if ((event->state & modifiers) == GDK_SHIFT_MASK) {
- gth_browser_activate_action_edit_delete (NULL, browser);
- result = GINT_TO_POINTER (1);
+ if (((event->state & modifiers) == 0) || ((event->state & modifiers) == GDK_SHIFT_MASK)) {
+ if (gth_browser_get_location_source (browser) != NULL) {
+ items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
+ file_data_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
+ gth_file_source_remove (gth_browser_get_location_source (browser),
+ file_data_list,
+ (event->state & modifiers) == GDK_SHIFT_MASK,
+ GTK_WINDOW (browser));
+
+ _g_object_list_unref (file_data_list);
+ _gtk_tree_path_list_free (items);
+ result = GINT_TO_POINTER (1);
+ }
}
break;
}
diff --git a/extensions/find_duplicates/Makefile.am b/extensions/find_duplicates/Makefile.am
index 1293510..e4830a4 100644
--- a/extensions/find_duplicates/Makefile.am
+++ b/extensions/find_duplicates/Makefile.am
@@ -16,7 +16,7 @@ libfind_duplicates_la_SOURCES = \
libfind_duplicates_la_CFLAGS = $(GTHUMB_CFLAGS) -I$(top_srcdir) -I$(top_builddir)/gthumb
libfind_duplicates_la_LDFLAGS = $(EXTENSION_LIBTOOL_FLAGS)
-libfind_duplicates_la_LIBADD = $(GTHUMB_LIBS) ../catalogs/libcatalogs.la ../file_manager/libfile_manager.la
+libfind_duplicates_la_LIBADD = $(GTHUMB_LIBS) ../catalogs/libcatalogs.la
libfind_duplicates_la_DEPENDENCIES = $(top_builddir)/gthumb/gthumb$(EXEEXT)
extensioninidir = $(extensiondir)
diff --git a/extensions/find_duplicates/find_duplicates.extension.in.in b/extensions/find_duplicates/find_duplicates.extension.in.in
index 826b5c4..92f3652 100644
--- a/extensions/find_duplicates/find_duplicates.extension.in.in
+++ b/extensions/find_duplicates/find_duplicates.extension.in.in
@@ -9,4 +9,4 @@ Category=Browser
[Loader]
Type=module
File=%LIBRARY%
-Requires=catalogs;file_manager
+Requires=catalogs
diff --git a/gthumb/gth-file-source-vfs.c b/gthumb/gth-file-source-vfs.c
index 561827a..d3405bd 100644
--- a/gthumb/gth-file-source-vfs.c
+++ b/gthumb/gth-file-source-vfs.c
@@ -23,11 +23,14 @@
#include <string.h>
#include <glib/gi18n.h>
#include <glib.h>
+#include "gconf-utils.h"
#include "gth-file-data.h"
#include "gio-utils.h"
#include "glib-utils.h"
#include "gth-file-source-vfs.h"
#include "gth-main.h"
+#include "gth-preferences.h"
+#include "gtk-utils.h"
#define GTH_MONITOR_N_EVENTS 3
#define MONITOR_UPDATE_DELAY 500
@@ -609,6 +612,209 @@ gth_file_source_vfs_monitor_directory (GthFileSource *file_source,
}
+/* -- gth_file_source_vfs_remove -- */
+
+
+static void
+notify_files_delete (GtkWindow *window,
+ GList *files)
+{
+ GFile *parent;
+
+ parent = g_file_get_parent ((GFile*) files->data);
+ gth_monitor_folder_changed (gth_main_get_default_monitor (),
+ parent,
+ files,
+ GTH_MONITOR_EVENT_DELETED);
+
+ g_object_unref (parent);
+}
+
+
+static void
+delete_file_permanently (GtkWindow *window,
+ GList *file_list)
+{
+ GList *files;
+ GError *error = NULL;
+
+ files = gth_file_data_list_to_file_list (file_list);
+ if (! _g_delete_files (files, TRUE, &error))
+ _gtk_error_dialog_from_gerror_show (window, _("Could not delete the files"), &error);
+ else
+ notify_files_delete (window, files);
+
+ _g_object_list_unref (files);
+}
+
+
+static void
+delete_permanently_response_cb (GtkDialog *dialog,
+ int response_id,
+ gpointer user_data)
+{
+ GList *file_list = user_data;
+
+ if (response_id == GTK_RESPONSE_YES)
+ delete_file_permanently (gtk_window_get_transient_for (GTK_WINDOW (dialog)), file_list);
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ _g_object_list_unref (file_list);
+}
+
+
+static void
+trash_files (GtkWindow *window,
+ GList *file_list)
+{
+ GList *scan;
+ gboolean moved_to_trash = TRUE;
+ GError *error = NULL;
+
+ for (scan = file_list; scan; scan = scan->next) {
+ GthFileData *file_data = scan->data;
+
+ if (! g_file_trash (file_data->file, NULL, &error)) {
+ moved_to_trash = FALSE;
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED)) {
+ GtkWidget *d;
+
+ g_clear_error (&error);
+
+ 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,
+ GTK_STOCK_DELETE);
+ g_signal_connect (d,
+ "response",
+ G_CALLBACK (delete_permanently_response_cb),
+ gth_file_data_list_dup (file_list));
+ gtk_widget_show (d);
+
+ break;
+ }
+ _gtk_error_dialog_from_gerror_show (window, _("Could not move the files to the Trash"), &error);
+ break;
+ }
+ }
+
+ if (moved_to_trash) {
+ GList *files;
+
+ files = gth_file_data_list_to_file_list (file_list);
+ 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_file_mananger_trash_files (GtkWindow *window,
+ GList *file_list /* GthFileData list */)
+{
+ 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 (window,
+ 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),
+ gth_file_data_list_dup (file_list));
+ gtk_widget_show (d);
+
+ g_free (prompt);
+ }
+ else
+ trash_files (window, file_list);
+}
+
+
+void
+gth_file_mananger_delete_files (GtkWindow *window,
+ GList *file_list /* GthFileData list */)
+{
+ int file_count;
+ char *prompt;
+ GtkWidget *d;
+
+ file_list = _g_object_list_ref (file_list);
+ 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
+ prompt = g_strdup_printf (ngettext("Are you sure you want to permanently delete "
+ "the %'d selected file?",
+ "Are you sure you want to permanently delete "
+ "the %'d selected files?", file_count),
+ file_count);
+
+ d = _gtk_message_dialog_new (window,
+ GTK_DIALOG_MODAL,
+ GTK_STOCK_DIALOG_QUESTION,
+ prompt,
+ _("If you delete a file, it will be permanently lost."),
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_DELETE, GTK_RESPONSE_YES,
+ NULL);
+ g_signal_connect (d, "response", G_CALLBACK (delete_permanently_response_cb), file_list);
+ gtk_widget_show (d);
+
+ g_free (prompt);
+}
+
+
+static void
+gth_file_source_vfs_remove (GthFileSource *file_source,
+ GList *file_list /* GthFileData list */,
+ gboolean permanently,
+ GtkWindow *parent)
+{
+ if (permanently)
+ gth_file_mananger_delete_files (parent, file_list);
+ else
+ gth_file_mananger_trash_files (parent, file_list);
+}
+
+
static void
gth_file_source_vfs_finalize (GObject *object)
{
@@ -658,6 +864,7 @@ gth_file_source_vfs_class_init (GthFileSourceVfsClass *class)
file_source_class->can_cut = gth_file_source_vfs_can_cut;
file_source_class->monitor_entry_points = gth_file_source_vfs_monitor_entry_points;
file_source_class->monitor_directory = gth_file_source_vfs_monitor_directory;
+ file_source_class->remove = gth_file_source_vfs_remove;
}
diff --git a/gthumb/gth-file-source-vfs.h b/gthumb/gth-file-source-vfs.h
index bfc5493..14590cf 100644
--- a/gthumb/gth-file-source-vfs.h
+++ b/gthumb/gth-file-source-vfs.h
@@ -45,10 +45,14 @@ struct _GthFileSourceVfs
struct _GthFileSourceVfsClass
{
- GthFileSourceClass __parent_class;
+ GthFileSourceClass __parent_class;
};
-GType gth_file_source_vfs_get_type (void) G_GNUC_CONST;
+GType gth_file_source_vfs_get_type (void) G_GNUC_CONST;
+void gth_file_mananger_trash_files (GtkWindow *window,
+ GList *file_list /* GthFileData list */);
+void gth_file_mananger_delete_files (GtkWindow *window,
+ GList *file_list /* GthFileData list */);
G_END_DECLS
diff --git a/gthumb/gth-file-source.c b/gthumb/gth-file-source.c
index 4b6dd50..ce6a436 100644
--- a/gthumb/gth-file-source.c
+++ b/gthumb/gth-file-source.c
@@ -131,9 +131,12 @@ typedef struct {
typedef struct {
- GList *file_list;
+ GList *file_list;
+ gboolean permanently;
+ GtkWindow *parent;
} RemoveData;
+
typedef struct {
GthFileSource *file_source;
FileSourceOp op;
@@ -379,14 +382,18 @@ gth_file_source_queue_reorder (GthFileSource *file_source,
static void
gth_file_source_queue_remove (GthFileSource *file_source,
- GList *file_list)
+ GList *file_list,
+ gboolean permanently,
+ GtkWindow *parent)
{
FileSourceAsyncOp *async_op;
async_op = g_new0 (FileSourceAsyncOp, 1);
async_op->file_source = file_source;
async_op->op = FILE_SOURCE_OP_REMOVE;
- async_op->data.remove.file_list = _g_file_list_dup (file_list);
+ async_op->data.remove.file_list = gth_file_data_list_dup (file_list);
+ async_op->data.remove.permanently = permanently;
+ async_op->data.remove.parent = parent;
file_source->priv->queue = g_list_append (file_source->priv->queue, async_op);
}
@@ -474,7 +481,9 @@ gth_file_source_exec_next_in_queue (GthFileSource *file_source)
break;
case FILE_SOURCE_OP_REMOVE:
gth_file_source_remove (file_source,
- async_op->data.remove.file_list);
+ async_op->data.remove.file_list,
+ async_op->data.remove.permanently,
+ async_op->data.remove.parent);
break;
}
@@ -706,7 +715,8 @@ base_reorder (GthFileSource *file_source,
static void
base_remove (GthFileSource *file_source,
- GList *file_list /* GFile list */)
+ GList *file_list, /* GFile list */
+ gboolean permanently)
{
/* void */
}
@@ -1222,12 +1232,14 @@ gth_file_source_reorder (GthFileSource *file_source,
void
gth_file_source_remove (GthFileSource *file_source,
- GList *file_list /* GFile list */)
+ GList *file_list, /* GthFileData list */
+ gboolean permanently,
+ GtkWindow *parent)
{
if (gth_file_source_is_active (file_source)) {
- gth_file_source_queue_remove (file_source, file_list);
+ gth_file_source_queue_remove (file_source, file_list, permanently, parent);
return;
}
g_cancellable_reset (file_source->priv->cancellable);
- GTH_FILE_SOURCE_GET_CLASS (G_OBJECT (file_source))->remove (file_source, file_list);
+ GTH_FILE_SOURCE_GET_CLASS (G_OBJECT (file_source))->remove (file_source, file_list, permanently, parent);
}
diff --git a/gthumb/gth-file-source.h b/gthumb/gth-file-source.h
index 95f81ad..9527939 100644
--- a/gthumb/gth-file-source.h
+++ b/gthumb/gth-file-source.h
@@ -122,7 +122,9 @@ struct _GthFileSourceClass
ReadyCallback callback,
gpointer data);
void (*remove) (GthFileSource *file_source,
- GList *file_list /* GFile list */);
+ GList *file_list, /* GthFileData list */
+ gboolean permanently,
+ GtkWindow *parent);
};
GType gth_file_source_get_type (void) G_GNUC_CONST;
@@ -202,7 +204,9 @@ void gth_file_source_reorder (GthFileSource *file
ReadyCallback callback,
gpointer data);
void gth_file_source_remove (GthFileSource *file_source,
- GList *file_list /* GFile list */);
+ GList *file_list /* GthFileData list */,
+ gboolean permanently,
+ GtkWindow *parent);
/*< protected >*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]