f-spot r3604 - in trunk: . src



Author: sdelcroix
Date: Tue Jan 29 15:07:32 2008
New Revision: 3604
URL: http://svn.gnome.org/viewvc/f-spot?rev=3604&view=rev

Log:
2008-01-29  Stephane Delcroix  <sdelcroix novell com>

	* src/Makefile.am:
	* src/IPreferenceBackend.cs:
	* src/Preferences.cs: abstract the backend operations.

	* src/GConfPreferenceBackend.cs: gconf as it used to be

	* src/NullPreferenceBackend.cs: a null backend, doing nothing but reverting
	to defaults.

	* src/PreferenceDialog.cs:
	* src/SingleView.cs:
	* src/MainWindow.cs: refer to the new handler signatures

	* configure.in: --disable-gconf at configure time


Added:
   trunk/src/GConfPreferenceBackend.cs
   trunk/src/IPreferenceBackend.cs
   trunk/src/NullPreferenceBackend.cs
Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/src/MainWindow.cs
   trunk/src/Makefile.am
   trunk/src/PreferenceDialog.cs
   trunk/src/Preferences.cs
   trunk/src/SingleView.cs

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Tue Jan 29 15:07:32 2008
@@ -69,7 +69,7 @@
 LCMS_REQUIRED=1.12
 dnl -- LIBGPHOTO2_REQUIRED=2.1.4
 
-PKG_CHECK_MODULES(F, libgnome-2.0 >= $LIBGNOME_REQUIRED libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED libexif >= $LIBEXIF_REQUIRED_MIN libexif < $LIBEXIF_REQUIRED_MAX gtkhtml-sharp-2.0 >= $GTKSHARP_REQUIRED gconf-sharp-2.0 >= $GTKSHARP_REQUIRED glade-sharp-2.0 >= $GTKSHARP_REQUIRED gnome-vfs-sharp-2.0 >= $GTKSHARP_REQUIRED gtk+-2.0 >= $GTK_REQUIRED mono >= $MONO_REQUIRED)
+PKG_CHECK_MODULES(F, libgnome-2.0 >= $LIBGNOME_REQUIRED libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED libexif >= $LIBEXIF_REQUIRED_MIN libexif < $LIBEXIF_REQUIRED_MAX gtkhtml-sharp-2.0 >= $GTKSHARP_REQUIRED glade-sharp-2.0 >= $GTKSHARP_REQUIRED gnome-vfs-sharp-2.0 >= $GTKSHARP_REQUIRED gtk+-2.0 >= $GTK_REQUIRED mono >= $MONO_REQUIRED)
 AC_SUBST(F_CFLAGS)
 AC_SUBST(F_LIBS)
 
@@ -80,9 +80,25 @@
 if pkg-config --atleast-version=2.11 gtk-sharp-2.0; then
    CSC_DEFINES="-d:GTK_2_11"
 fi
-if pkg-config --atleast-version=2.18 gconf-sharp-2.0; then
-  CSC_DEFINES="$CSC_DEFINES -d:GCONF_SHARP_2_18"
+
+dnl - Choose PreferenceBackend (default to gconf)
+AC_ARG_ENABLE([gconf],
+        [AC_HELP_STRING([--disable-gconf],
+                        [build without gconf preference backend])],,
+        enable_gconf=yes)
+AM_CONDITIONAL(ENABLE_GCONF, test "x$enable_gconf" = "xyes")
+
+if test "x$enable_gconf" = "xyes"; then
+  PKG_CHECK_MODULES(GCONF_SHARP, gconf-sharp-2.0 >= $GTKSHARP_REQUIRED)
+  if pkg-config --atleast-version=2.18 gconf-sharp-2.0; then
+    CSC_DEFINES="$CSC_DEFINES -d:GCONF_SHARP_2_18"
+  fi
+else
+  CSC_DEFINES="$CSC_DEFINES -d:NULLPREFERENCEBACKEND"
 fi
+
+
+
 AC_SUBST(CSC_DEFINES)
 
 PKG_CHECK_MODULES(BEAGLE, beagle-0.0 >= $BEAGLE_REQUIRED,

Added: trunk/src/GConfPreferenceBackend.cs
==============================================================================
--- (empty file)
+++ trunk/src/GConfPreferenceBackend.cs	Tue Jan 29 15:07:32 2008
@@ -0,0 +1,46 @@
+/*
+ * FSpot.GConfPreferenceBackend.cs
+ *
+ * Author(s):
+ *	Stephane Delcroix  <stephane delcroix org>
+ *
+ * This is free software. See COPYING for details.
+ */
+
+namespace FSpot
+{
+	public class GConfPreferenceBackend : IPreferenceBackend
+	{
+		private static GConf.Client client;
+		private GConf.Client Client {
+			get {
+				if (client == null)
+					client = new GConf.Client ();
+				return client;	
+			}
+		}
+
+		public GConfPreferenceBackend ()
+		{
+		}
+
+		public object Get (string key)
+		{
+			try {
+				return Client.Get (key);
+			} catch (GConf.NoSuchKeyException e) {
+				throw new NoSuchKeyException (key);
+			}
+		}
+
+		public void Set (string key, object o)
+		{
+			Client.Set (key, o);
+		}
+
+		public void AddNotify (string key, NotifyChangedHandler handler)
+		{
+			Client.AddNotify (key, delegate (object sender, GConf.NotifyEventArgs args) {handler (sender, new NotifyEventArgs (args.Key, args.Value));});
+		}
+	}
+}

Added: trunk/src/IPreferenceBackend.cs
==============================================================================
--- (empty file)
+++ trunk/src/IPreferenceBackend.cs	Tue Jan 29 15:07:32 2008
@@ -0,0 +1,50 @@
+/*
+ * FSpot.IPreferenceBackend.cs
+ *
+ * Author(s):
+ *	Stephane Delcroix  <stephane delcroix org>
+ *
+ * This is free software. See COPYING for details.
+ */
+
+namespace FSpot
+{
+	public class NotifyEventArgs : System.EventArgs
+	{
+		string key;
+		public string Key {
+			get { return key; }
+		}
+
+		object val;
+		public object Value {
+			get { return val; }
+		}
+
+		public NotifyEventArgs (string key, object val)
+		{
+			this.key = key;
+			this.val = val;
+		}
+	}
+
+	public class NoSuchKeyException : System.Exception
+	{
+		public NoSuchKeyException () : base ()
+		{
+		}
+
+		public NoSuchKeyException (string key) : base (key)
+		{
+		}
+	}
+
+	public delegate void NotifyChangedHandler (object sender, NotifyEventArgs args);
+
+	public interface IPreferenceBackend
+	{
+		object Get (string key);
+		void Set (string key, object value);	
+		void AddNotify (string key, NotifyChangedHandler handler);
+	}
+}

Modified: trunk/src/MainWindow.cs
==============================================================================
--- trunk/src/MainWindow.cs	(original)
+++ trunk/src/MainWindow.cs	Tue Jan 29 15:07:32 2008
@@ -2569,7 +2569,7 @@
 		query.Untagged = !query.Untagged;
 	}
 	
-	void OnPreferencesChanged (object sender, GConf.NotifyEventArgs args)
+	void OnPreferencesChanged (object sender, NotifyEventArgs args)
 	{
 		LoadPreference (args.Key);
 	}

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Tue Jan 29 15:07:32 2008
@@ -1,9 +1,9 @@
 include $(top_srcdir)/Makefile.include
 EXTRAFLAGS = -unsafe -nowarn:0169 -nowarn:0612 -nowarn:0414 -d:TEST_METADATA -d:BROKEN_RSVG $(NUNIT_DEFINES) $(BEAGLE_DEFINES) $(CSC_DEFINES)
 
-UTILS_CSDISTFILES =				\
-	$(srcdir)/Utils/GnomeUtil.cs		\
-	$(srcdir)/Utils/GtkUtil.cs		\
+UTILS_CSDISTFILES =					\
+	$(srcdir)/Utils/GnomeUtil.cs			\
+	$(srcdir)/Utils/GtkUtil.cs			\
 	$(srcdir)/Utils/ScreenSaver.cs
 
 CMS_CSDISTFILES =				\
@@ -14,7 +14,8 @@
 	$(srcdir)/Core/Category.cs		\
 	$(srcdir)/Core/DbItem.cs		\
 	$(srcdir)/Core/Tag.cs			\
-	$(srcdir)/Core/Global.cs
+	$(srcdir)/Core/Global.cs		\
+	$(srcdir)/Core/IPreferenceBackend.cs
 
 F_SPOT_CSDISTFILES =				\
 	$(srcdir)/Cairo/Antialias.cs		\
@@ -114,6 +115,7 @@
 	$(srcdir)/FotkiRemote.cs		\
 	$(srcdir)/FormClient.cs			\
 	$(srcdir)/FullScreenView.cs		\
+	$(srcdir)/GConfPreferenceBackend.cs	\
 	$(srcdir)/GdkGlx.cs			\
 	$(srcdir)/GlTransition.cs		\
 	$(srcdir)/GladeDialog.cs		\
@@ -164,6 +166,7 @@
 	$(srcdir)/MainWindow.cs			\
 	$(srcdir)/MetaStore.cs			\
 	$(srcdir)/MetadataStore.cs		\
+	$(srcdir)/NullPreferenceBackend.cs	\
 	$(srcdir)/Operation.cs			\
 	$(srcdir)/PhotoImageView.cs		\
 	$(srcdir)/PhotoLoader.cs		\

Added: trunk/src/NullPreferenceBackend.cs
==============================================================================
--- (empty file)
+++ trunk/src/NullPreferenceBackend.cs	Tue Jan 29 15:07:32 2008
@@ -0,0 +1,27 @@
+/*
+ * FSpot.NullPreferenceBackend.cs
+ *
+ * Author(s):
+ *	Stephane Delcroix  <stephane delcroix org>
+ *
+ * This is free software. See COPYING for details.
+ */
+
+namespace FSpot
+{
+	public class NullPreferenceBackend : IPreferenceBackend
+	{
+		public object Get (string key)
+		{
+			throw new NoSuchKeyException (key);
+		}
+
+		public void Set (string key, object o)
+		{
+		}
+
+		public void AddNotify (string key, NotifyChangedHandler handler)
+		{
+		}
+	}
+}

Modified: trunk/src/PreferenceDialog.cs
==============================================================================
--- trunk/src/PreferenceDialog.cs	(original)
+++ trunk/src/PreferenceDialog.cs	Tue Jan 29 15:07:32 2008
@@ -122,7 +122,7 @@
 				HandleTagMenuSelected (((tag_option.Menu as Menu).Active as TagMenu.TagMenuItem).Value);
 		}
 
-		void OnPreferencesChanged (object sender, GConf.NotifyEventArgs args)
+		void OnPreferencesChanged (object sender, NotifyEventArgs args)
 		{
 			LoadPreference (args.Key);
 		}

Modified: trunk/src/Preferences.cs
==============================================================================
--- trunk/src/Preferences.cs	(original)
+++ trunk/src/Preferences.cs	Tue Jan 29 15:07:32 2008
@@ -110,26 +110,27 @@
 		public const string PROXY_BYPASS_LIST = "/system/http_proxy/ignore_hosts";
 
 
-		private static GConf.Client client;
-		private static GConf.NotifyEventHandler changed_handler;
-		private static Dictionary<string, object> cache = new Dictionary<string, object>();
-
-		private static GConf.Client Client 
-		{
+		private static IPreferenceBackend backend;
+		private static NotifyChangedHandler changed_handler;
+		private static IPreferenceBackend Backend {
 			get {
-				if (client == null) {
-					client = new GConf.Client ();
-
-					changed_handler = new GConf.NotifyEventHandler (OnSettingChanged);
-					client.AddNotify ("/apps/f-spot", changed_handler);
-					client.AddNotify ("/apps/gnome-screensaver/themes", changed_handler);
-					client.AddNotify ("/apps/gnome-screensaver/mode", changed_handler);
-					client.AddNotify ("/desktop/gnome/url-handlers/mailto", changed_handler);
-					client.AddNotify ("/system/http_proxy", changed_handler);
+				if (backend == null) {
+#if !NULLPREFERENCEBACKEND
+					backend = new GConfPreferenceBackend ();
+#else
+					backend = new NullPreferenceBackend ();
+#endif
+					changed_handler = new NotifyChangedHandler (OnSettingChanged);
+					backend.AddNotify ("/apps/f-spot", changed_handler);
+					backend.AddNotify ("/apps/gnome-screensaver/themes", changed_handler);
+					backend.AddNotify ("/apps/gnome-screensaver/mode", changed_handler);
+					backend.AddNotify ("/desktop/gnome/url-handlers/mailto", changed_handler);
+					backend.AddNotify ("/system/http_proxy", changed_handler);
 				}
-				return client;
+				return backend;
 			}
 		}
+		private static Dictionary<string, object> cache = new Dictionary<string, object>();
 
 		public static object GetDefault (string key)
 		{
@@ -232,9 +233,9 @@
 					return val;
 
 				try {
-					val = Client.Get (key);
+					val = Backend.Get (key);
 					cache.Add (key, val);
-				} catch (GConf.NoSuchKeyException) {
+				} catch (NoSuchKeyException) {
 					val = GetDefault (key);
 
 					if (val != null)
@@ -250,7 +251,7 @@
 			lock (cache) {
 				try {
 					cache [key] = value;				
-					Client.Set (key, value);
+					Backend.Set (key, value);
 				} catch {
 					Console.WriteLine ("Unable to write this gconf key :"+key);
 				}
@@ -259,17 +260,17 @@
 
 		public static void SetAsBackground (string path)
 		{
-			Client.Set ("/desktop/gnome/background/color_shading_type", "solid");
-			Client.Set ("/desktop/gnome/background/primary_color", "#000000");
-			Client.Set ("/desktop/gnome/background/picture_options", "stretched");
-			Client.Set ("/desktop/gnome/background/picture_opacity", 100);
-			Client.Set ("/desktop/gnome/background/picture_filename", path);
-			Client.Set ("/desktop/gnome/background/draw_background", true);
+			Set ("/desktop/gnome/background/color_shading_type", "solid");
+			Set ("/desktop/gnome/background/primary_color", "#000000");
+			Set ("/desktop/gnome/background/picture_options", "stretched");
+			Set ("/desktop/gnome/background/picture_opacity", 100);
+			Set ("/desktop/gnome/background/picture_filename", path);
+			Set ("/desktop/gnome/background/draw_background", true);
 		}
 
-		public static event GConf.NotifyEventHandler SettingChanged;
+		public static event NotifyChangedHandler SettingChanged;
 
-		static void OnSettingChanged (object sender, GConf.NotifyEventArgs args)
+		static void OnSettingChanged (object sender, NotifyEventArgs args)
 		{
 			lock (cache) {
 				if (cache.ContainsKey (args.Key)) {

Modified: trunk/src/SingleView.cs
==============================================================================
--- trunk/src/SingleView.cs	(original)
+++ trunk/src/SingleView.cs	Tue Jan 29 15:07:32 2008
@@ -517,7 +517,7 @@
 			file_selector.Destroy ();
 		}
 
-		void OnPreferencesChanged (object sender, GConf.NotifyEventArgs args)
+		void OnPreferencesChanged (object sender, NotifyEventArgs args)
 		{
 			LoadPreference (args.Key);
 		}
@@ -635,7 +635,7 @@
 				prefs.Dialog.Present ();
 			}
 
-			void OnPreferencesChanged (object sender, GConf.NotifyEventArgs args)
+			void OnPreferencesChanged (object sender, NotifyEventArgs args)
 			{
 				LoadPreference (args.Key);
 			}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]