gthumb r2393 - in trunk: . libgthumb src



Author: mjc
Date: Mon Aug 11 14:34:38 2008
New Revision: 2393
URL: http://svn.gnome.org/viewvc/gthumb?rev=2393&view=rev

Log:
2008-08-11  Michael J. Chudobiak  <mjc svn gnome org>

        * libgthumb/file-utils.c: (xfer_file), (file_rename):
        * libgthumb/file-utils.h:
        * libgthumb/gfile-utils.c: (gfile_warning),
        (_empty_file_progress_cb), (gfile_xfer), (gfile_copy),
        (gfile_move):
        * libgthumb/gfile-utils.h:
        * src/dlg-file-utils.c: (dlg_file_rename_series):
        * src/gth-browser-actions-callbacks.c: (catalog_rename),
        (folder_rename), (folder_copy__response_cb):
        More gfile migration by Christophe BisiÃre. Bug #525482.
        Migrated simple (synchronous) file transfer bits of code.

        * src/catalog-web-exporter.c: (export__save_other_files),
        (export__copy_image):
        Purged more gnome-vfs bits from the web exporter.



Modified:
   trunk/ChangeLog
   trunk/libgthumb/file-utils.c
   trunk/libgthumb/file-utils.h
   trunk/libgthumb/gfile-utils.c
   trunk/libgthumb/gfile-utils.h
   trunk/src/catalog-web-exporter.c
   trunk/src/dlg-file-utils.c
   trunk/src/gth-browser-actions-callbacks.c

Modified: trunk/libgthumb/file-utils.c
==============================================================================
--- trunk/libgthumb/file-utils.c	(original)
+++ trunk/libgthumb/file-utils.c	Mon Aug 11 14:34:38 2008
@@ -68,12 +68,6 @@
 #define CHUNK_SIZE 128
 #define MAX_SYMLINKS_FOLLOWED 32
 
-/* empty functions */
-static void _empty_file_progress_cb  (goffset current_num_bytes,
-				      goffset total_num_bytes,
-				      gpointer user_data)
-{
-}
 
 /* Async directory list */
 
@@ -737,35 +731,19 @@
 	   const char *to,
 	   gboolean    move)
 {
-	GError        *ioerror = NULL;
-	GFile         *sfile, *dfile;
-
-	if (same_uri (from, to)) {
-		g_warning ("cannot copy file %s: source and destination are the same\n", from);
-		return FALSE;
-	}
+	GFile      *sfile;
+	GFile      *dfile;
+	gboolean    result;
 
 	sfile = gfile_new (from);
 	dfile = gfile_new (to);
-	if (move)
-		g_file_move (sfile, dfile,
-			     G_FILE_COPY_OVERWRITE,
-			     NULL, _empty_file_progress_cb,
-			     NULL, &ioerror);
-	else
-		g_file_copy (sfile, dfile,
-			     G_FILE_COPY_OVERWRITE,
-			     NULL, _empty_file_progress_cb,
-			     NULL, &ioerror);
+	
+	result = gfile_xfer (sfile, dfile, move);
 
 	g_object_unref (sfile);
 	g_object_unref (dfile);
 	
-	if (ioerror) {
-		g_error_free (ioerror);
-		return FALSE;
-	} else
-		return TRUE;
+	return result;
 }
 
 
@@ -792,29 +770,11 @@
 	return xfer_file (from, to, TRUE);
 }
 
-
-gboolean 
-file_rename (const char  *old_path,
-	     const char  *new_path,
-	     GError     **error)
-{
-	GFile *sfile, *dfile;
-	GError *err = NULL;
-	gboolean result;
-	sfile = gfile_new (old_path);
-	dfile = gfile_new (new_path);
-
-	result = g_file_move (sfile, dfile,
-                              G_FILE_COPY_OVERWRITE,
-                              NULL,
-			      _empty_file_progress_cb,
-			      NULL, &err);
-	if (err)
-		g_propagate_error (error, err);
-	
-	g_object_unref (sfile);
-	g_object_unref (dfile);
-	return result;
+gboolean
+file_rename (const char *from,
+	     const char *to)
+{
+	return xfer_file (from, to, TRUE);
 }
 
 

Modified: trunk/libgthumb/file-utils.h
==============================================================================
--- trunk/libgthumb/file-utils.h	(original)
+++ trunk/libgthumb/file-utils.h	Mon Aug 11 14:34:38 2008
@@ -135,8 +135,7 @@
 gboolean            local_file_move               (const char       *from,
 						   const char       *to);
 gboolean            file_rename                   (const char       *old_path,
-						   const char       *new_path,
-						   GError          **error);
+						   const char       *new_path);
 gboolean            file_unlink                   (const char       *path);
 void		    delete_thumbnail	          (const char       *path);
 gboolean            mime_type_is                  (const char       *mime_type,

Modified: trunk/libgthumb/gfile-utils.c
==============================================================================
--- trunk/libgthumb/gfile-utils.c	(original)
+++ trunk/libgthumb/gfile-utils.c	Mon Aug 11 14:34:38 2008
@@ -92,7 +92,11 @@
 	char *warning;
 	
 	uri = gfile_get_uri (file);
-	warning = g_strdup_printf ("%s: file %s: %s\n", msg, uri, err->message);
+	
+	if (err == NULL)
+		warning = g_strdup_printf ("%s: file %s\n", msg, uri);
+	else
+		warning = g_strdup_printf ("%s: file %s: %s\n", msg, uri, err->message);
 	
 	g_warning (warning);
 	
@@ -518,3 +522,63 @@
 
 	return result;
 }
+
+
+/* Xfer */
+
+
+/* empty functions */
+static void _empty_file_progress_cb  (goffset current_num_bytes,
+				      goffset total_num_bytes,
+				      gpointer user_data)
+{
+}
+
+gboolean
+gfile_xfer (GFile    *sfile,
+	    GFile    *dfile,
+	    gboolean  move)
+{
+	GError *error = NULL;
+
+	if (g_file_equal (sfile, dfile)) {
+		gfile_warning ("cannot copy file: source and destination are the same", 
+			       sfile, 
+			       NULL);
+		return FALSE;
+	}
+
+	if (move)
+		g_file_move (sfile, dfile,
+			     G_FILE_COPY_OVERWRITE,
+			     NULL, _empty_file_progress_cb,
+			     NULL, &error);
+	else
+		g_file_copy (sfile, dfile,
+			     G_FILE_COPY_OVERWRITE,
+			     NULL, _empty_file_progress_cb,
+			     NULL, &error);
+	
+	if (error != NULL) {
+		gfile_warning ("error during file copy", sfile, error);
+		g_error_free (error);
+		return FALSE;
+	}
+	
+	return TRUE;
+}
+
+
+gboolean
+gfile_copy (GFile *sfile,
+	    GFile *dfile)
+{
+	return gfile_xfer (sfile, dfile, FALSE);
+}
+
+gboolean
+gfile_move (GFile *sfile,
+	    GFile *dfile)
+{
+	return gfile_xfer (sfile, dfile, TRUE);
+}

Modified: trunk/libgthumb/gfile-utils.h
==============================================================================
--- trunk/libgthumb/gfile-utils.h	(original)
+++ trunk/libgthumb/gfile-utils.h	Mon Aug 11 14:34:38 2008
@@ -79,6 +79,16 @@
 GFile *       gfile_get_home_dir               (void);
 GFile *       gfile_get_tmp_dir                (void);
 GFile *       gfile_get_temp_dir_name          (void);
-gboolean      gfile_dir_remove_recursive       (GFile *dir);
+gboolean      gfile_dir_remove_recursive       (GFile      *dir);
+
+/* Xfer */
+
+gboolean      gfile_xfer                       (GFile      *sfile,
+		                                GFile      *dfile,
+		                                gboolean    move);
+gboolean      gfile_copy                       (GFile      *sfile,
+		                                GFile      *dfile);
+gboolean      gfile_move                       (GFile      *sfile,
+		                                GFile      *dfile);
 
 #endif /* GFILE_UTILS_H */

Modified: trunk/src/catalog-web-exporter.c
==============================================================================
--- trunk/src/catalog-web-exporter.c	(original)
+++ trunk/src/catalog-web-exporter.c	Mon Aug 11 14:34:38 2008
@@ -2135,57 +2135,95 @@
 static void
 export__save_other_files (CatalogWebExporter *ce)
 {
-	GnomeVFSResult  result;
-	GList          *file_list = NULL;
-	char           *uri;
-		
-	uri = gfile_get_uri (ce->style_dir);
-	result = gnome_vfs_directory_list_load (&file_list, uri, GNOME_VFS_FILE_INFO_DEFAULT);
-		
-	g_free (uri);
-
-	if (result == GNOME_VFS_OK) {
-		GList *scan;
-		GList *source_uri_list = NULL, *target_uri_list =  NULL;
-
-		for (scan = file_list; scan; scan = scan->next) {
-			GnomeVFSFileInfo *info = scan->data;
-			char		 *target_filename, *source_filename;
-			GFile            *source_file, *target_file;
-			GnomeVFSURI	 *source_uri = NULL, *target_uri = NULL;
-
-			if (info->type == GNOME_VFS_FILE_TYPE_DIRECTORY)
-				continue;
-
-			if ((strcmp (info->name, "index.gthtml") == 0)
-			    || (strcmp (info->name, "thumbnail.gthtml") == 0)
-			    || (strcmp (info->name, "image.gthtml") == 0))
-				continue;
-
-			source_file = gfile_append_path (ce->style_dir,
-							 info->name,
-							 NULL);
-			target_file = get_theme_file (ce, 
-					              ce->target_tmp_dir,
-					              info->name);
-
-			source_filename = gfile_get_uri (source_file);
-			source_uri = gnome_vfs_uri_new (source_filename);
-			
-			target_filename = gfile_get_uri (target_file);
-			target_uri = gnome_vfs_uri_new (target_filename);
-			
-			source_uri_list = g_list_prepend (source_uri_list, source_uri);
-			target_uri_list = g_list_prepend (target_uri_list, target_uri);
-
-			gfile_debug (DEBUG_INFO, "save file", source_file);
-
-			g_free (source_filename);
-			g_free (target_filename);
-			g_object_unref (source_file);
-			g_object_unref (target_file);
+	GFileEnumerator  *file_enum;
+	GError           *error = NULL;
+		
+	file_enum = g_file_enumerate_children (ce->style_dir,
+					       G_FILE_ATTRIBUTE_STANDARD_NAME ","
+					       G_FILE_ATTRIBUTE_STANDARD_TYPE,
+					       0, NULL, &error);
+
+	if (error != NULL) {
+		gfile_warning ("Cannot enumerate style directory", 
+			       ce->style_dir, 
+			       error);
+		g_error_free (error);
+	}
+	else {
+		GList *source_uri_list = NULL;
+		GList *target_uri_list = NULL;
+		
+		gboolean enumerate = TRUE;
+		
+		while (enumerate) {
+	
+			GFileInfo        *info;
+	
+			info = g_file_enumerator_next_file (file_enum, NULL, &error);
+			
+			/* error during enumeration */
+			
+			if (error != NULL) {
+				gfile_warning ("Error during enumeration of style directory", 
+					       ce->style_dir, 
+					       error);
+				g_error_free (error);
+				enumerate = FALSE;
+			}
+			
+			/* no more files */
+			
+			else if (info == NULL) {
+				enumerate = FALSE;
+			}
+			
+			/* OK, got a file */
+			
+			else {
+				const char       *name;
+				char		 *target_filename, *source_filename;
+				GFile            *source_file, *target_file;
+				GnomeVFSURI	 *source_uri = NULL, *target_uri = NULL;
+				
+				if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
+					continue;
+		
+				name = g_file_info_get_name (info);
+				
+				if ((strcmp (name, "index.gthtml") == 0)
+				    || (strcmp (name, "thumbnail.gthtml") == 0)
+				    || (strcmp (name, "image.gthtml") == 0))
+					continue;
+		
+				source_file = gfile_append_path (ce->style_dir,
+								 name,
+								 NULL);
+				target_file = get_theme_file (ce, 
+							      ce->target_tmp_dir,
+							      name);
+		
+				source_filename = gfile_get_uri (source_file);
+				source_uri = gnome_vfs_uri_new (source_filename);
+				
+				target_filename = gfile_get_uri (target_file);
+				target_uri = gnome_vfs_uri_new (target_filename);
+				
+				source_uri_list = g_list_prepend (source_uri_list, source_uri);
+				target_uri_list = g_list_prepend (target_uri_list, target_uri);
+		
+				gfile_debug (DEBUG_INFO, "save file", source_file);
+		
+				g_free (source_filename);
+				g_free (target_filename);
+				g_object_unref (source_file);
+				g_object_unref (target_file);
+				
+				g_object_unref (info);
+			}
 		}
 		
+		g_object_unref (file_enum);
+		
 		if (source_uri_list != NULL) {
 			
 			GnomeVFSXferOptions        xfer_options;
@@ -2196,14 +2234,14 @@
 			xfer_options    = 0;
 			xfer_error_mode = GNOME_VFS_XFER_ERROR_MODE_ABORT;
 			overwrite_mode  = GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE;
-
+	
 			result = gnome_vfs_xfer_uri_list (source_uri_list,
-				       			  target_uri_list,
+							  target_uri_list,
 							  xfer_options,
 							  xfer_error_mode,
 							  overwrite_mode,
 							  export__save_other_files__progress_update_cb,
-				 			  ce);
+							  ce);
 		}
 		
 		if (source_uri_list != NULL)
@@ -2211,9 +2249,6 @@
 		if (target_uri_list != NULL)
 			gnome_vfs_uri_list_free (target_uri_list);
 	}
-
-	if (file_list != NULL)
-		gnome_vfs_file_info_list_free (file_list);
 }
 
 
@@ -2606,12 +2641,10 @@
 static void
 export__copy_image (CatalogWebExporter *ce)
 {
-	ImageData                 *idata;
-	GFile                     *file;
-	char                      *uri;
-	GnomeVFSURI               *source_uri = NULL;
-	GnomeVFSURI               *target_uri = NULL;
-	GnomeVFSResult             result;
+	ImageData  *idata;
+	GFile      *sfile;
+	GFile      *dfile;
+	gboolean    copy_done;
 
 	/* This function is used when "Copy originals to destination" is
 	   enabled, and resizing is NOT enabled. This allows us to use a
@@ -2622,26 +2655,18 @@
 
 	idata = ce->file_to_load->data;
 
-	source_uri = gnome_vfs_uri_new (idata->src_file->path);
+	sfile = gfile_new (idata->src_file->path);
 	
-	file = get_image_file (ce, 
-			       idata, 
-			       ce->target_tmp_dir);
-	uri = gfile_get_uri (file);
-	target_uri = gnome_vfs_uri_new (uri);
-		
-	result = gnome_vfs_xfer_uri (source_uri,
-				     target_uri,
-				     GNOME_VFS_XFER_DEFAULT,
-				     GNOME_VFS_XFER_ERROR_MODE_ABORT,
-				     GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
-				     NULL,
-				     NULL);
-
-	gnome_vfs_uri_unref (source_uri);
-	gnome_vfs_uri_unref (target_uri);
+	dfile = get_image_file (ce, 
+			        idata, 
+			        ce->target_tmp_dir);
+		
+	copy_done = gfile_copy (sfile, dfile);
 
-	if (result == GNOME_VFS_OK) {
+	if (copy_done) {
+		char *uri;
+		uri = gfile_get_uri (dfile);
+		
 		if (image_is_jpeg (uri)) {
 			GthTransform  transform;
 		
@@ -2658,10 +2683,11 @@
 
 			file_data_unref (fd);
 		}
+		g_free (uri);
 	}
 	
-	g_object_unref (file);
-	g_free (uri);
+	g_object_unref (sfile);
+	g_object_unref (dfile);
 	
 	ce->saving_timeout = g_timeout_add (SAVING_TIMEOUT,
 					    save_image_preview_cb,

Modified: trunk/src/dlg-file-utils.c
==============================================================================
--- trunk/src/dlg-file-utils.c	(original)
+++ trunk/src/dlg-file-utils.c	Mon Aug 11 14:34:38 2008
@@ -1005,7 +1005,7 @@
 			continue;
 		}
 
-		result = file_rename (old_full_path, new_full_path, NULL);
+		result = file_rename (old_full_path, new_full_path);
 		if (result) {
 			cache_move (old_full_path, new_full_path);
 			comment_move (old_full_path, new_full_path);

Modified: trunk/src/gth-browser-actions-callbacks.c
==============================================================================
--- trunk/src/gth-browser-actions-callbacks.c	(original)
+++ trunk/src/gth-browser-actions-callbacks.c	Mon Aug 11 14:34:38 2008
@@ -509,7 +509,7 @@
 				       _("The name \"%s\" is already used. " "Please use a different name."), utf8_name);
 		g_free (utf8_name);
 	} 
-	else if (file_rename (catalog_path, new_catalog_path, NULL)) {
+	else if (file_rename (catalog_path, new_catalog_path)) {
 		all_windows_notify_catalog_rename (catalog_path,
 						   new_catalog_path);
 	} 
@@ -1031,14 +1031,14 @@
 
 		old_folder_comment = comments_get_comment_filename (old_path, TRUE);
 
-		result = file_rename (old_path, new_path, NULL);
+		result = file_rename (old_path, new_path);
 		if (result) {
 			char *new_folder_comment;
 
 			/* Comment cache. */
 
 			new_folder_comment = comments_get_comment_filename (new_path, TRUE);
-			file_rename (old_folder_comment, new_folder_comment, NULL);
+			file_rename (old_folder_comment, new_folder_comment);
 			g_free (new_folder_comment);
 
 			all_windows_notify_directory_rename (old_path, new_path);
@@ -1341,7 +1341,7 @@
 
 		old_folder_comment = comments_get_comment_filename (old_path, TRUE);
 
-		result = file_rename (old_path, new_path, NULL);
+		result = file_rename (old_path, new_path);
 		if (result) {
 			char *new_folder_comment;
 
@@ -1349,7 +1349,7 @@
 			 * implemeted with rename, which is faster. */
 
 			new_folder_comment = comments_get_comment_filename (new_path, TRUE);
-			file_rename (old_folder_comment, new_folder_comment, NULL);
+			file_rename (old_folder_comment, new_folder_comment);
 			g_free (new_folder_comment);
 
 			all_windows_notify_directory_rename (old_path, new_path);



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