From 2380c8b33ab0aa7e2ba64418db95351b2705ec30 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 9 Jul 2008 23:57:31 -0400 Subject: [PATCH] - Added new, stubbed, T::validate method for full T validation, one day. --- src/T.cpp | 8 ++++++++ src/T.h | 1 + src/TDB.cpp | 2 +- src/task.cpp | 49 +++++++++++++++++++++++++++---------------------- src/task.h | 2 +- 5 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/T.cpp b/src/T.cpp index 8a9c7fdc7..e243c1db6 100644 --- a/src/T.cpp +++ b/src/T.cpp @@ -521,3 +521,11 @@ int T::determineVersion (const std::string& line) } //////////////////////////////////////////////////////////////////////////////// +// TODO Expand this method into a full-blown task validation check. +bool T::validate () const +{ + // TODO Verify until > due + return true; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/T.h b/src/T.h index cb8ffb4a3..e26d25b5f 100644 --- a/src/T.h +++ b/src/T.h @@ -80,6 +80,7 @@ public: const std::string compose () const; const std::string composeCSV (); void parse (const std::string&); + bool validate () const; private: int determineVersion (const std::string&); diff --git a/src/TDB.cpp b/src/TDB.cpp index b2f5afd3d..abb3812ae 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -50,7 +50,7 @@ TDB::~TDB () //////////////////////////////////////////////////////////////////////////////// void TDB::dataDirectory (const std::string& directory) { - if (! access (directory.c_str (), F_OK)) + if (! access (expandPath (directory).c_str (), F_OK)) { mPendingFile = directory + "/pending.data"; mCompletedFile = directory + "/completed.data"; diff --git a/src/task.cpp b/src/task.cpp index 99b35a5ef..0d3f6c7f5 100644 --- a/src/task.cpp +++ b/src/task.cpp @@ -406,24 +406,28 @@ void handleRecurrence (TDB& tdb, std::vector & tasks) { if (t->getStatus () == T::recurring) { -// std::cout << "# found recurring task " << t->getUUID () << std::endl; - // Generate a list of due dates for this recurring task, regardless of // the mask. std::vector due; - generateDueDates (*t, due); + if (!generateDueDates (*t, due)) + { + std::cout << "Task " + << t->getUUID () + << " (" + << trim (t->getDescription ()) + << ") is past its 'until' date, and has be deleted" << std::endl; + tdb.deleteT (*t); + continue; + } // Get the mask from the parent task. std::string mask = t->getAttribute ("mask"); -// std::cout << "# mask=" << mask << std::endl; // Iterate over the due dates, and check each against the mask. bool changed = false; unsigned int i = 0; foreach (d, due) { -// std::cout << "# need: " << d->toString () << std::endl; - if (mask.length () <= i) { mask += '-'; @@ -444,11 +448,9 @@ void handleRecurrence (TDB& tdb, std::vector & tasks) rec.setAttribute ("imask", indexMask); // Store index into mask. // Add the new task to the vector, for immediate use. -// std::cout << "# adding to modified" << std::endl; modified.push_back (rec); // Add the new task to the DB. -// std::cout << "# adding to pending" << std::endl; tdb.addT (rec); } @@ -458,7 +460,6 @@ void handleRecurrence (TDB& tdb, std::vector & tasks) // Only modify the parent if necessary. if (changed) { -// std::cout << "# modifying parent with mask=" << mask << std::endl; t->setAttribute ("mask", mask); tdb.modifyT (*t); } @@ -473,13 +474,13 @@ void handleRecurrence (TDB& tdb, std::vector & tasks) //////////////////////////////////////////////////////////////////////////////// // Determine a start date (due), an optional end date (until), and an increment // period (recur). Then generate a set of corresponding dates. -void generateDueDates (T& parent, std::vector & allDue) +// +// Returns false if the parent recurring task is depleted. +bool generateDueDates (T& parent, std::vector & allDue) { // Determine due date, recur period and until date. Date due (atoi (parent.getAttribute ("due").c_str ())); -// std::cout << "# due=" << due.toString () << std::endl; std::string recur = parent.getAttribute ("recur"); -// std::cout << "# recur=" << recur << std::endl; bool specificEnd = false; Date until; @@ -489,25 +490,29 @@ void generateDueDates (T& parent, std::vector & allDue) specificEnd = true; } -// std::cout << "# specficEnd=" << (specificEnd ? "true" : "false") << std::endl; -// if (specificEnd) -// std::cout << "# until=" << until.toString () << std::endl; - Date now; for (Date i = due; ; i = getNextRecurrence (i, recur)) { allDue.push_back (i); -// std::cout << "# i=" << i.toString () << std::endl; if (specificEnd && i > until) - break; + { + // If i > until, it means there are no more tasks to generate, and if the + // parent mask contains all + or X, then there never will be another task + // to generate, and this parent task may be safely reaped. + std::string mask = parent.getAttribute ("mask"); + if (mask.length () == allDue.size () && + mask.find ('-') == std::string::npos) + return false; + + return true; + } if (i > now) -// { -// std::cout << "# already 1 instance into the future, stopping" << std::endl; - break; -// } + return true; } + + return true; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/task.h b/src/task.h index 9060c7dde..4a8dc78fd 100644 --- a/src/task.h +++ b/src/task.h @@ -62,7 +62,7 @@ void gatherNextTasks (const TDB&, T&, Config&, std::vector &, std::vector &); -void generateDueDates (T&, std::vector &); +bool generateDueDates (T&, std::vector &); Date getNextRecurrence (Date&, std::string&); void updateRecurrenceMask (TDB&, std::vector &, T&);