[gthumb/ext] implemented the --import-photos argument



commit 13d37cd0e177b15848d20ddea81ad1b5fd731741
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sat Aug 29 14:42:10 2009 +0200

    implemented the --import-photos argument

 extensions/photo_importer/callbacks.c          |    9 +++++
 extensions/photo_importer/callbacks.h          |    2 +
 extensions/photo_importer/dlg-photo-importer.c |    3 ++
 extensions/photo_importer/gth-import-task.c    |    3 ++
 extensions/photo_importer/main.c               |    1 +
 gthumb/gth-browser.c                           |   40 +++++++++++----------
 gthumb/gth-main-default-hooks.c                |    9 +++++
 gthumb/main.c                                  |   44 +++++++++++++++++++++++-
 gthumb/main.h                                  |    5 +++
 9 files changed, 96 insertions(+), 20 deletions(-)
---
diff --git a/extensions/photo_importer/callbacks.c b/extensions/photo_importer/callbacks.c
index 5dad419..b8dc23e 100644
--- a/extensions/photo_importer/callbacks.c
+++ b/extensions/photo_importer/callbacks.c
@@ -26,6 +26,7 @@
 #include <glib-object.h>
 #include <gthumb.h>
 #include "actions.h"
+#include "dlg-photo-importer.h"
 
 
 #define BROWSER_DATA_KEY "photo-importer-browser-data"
@@ -90,3 +91,11 @@ pi__gth_browser_construct_cb (GthBrowser *browser)
 
 	g_object_set_data_full (G_OBJECT (browser), BROWSER_DATA_KEY, data, (GDestroyNotify) browser_data_free);
 }
+
+
+void
+pi__import_photos_cb (GthBrowser *browser,
+		      GFile      *source)
+{
+	dlg_photo_importer (browser, source);
+}
diff --git a/extensions/photo_importer/callbacks.h b/extensions/photo_importer/callbacks.h
index 071e32c..a1bb41a 100644
--- a/extensions/photo_importer/callbacks.h
+++ b/extensions/photo_importer/callbacks.h
@@ -26,5 +26,7 @@
 #include <gthumb.h>
 
 void pi__gth_browser_construct_cb (GthBrowser *browser);
+void pi__import_photos_cb         (GthBrowser *browser,
+				   GFile      *source);
 
 #endif /* CALLBACKS_H */
diff --git a/extensions/photo_importer/dlg-photo-importer.c b/extensions/photo_importer/dlg-photo-importer.c
index 0ef1386..4e55b1a 100644
--- a/extensions/photo_importer/dlg-photo-importer.c
+++ b/extensions/photo_importer/dlg-photo-importer.c
@@ -134,6 +134,9 @@ destroy_dialog (gpointer user_data)
 	_g_object_list_unref (data->files);
 	_g_string_list_free (data->general_tests);
 
+	if (! data->import && ImportPhotos)
+		gth_window_close (GTH_WINDOW (data->browser));
+
 	g_free (data);
 }
 
diff --git a/extensions/photo_importer/gth-import-task.c b/extensions/photo_importer/gth-import-task.c
index a80f291..f4e5c3b 100644
--- a/extensions/photo_importer/gth-import-task.c
+++ b/extensions/photo_importer/gth-import-task.c
@@ -54,6 +54,9 @@ gth_import_task_finalize (GObject *object)
 
 	self = GTH_IMPORT_TASK (object);
 
+	if (ImportPhotos)
+		gtk_window_present (GTK_WINDOW (self->priv->browser));
+
 	_g_object_list_unref (self->priv->files);
 	g_object_unref (self->priv->destination);
 	_g_object_unref (self->priv->destination_file);
diff --git a/extensions/photo_importer/main.c b/extensions/photo_importer/main.c
index cd814ee..f9dcada 100644
--- a/extensions/photo_importer/main.c
+++ b/extensions/photo_importer/main.c
@@ -30,6 +30,7 @@
 G_MODULE_EXPORT void
 gthumb_extension_activate (void)
 {
+	gth_hook_add_callback ("import-photos", 10, G_CALLBACK (pi__import_photos_cb), NULL);
 	gth_hook_add_callback ("gth-browser-construct", 10, G_CALLBACK (pi__gth_browser_construct_cb), NULL);
 }
 
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 13657a0..a15a09f 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -1750,33 +1750,35 @@ _gth_browser_close_final_step (gpointer user_data)
 
 	/* Save visualization options only if the window is not maximized. */
 
-	state = gdk_window_get_state (GTK_WIDGET (browser)->window);
-	maximized = (state & GDK_WINDOW_STATE_MAXIMIZED) != 0;
-	if (! maximized && GTK_WIDGET_VISIBLE (browser)) {
-		int width, height;
-
-		gdk_drawable_get_size (GTK_WIDGET (browser)->window, &width, &height);
-		eel_gconf_set_integer (PREF_UI_WINDOW_WIDTH, width);
-		eel_gconf_set_integer (PREF_UI_WINDOW_HEIGHT, height);
-	}
+	if (GTK_WIDGET_REALIZED (browser)) {
+		state = gdk_window_get_state (GTK_WIDGET (browser)->window);
+		maximized = (state & GDK_WINDOW_STATE_MAXIMIZED) != 0;
+		if (! maximized && GTK_WIDGET_VISIBLE (browser)) {
+			int width, height;
+
+			gdk_drawable_get_size (GTK_WIDGET (browser)->window, &width, &height);
+			eel_gconf_set_integer (PREF_UI_WINDOW_WIDTH, width);
+			eel_gconf_set_integer (PREF_UI_WINDOW_HEIGHT, height);
+		}
 
-	pos = gtk_paned_get_position (GTK_PANED (browser->priv->browser_container));
-	if (pos > 0)
-		eel_gconf_set_integer (PREF_UI_BROWSER_SIDEBAR_WIDTH, pos);
+		pos = gtk_paned_get_position (GTK_PANED (browser->priv->browser_container));
+		if (pos > 0)
+			eel_gconf_set_integer (PREF_UI_BROWSER_SIDEBAR_WIDTH, pos);
 
-	pos = _gtk_paned_get_position2 (GTK_PANED (browser->priv->viewer_pane));
-	if (pos > 0)
-		eel_gconf_set_integer (PREF_UI_VIEWER_SIDEBAR_WIDTH, pos);
+		pos = _gtk_paned_get_position2 (GTK_PANED (browser->priv->viewer_pane));
+		if (pos > 0)
+			eel_gconf_set_integer (PREF_UI_VIEWER_SIDEBAR_WIDTH, pos);
 
-	pos = _gtk_paned_get_position2 (GTK_PANED (browser->priv->browser_sidebar));
-	if (pos > 0)
-		eel_gconf_set_integer (PREF_UI_PROPERTIES_HEIGHT, pos);
+		pos = _gtk_paned_get_position2 (GTK_PANED (browser->priv->browser_sidebar));
+		if (pos > 0)
+			eel_gconf_set_integer (PREF_UI_PROPERTIES_HEIGHT, pos);
+	}
 
 	/**/
 
 	gth_hook_invoke ("gth-browser-close", browser);
 
-	if (last_window) {
+	if (GTK_WIDGET_REALIZED (browser) && last_window) {
 		if (eel_gconf_get_boolean (PREF_GO_TO_LAST_LOCATION, TRUE)
 		    && (browser->priv->location != NULL))
 		{
diff --git a/gthumb/gth-main-default-hooks.c b/gthumb/gth-main-default-hooks.c
index b1b8a9a..8478c85 100644
--- a/gthumb/gth-main-default-hooks.c
+++ b/gthumb/gth-main-default-hooks.c
@@ -177,4 +177,13 @@ gth_main_register_default_hooks (void)
 	 * @builder (GtkBuilder*): the dialog ui builder.
 	 **/
 	gth_hook_register ("dlg-preferences-apply", 3);
+
+	/**
+	 * Called at start up time if the --import-photos argument is
+	 * specified.
+	 *
+	 * @browser (GthBrowser*): the main window.
+	 * @file (GFile *): import from this location
+	 **/
+	gth_hook_register ("import-photos", 2);
 }
diff --git a/gthumb/main.c b/gthumb/main.c
index 492245f..21484e2 100644
--- a/gthumb/main.c
+++ b/gthumb/main.c
@@ -199,7 +199,16 @@ unique_app_message_received_cb (UniqueApp         *unique_app,
 		break;
 
 	case COMMAND_IMPORT_PHOTOS:
-		/* gth_browser_activate_action_file_camera_import (NULL, NULL); */
+		window = gth_window_get_current_window ();
+		if (window == NULL)
+			window = gth_browser_new (NULL);
+
+		uri = unique_message_data_get_text (message);
+		location = g_file_new_for_uri (uri);
+		gth_hook_invoke ("import-photos", window, location, NULL);
+
+		g_object_unref (location);
+		g_free (uri);
 		break;
 
 	default:
@@ -237,6 +246,30 @@ open_browser_window (GFile *location)
 
 
 static void
+import_photos_from_location (GFile *location)
+{
+	if (unique_app_is_running (gthumb_app)) {
+		UniqueMessageData *data;
+		char              *uri;
+
+		data = unique_message_data_new ();
+		uri = g_file_get_uri (location);
+		unique_message_data_set_text (data, uri, -1);
+		unique_app_send_message (gthumb_app, COMMAND_IMPORT_PHOTOS, data);
+
+		g_free (uri);
+		unique_message_data_free (data);
+	}
+	else {
+		GtkWidget *window;
+
+		window = gth_browser_new (NULL);
+		gth_hook_invoke ("import-photos", window, location, NULL);
+	}
+}
+
+
+static void
 prepare_application (void)
 {
 	EggSMClient *client = NULL;
@@ -279,6 +312,15 @@ prepare_application (void)
 		return;
 	}
 
+	if (ImportPhotos) {
+		GFile *location;
+
+		location = g_file_new_for_commandline_arg (remaining_args[0]);
+		import_photos_from_location (location);
+
+		return;
+	}
+
 	/* open each location in a new window */
 
 	for (i = 0; (arg = remaining_args[i]) != NULL; i++) {
diff --git a/gthumb/main.h b/gthumb/main.h
index a4b2489..0d03106 100644
--- a/gthumb/main.h
+++ b/gthumb/main.h
@@ -25,6 +25,11 @@
 
 G_BEGIN_DECLS
 
+extern gboolean NewWindow;
+extern gboolean StartInFullscreen;
+extern gboolean StartSlideshow;
+extern gboolean ImportPhotos;
+
 void gth_restart (void);
 
 G_END_DECLS



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