From 0f4bcefcff770d1cfa9a22cc266757655a43d9f0 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 3 Mar 2012 14:24:41 -0500 Subject: [PATCH] Code Cleanup - Relocated code from helper.cpp to feedback.cpp. - Fixed typo. --- NEWS | 2 +- src/feedback.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ src/helpers.cpp | 86 ----------------------------------------------- src/main.h | 4 +-- 4 files changed, 90 insertions(+), 89 deletions(-) diff --git a/NEWS b/NEWS index 6f2626875..25def6da1 100644 --- a/NEWS +++ b/NEWS @@ -82,7 +82,7 @@ Newly deprecated features in taskwarrior 2.0.0 in the scripts/add-ons/export-ical.pl script. - Use of 'report..limit' configuration variable. This is now handled in the report filter as 'limit:'. - - Used of 't', '+', 'enable' and 'enabled' in configuration values to mean + - Use of 't', '+', 'enable' and 'enabled' in configuration values to mean 'on/yes/true'. --- diff --git a/src/feedback.cpp b/src/feedback.cpp index 70c500f7f..feb68fe2e 100644 --- a/src/feedback.cpp +++ b/src/feedback.cpp @@ -43,6 +43,8 @@ extern Context context; +static void countTasks (const std::vector &, const std::string&, int&, int&); + //////////////////////////////////////////////////////////////////////////////// bool taskDiff (const Task& before, const Task& after) { @@ -406,4 +408,89 @@ void feedback_unblocked (const Task& task) } } +/////////////////////////////////////////////////////////////////////////////// +std::string onProjectChange (Task& task, bool scope /* = true */) +{ + std::stringstream msg; + std::string project = task.get ("project"); + + if (project != "") + { + if (scope) + msg << format (STRING_HELPER_PROJECT_CHANGE, project) + << " "; + + // Count pending and done tasks, for this project. + int count_pending = 0; + int count_done = 0; + std::vector all = context.tdb2.all_tasks (); + countTasks (all, project, count_pending, count_done); + + // count_done count_pending percentage + // ---------- ------------- ---------- + // 0 0 0% + // >0 0 100% + // 0 >0 0% + // >0 >0 calculated + int percentage = 0; + if (count_done == 0) + percentage = 0; + else if (count_pending == 0) + percentage = 100; + else + percentage = (count_done * 100 / (count_done + count_pending)); + + msg << format (STRING_HELPER_PROJECT_COMPL, project, percentage) + << " " + << format (STRING_HELPER_PROJECT_REM, count_pending, count_pending + count_done) + << "\n"; + } + + return msg.str (); +} + +/////////////////////////////////////////////////////////////////////////////// +std::string onProjectChange (Task& task1, Task& task2) +{ + if (task1.get ("project") == task2.get ("project")) + return onProjectChange (task1); + + std::string messages = onProjectChange (task1); + messages += onProjectChange (task2); + + return messages; +} + +/////////////////////////////////////////////////////////////////////////////// +static void countTasks ( + const std::vector & all, + const std::string& project, + int& count_pending, + int& count_done) +{ + std::vector ::const_iterator it; + for (it = all.begin (); it != all.end (); ++it) + { + if (it->get ("project") == project) + { + switch (it->getStatus ()) + { + case Task::pending: + case Task::waiting: + ++count_pending; + break; + + case Task::completed: + ++count_done; + break; + + case Task::deleted: + case Task::recurring: + default: + break; + } + } + } +} + //////////////////////////////////////////////////////////////////////////////// diff --git a/src/helpers.cpp b/src/helpers.cpp index 4fc7d345d..5f3310501 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -50,7 +50,6 @@ #include #include -static void countTasks (const std::vector &, const std::string&, int&, int&); extern Context context; @@ -120,89 +119,4 @@ std::string getDueDate (Task& task, const std::string& format) return due; } -/////////////////////////////////////////////////////////////////////////////// -std::string onProjectChange (Task& task, bool scope /* = true */) -{ - std::stringstream msg; - std::string project = task.get ("project"); - - if (project != "") - { - if (scope) - msg << format (STRING_HELPER_PROJECT_CHANGE, project) - << " "; - - // Count pending and done tasks, for this project. - int count_pending = 0; - int count_done = 0; - std::vector all = context.tdb2.all_tasks (); - countTasks (all, project, count_pending, count_done); - - // count_done count_pending percentage - // ---------- ------------- ---------- - // 0 0 0% - // >0 0 100% - // 0 >0 0% - // >0 >0 calculated - int percentage = 0; - if (count_done == 0) - percentage = 0; - else if (count_pending == 0) - percentage = 100; - else - percentage = (count_done * 100 / (count_done + count_pending)); - - msg << format (STRING_HELPER_PROJECT_COMPL, project, percentage) - << " " - << format (STRING_HELPER_PROJECT_REM, count_pending, count_pending + count_done) - << "\n"; - } - - return msg.str (); -} - -/////////////////////////////////////////////////////////////////////////////// -std::string onProjectChange (Task& task1, Task& task2) -{ - if (task1.get ("project") == task2.get ("project")) - return onProjectChange (task1); - - std::string messages = onProjectChange (task1); - messages += onProjectChange (task2); - - return messages; -} - -/////////////////////////////////////////////////////////////////////////////// -static void countTasks ( - const std::vector & all, - const std::string& project, - int& count_pending, - int& count_done) -{ - std::vector ::const_iterator it; - for (it = all.begin (); it != all.end (); ++it) - { - if (it->get ("project") == project) - { - switch (it->getStatus ()) - { - case Task::pending: - case Task::waiting: - ++count_pending; - break; - - case Task::completed: - ++count_done; - break; - - case Task::deleted: - case Task::recurring: - default: - break; - } - } - } -} - //////////////////////////////////////////////////////////////////////////////// diff --git a/src/main.h b/src/main.h index aec37a5bc..72df1e11d 100644 --- a/src/main.h +++ b/src/main.h @@ -51,8 +51,6 @@ bool nag (Task&); // helpers.cpp std::string getFullDescription (Task&, const std::string&); std::string getDueDate (Task&, const std::string&); -std::string onProjectChange (Task&, bool scope = true); -std::string onProjectChange (Task&, Task&); // rules.cpp void initializeColorRules (); @@ -81,6 +79,8 @@ void feedback_affected (const std::string&, int); void feedback_affected (const std::string&, const Task&); void feedback_special_tags (const Task&, const std::string&); void feedback_unblocked (const Task&); +std::string onProjectChange (Task&, bool scope = true); +std::string onProjectChange (Task&, Task&); // sort.cpp void sort_tasks (std::vector &, std::vector &, const std::string&);