tomboy r2098 - in branches/tomboy-portable2: . Tomboy Tomboy/Addins/InsertTimestamp



Author: sharm
Date: Tue Aug 26 19:16:24 2008
New Revision: 2098
URL: http://svn.gnome.org/viewvc/tomboy?rev=2098&view=rev

Log:
* Tomboy.mdp, Tomboy/Makefile.am: Add new files.
* Tomboy/PlatformFactory.cs, Tomboy/Services.cs: Really basic factory
  and services stuff for getting platform-specific services.
* Tomboy/PreferencesDialog.cs: Just an idea for a way to leave out the
  Keybinding tab of the prefs dialog if there's no keybinding
  implementation.
* Tomboy/XmlPreferencesClient.cs, Tomboy/NoteEditor.cs,
  Tomboy/GConfPreferencesClient.cs, Tomboy/Watchers.cs,
  Tomboy/NoteWindow.cs,
  Tomboy/Addins/InsertTimestamp/InsertTimestampNoteAddin.cs,
  Tomboy/NoteManager.cs, Tomboy/PreferencesClient.cs,
  Tomboy/Preferences.cs: Portable preferences client from
  tomboy-portable.
* Tomboy/Applet.cs, Tomboy/PrefsKeybinder.cs, Tomboy/Keybinder.cs,
  Tomboy/Tray.cs, Tomboy/XKeybinder.cs: Portable keybinder from
  tomboy-portable.
* Tomboy/Utils.cs, Tomboy/GnomeApplication.cs,
  Tomboy/GtkApplication.cs, Tomboy/NativeApplication.cs: Portable
  "native application" code from tomboy-portable.

Added:
   branches/tomboy-portable2/Tomboy/GConfPreferencesClient.cs   (contents, props changed)
   branches/tomboy-portable2/Tomboy/GnomeApplication.cs   (contents, props changed)
   branches/tomboy-portable2/Tomboy/GtkApplication.cs   (contents, props changed)
   branches/tomboy-portable2/Tomboy/Keybinder.cs   (contents, props changed)
   branches/tomboy-portable2/Tomboy/NativeApplication.cs   (contents, props changed)
   branches/tomboy-portable2/Tomboy/PlatformFactory.cs   (contents, props changed)
   branches/tomboy-portable2/Tomboy/PreferencesClient.cs   (contents, props changed)
   branches/tomboy-portable2/Tomboy/PrefsKeybinder.cs   (contents, props changed)
   branches/tomboy-portable2/Tomboy/Services.cs   (contents, props changed)
   branches/tomboy-portable2/Tomboy/XmlPreferencesClient.cs   (contents, props changed)
Modified:
   branches/tomboy-portable2/ChangeLog
   branches/tomboy-portable2/Tomboy.mdp
   branches/tomboy-portable2/Tomboy/Addins/InsertTimestamp/InsertTimestampNoteAddin.cs
   branches/tomboy-portable2/Tomboy/Applet.cs
   branches/tomboy-portable2/Tomboy/Makefile.am
   branches/tomboy-portable2/Tomboy/NoteEditor.cs
   branches/tomboy-portable2/Tomboy/NoteManager.cs
   branches/tomboy-portable2/Tomboy/NoteWindow.cs
   branches/tomboy-portable2/Tomboy/Preferences.cs
   branches/tomboy-portable2/Tomboy/PreferencesDialog.cs
   branches/tomboy-portable2/Tomboy/Tray.cs
   branches/tomboy-portable2/Tomboy/Utils.cs
   branches/tomboy-portable2/Tomboy/Watchers.cs
   branches/tomboy-portable2/Tomboy/XKeybinder.cs

Modified: branches/tomboy-portable2/Tomboy.mdp
==============================================================================
--- branches/tomboy-portable2/Tomboy.mdp	(original)
+++ branches/tomboy-portable2/Tomboy.mdp	Tue Aug 26 19:16:24 2008
@@ -206,6 +206,16 @@
     <File name="Tomboy/Addins/GalagoPresence/GalagoPresenceNoteAddin.cs" subtype="Code" buildaction="Compile" />
     <File name="Tomboy/RecentTreeView.cs" subtype="Code" buildaction="Compile" />
     <File name="Mono.Addins/Mono.Addins/Mono.Addins/InstanceExtensionNode.cs" subtype="Code" buildaction="Compile" />
+    <File name="Tomboy/Services.cs" subtype="Code" buildaction="Compile" />
+    <File name="Tomboy/GConfPreferencesClient.cs" subtype="Code" buildaction="Compile" />
+    <File name="Tomboy/GnomeApplication.cs" subtype="Code" buildaction="Compile" />
+    <File name="Tomboy/Keybinder.cs" subtype="Code" buildaction="Compile" />
+    <File name="Tomboy/NativeApplication.cs" subtype="Code" buildaction="Compile" />
+    <File name="Tomboy/PlatformFactory.cs" subtype="Code" buildaction="Compile" />
+    <File name="Tomboy/PreferencesClient.cs" subtype="Code" buildaction="Compile" />
+    <File name="Tomboy/PrefsKeybinder.cs" subtype="Code" buildaction="Compile" />
+    <File name="Tomboy/GtkApplication.cs" subtype="Code" buildaction="Compile" />
+    <File name="Tomboy/XmlPreferencesClient.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="gdk-sharp, Version=2.8.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
@@ -218,6 +228,7 @@
     <ProjectReference type="Gac" localcopy="True" refto="pango-sharp, Version=2.10.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
     <ProjectReference type="Gac" localcopy="True" refto="Mono.Cairo, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
   </References>
+  <GtkDesignInfo gtkVersion="2.10.3" />
   <MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="True" RelativeMakefileName="./Makefile.am" ExecuteTargetName="run">
     <BuildFilesVar />
     <DeployFilesVar />

Modified: branches/tomboy-portable2/Tomboy/Addins/InsertTimestamp/InsertTimestampNoteAddin.cs
==============================================================================
--- branches/tomboy-portable2/Tomboy/Addins/InsertTimestamp/InsertTimestampNoteAddin.cs	(original)
+++ branches/tomboy-portable2/Tomboy/Addins/InsertTimestamp/InsertTimestampNoteAddin.cs	Tue Aug 26 19:16:24 2008
@@ -47,7 +47,7 @@
 			Buffer.InsertWithTagsByName (ref cursor, text, "datetime");
 		}
 
-		void OnFormatSettingChanged (object sender, GConf.NotifyEventArgs args)
+		void OnFormatSettingChanged (object sender, NotifyEventArgs args)
 		{
 			if (args.Key == Preferences.INSERT_TIMESTAMP_FORMAT)
 				date_format = (string) args.Value;

Modified: branches/tomboy-portable2/Tomboy/Applet.cs
==============================================================================
--- branches/tomboy-portable2/Tomboy/Applet.cs	(original)
+++ branches/tomboy-portable2/Tomboy/Applet.cs	Tue Aug 26 19:16:24 2008
@@ -13,7 +13,7 @@
 	{
 		NoteManager manager;
 		TomboyAppletEventBox applet_event_box;
-		TomboyGConfXKeybinder keybinder;
+		TomboyPrefsKeybinder keybinder;
 
 		// Keep referenced so our callbacks don't get reaped.
 		static BonoboUIVerb [] menu_verbs;
@@ -43,7 +43,7 @@
 
 			manager = Tomboy.DefaultNoteManager;
 			applet_event_box = new TomboyAppletEventBox (manager);
-			keybinder = new TomboyGConfXKeybinder (manager, applet_event_box.Tray);
+			keybinder = new TomboyPrefsKeybinder (manager, applet_event_box.Tray);
 
 			Flags |= PanelAppletFlags.ExpandMinor;
 

Added: branches/tomboy-portable2/Tomboy/GConfPreferencesClient.cs
==============================================================================
--- (empty file)
+++ branches/tomboy-portable2/Tomboy/GConfPreferencesClient.cs	Tue Aug 26 19:16:24 2008
@@ -0,0 +1,111 @@
+using System;
+using System.Collections.Generic;
+
+namespace Tomboy
+{
+	public class GConfPreferencesClient : IPreferencesClient
+	{
+		private GConf.Client client;
+		private List<NotifyWrapper> wrapper_list;
+
+		public GConfPreferencesClient ()
+		{
+			client = new GConf.Client ();
+			wrapper_list = new List<NotifyWrapper> ();
+		}
+
+		public void Set (string key, object val)
+		{
+			try {
+				client.Set (key, val);
+			} catch {	// TODO: what kind?
+			        throw new Exception ("Error setting key: " + key);	// TODO: can do better than this
+			}
+		}
+
+	public object Get (string key)
+		{
+			try {
+				return client.Get (key);
+			} catch (GConf.NoSuchKeyException) {
+				throw new NoSuchKeyException (key);
+			}
+		}
+
+		public void AddNotify (string dir, NotifyEventHandler notify)
+		{
+			if (dir == null)
+				throw new NullReferenceException("dir");
+			if (notify == null)
+				throw new NullReferenceException("notify");
+
+			NotifyWrapper wrapper = new NotifyWrapper (notify, dir);
+			client.AddNotify (dir, wrapper.HandleNotify);
+			wrapper_list.Add (wrapper);
+		}
+
+		public void RemoveNotify (string dir, NotifyEventHandler notify)
+		{
+			if (dir == null)
+				throw new NullReferenceException("dir");
+			if (notify == null)
+				throw new NullReferenceException("notify");
+
+			NotifyWrapper wrapper_to_remove = null;
+			foreach (NotifyWrapper wrapper in wrapper_list)
+			if (wrapper.dir.Equals (dir) && wrapper.notify.Equals (notify)) {
+				wrapper_to_remove = wrapper;
+				break;
+			}
+
+			// NOTE: For some unknown reason, the RemoveNotify call does not
+			//		 work here.  That is why we explicitly disable the wrapper,
+			//		 since it will unfortunately continue to exist and get
+			//		 inappropriately notified.
+			if (wrapper_to_remove != null) {
+				client.RemoveNotify (dir, wrapper_to_remove.HandleNotify);
+				wrapper_to_remove.enabled = false;
+				wrapper_list.Remove (wrapper_to_remove);
+			}
+		}
+
+		public void SuggestSync ()
+		{
+			client.SuggestSync ();
+		}
+
+		class NotifyWrapper
+		{
+			public NotifyEventHandler notify;
+			public string dir;
+			public bool enabled = true;
+
+			public NotifyWrapper (NotifyEventHandler notify, string dir)
+			{
+				this.notify = notify;
+				this.dir = dir;
+			}
+
+			public void HandleNotify (object sender, GConf.NotifyEventArgs args)
+			{
+				if (!enabled) {
+					Logger.Log ("NotifyWrapper for '" + dir + "' called after being disabled");	// TODO: Delete this...
+					return;
+				}
+				NotifyEventArgs newArgs = new NotifyEventArgs (args.Key, args.Value);
+				notify (sender, newArgs);
+			}
+		}
+	}
+
+
+	public class GConfPropertyEditorToggleButton : GConf.PropertyEditors.PropertyEditorToggleButton, IPropertyEditorBool
+	{
+		public GConfPropertyEditorToggleButton (string key, Gtk.CheckButton sourceButton) : base (key, sourceButton) {}
+	}
+
+	public class GConfPropertyEditorEntry : GConf.PropertyEditors.PropertyEditorEntry, IPropertyEditor
+	{
+		public GConfPropertyEditorEntry (string key, Gtk.Entry sourceEntry) : base (key, sourceEntry) { }
+	}
+}

Added: branches/tomboy-portable2/Tomboy/GnomeApplication.cs
==============================================================================
--- (empty file)
+++ branches/tomboy-portable2/Tomboy/GnomeApplication.cs	Tue Aug 26 19:16:24 2008
@@ -0,0 +1,144 @@
+using System;
+using System.Collections;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.IO;
+using System.Xml;
+
+using Mono.Unix;
+using Mono.Unix.Native;
+
+namespace Tomboy
+{
+	public class GnomeApplication : INativeApplication
+	{
+		private Gnome.Program program;
+
+		public void Initialize (string locale_dir,
+		                        string display_name,
+		                        string process_name,
+		                        string [] args)
+		{
+			try {
+				SetProcessName (process_name);
+			} catch {} // Ignore exception if fail (not needed to run)
+
+			Gtk.Application.Init ();
+			program = new Gnome.Program (display_name,
+			                             Defines.VERSION,
+			                             Gnome.Modules.UI,
+			                             args);
+
+			// Register handler for saving session when logging out of Gnome
+			Gnome.Client client = Gnome.Global.MasterClient ();
+			client.SaveYourself += OnSaveYourself;
+		}
+
+		public void RegisterSessionManagerRestart (string executable_path,
+		                string[] args,
+		                string[] environment)
+		{
+			if (executable_path == null)
+				return;
+
+			// Restart if we are running when the session ends or at crash...
+			Gnome.Client client = Gnome.Global.MasterClient ();
+			client.RestartStyle =
+			        Gnome.RestartStyle.IfRunning | Gnome.RestartStyle.Immediately;
+			client.Die += OnSessionManagerDie;
+
+			foreach (string env in environment) {
+				string [] split = env.Split (new char [] { '=' }, 2);
+				if (split.Length == 2) {
+					client.SetEnvironment (split[0], split[1]);
+				}
+			}
+
+			// Get the args for session restart...
+			string [] restart_args = new string [args.Length + 1];
+			restart_args [0] = executable_path;
+			args.CopyTo (restart_args, 1);
+			client.SetRestartCommand (restart_args.Length, restart_args);
+		}
+
+		public void RegisterSignalHandlers ()
+		{
+			// Connect to SIGTERM and SIGINT, so we don't lose
+			// unsaved notes on exit...
+			Stdlib.signal (Signum.SIGTERM, OnExitSignal);
+			Stdlib.signal (Signum.SIGINT, OnExitSignal);
+		}
+
+		public event EventHandler ExitingEvent;
+
+		public void Exit (int exitcode)
+		{
+			OnExitSignal (-1);
+			System.Environment.Exit (exitcode);
+		}
+
+		public void StartMainLoop ()
+		{
+			program.Run ();
+		}
+
+		public void QuitMainLoop ()
+		{
+			Gtk.Main.Quit ();
+		}
+
+		[DllImport("libc")]
+		private static extern int prctl (int option,
+			                                 byte [] arg2,
+			                                 IntPtr arg3,
+			                                 IntPtr arg4,
+			                                 IntPtr arg5);
+
+		// From Banshee: Banshee.Base/Utilities.cs
+		private void SetProcessName (string name)
+		{
+			if (prctl (15 /* PR_SET_NAME */,
+			                Encoding.ASCII.GetBytes (name + "\0"),
+			                IntPtr.Zero,
+			                IntPtr.Zero,
+			                IntPtr.Zero) != 0)
+				throw new ApplicationException (
+				        "Error setting process name: " +
+				        Mono.Unix.Native.Stdlib.GetLastError ());
+		}
+
+		private void OnSessionManagerDie (object sender, EventArgs args)
+		{
+			// Don't let the exit signal run, which would cancel
+			// session management.
+			QuitMainLoop ();
+		}
+
+		private void CancelSessionManagerRestart ()
+		{
+			Gnome.Client client = Gnome.Global.MasterClient ();
+			client.RestartStyle = Gnome.RestartStyle.IfRunning;
+			client.Flush ();
+		}
+
+		private void OnExitSignal (int signal)
+		{
+			// Don't auto-restart after exit/kill.
+			CancelSessionManagerRestart ();
+
+			if (ExitingEvent != null)
+				ExitingEvent (null, new EventArgs ());
+
+			if (signal >= 0)
+				System.Environment.Exit (0);
+		}
+
+		private void OnSaveYourself (object sender, Gnome.SaveYourselfArgs args)
+		{
+			Logger.Log ("Received request for saving session");
+
+			if (ExitingEvent != null)
+				ExitingEvent (null, new EventArgs ());
+		}
+	}
+}

Added: branches/tomboy-portable2/Tomboy/GtkApplication.cs
==============================================================================
--- (empty file)
+++ branches/tomboy-portable2/Tomboy/GtkApplication.cs	Tue Aug 26 19:16:24 2008
@@ -0,0 +1,72 @@
+// Permission is hereby granted, free of charge, to any person obtaining 
+// a copy of this software and associated documentation files (the 
+// "Software"), to deal in the Software without restriction, including 
+// without limitation the rights to use, copy, modify, merge, publish, 
+// distribute, sublicense, and/or sell copies of the Software, and to 
+// permit persons to whom the Software is furnished to do so, subject to 
+// the following conditions: 
+//  
+// The above copyright notice and this permission notice shall be 
+// included in all copies or substantial portions of the Software. 
+//  
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
+// 
+// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) 
+// 
+// Authors: 
+//      Sandy Armstrong <sanfordarmstrong gmail com>
+// 
+
+
+using System;
+
+namespace Tomboy
+{
+	public class GtkApplication : INativeApplication
+	{
+		#region INativeApplication implementation 
+		
+		public event EventHandler ExitingEvent;
+		
+		public void Initialize (string locale_dir, string display_name, string process_name, string[] args)
+		{
+			Gtk.Application.Init ();
+		}
+		
+		public void RegisterSessionManagerRestart (string executable_path, string[] args, string[] environment)
+		{
+			// Do nothing
+		}
+		
+		public void RegisterSignalHandlers ()
+		{
+			// Nothing yet, but need to register for native exit signals?
+		}
+		
+		public void Exit (int exitcode)
+		{
+			if (ExitingEvent != null)
+				ExitingEvent (null, new EventArgs ());
+			System.Environment.Exit (exitcode);
+		}
+		
+		public void StartMainLoop ()
+		{
+			Gtk.Application.Run ();
+		}
+		
+		public void QuitMainLoop ()
+		{
+			Gtk.Application.Quit ();
+		}
+		
+		#endregion 
+		
+	}
+}

Added: branches/tomboy-portable2/Tomboy/Keybinder.cs
==============================================================================
--- (empty file)
+++ branches/tomboy-portable2/Tomboy/Keybinder.cs	Tue Aug 26 19:16:24 2008
@@ -0,0 +1,41 @@
+using System;
+
+namespace Tomboy
+{
+	public interface IKeybinder
+	{
+		void Bind (string keystring, EventHandler handler);
+		void Unbind (string keystring);
+		void UnbindAll ();
+		bool GetAccelKeys (string gconf_path, out uint keyval, out Gdk.ModifierType mods);
+	}
+
+	public class NullKeybinder : IKeybinder
+	{
+		#region IKeybinder implementation 
+		
+		public void Bind (string keystring, EventHandler handler)
+		{
+			// Do nothing
+		}
+		
+		public void Unbind (string keystring)
+		{
+			// Do nothing
+		}
+		
+		public void UnbindAll ()
+		{
+			// Do nothing
+		}
+		
+		public bool GetAccelKeys (string gconf_path, out uint keyval, out Gdk.ModifierType mods)
+		{
+			keyval = 0;
+			mods = Gdk.ModifierType.None;
+			return false;
+		}
+		
+		#endregion
+	}
+}

Modified: branches/tomboy-portable2/Tomboy/Makefile.am
==============================================================================
--- branches/tomboy-portable2/Tomboy/Makefile.am	(original)
+++ branches/tomboy-portable2/Tomboy/Makefile.am	Tue Aug 26 19:16:24 2008
@@ -36,7 +36,12 @@
 	$(srcdir)/Applet.cs 			\
 	$(srcdir)/ApplicationAddin.cs		\
 	$(srcdir)/Contrast.cs		\
+	$(srcdir)/GConfPreferencesClient.cs	\
+	$(srcdir)/GnomeApplication.cs		\
+	$(srcdir)/GtkApplication.cs		\
+	$(srcdir)/Keybinder.cs			\
 	$(srcdir)/Logger.cs			\
+	$(srcdir)/NativeApplication.cs		\
 	$(srcdir)/Note.cs 			\
 	$(srcdir)/NoteAddin.cs			\
 	$(srcdir)/NoteEditor.cs			\
@@ -44,11 +49,15 @@
 	$(srcdir)/NoteWindow.cs 		\
 	$(srcdir)/NoteBuffer.cs 		\
 	$(srcdir)/NoteTag.cs 			\
+	$(srcdir)/PlatformFactory.cs		\
 	$(srcdir)/Preferences.cs		\
+	$(srcdir)/PreferencesClient.cs		\
 	$(srcdir)/PreferencesDialog.cs		\
 	$(srcdir)/PreferenceTabAddin.cs		\
+	$(srcdir)/PrefsKeybinder.cs		\
 	$(srcdir)/RecentChanges.cs		\
 	$(srcdir)/RecentTreeView.cs		\
+	$(srcdir)/Services.cs			\
 	$(srcdir)/Tag.cs			\
 	$(srcdir)/TagButton.cs			\
 	$(srcdir)/TagManager.cs			\
@@ -60,6 +69,7 @@
 	$(srcdir)/Watchers.cs			\
 	$(srcdir)/WrapBox.cs			\
 	$(srcdir)/XKeybinder.cs			\
+	$(srcdir)/XmlPreferencesClient.cs	\
 	$(srcdir)/Notebooks/*.cs		\
 	$(srcdir)/Synchronization/*.cs		\
 	\

Added: branches/tomboy-portable2/Tomboy/NativeApplication.cs
==============================================================================
--- (empty file)
+++ branches/tomboy-portable2/Tomboy/NativeApplication.cs	Tue Aug 26 19:16:24 2008
@@ -0,0 +1,22 @@
+using System;
+
+namespace Tomboy
+{
+	public interface INativeApplication
+	{
+		void Initialize (string locale_dir,
+		                 string display_name,
+		                 string process_name,
+		                 string [] args);
+
+		void RegisterSessionManagerRestart (string executable_path,
+		                                    string[] args,
+		                                    string[] environment);
+		void RegisterSignalHandlers ();
+		event EventHandler ExitingEvent;
+
+		void Exit (int exitcode);
+		void StartMainLoop ();
+		void QuitMainLoop ();
+	}
+}

Modified: branches/tomboy-portable2/Tomboy/NoteEditor.cs
==============================================================================
--- branches/tomboy-portable2/Tomboy/NoteEditor.cs	(original)
+++ branches/tomboy-portable2/Tomboy/NoteEditor.cs	Tue Aug 26 19:16:24 2008
@@ -61,7 +61,7 @@
 				string doc_font_string = (string)
 				                         Preferences.Client.Get (GNOME_DOCUMENT_FONT_KEY);
 				return Pango.FontDescription.FromString (doc_font_string);
-			} catch (GConf.NoSuchKeyException) {
+			} catch (NoSuchKeyException) {
 			} catch (System.InvalidCastException) {
 			}
 
@@ -72,7 +72,7 @@
 		// Update the font based on the changed Preference dialog setting.
 		// Also update the font based on the changed GConf GNOME document font setting.
 		//
-		void OnFontSettingChanged (object sender, GConf.NotifyEventArgs args)
+		void OnFontSettingChanged (object sender, NotifyEventArgs args)
 		{
 			switch (args.Key) {
 			case Preferences.ENABLE_CUSTOM_FONT:

Modified: branches/tomboy-portable2/Tomboy/NoteManager.cs
==============================================================================
--- branches/tomboy-portable2/Tomboy/NoteManager.cs	(original)
+++ branches/tomboy-portable2/Tomboy/NoteManager.cs	Tue Aug 26 19:16:24 2008
@@ -31,7 +31,7 @@
 			Preferences.SettingChanged += OnSettingChanged;
 		}
 
-		static void OnSettingChanged (object sender, GConf.NotifyEventArgs args)
+		static void OnSettingChanged (object sender, NotifyEventArgs args)
 		{
 			switch (args.Key) {
 			case Preferences.START_NOTE_URI:

Modified: branches/tomboy-portable2/Tomboy/NoteWindow.cs
==============================================================================
--- branches/tomboy-portable2/Tomboy/NoteWindow.cs	(original)
+++ branches/tomboy-portable2/Tomboy/NoteWindow.cs	Tue Aug 26 19:16:24 2008
@@ -200,7 +200,7 @@
 			Move (x, y);
 		}
 
-		void OnEscapeSettingChanged (object sender, GConf.NotifyEventArgs args)
+		void OnEscapeSettingChanged (object sender, NotifyEventArgs args)
 		{
 			// enable escape key
 			if ((bool) args.Value)

Added: branches/tomboy-portable2/Tomboy/PlatformFactory.cs
==============================================================================
--- (empty file)
+++ branches/tomboy-portable2/Tomboy/PlatformFactory.cs	Tue Aug 26 19:16:24 2008
@@ -0,0 +1,35 @@
+namespace Tomboy
+{
+	class PlatformFactory
+	{
+		public static IPropertyEditor CreatePropertyEditorEntry (string key, Gtk.Entry sourceEntry)
+		{
+			return new GConfPropertyEditorEntry (key, sourceEntry);
+		}
+
+		public static IPropertyEditorBool CreatePropertyEditorToggleButton (
+		        string key, Gtk.CheckButton sourceButton)
+		{
+			return new GConfPropertyEditorToggleButton (key, sourceButton);
+		}
+
+		public static IPreferencesClient CreatePreferencesClient ()
+		{
+			return new GConfPreferencesClient ();
+		}
+
+		public static INativeApplication CreateNativeApplication ()
+		{
+			return new GnomeApplication ();
+			// or GtkApplication
+		}
+
+		public static IKeybinder CreateKeybinder ()
+		{
+			return new XKeybinder ();
+			// or NullKeybinder
+			// (consider having a separate file+class
+			// for NeutralPlatformFactory vs GnomePlatformFactory)
+		}
+	}
+}

Modified: branches/tomboy-portable2/Tomboy/Preferences.cs
==============================================================================
--- branches/tomboy-portable2/Tomboy/Preferences.cs	(original)
+++ branches/tomboy-portable2/Tomboy/Preferences.cs	Tue Aug 26 19:16:24 2008
@@ -46,17 +46,14 @@
 		public const string SEARCH_WINDOW_WIDTH = "/apps/tomboy/search_window_width";
 		public const string SEARCH_WINDOW_HEIGHT = "/apps/tomboy/search_window_height";
 
-		static GConf.Client client;
-		static GConf.NotifyEventHandler changed_handler;
+		static IPreferencesClient client;
 
-		public static GConf.Client Client
+		public static IPreferencesClient Client
 		{
 			get {
 				if (client == null) {
-					client = new GConf.Client ();
-
-					changed_handler = new GConf.NotifyEventHandler (OnSettingChanged);
-					client.AddNotify ("/apps/tomboy", changed_handler);
+					client = Services.Preferences;
+					client.AddNotify ("/apps/tomboy", OnSettingChanged);
 				}
 				return client;
 			}
@@ -144,7 +141,7 @@
 		{
 			try {
 				return Client.Get (key);
-			} catch (GConf.NoSuchKeyException) {
+			} catch (NoSuchKeyException) {
 				object default_val = GetDefault (key);
 
 				if (default_val != null)
@@ -159,9 +156,9 @@
 			Client.Set (key, value);
 		}
 
-		public static event GConf.NotifyEventHandler SettingChanged;
+		public static event NotifyEventHandler SettingChanged;
 
-		static void OnSettingChanged (object sender, GConf.NotifyEventArgs args)
+		static void OnSettingChanged (object sender, NotifyEventArgs args)
 		{
 			if (SettingChanged != null) {
 				SettingChanged (sender, args);

Added: branches/tomboy-portable2/Tomboy/PreferencesClient.cs
==============================================================================
--- (empty file)
+++ branches/tomboy-portable2/Tomboy/PreferencesClient.cs	Tue Aug 26 19:16:24 2008
@@ -0,0 +1,83 @@
+
+namespace Tomboy
+{
+	public interface IPreferencesClient
+	{
+		void Set (string key, object val);
+		object Get (string key);
+		void AddNotify (string dir, NotifyEventHandler notify);
+		void RemoveNotify (string dir, NotifyEventHandler notify);
+		void SuggestSync ();
+	}
+
+	public interface IPropertyEditor
+	{
+		void Setup ();
+		string Key { get; }
+	}
+
+	public interface IPropertyEditorBool : IPropertyEditor
+	{
+		void AddGuard (Gtk.Widget widget);
+	}
+
+	public class NullPreferencesClient : IPreferencesClient
+	{
+		#region IPreferencesClient implementation 
+		
+		public void Set (string key, object val)
+		{
+			// Do nothing
+		}
+		
+		public object Get (string key)
+		{
+			throw new NoSuchKeyException (key);
+		}
+		
+		public void AddNotify (string dir, NotifyEventHandler notify)
+		{
+			// Do nothing
+		}
+		
+		public void RemoveNotify (string dir, NotifyEventHandler notify)
+		{
+			// Do nothing
+		}
+		
+		public void SuggestSync ()
+		{
+			// Do nothing
+		}
+		
+		#endregion
+	}
+
+	public delegate void NotifyEventHandler(object sender, NotifyEventArgs args);
+
+	public class NoSuchKeyException : System.Exception
+	{
+		public NoSuchKeyException(string key) : base(string.Format("No such key: {0}", key))
+		{}
+	}
+
+	public class NotifyEventArgs : System.EventArgs
+	{
+		private string key;
+		private object val;
+
+		public NotifyEventArgs (string key, object val)
+		{
+			this.key = key;
+			this.val = val;
+		}
+
+		public string Key { 
+			get { return key; }
+		}
+
+		public  object Value { 
+			get { return val; }
+		}
+	}
+}

Modified: branches/tomboy-portable2/Tomboy/PreferencesDialog.cs
==============================================================================
--- branches/tomboy-portable2/Tomboy/PreferencesDialog.cs	(original)
+++ branches/tomboy-portable2/Tomboy/PreferencesDialog.cs	Tue Aug 26 19:16:24 2008
@@ -79,8 +79,9 @@
 
 			notebook.AppendPage (MakeEditingPane (),
 			                     new Gtk.Label (Catalog.GetString ("Editing")));
-			notebook.AppendPage (MakeHotkeysPane (),
-			                     new Gtk.Label (Catalog.GetString ("Hotkeys")));
+			if (! (Services.Keybinder is NullKeybinder))
+				notebook.AppendPage (MakeHotkeysPane (),
+				                     new Gtk.Label (Catalog.GetString ("Hotkeys")));
 			notebook.AppendPage (MakeSyncPane (),
 			                     new Gtk.Label (Catalog.GetString ("Synchronization")));
 			notebook.AppendPage (MakeAddinsPane (),

Added: branches/tomboy-portable2/Tomboy/PrefsKeybinder.cs
==============================================================================
--- (empty file)
+++ branches/tomboy-portable2/Tomboy/PrefsKeybinder.cs	Tue Aug 26 19:16:24 2008
@@ -0,0 +1,223 @@
+// TODO: Rename this file?
+
+using System;
+using System.Collections;
+
+namespace Tomboy
+{
+	public class PrefsKeybinder
+	{
+		ArrayList bindings;
+		IKeybinder native_keybinder;
+
+		public PrefsKeybinder ()
+		{
+			bindings = new ArrayList ();
+			native_keybinder = PlatformFactory.CreateKeybinder ();
+		}
+
+		public void Bind (string       pref_path,
+		                  string       default_binding,
+		                  EventHandler handler)
+		{
+			try {
+				Binding binding = new Binding (pref_path,
+				                               default_binding,
+				                               handler,
+				                               native_keybinder);
+				bindings.Add (binding);
+			} catch (Exception e) {
+				Logger.Log ("Error Adding global keybinding:");
+				Logger.Log (e.ToString ());
+			}
+		}
+
+		public void UnbindAll ()
+		{
+			try {
+				foreach (Binding binding in bindings)
+				binding.RemoveNotify ();
+				bindings.Clear ();
+				native_keybinder.UnbindAll ();
+			} catch (Exception e) {
+				Logger.Log ("Error Removing global keybinding:");
+				Logger.Log (e.ToString ());
+			}
+		}
+
+		class Binding
+		{
+			public string   pref_path;
+			public string   key_sequence;
+			EventHandler    handler;
+			IKeybinder native_keybinder;
+
+			public Binding (string          pref_path,
+			                string          default_binding,
+			                EventHandler    handler,
+			                IKeybinder native_keybinder)
+			{
+				this.pref_path = pref_path;
+				this.key_sequence = default_binding;
+				this.handler = handler;
+				this.native_keybinder = native_keybinder;
+
+				try {
+					key_sequence = (string) Preferences.Client.Get (pref_path);
+				} catch {
+				        Logger.Log ("Preference key '{0}' does not exist, using default.",
+				                    pref_path);
+				}
+
+				SetBinding ();
+
+				Preferences.Client.AddNotify (
+				        pref_path,
+				        BindingChanged);
+			}
+
+			public void RemoveNotify ()
+			{
+				Preferences.Client.RemoveNotify (
+				        pref_path,
+				        BindingChanged);
+			}
+
+			void BindingChanged (object sender, NotifyEventArgs args)
+			{
+				if (args.Key == pref_path) {
+					Logger.Log ("Binding for '{0}' changed to '{1}'!",
+					            pref_path,
+					            args.Value);
+
+					UnsetBinding ();
+
+					key_sequence = (string) args.Value;
+					SetBinding ();
+				}
+			}
+
+			public void SetBinding ()
+			{
+				if (key_sequence == null ||
+				                key_sequence == String.Empty ||
+				                key_sequence == "disabled")
+					return;
+
+				Logger.Log ("Binding key '{0}' for '{1}'",
+				            key_sequence,
+				            pref_path);
+
+				native_keybinder.Bind (key_sequence, handler);
+			}
+
+			public void UnsetBinding ()
+			{
+				if (key_sequence == null)
+					return;
+
+				Logger.Log ("Unbinding key '{0}' for '{1}'",
+				            key_sequence,
+				            pref_path);
+
+				native_keybinder.Unbind (key_sequence);
+			}
+		}
+	}
+
+	public class TomboyPrefsKeybinder : PrefsKeybinder
+	{
+		NoteManager manager;
+		TomboyTray  tray;
+
+		public TomboyPrefsKeybinder (NoteManager manager, TomboyTray tray)
+				: base ()
+		{
+			this.manager = manager;
+			this.tray = tray;
+
+			EnableDisable ((bool) Preferences.Get (Preferences.ENABLE_KEYBINDINGS));
+
+			Preferences.SettingChanged += EnableKeybindingsChanged;
+		}
+
+		void EnableKeybindingsChanged (object sender, NotifyEventArgs args)
+		{
+			if (args.Key == Preferences.ENABLE_KEYBINDINGS) {
+				bool enabled = (bool) args.Value;
+				EnableDisable (enabled);
+			}
+		}
+
+		void EnableDisable (bool enable)
+		{
+			Logger.Log ("EnableDisable Called: enabling... {0}", enable);
+			if (enable) {
+				BindPreference (Preferences.KEYBINDING_SHOW_NOTE_MENU,
+				                new EventHandler (KeyShowMenu));
+
+				BindPreference (Preferences.KEYBINDING_OPEN_START_HERE,
+				                new EventHandler (KeyOpenStartHere));
+
+				BindPreference (Preferences.KEYBINDING_CREATE_NEW_NOTE,
+				                new EventHandler (KeyCreateNewNote));
+
+				BindPreference (Preferences.KEYBINDING_OPEN_SEARCH,
+				                new EventHandler (KeyOpenSearch));
+
+				BindPreference (Preferences.KEYBINDING_OPEN_RECENT_CHANGES,
+				                new EventHandler (KeyOpenRecentChanges));
+			} else {
+				UnbindAll ();
+			}
+		}
+
+		void BindPreference (string pref_path, EventHandler handler)
+		{
+			Bind (pref_path,
+			      (string) Preferences.GetDefault (pref_path),
+			      handler);
+		}
+
+		void KeyShowMenu (object sender, EventArgs args)
+		{
+			// Show the notes menu, highlighting the first item.
+			// This matches the behavior of GTK for
+			// accelerator-shown menus.
+			tray.ShowMenu (true);
+		}
+
+		void KeyOpenStartHere (object sender, EventArgs args)
+		{
+			Note note = manager.FindByUri (NoteManager.StartNoteUri);
+			if (note != null)
+				note.Window.Present ();
+		}
+
+		void KeyCreateNewNote (object sender, EventArgs args)
+		{
+			try {
+				Note new_note = manager.Create ();
+				new_note.Window.Show ();
+			} catch {
+			        // Fail silently.
+			}
+		}
+
+	void KeyOpenSearch (object sender, EventArgs args)
+		{
+			/* Find dialog is deprecated in favor of searcable ToC */
+			/*
+			NoteFindDialog find_dialog = NoteFindDialog.GetInstance (manager);
+			find_dialog.Present ();
+			*/
+			KeyOpenRecentChanges (sender, args);
+		}
+
+		void KeyOpenRecentChanges (object sender, EventArgs args)
+		{
+			NoteRecentChanges recent = NoteRecentChanges.GetInstance (manager);
+			recent.Present ();
+		}
+	}
+}

Added: branches/tomboy-portable2/Tomboy/Services.cs
==============================================================================
--- (empty file)
+++ branches/tomboy-portable2/Tomboy/Services.cs	Tue Aug 26 19:16:24 2008
@@ -0,0 +1,62 @@
+// Permission is hereby granted, free of charge, to any person obtaining 
+// a copy of this software and associated documentation files (the 
+// "Software"), to deal in the Software without restriction, including 
+// without limitation the rights to use, copy, modify, merge, publish, 
+// distribute, sublicense, and/or sell copies of the Software, and to 
+// permit persons to whom the Software is furnished to do so, subject to 
+// the following conditions: 
+//  
+// The above copyright notice and this permission notice shall be 
+// included in all copies or substantial portions of the Software. 
+//  
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
+// 
+// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) 
+// 
+// Authors: 
+//      Sandy Armstrong <sanfordarmstrong gmail com>
+// 
+
+
+using System;
+
+namespace Tomboy
+{
+	public class Services
+	{
+		private static IPreferencesClient prefs;
+		private static INativeApplication nativeApp;
+		private static IKeybinder keybinder;
+		
+		static Services ()
+		{
+			prefs = PlatformFactory.CreatePreferencesClient ();
+			nativeApp = PlatformFactory.CreateNativeApplication ();
+			keybinder = PlatformFactory.CreateKeybinder ();
+		}
+
+		public static IPreferencesClient Preferences {
+			get {
+				return prefs;
+			}
+		}
+
+		public static INativeApplication NativeApplication {
+			get {
+				return nativeApp;
+			}
+		}
+
+		public static IKeybinder Keybinder {
+			get {
+				return keybinder;
+			}
+		}
+	}
+}
\ No newline at end of file

Modified: branches/tomboy-portable2/Tomboy/Tray.cs
==============================================================================
--- branches/tomboy-portable2/Tomboy/Tray.cs	(original)
+++ branches/tomboy-portable2/Tomboy/Tray.cs	Tue Aug 26 19:16:24 2008
@@ -136,12 +136,12 @@
 	public class TomboyTrayIcon : Gtk.StatusIcon
 	{
 		TomboyTray tray;
-		TomboyGConfXKeybinder keybinder;
+		TomboyPrefsKeybinder keybinder;
 
 		public TomboyTrayIcon (NoteManager manager)
 		{
 			tray = new TomboyTray (manager, this);
-			keybinder = new TomboyGConfXKeybinder (manager, tray);
+			keybinder = new TomboyPrefsKeybinder (manager, tray);
 			int panel_size = 22;
 			Pixbuf = GuiUtils.GetIcon ("tomboy", panel_size);
 
@@ -575,54 +575,12 @@
 		}
 	}
 
-	[DllImport("libtomboy")]
-		static extern bool egg_accelerator_parse_virtual (string keystring,
-			                out uint keysym,
-			                out uint virtual_mods);
-
-		[DllImport("libtomboy")]
-		static extern void egg_keymap_resolve_virtual_modifiers (
-			        IntPtr keymap,
-			        uint virtual_mods,
-			        out Gdk.ModifierType real_mods);
-
-		public static bool GetAccelKeys (string               gconf_path,
-		                                 out uint             keyval,
-		                                 out Gdk.ModifierType mods)
-		{
-			keyval = 0;
-			mods = 0;
-
-			try {
-				string binding = (string) Preferences.Get (gconf_path);
-				if (binding == null ||
-				                binding == String.Empty ||
-				                binding == "disabled")
-					return false;
-
-				uint virtual_mods = 0;
-				if (!egg_accelerator_parse_virtual (binding,
-				                                    out keyval,
-				                                    out virtual_mods))
-					return false;
-
-				Gdk.Keymap keymap = Gdk.Keymap.Default;
-				egg_keymap_resolve_virtual_modifiers (keymap.Handle,
-				                                      virtual_mods,
-				                                      out mods);
-
-				return true;
-			} catch {
-			return false;
-		}
-	}
-
 	public static void AddAccelerator (Gtk.MenuItem item, string gconf_path)
 		{
 			uint keyval;
 			Gdk.ModifierType mods;
 
-			if (GetAccelKeys (gconf_path, out keyval, out mods))
+			if (Services.Keybinder.GetAccelKeys (gconf_path, out keyval, out mods))
 				item.AddAccelerator ("activate",
 				                     accel_group,
 				                     keyval,

Modified: branches/tomboy-portable2/Tomboy/Utils.cs
==============================================================================
--- branches/tomboy-portable2/Tomboy/Utils.cs	(original)
+++ branches/tomboy-portable2/Tomboy/Utils.cs	Tue Aug 26 19:16:24 2008
@@ -7,7 +7,6 @@
 using System.Xml;
 
 using Mono.Unix;
-using Mono.Unix.Native;
 
 namespace Tomboy
 {
@@ -868,7 +867,7 @@
 
 	public class Application
 	{
-		static Gnome.Program program;
+		static INativeApplication native_app;
 		static ActionManager action_manager;
 
 		public static void Initialize (string locale_dir,
@@ -876,131 +875,41 @@
 		                               string process_name,
 		                               string [] args)
 		{
-			try {
-				SetProcessName (process_name);
-			} catch {} // Ignore exception if fail (not needed to run)
-
-			Gtk.Application.Init ();
-			program = new Gnome.Program ("Tomboy",
-			                             Defines.VERSION,
-			                             Gnome.Modules.UI,
-			                             args);
+			native_app = Services.NativeApplication;
+			native_app.Initialize (locale_dir, display_name, process_name, args);
 
 			action_manager = new ActionManager ();
 			action_manager.LoadInterface ();
 
-			RegisterSignalHandlers ();
-
-			// Register handler for saving session when logging out of Gnome
-			Gnome.Client client = Gnome.Global.MasterClient ();
-			client.SaveYourself += OnSaveYourself;
-		}
-
-		[DllImport("libc")]
-		private static extern int prctl (int option,
-			                                 byte [] arg2,
-			                                 IntPtr arg3,
-			                                 IntPtr arg4,
-			                                 IntPtr arg5);
-
-		// From Banshee: Banshee.Base/Utilities.cs
-		public static void SetProcessName (string name)
-		{
-			if (prctl (15 /* PR_SET_NAME */,
-			                Encoding.ASCII.GetBytes (name + "\0"),
-			                IntPtr.Zero,
-			                IntPtr.Zero,
-			                IntPtr.Zero) != 0)
-				throw new ApplicationException (
-				        "Error setting process name: " +
-				        Mono.Unix.Native.Stdlib.GetLastError ());
-		}
-
-		static void RegisterSignalHandlers ()
-		{
-			// Connect to SIGTERM and SIGINT, so we don't lose
-			// unsaved notes on exit...
-			Stdlib.signal (Signum.SIGTERM, OnExitSignal);
-			Stdlib.signal (Signum.SIGINT, OnExitSignal);
-		}
-
-		static void OnSaveYourself (object sender, Gnome.SaveYourselfArgs args)
-		{
-			Logger.Log ("Received request for saving session");
-
-			if (ExitingEvent != null)
-				ExitingEvent (null, new EventArgs ());
+			native_app.RegisterSignalHandlers ();
 		}
 
 		public static void RegisterSessionManagerRestart (string executable_path,
 		                string[] args,
 		                string[] environment)
 		{
-			if (executable_path == null)
-				return;
-
-			// Restart if we are running when the session ends or at crash...
-			Gnome.Client client = Gnome.Global.MasterClient ();
-			client.RestartStyle =
-			        Gnome.RestartStyle.IfRunning | Gnome.RestartStyle.Immediately;
-			client.Die += OnSessionManagerDie;
-
-			foreach (string env in environment) {
-				string [] split = env.Split (new char [] { '=' }, 2);
-				if (split.Length == 2) {
-					client.SetEnvironment (split[0], split[1]);
-				}
-			}
-
-			// Get the args for session restart...
-			string [] restart_args = new string [args.Length + 1];
-			restart_args [0] = executable_path;
-			args.CopyTo (restart_args, 1);
-			client.SetRestartCommand (restart_args.Length, restart_args);
-		}
-
-		static void OnSessionManagerDie (object sender, EventArgs args)
-		{
-			// Don't let the exit signal run, which would cancel
-			// session management.
-			QuitMainLoop ();
+			native_app.RegisterSessionManagerRestart (executable_path, args, environment);
 		}
 
-		static void CancelSessionManagerRestart ()
+		public static event EventHandler ExitingEvent
 		{
-			Gnome.Client client = Gnome.Global.MasterClient ();
-			client.RestartStyle = Gnome.RestartStyle.IfRunning;
-			client.Flush ();
+		        add { native_app.ExitingEvent += value; }
+		        remove { native_app.ExitingEvent -= value; }
 		}
 
-		static void OnExitSignal (int signal)
-		{
-			// Don't auto-restart after exit/kill.
-			CancelSessionManagerRestart ();
-
-			if (ExitingEvent != null)
-				ExitingEvent (null, new EventArgs ());
-
-			if (signal >= 0)
-				System.Environment.Exit (0);
-		}
-
-		public static event EventHandler ExitingEvent;
-
 		public static void Exit (int exitcode)
 		{
-			OnExitSignal (-1);
-			System.Environment.Exit (exitcode);
+			native_app.Exit (exitcode);
 		}
 
 		public static void StartMainLoop ()
 		{
-			program.Run ();
+			native_app.StartMainLoop ();
 		}
 
 		public static void QuitMainLoop ()
 		{
-			Gtk.Main.Quit ();
+			native_app.QuitMainLoop ();
 		}
 
 		public static ActionManager ActionManager

Modified: branches/tomboy-portable2/Tomboy/Watchers.cs
==============================================================================
--- branches/tomboy-portable2/Tomboy/Watchers.cs	(original)
+++ branches/tomboy-portable2/Tomboy/Watchers.cs	Tue Aug 26 19:16:24 2008
@@ -313,7 +313,7 @@
 			}
 		}
 
-		void OnEnableSpellcheckChanged (object sender, GConf.NotifyEventArgs args)
+		void OnEnableSpellcheckChanged (object sender, NotifyEventArgs args)
 		{
 			if (args.Key != Preferences.ENABLE_SPELLCHECKING)
 				return;
@@ -895,7 +895,7 @@
 			Preferences.SettingChanged += OnEnableWikiwordsChanged;
 		}
 
-		void OnEnableWikiwordsChanged (object sender, GConf.NotifyEventArgs args)
+		void OnEnableWikiwordsChanged (object sender, NotifyEventArgs args)
 		{
 			if (args.Key != Preferences.ENABLE_WIKIWORDS)
 				return;

Modified: branches/tomboy-portable2/Tomboy/XKeybinder.cs
==============================================================================
--- branches/tomboy-portable2/Tomboy/XKeybinder.cs	(original)
+++ branches/tomboy-portable2/Tomboy/XKeybinder.cs	Tue Aug 26 19:16:24 2008
@@ -1,12 +1,10 @@
-
 using System;
 using System.Collections;
 using System.Runtime.InteropServices;
-using Mono.Unix;
 
 namespace Tomboy
 {
-	public class XKeybinder
+	public class XKeybinder : IKeybinder
 	{
 		[DllImport("libtomboy")]
 		static extern void tomboy_keybinder_init ();
@@ -21,6 +19,7 @@
 
 		public delegate void BindkeyHandler (string key, IntPtr user_data);
 
+		// TODO: Change to IList<T>
 		ArrayList      bindings;
 		BindkeyHandler key_handler;
 
@@ -30,7 +29,6 @@
 		}
 
 		public XKeybinder ()
-: base ()
 		{
 			bindings = new ArrayList ();
 			key_handler = new BindkeyHandler (KeybindingPressed);
@@ -79,212 +77,47 @@
 
 			bindings.Clear ();
 		}
-	}
 
-	public class GConfXKeybinder : XKeybinder
-	{
-		GConf.Client client;
-		ArrayList bindings;
+	[DllImport("libtomboy")]
+		static extern bool egg_accelerator_parse_virtual (string keystring,
+			                out uint keysym,
+			                out uint virtual_mods);
 
-		public GConfXKeybinder ()
+		[DllImport("libtomboy")]
+		static extern void egg_keymap_resolve_virtual_modifiers (
+			        IntPtr keymap,
+			        uint virtual_mods,
+			        out Gdk.ModifierType real_mods);
+
+		public bool GetAccelKeys (string               gconf_path,
+		                                 out uint             keyval,
+		                                 out Gdk.ModifierType mods)
 		{
-			client = new GConf.Client ();
-			bindings = new ArrayList ();
-		}
+			keyval = 0;
+			mods = 0;
 
-		public void Bind (string       gconf_path,
-		                  string       default_binding,
-		                  EventHandler handler)
-		{
 			try {
-				Binding binding = new Binding (gconf_path,
-				                               default_binding,
-				                               handler,
-				                               this);
-				bindings.Add (binding);
-			} catch (Exception e) {
-				Logger.Log ("Error Adding global keybinding:");
-				Logger.Log (e.ToString ());
-			}
-		}
-
-		public override void UnbindAll ()
-		{
-			try {
-				bindings.Clear ();
-				base.UnbindAll ();
-			} catch (Exception e) {
-				Logger.Log ("Error Removing global keybinding:");
-				Logger.Log (e.ToString ());
-			}
-		}
-
-		class Binding
-		{
-			public string   gconf_path;
-			public string   key_sequence;
-			EventHandler    handler;
-			GConfXKeybinder parent;
-
-			public Binding (string          gconf_path,
-			                string          default_binding,
-			                EventHandler    handler,
-			                GConfXKeybinder parent)
-			{
-				this.gconf_path = gconf_path;
-				this.key_sequence = default_binding;
-				this.handler = handler;
-				this.parent = parent;
-
-				try {
-					key_sequence = (string) parent.client.Get (gconf_path);
-				} catch {
-				Logger.Log ("GConf key '{0}' does not exist, using default.",
-				gconf_path);
-				}
-
-				SetBinding ();
-
-				parent.client.AddNotify (
-				        gconf_path,
-				        new GConf.NotifyEventHandler (BindingChanged));
-			}
-
-			void BindingChanged (object sender, GConf.NotifyEventArgs args)
-			{
-				if (args.Key == gconf_path) {
-					Logger.Log ("Binding for '{0}' changed to '{1}'!",
-					            gconf_path,
-					            args.Value);
-
-					UnsetBinding ();
-
-					key_sequence = (string) args.Value;
-					SetBinding ();
-				}
-			}
-
-			public void SetBinding ()
-			{
-				if (key_sequence == null ||
-				                key_sequence == String.Empty ||
-				                key_sequence == "disabled")
-					return;
-
-				Logger.Log ("Binding key '{0}' for '{1}'",
-				            key_sequence,
-				            gconf_path);
-
-				parent.Bind (key_sequence, handler);
-			}
-
-			public void UnsetBinding ()
-			{
-				if (key_sequence == null)
-					return;
-
-				Logger.Log ("Unbinding key '{0}' for '{1}'",
-				            key_sequence,
-				            gconf_path);
-
-				parent.Unbind (key_sequence);
-			}
-		}
-	}
-
-	public class TomboyGConfXKeybinder : GConfXKeybinder
-	{
-		NoteManager manager;
-		TomboyTray  tray;
-
-		public TomboyGConfXKeybinder (NoteManager manager, TomboyTray tray)
-: base ()
-		{
-			this.manager = manager;
-			this.tray = tray;
+				string binding = (string) Preferences.Get (gconf_path);
+				if (binding == null ||
+				                binding == String.Empty ||
+				                binding == "disabled")
+					return false;
+
+				uint virtual_mods = 0;
+				if (!egg_accelerator_parse_virtual (binding,
+				                                    out keyval,
+				                                    out virtual_mods))
+					return false;
+
+				Gdk.Keymap keymap = Gdk.Keymap.Default;
+				egg_keymap_resolve_virtual_modifiers (keymap.Handle,
+				                                      virtual_mods,
+				                                      out mods);
 
-			EnableDisable ((bool) Preferences.Get (Preferences.ENABLE_KEYBINDINGS));
-
-			Preferences.SettingChanged += EnableKeybindingsChanged;
-		}
-
-		void EnableKeybindingsChanged (object sender, GConf.NotifyEventArgs args)
-		{
-			if (args.Key == Preferences.ENABLE_KEYBINDINGS) {
-				bool enabled = (bool) args.Value;
-				EnableDisable (enabled);
-			}
-		}
-
-		void EnableDisable (bool enable)
-		{
-			Logger.Log ("EnableDisable Called: enabling... {0}", enable);
-			if (enable) {
-				BindPreference (Preferences.KEYBINDING_SHOW_NOTE_MENU,
-				                new EventHandler (KeyShowMenu));
-
-				BindPreference (Preferences.KEYBINDING_OPEN_START_HERE,
-				                new EventHandler (KeyOpenStartHere));
-
-				BindPreference (Preferences.KEYBINDING_CREATE_NEW_NOTE,
-				                new EventHandler (KeyCreateNewNote));
-
-				BindPreference (Preferences.KEYBINDING_OPEN_SEARCH,
-				                new EventHandler (KeyOpenSearch));
-
-				BindPreference (Preferences.KEYBINDING_OPEN_RECENT_CHANGES,
-				                new EventHandler (KeyOpenRecentChanges));
-			} else {
-				UnbindAll ();
-			}
-		}
-
-		void BindPreference (string gconf_path, EventHandler handler)
-		{
-			Bind (gconf_path,
-			      (string) Preferences.GetDefault (gconf_path),
-			      handler);
-		}
-
-		void KeyShowMenu (object sender, EventArgs args)
-		{
-			// Show the notes menu, highlighting the first item.
-			// This matches the behavior of GTK for
-			// accelerator-shown menus.
-			tray.ShowMenu (true);
-		}
-
-		void KeyOpenStartHere (object sender, EventArgs args)
-		{
-			Note note = manager.FindByUri (NoteManager.StartNoteUri);
-			if (note != null)
-				note.Window.Present ();
-		}
-
-		void KeyCreateNewNote (object sender, EventArgs args)
-		{
-			try {
-				Note new_note = manager.Create ();
-				new_note.Window.Show ();
+				return true;
 			} catch {
-			// Fail silently.
+			return false;
 		}
 	}
-
-	void KeyOpenSearch (object sender, EventArgs args)
-		{
-			/* Find dialog is deprecated in favor of searcable ToC */
-			/*
-			NoteFindDialog find_dialog = NoteFindDialog.GetInstance (manager);
-			find_dialog.Present ();
-			*/
-			KeyOpenRecentChanges (sender, args);
-		}
-
-		void KeyOpenRecentChanges (object sender, EventArgs args)
-		{
-			NoteRecentChanges recent = NoteRecentChanges.GetInstance (manager);
-			recent.Present ();
-		}
 	}
 }

Added: branches/tomboy-portable2/Tomboy/XmlPreferencesClient.cs
==============================================================================
--- (empty file)
+++ branches/tomboy-portable2/Tomboy/XmlPreferencesClient.cs	Tue Aug 26 19:16:24 2008
@@ -0,0 +1,137 @@
+// Permission is hereby granted, free of charge, to any person obtaining 
+// a copy of this software and associated documentation files (the 
+// "Software"), to deal in the Software without restriction, including 
+// without limitation the rights to use, copy, modify, merge, publish, 
+// distribute, sublicense, and/or sell copies of the Software, and to 
+// permit persons to whom the Software is furnished to do so, subject to 
+// the following conditions: 
+//  
+// The above copyright notice and this permission notice shall be 
+// included in all copies or substantial portions of the Software. 
+//  
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
+// 
+// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) 
+// 
+// Authors: 
+//      Sandy Armstrong <sanfordarmstrong gmail com>
+// 
+
+
+using System;
+using System.Collections.Generic;
+using System.Xml;
+
+namespace Tomboy
+{
+	public class XmlPreferencesClient : IPreferencesClient
+	{
+		#region Private Members
+		
+		private string fileName;
+		private XmlDocument prefsDoc;
+		private Dictionary<string, NotifyEventHandler> events;
+
+		#endregion
+
+		#region Constructor
+
+		public XmlPreferencesClient ()
+		{
+
+		}
+		
+		#endregion
+		
+		#region IPreferencesClient implementation
+		
+		public void Set (string key, object value)
+		{
+			try {
+				CreatePath (key);
+				prefsDoc.SelectSingleNode (key).InnerText = System.Convert.ToString(value);
+				prefsDoc.Save(fileName);
+				foreach (string nkey in events.Keys) {
+					NotifyEventHandler handler = events [nkey] as NotifyEventHandler;
+					if (handler != null && key.StartsWith (nkey))
+					{
+						NotifyEventArgs args = new NotifyEventArgs (key, value);
+						handler (this, args);
+					}
+				}
+			}
+			catch {}
+		}
+		
+		public object Get (string key)
+		{
+			try {
+				XmlElement element = prefsDoc.SelectSingleNode(key) as XmlElement;
+				if (element != null) {
+					if (element.InnerText.ToLower () == "true")
+						return true;
+					if (element.InnerText.ToLower () == "false")
+						return false;
+					return element.InnerText;
+				}
+				
+				throw new System.Exception();
+			} catch {
+				throw new NoSuchKeyException (key);
+			}
+
+		}
+		
+		public void AddNotify (string dir, NotifyEventHandler notify)
+		{
+			lock (events) {
+				events [dir] += notify;
+			}
+		}
+		
+		public void RemoveNotify (string dir, NotifyEventHandler notify)
+		{
+			lock (events) {
+				events [dir] -= notify;
+			}
+		}
+		
+		public void SuggestSync ()
+		{
+			// TODO: Sync with file?
+		}
+		
+		#endregion
+
+		#region Private Methods
+
+		private void CreatePath(string path)
+		{
+			if (path.Length == 0)
+				return;
+			if (path [0] == '/') 
+				path = path.Substring (1);
+			if (path.Length == 0)
+				return;
+
+			string [] parts = path.Split ('/');
+			XmlNode node = prefsDoc;
+			for (int i = 0; i < parts.Length; ++i)
+			{
+				if (node [parts [i]] == null)
+				{
+					node.AppendChild (prefsDoc.CreateElement (parts [i]));
+				}
+				node = node [parts [i]];
+			}
+		}
+
+		#endregion
+	}
+}



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