[gthumb] Simplify catalog deletion using g_file_delete



commit e15fdca484ebb3b7d7e8e143dabafa14a260887e
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date:   Tue May 12 10:37:33 2009 -0400

    Simplify catalog deletion using g_file_delete
---
 libgthumb/file-utils.c              |   63 +++--------------------------------
 libgthumb/file-utils.h              |    5 +--
 src/gth-browser-actions-callbacks.c |   10 ++----
 3 files changed, 9 insertions(+), 69 deletions(-)

diff --git a/libgthumb/file-utils.c b/libgthumb/file-utils.c
index ac9ad9c..517a429 100644
--- a/libgthumb/file-utils.c
+++ b/libgthumb/file-utils.c
@@ -1796,67 +1796,14 @@ get_catalog_full_path (const char *relative_path)
 }
 
 
-gboolean
-delete_catalog_dir (const char  *full_path,
-		    gboolean     recursive,
-		    GError     **gerror)
-{
-	if (dir_remove (full_path))
-		return TRUE;
-
-	if (gerror != NULL) {
-		char       *utf8_path;
-		const char *details;
-
-		utf8_path = basename_for_display (full_path);
-
-		switch (gnome_vfs_result_from_errno ()) {
-		case GNOME_VFS_ERROR_DIRECTORY_NOT_EMPTY:
-			details = _("Library not empty");
-			break;
-		default:
-			details = errno_to_string ();
-			break;
-		}
-
-		*gerror = g_error_new (GTHUMB_ERROR,
-				       errno,
-				       _("Cannot remove library \"%s\": %s"),
-				       utf8_path,
-				       details);
-		g_free (utf8_path);
-	}
-
-	return FALSE;
-}
-
-
-gboolean
+void
 delete_catalog (const char  *full_path,
 		GError     **gerror)
 {
-	if (! file_unlink (full_path)) {
-		if (gerror != NULL) {
-			const char *rel_path;
-			char       *base_path;
-			char       *catalog;
-
-			base_path = get_catalog_full_path (NULL);
-			rel_path = full_path + strlen (base_path) + 1;
-			g_free (base_path);
-			catalog = remove_extension_from_path (rel_path);
-
-			*gerror = g_error_new (GTHUMB_ERROR,
-					       errno,
-					       _("Cannot remove catalog \"%s\": %s"),
-					       catalog,
-					       errno_to_string ());
-			g_free (catalog);
-		}
-		return FALSE;
-	}
-
-	return TRUE;
+	GFile *gfile;
+	gfile = gfile_new (full_path);
+	g_file_delete (gfile, NULL, gerror);
+	g_object_unref (gfile);
 }
 
 
diff --git a/libgthumb/file-utils.h b/libgthumb/file-utils.h
index 544e989..dd3591e 100644
--- a/libgthumb/file-utils.h
+++ b/libgthumb/file-utils.h
@@ -178,10 +178,7 @@ gboolean            uri_is_root                   (const char       *uri);
 /* Catalogs */
 
 char *              get_catalog_full_path         (const char       *relative_path);
-gboolean            delete_catalog_dir            (const char       *full_path,
-						   gboolean          recursive,
-						   GError          **error);
-gboolean            delete_catalog                (const char       *full_path,
+void                delete_catalog                (const char       *full_path,
 						   GError          **error);
 gboolean            file_is_search_result         (const char       *full_path);
 
diff --git a/src/gth-browser-actions-callbacks.c b/src/gth-browser-actions-callbacks.c
index dfa4d06..f931148 100644
--- a/src/gth-browser-actions-callbacks.c
+++ b/src/gth-browser-actions-callbacks.c
@@ -549,20 +549,16 @@ static void
 real_catalog_delete (GthBrowser *browser)
 {
 	char     *catalog_path;
-	GError   *gerror;
-	gboolean  error;
+	GError   *error = NULL;
 
 	catalog_path = catalog_list_get_selected_path (gth_browser_get_catalog_list (browser));
 	if (catalog_path == NULL)
 		return;
 
-	if (path_is_dir (catalog_path))
-		error = ! delete_catalog_dir (catalog_path, TRUE, &gerror);
-	else
-		error = ! delete_catalog (catalog_path, &gerror);
+	delete_catalog (catalog_path, &error);
 
 	if (error)
-		_gtk_error_dialog_from_gerror_run (GTK_WINDOW (browser), &gerror);
+		_gtk_error_dialog_from_gerror_run (GTK_WINDOW (browser), &error);
 
 	all_windows_notify_catalog_delete (catalog_path);
 	g_free (catalog_path);



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