diff --git a/src/commands/CmdProjects.cpp b/src/commands/CmdProjects.cpp index 032fddc78..acc94371e 100644 --- a/src/commands/CmdProjects.cpp +++ b/src/commands/CmdProjects.cpp @@ -25,10 +25,14 @@ // //////////////////////////////////////////////////////////////////////////////// +#define L10N // Localization complete. + #include #include #include #include +#include +#include #include extern Context context; @@ -38,7 +42,7 @@ CmdProjects::CmdProjects () { _keyword = "projects"; _usage = "task projects []"; - _description = "Shows a list of all project names used, and how many tasks are in each"; + _description = STRING_CMD_PROJECTS_USAGE; _read_only = true; _displays_id = false; } @@ -47,20 +51,27 @@ CmdProjects::CmdProjects () int CmdProjects::execute (std::string& output) { int rc = 0; -/* - std::stringstream out; + // Get all the tasks. std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); + handleRecurrence (); + int quantity; if (context.config.getBoolean ("list.all.projects")) - quantity = context.tdb.load (tasks, context.filter); + quantity = context.tdb.load (tasks); else - quantity = context.tdb.loadPending (tasks, context.filter); + quantity = context.tdb.loadPending (tasks); context.tdb.commit (); context.tdb.unlock (); + // Apply filter. + std::vector filtered; + filter (tasks, filtered); + + std::stringstream out; + // Scan all the tasks for their project name, building a map using project // names as keys. std::map unique; @@ -72,7 +83,7 @@ int CmdProjects::execute (std::string& output) std::string project; std::string priority; std::vector ::iterator task; - for (task = tasks.begin (); task != tasks.end (); ++task) + for (task = filtered.begin (); task != filtered.end (); ++task) { project = task->get ("project"); priority = task->get ("priority"); @@ -92,18 +103,18 @@ int CmdProjects::execute (std::string& output) // 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")); + view.add (Column::factory ("string", STRING_COLUMN_LABEL_PROJECT)); + view.add (Column::factory ("string.right", STRING_COLUMN_LABEL_TASKS)); + view.add (Column::factory ("string.right", STRING_CMD_PROJECTS_PRI_N)); + view.add (Column::factory ("string.right", STRING_CMD_PROJECTS_PRI_H)); + view.add (Column::factory ("string.right", STRING_CMD_PROJECTS_PRI_M)); + view.add (Column::factory ("string.right", STRING_CMD_PROJECTS_PRI_L)); 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, 0, (project->first == "" ? STRING_CMD_PROJECTS_NONE : project->first)); view.set (row, 1, project->second); view.set (row, 2, none[project->first]); view.set (row, 3, low[project->first]); @@ -118,18 +129,22 @@ int CmdProjects::execute (std::string& output) out << optionalBlankLine () << view.render () << optionalBlankLine () - << number_projects - << (number_projects == 1 ? " project" : " projects") - << " (" << quantity << (quantity == 1 ? " task" : " tasks") << ")\n"; + << (number_projects == 1 + ? format (STRING_CMD_PROJECTS_SUMMARY, number_projects) + : format (STRING_CMD_PROJECTS_SUMMARY2, number_projects)) + << " " + << (quantity == 1 + ? format (STRING_CMD_PROJECTS_TASK, quantity) + : format (STRING_CMD_PROJECTS_TASKS, quantity)) + << "\n"; } else { - out << "No projects.\n"; + out << STRING_CMD_PROJECTS_NO << "\n"; rc = 1; } output = out.str (); -*/ return rc; } @@ -138,7 +153,7 @@ CmdCompletionProjects::CmdCompletionProjects () { _keyword = "_projects"; _usage = "task _projects []"; - _description = "Shows only a list of all project names used"; + _description = STRING_CMD_PROJECTS_USAGE_2; _read_only = true; _displays_id = false; } @@ -146,31 +161,34 @@ CmdCompletionProjects::CmdCompletionProjects () //////////////////////////////////////////////////////////////////////////////// int CmdCompletionProjects::execute (std::string& output) { -/* + // Get all the tasks. std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); + handleRecurrence (); - Filter filter; if (context.config.getBoolean ("complete.all.projects")) - context.tdb.load (tasks, filter); + context.tdb.load (tasks); else - context.tdb.loadPending (tasks, filter); + context.tdb.loadPending (tasks); context.tdb.commit (); context.tdb.unlock (); + // Apply filter. + std::vector filtered; + filter (tasks, filtered); + // 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) + for (task = filtered.begin (); task != filtered.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/en-US.h b/src/en-US.h index ab268dd14..4d87fc450 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -108,6 +108,7 @@ // columns/Col* #define STRING_COLUMN_BAD_NAME "Unrecognized column name '{1}'" #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_S "Dep" #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_MARKED "Marked {1} task 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 #define STRING_CONFIG_OVERNEST "Configuration file nested to more than 10 levels deep - this has to be a mistake."