[Xfce4-commits] <thunar:master> Add function to generate nice remote display names.

Nick Schermer noreply at xfce.org
Mon Oct 22 20:42:01 CEST 2012


Updating branch refs/heads/master
         to 0c5e3059464027ea7116b73f36a05b2965b089e6 (commit)
       from fcf3c9417141a6d066d1a09d6588efb6b7dacdb5 (commit)

commit 0c5e3059464027ea7116b73f36a05b2965b089e6
Author: Nick Schermer <nick at xfce.org>
Date:   Mon Oct 22 20:12:55 2012 +0200

    Add function to generate nice remote display names.

 thunar/thunar-gio-extensions.c |   69 ++++++++++++++++++++++++++++++++++++++++
 thunar/thunar-gio-extensions.h |    2 +
 2 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/thunar/thunar-gio-extensions.c b/thunar/thunar-gio-extensions.c
index f0b51a8..9968feb 100644
--- a/thunar/thunar-gio-extensions.c
+++ b/thunar/thunar-gio-extensions.c
@@ -257,6 +257,75 @@ thunar_g_file_get_display_name (GFile *file)
 
 
 
+gchar *
+thunar_g_file_get_display_name_remote (GFile *mount_point)
+{
+  gchar       *scheme;
+  gchar       *parse_name;
+  const gchar *p;
+  const gchar *path;
+  gchar       *hostname;
+  gchar       *display_name = NULL;
+  const gchar *skip;
+  const gchar  skip_chars[] = G_URI_RESERVED_CHARS_ALLOWED_IN_PATH_ELEMENT;
+  guint        n;
+
+  _thunar_return_val_if_fail (G_IS_FILE (mount_point), NULL);
+
+  /* not intended for local mounts */
+  if (!g_file_is_native (mount_point))
+    {
+      scheme = g_file_get_uri_scheme (mount_point);
+      parse_name = g_file_get_parse_name (mount_point);
+
+      if (g_str_has_prefix (parse_name, scheme))
+        {
+          /* extract the hostname */
+          p = parse_name + strlen (scheme);
+          while (*p == ':' || *p == '/')
+            ++p;
+
+          /* goto path part */
+          path = strchr (p, '/');
+
+          /* skip password or login names in the hostname */
+          for (n = 0; n < G_N_ELEMENTS (skip_chars) - 1; n++)
+            {
+              skip = strchr (p, skip_chars[n]);
+              if (skip != NULL && (path == NULL || skip < path))
+                p = skip + 1;
+            }
+
+          /* extract the path and hostname from the string */
+          if (G_LIKELY (path != NULL))
+            {
+              hostname = g_strndup (p, path - p);
+            }
+          else
+            {
+              hostname = g_strdup (p);
+              path = "/";
+            }
+
+          /* TRANSLATORS: this will result in "<path> on <hostname>" */
+          display_name = g_strdup_printf (_("%s on %s"), path, hostname);
+
+          g_free (hostname);
+        }
+
+      g_free (scheme);
+      g_free (parse_name);
+    }
+
+  /* never return null */
+  if (display_name == NULL)
+    display_name = thunar_g_file_get_display_name (mount_point);
+
+  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 4a879c5..4fa79d4 100644
--- a/thunar/thunar-gio-extensions.h
+++ b/thunar/thunar-gio-extensions.h
@@ -46,6 +46,8 @@ gboolean  thunar_g_file_write_key_file           (GFile                *file,
 gchar    *thunar_g_file_get_location             (GFile                *file);
 
 gchar    *thunar_g_file_get_display_name         (GFile                *file);
+
+gchar    *thunar_g_file_get_display_name_remote  (GFile                *file);
                                                                       
 gboolean  thunar_g_vfs_is_uri_scheme_supported   (const gchar          *scheme);
 


More information about the Xfce4-commits mailing list