[gtk+/wip/csoriano/gtkpathbar_rework] f



commit c5fed5624a45080db08560e9090987ef66252ebd
Author: Carlos Soriano <csoriano gnome org>
Date:   Thu Mar 5 16:46:23 2015 +0100

    f

 gtk/gtkpathbar.c |  248 +++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 172 insertions(+), 76 deletions(-)
---
diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c
index 7110392..ff8f34c 100644
--- a/gtk/gtkpathbar.c
+++ b/gtk/gtkpathbar.c
@@ -150,6 +150,11 @@ static void gtk_path_bar_check_icon_theme         (GtkPathBar       *path_bar);
 static void gtk_path_bar_update_button_appearance_and_state (ButtonData       *button_data,
                                                              gboolean          current_dir);
 static void gtk_path_bar_update_button_appearance (ButtonData       *button_data);
+static void gtk_path_bar_on_file_changed (GFileMonitor      *monitor,
+                                          GFile             *file,
+                                          GFile             *new_file,
+                                          GFileMonitorEvent  event_type,
+                                          gpointer          *user_data);
 
 static void
 gtk_path_bar_init (GtkPathBar *path_bar)
@@ -1365,10 +1370,13 @@ button_data_free (ButtonData *button_data)
 {
   if (button_data->file)
     {
-      g_signal_handler_disconnect (button_data->file,
+      g_signal_handler_disconnect (button_data->monitor,
                                    button_data->file_changed_signal_id);
+      button_data->file_changed_signal_id = 0;
       g_object_unref (button_data->monitor);
       g_object_unref (button_data->file);
+      button_data->file = NULL;
+      button_data->monitor= NULL;
     }
   button_data->file = NULL;
 
@@ -1523,6 +1531,79 @@ button_drag_data_get_cb (GtkWidget        *widget,
   g_free (uris[0]);
 }
 
+static ButtonData *
+gtk_path_bar_find_button_from_file (GtkPathBar *path_bar,
+                                    GFile      *file)
+{
+  ButtonData *result = NULL;
+  ButtonData *button_data;
+  GList *list;
+
+  g_return_if_fail (G_IS_FILE (file));
+
+  for (list = path_bar->priv->button_list; list; list = list->next)
+    {
+      button_data = list->data;
+      if (g_file_equal (file, button_data->file))
+        {
+          result = list->data;
+          break;
+        }
+    }
+
+  return result;
+}
+
+static ButtonData *
+gtk_path_bar_get_button_child (GtkPathBar *path_bar,
+                               ButtonData *button_data)
+{
+  ButtonData *result = NULL;
+  ButtonData *iter_button_data;
+  GList *list;
+
+  g_return_if_fail (G_IS_FILE (file));
+
+  for (list = path_bar->priv->button_list; list; list = list->next)
+    {
+      iter_button_data = list->data;
+      if (iter_button_data == button_data)
+        {
+          result = list->next != NULL? list->next->data : NULL;
+          break;
+        }
+    }
+
+  return result;
+}
+
+static void
+gtk_path_bar_button_data_unmonitor_file (ButtonData *button_data)
+{
+  g_return_if_fail (button_data != NULL);
+
+  if (button_data->file)
+    {
+      g_signal_handler_disconnect (button_data->monitor,
+                                   button_data->file_changed_signal_id);
+      button_data->file_changed_signal_id = 0;
+      g_object_unref (button_data->monitor);
+      g_object_unref (button_data->file);
+      button_data->file = NULL;
+      button_data->monitor= NULL;
+    }
+}
+
+static void
+gtk_path_bar_button_data_monitor_file (ButtonData *button_data)
+{
+
+  button_data->monitor = g_file_monitor (button_data->file, G_FILE_MONITOR_SEND_MOVED, NULL, NULL);
+  button_data->file_changed_signal_id = g_signal_connect (button_data->monitor, "changed",
+                                                                     G_CALLBACK 
(gtk_path_bar_on_file_changed),
+                                                                     button_data);
+}
+
 static void
 gtk_path_bar_file_changed_on_get_info (GObject      *object,
                                        GAsyncResult *result,
@@ -1530,18 +1611,17 @@ gtk_path_bar_file_changed_on_get_info (GObject      *object,
 {
   const gchar *display_name;
   ButtonData *button_data;
+  ButtonData *child_button_data;
+  GFile *updated_file;
   GFileInfo *info;
   GFile *file;
 
   button_data = BUTTON_DATA (user_data);
   file = G_FILE (object);
-
   info = g_file_query_info_finish (file, result, NULL);
-  if (!info)
-    {
-      g_print ("no info for %s\n", g_file_get_uri (file));
-      return;
-    }
+
+  g_return_if_fail (info != NULL);
+
   display_name = g_file_info_get_display_name (info);
 
   if (g_strcmp0 (display_name, button_data->dir_name) != 0)
@@ -1552,59 +1632,86 @@ gtk_path_bar_file_changed_on_get_info (GObject      *object,
 
   gtk_path_bar_update_button_appearance (button_data);
 
+  /* Update recursively if there is children */
+  child_button_data = gtk_path_bar_get_button_child (path_bar, button_data);
+  if (child_button_data != NULL)
+    {
+      gchar *child_basename;
+      gchar *updated_path;
+
+      child_basename = g_file_get_basename (child_button_data->file);
+      updated_path = g_file_get_child (file, child_basename);
+      gtk_path_bar_button_data_update_path (button_data, updated_path);
+    }
+
   g_object_unref (info);
 }
 
 static void
+gtk_path_bar_button_data_update_path (ButtonData *button_data,
+                                      GFile      *updated_file)
+{
+  g_print ("renamed \n");
+
+  gtk_path_bar_button_data_unmonitor_file (button_data);
+  child->file= g_object_ref (new_file);
+  gtk_path_bar_button_data_monitor_file (button_data);
+  g_file_query_info_async (new_file,
+                           "standard::display-name",
+                           G_FILE_QUERY_INFO_NONE,
+                           G_PRIORITY_DEFAULT,
+                           NULL,
+                           gtk_path_bar_file_changed_on_get_info,
+                           renamed_button_data);
+}
+
+static void
 gtk_path_bar_on_file_changed (GFileMonitor      *monitor,
                               GFile             *file,
-                              GFile             *other_file,
+                              GFile             *new_file,
                               GFileMonitorEvent  event_type,
                               gpointer          *user_data)
 {
-  GFile *location, *current_location, *parent, *button_parent;
-  ButtonData *innermost_button_data, *button_data;
+  GFile *location, *current_location, *new_file_parent, *old_file_parent;
+  ButtonData *button_data;
   GtkPathBar *path_bar;
-  gboolean renamed, child;
+  gboolean renamed, child_moved;
 
   button_data = BUTTON_DATA (user_data);
-  g_print ("gtk_path_bar_on_file_changed %s, %s\n", g_file_get_uri (file), g_file_get_uri 
(button_data->file));
   path_bar = (GtkPathBar *) gtk_widget_get_ancestor (button_data->button,
                                                      GTK_TYPE_PATH_BAR);
+  g_print ("event type %i\n", event_type);
+  g_print ("gtk_path_bar_on_file_changed %s, %s, %s\n", g_file_get_uri (file), g_file_get_uri 
(button_data->file), g_file_get_uri (path_bar->priv->current_path));
   if (path_bar == NULL)
     {
       return;
     }
 
-  innermost_button_data = g_list_nth_data(path_bar->priv->button_list, 0);
-
   g_assert (path_bar->priv->current_path!= NULL);
-  g_assert (innermost_button_data != NULL);
 
-  /* There's an actual change in the name or location of the file reflected as
-   * different GFile between the one in the button_data and the one that were monitoring
-   * that was the same file at the time of creation of the button_data. */
-      g_print ("event type %i\n", event_type);
-  if (!g_file_equal (button_data->file, file))
+  if (event_type == G_FILE_MONITOR_EVENT_MOVED)
     {
-      parent = g_file_get_parent (file);
-      button_parent = g_file_get_parent (button_data->file);
+      old_file_parent = g_file_get_parent (file);
+      new_file_parent = g_file_get_parent (new_file);
+      g_print ("new file %s\n", g_file_get_uri (new_file));
 
-      renamed = (parent != NULL && button_parent != NULL) &&
-                g_file_equal (parent, button_parent);
+      renamed = (old_file_parent != NULL && new_file_parent != NULL) &&
+                 g_file_equal (old_file_parent, new_file_parent);
 
-      if (parent != NULL)
-        {
-          g_object_unref (parent);
-        }
-      if (button_parent != NULL)
-        {
-          g_object_unref (button_parent);
-        }
+      g_clear_object (&old_file_parent);
+      g_clear_object (&new_file_parent);
 
       if (renamed)
         {
-          button_data->file= g_object_ref (file);
+          ButtonData *renamed_button_data;
+
+          renamed_button_data = gtk_path_bar_find_button_from_file (path_bar, file);
+          g_print ("renamed \n");
+          if (renamed_button_data != NULL)
+
+            {
+              gtk_path_bar_button_data_update_path (path_bar, new_file);
+            }
         }
       else
         {
@@ -1612,11 +1719,11 @@ gtk_path_bar_on_file_changed (GFileMonitor      *monitor,
            * If it was below the currently displayed location, remove it.
            * If it was not below the currently displayed location, update the path bar
            */
-          child = g_file_has_prefix (button_data->file,
-                                     path_bar->priv->current_path);
+          child_moved= g_file_has_prefix (file, path_bar->priv->current_path);
 
-          if (child)
+          if (child_moved)
             {
+              g_print ("moved inside current path\n");
               /* moved file inside current path hierarchy */
 #if 0
               location = g_file_get_parent (button_data->file);
@@ -1625,71 +1732,59 @@ gtk_path_bar_on_file_changed (GFileMonitor      *monitor,
             }
           else
             {
+              g_print ("moved outside current path\n");
               /* moved current path, or file outside current path hierarchy.
                * Update path bar to new locations.
                */
-              current_location = button_data->file;
+              current_location = new_file;
             }
 
 #if 0
           nautilus_path_bar_update_path (path_bar, location);
 #endif
-          _gtk_path_bar_set_file (path_bar, current_location, TRUE);
+          gtk_path_bar_clear_buttons (path_bar);
+          _gtk_path_bar_set_file (path_bar, current_location, FALSE);
           g_object_unref (current_location);
           return;
         }
     }
 #if 0
-  else if (nautilus_file_is_gone (file))
+  else if (event_type == G_FILE_MONITOR_EVENT_DELETED)
     {
       gint idx, position;
-
       /* if the current or a parent location are gone, clear all the buttons,
        * the view will set the new path.
        */
-      current_location = nautilus_file_get_location (button_data->file);
-
-      if (g_file_has_prefix (current_location, location) ||
-          g_file_equal (current_location, location)) {
-        nautilus_path_bar_clear_buttons (path_bar);
-      } else if (g_file_has_prefix (location, current_location)) {
-        /* remove this and the following buttons */
-        position = g_list_position (path_bar->priv->button_list,
-                  g_list_find (path_bar->priv->button_list, button_data));
-
-        if (position != -1) {
-          for (idx = 0; idx <= position; idx++) {
-            gtk_container_remove (GTK_CONTAINER (path_bar),
-                      BUTTON_DATA (path_bar->priv->button_list->data)->button);
-          }
+      if (g_file_has_prefix (path_bar->priv->current_path, file) ||
+          g_file_equal (path_bar->priv->current_path, file))
+        {
+          g_print ("deleted below current\n");
+          gtk_path_bar_clear_buttons (path_bar);
+        }
+      else if (g_file_has_prefix (file, path_bar->priv->current_path))
+        {
+          g_print ("deleted below current\n");
+          /* remove this and the following buttons */
+          position = g_list_position (path_bar->priv->button_list,
+                     g_list_find (path_bar->priv->button_list, button_data));
+
+          if (position != -1)
+            {
+              for (idx = 0; idx <= position; idx++)
+                {
+                  gtk_container_remove (GTK_CONTAINER (path_bar),
+                                        BUTTON_DATA (path_bar->priv->button_list->data)->button);
+                }
+            }
         }
-      }
 
-      g_object_unref (current_location);
-      g_object_unref (location);
+
       return;
     }
+
 #endif
 
   /* MOUNTs use the GMount as the name, so don't update for those */
-  if (button_data->type != MOUNT_BUTTON)
-    {
-      if (event_type == G_FILE_MONITOR_EVENT_CREATED ||
-          event_type == G_FILE_MONITOR_EVENT_MOVED)
-        {
-          g_file_query_info_async (file,
-                                   "standard::display-name",
-                                   G_FILE_QUERY_INFO_NONE,
-                                   G_PRIORITY_DEFAULT,
-                                   NULL,
-                                   gtk_path_bar_file_changed_on_get_info,
-                                   button_data);
-        }
-    }
-  else
-    {
-      gtk_path_bar_update_button_appearance (button_data);
-    }
 }
 
 static ButtonData *
@@ -1931,6 +2026,7 @@ _gtk_path_bar_set_file (GtkPathBar *path_bar,
     }
   path_bar->priv->current_path = g_object_ref (file);
 
+  g_print ("set file %s\n", g_file_get_uri (file));
   /* Check whether the new path is already present in the pathbar as buttons.
    * This could be a parent directory or a previous selected subdirectory.
    */


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