[Gtk-sharp-list] GConf Client patch

Gonzalo Paniagua Javier gonzalo@ximian.com
10 Feb 2003 10:05:48 +0100


--=-5vso6S5LDo60r+uRK7P9
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi there!

While testing the latest changes in monotalk, it bailed out because it
didn't find the gconf keys it was looking for.

The attached patch adds a new Get method to GConf.Client that takes a
default value to be returned when the key is not found.

Ok to commit?

-Gonzalo


--=-5vso6S5LDo60r+uRK7P9
Content-Disposition: attachment; filename=gconf.patch
Content-Type: text/x-patch; name=gconf.patch; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Index: ChangeLog
===================================================================
RCS file: /cvs/public/gtk-sharp/ChangeLog,v
retrieving revision 1.312
diff -u -r1.312 ChangeLog
--- ChangeLog	10 Feb 2003 08:30:58 -0000	1.312
+++ ChangeLog	10 Feb 2003 09:07:35 -0000
@@ -1,5 +1,13 @@
 2003-02-10  Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
+	* gconf/GConf/Client.cs: added a new Get method which takes a default
+	value to be returned when the key is not found.
+
+	* gconf/GConf/NoSuchKeyException.cs: added a couple of ctors to display
+	useful messages.
+
+2003-02-10  Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
 	* glade/XML.custom: added a couple of checks for null.
 
 2003-02-09  Duncan Mak  <duncan@ximian.com>
Index: gconf/GConf/Client.cs
===================================================================
RCS file: /cvs/public/gtk-sharp/gconf/GConf/Client.cs,v
retrieving revision 1.2
diff -u -r1.2 Client.cs
--- gconf/GConf/Client.cs	8 Feb 2003 10:11:56 -0000	1.2
+++ gconf/GConf/Client.cs	10 Feb 2003 09:07:35 -0000
@@ -41,15 +41,26 @@
 
 		public override object Get (string key)
 		{
+			return Get (key, null);
+		}
+
+		public object Get (string key, object dflt)
+		{
+			if (key == null)
+				throw new ArgumentNullException ("key");
+
 			IntPtr err;
 			IntPtr raw = gconf_client_get (Raw, key, out err);
 			if (err != IntPtr.Zero)
 				throw new GLib.GException (err);
-			if (raw == IntPtr.Zero)
-				throw new NoSuchKeyException ();
+			
+			if (raw != IntPtr.Zero)
+				return new Value (raw).Get ();
+
+			if (dflt == null)
+				throw new NoSuchKeyException (key);
 
-			Value val = new Value (raw);
-			return val.Get ();
+			return dflt;
 		}
 
 		[DllImport("gconf-2")]
Index: gconf/GConf/NoSuchKeyException.cs
===================================================================
RCS file: /cvs/public/gtk-sharp/gconf/GConf/NoSuchKeyException.cs,v
retrieving revision 1.1
diff -u -r1.1 NoSuchKeyException.cs
--- gconf/GConf/NoSuchKeyException.cs	19 Oct 2002 09:31:19 -0000	1.1
+++ gconf/GConf/NoSuchKeyException.cs	10 Feb 2003 09:07:35 -0000
@@ -4,5 +4,15 @@
 	
 	public class NoSuchKeyException : Exception
 	{
+		public NoSuchKeyException ()
+			: base ("The requested GConf key was not found")
+		{
+		}
+
+		public NoSuchKeyException (string key)
+			: base ("Key '" + key + "' not found in GConf")
+		{
+		}
 	}
 }
+

--=-5vso6S5LDo60r+uRK7P9--