2004-06-25 18:42:19 +00:00
|
|
|
// Client.cs -
|
|
|
|
//
|
|
|
|
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of version 2 of the Lesser GNU General
|
|
|
|
// Public License as published by the Free Software Foundation.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this program; if not, write to the
|
|
|
|
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
// Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
|
2002-10-19 09:31:20 +00:00
|
|
|
namespace GConf
|
|
|
|
{
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
public class Client : ClientBase
|
|
|
|
{
|
|
|
|
IntPtr Raw = IntPtr.Zero;
|
|
|
|
Hashtable dirs = new Hashtable ();
|
|
|
|
|
|
|
|
[DllImport("gconf-2")]
|
|
|
|
static extern IntPtr gconf_client_get_default ();
|
|
|
|
|
|
|
|
public Client ()
|
|
|
|
{
|
|
|
|
Initialize ();
|
|
|
|
Raw = gconf_client_get_default ();
|
|
|
|
}
|
|
|
|
|
|
|
|
internal Client (IntPtr raw)
|
|
|
|
{
|
|
|
|
Initialize ();
|
|
|
|
Raw = raw;
|
|
|
|
}
|
|
|
|
|
|
|
|
[DllImport("gconf-2")]
|
|
|
|
static extern void gconf_client_set (IntPtr client, string key, IntPtr val, out IntPtr err);
|
|
|
|
|
2003-05-27 06:27:26 +00:00
|
|
|
internal override void SetValue (string key, Value val)
|
2002-10-19 09:31:20 +00:00
|
|
|
{
|
|
|
|
IntPtr err;
|
|
|
|
gconf_client_set (Raw, key, val.Handle, out err);
|
|
|
|
if (err != IntPtr.Zero)
|
|
|
|
throw new GLib.GException (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
[DllImport("gconf-2")]
|
|
|
|
static extern IntPtr gconf_client_get (IntPtr client, string key, out IntPtr err);
|
|
|
|
|
|
|
|
public override object Get (string key)
|
|
|
|
{
|
2003-02-13 03:05:17 +00:00
|
|
|
if (key == null)
|
|
|
|
throw new ArgumentNullException ("key");
|
|
|
|
|
2002-10-19 09:31:20 +00:00
|
|
|
IntPtr err;
|
|
|
|
IntPtr raw = gconf_client_get (Raw, key, out err);
|
|
|
|
if (err != IntPtr.Zero)
|
|
|
|
throw new GLib.GException (err);
|
2003-02-13 03:05:17 +00:00
|
|
|
|
2002-10-19 09:31:20 +00:00
|
|
|
if (raw == IntPtr.Zero)
|
2003-02-13 03:05:17 +00:00
|
|
|
throw new NoSuchKeyException (key);
|
2002-10-19 09:31:20 +00:00
|
|
|
|
|
|
|
Value val = new Value (raw);
|
|
|
|
return val.Get ();
|
|
|
|
}
|
|
|
|
|
|
|
|
[DllImport("gconf-2")]
|
|
|
|
static extern uint gconf_client_add_dir (IntPtr client, string dir, int preload, out IntPtr err);
|
|
|
|
|
2005-06-23 21:52:54 +00:00
|
|
|
DirectoryConnections GetConnections (string dir)
|
2002-10-19 09:31:20 +00:00
|
|
|
{
|
|
|
|
if (dirs.Contains (dir))
|
2005-06-23 21:52:54 +00:00
|
|
|
return dirs [dir] as DirectoryConnections;
|
2002-10-19 09:31:20 +00:00
|
|
|
|
2005-06-23 21:52:54 +00:00
|
|
|
IntPtr err;
|
2002-10-19 09:31:20 +00:00
|
|
|
gconf_client_add_dir (Raw, dir, 0, out err);
|
|
|
|
if (err != IntPtr.Zero)
|
|
|
|
throw new GLib.GException (err);
|
2005-06-23 21:52:54 +00:00
|
|
|
|
|
|
|
DirectoryConnections result = new DirectoryConnections (this, dir);
|
|
|
|
dirs.Add (dir, result);
|
|
|
|
return result;
|
2002-10-19 09:31:20 +00:00
|
|
|
}
|
|
|
|
|
2005-06-23 21:52:54 +00:00
|
|
|
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);
|
2002-10-19 09:31:20 +00:00
|
|
|
|
2005-06-23 21:52:54 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-19 09:31:20 +00:00
|
|
|
public void AddNotify (string dir, NotifyEventHandler notify)
|
|
|
|
{
|
2005-06-23 21:52:54 +00:00
|
|
|
GetConnections (dir).Add (notify);
|
2002-10-19 09:31:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void RemoveNotify (string dir, NotifyEventHandler notify)
|
|
|
|
{
|
2005-06-23 21:52:54 +00:00
|
|
|
GetConnections (dir).Remove (notify);
|
2002-10-19 09:31:20 +00:00
|
|
|
}
|
2003-02-08 10:11:56 +00:00
|
|
|
|
|
|
|
[DllImport("gconf-2")]
|
|
|
|
static extern void gconf_client_suggest_sync (IntPtr client, out IntPtr err);
|
|
|
|
|
|
|
|
public void SuggestSync ()
|
|
|
|
{
|
|
|
|
IntPtr err;
|
|
|
|
gconf_client_suggest_sync (Raw, out err);
|
|
|
|
if (err != IntPtr.Zero)
|
|
|
|
throw new GLib.GException (err);
|
|
|
|
}
|
2002-10-19 09:31:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|