[eog] Make eog_image_get_caption() use GFileInfo



commit e7bf0daef3c73bedcce3b59f59bcb8886003fed3
Author: Felix Riemann <friemann gnome org>
Date:   Sat Dec 1 20:15:56 2012 +0100

    Make eog_image_get_caption() use GFileInfo
    
    GFileInfo has everything needed to get a UTF8-formatted filename
    that can be displayed in the UI.

 src/eog-image.c |   77 ++++++++-----------------------------------------------
 1 files changed, 11 insertions(+), 66 deletions(-)
---
diff --git a/src/eog-image.c b/src/eog-image.c
index 9098802..4ce2e60 100644
--- a/src/eog-image.c
+++ b/src/eog-image.c
@@ -2015,30 +2015,6 @@ eog_image_save_as_by_info (EogImage *img, EogImageSaveInfo *source, EogImageSave
 	return success;
 }
 
-
-/*
- * This function is extracted from
- * File: nautilus/libnautilus-private/nautilus-file.c
- * Revision: 1.309
- * Author: Darin Adler <darin bentspoon com>
- */
-static gboolean
-have_broken_filenames (void)
-{
-	static gboolean initialized = FALSE;
-	static gboolean broken;
-
-	if (initialized) {
-		return broken;
-	}
-
-	broken = g_getenv ("G_BROKEN_FILENAMES") != NULL;
-
-	initialized = TRUE;
-
-	return broken;
-}
-
 /*
  * This function is inspired by
  * nautilus/libnautilus-private/nautilus-file.c:nautilus_file_get_display_name_nocopy
@@ -2049,11 +2025,7 @@ const gchar*
 eog_image_get_caption (EogImage *img)
 {
 	EogImagePrivate *priv;
-	char *name;
-	char *utf8_name;
-	char *scheme;
-	gboolean validated = FALSE;
-	gboolean broken_filenames;
+	GFileInfo *info;
 
 	g_return_val_if_fail (EOG_IS_IMAGE (img), NULL);
 
@@ -2065,45 +2037,19 @@ eog_image_get_caption (EogImage *img)
 		/* Use cached caption string */
 		return priv->caption;
 
-	name = g_file_get_basename (priv->file);
-	scheme = g_file_get_uri_scheme (priv->file);
-
-	if (name != NULL && g_ascii_strcasecmp (scheme, "file") == 0) {
-		/* Support the G_BROKEN_FILENAMES feature of
-		 * glib by using g_filename_to_utf8 to convert
-		 * local filenames to UTF-8. Also do the same
-		 * thing with any local filename that does not
-		 * validate as good UTF-8.
-		 */
-		broken_filenames = have_broken_filenames ();
-
-		if (broken_filenames || !g_utf8_validate (name, -1, NULL)) {
-			utf8_name = g_locale_to_utf8 (name, -1, NULL, NULL, NULL);
-			if (utf8_name != NULL) {
-				g_free (name);
-				name = utf8_name;
-				/* Guaranteed to be correct utf8 here */
-				validated = TRUE;
-			}
-		} else if (!broken_filenames) {
-			/* name was valid, no need to re-validate */
-			validated = TRUE;
-		}
-	}
+	info = g_file_query_info (priv->file,
+				  G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
+				  G_FILE_QUERY_INFO_NONE,
+				  NULL,
+				  NULL);
 
-	if (!validated && !g_utf8_validate (name, -1, NULL)) {
-		if (name == NULL) {
-			name = g_strdup ("[Invalid Unicode]");
-		} else {
-			utf8_name = eog_util_make_valid_utf8 (name);
-			g_free (name);
-			name = utf8_name;
-		}
+	if (G_LIKELY (info != NULL))
+	{
+		priv->caption = g_strdup (g_file_info_get_display_name (info));
+		g_object_unref(info);
 	}
 
-	priv->caption = name;
-
-	if (priv->caption == NULL) {
+	if (G_UNLIKELY (priv->caption == NULL)) {
 		char *short_str;
 
 		short_str = g_file_get_basename (priv->file);
@@ -2114,7 +2060,6 @@ eog_image_get_caption (EogImage *img)
 		}
 		g_free (short_str);
 	}
-	g_free (scheme);
 
 	return priv->caption;
 }



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