tasque r33 - in branches/cache: . src



Author: calvinrg
Date: Sat Mar 15 06:12:25 2008
New Revision: 33
URL: http://svn.gnome.org/viewvc/tasque?rev=33&view=rev

Log:
* src/TaskTreeView.cs, src/LocalCache.cs: Further work on enabling new
  TreeView

Modified:
   branches/cache/ChangeLog
   branches/cache/src/LocalCache.cs
   branches/cache/src/TaskTreeView.cs

Modified: branches/cache/src/LocalCache.cs
==============================================================================
--- branches/cache/src/LocalCache.cs	(original)
+++ branches/cache/src/LocalCache.cs	Sat Mar 15 06:12:25 2008
@@ -26,6 +26,21 @@
 		public event BackendInitializedHandler BackendInitialized;
 		public event BackendSyncStartedHandler BackendSyncStarted;
 		public event BackendSyncFinishedHandler BackendSyncFinished;
+
+		private DateTime overdueRangeStart;
+		private DateTime overdueRangeEnd;
+
+		private DateTime todayRangeStart;
+		private DateTime todayRangeEnd;
+
+		private DateTime tomorrowRangeStart;
+		private DateTime tomorrowRangeEnd;
+
+		private DateTime sevenDaysRangeStart;
+		private DateTime sevenDaysRangeEnd;
+
+		private DateTime futureRangeStart;
+		private DateTime futureRangeEnd;
 		
 		//private TaskGroup overdueGroup;
 		//private TaskGroup todayGroup;
@@ -41,12 +56,11 @@
 		private Gtk.TreeIter futureIter;
 		private Gtk.TreeIter completedTaskIter;
 
-
-		
 		Category defaultCategory;
 		//Category workCategory;
 		//Category projectsCategory;
 		
+		
 		public LocalCache ()
 		{
 			initialized = false;
@@ -143,7 +157,7 @@
 			Gtk.TreeIter iter = categoryListStore.Append ();
 			categoryListStore.SetValue (iter, 0, allCategory);
 			
-			
+			RefreshDates();
 			RefreshCategories();
 			RefreshTasks();		
 
@@ -209,6 +223,9 @@
 		{
 			// Set the task in the store so the model will update the UI.
 			Gtk.TreeIter iter;
+			Gtk.TreeIter parentIter;
+			
+			Logger.Debug("Update task was called");
 			
 			if (taskIters.ContainsKey (task.Id) == false)
 				return;
@@ -225,7 +242,19 @@
 						task.Name);
 				}
 			} else {
-				taskStore.SetValue (iter, 0, task);
+				parentIter = GetParentIter(task);
+				
+				if(!taskStore.IsAncestor(parentIter, iter))
+				{
+					Logger.Debug("Task is in the wrong group!");
+
+					taskStore.Remove(ref iter);
+					iter = taskStore.AppendNode(parentIter);
+					taskStore.SetValue (iter, 0, new TaskModelNode(task));					
+					taskIters [task.Id] = iter;
+				} else {
+					taskStore.SetValue (iter, 0, new TaskModelNode(task));
+				}
 			}
 		}
 		
@@ -305,12 +334,16 @@
         	cmd.CommandText = command;
         	SqliteDataReader dataReader = cmd.ExecuteReader();
         	while(dataReader.Read()) {
+        		Gtk.TreeIter parentIter;
+        		
 			    int id = dataReader.GetInt32(0);
 				hasValues = true;
 				
 				newTask = new Task(this, id);
-				iter = taskStore.AppendNode(overdueIter);
-				taskStore.SetValue (iter, 0, new TaskModelNode(newTask));				
+				parentIter = GetParentIter(newTask);
+				iter = taskStore.AppendNode(parentIter);
+				taskStore.SetValue (iter, 0, new TaskModelNode(newTask));
+				taskIters [newTask.Id] = iter;				
         	}
 
         	dataReader.Close();
@@ -328,6 +361,90 @@
 			}
 		}
 
+		private Gtk.TreeIter GetParentIter(Task task)
+		{
+			Gtk.TreeIter iter;
+			
+			if(task.LocalState == TaskState.Completed) {
+				Logger.Debug("Parent is Complete");
+				iter = completedTaskIter;
+			}
+			else if( InRange(overdueRangeStart, overdueRangeEnd, task) ) {
+				Logger.Debug("Parent is Overdue");
+				iter = overdueIter;
+			}
+			else if( InRange(todayRangeStart, todayRangeEnd, task) ) {
+				Logger.Debug("Parent is Today");
+				iter = todayIter;
+			}
+			else if( InRange(tomorrowRangeStart, tomorrowRangeEnd, task) ) {
+				Logger.Debug("Parent is Tomorrow");
+				iter = tomorrowIter;
+			}
+			else if( InRange(sevenDaysRangeStart, sevenDaysRangeEnd, task) ) {
+				Logger.Debug("Parent is Next Seven Days");
+				iter = nextSevenDaysIter;
+			}
+			else { 
+				Logger.Debug("Parent is Future");
+				iter = futureIter;
+			}
+			
+			return iter;
+		}
+		
+		
+		private bool InRange (DateTime rangeStart, DateTime rangeEnd, Task task)
+		{
+			if (task == null)
+				return false;
+				
+			if (task.DueDate < rangeStart || task.DueDate > rangeEnd)
+				return false;
+			
+			return true;
+		}
+		
+		
+		private void RefreshDates()
+		{
+			// Overdue
+			overdueRangeStart = DateTime.MinValue;
+			overdueRangeEnd = DateTime.Now.AddDays (-1);
+			overdueRangeEnd = new DateTime (overdueRangeEnd.Year, overdueRangeEnd.Month, overdueRangeEnd.Day,
+									 23, 59, 59);		
+
+			// Today
+			todayRangeStart = DateTime.Now;
+			todayRangeStart = new DateTime (todayRangeStart.Year, todayRangeStart.Month,
+									   todayRangeStart.Day, 0, 0, 0);
+			todayRangeEnd = DateTime.Now;
+			todayRangeEnd = new DateTime (todayRangeEnd.Year, todayRangeEnd.Month,
+									 todayRangeEnd.Day, 23, 59, 59);
+
+			// Tomorrow
+			tomorrowRangeStart = DateTime.Now.AddDays (1);
+			tomorrowRangeStart = new DateTime (tomorrowRangeStart.Year, tomorrowRangeStart.Month,
+									   tomorrowRangeStart.Day, 0, 0, 0);
+			tomorrowRangeEnd = DateTime.Now.AddDays (1);
+			tomorrowRangeEnd = new DateTime (tomorrowRangeEnd.Year, tomorrowRangeEnd.Month,
+									 tomorrowRangeEnd.Day, 23, 59, 59);
+
+			// Next Seven Days
+			sevenDaysRangeStart = DateTime.Now.AddDays (2);
+			sevenDaysRangeStart = new DateTime (sevenDaysRangeStart.Year, sevenDaysRangeStart.Month,
+									   sevenDaysRangeStart.Day, 0, 0, 0);
+			sevenDaysRangeEnd = DateTime.Now.AddDays (6);
+			sevenDaysRangeEnd = new DateTime (sevenDaysRangeEnd.Year, sevenDaysRangeEnd.Month,
+									 sevenDaysRangeEnd.Day, 23, 59, 59);
+
+			// Future
+			futureRangeStart = DateTime.Now.AddDays (7);
+			futureRangeStart = new DateTime (futureRangeStart.Year, futureRangeStart.Month,
+									   futureRangeStart.Day, 0, 0, 0);
+			futureRangeEnd = DateTime.MaxValue;
+		}
+
 		#endregion // Private Methods
 		
 		#region Event Handlers

Modified: branches/cache/src/TaskTreeView.cs
==============================================================================
--- branches/cache/src/TaskTreeView.cs	(original)
+++ branches/cache/src/TaskTreeView.cs	Sat Mar 15 06:12:25 2008
@@ -59,12 +59,14 @@
 			RulesHint = false;
 			HeadersVisible = false;
 			HoverSelection = true;
+			// TODO: This can eventually be turned to false, but until debugged
+			// this should stay
+			this.ShowExpanders = true;
 			
 			// TODO: Figure out how to turn off selection highlight
 			
 			Gtk.CellRenderer renderer;
 
-			this.ShowExpanders = false;
 			//
 			// Checkbox Column
 			//
@@ -734,6 +736,7 @@
 			} else {
 				node.Task.Activate ();
 			}
+			this.ExpandAll();			
 		}
 
 		void OnTaskPriorityEdited (object sender, Gtk.EditedArgs args)
@@ -858,6 +861,7 @@
 				// Modify the due date
 				node.Task.DueDate = newDate;
 			}
+			this.ExpandAll();
 		}
 		
 		void OnRowInsertedHandler (object sender, Gtk.RowInsertedArgs args)



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