[Gtk-sharp-list] GConf replacement

Pablo Baena pbaena@uol.com.ar
26 Apr 2003 09:15:32 +0000


--=-MNkoYGgj488GbJoWFlCp
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit

Hi! I told you some time ago that I was avoiding gconf because of a few
issues. Well, I finished some prototype of what I'm doing to replace
gconf# in my project.

The nifty thing works this way. First you define an interface like this:


	interface IMySettings 
	{
		[GeSettings.Property ("GnoMencoder", 
				      "/dev/cdroms/cdrom0", 
				      "DVD Device")]
		string DVDDevice 
		{
			get; 
			set;
		}
	}

The arguments of the attribute are: name of the app, default value and
description, respectively.

Then you pass the interface to a magic machine like this:


IMySettings mySettings = (IMySettings) 
	GeSettings.Builder.Build (typeof(IMySettings));


Et voilá, you'll have a mySettings.DVDDevice to use as any other
property, only that any changes to it will be recorded in a XML file on
your home directory for future sessions, and all get operations will
retrieve that setting from said XML file (without you having to know
_anything_ about XML).

With this we avoided all the steps we had to make with gconf#, that
were:

* create a GConf schema (learn how to make one)
* run gconf-schemagen over it to create the class
* have root priviledges to install the schema

And there is more! With another class I created (it is apart so one
doesn't have to depend on gtk# for other uses), one can do this:



	interface IMySettings 
	{
		[GeSettings.Property ("GnoMencoder", 
				      "/dev/cdroms/cdrom0", 
				      "DVD Device",
				      WidgetName="dvddevice_entry")]
		string DVDDevice 
		{
			get; 
			set;
		}
	}

And, with this function:


IMySettings mySettings = (IMySettings) 
	GeSettings.GladeBuilder.Build (typeof(IMySettings), gxml);

we'll have the property associated with the widget on the glade
resource, which will update the value on the Changed events and display
the value on Realized.

The classes are in a very very alpha state yet, and aren't optimized in
any way, so I didn't released them to the public. Anyway, the quality is
poor because they're 'inside use only' and it serves its purpose for
what I'm doing. If there is enough interest on making them available
independently, I can do the work. It only supports storing string
settings by now, doesn't monitor the settings for external changes as
GConf does and only supports Entry widgets, but that can change, and I
can do it without adding anything complicated to the API.

Do you think I should make it releasable?

Cheers!

PS: I hate to reinvent the wheel, but I just don't like gconf. It is
good at what it does, but complicates something that should be MUCH
easier.

-- 
Pablo Baena <pbaena@uol.com.ar>

--=-MNkoYGgj488GbJoWFlCp
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/1.1.7">
</HEAD>
<BODY>
Hi! I told you some time ago that I was avoiding gconf because of a few issues. Well, I finished some prototype of what I'm doing to replace gconf# in my project.<BR>
<BR>
The nifty thing works this way. First you define an interface like this:<BR>
<BR>
<PRE>	interface IMySettings 
	{
		[GeSettings.Property (&quot;GnoMencoder&quot;, 
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;/dev/cdroms/cdrom0&quot;, 
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;DVD Device&quot;)]
		string DVDDevice 
		{
			get; 
			set;
		}
	}</PRE>
The arguments of the attribute are: name of the app, default value and description, respectively.<BR>
<BR>
Then you pass the interface to a magic machine like this:<BR>
<BR>
<PRE>IMySettings mySettings = (IMySettings) 
	GeSettings.Builder.Build (typeof(IMySettings));
</PRE>
Et voil&#225;, you'll have a mySettings.DVDDevice to use as any other property, only that any changes to it will be recorded in a XML file on your home directory for future sessions, and all get operations will retrieve that setting from said XML file (without you having to know _anything_ about XML).<BR>
<BR>
With this we avoided all the steps we had to make with gconf#, that were:<BR>
<BR>
* create a <FONT COLOR="#a020f0" SIZE="3"><B>GConf</B></FONT> schema (learn how to make one)<BR>
* run <FONT COLOR="#a020f0" SIZE="3"><B>gconf</B></FONT>-schemagen over it to create the class<BR>
* have root priviledges to install the schema<BR>
<BR>
And there is more! With another class I created (it is apart so one doesn't have to depend on gtk# for other uses), one can do this:<BR>
<BR>
<BR>
<PRE>	interface IMySettings 
	{
		[GeSettings.Property (&quot;GnoMencoder&quot;, 
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;/dev/cdroms/cdrom0&quot;, 
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;DVD Device&quot;,
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <B>WidgetName=&quot;dvddevice_entry&quot;</B>)]
		string DVDDevice 
		{
			get; 
			set;
		}
	}</PRE>
And, with this function:<BR>
<BR>
<PRE>IMySettings mySettings = (IMySettings) 
	GeSettings.GladeBuilder.Build (typeof(IMySettings), gxml);</PRE>
we'll have the property associated with the widget on the glade resource, which will update the value on the Changed events and display the value on Realized.<BR>
<BR>
The classes are in a very very alpha state yet, and aren't optimized in any way, so I didn't released them to the public. Anyway, the quality is poor because they're 'inside use only' and it serves its purpose for what I'm doing. If there is enough interest on making them available independently, I can do the work. It only supports storing string settings by now, doesn't monitor the settings for external changes as GConf does and only supports Entry widgets, but that can change, and I can do it without adding anything complicated to the API.<BR>
<BR>
Do you think I should make it releasable?<BR>
<BR>
Cheers!<BR>
<BR>
PS: I hate to reinvent the wheel, but I just don't like gconf. It is good at what it does, but complicates something that should be MUCH easier.<BR>
<BR>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
-- <BR>
Pablo Baena &lt;<A HREF="mailto:pbaena@uol.com.ar">pbaena@uol.com.ar</A>&gt;
</TD>
</TR>
</TABLE>

</BODY>
</HTML>

--=-MNkoYGgj488GbJoWFlCp--