tasque r36 - in branches/cache: . src src/Backends/Rtm



Author: calvinrg
Date: Tue Mar 18 20:55:37 2008
New Revision: 36
URL: http://svn.gnome.org/viewvc/tasque?rev=36&view=rev

Log:
* tasque.mdp, src/LocalCache.cs, src/IBackend.cs, src/Application.cs,
  src/Backends/Rtm/RtmBackend.cs, src/SyncManager.cs,
  src/TaskWindow.cs, src/Makefile.am: Created SyncManager and removed
  threading from RtmBackend

Added:
   branches/cache/src/SyncManager.cs
Modified:
   branches/cache/ChangeLog
   branches/cache/src/Application.cs
   branches/cache/src/Backends/Rtm/RtmBackend.cs
   branches/cache/src/IBackend.cs
   branches/cache/src/LocalCache.cs
   branches/cache/src/Makefile.am
   branches/cache/src/TaskWindow.cs
   branches/cache/tasque.mdp

Modified: branches/cache/src/Application.cs
==============================================================================
--- branches/cache/src/Application.cs	(original)
+++ branches/cache/src/Application.cs	Tue Mar 18 20:55:37 2008
@@ -61,6 +61,7 @@
 		private Preferences preferences;
 		private EventBox eb;
 		private IBackend backend;
+		private SyncManager syncManager;
 		private PreferencesDialog preferencesDialog;
 		private LocalCache localCache;
 		
@@ -162,6 +163,8 @@
 							args);
 
 			preferences = new Preferences();
+
+			syncManager = new SyncManager();
 			
 			// Register Tasque RemoteControl
 			try {
@@ -327,7 +330,9 @@
 			}
 
 			TaskWindow.ShowWindow();
-			
+
+			syncManager.Start();
+
 			return false;
 		}
 
@@ -429,6 +434,9 @@
 		{
 			Logger.Info ("OnQuitAction called - terminating application");
 
+			if(syncManager != null)
+				syncManager.Stop();
+			
 			if (backend != null) {
 				backend.Cleanup();
 			}
@@ -439,10 +447,8 @@
 		
 		private void OnRefreshAction (object sender, EventArgs args)
 		{
-			Application.Backend.Refresh();
+			syncManager.Sync();
 		}
-		
-		
 
 		private void OnTrayIconClick (object o, ButtonPressEventArgs args) // handler for mouse click
 		{
@@ -456,14 +462,14 @@
 					(Catalog.GetString ("Show Tasks ..."));
 
 				showTasksItem.Image = new Gtk.Image(Utilities.GetIcon ("tasque-16", 16));
-				showTasksItem.Sensitive = backend != null && backend.Initialized;
+				showTasksItem.Sensitive = true;
 				showTasksItem.Activated += OnShowTaskWindow;
 				popupMenu.Add (showTasksItem);
 				
 				ImageMenuItem newTaskItem = new ImageMenuItem
 					(Catalog.GetString ("New Task ..."));
 				newTaskItem.Image = new Gtk.Image (Gtk.Stock.New, IconSize.Menu);
-				newTaskItem.Sensitive = backend != null && backend.Initialized;
+				newTaskItem.Sensitive = true;
 				newTaskItem.Activated += OnNewTask;
 				popupMenu.Add (newTaskItem);
 
@@ -485,7 +491,7 @@
 					(Catalog.GetString ("Refresh Tasks"));
 
 				refreshAction.Image = new Gtk.Image(Utilities.GetIcon (Gtk.Stock.Execute, 16));
-				refreshAction.Sensitive = backend != null && backend.Initialized;
+				refreshAction.Sensitive = true;
 				refreshAction.Activated += OnRefreshAction;
 				popupMenu.Add (refreshAction);
 				

Modified: branches/cache/src/Backends/Rtm/RtmBackend.cs
==============================================================================
--- branches/cache/src/Backends/Rtm/RtmBackend.cs	(original)
+++ branches/cache/src/Backends/Rtm/RtmBackend.cs	Tue Mar 18 20:55:37 2008
@@ -23,10 +23,6 @@
 		private Gtk.ListStore categoryListStore;
 		private Gtk.TreeModelSort sortedCategoriesModel;
 		
-		private Thread refreshThread;
-		private bool runningRefreshThread;
-		private AutoResetEvent runRefreshEvent;
-
 		private Rtm rtm;
 		private string frob;
 		private Auth rtmAuth;
@@ -40,10 +36,6 @@
 		private bool initialized;
 		private bool configured;
 
-		public event BackendInitializedHandler BackendInitialized;
-		public event BackendSyncStartedHandler BackendSyncStarted;
-		public event BackendSyncFinishedHandler BackendSyncFinished;
-		
 		public RtmBackend ()
 		{
 			initialized = false;
@@ -77,10 +69,6 @@
 				categoryListStore.SetValue (iter, 0, allCategory);				
 			});
 
-			runRefreshEvent = new AutoResetEvent(false);
-			
-			runningRefreshThread = false;
-			refreshThread  = new Thread(RefreshThreadLoop);
 		}
 
 		#region Public Properties
@@ -193,11 +181,12 @@
 		
 		public void Refresh()
 		{
-			Logger.Debug("Refreshing data...");
+			Logger.Debug("RtmBackend Refreshing data...");
 
-			runRefreshEvent.Set();
-			
-			Logger.Debug("Done refreshing data!");
+			UpdateCategories();			
+			UpdateTasks();
+
+			Logger.Debug("RtmBackend refreshing data!");
 		}
 
 		public void Initialize()
@@ -229,20 +218,11 @@
 			if(rtm == null)
 				rtm = new Rtm(apiKey, sharedSecret);
 			
-			runningRefreshThread = true;
-			if (refreshThread.ThreadState == ThreadState.Running) {
-				Logger.Debug ("RtmBackend refreshThread already running");
-			} else {
-				refreshThread.Start();
-			}
-			runRefreshEvent.Set();		
+			initialized = true;
 		}
 
 		public void Cleanup()
 		{
-			runningRefreshThread = false;
-			runRefreshEvent.Set();
-			refreshThread.Abort ();
 		}
 
 		public Gtk.Widget GetPreferencesWidget ()
@@ -280,7 +260,7 @@
 					Logger.Debug("RTM Auth Token is valid!");
 					Logger.Debug("Setting configured status to true");
 					configured = true;
-					Refresh();
+//					Refresh();
 				} catch (Exception e) {
 					rtm = null;
 					rtmAuth = null;				
@@ -612,46 +592,7 @@
 			}
 			Logger.Debug("RtmBackend.UpdateTasks is done");			
 		}
-		
-		
-		
-		private void RefreshThreadLoop()
-		{
-			while(runningRefreshThread) {
-				runRefreshEvent.WaitOne();
 
-				if(!runningRefreshThread)
-					return;
-
-				// Fire the event on the main thread
-				Gtk.Application.Invoke ( delegate {
-					if(BackendSyncStarted != null)
-						BackendSyncStarted();
-				});
-
-				runRefreshEvent.Reset();
-
-				if(rtmAuth != null) {
-					UpdateCategories();			
-					UpdateTasks();
-				}
-				if(!initialized) {
-					initialized = true;
-
-					// Fire the event on the main thread
-					Gtk.Application.Invoke ( delegate {
-						if(BackendInitialized != null)
-							BackendInitialized();
-					});
-				}
-
-				// Fire the event on the main thread
-				Gtk.Application.Invoke ( delegate {
-					if(BackendSyncFinished != null)
-						BackendSyncFinished();
-				});
-			}
-		}
 		
 #endregion // Private Methods
 

Modified: branches/cache/src/IBackend.cs
==============================================================================
--- branches/cache/src/IBackend.cs	(original)
+++ branches/cache/src/IBackend.cs	Tue Mar 18 20:55:37 2008
@@ -5,20 +5,12 @@
 
 namespace Tasque.Backends
 {
-	public delegate void BackendInitializedHandler ();
-	public delegate void BackendSyncStartedHandler ();
-	public delegate void BackendSyncFinishedHandler ();
-	
 	/// <summary>
 	/// This is the main integration interface for different backends that
 	/// Tasque can use.
 	/// </summary>
 	public interface IBackend
 	{
-		event BackendInitializedHandler BackendInitialized;
-		event BackendSyncStartedHandler BackendSyncStarted;
-		event BackendSyncFinishedHandler BackendSyncFinished;
-
 		#region Properties
 		/// <value>
 		/// A human-readable name for the backend that will be displayed in the

Modified: branches/cache/src/LocalCache.cs
==============================================================================
--- branches/cache/src/LocalCache.cs	(original)
+++ branches/cache/src/LocalCache.cs	Tue Mar 18 20:55:37 2008
@@ -23,10 +23,6 @@
 		private Gtk.ListStore categoryListStore;
 		private Gtk.TreeModelSort sortedCategoriesModel;
 
-		public event BackendInitializedHandler BackendInitialized;
-		public event BackendSyncStartedHandler BackendSyncStarted;
-		public event BackendSyncFinishedHandler BackendSyncFinished;
-
 		private DateTime overdueRangeStart;
 		private DateTime overdueRangeEnd;
 
@@ -156,11 +152,7 @@
 			RefreshCategories();
 			RefreshTasks();		
 
-		
 			initialized = true;
-			if(BackendInitialized != null) {
-				BackendInitialized();
-			}		
 		}
 
 		public void Cleanup()

Modified: branches/cache/src/Makefile.am
==============================================================================
--- branches/cache/src/Makefile.am	(original)
+++ branches/cache/src/Makefile.am	Tue Mar 18 20:55:37 2008
@@ -59,6 +59,7 @@
 	$(srcdir)/PreferencesDialog.cs \
 	$(srcdir)/RemoteControl.cs \
 	$(srcdir)/RemoteControlProxy.cs \
+	$(srcdir)/SyncManager.cs \
 	$(srcdir)/Task.cs \
 	$(srcdir)/TaskCalendar.cs \
 	$(srcdir)/TaskGroup.cs \

Added: branches/cache/src/SyncManager.cs
==============================================================================
--- (empty file)
+++ branches/cache/src/SyncManager.cs	Tue Mar 18 20:55:37 2008
@@ -0,0 +1,78 @@
+// SyncManager.cs created with MonoDevelop
+// User: calvin at 12:23 PMÂ3/18/2008
+//
+// To change standard headers go to Edit->Preferences->Coding->Standard Headers
+//
+
+using System;
+using System.Threading;
+using System.Collections.Generic;
+
+namespace Tasque
+{
+	public class SyncManager
+	{
+		
+		private Thread syncThread;
+		private bool runningSyncThread;
+		private AutoResetEvent runSyncEvent;
+		
+		
+		public SyncManager()
+		{
+			runSyncEvent = new AutoResetEvent(false);
+			
+			runningSyncThread = false;
+			syncThread  = new Thread(SyncThreadLoop);
+			
+		}
+
+		public void Sync()
+		{
+			runSyncEvent.Set();
+		}		
+
+		public void Start()
+		{
+			runningSyncThread = true;
+			syncThread.Start();
+		}
+
+		public void Stop()
+		{
+			runningSyncThread = false;
+			runSyncEvent.Set();
+			syncThread.Abort();
+		}		
+
+		
+		private void SyncThreadLoop()
+		{
+			while(runningSyncThread) {
+				runSyncEvent.WaitOne();
+
+				if(!runningSyncThread)
+					return;
+
+				runSyncEvent.Reset();
+
+				Logger.Debug("SyncThreadLoop running...");
+
+				if( (Application.Backend != null) && 
+					(Application.Backend.Configured) &&
+					(Application.Backend.Initialized) )
+				{
+					// Refresh the tasks
+					Application.Backend.Refresh();
+
+					// Read Categories and populate them in the localCache
+					
+					// Read Tasks and populate them into the localCache
+				}
+			
+				Logger.Debug("SyncThreadLoop done!");
+			}
+		}
+		
+	}
+}

Modified: branches/cache/src/TaskWindow.cs
==============================================================================
--- branches/cache/src/TaskWindow.cs	(original)
+++ branches/cache/src/TaskWindow.cs	Tue Mar 18 20:55:37 2008
@@ -1085,15 +1085,10 @@
 		{		
 			//backend.BackendInitialized -= OnBackendInitialized;
 			PopulateWindow();
-			OnBackendSyncFinished (); // To update the statusbar
+//			OnBackendSyncFinished (); // To update the statusbar
 		}
 		
-		private void OnBackendSyncStarted ()
-		{
-			TaskWindow.ShowStatus (Catalog.GetString ("Reloading tasks..."));
-		}
-		
-		private void OnBackendSyncFinished ()
+/*		private void OnBackendSyncFinished ()
 		{
 			Logger.Debug("Backend sync finished");
 			string status =
@@ -1108,7 +1103,8 @@
 				addTaskEntry.ModifyText (Gtk.StateType.Normal, insensitiveColor);
 			//}
 		}
-		#endregion // Event Handlers
+*/
+#endregion // Event Handlers
 		
 		#region Private Classes
 		class CategoryMenuItem : Gtk.MenuItem

Modified: branches/cache/tasque.mdp
==============================================================================
--- branches/cache/tasque.mdp	(original)
+++ branches/cache/tasque.mdp	Tue Mar 18 20:55:37 2008
@@ -63,6 +63,7 @@
     <File name="src/LocalCache.cs" subtype="Code" buildaction="Compile" />
     <File name="src/Database.cs" subtype="Code" buildaction="Compile" />
     <File name="src/TaskModelNode.cs" subtype="Code" buildaction="Compile" />
+    <File name="src/SyncManager.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="glib-sharp, Version=2.10.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />



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