[gthumb: 17/24] [copy_move] removed the preference and the completed dialog



commit ad3aeb9290dce690f4b281d3e802118487ef11a2
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon Nov 15 18:24:16 2010 +0100

    [copy_move] removed the preference and the completed dialog
    
    added an option to view the destination folder in the folder selection
    dialog, this allows to remove the preferences dialog and the "copy
    completed" dialog.

 extensions/copy_move_to_folder/Makefile.am         |   16 +-
 extensions/copy_move_to_folder/actions.c           |  221 +++++++++-----------
 extensions/copy_move_to_folder/data/Makefile.am    |    2 -
 .../data/gthumb-copy-move-to-folder.schemas.in     |   12 +
 extensions/copy_move_to_folder/data/ui/Makefile.am |    8 -
 .../data/ui/copy-move-to-folder-copy-complete.ui   |   84 --------
 .../data/ui/copy-move-to-folder-preferences.ui     |   66 ------
 extensions/copy_move_to_folder/dlg-copy-complete.c |  120 -----------
 extensions/copy_move_to_folder/dlg-copy-complete.h |   31 ---
 .../dlg-copy-move-to-folder-preferences.c          |   87 --------
 .../dlg-copy-move-to-folder-preferences.h          |   29 ---
 extensions/copy_move_to_folder/main.c              |    4 +-
 extensions/copy_move_to_folder/preferences.h       |    1 +
 13 files changed, 122 insertions(+), 559 deletions(-)
---
diff --git a/extensions/copy_move_to_folder/Makefile.am b/extensions/copy_move_to_folder/Makefile.am
index c9c3d09..d92c8b8 100644
--- a/extensions/copy_move_to_folder/Makefile.am
+++ b/extensions/copy_move_to_folder/Makefile.am
@@ -3,16 +3,12 @@ SUBDIRS = data
 extensiondir = $(pkglibdir)/extensions
 extension_LTLIBRARIES = libcopy_move_to_folder.la
 
-libcopy_move_to_folder_la_SOURCES = \
-	actions.c \
-	actions.h \
-	callbacks.c \
-	callbacks.h \
-	preferences.h \
-	dlg-copy-complete.c \
-	dlg-copy-complete.h \
-	dlg-copy-move-to-folder-preferences.c \
-	dlg-copy-move-to-folder-preferences.h \
+libcopy_move_to_folder_la_SOURCES = 	\
+	actions.c 			\
+	actions.h 			\
+	callbacks.c 			\
+	callbacks.h 			\
+	preferences.h 			\
 	main.c
 
 libcopy_move_to_folder_la_CFLAGS = $(GTHUMB_CFLAGS) -I$(top_srcdir) -I$(top_builddir)/gthumb
diff --git a/extensions/copy_move_to_folder/actions.c b/extensions/copy_move_to_folder/actions.c
index a35b9b6..c8c97f1 100644
--- a/extensions/copy_move_to_folder/actions.c
+++ b/extensions/copy_move_to_folder/actions.c
@@ -3,7 +3,7 @@
 /*
  *  GThumb
  *
- *  Copyright (C) 2009 Free Software Foundation, Inc.
+ *  Copyright (C) 2010 Free Software Foundation, Inc.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -23,168 +23,151 @@
 #include <config.h>
 #include <glib/gi18n.h>
 #include <gthumb.h>
-#include "preferences.h"
-#include "dlg-copy-complete.h"
 #include <extensions/file_manager/gth-copy-task.h>
+#include "preferences.h"
 
-struct _CopyMoveToFolderPrivate{
-	GFile   *destination;
-	gboolean move;
-	GthBrowser   *browser;
-};
-
-typedef struct _CopyMoveToFolderPrivate CopyMoveToFolderPrivate;
-
-/* get the previous dir stored in gconf
- default to the home dir if no previous */
-static char*
-copy_move_to_folder_get_start_uri(gboolean move) {
-	GFile		*home_dir_gfile;
-	char		*default_uri;
-	char		*start_uri;
-
-	home_dir_gfile = g_file_new_for_path(g_get_home_dir());
-	default_uri = g_file_get_uri(home_dir_gfile);
-	if(move)
-		start_uri = eel_gconf_get_string (PREF_COPY_MOVE_TO_FOLDER_MOVE_URI, default_uri);
-	else
-		start_uri = eel_gconf_get_string (PREF_COPY_MOVE_TO_FOLDER_COPY_URI, default_uri);
-	g_object_unref(home_dir_gfile);
-	g_free(default_uri);
-	return start_uri;
-}
 
-/* ask the user if they wish to move to the destination folder */
-void
-copy_complete_cb(GthTask    *task,
-				GError     *error,
-				gpointer   data)
+typedef struct {
+	GthBrowser *browser;
+	gboolean    move;
+	GFile      *destination;
+	gboolean    view_destination;
+} CopyToFolderData;
+
+
+static void
+copy_to_folder_data_free (CopyToFolderData *data)
 {
-	/* TODO */
-	/* what should we do on error here? */
+	g_object_unref (data->destination);
+	g_object_unref (data->browser);
+	g_free (data);
+}
 
-	CopyMoveToFolderPrivate *priv;
-	priv = data;
 
-	dlg_copy_complete(priv->browser, priv->move, priv->destination);
+void
+copy_complete_cb (GthTask  *task,
+		  GError   *error,
+		  gpointer  user_data)
+{
+	CopyToFolderData *data = user_data;
 
-	g_object_unref(priv->browser);
-	g_object_unref(priv->destination);
-	g_free(priv);
+	if ((error == NULL) && (data->view_destination))
+		gth_browser_load_location (data->browser, data->destination);
 
+	g_object_unref (task);
+	copy_to_folder_data_free (data);
 }
 
-/* get the list of files and create and execute the task */
+
 static void
-copy_move_to_folder_copy_files(GthBrowser *browser,
-					gboolean move,
-					char *selected_folder_uri)
+copy_files_to_folder (GthBrowser *browser,
+		      gboolean    move,
+		      char       *destination_uri,
+		      gboolean    view_destination)
 {
-	GList		*items;
-	GList		*file_list;
-	GthTask 	*task;
-	GthFileData	*destination_path_fd;
-	GthFileSource	*file_source;
-	GList		*files;
-	GList 		*scan;
-	GthFileData 	*fd;
-
-	//get the selected folder as a GFile
-	GFile *destination_path;
-	destination_path = g_file_new_for_uri(selected_folder_uri);
-
-	//create a file data object for the destination GFile
-	destination_path_fd = gth_file_data_new(destination_path, NULL);
-	g_object_unref(destination_path);
-	file_source = gth_main_get_file_source (destination_path_fd->file);
-
-	//create the GList of GFiles to copied
-	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);
+	GthFileData      *destination_data;
+	GthFileSource    *file_source;
+	GList            *items;
+	GList            *file_list;
+	GList            *files;
+	CopyToFolderData *data;
+	GthTask          *task;
 
-	files = NULL;
+	destination_data = gth_file_data_new_for_uri (destination_uri, NULL);
+	file_source = gth_main_get_file_source (destination_data->file);
 
-	for (scan = file_list; scan; scan = scan->next)
-	{
-		fd = (GthFileData*) scan->data;
-		files = g_list_prepend(files, g_file_dup(fd->file));
-	}
-
-	// create and execute the task
-	task = gth_copy_task_new (file_source, destination_path_fd, move, files);
+	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);
+	files = gth_file_data_list_to_file_list (file_list);
 
-	// setup copy completed signal
-	CopyMoveToFolderPrivate *data;
-	data = g_new0(CopyMoveToFolderPrivate, 1);
-	data->destination = g_file_dup(destination_path_fd->file);
-	data->browser = browser;
+	data = g_new0 (CopyToFolderData, 1);
+	data->browser = g_object_ref (browser);
 	data->move = move;
-	g_object_ref(browser);
+	data->destination = g_file_dup (destination_data->file);
+	data->view_destination = view_destination;
+
+	task = gth_copy_task_new (file_source, destination_data, move, files);
 	g_signal_connect (task,
 			  "completed",
 			  G_CALLBACK (copy_complete_cb),
-			  (gpointer)data);
+			  data);
 	gth_browser_exec_task (browser, task, FALSE);
 
-	//free data
-	g_object_unref(file_source);
+	_g_object_list_unref (files);
 	_g_object_list_unref (file_list);
 	_gtk_tree_path_list_free (items);
-	_g_object_list_unref (files);
-
+	g_object_unref (file_source);
 }
 
-/* show the dialog and execute the copy/move */
+
 static void
-copy_move_to_folder(GthBrowser *browser,
-				gboolean move)
+copy_to_folder_dialog (GthBrowser *browser,
+		       gboolean    move)
 {
-
-	char		*start_uri;
-	GtkWidget 	*dialog;
-	char 		*selected_folder_uri;
-
-	// create the select folder dialog
-	start_uri = copy_move_to_folder_get_start_uri(move);
+	GtkWidget *dialog;
+	char      *start_uri;
+	GtkWidget *view_destination_button;
 
 	dialog = gtk_file_chooser_dialog_new (move ? _("Move To") : _("Copy To"),
-		NULL,
-		GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
-		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-		(move ? _("Move") : _("Copy")), GTK_RESPONSE_ACCEPT,
-		NULL);
+					      NULL,
+					      GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+					      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+					      (move ? _("Move") : _("Copy")), GTK_RESPONSE_ACCEPT,
+					      NULL);
+
+	start_uri = eel_gconf_get_string (move ? PREF_COPY_MOVE_TO_FOLDER_MOVE_URI : PREF_COPY_MOVE_TO_FOLDER_COPY_URI, get_home_uri ());
 	gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog), start_uri);
 	g_free(start_uri);
 
-	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
-	{
-		selected_folder_uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
-		copy_move_to_folder_copy_files(browser, move, selected_folder_uri);
+	view_destination_button = gtk_check_button_new_with_mnemonic (_("_View the destination"));
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (view_destination_button),
+				      eel_gconf_get_boolean (PREF_FILE_MANAGER_COPY_VIEW_DESTINATION, FALSE));
+	gtk_widget_show (view_destination_button);
+	gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
+			    view_destination_button,
+			    FALSE,
+			    FALSE,
+			    0);
+
+	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
+		char *destination_uri;
 
-		//store the current uri in gconf
-		if(move)
-			eel_gconf_set_string (PREF_COPY_MOVE_TO_FOLDER_MOVE_URI, selected_folder_uri);
-		else
-			eel_gconf_set_string (PREF_COPY_MOVE_TO_FOLDER_COPY_URI, selected_folder_uri);
+		destination_uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
+		if (destination_uri != NULL) {
+			gboolean view_destination;
 
-		g_free (selected_folder_uri);
+			/* save the options */
+
+			view_destination = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (view_destination_button));
+			eel_gconf_set_boolean (PREF_FILE_MANAGER_COPY_VIEW_DESTINATION, view_destination);
+			if (move)
+				eel_gconf_set_string (PREF_COPY_MOVE_TO_FOLDER_MOVE_URI, destination_uri);
+			else
+				eel_gconf_set_string (PREF_COPY_MOVE_TO_FOLDER_COPY_URI, destination_uri);
+
+			/* copy / move the files */
+
+			copy_files_to_folder (browser, move, destination_uri, view_destination);
+		}
+
+		g_free (destination_uri);
 	}
+
 	gtk_widget_destroy (dialog);
 }
 
-/* copy to folder action */
+
 void
 gth_browser_activate_action_tool_copy_to_folder (GtkAction  *action,
-						GthBrowser *browser)
+						 GthBrowser *browser)
 {
-	copy_move_to_folder(browser, FALSE);
-
+	copy_to_folder_dialog (browser, FALSE);
 }
 
-/* move to folder action */
+
 void
 gth_browser_activate_action_tool_move_to_folder (GtkAction  *action,
-						GthBrowser *browser)
+						 GthBrowser *browser)
 {
-	copy_move_to_folder(browser, TRUE);
+	copy_to_folder_dialog (browser, TRUE);
 }
diff --git a/extensions/copy_move_to_folder/data/Makefile.am b/extensions/copy_move_to_folder/data/Makefile.am
index 6d4b723..a4ebfaf 100644
--- a/extensions/copy_move_to_folder/data/Makefile.am
+++ b/extensions/copy_move_to_folder/data/Makefile.am
@@ -1,5 +1,3 @@
-SUBDIRS = ui
-
 schemadir = @GCONF_SCHEMA_FILE_DIR@
 schema_in_files = gthumb-copy-move-to-folder.schemas.in
 schema_DATA = $(schema_in_files:.schemas.in=.schemas)
diff --git a/extensions/copy_move_to_folder/data/gthumb-copy-move-to-folder.schemas.in b/extensions/copy_move_to_folder/data/gthumb-copy-move-to-folder.schemas.in
index 0cf8164..1bd2fdd 100644
--- a/extensions/copy_move_to_folder/data/gthumb-copy-move-to-folder.schemas.in
+++ b/extensions/copy_move_to_folder/data/gthumb-copy-move-to-folder.schemas.in
@@ -49,5 +49,17 @@
 	</locale>
       </schema>
 
+      <schema>
+	<key>/schemas/apps/gthumb/ext/file_manager/copy_move/view_destination</key>
+	<applyto>/apps/gthumb/ext/file_manager/copy_move/view_destination</applyto>
+	<owner>gthumb</owner>
+	<type>bool</type>
+	<default>false</default>
+	<locale name="C">
+	  <short></short>
+	  <long></long>
+	</locale>
+      </schema>
+
     </schemalist>
 </gconfschemafile>
diff --git a/extensions/copy_move_to_folder/main.c b/extensions/copy_move_to_folder/main.c
index cb2681c..87dfbf7 100644
--- a/extensions/copy_move_to_folder/main.c
+++ b/extensions/copy_move_to_folder/main.c
@@ -24,7 +24,6 @@
 #include <gtk/gtk.h>
 #include <gthumb.h>
 #include "callbacks.h"
-#include "dlg-copy-move-to-folder-preferences.h"
 
 
 G_MODULE_EXPORT void
@@ -44,12 +43,11 @@ gthumb_extension_deactivate (void)
 G_MODULE_EXPORT gboolean
 gthumb_extension_is_configurable (void)
 {
-	return TRUE;
+	return FALSE;
 }
 
 
 G_MODULE_EXPORT void
 gthumb_extension_configure (GtkWindow *parent)
 {
-	dlg_copy_move_to_folder_preferences (parent);
 }
diff --git a/extensions/copy_move_to_folder/preferences.h b/extensions/copy_move_to_folder/preferences.h
index 47e2e99..7ac1704 100644
--- a/extensions/copy_move_to_folder/preferences.h
+++ b/extensions/copy_move_to_folder/preferences.h
@@ -28,6 +28,7 @@ G_BEGIN_DECLS
 #define  PREF_COPY_MOVE_TO_FOLDER_MOVE_URI      "/apps/gthumb/ext/copy_move_to_folder/move_uri"
 #define  PREF_COPY_MOVE_TO_FOLDER_SHOW_DIALOG   "/apps/gthumb/ext/copy_move_to_folder/show_dialog"
 #define  PREF_COPY_MOVE_TO_FOLDER_ALWAYS_OPEN   "/apps/gthumb/ext/copy_move_to_folder/always_open"
+#define  PREF_FILE_MANAGER_COPY_VIEW_DESTINATION "/apps/gthumb/ext/file_manager/copy_move/view_destination"
 
 G_END_DECLS
 



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