From ec386592199a543a5c747233bf037d37a059f6b0 Mon Sep 17 00:00:00 2001
From: Benedikt Meurer <benny@xfce.org>
Date: Sat, 25 Jun 2005 22:20:39 +0000
Subject: [PATCH] 2005-06-25	Benedikt Meurer <benny@xfce.org>

	* thunar/thunar-local-file.c: Use a static variable for the VFS monitor
	  instead of a class variable, that never gets freed with static types.
	* thunar/thunar-favourites-model.c: Watch the files in the favourites
	  list for changes, so that folders that no longer exists are
	  automatically removed from the list.




(Old svn revision: 16356)
---
 ChangeLog                        |  8 ++++++++
 thunar/thunar-favourites-model.c | 11 +++++++++++
 thunar/thunar-local-file.c       | 29 ++++++++++++++++++++++-------
 3 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cdec120c7..d94fdee6f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-06-25	Benedikt Meurer <benny@xfce.org>
+
+	* thunar/thunar-local-file.c: Use a static variable for the VFS monitor
+	  instead of a class variable, that never gets freed with static types.
+	* thunar/thunar-favourites-model.c: Watch the files in the favourites
+	  list for changes, so that folders that no longer exists are
+	  automatically removed from the list.
+
 2005-06-25	Benedikt Meurer <benny@xfce.org>
 
 	* thunar/thunar-navigator.c(thunar_navigator_get_type): Do not require
diff --git a/thunar/thunar-favourites-model.c b/thunar/thunar-favourites-model.c
index bfe809b14..5f6b3bffb 100644
--- a/thunar/thunar-favourites-model.c
+++ b/thunar/thunar-favourites-model.c
@@ -362,6 +362,10 @@ thunar_favourites_model_finalize (GObject *object)
 
       if (G_LIKELY (current->file != NULL))
         {
+          /* drop the file watch */
+          thunar_file_unwatch (current->file);
+
+          /* unregister from the file */
           g_signal_handlers_disconnect_matched (G_OBJECT (current->file),
                                                 G_SIGNAL_MATCH_DATA, 0,
                                                 0, NULL, NULL, model);
@@ -710,6 +714,10 @@ thunar_favourites_model_add_favourite (ThunarFavouritesModel *model,
   /* we want to stay informed about changes to the file */
   if (G_LIKELY (favourite->file != NULL))
     {
+      /* watch the file for changes */
+      thunar_file_watch (favourite->file);
+
+      /* connect appropriate signals */
       g_signal_connect (G_OBJECT (favourite->file), "changed",
                         G_CALLBACK (thunar_favourites_model_file_changed), model);
       g_signal_connect (G_OBJECT (favourite->file), "destroy",
@@ -896,6 +904,9 @@ thunar_favourites_model_file_destroy (ThunarFile            *file,
   gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
   gtk_tree_path_free (path);
 
+  /* drop the watch from the file */
+  thunar_file_unwatch (favourite->file);
+
   /* disconnect us from the favourite's file */
   g_signal_handlers_disconnect_matched (G_OBJECT (favourite->file),
                                         G_SIGNAL_MATCH_DATA, 0,
diff --git a/thunar/thunar-local-file.c b/thunar/thunar-local-file.c
index ca4afb9bc..936c9e8af 100644
--- a/thunar/thunar-local-file.c
+++ b/thunar/thunar-local-file.c
@@ -59,8 +59,6 @@ static void               thunar_local_file_monitor           (ThunarVfsMonitor
 struct _ThunarLocalFileClass
 {
   ThunarFileClass __parent__;
-
-  ThunarVfsMonitor *monitor;
 };
 
 struct _ThunarLocalFile
@@ -76,6 +74,8 @@ struct _ThunarLocalFile
 
 
 
+static ThunarVfsMonitor *monitor = NULL;
+
 G_DEFINE_TYPE (ThunarLocalFile, thunar_local_file, THUNAR_TYPE_FILE);
 
 
@@ -86,8 +86,6 @@ thunar_local_file_class_init (ThunarLocalFileClass *klass)
   ThunarFileClass *thunarfile_class;
   GObjectClass    *gobject_class;
 
-  klass->monitor = thunar_vfs_monitor_get_default ();
-
   gobject_class = G_OBJECT_CLASS (klass);
   gobject_class->finalize = thunar_local_file_finalize;
 
@@ -343,8 +341,21 @@ thunar_local_file_watch (ThunarFile *file)
 
   g_return_if_fail (local_file->watch_id == 0);
 
-  local_file->watch_id = thunar_vfs_monitor_add_info (THUNAR_LOCAL_FILE_GET_CLASS (local_file)->monitor,
-                                                      &local_file->info, thunar_local_file_monitor, local_file);
+  /* take a reference on the VFS monitor for this instance */
+  if (G_UNLIKELY (monitor == NULL))
+    {
+      monitor = thunar_vfs_monitor_get_default ();
+      g_object_add_weak_pointer (G_OBJECT (monitor), (gpointer) &monitor);
+    }
+  else
+    {
+      g_object_ref (G_OBJECT (monitor));
+    }
+
+  /* add our VFS info to the monitor */
+  local_file->watch_id = thunar_vfs_monitor_add_info (monitor, &local_file->info,
+                                                      thunar_local_file_monitor,
+                                                      local_file);
 }
 
 
@@ -356,8 +367,12 @@ thunar_local_file_unwatch (ThunarFile *file)
 
   g_return_if_fail (local_file->watch_id != 0);
 
-  thunar_vfs_monitor_remove (THUNAR_LOCAL_FILE_GET_CLASS (local_file)->monitor, local_file->watch_id);
+  /* remove our VFS info from the monitor */
+  thunar_vfs_monitor_remove (monitor, local_file->watch_id);
   local_file->watch_id = 0;
+
+  /* release our reference on the VFS monitor */
+  g_object_unref (G_OBJECT (monitor));
 }
 
 
-- 
GitLab