[gthumb/ext: 62/79] when adding a file monitor, monitor the file parents as well
- From: Paolo Bacchilega <paobac src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gthumb/ext: 62/79] when adding a file monitor, monitor the file parents as well
- Date: Sun, 2 Aug 2009 20:31:19 +0000 (UTC)
commit 3f3df668990d018e5b10735beb3b958b68fba678
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sat Jul 25 00:22:06 2009 +0200
when adding a file monitor, monitor the file parents as well
gthumb/gth-file-source-vfs.c | 65 ++++++++++++++++++++++++++++++++---------
1 files changed, 50 insertions(+), 15 deletions(-)
---
diff --git a/gthumb/gth-file-source-vfs.c b/gthumb/gth-file-source-vfs.c
index fb68701..8c7d990 100644
--- a/gthumb/gth-file-source-vfs.c
+++ b/gthumb/gth-file-source-vfs.c
@@ -466,27 +466,62 @@ monitor_changed_cb (GFileMonitor *file_monitor,
static void
-gth_file_source_vfs_monitor_directory (GthFileSource *file_source,
- GFile *file,
- gboolean activate)
+remove_monitor_for_directory (GthFileSourceVfs *file_source_vfs,
+ GFile *file)
{
- GthFileSourceVfs *file_source_vfs = (GthFileSourceVfs *) file_source;
- GFileMonitor *monitor;
+ GFile *parent;
- if (! activate) {
- g_hash_table_remove (file_source_vfs->priv->monitors, file);
- return;
+ parent = g_object_ref (file);
+ while (parent != NULL) {
+ GFile *tmp;
+
+ g_hash_table_remove (file_source_vfs->priv->monitors, parent);
+
+ tmp = g_file_get_parent (parent);
+ g_object_unref (parent);
+ parent = tmp;
}
+}
- if (g_hash_table_lookup (file_source_vfs->priv->monitors, file) != NULL)
- return;
- monitor = g_file_monitor_directory (file, 0, NULL, NULL);
- if (monitor == NULL)
- return;
+static void
+add_monitor_for_directory (GthFileSourceVfs *file_source_vfs,
+ GFile *file)
+{
+ GFile *parent;
+
+ parent = g_object_ref (file);
+ while (parent != NULL) {
+ GFile *tmp;
+
+ if (g_hash_table_lookup (file_source_vfs->priv->monitors, parent) == NULL) {
+ GFileMonitor *monitor;
+
+ monitor = g_file_monitor_directory (parent, 0, NULL, NULL);
+ if (monitor != NULL) {
+ g_hash_table_insert (file_source_vfs->priv->monitors, g_object_ref (parent), monitor);
+ g_signal_connect (monitor, "changed", G_CALLBACK (monitor_changed_cb), file_source_vfs);
+ }
+ }
+
+ tmp = g_file_get_parent (parent);
+ g_object_unref (parent);
+ parent = tmp;
+ }
+}
+
+
+static void
+gth_file_source_vfs_monitor_directory (GthFileSource *file_source,
+ GFile *file,
+ gboolean activate)
+{
+ GthFileSourceVfs *file_source_vfs = (GthFileSourceVfs *) file_source;
- g_hash_table_insert (file_source_vfs->priv->monitors, g_object_ref (file), monitor);
- g_signal_connect (monitor, "changed", G_CALLBACK (monitor_changed_cb), file_source);
+ if (activate)
+ add_monitor_for_directory (file_source_vfs, file);
+ else
+ remove_monitor_for_directory (file_source_vfs, file);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]