[gthumb] Added the "command line" special catalog



commit 25a0485cbdbb8b3fcd6d51df58a2c6c446a6ab81
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sat Jan 16 19:01:33 2010 +0100

    Added the "command line" special catalog
    
    create the "command line" catalog if more than a file is specified
    at command line.

 extensions/catalogs/callbacks.c |   24 +++++++++++++++++
 extensions/catalogs/callbacks.h |    3 +-
 extensions/catalogs/main.c      |    1 +
 extensions/exiv2/Makefile.am    |    2 +-
 gthumb/gth-main-default-hooks.c |   12 ++++++++-
 gthumb/main.c                   |   54 +++++++++++++++++++++++++++++---------
 6 files changed, 80 insertions(+), 16 deletions(-)
---
diff --git a/extensions/catalogs/callbacks.c b/extensions/catalogs/callbacks.c
index 0d1c2d6..9c9d825 100644
--- a/extensions/catalogs/callbacks.c
+++ b/extensions/catalogs/callbacks.c
@@ -247,6 +247,30 @@ catalogs__gth_browser_update_sensitivity_cb (GthBrowser *browser)
 }
 
 
+GFile *
+catalogs__command_line_files_cb (GList *files)
+{
+	GFile      *file;
+	GthCatalog *catalog;
+	GList      *scan;
+
+	if (g_list_length (files) <= 1)
+		return NULL;
+
+	file = g_file_new_for_uri ("catalog://command_line.catalog");
+	catalog = gth_catalog_new ();
+	gth_catalog_set_file (catalog, file);
+	gth_catalog_set_name (catalog, _("Command Line"));
+	for (scan = files; scan; scan = scan->next)
+		gth_catalog_insert_file (catalog, (GFile *) scan->data, -1);
+	gth_catalog_save (catalog);
+
+	g_object_unref (catalog);
+
+	return file;
+}
+
+
 GthCatalog *
 catalogs__gth_catalog_load_from_data_cb (const void *buffer)
 {
diff --git a/extensions/catalogs/callbacks.h b/extensions/catalogs/callbacks.h
index 8a0b794..387cf0e 100644
--- a/extensions/catalogs/callbacks.h
+++ b/extensions/catalogs/callbacks.h
@@ -33,7 +33,8 @@ void catalogs__gth_browser_file_list_popup_before_cb      (GthBrowser    *browse
 void catalogs__gth_browser_file_popup_before_cb           (GthBrowser    *browser);
 void catalogs__gth_browser_folder_tree_popup_before_cb    (GthBrowser    *browser,
 							   GthFileSource *file_source,
-					                   GFile         *folder);
+							   GFile         *folder);
+GFile *      catalogs__command_line_files_cb              (GList         *files);
 GthCatalog * catalogs__gth_catalog_load_from_data_cb      (const void    *buffer);
 void         catalogs__gth_browser_load_location_after_cb (GthBrowser    *browser,
 					                   GFile         *location,
diff --git a/extensions/catalogs/main.c b/extensions/catalogs/main.c
index a61dd31..6ad566e 100644
--- a/extensions/catalogs/main.c
+++ b/extensions/catalogs/main.c
@@ -67,6 +67,7 @@ gthumb_extension_activate (void)
 	 **/
 	gth_hook_register ("dlg-catalog-properties-saved", 3);
 
+	gth_hook_add_callback ("command-line-files", 10, G_CALLBACK (catalogs__command_line_files_cb), NULL);
 	gth_hook_add_callback ("gth-catalog-load-from-data", 10, G_CALLBACK (catalogs__gth_catalog_load_from_data_cb), NULL);
 
 	gth_main_register_file_source (GTH_TYPE_FILE_SOURCE_CATALOGS);
diff --git a/extensions/exiv2/Makefile.am b/extensions/exiv2/Makefile.am
index 8edf668..f905128 100644
--- a/extensions/exiv2/Makefile.am
+++ b/extensions/exiv2/Makefile.am
@@ -16,7 +16,7 @@ libexiv2_la_SOURCES = 			\
 
 libexiv2_la_CPPFLAGS = $(GTHUMB_CFLAGS) $(EXIV2_CFLAGS) -I$(top_srcdir) -I$(top_builddir)/gthumb 
 libexiv2_la_LDFLAGS = $(EXTENSION_LIBTOOL_FLAGS)
-libexiv2_la_LIBADD = $(GTHUMB_LIBS) $(EXIV2_LIBS)
+libexiv2_la_LIBADD = $(GTHUMB_LIBS)
 libexiv2_la_DEPENDENCIES = $(top_builddir)/gthumb/gthumb$(EXEEXT)
 
 extensioninidir = $(extensiondir)
diff --git a/gthumb/gth-main-default-hooks.c b/gthumb/gth-main-default-hooks.c
index 6fe29e3..46bf49c 100644
--- a/gthumb/gth-main-default-hooks.c
+++ b/gthumb/gth-main-default-hooks.c
@@ -224,7 +224,6 @@ gth_main_register_default_hooks (void)
 	 **/
 	gth_hook_register ("import-photos", 2);
 
-
 	/**
 	 * Called at start up time if the --slideshow argument is
 	 * specified.
@@ -232,4 +231,15 @@ gth_main_register_default_hooks (void)
 	 * @browser (GthBrowser*): the main window.
 	 **/
 	gth_hook_register ("slideshow", 1);
+
+	/**
+	 * Called at start up time with the list of the command line
+	 * files.
+	 *
+	 * @file_list (GList *): list of GFile with the files specified
+	 * on the command line.
+	 * @return (GFile *): the location where to open the window at or NULL
+	 * for nothing.
+	 **/
+	gth_hook_register ("command-line-files", 1);
 }
diff --git a/gthumb/main.c b/gthumb/main.c
index 2c957c1..648ae75 100644
--- a/gthumb/main.c
+++ b/gthumb/main.c
@@ -290,25 +290,29 @@ prepare_application (void)
 	EggSMClient *client = NULL;
 	const char  *arg;
 	int          i;
+	GList       *files;
+	GList       *dirs;
+	GFile       *location;
+	GList       *scan;
 
 	gthumb_app = unique_app_new_with_commands ("org.gnome.gthumb", NULL,
 						   "import-photos", COMMAND_IMPORT_PHOTOS,
 						   NULL);
 
-	if (! unique_app_is_running (gthumb_app)) {
-		gth_main_register_default_hooks ();
-		gth_main_register_file_source (GTH_TYPE_FILE_SOURCE_VFS);
-		gth_main_register_default_sort_types ();
-		gth_main_register_default_tests ();
-		gth_main_register_default_types ();
-		gth_main_register_default_metadata ();
-		gth_main_activate_extensions ();
-		gth_hook_invoke ("initialize", NULL);
+	gth_main_register_default_hooks ();
+	gth_main_register_file_source (GTH_TYPE_FILE_SOURCE_VFS);
+	gth_main_register_default_sort_types ();
+	gth_main_register_default_tests ();
+	gth_main_register_default_types ();
+	gth_main_register_default_metadata ();
+	gth_main_activate_extensions ();
+	gth_hook_invoke ("initialize", NULL);
+
+	if (! unique_app_is_running (gthumb_app))
 		g_signal_connect (gthumb_app,
 				  "message-received",
 				  G_CALLBACK (unique_app_message_received_cb),
 				  NULL);
-	}
 
 	client = egg_sm_client_get ();
 	if (egg_sm_client_is_resumed (client)) {
@@ -337,16 +341,40 @@ prepare_application (void)
 		return;
 	}
 
-	/* open each location in a new window */
+	/* At least a location was specified */
 
+	files = NULL;
+	dirs = NULL;
 	for (i = 0; (arg = remaining_args[i]) != NULL; i++) {
-		GFile *location;
+		GFile     *location;
+		GFileType  file_type;
 
 		location = g_file_new_for_commandline_arg (arg);
-		open_browser_window (location);
+		file_type = _g_file_get_standard_type (location);
+		if (file_type == G_FILE_TYPE_REGULAR)
+			files = g_list_prepend (files, location);
+		else
+			dirs = g_list_prepend (dirs, location);
+	}
+	files = g_list_reverse (files);
+	dirs = g_list_reverse (dirs);
 
+	location = gth_hook_invoke_get ("command-line-files", files);
+	if (location != NULL) {
+		open_browser_window (location);
 		g_object_unref (location);
 	}
+	else /* Open each file in a new window */
+		for (scan = files; scan; scan = scan->next)
+			open_browser_window ((GFile *) scan->data);
+
+	/* Open each dir in a new window */
+
+	for (scan = dirs; scan; scan = scan->next)
+		open_browser_window ((GFile *) scan->data);
+
+	_g_object_list_unref (dirs);
+	_g_object_list_unref (files);
 }
 
 



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