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 "util.h"
#include "Date.h" #include "Date.h"
#include "Duration.h" #include "Duration.h"
#include "Context.h"
#include "Att.h" #include "Att.h"
extern Context context;
static const char* internalNames[] = static const char* internalNames[] =
{ {
"entry", "entry",
@ -42,6 +45,8 @@ static const char* internalNames[] =
"mask", "mask",
"imask", "imask",
// "limit", // "limit",
"status",
"description",
}; };
static const char* modifiableNames[] = static const char* modifiableNames[] =
@ -347,15 +352,18 @@ bool Att::validNameValue (
throw std::string ("The '") + name + "' attribute must be an integer."; 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" || else if (name == "entry" ||
name == "start" || name == "start" ||
name == "end" || name == "end" ||
name == "mask" || name == "mask" ||
name == "imask" || name == "imask" ||
name == "uuid" || name == "uuid" ||
name == "status") name == "status" ||
name == "description")
{ {
if (context.cmd.isWriteCommand ())
throw std::string ("\"") + throw std::string ("\"") +
name + name +
"\" is not an attribute you may modify directly."; "\" 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 == "done") { out = handleDone (); }
/* /*
else if (cmd.command == "undo") { out = handleUndo (); } 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 == "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 == "export") { out = handleExport (); } else if (cmd.command == "export") { out = handleExport (); }

View file

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