diff --git a/src/Cmd.cpp b/src/Cmd.cpp index 2bf3123f9..5751cacf8 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -134,7 +134,6 @@ void Cmd::load () commands.push_back ("_commands"); commands.push_back ("_ids"); commands.push_back ("_config"); - commands.push_back ("_urgency"); commands.push_back ("_query"); commands.push_back ("_zshcommands"); commands.push_back ("_zshids"); @@ -236,7 +235,6 @@ bool Cmd::isReadOnlyCommand () command == "_commands" || command == "_ids" || command == "_config" || - command == "_urgency" || command == "_query" || command == "_zshcommands" || command == "_zshids" || diff --git a/src/Context.cpp b/src/Context.cpp index 2fc44c084..601f5787b 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -289,7 +289,6 @@ int Context::dispatch (std::string &out) else if (cmd.command == "_commands") { rc = handleCompletionCommands (out); } else if (cmd.command == "_ids") { rc = handleCompletionIDs (out); } else if (cmd.command == "_config") { rc = handleCompletionConfig (out); } - else if (cmd.command == "_urgency") { rc = handleUrgency (out); } else if (cmd.command == "_query") { rc = handleQuery (out); } else if (cmd.command == "_zshcommands") { rc = handleZshCompletionCommands (out); } else if (cmd.command == "_zshids") { rc = handleZshCompletionIDs (out); } diff --git a/src/command.cpp b/src/command.cpp index 87ead7bcf..f4cafb461 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -411,41 +411,6 @@ int handleCompletionConfig (std::string& outs) return 0; } -//////////////////////////////////////////////////////////////////////////////// -// Temporary command to display urgency for a task. -int handleUrgency (std::string& outs) -{ - // Get all the tasks. - std::vector tasks; - context.tdb.lock (context.config.getBoolean ("locking")); - handleRecurrence (); - context.tdb.loadPending (tasks, context.filter); - context.tdb.commit (); - context.tdb.unlock (); - - // Filter sequence. - context.filter.applySequence (tasks, context.sequence); - if (tasks.size () == 0) - { - std::cout << "No tasks specified.\n"; - return 1; - } - - // Find the task(s). - std::stringstream out; - foreach (task, tasks) - { - out << "task " - << task->id - << " urgency " - << task->urgency () - << "\n"; - } - - outs = out.str (); - return 0; -} - //////////////////////////////////////////////////////////////////////////////// int handleQuery (std::string& outs) { diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index 4b8ae4a76..d5a4736cb 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -17,6 +17,7 @@ set (commands_SRCS Command.cpp Command.h CmdShow.cpp CmdShow.h CmdTags.cpp CmdTags.h CmdTip.cpp CmdTip.h + CmdUrgency.cpp CmdUrgency.h CmdVersion.cpp CmdVersion.h) add_library (commands STATIC ${commands_SRCS}) diff --git a/src/commands/CmdUrgency.cpp b/src/commands/CmdUrgency.cpp new file mode 100644 index 000000000..b41e2466d --- /dev/null +++ b/src/commands/CmdUrgency.cpp @@ -0,0 +1,79 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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; + +//////////////////////////////////////////////////////////////////////////////// +CmdUrgency::CmdUrgency () +{ + _keyword = "_urgency"; + _usage = "task _urgency "; + _description = "Displays the urgency measure of a task."; + _read_only = true; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdUrgency::execute (const std::string& command_line, std::string& output) +{ + // Get all the tasks. + std::vector tasks; + context.tdb.lock (context.config.getBoolean ("locking")); + handleRecurrence (); + context.tdb.loadPending (tasks, context.filter); + context.tdb.commit (); + context.tdb.unlock (); + + // Filter sequence. + context.filter.applySequence (tasks, context.sequence); + if (tasks.size () == 0) + { + context.footnote ("No tasks specified."); + return 1; + } + + // Find the task(s). + std::stringstream out; + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) + out << "task " + << task->id + << " urgency " + << task->urgency () + << "\n"; + + output = out.str (); + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdUrgency.h b/src/commands/CmdUrgency.h new file mode 100644 index 000000000..25dbe30e2 --- /dev/null +++ b/src/commands/CmdUrgency.h @@ -0,0 +1,42 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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_CMDURGENCY +#define INCLUDED_CMDURGENCY +#define L10N // Localization complete. + +#include +#include + +class CmdUrgency : public Command +{ +public: + CmdUrgency (); + int execute (const std::string&, std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index 437a25b2d..f00108e42 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -60,6 +61,7 @@ void Command::factory (std::map & all) c = new CmdShow (); all[c->keyword ()] = c; c = new CmdTags (); all[c->keyword ()] = c; c = new CmdTip (); all[c->keyword ()] = c; + c = new CmdUrgency (); all[c->keyword ()] = c; c = new CmdVersion (); all[c->keyword ()] = c; // Instantiate a command object for each custom report. diff --git a/src/main.h b/src/main.h index d44c6d2c8..845085f37 100644 --- a/src/main.h +++ b/src/main.h @@ -62,7 +62,6 @@ int handleCompletionTags (std::string&); int handleCompletionCommands (std::string&); int handleCompletionIDs (std::string&); int handleCompletionConfig (std::string&); -int handleUrgency (std::string&); int handleQuery (std::string&); int handleZshCompletionCommands (std::string&); int handleZshCompletionIDs (std::string&);