tasque r26 - in branches/cache: . src src/Backends/Rtm src/Backends/Sqlite
- From: btimothy svn gnome org
- To: svn-commits-list gnome org
- Subject: tasque r26 - in branches/cache: . src src/Backends/Rtm src/Backends/Sqlite
- Date: Fri, 14 Mar 2008 20:19:15 +0000 (GMT)
Author: btimothy
Date: Fri Mar 14 20:19:15 2008
New Revision: 26
URL: http://svn.gnome.org/viewvc/tasque?rev=26&view=rev
Log:
* tasque.mdp, tasque.mds, src/LocalCache.cs, src/Application.cs,
src/Backends/Sqlite/SqliteCategory.cs,
src/Backends/Sqlite/Database.cs, src/Backends/Sqlite/SqliteTask.cs,
src/Backends/Sqlite/SqliteNote.cs,
src/Backends/Sqlite/SqliteBackend.cs, src/Backends/Rtm/RtmTask.cs,
src/Backends/Rtm/RtmNote.cs, src/Category.cs, src/Task.cs,
src/Database.cs, src/Note.cs, src/Makefile.am: Removed SQLite
Backend and moved it into src/LocalCache.cs. Created Note.cs,
Category.cs, and Task.cs that the UI will eventually use.
Added:
branches/cache/src/Category.cs
branches/cache/src/Database.cs
branches/cache/src/LocalCache.cs
branches/cache/src/Note.cs
branches/cache/src/Task.cs
Removed:
branches/cache/src/Backends/Sqlite/Database.cs
branches/cache/src/Backends/Sqlite/SqliteBackend.cs
branches/cache/src/Backends/Sqlite/SqliteCategory.cs
branches/cache/src/Backends/Sqlite/SqliteNote.cs
branches/cache/src/Backends/Sqlite/SqliteTask.cs
Modified:
branches/cache/ChangeLog
branches/cache/src/Application.cs
branches/cache/src/Backends/Rtm/RtmNote.cs
branches/cache/src/Backends/Rtm/RtmTask.cs
branches/cache/src/Makefile.am
branches/cache/tasque.mdp
branches/cache/tasque.mds
Modified: branches/cache/src/Application.cs
==============================================================================
--- branches/cache/src/Application.cs (original)
+++ branches/cache/src/Application.cs Fri Mar 14 20:19:15 2008
@@ -62,6 +62,7 @@
private EventBox eb;
private IBackend backend;
private PreferencesDialog preferencesDialog;
+ private LocalCache localCache;
/// <value>
/// Keep track of the available backends. The key is the Type name of
@@ -72,7 +73,7 @@
private IBackend customBackend;
public static IBackend Backend
- {
+ {
get { return Application.Instance.backend; }
set {
Application tasque = Application.Instance;
@@ -118,6 +119,11 @@
// get { return Application.Instance.availableBackends; }
}
+ public static LocalCache LocalCache
+ {
+ get { return Application.Instance.localCache; }
+ }
+
public static Application Instance
{
get {
@@ -295,6 +301,9 @@
private bool InitializeIdle()
{
+ localCache = new LocalCache ();
+ localCache.Initialize ();
+
if (customBackend != null) {
Application.Backend = customBackend;
} else {
Modified: branches/cache/src/Backends/Rtm/RtmNote.cs
==============================================================================
--- branches/cache/src/Backends/Rtm/RtmNote.cs (original)
+++ branches/cache/src/Backends/Rtm/RtmNote.cs Fri Mar 14 20:19:15 2008
@@ -12,9 +12,9 @@
{
public class RtmNote : INote
{
- Note note;
+ RtmNet.Note note;
- public RtmNote(Note note)
+ public RtmNote(RtmNet.Note note)
{
this.note = note;
if( (note.Title != null) && (note.Title.Length > 0) ) {
Modified: branches/cache/src/Backends/Rtm/RtmTask.cs
==============================================================================
--- branches/cache/src/Backends/Rtm/RtmTask.cs (original)
+++ branches/cache/src/Backends/Rtm/RtmTask.cs Fri Mar 14 20:19:15 2008
@@ -34,7 +34,7 @@
state = TaskState.Completed;
notes = new List<INote>();
- foreach(Note note in taskSeries.Notes.NoteCollection) {
+ foreach(RtmNet.Note note in taskSeries.Notes.NoteCollection) {
RtmNote rtmNote = new RtmNote(note);
notes.Add(rtmNote);
}
Added: branches/cache/src/Category.cs
==============================================================================
--- (empty file)
+++ branches/cache/src/Category.cs Fri Mar 14 20:19:15 2008
@@ -0,0 +1,67 @@
+// 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 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;
+ }
+
+ public bool ContainsTask(ITask task)
+ {
+ if(task.Category is Category)
+ return ((task.Category as Category).ID == id);
+
+ return false;
+ }
+
+ }
+}
Added: branches/cache/src/Database.cs
==============================================================================
--- (empty file)
+++ branches/cache/src/Database.cs Fri Mar 14 20:19:15 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/cache/src/LocalCache.cs
==============================================================================
--- (empty file)
+++ branches/cache/src/LocalCache.cs Fri Mar 14 20:19:15 2008
@@ -0,0 +1,302 @@
+// 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;
+
+ public event BackendInitializedHandler BackendInitialized;
+ public event BackendSyncStartedHandler BackendSyncStarted;
+ public event BackendSyncFinishedHandler BackendSyncFinished;
+
+ Category defaultCategory;
+ //Category workCategory;
+ //Category projectsCategory;
+
+ public LocalCache ()
+ {
+ initialized = false;
+ taskIters = new Dictionary<int, Gtk.TreeIter> ();
+ taskStore = new Gtk.TreeStore (typeof (Task));
+
+ 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 iter = taskStore.AppendNode ();
+ taskStore.SetValue (iter, 0, task);
+ taskIters [task.Id] = iter;
+
+ 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);
+
+
+ RefreshCategories();
+ RefreshTasks();
+
+
+ initialized = true;
+ if(BackendInitialized != null) {
+ BackendInitialized();
+ }
+ }
+
+ public void Cleanup()
+ {
+ this.categoryListStore.Clear();
+ this.taskStore.Clear();
+ this.taskIters.Clear();
+
+ db.Close();
+ db = null;
+ initialized = false;
+ }
+
+ public Gtk.Widget GetPreferencesWidget ()
+ {
+ // TODO: Replace this with returning null once things are going
+ // so that the Preferences Dialog doesn't waste space.
+ return new Gtk.Label ("Local file requires no configuration.");
+ }
+ #endregion // Public Methods
+
+ #region Private Methods
+ static int CompareTasksSortFunc (Gtk.TreeModel model,
+ Gtk.TreeIter a,
+ Gtk.TreeIter b)
+ {
+ Task taskA = model.GetValue (a, 0) as Task;
+ Task taskB = model.GetValue (b, 0) as Task;
+
+ if (taskA == null || taskB == null)
+ return 0;
+
+ return (taskA.CompareTo (taskB));
+ }
+
+ 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;
+
+ 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 {
+ taskStore.SetValue (iter, 0, 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;
+ Task newTask;
+ bool hasValues = false;
+
+ 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);
+ iter = taskStore.AppendNode();
+ taskStore.SetValue (iter, 0, newTask);
+ }
+
+ dataReader.Close();
+ cmd.Dispose();
+
+ if(!hasValues)
+ {
+ newTask = new Task (this, "Create some tasks");
+ newTask.Category = defaultCategory;
+ newTask.DueDate = DateTime.Now;
+ newTask.Priority = TaskPriority.Medium;
+ iter = taskStore.AppendNode ();
+ taskStore.SetValue (iter, 0, newTask);
+ taskIters [newTask.Id] = iter;
+ }
+ }
+
+ #endregion // Private Methods
+
+ #region Event Handlers
+ #endregion // Event Handlers
+ }
+}
Modified: branches/cache/src/Makefile.am
==============================================================================
--- branches/cache/src/Makefile.am (original)
+++ branches/cache/src/Makefile.am Fri Mar 14 20:19:15 2008
@@ -30,15 +30,6 @@
RTM_CSFILES =
endif
-if ENABLE_BACKEND_SQLITE
-SQLITE_CSFILES = \
- $(srcdir)/Backends/Sqlite/*.cs
-SQLITE_LIBS = -r:Mono.Data.Sqlite
-else
-SQLITE_CSFILES =
-SQLITE_LIBS =
-endif
-
if ENABLE_BACKEND_EDS
EDS_CSFILES = \
$(srcdir)/Backends/EDS/*.cs
@@ -50,20 +41,25 @@
$(srcdir)/AbstractTask.cs \
$(srcdir)/AllCategory.cs \
$(srcdir)/Application.cs \
+ $(srcdir)/Category.cs \
$(srcdir)/CellRendererDate.cs \
$(srcdir)/CompletedTaskGroup.cs \
+ $(srcdir)/Database.cs \
$(srcdir)/DateButton.cs \
$(srcdir)/IBackend.cs \
$(srcdir)/ICategory.cs \
$(srcdir)/ITask.cs \
$(srcdir)/INote.cs \
+ $(srcdir)/LocalCache.cs \
$(srcdir)/Logger.cs \
+ $(srcdir)/Note.cs \
$(srcdir)/NoteDialog.cs \
$(srcdir)/NoteWidget.cs \
$(srcdir)/Preferences.cs \
$(srcdir)/PreferencesDialog.cs \
$(srcdir)/RemoteControl.cs \
$(srcdir)/RemoteControlProxy.cs \
+ $(srcdir)/Task.cs \
$(srcdir)/TaskCalendar.cs \
$(srcdir)/TaskGroup.cs \
$(srcdir)/TaskPriority.cs \
@@ -79,8 +75,6 @@
\
$(ICECORE_CSFILES) \
\
- $(SQLITE_CSFILES) \
- \
$(EDS_CSFILES)
RESOURCES = \
@@ -108,6 +102,7 @@
-r:System \
-r:Mono.Posix \
-r:System.Xml \
+ -r:Mono.Data.Sqlite \
-r:$(top_builddir)/RtmNet/RtmNet \
$(GLIB_SHARP_20_LIBS) \
$(GNOME_SHARP_20_LIBS) \
@@ -116,7 +111,6 @@
$(NDESK_DBUS_10_LIBS) \
$(NDESK_DBUS_GLIB_10_LIBS) \
$(ICE_DESKTOP_LIBS) \
- $(SQLITE_LIBS) \
$(EVOLUTION_SHARP_LIBS)
$(TARGET): $(CSFILES) Defines.cs
Added: branches/cache/src/Note.cs
==============================================================================
--- (empty file)
+++ branches/cache/src/Note.cs Fri Mar 14 20:19:15 2008
@@ -0,0 +1,25 @@
+// Note.cs created with MonoDevelop
+// User: boyd at 1:34 PMÂ3/14/2008
+//
+
+using System;
+
+namespace Tasque
+{
+ public class Note
+ {
+ public string Name
+ {
+ get { return ""; }
+ set { // TODO: Implement something
+ }
+ }
+
+ public string Text
+ {
+ get { return ""; }
+ set { // TODO: Implement something
+ }
+ }
+ }
+}
Added: branches/cache/src/Task.cs
==============================================================================
--- (empty file)
+++ branches/cache/src/Task.cs Fri Mar 14 20:19:15 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
+ }
+}
Modified: branches/cache/tasque.mdp
==============================================================================
--- branches/cache/tasque.mdp (original)
+++ branches/cache/tasque.mdp Fri Mar 14 20:19:15 2008
@@ -55,13 +55,13 @@
<File name="src/Backends/IceCore/IceTask.cs" subtype="Code" buildaction="Compile" />
<File name="src/RemoteControl.cs" subtype="Code" buildaction="Compile" />
<File name="src/RemoteControlProxy.cs" subtype="Code" buildaction="Compile" />
- <File name="src/Backends/Sqlite/SqliteBackend.cs" subtype="Code" buildaction="Compile" />
- <File name="src/Backends/Sqlite/SqliteCategory.cs" subtype="Code" buildaction="Compile" />
- <File name="src/Backends/Sqlite/SqliteNote.cs" subtype="Code" buildaction="Compile" />
- <File name="src/Backends/Sqlite/SqliteTask.cs" subtype="Code" buildaction="Compile" />
- <File name="src/Backends/Sqlite/Database.cs" subtype="Code" buildaction="Compile" />
<File name="src/Backends/Rtm/RtmPreferencesWidget.cs" subtype="Code" buildaction="Compile" />
<File name="src/CompletedTaskGroup.cs" subtype="Code" buildaction="Compile" />
+ <File name="src/Task.cs" subtype="Code" buildaction="Compile" />
+ <File name="src/Note.cs" subtype="Code" buildaction="Compile" />
+ <File name="src/Category.cs" subtype="Code" buildaction="Compile" />
+ <File name="src/LocalCache.cs" subtype="Code" buildaction="Compile" />
+ <File name="src/Database.cs" subtype="Code" buildaction="Compile" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="True" refto="glib-sharp, Version=2.10.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
@@ -86,4 +86,4 @@
<AsmRefVar />
<ProjectRefVar />
</MonoDevelop.Autotools.MakefileInfo>
-</Project>
+</Project>
\ No newline at end of file
Modified: branches/cache/tasque.mds
==============================================================================
--- branches/cache/tasque.mds (original)
+++ branches/cache/tasque.mds Fri Mar 14 20:19:15 2008
@@ -18,4 +18,4 @@
<Entry filename="tasque.mdp" />
<Entry filename="RtmNet/RtmNet.mdp" />
</Entries>
-</Combine>
+</Combine>
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]