[gthumb] Use gfile functions to get get_utf8_display_name_from_uri



commit 3cf368c6ac68c83805c8410413b67d978a8e3670
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date:   Wed Apr 22 12:47:06 2009 -0400

    Use gfile functions to get get_utf8_display_name_from_uri
    
    Hopefully this fixes all those exotic filesystem character-set
    problems. Also, an unrelated crash in the web exporter was fixed.
---
 libgthumb/file-utils.c     |   39 +++++++++++++++++++++++++--------------
 src/catalog-web-exporter.c |    6 +++---
 2 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/libgthumb/file-utils.c b/libgthumb/file-utils.c
index 37ac955..e4ba72e 100644
--- a/libgthumb/file-utils.c
+++ b/libgthumb/file-utils.c
@@ -1055,23 +1055,34 @@ set_file_mtime (const gchar *path,
 char *
 get_utf8_display_name_from_uri (const char *escaped_uri)
 {
-	char        *unescaped_name = NULL;
 	char        *utf8_name = NULL;
-	GError      *err = NULL;
+	GFile       *gfile;
+
+	/* g_file_get_parse_name can handle escaped and unescaped uris */
+
+	if (strcmp (escaped_uri,"/") == 0) {
+		utf8_name = g_strdup ("/");
+	} else if (strcmp (escaped_uri,"..") == 0) {
+		utf8_name = g_strdup ("..");
+	} else if (uri_has_scheme (escaped_uri) || escaped_uri[0]=='/') {
+        	gfile = gfile_new (escaped_uri);
+		utf8_name = g_file_get_parse_name (gfile);
+        	g_object_unref (gfile);
+	} else {
+		char *result;
+		char *fake_uri;
 
-	unescaped_name = gnome_vfs_unescape_string_for_display (escaped_uri);
-	utf8_name = g_filename_to_utf8 (unescaped_name, -1, NULL, NULL, &err);
+		/* This is a bit hackish. */
+		fake_uri = g_strconcat ("file:///", escaped_uri, NULL);
+                gfile = gfile_new (fake_uri);
+                result = g_file_get_parse_name (gfile);
+                g_object_unref (gfile);
 
-	if (err != NULL) {
-		g_warning ("%s:%u:%s(): %s\n", __FILE__, __LINE__, __FUNCTION__, err->message);
-		g_warning ("Hint: try to set G_FILENAME_ENCODING environment variable to the correct filename encoding or G_BROKEN_FILENAMES to 1\n");
-		utf8_name = unescaped_name;
-	} else {
-		g_free (unescaped_name);
+		/* g_file_get_parse_name strips off the "file://" bit,
+		   we need to skip the one remaining leading slash */
+		utf8_name = g_strdup_printf ("%s",result+1);
+		g_free (result);
 	}
-
-	if (g_utf8_validate (utf8_name, -1, NULL) == FALSE)
-		g_warning ("File display name is not valid UTF8. Please file a bug report.\n");
 		
 	return utf8_name;
 }
diff --git a/src/catalog-web-exporter.c b/src/catalog-web-exporter.c
index 1d92e1b..bd2a3f5 100644
--- a/src/catalog-web-exporter.c
+++ b/src/catalog-web-exporter.c
@@ -2139,12 +2139,12 @@ export__copy_to_destination__step2 (GError 	   *error,
 {
 	CatalogWebExporter *ce = data;
 
-	debug (DEBUG_INFO, "result: %s", error->message);
-
-	if (error != NULL)
+	if (error != NULL) {
+		debug (DEBUG_INFO, "result: %s", error->message);
 		_gtk_error_dialog_run (GTK_WINDOW (ce->window),
 				       "%s",
 				       error->message);
+	}
 
 	dlg_folder_delete (ce->window,
 			   ce->base_tmp_dir,



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