From d37e46cc487d50666f9a97505344a308894ebd7f Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 9 Sep 2011 00:13:08 -0400 Subject: [PATCH] Enhancement - Re-enabled the onProjectChange function, and upgraded it to TDB2. Now it does a lot less, which is another way of saying it is faster. --- src/commands/CmdAdd.cpp | 2 +- src/commands/CmdLog.cpp | 4 +--- src/helpers.cpp | 47 ++++++++++++----------------------------- 3 files changed, 15 insertions(+), 38 deletions(-) diff --git a/src/commands/CmdAdd.cpp b/src/commands/CmdAdd.cpp index db4a07212..1cf1df207 100644 --- a/src/commands/CmdAdd.cpp +++ b/src/commands/CmdAdd.cpp @@ -60,7 +60,7 @@ int CmdAdd::execute (std::string& output) if (context.verbose ("new-id")) output = format (STRING_CMD_ADD_FEEDBACK, context.tdb2.next_id ()) + "\n"; -// TODO context.footnote (onProjectChange (task)); + context.footnote (onProjectChange (task)); context.tdb2.commit (); return rc; diff --git a/src/commands/CmdLog.cpp b/src/commands/CmdLog.cpp index 41ffc5e2b..a33a3f792 100644 --- a/src/commands/CmdLog.cpp +++ b/src/commands/CmdLog.cpp @@ -66,9 +66,7 @@ int CmdLog::execute (std::string& output) context.tdb2.add (task); -/* - TODO context.footnote (onProjectChange (task)); -*/ + context.footnote (onProjectChange (task)); context.tdb2.commit (); if (context.config.getBoolean ("echo.command")) diff --git a/src/helpers.cpp b/src/helpers.cpp index 6a337ebe9..b49333030 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -47,7 +47,7 @@ #include #include -static void countTasks (const std::vector &, const std::string&, const std::vector &, int&, int&); +static void countTasks (const std::vector &, const std::string&, int&, int&); extern Context context; @@ -134,13 +134,8 @@ std::string onProjectChange (Task& task, bool scope /* = true */) int count_pending = 0; int count_done = 0; - std::vector all; - std::vector none; -// TODO Fix. -// context.tdb.load (all); -// -// countTasks (all, project, context.tdb.getAllModified (), count_pending, count_done); -// countTasks (context.tdb.getAllModified (), project, none, count_pending, count_done); + std::vector all = context.tdb2.all_tasks (); + countTasks (all, project, count_pending, count_done); // count_done count_pending percentage // ---------- ------------- ---------- @@ -183,43 +178,27 @@ std::string onProjectChange (Task& task1, Task& task2) static void countTasks ( const std::vector & all, const std::string& project, - const std::vector & skipTasks, int& count_pending, int& count_done) { std::vector ::const_iterator it; for (it = all.begin (); it != all.end (); ++it) { - bool skip = 0; - if (it->get ("project") == project) { - std::vector ::const_iterator itSkipTasks; - for (itSkipTasks = skipTasks.begin (); itSkipTasks != skipTasks.end (); ++itSkipTasks) + switch (it->getStatus ()) { - if (it->get("uuid") == itSkipTasks->get("uuid")) - { - skip = 1; - break; - } - } + case Task::pending: + case Task::waiting: + ++count_pending; + break; - if (skip == 0) - { - switch (it->getStatus ()) - { - case Task::pending: - case Task::waiting: - ++count_pending; - break; + case Task::completed: + ++count_done; + break; - case Task::completed: - ++count_done; - break; - - default: - break; - } + default: + break; } } }