[gtk+/wip/csoriano/pathbar-prototype] file management progress



commit e5e6a4bc1c05d34c15d657c6ffc10d8f1903461c
Author: Carlos Soriano <csoriano gnome org>
Date:   Tue Nov 24 10:18:14 2015 +0100

    file management progress

 gtk/gtkfilespathbar.c |  310 ++++++++++++++++++++++++++++++++++++++++++++++---
 gtk/gtkpathbar.c      |  205 ++++++++++++---------------------
 gtk/gtkpathbar.h      |    2 +-
 tests/testpathbar.c   |   53 +++++---
 4 files changed, 402 insertions(+), 168 deletions(-)
---
diff --git a/gtk/gtkfilespathbar.c b/gtk/gtkfilespathbar.c
index e1de808..5ea83fb 100644
--- a/gtk/gtkfilespathbar.c
+++ b/gtk/gtkfilespathbar.c
@@ -28,6 +28,8 @@
 #include "gtkmarshalers.h"
 #include "gtktypebuiltins.h"
 
+#define LOCAL_FILESYSTEM_ROOT_URI "file:///"
+#define OTHER_LOCATIONS_URI "other-locations:///"
 /**
  * SECTION:gtkfilespathbar
  * @Short_description: Widget that displays a path in UNIX format in a button-like manner
@@ -48,6 +50,8 @@ struct _GtkFilesPathBarPrivate
   GtkWidget *path_bar;
 
   GFile *file;
+  GCancellable *cancellable;
+  GFileMonitor *monitor;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkFilesPathBar, gtk_files_path_bar, GTK_TYPE_BIN)
@@ -66,6 +70,267 @@ enum {
 static GParamSpec *files_path_bar_properties[LAST_PROP] = { NULL, };
 static guint files_path_bar_signals[LAST_SIGNAL] = { 0 };
 
+typedef struct {
+  GtkFilesPathBar *path_bar;
+  GString *display_path;
+  GFile *root_file;
+  gchar *root_label;
+  GIcon *root_icon;
+  GCancellable *cancellable;
+} PathFilesInfo;
+
+static GMount*
+get_mounted_mount_for_root (GFile *file)
+{
+  GVolumeMonitor *volume_monitor;
+  GList *mounts;
+  GList *l;
+  GMount *mount;
+  GMount *result = NULL;
+  GFile *root = NULL;
+  GFile *default_location = NULL;
+
+  volume_monitor = g_volume_monitor_get ();
+  mounts = g_volume_monitor_get_mounts (volume_monitor);
+
+  for (l = mounts; l != NULL; l = l->next)
+    {
+      mount = l->data;
+
+      if (g_mount_is_shadowed (mount))
+        continue;
+
+      root = g_mount_get_root (mount);
+      if (g_file_equal (file, root))
+        {
+          result = g_object_ref (mount);
+          break;
+        }
+
+      default_location = g_mount_get_default_location (mount);
+      if (!g_file_equal (default_location, root) &&
+          g_file_equal (file, default_location))
+        {
+          result = g_object_ref (mount);
+          break;
+        }
+    }
+
+  g_clear_object (&root);
+  g_clear_object (&default_location);
+  g_list_free_full (mounts, g_object_unref);
+
+  return result;
+}
+
+static gboolean
+file_is_home_dir (GFile *file)
+{
+  gboolean is_home_dir;
+  gchar *path;
+
+  path = g_file_get_path (file);
+
+  is_home_dir = g_strcmp0 (path, g_get_home_dir ()) == 0;
+
+  if (path)
+    g_free (path);
+
+  return is_home_dir;
+}
+
+static gboolean
+file_is_absolute_root (GFile *file)
+{
+  gboolean is_filesystem_root;
+  gchar *file_basename;
+
+  file_basename = g_file_get_basename (file);
+  is_filesystem_root = g_strcmp0 (file_basename, G_DIR_SEPARATOR_S) == 0;
+
+  g_free (file_basename);
+
+  return is_filesystem_root;
+}
+
+static gboolean
+file_is_root (GFile *file)
+{
+  GMount *mount;
+  gboolean is_root = FALSE;
+
+  mount = get_mounted_mount_for_root (file);
+
+  is_root = file_is_absolute_root (file) || file_is_home_dir (file) || mount;
+
+  g_object_unref (file);
+  g_clear_object (&mount);
+
+  return is_root;
+}
+
+static GIcon*
+get_root_icon (GFile *file)
+{
+  GIcon *icon = NULL;
+  GFile *local_filesystem_file;
+
+  local_filesystem_file = g_file_new_for_uri (LOCAL_FILESYSTEM_ROOT_URI);
+  if (g_file_equal (file, local_filesystem_file))
+    icon = g_themed_icon_new ("drive-harddisk");
+
+  g_object_unref (local_filesystem_file);
+
+  return icon;
+}
+
+static gchar*
+get_root_label (GFile *file)
+{
+  gchar *label = NULL;
+  gchar *path;
+  GMount *mount;
+  GFile *other_locations;
+
+  path = g_file_get_path (file);
+  mount = get_mounted_mount_for_root (file);
+  other_locations = g_file_new_for_uri (OTHER_LOCATIONS_URI);
+  if (g_strcmp0 (path, g_get_home_dir ()) == 0)
+    label = g_strdup (_("Home"));
+  else if (g_file_equal (file, other_locations))
+    label = g_strdup (_("Other Locations"));
+  else if (mount)
+    label = g_mount_get_name (mount);
+
+  if (path)
+    g_free (path);
+  g_clear_object (&mount);
+  g_object_unref (other_locations);
+
+  return label;
+}
+
+static void
+free_path_files_info (PathFilesInfo *path_files_info)
+{
+  if (path_files_info->display_path)
+    g_string_free (path_files_info->display_path, TRUE);
+  if (path_files_info->root_label)
+    g_free (path_files_info->root_label);
+
+  g_clear_object (&path_files_info->cancellable);
+  g_clear_object (&path_files_info->root_file);
+  g_clear_object (&path_files_info->root_icon);
+
+  g_slice_free (PathFilesInfo, path_files_info);
+}
+
+static void
+on_all_path_files_info_queried (PathFilesInfo *path_files_info)
+{
+  GtkFilesPathBarPrivate *priv = gtk_files_path_bar_get_instance_private (path_files_info->path_bar);
+  gchar *root_uri;
+
+  root_uri = g_file_get_uri (path_files_info->root_file);
+  g_print ("setting path extended %s %s %s\n", path_files_info->display_path->str, root_uri, 
path_files_info->root_label);
+  gtk_path_bar_set_path_extended (GTK_PATH_BAR (priv->path_bar),
+                                  path_files_info->display_path->str, root_uri,
+                                  path_files_info->root_label, path_files_info->root_icon);
+
+  g_free (root_uri);
+  free_path_files_info (path_files_info);
+}
+
+static void
+on_queried_file_info (GObject      *object,
+                      GAsyncResult *result,
+                      gpointer      user_data)
+{
+  GFile *file = G_FILE (object);
+  GError *error = NULL;
+  PathFilesInfo *path_files_info = (PathFilesInfo *) user_data;
+  GFileInfo *file_info;
+
+  g_print ("queried file info\n");
+  if (g_cancellable_is_cancelled (path_files_info->cancellable))
+    {
+      free_path_files_info (path_files_info);
+      goto out;
+    }
+
+  file_info = g_file_query_info_finish (file, result, &error);
+  if (!error || g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
+    {
+      if (file_is_root (file))
+        {
+          path_files_info->root_icon = get_root_icon (file);
+          path_files_info->root_label = get_root_label (file);
+          path_files_info->root_file = g_object_ref (file);
+          /* If it is not specific root managed by us, just query display name */
+          if (!path_files_info->root_label && !path_files_info->root_icon)
+            {
+              if (!error)
+                {
+                  path_files_info->root_label = g_strdup (g_file_info_get_display_name (file_info));
+                }
+              else
+                {
+                  gchar *uri;
+
+                  uri = g_file_get_uri (file);
+                  g_warning ("Error trying to get info from %s, location not supported", uri);
+
+                  free_path_files_info (path_files_info);
+                  g_free (uri);
+
+                  goto out;
+                }
+            }
+          /* Avoid appending twice the OS separator if it is an absolute root */
+          if (!file_is_absolute_root (file))
+            {
+              gchar *uri;
+
+              uri = g_file_get_uri (file);
+              g_string_prepend (path_files_info->display_path, uri);
+              g_free (uri);
+            }
+          on_all_path_files_info_queried (path_files_info);
+        }
+      else
+        {
+          GFile *parent;
+
+          parent = g_file_get_parent (file);
+
+          g_string_prepend (path_files_info->display_path, g_file_info_get_display_name (file_info));
+          g_string_prepend (path_files_info->display_path, G_DIR_SEPARATOR_S);
+          g_file_query_info_async (parent,
+                                   "standard::display-name",
+                                   G_FILE_QUERY_INFO_NONE,
+                                   G_PRIORITY_DEFAULT,
+                                   path_files_info->cancellable,
+                                   on_queried_file_info,
+                                   path_files_info);
+        }
+    }
+  else
+    {
+      gchar *uri;
+
+      uri = g_file_get_uri (file);
+      g_warning ("%s", error->message);
+
+      free_path_files_info (path_files_info);
+      g_free (uri);
+    }
+
+out:
+  g_object_unref (file);
+  if (error)
+   g_error_free (error);
+}
+
 static void
 on_path_bar_populate_popup (GtkPathBar      *path_bar,
                             GtkWidget       *container,
@@ -86,7 +351,7 @@ on_path_bar_selected_path (GtkPathBar      *path_bar,
 {
   GFile *file;
 
-  file = g_file_new_for_path (gtk_path_bar_get_selected_path (path_bar));
+  file = g_file_new_for_uri (gtk_path_bar_get_selected_path (path_bar));
 
   gtk_files_path_bar_set_file (self, file);
 
@@ -94,14 +359,16 @@ on_path_bar_selected_path (GtkPathBar      *path_bar,
 }
 
 static void
-gtk_files_path_bar_finalize (GObject *object)
+gtk_files_path_bar_dispose (GObject *object)
 {
   GtkFilesPathBar *self = (GtkFilesPathBar *)object;
   GtkFilesPathBarPrivate *priv = gtk_files_path_bar_get_instance_private (self);
 
+  g_cancellable_cancel (priv->cancellable);
+  g_clear_object (&priv->cancellable);
   g_clear_object (&priv->file);
 
-  G_OBJECT_CLASS (gtk_files_path_bar_parent_class)->finalize (object);
+  G_OBJECT_CLASS (gtk_files_path_bar_parent_class)->dispose (object);
 }
 
 static void
@@ -147,7 +414,7 @@ gtk_files_path_bar_class_init (GtkFilesPathBarClass *klass)
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
-  object_class->finalize = gtk_files_path_bar_finalize;
+  object_class->dispose = gtk_files_path_bar_dispose;
   object_class->get_property = gtk_files_path_bar_get_property;
   object_class->set_property = gtk_files_path_bar_set_property;
 
@@ -244,8 +511,7 @@ gtk_files_path_bar_set_file (GtkFilesPathBar *self,
                              GFile           *file)
 {
   GtkFilesPathBarPrivate *priv;
-  gchar *uri;
-  gchar *path;
+  PathFilesInfo *path_files_info;
 
   g_return_if_fail (GTK_IS_FILES_PATH_BAR (self));
 
@@ -254,18 +520,32 @@ gtk_files_path_bar_set_file (GtkFilesPathBar *self,
   if (priv->file && g_file_equal (priv->file, file))
     return;
 
-  g_clear_object (&priv->file);
-  /* Use a new object to avoid complex debugging in applications */
-  uri = g_file_get_uri (file);
-  priv->file = g_file_new_for_uri (uri);
-  path = g_file_get_path (file);
+  g_print ("bef cancellable %s\n", g_file_get_uri (file));
+  g_cancellable_cancel (priv->cancellable);
+  g_print ("after cancellable %s\n", g_file_get_uri (file));
+  g_clear_object (&priv->cancellable);
+  priv->cancellable = g_cancellable_new ();
 
-  gtk_path_bar_set_path (GTK_PATH_BAR (priv->path_bar), path);
+  g_clear_object (&priv->file);
+  priv->file = g_object_ref (file);
+
+  path_files_info = g_slice_new (PathFilesInfo);
+  path_files_info->path_bar = self;
+  path_files_info->display_path = g_string_new ("");
+  path_files_info->root_file = NULL;
+  path_files_info->root_label = NULL;
+  path_files_info->root_icon = NULL;
+  path_files_info->cancellable = g_object_ref (priv->cancellable);
+
+  g_file_query_info_async (g_object_ref (file),
+                           "standard::display-name",
+                           G_FILE_QUERY_INFO_NONE,
+                           G_PRIORITY_DEFAULT,
+                           path_files_info->cancellable,
+                           on_queried_file_info,
+                           path_files_info);
 
   g_object_notify_by_pspec (G_OBJECT (self), files_path_bar_properties[PROP_FILE]);
-
-  g_free (uri);
-  g_free (path);
 }
 
 GtkWidget *
diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c
index 5284bb0..49b22ed 100644
--- a/gtk/gtkpathbar.c
+++ b/gtk/gtkpathbar.c
@@ -73,7 +73,6 @@ struct _GtkPathBarPrivate
   gchar *root_path;
 
   gchar *path;
-  gchar *display_path;
   gchar *selected_path;
   gboolean inverted;
 
@@ -270,7 +269,7 @@ create_path_chunk (GtkPathBar  *self,
     }
   else
     {
-      g_assert_not_reached ();
+      g_critical ("Path chunk doesn't provide either icon or label");
     }
 
   style = gtk_widget_get_style_context (button);
@@ -281,14 +280,14 @@ create_path_chunk (GtkPathBar  *self,
 
   if (add_separator && !separator_after_button)
     {
-      separator = gtk_label_new ("/");
+      separator = gtk_label_new (G_DIR_SEPARATOR_S);
       gtk_widget_set_sensitive (separator, FALSE);
       gtk_container_add (GTK_CONTAINER (path_chunk), separator);
     }
   gtk_container_add (GTK_CONTAINER (path_chunk), button);
   if (add_separator && separator_after_button)
     {
-      separator = gtk_label_new ("/");
+      separator = gtk_label_new (G_DIR_SEPARATOR_S);
       gtk_widget_set_sensitive (separator, FALSE);
       gtk_container_add (GTK_CONTAINER (path_chunk), separator);
     }
@@ -322,7 +321,7 @@ get_splitted_path (const gchar* path)
   gchar **splitted_path;
 
   path_no_first_slash = g_utf8_substring (path, 1, strlen (path));
-  splitted_path = g_strsplit (path_no_first_slash, "/", -1);
+  splitted_path = g_strsplit (path_no_first_slash, G_DIR_SEPARATOR_S, -1);
 
   g_free (path_no_first_slash);
 
@@ -330,9 +329,15 @@ get_splitted_path (const gchar* path)
 }
 
 static gboolean
+is_absolute_root (const gchar *path)
+{
+  return g_strcmp0 (path, G_DIR_SEPARATOR_S) == 0;
+}
+
+static gboolean
 validate_path (const gchar *path)
 {
-  gchar ** splitted_path = NULL;
+  GFile *file = NULL;
   gboolean valid = FALSE;
 
   if (!path || strlen (path) == 0)
@@ -341,31 +346,21 @@ validate_path (const gchar *path)
   if (!g_utf8_validate (path, -1, NULL))
     goto out;
 
-  /* Special case "/", which is always valid */
-  if (g_strcmp0 (path, "/") == 0)
+  /* Special case absolute root which is always valid */
+  if (is_absolute_root (path))
     {
       valid = TRUE;
       goto out;
     }
 
-  splitted_path = g_strsplit (path, "/", -1);
-
-  /* Path must start with "/" */
-  if (g_strcmp0 (splitted_path[0], "") != 0)
+  file = g_file_new_for_uri (path);
+  if (!file)
     goto out;
 
-  for (guint i = 0; i < g_strv_length (splitted_path); i++)
-    {
-      /* First part of the path is always empty when splitted */
-      if (g_strcmp0 (splitted_path[i], "") == 0 && i != 0)
-        goto out;
-    }
-
   valid = TRUE;
 
 out:
-  if (splitted_path)
-    g_strfreev (splitted_path);
+  g_clear_object (&file);
 
   return valid;
 }
@@ -378,56 +373,6 @@ validate_root_path (const gchar *path,
          (g_str_has_prefix (path, root_path) || g_strcmp0 (path, root_path) == 0);
 }
 
-static gboolean
-validate_display_path (const gchar *path,
-                       const gchar *display_path)
-{
-  gchar ** splitted_path = NULL;
-  gchar ** splitted_display_path = NULL;
-  gboolean same_length;
-
-  if (!validate_path (display_path))
-    return FALSE;
-
-  splitted_display_path = g_strsplit (display_path, "/", -1);
-  splitted_path = g_strsplit (path, "/", -1);
-  same_length = g_strv_length (splitted_path) == g_strv_length (splitted_display_path);
-
-  g_strfreev (splitted_path);
-  g_strfreev (splitted_display_path);
-
-  return same_length;
-}
-
-static gchar*
-get_display_name (GtkPathBar  *self,
-                  const gchar *path)
-{
-  GtkPathBarPrivate *priv = gtk_path_bar_get_instance_private (self);
-  gchar **splitted_path;
-  gchar **splitted_current_path;
-  gchar **splitted_display_path;
-  gchar *name;
-
-  splitted_path = get_splitted_path (path);
-  if (priv->display_path)
-    {
-      splitted_display_path = get_splitted_path (priv->display_path);
-      name = g_strdup (splitted_display_path[g_strv_length (splitted_path) - 1]);
-      g_strfreev (splitted_display_path);
-    }
-  else
-    {
-      splitted_current_path = get_splitted_path (priv->path);
-      name = g_strdup (splitted_current_path[g_strv_length (splitted_path) - 1]);
-      g_strfreev (splitted_current_path);
-    }
-
-   g_strfreev (splitted_path);
-
-  return name;
-}
-
 static void
 update_path_bar (GtkPathBar  *self)
 {
@@ -438,10 +383,7 @@ update_path_bar (GtkPathBar  *self)
   GtkWidget *path_bar;
   GtkWidget *root_chunk;
   gchar *unprefixed_path;
-  gchar *label;
-  GtkTextDirection direction;
 
-  direction = gtk_widget_get_direction (GTK_WIDGET (self));
   get_path_bar_widgets (GTK_PATH_BAR (self), &path_bar, &overflow_button, &path_box, FALSE);
 
   /* Make sure we dismiss all popovers */
@@ -452,73 +394,73 @@ update_path_bar (GtkPathBar  *self)
 
   if (priv->root_path)
     {
-      label = get_display_name (self, priv->root_path);
-      root_chunk = create_path_chunk (self, priv->root_path, label,
+      root_chunk = create_path_chunk (self, priv->root_path, priv->root_label,
                                       priv->root_icon, TRUE, TRUE);
-      g_free (label);
 
       gtk_container_add (GTK_CONTAINER (path_box), root_chunk);
-      /* Remove root path */
-      unprefixed_path = g_utf8_substring (priv->path, strlen (priv->root_path),
-                                          strlen (priv->path));
-    }
-  else
-    {
-      unprefixed_path = g_strdup (priv->path);
     }
 
-  /* We always expect a label and we use "/" as a separator.
-   * However, "/" is a valid path, so we need to handle it ourselves
-   * if the client didn't set a root label or icon for it.
+  if (g_strcmp0 (priv->root_path, priv->path) == 0)
+    goto done;
+
+  /* We always expect a path in the format /path/path in UNIX or \path\path in Windows.
+   * However, the OS separator alone is a valid path, so we need to handle it
+   * ourselves if the client didn't set a root label or icon for it.
    */
-  if (g_strcmp0 (priv->path, "/") != 0 || priv->root_path)
+  if (!is_absolute_root (priv->path) || priv->root_path)
     {
-      /* Do nothing if the path and the path reprensented by the root are equal */
-      if (g_strcmp0 (priv->path, priv->root_path) != 0)
+      GString *current_path = NULL;
+      gchar **splitted_path;
+      gboolean add_separator;
+      gboolean separator_after_button;
+      gint length;
+      gint i;
+
+      current_path = g_string_new ("");
+      if (priv->root_path && !is_absolute_root (priv->root_path))
+        {
+          g_string_append (current_path, priv->root_path);
+          unprefixed_path = g_utf8_substring (priv->path, strlen (priv->root_path),
+                                              strlen (priv->path));
+        }
+      else
         {
-          GString *current_path = NULL;
-          gchar **splitted_path;
-          gboolean add_separator;
-          gboolean separator_after_button;
-          gint length;
-          gint i;
-
-          splitted_path = get_splitted_path (unprefixed_path);
-          current_path = g_string_new (priv->root_path);
-          length = g_strv_length (splitted_path);
-          for (i = 0; i < length; i++)
-            {
-              g_string_append (current_path, "/");
-              g_string_append (current_path, splitted_path[i]);
-
-              /* We add a separator for all items except the last one, which will result
-               * in a pathbar in the form of "Home/Documents/Example".
-               * However, if only one item is present, add a separator at the end since
-               * is visually more pleasant. The result will be in the form of "Home/" */
-              add_separator = length == 1 || (i != length - 1 && priv->inverted) ||
-                              (i != 0 && !priv->inverted);
-              separator_after_button = length == 1 || priv->inverted;
-
-              label = get_display_name (self, current_path->str);
-              path_chunk = create_path_chunk (self, current_path->str, splitted_path[i],
-                                              NULL, add_separator, separator_after_button);
-              g_free (label);
-              gtk_container_add (GTK_CONTAINER (path_box), path_chunk);
-            }
-
-          g_strfreev (splitted_path);
-          g_string_free (current_path, TRUE);
+          unprefixed_path = g_strdup (priv->path);
         }
+
+      splitted_path = get_splitted_path (unprefixed_path);
+      length = g_strv_length (splitted_path);
+      for (i = 0; i < length; i++)
+        {
+          g_string_append (current_path, G_DIR_SEPARATOR_S);
+          g_string_append (current_path, splitted_path[i]);
+
+          /* We add a separator for all items except the last one, which will result
+           * in a pathbar in the form of "Home/Documents/Example".
+           * However, if only one item is present, add a separator at the end since
+           * is visually more pleasant. The result will be in the form of "Home/" */
+          add_separator = length == 1 || (i != length - 1 && priv->inverted) ||
+                          (i != 0 && !priv->inverted);
+          separator_after_button = length == 1 || priv->inverted;
+
+          path_chunk = create_path_chunk (self, current_path->str, splitted_path[i],
+                                          NULL, add_separator, separator_after_button);
+          gtk_container_add (GTK_CONTAINER (path_box), path_chunk);
+        }
+
+      g_strfreev (splitted_path);
+      g_string_free (current_path, TRUE);
+      g_free (unprefixed_path);
     }
   else
     {
-      path_chunk = create_path_chunk (self, "/", "/", NULL, FALSE, FALSE);
+      path_chunk = create_path_chunk (self, G_DIR_SEPARATOR_S, G_DIR_SEPARATOR_S,
+                                      NULL, FALSE, FALSE);
       gtk_container_add (GTK_CONTAINER (path_box), path_chunk);
     }
 
+done:
   gtk_stack_set_visible_child (GTK_STACK (priv->path_bar_containers_stack), path_bar);
-
-  g_free (unprefixed_path);
 }
 
 static void
@@ -756,8 +698,8 @@ gtk_path_bar_init (GtkPathBar *self)
 void
 gtk_path_bar_set_path_extended (GtkPathBar  *self,
                                 const gchar *path,
-                                const gchar *display_path,
                                 const gchar *root_path,
+                                const gchar *root_label,
                                 GIcon       *root_icon)
 {
   GtkPathBarPrivate *priv;
@@ -766,7 +708,6 @@ gtk_path_bar_set_path_extended (GtkPathBar  *self,
   g_return_if_fail (GTK_IS_PATH_BAR (self));
   g_return_if_fail (validate_path (path));
   g_return_if_fail (!root_path || validate_root_path (path, root_path));
-  g_return_if_fail (!display_path || validate_display_path (path, display_path));
 
   priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
 
@@ -780,18 +721,18 @@ gtk_path_bar_set_path_extended (GtkPathBar  *self,
       g_free (priv->root_path);
       priv->root_path = NULL;
     }
-  if (priv->display_path)
+  if (priv->root_label)
     {
-      g_free (priv->display_path);
-      priv->display_path = NULL;
+      g_free (priv->root_label);
+      priv->root_label = NULL;
     }
 
   if (root_icon)
     priv->root_icon = g_object_ref (root_icon);
   if (root_path)
     priv->root_path = g_strdup (root_path);
-  if (display_path)
-    priv->display_path = g_strdup (display_path);
+  if (root_label)
+    priv->root_label = g_strdup (root_label);
 
   old_path = priv->path;
   priv->path = g_strdup (path);
diff --git a/gtk/gtkpathbar.h b/gtk/gtkpathbar.h
index 67f00eb..7572ec2 100644
--- a/gtk/gtkpathbar.h
+++ b/gtk/gtkpathbar.h
@@ -72,8 +72,8 @@ const gchar*          gtk_path_bar_get_path              (GtkPathBar       *path
 GDK_AVAILABLE_IN_3_20
 void                  gtk_path_bar_set_path_extended     (GtkPathBar       *self,
                                                           const gchar      *path,
-                                                          const gchar      *display_path,
                                                           const gchar      *root_path,
+                                                          const gchar      *root_label,
                                                           GIcon            *root_icon);
 
 GDK_AVAILABLE_IN_3_20
diff --git a/tests/testpathbar.c b/tests/testpathbar.c
index 8bdb2ee..31c4922 100644
--- a/tests/testpathbar.c
+++ b/tests/testpathbar.c
@@ -8,7 +8,10 @@ static GtkWidget *path_bar_inverted;
 static GtkWidget *path_bar_slash;
 static GtkWidget *path_bar_custom_root_label;
 static GtkWidget *path_bar_custom_root_icon;
-static GtkWidget *files_path_bar;
+static GtkWidget *files_path_bar_random;
+static GtkWidget *files_path_bar_recent;
+static const gchar* REAL_LOCATION_RANDOM = "file:///boot/efi/EFI/BOOT";
+static const gchar* REAL_LOCATION_RECENT = "recent:///";
 static const gchar* ORIGINAL_PATH = "/test/test 2/test 3/asda lkasdl/pppppppppppppppp/ alskd";
 static const gchar* ROOT_PATH = "/test/test 2/test 3";
 static const gchar* DISPLAY_PATH = "/test/test 2/This Is A Root/asda lkasdl/pppppppppppppppp/ alskd";
@@ -126,7 +129,7 @@ on_path_selected_set_path (GtkPathBar *path_bar,
   if (path_bar == GTK_PATH_BAR (path_bar_custom_root_label))
     {
       gtk_path_bar_set_path_extended (GTK_PATH_BAR (path_bar_custom_root_label),
-                                      selected_path, new_display_path, ROOT_PATH, NULL);
+                                      selected_path, ROOT_PATH, "This Is A Root", NULL);
     }
   else if (path_bar == GTK_PATH_BAR (path_bar_custom_root_icon))
     {
@@ -134,7 +137,7 @@ on_path_selected_set_path (GtkPathBar *path_bar,
 
       icon = g_themed_icon_new ("drive-harddisk");
       gtk_path_bar_set_path_extended (GTK_PATH_BAR (path_bar_custom_root_icon),
-                                      selected_path, new_display_path, ROOT_PATH, icon);
+                                      selected_path, "/", NULL, icon);
       g_object_unref (icon);
     }
   else
@@ -194,21 +197,23 @@ on_reset_button_clicked (GtkButton *reset_button)
   GFile *file;
   GIcon *icon;
 
-  file = g_file_new_for_path (ORIGINAL_PATH);
-  icon = g_themed_icon_new ("drive-harddisk");
-
   gtk_path_bar_set_path (GTK_PATH_BAR (path_bar), ORIGINAL_PATH);
   gtk_path_bar_set_path (GTK_PATH_BAR (path_bar_inverted), ORIGINAL_PATH);
   gtk_path_bar_set_path (GTK_PATH_BAR (path_bar_slash), "/");
   gtk_path_bar_set_path_extended (GTK_PATH_BAR (path_bar_custom_root_label),
-                                  ORIGINAL_PATH, DISPLAY_PATH, ROOT_PATH, NULL);
+                                  ORIGINAL_PATH, ROOT_PATH, "This Is A Root", NULL);
+  icon = g_themed_icon_new ("drive-harddisk");
   gtk_path_bar_set_path_extended (GTK_PATH_BAR (path_bar_custom_root_icon),
-                                  ORIGINAL_PATH, DISPLAY_PATH, ROOT_PATH, icon);
-  gtk_files_path_bar_set_file (GTK_FILES_PATH_BAR (files_path_bar), file);
-
-
+                                  ORIGINAL_PATH, "/", NULL, icon);
   g_object_unref (icon);
+
+  file = g_file_new_for_uri (REAL_LOCATION_RANDOM);
+  gtk_files_path_bar_set_file (GTK_FILES_PATH_BAR (files_path_bar_random), file);
   g_object_unref (file);
+  file = g_file_new_for_uri (REAL_LOCATION_RECENT);
+  gtk_files_path_bar_set_file (GTK_FILES_PATH_BAR (files_path_bar_recent), file);
+  g_object_unref (file);
+
 }
 
 int
@@ -218,7 +223,7 @@ main (int argc, char *argv[])
   GtkWidget *grid;
   GtkWidget *reset_button;
   GtkWidget *label;
-  GFile *file;
+  GFile *file = NULL;
   GIcon *icon;
 
   gtk_init (&argc, &argv);
@@ -274,7 +279,7 @@ main (int argc, char *argv[])
   path_bar_custom_root_label = gtk_path_bar_new ();
   gtk_path_bar_set_inverted (GTK_PATH_BAR (path_bar_custom_root_label), TRUE);
   gtk_path_bar_set_path_extended (GTK_PATH_BAR (path_bar_custom_root_label),
-                                  ORIGINAL_PATH, DISPLAY_PATH, ROOT_PATH, NULL);
+                                  ORIGINAL_PATH, ROOT_PATH, "This Is A Root", NULL);
   connect_path_bar_set_path (GTK_PATH_BAR (path_bar_custom_root_label));
   gtk_grid_attach (GTK_GRID (grid), path_bar_custom_root_label, 0, 6, 1, 1);
 
@@ -283,7 +288,7 @@ main (int argc, char *argv[])
   gtk_path_bar_set_inverted (GTK_PATH_BAR (path_bar_custom_root_icon), TRUE);
   icon = g_themed_icon_new ("drive-harddisk");
   gtk_path_bar_set_path_extended (GTK_PATH_BAR (path_bar_custom_root_icon),
-                                  ORIGINAL_PATH, DISPLAY_PATH, ROOT_PATH, icon);
+                                  ORIGINAL_PATH, "/", NULL, icon);
   g_object_unref (icon);
   connect_path_bar_set_path (GTK_PATH_BAR (path_bar_custom_root_icon));
   gtk_grid_attach (GTK_GRID (grid), path_bar_custom_root_icon, 0, 7, 1, 1);
@@ -293,11 +298,19 @@ main (int argc, char *argv[])
   gtk_grid_attach (GTK_GRID (grid), label, 0, 8, 2, 1);
 
   /* ----------------------------------------------------------------------- */
-  files_path_bar = gtk_files_path_bar_new ();
-  file = g_file_new_for_path (ORIGINAL_PATH);
-  gtk_files_path_bar_set_file (GTK_FILES_PATH_BAR (files_path_bar), file);
-  connect_files_path_bar (GTK_FILES_PATH_BAR (files_path_bar));
-  gtk_grid_attach (GTK_GRID (grid), files_path_bar, 0, 9, 1, 1);
+  files_path_bar_random = gtk_files_path_bar_new ();
+  file = g_file_new_for_uri (REAL_LOCATION_RANDOM);
+  gtk_files_path_bar_set_file (GTK_FILES_PATH_BAR (files_path_bar_random), file);
+  connect_files_path_bar (GTK_FILES_PATH_BAR (files_path_bar_random));
+  gtk_grid_attach (GTK_GRID (grid), files_path_bar_random, 0, 9, 1, 1);
+
+  g_clear_object (&file);
+
+  files_path_bar_recent = gtk_files_path_bar_new ();
+  file = g_file_new_for_uri (REAL_LOCATION_RECENT);
+  gtk_files_path_bar_set_file (GTK_FILES_PATH_BAR (files_path_bar_recent), file);
+  connect_files_path_bar (GTK_FILES_PATH_BAR (files_path_bar_recent));
+  gtk_grid_attach (GTK_GRID (grid), files_path_bar_recent, 0, 10, 1, 1);
 
   g_clear_object (&file);
 
@@ -306,7 +319,7 @@ main (int argc, char *argv[])
   gtk_widget_set_hexpand (reset_button, TRUE);
   g_signal_connect (GTK_BUTTON (reset_button), "clicked",
                     G_CALLBACK (on_reset_button_clicked), window);
-  gtk_grid_attach (GTK_GRID (grid), reset_button, 0, 10, 2, 1);
+  gtk_grid_attach (GTK_GRID (grid), reset_button, 0, 11, 2, 1);
 
   gtk_container_add (GTK_CONTAINER (window), grid);
   gtk_widget_show_all (window);


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