From 0dba8bb0cbb3b949f7c1edc371a4aca96fc84540 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Thu, 23 Jun 2005 21:52:54 +0000 Subject: [PATCH] 2005-06-23 Mike Kestner * gconf/GConf/Client.cs : support add/remove of a single notify handle to multiple directories. [Fixes #55877] svn path=/trunk/gtk-sharp/; revision=46456 --- ChangeLog | 5 +++ gconf/GConf/Client.cs | 73 +++++++++++++++++++++++++++++-------------- 2 files changed, 54 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4eb2b78a0..51916faf8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-06-23 Mike Kestner + + * gconf/GConf/Client.cs : support add/remove of a single notify handle + to multiple directories. [Fixes #55877] + 2005-06-22 Mike Kestner * sample/GladeTest.cs : add a menu item signal connect to test for the diff --git a/gconf/GConf/Client.cs b/gconf/GConf/Client.cs index 4a363eb97..b8cc881e8 100644 --- a/gconf/GConf/Client.cs +++ b/gconf/GConf/Client.cs @@ -27,7 +27,6 @@ namespace GConf { IntPtr Raw = IntPtr.Zero; Hashtable dirs = new Hashtable (); - Hashtable callbacks = new Hashtable (); [DllImport("gconf-2")] static extern IntPtr gconf_client_get_default (); @@ -78,44 +77,70 @@ namespace GConf [DllImport("gconf-2")] static extern uint gconf_client_add_dir (IntPtr client, string dir, int preload, out IntPtr err); - void AddDir (string dir) + DirectoryConnections GetConnections (string dir) { - IntPtr err; - if (dirs.Contains (dir)) - return; + return dirs [dir] as DirectoryConnections; - dirs.Add (dir, 1); + IntPtr err; gconf_client_add_dir (Raw, dir, 0, out err); if (err != IntPtr.Zero) throw new GLib.GException (err); + + DirectoryConnections result = new DirectoryConnections (this, dir); + dirs.Add (dir, result); + return result; } - [DllImport("gconf-2")] - static extern uint gconf_client_notify_add (IntPtr client, string dir, NotifyFuncNative func, IntPtr user_data, IntPtr destroy_notify, out IntPtr err); + class DirectoryConnections { + + string path; + IntPtr handle; + Hashtable connections = new Hashtable (); + + public DirectoryConnections (Client client, string dir) + { + handle = client.Raw; + path = dir; + } + + [DllImport("gconf-2")] + static extern uint gconf_client_notify_add (IntPtr client, string dir, NotifyFuncNative func, IntPtr user_data, IntPtr destroy_notify, out IntPtr err); + public void Add (NotifyEventHandler notify) + { + IntPtr error; + uint id = gconf_client_notify_add (handle, path, NotifyWrapper.Wrap (notify), IntPtr.Zero, IntPtr.Zero, out error); + if (error != IntPtr.Zero) + throw new GLib.GException (error); + + connections [id] = notify; + } + + [DllImport("gconf-2")] + static extern void gconf_client_notify_remove (IntPtr client, uint cnxn); + + public void Remove (NotifyEventHandler notify) + { + ArrayList removes = new ArrayList (); + foreach (uint id in connections.Keys) + if (connections [id] == notify) + removes.Add (id); + foreach (uint id in removes) { + gconf_client_notify_remove (handle, id); + connections.Remove (id); + } + } + } + public void AddNotify (string dir, NotifyEventHandler notify) { - IntPtr err; - - AddDir (dir); - uint cnxn = gconf_client_notify_add (Raw, dir, NotifyWrapper.Wrap (notify), IntPtr.Zero, IntPtr.Zero, out err); - if (err != IntPtr.Zero) - throw new GLib.GException (err); - callbacks.Add (notify, cnxn); + GetConnections (dir).Add (notify); } - [DllImport("gconf-2")] - static extern void gconf_client_notify_remove (IntPtr client, uint cnxn); - public void RemoveNotify (string dir, NotifyEventHandler notify) { - if (!callbacks.Contains (notify)) - return; - - uint cnxn = (uint) callbacks[notify]; - gconf_client_notify_remove (Raw, cnxn); - callbacks.Remove (notify); + GetConnections (dir).Remove (notify); } [DllImport("gconf-2")]