Author: mhabersack
Date: 2007-06-28 19:15:34 -0400 (Thu, 28 Jun 2007)
New Revision: 81013
Modified:
trunk/moon/ChangeLog
trunk/moon/desklet/Makefile
trunk/moon/desklet/desklets.cs
trunk/moon/desklet/docs/index.xml
trunk/moon/desklet/weather/default.xaml.cs
Log:
2007-06-29 Marek Habersack <[EMAIL PROTECTED]>
* desklet/desklets.cs: added GConf config storage backend.
Modified: trunk/moon/ChangeLog
===================================================================
--- trunk/moon/ChangeLog 2007-06-28 22:34:59 UTC (rev 81012)
+++ trunk/moon/ChangeLog 2007-06-28 23:15:34 UTC (rev 81013)
@@ -1,3 +1,7 @@
+2007-06-29 Marek Habersack <[EMAIL PROTECTED]>
+
+ * desklet/desklets.cs: added GConf config storage backend.
+
2007-06-28 Marek Habersack <[EMAIL PROTECTED]>
* desklet/desklets.cs: beginnings of the config storage code.
Modified: trunk/moon/desklet/Makefile
===================================================================
--- trunk/moon/desklet/Makefile 2007-06-28 22:34:59 UTC (rev 81012)
+++ trunk/moon/desklet/Makefile 2007-06-28 23:15:34 UTC (rev 81013)
@@ -1,7 +1,7 @@
all: docs/Mono.Desklets.xml desklets.dll
desklets.dll desklets.xml: desklets.cs
- gmcs -debug -doc:desklets.xml -target:library desklets.cs -pkg:silver
-pkg:gtk-sharp-2.0
+ gmcs -debug -doc:desklets.xml -target:library desklets.cs -pkg:silver
-pkg:gtk-sharp-2.0 -pkg:gconf-sharp-2.0
docs/Mono.Desklets.xml: desklets.xml desklets.dll
monodocer -importslashdoc:desklets.xml -path:docs -assembly:desklets.dll
Modified: trunk/moon/desklet/desklets.cs
===================================================================
--- trunk/moon/desklet/desklets.cs 2007-06-28 22:34:59 UTC (rev 81012)
+++ trunk/moon/desklet/desklets.cs 2007-06-28 23:15:34 UTC (rev 81013)
@@ -29,6 +29,7 @@
using System;
using System.Windows;
using Gtk;
+using GConf;
namespace Mono.Desklets {
@@ -39,7 +40,8 @@
{
string deskletName;
int deskletInstance;
-
+ string storageName;
+
/// <summary>
/// Desklet name
/// </summary>
@@ -63,6 +65,13 @@
get { return deskletInstance; }
}
+ protected string StorageName {
+ get { return storageName; }
+ }
+
+ protected ConfigStorage () : this (null, -1)
+ {}
+
/// <summary>
/// Construct new storage class using the specified desklet
name
/// </summary>
@@ -91,7 +100,20 @@
{
this.deskletName = deskletName;
this.deskletInstance = deskletInstance;
+
+ if (deskletInstance >= 0)
+ storageName = String.Format ("{0}_{1}",
deskletName, deskletInstance);
+ else
+ storageName = deskletName;
}
+
+ protected void CheckValid ()
+ {
+ if (String.IsNullOrEmpty (deskletName))
+ throw new ApplicationException ("DeskletName
must not be empty");
+ if (String.IsNullOrEmpty (storageName))
+ throw new ApplicationException ("No storage
name specified");
+ }
/// <summary>
/// Stores the named configuration item with the specified
value.
@@ -141,8 +163,93 @@
/// <returns>
/// The requested item's value or null if not found
/// </returns>
- public abstract object RetrieveCommon (string name);
+ public abstract object RetrieveCommon (string name);
}
+
+ public class GConfConfigStorage : ConfigStorage {
+ readonly string baseKeyPath = "/apps/mono/desklets";
+
+ GConf.Client client;
+
+ string keyPathCommon;
+ string keyPathInstance;
+
+ public string KeyPathCommon {
+ get {
+ if (keyPathCommon == null)
+ keyPathCommon = String.Format
("{0}/{1}", baseKeyPath, DeskletName);
+
+ return keyPathCommon;
+ }
+ }
+
+ public string KeyPathInstance {
+ get {
+ if (keyPathInstance == null)
+ if (DeskletInstance >= 0)
+ keyPathInstance = String.Format
("{0}/{1}/{2}", baseKeyPath, DeskletName,
+
DeskletInstance);
+ else
+ keyPathInstance = KeyPathCommon;
+
+ return keyPathInstance;
+ }
+ }
+
+ public GConfConfigStorage (string deskletName) : this
(deskletName, -1)
+ {}
+
+ public GConfConfigStorage (string deskletName, int
deskletInstance)
+ : base (deskletName, deskletInstance)
+ {
+ client = new GConf.Client ();
+ }
+
+ public override void Store (string name, object value)
+ {
+ CheckValid ();
+
+ string key = String.Format ("{0}/{1}", KeyPathInstance,
name);
+ client.Set (key, value);
+ }
+
+ public override void StoreCommon (string name, object value)
+ {
+ string key = String.Format ("{0}/{1}", KeyPathCommon,
name);
+ client.Set (key, value);
+ CheckValid ();
+ }
+
+ public override object Retrieve (string name)
+ {
+ CheckValid ();
+
+ object ret = null;
+ string key = String.Format ("{0}/{1}", KeyPathInstance,
name);
+ try {
+ ret = client.Get (key);
+ } catch (GConf.NoSuchKeyException) {
+ ret = null;
+ }
+
+ return ret;
+ }
+
+ public override object RetrieveCommon (string name)
+ {
+ CheckValid ();
+
+ object ret = null;
+ string key = String.Format ("{0}/{1}", KeyPathCommon,
name);
+ try {
+ ret = client.Get (key);
+ } catch (GConf.NoSuchKeyException) {
+ ret = null;
+ }
+
+ return ret;
+ }
+ }
/// <summary>
/// Provides utility functions for Desklet developers
Modified: trunk/moon/desklet/docs/index.xml
===================================================================
--- trunk/moon/desklet/docs/index.xml 2007-06-28 22:34:59 UTC (rev 81012)
+++ trunk/moon/desklet/docs/index.xml 2007-06-28 23:15:34 UTC (rev 81013)
@@ -13,7 +13,9 @@
<Copyright>Copyright 2007, Novell, Inc..</Copyright>
<Types>
<Namespace Name="Mono.Desklets">
+ <Type Name="ConfigStorage" />
<Type Name="Desklet" />
+ <Type Name="GconfConfigStorage" />
</Namespace>
</Types>
<Title>desklets</Title>
Modified: trunk/moon/desklet/weather/default.xaml.cs
===================================================================
--- trunk/moon/desklet/weather/default.xaml.cs 2007-06-28 22:34:59 UTC (rev
81012)
+++ trunk/moon/desklet/weather/default.xaml.cs 2007-06-28 23:15:34 UTC (rev
81013)
@@ -121,6 +121,8 @@
double windIconTop;
double windIconLeft;
+
+ GConfConfigStorage config = new GConfConfigStorage ("Weather",
0);
public void DownloadComplete (Downloader downloader)
{
@@ -488,6 +490,8 @@
val = (string) model.GetValue (iter, 1);
if (val == "Location")
val = (string) model.GetValue
(iter, 2);
+ else
+ val = null;
}
win.Hide ();
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches