[tasque] Extract preferences keys from Preferences class



commit 148538247200f81a8cd1c5804c4d6b2e599dca6e
Author: Antonius Riha <antoniusriha gmail com>
Date:   Thu Jan 3 18:10:43 2013 +0100

    Extract preferences keys from Preferences class
    
    this should improve testablility later ...

 src/Addins/Backends/Dummy/DummyBackend.cs          |    2 +-
 .../Backends/Rtm/Gtk/RtmPreferencesWidget.cs       |   10 ++--
 src/Addins/Backends/Rtm/RtmBackend.cs              |   20 ++++----
 src/Addins/Backends/Sqlite/SqliteBackend.cs        |    2 +-
 src/Gtk.Tasque/CompletedTaskGroup.cs               |   12 ++--
 src/Gtk.Tasque/PreferencesDialog.cs                |   26 +++++-----
 src/Gtk.Tasque/RemoteControl.cs                    |    2 +-
 src/Gtk.Tasque/TaskGroup.cs                        |    8 ++--
 src/Gtk.Tasque/TaskTreeView.cs                     |   16 +++---
 src/Gtk.Tasque/TaskWindow.cs                       |   14 +++---
 src/libtasque/AllCategory.cs                       |   12 ++--
 src/libtasque/CompletedTaskGroupModel.cs           |    2 +-
 src/libtasque/IBackend.cs                          |    2 +-
 src/libtasque/INativeApplication.cs                |    2 +-
 src/libtasque/IPreferences.cs                      |    2 +-
 src/libtasque/NativeApplication.cs                 |    6 +-
 src/libtasque/Preferences.cs                       |   40 ++------------
 src/libtasque/PreferencesKeys.cs                   |   55 ++++++++++++++++++++
 src/libtasque/TaskGroupModel.cs                    |    4 +-
 src/libtasque/TaskGroupModelFactory.cs             |    6 +-
 src/libtasque/libtasque.csproj                     |    1 +
 21 files changed, 135 insertions(+), 109 deletions(-)
---
diff --git a/src/Addins/Backends/Dummy/DummyBackend.cs b/src/Addins/Backends/Dummy/DummyBackend.cs
index 222aa1f..b0ef031 100644
--- a/src/Addins/Backends/Dummy/DummyBackend.cs
+++ b/src/Addins/Backends/Dummy/DummyBackend.cs
@@ -112,7 +112,7 @@ namespace Tasque.Backends.Dummy
 		public void Refresh()
 		{}
 
-		public void Initialize (Preferences preferences)
+		public void Initialize (IPreferences preferences)
 		{
 			if (preferences == null)
 				throw new ArgumentNullException ("preferences");
diff --git a/src/Addins/Backends/Rtm/Gtk/RtmPreferencesWidget.cs b/src/Addins/Backends/Rtm/Gtk/RtmPreferencesWidget.cs
index 528dc72..21b4204 100644
--- a/src/Addins/Backends/Rtm/Gtk/RtmPreferencesWidget.cs
+++ b/src/Addins/Backends/Rtm/Gtk/RtmPreferencesWidget.cs
@@ -12,7 +12,7 @@ namespace Tasque.Backends.Rtm
 {
 	public class RtmPreferencesWidget : Gtk.EventBox, IBackendPreferences
 	{
-		Preferences preferences;
+		IPreferences preferences;
 		RtmBackend backend;
 
  		private LinkButton		authButton;
@@ -29,7 +29,7 @@ namespace Tasque.Backends.Rtm
 			normalPixbuf = GetIcon ("tasque-rtm-logo", 128);
 		}
 		
-		public RtmPreferencesWidget (RtmBackend backend, Preferences preferences) : base ()
+		public RtmPreferencesWidget (RtmBackend backend, IPreferences preferences) : base ()
 		{
 			if (backend == null)
 				throw new ArgumentNullException ("backend");
@@ -82,7 +82,7 @@ namespace Tasque.Backends.Rtm
 			if ( isAuthorized ) {
 				statusLabel.Text = "\n\n" +
 					Catalog.GetString ("You are currently connected");
-				string userName = preferences.Get (Preferences.UserNameKey);
+				string userName = preferences.Get (PreferencesKeys.UserNameKey);
 				if (userName != null && userName.Trim () != string.Empty)
 					statusLabel.Text = "\n\n" +
 						Catalog.GetString ("You are currently connected as") +
@@ -102,7 +102,7 @@ namespace Tasque.Backends.Rtm
 		
 		private void LoadPreferences ()
 		{
-			string authToken = preferences.Get(Preferences.AuthTokenKey);
+			string authToken = preferences.Get(PreferencesKeys.AuthTokenKey);
 			if (authToken == null || authToken.Trim() == "") {
 				Logger.Debug("Rtm: Not authorized");
 				isAuthorized = false;
@@ -151,7 +151,7 @@ namespace Tasque.Backends.Rtm
 				authButton.Sensitive = false;
 				statusLabel.Text = "\n\n" +
 					Catalog.GetString ("You are currently connected");
-				string userName = preferences.Get (Preferences.UserNameKey);
+				string userName = preferences.Get (PreferencesKeys.UserNameKey);
 				if (userName != null && userName.Trim () != string.Empty)
 					statusLabel.Text = "\n\n" +
 						Catalog.GetString ("You are currently connected as") +
diff --git a/src/Addins/Backends/Rtm/RtmBackend.cs b/src/Addins/Backends/Rtm/RtmBackend.cs
index 79bd449..25f5395 100644
--- a/src/Addins/Backends/Rtm/RtmBackend.cs
+++ b/src/Addins/Backends/Rtm/RtmBackend.cs
@@ -121,7 +121,7 @@ namespace Tasque.Backends.Rtm
 			Logger.Debug("Done refreshing data!");
 		}
 
-		public void Initialize (Preferences preferences)
+		public void Initialize (IPreferences preferences)
 		{
 			if (preferences == null)
 				throw new ArgumentNullException ("preferences");
@@ -134,7 +134,7 @@ namespace Tasque.Backends.Rtm
 			// *************************************
 			// AUTHENTICATION to Remember The Milk
 			// *************************************
-			string authToken = preferences.Get (Tasque.Preferences.AuthTokenKey);
+			string authToken = preferences.Get (PreferencesKeys.AuthTokenKey);
 			if (authToken != null) {
 				Logger.Debug ("Found AuthToken, checking credentials...");
 				try {
@@ -145,9 +145,9 @@ namespace Tasque.Backends.Rtm
 					Logger.Debug ("Setting configured status to true");
 					Configured = true;
 				} catch (RtmNet.RtmApiException e) {
-					preferences.Set (Tasque.Preferences.AuthTokenKey, null);
-					preferences.Set (Tasque.Preferences.UserIdKey, null);
-					preferences.Set (Tasque.Preferences.UserNameKey, null);
+					preferences.Set (PreferencesKeys.AuthTokenKey, null);
+					preferences.Set (PreferencesKeys.UserIdKey, null);
+					preferences.Set (PreferencesKeys.UserNameKey, null);
 					rtm = null;
 					rtmAuth = null;
 					Logger.Error ("Exception authenticating, reverting" + e.Message);
@@ -201,14 +201,14 @@ namespace Tasque.Backends.Rtm
 		{
 			rtmAuth = rtm.AuthGetToken (frob);
 			if (rtmAuth != null) {
-				preferences.Set (Tasque.Preferences.AuthTokenKey, rtmAuth.Token);
+				preferences.Set (PreferencesKeys.AuthTokenKey, rtmAuth.Token);
 				if (rtmAuth.User != null) {
-					preferences.Set (Tasque.Preferences.UserNameKey, rtmAuth.User.Username);
-					preferences.Set (Tasque.Preferences.UserIdKey, rtmAuth.User.UserId);
+					preferences.Set (PreferencesKeys.UserNameKey, rtmAuth.User.Username);
+					preferences.Set (PreferencesKeys.UserIdKey, rtmAuth.User.UserId);
 				}
 			}
 			
-			var authToken = preferences.Get (Tasque.Preferences.AuthTokenKey);
+			var authToken = preferences.Get (PreferencesKeys.AuthTokenKey);
 			if (authToken != null) {
 				Logger.Debug ("Found AuthToken, checking credentials...");
 				try {
@@ -493,7 +493,7 @@ namespace Tasque.Backends.Rtm
 		TaskComparer taskComparer;
 		CategoryComparer categoryComparer;
 
-		Preferences preferences;
+		IPreferences preferences;
 
 		const string apiKey = "b29f7517b6584035d07df3170b80c430";
 		const string sharedSecret = "93eb5f83628b2066";
diff --git a/src/Addins/Backends/Sqlite/SqliteBackend.cs b/src/Addins/Backends/Sqlite/SqliteBackend.cs
index 49201e5..25f7e21 100644
--- a/src/Addins/Backends/Sqlite/SqliteBackend.cs
+++ b/src/Addins/Backends/Sqlite/SqliteBackend.cs
@@ -128,7 +128,7 @@ namespace Tasque.Backends.Sqlite
 		public void Refresh()
 		{}
 		
-		public void Initialize (Preferences preferences)
+		public void Initialize (IPreferences preferences)
 		{
 			if (preferences == null)
 				throw new ArgumentNullException ("preferences");
diff --git a/src/Gtk.Tasque/CompletedTaskGroup.cs b/src/Gtk.Tasque/CompletedTaskGroup.cs
index 7213e28..ed968f5 100644
--- a/src/Gtk.Tasque/CompletedTaskGroup.cs
+++ b/src/Gtk.Tasque/CompletedTaskGroup.cs
@@ -62,11 +62,11 @@ namespace Tasque
 			
 			// TODO: Set the initial value and range
 			string rangeStr =
-				Application.Preferences.Get (Preferences.CompletedTasksRange);
+				Application.Preferences.Get (PreferencesKeys.CompletedTasksRange);
 			if (rangeStr == null) {
 				// Set a default value of All
 				rangeStr = ShowCompletedRange.All.ToString ();
-				Application.Preferences.Set (Preferences.CompletedTasksRange,
+				Application.Preferences.Set (PreferencesKeys.CompletedTasksRange,
 											 rangeStr);
 			}
 			
@@ -88,10 +88,10 @@ namespace Tasque
 		}
 		
 		protected void OnSelectedCategorySettingChanged (
-								Preferences preferences,
+								IPreferences preferences,
 								string settingKey)
 		{
-			if (settingKey.CompareTo (Preferences.SelectedCategoryKey) != 0)
+			if (settingKey.CompareTo (PreferencesKeys.SelectedCategoryKey) != 0)
 				return;
 			
 			selectedCategory = GetSelectedCategory ();
@@ -103,7 +103,7 @@ namespace Tasque
 			ICategory foundCategory = null;
 			
 			string cat = Application.Preferences.Get (
-							Preferences.SelectedCategoryKey);
+				PreferencesKeys.SelectedCategoryKey);
 			if (cat != null) {
 				var model = Application.Backend.Categories;
 				foundCategory = model.FirstOrDefault (c => c.Name == cat);
@@ -122,7 +122,7 @@ namespace Tasque
 				return;
 			
 			this.currentRange = range;
-			Application.Preferences.Set (Preferences.CompletedTasksRange,
+			Application.Preferences.Set (PreferencesKeys.CompletedTasksRange,
 										 range.ToString ());
 			
 			UpdateDateRanges ();
diff --git a/src/Gtk.Tasque/PreferencesDialog.cs b/src/Gtk.Tasque/PreferencesDialog.cs
index 341245c..0d54b03 100644
--- a/src/Gtk.Tasque/PreferencesDialog.cs
+++ b/src/Gtk.Tasque/PreferencesDialog.cs
@@ -178,14 +178,14 @@ namespace Tasque
 			lblTodaysTaskColor.WidthRequest = 75;
 			lblTodaysTaskColor.Show ();
 
-			Preferences prefs = application.Preferences;
+			IPreferences prefs = application.Preferences;
 			txtTodaysTaskColor = new Entry();
-			txtTodaysTaskColor.Text = prefs.Get (Preferences.TodayTaskTextColor);
+			txtTodaysTaskColor.Text = prefs.Get (PreferencesKeys.TodayTaskTextColor);
 			txtTodaysTaskColor.Changed += OnTxtTodaysTaskColorChanged;
 			txtTodaysTaskColor.Show ();
 
 			btnChangeTodaysTaskColor = new ColorButton();
-			string todayTasksColor = prefs.Get (Preferences.TodayTaskTextColor);
+			string todayTasksColor = prefs.Get (PreferencesKeys.TodayTaskTextColor);
 			Gdk.Color currentColor = new Gdk.Color();
 			Gdk.Color.Parse (todayTasksColor, ref currentColor);
 			btnChangeTodaysTaskColor.Color = currentColor;
@@ -207,12 +207,12 @@ namespace Tasque
 			lblOverdueTaskColor.Show ();
 
 			txtOverdueTaskColor = new Entry();
-			txtOverdueTaskColor.Text = prefs.Get (Preferences.OverdueTaskTextColor);
+			txtOverdueTaskColor.Text = prefs.Get (PreferencesKeys.OverdueTaskTextColor);
 			txtOverdueTaskColor.Changed += OnTxtOverdueTaskColorChanged;
 			txtOverdueTaskColor.Show ();
 
 			btnChangeOverdueTaskColor = new ColorButton();
-			string overdueTasksColor = prefs.Get (Preferences.OverdueTaskTextColor);
+			string overdueTasksColor = prefs.Get (PreferencesKeys.OverdueTaskTextColor);
 			Gdk.Color overdueColor = new Gdk.Color();
 			Gdk.Color.Parse (overdueTasksColor, ref overdueColor);
 			btnChangeOverdueTaskColor.Color = overdueColor;
@@ -304,7 +304,7 @@ namespace Tasque
 			hbox = new HBox (false, 6);
 			
 			bool showCompletedTasks = application.Preferences.GetBool (
-											Preferences.ShowCompletedTasksKey);
+				PreferencesKeys.ShowCompletedTasksKey);
 			showCompletedTasksCheckButton =
 				new CheckButton (Catalog.GetString ("Sh_ow completed tasks"));
 			showCompletedTasksCheckButton.UseUnderline = true;
@@ -380,7 +380,7 @@ namespace Tasque
 		{
 			Logger.Debug("Loading preferences");
 			categoriesToHide =
-				application.Preferences.GetStringList (Preferences.HideInAllCategory);
+				application.Preferences.GetStringList (PreferencesKeys.HideInAllCategory);
 			//if (categoriesToHide == null || categoriesToHide.Count == 0)
 			//	categoriesToHide = BuildNewCategoryList ();
 		}
@@ -390,7 +390,7 @@ namespace Tasque
 			// showCompletedTasksCheckbox delegate
 			showCompletedTasksCheckButton.Toggled += delegate {
 				application.Preferences.SetBool (
-					Preferences.ShowCompletedTasksKey,
+					PreferencesKeys.ShowCompletedTasksKey,
 					showCompletedTasksCheckButton.Active);
 			};
 		}
@@ -404,7 +404,7 @@ namespace Tasque
 		private void OnTxtTodaysTaskColorChanged (object sender, EventArgs args)
 		{
 			// Save the user preference
-			application.Preferences.Set (Preferences.TodayTaskTextColor,
+			application.Preferences.Set (PreferencesKeys.TodayTaskTextColor,
 			                             ((Entry) sender).Text);
 		}
 
@@ -417,7 +417,7 @@ namespace Tasque
 		private void OnTxtOverdueTaskColorChanged (object sender, EventArgs args)
 		{
 			// Save the user preference
-			application.Preferences.Set (Preferences.OverdueTaskTextColor,
+			application.Preferences.Set (PreferencesKeys.OverdueTaskTextColor,
 			                             ((Entry) sender).Text);
 		}
 
@@ -483,11 +483,11 @@ namespace Tasque
 			}
 			
 			// Save the user preference
-			application.Preferences.Set (Preferences.CurrentBackend,
+			application.Preferences.Set (PreferencesKeys.CurrentBackend,
 										 newBackend.GetType ().ToString ());
 			
 			//categoriesToHide = BuildNewCategoryList ();
-			//Application.Preferences.SetStringList (Preferences.HideInAllCategory,
+			//Application.Preferences.SetStringList (IPreferences.HideInAllCategory,
 			//									   categoriesToHide);
 			RebuildCategoryTree ();
 		}
@@ -554,7 +554,7 @@ namespace Tasque
 			else
 				categoriesToHide.Add (category.Name);
 			
-			application.Preferences.SetStringList (Preferences.HideInAllCategory,
+			application.Preferences.SetStringList (PreferencesKeys.HideInAllCategory,
 												   categoriesToHide);
 		}
 		
diff --git a/src/Gtk.Tasque/RemoteControl.cs b/src/Gtk.Tasque/RemoteControl.cs
index 5c1caf8..8553c65 100644
--- a/src/Gtk.Tasque/RemoteControl.cs
+++ b/src/Gtk.Tasque/RemoteControl.cs
@@ -143,7 +143,7 @@ namespace Tasque
 			// If enabled, attempt to parse due date information
 			// out of the taskName.
 			DateTime taskDueDate = DateTime.MinValue;
-			if (parseDate && application.Preferences.GetBool (Preferences.ParseDateEnabledKey))
+			if (parseDate && application.Preferences.GetBool (PreferencesKeys.ParseDateEnabledKey))
 				TaskParser.Instance.TryParse (
 				                         taskName,
 				                         out taskName,
diff --git a/src/Gtk.Tasque/TaskGroup.cs b/src/Gtk.Tasque/TaskGroup.cs
index 711f137..cefe638 100644
--- a/src/Gtk.Tasque/TaskGroup.cs
+++ b/src/Gtk.Tasque/TaskGroup.cs
@@ -375,7 +375,7 @@ namespace Tasque
 			// TODO: Move this code into some function in the backend/somewhere
 			// with the signature of GetCategoryForName (string catName):ICategory
 			string selectedCategoryName =
-				Application.Preferences.Get (Preferences.SelectedCategoryKey);
+				Application.Preferences.Get (PreferencesKeys.SelectedCategoryKey);
 			
 			ICategory category = null;
 			if (selectedCategoryName != null) {
@@ -438,14 +438,14 @@ namespace Tasque
 				ButtonPressed (sender, args);
 		}
 		
-		protected void OnSettingChanged (Preferences preferences,
+		protected void OnSettingChanged (IPreferences preferences,
 										 string settingKey)
 		{
-			if (settingKey.CompareTo (Preferences.ShowCompletedTasksKey) != 0)
+			if (settingKey.CompareTo (PreferencesKeys.ShowCompletedTasksKey) != 0)
 				return;
 			
 			bool newValue =
-				preferences.GetBool (Preferences.ShowCompletedTasksKey);
+				preferences.GetBool (PreferencesKeys.ShowCompletedTasksKey);
 			if (Model.ShowCompletedTasks == newValue)
 				return; // don't do anything if nothing has changed
 			
diff --git a/src/Gtk.Tasque/TaskTreeView.cs b/src/Gtk.Tasque/TaskTreeView.cs
index 845fbda..a0f39d6 100644
--- a/src/Gtk.Tasque/TaskTreeView.cs
+++ b/src/Gtk.Tasque/TaskTreeView.cs
@@ -14,7 +14,7 @@ namespace Tasque
 	/// </summary>
 	public class TaskTreeView : Gtk.TreeView
 	{
-		Preferences preferences;
+		IPreferences preferences;
 
 		private static Gdk.Pixbuf notePixbuf;
 		
@@ -44,7 +44,7 @@ namespace Tasque
 			get { return taskBeingEdited; }
 		}
 
-		public TaskTreeView (Gtk.TreeModel model, Preferences preferences)
+		public TaskTreeView (Gtk.TreeModel model, IPreferences preferences)
 			: base ()
 		{
 			if (preferences == null)
@@ -448,8 +448,8 @@ namespace Tasque
 			
 			string formatString = "{0}";
 
-			string todayTasksColor = preferences.Get (Preferences.TodayTaskTextColor);
-			string overdueTaskColor = preferences.Get (Preferences.OverdueTaskTextColor);
+			string todayTasksColor = preferences.Get (PreferencesKeys.TodayTaskTextColor);
+			string overdueTaskColor = preferences.Get (PreferencesKeys.OverdueTaskTextColor);
 
 			if (task.IsComplete)
 				; // Completed tasks colored below
@@ -531,7 +531,7 @@ namespace Tasque
 				return;
 			}
 
-			int timerSeconds = preferences.GetInt (Preferences.InactivateTimeoutKey);
+			int timerSeconds = preferences.GetInt (PreferencesKeys.InactivateTimeoutKey);
 			// convert to milliseconds for more granularity
 			long timeout = timerSeconds * 1000;
 			
@@ -634,7 +634,7 @@ namespace Tasque
 			
 			if (task.State == TaskState.Active) {
 				bool showCompletedTasks =
-					preferences.GetBool (Preferences.ShowCompletedTasksKey);
+					preferences.GetBool (PreferencesKeys.ShowCompletedTasksKey);
 				
 				// When showCompletedTasks is true, complete the tasks right
 				// away.  Otherwise, set a timer and show the timer animation
@@ -647,7 +647,7 @@ namespace Tasque
 					
 					// Read the inactivate timeout from a preference
 					int timeout =
-						preferences.GetInt (Preferences.InactivateTimeoutKey);
+						preferences.GetInt (PreferencesKeys.InactivateTimeoutKey);
 					Logger.Debug ("Read timeout from prefs: {0}", timeout);
 					InactivateTimer timer =
 						new InactivateTimer (this, iter, task, (uint) timeout);
@@ -697,7 +697,7 @@ namespace Tasque
 			string newText = args.NewText;
 			
 			// Attempt to derive due date information from text.
-			if (preferences.GetBool (Preferences.ParseDateEnabledKey) &&
+			if (preferences.GetBool (PreferencesKeys.ParseDateEnabledKey) &&
 			    task.State == TaskState.Active &&
 			    task.DueDate == DateTime.MinValue) {
 				
diff --git a/src/Gtk.Tasque/TaskWindow.cs b/src/Gtk.Tasque/TaskWindow.cs
index 24142ff..9576fb7 100644
--- a/src/Gtk.Tasque/TaskWindow.cs
+++ b/src/Gtk.Tasque/TaskWindow.cs
@@ -374,7 +374,7 @@ namespace Tasque
 
 			// Read preferences for the last-selected category and select it
 			string selectedCategoryName =
-				application.Preferences.Get (Preferences.SelectedCategoryKey);
+				application.Preferences.Get (PreferencesKeys.SelectedCategoryKey);
 			
 			categoryComboBox.Changed += OnCategoryChanged;
 			
@@ -393,7 +393,7 @@ namespace Tasque
 			taskWindow.OnAddTask (null, EventArgs.Empty);
 		}
 
-		public static void SavePosition (Preferences preferences)
+		public static void SavePosition (IPreferences preferences)
 		{
 			if(taskWindow != null) {
 				int x;
@@ -865,9 +865,9 @@ namespace Tasque
 
 		}
 		
-		void OnSettingChanged (Preferences preferences, string settingKey)
+		void OnSettingChanged (IPreferences preferences, string settingKey)
 		{
-			if (settingKey.CompareTo (Preferences.HideInAllCategory) != 0)
+			if (settingKey.CompareTo (PreferencesKeys.HideInAllCategory) != 0)
 				return;
 			
 			OnCategoryChanged (this, EventArgs.Empty);
@@ -942,7 +942,7 @@ namespace Tasque
 			// out of the entered task text.
 			DateTime taskDueDate = DateTime.MinValue;
 			string taskName;
-			if (application.Preferences.GetBool (Preferences.ParseDateEnabledKey))
+			if (application.Preferences.GetBool (PreferencesKeys.ParseDateEnabledKey))
 				TaskParser.Instance.TryParse (
 				                         enteredTaskText,
 				                         out taskName,
@@ -987,7 +987,7 @@ namespace Tasque
 					// specifically.
 					List<string> categoriesToHide =
 						application.Preferences.GetStringList (
-							Preferences.HideInAllCategory);
+							PreferencesKeys.HideInAllCategory);
 					if (categoriesToHide != null && categoriesToHide.Contains (item.Category.Name)) {
 						SelectCategory (item.Category.Name);
 					}
@@ -1019,7 +1019,7 @@ namespace Tasque
 			completedTaskGroup.Refilter (category);
 			
 			// Save the selected category in preferences
-			application.Preferences.Set (Preferences.SelectedCategoryKey,
+			application.Preferences.Set (PreferencesKeys.SelectedCategoryKey,
 										 category.Name);
 		}
 		
diff --git a/src/libtasque/AllCategory.cs b/src/libtasque/AllCategory.cs
index 34d0ebe..699bb3b 100644
--- a/src/libtasque/AllCategory.cs
+++ b/src/libtasque/AllCategory.cs
@@ -15,13 +15,13 @@ namespace Tasque
 		// specified lists will be shown.
 		List<string> categoriesToHide;
 		
-		public AllCategory (Preferences preferences)
+		public AllCategory (IPreferences preferences)
 		{
 			if (preferences == null)
 				throw new ArgumentNullException ("preferences");
 			categoriesToHide =
-				preferences.GetStringList (Preferences.HideInAllCategory);
-			categoriesToHide = preferences.GetStringList (Preferences.HideInAllCategory);
+				preferences.GetStringList (PreferencesKeys.HideInAllCategory);
+			categoriesToHide = preferences.GetStringList (PreferencesKeys.HideInAllCategory);
 			preferences.SettingChanged += OnSettingChanged;
 		}
 		
@@ -44,13 +44,13 @@ namespace Tasque
 			return (!categoriesToHide.Contains (category.Name));
 		}
 		
-		private void OnSettingChanged (Preferences preferences, string settingKey)
+		private void OnSettingChanged (IPreferences preferences, string settingKey)
 		{
-			if (settingKey.CompareTo (Preferences.HideInAllCategory) != 0)
+			if (settingKey.CompareTo (PreferencesKeys.HideInAllCategory) != 0)
 				return;
 			
 			categoriesToHide =
-				preferences.GetStringList (Preferences.HideInAllCategory);
+				preferences.GetStringList (PreferencesKeys.HideInAllCategory);
 		}
 	}
 }
diff --git a/src/libtasque/CompletedTaskGroupModel.cs b/src/libtasque/CompletedTaskGroupModel.cs
index 446d0e6..1bc3afa 100644
--- a/src/libtasque/CompletedTaskGroupModel.cs
+++ b/src/libtasque/CompletedTaskGroupModel.cs
@@ -7,7 +7,7 @@ namespace Tasque
 	public class CompletedTaskGroupModel : TaskGroupModel
 	{
 		public CompletedTaskGroupModel (DateTime rangeStart, DateTime rangeEnd,
-		                                ICollection<ITask> tasks, Preferences preferences)
+		                                ICollection<ITask> tasks, IPreferences preferences)
 			: base (rangeStart, rangeEnd, tasks, preferences)
 		{
 		}
diff --git a/src/libtasque/IBackend.cs b/src/libtasque/IBackend.cs
index d7c628d..1a35014 100644
--- a/src/libtasque/IBackend.cs
+++ b/src/libtasque/IBackend.cs
@@ -96,7 +96,7 @@ namespace Tasque.Backends
 		/// <summary>
 		/// Initializes the backend
 		/// </summary>
-		void Initialize (Preferences preferences);
+		void Initialize (IPreferences preferences);
 
 		/// <summary>
 		/// Cleanup the backend before quitting
diff --git a/src/libtasque/INativeApplication.cs b/src/libtasque/INativeApplication.cs
index 1fef995..ad28933 100644
--- a/src/libtasque/INativeApplication.cs
+++ b/src/libtasque/INativeApplication.cs
@@ -12,7 +12,7 @@ namespace Tasque
 		TaskGroupModel TodayTasks { get; }
 		TaskGroupModel TomorrowTasks { get; }
 		string ConfDir { get; }
-		Preferences Preferences { get; }
+		IPreferences Preferences { get; }
 		void Exit (int exitcode = 0);
 		void Initialize (string [] args);
 		void ShowPreferences ();
diff --git a/src/libtasque/IPreferences.cs b/src/libtasque/IPreferences.cs
index 9828a3e..222f49b 100644
--- a/src/libtasque/IPreferences.cs
+++ b/src/libtasque/IPreferences.cs
@@ -27,7 +27,7 @@ using System.Collections.Generic;
 
 namespace Tasque
 {
-	public delegate void SettingChangedHandler (Preferences preferences, string settingKey);
+	public delegate void SettingChangedHandler (IPreferences preferences, string settingKey);
 
 	public interface IPreferences
 	{
diff --git a/src/libtasque/NativeApplication.cs b/src/libtasque/NativeApplication.cs
index 4ab1572..a93b36a 100644
--- a/src/libtasque/NativeApplication.cs
+++ b/src/libtasque/NativeApplication.cs
@@ -37,7 +37,7 @@ namespace Tasque
 	{
 		public abstract string ConfDir { get; }
 		
-		public Preferences Preferences { get { return preferences; } }
+		public IPreferences Preferences { get { return preferences; } }
 
 		public abstract void ShowPreferences ();
 
@@ -78,7 +78,7 @@ namespace Tasque
 				// Check to see if the user has a preference of which backend
 				// to use.  If so, use it, otherwise, pop open the preferences
 				// dialog so they can choose one.
-				var backendTypeString = preferences.Get (Preferences.CurrentBackend);
+				var backendTypeString = preferences.Get (PreferencesKeys.CurrentBackend);
 				Logger.Debug ("CurrentBackend specified in Preferences: {0}", backendTypeString);
 				if (backendTypeString != null && availableBackends.ContainsKey (backendTypeString))
 					Backend = availableBackends [backendTypeString];
@@ -345,6 +345,6 @@ namespace Tasque
 		IBackend backend;
 		IBackend customBackend;
 		string potentialBackendClassName;
-		Preferences preferences;
+		IPreferences preferences;
 	}
 }
diff --git a/src/libtasque/Preferences.cs b/src/libtasque/Preferences.cs
index ae7992b..3fbd806 100644
--- a/src/libtasque/Preferences.cs
+++ b/src/libtasque/Preferences.cs
@@ -42,36 +42,6 @@ namespace Tasque
 	{
 		private System.Xml.XmlDocument document;
 		private string location;
-		
-		public const string AuthTokenKey = "AuthToken";
-		public const string CurrentBackend = "CurrentBackend";
-		public const string InactivateTimeoutKey = "InactivateTimeout";
-		public const string SelectedCategoryKey = "SelectedCategory";
-		public const string ParseDateEnabledKey = "ParseDateEnabled";
-		public const string TodayTaskTextColor = "TodayTaskTextColor";
-		public const string OverdueTaskTextColor = "OverdueTaskTextColor";
-
-		/// <summary>
-		/// A list of category names to show in the TaskWindow when the "All"
-		/// category is selected.
-		/// </summary>
-		public const string HideInAllCategory = "HideInAllCategory";
-		public const string ShowCompletedTasksKey = "ShowCompletedTasks";
-		public const string UserNameKey = "UserName";
-		public const string UserIdKey = "UserID";
-		
-		/// <summary>
-		/// This setting allows a user to specify how many completed tasks to
-		/// show in the Completed Tasks Category.  The setting should be one of:
-		/// "Yesterday", "Last7Days", "LastMonth", "LastYear", or "All".
-		/// </summary>
-		/// <param name="settingKey">
-		/// A <see cref="System.String"/>
-		/// </param>
-		/// <returns>
-		/// A <see cref="System.String"/>
-		/// </returns>
-		public const string CompletedTasksRange = "CompletedTasksRange";
 
 		public event SettingChangedHandler SettingChanged;
 		
@@ -103,11 +73,11 @@ namespace Tasque
 		private string GetDefault (string settingKey)
 		{
 			switch (settingKey) {
-			case ParseDateEnabledKey:
+			case PreferencesKeys.ParseDateEnabledKey:
 				return true.ToString ();
-			case TodayTaskTextColor:
+			case PreferencesKeys.TodayTaskTextColor:
 				return "#181AB7";
-			case OverdueTaskTextColor:
+			case PreferencesKeys.OverdueTaskTextColor:
 				return "#EB3320";
 			default:
 				return null;
@@ -251,8 +221,8 @@ namespace Tasque
 		/// </summary>
 		private void ValidatePrefs ()
 		{
-			if (GetInt (Preferences.InactivateTimeoutKey) <= 0)
-				SetInt (Preferences.InactivateTimeoutKey, 5);
+			if (GetInt (PreferencesKeys.InactivateTimeoutKey) <= 0)
+				SetInt (PreferencesKeys.InactivateTimeoutKey, 5);
 		}
 
 
diff --git a/src/libtasque/PreferencesKeys.cs b/src/libtasque/PreferencesKeys.cs
new file mode 100644
index 0000000..4b12682
--- /dev/null
+++ b/src/libtasque/PreferencesKeys.cs
@@ -0,0 +1,55 @@
+//
+// PreferencesKeys.cs
+//
+// Author:
+//       Antonius Riha <antoniusriha gmail com>
+//
+// Copyright (c) 2013 Antonius Riha
+//
+// 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.
+
+namespace Tasque
+{
+	public static class PreferencesKeys
+	{
+		public const string AuthTokenKey = "AuthToken";
+		public const string CurrentBackend = "CurrentBackend";
+		public const string InactivateTimeoutKey = "InactivateTimeout";
+		public const string SelectedCategoryKey = "SelectedCategory";
+		public const string ParseDateEnabledKey = "ParseDateEnabled";
+		public const string TodayTaskTextColor = "TodayTaskTextColor";
+		public const string OverdueTaskTextColor = "OverdueTaskTextColor";
+		
+		/// <summary>
+		/// A list of category names to show in the TaskWindow when the "All"
+		/// category is selected.
+		/// </summary>
+		public const string HideInAllCategory = "HideInAllCategory";
+		public const string ShowCompletedTasksKey = "ShowCompletedTasks";
+		public const string UserNameKey = "UserName";
+		public const string UserIdKey = "UserID";
+		
+		/// <summary>
+		/// This setting allows a user to specify how many completed tasks to
+		/// show in the Completed Tasks Category.  The setting should be one of:
+		/// "Yesterday", "Last7Days", "LastMonth", "LastYear", or "All".
+		/// </summary>
+		public const string CompletedTasksRange = "CompletedTasksRange";
+	}
+}
diff --git a/src/libtasque/TaskGroupModel.cs b/src/libtasque/TaskGroupModel.cs
index 7235258..51f0ed7 100644
--- a/src/libtasque/TaskGroupModel.cs
+++ b/src/libtasque/TaskGroupModel.cs
@@ -34,7 +34,7 @@ namespace Tasque
 		}
 		
 		public TaskGroupModel (DateTime rangeStart, DateTime rangeEnd,
-		                       ICollection<ITask> tasks, Preferences preferences)
+		                       ICollection<ITask> tasks, IPreferences preferences)
 		{
 			if (preferences == null)
 				throw new ArgumentNullException ("preferences");
@@ -47,7 +47,7 @@ namespace Tasque
 			taskChangeLog = new List<MementoTask> ();
 			
 			showCompletedTasks = preferences.GetBool (
-				Preferences.ShowCompletedTasksKey);
+				PreferencesKeys.ShowCompletedTasksKey);
 			
 			originalTasks = tasks;
 			((INotifyCollectionChanged)tasks).CollectionChanged += HandleCollectionChanged;
diff --git a/src/libtasque/TaskGroupModelFactory.cs b/src/libtasque/TaskGroupModelFactory.cs
index a4e276c..e5f17d1 100644
--- a/src/libtasque/TaskGroupModelFactory.cs
+++ b/src/libtasque/TaskGroupModelFactory.cs
@@ -6,7 +6,7 @@ namespace Tasque
 {
 	public static class TaskGroupModelFactory
 	{
-		public static TaskGroupModel CreateTodayModel (ICollection<ITask> tasks, Preferences preferences)
+		public static TaskGroupModel CreateTodayModel (ICollection<ITask> tasks, IPreferences preferences)
 		{
 			DateTime rangeStart = DateTime.Now;
 			rangeStart = new DateTime (rangeStart.Year, rangeStart.Month,
@@ -17,7 +17,7 @@ namespace Tasque
 			return new TaskGroupModel (rangeStart, rangeEnd, tasks, preferences);
 		}
 
-		public static TaskGroupModel CreateOverdueModel (ICollection<ITask> tasks, Preferences preferences)
+		public static TaskGroupModel CreateOverdueModel (ICollection<ITask> tasks, IPreferences preferences)
 		{
 			DateTime rangeStart = DateTime.MinValue;
 			DateTime rangeEnd = DateTime.Now.AddDays (-1);
@@ -27,7 +27,7 @@ namespace Tasque
 			return new TaskGroupModel (rangeStart, rangeEnd, tasks, preferences);
 		}
 
-		public static TaskGroupModel CreateTomorrowModel (ICollection<ITask> tasks, Preferences preferences)
+		public static TaskGroupModel CreateTomorrowModel (ICollection<ITask> tasks, IPreferences preferences)
 		{
 			DateTime rangeStart = DateTime.Now.AddDays (1);
 			rangeStart = new DateTime (rangeStart.Year, rangeStart.Month,
diff --git a/src/libtasque/libtasque.csproj b/src/libtasque/libtasque.csproj
index 870c1d5..1ce5d7f 100644
--- a/src/libtasque/libtasque.csproj
+++ b/src/libtasque/libtasque.csproj
@@ -79,6 +79,7 @@
     <Compile Include="TaskComparer.cs" />
     <Compile Include="AllCategory.cs" />
     <Compile Include="IPreferences.cs" />
+    <Compile Include="PreferencesKeys.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="DateFormatters\" />



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