From 3d1a5acafb6eb41a0ef9f464a0d458d02f7a0da1 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 3 Sep 2011 11:17:12 -0400 Subject: [PATCH] TDB2 - Implemented high-level TDB2::id and TDB2:uuid that delegates to TF2. - Fixed a bug in TDB2::modify that failed to properly overwrite a task. --- src/TDB2.cpp | 53 +++++++++++++++++++++++++++++++++++++++------------- src/TDB2.h | 4 ++++ 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/TDB2.cpp b/src/TDB2.cpp index dc94def2f..ad3207a6f 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -156,11 +156,15 @@ void TF2::modify_task (const Task& task) // std::cout << "# TF2::modify_task " << _file._data << "\n"; // Modify in-place. + std::string uuid = task.get ("uuid"); std::vector ::iterator i; for (i = _tasks.begin (); i != _tasks.end (); ++i) { - if (i->get ("uuid") == task.get ("uuid")) + if (i->get ("uuid") == uuid) { +// std::cout << "# TF2::modify_task overwriting:\n" +// << "# old " << i->composeF4 () +// << "# new " << task.composeF4 (); *i = task; break; } @@ -546,22 +550,26 @@ void TDB2::modify (Task& task) // Ensure the task is consistent, and provide defaults if necessary. task.validate (); - // Update task in either completed or deleted. - // TODO Find task, overwrite it. - std::string status = task.get ("status"); - if (status == "completed" || - status == "deleted") - completed.modify_task (task); - else + // Find task, overwrite it. + Task original; + get (task.get ("uuid"), original); + + std::string status = original.get ("status"); + if (status == "pending" || + status == "waiting" || + status == "recurring") + { pending.modify_task (task); + } + else + { + completed.modify_task (task); + } // time