[Xfce4-commits] <thunar:nick/new-shortcuts-pane-model> Some random fixes.

Nick Schermer noreply at xfce.org
Fri Oct 12 21:06:01 CEST 2012


Updating branch refs/heads/nick/new-shortcuts-pane-model
         to ed651e98cdea5053327c52f42764de0304c4d664 (commit)
       from 1e560601e48793188427f71defaa623cba5d18ba (commit)

commit ed651e98cdea5053327c52f42764de0304c4d664
Author: Nick Schermer <nick at xfce.org>
Date:   Fri Oct 12 21:00:46 2012 +0200

    Some random fixes.

 thunar/thunar-device-monitor.c  |    2 +-
 thunar/thunar-file.c            |   43 +++++++++++++++----
 thunar/thunar-file.h            |    2 +
 thunar/thunar-shortcuts-model.c |   86 ++++++++++++++++-----------------------
 thunar/thunar-shortcuts-model.h |    4 --
 thunar/thunar-shortcuts-view.c  |   22 ++++------
 thunar/thunar-window.c          |   10 +----
 7 files changed, 82 insertions(+), 87 deletions(-)

diff --git a/thunar/thunar-device-monitor.c b/thunar/thunar-device-monitor.c
index a704bd0..b6c64ba 100644
--- a/thunar/thunar-device-monitor.c
+++ b/thunar/thunar-device-monitor.c
@@ -343,7 +343,7 @@ thunar_device_monitor_update_hidden (gpointer key,
   g_free (id);
 
   if (thunar_device_get_hidden (device) != hidden)
-    {g_message ("update device");
+    {
       g_object_set (G_OBJECT (device), "hidden", hidden, NULL);
       g_signal_emit (G_OBJECT (monitor), device_monitor_signals[DEVICE_CHANGED], 0, device);
     }
diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index d0c7286..a26a3e9 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -182,6 +182,8 @@ G_DEFINE_TYPE_WITH_CODE (ThunarFile, thunar_file, G_TYPE_OBJECT,
 #ifdef HAVE_ATEXIT
 static gboolean thunar_file_atexit_registered = FALSE;
 
+
+
 static void
 thunar_file_atexit_foreach (gpointer key,
                             gpointer value,
@@ -191,9 +193,13 @@ thunar_file_atexit_foreach (gpointer key,
 
   uri = g_file_get_uri (key);
   g_print ("--> %s (%u)\n", uri, G_OBJECT (value)->ref_count);
+  if (G_OBJECT (key)->ref_count > 2)
+    g_print ("    GFile (%u)\n", G_OBJECT (key)->ref_count - 2);
   g_free (uri);
 }
 
+
+
 static void
 thunar_file_atexit (void)
 {
@@ -846,9 +852,6 @@ thunar_file_get_async_finish (GObject      *object,
   if (error != NULL)
     g_error_free (error);
 
-  /* release the file */
-  g_object_unref (file);
-
   /* release the get data */
   if (data->cancellable != NULL)
     g_object_unref (data->cancellable);
@@ -2357,11 +2360,10 @@ thunar_file_is_parent (const ThunarFile *file,
 }
 
 
-
 /**
  * thunar_file_is_ancestor:
  * @file     : a #ThunarFile instance.
- * @ancestor : another #ThunarFile instance.
+ * @ancestor : another #GFile instance.
  *
  * Determines whether @file is somewhere inside @ancestor,
  * possibly with intermediate folders.
@@ -2370,21 +2372,21 @@ thunar_file_is_parent (const ThunarFile *file,
  *               child, grandchild, great grandchild, etc.
  **/
 gboolean
-thunar_file_is_ancestor (const ThunarFile *file, 
-                         const ThunarFile *ancestor)
+thunar_file_is_gfile_ancestor (const ThunarFile *file,
+                               GFile            *ancestor)
 {
   gboolean is_ancestor = FALSE;
   GFile   *current = NULL;
   GFile   *tmp;
 
   _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
-  _thunar_return_val_if_fail (THUNAR_IS_FILE (ancestor), FALSE);
+  _thunar_return_val_if_fail (G_IS_FILE (ancestor), FALSE);
 
   for (current = g_object_ref (file->gfile);
        is_ancestor == FALSE && current != NULL;
        tmp = g_file_get_parent (current), g_object_unref (current), current = tmp)
     {
-      if (G_UNLIKELY (g_file_equal (current, ancestor->gfile)))
+      if (G_UNLIKELY (g_file_equal (current, ancestor)))
         is_ancestor = TRUE;
     }
 
@@ -2397,6 +2399,29 @@ thunar_file_is_ancestor (const ThunarFile *file,
 
 
 /**
+ * thunar_file_is_ancestor:
+ * @file     : a #ThunarFile instance.
+ * @ancestor : another #ThunarFile instance.
+ *
+ * Determines whether @file is somewhere inside @ancestor,
+ * possibly with intermediate folders.
+ *
+ * Return value: %TRUE if @ancestor contains @file as a
+ *               child, grandchild, great grandchild, etc.
+ **/
+gboolean
+thunar_file_is_ancestor (const ThunarFile *file,
+                         const ThunarFile *ancestor)
+{
+  _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
+  _thunar_return_val_if_fail (THUNAR_IS_FILE (ancestor), FALSE);
+
+  return thunar_file_is_gfile_ancestor (file, ancestor->gfile);
+}
+
+
+
+/**
  * thunar_file_is_executable:
  * @file : a #ThunarFile instance.
  *
diff --git a/thunar/thunar-file.h b/thunar/thunar-file.h
index ae17d56..5d0c03c 100644
--- a/thunar/thunar-file.h
+++ b/thunar/thunar-file.h
@@ -187,6 +187,8 @@ gboolean          thunar_file_is_mountable         (const ThunarFile       *file
 gboolean          thunar_file_is_local             (const ThunarFile       *file);
 gboolean          thunar_file_is_parent            (const ThunarFile       *file,
                                                     const ThunarFile       *child);
+gboolean          thunar_file_is_gfile_ancestor    (const ThunarFile       *file, 
+                                                    GFile                  *ancestor);
 gboolean          thunar_file_is_ancestor          (const ThunarFile       *file, 
                                                     const ThunarFile       *ancestor);
 gboolean          thunar_file_is_executable        (const ThunarFile       *file);
diff --git a/thunar/thunar-shortcuts-model.c b/thunar/thunar-shortcuts-model.c
index 6496510..36cf943 100644
--- a/thunar/thunar-shortcuts-model.c
+++ b/thunar/thunar-shortcuts-model.c
@@ -617,7 +617,9 @@ thunar_shortcuts_model_get_value (GtkTreeModel *tree_model,
 
     case THUNAR_SHORTCUTS_MODEL_COLUMN_MUTABLE:
       g_value_init (value, G_TYPE_BOOLEAN);
-      g_value_set_boolean (value, shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS);
+      g_value_set_boolean (value,
+                           shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS
+                           || shortcut->group == THUNAR_SHORTCUT_GROUP_NETWORK_BOOKMARKS);
       break;
 
     case THUNAR_SHORTCUTS_MODEL_COLUMN_CAN_EJECT:
@@ -1064,6 +1066,7 @@ thunar_shortcuts_model_remove_shortcut (ThunarShortcutsModel *model,
 {
   GtkTreePath *path;
   gint         idx;
+  gboolean     needs_save;
 
   /* determine the index of the shortcut */
   idx = g_list_index (model->shortcuts, shortcut);
@@ -1077,11 +1080,16 @@ thunar_shortcuts_model_remove_shortcut (ThunarShortcutsModel *model,
       gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
       gtk_tree_path_free (path);
 
+      /* check if we need to save */
+      needs_save = shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS
+                   || shortcut->group == THUNAR_SHORTCUT_GROUP_NETWORK_BOOKMARKS;
+
       /* actually free the shortcut */
       thunar_shortcut_free (shortcut, model);
 
       /* the shortcuts list was changed, so write the gtk bookmarks file */
-      thunar_shortcuts_model_save (model);
+      if (needs_save)
+        thunar_shortcuts_model_save (model);
     }
 }
 
@@ -1282,7 +1290,8 @@ thunar_shortcuts_model_save (ThunarShortcutsModel *model)
   for (lp = model->shortcuts; lp != NULL; lp = lp->next)
     {
       shortcut = THUNAR_SHORTCUT (lp->data);
-      if (shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS)
+      if (shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS
+          || shortcut->group == THUNAR_SHORTCUT_GROUP_NETWORK_BOOKMARKS)
         {
           if (shortcut->file != NULL)
             uri = thunar_file_dup_uri (shortcut->file);
@@ -1638,6 +1647,13 @@ thunar_shortcuts_model_iter_for_file (ThunarShortcutsModel *model,
           return TRUE;
         }
 
+      if (shortcut->location != NULL
+          && g_file_equal (shortcut->location, thunar_file_get_file (file)))
+        {
+          GTK_TREE_ITER_INIT (*iter, model->stamp, lp);
+          return TRUE;
+        }
+
       /* but maybe we have a mounted(!) volume with a matching mount point */
       if (shortcut->device != NULL)
         {
@@ -1662,50 +1678,6 @@ thunar_shortcuts_model_iter_for_file (ThunarShortcutsModel *model,
 
 
 /**
- * thunar_shortcuts_model_set_file:
- * @location : a #GFile.
- * @file  : a #ThunarFile.
- *
- * Set the ThunarFile for the activated GFile in the database.
- **/
-void
-thunar_shortcuts_model_set_file (ThunarShortcutsModel *model,
-                                 GFile                *location,
-                                 ThunarFile           *file)
-{
-  GList          *lp;
-  ThunarShortcut *shortcut;
-
-  _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_MODEL (model));
-  _thunar_return_if_fail (G_IS_FILE (location));
-  _thunar_return_if_fail (THUNAR_IS_FILE (file));
-
-  for (lp = model->shortcuts; lp != NULL; lp = lp->next)
-    {
-      shortcut = lp->data;
-
-      /* check if we have a location that matches */
-      if (shortcut->location != NULL
-          && shortcut->file == NULL
-          && g_file_equal (shortcut->location, location))
-        {
-          shortcut->file = g_object_ref (file);
-
-          /* watch the file for changes */
-          thunar_file_watch (shortcut->file);
-
-          /* connect appropriate signals */
-          g_signal_connect (G_OBJECT (shortcut->file), "changed",
-                            G_CALLBACK (thunar_shortcuts_model_file_changed), model);
-          g_signal_connect (G_OBJECT (shortcut->file), "destroy",
-                            G_CALLBACK (thunar_shortcuts_model_file_destroy), model);
-        }
-    }
-}
-
-
-
-/**
  * thunar_shortcuts_model_drop_possible:
  * @model : a #ThunarShortcutstModel.
  * @path  : a #GtkTreePath.
@@ -1776,9 +1748,20 @@ thunar_shortcuts_model_add (ThunarShortcutsModel *model,
 
   /* create the new shortcut that will be inserted */
   shortcut = g_slice_new0 (ThunarShortcut);
-  shortcut->group = THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS;
   shortcut->file = g_object_ref (G_OBJECT (file));
 
+  if (thunar_file_is_local (file))
+    {
+      shortcut->group = THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS;
+    }
+  else
+    {
+      shortcut->group = THUNAR_SHORTCUT_GROUP_NETWORK_BOOKMARKS;
+      shortcut->gicon = g_themed_icon_new ("folder-remote");
+
+      dst_path = NULL;
+    }
+
   /* add the shortcut to the list at the given position */
   thunar_shortcuts_model_add_shortcut_with_path (model, shortcut, dst_path);
 
@@ -1907,7 +1890,8 @@ thunar_shortcuts_model_remove (ThunarShortcutsModel *model,
   shortcut = g_list_nth_data (model->shortcuts, gtk_tree_path_get_indices (path)[0]);
 
   /* verify that the shortcut is removable */
-  _thunar_assert (shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS);
+  _thunar_assert (shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS
+                  || shortcut->group == THUNAR_SHORTCUT_GROUP_NETWORK_BOOKMARKS);
 
   /* remove the shortcut (using the file destroy handler) */
   thunar_shortcuts_model_remove_shortcut (model, shortcut);
@@ -1945,8 +1929,8 @@ thunar_shortcuts_model_rename (ThunarShortcutsModel *model,
   shortcut = THUNAR_SHORTCUT (((GList *) iter->user_data)->data);
 
   /* verify the shortcut */
-  _thunar_assert (shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS);
-  _thunar_assert (THUNAR_IS_FILE (shortcut->file));
+  _thunar_assert (shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS
+                  || shortcut->group == THUNAR_SHORTCUT_GROUP_NETWORK_BOOKMARKS);
 
   /* perform the rename */
   if (G_UNLIKELY (shortcut->name != NULL))
diff --git a/thunar/thunar-shortcuts-model.h b/thunar/thunar-shortcuts-model.h
index 0f9bcc1..4c37459 100644
--- a/thunar/thunar-shortcuts-model.h
+++ b/thunar/thunar-shortcuts-model.h
@@ -102,10 +102,6 @@ gboolean               thunar_shortcuts_model_iter_for_file (ThunarShortcutsMode
                                                              ThunarFile           *file,
                                                              GtkTreeIter          *iter);
 
-void                   thunar_shortcuts_model_set_file      (ThunarShortcutsModel *model,
-                                                             GFile                *location,
-                                                             ThunarFile           *file);
-
 gboolean               thunar_shortcuts_model_drop_possible (ThunarShortcutsModel *model,
                                                              GtkTreePath          *path);
 
diff --git a/thunar/thunar-shortcuts-view.c b/thunar/thunar-shortcuts-view.c
index 97ebdda..04dbee9 100644
--- a/thunar/thunar-shortcuts-view.c
+++ b/thunar/thunar-shortcuts-view.c
@@ -1162,7 +1162,8 @@ thunar_shortcuts_view_context_menu (ThunarShortcutsView *view,
     }
 
   /* append the remove menu item */
-  if (group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS)
+  if (group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS
+      || group == THUNAR_SHORTCUT_GROUP_NETWORK_BOOKMARKS)
     {
       /* append a menu separator */
       item = gtk_separator_menu_item_new ();
@@ -1194,16 +1195,16 @@ thunar_shortcuts_view_context_menu (ThunarShortcutsView *view,
       gtk_widget_show (item);
     }
 
-  /* run the menu on the view's screen (taking over the floating reference on menu) */
-  thunar_gtk_menu_run (GTK_MENU (menu), GTK_WIDGET (view), NULL, NULL, (event != NULL) ? event->button : 0,
-                       (event != NULL) ? event->time : gtk_get_current_event_time ());
-
   /* clean up */
   if (G_LIKELY (file != NULL))
     g_object_unref (G_OBJECT (file));
   if (G_UNLIKELY (device != NULL))
     g_object_unref (G_OBJECT (device));
   gtk_tree_path_free (path);
+
+  /* run the menu on the view's screen (taking over the floating reference on menu) */
+  thunar_gtk_menu_run (GTK_MENU (menu), GTK_WIDGET (view), NULL, NULL, (event != NULL) ? event->button : 0,
+                       (event != NULL) ? event->time : gtk_get_current_event_time ());
 }
 
 
@@ -1556,9 +1557,7 @@ thunar_shortcuts_view_poke_location_finish (ThunarBrowser *browser,
                                             GError        *error,
                                             gpointer       user_data)
 {
-  ThunarShortcutsView *view = THUNAR_SHORTCUTS_VIEW (browser);
-  GtkTreeModel        *model;
-  gchar               *name;
+  gchar *name;
 
   _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (browser));
   _thunar_return_if_fail (G_IS_FILE (location));
@@ -1566,9 +1565,6 @@ thunar_shortcuts_view_poke_location_finish (ThunarBrowser *browser,
   /* sotre the new file in the shortcuts model */
   if (error == NULL)
     {
-      model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
-      thunar_shortcuts_model_set_file (THUNAR_SHORTCUTS_MODEL (model), location, file);
-
       thunar_shortcuts_view_poke_file_finish (browser, file, target_file, error, user_data);
     }
   else
@@ -1833,9 +1829,7 @@ thunar_shortcuts_view_mount (ThunarShortcutsView *view)
   if (gtk_tree_selection_get_selected (selection, &model, &iter))
     {
       /* determine the file for the shortcut at the given tree iterator */
-      gtk_tree_model_get (model, &iter,
-                          THUNAR_SHORTCUTS_MODEL_COLUMN_DEVICE, &device,
-                          -1);
+      gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_DEVICE, &device, -1);
 
       if (G_LIKELY (device != NULL))
         {
diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c
index eb18d56..7df0860 100644
--- a/thunar/thunar-window.c
+++ b/thunar/thunar-window.c
@@ -2782,8 +2782,7 @@ thunar_window_device_pre_unmount (ThunarDeviceMonitor *device_monitor,
                                   GFile               *root_file,
                                   ThunarWindow        *window)
 {
-  ThunarFile *file;
-  GtkAction  *action;
+  GtkAction *action;
 
   _thunar_return_if_fail (THUNAR_IS_DEVICE_MONITOR (device_monitor));
   _thunar_return_if_fail (window->device_monitor == device_monitor);
@@ -2795,13 +2794,8 @@ thunar_window_device_pre_unmount (ThunarDeviceMonitor *device_monitor,
   if (G_UNLIKELY (window->current_directory == NULL))
     return;
 
-  /* try to get the ThunarFile for the mount point from the file cache */
-  file = thunar_file_cache_lookup (root_file);
-  if (G_UNLIKELY (file == NULL))
-    return;
-
   /* check if the file is the current directory or an ancestor of the current directory */
-  if (window->current_directory == file || thunar_file_is_ancestor (window->current_directory, file))
+  if (thunar_file_is_gfile_ancestor (window->current_directory, root_file))
     {
       /* change to the home folder */
       action = gtk_action_group_get_action (window->action_group, "open-home");


More information about the Xfce4-commits mailing list