From 5bd7f363feff3747bc52e81ce0d8b9dcdaa747c6 Mon Sep 17 00:00:00 2001
From: Dito didio <tr1@timabea.de>
Date: Wed, 10 Mar 2021 08:06:44 +0000
Subject: [PATCH] Remove watches on shortcuts (Issue #513) (Issue #47)

MR !66
Fixes #47
Fixes #513
---
 thunar/thunar-shortcuts-model.c | 135 +++++---------------------------
 1 file changed, 18 insertions(+), 117 deletions(-)

diff --git a/thunar/thunar-shortcuts-model.c b/thunar/thunar-shortcuts-model.c
index 9f6848038..4c1ec9daa 100644
--- a/thunar/thunar-shortcuts-model.c
+++ b/thunar/thunar-shortcuts-model.c
@@ -132,10 +132,6 @@ static void               thunar_shortcuts_model_monitor            (GFileMonito
                                                                      GFile                     *other_file,
                                                                      GFileMonitorEvent          event_type,
                                                                      gpointer                   user_data);
-static void               thunar_shortcuts_model_file_changed       (ThunarFile                *file,
-                                                                     ThunarShortcutsModel      *model);
-static void               thunar_shortcuts_model_file_destroy       (ThunarFile                *file,
-                                                                     ThunarShortcutsModel      *model);
 static void               thunar_shortcuts_model_device_added       (ThunarDeviceMonitor       *device_monitor,
                                                                      ThunarDevice              *device,
                                                                      ThunarShortcutsModel      *model);
@@ -1216,19 +1212,6 @@ thunar_shortcuts_model_add_shortcut_with_path (ThunarShortcutsModel *model,
   _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_MODEL (model));
   _thunar_return_if_fail (shortcut->file == NULL || THUNAR_IS_FILE (shortcut->file));
 
-  /* we want to stay informed about changes to the file */
-  if (G_LIKELY (shortcut->file != NULL))
-    {
-      /* 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);
-    }
-
   if (path == NULL)
     {
       /* insert the new shortcut to the shortcuts list */
@@ -1330,47 +1313,40 @@ thunar_shortcuts_model_load_line (GFile       *file_path,
   _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_MODEL (model));
   _thunar_return_if_fail (name == NULL || g_utf8_validate (name, -1, NULL));
 
-  /* handle local and remove files differently */
+  shortcut = g_slice_new0 (ThunarShortcut);
+  shortcut->group = THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS;
+
+  /* handle local and remote files differently */
   if (thunar_shortcuts_model_local_file (file_path))
     {
       /* try to open the file corresponding to the uri */
       file = thunar_file_get (file_path, NULL);
       if (G_UNLIKELY (file == NULL))
-        return;
-
-      /* make sure the file refers to a directory */
-      if (G_UNLIKELY (thunar_file_is_directory (file)))
         {
-          /* create the shortcut entry */
-          shortcut = g_slice_new0 (ThunarShortcut);
-          shortcut->group = THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS;
-          shortcut->file = file;
-          shortcut->sort_id = row_num;
-          shortcut->hidden = thunar_shortcuts_model_get_hidden (model, shortcut);
-          shortcut->name = g_strdup (name);
-
-          /* append the shortcut to the list */
-          thunar_shortcuts_model_add_shortcut (model, shortcut);
+          shortcut->gicon = g_themed_icon_new ("folder");
+          shortcut->location = g_object_ref (file_path);
         }
       else
         {
-          g_object_unref (file);
+          /* make sure the file refers to a directory */
+          if (G_UNLIKELY (thunar_file_is_directory (file)))
+            shortcut->file = file;
+          else
+            g_object_unref (file);
         }
     }
   else
     {
-      /* create the shortcut entry */
-      shortcut = g_slice_new0 (ThunarShortcut);
-      shortcut->group = THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS;
       shortcut->gicon = g_themed_icon_new ("folder-remote");
       shortcut->location = g_object_ref (file_path);
-      shortcut->sort_id = row_num;
-      shortcut->hidden = thunar_shortcuts_model_get_hidden (model, shortcut);
-      shortcut->name = g_strdup (name);
-
-      /* append the shortcut to the list */
-      thunar_shortcuts_model_add_shortcut (model, shortcut);
     }
+
+  shortcut->sort_id = row_num;
+  shortcut->hidden = thunar_shortcuts_model_get_hidden (model, shortcut);
+  shortcut->name = g_strdup (name);
+
+  /* append the shortcut to the list */
+  thunar_shortcuts_model_add_shortcut (model, shortcut);
 }
 
 
@@ -1541,74 +1517,6 @@ thunar_shortcuts_model_save (ThunarShortcutsModel *model)
 
 
 
-static void
-thunar_shortcuts_model_file_changed (ThunarFile           *file,
-                                     ThunarShortcutsModel *model)
-{
-  ThunarShortcut *shortcut;
-  GtkTreePath    *path;
-  GtkTreeIter     iter;
-  GList          *lp;
-  gint            idx;
-
-  _thunar_return_if_fail (THUNAR_IS_FILE (file));
-  _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_MODEL (model));
-
-  /* check if the file still refers to a directory or a not mounted URI,
-   * otherwise we cannot keep it on the shortcuts list, and so we'll treat
-   * it like the file was destroyed (and thereby removed) */
-
-  if (G_UNLIKELY (!thunar_file_is_directory (file)))
-    {
-      thunar_shortcuts_model_file_destroy (file, model);
-      return;
-    }
-
-  for (idx = 0, lp = model->shortcuts; lp != NULL; ++idx, lp = lp->next)
-    {
-      shortcut = THUNAR_SHORTCUT (lp->data);
-      if (shortcut->file == file)
-        {
-          GTK_TREE_ITER_INIT (iter, model->stamp, lp);
-
-          path = gtk_tree_path_new_from_indices (idx, -1);
-          gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
-          gtk_tree_path_free (path);
-          break;
-        }
-    }
-}
-
-
-
-static void
-thunar_shortcuts_model_file_destroy (ThunarFile           *file,
-                                     ThunarShortcutsModel *model)
-{
-  ThunarShortcut *shortcut = NULL;
-  GList          *lp;
-
-  _thunar_return_if_fail (THUNAR_IS_FILE (file));
-  _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_MODEL (model));
-
-  /* lookup the shortcut matching the file */
-  for (lp = model->shortcuts; lp != NULL; lp = lp->next)
-    {
-      shortcut = THUNAR_SHORTCUT (lp->data);
-      if (shortcut->file == file)
-        break;
-    }
-
-  /* verify that we actually found a shortcut */
-  _thunar_assert (lp != NULL);
-  _thunar_assert (THUNAR_IS_FILE (shortcut->file));
-
-  /* drop the shortcut from the model */
-  thunar_shortcuts_model_remove_shortcut (model, shortcut);
-}
-
-
-
 static void
 thunar_shortcuts_model_device_added (ThunarDeviceMonitor  *device_monitor,
                                      ThunarDevice         *device,
@@ -1743,13 +1651,6 @@ thunar_shortcut_free (ThunarShortcut       *shortcut,
 {
   if (G_LIKELY (shortcut->file != NULL))
     {
-      /* drop the file watch */
-      thunar_file_unwatch (shortcut->file);
-
-      /* unregister from the file */
-      g_signal_handlers_disconnect_matched (shortcut->file,
-                                            G_SIGNAL_MATCH_DATA, 0,
-                                            0, NULL, NULL, model);
       g_object_unref (shortcut->file);
     }
 
-- 
GitLab