ThunarVfsURI *handle_uri,
ThunarVfsURI *event_uri,
gpointer user_data);
+static void thunar_local_file_watch_free (gpointer data);
{
ThunarFile __parent__;
- ThunarVfsInfo *info;
-
- ThunarVfsMonitorHandle *handle;
+ ThunarVfsInfo *info;
};
static ThunarVfsMonitor *monitor = NULL;
static GObjectClass *thunar_local_file_parent_class;
+static GQuark thunar_local_file_watch_quark;
ThunarFileClass *thunarfile_class;
GObjectClass *gobject_class;
+ /* query the thunar-local-file-watch quark */
+ thunar_local_file_watch_quark = g_quark_from_static_string ("thunar-local-file-watch");
+
/* query the parent class */
thunar_local_file_parent_class = g_type_class_peek_parent (klass);
ThunarLocalFile *local_file = THUNAR_LOCAL_FILE (object);
#ifndef G_DISABLE_CHECKS
- if (G_UNLIKELY (local_file->handle != NULL))
+ if (G_UNLIKELY (g_object_get_qdata (object, thunar_local_file_watch_quark) != NULL))
{
g_error ("Attempt to finalize a ThunarLocalFile, which "
"is still being watched for changes");
if (G_LIKELY (local_file->info != NULL))
thunar_vfs_info_unref (local_file->info);
- G_OBJECT_CLASS (thunar_local_file_parent_class)->finalize (object);
+ (*G_OBJECT_CLASS (thunar_local_file_parent_class)->finalize) (object);
}
if (G_LIKELY (succeed))
{
/* need to re-register the monitor handle for the new uri */
- if (G_LIKELY (local_file->handle != NULL))
+ if (g_object_get_qdata (G_OBJECT (file), thunar_local_file_watch_quark) != NULL)
{
/* drop the previous handle (with the old URI) */
- thunar_vfs_monitor_remove (monitor, local_file->handle);
+ thunar_local_file_unwatch (file);
/* register the new handle (with the new URI) */
- local_file->handle = thunar_vfs_monitor_add_file (monitor, local_file->info->uri, thunar_local_file_monitor, local_file);
+ thunar_local_file_watch (file);
}
/* perform the rename on the file cache */
static void
thunar_local_file_watch (ThunarFile *file)
{
- ThunarLocalFile *local_file = THUNAR_LOCAL_FILE (file);
-
- g_return_if_fail (local_file->handle == NULL);
+ ThunarVfsMonitorHandle *handle;
/* take a reference on the VFS monitor for this instance */
if (G_UNLIKELY (monitor == NULL))
}
/* add us to the file monitor */
- local_file->handle = thunar_vfs_monitor_add_file (monitor, local_file->info->uri, thunar_local_file_monitor, local_file);
+ handle = thunar_vfs_monitor_add_file (monitor, THUNAR_LOCAL_FILE (file)->info->uri, thunar_local_file_monitor, file);
+ g_object_set_qdata_full (G_OBJECT (file), thunar_local_file_watch_quark, handle, thunar_local_file_watch_free);
}
static void
thunar_local_file_unwatch (ThunarFile *file)
{
- ThunarLocalFile *local_file = THUNAR_LOCAL_FILE (file);
-
- g_return_if_fail (local_file->handle != NULL);
-
- /* remove our VFS info from the monitor */
- thunar_vfs_monitor_remove (monitor, local_file->handle);
- local_file->handle = NULL;
-
- /* release our reference on the VFS monitor */
- g_object_unref (G_OBJECT (monitor));
+ /* just unset the watch handle */
+ g_object_set_qdata (G_OBJECT (file), thunar_local_file_watch_quark, NULL);
}
g_return_if_fail (THUNAR_VFS_IS_URI (handle_uri));
g_return_if_fail (THUNAR_VFS_IS_URI (event_uri));
g_return_if_fail (THUNAR_IS_LOCAL_FILE (local_file));
- g_return_if_fail (local_file->handle == handle);
g_return_if_fail (thunar_vfs_uri_equal (local_file->info->uri, handle_uri));
/* just to be sure... */
+static void
+thunar_local_file_watch_free (gpointer data)
+{
+ /* remove the watch from the VFS monitor */
+ thunar_vfs_monitor_remove (monitor, data);
+
+ /* release our reference on the VFS monitor */
+ g_object_unref (G_OBJECT (monitor));
+}
+
+
+
/**
* thunar_local_file_new:
* @uri : the #ThunarVfsURI referrring to the local file.