[tasque] Remove preferences Gtk# dep from model: IBackend.GetPreferencesWidget ()



commit d0ce33fed08866e7ddbedf69dca98065d5ac2f78
Author: Antonius Riha <antoniusriha gmail com>
Date:   Tue Nov 27 11:27:50 2012 +0100

    Remove preferences Gtk# dep from model: IBackend.GetPreferencesWidget ()
    
    The method IBackend.GetPreferencesWidget () has been substituted by the read-only property IBackend.Preferences, which is of type IBackendPreferences. This interface has been created to provide an abstract handle for the class PreferencesDialog.cs in the application. A concrete preferences widget is being provided along with the backend implementation: DummyPreferences.cs.
    
    Conflicts:
    
    	src/libtasque/IBackend.cs
    	src/libtasque/libtasque.csproj
    	src/tasque/tasque.csproj

 src/Addins/Backends/Dummy/DummyBackend.cs          |   11 +++--
 src/Addins/Backends/Dummy/DummyBackend.csproj      |    2 +
 src/Addins/Backends/Dummy/Gtk/DummyPreferences.cs  |   40 ++++++++++++++++++++
 .../Backends/Rtm/Gtk/RtmPreferencesWidget.cs       |    2 +-
 src/Addins/Backends/Rtm/RtmBackend.cs              |   23 +++++------
 .../Backends/Sqlite/Gtk/SqlitePreferences.cs       |   40 ++++++++++++++++++++
 src/Addins/Backends/Sqlite/SqliteBackend.cs        |   16 ++++---
 src/Addins/Backends/Sqlite/SqliteBackend.csproj    |    2 +
 src/Gtk.Tasque/PreferencesDialog.cs                |    4 +-
 src/libtasque/IBackend.cs                          |   22 +++++------
 src/libtasque/IBackendPreferences.cs               |   32 ++++++++++++++++
 src/libtasque/libtasque.csproj                     |    1 +
 12 files changed, 156 insertions(+), 39 deletions(-)
---
diff --git a/src/Addins/Backends/Dummy/DummyBackend.cs b/src/Addins/Backends/Dummy/DummyBackend.cs
index 18bf150..7eb5c3f 100644
--- a/src/Addins/Backends/Dummy/DummyBackend.cs
+++ b/src/Addins/Backends/Dummy/DummyBackend.cs
@@ -5,6 +5,7 @@ using System;
 using System.Collections.Generic;
 using Mono.Unix;
 using Tasque.Backends;
+using Gtk.Tasque.Backends.Dummy;
 
 namespace Tasque.Backends.Dummy
 {
@@ -256,11 +257,13 @@ namespace Tasque.Backends.Dummy
 		public void Cleanup()
 		{}
 		
-		public Gtk.Widget GetPreferencesWidget ()
+		public IBackendPreferences Preferences
 		{
-			// TODO: Replace this with returning null once things are going
-			// so that the Preferences Dialog doesn't waste space.
-			return new Gtk.Label ("Debugging System (this message is a test)");
+			get {
+				// TODO: Replace this with returning null once things are going
+				// so that the Preferences Dialog doesn't waste space.
+				return new DummyPreferences ();
+			}
 		}
 		#endregion // Public Methods
 		
diff --git a/src/Addins/Backends/Dummy/DummyBackend.csproj b/src/Addins/Backends/Dummy/DummyBackend.csproj
index 5cc41ee..5000d1e 100644
--- a/src/Addins/Backends/Dummy/DummyBackend.csproj
+++ b/src/Addins/Backends/Dummy/DummyBackend.csproj
@@ -53,6 +53,7 @@
     <Compile Include="..\..\..\..\build\CommonAssemblyInfo.cs">
       <Link>Properties\CommonAssemblyInfo.cs</Link>
     </Compile>
+    <Compile Include="Gtk\DummyPreferences.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\..\..\Gtk.Tasque\Gtk.Tasque.csproj">
@@ -66,6 +67,7 @@
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Properties\" />
+    <Folder Include="Gtk\" />
   </ItemGroup>
   <Import Project="..\..\..\..\build\X.Common.targets" />
 </Project>
diff --git a/src/Addins/Backends/Dummy/Gtk/DummyPreferences.cs b/src/Addins/Backends/Dummy/Gtk/DummyPreferences.cs
new file mode 100644
index 0000000..0834c67
--- /dev/null
+++ b/src/Addins/Backends/Dummy/Gtk/DummyPreferences.cs
@@ -0,0 +1,40 @@
+// 
+// DummyPreferences.cs
+//  
+// Author:
+//       Antonius Riha <antoniusriha gmail com>
+// 
+// Copyright (c) 2012 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.
+using Gtk;
+using Tasque.Backends;
+
+namespace Gtk.Tasque.Backends.Dummy
+{
+	public class DummyPreferences : Box, IBackendPreferences
+	{
+		public DummyPreferences () : base ()
+		{
+			var lbl = new Label ("Debugging System (this message is a test)");
+			PackStart (lbl, true, true, 0);
+			ShowAll ();
+		}
+	}
+}
diff --git a/src/Addins/Backends/Rtm/Gtk/RtmPreferencesWidget.cs b/src/Addins/Backends/Rtm/Gtk/RtmPreferencesWidget.cs
index dec3e5f..45387b7 100644
--- a/src/Addins/Backends/Rtm/Gtk/RtmPreferencesWidget.cs
+++ b/src/Addins/Backends/Rtm/Gtk/RtmPreferencesWidget.cs
@@ -7,7 +7,7 @@ using Mono.Unix;
 
 namespace Tasque.Backends.RtmBackend
 {
-	public class RtmPreferencesWidget : Gtk.EventBox
+	public class RtmPreferencesWidget : Gtk.EventBox, IBackendPreferences
 	{
  		private LinkButton		authButton;
 		
diff --git a/src/Addins/Backends/Rtm/RtmBackend.cs b/src/Addins/Backends/Rtm/RtmBackend.cs
index 8be781a..dd448d2 100644
--- a/src/Addins/Backends/Rtm/RtmBackend.cs
+++ b/src/Addins/Backends/Rtm/RtmBackend.cs
@@ -131,6 +131,8 @@ namespace Tasque.Backends.RtmBackend
 			get { return initialized; }
 		}
 		
+		public IBackendPreferences Preferences { get { return new RtmPreferencesWidget (); } }
+		
 #endregion // Public Properties
 
 #region Public Methods
@@ -209,7 +211,7 @@ namespace Tasque.Backends.RtmBackend
 			// AUTHENTICATION to Remember The Milk
 			// *************************************
 			string authToken =
-				Application.Preferences.Get (Preferences.AuthTokenKey);
+				Application.Preferences.Get (Tasque.Preferences.AuthTokenKey);
 			if (authToken != null ) {
 				Logger.Debug("Found AuthToken, checking credentials...");
 				try {
@@ -221,9 +223,9 @@ namespace Tasque.Backends.RtmBackend
 					configured = true;
 				} catch (RtmNet.RtmApiException e) {
 					
-					Application.Preferences.Set (Preferences.AuthTokenKey, null);
-					Application.Preferences.Set (Preferences.UserIdKey, null);
-					Application.Preferences.Set (Preferences.UserNameKey, null);
+					Application.Preferences.Set (Tasque.Preferences.AuthTokenKey, null);
+					Application.Preferences.Set (Tasque.Preferences.UserIdKey, null);
+					Application.Preferences.Set (Tasque.Preferences.UserNameKey, null);
 					rtm = null;
 					rtmAuth = null;
 					Logger.Error("Exception authenticating, reverting" + e.Message);
@@ -276,11 +278,6 @@ namespace Tasque.Backends.RtmBackend
 			refreshThread.Abort ();
 		}
 
-		public Gtk.Widget GetPreferencesWidget ()
-		{
-			return new RtmPreferencesWidget ();
-		}
-
 		public string GetAuthUrl()
 		{
 			frob = rtm.AuthGetFrob();
@@ -293,15 +290,15 @@ namespace Tasque.Backends.RtmBackend
 			rtmAuth = rtm.AuthGetToken(frob);
 			if (rtmAuth != null) {
 				Preferences prefs = Application.Preferences;
-				prefs.Set (Preferences.AuthTokenKey, rtmAuth.Token);
+				prefs.Set (Tasque.Preferences.AuthTokenKey, rtmAuth.Token);
 				if (rtmAuth.User != null) {
-					prefs.Set (Preferences.UserNameKey, rtmAuth.User.Username);
-					prefs.Set (Preferences.UserIdKey, rtmAuth.User.UserId);
+					prefs.Set (Tasque.Preferences.UserNameKey, rtmAuth.User.Username);
+					prefs.Set (Tasque.Preferences.UserIdKey, rtmAuth.User.UserId);
 				}
 			}
 			
 			string authToken =
-				Application.Preferences.Get (Preferences.AuthTokenKey);
+				Application.Preferences.Get (Tasque.Preferences.AuthTokenKey);
 			if (authToken != null ) {
 				Logger.Debug("Found AuthToken, checking credentials...");
 				try {
diff --git a/src/Addins/Backends/Sqlite/Gtk/SqlitePreferences.cs b/src/Addins/Backends/Sqlite/Gtk/SqlitePreferences.cs
new file mode 100644
index 0000000..19689f8
--- /dev/null
+++ b/src/Addins/Backends/Sqlite/Gtk/SqlitePreferences.cs
@@ -0,0 +1,40 @@
+//
+// SqlitePreferences.cs
+//
+// Author:
+//       Antonius Riha <antoniusriha gmail com>
+//
+// Copyright (c) 2012 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.
+using Gtk;
+using Tasque.Backends;
+
+namespace Gtk.Tasque.Backends.Sqlite
+{
+	public class SqlitePreferences : Box, IBackendPreferences
+	{
+		public SqlitePreferences () : base ()
+		{
+			var lbl = new Label ("Local file requires no configuration.");
+			PackStart (lbl, true, true, 0);
+			ShowAll ();
+		}
+	}
+}
diff --git a/src/Addins/Backends/Sqlite/SqliteBackend.cs b/src/Addins/Backends/Sqlite/SqliteBackend.cs
index f9da4f2..cd41d1a 100644
--- a/src/Addins/Backends/Sqlite/SqliteBackend.cs
+++ b/src/Addins/Backends/Sqlite/SqliteBackend.cs
@@ -6,6 +6,7 @@ using System.Collections.Generic;
 using Mono.Unix;
 using Tasque.Backends;
 using Mono.Data.Sqlite;
+using Gtk.Tasque.Backends.Sqlite;
 
 namespace Tasque.Backends.Sqlite
 {
@@ -90,6 +91,14 @@ namespace Tasque.Backends.Sqlite
 		{
 			get { return db; }
 		}
+		
+		public IBackendPreferences Preferences {
+			get {
+				// TODO: Replace this with returning null once things are going
+				// so that the Preferences Dialog doesn't waste space.
+				return new SqlitePreferences ();
+			}
+		}
 		#endregion // Public Properties
 		
 		#region Public Methods
@@ -159,13 +168,6 @@ namespace Tasque.Backends.Sqlite
 			initialized = false;		
 		}
 
-		public Gtk.Widget GetPreferencesWidget ()
-		{
-			// TODO: Replace this with returning null once things are going
-			// so that the Preferences Dialog doesn't waste space.
-			return new Gtk.Label ("Local file requires no configuration.");
-		}
-
 		/// <summary>
 		/// Given some text to be input into the database, do whatever
 		/// processing is required to make sure special characters are
diff --git a/src/Addins/Backends/Sqlite/SqliteBackend.csproj b/src/Addins/Backends/Sqlite/SqliteBackend.csproj
index c474b8a..ebee3af 100644
--- a/src/Addins/Backends/Sqlite/SqliteBackend.csproj
+++ b/src/Addins/Backends/Sqlite/SqliteBackend.csproj
@@ -98,9 +98,11 @@
     <Compile Include="..\..\..\..\build\CommonAssemblyInfo.cs">
       <Link>Properties\CommonAssemblyInfo.cs</Link>
     </Compile>
+    <Compile Include="Gtk\SqlitePreferences.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Properties\" />
+    <Folder Include="Gtk\" />
   </ItemGroup>
   <Import Project="..\..\..\..\build\X.Common.targets" />
   <Target Name="BeforeInstall" Condition=" '$(Configuration)' == 'GtkWinDebug' Or '$(Configuration)' == 'GtkWinRelease' ">
diff --git a/src/Gtk.Tasque/PreferencesDialog.cs b/src/Gtk.Tasque/PreferencesDialog.cs
index 77d11c0..252d9dd 100644
--- a/src/Gtk.Tasque/PreferencesDialog.cs
+++ b/src/Gtk.Tasque/PreferencesDialog.cs
@@ -130,7 +130,7 @@ namespace Tasque
 			backendPageId = -1;
 			
 			if (Application.Backend != null) {
-				backendPage = Application.Backend.GetPreferencesWidget ();
+				backendPage = (Widget)Application.Backend.Preferences;
 				if (backendPage != null) {
 					backendPage.Show ();
 					Label l =
@@ -461,7 +461,7 @@ namespace Tasque
 			selectedBackend = backendComboBox.Active;
 			
 			// Add a backend prefs page if one exists
-			backendPage = newBackend.GetPreferencesWidget ();
+			backendPage = (Widget)newBackend.Preferences;
 			if (backendPage != null) {
 				backendPage.Show ();
 				Label l = new Label (GLib.Markup.EscapeText (newBackend.Name));
diff --git a/src/libtasque/IBackend.cs b/src/libtasque/IBackend.cs
index d6df7b8..06073e5 100644
--- a/src/libtasque/IBackend.cs
+++ b/src/libtasque/IBackend.cs
@@ -63,6 +63,14 @@ namespace Tasque.Backends
 		{
 			get;
 		}
+		
+		/// <summary>
+		/// An object that provides a means of managing backend specific preferences.
+		/// </summary>
+		/// <returns>
+		/// A <see cref="Tasque.Backends.IBackendPreferences"/>
+		/// </returns>
+		IBackendPreferences Preferences { get; }
 		#endregion // Properties
 		
 		#region Methods
@@ -92,17 +100,7 @@ namespace Tasque.Backends
 		/// <summary>
 		/// Cleanup the backend before quitting
 		/// </summary>
-		void Cleanup();
-		
-		/// <summary>
-		/// A widget that will be placed into the Preferences Dialog when the
-		/// backend is the one being used.
-		/// </summary>
-		/// <returns>
-		/// A <see cref="Gtk.Widget"/>
-		/// </returns>
-		Gtk.Widget GetPreferencesWidget ();
-
-#endregion // Methods
+		void Cleanup ();
+		#endregion // Methods
 	}
 }
diff --git a/src/libtasque/IBackendPreferences.cs b/src/libtasque/IBackendPreferences.cs
new file mode 100644
index 0000000..1f1a236
--- /dev/null
+++ b/src/libtasque/IBackendPreferences.cs
@@ -0,0 +1,32 @@
+// 
+// IBackendPreferences.cs
+//  
+// Author:
+//       Antonius Riha <antoniusriha gmail com>
+// 
+// Copyright (c) 2012 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.Backends
+{
+	public interface IBackendPreferences
+	{
+	}
+}
diff --git a/src/libtasque/libtasque.csproj b/src/libtasque/libtasque.csproj
index 2ef9f6f..1dc2c11 100644
--- a/src/libtasque/libtasque.csproj
+++ b/src/libtasque/libtasque.csproj
@@ -70,6 +70,7 @@
     <Compile Include="..\..\build\CommonAssemblyInfo.cs">
       <Link>Properties\CommonAssemblyInfo.cs</Link>
     </Compile>
+    <Compile Include="IBackendPreferences.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="DateFormatters\" />



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