- Localized projects and _projects commands.
This commit is contained in:
Paul Beckingham 2011-06-29 23:05:53 -04:00
parent f5e155e54d
commit 829a26d70b
2 changed files with 56 additions and 25 deletions

View file

@ -25,10 +25,14 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#define L10N // Localization complete.
#include <sstream> #include <sstream>
#include <Context.h> #include <Context.h>
#include <ViewText.h> #include <ViewText.h>
#include <text.h> #include <text.h>
#include <i18n.h>
#include <main.h>
#include <CmdProjects.h> #include <CmdProjects.h>
extern Context context; extern Context context;
@ -38,7 +42,7 @@ CmdProjects::CmdProjects ()
{ {
_keyword = "projects"; _keyword = "projects";
_usage = "task projects [<filter>]"; _usage = "task projects [<filter>]";
_description = "Shows a list of all project names used, and how many tasks are in each"; _description = STRING_CMD_PROJECTS_USAGE;
_read_only = true; _read_only = true;
_displays_id = false; _displays_id = false;
} }
@ -47,20 +51,27 @@ CmdProjects::CmdProjects ()
int CmdProjects::execute (std::string& output) int CmdProjects::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
/*
std::stringstream out;
// Get all the tasks.
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking")); context.tdb.lock (context.config.getBoolean ("locking"));
handleRecurrence ();
int quantity; int quantity;
if (context.config.getBoolean ("list.all.projects")) if (context.config.getBoolean ("list.all.projects"))
quantity = context.tdb.load (tasks, context.filter); quantity = context.tdb.load (tasks);
else else
quantity = context.tdb.loadPending (tasks, context.filter); quantity = context.tdb.loadPending (tasks);
context.tdb.commit (); context.tdb.commit ();
context.tdb.unlock (); context.tdb.unlock ();
// Apply filter.
std::vector <Task> filtered;
filter (tasks, filtered);
std::stringstream out;
// Scan all the tasks for their project name, building a map using project // Scan all the tasks for their project name, building a map using project
// names as keys. // names as keys.
std::map <std::string, int> unique; std::map <std::string, int> unique;
@ -72,7 +83,7 @@ int CmdProjects::execute (std::string& output)
std::string project; std::string project;
std::string priority; std::string priority;
std::vector <Task>::iterator task; std::vector <Task>::iterator task;
for (task = tasks.begin (); task != tasks.end (); ++task) for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
project = task->get ("project"); project = task->get ("project");
priority = task->get ("priority"); priority = task->get ("priority");
@ -92,18 +103,18 @@ int CmdProjects::execute (std::string& output)
// Render a list of project names from the map. // Render a list of project names from the map.
ViewText view; ViewText view;
view.width (context.getWidth ()); view.width (context.getWidth ());
view.add (Column::factory ("string", "Project")); view.add (Column::factory ("string", STRING_COLUMN_LABEL_PROJECT));
view.add (Column::factory ("string.right", "Tasks")); view.add (Column::factory ("string.right", STRING_COLUMN_LABEL_TASKS));
view.add (Column::factory ("string.right", "Pri:None")); view.add (Column::factory ("string.right", STRING_CMD_PROJECTS_PRI_N));
view.add (Column::factory ("string.right", "Pri:L")); view.add (Column::factory ("string.right", STRING_CMD_PROJECTS_PRI_H));
view.add (Column::factory ("string.right", "Pri:M")); view.add (Column::factory ("string.right", STRING_CMD_PROJECTS_PRI_M));
view.add (Column::factory ("string.right", "Pri:H")); view.add (Column::factory ("string.right", STRING_CMD_PROJECTS_PRI_L));
std::map <std::string, int>::iterator project; std::map <std::string, int>::iterator project;
for (project = unique.begin (); project != unique.end (); ++project) for (project = unique.begin (); project != unique.end (); ++project)
{ {
int row = view.addRow (); int row = view.addRow ();
view.set (row, 0, (project->first == "" ? "(none)" : project->first)); view.set (row, 0, (project->first == "" ? STRING_CMD_PROJECTS_NONE : project->first));
view.set (row, 1, project->second); view.set (row, 1, project->second);
view.set (row, 2, none[project->first]); view.set (row, 2, none[project->first]);
view.set (row, 3, low[project->first]); view.set (row, 3, low[project->first]);
@ -118,18 +129,22 @@ int CmdProjects::execute (std::string& output)
out << optionalBlankLine () out << optionalBlankLine ()
<< view.render () << view.render ()
<< optionalBlankLine () << optionalBlankLine ()
<< number_projects << (number_projects == 1
<< (number_projects == 1 ? " project" : " projects") ? format (STRING_CMD_PROJECTS_SUMMARY, number_projects)
<< " (" << quantity << (quantity == 1 ? " task" : " tasks") << ")\n"; : format (STRING_CMD_PROJECTS_SUMMARY2, number_projects))
<< " "
<< (quantity == 1
? format (STRING_CMD_PROJECTS_TASK, quantity)
: format (STRING_CMD_PROJECTS_TASKS, quantity))
<< "\n";
} }
else else
{ {
out << "No projects.\n"; out << STRING_CMD_PROJECTS_NO << "\n";
rc = 1; rc = 1;
} }
output = out.str (); output = out.str ();
*/
return rc; return rc;
} }
@ -138,7 +153,7 @@ CmdCompletionProjects::CmdCompletionProjects ()
{ {
_keyword = "_projects"; _keyword = "_projects";
_usage = "task _projects [<filter>]"; _usage = "task _projects [<filter>]";
_description = "Shows only a list of all project names used"; _description = STRING_CMD_PROJECTS_USAGE_2;
_read_only = true; _read_only = true;
_displays_id = false; _displays_id = false;
} }
@ -146,31 +161,34 @@ CmdCompletionProjects::CmdCompletionProjects ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdCompletionProjects::execute (std::string& output) int CmdCompletionProjects::execute (std::string& output)
{ {
/* // Get all the tasks.
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking")); context.tdb.lock (context.config.getBoolean ("locking"));
handleRecurrence ();
Filter filter;
if (context.config.getBoolean ("complete.all.projects")) if (context.config.getBoolean ("complete.all.projects"))
context.tdb.load (tasks, filter); context.tdb.load (tasks);
else else
context.tdb.loadPending (tasks, filter); context.tdb.loadPending (tasks);
context.tdb.commit (); context.tdb.commit ();
context.tdb.unlock (); context.tdb.unlock ();
// Apply filter.
std::vector <Task> filtered;
filter (tasks, filtered);
// Scan all the tasks for their project name, building a map using project // Scan all the tasks for their project name, building a map using project
// names as keys. // names as keys.
std::map <std::string, int> unique; std::map <std::string, int> unique;
std::vector <Task>::iterator task; std::vector <Task>::iterator task;
for (task = tasks.begin (); task != tasks.end (); ++task) for (task = filtered.begin (); task != filtered.end (); ++task)
unique[task->get ("project")] = 0; unique[task->get ("project")] = 0;
std::map <std::string, int>::iterator project; std::map <std::string, int>::iterator project;
for (project = unique.begin (); project != unique.end (); ++project) for (project = unique.begin (); project != unique.end (); ++project)
if (project->first.length ()) if (project->first.length ())
output += project->first + "\n"; output += project->first + "\n";
*/
return 0; return 0;
} }

View file

@ -108,6 +108,7 @@
// columns/Col* // columns/Col*
#define STRING_COLUMN_BAD_NAME "Unrecognized column name '{1}'" #define STRING_COLUMN_BAD_NAME "Unrecognized column name '{1}'"
#define STRING_COLUMN_BAD_FORMAT "Unrecognized column format '{1}.{2}'" #define STRING_COLUMN_BAD_FORMAT "Unrecognized column format '{1}.{2}'"
#define STRING_COLUMN_LABEL_TASKS "Tasks"
#define STRING_COLUMN_LABEL_DEP "Depends" #define STRING_COLUMN_LABEL_DEP "Depends"
#define STRING_COLUMN_LABEL_DEP_S "Dep" #define STRING_COLUMN_LABEL_DEP_S "Dep"
#define STRING_COLUMN_LABEL_DESC "Description" #define STRING_COLUMN_LABEL_DESC "Description"
@ -235,6 +236,18 @@
#define STRING_CMD_DONE_NOT_PENDING "Task {1} '{2}' is neither pending nor waiting." #define STRING_CMD_DONE_NOT_PENDING "Task {1} '{2}' is neither pending nor waiting."
#define STRING_CMD_DONE_MARKED "Marked {1} task as done" #define STRING_CMD_DONE_MARKED "Marked {1} task as done"
#define STRING_CMD_DONE_MARKED_N "Marked {1} tasks as done" #define STRING_CMD_DONE_MARKED_N "Marked {1} tasks as done"
#define STRING_CMD_PROJECTS_USAGE "Shows a list of all project names used, and how many tasks are in each"
#define STRING_CMD_PROJECTS_USAGE_2 "Shows only a list of all project names used"
#define STRING_CMD_PROJECTS_NO "No projects."
#define STRING_CMD_PROJECTS_PRI_N "Pri:None"
#define STRING_CMD_PROJECTS_PRI_H "Pri:H"
#define STRING_CMD_PROJECTS_PRI_M "Pri:M"
#define STRING_CMD_PROJECTS_PRI_L "Pri:L"
#define STRING_CMD_PROJECTS_NONE "(none)"
#define STRING_CMD_PROJECTS_SUMMARY "{1} project"
#define STRING_CMD_PROJECTS_SUMMARY2 "{1} projects"
#define STRING_CMD_PROJECTS_TASK "({1} task)"
#define STRING_CMD_PROJECTS_TASKS "({1} tasks)"
// Config // Config
#define STRING_CONFIG_OVERNEST "Configuration file nested to more than 10 levels deep - this has to be a mistake." #define STRING_CONFIG_OVERNEST "Configuration file nested to more than 10 levels deep - this has to be a mistake."