[tasque] Make IBackend IDisposable



commit 771f67311e2c0aecdeb0ee70b62d4db63031b84d
Author: Antonius Riha <antoniusriha gmail com>
Date:   Sat Jan 5 13:22:59 2013 +0100

    Make IBackend IDisposable
    
    Cleanup () -> Dispose ()

 src/Addins/Backends/Dummy/DummyBackend.cs   |    3 +--
 src/Addins/Backends/Rtm/RtmBackend.cs       |    8 +++++++-
 src/Addins/Backends/Sqlite/SqliteBackend.cs |   10 ++++++++--
 src/Gtk.Tasque/PreferencesDialog.cs         |    2 +-
 src/libtasque/IBackend.cs                   |    7 +------
 src/libtasque/NativeApplication.cs          |    6 +++---
 6 files changed, 21 insertions(+), 15 deletions(-)
---
diff --git a/src/Addins/Backends/Dummy/DummyBackend.cs b/src/Addins/Backends/Dummy/DummyBackend.cs
index b0ef031..0b2ac3f 100644
--- a/src/Addins/Backends/Dummy/DummyBackend.cs
+++ b/src/Addins/Backends/Dummy/DummyBackend.cs
@@ -232,8 +232,7 @@ namespace Tasque.Backends.Dummy
 			}		
 		}
 
-		public void Cleanup()
-		{}
+		public void Dispose () {}
 		
 		public IBackendPreferences Preferences
 		{
diff --git a/src/Addins/Backends/Rtm/RtmBackend.cs b/src/Addins/Backends/Rtm/RtmBackend.cs
index 25f5395..bea2612 100644
--- a/src/Addins/Backends/Rtm/RtmBackend.cs
+++ b/src/Addins/Backends/Rtm/RtmBackend.cs
@@ -177,13 +177,17 @@ namespace Tasque.Backends.Rtm
 				BackendInitialized ();
 		}
 
-		public void Cleanup ()
+		public void Dispose ()
 		{
+			if (disposed)
+				return;
+
 			tasks.Clear ();
 			categories.Clear ();
 
 			rtm = null;
 			Initialized = false;
+			disposed = true;
 		}
 
 		public event BackendInitializedHandler BackendInitialized;
@@ -502,6 +506,8 @@ namespace Tasque.Backends.Rtm
 		string frob;
 		RtmNet.Auth rtmAuth;
 		string timeline;
+
+		bool disposed;
 		#endregion
 	}
 }
diff --git a/src/Addins/Backends/Sqlite/SqliteBackend.cs b/src/Addins/Backends/Sqlite/SqliteBackend.cs
index 25f7e21..ea3ac97 100644
--- a/src/Addins/Backends/Sqlite/SqliteBackend.cs
+++ b/src/Addins/Backends/Sqlite/SqliteBackend.cs
@@ -153,15 +153,19 @@ namespace Tasque.Backends.Sqlite
 			}		
 		}
 
-		public void Cleanup()
+		public void Dispose()
 		{
+			if (disposed)
+				return;
+
 			this.categoryListStore.Clear();
 			this.taskStore.Clear();
 
 			if (db != null)
 				db.Close();
 			db = null;
-			initialized = false;		
+			initialized = false;
+			disposed = true;
 		}
 
 		/// <summary>
@@ -293,5 +297,7 @@ namespace Tasque.Backends.Sqlite
 		
 		#region Event Handlers
 		#endregion // Event Handlers
+
+		bool disposed;
 	}
 }
diff --git a/src/Gtk.Tasque/PreferencesDialog.cs b/src/Gtk.Tasque/PreferencesDialog.cs
index 0d54b03..491180f 100644
--- a/src/Gtk.Tasque/PreferencesDialog.cs
+++ b/src/Gtk.Tasque/PreferencesDialog.cs
@@ -440,7 +440,7 @@ namespace Tasque
 					IBackend oldBackend = backendComboMap [selectedBackend];
 					Logger.Info ("Cleaning up '{0}'...", oldBackend.Name);
 					try {
-						oldBackend.Cleanup ();
+						oldBackend.Dispose ();
 					} catch (Exception e) {
 						Logger.Warn ("Exception cleaning up '{0}': {2}",
 									 oldBackend.Name,
diff --git a/src/libtasque/IBackend.cs b/src/libtasque/IBackend.cs
index 1a35014..e8ab0d3 100644
--- a/src/libtasque/IBackend.cs
+++ b/src/libtasque/IBackend.cs
@@ -14,7 +14,7 @@ namespace Tasque.Backends
 	/// This is the main integration interface for different backends that
 	/// Tasque can use.
 	/// </summary>
-	public interface IBackend
+	public interface IBackend : IDisposable
 	{
 		event BackendInitializedHandler BackendInitialized;
 		event BackendSyncStartedHandler BackendSyncStarted;
@@ -97,11 +97,6 @@ namespace Tasque.Backends
 		/// Initializes the backend
 		/// </summary>
 		void Initialize (IPreferences preferences);
-
-		/// <summary>
-		/// Cleanup the backend before quitting
-		/// </summary>
-		void Cleanup ();
 		#endregion // Methods
 	}
 }
diff --git a/src/libtasque/NativeApplication.cs b/src/libtasque/NativeApplication.cs
index a93b36a..ab8bf2b 100644
--- a/src/libtasque/NativeApplication.cs
+++ b/src/libtasque/NativeApplication.cs
@@ -110,7 +110,7 @@ namespace Tasque
 			Logger.Info ("Exit called - terminating application");
 
 			if (backend != null)
-				backend.Cleanup ();
+				backend.Dispose ();
 
 			OnExit (exitcode);
 			if (Exiting != null)
@@ -152,7 +152,7 @@ namespace Tasque
 				// Cleanup the old backend
 				try {
 					Logger.Debug ("Cleaning up backend: {0}", backend.Name);
-					backend.Cleanup ();
+					backend.Dispose ();
 				} catch (Exception e) {
 					Logger.Warn ("Exception cleaning up '{0}': {1}", backend.Name, e);
 				}
@@ -204,7 +204,7 @@ namespace Tasque
 		{
 			try {
 				if (backend != null && !backend.Configured) {
-					backend.Cleanup ();
+					backend.Dispose ();
 					backend.Initialize (preferences);
 				}
 			} catch (Exception e) {



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