[gthumb] Tidy up photo importer code, remove cache reference



commit 59dd64f9c40d57e6b8b694bf71112335e72a0240
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date:   Mon May 4 13:55:06 2009 -0400

    Tidy up photo importer code, remove cache reference
    
    The importer now supports remote destinations if a gvfs
    mount point is present.
    
    The free-space reporting routine now reports lots of space
    if the gvfs backend doesn't support such reporting.
    
    The ensure-dir-exists routines now check directly for
    directory existence before attempting to create the
    folders.
---
 libgthumb/gfile-utils.c  |    5 ++-
 src/dlg-photo-importer.c |   84 +++++++++++++++++++++++++++-------------------
 2 files changed, 53 insertions(+), 36 deletions(-)

diff --git a/libgthumb/gfile-utils.c b/libgthumb/gfile-utils.c
index ff4e667..f7e3101 100644
--- a/libgthumb/gfile-utils.c
+++ b/libgthumb/gfile-utils.c
@@ -474,6 +474,9 @@ gfile_ensure_dir_exists (GFile    *dir,
         if (error == NULL)
                 error = &priv_error;
 
+	if (gfile_path_is_dir (dir))
+		return TRUE;
+	
         if (! _gfile_make_directory_tree (dir, mode, error)) {
 
                 gfile_warning ("could not create directory", dir, *error);
@@ -490,7 +493,7 @@ gfile_ensure_dir_exists (GFile    *dir,
 guint64
 gfile_get_destination_free_space (GFile *file)
 {
-        guint64    freespace = 0;
+        guint64    freespace = 100000000000; /* bogus value for unsupported systems */
         GFileInfo *info;
         GError    *err = NULL;
 
diff --git a/src/dlg-photo-importer.c b/src/dlg-photo-importer.c
index ff40fb9..03c0265 100644
--- a/src/dlg-photo-importer.c
+++ b/src/dlg-photo-importer.c
@@ -1268,14 +1268,14 @@ save_image (DialogData *data,
 	CameraFile   *file;
 	char         *camera_folder;
 	const char   *camera_filename;
-	char         *local_path;
-	char         *file_uri = NULL;
-	char	     *unescaped_local_folder;
+	char         *initial_dest_path;
+	char         *final_dest_path;
 	time_t        exif_date;
 	GthSubFolder  subfolder_value;
 	char	     *temp_dir = NULL;
 	gboolean      error_found = FALSE;
-	
+	FileData     *folder_fd;
+
 	gp_file_new (&file);
 
 	camera_folder = remove_level_from_path (camera_path);
@@ -1288,23 +1288,35 @@ save_image (DialogData *data,
 			    data->context);
 
 	subfolder_value = gtk_combo_box_get_active (GTK_COMBO_BOX (data->subfolder_combobox));
-	unescaped_local_folder = gnome_vfs_unescape_string (local_folder, "");
-
-	/* When grouping by exif date, we need a temporary directory to upload the
-	   photo to. The exif date tags are then read, and the file is then moved
-	   to its final destination. */
-	if ( (subfolder_value == GTH_IMPORT_SUBFOLDER_GROUP_DAY) || 
-	     (subfolder_value == GTH_IMPORT_SUBFOLDER_GROUP_MONTH) || 
-	     (subfolder_value == GTH_IMPORT_SUBFOLDER_GROUP_CUSTOM)) {
-		temp_dir = get_temp_dir_name ();
-		local_path = get_temp_file_name (temp_dir, NULL);
+
+	folder_fd = file_data_new (local_folder);
+
+	if (folder_fd->local_path == NULL) {
+		error_found = TRUE;
 	} else {
-		/* Otherwise, the images go straight into the destination folder */
-		file_uri = get_file_name (data, camera_path, unescaped_local_folder, n);
-		local_path = get_cache_filename_from_uri (file_uri);		
+		/* When grouping by exif date, we need a temporary directory to upload the
+		   photo to. The exif date tags are then read, and the file is then moved
+		   to its final destination. */
+		if ( (subfolder_value == GTH_IMPORT_SUBFOLDER_GROUP_DAY) || 
+		     (subfolder_value == GTH_IMPORT_SUBFOLDER_GROUP_MONTH) || 
+		     (subfolder_value == GTH_IMPORT_SUBFOLDER_GROUP_CUSTOM)) {
+			temp_dir = get_temp_dir_name ();
+			if (temp_dir == NULL) {
+				error_found = TRUE;
+			} else {
+				initial_dest_path = get_temp_file_name (temp_dir, NULL);
+			}
+		} else {
+			/* Otherwise, the images go straight into the destination folder */
+			initial_dest_path = get_file_name (data, camera_path, folder_fd->local_path, n);
+		}
+	}
+
+	if (initial_dest_path == NULL) {
+		error_found = TRUE;
 	}
 
-	if ( (local_path != NULL) && gp_file_save (file, local_path) >= 0) {
+	if ((error_found == FALSE) && gp_file_save (file, initial_dest_path) >= 0) {
 
 		if ( (subfolder_value == GTH_IMPORT_SUBFOLDER_GROUP_DAY) || 
 		     (subfolder_value == GTH_IMPORT_SUBFOLDER_GROUP_MONTH) || 
@@ -1313,12 +1325,11 @@ save_image (DialogData *data,
 			FileData *file;
 
 			/* Name a subfolder based on the exif date */
-                        file = file_data_new (local_path);
+                        file = file_data_new (initial_dest_path);
                         file_data_update_all (file, FALSE);
 			exif_date = get_exif_time_or_mtime (file);
 			file_data_unref (file);
 
-
 			if (exif_date != (time_t) 0) {
 				struct tm  *exif_tm = localtime(&exif_date);
 				char        dest_subfolder[255 + 1];
@@ -1358,18 +1369,18 @@ save_image (DialogData *data,
 					tmp++;
 				}
 
-				dest_folder = g_build_filename (unescaped_local_folder, dest_subfolder, NULL);
+				dest_folder = g_build_filename (folder_fd->local_path, dest_subfolder, NULL);
 			} else {
 				/* If no exif data was found, use the base folder */
-				dest_folder = g_strdup (unescaped_local_folder);
+				dest_folder = g_strdup (folder_fd->local_path);
 			}
 
-			file_uri = get_file_name (data, camera_path, dest_folder, n);
+			final_dest_path = get_file_name (data, camera_path, dest_folder, n);
 
 			/* Create the subfolder if necessary, and move the 
 			   temporary file to it */
 			if (ensure_dir_exists (dest_folder, 0755) ) {
-				if (!file_move (local_path, file_uri)) {
+				if (!file_move (initial_dest_path, final_dest_path)) {
 					error_found = TRUE;
 				}
 			} else {
@@ -1380,17 +1391,19 @@ save_image (DialogData *data,
 			data->last_folder = g_strdup (dest_folder);
 
 			g_free (dest_folder);
+		} else {
+			final_dest_path = g_strdup (initial_dest_path);
 		}
 
 		/* Adjust the photo orientation based on the exif 
 		   orientation tag, if requested */
 		if (!error_found) {
 			if (data->adjust_orientation) 
-				data->adjust_orientation_list = g_list_prepend (data->adjust_orientation_list, g_strdup (file_uri));
+				data->adjust_orientation_list = g_list_prepend (data->adjust_orientation_list, g_strdup (final_dest_path));
 			if (data->delete_from_camera)
 				data->delete_list = g_list_prepend (data->delete_list, g_strdup (camera_path));
-			data->saved_images_list = g_list_prepend (data->saved_images_list, g_strdup (file_uri));
-			add_categories_to_image (data, local_path);
+			data->saved_images_list = g_list_prepend (data->saved_images_list, g_strdup (final_dest_path));
+			add_categories_to_image (data, final_dest_path);
 		}
 	} 
 	else {
@@ -1410,11 +1423,11 @@ save_image (DialogData *data,
 		g_free (temp_dir);
 	}
 		
-	g_free (unescaped_local_folder);
 	g_free (camera_folder);
-	g_free (file_uri);
-	g_free (local_path);
+	g_free (final_dest_path);
+	g_free (initial_dest_path);
 	gp_file_unref (file);
+	file_data_unref (folder_fd);
 }
 
 static void
@@ -1692,6 +1705,7 @@ ok_clicked_cb (GtkButton  *button,
 	GList    *sel_list;
 	gboolean  error;
 	goffset   total_size = 0;
+	FileData *folder_fd;
 
 	if (!data->camera_setted) {
 		display_error_dialog (data,
@@ -1750,22 +1764,22 @@ ok_clicked_cb (GtkButton  *button,
 		return;
 	}
 
-	if (! ensure_dir_exists (data->local_folder, 0755)) {
-		char *utf8_path;
+	folder_fd = file_data_new (data->local_folder);
+	if ((folder_fd->local_path==NULL) || !ensure_dir_exists (folder_fd->local_path, 0755)) {
 		char *msg;
-		utf8_path = get_utf8_display_name_from_uri (data->local_folder);
 		msg = g_strdup_printf (_("Could not create the folder \"%s\": %s"),
-				       utf8_path,
+				       folder_fd->utf8_name,
 				       errno_to_string ());
 		display_error_dialog (data, _("Could not import photos"), msg);
 
-		g_free (utf8_path);
 		g_free (msg);
 		g_free (data->local_folder);
 		data->local_folder = NULL;
 		path_list_free (file_list);
+		file_data_unref (folder_fd);
 		return;
 	}
+	file_data_unref (folder_fd);
 
 	if (! can_read_write_execute (data->local_folder)) {
 		char *utf8_path;



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