diff --git a/src/TDB.cpp b/src/TDB.cpp index cd5de6d68..82451ded4 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -85,6 +85,7 @@ TDB::~TDB () //////////////////////////////////////////////////////////////////////////////// void TDB::clear () { + mPending.clear (); mLocations.clear (); mLock = true; @@ -196,33 +197,47 @@ int TDB::loadPending (std::vector & tasks, Filter& filter) try { - mPending.clear (); - - mId = 1; - char line[T_LINE_MAX]; - foreach (location, mLocations) + if (mPending.size () == 0) { - line_number = 1; - file = location->path + "/pending.data"; - - fseek (location->pending, 0, SEEK_SET); - while (fgets (line, T_LINE_MAX, location->pending)) + mId = 1; + char line[T_LINE_MAX]; + foreach (location, mLocations) { - int length = ::strlen (line); - if (length > 1) + line_number = 1; + file = location->path + "/pending.data"; + + fseek (location->pending, 0, SEEK_SET); + while (fgets (line, T_LINE_MAX, location->pending)) { - // TODO Add hidden attribute indicating source? - Task task (line); - task.id = mId++; + int length = ::strlen (line); + if (length > 1) + { + // TODO Add hidden attribute indicating source? + Task task (line); + task.id = mId++; - mPending.push_back (task); - if (filter.pass (task)) - tasks.push_back (task); + mPending.push_back (task); + } + + ++line_number; } - - ++line_number; } } + + // Now filter and return. + foreach (task, mPending) + if (filter.pass (*task)) + tasks.push_back (*task); + + // Hand back any accumulated additions, if TDB::loadPending is being called + // repeatedly. + int fakeId = mId; + foreach (task, mNew) + { + task->id = fakeId++; + if (filter.pass (*task)) + tasks.push_back (*task); + } } catch (std::string& e) @@ -267,7 +282,7 @@ int TDB::loadCompleted (std::vector & tasks, Filter& filter) line[length - 1] = '\0'; Task task (line); - task.id = mId++; + // Note: no id is set for completed tasks. if (filter.pass (task)) tasks.push_back (task); @@ -294,6 +309,7 @@ int TDB::loadCompleted (std::vector & tasks, Filter& filter) void TDB::add (const Task& task) { mNew.push_back (task); + } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/command.cpp b/src/command.cpp index f0afa8860..181090346 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -98,8 +98,8 @@ std::string handleProjects () std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); int quantity = context.tdb.loadPending (tasks, context.filter); - handleRecurrence (tasks); context.tdb.commit (); context.tdb.unlock (); @@ -157,8 +157,8 @@ std::string handleTags () std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); int quantity = context.tdb.loadPending (tasks, context.filter); - handleRecurrence (tasks); context.tdb.commit (); context.tdb.unlock (); @@ -455,8 +455,8 @@ std::string handleDelete () std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); context.tdb.loadPending (tasks, context.filter); - handleRecurrence (tasks); // Filter sequence. context.filter.applySequence (tasks, context.sequence); @@ -553,8 +553,8 @@ std::string handleStart () std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); context.tdb.loadPending (tasks, context.filter); - handleRecurrence (tasks); // Filter sequence. context.filter.applySequence (tasks, context.sequence); @@ -602,8 +602,8 @@ std::string handleStop () std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); context.tdb.loadPending (tasks, context.filter); - handleRecurrence (tasks); // Filter sequence. context.filter.applySequence (tasks, context.sequence); @@ -648,8 +648,8 @@ std::string handleDone () std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); context.tdb.loadPending (tasks, context.filter); - handleRecurrence (tasks); // Filter sequence. std::vector all = tasks; @@ -736,8 +736,8 @@ std::string handleExport () // Get all the tasks. std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); context.tdb.loadPending (tasks, context.filter); - handleRecurrence (tasks); context.tdb.commit (); context.tdb.unlock (); @@ -762,8 +762,8 @@ std::string handleModify () std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); context.tdb.loadPending (tasks, context.filter); - handleRecurrence (tasks); // Filter sequence. std::vector all = tasks; @@ -824,8 +824,8 @@ std::string handleAppend () std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); context.tdb.loadPending (tasks, context.filter); - handleRecurrence (tasks); // Filter sequence. std::vector all = tasks; diff --git a/src/custom.cpp b/src/custom.cpp index 65f526a6a..08b893fbb 100644 --- a/src/custom.cpp +++ b/src/custom.cpp @@ -101,8 +101,8 @@ std::string handleCustomReport (const std::string& report) // Get all the tasks. std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); context.tdb.load (tasks, context.filter); - handleRecurrence (tasks); context.tdb.commit (); context.tdb.unlock (); diff --git a/src/edit.cpp b/src/edit.cpp index b2829730a..b672af0ce 100644 --- a/src/edit.cpp +++ b/src/edit.cpp @@ -490,8 +490,8 @@ std::string handleEdit () std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); context.tdb.loadPending (tasks, context.filter); - handleRecurrence (tasks); // Filter sequence. context.filter.applySequence (tasks, context.sequence); diff --git a/src/main.h b/src/main.h index 702401a38..6c0f4d76c 100644 --- a/src/main.h +++ b/src/main.h @@ -49,7 +49,7 @@ void gatherNextTasks (std::vector &, std::vector &); void onChangeCallback (); // recur.cpp -void handleRecurrence (std::vector &); +void handleRecurrence (); Date getNextRecurrence (Date&, std::string&); bool generateDueDates (Task&, std::vector &); void updateRecurrenceMask (std::vector &, Task&); diff --git a/src/recur.cpp b/src/recur.cpp index 2b2ceef7e..174cb59b5 100644 --- a/src/recur.cpp +++ b/src/recur.cpp @@ -53,8 +53,12 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// // Scans all tasks, and for any recurring tasks, determines whether any new // child tasks need to be generated to fill gaps. -void handleRecurrence (std::vector & tasks) +void handleRecurrence () { + std::vector tasks; + Filter filter; + context.tdb.loadPending (tasks, filter); + std::vector modified; // Look at all tasks and find any recurring ones. @@ -97,7 +101,6 @@ void handleRecurrence (std::vector & tasks) changed = true; 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. diff --git a/src/report.cpp b/src/report.cpp index 89c40b938..2aebc16cf 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -268,8 +268,8 @@ std::string handleInfo () // Get all the tasks. std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); context.tdb.loadPending (tasks, context.filter); - handleRecurrence (tasks); context.tdb.commit (); context.tdb.unlock (); @@ -485,8 +485,8 @@ std::string handleReportSummary () // Scan the pending tasks. std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); context.tdb.load (tasks, context.filter); - handleRecurrence (tasks); context.tdb.commit (); context.tdb.unlock (); @@ -650,8 +650,8 @@ std::string handleReportNext () // Get all the tasks. std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); context.tdb.loadPending (tasks, context.filter); - handleRecurrence (tasks); context.tdb.commit (); context.tdb.unlock (); @@ -814,8 +814,8 @@ std::string handleReportHistory () // Scan the pending tasks. std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); context.tdb.load (tasks, context.filter); - handleRecurrence (tasks); context.tdb.commit (); context.tdb.unlock (); @@ -968,8 +968,8 @@ std::string handleReportGHistory () // Scan the pending tasks. std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); context.tdb.load (tasks, context.filter); - handleRecurrence (tasks); context.tdb.commit (); context.tdb.unlock (); @@ -1159,8 +1159,8 @@ std::string handleReportTimesheet () // Scan the pending tasks. std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); context.tdb.load (tasks, context.filter); - handleRecurrence (tasks); context.tdb.commit (); context.tdb.unlock (); @@ -1490,8 +1490,8 @@ std::string handleReportCalendar () // Get all the tasks. std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); context.tdb.loadPending (tasks, context.filter); - handleRecurrence (tasks); context.tdb.commit (); context.tdb.unlock (); @@ -1613,8 +1613,8 @@ std::string handleReportStats () // Get all the tasks. std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); context.tdb.load (tasks, context.filter); - handleRecurrence (tasks); context.tdb.commit (); context.tdb.unlock ();