On Tue, 2007-07-17 at 18:45 +0200, Mario Manno wrote:
> Hi,
> 

> From looking at the source of gnome-sharp2, i guess there is no support
> for the Schema return type.

I wrote a little patch to address this problem.
This patch doesn't add gconf_schema_new and gconf_schema_set_* support,
but get_* should be sufficient for most use cases.

I guess I could implement the other functions if you consider them
useful.

cheers,
Mario

--- gconf/GConf/Makefile.am	(revision 647)
+++ gconf/GConf/Makefile.am	(local)
@@ -32,6 +32,7 @@
 	NotifyEventArgs.cs 	\
 	NotifyEventHandler.cs 	\
 	NotifyWrapper.cs 	\
+	Schema.cs 		\
 	Value.cs
 
 build_sources = $(addprefix $(srcdir)/, $(sources)) ../../AssemblyInfo.cs
--- gconf/GConf/Makefile.in	(revision 647)
+++ gconf/GConf/Makefile.in	(local)
@@ -258,6 +258,7 @@
 	NotifyEventArgs.cs 	\
 	NotifyEventHandler.cs 	\
 	NotifyWrapper.cs 	\
+	Schema.cs 	\
 	Value.cs
 
 build_sources = $(addprefix $(srcdir)/, $(sources)) ../../AssemblyInfo.cs
--- gconf/GConf/Value.cs	(revision 647)
+++ gconf/GConf/Value.cs	(local)
@@ -159,6 +159,9 @@
 		
 		[DllImport("gconf-2")]
 		static extern IntPtr gconf_value_get_list (IntPtr value);
+
+		[DllImport("gconf-2")]
+		static extern IntPtr gconf_value_get_schema (IntPtr value);
 		
 		public object Get ()
 		{
@@ -183,6 +186,8 @@
 					}
 
 					return result;
+				case ValueType.Schema:
+					return new Schema (gconf_value_get_schema (Raw));
 				default:
 					throw new InvalidValueTypeException ();
 			}
--- gconf/GConf/Schema.cs	(revision 647)
+++ gconf/GConf/Schema.cs	(local)
@@ -0,0 +1,76 @@
+namespace GConf
+{
+	using System;
+	using System.Collections;
+	using System.Runtime.InteropServices;
+
+	public class Schema
+	{
+		[DllImport("gconf-2")]
+		static extern ValueType gconf_schema_get_type (IntPtr value);
+		[DllImport("gconf-2")]
+		static extern ValueType gconf_schema_get_car_type (IntPtr value);
+		[DllImport("gconf-2")]
+		static extern ValueType gconf_schema_get_cdr_type (IntPtr value);
+		[DllImport("gconf-2")]
+		static extern ValueType gconf_schema_get_list_type (IntPtr value);
+		[DllImport("gconf-2")]
+		static extern IntPtr gconf_schema_get_default_value (IntPtr value);
+		[DllImport("gconf-2")]
+		static extern IntPtr gconf_schema_get_locale (IntPtr value);
+		[DllImport("gconf-2")]
+		static extern IntPtr gconf_schema_get_short_desc (IntPtr value);
+		[DllImport("gconf-2")]
+		static extern IntPtr gconf_schema_get_long_desc (IntPtr value);
+		[DllImport("gconf-2")]
+		static extern IntPtr gconf_schema_get_owner (IntPtr value);
+
+		string locale, short_desc, long_desc, owner;
+		object type, cdr_type, car_type, list_type, default_value;
+
+		public Schema (IntPtr Raw)
+		{
+			type = FindType(gconf_schema_get_type (Raw));
+			cdr_type = FindType(gconf_schema_get_cdr_type (Raw));
+			car_type = FindType(gconf_schema_get_car_type (Raw));
+			list_type =  FindType(gconf_schema_get_list_type (Raw));
+			locale = GLib.Marshaller.Utf8PtrToString (gconf_schema_get_locale(Raw));
+			short_desc = GLib.Marshaller.Utf8PtrToString (gconf_schema_get_short_desc(Raw));
+			long_desc = GLib.Marshaller.Utf8PtrToString (gconf_schema_get_long_desc(Raw));
+			owner = GLib.Marshaller.Utf8PtrToString (gconf_schema_get_owner(Raw));
+			Value val = new Value (gconf_schema_get_default_value(Raw));
+			default_value = val.Get ();
+			val.Dispose();
+		}
+
+		object FindType (ValueType vt)
+		{
+			switch (vt) {
+			case ValueType.String:
+				return typeof (string);
+			case ValueType.Int:
+				return typeof (int);
+			case ValueType.Float:
+				return typeof (float);
+			case ValueType.Bool:
+				return typeof (bool);
+			case ValueType.List:
+				return typeof (GLib.SList);
+			case ValueType.Invalid:
+				return null;
+			default:
+				throw new InvalidValueTypeException ();
+			}
+		}
+
+		public object Type { get { return type; } }
+		public object CdrType { get { return cdr_type; } }
+		public object CarType { get { return car_type;; } }
+		public object ListType { get { return list_type;; } }
+		public object Locale { get { return locale; } }
+		public object ShortDesc { get { return short_desc; } }
+		public object LongDesc { get { return long_desc; } }
+		public object Owner { get { return owner; } }
+		public object DefaultValue { get { return default_value; } }
+	}
+}
_______________________________________________
Gtk-sharp-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Reply via email to