From 9f1880e0506bb231fcfc9a8107c7eb500d3705cf Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 15 Jun 2009 11:27:50 -0400 Subject: [PATCH] Enhancement - done command - Implemented done command. --- src/Context.cpp | 6 +++-- src/TDB.cpp | 3 --- src/TDB.h | 1 - src/command.cpp | 58 ++++++++++++++++++++++++++++--------------------- src/main.h | 4 ++-- 5 files changed, 39 insertions(+), 33 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index a3964ad24..4abdb60e6 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -182,12 +182,14 @@ std::string Context::dispatch () else if (cmd.command == "append") { out = handleAppend (); } /* else if (cmd.command == "annotate") { out = handleAnnotate (); } +*/ else if (cmd.command == "done") { out = handleDone (); } - else if (cmd.command == "undelete") { out = handleUndelete (); } +/* + else if (cmd.command == "undo") { out = handleUndo (); } else if (cmd.command == "delete") { out = handleDelete (); } + else if (cmd.command == "undelete") { out = handleUndelete (); } else if (cmd.command == "start") { out = handleStart (); } else if (cmd.command == "stop") { out = handleStop (); } - else if (cmd.command == "undo") { out = handleUndo (); } */ else if (cmd.command == "export") { out = handleExport (); } /* diff --git a/src/TDB.cpp b/src/TDB.cpp index 278b2414f..ba0de0f27 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -109,7 +109,6 @@ void TDB::lock (bool lockFile /* = true */) mLock = lockFile; mPending.clear (); -// mCompleted.clear (); mNew.clear (); mPending.clear (); @@ -128,7 +127,6 @@ void TDB::unlock () if (mAllOpenAndLocked) { mPending.clear (); -// mCompleted.clear (); mNew.clear (); mModified.clear (); @@ -238,7 +236,6 @@ int TDB::loadCompleted (std::vector & tasks, Filter& filter) Task task (line); task.id = mId++; -// mCompleted.push_back (task); if (filter.pass (task)) tasks.push_back (task); } diff --git a/src/TDB.h b/src/TDB.h index 2f79ce389..7d86ab833 100644 --- a/src/TDB.h +++ b/src/TDB.h @@ -69,7 +69,6 @@ private: int mId; std::vector mPending; // Contents of pending.data -// std::vector mCompleted; // Contents of completed.data std::vector mNew; // Uncommitted new tasks std::vector mModified; // Uncommitted modified tasks diff --git a/src/command.cpp b/src/command.cpp index 1775af503..459f53fdc 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -24,6 +24,7 @@ // USA // //////////////////////////////////////////////////////////////////////////////// + #include #include #include @@ -577,59 +578,66 @@ std::string handleStop () //////////////////////////////////////////////////////////////////////////////// std::string handleDone () { -/* int count = 0; -*/ std::stringstream out; -/* - std::vector all; - tdb.allPendingT (all); - std::vector filtered = all; - filterSequence (filtered, task); - foreach (seq, filtered) + std::vector tasks; + context.tdb.lock (context.config.get ("locking", true)); + context.tdb.loadPending (tasks, context.filter); + handleRecurrence (tasks); + + // Filter sequence. + std::vector all = tasks; + context.filter.applySequence (tasks, context.sequence); + + foreach (task, tasks) { - if (seq->getStatus () == T::pending) + if (task->getStatus () == Task::pending) { // Apply deltas. - deltaDescription (*seq, task); - deltaTags (*seq, task); - deltaAttributes (*seq, task); - deltaSubstitutions (*seq, task); + deltaDescription (*task); + context.task.remove ("description"); + + deltaTags (*task); + context.task.remove ("tags"); + + deltaAttributes (*task); + deltaSubstitutions (*task); // Add an end date. char entryTime[16]; sprintf (entryTime, "%u", (unsigned int) time (NULL)); - seq->setAttribute ("end", entryTime); + task->set ("end", entryTime); // Change status. - seq->setStatus (T::completed); - - if (!tdb.modifyT (*seq)) - throw std::string ("Could not mark task as completed."); + task->setStatus (Task::completed); + context.tdb.update (*task); if (context.config.get ("echo.command", true)) out << "Completed " - << seq->getId () + << task->id << " '" - << seq->getDescription () + << task->get ("description") << "'" << std::endl; - updateRecurrenceMask (tdb, all, *seq); - nag (tdb, *seq); + updateRecurrenceMask (all, *task); + nag (*task); ++count; } else out << "Task " - << seq->getId () + << task->id << " '" - << seq->getDescription () + << task->get ("description") << "' is not pending" << std::endl; } + context.tdb.commit (); + context.tdb.unlock (); + if (context.config.get ("echo.command", true)) out << "Marked " << count @@ -637,7 +645,7 @@ std::string handleDone () << (count == 1 ? "" : "s") << " as done" << std::endl; -*/ + return out.str (); } diff --git a/src/main.h b/src/main.h index d630c7385..9f496caaa 100644 --- a/src/main.h +++ b/src/main.h @@ -48,9 +48,9 @@ void onChangeCallback (); void handleRecurrence (std::vector &); Date getNextRecurrence (Date&, std::string&); bool generateDueDates (Task&, std::vector &); -void updateRecurrenceMask (/*TDB&,*/ std::vector &, Task&); +void updateRecurrenceMask (std::vector &, Task&); int getDueState (const std::string&); -void nag (/*TDB&,*/ Task&); +void nag (Task&); // command.cpp std::string handleAdd ();