Enhancements - delete, start

- Implemented delete command.
- Implemented start command.
This commit is contained in:
Paul Beckingham 2009-06-15 23:47:42 -04:00
parent 6e6f86783f
commit 1551362d1e
3 changed files with 83 additions and 52 deletions

View file

@ -32,8 +32,11 @@
#include "util.h"
#include "Date.h"
#include "Duration.h"
#include "Context.h"
#include "Att.h"
extern Context context;
static const char* internalNames[] =
{
"entry",
@ -42,6 +45,8 @@ static const char* internalNames[] =
"mask",
"imask",
// "limit",
"status",
"description",
};
static const char* modifiableNames[] =
@ -347,15 +352,18 @@ bool Att::validNameValue (
throw std::string ("The '") + name + "' attribute must be an integer.";
}
// Some attributes are intended to be private.
// Some attributes are intended to be private, unless the command is read-
// only, in which cased these are perfectly valid elements of a filter.
else if (name == "entry" ||
name == "start" ||
name == "end" ||
name == "mask" ||
name == "imask" ||
name == "uuid" ||
name == "status")
name == "status" ||
name == "description")
{
if (context.cmd.isWriteCommand ())
throw std::string ("\"") +
name +
"\" is not an attribute you may modify directly.";

View file

@ -186,9 +186,13 @@ std::string Context::dispatch ()
else if (cmd.command == "done") { out = handleDone (); }
/*
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 == "export") { out = handleExport (); }

View file

@ -423,49 +423,53 @@ std::string handleVersion ()
std::string handleDelete ()
{
std::stringstream out;
/*
std::vector <T> all;
tdb.allPendingT (all);
filterSequence (all, task);
std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true));
context.tdb.loadPending (tasks, context.filter);
handleRecurrence (tasks);
// Filter sequence.
context.filter.applySequence (tasks, context.sequence);
// Determine the end date.
char endTime[16];
sprintf (endTime, "%u", (unsigned int) time (NULL));
foreach (t, all)
foreach (task, tasks)
{
std::stringstream question;
question << "Permanently delete task "
<< t->getId ()
<< task->id
<< " '"
<< t->getDescription ()
<< task->get ("description")
<< "'?";
if (!context.config.get (std::string ("confirmation"), false) || confirm (question.str ()))
{
// Check for the more complex case of a recurring task. If this is a
// recurring task, get confirmation to delete them all.
std::string parent = t->getAttribute ("parent");
std::string parent = task->get ("parent");
if (parent != "")
{
if (confirm ("This is a recurring task. Do you want to delete all pending recurrences of this same task?"))
{
// Scan all pending tasks for siblings of this task, and the parent
// itself, and delete them.
foreach (sibling, all)
foreach (sibling, tasks)
{
if (sibling->getAttribute ("parent") == parent ||
sibling->getUUID () == parent)
if (sibling->get ("parent") == parent ||
sibling->get ("uuid") == parent)
{
sibling->setStatus (T::deleted);
sibling->setAttribute ("end", endTime);
tdb.modifyT (*sibling);
sibling->setStatus (Task::deleted);
sibling->set ("end", endTime);
context.tdb.update (*sibling);
if (context.config.get ("echo.command", true))
out << "Deleting recurring task "
<< sibling->getId ()
<< sibling->id
<< " '"
<< sibling->getDescription ()
<< sibling->get ("description")
<< "'"
<< std::endl;
}
@ -474,31 +478,31 @@ std::string handleDelete ()
else
{
// Update mask in parent.
t->setStatus (T::deleted);
updateRecurrenceMask (tdb, all, *t);
task->setStatus (Task::deleted);
updateRecurrenceMask (tasks, *task);
t->setAttribute ("end", endTime);
tdb.modifyT (*t);
task->set ("end", endTime);
context.tdb.update (*task);
out << "Deleting recurring task "
<< t->getId ()
<< task->id
<< " '"
<< t->getDescription ()
<< task->get ("description")
<< "'"
<< std::endl;
}
}
else
{
t->setStatus (T::deleted);
t->setAttribute ("end", endTime);
tdb.modifyT (*t);
task->setStatus (Task::deleted);
task->set ("end", endTime);
context.tdb.update (*task);
if (context.config.get ("echo.command", true))
out << "Deleting task "
<< t->getId ()
<< task->id
<< " '"
<< t->getDescription ()
<< task->get ("description")
<< "'"
<< std::endl;
}
@ -506,7 +510,10 @@ std::string handleDelete ()
else
out << "Task not deleted." << std::endl;
}
*/
context.tdb.commit ();
context.tdb.unlock ();
return out.str ();
}
@ -514,36 +521,48 @@ std::string handleDelete ()
std::string handleStart ()
{
std::stringstream out;
/*
std::vector <T> all;
tdb.pendingT (all);
filterSequence (all, task);
foreach (t, all)
std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true));
context.tdb.loadPending (tasks, context.filter);
handleRecurrence (tasks);
// Filter sequence.
context.filter.applySequence (tasks, context.sequence);
foreach (task, tasks)
{
if (t->getAttribute ("start") == "")
if (! task->has ("start"))
{
char startTime[16];
sprintf (startTime, "%u", (unsigned int) time (NULL));
t->setAttribute ("start", startTime);
task->set ("start", startTime);
tdb.modifyT (*t);
context.tdb.update (*task);
if (context.config.get ("echo.command", true))
out << "Started "
<< t->getId ()
<< task->id
<< " '"
<< t->getDescription ()
<< task->get ("description")
<< "'"
<< std::endl;
nag (tdb, task);
nag (*task);
}
else
{
out << "Task " << t->getId () << " '" << t->getDescription () << "' already started." << std::endl;
out << "Task "
<< task->id
<< " '"
<< task->get ("description")
<< "' already started."
<< std::endl;
}
}
*/
context.tdb.commit ();
context.tdb.unlock ();
return out.str ();
}