Enhancement - done command

- Implemented done command.
This commit is contained in:
Paul Beckingham 2009-06-15 11:27:50 -04:00
parent c65b6e9f48
commit 9f1880e050
5 changed files with 39 additions and 33 deletions

View file

@ -182,12 +182,14 @@ std::string Context::dispatch ()
else if (cmd.command == "append") { out = handleAppend (); } else if (cmd.command == "append") { out = handleAppend (); }
/* /*
else if (cmd.command == "annotate") { out = handleAnnotate (); } else if (cmd.command == "annotate") { out = handleAnnotate (); }
*/
else if (cmd.command == "done") { out = handleDone (); } 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 == "delete") { out = handleDelete (); }
else if (cmd.command == "undelete") { out = handleUndelete (); }
else if (cmd.command == "start") { out = handleStart (); } else if (cmd.command == "start") { out = handleStart (); }
else if (cmd.command == "stop") { out = handleStop (); } else if (cmd.command == "stop") { out = handleStop (); }
else if (cmd.command == "undo") { out = handleUndo (); }
*/ */
else if (cmd.command == "export") { out = handleExport (); } else if (cmd.command == "export") { out = handleExport (); }
/* /*

View file

@ -109,7 +109,6 @@ void TDB::lock (bool lockFile /* = true */)
mLock = lockFile; mLock = lockFile;
mPending.clear (); mPending.clear ();
// mCompleted.clear ();
mNew.clear (); mNew.clear ();
mPending.clear (); mPending.clear ();
@ -128,7 +127,6 @@ void TDB::unlock ()
if (mAllOpenAndLocked) if (mAllOpenAndLocked)
{ {
mPending.clear (); mPending.clear ();
// mCompleted.clear ();
mNew.clear (); mNew.clear ();
mModified.clear (); mModified.clear ();
@ -238,7 +236,6 @@ int TDB::loadCompleted (std::vector <Task>& tasks, Filter& filter)
Task task (line); Task task (line);
task.id = mId++; task.id = mId++;
// mCompleted.push_back (task);
if (filter.pass (task)) if (filter.pass (task))
tasks.push_back (task); tasks.push_back (task);
} }

View file

@ -69,7 +69,6 @@ private:
int mId; int mId;
std::vector <Task> mPending; // Contents of pending.data std::vector <Task> mPending; // Contents of pending.data
// std::vector <Task> mCompleted; // Contents of completed.data
std::vector <Task> mNew; // Uncommitted new tasks std::vector <Task> mNew; // Uncommitted new tasks
std::vector <Task> mModified; // Uncommitted modified tasks std::vector <Task> mModified; // Uncommitted modified tasks

View file

@ -24,6 +24,7 @@
// USA // USA
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>
@ -577,59 +578,66 @@ std::string handleStop ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string handleDone () std::string handleDone ()
{ {
/*
int count = 0; int count = 0;
*/
std::stringstream out; std::stringstream out;
/*
std::vector <T> all;
tdb.allPendingT (all);
std::vector <T> filtered = all; std::vector <Task> tasks;
filterSequence (filtered, task); context.tdb.lock (context.config.get ("locking", true));
foreach (seq, filtered) context.tdb.loadPending (tasks, context.filter);
handleRecurrence (tasks);
// Filter sequence.
std::vector <Task> all = tasks;
context.filter.applySequence (tasks, context.sequence);
foreach (task, tasks)
{ {
if (seq->getStatus () == T::pending) if (task->getStatus () == Task::pending)
{ {
// Apply deltas. // Apply deltas.
deltaDescription (*seq, task); deltaDescription (*task);
deltaTags (*seq, task); context.task.remove ("description");
deltaAttributes (*seq, task);
deltaSubstitutions (*seq, task); deltaTags (*task);
context.task.remove ("tags");
deltaAttributes (*task);
deltaSubstitutions (*task);
// Add an end date. // Add an end date.
char entryTime[16]; char entryTime[16];
sprintf (entryTime, "%u", (unsigned int) time (NULL)); sprintf (entryTime, "%u", (unsigned int) time (NULL));
seq->setAttribute ("end", entryTime); task->set ("end", entryTime);
// Change status. // Change status.
seq->setStatus (T::completed); task->setStatus (Task::completed);
context.tdb.update (*task);
if (!tdb.modifyT (*seq))
throw std::string ("Could not mark task as completed.");
if (context.config.get ("echo.command", true)) if (context.config.get ("echo.command", true))
out << "Completed " out << "Completed "
<< seq->getId () << task->id
<< " '" << " '"
<< seq->getDescription () << task->get ("description")
<< "'" << "'"
<< std::endl; << std::endl;
updateRecurrenceMask (tdb, all, *seq); updateRecurrenceMask (all, *task);
nag (tdb, *seq); nag (*task);
++count; ++count;
} }
else else
out << "Task " out << "Task "
<< seq->getId () << task->id
<< " '" << " '"
<< seq->getDescription () << task->get ("description")
<< "' is not pending" << "' is not pending"
<< std::endl; << std::endl;
} }
context.tdb.commit ();
context.tdb.unlock ();
if (context.config.get ("echo.command", true)) if (context.config.get ("echo.command", true))
out << "Marked " out << "Marked "
<< count << count
@ -637,7 +645,7 @@ std::string handleDone ()
<< (count == 1 ? "" : "s") << (count == 1 ? "" : "s")
<< " as done" << " as done"
<< std::endl; << std::endl;
*/
return out.str (); return out.str ();
} }

View file

@ -48,9 +48,9 @@ void onChangeCallback ();
void handleRecurrence (std::vector <Task>&); void handleRecurrence (std::vector <Task>&);
Date getNextRecurrence (Date&, std::string&); Date getNextRecurrence (Date&, std::string&);
bool generateDueDates (Task&, std::vector <Date>&); bool generateDueDates (Task&, std::vector <Date>&);
void updateRecurrenceMask (/*TDB&,*/ std::vector <Task>&, Task&); void updateRecurrenceMask (std::vector <Task>&, Task&);
int getDueState (const std::string&); int getDueState (const std::string&);
void nag (/*TDB&,*/ Task&); void nag (Task&);
// command.cpp // command.cpp
std::string handleAdd (); std::string handleAdd ();