[tasque/transition: 61/213] Progress...



commit bfe761e2c37e1e78db6c10aa7fde92c6e5b6a019
Author: Antonius Riha <antoniusriha gmail com>
Date:   Tue Jun 19 16:37:01 2012 +0200

    Progress...

 src/libtasque/IBackend.cs                   |   27 +++--
 src/libtasque/ITask.cs                      |   44 +++-----
 src/tasque/Application.cs                   |    6 +-
 src/tasque/Backends/Dummy/DummyBackend.cs   |  163 +++++++++++----------------
 src/tasque/Backends/Hiveminder/HmBackend.cs |    2 +-
 src/tasque/Backends/Rtm/RtmBackend.cs       |    2 +-
 src/tasque/Backends/Sqlite/SqliteBackend.cs |    2 +-
 src/tasque/CompletedTaskGroup.cs            |   35 ++----
 src/tasque/CompletedTaskGroupModel.cs       |    6 +-
 src/tasque/RemoteControl.cs                 |   42 ++-----
 src/tasque/TaskGroup.cs                     |   41 +++----
 src/tasque/TaskGroupModel.cs                |   21 ++--
 src/tasque/TaskGroupModelFactory.cs         |    8 +-
 src/tasque/TaskWindow.cs                    |   41 +------
 src/tasque/TreeViewModelImplementor.cs      |   35 ++++--
 src/tasque/tasque.csproj                    |   40 ++++----
 16 files changed, 212 insertions(+), 303 deletions(-)
---
diff --git a/src/libtasque/IBackend.cs b/src/libtasque/IBackend.cs
index d6df7b8..e41b885 100644
--- a/src/libtasque/IBackend.cs
+++ b/src/libtasque/IBackend.cs
@@ -2,6 +2,8 @@
 // User: boyd at 7:02 AMÂ2/11/2008
 
 using System;
+using System.Collections.ObjectModel;
+using System.Collections.Generic;
 
 namespace Tasque.Backends
 {
@@ -25,24 +27,25 @@ namespace Tasque.Backends
 		/// preferences dialog to allow the user to select which backend Tasque
 		/// should use.
 		/// </value>
-		string Name
-		{
+		string Name {
 			get;
 		}
 		
 		/// <value>
 		/// All the tasks provided by the backend.
 		/// </value>
-		Gtk.TreeModel Tasks
-		{
+		ObservableCollection<ITask> Tasks {
+			get;
+		}
+
+		IEnumerable<ITask> SortedTasks {
 			get;
 		}
 		
 		/// <value>
 		/// This returns all the ICategory items from the backend.
 		/// </value>
-		Gtk.TreeModel Categories
-		{
+		Gtk.TreeModel Categories {
 			get;
 		}
 		
@@ -51,16 +54,14 @@ namespace Tasque.Backends
 		/// (credentials/etc.) to run.  If false, the properties dialog will
 		/// be shown so the user can configure the backend.
 		/// </value>
-		bool Configured
-		{
+		bool Configured {
 			get;
 		}
 		
 		/// <value>
 		/// Inidication that the backend is initialized
 		/// </value>
-		bool Initialized
-		{
+		bool Initialized {
 			get;
 		}
 		#endregion // Properties
@@ -82,17 +83,17 @@ namespace Tasque.Backends
 		/// <summary>
 		/// Refreshes the backend.
 		/// </summary>
-		void Refresh();
+		void Refresh ();
 		
 		/// <summary>
 		/// Initializes the backend
 		/// </summary>
-		void Initialize();
+		void Initialize ();
 
 		/// <summary>
 		/// Cleanup the backend before quitting
 		/// </summary>
-		void Cleanup();
+		void Cleanup ();
 		
 		/// <summary>
 		/// A widget that will be placed into the Preferences Dialog when the
diff --git a/src/libtasque/ITask.cs b/src/libtasque/ITask.cs
index aeef9c1..852c263 100644
--- a/src/libtasque/ITask.cs
+++ b/src/libtasque/ITask.cs
@@ -6,22 +6,20 @@ using System.Collections.Generic;
 
 namespace Tasque
 {
-	public interface ITask
+	public interface ITask : IComparable<ITask>
 	{
 		#region Properties
 		/// <value>
 		/// A unique identifier for the task
 		/// </value>
-		string Id
-		{
+		string Id {
 			get; 
 		}
 
 		/// <value>
 		/// A Task's Name will be used to show the task in the main list window.
 		/// </value>
-		string Name
-		{
+		string Name {
 			get;
 			set;
 		}
@@ -29,8 +27,7 @@ namespace Tasque
 		/// <value>
 		/// A DueDate of DateTime.MinValue indicates that a due date is not set.
 		/// </value>
-		DateTime DueDate
-		{
+		DateTime DueDate {
 			get;
 			set;
 		}
@@ -38,8 +35,7 @@ namespace Tasque
 		/// <value>
 		/// If set to CompletionDate.MinValue, the task has not been completed.
 		/// </value>
-		DateTime CompletionDate
-		{
+		DateTime CompletionDate {
 			get;
 			set;
 		}
@@ -48,8 +44,7 @@ namespace Tasque
 		/// This is a convenience property which should use the CompletionDate
 		/// to determine whether a task is completed.
 		/// </value>
-		bool IsComplete 
-		{
+		bool IsComplete {
 			get;
 		}
 		
@@ -57,8 +52,7 @@ namespace Tasque
 		/// Backends should, by default, set the priority of a task to
 		/// TaskPriority.None.
 		/// </value>
-		TaskPriority Priority
-		{
+		TaskPriority Priority {
 			get;
 			set;
 		}
@@ -67,16 +61,14 @@ namespace Tasque
 		/// Indicates whether any notes exist in this task.  If a backend does
 		/// not support notes, it should always return false.
 		/// </value>
-		bool HasNotes
-		{
+		bool HasNotes {
 			get;
 		}
 		
 		/// <value>
 		/// Should be true if the task supports having multiple notes.
 		/// </value>
-		bool SupportsMultipleNotes
-		{
+		bool SupportsMultipleNotes {
 			get;
 		}
 		
@@ -84,16 +76,14 @@ namespace Tasque
 		/// The state of the task.  Note: sreeves' LOVES source code comments
 		/// like these.
 		/// </value>
-		TaskState State
-		{
+		TaskState State {
 			get;
 		}
 		
 		/// <value>
 		/// The category to which this task belongs
 		/// </value>
-		ICategory Category
-		{
+		ICategory Category {
 			get; 
 			set;
 		}
@@ -101,8 +91,7 @@ namespace Tasque
 		/// <value>
 		/// The notes associated with this task
 		/// </value>
-		List<INote> Notes
-		{
+		List<INote> Notes {
 			get;
 		}
 		
@@ -110,8 +99,7 @@ namespace Tasque
 		/// The ID of the timer used to complete a task after being marked
 		/// inactive.
 		/// </value>
-		uint TimerID
-		{
+		uint TimerID {
 			get;
 			set;
 		}	
@@ -143,17 +131,17 @@ namespace Tasque
 		/// <summary>
 		/// Creates a new note on this task
 		/// </summary>
-		INote CreateNote(string text);
+		INote CreateNote (string text);
 		
 		/// <summary>
 		/// Removes a note from this task
 		/// </summary>
-		void DeleteNote(INote note);
+		void DeleteNote (INote note);
 		
 		/// <summary>
 		/// Updates an exising note on the task
 		/// </summary>
-		void SaveNote(INote note);
+		void SaveNote (INote note);
 		
 		/// <summary>
 		/// This is used for sorting tasks in the TaskWindow and should compare
diff --git a/src/tasque/Application.cs b/src/tasque/Application.cs
index 68fc577..652c560 100644
--- a/src/tasque/Application.cs
+++ b/src/tasque/Application.cs
@@ -478,9 +478,9 @@ namespace Tasque
 				return;
 			}
 
-			overdue_tasks = TaskGroupModelFactory.CreateOverdueModel (backend.Tasks);
-			today_tasks = TaskGroupModelFactory.CreateTodayModel (backend.Tasks);
-			tomorrow_tasks = TaskGroupModelFactory.CreateTomorrowModel (backend.Tasks);
+			overdue_tasks = TaskGroupModelFactory.CreateOverdueModel (backend.SortedTasks);
+			today_tasks = TaskGroupModelFactory.CreateTodayModel (backend.SortedTasks);
+			tomorrow_tasks = TaskGroupModelFactory.CreateTomorrowModel (backend.SortedTasks);
 
 			foreach (TaskGroupModel model in new TaskGroupModel[] { overdue_tasks, today_tasks, tomorrow_tasks })
 			{
diff --git a/src/tasque/Backends/Dummy/DummyBackend.cs b/src/tasque/Backends/Dummy/DummyBackend.cs
index 18bf150..ac62241 100644
--- a/src/tasque/Backends/Dummy/DummyBackend.cs
+++ b/src/tasque/Backends/Dummy/DummyBackend.cs
@@ -5,6 +5,8 @@ using System;
 using System.Collections.Generic;
 using Mono.Unix;
 using Tasque.Backends;
+using System.Collections.ObjectModel;
+using System.Linq;
 
 namespace Tasque.Backends.Dummy
 {
@@ -19,8 +21,6 @@ namespace Tasque.Backends.Dummy
 		/// </summary>
 		private Dictionary<int, Gtk.TreeIter> taskIters;
 		private int newTaskId;
-		private Gtk.TreeStore taskStore;
-		private Gtk.TreeModelSort sortedTasksModel;
 		private bool initialized;
 		private bool configured = true;
 		
@@ -40,13 +40,9 @@ namespace Tasque.Backends.Dummy
 			initialized = false;
 			newTaskId = 0;
 			taskIters = new Dictionary<int, Gtk.TreeIter> (); 
-			taskStore = new Gtk.TreeStore (typeof (ITask));
+			Tasks = new ObservableCollection<ITask> ();
 			
-			sortedTasksModel = new Gtk.TreeModelSort (taskStore);
-			sortedTasksModel.SetSortFunc (0, new Gtk.TreeIterCompareFunc (CompareTasksSortFunc));
-			sortedTasksModel.SetSortColumnId (0, Gtk.SortType.Ascending);
-			
-			categoryListStore = new Gtk.ListStore (typeof (ICategory));
+			categoryListStore = new Gtk.ListStore (typeof(ICategory));
 			
 			sortedCategoriesModel = new Gtk.TreeModelSort (categoryListStore);
 			sortedCategoriesModel.SetSortFunc (0, new Gtk.TreeIterCompareFunc (CompareCategorySortFunc));
@@ -54,46 +50,43 @@ namespace Tasque.Backends.Dummy
 		}
 		
 		#region Public Properties
-		public string Name
-		{
+		public string Name {
 			get { return "Debugging System"; }
 		}
 		
 		/// <value>
 		/// All the tasks including ITaskDivider items.
 		/// </value>
-		public Gtk.TreeModel Tasks
-		{
-			get { return sortedTasksModel; }
+		public IEnumerable<ITask> SortedTasks {
+			get { return Tasks.OrderBy (t => t, Comparer<ITask>.Default); }
 		}
+
+		public ObservableCollection<ITask> Tasks { get; private set; }
 		
 		/// <value>
 		/// This returns all the task lists (categories) that exist.
 		/// </value>
-		public Gtk.TreeModel Categories
-		{
+		public Gtk.TreeModel Categories {
 			get { return sortedCategoriesModel; }
 		}
 		
 		/// <value>
 		/// Indication that the dummy backend is configured
 		/// </value>
-		public bool Configured 
-		{
+		public bool Configured {
 			get { return configured; }
 		}
 		
 		/// <value>
 		/// Inidication that the backend is initialized
 		/// </value>
-		public bool Initialized
-		{
+		public bool Initialized {
 			get { return initialized; }
 		}		
 		#endregion // Public Properties
 		
 		#region Public Methods
-		public ITask CreateTask (string taskName, ICategory category)		
+		public ITask CreateTask (string taskName, ICategory category)
 		{
 			// not sure what to do here with the category
 			DummyTask task = new DummyTask (this, newTaskId, taskName);
@@ -103,22 +96,22 @@ namespace Tasque.Backends.Dummy
 				task.Category = workCategory; // Default to work
 			else
 				task.Category = category;
-			
-			Gtk.TreeIter iter = taskStore.AppendNode ();
-			taskStore.SetValue (iter, 0, task);
-			taskIters [newTaskId] = iter;
+
+			Tasks.Add (task);
 			newTaskId++;
 			
 			return task;
 		}
 		
-		public void DeleteTask(ITask task)
-		{}
+		public void DeleteTask (ITask task)
+		{
+		}
 		
-		public void Refresh()
-		{}
+		public void Refresh ()
+		{
+		}
 		
-		public void Initialize()
+		public void Initialize ()
 		{
 			Gtk.TreeIter iter;
 			
@@ -152,9 +145,7 @@ namespace Tasque.Backends.Dummy
 			task.Category = projectsCategory;
 			task.DueDate = DateTime.Now.AddDays (1);
 			task.Priority = TaskPriority.Medium;
-			iter = taskStore.AppendNode ();
-			taskStore.SetValue (iter, 0, task);
-			taskIters [newTaskId] = iter;
+			Tasks.Add (task);
 			newTaskId++;
 			
 			task = new DummyTask (this, newTaskId, "Call Roger");
@@ -162,79 +153,61 @@ namespace Tasque.Backends.Dummy
 			task.DueDate = DateTime.Now.AddDays (-1);
 			task.Complete ();
 			task.CompletionDate = task.DueDate;
-			iter = taskStore.AppendNode ();
-			taskStore.SetValue (iter, 0, task);
-			taskIters [newTaskId] = iter;
+			Tasks.Add (task);
 			newTaskId++;
 			
 			task = new DummyTask (this, newTaskId, "Replace burnt out lightbulb");
 			task.Category = homeCategory;
 			task.DueDate = DateTime.Now;
 			task.Priority = TaskPriority.Low;
-			iter = taskStore.AppendNode ();
-			taskStore.SetValue (iter, 0, task);
-			taskIters [newTaskId] = iter;
+			Tasks.Add (task);
 			newTaskId++;
 			
 			task = new DummyTask (this, newTaskId, "File taxes");
 			task.Category = homeCategory;
 			task.DueDate = new DateTime (2008, 4, 1);
-			iter = taskStore.AppendNode ();
-			taskStore.SetValue (iter, 0, task);
-			taskIters [newTaskId] = iter;
+			Tasks.Add (task);
 			newTaskId++;
 			
 			task = new DummyTask (this, newTaskId, "Purchase lumber");
 			task.Category = projectsCategory;
 			task.DueDate = DateTime.Now.AddDays (1);
 			task.Priority = TaskPriority.High;
-			iter = taskStore.AppendNode ();
-			taskStore.SetValue (iter, 0, task);
-			taskIters [newTaskId] = iter;
+			Tasks.Add (task);
 			newTaskId++;
 						
 			task = new DummyTask (this, newTaskId, "Estimate drywall requirements");
 			task.Category = projectsCategory;
 			task.DueDate = DateTime.Now.AddDays (1);
 			task.Priority = TaskPriority.Low;
-			iter = taskStore.AppendNode ();
-			taskStore.SetValue (iter, 0, task);
-			taskIters [newTaskId] = iter;
+			Tasks.Add (task);
 			newTaskId++;
 			
 			task = new DummyTask (this, newTaskId, "Borrow framing nailer from Ben");
 			task.Category = projectsCategory;
 			task.DueDate = DateTime.Now.AddDays (1);
 			task.Priority = TaskPriority.High;
-			iter = taskStore.AppendNode ();
-			taskStore.SetValue (iter, 0, task);
-			taskIters [newTaskId] = iter;
+			Tasks.Add (task);
 			newTaskId++;
 			
 			task = new DummyTask (this, newTaskId, "Call for an insulation estimate");
 			task.Category = projectsCategory;
 			task.DueDate = DateTime.Now.AddDays (1);
 			task.Priority = TaskPriority.Medium;
-			iter = taskStore.AppendNode ();
-			taskStore.SetValue (iter, 0, task);
-			taskIters [newTaskId] = iter;
+			Tasks.Add (task);
 			newTaskId++;
 			
 			task = new DummyTask (this, newTaskId, "Pay storage rental fee");
 			task.Category = homeCategory;
 			task.DueDate = DateTime.Now.AddDays (1);
 			task.Priority = TaskPriority.None;
-			iter = taskStore.AppendNode ();
-			taskStore.SetValue (iter, 0, task);
-			taskIters [newTaskId] = iter;
+			Tasks.Add (task);
 			newTaskId++;
 			
 			task = new DummyTask (this, newTaskId, "Place carpet order");
 			task.Category = projectsCategory;
 			task.Priority = TaskPriority.None;
-			iter = taskStore.AppendNode ();
-			taskStore.SetValue (iter, 0, task);
-			taskIters [newTaskId] = iter;
+			Tasks.Add (task);
 			newTaskId++;
 			
 			task = new DummyTask (this, newTaskId, "Test task overdue");
@@ -242,19 +215,18 @@ namespace Tasque.Backends.Dummy
 			task.DueDate = DateTime.Now.AddDays (-89);
 			task.Priority = TaskPriority.None;
 			task.Complete ();
-			iter = taskStore.AppendNode ();
-			taskStore.SetValue (iter, 0, task);
-			taskIters [newTaskId] = iter;
+			Tasks.Add (task);
 			newTaskId++;
 			
 			initialized = true;
-			if(BackendInitialized != null) {
-				BackendInitialized();
+			if (BackendInitialized != null) {
+				BackendInitialized ();
 			}		
 		}
 
-		public void Cleanup()
-		{}
+		public void Cleanup ()
+		{
+		}
 		
 		public Gtk.Widget GetPreferencesWidget ()
 		{
@@ -265,19 +237,7 @@ namespace Tasque.Backends.Dummy
 		#endregion // Public Methods
 		
 		#region Private Methods
-		static int CompareTasksSortFunc (Gtk.TreeModel model,
-										 Gtk.TreeIter a,
-										 Gtk.TreeIter b)
-		{
-			ITask taskA = model.GetValue (a, 0) as ITask;
-			ITask taskB = model.GetValue (b, 0) as ITask;
-			
-			if (taskA == null || taskB == null)
-				return 0;
-			
-			return (taskA.CompareTo (taskB));
-		}
-		
+
 		static int CompareCategorySortFunc (Gtk.TreeModel model,
 											Gtk.TreeIter a,
 											Gtk.TreeIter b)
@@ -295,29 +255,40 @@ namespace Tasque.Backends.Dummy
 			
 			return (categoryA.Name.CompareTo (categoryB.Name));
 		}
-		
+
 		public void UpdateTask (DummyTask task)
 		{
-			// Set the task in the store so the model will update the UI.
-			Gtk.TreeIter iter;
-			
-			if (!taskIters.ContainsKey (task.DummyId))
+			if (!Tasks.Contains (task))
 				return;
-				
-			iter = taskIters [task.DummyId];
-			
+
 			if (task.State == TaskState.Deleted) {
-				taskIters.Remove (task.DummyId);
-				if (!taskStore.Remove (ref iter)) {
-					Logger.Debug ("Successfully deleted from taskStore: {0}",
-						task.Name);
-				} else {
-					Logger.Debug ("Problem removing from taskStore: {0}",
-						task.Name);
-				}
+				Tasks.Remove (task);
+				Logger.Debug ("Successfully deleted from taskStore: {0}", task.Name);
 			} else {
-				taskStore.SetValue (iter, 0, task);
+				// TODO: Notify UI
+				Logger.Debug ("The UI should be notified here.");
 			}
+
+			// Set the task in the store so the model will update the UI.
+//			Gtk.TreeIter iter;
+//			
+//			if (!taskIters.ContainsKey (task.DummyId))
+//				return;
+//				
+//			iter = taskIters [task.DummyId];
+//			
+//			if (task.State == TaskState.Deleted) {
+//				taskIters.Remove (task.DummyId);
+//				if (!taskStore.Remove (ref iter)) {
+//					Logger.Debug ("Successfully deleted from taskStore: {0}",
+//						task.Name);
+//				} else {
+//					Logger.Debug ("Problem removing from taskStore: {0}",
+//						task.Name);
+//				}
+//			} else {
+//				taskStore.SetValue (iter, 0, task);
+//			}
 		}
 		#endregion // Private Methods
 		
diff --git a/src/tasque/Backends/Hiveminder/HmBackend.cs b/src/tasque/Backends/Hiveminder/HmBackend.cs
index d791b03..d805613 100644
--- a/src/tasque/Backends/Hiveminder/HmBackend.cs
+++ b/src/tasque/Backends/Hiveminder/HmBackend.cs
@@ -113,7 +113,7 @@ namespace Tasque.Backends.HmBackend
 		/// <value>
 		/// All the tasks .
 		/// </value>
-		public Gtk.TreeModel Tasks
+		public Gtk.TreeModel SortedTasks
 		{
 			get { return sortedTasksModel; }
 		}
diff --git a/src/tasque/Backends/Rtm/RtmBackend.cs b/src/tasque/Backends/Rtm/RtmBackend.cs
index 98acec8..8348d2e 100644
--- a/src/tasque/Backends/Rtm/RtmBackend.cs
+++ b/src/tasque/Backends/Rtm/RtmBackend.cs
@@ -92,7 +92,7 @@ namespace Tasque.Backends.RtmBackend
 		/// <value>
 		/// All the tasks including ITaskDivider items.
 		/// </value>
-		public Gtk.TreeModel Tasks
+		public Gtk.TreeModel SortedTasks
 		{
 			get { return sortedTasksModel; }
 		}
diff --git a/src/tasque/Backends/Sqlite/SqliteBackend.cs b/src/tasque/Backends/Sqlite/SqliteBackend.cs
index f9da4f2..fd4d1a8 100644
--- a/src/tasque/Backends/Sqlite/SqliteBackend.cs
+++ b/src/tasque/Backends/Sqlite/SqliteBackend.cs
@@ -56,7 +56,7 @@ namespace Tasque.Backends.Sqlite
 		/// <value>
 		/// All the tasks including ITaskDivider items.
 		/// </value>
-		public Gtk.TreeModel Tasks
+		public Gtk.TreeModel SortedTasks
 		{
 			get { return sortedTasksModel; }
 		}
diff --git a/src/tasque/CompletedTaskGroup.cs b/src/tasque/CompletedTaskGroup.cs
index 9b0b0df..c663f29 100644
--- a/src/tasque/CompletedTaskGroup.cs
+++ b/src/tasque/CompletedTaskGroup.cs
@@ -7,6 +7,9 @@
 using System;
 using Gtk;
 using Mono.Unix;
+using System.Collections.ObjectModel;
+using System.Collections.Generic;
+using System.Linq;
 
 namespace Tasque
 {
@@ -26,9 +29,9 @@ namespace Tasque
 		ShowCompletedRange currentRange;
 		
 		public CompletedTaskGroup (string groupName, DateTime rangeStart,
-								   DateTime rangeEnd, Gtk.TreeModel tasks)
+								   DateTime rangeEnd, IEnumerable<ITask> tasks)
 			: base (groupName, rangeStart, rangeEnd,
-					new CompletedTasksSortModel(tasks))
+					tasks.OrderBy (f => f, new CompletedTasksComparer ()))
 		{
 			// Don't hide this group when it's empty because then the range
 			// slider won't appear and the user won't be able to customize the
@@ -77,7 +80,7 @@ namespace Tasque
 
 		protected override TaskGroupModel CreateModel (DateTime rangeStart,
 		                                               DateTime rangeEnd,
-		                                               TreeModel tasks)
+		                                               IEnumerable<ITask> tasks)
 		{
 			return new CompletedTaskGroupModel (rangeStart, rangeEnd, tasks);
 		}
@@ -205,35 +208,17 @@ namespace Tasque
 			this.TimeRangeStart = date;
 		}
 	}
-	
+
 	/// <summary>
 	/// The purpose of this class is to allow the CompletedTaskGroup to show
 	/// completed tasks in reverse order (i.e., most recently completed tasks
 	/// at the top of the list).
 	/// </summary>
-	class CompletedTasksSortModel : Gtk.TreeModelSort
+	class CompletedTasksComparer : Comparer<ITask>
 	{
-		public CompletedTasksSortModel (Gtk.TreeModel childModel)
-			: base (childModel)
+		public override int Compare (ITask x, ITask y)
 		{
-			SetSortFunc (0, new Gtk.TreeIterCompareFunc (CompareTasksSortFunc));
-			SetSortColumnId (0, Gtk.SortType.Descending);
-		}
-		
-		#region Private Methods
-		static int CompareTasksSortFunc (Gtk.TreeModel model,
-										 Gtk.TreeIter a,
-										 Gtk.TreeIter b)
-		{
-			ITask taskA = model.GetValue (a, 0) as ITask;
-			ITask taskB = model.GetValue (b, 0) as ITask;
-			
-			if (taskA == null || taskB == null)
-				return 0;
-			
-			// Reverse the logic with the '!' so it's in re
-			return (taskA.CompareToByCompletionDate (taskB));
+			return x.CompareToByCompletionDate (y);
 		}
-		#endregion // Private Methods
 	}
 }
diff --git a/src/tasque/CompletedTaskGroupModel.cs b/src/tasque/CompletedTaskGroupModel.cs
index 0db7cbe..3ecbf3a 100644
--- a/src/tasque/CompletedTaskGroupModel.cs
+++ b/src/tasque/CompletedTaskGroupModel.cs
@@ -1,12 +1,14 @@
 
 using System;
 using Gtk;
+using System.Collections.ObjectModel;
+using System.Collections.Generic;
 
 namespace Tasque
 {
 	public class CompletedTaskGroupModel : TaskGroupModel
 	{
-		public CompletedTaskGroupModel (DateTime rangeStart, DateTime rangeEnd, TreeModel tasks)
+		public CompletedTaskGroupModel (DateTime rangeStart, DateTime rangeEnd, IEnumerable<ITask> tasks)
 			: base (rangeStart, rangeEnd, tasks)
 		{
 		}
@@ -48,7 +50,7 @@ namespace Tasque
 			DateTime today = DateTime.Now;
 			
 			if (today.Year == task.CompletionDate.Year
-					&& today.DayOfYear == task.CompletionDate.DayOfYear)
+				&& today.DayOfYear == task.CompletionDate.DayOfYear)
 				return false;
 			
 			return true;
diff --git a/src/tasque/RemoteControl.cs b/src/tasque/RemoteControl.cs
index 54cf313..df51eab 100644
--- a/src/tasque/RemoteControl.cs
+++ b/src/tasque/RemoteControl.cs
@@ -6,6 +6,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Linq;
 
 using Mono.Unix; // for Catalog.GetString ()
 
@@ -198,24 +199,18 @@ namespace Tasque
 		/// </returns>
 		public string[] GetTaskIds ()
 		{
-			Gtk.TreeIter iter;
-			Gtk.TreeModel model;
-			
-			ITask task;
-			List<string> ids;
-			
-			ids = new List<string> ();
-			model = Application.Backend.Tasks;
-			
-			if (!model.GetIterFirst (out iter))
+			var model = Application.Backend.Tasks;
+
+			if (model == null)
 				return new string[0];
-				
-			do {
-				task = model.GetValue (iter, 0) as ITask;
+
+			List<string> ids = new List<string> ();
+			foreach (var task in model) {
 				ids.Add (task.Id);
-			} while (model.IterNext (ref iter));
-			
+			}
+
 			return ids.ToArray ();
+
 		}
 		
 		/// <summary>
@@ -483,22 +478,7 @@ namespace Tasque
 		/// </returns>
 		private ITask GetTaskById (string id)
 		{
-			Gtk.TreeIter  iter;
-			Gtk.TreeModel model;
-			
-			ITask task = null;
-			model = Application.Backend.Tasks;
-			
-			if (model.GetIterFirst (out iter)) {
-				do {
-					task = model.GetValue (iter, 0) as ITask;
-					if (task.Id.Equals (id)) {
-						return task;
-					}
-				} while (model.IterNext (ref iter));
-			}			
-			
-			return task;
+			return Application.Backend.Tasks.SingleOrDefault (f => f.Id == id);
 		}
 	}
 }
diff --git a/src/tasque/TaskGroup.cs b/src/tasque/TaskGroup.cs
index 73f143a..4228a5b 100644
--- a/src/tasque/TaskGroup.cs
+++ b/src/tasque/TaskGroup.cs
@@ -4,6 +4,8 @@
 using System;
 using Gdk;
 using Gtk;
+using System.Collections.ObjectModel;
+using System.Collections.Generic;
 
 namespace Tasque
 {
@@ -24,7 +26,7 @@ namespace Tasque
 		
 		#region Constructor
 		public TaskGroup (string groupName, DateTime rangeStart,
-						  DateTime rangeEnd, Gtk.TreeModel tasks)
+						  DateTime rangeEnd, IEnumerable<ITask> tasks)
 		{
 			hideWhenEmpty = true;
 						
@@ -100,13 +102,11 @@ namespace Tasque
 		#endregion // Events
 		
 		#region Public Properties
-		public string DisplayName
-		{
+		public string DisplayName {
 			get { return header.Text; }
 		}
 		
-		public int HeaderHeight
-		{
+		public int HeaderHeight {
 			get { return header.Requisition.Height; }
 		}
 		
@@ -114,8 +114,7 @@ namespace Tasque
 		/// Use this to set an Extra Widget.  The extra widget will be placed
 		/// on the right-hand side of the TaskGroup header.
 		/// </value>
-		public Gtk.Widget ExtraWidget
-		{
+		public Gtk.Widget ExtraWidget {
 			get { return extraWidget; }
 			set {
 				// Remove and destroy an existing extraWidget
@@ -142,8 +141,7 @@ namespace Tasque
 		/// range slider (HScale) widget can control how many completed tasks to
 		/// show.
 		/// </value>
-		public bool HideWhenEmpty
-		{
+		public bool HideWhenEmpty {
 			get { return hideWhenEmpty; }
 			set {
 				if (hideWhenEmpty == value)
@@ -156,8 +154,7 @@ namespace Tasque
 		/// <value>
 		/// Get and set the minimum date for the group
 		/// </value>
-		public DateTime TimeRangeStart
-		{
+		public DateTime TimeRangeStart {
 			get { return filteredTasks.TimeRangeStart; }
 			set {
 				if (value == filteredTasks.TimeRangeStart)
@@ -171,8 +168,7 @@ namespace Tasque
 		/// <value>
 		/// Get and set the maxiumum date for the group
 		/// </value>
-		public DateTime TimeRangeEnd
-		{
+		public DateTime TimeRangeEnd {
 			get { return filteredTasks.TimeRangeEnd; }
 			set {
 				if (value == filteredTasks.TimeRangeEnd)
@@ -183,8 +179,7 @@ namespace Tasque
 			}
 		}
 		
-		public Gtk.TreeView TreeView
-		{
+		public Gtk.TreeView TreeView {
 			get { return this.treeView; }
 		}
 		#endregion // Public Properties
@@ -234,9 +229,9 @@ namespace Tasque
 			return false;
 		}
 		
-		public int GetNChildren(Gtk.TreeIter iter)
+		public int GetNChildren (Gtk.TreeIter iter)
 		{
-			return treeView.Model.IterNChildren();
+			return treeView.Model.IterNChildren ();
 		}
 			
 		// Find the index within the tree
@@ -308,7 +303,7 @@ namespace Tasque
 				nameColumn.CellRenderers [0] as Gtk.CellRendererText;
 			path = treeView.Model.GetPath (iter);
 			
-			treeView.Model.IterNChildren();
+			treeView.Model.IterNChildren ();
 				
 			treeView.SetCursorOnCell (path, nameColumn, nameCellRendererText, true);
 		}
@@ -320,13 +315,13 @@ namespace Tasque
 			base.OnRealized ();
 			
 			if (treeView.GetNumberOfTasks () == 0
-					&& (!filteredTasks.ShowCompletedTasks || hideWhenEmpty))
+				&& (!filteredTasks.ShowCompletedTasks || hideWhenEmpty))
 				Hide ();
 			else
 				Show ();
 		}
 
-		protected override void OnStyleSet(Style previous_style)
+		protected override void OnStyleSet (Style previous_style)
 		{
 			base.OnStyleSet (previous_style);
 			header.Markup = GetHeaderMarkup (DisplayName);
@@ -334,7 +329,7 @@ namespace Tasque
 
 		protected virtual  TaskGroupModel CreateModel (DateTime rangeStart,
 		                                               DateTime rangeEnd,
-		                                               TreeModel tasks)
+		                                               IEnumerable<ITask> tasks)
 		{
 			return new TaskGroupModel (rangeStart, rangeEnd, tasks);
 		}
@@ -396,7 +391,7 @@ namespace Tasque
 			Gdk.Color fgColor;
 
 			using (Gtk.Style style = Gtk.Rc.GetStyle (this)) 
-				fgColor = style.Backgrounds [(int) StateType.Selected];
+				fgColor = style.Backgrounds [(int)StateType.Selected];
 
 			return Utilities.ColorGetHex (fgColor);
 		}
@@ -416,7 +411,7 @@ namespace Tasque
 			//Logger.Debug ("TaskGroup (\"{0}\").OnNumberOfTasksChanged ()", DisplayName);
 			// Check to see whether this group should be hidden or shown.
 			if (treeView.GetNumberOfTasks () == 0
-					&& (!filteredTasks.ShowCompletedTasks || hideWhenEmpty))
+				&& (!filteredTasks.ShowCompletedTasks || hideWhenEmpty))
 				Hide ();
 			else
 				Show ();
diff --git a/src/tasque/TaskGroupModel.cs b/src/tasque/TaskGroupModel.cs
index 0e8cdb1..4da66c1 100644
--- a/src/tasque/TaskGroupModel.cs
+++ b/src/tasque/TaskGroupModel.cs
@@ -1,14 +1,14 @@
 
 using System;
-
+using System.Collections.ObjectModel;
 using Gtk;
+using System.Collections.Generic;
 
 namespace Tasque
 {
 	public class TaskGroupModel : TreeModelFilter
 	{
-		public bool ShowCompletedTasks
-		{
+		public bool ShowCompletedTasks {
 			get { return showCompletedTasks; }
 			set {
 				showCompletedTasks = value;
@@ -16,18 +16,17 @@ namespace Tasque
 			}
 		}
 
-		public DateTime TimeRangeStart
-		{
+		public DateTime TimeRangeStart {
 			get { return timeRangeStart; }
 		}
 
-		public DateTime TimeRangeEnd
-		{
+		public DateTime TimeRangeEnd {
 			get { return timeRangeEnd; }
 		}
 		
 		public TaskGroupModel (DateTime rangeStart, DateTime rangeEnd,
-		                       Gtk.TreeModel tasks) : base (tasks, null)
+		                       IEnumerable<ITask> tasks)
+			: base (new TreeModelAdapter (new TreeViewModelImplementor<ITask> (tasks)), null)
 		{
 			this.timeRangeStart = rangeStart;
 			this.timeRangeEnd = rangeEnd;
@@ -43,8 +42,8 @@ namespace Tasque
 		}
 
 		/// <summary>
-	        /// Filter out tasks that don't fit within the group's date range
-	        /// </summary>
+		/// Filter out tasks that don't fit within the group's date range
+		/// </summary>
 		protected virtual bool FilterTasks (Gtk.TreeModel model, Gtk.TreeIter iter)
 		{
 			ITask task = model.GetValue (iter, 0) as ITask;
@@ -100,7 +99,7 @@ namespace Tasque
 		{
 			DateTime today = DateTime.Now;
 			if (today.Year != testDate.Year
-					|| today.DayOfYear != testDate.DayOfYear)
+				|| today.DayOfYear != testDate.DayOfYear)
 				return false;
 			
 			return true;
diff --git a/src/tasque/TaskGroupModelFactory.cs b/src/tasque/TaskGroupModelFactory.cs
index 61e5819..c0f4cec 100644
--- a/src/tasque/TaskGroupModelFactory.cs
+++ b/src/tasque/TaskGroupModelFactory.cs
@@ -2,12 +2,14 @@
 using System;
 
 using Gtk;
+using System.Collections.ObjectModel;
+using System.Collections.Generic;
 
 namespace Tasque
 {
 	public static class TaskGroupModelFactory
 	{
-		public static TaskGroupModel CreateTodayModel (TreeModel tasks)
+		public static TaskGroupModel CreateTodayModel (IEnumerable<ITask> tasks)
 		{
 			DateTime rangeStart = DateTime.Now;
 			rangeStart = new DateTime (rangeStart.Year, rangeStart.Month,
@@ -18,7 +20,7 @@ namespace Tasque
 			return new TaskGroupModel (rangeStart, rangeEnd, tasks);
 		}
 
-		public static TaskGroupModel CreateOverdueModel (TreeModel tasks)
+		public static TaskGroupModel CreateOverdueModel (IEnumerable<ITask> tasks)
 		{
 			DateTime rangeStart = DateTime.MinValue;
 			DateTime rangeEnd = DateTime.Now.AddDays (-1);
@@ -28,7 +30,7 @@ namespace Tasque
 			return new TaskGroupModel (rangeStart, rangeEnd, tasks);
 		}
 
-		public static TaskGroupModel CreateTomorrowModel (TreeModel tasks)
+		public static TaskGroupModel CreateTomorrowModel (IEnumerable<ITask> tasks)
 		{
 			DateTime rangeStart = DateTime.Now.AddDays (1);
 			rangeStart = new DateTime (rangeStart.Year, rangeStart.Month,
diff --git a/src/tasque/TaskWindow.cs b/src/tasque/TaskWindow.cs
index e9bc2ff..1b80947 100644
--- a/src/tasque/TaskWindow.cs
+++ b/src/tasque/TaskWindow.cs
@@ -256,7 +256,7 @@ namespace Tasque
 			
 			overdueGroup = new TaskGroup (Catalog.GetString ("Overdue"),
 										  rangeStart, rangeEnd,
-										  backend.Tasks);
+										  backend.SortedTasks);
 			overdueGroup.RowActivated += OnRowActivated;
 			overdueGroup.ButtonPressed += OnButtonPressed;
 			overdueGroup.Show ();
@@ -274,7 +274,7 @@ namespace Tasque
 									 rangeEnd.Day, 23, 59, 59);
 			todayGroup = new TaskGroup (Catalog.GetString ("Today"),
 										rangeStart, rangeEnd,
-										backend.Tasks);
+										backend.SortedTasks);
 			todayGroup.RowActivated += OnRowActivated;
 			todayGroup.ButtonPressed += OnButtonPressed;
 			todayGroup.Show ();
@@ -292,7 +292,7 @@ namespace Tasque
 									 rangeEnd.Day, 23, 59, 59);
 			tomorrowGroup = new TaskGroup (Catalog.GetString ("Tomorrow"),
 										   rangeStart, rangeEnd,
-										   backend.Tasks);
+										   backend.SortedTasks);
 			tomorrowGroup.RowActivated += OnRowActivated;
 			tomorrowGroup.ButtonPressed += OnButtonPressed;			
 			tomorrowGroup.Show ();
@@ -310,7 +310,7 @@ namespace Tasque
 									 rangeEnd.Day, 23, 59, 59);
 			nextSevenDaysGroup = new TaskGroup (Catalog.GetString ("Next 7 Days"),
 										   rangeStart, rangeEnd,
-										   backend.Tasks);
+										   backend.SortedTasks);
 			nextSevenDaysGroup.RowActivated += OnRowActivated;
 			nextSevenDaysGroup.ButtonPressed += OnButtonPressed;				
 			nextSevenDaysGroup.Show ();
@@ -326,7 +326,7 @@ namespace Tasque
 			rangeEnd = DateTime.MaxValue;
 			futureGroup = new TaskGroup (Catalog.GetString ("Future"),
 										 rangeStart, rangeEnd,
-										 backend.Tasks);
+										 backend.SortedTasks);
 			futureGroup.RowActivated += OnRowActivated;
 			futureGroup.ButtonPressed += OnButtonPressed;			
 			futureGroup.Show ();
@@ -341,7 +341,7 @@ namespace Tasque
 			completedTaskGroup = new CompletedTaskGroup (
 					Catalog.GetString ("Completed"),
 					rangeStart, rangeEnd,
-					backend.Tasks);
+					backend.SortedTasks);
 			completedTaskGroup.RowActivated += OnRowActivated;
 			completedTaskGroup.ButtonPressed += OnButtonPressed;
 			completedTaskGroup.Show ();
@@ -645,38 +645,11 @@ namespace Tasque
 				crt.Text =
 					string.Format ("{0} ({1})",
 								   category.Name,
-								   GetTaskCountInCategory (category));
+								   "HERE SHOULD BE THE TASK COUNT");
 			} else
 				crt.Text = "unknown";
 		}
 		
-		// TODO: Move this method into a property of ICategory.TaskCount
-		private int GetTaskCountInCategory (ICategory category)
-		{
-			// This is disgustingly inefficient, but, oh well
-			int count = 0;
-			
-			Gtk.TreeIter iter;
-			Gtk.TreeModel model = Application.Backend.Tasks;
-			
-			if (!model.GetIterFirst (out iter))
-				return 0;
-			
-			do {
-				ITask task = model.GetValue (iter, 0) as ITask;
-				if (task == null)
-					continue;
-				if (task.State != TaskState.Active
-						&& task.State != TaskState.Inactive)
-					continue;
-				
-				if (category.ContainsTask (task))
-					count++;
-			} while (model.IterNext (ref iter));
-			
-			return count;
-		}
-		
 		/// <summary>
 		/// Search through the TaskGroups looking for the specified task and:
 		/// 1) scroll the window to its location, 2) enter directly into edit
diff --git a/src/tasque/TreeViewModelImplementor.cs b/src/tasque/TreeViewModelImplementor.cs
index 2004e89..490b296 100644
--- a/src/tasque/TreeViewModelImplementor.cs
+++ b/src/tasque/TreeViewModelImplementor.cs
@@ -29,12 +29,13 @@ using System.Collections.ObjectModel;
 using System.Runtime.InteropServices;
 using GLib;
 using Gtk;
+using System.Linq;
 
 namespace Tasque
 {
-	public class TreeViewModelImplementor<T> : GLib.Object, TreeModelImplementor
+	public class TreeViewModelImplementor<T> : GLib.Object, TreeModelImplementor where T : class
 	{
-		public TreeViewModelImplementor (Collection<T> collection)
+		public TreeViewModelImplementor (IEnumerable<T> collection)
 		{
 			stamp = new Random ().Next (int.MinValue, int.MaxValue);
 			items = collection;
@@ -68,12 +69,12 @@ namespace Tasque
 			if (path == null)
 				throw new ArgumentNullException ("path");
 
-			if (path.Depth != 1 || path.Indices [0] > items.Count) {
+			if (path.Depth != 1 || path.Indices [0] > items.Count ()) {
 				iter = TreeIter.Zero;
 				return false;
 			}
 
-			var item = items [path.Indices [0]];
+			var item = items.ElementAt (path.Indices [0]);
 
 			if (item == null) {
 				iter = TreeIter.Zero;
@@ -97,7 +98,7 @@ namespace Tasque
 			if (target == null)
 				return new TreePath ();
 
-			var index = items.IndexOf ((T)target);
+			var index = IndexOf (items, ((T)target));
 			if (index != -1)
 				return new TreePath (new int[] { index });
 			else
@@ -129,10 +130,10 @@ namespace Tasque
 
 		public int IterNChildren (TreeIter iter)
 		{
-			if (iter.Stamp != stamp)
-				return -1;
+			if (iter.Equals (TreeIter.Zero))
+				return items.Count ();
 
-			// No iter has children
+			// else: No iter has children
 			return 0;
 		}
 
@@ -147,11 +148,11 @@ namespace Tasque
 			if (target == null)
 				return false;
 
-			var index = items.IndexOf ((T)target);
+			var index = IndexOf (items, ((T)target));
 			if (index == -1)
 				return false;
 
-			if (index >= items.Count - 1) {
+			if (index >= items.Count () - 1) {
 				iter = TreeIter.Zero;
 				return false;
 			}
@@ -180,9 +181,21 @@ namespace Tasque
 		{
 		}
 
+		int IndexOf (IEnumerable<T> enumerable, T item)
+		{
+			int index = 0;
+			foreach (var i in enumerable) {
+				if (item == i)
+					return index;
+				index++;
+			}
+
+			return -1;
+		}
+
 //		TreeModelAdapter adapter;
 		List<GCHandle> gcHandles;
-		Collection<T> items;
+		IEnumerable<T> items;
 		readonly int stamp;
 	}
 }
diff --git a/src/tasque/tasque.csproj b/src/tasque/tasque.csproj
index 98e2f76..f57f57f 100644
--- a/src/tasque/tasque.csproj
+++ b/src/tasque/tasque.csproj
@@ -159,7 +159,6 @@
     </Reference>
     <Reference Include="notify-sharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=2df29c54e245917a">
       <Private>False</Private>
-      <Package>notify-sharp</Package>
     </Reference>
     <Reference Include="NDesk.DBus.GLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f6716e4f9b2ed099">
       <Private>False</Private>
@@ -179,6 +178,25 @@
     <None Include="..\..\data\sounds\notify.wav">
       <Link>data\sounds\notify.wav</Link>
     </None>
+    <None Include="Backends\Hiveminder\HmBackend.cs" />
+    <None Include="Backends\Hiveminder\HmCategory.cs" />
+    <None Include="Backends\Hiveminder\HmNote.cs" />
+    <None Include="Backends\Hiveminder\HmPreferencesWidget.cs" />
+    <None Include="Backends\Hiveminder\HmTask.cs" />
+    <None Include="Backends\Hiveminder\service\Group.cs" />
+    <None Include="Backends\Hiveminder\service\Hiveminder.cs" />
+    <None Include="Backends\Hiveminder\service\HiveminderException.cs" />
+    <None Include="Backends\Hiveminder\service\Task.cs" />
+    <None Include="Backends\Rtm\RtmBackend.cs" />
+    <None Include="Backends\Rtm\RtmCategory.cs" />
+    <None Include="Backends\Rtm\RtmNote.cs" />
+    <None Include="Backends\Rtm\RtmPreferencesWidget.cs" />
+    <None Include="Backends\Rtm\RtmTask.cs" />
+    <None Include="Backends\Sqlite\Database.cs" />
+    <None Include="Backends\Sqlite\SqliteBackend.cs" />
+    <None Include="Backends\Sqlite\SqliteCategory.cs" />
+    <None Include="Backends\Sqlite\SqliteNote.cs" />
+    <None Include="Backends\Sqlite\SqliteTask.cs" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Properties\AssemblyInfo.cs" />
@@ -195,25 +213,6 @@
     <Compile Include="Backends\Dummy\DummyCategory.cs" />
     <Compile Include="Backends\Dummy\DummyNote.cs" />
     <Compile Include="Backends\Dummy\DummyTask.cs" />
-    <Compile Include="Backends\Hiveminder\HmBackend.cs" />
-    <Compile Include="Backends\Hiveminder\HmCategory.cs" />
-    <Compile Include="Backends\Hiveminder\HmNote.cs" />
-    <Compile Include="Backends\Hiveminder\HmPreferencesWidget.cs" />
-    <Compile Include="Backends\Hiveminder\HmTask.cs" />
-    <Compile Include="Backends\Hiveminder\service\Group.cs" />
-    <Compile Include="Backends\Hiveminder\service\Hiveminder.cs" />
-    <Compile Include="Backends\Hiveminder\service\HiveminderException.cs" />
-    <Compile Include="Backends\Hiveminder\service\Task.cs" />
-    <Compile Include="Backends\Rtm\RtmBackend.cs" />
-    <Compile Include="Backends\Rtm\RtmCategory.cs" />
-    <Compile Include="Backends\Rtm\RtmNote.cs" />
-    <Compile Include="Backends\Rtm\RtmPreferencesWidget.cs" />
-    <Compile Include="Backends\Rtm\RtmTask.cs" />
-    <Compile Include="Backends\Sqlite\Database.cs" />
-    <Compile Include="Backends\Sqlite\SqliteBackend.cs" />
-    <Compile Include="Backends\Sqlite\SqliteCategory.cs" />
-    <Compile Include="Backends\Sqlite\SqliteNote.cs" />
-    <Compile Include="Backends\Sqlite\SqliteTask.cs" />
     <Compile Include="CellRendererDate.cs" />
     <Compile Include="CompletedTaskGroup.cs" />
     <Compile Include="CompletedTaskGroupModel.cs" />
@@ -230,6 +229,7 @@
     <Compile Include="TaskTreeView.cs" />
     <Compile Include="TaskWindow.cs" />
     <Compile Include="Utilities.cs" />
+    <Compile Include="TreeViewModelImplementor.cs" />
   </ItemGroup>
   <ItemGroup Condition=" '$(Configuration)' == 'GnomeDebug' or '$(Configuration)' == 'GnomeRelease' ">
     <Compile Include="GnomeApplication.cs" />



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