diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f23c5db42..94241b0ab 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -45,7 +45,6 @@ set (task_SRCS API.cpp API.h dependency.cpp export.cpp feedback.cpp - history.cpp i18n.h import.cpp interactive.cpp diff --git a/src/Cmd.cpp b/src/Cmd.cpp index 600df3c9a..720f7a9c2 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -134,10 +134,6 @@ void Cmd::load () commands.push_back ("export.csv"); commands.push_back ("export.ical"); commands.push_back ("export.yaml"); - commands.push_back ("history.monthly"); - commands.push_back ("history.annual"); - commands.push_back ("ghistory.monthly"); - commands.push_back ("ghistory.annual"); commands.push_back ("burndown.daily"); commands.push_back ("burndown.weekly"); commands.push_back ("burndown.monthly"); @@ -221,10 +217,6 @@ bool Cmd::isReadOnlyCommand () command == "export.csv" || command == "export.ical" || command == "export.yaml" || - command == "history.monthly" || - command == "history.annual" || - command == "ghistory.monthly" || - command == "ghistory.annual" || command == "burndown.daily" || command == "burndown.weekly" || command == "burndown.monthly" || diff --git a/src/Context.cpp b/src/Context.cpp index a4f441825..3a7092035 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -249,10 +249,6 @@ int Context::dispatch (std::string &out) // TODO Chain-of-command pattern dispatch. if (cmd.command == "colors") { rc = handleColor (out); } else if (cmd.command == "config") { rc = handleConfig (out); } - else if (cmd.command == "history.monthly") { rc = handleReportHistoryMonthly (out); } - else if (cmd.command == "history.annual") { rc = handleReportHistoryAnnual (out); } - else if (cmd.command == "ghistory.monthly") { rc = handleReportGHistoryMonthly (out); } - else if (cmd.command == "ghistory.annual") { rc = handleReportGHistoryAnnual (out); } else if (cmd.command == "burndown.daily") { rc = handleReportBurndownDaily (out); } else if (cmd.command == "burndown.weekly") { rc = handleReportBurndownWeekly (out); } else if (cmd.command == "burndown.monthly") { rc = handleReportBurndownMonthly (out); } diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index 303254de2..999813a7e 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -14,6 +14,7 @@ set (commands_SRCS Command.cpp Command.h CmdEdit.cpp CmdEdit.h CmdExec.cpp CmdExec.h CmdHelp.cpp CmdHelp.h + CmdHistory.cpp CmdHistory.h CmdIds.cpp CmdIds.h CmdInfo.cpp CmdInfo.h CmdInstall.cpp CmdInstall.h diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index 850972d27..768d00464 100644 --- a/src/commands/CmdHelp.cpp +++ b/src/commands/CmdHelp.cpp @@ -151,22 +151,6 @@ int CmdHelp::execute (const std::string& command_line, std::string& output) view.set (row, 1, "task timesheet [weeks]"); view.set (row, 2, "Shows a weekly report of tasks completed and started."); - row = view.addRow (); - view.set (row, 1, "task history"); - view.set (row, 2, "Shows a report of task history, by month. Alias to history.monthly."); - - row = view.addRow (); - view.set (row, 1, "task history.annual"); - view.set (row, 2, "Shows a report of task history, by year."); - - row = view.addRow (); - view.set (row, 1, "task ghistory"); - view.set (row, 2, "Shows a graphical report of task history, by month. Alias to ghistory.monthly."); - - row = view.addRow (); - view.set (row, 1, "task ghistory.annual"); - view.set (row, 2, "Shows a graphical report of task history, by year."); - row = view.addRow (); view.set (row, 1, "task burndown.daily"); view.set (row, 2, "Shows a graphical burndown chart, by day."); diff --git a/src/history.cpp b/src/commands/CmdHistory.cpp similarity index 86% rename from src/history.cpp rename to src/commands/CmdHistory.cpp index 5889b96cb..6698e0038 100644 --- a/src/history.cpp +++ b/src/commands/CmdHistory.cpp @@ -28,14 +28,25 @@ #include #include #include -#include -#include #include +#include +#include extern Context context; //////////////////////////////////////////////////////////////////////////////// -int handleReportHistoryMonthly (std::string& outs) +CmdHistoryMonthly::CmdHistoryMonthly () +{ + _keyword = "history.monthly"; + _usage = "task execute "; + _usage = "task history.monthly []"; + _description = "Shows a report of task history, by month."; + _read_only = true; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdHistoryMonthly::execute (const std::string& command_line, std::string& output) { int rc = 0; std::map groups; // Represents any month with data @@ -51,7 +62,8 @@ int handleReportHistoryMonthly (std::string& outs) context.tdb.commit (); context.tdb.unlock (); - foreach (task, tasks) + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) { Date entry (task->get ("entry")); @@ -98,7 +110,8 @@ int handleReportHistoryMonthly (std::string& outs) int priorYear = 0; int row = 0; - foreach (i, groups) + std::map ::iterator i; + for (i = groups.begin (); i != groups.end (); ++i) { row = view.addRow (); @@ -174,12 +187,22 @@ int handleReportHistoryMonthly (std::string& outs) rc = 1; } - outs = out.str (); + output = out.str (); return rc; } //////////////////////////////////////////////////////////////////////////////// -int handleReportHistoryAnnual (std::string& outs) +CmdHistoryAnnual::CmdHistoryAnnual () +{ + _keyword = "history.annual"; + _usage = "task history.annual []"; + _description = "Shows a report of task history, by year."; + _read_only = true; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdHistoryAnnual::execute (const std::string& command_line, std::string& output) { int rc = 0; std::map groups; // Represents any month with data @@ -195,7 +218,8 @@ int handleReportHistoryAnnual (std::string& outs) context.tdb.commit (); context.tdb.unlock (); - foreach (task, tasks) + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) { Date entry (task->get ("entry")); @@ -241,7 +265,8 @@ int handleReportHistoryAnnual (std::string& outs) int priorYear = 0; int row = 0; - foreach (i, groups) + std::map ::iterator i; + for (i = groups.begin (); i != groups.end (); ++i) { row = view.addRow (); @@ -315,12 +340,22 @@ int handleReportHistoryAnnual (std::string& outs) rc = 1; } - outs = out.str (); + output = out.str (); return rc; } //////////////////////////////////////////////////////////////////////////////// -int handleReportGHistoryMonthly (std::string& outs) +CmdGHistoryMonthly::CmdGHistoryMonthly () +{ + _keyword = "ghistory.monthly"; + _usage = "task ghistory.monthly []"; + _description = "Shows a graphical report of task history, by month."; + _read_only = true; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdGHistoryMonthly::execute (const std::string& command_line, std::string& output) { int rc = 0; std::map groups; // Represents any month with data @@ -336,7 +371,8 @@ int handleReportGHistoryMonthly (std::string& outs) context.tdb.commit (); context.tdb.unlock (); - foreach (task, tasks) + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) { Date entry (task->get ("entry")); @@ -383,7 +419,8 @@ int handleReportGHistoryMonthly (std::string& outs) // Determine the longest line, and the longest "added" line. int maxAddedLine = 0; int maxRemovedLine = 0; - foreach (i, groups) + std::map ::iterator i; + for (i = groups.begin (); i != groups.end (); ++i) { if (completedGroup[i->first] + deletedGroup[i->first] > maxRemovedLine) maxRemovedLine = completedGroup[i->first] + deletedGroup[i->first]; @@ -403,7 +440,8 @@ int handleReportGHistoryMonthly (std::string& outs) int priorYear = 0; int row = 0; - foreach (i, groups) + std::map ::iterator i; + for (i = groups.begin (); i != groups.end (); ++i) { row = view.addRow (); @@ -498,12 +536,22 @@ int handleReportGHistoryMonthly (std::string& outs) rc = 1; } - outs = out.str (); + output = out.str (); return rc; } //////////////////////////////////////////////////////////////////////////////// -int handleReportGHistoryAnnual (std::string& outs) +CmdGHistoryAnnual::CmdGHistoryAnnual () +{ + _keyword = "ghistory.annual"; + _usage = "task ghistory.annual []"; + _description = "Shows a graphical report of task history, by year."; + _read_only = true; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdGHistoryAnnual::execute (const std::string& command_line, std::string& output) { int rc = 0; std::map groups; // Represents any month with data @@ -519,7 +567,8 @@ int handleReportGHistoryAnnual (std::string& outs) context.tdb.commit (); context.tdb.unlock (); - foreach (task, tasks) + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) { Date entry (task->get ("entry")); @@ -565,7 +614,8 @@ int handleReportGHistoryAnnual (std::string& outs) // Determine the longest line, and the longest "added" line. int maxAddedLine = 0; int maxRemovedLine = 0; - foreach (i, groups) + std::map ::iterator i; + for (i = groups.begin (); i != groups.end (); ++i) { if (completedGroup[i->first] + deletedGroup[i->first] > maxRemovedLine) maxRemovedLine = completedGroup[i->first] + deletedGroup[i->first]; @@ -585,7 +635,8 @@ int handleReportGHistoryAnnual (std::string& outs) int priorYear = 0; int row = 0; - foreach (i, groups) + std::map ::iterator i; + for (i = groups.begin (); i != groups.end (); ++i) { row = view.addRow (); @@ -678,7 +729,7 @@ int handleReportGHistoryAnnual (std::string& outs) rc = 1; } - outs = out.str (); + output = out.str (); return rc; } diff --git a/src/commands/CmdHistory.h b/src/commands/CmdHistory.h new file mode 100644 index 000000000..fa5a23df6 --- /dev/null +++ b/src/commands/CmdHistory.h @@ -0,0 +1,63 @@ +//////////////////////////////////////////////////////////////////////////////// +// taskwarrior - a command line task list manager. +// +// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez. +// All rights reserved. +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2 of the License, or (at your option) any later +// version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +// details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the +// +// Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, +// Boston, MA +// 02110-1301 +// USA +// +//////////////////////////////////////////////////////////////////////////////// +#ifndef INCLUDED_CMDHISTORY +#define INCLUDED_CMDHISTORY +#define L10N // Localization complete. + +#include +#include + +class CmdHistoryMonthly : public Command +{ +public: + CmdHistoryMonthly (); + int execute (const std::string&, std::string&); +}; + +class CmdHistoryAnnual : public Command +{ +public: + CmdHistoryAnnual (); + int execute (const std::string&, std::string&); +}; + +class CmdGHistoryMonthly : public Command +{ +public: + CmdGHistoryMonthly (); + int execute (const std::string&, std::string&); +}; + +class CmdGHistoryAnnual : public Command +{ +public: + CmdGHistoryAnnual (); + int execute (const std::string&, std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index a06e42410..57ae001d1 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -68,7 +69,11 @@ void Command::factory (std::map & all) c = new CmdDiagnostics (); all[c->keyword ()] = c; c = new CmdEdit (); all[c->keyword ()] = c; c = new CmdExec (); all[c->keyword ()] = c; + c = new CmdGHistoryMonthly (); all[c->keyword ()] = c; + c = new CmdGHistoryAnnual (); all[c->keyword ()] = c; c = new CmdHelp (); all[c->keyword ()] = c; + c = new CmdHistoryMonthly (); all[c->keyword ()] = c; + c = new CmdHistoryAnnual (); all[c->keyword ()] = c; c = new CmdIds (); all[c->keyword ()] = c; c = new CmdInfo (); all[c->keyword ()] = c; c = new CmdInstall (); all[c->keyword ()] = c; diff --git a/src/main.h b/src/main.h index 15334239d..fbb269402 100644 --- a/src/main.h +++ b/src/main.h @@ -89,12 +89,6 @@ int handleReportBurndownDaily (std::string&); int handleReportBurndownWeekly (std::string&); int handleReportBurndownMonthly (std::string&); -// history.cpp -int handleReportHistoryMonthly (std::string&); -int handleReportHistoryAnnual (std::string&); -int handleReportGHistoryMonthly (std::string&); -int handleReportGHistoryAnnual (std::string&); - // rules.cpp void initializeColorRules (); void autoColorize (Task&, Color&);