[tasque/transition: 200/213] [libtasque] Backend: Change CreateTask method to only do creation of task
- From: Antonius Riha <antoniusri src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tasque/transition: 200/213] [libtasque] Backend: Change CreateTask method to only do creation of task
- Date: Wed, 29 Aug 2012 18:50:50 +0000 (UTC)
commit 6db110b3dd89f5b3295b26d5c49569af88535657
Author: Antonius Riha <antoniusriha gmail com>
Date: Sun Aug 19 17:52:50 2012 +0200
[libtasque] Backend: Change CreateTask method to only do creation of task
Create task should not add the new task to any category. The new usage of
of this API is:
var task = backend.CreateTask (taskName);
category.Add (task);
src/Addins/DummyBackend/DummyBackend.cs | 34 ++++++++++++++++++----------
src/Addins/SqliteBackend/SqliteBackend.cs | 16 +++++--------
src/Addins/SqliteBackend/SqliteTask.cs | 4 +-
src/Tasque.Gtk/TaskWindow.cs | 3 +-
src/libtasque/Backend.cs | 33 +---------------------------
5 files changed, 33 insertions(+), 57 deletions(-)
---
diff --git a/src/Addins/DummyBackend/DummyBackend.cs b/src/Addins/DummyBackend/DummyBackend.cs
index 7def4f3..b0276de 100644
--- a/src/Addins/DummyBackend/DummyBackend.cs
+++ b/src/Addins/DummyBackend/DummyBackend.cs
@@ -76,41 +76,51 @@ namespace Tasque.Backends.Dummy
//
// Add in some fake tasks
//
- var task = CreateTask ("Buy some nails", projectsCategory);
+ var task = CreateTask ("Buy some nails");
task.DueDate = DateTime.Now.AddDays (1);
task.Priority = TaskPriority.Medium;
+ projectsCategory.Add (task);
- task = CreateTask ("Call Roger", homeCategory);
+ task = CreateTask ("Call Roger");
task.DueDate = DateTime.Now.AddDays (-1);
task.Complete ();
- task.CompletionDate = task.DueDate;
+ homeCategory.Add (task);
- task = CreateTask ("Replace burnt out lightbulb", homeCategory);
+ task = CreateTask ("Replace burnt out lightbulb");
task.DueDate = DateTime.Now;
task.Priority = TaskPriority.Low;
+ homeCategory.Add (task);
- task = CreateTask ("File taxes", homeCategory);
+ task = CreateTask ("File taxes");
task.DueDate = new DateTime (2008, 4, 1);
+ homeCategory.Add (task);
- task = CreateTask ("Purchase lumber", projectsCategory);
+ task = CreateTask ("Purchase lumber");
task.DueDate = DateTime.Now.AddDays (1);
task.Priority = TaskPriority.High;
-
- task = CreateTask ("Estimate drywall requirements", new Category [] { projectsCategory, workCategory });
+ projectsCategory.Add (task);
+
+ task = CreateTask ("Estimate drywall requirements");
task.DueDate = DateTime.Now.AddDays (1);
task.Priority = TaskPriority.Low;
+ projectsCategory.Add (task);
+ workCategory.Add (task);
- task = CreateTask ("Borrow framing nailer from Ben", new Category [] { projectsCategory, homeCategory });
+ task = CreateTask ("Borrow framing nailer from Ben");
task.DueDate = DateTime.Now.AddDays (1);
task.Priority = TaskPriority.High;
+ projectsCategory.Add (task);
+ homeCategory.Add (task);
- task = CreateTask ("Call for an insulation estimate", projectsCategory);
+ task = CreateTask ("Call for an insulation estimate");
task.DueDate = DateTime.Now.AddDays (1);
task.Priority = TaskPriority.Medium;
+ projectsCategory.Add (task);
- task = CreateTask ("Pay storage rental fee", homeCategory);
+ task = CreateTask ("Pay storage rental fee");
task.DueDate = DateTime.Now.AddDays (1);
task.Priority = TaskPriority.None;
+ homeCategory.Add (task);
task = new DummyTask ("Place carpet order");
projectsCategory.Add (task);
@@ -136,7 +146,7 @@ namespace Tasque.Backends.Dummy
}
#endregion
- protected override Task CreateTaskCore (string taskName, IEnumerable<Category> categories)
+ public override Task CreateTask (string taskName)
{
return new DummyTask (taskName);
}
diff --git a/src/Addins/SqliteBackend/SqliteBackend.cs b/src/Addins/SqliteBackend/SqliteBackend.cs
index e1d1e68..96b0bc3 100644
--- a/src/Addins/SqliteBackend/SqliteBackend.cs
+++ b/src/Addins/SqliteBackend/SqliteBackend.cs
@@ -35,15 +35,9 @@ namespace Tasque.Backends.Sqlite
}
}
- protected override Task CreateTaskCore (string taskName, IEnumerable<Category> categories)
+ public override Task CreateTask (string taskName)
{
- var index = 0;
- foreach (var cat in Categories) {
- if (cat == categories.ElementAt (0))
- break;
- index++;
- }
- return new SqliteTask (this, taskName, index);
+ return new SqliteTask (this, taskName);
}
protected override void OnDeleteTask (Task task)
@@ -157,8 +151,10 @@ namespace Tasque.Backends.Sqlite
dataReader.Close ();
cmd.Dispose ();
- if (!hasValues)
- CreateTask (Catalog.GetString ("Create some tasks"), DefaultCategory);
+ if (!hasValues) {
+ var task = CreateTask (Catalog.GetString ("Create some tasks"));
+ defaultCategory.Add (task);
+ }
}
Category defaultCategory;
diff --git a/src/Addins/SqliteBackend/SqliteTask.cs b/src/Addins/SqliteBackend/SqliteTask.cs
index 1b67d53..c6ec0c0 100644
--- a/src/Addins/SqliteBackend/SqliteTask.cs
+++ b/src/Addins/SqliteBackend/SqliteTask.cs
@@ -7,7 +7,7 @@ namespace Tasque.Backends.Sqlite
{
public class SqliteTask : Task
{
- public SqliteTask (SqliteBackend backend, string name, int category)
+ public SqliteTask (SqliteBackend backend, string name)
: base (backend.SanitizeText (name), TaskNoteSupport.Multiple)
{
if (backend == null)
@@ -21,7 +21,7 @@ namespace Tasque.Backends.Sqlite
var priority = (int)Priority;
var state = (int)State;
var command = string.Format ("INSERT INTO Tasks (Name, DueDate, CompletionDate, Priority, State, Category, ExternalID) values ('{0}','{1}', '{2}','{3}', '{4}', '{5}', '{6}'); SELECT last_insert_rowid();",
- name, dueDate, completionDate, priority, state, category, string.Empty);
+ name, dueDate, completionDate, priority, state, 0, string.Empty);
id = Convert.ToInt32 (backend.Database.ExecuteScalar (command));
}
diff --git a/src/Tasque.Gtk/TaskWindow.cs b/src/Tasque.Gtk/TaskWindow.cs
index 7bb1b46..33721b5 100644
--- a/src/Tasque.Gtk/TaskWindow.cs
+++ b/src/Tasque.Gtk/TaskWindow.cs
@@ -766,7 +766,8 @@ namespace Tasque
private Task CreateTask (string taskText, Category category)
{
- Task task = backend.CreateTask (taskText, category);
+ Task task = backend.CreateTask (taskText);
+ category.Add (task);
if (task == null) {
Debug.WriteLine ("Error creating a new task!");
diff --git a/src/libtasque/Backend.cs b/src/libtasque/Backend.cs
index 5f75579..172c7c3 100644
--- a/src/libtasque/Backend.cs
+++ b/src/libtasque/Backend.cs
@@ -122,36 +122,7 @@ namespace Tasque
/// <summary>
/// Create a new task.
/// </summary>
- public Task CreateTask (string taskName, Category category)
- {
- return CreateTask (taskName, new Category [] { category });
- }
-
- public Task CreateTask (string taskName, IEnumerable<Category> categories)
- {
- if (taskName == null)
- throw new ArgumentNullException ("taskName");
- if (categories == null)
- throw new ArgumentNullException ("categories");
-
- var task = CreateTaskCore (taskName, categories);
-
- bool isEmpty = true;
- foreach (var item in categories) {
- Category cat = item;
- if (item == null)
- cat = DefaultCategory;
-
- cat.Add (task);
- isEmpty = false;
- }
-
- if (isEmpty)
- throw new ArgumentException ("This backend doesn't contain a category. Hence it's " +
- "impossible to add an item.", "categories");
-
- return task;
- }
+ public abstract Task CreateTask (string taskName);
public void DeleteTask (Task task)
{
@@ -175,8 +146,6 @@ namespace Tasque
/// Refreshes the backend.
/// </summary>
public virtual void Refresh () {}
-
- protected abstract Task CreateTaskCore (string taskName, IEnumerable<Category> categories);
protected void OnBackendInitialized () {
if (BackendInitialized != null)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]