[gthumb] Try to feed gfile generated from command line to the photo importer



commit dd898ff84d2894c3d7df24e38a5e63563445afcc
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date:   Mon Jun 8 09:46:51 2009 -0400

    Try to feed gfile generated from command line to the photo importer
    
    Something is still broken when plugging in camera, though. Something
    weird in the gphoto backend, probably.
---
 src/dlg-photo-importer.c |   36 +++++++++++++++++++++---------------
 src/dlg-photo-importer.h |    2 +-
 src/main.c               |   43 +++++++++++++++++++++++++------------------
 3 files changed, 47 insertions(+), 34 deletions(-)

diff --git a/src/dlg-photo-importer.c b/src/dlg-photo-importer.c
index d8f9ab9..f41e2bd 100644
--- a/src/dlg-photo-importer.c
+++ b/src/dlg-photo-importer.c
@@ -128,7 +128,7 @@ struct _DialogData {
 
 	GList               *dcim_dirs;
 	gboolean	     dcim_dirs_only;
-	char		    *uri;
+	GFile		    *gfile_import_from;
 };
 
 
@@ -359,7 +359,9 @@ destroy_cb (GtkWidget  *widget,
 	g_free (data->msg_text);
 	g_free (data->main_dest_folder);
 	g_free (data->last_folder);
-	g_free (data->uri);
+
+	if (data->gfile_import_from)
+		g_object_unref (data->gfile_import_from);
 
 	gfile_list_free (data->dcim_dirs);
 	path_list_free (data->tags_list);
@@ -547,28 +549,29 @@ get_all_files (DialogData *data)
 	GFile *gfile;
 	GList *file_list = NULL;
 	GList *scan;
+	char  *utf8_path = NULL;
 
 	if (data->dcim_dirs != NULL) {
 		gfile_list_free (data->dcim_dirs);	
 		data->dcim_dirs = NULL;
 	}
 
-	if (data->uri && !path_is_dir (data->uri)) {
-		_gtk_info_dialog_run (GTK_WINDOW (data->dialog), _("%s is not a valid directory, scanning for attached devices instead"), data->uri);
-		g_free (data->uri);
-		data->uri = NULL;
-	}
+	if (data->gfile_import_from)
+		utf8_path = g_file_get_parse_name (data->gfile_import_from);
 
-	if (data->uri) {
+	if (data->gfile_import_from && !gfile_is_dir (data->gfile_import_from)) {
+		_gtk_info_dialog_run (GTK_WINDOW (data->dialog), _("%s is not a valid directory, scanning for attached devices instead"), utf8_path);
+	} else if (data->gfile_import_from) {
 		if (data->dcim_dirs_only) {
-			gfile = gfile_new (data->uri);
-			data->dcim_dirs = gfile_import_dir_list_recursive (gfile, data->dcim_dirs, NULL, 0);
-	                g_object_unref (gfile);
+			data->dcim_dirs = gfile_import_dir_list_recursive (data->gfile_import_from,
+									   data->dcim_dirs, NULL, 0);
 		} else {
-			data->dcim_dirs = g_list_prepend (data->dcim_dirs, gfile_new (data->uri));
+			data->dcim_dirs = g_list_prepend (data->dcim_dirs,
+							  data->gfile_import_from);
 			}
+
 		if (!file_list) {
-			_gtk_info_dialog_run (GTK_WINDOW (data->dialog), _("No files found in %s, scanning for attached devices instead"), data->uri);
+			_gtk_info_dialog_run (GTK_WINDOW (data->dialog), _("No files found in %s, scanning for attached devices instead"), utf8_path);
 		}
 	}
 
@@ -589,6 +592,7 @@ get_all_files (DialogData *data)
 		file_list = gfile_import_file_list_recursive (gfile, file_list);
 	}
 
+	g_free (utf8_path);
 	return file_list;
 }
 
@@ -1546,7 +1550,7 @@ help_cb (GtkWidget  *widget,
 
 void
 dlg_photo_importer (GthBrowser *browser,
-		    const char *uri,
+		    GFile      *gfile_import_from,
 		    gboolean    dcim_dirs_only)
 {
 	DialogData *data;
@@ -1577,7 +1581,9 @@ dlg_photo_importer (GthBrowser *browser,
 
 	data->dcim_dirs = NULL;
 	data->dcim_dirs_only = dcim_dirs_only;
-	data->uri = g_strdup (uri);
+	data->gfile_import_from = gfile_import_from;
+	if (gfile_import_from)
+		g_object_ref (gfile_import_from);
 
 	/* Get the widgets. */
 
diff --git a/src/dlg-photo-importer.h b/src/dlg-photo-importer.h
index 9c18486..303a271 100644
--- a/src/dlg-photo-importer.h
+++ b/src/dlg-photo-importer.h
@@ -26,7 +26,7 @@
 #include "gth-browser.h"
 
 void   dlg_photo_importer (GthBrowser *browser,
-			   const char *uri,
+			   GFile      *gfile_import_from,
 			   gboolean    dcim_dirs_only);
 
 #endif /* DLG_PHOTO_IMPORTER_H */
diff --git a/src/main.c b/src/main.c
index 64a860d..5ce3636 100644
--- a/src/main.c
+++ b/src/main.c
@@ -32,6 +32,7 @@
 #include "main.h"
 #include "dlg-photo-importer.h"
 #include "file-utils.h"
+#include "gfile-utils.h"
 #include "glib-utils.h"
 #include "gconf-utils.h"
 #include "gtk-utils.h"
@@ -64,7 +65,8 @@ static char*icon_mime_name[ICON_NAMES] = { "gnome-fs-directory",
 					   "gnome-fs-desktop" };
 
 GList         *file_urls = NULL, *dir_urls = NULL;
-int            n_file_urls, n_dir_urls;
+GList         *file_gfiles = NULL, *dir_gfiles = NULL;
+int            n_files, n_dirs;
 int            StartInFullscreen = FALSE;
 int            StartSlideshow = FALSE;
 int            ViewFirstImage = FALSE;
@@ -476,21 +478,22 @@ initialize_data (void)
 			continue;
 		}
 
-		if (file_type == G_FILE_TYPE_DIRECTORY)
+		if (file_type == G_FILE_TYPE_DIRECTORY) {
 			dir_urls = g_list_prepend (dir_urls, path);
-		else
+			dir_gfiles = g_list_prepend (dir_gfiles, gfile);
+		} else {
 			file_urls = g_list_prepend (file_urls, path);
-
-		g_object_unref (gfile);
+			file_gfiles = g_list_prepend (file_gfiles, gfile);
+			}
 	}
 
-	n_file_urls = g_list_length (file_urls);
-	n_dir_urls = g_list_length (dir_urls);
+	n_files = g_list_length (file_gfiles);
+	n_dirs = g_list_length (dir_gfiles);
 
-	if (n_file_urls == 1)
+	if (n_files == 1)
 		view_single_image = TRUE;
 
-	if (n_file_urls > 1) {
+	if (n_files > 1) {
 		/* Create a catalog with the command line list. */
 		Catalog *catalog;
 		char    *catalog_path;
@@ -636,19 +639,21 @@ prepare_app (void)
 	}
 
 	if (ImportPhotos) {
-		const char *import_dir = NULL;
+		GFile *import_dir = NULL;
 
-		if (dir_urls)
-			import_dir = (char *) dir_urls->data;
-		
-		if (use_factory)
-		 	GNOME_GThumb_Application_import_photos (app, import_dir, &env);
-		else
+		if (dir_gfiles)
+			import_dir = (GFile *) dir_gfiles->data;
+
+// This is broken, because I don't know how to use bonobo to pass a gfile argument.
+// FIXME		
+//		if (use_factory)
+//		 	GNOME_GThumb_Application_import_photos (app, import_dir, &env);
+//		else
 			dlg_photo_importer (NULL, import_dir, TRUE);
 	} 
 	else if (! view_comline_catalog
-		 && (n_dir_urls == 0)
-		 && (n_file_urls == 0)) 
+		 && (n_dirs == 0)
+		 && (n_files == 0)) 
 	{
 		open_browser_window (NULL, TRUE, use_factory, app, &env);
 	} 
@@ -687,6 +692,8 @@ prepare_app (void)
 
 	path_list_free (file_urls);
 	path_list_free (dir_urls);
+	gfile_list_free (file_gfiles);
+	gfile_list_free (dir_gfiles);
 
 	/**/
 



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