From 1551362d1e9edd192e3e76217a83c58ae85e21e9 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 15 Jun 2009 23:47:42 -0400 Subject: [PATCH] Enhancements - delete, start - Implemented delete command. - Implemented start command. --- src/Att.cpp | 30 ++++++++------ src/Context.cpp | 4 ++ src/command.cpp | 101 ++++++++++++++++++++++++++++-------------------- 3 files changed, 83 insertions(+), 52 deletions(-) diff --git a/src/Att.cpp b/src/Att.cpp index eed8e98d3..36d916c76 100644 --- a/src/Att.cpp +++ b/src/Att.cpp @@ -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,18 +352,21 @@ bool Att::validNameValue ( throw std::string ("The '") + name + "' attribute must be an integer."; } - // Some attributes are intended to be private. - else if (name == "entry" || - name == "start" || - name == "end" || - name == "mask" || - name == "imask" || - name == "uuid" || - name == "status") + // 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 == "description") { - throw std::string ("\"") + - name + - "\" is not an attribute you may modify directly."; + if (context.cmd.isWriteCommand ()) + throw std::string ("\"") + + name + + "\" is not an attribute you may modify directly."; } else diff --git a/src/Context.cpp b/src/Context.cpp index ee5a4b795..42eb61290 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -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 (); } diff --git a/src/command.cpp b/src/command.cpp index 459f53fdc..7c09304fc 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -423,49 +423,53 @@ std::string handleVersion () std::string handleDelete () { std::stringstream out; -/* - std::vector all; - tdb.allPendingT (all); - filterSequence (all, task); + + std::vector 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 all; - tdb.pendingT (all); - filterSequence (all, task); - foreach (t, all) + std::vector 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 (); }