[Xfce4-commits] <thunar:master> Add function to generate display name for a GFile.
Nick Schermer
noreply at xfce.org
Sat Oct 13 16:12:02 CEST 2012
Updating branch refs/heads/master
to 569d4db2c78f076e29aa24d670a920d89500bcad (commit)
from fb21e1dfddeb8e6629fea02f5aae81b657b268f1 (commit)
commit 569d4db2c78f076e29aa24d670a920d89500bcad
Author: Nick Schermer <nick at xfce.org>
Date: Fri Oct 5 15:01:50 2012 +0200
Add function to generate display name for a GFile.
This is a fallback in case no GFileInfo is available.
thunar/thunar-file.c | 46 ++++++---------------------------------
thunar/thunar-gio-extensions.c | 36 +++++++++++++++++++++++++++++++
thunar/thunar-gio-extensions.h | 2 +
3 files changed, 45 insertions(+), 39 deletions(-)
diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 14ceb6c..6926ec9 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -684,7 +684,6 @@ thunar_file_info_reload (ThunarFile *file,
const gchar *target_uri;
GKeyFile *key_file;
GFile *thumbnail_dir;
- gchar *base_name;
gchar *p;
gchar *thumbnail_dir_path;
const gchar *display_name;
@@ -762,31 +761,17 @@ thunar_file_info_reload (ThunarFile *file,
G_KEY_FILE_DESKTOP_KEY_NAME,
NULL, NULL);
- /* check if we have a display name now */
- if (file->display_name != NULL)
+ /* drop the name if it's empty or has invalid encoding */
+ if (exo_str_is_empty (file->display_name)
+ || !g_utf8_validate (file->display_name, -1, NULL))
{
- /* drop the name if it's empty or has invalid encoding */
- if (*file->display_name == '\0'
- || !g_utf8_validate (file->display_name, -1, NULL))
- {
- g_free (file->display_name);
- file->display_name = NULL;
- }
+ g_free (file->display_name);
+ file->display_name = NULL;
}
/* free the key file */
g_key_file_free (key_file);
}
- else
- {
- /* cannot parse the key file, no custom icon */
- file->custom_icon_name = NULL;
- }
- }
- else
- {
- /* not a .desktop file, no custom icon */
- file->custom_icon_name = NULL;
}
/* determine the display name */
@@ -804,26 +789,9 @@ thunar_file_info_reload (ThunarFile *file,
}
}
+ /* faccl back to a name for the gfile */
if (file->display_name == NULL)
- {
- base_name = g_file_get_basename (file->gfile);
- if (G_LIKELY (base_name != NULL))
- {
- if (g_utf8_validate (base_name, -1, NULL))
- {
- file->display_name = base_name;
- }
- else
- {
- file->display_name = g_uri_escape_string (base_name, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, TRUE);
- g_free (base_name);
- }
- }
- else
- {
- file->display_name = g_strdup ("?");
- }
- }
+ file->display_name = thunar_g_file_get_display_name (file->gfile);
}
/* create case sensitive collation key */
diff --git a/thunar/thunar-gio-extensions.c b/thunar/thunar-gio-extensions.c
index 626490b..ae52cda 100644
--- a/thunar/thunar-gio-extensions.c
+++ b/thunar/thunar-gio-extensions.c
@@ -219,6 +219,42 @@ thunar_g_file_get_location (GFile *file)
+gchar *
+thunar_g_file_get_display_name (GFile *file)
+{
+ gchar *base_name;
+ gchar *display_name;
+
+ _thunar_return_val_if_fail (G_IS_FILE (file), NULL);
+
+ base_name = g_file_get_basename (file);
+ if (G_LIKELY (base_name != NULL))
+ {
+ if (strcmp (base_name, "/") == 0)
+ {
+ display_name = g_strdup (_("File System"));
+ g_free (base_name);
+ }
+ else if (g_utf8_validate (base_name, -1, NULL))
+ {
+ display_name = base_name;
+ }
+ else
+ {
+ display_name = g_uri_escape_string (base_name, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, TRUE);
+ g_free (base_name);
+ }
+ }
+ else
+ {
+ display_name = g_strdup ("?");
+ }
+
+ return display_name;
+}
+
+
+
gboolean
thunar_g_vfs_is_uri_scheme_supported (const gchar *scheme)
{
diff --git a/thunar/thunar-gio-extensions.h b/thunar/thunar-gio-extensions.h
index 93ca514..7afb1dd 100644
--- a/thunar/thunar-gio-extensions.h
+++ b/thunar/thunar-gio-extensions.h
@@ -44,6 +44,8 @@ gboolean thunar_g_file_write_key_file (GFile *file,
GError **error);
gchar *thunar_g_file_get_location (GFile *file);
+
+gchar *thunar_g_file_get_display_name (GFile *file);
gboolean thunar_g_vfs_is_uri_scheme_supported (const gchar *scheme);
More information about the Xfce4-commits
mailing list