diff --git a/src/Cmd.cpp b/src/Cmd.cpp index b34b9fdfe..7fb56442c 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -129,7 +129,6 @@ void Cmd::load () { if (commands.size () == 0) { - commands.push_back ("_projects"); commands.push_back ("_config"); commands.push_back ("_query"); commands.push_back ("export.csv"); @@ -155,7 +154,6 @@ void Cmd::load () commands.push_back ("import"); commands.push_back ("log"); commands.push_back ("prepend"); - commands.push_back ("projects"); commands.push_back ("start"); commands.push_back ("stop"); commands.push_back ("summary"); @@ -220,8 +218,7 @@ void Cmd::allCommands (std::vector & all) const // Commands that do not directly modify the data files. bool Cmd::isReadOnlyCommand () { - if (command == "_projects" || - command == "_config" || + if (command == "_config" || command == "_query" || command == "export.csv" || command == "export.ical" || @@ -236,7 +233,6 @@ bool Cmd::isReadOnlyCommand () command == "calendar" || command == "colors" || command == "config" || - command == "projects" || command == "push" || command == "summary" || command == "timesheet" || diff --git a/src/Context.cpp b/src/Context.cpp index f5035cd1e..3227bae9c 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -247,8 +247,7 @@ int Context::dispatch (std::string &out) Timer t ("Context::dispatch"); // TODO Chain-of-command pattern dispatch. - if (cmd.command == "projects") { rc = handleProjects (out); } - else if (cmd.command == "colors") { rc = handleColor (out); } + 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); } @@ -280,7 +279,6 @@ int Context::dispatch (std::string &out) handleMerge (out); } else if (cmd.command == "push") { handlePush (out); } else if (cmd.command == "pull") { handlePull (out); } - else if (cmd.command == "_projects") { rc = handleCompletionProjects (out); } else if (cmd.command == "_config") { rc = handleCompletionConfig (out); } else if (cmd.command == "_query") { rc = handleQuery (out); } else if (cmd.command == "" && diff --git a/src/command.cpp b/src/command.cpp index d962309f0..67edb04d4 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -215,122 +215,6 @@ int handleLog (std::string& outs) return rc; } -//////////////////////////////////////////////////////////////////////////////// -int handleProjects (std::string& outs) -{ - int rc = 0; - std::stringstream out; - - std::vector tasks; - context.tdb.lock (context.config.getBoolean ("locking")); - int quantity; - if (context.config.getBoolean ("list.all.projects")) - quantity = context.tdb.load (tasks, context.filter); - else - quantity = context.tdb.loadPending (tasks, context.filter); - - context.tdb.commit (); - context.tdb.unlock (); - - // Scan all the tasks for their project name, building a map using project - // names as keys. - std::map unique; - std::map high; - std::map medium; - std::map low; - std::map none; - bool no_project = false; - std::string project; - std::string priority; - foreach (t, tasks) - { - project = t->get ("project"); - priority = t->get ("priority"); - - unique[project] += 1; - if (project == "") - no_project = true; - - if (priority == "H") high[project] += 1; - else if (priority == "M") medium[project] += 1; - else if (priority == "L") low[project] += 1; - else none[project] += 1; - } - - if (unique.size ()) - { - // Render a list of project names from the map. - ViewText view; - view.width (context.getWidth ()); - view.add (Column::factory ("string", "Project")); - view.add (Column::factory ("string.right", "Tasks")); - view.add (Column::factory ("string.right", "Pri:None")); - view.add (Column::factory ("string.right", "Pri:L")); - view.add (Column::factory ("string.right", "Pri:M")); - view.add (Column::factory ("string.right", "Pri:H")); - - foreach (i, unique) - { - int row = view.addRow (); - view.set (row, 0, (i->first == "" ? "(none)" : i->first)); - view.set (row, 1, i->second); - view.set (row, 2, none[i->first]); - view.set (row, 3, low[i->first]); - view.set (row, 4, medium[i->first]); - view.set (row, 5, high[i->first]); - } - - int number_projects = unique.size (); - if (no_project) - --number_projects; - - out << optionalBlankLine () - << view.render () - << optionalBlankLine () - << number_projects - << (number_projects == 1 ? " project" : " projects") - << " (" << quantity << (quantity == 1 ? " task" : " tasks") << ")\n"; - } - else - { - out << "No projects.\n"; - rc = 1; - } - - outs = out.str (); - return rc; -} - -//////////////////////////////////////////////////////////////////////////////// -int handleCompletionProjects (std::string& outs) -{ - std::vector tasks; - context.tdb.lock (context.config.getBoolean ("locking")); - - Filter filter; - if (context.config.getBoolean ("complete.all.projects")) - context.tdb.load (tasks, filter); - else - context.tdb.loadPending (tasks, filter); - - context.tdb.commit (); - context.tdb.unlock (); - - // Scan all the tasks for their project name, building a map using project - // names as keys. - std::map unique; - foreach (t, tasks) - unique[t->get ("project")] = 0; - - std::stringstream out; - foreach (project, unique) - if (project->first.length ()) - out << project->first << "\n"; - - outs = out.str (); - return 0; -} - //////////////////////////////////////////////////////////////////////////////// int handleCompletionConfig (std::string& outs) { diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index 919a44e9d..c494ff92d 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -17,6 +17,7 @@ set (commands_SRCS Command.cpp Command.h CmdInfo.cpp CmdInfo.h CmdInstall.cpp CmdInstall.h CmdLogo.cpp CmdLogo.h + CmdProjects.cpp CmdProjects.h CmdShell.cpp CmdShell.h CmdShow.cpp CmdShow.h CmdStatistics.cpp CmdStatistics.h diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index 93d300ca2..301b75b14 100644 --- a/src/commands/CmdHelp.cpp +++ b/src/commands/CmdHelp.cpp @@ -151,10 +151,6 @@ int CmdHelp::execute (const std::string& command_line, std::string& output) view.set (row, 1, "task done ID [tags] [attrs] [desc...]"); view.set (row, 2, "Marks the specified task as completed."); - row = view.addRow (); - view.set (row, 1, "task projects"); - view.set (row, 2, "Shows a list of all project names used, and how many tasks are in each."); - row = view.addRow (); view.set (row, 1, "task summary"); view.set (row, 2, "Shows a report of task status by project."); diff --git a/src/commands/CmdProjects.cpp b/src/commands/CmdProjects.cpp new file mode 100644 index 000000000..684e667e4 --- /dev/null +++ b/src/commands/CmdProjects.cpp @@ -0,0 +1,174 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +extern Context context; + +//////////////////////////////////////////////////////////////////////////////// +CmdProjects::CmdProjects () +{ + _keyword = "projects"; + _usage = "task projects []"; + _description = "Shows a list of all project names used, and how many tasks are in each"; + _read_only = true; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdProjects::execute (const std::string& command_line, std::string& output) +{ + int rc = 0; + std::stringstream out; + + std::vector tasks; + context.tdb.lock (context.config.getBoolean ("locking")); + int quantity; + if (context.config.getBoolean ("list.all.projects")) + quantity = context.tdb.load (tasks, context.filter); + else + quantity = context.tdb.loadPending (tasks, context.filter); + + context.tdb.commit (); + context.tdb.unlock (); + + // Scan all the tasks for their project name, building a map using project + // names as keys. + std::map unique; + std::map high; + std::map medium; + std::map low; + std::map none; + bool no_project = false; + std::string project; + std::string priority; + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) + { + project = task->get ("project"); + priority = task->get ("priority"); + + unique[project] += 1; + if (project == "") + no_project = true; + + if (priority == "H") high[project] += 1; + else if (priority == "M") medium[project] += 1; + else if (priority == "L") low[project] += 1; + else none[project] += 1; + } + + if (unique.size ()) + { + // Render a list of project names from the map. + ViewText view; + view.width (context.getWidth ()); + view.add (Column::factory ("string", "Project")); + view.add (Column::factory ("string.right", "Tasks")); + view.add (Column::factory ("string.right", "Pri:None")); + view.add (Column::factory ("string.right", "Pri:L")); + view.add (Column::factory ("string.right", "Pri:M")); + view.add (Column::factory ("string.right", "Pri:H")); + + std::map ::iterator project; + for (project = unique.begin (); project != unique.end (); ++project) + { + int row = view.addRow (); + view.set (row, 0, (project->first == "" ? "(none)" : project->first)); + view.set (row, 1, project->second); + view.set (row, 2, none[project->first]); + view.set (row, 3, low[project->first]); + view.set (row, 4, medium[project->first]); + view.set (row, 5, high[project->first]); + } + + int number_projects = unique.size (); + if (no_project) + --number_projects; + + out << optionalBlankLine () + << view.render () + << optionalBlankLine () + << number_projects + << (number_projects == 1 ? " project" : " projects") + << " (" << quantity << (quantity == 1 ? " task" : " tasks") << ")\n"; + } + else + { + out << "No projects.\n"; + rc = 1; + } + + output = out.str (); + return rc; +} + +//////////////////////////////////////////////////////////////////////////////// +CmdCompletionProjects::CmdCompletionProjects () +{ + _keyword = "_projects"; + _usage = "task _projects []"; + _description = "Shows only a list of all project names used"; + _read_only = true; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdCompletionProjects::execute (const std::string& command_line, std::string& output) +{ + std::vector tasks; + context.tdb.lock (context.config.getBoolean ("locking")); + + Filter filter; + if (context.config.getBoolean ("complete.all.projects")) + context.tdb.load (tasks, filter); + else + context.tdb.loadPending (tasks, filter); + + context.tdb.commit (); + context.tdb.unlock (); + + // Scan all the tasks for their project name, building a map using project + // names as keys. + std::map unique; + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) + unique[task->get ("project")] = 0; + + std::map ::iterator project; + for (project = unique.begin (); project != unique.end (); ++project) + if (project->first.length ()) + output += project->first + "\n"; + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdProjects.h b/src/commands/CmdProjects.h new file mode 100644 index 000000000..b63b28f77 --- /dev/null +++ b/src/commands/CmdProjects.h @@ -0,0 +1,49 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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_CMDPROJECTS +#define INCLUDED_CMDPROJECTS +#define L10N // Localization complete. + +#include +#include + +class CmdProjects : public Command +{ +public: + CmdProjects (); + int execute (const std::string&, std::string&); +}; + +class CmdCompletionProjects : public Command +{ +public: + CmdCompletionProjects (); + int execute (const std::string&, std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index e0c2dad8a..070e36e45 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -57,6 +58,7 @@ void Command::factory (std::map & all) c = new CmdCompletionCommands (); all[c->keyword ()] = c; c = new CmdCompletionIds (); all[c->keyword ()] = c; + c = new CmdCompletionProjects (); all[c->keyword ()] = c; c = new CmdCompletionTags (); all[c->keyword ()] = c; c = new CmdCompletionVersion (); all[c->keyword ()] = c; c = new CmdCount (); all[c->keyword ()] = c; @@ -68,6 +70,7 @@ void Command::factory (std::map & all) c = new CmdInfo (); all[c->keyword ()] = c; c = new CmdInstall (); all[c->keyword ()] = c; c = new CmdLogo (); all[c->keyword ()] = c; + c = new CmdProjects (); all[c->keyword ()] = c; c = new CmdShell (); all[c->keyword ()] = c; c = new CmdShow (); all[c->keyword ()] = c; c = new CmdStatistics (); all[c->keyword ()] = c; diff --git a/src/main.h b/src/main.h index d3ccd5382..d3e094692 100644 --- a/src/main.h +++ b/src/main.h @@ -56,8 +56,6 @@ int handleAppend (std::string&); int handlePrepend (std::string&); int handleDone (std::string&); int handleModify (std::string&); -int handleProjects (std::string&); -int handleCompletionProjects (std::string&); int handleCompletionConfig (std::string&); int handleQuery (std::string&); int handleConfig (std::string&);