From 4d43b77441e389325f2046fe6b3ef54f8f07aa86 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Thu, 18 Jun 2009 00:02:12 -0400 Subject: [PATCH] Enhancement - recurring tasks - Implemented handleRecurringTasks. - Implemented TDB::nextId. --- src/TDB.cpp | 7 +++++ src/TDB.h | 1 + src/custom.cpp | 1 + src/recur.cpp | 74 ++++++++++++++++++++++++-------------------------- 4 files changed, 44 insertions(+), 39 deletions(-) diff --git a/src/TDB.cpp b/src/TDB.cpp index 790f3006b..4e475c74e 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -196,6 +196,7 @@ int TDB::loadPending (std::vector & tasks, Filter& filter) try { + mId = 1; char line[T_LINE_MAX]; foreach (location, mLocations) { @@ -425,6 +426,12 @@ int TDB::gc () return count; } +//////////////////////////////////////////////////////////////////////////////// +int TDB::nextId () +{ + return mId++; +} + //////////////////////////////////////////////////////////////////////////////// FILE* TDB::openAndLock (const std::string& file) { diff --git a/src/TDB.h b/src/TDB.h index 7d86ab833..29ba29928 100644 --- a/src/TDB.h +++ b/src/TDB.h @@ -58,6 +58,7 @@ public: int commit (); // Write out all tasks void upgrade (); // Convert both files to FF4 int gc (); // Clean up pending + int nextId (); private: FILE* openAndLock (const std::string&); diff --git a/src/custom.cpp b/src/custom.cpp index 64131f5d3..48610052b 100644 --- a/src/custom.cpp +++ b/src/custom.cpp @@ -87,6 +87,7 @@ std::string handleCustomReport (const std::string& report) // TODO Include filter from custom report. context.tdb.load (tasks, context.filter); handleRecurrence (tasks); + context.tdb.commit (); context.tdb.unlock (); // Filter sequence. diff --git a/src/recur.cpp b/src/recur.cpp index a8ceb24b6..37b009bba 100644 --- a/src/recur.cpp +++ b/src/recur.cpp @@ -55,13 +55,12 @@ extern Context context; // child tasks need to be generated to fill gaps. void handleRecurrence (std::vector & tasks) { -/* - std::vector modified; + std::vector modified; // Look at all tasks and find any recurring ones. foreach (t, tasks) { - if (t->getStatus () == T::recurring) + if (t->getStatus () == Task::recurring) { // Generate a list of due dates for this recurring task, regardless of // the mask. @@ -69,22 +68,23 @@ void handleRecurrence (std::vector & tasks) if (!generateDueDates (*t, due)) { std::cout << "Task " - << t->getUUID () + << t->get ("uuid") << " (" - << trim (t->getDescription ()) - << ") is past its 'until' date, and has be deleted" << std::endl; + << trim (t->get ("description")) + << ") is past its 'until' date, and has been deleted" + << std::endl; // Determine the end date. char endTime[16]; sprintf (endTime, "%u", (unsigned int) time (NULL)); - t->setAttribute ("end", endTime); - t->setStatus (T::deleted); - tdb.modifyT (*t); + t->set ("end", endTime); + t->setStatus (Task::deleted); + context.tdb.update (*t); continue; } // Get the mask from the parent task. - std::string mask = t->getAttribute ("mask"); + std::string mask = t->get ("mask"); // Iterate over the due dates, and check each against the mask. bool changed = false; @@ -96,25 +96,25 @@ void handleRecurrence (std::vector & tasks) mask += '-'; changed = true; - T rec (*t); // Clone the parent. - rec.setId (tdb.nextId ()); // Assign a unique id. - rec.setUUID (uuid ()); // New UUID. - rec.setStatus (T::pending); // Shiny. - rec.setAttribute ("parent", t->getUUID ()); // Remember mom. + Task rec (*t); // Clone the parent. + rec.id = context.tdb.nextId (); // Assign a unique id. + rec.set ("uuid", uuid ()); // New UUID. + rec.setStatus (Task::pending); // Shiny. + rec.set ("parent", t->get ("uuid")); // Remember mom. char dueDate[16]; sprintf (dueDate, "%u", (unsigned int) d->toEpoch ()); - rec.setAttribute ("due", dueDate); // Store generated due date. + rec.set ("due", dueDate); // Store generated due date. char indexMask[12]; sprintf (indexMask, "%u", (unsigned int) i); - rec.setAttribute ("imask", indexMask); // Store index into mask. + rec.set ("imask", indexMask); // Store index into mask. // Add the new task to the vector, for immediate use. modified.push_back (rec); // Add the new task to the DB. - tdb.addT (rec); + context.tdb.add (rec); } ++i; @@ -123,8 +123,8 @@ void handleRecurrence (std::vector & tasks) // Only modify the parent if necessary. if (changed) { - t->setAttribute ("mask", mask); - tdb.modifyT (*t); + t->set ("mask", mask); + context.tdb.update (*t); } } else @@ -132,7 +132,6 @@ void handleRecurrence (std::vector & tasks) } tasks = modified; -*/ } //////////////////////////////////////////////////////////////////////////////// @@ -327,30 +326,28 @@ Date getNextRecurrence (Date& current, std::string& period) // When the status of a recurring child task changes, the parent task must // update it's mask. void updateRecurrenceMask ( -// TDB& tdb, std::vector & all, Task& task) { -/* - std::string parent = task.getAttribute ("parent"); + std::string parent = task.get ("parent"); if (parent != "") { - std::vector ::iterator it; + std::vector ::iterator it; for (it = all.begin (); it != all.end (); ++it) { - if (it->getUUID () == parent) + if (it->get ("uuid") == parent) { - unsigned int index = atoi (task.getAttribute ("imask").c_str ()); - std::string mask = it->getAttribute ("mask"); + unsigned int index = ::atoi (task.get ("imask").c_str ()); + std::string mask = it->get ("mask"); if (mask.length () > index) { - mask[index] = (task.getStatus () == T::pending) ? '-' - : (task.getStatus () == T::completed) ? '+' - : (task.getStatus () == T::deleted) ? 'X' - : '?'; + mask[index] = (task.getStatus () == Task::pending) ? '-' + : (task.getStatus () == Task::completed) ? '+' + : (task.getStatus () == Task::deleted) ? 'X' + : '?'; - it->setAttribute ("mask", mask); - tdb.modifyT (*it); + it->set ("mask", mask); + context.tdb.update (*it); } else { @@ -358,17 +355,16 @@ void updateRecurrenceMask ( for (unsigned int i = 0; i < index; ++i) mask += "?"; - mask += (task.getStatus () == T::pending) ? '-' - : (task.getStatus () == T::completed) ? '+' - : (task.getStatus () == T::deleted) ? 'X' - : '?'; + mask += (task.getStatus () == Task::pending) ? '-' + : (task.getStatus () == Task::completed) ? '+' + : (task.getStatus () == Task::deleted) ? 'X' + : '?'; } return; // No point continuing the loop. } } } -*/ } ////////////////////////////////////////////////////////////////////////////////