[gthumb: 1/24] Initial commit for copy_move_to_folder extension



commit be00b9a8c3a5f6deda2495ce72459954491d8cb9
Author: Marlodavampire <vworker.com>
Date:   Tue Nov 9 22:28:14 2010 +1100

    Initial commit for copy_move_to_folder extension

 configure.ac                                       |    1 +
 extensions/Makefile.am                             |    3 +-
 extensions/copy_move_to_folder/Makefile.am         |   28 ++++
 extensions/copy_move_to_folder/actions.c           |  151 ++++++++++++++++++++
 extensions/copy_move_to_folder/actions.h           |   32 ++++
 extensions/copy_move_to_folder/callbacks.c         |  124 ++++++++++++++++
 extensions/copy_move_to_folder/callbacks.h         |   30 ++++
 .../copy_move_to_folder.extension.in.in            |   13 ++
 extensions/copy_move_to_folder/main.c              |   53 +++++++
 extensions/copy_move_to_folder/preferences.h       |   32 ++++
 10 files changed, 466 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 2082202..f026512 100644
--- a/configure.ac
+++ b/configure.ac
@@ -579,6 +579,7 @@ extensions/webalbums/data/albumthemes/ClassicClips/Makefile
 extensions/webalbums/data/albumthemes/NeatRound/Makefile
 extensions/webalbums/data/albumthemes/Wiki/Makefile
 extensions/webalbums/data/ui/Makefile
+extensions/copy_move_to_folder/Makefile
 gthumb/Makefile
 gthumb/cursors/Makefile
 po/Makefile.in
diff --git a/extensions/Makefile.am b/extensions/Makefile.am
index 024bb49..e863e94 100644
--- a/extensions/Makefile.am
+++ b/extensions/Makefile.am
@@ -33,7 +33,8 @@ SUBDIRS = 			\
 	webalbums		\
 	flicker			\
 	burn_disc		\
-	desktop_background
+	desktop_background	\
+	copy_move_to_folder
 
 EXTRA_DIST = example
 
diff --git a/extensions/copy_move_to_folder/Makefile.am b/extensions/copy_move_to_folder/Makefile.am
new file mode 100644
index 0000000..6e3668f
--- /dev/null
+++ b/extensions/copy_move_to_folder/Makefile.am
@@ -0,0 +1,28 @@
+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 \
+	main.c
+
+libcopy_move_to_folder_la_CFLAGS = $(GTHUMB_CFLAGS) -I$(top_srcdir) -I$(top_builddir)/gthumb
+libcopy_move_to_folder_la_LDFLAGS = $(EXTENSION_LIBTOOL_FLAGS)
+libcopy_move_to_folder_la_LIBADD = $(GTHUMB_LIBS)  ../file_manager/libfile_manager.la
+libcopy_move_to_folder_la_DEPENDENCIES = $(top_builddir)/gthumb/gthumb$(EXEEXT)
+
+extensioninidir = $(extensiondir)
+extensionini_in_files = copy_move_to_folder.extension.in.in
+extensionini_DATA = $(extensionini_in_files:.extension.in.in=.extension)
+
+ GTHUMB_EXTENSION_IN_RULE@
+ GTHUMB_EXTENSION_RULE@
+
+EXTRA_DIST = $(extensionini_in_files)
+
+DISTCLEANFILES = $(extensionini_DATA)
+
+-include $(top_srcdir)/git.mk
diff --git a/extensions/copy_move_to_folder/actions.c b/extensions/copy_move_to_folder/actions.c
new file mode 100644
index 0000000..1cdd2ec
--- /dev/null
+++ b/extensions/copy_move_to_folder/actions.c
@@ -0,0 +1,151 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2009 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
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <config.h>
+#include <glib/gi18n.h>
+#include <gthumb.h>
+#include "preferences.h"
+#include <extensions/file_manager/gth-copy-task.h>
+
+/* 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;
+}
+
+
+/* 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)
+{
+	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);
+
+	files = NULL;
+
+	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);
+	gth_browser_exec_task (browser, task, FALSE);
+
+	//free data
+	g_object_unref(destination_path_fd);
+	g_object_unref(file_source);
+	_g_object_list_unref (file_list);
+	_gtk_tree_path_list_free (items);
+	_g_object_list_unref (files);
+
+}
+
+/* show the dialog and execute the copy/move */
+static void
+copy_move_to_folder(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);
+
+	dialog = gtk_file_chooser_dialog_new (N_("Select Folder"),
+		NULL,
+		GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+		GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+		NULL);
+	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);
+
+		//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);
+
+		g_free (selected_folder_uri);
+	}
+	gtk_widget_destroy (dialog);
+}
+
+/* copy to folder action */
+void
+gth_browser_activate_action_tool_copy_to_folder (GtkAction  *action,
+						GthBrowser *browser)
+{
+	copy_move_to_folder(browser, FALSE);
+
+}
+
+/* move to folder action */
+void
+gth_browser_activate_action_tool_move_to_folder (GtkAction  *action,
+						GthBrowser *browser)
+{
+	copy_move_to_folder(browser, TRUE);
+}
diff --git a/extensions/copy_move_to_folder/actions.h b/extensions/copy_move_to_folder/actions.h
new file mode 100644
index 0000000..bee0136
--- /dev/null
+++ b/extensions/copy_move_to_folder/actions.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2009 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
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ACTIONS_H
+#define ACTIONS_H
+
+#include <gtk/gtk.h>
+
+#define DEFINE_ACTION(x) void x (GtkAction *action, gpointer data);
+
+DEFINE_ACTION(gth_browser_activate_action_tool_copy_to_folder)
+DEFINE_ACTION(gth_browser_activate_action_tool_move_to_folder)
+
+#endif /* ACTIONS_H */
diff --git a/extensions/copy_move_to_folder/callbacks.c b/extensions/copy_move_to_folder/callbacks.c
new file mode 100644
index 0000000..e9392a4
--- /dev/null
+++ b/extensions/copy_move_to_folder/callbacks.c
@@ -0,0 +1,124 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2009 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
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <config.h>
+#include <glib/gi18n.h>
+#include <glib-object.h>
+#include <gthumb.h>
+#include "actions.h"
+
+#define BROWSER_DATA_KEY "copy-move-to-folder-browser-data"
+
+static const char *fixed_ui_info =
+"<ui>"
+"  <popup name='FileListPopup'>"
+"    <placeholder name='File_Actions'>"
+"      <menuitem name='CopyToFolder' action='Tool_CopyToFolder'/>"
+"      <menuitem name='MoveToFolder' action='Tool_MoveToFolder'/>"
+"    </placeholder>"
+"  </popup>"
+"  <popup name='FilePopup'>"
+"    <placeholder name='File_Actions'>"
+"      <menuitem name='CopyToFolder' action='Tool_CopyToFolder'/>"
+"      <menuitem name='MoveToFolder' action='Tool_MoveToFolder'/>"
+"    </placeholder>"
+"  </popup>"
+"  <menubar name='MenuBar'>"
+"    <menu name='Edit' action='EditMenu'>"
+"      <placeholder name='Folder_Actions_2'>"
+"        <menuitem name='CopyToFolder' action='Tool_CopyToFolder'/>"
+"        <menuitem name='MoveToFolder' action='Tool_MoveToFolder'/>"
+"      </placeholder>"
+"    </menu>"
+"  </menubar>"
+"</ui>";
+
+
+static GtkActionEntry action_entries[] = {
+	{ "Tool_CopyToFolder", "edit-copy",
+	  N_("Copy to Folder"), NULL,
+	  N_("Copy the selected image(s) to a folder"),
+	  G_CALLBACK (gth_browser_activate_action_tool_copy_to_folder)
+	},
+	{ "Tool_MoveToFolder", "edit-cut",
+	  N_("Move to Folder"), NULL,
+	  N_("Move the selected image(s) to a folder"),
+	  G_CALLBACK (gth_browser_activate_action_tool_move_to_folder)
+	},
+};
+
+
+typedef struct {
+	GtkActionGroup *action_group;
+} BrowserData;
+
+
+static void
+browser_data_free (BrowserData *data)
+{
+	g_free (data);
+}
+
+
+void
+db__gth_browser_construct_cb (GthBrowser *browser)
+{
+	BrowserData *data;
+	GError      *error = NULL;
+
+	g_return_if_fail (GTH_IS_BROWSER (browser));
+
+	data = g_new0 (BrowserData, 1);
+	data->action_group = gtk_action_group_new ("Copy Move To Folder Actions");
+	gtk_action_group_set_translation_domain (data->action_group, NULL);
+	gtk_action_group_add_actions (data->action_group,
+				      action_entries,
+				      G_N_ELEMENTS (action_entries),
+				      browser);
+	gtk_ui_manager_insert_action_group (gth_browser_get_ui_manager (browser), data->action_group, 0);
+
+	if (! gtk_ui_manager_add_ui_from_string (gth_browser_get_ui_manager (browser), fixed_ui_info, -1, &error)) {
+		g_message ("building menus failed: %s", error->message);
+		g_clear_error (&error);
+	}
+
+	g_object_set_data_full (G_OBJECT (browser), BROWSER_DATA_KEY, data, (GDestroyNotify) browser_data_free);
+}
+
+
+void
+db__gth_browser_update_sensitivity_cb (GthBrowser *browser)
+{
+	BrowserData *data;
+	GtkAction   *action;
+	int          n_selected;
+	gboolean     sensitive;
+
+	data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
+	g_return_if_fail (data != NULL);
+
+	n_selected = gth_file_selection_get_n_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
+	sensitive = n_selected > 0;
+
+	action = gtk_action_group_get_action (data->action_group, "Tool_MoveToFolder");
+	g_object_set (action, "sensitive", sensitive, NULL);
+}
diff --git a/extensions/copy_move_to_folder/callbacks.h b/extensions/copy_move_to_folder/callbacks.h
new file mode 100644
index 0000000..5c9462d
--- /dev/null
+++ b/extensions/copy_move_to_folder/callbacks.h
@@ -0,0 +1,30 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2009 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
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CALLBACKS_H
+#define CALLBACKS_H
+
+#include <gthumb.h>
+
+void      db__gth_browser_construct_cb           (GthBrowser  *browser);
+void      db__gth_browser_update_sensitivity_cb  (GthBrowser  *browser);
+
+#endif /* CALLBACKS_H */
diff --git a/extensions/copy_move_to_folder/copy_move_to_folder.extension.in.in b/extensions/copy_move_to_folder/copy_move_to_folder.extension.in.in
new file mode 100644
index 0000000..1c286e9
--- /dev/null
+++ b/extensions/copy_move_to_folder/copy_move_to_folder.extension.in.in
@@ -0,0 +1,13 @@
+[Extension]
+_Name=Copy/Move to Folder
+_Description=Adds a bulk copy/move tool for files, in addition to the normal cut and paste functions.
+Authors= Michael Chudobiak, marlodavampire
+Copyright=Copyright © 2010 The Free Software Foundation, Inc.
+Version=%VERSION%
+Category=Browser
+Icon=edit-copy
+
+[Loader]
+Type=module
+File=%LIBRARY%
+Requires=file_manager
diff --git a/extensions/copy_move_to_folder/main.c b/extensions/copy_move_to_folder/main.c
new file mode 100644
index 0000000..1129959
--- /dev/null
+++ b/extensions/copy_move_to_folder/main.c
@@ -0,0 +1,53 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  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
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <config.h>
+#include <gtk/gtk.h>
+#include <gthumb.h>
+#include "callbacks.h"
+
+
+G_MODULE_EXPORT void
+gthumb_extension_activate (void)
+{
+	gth_hook_add_callback ("gth-browser-construct", 20, G_CALLBACK (db__gth_browser_construct_cb), NULL);
+	gth_hook_add_callback ("gth-browser-update-sensitivity", 10, G_CALLBACK (db__gth_browser_update_sensitivity_cb), NULL);
+}
+
+
+G_MODULE_EXPORT void
+gthumb_extension_deactivate (void)
+{
+}
+
+
+G_MODULE_EXPORT gboolean
+gthumb_extension_is_configurable (void)
+{
+	return FALSE;
+}
+
+
+G_MODULE_EXPORT void
+gthumb_extension_configure (GtkWindow *parent)
+{
+}
diff --git a/extensions/copy_move_to_folder/preferences.h b/extensions/copy_move_to_folder/preferences.h
new file mode 100644
index 0000000..f04a406
--- /dev/null
+++ b/extensions/copy_move_to_folder/preferences.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  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
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PREFERENCES_H
+#define PREFERENCES_H
+
+G_BEGIN_DECLS
+
+#define  PREF_COPY_MOVE_TO_FOLDER_COPY_URI      "/apps/gthumb/ext/copy_move_to_folder/copy_uri"
+#define  PREF_COPY_MOVE_TO_FOLDER_MOVE_URI      "/apps/gthumb/ext/copy_move_to_folder/move_uri"
+
+G_END_DECLS
+
+#endif /* PREFERENCES_H */



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