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 == "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 (); }
/*

View file

@ -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 <Task>& tasks, Filter& filter)
Task task (line);
task.id = mId++;
// mCompleted.push_back (task);
if (filter.pass (task))
tasks.push_back (task);
}

View file

@ -69,7 +69,6 @@ private:
int mId;
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> mModified; // Uncommitted modified tasks

View file

@ -24,6 +24,7 @@
// USA
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <iomanip>
#include <sstream>
@ -577,59 +578,66 @@ std::string handleStop ()
////////////////////////////////////////////////////////////////////////////////
std::string handleDone ()
{
/*
int count = 0;
*/
std::stringstream out;
/*
std::vector <T> all;
tdb.allPendingT (all);
std::vector <T> filtered = all;
filterSequence (filtered, task);
foreach (seq, filtered)
std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true));
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.
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 ();
}

View file

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