tasque r197 - in branches/new_cache: . src
- From: bgmerrell svn gnome org
- To: svn-commits-list gnome org
- Subject: tasque r197 - in branches/new_cache: . src
- Date: Mon, 29 Dec 2008 03:10:44 +0000 (UTC)
Author: bgmerrell
Date: Mon Dec 29 03:10:43 2008
New Revision: 197
URL: http://svn.gnome.org/viewvc/tasque?rev=197&view=rev
Log:
* src/Category.cs,
* src/LocalCache.cs,
* src/TaskModelNode.cs,
* src/Task.cs,
* src/Database.cs: Forgot to add these files in the previous commit
* src/Makefile.am: Add SyncManager.cs
* src/Application.cs: Add SyncManager calls
* configure.ac: Remove reference to SQLite and changed a typo in a
comment from "SQLite" to "Hiveminder."
Added:
branches/new_cache/src/Category.cs
branches/new_cache/src/Database.cs
branches/new_cache/src/LocalCache.cs
branches/new_cache/src/Task.cs
branches/new_cache/src/TaskModelNode.cs
Modified:
branches/new_cache/ChangeLog
branches/new_cache/configure.ac
branches/new_cache/src/Application.cs
branches/new_cache/src/Makefile.am
Modified: branches/new_cache/configure.ac
==============================================================================
--- branches/new_cache/configure.ac (original)
+++ branches/new_cache/configure.ac Mon Dec 29 03:10:43 2008
@@ -152,7 +152,7 @@
AC_SUBST(EVOLUTION_SHARP_LIBS)
#
-# SQLite Backend
+# Hiveminder Backend
#
AC_ARG_ENABLE(backend_hiveminder,
AC_HELP_STRING([--enable-backend-hiveminder],
@@ -224,7 +224,6 @@
Evolution Backend: ${enable_backend_eds}
ICECore Backend: ${enable_backend_icecore}
RTM Backend: ${enable_backend_rtm}
- SQLite Backend: ${enable_backend_sqlite}
Hiveminder Backend: ${enable_backend_hiveminder}
"
Modified: branches/new_cache/src/Application.cs
==============================================================================
--- branches/new_cache/src/Application.cs (original)
+++ branches/new_cache/src/Application.cs Mon Dec 29 03:10:43 2008
@@ -61,6 +61,7 @@
private Preferences preferences;
private EventBox eb;
private IBackend backend;
+ private SyncManager syncManager;
private PreferencesDialog preferencesDialog;
private LocalCache localCache;
private bool quietStart = false;
@@ -212,6 +213,8 @@
RegisterUIManager ();
preferences = new Preferences (nativeApp.ConfDir);
+
+ syncManager = new SyncManager();
#if !WIN32 && !OSX
// Register Tasque RemoteControl
@@ -379,6 +382,9 @@
private bool InitializeIdle()
{
+ localCache = new LocalCache ();
+ localCache.Initialize ();
+
if (customBackend != null) {
Application.Backend = customBackend;
} else {
@@ -407,6 +413,8 @@
}
nativeApp.InitializeIdle ();
+
+ syncManager.Start();
return false;
}
@@ -530,6 +538,11 @@
private void OnQuit (object sender, EventArgs args)
{
Logger.Info ("OnQuit called - terminating application");
+
+ if (syncManager != null) {
+ syncManager.Stop();
+ }
+
if (backend != null) {
backend.Cleanup();
}
@@ -540,7 +553,7 @@
private void OnRefreshAction (object sender, EventArgs args)
{
- Application.Backend.Refresh();
+ syncManager.Sync();
}
private void OnTrayIconClick (object sender, EventArgs args) // handler for mouse click
Added: branches/new_cache/src/Category.cs
==============================================================================
--- (empty file)
+++ branches/new_cache/src/Category.cs Mon Dec 29 03:10:43 2008
@@ -0,0 +1,72 @@
+// Category.cs created with MonoDevelop
+// User: boyd at 1:34 PMÂ3/14/2008
+//
+
+using System;
+
+namespace Tasque
+{
+ public class Category
+ {
+ private int id;
+ LocalCache cache;
+
+ public int ID
+ {
+ get { return id; }
+ }
+
+ public virtual string Name
+ {
+ get {
+ string command = String.Format("SELECT Name FROM Categories where ID='{0}'", id);
+ return cache.Database.GetSingleString(command);
+ }
+ set {
+ string command = String.Format("UPDATE Categories set Name='{0}' where ID='{0}'", value, id);
+ cache.Database.ExecuteScalar(command);
+ }
+ }
+
+ public string ExternalID
+ {
+ get {
+ string command = String.Format("SELECT ExternalID FROM Categories where ID='{0}'", id);
+ return cache.Database.GetSingleString(command);
+ }
+ set {
+ string command = String.Format("UPDATE Categories set ExternalID='{0}' where ID='{0}'", value, id);
+ cache.Database.ExecuteScalar(command);
+ }
+ }
+
+ public Category (LocalCache cache, string name)
+ {
+ this.cache = cache;
+ string command = String.Format("INSERT INTO Categories (Name, ExternalID) values ('{0}', '{1}')", name, string.Empty);
+ cache.Database.ExecuteScalar(command);
+ this.id = cache.Database.Connection.LastInsertRowId;
+ //Logger.Debug("Inserted category named: {0} with id {1}", name, id);
+ }
+
+ public Category (LocalCache cache, int id)
+ {
+ this.cache = cache;
+ this.id = id;
+ }
+
+ internal Category ()
+ {
+ }
+
+
+ public virtual bool ContainsTask(Task task)
+ {
+ if(task.Category is Category)
+ return ((task.Category as Category).ID == id);
+
+ return false;
+ }
+
+ }
+}
Added: branches/new_cache/src/Database.cs
==============================================================================
--- (empty file)
+++ branches/new_cache/src/Database.cs Mon Dec 29 03:10:43 2008
@@ -0,0 +1,209 @@
+// Database.cs created with MonoDevelop
+// User: calvin at 11:27 AMÂ2/19/2008
+//
+// To change standard headers go to Edit->Preferences->Coding->Standard Headers
+//
+
+using System;
+using Mono.Data.Sqlite;
+using System.IO;
+using Tasque;
+
+namespace Tasque
+{
+ public class Database
+ {
+ private SqliteConnection connection;
+ public static readonly DateTime LocalUnixEpoch = new DateTime(1970, 1, 1).ToLocalTime();
+
+ public SqliteConnection Connection
+ {
+ get { return connection; }
+ }
+
+ public Database()
+ {
+ }
+
+
+ public void Open()
+ {
+ string dbLocation = "URI=file:" + Path.Combine(
+ Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
+ "tasque/sqlitebackend.db");
+
+ connection = new SqliteConnection(dbLocation);
+ connection.Open();
+
+ CreateTables();
+ }
+
+ public void Close()
+ {
+ connection.Close();
+ connection = null;
+ }
+
+ public void CreateTables()
+ {
+ if(!TableExists("Categories")) {
+ Console.WriteLine("Creating Categories table");
+ ExecuteScalar(@"CREATE TABLE Categories (
+ ID INTEGER PRIMARY KEY,
+ Name TEXT,
+ ExternalID TEXT
+ )");
+ }
+
+ if(!TableExists("Tasks")) {
+ Console.WriteLine("Creating Tasks table");
+ ExecuteScalar(@"CREATE TABLE Tasks (
+ ID INTEGER PRIMARY KEY,
+ Category INTEGER,
+ Name TEXT,
+ DueDate INTEGER,
+ CompletionDate INTEGER,
+ Priority INTEGER,
+ State INTEGER,
+ ExternalID TEXT
+ )");
+ }
+
+ if(!TableExists("Notes")) {
+ Console.WriteLine("Creating Notes table");
+ ExecuteScalar(@"CREATE TABLE Notes (
+ ID INTEGER PRIMARY KEY,
+ Task INTEGER KEY,
+ Name TEXT,
+ Text TEXT,
+ ExternalID TEXT
+ )");
+ }
+ }
+
+
+ public object ExecuteScalar(string command)
+ {
+ object resultset;
+
+ SqliteCommand cmd = connection.CreateCommand();
+ cmd.CommandText = command;
+ resultset = cmd.ExecuteScalar();
+ return resultset;
+ }
+
+ public int ExecuteNonQuery(string command)
+ {
+ int resultCode;
+ SqliteCommand cmd = connection.CreateCommand();
+ cmd.CommandText = command;
+ resultCode = cmd.ExecuteNonQuery();
+ cmd.Dispose();
+ return resultCode;
+ }
+
+ public string GetSingleString(string command)
+ {
+ string readString = String.Empty;
+ try {
+ SqliteCommand cmd = connection.CreateCommand();
+ cmd.CommandText = command;
+ SqliteDataReader dataReader = cmd.ExecuteReader();
+ if(dataReader.Read())
+ readString = dataReader.GetString(0);
+ else
+ readString = string.Empty;
+ dataReader.Close();
+ cmd.Dispose();
+ } catch (Exception e) {
+ Logger.Debug("Exception Thrown {0}", e);
+ }
+ return readString;
+ }
+
+ public DateTime GetDateTime(string command)
+ {
+ long longValue;
+ DateTime dtValue;
+ try{
+ longValue = GetSingleLong(command);
+ if(longValue == 0)
+ dtValue = DateTime.MinValue;
+ else
+ dtValue = Database.ToDateTime(longValue);
+ } catch (Exception e) {
+ Logger.Debug("Exception Thrown {0}", e);
+ dtValue = DateTime.MinValue;
+ }
+ return dtValue;
+ }
+
+ public int GetSingleInt(string command)
+ {
+ int dtVal = 0;
+ try {
+ SqliteCommand cmd = connection.CreateCommand();
+ cmd.CommandText = command;
+ SqliteDataReader dataReader = cmd.ExecuteReader();
+ if(dataReader.Read())
+ dtVal = dataReader.GetInt32(0);
+ else
+ dtVal = 0;
+ dataReader.Close();
+ cmd.Dispose();
+ } catch (Exception e) {
+ Logger.Debug("Exception Thrown {0}", e);
+ }
+ return dtVal;
+ }
+
+ public long GetSingleLong(string command)
+ {
+ long dtVal = 0;
+ try {
+ SqliteCommand cmd = connection.CreateCommand();
+ cmd.CommandText = command;
+ SqliteDataReader dataReader = cmd.ExecuteReader();
+ if(dataReader.Read())
+ dtVal = dataReader.GetInt64(0);
+ else
+ dtVal = 0;
+ dataReader.Close();
+ cmd.Dispose();
+ } catch (Exception e) {
+ Logger.Debug("Exception Thrown {0}", e);
+ }
+ return dtVal;
+ }
+
+
+ public bool TableExists(string table)
+ {
+ return Convert.ToInt32(ExecuteScalar(String.Format(@"
+ SELECT COUNT(*)
+ FROM sqlite_master
+ WHERE Type='table' AND Name='{0}'",
+ table))) > 0;
+ }
+
+ public static DateTime ToDateTime(long time)
+ {
+ return FromTimeT(time);
+ }
+
+ public static long FromDateTime(DateTime time)
+ {
+ return ToTimeT(time);
+ }
+
+ public static DateTime FromTimeT(long time)
+ {
+ return LocalUnixEpoch.AddSeconds(time);
+ }
+
+ public static long ToTimeT(DateTime time)
+ {
+ return (long)time.Subtract(LocalUnixEpoch).TotalSeconds;
+ }
+ }
+}
Added: branches/new_cache/src/LocalCache.cs
==============================================================================
--- (empty file)
+++ branches/new_cache/src/LocalCache.cs Mon Dec 29 03:10:43 2008
@@ -0,0 +1,473 @@
+// LocalCache.cs created with MonoDevelop
+// User: boyd at 1:35 PMÂ3/14/2008
+//
+
+using System;
+using System.Collections.Generic;
+using Mono.Unix;
+using Tasque.Backends;
+using Mono.Data.Sqlite;
+
+namespace Tasque
+{
+ public class LocalCache
+ {
+ private Dictionary<int, Gtk.TreeIter> taskIters;
+ private Gtk.TreeStore taskStore;
+ private Gtk.TreeModelSort sortedTasksModel;
+ private bool initialized;
+ private bool configured = true;
+
+ private Database db;
+
+ private Gtk.ListStore categoryListStore;
+ private Gtk.TreeModelSort sortedCategoriesModel;
+
+ 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 Gtk.TreeIter overdueIter;
+ private Gtk.TreeIter todayIter;
+ private Gtk.TreeIter tomorrowIter;
+ private Gtk.TreeIter nextSevenDaysIter;
+ private Gtk.TreeIter futureIter;
+ private Gtk.TreeIter completedTaskIter;
+
+ Category defaultCategory;
+
+ public LocalCache ()
+ {
+ initialized = false;
+ taskIters = new Dictionary<int, Gtk.TreeIter> ();
+ taskStore = new Gtk.TreeStore (typeof (TaskModelNode));
+
+ sortedTasksModel = new Gtk.TreeModelSort (taskStore);
+ sortedTasksModel.SetSortFunc (0, new Gtk.TreeIterCompareFunc (CompareTasksSortFunc));
+ sortedTasksModel.SetSortColumnId (0, Gtk.SortType.Ascending);
+
+ categoryListStore = new Gtk.ListStore (typeof (Category));
+
+ sortedCategoriesModel = new Gtk.TreeModelSort (categoryListStore);
+ sortedCategoriesModel.SetSortFunc (0, new Gtk.TreeIterCompareFunc (CompareCategorySortFunc));
+ sortedCategoriesModel.SetSortColumnId (0, Gtk.SortType.Ascending);
+ }
+
+ #region Public Properties
+ /// <value>
+ /// All the tasks including ITaskDivider items.
+ /// </value>
+ public Gtk.TreeModel Tasks
+ {
+ get { return sortedTasksModel; }
+ }
+
+ /// <value>
+ /// This returns all the task lists (categories) that exist.
+ /// </value>
+ public Gtk.TreeModel Categories
+ {
+ get { return sortedCategoriesModel; }
+ }
+
+ /// <value>
+ /// Indication that the Sqlite backend is configured
+ /// </value>
+ public bool Configured
+ {
+ get { return configured; }
+ }
+
+ /// <value>
+ /// Inidication that the backend is initialized
+ /// </value>
+ public bool Initialized
+ {
+ get { return initialized; }
+ }
+
+ public Database Database
+ {
+ get { return db; }
+ }
+ #endregion // Public Properties
+
+ #region Public Methods
+ public Task CreateTask (string taskName, Category category)
+ {
+ // not sure what to do here with the category
+ Task task = new Task (this, taskName);
+
+ // Determine and set the task category
+ if (category == null || category is Tasque.AllCategory)
+ task.Category = defaultCategory; // Default to work
+ else
+ task.Category = category;
+
+ Gtk.TreeIter parentIter = GetParentIter(task);
+ Gtk.TreeIter iter = taskStore.AppendNode(parentIter);
+ taskStore.SetValue (iter, 0, new TaskModelNode(task));
+ taskIters [task.Id] = iter;
+
+ // Set the parent iter object so that in case it's not showing
+ // already, the TreeModelFilter will refilter and cause it to appear.
+ object parentObj = taskStore.GetValue (parentIter, 0);
+ taskStore.SetValue (parentIter, 0, parentObj);
+
+ return task;
+ }
+
+ public void DeleteTask(Task task)
+ {}
+
+ public void Refresh()
+ {}
+
+ public void Initialize()
+ {
+ if(db == null)
+ db = new Database();
+
+ db.Open();
+
+ //
+ // Add in the "All" Category
+ //
+ AllCategory allCategory = new Tasque.AllCategory ();
+ Gtk.TreeIter iter = categoryListStore.Append ();
+ categoryListStore.SetValue (iter, 0, allCategory);
+
+ RefreshDates();
+ RefreshCategories();
+ RefreshTasks();
+
+ initialized = true;
+ }
+
+ public void Cleanup()
+ {
+ this.categoryListStore.Clear();
+ this.taskStore.Clear();
+ this.taskIters.Clear();
+
+ db.Close();
+ db = null;
+ initialized = false;
+ }
+ #endregion // Public Methods
+
+ #region Private Methods
+ static int CompareTasksSortFunc (Gtk.TreeModel model,
+ Gtk.TreeIter a,
+ Gtk.TreeIter b)
+ {
+ TaskModelNode taskModelNodeA = model.GetValue (a, 0) as TaskModelNode;
+ TaskModelNode taskModelNodeB = model.GetValue (b, 0) as TaskModelNode;
+
+ if (taskModelNodeA == null || taskModelNodeB == null || taskModelNodeA.Task == null || taskModelNodeB.Task == null)
+ return 0;
+
+ return (taskModelNodeA.Task.CompareTo (taskModelNodeB.Task));
+ }
+
+ static int CompareCategorySortFunc (Gtk.TreeModel model,
+ Gtk.TreeIter a,
+ Gtk.TreeIter b)
+ {
+ Category categoryA = model.GetValue (a, 0) as Category;
+ Category categoryB = model.GetValue (b, 0) as Category;
+
+ if (categoryA == null || categoryB == null)
+ return 0;
+
+ if (categoryA is Tasque.AllCategory)
+ return -1;
+ else if (categoryB is Tasque.AllCategory)
+ return 1;
+
+ return (categoryA.Name.CompareTo (categoryB.Name));
+ }
+
+
+ public void UpdateTask (Task task)
+ {
+ // 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;
+
+ iter = taskIters [task.Id];
+
+ if (task.State == TaskState.Deleted) {
+ taskIters.Remove (task.Id);
+ if (taskStore.Remove (ref iter) == false) {
+ Logger.Debug ("Successfully deleted from taskStore: {0}",
+ task.Name);
+ } else {
+ Logger.Debug ("Problem removing from taskStore: {0}",
+ task.Name);
+ }
+ } else {
+ parentIter = GetParentIter(task);
+
+ if(!taskStore.IsAncestor(parentIter, iter))
+ {
+ Logger.Debug("Task needs to be re-parented...");
+
+ taskStore.Remove(ref iter);
+ iter = taskStore.AppendNode(parentIter);
+ taskStore.SetValue (iter, 0, new TaskModelNode(task));
+ taskIters [task.Id] = iter;
+
+ // Set the values of all the parent objects so any filters
+ // will update themselves
+ UpdateParentIters ();
+ } else {
+ taskStore.SetValue (iter, 0, new TaskModelNode(task));
+ }
+ }
+ }
+
+
+
+ public void RefreshCategories()
+ {
+ Gtk.TreeIter iter;
+ Category newCategory;
+ bool hasValues = false;
+
+ string command = "SELECT id FROM Categories";
+ SqliteCommand cmd = db.Connection.CreateCommand();
+ cmd.CommandText = command;
+ SqliteDataReader dataReader = cmd.ExecuteReader();
+ while(dataReader.Read()) {
+ int id = dataReader.GetInt32(0);
+ hasValues = true;
+
+ newCategory = new Category (this, id);
+ if( (defaultCategory == null) || (newCategory.Name.CompareTo("Work") == 0) )
+ defaultCategory = newCategory;
+ iter = categoryListStore.Append ();
+ categoryListStore.SetValue (iter, 0, newCategory);
+ }
+
+ dataReader.Close();
+ cmd.Dispose();
+
+ if(!hasValues)
+ {
+ defaultCategory = newCategory = new Category (this, "Work");
+ iter = categoryListStore.Append ();
+ categoryListStore.SetValue (iter, 0, newCategory);
+
+ newCategory = new Category (this, "Personal");
+ iter = categoryListStore.Append ();
+ categoryListStore.SetValue (iter, 0, newCategory);
+
+ newCategory = new Category (this, "Family");
+ iter = categoryListStore.Append ();
+ categoryListStore.SetValue (iter, 0, newCategory);
+
+ newCategory = new Category (this, "Project");
+ iter = categoryListStore.Append ();
+ categoryListStore.SetValue (iter, 0, newCategory);
+ }
+ }
+
+
+
+ public void RefreshTasks()
+ {
+ Gtk.TreeIter iter;
+ Gtk.TreeIter parentIter;
+ Task newTask;
+ bool hasValues = false;
+
+ overdueIter = taskStore.AppendNode();
+ taskStore.SetValue(overdueIter, 0, new TaskModelNode(Catalog.GetString("Overdue")));
+
+ todayIter = taskStore.AppendNode();
+ taskStore.SetValue(todayIter, 0, new TaskModelNode(Catalog.GetString("Today")));
+
+ tomorrowIter = taskStore.AppendNode();
+ taskStore.SetValue(tomorrowIter, 0, new TaskModelNode(Catalog.GetString("Tomorrow")));
+
+ nextSevenDaysIter = taskStore.AppendNode();
+ taskStore.SetValue(nextSevenDaysIter, 0, new TaskModelNode(Catalog.GetString("Next 7 Days")));
+
+ futureIter = taskStore.AppendNode();
+ taskStore.SetValue(futureIter, 0, new TaskModelNode(Catalog.GetString("Future")));
+
+ completedTaskIter = taskStore.AppendNode();
+ taskStore.SetValue(completedTaskIter, 0, new TaskModelNode(Catalog.GetString("Completed")));
+
+ string command = "SELECT id FROM Tasks";
+ SqliteCommand cmd = db.Connection.CreateCommand();
+ cmd.CommandText = command;
+ SqliteDataReader dataReader = cmd.ExecuteReader();
+ while(dataReader.Read()) {
+ int id = dataReader.GetInt32(0);
+ hasValues = true;
+
+ newTask = new Task(this, id);
+ parentIter = GetParentIter(newTask);
+ iter = taskStore.AppendNode(parentIter);
+ taskStore.SetValue (iter, 0, new TaskModelNode(newTask));
+ taskIters [newTask.Id] = iter;
+ }
+
+ dataReader.Close();
+ cmd.Dispose();
+
+ if(!hasValues)
+ {
+ newTask = new Task (this, "Enter tasks into Tasque");
+ newTask.Category = defaultCategory;
+ newTask.DueDate = DateTime.Now;
+ newTask.Priority = TaskPriority.High;
+ parentIter = GetParentIter(newTask);
+ iter = taskStore.AppendNode(parentIter);
+ taskStore.SetValue (iter, 0, new TaskModelNode(newTask));
+ taskIters [newTask.Id] = iter;
+
+ newTask = new Task (this, "Get things done");
+ newTask.Category = defaultCategory;
+ newTask.DueDate = DateTime.Now;
+ newTask.Priority = TaskPriority.Medium;
+ parentIter = GetParentIter(newTask);
+ iter = taskStore.AppendNode(parentIter);
+ taskStore.SetValue (iter, 0, new TaskModelNode(newTask));
+ taskIters [newTask.Id] = iter;
+
+ newTask = new Task (this, "Enjoy new found freedom");
+ newTask.Category = defaultCategory;
+ newTask.DueDate = DateTime.Now;
+ newTask.Priority = TaskPriority.Low;
+ parentIter = GetParentIter(newTask);
+ iter = taskStore.AppendNode(parentIter);
+ taskStore.SetValue (iter, 0, new TaskModelNode(newTask));
+ taskIters [newTask.Id] = iter;
+
+ }
+ }
+
+ 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.AddSeconds(1); // min is one second more than min
+ 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;
+ }
+
+ void UpdateParentIters ()
+ {
+ Gtk.TreeIter iter;
+ if (taskStore.GetIterFirst (out iter) == false)
+ return;
+
+ do {
+ TaskModelNode node = taskStore.GetValue (iter, 0) as TaskModelNode;
+ if (node == null)
+ continue;
+
+ taskStore.SetValue (iter, 0, node);
+ } while (taskStore.IterNext (ref iter) == true);
+ }
+
+ #endregion // Private Methods
+
+ #region Event Handlers
+ #endregion // Event Handlers
+ }
+}
Modified: branches/new_cache/src/Makefile.am
==============================================================================
--- branches/new_cache/src/Makefile.am (original)
+++ branches/new_cache/src/Makefile.am Mon Dec 29 03:10:43 2008
@@ -73,6 +73,7 @@
$(srcdir)/PreferencesDialog.cs \
$(srcdir)/RemoteControl.cs \
$(srcdir)/RemoteControlProxy.cs \
+ $(srcdir)/SyncManager.cs \
$(srcdir)/Task.cs \
$(srcdir)/TaskCalendar.cs \
$(srcdir)/TaskGroup.cs \
Added: branches/new_cache/src/Task.cs
==============================================================================
--- (empty file)
+++ branches/new_cache/src/Task.cs Mon Dec 29 03:10:43 2008
@@ -0,0 +1,297 @@
+// Task.cs created with MonoDevelop
+// User: boyd at 1:34 PMÂ3/14/2008
+//
+
+using System;
+using System.Collections.Generic;
+
+namespace Tasque
+{
+ public class Task
+ {
+ private LocalCache cache;
+ private int id;
+ private uint timerID = 0;
+
+ public Task(LocalCache cache, string name)
+ {
+ this.cache = cache;
+ string command = String.Format("INSERT INTO Tasks (Name, DueDate, CompletionDate, Priority, State, Category, ExternalID) values ('{0}','{1}', '{2}','{3}', '{4}', '{5}', '{6}')",
+ name, Database.FromDateTime(DateTime.MinValue), Database.FromDateTime(DateTime.MinValue),
+ ((int)(TaskPriority.None)), ((int)TaskState.Active), 0, string.Empty );
+ cache.Database.ExecuteScalar(command);
+ this.id = cache.Database.Connection.LastInsertRowId;
+ }
+
+ public Task (LocalCache cache, int id)
+ {
+ this.cache = cache;
+ this.id = id;
+ }
+
+ #region Public Properties
+
+ public int Id
+ {
+ get { return id; }
+ set { id = value; }
+ }
+
+ public string Name
+ {
+ get {
+ string command = String.Format("SELECT Name FROM Tasks where ID='{0}'", id);
+ return cache.Database.GetSingleString(command);
+ }
+ set {
+ string command = String.Format("UPDATE Tasks set Name='{0}' where ID='{1}'", value, id);
+ cache.Database.ExecuteScalar(command);
+ cache.UpdateTask(this);
+ }
+ }
+
+ public DateTime DueDate
+ {
+ get {
+ string command = String.Format("SELECT DueDate FROM Tasks where ID='{0}'", id);
+ return cache.Database.GetDateTime(command);
+ }
+ set {
+ string command = String.Format("UPDATE Tasks set DueDate='{0}' where ID='{1}'", Database.FromDateTime(value), id);
+ cache.Database.ExecuteScalar(command);
+ cache.UpdateTask(this);
+ }
+ }
+
+
+ public DateTime CompletionDate
+ {
+ get {
+ string command = String.Format("SELECT CompletionDate FROM Tasks where ID='{0}'", id);
+ return cache.Database.GetDateTime(command);
+ }
+ set {
+ string command = String.Format("UPDATE Tasks set CompletionDate='{0}' where ID='{1}'", Database.FromDateTime(value), id);
+ cache.Database.ExecuteScalar(command);
+ cache.UpdateTask(this);
+ }
+ }
+
+
+ public bool IsComplete
+ {
+ get {
+ if (CompletionDate == DateTime.MinValue)
+ return false;
+
+ return true;
+ }
+ }
+
+ public TaskPriority Priority
+ {
+ get {
+ string command = String.Format("SELECT Priority FROM Tasks where ID='{0}'", id);
+ return (TaskPriority)cache.Database.GetSingleInt(command);
+ }
+ set {
+ string command = String.Format("UPDATE Tasks set Priority='{0}' where ID='{1}'", ((int)value), id);
+ cache.Database.ExecuteScalar(command);
+ cache.UpdateTask(this);
+ }
+ }
+
+ public bool HasNotes
+ {
+ get { return false; }
+ }
+
+ public bool SupportsMultipleNotes
+ {
+ get { return false; }
+ }
+
+ public TaskState State
+ {
+ get { return LocalState; }
+ }
+
+ public TaskState LocalState
+ {
+ get {
+ string command = String.Format("SELECT State FROM Tasks where ID='{0}'", id);
+ return (TaskState)cache.Database.GetSingleInt(command);
+ }
+ set {
+ string command = String.Format("UPDATE Tasks set State='{0}' where ID='{1}'", ((int)value), id);
+ cache.Database.ExecuteScalar(command);
+ cache.UpdateTask(this);
+ }
+ }
+
+ public Category Category
+ {
+ get {
+ string command = String.Format("SELECT Category FROM Tasks where ID='{0}'", id);
+ int catID = cache.Database.GetSingleInt(command);
+ Category sqCat = new Category(cache, catID);
+ return sqCat;
+ }
+ set {
+ string command = String.Format("UPDATE Tasks set Category='{0}' where ID='{1}'", ((int)(value as Category).ID), id);
+ cache.Database.ExecuteScalar(command);
+ cache.UpdateTask(this);
+ }
+ }
+
+ public List<INote> Notes
+ {
+ get { return null; }
+ }
+
+ /// <value>
+ /// The ID of the timer used to complete a task after being marked
+ /// inactive.
+ /// </value>
+ public uint TimerID
+ {
+ get { return timerID; }
+ set { timerID = value; }
+ }
+ #endregion // Public Properties
+
+ #region Public Methods
+ public void Activate ()
+ {
+ // Logger.Debug ("Task.Activate ()");
+ CompletionDate = DateTime.MinValue;
+ LocalState = TaskState.Active;
+ cache.UpdateTask (this);
+ }
+
+ public void Inactivate ()
+ {
+ // Logger.Debug ("Task.Inactivate ()");
+ CompletionDate = DateTime.Now;
+ LocalState = TaskState.Inactive;
+ cache.UpdateTask (this);
+ }
+
+ public void Complete ()
+ {
+ //Logger.Debug ("Task.Complete ()");
+ CompletionDate = DateTime.Now;
+ LocalState = TaskState.Completed;
+ cache.UpdateTask (this);
+ }
+
+ public void Delete ()
+ {
+ //Logger.Debug ("Task.Delete ()");
+ LocalState = TaskState.Deleted;
+ cache.UpdateTask (this);
+ }
+
+ public INote CreateNote(string text)
+ {
+ return null;
+ }
+
+ public void DeleteNote(INote note)
+ {
+ }
+
+ public void SaveNote(INote note)
+ {
+ }
+
+ public int CompareTo (Task task)
+ {
+ bool isSameDate = true;
+ if (DueDate.Year != task.DueDate.Year
+ || DueDate.DayOfYear != task.DueDate.DayOfYear)
+ isSameDate = false;
+
+ if (isSameDate == false) {
+ if (DueDate == DateTime.MinValue) {
+ // No due date set on this task. Since we already tested to see
+ // if the dates were the same above, we know that the passed-in
+ // task has a due date set and it should be "higher" in a sort.
+ return 1;
+ } else if (task.DueDate == DateTime.MinValue) {
+ // This task has a due date and should be "first" in sort order.
+ return -1;
+ }
+
+ int result = DueDate.CompareTo (task.DueDate);
+
+ if (result != 0) {
+ return result;
+ }
+ }
+
+ // The due dates match, so now sort based on priority and name
+ return CompareByPriorityAndName (task);
+ }
+
+ public int CompareToByCompletionDate (Task task)
+ {
+ bool isSameDate = true;
+ if (CompletionDate.Year != task.CompletionDate.Year
+ || CompletionDate.DayOfYear != task.CompletionDate.DayOfYear)
+ isSameDate = false;
+
+ if (isSameDate == false) {
+ if (CompletionDate == DateTime.MinValue) {
+ // No completion date set for some reason. Since we already
+ // tested to see if the dates were the same above, we know
+ // that the passed-in task has a CompletionDate set, so the
+ // passed-in task should be "higher" in the sort.
+ return 1;
+ } else if (task.CompletionDate == DateTime.MinValue) {
+ // "this" task has a completion date and should evaluate
+ // higher than the passed-in task which doesn't have a
+ // completion date.
+ return -1;
+ }
+
+ return CompletionDate.CompareTo (task.CompletionDate);
+ }
+
+ // The completion dates are the same, so no sort based on other
+ // things.
+ return CompareByPriorityAndName (task);
+ }
+ #endregion // Public Methods
+
+ #region Private Methods
+ private int CompareByPriorityAndName (Task task)
+ {
+ // The due dates match, so now sort based on priority
+ if (Priority != task.Priority) {
+ switch (Priority) {
+ case TaskPriority.High:
+ return -1;
+ case TaskPriority.Medium:
+ if (task.Priority == TaskPriority.High) {
+ return 1;
+ } else {
+ return -1;
+ }
+ case TaskPriority.Low:
+ if (task.Priority == TaskPriority.None) {
+ return -1;
+ } else {
+ return 1;
+ }
+ case TaskPriority.None:
+ return 1;
+ }
+ }
+
+ // Due dates and priorities match, now sort by name
+ return Name.CompareTo (task.Name);
+ }
+ #endregion // Private Methods
+ }
+}
Added: branches/new_cache/src/TaskModelNode.cs
==============================================================================
--- (empty file)
+++ branches/new_cache/src/TaskModelNode.cs Mon Dec 29 03:10:43 2008
@@ -0,0 +1,51 @@
+// TaskModelNode.cs created with MonoDevelop
+// User: calvin at 4:29 PMÂ3/14/2008
+//
+// To change standard headers go to Edit->Preferences->Coding->Standard Headers
+//
+
+using System;
+using System.Collections.Generic;
+using Gtk;
+using Mono.Unix;
+
+namespace Tasque
+{
+ public class TaskModelNode
+ {
+ private Task task;
+ private string name;
+
+ public bool IsSeparator
+ {
+ get { return (task == null); }
+ }
+
+ public Task Task
+ {
+ get { return task; }
+ }
+
+ public string Name
+ {
+ get {
+ if(task == null)
+ return name;
+ else
+ return task.Name;
+ }
+ }
+
+
+ public TaskModelNode(Task task)
+ {
+ this.task = task;
+ }
+
+ public TaskModelNode(string name)
+ {
+ this.task = null;
+ this.name = name;
+ }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]