mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
C++11: Cleaned up commands code with range-based for
This commit is contained in:
parent
bd3d58484a
commit
5a57dfd70d
42 changed files with 911 additions and 1065 deletions
|
@ -45,10 +45,9 @@ CmdCompletionAliases::CmdCompletionAliases ()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdCompletionAliases::execute (std::string& output)
|
||||
{
|
||||
std::map <std::string, std::string>::iterator alias;
|
||||
for (alias = context.config.begin (); alias != context.config.end (); ++alias)
|
||||
if (alias->first.substr (0, 6) == "alias.")
|
||||
output += alias->first.substr (6) + "\n";
|
||||
for (auto& alias : context.config)
|
||||
if (alias.first.substr (0, 6) == "alias.")
|
||||
output += alias.first.substr (6) + "\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -67,46 +67,44 @@ int CmdAnnotate::execute (std::string& output)
|
|||
// Accumulated project change notifications.
|
||||
std::map <std::string, std::string> projectChanges;
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
Task before (*task);
|
||||
Task before (task);
|
||||
|
||||
// Annotate the specified task.
|
||||
std::string question = format (STRING_CMD_ANNO_CONFIRM,
|
||||
task->id,
|
||||
task->get ("description"));
|
||||
task.id,
|
||||
task.get ("description"));
|
||||
|
||||
task->modify (Task::modAnnotate, true);
|
||||
task.modify (Task::modAnnotate, true);
|
||||
|
||||
if (permission (*task, taskDifferences (before, *task) + question, filtered.size ()))
|
||||
if (permission (task, taskDifferences (before, task) + question, filtered.size ()))
|
||||
{
|
||||
context.tdb2.modify (*task);
|
||||
context.tdb2.modify (task);
|
||||
++count;
|
||||
feedback_affected (STRING_CMD_ANNO_TASK, *task);
|
||||
feedback_affected (STRING_CMD_ANNO_TASK, task);
|
||||
if (context.verbose ("project"))
|
||||
projectChanges[task->get ("project")] = onProjectChange (*task, false);
|
||||
projectChanges[task.get ("project")] = onProjectChange (task, false);
|
||||
|
||||
// Annotate siblings.
|
||||
if (task->has ("parent"))
|
||||
if (task.has ("parent"))
|
||||
{
|
||||
if ((context.config.get ("recurrence.confirmation") == "prompt"
|
||||
&& confirm (STRING_CMD_ANNO_CONFIRM_R)) ||
|
||||
context.config.getBoolean ("recurrence.confirmation"))
|
||||
{
|
||||
std::vector <Task> siblings = context.tdb2.siblings (*task);
|
||||
std::vector <Task>::iterator sibling;
|
||||
for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling)
|
||||
std::vector <Task> siblings = context.tdb2.siblings (task);
|
||||
for (auto& sibling : siblings)
|
||||
{
|
||||
sibling->modify (Task::modAnnotate, true);
|
||||
context.tdb2.modify (*sibling);
|
||||
sibling.modify (Task::modAnnotate, true);
|
||||
context.tdb2.modify (sibling);
|
||||
++count;
|
||||
feedback_affected (STRING_CMD_ANNO_TASK_R, *sibling);
|
||||
feedback_affected (STRING_CMD_ANNO_TASK_R, sibling);
|
||||
}
|
||||
|
||||
// Annotate the parent
|
||||
Task parent;
|
||||
context.tdb2.get (task->get ("parent"), parent);
|
||||
context.tdb2.get (task.get ("parent"), parent);
|
||||
parent.modify (Task::modAnnotate, true);
|
||||
context.tdb2.modify (parent);
|
||||
}
|
||||
|
@ -122,10 +120,9 @@ int CmdAnnotate::execute (std::string& output)
|
|||
}
|
||||
|
||||
// Now list the project changes.
|
||||
std::map <std::string, std::string>::iterator i;
|
||||
for (i = projectChanges.begin (); i != projectChanges.end (); ++i)
|
||||
if (i->first != "")
|
||||
context.footnote (i->second);
|
||||
for (auto& change : projectChanges)
|
||||
if (change.first != "")
|
||||
context.footnote (change.second);
|
||||
|
||||
feedback_affected (count == 1 ? STRING_CMD_ANNO_1 : STRING_CMD_ANNO_N, count);
|
||||
return rc;
|
||||
|
|
|
@ -67,46 +67,44 @@ int CmdAppend::execute (std::string& output)
|
|||
// Accumulated project change notifications.
|
||||
std::map <std::string, std::string> projectChanges;
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
Task before (*task);
|
||||
Task before (task);
|
||||
|
||||
// Append to the specified task.
|
||||
std::string question = format (STRING_CMD_APPEND_CONFIRM,
|
||||
task->id,
|
||||
task->get ("description"));
|
||||
task.id,
|
||||
task.get ("description"));
|
||||
|
||||
task->modify (Task::modAppend, true);
|
||||
task.modify (Task::modAppend, true);
|
||||
|
||||
if (permission (*task, taskDifferences (before, *task) + question, filtered.size ()))
|
||||
if (permission (task, taskDifferences (before, task) + question, filtered.size ()))
|
||||
{
|
||||
context.tdb2.modify (*task);
|
||||
context.tdb2.modify (task);
|
||||
++count;
|
||||
feedback_affected (STRING_CMD_APPEND_TASK, *task);
|
||||
feedback_affected (STRING_CMD_APPEND_TASK, task);
|
||||
if (context.verbose ("project"))
|
||||
projectChanges[task->get ("project")] = onProjectChange (*task, false);
|
||||
projectChanges[task.get ("project")] = onProjectChange (task, false);
|
||||
|
||||
// Append to siblings.
|
||||
if (task->has ("parent"))
|
||||
if (task.has ("parent"))
|
||||
{
|
||||
if ((context.config.get ("recurrence.confirmation") == "prompt"
|
||||
&& confirm (STRING_CMD_APPEND_CONFIRM_R)) ||
|
||||
context.config.getBoolean ("recurrence.confirmation"))
|
||||
{
|
||||
std::vector <Task> siblings = context.tdb2.siblings (*task);
|
||||
std::vector <Task>::iterator sibling;
|
||||
for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling)
|
||||
std::vector <Task> siblings = context.tdb2.siblings (task);
|
||||
for (auto& sibling : siblings)
|
||||
{
|
||||
sibling->modify (Task::modAppend, true);
|
||||
context.tdb2.modify (*sibling);
|
||||
sibling.modify (Task::modAppend, true);
|
||||
context.tdb2.modify (sibling);
|
||||
++count;
|
||||
feedback_affected (STRING_CMD_APPEND_TASK_R, *sibling);
|
||||
feedback_affected (STRING_CMD_APPEND_TASK_R, sibling);
|
||||
}
|
||||
|
||||
// Append to the parent
|
||||
Task parent;
|
||||
context.tdb2.get (task->get ("parent"), parent);
|
||||
context.tdb2.get (task.get ("parent"), parent);
|
||||
parent.modify (Task::modAppend, true);
|
||||
context.tdb2.modify (parent);
|
||||
}
|
||||
|
@ -122,10 +120,9 @@ int CmdAppend::execute (std::string& output)
|
|||
}
|
||||
|
||||
// Now list the project changes.
|
||||
std::map <std::string, std::string>::iterator i;
|
||||
for (i = projectChanges.begin (); i != projectChanges.end (); ++i)
|
||||
if (i->first != "")
|
||||
context.footnote (i->second);
|
||||
for (auto& change : projectChanges)
|
||||
if (change.first != "")
|
||||
context.footnote (change.second);
|
||||
|
||||
feedback_affected (count == 1 ? STRING_CMD_APPEND_1 : STRING_CMD_APPEND_N, count);
|
||||
return rc;
|
||||
|
|
|
@ -48,16 +48,13 @@ CmdZshAttributes::CmdZshAttributes ()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdZshAttributes::execute (std::string& output)
|
||||
{
|
||||
// Get a list of all columns.
|
||||
// Get a list of all columns, sort them.
|
||||
std::vector <std::string> columns = context.getColumns ();
|
||||
|
||||
// Sort alphabetically.
|
||||
std::sort (columns.begin (), columns.end ());
|
||||
|
||||
std::stringstream out;
|
||||
std::vector <std::string>::iterator c;
|
||||
for (c = columns.begin (); c != columns.end (); ++c)
|
||||
out << *c << ":" << *c << "\n";
|
||||
for (auto& col : columns)
|
||||
out << col << ":" << col << "\n";
|
||||
|
||||
output = out.str ();
|
||||
return 0;
|
||||
|
|
|
@ -229,11 +229,10 @@ void Chart::scan (std::vector <Task>& tasks)
|
|||
Date now;
|
||||
|
||||
time_t epoch;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
for (auto& task : tasks)
|
||||
{
|
||||
// The entry date is when the counting starts.
|
||||
Date from = quantize (Date (task->get_date ("entry")));
|
||||
Date from = quantize (Date (task.get_date ("entry")));
|
||||
epoch = from.toEpoch ();
|
||||
|
||||
if (_bars.find (epoch) != _bars.end ())
|
||||
|
@ -241,24 +240,26 @@ void Chart::scan (std::vector <Task>& tasks)
|
|||
|
||||
// e--> e--s-->
|
||||
// ppp> pppsss>
|
||||
Task::status status = task->getStatus ();
|
||||
Task::status status = task.getStatus ();
|
||||
if (status == Task::pending ||
|
||||
status == Task::waiting)
|
||||
{
|
||||
if (task->has ("start"))
|
||||
if (task.has ("start"))
|
||||
{
|
||||
Date start = quantize (Date (task->get_date ("start")));
|
||||
Date start = quantize (Date (task.get_date ("start")));
|
||||
while (from < start)
|
||||
{
|
||||
epoch = from.toEpoch ();
|
||||
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._pending;
|
||||
if (_bars.find (epoch) != _bars.end ())
|
||||
++_bars[epoch]._pending;
|
||||
from = increment (from);
|
||||
}
|
||||
|
||||
while (from < now)
|
||||
{
|
||||
epoch = from.toEpoch ();
|
||||
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._started;
|
||||
if (_bars.find (epoch) != _bars.end ())
|
||||
++_bars[epoch]._started;
|
||||
from = increment (from);
|
||||
}
|
||||
}
|
||||
|
@ -267,7 +268,8 @@ void Chart::scan (std::vector <Task>& tasks)
|
|||
while (from < now)
|
||||
{
|
||||
epoch = from.toEpoch ();
|
||||
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._pending;
|
||||
if (_bars.find (epoch) != _bars.end ())
|
||||
++_bars[epoch]._pending;
|
||||
from = increment (from);
|
||||
}
|
||||
}
|
||||
|
@ -278,7 +280,7 @@ void Chart::scan (std::vector <Task>& tasks)
|
|||
else if (status == Task::completed)
|
||||
{
|
||||
// Truncate history so it starts at 'earliest' for completed tasks.
|
||||
Date end = quantize (Date (task->get_date ("end")));
|
||||
Date end = quantize (Date (task.get_date ("end")));
|
||||
epoch = end.toEpoch ();
|
||||
|
||||
if (_bars.find (epoch) != _bars.end ())
|
||||
|
@ -292,44 +294,49 @@ void Chart::scan (std::vector <Task>& tasks)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (task->has ("start"))
|
||||
if (task.has ("start"))
|
||||
{
|
||||
Date start = quantize (Date (task->get_date ("start")));
|
||||
Date start = quantize (Date (task.get_date ("start")));
|
||||
while (from < start)
|
||||
{
|
||||
epoch = from.toEpoch ();
|
||||
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._pending;
|
||||
if (_bars.find (epoch) != _bars.end ())
|
||||
++_bars[epoch]._pending;
|
||||
from = increment (from);
|
||||
}
|
||||
|
||||
while (from < end)
|
||||
{
|
||||
epoch = from.toEpoch ();
|
||||
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._started;
|
||||
if (_bars.find (epoch) != _bars.end ())
|
||||
++_bars[epoch]._started;
|
||||
from = increment (from);
|
||||
}
|
||||
|
||||
while (from < now)
|
||||
{
|
||||
epoch = from.toEpoch ();
|
||||
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._done;
|
||||
if (_bars.find (epoch) != _bars.end ())
|
||||
++_bars[epoch]._done;
|
||||
from = increment (from);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Date end = quantize (Date (task->get_date ("end")));
|
||||
Date end = quantize (Date (task.get_date ("end")));
|
||||
while (from < end)
|
||||
{
|
||||
epoch = from.toEpoch ();
|
||||
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._pending;
|
||||
if (_bars.find (epoch) != _bars.end ())
|
||||
++_bars[epoch]._pending;
|
||||
from = increment (from);
|
||||
}
|
||||
|
||||
while (from < now)
|
||||
{
|
||||
epoch = from.toEpoch ();
|
||||
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._done;
|
||||
if (_bars.find (epoch) != _bars.end ())
|
||||
++_bars[epoch]._done;
|
||||
from = increment (from);
|
||||
}
|
||||
}
|
||||
|
@ -340,7 +347,7 @@ void Chart::scan (std::vector <Task>& tasks)
|
|||
else if (status == Task::deleted)
|
||||
{
|
||||
// Skip old deleted tasks.
|
||||
Date end = quantize (Date (task->get_date ("end")));
|
||||
Date end = quantize (Date (task.get_date ("end")));
|
||||
epoch = end.toEpoch ();
|
||||
if (_bars.find (epoch) != _bars.end ())
|
||||
++_bars[epoch]._removed;
|
||||
|
@ -348,30 +355,33 @@ void Chart::scan (std::vector <Task>& tasks)
|
|||
if (end < _earliest)
|
||||
continue;
|
||||
|
||||
if (task->has ("start"))
|
||||
if (task.has ("start"))
|
||||
{
|
||||
Date start = quantize (Date (task->get_date ("start")));
|
||||
Date start = quantize (Date (task.get_date ("start")));
|
||||
while (from < start)
|
||||
{
|
||||
epoch = from.toEpoch ();
|
||||
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._pending;
|
||||
if (_bars.find (epoch) != _bars.end ())
|
||||
++_bars[epoch]._pending;
|
||||
from = increment (from);
|
||||
}
|
||||
|
||||
while (from < end)
|
||||
{
|
||||
epoch = from.toEpoch ();
|
||||
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._started;
|
||||
if (_bars.find (epoch) != _bars.end ())
|
||||
++_bars[epoch]._started;
|
||||
from = increment (from);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Date end = quantize (Date (task->get_date ("end")));
|
||||
Date end = quantize (Date (task.get_date ("end")));
|
||||
while (from < end)
|
||||
{
|
||||
epoch = from.toEpoch ();
|
||||
if (_bars.find (epoch) != _bars.end ()) ++_bars[epoch]._pending;
|
||||
if (_bars.find (epoch) != _bars.end ())
|
||||
++_bars[epoch]._pending;
|
||||
from = increment (from);
|
||||
}
|
||||
}
|
||||
|
@ -474,16 +484,14 @@ std::string Chart::render ()
|
|||
|
||||
// Draw x-axis labels.
|
||||
std::vector <time_t> bars_in_sequence;
|
||||
std::map <time_t, Bar>::iterator it;
|
||||
for (it = _bars.begin (); it != _bars.end (); ++it)
|
||||
bars_in_sequence.push_back (it->first);
|
||||
for (auto& bar : _bars)
|
||||
bars_in_sequence.push_back (bar.first);
|
||||
|
||||
std::sort (bars_in_sequence.begin (), bars_in_sequence.end ());
|
||||
std::vector <time_t>::iterator seq;
|
||||
std::string _major_label;
|
||||
for (seq = bars_in_sequence.begin (); seq != bars_in_sequence.end (); ++seq)
|
||||
for (auto& seq : bars_in_sequence)
|
||||
{
|
||||
Bar bar = _bars[*seq];
|
||||
Bar bar = _bars[seq];
|
||||
|
||||
// If it fits within the allowed space.
|
||||
if (bar._offset < _actual_bars)
|
||||
|
@ -498,15 +506,15 @@ std::string Chart::render ()
|
|||
}
|
||||
|
||||
// Draw bars.
|
||||
for (seq = bars_in_sequence.begin (); seq != bars_in_sequence.end (); ++seq)
|
||||
for (auto& seq : bars_in_sequence)
|
||||
{
|
||||
Bar bar = _bars[*seq];
|
||||
Bar bar = _bars[seq];
|
||||
|
||||
// If it fits within the allowed space.
|
||||
if (bar._offset < _actual_bars)
|
||||
{
|
||||
int pending = ( bar._pending * _graph_height) / _labels[2];
|
||||
int started = ((bar._pending + bar._started) * _graph_height) / _labels[2];
|
||||
int pending = ( bar._pending * _graph_height) / _labels[2];
|
||||
int started = ((bar._pending + bar._started) * _graph_height) / _labels[2];
|
||||
int done = ((bar._pending + bar._started + bar._done + _carryover_done) * _graph_height) / _labels[2];
|
||||
|
||||
for (int b = 0; b < pending; ++b)
|
||||
|
@ -772,13 +780,12 @@ void Chart::maxima ()
|
|||
_max_value = 0;
|
||||
_max_label = 1;
|
||||
|
||||
std::map <time_t, Bar>::iterator it;
|
||||
for (it = _bars.begin (); it != _bars.end (); it++)
|
||||
for (auto& bar : _bars)
|
||||
{
|
||||
// Determine _max_label.
|
||||
int total = it->second._pending +
|
||||
it->second._started +
|
||||
it->second._done +
|
||||
int total = bar.second._pending +
|
||||
bar.second._started +
|
||||
bar.second._done +
|
||||
_carryover_done;
|
||||
|
||||
// Determine _max_value.
|
||||
|
|
|
@ -64,9 +64,8 @@ int CmdCalc::execute (std::string& output)
|
|||
// Compile all the args into one expression.
|
||||
std::string expression;
|
||||
std::vector <std::string> words = context.cli.getWords ();
|
||||
std::vector <std::string>::iterator word;
|
||||
for (word = words.begin (); word != words.end (); ++word)
|
||||
expression += *word + " ";
|
||||
for (auto& word : words)
|
||||
expression += word + " ";
|
||||
|
||||
// Evaluate according to preference.
|
||||
Variant result;
|
||||
|
|
|
@ -66,7 +66,7 @@ int CmdCalendar::execute (std::string& output)
|
|||
|
||||
// Load the pending tasks.
|
||||
handleRecurrence ();
|
||||
std::vector <Task> tasks = context.tdb2.pending.get_tasks ();
|
||||
auto tasks = context.tdb2.pending.get_tasks ();
|
||||
|
||||
Date today;
|
||||
bool getpendingdate = false;
|
||||
|
@ -104,43 +104,42 @@ int CmdCalendar::execute (std::string& output)
|
|||
|
||||
std::vector <std::string> words = context.cli.getWords ();
|
||||
|
||||
std::vector <std::string>::iterator arg;
|
||||
for (arg = words.begin (); arg != words.end (); ++arg)
|
||||
for (auto& arg : words)
|
||||
{
|
||||
// Some version of "calendar".
|
||||
if (autoComplete (lowerCase (*arg), commandNames, matches, context.config.getInteger ("abbreviation.minimum")) == 1)
|
||||
if (autoComplete (lowerCase (arg), commandNames, matches, context.config.getInteger ("abbreviation.minimum")) == 1)
|
||||
continue;
|
||||
|
||||
// "due".
|
||||
else if (autoComplete (lowerCase (*arg), keywordNames, matches, context.config.getInteger ("abbreviation.minimum")) == 1)
|
||||
else if (autoComplete (lowerCase (arg), keywordNames, matches, context.config.getInteger ("abbreviation.minimum")) == 1)
|
||||
getpendingdate = true;
|
||||
|
||||
// "y".
|
||||
else if (lowerCase (*arg) == "y")
|
||||
else if (lowerCase (arg) == "y")
|
||||
argWholeYear = true;
|
||||
|
||||
// YYYY.
|
||||
else if (Lexer::isAllDigits (*arg) && arg->length () == 4)
|
||||
argYear = strtol (arg->c_str (), NULL, 10);
|
||||
else if (Lexer::isAllDigits (arg) && arg.length () == 4)
|
||||
argYear = strtol (arg.c_str (), NULL, 10);
|
||||
|
||||
// MM.
|
||||
else if (Lexer::isAllDigits (*arg) && arg->length () <= 2)
|
||||
else if (Lexer::isAllDigits (arg) && arg.length () <= 2)
|
||||
{
|
||||
argMonth = strtol (arg->c_str (), NULL, 10);
|
||||
argMonth = strtol (arg.c_str (), NULL, 10);
|
||||
if (argMonth < 1 || argMonth > 12)
|
||||
throw format (STRING_CMD_CAL_BAD_MONTH, *arg);
|
||||
throw format (STRING_CMD_CAL_BAD_MONTH, arg);
|
||||
}
|
||||
|
||||
// "January" etc.
|
||||
else if (autoComplete (lowerCase (*arg), monthNames, matches, context.config.getInteger ("abbreviation.minimum")) == 1)
|
||||
else if (autoComplete (lowerCase (arg), monthNames, matches, context.config.getInteger ("abbreviation.minimum")) == 1)
|
||||
{
|
||||
argMonth = Date::monthOfYear (matches[0]);
|
||||
if (argMonth == -1)
|
||||
throw format (STRING_CMD_CAL_BAD_MONTH, *arg);
|
||||
throw format (STRING_CMD_CAL_BAD_MONTH, arg);
|
||||
}
|
||||
|
||||
else
|
||||
throw format (STRING_CMD_CAL_BAD_ARG, *arg);
|
||||
throw format (STRING_CMD_CAL_BAD_ARG, arg);
|
||||
}
|
||||
|
||||
// Supported combinations:
|
||||
|
@ -172,16 +171,15 @@ int CmdCalendar::execute (std::string& output)
|
|||
{
|
||||
// Find the oldest pending due date.
|
||||
Date oldest (12, 31, 2037);
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
for (auto& task : tasks)
|
||||
{
|
||||
if (task->getStatus () == Task::pending)
|
||||
if (task.getStatus () == Task::pending)
|
||||
{
|
||||
if (task->has ("due") &&
|
||||
!task->hasTag ("nocal"))
|
||||
if (task.has ("due") &&
|
||||
!task.hasTag ("nocal"))
|
||||
{
|
||||
++countDueDates;
|
||||
Date d (task->get ("due"));
|
||||
Date d (task.get ("due"));
|
||||
if (d < oldest) oldest = d;
|
||||
}
|
||||
}
|
||||
|
@ -365,20 +363,17 @@ int CmdCalendar::execute (std::string& output)
|
|||
holTable.add (Column::factory ("string", STRING_CMD_CAL_LABEL_HOL));
|
||||
holTable.colorHeader (color_label);
|
||||
|
||||
Config::const_iterator it;
|
||||
std::map <time_t, std::vector<std::string>> hm; // we need to store multiple holidays per day
|
||||
for (it = context.config.begin (); it != context.config.end (); ++it)
|
||||
if (it->first.substr (0, 8) == "holiday.")
|
||||
if (it->first.substr (it->first.size () - 4) == "name")
|
||||
for (auto& it : context.config)
|
||||
if (it.first.substr (0, 8) == "holiday.")
|
||||
if (it.first.substr (it.first.size () - 4) == "name")
|
||||
{
|
||||
std::string holName = context.config.get ("holiday." + it->first.substr (8, it->first.size () - 13) + ".name");
|
||||
std::string holDate = context.config.get ("holiday." + it->first.substr (8, it->first.size () - 13) + ".date");
|
||||
std::string holName = context.config.get ("holiday." + it.first.substr (8, it.first.size () - 13) + ".name");
|
||||
std::string holDate = context.config.get ("holiday." + it.first.substr (8, it.first.size () - 13) + ".date");
|
||||
Date hDate (holDate.c_str (), context.config.get ("dateformat.holiday"));
|
||||
|
||||
if (date_after < hDate && hDate < date_before)
|
||||
{
|
||||
hm[hDate.toEpoch()].push_back(holName);
|
||||
}
|
||||
}
|
||||
|
||||
std::string format = context.config.get ("report." +
|
||||
|
@ -389,11 +384,10 @@ int CmdCalendar::execute (std::string& output)
|
|||
if (format == "")
|
||||
format = context.config.get ("dateformat");
|
||||
|
||||
std::map <time_t, std::vector<std::string>>::iterator hm_it;
|
||||
for (hm_it = hm.begin(); hm_it != hm.end(); ++hm_it)
|
||||
for (auto& hm_it : hm)
|
||||
{
|
||||
std::vector <std::string> v = hm_it->second;
|
||||
Date hDate (hm_it->first);
|
||||
std::vector <std::string> v = hm_it.second;
|
||||
Date hDate (hm_it.first);
|
||||
std::string d = hDate.toString (format);
|
||||
for (size_t i = 0; i < v.size(); i++)
|
||||
{
|
||||
|
@ -535,12 +529,11 @@ std::string CmdCalendar::renderMonths (
|
|||
// colorize holidays
|
||||
if (context.config.get ("calendar.holidays") != "none")
|
||||
{
|
||||
Config::const_iterator hol;
|
||||
for (hol = context.config.begin (); hol != context.config.end (); ++hol)
|
||||
if (hol->first.substr (0, 8) == "holiday.")
|
||||
if (hol->first.substr (hol->first.size () - 4) == "date")
|
||||
for (auto& hol : context.config)
|
||||
if (hol.first.substr (0, 8) == "holiday.")
|
||||
if (hol.first.substr (hol.first.size () - 4) == "date")
|
||||
{
|
||||
std::string value = hol->second;
|
||||
std::string value = hol.second;
|
||||
Date holDate (value.c_str (), context.config.get ("dateformat.holiday"));
|
||||
if (holDate.day () == d &&
|
||||
holDate.month () == months[mpl] &&
|
||||
|
@ -559,21 +552,20 @@ std::string CmdCalendar::renderMonths (
|
|||
if (context.config.get ("calendar.details") != "none")
|
||||
{
|
||||
context.config.set ("due", 0);
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = all.begin (); task != all.end (); ++task)
|
||||
for (auto& task : all)
|
||||
{
|
||||
if (task->getStatus () == Task::pending &&
|
||||
!task->hasTag ("nocal") &&
|
||||
task->has ("due"))
|
||||
if (task.getStatus () == Task::pending &&
|
||||
!task.hasTag ("nocal") &&
|
||||
task.has ("due"))
|
||||
{
|
||||
std::string due = task->get ("due");
|
||||
std::string due = task.get ("due");
|
||||
Date duedmy (strtol (due.c_str(), NULL, 10));
|
||||
|
||||
if (duedmy.day () == d &&
|
||||
duedmy.month () == months[mpl] &&
|
||||
duedmy.year () == years[mpl])
|
||||
{
|
||||
switch (task->getDateState ("due"))
|
||||
switch (task.getDateState ("due"))
|
||||
{
|
||||
case Task::dateNotDue:
|
||||
break;
|
||||
|
|
|
@ -55,9 +55,8 @@ int CmdColor::execute (std::string& output)
|
|||
// Get the non-attribute, non-fancy command line arguments.
|
||||
bool legend = false;
|
||||
std::vector <std::string> words = context.cli.getWords ();
|
||||
std::vector <std::string>::iterator word;
|
||||
for (word = words.begin (); word != words.end (); ++word)
|
||||
if (closeEnough ("legend", *word))
|
||||
for (auto& word : words)
|
||||
if (closeEnough ("legend", word))
|
||||
legend = true;
|
||||
|
||||
std::stringstream out;
|
||||
|
@ -74,19 +73,18 @@ int CmdColor::execute (std::string& output)
|
|||
view.add (Column::factory ("string", STRING_CMD_COLOR_COLOR));
|
||||
view.add (Column::factory ("string", STRING_CMD_COLOR_DEFINITION));
|
||||
|
||||
Config::const_iterator item;
|
||||
for (item = context.config.begin (); item != context.config.end (); ++item)
|
||||
for (auto& item : context.config)
|
||||
{
|
||||
// Skip items with 'color' in their name, that are not referring to
|
||||
// actual colors.
|
||||
if (item->first != "_forcecolor" &&
|
||||
item->first != "color" &&
|
||||
item->first.find ("color") == 0)
|
||||
if (item.first != "_forcecolor" &&
|
||||
item.first != "color" &&
|
||||
item.first.find ("color") == 0)
|
||||
{
|
||||
Color color (context.config.get (item->first));
|
||||
Color color (context.config.get (item.first));
|
||||
int row = view.addRow ();
|
||||
view.set (row, 0, item->first, color);
|
||||
view.set (row, 1, item->second, color);
|
||||
view.set (row, 0, item.first, color);
|
||||
view.set (row, 1, item.second, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,7 +104,7 @@ int CmdColor::execute (std::string& output)
|
|||
Color six ("red on color173");
|
||||
|
||||
std::string swatch;
|
||||
for (word = words.begin (); word != words.end (); ++word)
|
||||
for (auto word = words.begin (); word != words.end (); ++word)
|
||||
{
|
||||
if (word != words.begin ())
|
||||
swatch += " ";
|
||||
|
|
|
@ -57,9 +57,8 @@ int CmdColumns::execute (std::string& output)
|
|||
|
||||
// Include all columns in the table.
|
||||
std::vector <std::string> names;
|
||||
std::map <std::string, Column*>::const_iterator col;
|
||||
for (col = context.columns.begin (); col != context.columns.end (); ++col)
|
||||
names.push_back (col->first);
|
||||
for (auto& col : context.columns)
|
||||
names.push_back (col.first);
|
||||
|
||||
std::sort (names.begin (), names.end ());
|
||||
|
||||
|
@ -77,19 +76,18 @@ int CmdColumns::execute (std::string& output)
|
|||
formats.colorOdd (alternate);
|
||||
formats.intraColorOdd (alternate);
|
||||
|
||||
std::vector <std::string>::iterator name;
|
||||
for (name = names.begin (); name != names.end (); ++name)
|
||||
for (auto& name : names)
|
||||
{
|
||||
if (words.size () == 0 ||
|
||||
find (*name, words[0], false) != std::string::npos)
|
||||
find (name, words[0], false) != std::string::npos)
|
||||
{
|
||||
const std::vector <std::string> styles = context.columns[*name]->styles ();
|
||||
const std::vector <std::string> examples = context.columns[*name]->examples ();
|
||||
const std::vector <std::string> styles = context.columns[name]->styles ();
|
||||
const std::vector <std::string> examples = context.columns[name]->examples ();
|
||||
|
||||
for (unsigned int i = 0; i < styles.size (); ++i)
|
||||
{
|
||||
int row = formats.addRow ();
|
||||
formats.set (row, 0, i == 0 ? *name : "");
|
||||
formats.set (row, 0, i == 0 ? name : "");
|
||||
formats.set (row, 1, styles[i] + (i == 0 ? "*" : ""));
|
||||
formats.set (row, 2, i < examples.size () ? examples[i] : "");
|
||||
}
|
||||
|
@ -120,16 +118,14 @@ int CmdCompletionColumns::execute (std::string& output)
|
|||
{
|
||||
// Include all columns.
|
||||
std::vector <std::string> names;
|
||||
std::map <std::string, Column*>::const_iterator col;
|
||||
for (col = context.columns.begin (); col != context.columns.end (); ++col)
|
||||
names.push_back (col->first);
|
||||
for (auto& col : context.columns)
|
||||
names.push_back (col.first);
|
||||
|
||||
std::sort (names.begin (), names.end ());
|
||||
|
||||
// Render only the column names.
|
||||
std::vector <std::string>::iterator name;
|
||||
for (name = names.begin (); name != names.end (); ++name)
|
||||
output += *name + "\n";
|
||||
for (auto& name : names)
|
||||
output += name + "\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -51,21 +51,15 @@ int CmdCompletionCommands::execute (std::string& output)
|
|||
// Get a list of all commands.
|
||||
std::vector <std::string> commands;
|
||||
|
||||
std::map <std::string, Command*>::iterator command;
|
||||
for (command = context.commands.begin ();
|
||||
command != context.commands.end ();
|
||||
++command)
|
||||
{
|
||||
commands.push_back (command->first);
|
||||
}
|
||||
for (auto& command : context.commands)
|
||||
commands.push_back (command.first);
|
||||
|
||||
// Sort alphabetically.
|
||||
std::sort (commands.begin (), commands.end ());
|
||||
|
||||
std::stringstream out;
|
||||
std::vector <std::string>::iterator c;
|
||||
for (c = commands.begin (); c != commands.end (); ++c)
|
||||
out << *c << "\n";
|
||||
for (auto& c : commands)
|
||||
out << c << "\n";
|
||||
|
||||
output = out.str ();
|
||||
return 0;
|
||||
|
@ -87,21 +81,15 @@ int CmdZshCommands::execute (std::string& output)
|
|||
// Get a list of all commands.
|
||||
std::vector <std::string> commands;
|
||||
|
||||
std::map <std::string, Command*>::iterator command;
|
||||
for (command = context.commands.begin ();
|
||||
command != context.commands.end ();
|
||||
++command)
|
||||
{
|
||||
commands.push_back (command->first);
|
||||
}
|
||||
for (auto& command : context.commands)
|
||||
commands.push_back (command.first);
|
||||
|
||||
// Sort alphabetically.
|
||||
std::sort (commands.begin (), commands.end ());
|
||||
|
||||
std::stringstream out;
|
||||
std::vector <std::string>::iterator c;
|
||||
for (c = commands.begin (); c != commands.end (); ++c)
|
||||
out << *c << ":" << context.commands[*c]->description () << "\n";
|
||||
for (auto& c : commands)
|
||||
out << c << ":" << context.commands[c]->description () << "\n";
|
||||
|
||||
output = out.str ();
|
||||
return 0;
|
||||
|
|
|
@ -56,12 +56,11 @@ bool CmdConfig::setConfigVariable (std::string name, std::string value, bool con
|
|||
bool found = false;
|
||||
bool change = false;
|
||||
|
||||
std::vector <std::string>::iterator line;
|
||||
for (line = contents.begin (); line != contents.end (); ++line)
|
||||
for (auto& line : contents)
|
||||
{
|
||||
// If there is a comment on the line, it must follow the pattern.
|
||||
std::string::size_type comment = line->find ("#");
|
||||
std::string::size_type pos = line->find (name + "=");
|
||||
std::string::size_type comment = line.find ("#");
|
||||
std::string::size_type pos = line.find (name + "=");
|
||||
|
||||
if (pos != std::string::npos &&
|
||||
(comment == std::string::npos ||
|
||||
|
@ -72,9 +71,9 @@ bool CmdConfig::setConfigVariable (std::string name, std::string value, bool con
|
|||
confirm (format (STRING_CMD_CONFIG_CONFIRM, name, context.config.get (name), value)))
|
||||
{
|
||||
if (comment != std::string::npos)
|
||||
*line = name + "=" + json::encode (value) + " " + line->substr (comment);
|
||||
line = name + "=" + json::encode (value) + " " + line.substr (comment);
|
||||
else
|
||||
*line = name + "=" + json::encode (value);
|
||||
line = name + "=" + json::encode (value);
|
||||
|
||||
change = true;
|
||||
}
|
||||
|
@ -106,8 +105,7 @@ int CmdConfig::unsetConfigVariable (std::string name, bool confirmation /* = fal
|
|||
bool found = false;
|
||||
bool change = false;
|
||||
|
||||
std::vector <std::string>::iterator line;
|
||||
for (line = contents.begin (); line != contents.end (); )
|
||||
for (auto line = contents.begin (); line != contents.end (); )
|
||||
{
|
||||
bool lineDeleted = false;
|
||||
|
||||
|
@ -243,9 +241,8 @@ int CmdCompletionConfig::execute (std::string& output)
|
|||
context.config.all (configs);
|
||||
std::sort (configs.begin (), configs.end ());
|
||||
|
||||
std::vector <std::string>::iterator config;
|
||||
for (config = configs.begin (); config != configs.end (); ++config)
|
||||
output += *config + "\n";
|
||||
for (auto& config : configs)
|
||||
output += config + "\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -109,10 +109,9 @@ std::vector <std::string> CmdContext::getContexts ()
|
|||
{
|
||||
std::vector <std::string> contexts;
|
||||
|
||||
Config::const_iterator name;
|
||||
for (name = context.config.begin (); name != context.config.end (); ++name)
|
||||
if (name->first.substr (0, 8) == "context.")
|
||||
contexts.push_back (name->first.substr (8));
|
||||
for (auto& name : context.config)
|
||||
if (name.first.substr (0, 8) == "context.")
|
||||
contexts.push_back (name.first.substr (8));
|
||||
|
||||
return contexts;
|
||||
}
|
||||
|
@ -140,7 +139,7 @@ int CmdContext::defineContext (std::vector <std::string>& words, std::stringstre
|
|||
// Check if the value is a proper filter by filtering current pending.data
|
||||
Filter filter;
|
||||
std::vector <Task> filtered;
|
||||
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
|
||||
auto pending = context.tdb2.pending.get_tasks ();
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -246,13 +245,12 @@ int CmdContext::listContexts (std::vector <std::string>& words, std::stringstrea
|
|||
Color label (context.config.get ("color.label"));
|
||||
view.colorHeader (label);
|
||||
|
||||
std::vector <std::string>::iterator userContext;
|
||||
for (userContext = contexts.begin (); userContext != contexts.end (); ++userContext)
|
||||
for (auto& userContext : contexts)
|
||||
{
|
||||
std::string definition = context.config.get ("context." + *userContext);
|
||||
std::string definition = context.config.get ("context." + userContext);
|
||||
|
||||
int row = view.addRow ();
|
||||
view.set (row, 0, *userContext);
|
||||
view.set (row, 0, userContext);
|
||||
view.set (row, 1, definition);
|
||||
}
|
||||
|
||||
|
@ -369,9 +367,8 @@ int CmdCompletionContext::execute (std::string& output)
|
|||
{
|
||||
std::vector <std::string> userContexts = CmdContext::getContexts ();
|
||||
|
||||
std::vector <std::string>::iterator userContext;
|
||||
for (userContext = userContexts.begin (); userContext != userContexts.end (); ++userContext)
|
||||
output += *userContext + "\n";
|
||||
for (auto& userContext : userContexts)
|
||||
output += userContext + "\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -55,9 +55,8 @@ int CmdCount::execute (std::string& output)
|
|||
|
||||
// Find number of matching tasks. Skip recurring parent tasks.
|
||||
int count = 0;
|
||||
std::vector <Task>::iterator it;
|
||||
for (it = filtered.begin (); it != filtered.end (); ++it)
|
||||
if (it->getStatus () != Task::recurring)
|
||||
for (auto& task : filtered)
|
||||
if (task.getStatus () != Task::recurring)
|
||||
++count;
|
||||
|
||||
output = format (count) + "\n";
|
||||
|
|
|
@ -118,13 +118,12 @@ int CmdCustom::execute (std::string& output)
|
|||
std::vector <std::string> sortColumns;
|
||||
|
||||
// Add the break columns, if any.
|
||||
std::vector <std::string>::iterator so;
|
||||
for (so = sortOrder.begin (); so != sortOrder.end (); ++so)
|
||||
for (auto& so : sortOrder)
|
||||
{
|
||||
std::string name;
|
||||
bool ascending;
|
||||
bool breakIndicator;
|
||||
context.decomposeSortField (*so, name, ascending, breakIndicator);
|
||||
context.decomposeSortField (so, name, ascending, breakIndicator);
|
||||
|
||||
if (breakIndicator)
|
||||
view.addBreak (name);
|
||||
|
@ -211,17 +210,15 @@ int CmdCustom::execute (std::string& output)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
void CmdCustom::validateReportColumns (std::vector <std::string>& columns)
|
||||
{
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = columns.begin (); i != columns.end (); ++i)
|
||||
legacyColumnMap (*i);
|
||||
for (auto& col : columns)
|
||||
legacyColumnMap (col);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void CmdCustom::validateSortColumns (std::vector <std::string>& columns)
|
||||
{
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = columns.begin (); i != columns.end (); ++i)
|
||||
legacySortColumnMap (*i);
|
||||
for (auto& col : columns)
|
||||
legacySortColumnMap (col);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -66,66 +66,64 @@ int CmdDelete::execute (std::string& output)
|
|||
// Accumulated project change notifications.
|
||||
std::map <std::string, std::string> projectChanges;
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
Task before (*task);
|
||||
Task before (task);
|
||||
|
||||
if (task->getStatus () != Task::deleted)
|
||||
if (task.getStatus () != Task::deleted)
|
||||
{
|
||||
// Delete the specified task.
|
||||
std::string question;
|
||||
if (task->id)
|
||||
if (task.id)
|
||||
question = format (STRING_CMD_DELETE_CONFIRM,
|
||||
task->id,
|
||||
task->get ("description"));
|
||||
task.id,
|
||||
task.get ("description"));
|
||||
else
|
||||
question = format (STRING_CMD_DELETE_CONFIRM,
|
||||
task->get ("uuid"),
|
||||
task->get ("description"));
|
||||
task.get ("uuid"),
|
||||
task.get ("description"));
|
||||
|
||||
task->modify (Task::modAnnotate);
|
||||
task->setStatus (Task::deleted);
|
||||
if (! task->has ("end"))
|
||||
task->setAsNow ("end");
|
||||
task.modify (Task::modAnnotate);
|
||||
task.setStatus (Task::deleted);
|
||||
if (! task.has ("end"))
|
||||
task.setAsNow ("end");
|
||||
|
||||
if (permission (*task, question, filtered.size ()))
|
||||
if (permission (task, question, filtered.size ()))
|
||||
{
|
||||
updateRecurrenceMask (*task);
|
||||
updateRecurrenceMask (task);
|
||||
++count;
|
||||
context.tdb2.modify (*task);
|
||||
feedback_affected (STRING_CMD_DELETE_TASK, *task);
|
||||
feedback_unblocked (*task);
|
||||
dependencyChainOnComplete (*task);
|
||||
context.tdb2.modify (task);
|
||||
feedback_affected (STRING_CMD_DELETE_TASK, task);
|
||||
feedback_unblocked (task);
|
||||
dependencyChainOnComplete (task);
|
||||
if (context.verbose ("project"))
|
||||
projectChanges[task->get ("project")] = onProjectChange (*task);
|
||||
projectChanges[task.get ("project")] = onProjectChange (task);
|
||||
|
||||
// Delete siblings.
|
||||
if (task->has ("parent"))
|
||||
if (task.has ("parent"))
|
||||
{
|
||||
if ((context.config.get ("recurrence.confirmation") == "prompt"
|
||||
&& confirm (STRING_CMD_DELETE_CONFIRM_R)) ||
|
||||
context.config.getBoolean ("recurrence.confirmation"))
|
||||
{
|
||||
std::vector <Task> siblings = context.tdb2.siblings (*task);
|
||||
std::vector <Task>::iterator sibling;
|
||||
for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling)
|
||||
std::vector <Task> siblings = context.tdb2.siblings (task);
|
||||
for (auto& sibling : siblings)
|
||||
{
|
||||
sibling->modify (Task::modAnnotate);
|
||||
sibling->setStatus (Task::deleted);
|
||||
if (! sibling->has ("end"))
|
||||
sibling->setAsNow ("end");
|
||||
sibling.modify (Task::modAnnotate);
|
||||
sibling.setStatus (Task::deleted);
|
||||
if (! sibling.has ("end"))
|
||||
sibling.setAsNow ("end");
|
||||
|
||||
updateRecurrenceMask (*sibling);
|
||||
context.tdb2.modify (*sibling);
|
||||
feedback_affected (STRING_CMD_DELETE_TASK_R, *sibling);
|
||||
feedback_unblocked (*sibling);
|
||||
updateRecurrenceMask (sibling);
|
||||
context.tdb2.modify (sibling);
|
||||
feedback_affected (STRING_CMD_DELETE_TASK_R, sibling);
|
||||
feedback_unblocked (sibling);
|
||||
++count;
|
||||
}
|
||||
|
||||
// Delete the parent
|
||||
Task parent;
|
||||
context.tdb2.get (task->get ("parent"), parent);
|
||||
context.tdb2.get (task.get ("parent"), parent);
|
||||
parent.setStatus (Task::deleted);
|
||||
if (! parent.has ("end"))
|
||||
parent.setAsNow ("end");
|
||||
|
@ -137,23 +135,22 @@ int CmdDelete::execute (std::string& output)
|
|||
// Task potentially has child tasks - optionally delete them.
|
||||
else
|
||||
{
|
||||
std::vector <Task> children = context.tdb2.children (*task);
|
||||
std::vector <Task> children = context.tdb2.children (task);
|
||||
if (children.size () &&
|
||||
(context.config.getBoolean ("recurrence.confirmation") ||
|
||||
confirm (STRING_CMD_DELETE_CONFIRM_R)))
|
||||
{
|
||||
std::vector <Task>::iterator child;
|
||||
for (child = children.begin (); child != children.end (); ++child)
|
||||
for (auto& child : children)
|
||||
{
|
||||
child->modify (Task::modAnnotate);
|
||||
child->setStatus (Task::deleted);
|
||||
if (! child->has ("end"))
|
||||
child->setAsNow ("end");
|
||||
child.modify (Task::modAnnotate);
|
||||
child.setStatus (Task::deleted);
|
||||
if (! child.has ("end"))
|
||||
child.setAsNow ("end");
|
||||
|
||||
updateRecurrenceMask (*child);
|
||||
context.tdb2.modify (*child);
|
||||
feedback_affected (STRING_CMD_DELETE_TASK_R, *child);
|
||||
feedback_unblocked (*child);
|
||||
updateRecurrenceMask (child);
|
||||
context.tdb2.modify (child);
|
||||
feedback_affected (STRING_CMD_DELETE_TASK_R, child);
|
||||
feedback_unblocked (child);
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
@ -170,18 +167,17 @@ int CmdDelete::execute (std::string& output)
|
|||
else
|
||||
{
|
||||
std::cout << format (STRING_CMD_DELETE_NOT_DEL,
|
||||
task->id,
|
||||
task->get ("description"))
|
||||
task.id,
|
||||
task.get ("description"))
|
||||
<< "\n";
|
||||
rc = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Now list the project changes.
|
||||
std::map <std::string, std::string>::iterator i;
|
||||
for (i = projectChanges.begin (); i != projectChanges.end (); ++i)
|
||||
if (i->first != "")
|
||||
context.footnote (i->second);
|
||||
for (auto& change : projectChanges)
|
||||
if (change.first != "")
|
||||
context.footnote (change.second);
|
||||
|
||||
feedback_affected (count == 1 ? STRING_CMD_DELETE_1 : STRING_CMD_DELETE_N, count);
|
||||
return rc;
|
||||
|
|
|
@ -65,75 +65,73 @@ int CmdDenotate::execute (std::string& output)
|
|||
|
||||
// Extract all the ORIGINAL MODIFICATION args as simple text patterns.
|
||||
std::string pattern = "";
|
||||
std::vector <A>::iterator a;
|
||||
for (a = context.cli._args.begin (); a != context.cli._args.end (); ++a)
|
||||
for (auto& a : context.cli._args)
|
||||
{
|
||||
if (a->hasTag ("ORIGINAL") &&
|
||||
a->hasTag ("MODIFICATION"))
|
||||
if (a.hasTag ("ORIGINAL") &&
|
||||
a.hasTag ("MODIFICATION"))
|
||||
{
|
||||
if (pattern != "")
|
||||
pattern += ' ';
|
||||
|
||||
pattern += a->attribute ("raw");
|
||||
pattern += a.attribute ("raw");
|
||||
}
|
||||
}
|
||||
|
||||
// Accumulated project change notifications.
|
||||
std::map <std::string, std::string> projectChanges;
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
Task before (*task);
|
||||
Task before (task);
|
||||
|
||||
std::map <std::string, std::string> annotations;
|
||||
task->getAnnotations (annotations);
|
||||
task.getAnnotations (annotations);
|
||||
|
||||
if (annotations.size () == 0)
|
||||
throw std::string (STRING_CMD_DENO_NONE);
|
||||
|
||||
std::map <std::string, std::string>::iterator i;
|
||||
std::string anno;
|
||||
bool match = false;
|
||||
for (i = annotations.begin (); i != annotations.end (); ++i)
|
||||
for (auto i = annotations.begin (); i != annotations.end (); ++i)
|
||||
{
|
||||
if (i->second == pattern)
|
||||
{
|
||||
match = true;
|
||||
anno = i->second;
|
||||
annotations.erase (i);
|
||||
task->setAnnotations (annotations);
|
||||
task.setAnnotations (annotations);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (! match)
|
||||
{
|
||||
for (i = annotations.begin (); i != annotations.end (); ++i)
|
||||
for (auto i = annotations.begin (); i != annotations.end (); ++i)
|
||||
{
|
||||
std::string::size_type loc = find (i->second, pattern, sensitive);
|
||||
if (loc != std::string::npos)
|
||||
{
|
||||
anno = i->second;
|
||||
annotations.erase (i);
|
||||
task->setAnnotations (annotations);
|
||||
task.setAnnotations (annotations);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (taskDiff (before, *task))
|
||||
if (taskDiff (before, task))
|
||||
{
|
||||
std::string question = format (STRING_CMD_DENO_CONFIRM,
|
||||
task->id,
|
||||
task->get ("description"));
|
||||
task.id,
|
||||
task.get ("description"));
|
||||
|
||||
if (permission (*task, taskDifferences (before, *task) + question, filtered.size ()))
|
||||
if (permission (task, taskDifferences (before, task) + question, filtered.size ()))
|
||||
{
|
||||
++count;
|
||||
context.tdb2.modify (*task);
|
||||
context.tdb2.modify (task);
|
||||
feedback_affected (format (STRING_CMD_DENO_FOUND, anno));
|
||||
if (context.verbose ("project"))
|
||||
projectChanges[task->get ("project")] = onProjectChange (*task, false);
|
||||
projectChanges[task.get ("project")] = onProjectChange (task, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -151,10 +149,9 @@ int CmdDenotate::execute (std::string& output)
|
|||
}
|
||||
|
||||
// Now list the project changes.
|
||||
std::map <std::string, std::string>::iterator i;
|
||||
for (i = projectChanges.begin (); i != projectChanges.end (); ++i)
|
||||
if (i->first != "")
|
||||
context.footnote (i->second);
|
||||
for (auto& change : projectChanges)
|
||||
if (change.first != "")
|
||||
context.footnote (change.second);
|
||||
|
||||
feedback_affected (count == 1 ? STRING_CMD_DENO_1 : STRING_CMD_DENO_N, count);
|
||||
return rc;
|
||||
|
|
|
@ -305,13 +305,12 @@ int CmdDiagnostics::execute (std::string& output)
|
|||
std::vector <std::string> hooks = context.hooks.list ();
|
||||
if (hooks.size ())
|
||||
{
|
||||
std::vector <std::string>::iterator h;
|
||||
for (h = hooks.begin (); h != hooks.end (); ++h)
|
||||
for (auto& hook : hooks)
|
||||
{
|
||||
Path p (*h);
|
||||
Path p (hook);
|
||||
std::string name = p.name ();
|
||||
out << " "
|
||||
<< *h
|
||||
<< hook
|
||||
<< (p.executable () ? format (" ({1})", STRING_CMD_DIAG_HOOK_EXEC) : format (" ({1})", STRING_CMD_DIAG_HOOK_NO_EXEC))
|
||||
<< (p.is_link () ? format (" ({1})", STRING_CMD_DIAG_HOOK_SYMLINK) : "")
|
||||
<< ((name.substr (0, 6) == "on-add" ||
|
||||
|
@ -345,10 +344,9 @@ int CmdDiagnostics::execute (std::string& output)
|
|||
std::map <std::string, int> seen;
|
||||
std::vector <std::string> dups;
|
||||
std::string uuid;
|
||||
std::vector <Task>::iterator i;
|
||||
for (i = all.begin (); i != all.end (); ++i)
|
||||
for (auto& i : all)
|
||||
{
|
||||
uuid = i->get ("uuid");
|
||||
uuid = i.get ("uuid");
|
||||
if (seen.find (uuid) != seen.end ())
|
||||
dups.push_back (uuid);
|
||||
else
|
||||
|
@ -361,9 +359,8 @@ int CmdDiagnostics::execute (std::string& output)
|
|||
|
||||
if (dups.size ())
|
||||
{
|
||||
std::vector <std::string>::iterator d;
|
||||
for (d = dups.begin (); d != dups.end (); ++d)
|
||||
out << " " << format (STRING_CMD_DIAG_UUID_DUP, *d) << "\n";
|
||||
for (auto& d : dups)
|
||||
out << " " << format (STRING_CMD_DIAG_UUID_DUP, d) << "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -66,44 +66,43 @@ int CmdDone::execute (std::string& output)
|
|||
std::map <std::string, std::string> projectChanges;
|
||||
|
||||
bool nagged = false;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
Task before (*task);
|
||||
Task before (task);
|
||||
|
||||
if (task->getStatus () == Task::pending ||
|
||||
task->getStatus () == Task::waiting)
|
||||
if (task.getStatus () == Task::pending ||
|
||||
task.getStatus () == Task::waiting)
|
||||
{
|
||||
// Complete the specified task.
|
||||
std::string question = format (STRING_CMD_DONE_CONFIRM,
|
||||
task->id,
|
||||
task->get ("description"));
|
||||
task.id,
|
||||
task.get ("description"));
|
||||
|
||||
task->modify (Task::modAnnotate);
|
||||
task->setStatus (Task::completed);
|
||||
if (! task->has ("end"))
|
||||
task->setAsNow ("end");
|
||||
task.modify (Task::modAnnotate);
|
||||
task.setStatus (Task::completed);
|
||||
if (! task.has ("end"))
|
||||
task.setAsNow ("end");
|
||||
|
||||
// Stop the task, if started.
|
||||
if (task->has ("start"))
|
||||
if (task.has ("start"))
|
||||
{
|
||||
task->remove ("start");
|
||||
task.remove ("start");
|
||||
if (context.config.getBoolean ("journal.time"))
|
||||
task->addAnnotation (context.config.get ("journal.time.stop.annotation"));
|
||||
task.addAnnotation (context.config.get ("journal.time.stop.annotation"));
|
||||
}
|
||||
|
||||
if (permission (*task, taskDifferences (before, *task) + question, filtered.size ()))
|
||||
if (permission (task, taskDifferences (before, task) + question, filtered.size ()))
|
||||
{
|
||||
updateRecurrenceMask (*task);
|
||||
context.tdb2.modify (*task);
|
||||
updateRecurrenceMask (task);
|
||||
context.tdb2.modify (task);
|
||||
++count;
|
||||
feedback_affected (STRING_CMD_DONE_TASK, *task);
|
||||
feedback_unblocked (*task);
|
||||
feedback_affected (STRING_CMD_DONE_TASK, task);
|
||||
feedback_unblocked (task);
|
||||
if (!nagged)
|
||||
nagged = nag (*task);
|
||||
dependencyChainOnComplete (*task);
|
||||
nagged = nag (task);
|
||||
dependencyChainOnComplete (task);
|
||||
if (context.verbose ("project"))
|
||||
projectChanges[task->get ("project")] = onProjectChange (*task);
|
||||
projectChanges[task.get ("project")] = onProjectChange (task);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -116,18 +115,17 @@ int CmdDone::execute (std::string& output)
|
|||
else
|
||||
{
|
||||
std::cout << format (STRING_CMD_DONE_NOTPEND,
|
||||
task->id,
|
||||
task->get ("description"))
|
||||
task.id,
|
||||
task.get ("description"))
|
||||
<< "\n";
|
||||
rc = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Now list the project changes.
|
||||
std::map <std::string, std::string>::iterator i;
|
||||
for (i = projectChanges.begin (); i != projectChanges.end (); ++i)
|
||||
if (i->first != "")
|
||||
context.footnote (i->second);
|
||||
for (auto& change : projectChanges)
|
||||
if (change.first != "")
|
||||
context.footnote (change.second);
|
||||
|
||||
feedback_affected (count == 1 ? STRING_CMD_DONE_1 : STRING_CMD_DONE_N, count);
|
||||
return rc;
|
||||
|
|
|
@ -65,11 +65,10 @@ int CmdDuplicate::execute (std::string& output)
|
|||
// Accumulated project change notifications.
|
||||
std::map <std::string, std::string> projectChanges;
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
// Duplicate the specified task.
|
||||
Task dup (*task);
|
||||
Task dup (task);
|
||||
dup.id = 0; // Reset, and TDB2::add will set.
|
||||
dup.set ("uuid", uuid ()); // Needs a new UUID.
|
||||
dup.remove ("start"); // Does not inherit start date.
|
||||
|
@ -83,7 +82,7 @@ int CmdDuplicate::execute (std::string& output)
|
|||
dup.remove ("recur");
|
||||
dup.remove ("until");
|
||||
dup.remove ("imask");
|
||||
std::cout << format (STRING_CMD_DUPLICATE_NON_REC, task->id)
|
||||
std::cout << format (STRING_CMD_DUPLICATE_NON_REC, task.id)
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
|
@ -91,7 +90,7 @@ int CmdDuplicate::execute (std::string& output)
|
|||
else if (dup.getStatus () == Task::recurring)
|
||||
{
|
||||
dup.remove ("mask");
|
||||
std::cout << format (STRING_CMD_DUPLICATE_REC, task->id)
|
||||
std::cout << format (STRING_CMD_DUPLICATE_REC, task.id)
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
|
@ -102,13 +101,13 @@ int CmdDuplicate::execute (std::string& output)
|
|||
|
||||
if (permission (dup,
|
||||
format (STRING_CMD_DUPLICATE_CONFIRM,
|
||||
task->id,
|
||||
task->get ("description")),
|
||||
task.id,
|
||||
task.get ("description")),
|
||||
filtered.size ()))
|
||||
{
|
||||
context.tdb2.add (dup);
|
||||
++count;
|
||||
feedback_affected (STRING_CMD_DUPLICATE_TASK, *task);
|
||||
feedback_affected (STRING_CMD_DUPLICATE_TASK, task);
|
||||
|
||||
if (context.verbose ("new-id"))
|
||||
std::cout << format (STRING_CMD_ADD_FEEDBACK, dup.id) + "\n";
|
||||
|
@ -116,7 +115,7 @@ int CmdDuplicate::execute (std::string& output)
|
|||
std::cout << format (STRING_CMD_ADD_FEEDBACK, dup.get ("uuid")) + "\n";
|
||||
|
||||
if (context.verbose ("project"))
|
||||
projectChanges[task->get ("project")] = onProjectChange (*task);
|
||||
projectChanges[task.get ("project")] = onProjectChange (task);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -128,10 +127,9 @@ int CmdDuplicate::execute (std::string& output)
|
|||
}
|
||||
|
||||
// Now list the project changes.
|
||||
std::map <std::string, std::string>::iterator i;
|
||||
for (i = projectChanges.begin (); i != projectChanges.end (); ++i)
|
||||
if (i->first != "")
|
||||
context.footnote (i->second);
|
||||
for (auto& change : projectChanges)
|
||||
if (change.first != "")
|
||||
context.footnote (change.second);
|
||||
|
||||
feedback_affected (count == 1 ? STRING_CMD_DUPLICATE_1 : STRING_CMD_DUPLICATE_N, count);
|
||||
return rc;
|
||||
|
|
|
@ -66,10 +66,9 @@ int CmdEdit::execute (std::string& output)
|
|||
filter.subset (filtered);
|
||||
|
||||
// Find number of matching tasks.
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
if (editFile (*task))
|
||||
context.tdb2.modify (*task);
|
||||
for (auto& task : filtered)
|
||||
if (editFile (task))
|
||||
context.tdb2.modify (task);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -236,12 +235,11 @@ std::string CmdEdit::formatTask (Task task, const std::string& dateformat)
|
|||
|
||||
std::map <std::string, std::string> annotations;
|
||||
task.getAnnotations (annotations);
|
||||
std::map <std::string, std::string>::iterator anno;
|
||||
for (anno = annotations.begin (); anno != annotations.end (); ++anno)
|
||||
for (auto& anno : annotations)
|
||||
{
|
||||
Date dt (strtol (anno->first.substr (11).c_str (), NULL, 10));
|
||||
Date dt (strtol (anno.first.substr (11).c_str (), NULL, 10));
|
||||
before << " Annotation: " << dt.toString (dateformat)
|
||||
<< " -- " << anno->second << "\n";
|
||||
<< " -- " << anno.second << "\n";
|
||||
}
|
||||
|
||||
Date now;
|
||||
|
@ -272,30 +270,28 @@ std::string CmdEdit::formatTask (Task task, const std::string& dateformat)
|
|||
|
||||
// UDAs
|
||||
std::vector <std::string> udas;
|
||||
std::map <std::string, Column*>::iterator col;
|
||||
for (col = context.columns.begin (); col != context.columns.end (); ++col)
|
||||
if (context.config.get ("uda." + col->first + ".type") != "")
|
||||
udas.push_back (col->first);
|
||||
for (auto& col : context.columns)
|
||||
if (context.config.get ("uda." + col.first + ".type") != "")
|
||||
udas.push_back (col.first);
|
||||
|
||||
if (udas.size ())
|
||||
{
|
||||
before << "# " << STRING_EDIT_UDA_SEP << "\n";
|
||||
std::sort (udas.begin (), udas.end ());
|
||||
std::vector <std::string>::iterator uda;
|
||||
for (uda = udas.begin (); uda != udas.end (); ++uda)
|
||||
for (auto& uda : udas)
|
||||
{
|
||||
int pad = 13 - uda->length ();
|
||||
int pad = 13 - uda.length ();
|
||||
std::string padding = "";
|
||||
if (pad > 0)
|
||||
padding = std::string (pad, ' ');
|
||||
|
||||
std::string type = context.config.get ("uda." + *uda + ".type");
|
||||
std::string type = context.config.get ("uda." + uda + ".type");
|
||||
if (type == "string" || type == "numeric")
|
||||
before << " UDA " << *uda << ": " << padding << task.get (*uda) << "\n";
|
||||
before << " UDA " << uda << ": " << padding << task.get (uda) << "\n";
|
||||
else if (type == "date")
|
||||
before << " UDA " << *uda << ": " << padding << formatDate (task, *uda, dateformat) << "\n";
|
||||
before << " UDA " << uda << ": " << padding << formatDate (task, uda, dateformat) << "\n";
|
||||
else if (type == "duration")
|
||||
before << " UDA " << *uda << ": " << padding << formatDuration (task, *uda) << "\n";
|
||||
before << " UDA " << uda << ": " << padding << formatDuration (task, uda) << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -307,15 +303,14 @@ std::string CmdEdit::formatTask (Task task, const std::string& dateformat)
|
|||
{
|
||||
before << "# " << STRING_EDIT_UDA_ORPHAN_SEP << "\n";
|
||||
std::sort (orphans.begin (), orphans.end ());
|
||||
std::vector <std::string>::iterator orphan;
|
||||
for (orphan = orphans.begin (); orphan != orphans.end (); ++orphan)
|
||||
for (auto& orphan : orphans)
|
||||
{
|
||||
int pad = 6 - orphan->length ();
|
||||
int pad = 6 - orphan.length ();
|
||||
std::string padding = "";
|
||||
if (pad > 0)
|
||||
padding = std::string (pad, ' ');
|
||||
|
||||
before << " UDA Orphan " << *orphan << ": " << padding << task.get (*orphan) << "\n";
|
||||
before << " UDA Orphan " << orphan << ": " << padding << task.get (orphan) << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -657,35 +652,33 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
|
|||
split (dependencies, value, ",");
|
||||
|
||||
task.remove ("depends");
|
||||
std::vector <std::string>::iterator dep;
|
||||
for (dep = dependencies.begin (); dep != dependencies.end (); ++dep)
|
||||
for (auto& dep : dependencies)
|
||||
{
|
||||
if (dep->length () >= 7)
|
||||
task.addDependency (*dep);
|
||||
if (dep.length () >= 7)
|
||||
task.addDependency (dep);
|
||||
else
|
||||
task.addDependency ((int) strtol (dep->c_str (), NULL, 10));
|
||||
task.addDependency ((int) strtol (dep.c_str (), NULL, 10));
|
||||
}
|
||||
|
||||
// UDAs
|
||||
std::map <std::string, Column*>::iterator col;
|
||||
for (col = context.columns.begin (); col != context.columns.end (); ++col)
|
||||
for (auto& col : context.columns)
|
||||
{
|
||||
std::string type = context.config.get ("uda." + col->first + ".type");
|
||||
std::string type = context.config.get ("uda." + col.first + ".type");
|
||||
if (type != "")
|
||||
{
|
||||
std::string value = findValue (after, "\n UDA " + col->first + ":");
|
||||
if ((task.get (col->first) != value) && (type != "date" ||
|
||||
(task.get (col->first) != Date (value, dateformat).toEpochString ())) &&
|
||||
std::string value = findValue (after, "\n UDA " + col.first + ":");
|
||||
if ((task.get (col.first) != value) && (type != "date" ||
|
||||
(task.get (col.first) != Date (value, dateformat).toEpochString ())) &&
|
||||
(type != "duration" ||
|
||||
(task.get (col->first) != (std::string) Duration (value) )))
|
||||
(task.get (col.first) != (std::string) Duration (value))))
|
||||
{
|
||||
if (value != "")
|
||||
{
|
||||
context.footnote (format (STRING_EDIT_UDA_MOD, col->first));
|
||||
context.footnote (format (STRING_EDIT_UDA_MOD, col.first));
|
||||
|
||||
if (type == "string")
|
||||
{
|
||||
task.set (col->first, value);
|
||||
task.set (col.first, value);
|
||||
}
|
||||
else if (type == "numeric")
|
||||
{
|
||||
|
@ -693,25 +686,25 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
|
|||
double d;
|
||||
if (n.getNumber (d) &&
|
||||
n.depleted ())
|
||||
task.set (col->first, value);
|
||||
task.set (col.first, value);
|
||||
else
|
||||
throw format (STRING_UDA_NUMERIC, value);
|
||||
}
|
||||
else if (type == "date")
|
||||
{
|
||||
Date d (value, dateformat);
|
||||
task.set (col->first, d.toEpochString ());
|
||||
task.set (col.first, d.toEpochString ());
|
||||
}
|
||||
else if (type == "duration")
|
||||
{
|
||||
Duration d (value);
|
||||
task.set (col->first, (time_t) d);
|
||||
task.set (col.first, (time_t) d);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
context.footnote (format (STRING_EDIT_UDA_DEL, col->first));
|
||||
task.remove (col->first);
|
||||
context.footnote (format (STRING_EDIT_UDA_DEL, col.first));
|
||||
task.remove (col.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -719,14 +712,13 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
|
|||
|
||||
// UDA orphans
|
||||
std::vector <std::string> orphanValues = findValues (after, "\n UDA Orphan ");
|
||||
std::vector <std::string>::iterator orphan;
|
||||
for (orphan = orphanValues.begin (); orphan != orphanValues.end (); ++orphan)
|
||||
for (auto& orphan : orphanValues)
|
||||
{
|
||||
std::string::size_type colon = orphan->find (':');
|
||||
std::string::size_type colon = orphan.find (':');
|
||||
if (colon != std::string::npos)
|
||||
{
|
||||
std::string name = trim (orphan->substr (0, colon), "\t ");
|
||||
std::string value = trim (orphan->substr (colon + 1), "\t ");
|
||||
std::string name = trim (orphan.substr (0, colon), "\t ");
|
||||
std::string value = trim (orphan.substr (colon + 1), "\t ");
|
||||
|
||||
if (value != "")
|
||||
task.set (name, value);
|
||||
|
|
|
@ -70,8 +70,7 @@ int CmdExport::execute (std::string& output)
|
|||
output += "[\n";
|
||||
|
||||
int counter = 0;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto task = filtered.begin (); task != filtered.end (); ++task)
|
||||
{
|
||||
if (task != filtered.begin ())
|
||||
{
|
||||
|
|
|
@ -55,12 +55,11 @@ int CmdGet::execute (std::string& output)
|
|||
|
||||
bool found = false;
|
||||
std::vector <std::string> results;
|
||||
std::vector <std::string>::iterator word;
|
||||
for (word = words.begin (); word != words.end (); ++word)
|
||||
for (auto& word : words)
|
||||
{
|
||||
Task t;
|
||||
Variant result;
|
||||
if (context.dom.get (*word, t, result))
|
||||
if (context.dom.get (word, t, result))
|
||||
{
|
||||
results.push_back ((std::string) result);
|
||||
found = true;
|
||||
|
|
|
@ -62,33 +62,31 @@ int CmdHelp::execute (std::string& output)
|
|||
|
||||
// Obsolete method of getting a list of all commands.
|
||||
std::vector <std::string> all;
|
||||
std::map <std::string, Command*>::iterator i;
|
||||
for (i = context.commands.begin (); i != context.commands.end (); ++i)
|
||||
all.push_back (i->first);
|
||||
for (auto& cmd : context.commands)
|
||||
all.push_back (cmd.first);
|
||||
|
||||
// Sort alphabetically by usage.
|
||||
std::sort (all.begin (), all.end ());
|
||||
|
||||
// Add the regular commands.
|
||||
std::vector <std::string>::iterator name;
|
||||
for (name = all.begin (); name != all.end (); ++name)
|
||||
for (auto& name : all)
|
||||
{
|
||||
if ((*name)[0] != '_')
|
||||
if (name[0] != '_')
|
||||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 1, context.commands[*name]->usage ());
|
||||
view.set (row, 2, context.commands[*name]->description ());
|
||||
view.set (row, 1, context.commands[name]->usage ());
|
||||
view.set (row, 2, context.commands[name]->description ());
|
||||
}
|
||||
}
|
||||
|
||||
// Add the helper commands.
|
||||
for (name = all.begin (); name != all.end (); ++name)
|
||||
for (auto& name : all)
|
||||
{
|
||||
if ((*name)[0] == '_')
|
||||
if (name[0] == '_')
|
||||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 1, context.commands[*name]->usage ());
|
||||
view.set (row, 2, context.commands[*name]->description ());
|
||||
view.set (row, 1, context.commands[name]->usage ());
|
||||
view.set (row, 2, context.commands[name]->description ());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,14 +94,13 @@ int CmdHelp::execute (std::string& output)
|
|||
row = view.addRow ();
|
||||
view.set (row, 1, " ");
|
||||
|
||||
std::map <std::string, std::string>::iterator alias;
|
||||
for (alias = context.config.begin (); alias != context.config.end (); ++alias)
|
||||
for (auto& alias : context.config)
|
||||
{
|
||||
if (alias->first.substr (0, 6) == "alias.")
|
||||
if (alias.first.substr (0, 6) == "alias.")
|
||||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 1, alias->first.substr (6));
|
||||
view.set (row, 2, format (STRING_CMD_HELP_ALIASED, alias->second));
|
||||
view.set (row, 1, alias.first.substr (6));
|
||||
view.set (row, 2, format (STRING_CMD_HELP_ALIASED, alias.second));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,14 +62,13 @@ int CmdHistoryMonthly::execute (std::string& output)
|
|||
std::vector <Task> filtered;
|
||||
filter.subset (filtered);
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
Date entry (task->get_date ("entry"));
|
||||
Date entry (task.get_date ("entry"));
|
||||
|
||||
Date end;
|
||||
if (task->has ("end"))
|
||||
end = Date (task->get_date ("end"));
|
||||
if (task.has ("end"))
|
||||
end = Date (task.get_date ("end"));
|
||||
|
||||
time_t epoch = entry.startOfMonth ().toEpoch ();
|
||||
groups[epoch] = 0;
|
||||
|
@ -78,7 +77,7 @@ int CmdHistoryMonthly::execute (std::string& output)
|
|||
++addedGroup[epoch];
|
||||
|
||||
// All deleted tasks have an end date.
|
||||
if (task->getStatus () == Task::deleted)
|
||||
if (task.getStatus () == Task::deleted)
|
||||
{
|
||||
epoch = end.startOfMonth ().toEpoch ();
|
||||
groups[epoch] = 0;
|
||||
|
@ -86,7 +85,7 @@ int CmdHistoryMonthly::execute (std::string& output)
|
|||
}
|
||||
|
||||
// All completed tasks have an end date.
|
||||
else if (task->getStatus () == Task::completed)
|
||||
else if (task.getStatus () == Task::completed)
|
||||
{
|
||||
epoch = end.startOfMonth ().toEpoch ();
|
||||
groups[epoch] = 0;
|
||||
|
@ -113,16 +112,15 @@ int CmdHistoryMonthly::execute (std::string& output)
|
|||
|
||||
int priorYear = 0;
|
||||
int row = 0;
|
||||
std::map <time_t, int>::iterator i;
|
||||
for (i = groups.begin (); i != groups.end (); ++i)
|
||||
for (auto& i : groups)
|
||||
{
|
||||
row = view.addRow ();
|
||||
|
||||
totalAdded += addedGroup [i->first];
|
||||
totalCompleted += completedGroup [i->first];
|
||||
totalDeleted += deletedGroup [i->first];
|
||||
totalAdded += addedGroup [i.first];
|
||||
totalCompleted += completedGroup [i.first];
|
||||
totalDeleted += deletedGroup [i.first];
|
||||
|
||||
Date dt (i->first);
|
||||
Date dt (i.first);
|
||||
int m, d, y;
|
||||
dt.toMDY (m, d, y);
|
||||
|
||||
|
@ -135,22 +133,22 @@ int CmdHistoryMonthly::execute (std::string& output)
|
|||
|
||||
int net = 0;
|
||||
|
||||
if (addedGroup.find (i->first) != addedGroup.end ())
|
||||
if (addedGroup.find (i.first) != addedGroup.end ())
|
||||
{
|
||||
view.set (row, 2, addedGroup[i->first]);
|
||||
net +=addedGroup[i->first];
|
||||
view.set (row, 2, addedGroup[i.first]);
|
||||
net +=addedGroup[i.first];
|
||||
}
|
||||
|
||||
if (completedGroup.find (i->first) != completedGroup.end ())
|
||||
if (completedGroup.find (i.first) != completedGroup.end ())
|
||||
{
|
||||
view.set (row, 3, completedGroup[i->first]);
|
||||
net -= completedGroup[i->first];
|
||||
view.set (row, 3, completedGroup[i.first]);
|
||||
net -= completedGroup[i.first];
|
||||
}
|
||||
|
||||
if (deletedGroup.find (i->first) != deletedGroup.end ())
|
||||
if (deletedGroup.find (i.first) != deletedGroup.end ())
|
||||
{
|
||||
view.set (row, 4, deletedGroup[i->first]);
|
||||
net -= deletedGroup[i->first];
|
||||
view.set (row, 4, deletedGroup[i.first]);
|
||||
net -= deletedGroup[i.first];
|
||||
}
|
||||
|
||||
Color net_color;
|
||||
|
@ -219,14 +217,13 @@ int CmdHistoryAnnual::execute (std::string& output)
|
|||
std::vector <Task> filtered;
|
||||
filter.subset (filtered);
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
Date entry (task->get_date ("entry"));
|
||||
Date entry (task.get_date ("entry"));
|
||||
|
||||
Date end;
|
||||
if (task->has ("end"))
|
||||
end = Date (task->get_date ("end"));
|
||||
if (task.has ("end"))
|
||||
end = Date (task.get_date ("end"));
|
||||
|
||||
time_t epoch = entry.startOfYear ().toEpoch ();
|
||||
groups[epoch] = 0;
|
||||
|
@ -235,7 +232,7 @@ int CmdHistoryAnnual::execute (std::string& output)
|
|||
++addedGroup[epoch];
|
||||
|
||||
// All deleted tasks have an end date.
|
||||
if (task->getStatus () == Task::deleted)
|
||||
if (task.getStatus () == Task::deleted)
|
||||
{
|
||||
epoch = end.startOfYear ().toEpoch ();
|
||||
groups[epoch] = 0;
|
||||
|
@ -243,7 +240,7 @@ int CmdHistoryAnnual::execute (std::string& output)
|
|||
}
|
||||
|
||||
// All completed tasks have an end date.
|
||||
else if (task->getStatus () == Task::completed)
|
||||
else if (task.getStatus () == Task::completed)
|
||||
{
|
||||
epoch = end.startOfYear ().toEpoch ();
|
||||
groups[epoch] = 0;
|
||||
|
@ -269,16 +266,15 @@ int CmdHistoryAnnual::execute (std::string& output)
|
|||
|
||||
int priorYear = 0;
|
||||
int row = 0;
|
||||
std::map <time_t, int>::iterator i;
|
||||
for (i = groups.begin (); i != groups.end (); ++i)
|
||||
for (auto& i : groups)
|
||||
{
|
||||
row = view.addRow ();
|
||||
|
||||
totalAdded += addedGroup [i->first];
|
||||
totalCompleted += completedGroup [i->first];
|
||||
totalDeleted += deletedGroup [i->first];
|
||||
totalAdded += addedGroup [i.first];
|
||||
totalCompleted += completedGroup [i.first];
|
||||
totalDeleted += deletedGroup [i.first];
|
||||
|
||||
Date dt (i->first);
|
||||
Date dt (i.first);
|
||||
int m, d, y;
|
||||
dt.toMDY (m, d, y);
|
||||
|
||||
|
@ -290,22 +286,22 @@ int CmdHistoryAnnual::execute (std::string& output)
|
|||
|
||||
int net = 0;
|
||||
|
||||
if (addedGroup.find (i->first) != addedGroup.end ())
|
||||
if (addedGroup.find (i.first) != addedGroup.end ())
|
||||
{
|
||||
view.set (row, 1, addedGroup[i->first]);
|
||||
net +=addedGroup[i->first];
|
||||
view.set (row, 1, addedGroup[i.first]);
|
||||
net +=addedGroup[i.first];
|
||||
}
|
||||
|
||||
if (completedGroup.find (i->first) != completedGroup.end ())
|
||||
if (completedGroup.find (i.first) != completedGroup.end ())
|
||||
{
|
||||
view.set (row, 2, completedGroup[i->first]);
|
||||
net -= completedGroup[i->first];
|
||||
view.set (row, 2, completedGroup[i.first]);
|
||||
net -= completedGroup[i.first];
|
||||
}
|
||||
|
||||
if (deletedGroup.find (i->first) != deletedGroup.end ())
|
||||
if (deletedGroup.find (i.first) != deletedGroup.end ())
|
||||
{
|
||||
view.set (row, 3, deletedGroup[i->first]);
|
||||
net -= deletedGroup[i->first];
|
||||
view.set (row, 3, deletedGroup[i.first]);
|
||||
net -= deletedGroup[i.first];
|
||||
}
|
||||
|
||||
Color net_color;
|
||||
|
@ -373,14 +369,13 @@ int CmdGHistoryMonthly::execute (std::string& output)
|
|||
std::vector <Task> filtered;
|
||||
filter.subset (filtered);
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
Date entry (task->get_date ("entry"));
|
||||
Date entry (task.get_date ("entry"));
|
||||
|
||||
Date end;
|
||||
if (task->has ("end"))
|
||||
end = Date (task->get_date ("end"));
|
||||
if (task.has ("end"))
|
||||
end = Date (task.get_date ("end"));
|
||||
|
||||
time_t epoch = entry.startOfMonth ().toEpoch ();
|
||||
groups[epoch] = 0;
|
||||
|
@ -389,7 +384,7 @@ int CmdGHistoryMonthly::execute (std::string& output)
|
|||
++addedGroup[epoch];
|
||||
|
||||
// All deleted tasks have an end date.
|
||||
if (task->getStatus () == Task::deleted)
|
||||
if (task.getStatus () == Task::deleted)
|
||||
{
|
||||
epoch = end.startOfMonth ().toEpoch ();
|
||||
groups[epoch] = 0;
|
||||
|
@ -397,7 +392,7 @@ int CmdGHistoryMonthly::execute (std::string& output)
|
|||
}
|
||||
|
||||
// All completed tasks have an end date.
|
||||
else if (task->getStatus () == Task::completed)
|
||||
else if (task.getStatus () == Task::completed)
|
||||
{
|
||||
epoch = end.startOfMonth ().toEpoch ();
|
||||
groups[epoch] = 0;
|
||||
|
@ -424,14 +419,13 @@ int CmdGHistoryMonthly::execute (std::string& output)
|
|||
// Determine the longest line, and the longest "added" line.
|
||||
int maxAddedLine = 0;
|
||||
int maxRemovedLine = 0;
|
||||
std::map <time_t, int>::iterator i;
|
||||
for (i = groups.begin (); i != groups.end (); ++i)
|
||||
for (auto& i : groups)
|
||||
{
|
||||
if (completedGroup[i->first] + deletedGroup[i->first] > maxRemovedLine)
|
||||
maxRemovedLine = completedGroup[i->first] + deletedGroup[i->first];
|
||||
if (completedGroup[i.first] + deletedGroup[i.first] > maxRemovedLine)
|
||||
maxRemovedLine = completedGroup[i.first] + deletedGroup[i.first];
|
||||
|
||||
if (addedGroup[i->first] > maxAddedLine)
|
||||
maxAddedLine = addedGroup[i->first];
|
||||
if (addedGroup[i.first] > maxAddedLine)
|
||||
maxAddedLine = addedGroup[i.first];
|
||||
}
|
||||
|
||||
int maxLine = maxAddedLine + maxRemovedLine;
|
||||
|
@ -445,16 +439,15 @@ int CmdGHistoryMonthly::execute (std::string& output)
|
|||
|
||||
int priorYear = 0;
|
||||
int row = 0;
|
||||
std::map <time_t, int>::iterator i;
|
||||
for (i = groups.begin (); i != groups.end (); ++i)
|
||||
for (auto& i : groups)
|
||||
{
|
||||
row = view.addRow ();
|
||||
|
||||
totalAdded += addedGroup[i->first];
|
||||
totalCompleted += completedGroup[i->first];
|
||||
totalDeleted += deletedGroup[i->first];
|
||||
totalAdded += addedGroup[i.first];
|
||||
totalCompleted += completedGroup[i.first];
|
||||
totalDeleted += deletedGroup[i.first];
|
||||
|
||||
Date dt (i->first);
|
||||
Date dt (i.first);
|
||||
int m, d, y;
|
||||
dt.toMDY (m, d, y);
|
||||
|
||||
|
@ -465,33 +458,33 @@ int CmdGHistoryMonthly::execute (std::string& output)
|
|||
}
|
||||
view.set (row, 1, Date::monthName(m));
|
||||
|
||||
unsigned int addedBar = (widthOfBar * addedGroup[i->first]) / maxLine;
|
||||
unsigned int completedBar = (widthOfBar * completedGroup[i->first]) / maxLine;
|
||||
unsigned int deletedBar = (widthOfBar * deletedGroup[i->first]) / maxLine;
|
||||
unsigned int addedBar = (widthOfBar * addedGroup[i.first]) / maxLine;
|
||||
unsigned int completedBar = (widthOfBar * completedGroup[i.first]) / maxLine;
|
||||
unsigned int deletedBar = (widthOfBar * deletedGroup[i.first]) / maxLine;
|
||||
|
||||
std::string bar = "";
|
||||
if (context.color ())
|
||||
{
|
||||
std::string aBar = "";
|
||||
if (addedGroup[i->first])
|
||||
if (addedGroup[i.first])
|
||||
{
|
||||
aBar = format (addedGroup[i->first]);
|
||||
aBar = format (addedGroup[i.first]);
|
||||
while (aBar.length () < addedBar)
|
||||
aBar = " " + aBar;
|
||||
}
|
||||
|
||||
std::string cBar = "";
|
||||
if (completedGroup[i->first])
|
||||
if (completedGroup[i.first])
|
||||
{
|
||||
cBar = format (completedGroup[i->first]);
|
||||
cBar = format (completedGroup[i.first]);
|
||||
while (cBar.length () < completedBar)
|
||||
cBar = " " + cBar;
|
||||
}
|
||||
|
||||
std::string dBar = "";
|
||||
if (deletedGroup[i->first])
|
||||
if (deletedGroup[i.first])
|
||||
{
|
||||
dBar = format (deletedGroup[i->first]);
|
||||
dBar = format (deletedGroup[i.first]);
|
||||
while (dBar.length () < deletedBar)
|
||||
dBar = " " + dBar;
|
||||
}
|
||||
|
@ -569,14 +562,13 @@ int CmdGHistoryAnnual::execute (std::string& output)
|
|||
std::vector <Task> filtered;
|
||||
filter.subset (filtered);
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
Date entry (task->get_date ("entry"));
|
||||
Date entry (task.get_date ("entry"));
|
||||
|
||||
Date end;
|
||||
if (task->has ("end"))
|
||||
end = Date (task->get_date ("end"));
|
||||
if (task.has ("end"))
|
||||
end = Date (task.get_date ("end"));
|
||||
|
||||
time_t epoch = entry.startOfYear ().toEpoch ();
|
||||
groups[epoch] = 0;
|
||||
|
@ -585,7 +577,7 @@ int CmdGHistoryAnnual::execute (std::string& output)
|
|||
++addedGroup[epoch];
|
||||
|
||||
// All deleted tasks have an end date.
|
||||
if (task->getStatus () == Task::deleted)
|
||||
if (task.getStatus () == Task::deleted)
|
||||
{
|
||||
epoch = end.startOfYear ().toEpoch ();
|
||||
groups[epoch] = 0;
|
||||
|
@ -593,7 +585,7 @@ int CmdGHistoryAnnual::execute (std::string& output)
|
|||
}
|
||||
|
||||
// All completed tasks have an end date.
|
||||
else if (task->getStatus () == Task::completed)
|
||||
else if (task.getStatus () == Task::completed)
|
||||
{
|
||||
epoch = end.startOfYear ().toEpoch ();
|
||||
groups[epoch] = 0;
|
||||
|
@ -619,14 +611,13 @@ int CmdGHistoryAnnual::execute (std::string& output)
|
|||
// Determine the longest line, and the longest "added" line.
|
||||
int maxAddedLine = 0;
|
||||
int maxRemovedLine = 0;
|
||||
std::map <time_t, int>::iterator i;
|
||||
for (i = groups.begin (); i != groups.end (); ++i)
|
||||
for (auto& i : groups)
|
||||
{
|
||||
if (completedGroup[i->first] + deletedGroup[i->first] > maxRemovedLine)
|
||||
maxRemovedLine = completedGroup[i->first] + deletedGroup[i->first];
|
||||
if (completedGroup[i.first] + deletedGroup[i.first] > maxRemovedLine)
|
||||
maxRemovedLine = completedGroup[i.first] + deletedGroup[i.first];
|
||||
|
||||
if (addedGroup[i->first] > maxAddedLine)
|
||||
maxAddedLine = addedGroup[i->first];
|
||||
if (addedGroup[i.first] > maxAddedLine)
|
||||
maxAddedLine = addedGroup[i.first];
|
||||
}
|
||||
|
||||
int maxLine = maxAddedLine + maxRemovedLine;
|
||||
|
@ -640,16 +631,15 @@ int CmdGHistoryAnnual::execute (std::string& output)
|
|||
|
||||
int priorYear = 0;
|
||||
int row = 0;
|
||||
std::map <time_t, int>::iterator i;
|
||||
for (i = groups.begin (); i != groups.end (); ++i)
|
||||
for (auto& i : groups)
|
||||
{
|
||||
row = view.addRow ();
|
||||
|
||||
totalAdded += addedGroup[i->first];
|
||||
totalCompleted += completedGroup[i->first];
|
||||
totalDeleted += deletedGroup[i->first];
|
||||
totalAdded += addedGroup[i.first];
|
||||
totalCompleted += completedGroup[i.first];
|
||||
totalDeleted += deletedGroup[i.first];
|
||||
|
||||
Date dt (i->first);
|
||||
Date dt (i.first);
|
||||
int m, d, y;
|
||||
dt.toMDY (m, d, y);
|
||||
|
||||
|
@ -659,33 +649,33 @@ int CmdGHistoryAnnual::execute (std::string& output)
|
|||
priorYear = y;
|
||||
}
|
||||
|
||||
unsigned int addedBar = (widthOfBar * addedGroup[i->first]) / maxLine;
|
||||
unsigned int completedBar = (widthOfBar * completedGroup[i->first]) / maxLine;
|
||||
unsigned int deletedBar = (widthOfBar * deletedGroup[i->first]) / maxLine;
|
||||
unsigned int addedBar = (widthOfBar * addedGroup[i.first]) / maxLine;
|
||||
unsigned int completedBar = (widthOfBar * completedGroup[i.first]) / maxLine;
|
||||
unsigned int deletedBar = (widthOfBar * deletedGroup[i.first]) / maxLine;
|
||||
|
||||
std::string bar = "";
|
||||
if (context.color ())
|
||||
{
|
||||
std::string aBar = "";
|
||||
if (addedGroup[i->first])
|
||||
if (addedGroup[i.first])
|
||||
{
|
||||
aBar = format (addedGroup[i->first]);
|
||||
aBar = format (addedGroup[i.first]);
|
||||
while (aBar.length () < addedBar)
|
||||
aBar = " " + aBar;
|
||||
}
|
||||
|
||||
std::string cBar = "";
|
||||
if (completedGroup[i->first])
|
||||
if (completedGroup[i.first])
|
||||
{
|
||||
cBar = format (completedGroup[i->first]);
|
||||
cBar = format (completedGroup[i.first]);
|
||||
while (cBar.length () < completedBar)
|
||||
cBar = " " + cBar;
|
||||
}
|
||||
|
||||
std::string dBar = "";
|
||||
if (deletedGroup[i->first])
|
||||
if (deletedGroup[i.first])
|
||||
{
|
||||
dBar = format (deletedGroup[i->first]);
|
||||
dBar = format (deletedGroup[i.first]);
|
||||
while (dBar.length () < deletedBar)
|
||||
dBar = " " + dBar;
|
||||
}
|
||||
|
|
|
@ -59,10 +59,9 @@ int CmdIDs::execute (std::string& output)
|
|||
|
||||
// Find number of matching tasks.
|
||||
std::vector <int> ids;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
if (task->id)
|
||||
ids.push_back (task->id);
|
||||
for (auto& task : filtered)
|
||||
if (task.id)
|
||||
ids.push_back (task.id);
|
||||
|
||||
std::sort (ids.begin (), ids.end ());
|
||||
output = compressIds (ids) + "\n";
|
||||
|
@ -146,11 +145,10 @@ int CmdCompletionIds::execute (std::string& output)
|
|||
filter.subset (filtered);
|
||||
|
||||
std::vector <int> ids;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
if (task->getStatus () != Task::deleted &&
|
||||
task->getStatus () != Task::completed)
|
||||
ids.push_back (task->id);
|
||||
for (auto& task : filtered)
|
||||
if (task.getStatus () != Task::deleted &&
|
||||
task.getStatus () != Task::completed)
|
||||
ids.push_back (task.id);
|
||||
|
||||
std::sort (ids.begin (), ids.end ());
|
||||
join (output, "\n", ids);
|
||||
|
@ -180,13 +178,12 @@ int CmdZshCompletionIds::execute (std::string& output)
|
|||
filter.subset (filtered);
|
||||
|
||||
std::stringstream out;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
if (task->getStatus () != Task::deleted &&
|
||||
task->getStatus () != Task::completed)
|
||||
out << task->id
|
||||
for (auto& task : filtered)
|
||||
if (task.getStatus () != Task::deleted &&
|
||||
task.getStatus () != Task::completed)
|
||||
out << task.id
|
||||
<< ":"
|
||||
<< str_replace(task->get ("description"), ":", zshColonReplacement)
|
||||
<< str_replace(task.get ("description"), ":", zshColonReplacement)
|
||||
<< "\n";
|
||||
|
||||
output = out.str ();
|
||||
|
@ -215,9 +212,8 @@ int CmdUUIDs::execute (std::string& output)
|
|||
filter.subset (filtered);
|
||||
|
||||
std::vector <std::string> uuids;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
uuids.push_back (task->get ("uuid"));
|
||||
for (auto& task : filtered)
|
||||
uuids.push_back (task.get ("uuid"));
|
||||
|
||||
std::sort (uuids.begin (), uuids.end ());
|
||||
join (output, ",", uuids);
|
||||
|
@ -247,9 +243,8 @@ int CmdCompletionUuids::execute (std::string& output)
|
|||
filter.subset (filtered);
|
||||
|
||||
std::vector <std::string> uuids;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
uuids.push_back (task->get ("uuid"));
|
||||
for (auto& task : filtered)
|
||||
uuids.push_back (task.get ("uuid"));
|
||||
|
||||
std::sort (uuids.begin (), uuids.end ());
|
||||
join (output, "\n", uuids);
|
||||
|
@ -279,11 +274,10 @@ int CmdZshCompletionUuids::execute (std::string& output)
|
|||
filter.subset (filtered);
|
||||
|
||||
std::stringstream out;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
out << task->get ("uuid")
|
||||
for (auto& task : filtered)
|
||||
out << task.get ("uuid")
|
||||
<< ":"
|
||||
<< str_replace (task->get ("description"), ":", zshColonReplacement)
|
||||
<< str_replace (task.get ("description"), ":", zshColonReplacement)
|
||||
<< "\n";
|
||||
|
||||
output = out.str ();
|
||||
|
|
|
@ -58,35 +58,34 @@ int CmdImport::execute (std::string& output)
|
|||
if (! words.size ())
|
||||
throw std::string (STRING_CMD_IMPORT_NOFILE);
|
||||
|
||||
std::vector <std::string>::iterator word;
|
||||
for (word = words.begin (); word != words.end (); ++word)
|
||||
for (auto& word : words)
|
||||
{
|
||||
File incoming (*word);
|
||||
File incoming (word);
|
||||
if (! incoming.exists ())
|
||||
throw format (STRING_CMD_IMPORT_MISSING, *word);
|
||||
throw format (STRING_CMD_IMPORT_MISSING, word);
|
||||
|
||||
std::cout << format (STRING_CMD_IMPORT_FILE, *word) << "\n";
|
||||
std::cout << format (STRING_CMD_IMPORT_FILE, word) << "\n";
|
||||
|
||||
// Load the file.
|
||||
std::vector <std::string> lines;
|
||||
incoming.read (lines);
|
||||
|
||||
std::vector <std::string>::iterator line;
|
||||
for (line = lines.begin (); line != lines.end (); ++line)
|
||||
for (auto& line : lines)
|
||||
{
|
||||
std::string object = trimLeft (
|
||||
trimRight (
|
||||
trim (*line),
|
||||
trim (line),
|
||||
"]"),
|
||||
"[");
|
||||
|
||||
// Skip blanks. May be caused by the trim calls above.
|
||||
if (! object.length ())
|
||||
continue;
|
||||
|
||||
// Parse the whole thing.
|
||||
Task task (object);
|
||||
|
||||
context.tdb2.add (task);
|
||||
|
||||
++count;
|
||||
std::cout << " "
|
||||
<< task.get ("uuid")
|
||||
|
|
|
@ -89,8 +89,7 @@ int CmdInfo::execute (std::string& output)
|
|||
|
||||
// Render each task.
|
||||
std::stringstream out;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
ViewText view;
|
||||
view.width (context.getWidth ());
|
||||
|
@ -113,25 +112,24 @@ int CmdInfo::execute (std::string& output)
|
|||
// id
|
||||
int row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_ID);
|
||||
view.set (row, 1, (task->id ? format (task->id) : "-"));
|
||||
view.set (row, 1, (task.id ? format (task.id) : "-"));
|
||||
|
||||
std::string status = ucFirst (Task::statusToText (task->getStatus ())); // L10N safe ucFirst.
|
||||
std::string status = ucFirst (Task::statusToText (task.getStatus ())); // L10N safe ucFirst.
|
||||
|
||||
// description
|
||||
Color c;
|
||||
autoColorize (*task, c);
|
||||
std::string description = task->get ("description");
|
||||
autoColorize (task, c);
|
||||
std::string description = task.get ("description");
|
||||
int indent = context.config.getInteger ("indent.annotation");
|
||||
|
||||
std::map <std::string, std::string> annotations;
|
||||
task->getAnnotations (annotations);
|
||||
std::map <std::string, std::string>::iterator ann;
|
||||
for (ann = annotations.begin (); ann != annotations.end (); ++ann)
|
||||
task.getAnnotations (annotations);
|
||||
for (auto& anno : annotations)
|
||||
description += "\n"
|
||||
+ std::string (indent, ' ')
|
||||
+ Date (ann->first.substr (11)).toString (dateformatanno)
|
||||
+ Date (anno.first.substr (11)).toString (dateformatanno)
|
||||
+ " "
|
||||
+ ann->second;
|
||||
+ anno.second;
|
||||
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_DESC);
|
||||
|
@ -143,23 +141,22 @@ int CmdInfo::execute (std::string& output)
|
|||
view.set (row, 1, status);
|
||||
|
||||
// project
|
||||
if (task->has ("project"))
|
||||
if (task.has ("project"))
|
||||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_PROJECT);
|
||||
view.set (row, 1, task->get ("project"));
|
||||
view.set (row, 1, task.get ("project"));
|
||||
}
|
||||
|
||||
// dependencies: blocked
|
||||
{
|
||||
std::vector <Task> blocked;
|
||||
dependencyGetBlocking (*task, blocked);
|
||||
dependencyGetBlocking (task, blocked);
|
||||
if (blocked.size ())
|
||||
{
|
||||
std::stringstream message;
|
||||
std::vector <Task>::const_iterator it;
|
||||
for (it = blocked.begin (); it != blocked.end (); ++it)
|
||||
message << it->id << " " << it->get ("description") << "\n";
|
||||
for (auto& block : blocked)
|
||||
message << block.id << " " << block.get ("description") << "\n";
|
||||
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_CMD_INFO_BLOCKED);
|
||||
|
@ -170,13 +167,12 @@ int CmdInfo::execute (std::string& output)
|
|||
// dependencies: blocking
|
||||
{
|
||||
std::vector <Task> blocking;
|
||||
dependencyGetBlocked (*task, blocking);
|
||||
dependencyGetBlocked (task, blocking);
|
||||
if (blocking.size ())
|
||||
{
|
||||
std::stringstream message;
|
||||
std::vector <Task>::const_iterator it;
|
||||
for (it = blocking.begin (); it != blocking.end (); ++it)
|
||||
message << it->id << " " << it->get ("description") << "\n";
|
||||
for (auto& block : blocking)
|
||||
message << block.id << " " << block.get ("description") << "\n";
|
||||
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_CMD_INFO_BLOCKING);
|
||||
|
@ -185,45 +181,45 @@ int CmdInfo::execute (std::string& output)
|
|||
}
|
||||
|
||||
// recur
|
||||
if (task->has ("recur"))
|
||||
if (task.has ("recur"))
|
||||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_RECUR_L);
|
||||
view.set (row, 1, task->get ("recur"));
|
||||
view.set (row, 1, task.get ("recur"));
|
||||
}
|
||||
|
||||
// parent
|
||||
if (task->has ("parent"))
|
||||
if (task.has ("parent"))
|
||||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_PARENT);
|
||||
view.set (row, 1, task->get ("parent"));
|
||||
view.set (row, 1, task.get ("parent"));
|
||||
}
|
||||
|
||||
// mask
|
||||
if (task->has ("mask"))
|
||||
if (task.has ("mask"))
|
||||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_MASK);
|
||||
view.set (row, 1, task->get ("mask"));
|
||||
view.set (row, 1, task.get ("mask"));
|
||||
}
|
||||
|
||||
// imask
|
||||
if (task->has ("imask"))
|
||||
if (task.has ("imask"))
|
||||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_MASK_IDX);
|
||||
view.set (row, 1, task->get ("imask"));
|
||||
view.set (row, 1, task.get ("imask"));
|
||||
}
|
||||
|
||||
// entry
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_ENTERED);
|
||||
Date dt (task->get_date ("entry"));
|
||||
Date dt (task.get_date ("entry"));
|
||||
std::string entry = dt.toString (dateformat);
|
||||
|
||||
std::string age;
|
||||
std::string created = task->get ("entry");
|
||||
std::string created = task.get ("entry");
|
||||
if (created.length ())
|
||||
{
|
||||
Date dt (strtol (created.c_str (), NULL, 10));
|
||||
|
@ -233,67 +229,67 @@ int CmdInfo::execute (std::string& output)
|
|||
view.set (row, 1, entry + " (" + age + ")");
|
||||
|
||||
// wait
|
||||
if (task->has ("wait"))
|
||||
if (task.has ("wait"))
|
||||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_WAITING);
|
||||
view.set (row, 1, Date (task->get_date ("wait")).toString (dateformat));
|
||||
view.set (row, 1, Date (task.get_date ("wait")).toString (dateformat));
|
||||
}
|
||||
|
||||
// scheduled
|
||||
if (task->has ("scheduled"))
|
||||
if (task.has ("scheduled"))
|
||||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_SCHED);
|
||||
view.set (row, 1, Date (task->get_date ("scheduled")).toString (dateformat));
|
||||
view.set (row, 1, Date (task.get_date ("scheduled")).toString (dateformat));
|
||||
}
|
||||
|
||||
// start
|
||||
if (task->has ("start"))
|
||||
if (task.has ("start"))
|
||||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_START);
|
||||
view.set (row, 1, Date (task->get_date ("start")).toString (dateformat));
|
||||
view.set (row, 1, Date (task.get_date ("start")).toString (dateformat));
|
||||
}
|
||||
|
||||
// due (colored)
|
||||
if (task->has ("due"))
|
||||
if (task.has ("due"))
|
||||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_DUE);
|
||||
view.set (row, 1, Date (task->get_date ("due")).toString (dateformat));
|
||||
view.set (row, 1, Date (task.get_date ("due")).toString (dateformat));
|
||||
}
|
||||
|
||||
// end
|
||||
if (task->has ("end"))
|
||||
if (task.has ("end"))
|
||||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_END);
|
||||
view.set (row, 1, Date (task->get_date ("end")).toString (dateformat));
|
||||
view.set (row, 1, Date (task.get_date ("end")).toString (dateformat));
|
||||
}
|
||||
|
||||
// until
|
||||
if (task->has ("until"))
|
||||
if (task.has ("until"))
|
||||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_CMD_INFO_UNTIL);
|
||||
view.set (row, 1, Date (task->get_date ("until")).toString (dateformat));
|
||||
view.set (row, 1, Date (task.get_date ("until")).toString (dateformat));
|
||||
}
|
||||
|
||||
// modified
|
||||
if (task->has ("modified"))
|
||||
if (task.has ("modified"))
|
||||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_CMD_INFO_MODIFIED);
|
||||
|
||||
Date mod (task->get_date ("modified"));
|
||||
Date mod (task.get_date ("modified"));
|
||||
std::string age = Duration (now - mod).format ();
|
||||
view.set (row, 1, mod.toString (dateformat) + " (" + age + ")");
|
||||
}
|
||||
|
||||
// tags ...
|
||||
std::vector <std::string> tags;
|
||||
task->getTags (tags);
|
||||
task.getTags (tags);
|
||||
if (tags.size ())
|
||||
{
|
||||
std::string allTags;
|
||||
|
@ -308,30 +304,30 @@ int CmdInfo::execute (std::string& output)
|
|||
{
|
||||
// Note: This list must match that in Task::hasTag.
|
||||
std::string virtualTags = "";
|
||||
if (task->hasTag ("ACTIVE")) virtualTags += "ACTIVE ";
|
||||
if (task->hasTag ("ANNOTATED")) virtualTags += "ANNOTATED ";
|
||||
if (task->hasTag ("BLOCKED")) virtualTags += "BLOCKED ";
|
||||
if (task->hasTag ("BLOCKING")) virtualTags += "BLOCKING ";
|
||||
if (task->hasTag ("CHILD")) virtualTags += "CHILD ";
|
||||
if (task->hasTag ("COMPLETED")) virtualTags += "COMPLETED ";
|
||||
if (task->hasTag ("DELETED")) virtualTags += "DELETED ";
|
||||
if (task->hasTag ("DUE")) virtualTags += "DUE ";
|
||||
if (task->hasTag ("DUETODAY")) virtualTags += "DUETODAY ";
|
||||
if (task->hasTag ("MONTH")) virtualTags += "MONTH ";
|
||||
if (task->hasTag ("OVERDUE")) virtualTags += "OVERDUE ";
|
||||
if (task->hasTag ("PARENT")) virtualTags += "PARENT ";
|
||||
if (task->hasTag ("PENDING")) virtualTags += "PENDING ";
|
||||
if (task->hasTag ("READY")) virtualTags += "READY ";
|
||||
if (task->hasTag ("SCHEDULED")) virtualTags += "SCHEDULED ";
|
||||
if (task->hasTag ("TAGGED")) virtualTags += "TAGGED ";
|
||||
if (task->hasTag ("TODAY")) virtualTags += "TODAY ";
|
||||
if (task->hasTag ("TOMORROW")) virtualTags += "TOMORROW ";
|
||||
if (task->hasTag ("UNBLOCKED")) virtualTags += "UNBLOCKED ";
|
||||
if (task->hasTag ("UNTIL")) virtualTags += "UNTIL ";
|
||||
if (task->hasTag ("WAITING")) virtualTags += "WAITING ";
|
||||
if (task->hasTag ("WEEK")) virtualTags += "WEEK ";
|
||||
if (task->hasTag ("YEAR")) virtualTags += "YEAR ";
|
||||
if (task->hasTag ("YESTERDAY")) virtualTags += "YESTERDAY ";
|
||||
if (task.hasTag ("ACTIVE")) virtualTags += "ACTIVE ";
|
||||
if (task.hasTag ("ANNOTATED")) virtualTags += "ANNOTATED ";
|
||||
if (task.hasTag ("BLOCKED")) virtualTags += "BLOCKED ";
|
||||
if (task.hasTag ("BLOCKING")) virtualTags += "BLOCKING ";
|
||||
if (task.hasTag ("CHILD")) virtualTags += "CHILD ";
|
||||
if (task.hasTag ("COMPLETED")) virtualTags += "COMPLETED ";
|
||||
if (task.hasTag ("DELETED")) virtualTags += "DELETED ";
|
||||
if (task.hasTag ("DUE")) virtualTags += "DUE ";
|
||||
if (task.hasTag ("DUETODAY")) virtualTags += "DUETODAY ";
|
||||
if (task.hasTag ("MONTH")) virtualTags += "MONTH ";
|
||||
if (task.hasTag ("OVERDUE")) virtualTags += "OVERDUE ";
|
||||
if (task.hasTag ("PARENT")) virtualTags += "PARENT ";
|
||||
if (task.hasTag ("PENDING")) virtualTags += "PENDING ";
|
||||
if (task.hasTag ("READY")) virtualTags += "READY ";
|
||||
if (task.hasTag ("SCHEDULED")) virtualTags += "SCHEDULED ";
|
||||
if (task.hasTag ("TAGGED")) virtualTags += "TAGGED ";
|
||||
if (task.hasTag ("TODAY")) virtualTags += "TODAY ";
|
||||
if (task.hasTag ("TOMORROW")) virtualTags += "TOMORROW ";
|
||||
if (task.hasTag ("UNBLOCKED")) virtualTags += "UNBLOCKED ";
|
||||
if (task.hasTag ("UNTIL")) virtualTags += "UNTIL ";
|
||||
if (task.hasTag ("WAITING")) virtualTags += "WAITING ";
|
||||
if (task.hasTag ("WEEK")) virtualTags += "WEEK ";
|
||||
if (task.hasTag ("YEAR")) virtualTags += "YEAR ";
|
||||
if (task.hasTag ("YESTERDAY")) virtualTags += "YESTERDAY ";
|
||||
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_CMD_INFO_VIRTUAL_TAGS);
|
||||
|
@ -341,27 +337,26 @@ int CmdInfo::execute (std::string& output)
|
|||
// uuid
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_UUID);
|
||||
std::string uuid = task->get ("uuid");
|
||||
std::string uuid = task.get ("uuid");
|
||||
view.set (row, 1, uuid);
|
||||
|
||||
// Task::urgency
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_URGENCY);
|
||||
view.set (row, 1, format (task->urgency (), 4, 4));
|
||||
view.set (row, 1, format (task.urgency (), 4, 4));
|
||||
|
||||
// Show any UDAs
|
||||
std::vector <std::string> all = task->all ();
|
||||
std::vector <std::string>::iterator att;
|
||||
std::vector <std::string> all = task.all ();
|
||||
std::string type;
|
||||
for (att = all.begin (); att != all.end (); ++att)
|
||||
for (auto& att: all)
|
||||
{
|
||||
type = context.config.get ("uda." + *att + ".type");
|
||||
type = context.config.get ("uda." + att + ".type");
|
||||
if (type != "")
|
||||
{
|
||||
Column* col = context.columns[*att];
|
||||
Column* col = context.columns[att];
|
||||
if (col)
|
||||
{
|
||||
std::string value = task->get (*att);
|
||||
std::string value = task.get (att);
|
||||
if (value != "")
|
||||
{
|
||||
row = view.addRow ();
|
||||
|
@ -380,20 +375,20 @@ int CmdInfo::execute (std::string& output)
|
|||
|
||||
// Show any orphaned UDAs, which are identified by not being represented in
|
||||
// the context.columns map.
|
||||
for (att = all.begin (); att != all.end (); ++att)
|
||||
for (auto& att : all)
|
||||
{
|
||||
if (att->substr (0, 11) != "annotation_" &&
|
||||
context.columns.find (*att) == context.columns.end ())
|
||||
if (att.substr (0, 11) != "annotation_" &&
|
||||
context.columns.find (att) == context.columns.end ())
|
||||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, "[" + *att);
|
||||
view.set (row, 1, task->get (*att) + "]");
|
||||
view.set (row, 0, "[" + att);
|
||||
view.set (row, 1, task.get (att) + "]");
|
||||
}
|
||||
}
|
||||
|
||||
// Create a second table, containing urgency details, if necessary.
|
||||
ViewText urgencyDetails;
|
||||
if (task->urgency () != 0.0)
|
||||
if (task.urgency () != 0.0)
|
||||
{
|
||||
if (context.color ())
|
||||
{
|
||||
|
@ -413,74 +408,73 @@ int CmdInfo::execute (std::string& output)
|
|||
urgencyDetails.add (Column::factory ("string", "")); // =
|
||||
urgencyDetails.add (Column::factory ("string", "")); // Result
|
||||
|
||||
urgencyTerm (urgencyDetails, "project", task->urgency_project (), Task::urgencyProjectCoefficient);
|
||||
urgencyTerm (urgencyDetails, "active", task->urgency_active (), Task::urgencyActiveCoefficient);
|
||||
urgencyTerm (urgencyDetails, "scheduled", task->urgency_scheduled (), Task::urgencyScheduledCoefficient);
|
||||
urgencyTerm (urgencyDetails, "waiting", task->urgency_waiting (), Task::urgencyWaitingCoefficient);
|
||||
urgencyTerm (urgencyDetails, "blocked", task->urgency_blocked (), Task::urgencyBlockedCoefficient);
|
||||
urgencyTerm (urgencyDetails, "blocking", task->urgency_blocking (), Task::urgencyBlockingCoefficient);
|
||||
urgencyTerm (urgencyDetails, "annotations", task->urgency_annotations (), Task::urgencyAnnotationsCoefficient);
|
||||
urgencyTerm (urgencyDetails, "tags", task->urgency_tags (), Task::urgencyTagsCoefficient);
|
||||
urgencyTerm (urgencyDetails, "next", task->urgency_next (), Task::urgencyNextCoefficient);
|
||||
urgencyTerm (urgencyDetails, "due", task->urgency_due (), Task::urgencyDueCoefficient);
|
||||
urgencyTerm (urgencyDetails, "age", task->urgency_age (), Task::urgencyAgeCoefficient);
|
||||
urgencyTerm (urgencyDetails, "project", task.urgency_project (), Task::urgencyProjectCoefficient);
|
||||
urgencyTerm (urgencyDetails, "active", task.urgency_active (), Task::urgencyActiveCoefficient);
|
||||
urgencyTerm (urgencyDetails, "scheduled", task.urgency_scheduled (), Task::urgencyScheduledCoefficient);
|
||||
urgencyTerm (urgencyDetails, "waiting", task.urgency_waiting (), Task::urgencyWaitingCoefficient);
|
||||
urgencyTerm (urgencyDetails, "blocked", task.urgency_blocked (), Task::urgencyBlockedCoefficient);
|
||||
urgencyTerm (urgencyDetails, "blocking", task.urgency_blocking (), Task::urgencyBlockingCoefficient);
|
||||
urgencyTerm (urgencyDetails, "annotations", task.urgency_annotations (), Task::urgencyAnnotationsCoefficient);
|
||||
urgencyTerm (urgencyDetails, "tags", task.urgency_tags (), Task::urgencyTagsCoefficient);
|
||||
urgencyTerm (urgencyDetails, "next", task.urgency_next (), Task::urgencyNextCoefficient);
|
||||
urgencyTerm (urgencyDetails, "due", task.urgency_due (), Task::urgencyDueCoefficient);
|
||||
urgencyTerm (urgencyDetails, "age", task.urgency_age (), Task::urgencyAgeCoefficient);
|
||||
|
||||
// Tag, Project- and UDA-specific coefficients.
|
||||
std::map <std::string, float>::iterator var;
|
||||
for (var = Task::coefficients.begin (); var != Task::coefficients.end (); ++var)
|
||||
for (auto& var : Task::coefficients)
|
||||
{
|
||||
if (var->first.substr (0, 13) == "urgency.user.")
|
||||
if (var.first.substr (0, 13) == "urgency.user.")
|
||||
{
|
||||
// urgency.user.project.<project>.coefficient
|
||||
std::string::size_type end = std::string::npos;
|
||||
if (var->first.substr (13, 8) == "project." &&
|
||||
(end = var->first.find (".coefficient")) != std::string::npos)
|
||||
if (var.first.substr (13, 8) == "project." &&
|
||||
(end = var.first.find (".coefficient")) != std::string::npos)
|
||||
{
|
||||
std::string project = var->first.substr (21, end - 21);
|
||||
if (task->get ("project").find (project) == 0)
|
||||
urgencyTerm (urgencyDetails, "PROJECT " + project, 1.0, var->second);
|
||||
std::string project = var.first.substr (21, end - 21);
|
||||
if (task.get ("project").find (project) == 0)
|
||||
urgencyTerm (urgencyDetails, "PROJECT " + project, 1.0, var.second);
|
||||
}
|
||||
|
||||
// urgency.user.tag.<tag>.coefficient
|
||||
if (var->first.substr (13, 4) == "tag." &&
|
||||
(end = var->first.find (".coefficient")) != std::string::npos)
|
||||
if (var.first.substr (13, 4) == "tag." &&
|
||||
(end = var.first.find (".coefficient")) != std::string::npos)
|
||||
{
|
||||
std::string name = var->first.substr (17, end - 17);
|
||||
if (task->hasTag (name))
|
||||
urgencyTerm (urgencyDetails, "TAG " + name, 1.0, var->second);
|
||||
std::string name = var.first.substr (17, end - 17);
|
||||
if (task.hasTag (name))
|
||||
urgencyTerm (urgencyDetails, "TAG " + name, 1.0, var.second);
|
||||
}
|
||||
|
||||
// urgency.user.keyword.<keyword>.coefficient
|
||||
if (var->first.substr (13, 8) == "keyword." &&
|
||||
(end = var->first.find (".coefficient")) != std::string::npos)
|
||||
if (var.first.substr (13, 8) == "keyword." &&
|
||||
(end = var.first.find (".coefficient")) != std::string::npos)
|
||||
{
|
||||
std::string keyword = var->first.substr (21, end - 21);
|
||||
if (task->get ("description").find (keyword) != std::string::npos)
|
||||
urgencyTerm (urgencyDetails, "KEYWORD " + keyword, 1.0, var->second);
|
||||
std::string keyword = var.first.substr (21, end - 21);
|
||||
if (task.get ("description").find (keyword) != std::string::npos)
|
||||
urgencyTerm (urgencyDetails, "KEYWORD " + keyword, 1.0, var.second);
|
||||
}
|
||||
}
|
||||
|
||||
// urgency.uda.<name>.coefficient
|
||||
else if (var->first.substr (0, 12) == "urgency.uda.")
|
||||
else if (var.first.substr (0, 12) == "urgency.uda.")
|
||||
{
|
||||
// urgency.uda.<name>.coefficient
|
||||
// urgency.uda.<name>.<value>.coefficient
|
||||
std::string::size_type end = var->first.find (".coefficient");
|
||||
std::string::size_type end = var.first.find (".coefficient");
|
||||
if (end != std::string::npos)
|
||||
{
|
||||
const std::string uda = var->first.substr (12, end - 12);
|
||||
const std::string uda = var.first.substr (12, end - 12);
|
||||
std::string::size_type dot = uda.find (".");
|
||||
if (dot == std::string::npos)
|
||||
{
|
||||
// urgency.uda.<name>.coefficient
|
||||
if (task->has (uda))
|
||||
urgencyTerm (urgencyDetails, std::string ("UDA ") + uda, 1.0, var->second);
|
||||
if (task.has (uda))
|
||||
urgencyTerm (urgencyDetails, std::string ("UDA ") + uda, 1.0, var.second);
|
||||
}
|
||||
else
|
||||
{
|
||||
// urgency.uda.<name>.<value>.coefficient
|
||||
if (task->get (uda.substr(0, dot)) == uda.substr(dot+1))
|
||||
urgencyTerm (urgencyDetails, std::string ("UDA ") + uda, 1.0, var->second);
|
||||
if (task.get (uda.substr(0, dot)) == uda.substr(dot+1))
|
||||
urgencyTerm (urgencyDetails, std::string ("UDA ") + uda, 1.0, var.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -489,7 +483,7 @@ int CmdInfo::execute (std::string& output)
|
|||
row = urgencyDetails.addRow ();
|
||||
urgencyDetails.set (row, 5, rightJustify ("------", 6));
|
||||
row = urgencyDetails.addRow ();
|
||||
urgencyDetails.set (row, 5, rightJustify (format (task->urgency (), 4, 4), 6));
|
||||
urgencyDetails.set (row, 5, rightJustify (format (task.urgency (), 4, 4), 6));
|
||||
}
|
||||
|
||||
// Create a third table, containing undo log change details.
|
||||
|
|
|
@ -67,104 +67,101 @@ int CmdModify::execute (std::string& output)
|
|||
// Accumulated project change notifications.
|
||||
std::map <std::string, std::string> projectChanges;
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
Task before (*task);
|
||||
task->modify (Task::modReplace);
|
||||
Task before (task);
|
||||
task.modify (Task::modReplace);
|
||||
|
||||
if (taskDiff (before, *task))
|
||||
if (taskDiff (before, task))
|
||||
{
|
||||
// Perform some logical consistency checks.
|
||||
if (task->has ("recur") &&
|
||||
!task->has ("due") &&
|
||||
if (task.has ("recur") &&
|
||||
!task.has ("due") &&
|
||||
!before.has ("due"))
|
||||
throw std::string (STRING_CMD_MODIFY_NO_DUE);
|
||||
|
||||
if (before.has ("recur") &&
|
||||
before.has ("due") &&
|
||||
(!task->has ("due") ||
|
||||
task->get ("due") == ""))
|
||||
(!task.has ("due") ||
|
||||
task.get ("due") == ""))
|
||||
throw std::string (STRING_CMD_MODIFY_REM_DUE);
|
||||
|
||||
if (before.has ("recur") &&
|
||||
(!task->has ("recur") ||
|
||||
task->get ("recur") == ""))
|
||||
(!task.has ("recur") ||
|
||||
task.get ("recur") == ""))
|
||||
throw std::string (STRING_CMD_MODIFY_REC_ALWAYS);
|
||||
|
||||
// Delete the specified task.
|
||||
std::string question;
|
||||
if (task->id != 0)
|
||||
if (task.id != 0)
|
||||
question = format (STRING_CMD_MODIFY_CONFIRM,
|
||||
task->id,
|
||||
task->get ("description"));
|
||||
task.id,
|
||||
task.get ("description"));
|
||||
else
|
||||
question = format (STRING_CMD_MODIFY_CONFIRM,
|
||||
task->get ("uuid"),
|
||||
task->get ("description"));
|
||||
task.get ("uuid"),
|
||||
task.get ("description"));
|
||||
|
||||
if (permission (*task, taskDifferences (before, *task) + question, filtered.size ()))
|
||||
if (permission (task, taskDifferences (before, task) + question, filtered.size ()))
|
||||
{
|
||||
updateRecurrenceMask (*task);
|
||||
dependencyChainOnModify (before, *task);
|
||||
updateRecurrenceMask (task);
|
||||
dependencyChainOnModify (before, task);
|
||||
++count;
|
||||
feedback_affected (STRING_CMD_MODIFY_TASK, *task);
|
||||
feedback_unblocked (*task);
|
||||
context.tdb2.modify (*task);
|
||||
feedback_affected (STRING_CMD_MODIFY_TASK, task);
|
||||
feedback_unblocked (task);
|
||||
context.tdb2.modify (task);
|
||||
if (context.verbose ("project"))
|
||||
projectChanges[task->get ("project")] = onProjectChange (before, *task);
|
||||
projectChanges[task.get ("project")] = onProjectChange (before, task);
|
||||
|
||||
// Task potentially has siblings - modify them.
|
||||
if (task->has ("parent"))
|
||||
if (task.has ("parent"))
|
||||
{
|
||||
if ((context.config.get ("recurrence.confirmation") == "prompt"
|
||||
&& confirm (STRING_CMD_MODIFY_RECUR)) ||
|
||||
context.config.getBoolean ("recurrence.confirmation"))
|
||||
{
|
||||
std::vector <Task> siblings = context.tdb2.siblings (*task);
|
||||
std::vector <Task>::iterator sibling;
|
||||
for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling)
|
||||
std::vector <Task> siblings = context.tdb2.siblings (task);
|
||||
for (auto& sibling : siblings)
|
||||
{
|
||||
Task alternate (*sibling);
|
||||
sibling->modify (Task::modReplace);
|
||||
updateRecurrenceMask (*sibling);
|
||||
dependencyChainOnModify (alternate, *sibling);
|
||||
Task alternate (sibling);
|
||||
sibling.modify (Task::modReplace);
|
||||
updateRecurrenceMask (sibling);
|
||||
dependencyChainOnModify (alternate, sibling);
|
||||
++count;
|
||||
feedback_affected (STRING_CMD_MODIFY_TASK_R, *sibling);
|
||||
feedback_unblocked (*sibling);
|
||||
context.tdb2.modify (*sibling);
|
||||
feedback_affected (STRING_CMD_MODIFY_TASK_R, sibling);
|
||||
feedback_unblocked (sibling);
|
||||
context.tdb2.modify (sibling);
|
||||
if (context.verbose ("project"))
|
||||
projectChanges[sibling->get ("project")] = onProjectChange (alternate, *sibling);
|
||||
projectChanges[sibling.get ("project")] = onProjectChange (alternate, sibling);
|
||||
}
|
||||
|
||||
// Modify the parent
|
||||
Task parent;
|
||||
context.tdb2.get (task->get ("parent"), parent);
|
||||
context.tdb2.get (task.get ("parent"), parent);
|
||||
parent.modify (Task::modReplace);
|
||||
context.tdb2.modify (parent);
|
||||
}
|
||||
}
|
||||
|
||||
// Task potentially has child tasks - modify them.
|
||||
else if (task->get ("status") == "recurring")
|
||||
else if (task.get ("status") == "recurring")
|
||||
{
|
||||
std::vector <Task> children = context.tdb2.children (*task);
|
||||
std::vector <Task> children = context.tdb2.children (task);
|
||||
if (children.size () &&
|
||||
(! context.config.getBoolean ("recurrence.confirmation") ||
|
||||
confirm (STRING_CMD_MODIFY_RECUR)))
|
||||
{
|
||||
std::vector <Task>::iterator child;
|
||||
for (child = children.begin (); child != children.end (); ++child)
|
||||
for (auto& child : children)
|
||||
{
|
||||
Task alternate (*child);
|
||||
child->modify (Task::modReplace);
|
||||
updateRecurrenceMask (*child);
|
||||
context.tdb2.modify (*child);
|
||||
dependencyChainOnModify (alternate, *child);
|
||||
Task alternate (child);
|
||||
child.modify (Task::modReplace);
|
||||
updateRecurrenceMask (child);
|
||||
context.tdb2.modify (child);
|
||||
dependencyChainOnModify (alternate, child);
|
||||
if (context.verbose ("project"))
|
||||
projectChanges[child->get ("project")] = onProjectChange (alternate, *child);
|
||||
projectChanges[child.get ("project")] = onProjectChange (alternate, child);
|
||||
++count;
|
||||
feedback_affected (STRING_CMD_MODIFY_TASK_R, *child);
|
||||
feedback_affected (STRING_CMD_MODIFY_TASK_R, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -180,10 +177,9 @@ int CmdModify::execute (std::string& output)
|
|||
}
|
||||
|
||||
// Now list the project changes.
|
||||
std::map <std::string, std::string>::iterator i;
|
||||
for (i = projectChanges.begin (); i != projectChanges.end (); ++i)
|
||||
if (i->first != "")
|
||||
context.footnote (i->second);
|
||||
for (auto& change : projectChanges)
|
||||
if (change.first != "")
|
||||
context.footnote (change.second);
|
||||
|
||||
feedback_affected (count == 1 ? STRING_CMD_MODIFY_1 : STRING_CMD_MODIFY_N, count);
|
||||
return rc;
|
||||
|
|
|
@ -67,46 +67,44 @@ int CmdPrepend::execute (std::string& output)
|
|||
// Accumulated project change notifications.
|
||||
std::map <std::string, std::string> projectChanges;
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
Task before (*task);
|
||||
Task before (task);
|
||||
|
||||
// Prepend to the specified task.
|
||||
std::string question = format (STRING_CMD_PREPEND_CONFIRM,
|
||||
task->id,
|
||||
task->get ("description"));
|
||||
task.id,
|
||||
task.get ("description"));
|
||||
|
||||
task->modify (Task::modPrepend, true);
|
||||
task.modify (Task::modPrepend, true);
|
||||
|
||||
if (permission (*task, taskDifferences (before, *task) + question, filtered.size ()))
|
||||
if (permission (task, taskDifferences (before, task) + question, filtered.size ()))
|
||||
{
|
||||
context.tdb2.modify (*task);
|
||||
context.tdb2.modify (task);
|
||||
++count;
|
||||
feedback_affected (STRING_CMD_PREPEND_TASK, *task);
|
||||
feedback_affected (STRING_CMD_PREPEND_TASK, task);
|
||||
if (context.verbose ("project"))
|
||||
projectChanges[task->get ("project")] = onProjectChange (*task, false);
|
||||
projectChanges[task.get ("project")] = onProjectChange (task, false);
|
||||
|
||||
// Prepend to siblings.
|
||||
if (task->has ("parent"))
|
||||
if (task.has ("parent"))
|
||||
{
|
||||
if ((context.config.get ("recurrence.confirmation") == "prompt"
|
||||
&& confirm (STRING_CMD_PREPEND_CONFIRM_R)) ||
|
||||
context.config.getBoolean ("recurrence.confirmation"))
|
||||
{
|
||||
std::vector <Task> siblings = context.tdb2.siblings (*task);
|
||||
std::vector <Task>::iterator sibling;
|
||||
for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling)
|
||||
std::vector <Task> siblings = context.tdb2.siblings (task);
|
||||
for (auto& sibling : siblings)
|
||||
{
|
||||
sibling->modify (Task::modPrepend, true);
|
||||
context.tdb2.modify (*sibling);
|
||||
sibling.modify (Task::modPrepend, true);
|
||||
context.tdb2.modify (sibling);
|
||||
++count;
|
||||
feedback_affected (STRING_CMD_PREPEND_TASK_R, *sibling);
|
||||
feedback_affected (STRING_CMD_PREPEND_TASK_R, sibling);
|
||||
}
|
||||
|
||||
// Prepend to the parent
|
||||
Task parent;
|
||||
context.tdb2.get (task->get ("parent"), parent);
|
||||
context.tdb2.get (task.get ("parent"), parent);
|
||||
parent.modify (Task::modPrepend, true);
|
||||
context.tdb2.modify (parent);
|
||||
}
|
||||
|
@ -122,10 +120,9 @@ int CmdPrepend::execute (std::string& output)
|
|||
}
|
||||
|
||||
// Now list the project changes.
|
||||
std::map <std::string, std::string>::iterator i;
|
||||
for (i = projectChanges.begin (); i != projectChanges.end (); ++i)
|
||||
if (i->first != "")
|
||||
context.footnote (i->second);
|
||||
for (auto& change : projectChanges)
|
||||
if (change.first != "")
|
||||
context.footnote (change.second);
|
||||
|
||||
feedback_affected (count == 1 ? STRING_CMD_PREPEND_1 : STRING_CMD_PREPEND_N, count);
|
||||
return rc;
|
||||
|
|
|
@ -58,15 +58,11 @@ int CmdProjects::execute (std::string& output)
|
|||
|
||||
// Get all the tasks.
|
||||
handleRecurrence ();
|
||||
std::vector <Task> tasks = context.tdb2.pending.get_tasks ();
|
||||
auto tasks = context.tdb2.pending.get_tasks ();
|
||||
|
||||
if (context.config.getBoolean ("list.all.projects"))
|
||||
{
|
||||
std::vector <Task> extra = context.tdb2.completed.get_tasks ();
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = extra.begin (); task != extra.end (); ++task)
|
||||
tasks.push_back (*task);
|
||||
}
|
||||
for (auto& task : context.tdb2.completed.get_tasks ())
|
||||
tasks.push_back (task);
|
||||
|
||||
// Apply the filter.
|
||||
Filter filter;
|
||||
|
@ -82,10 +78,9 @@ int CmdProjects::execute (std::string& output)
|
|||
std::map <std::string, int> unique;
|
||||
bool no_project = false;
|
||||
std::string project;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
if (task->getStatus () == Task::deleted)
|
||||
if (task.getStatus () == Task::deleted)
|
||||
{
|
||||
--quantity;
|
||||
continue;
|
||||
|
@ -93,14 +88,13 @@ int CmdProjects::execute (std::string& output)
|
|||
|
||||
// Increase the count for the project the task belongs to and all
|
||||
// its super-projects
|
||||
project = task->get ("project");
|
||||
project = task.get ("project");
|
||||
|
||||
std::vector <std::string> projects = extractParents (project);
|
||||
projects.push_back (project);
|
||||
|
||||
std::vector <std::string>::const_iterator parent;
|
||||
for (parent = projects.begin (); parent != projects.end (); ++parent)
|
||||
unique[*parent] += 1;
|
||||
for (auto& parent : projects)
|
||||
unique[parent] += 1;
|
||||
|
||||
if (project == "")
|
||||
no_project = true;
|
||||
|
@ -118,27 +112,24 @@ int CmdProjects::execute (std::string& output)
|
|||
view.colorHeader (label);
|
||||
|
||||
std::vector <std::string> processed;
|
||||
std::map <std::string, int>::iterator project;
|
||||
for (project = unique.begin (); project != unique.end (); ++project)
|
||||
for (auto& project : unique)
|
||||
{
|
||||
const std::vector <std::string> parents = extractParents (project->first);
|
||||
std::vector <std::string>::const_iterator parent;
|
||||
for (parent = parents.begin (); parent != parents.end (); parent++)
|
||||
const std::vector <std::string> parents = extractParents (project.first);
|
||||
for (auto& parent : parents)
|
||||
{
|
||||
if (std::find (processed.begin (), processed.end (), *parent)
|
||||
== processed.end ())
|
||||
if (std::find (processed.begin (), processed.end (), parent) == processed.end ())
|
||||
{
|
||||
int row = view.addRow ();
|
||||
view.set (row, 0, indentProject (*parent));
|
||||
processed.push_back (*parent);
|
||||
view.set (row, 0, indentProject (parent));
|
||||
processed.push_back (parent);
|
||||
}
|
||||
}
|
||||
int row = view.addRow ();
|
||||
view.set (row, 0, (project->first == ""
|
||||
view.set (row, 0, (project.first == ""
|
||||
? STRING_CMD_PROJECTS_NONE
|
||||
: indentProject (project->first, " ", '.')));
|
||||
view.set (row, 1, project->second);
|
||||
processed.push_back (project->first);
|
||||
: indentProject (project.first, " ", '.')));
|
||||
view.set (row, 1, project.second);
|
||||
processed.push_back (project.first);
|
||||
}
|
||||
|
||||
int number_projects = unique.size ();
|
||||
|
@ -182,15 +173,11 @@ int CmdCompletionProjects::execute (std::string& output)
|
|||
{
|
||||
// Get all the tasks.
|
||||
handleRecurrence ();
|
||||
std::vector <Task> tasks = context.tdb2.pending.get_tasks ();
|
||||
auto tasks = context.tdb2.pending.get_tasks ();
|
||||
|
||||
if (context.config.getBoolean ("list.all.projects"))
|
||||
{
|
||||
std::vector <Task> extra = context.tdb2.completed.get_tasks ();
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = extra.begin (); task != extra.end (); ++task)
|
||||
tasks.push_back (*task);
|
||||
}
|
||||
for (auto& task : context.tdb2.completed.get_tasks ())
|
||||
tasks.push_back (task);
|
||||
|
||||
// Apply the filter.
|
||||
Filter filter;
|
||||
|
@ -200,14 +187,12 @@ int CmdCompletionProjects::execute (std::string& output)
|
|||
// Scan all the tasks for their project name, building a map using project
|
||||
// names as keys.
|
||||
std::map <std::string, int> unique;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
unique[task->get ("project")] = 0;
|
||||
for (auto& task : filtered)
|
||||
unique[task.get ("project")] = 0;
|
||||
|
||||
std::map <std::string, int>::iterator project;
|
||||
for (project = unique.begin (); project != unique.end (); ++project)
|
||||
if (project->first.length ())
|
||||
output += project->first + "\n";
|
||||
for (auto& project : unique)
|
||||
if (project.first.length ())
|
||||
output += project.first + "\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -51,12 +51,11 @@ int CmdReports::execute (std::string& output)
|
|||
std::vector <std::string> reports;
|
||||
|
||||
// Add custom reports.
|
||||
Config::const_iterator i;
|
||||
for (i = context.config.begin (); i != context.config.end (); ++i)
|
||||
for (auto& i : context.config)
|
||||
{
|
||||
if (i->first.substr (0, 7) == "report.")
|
||||
if (i.first.substr (0, 7) == "report.")
|
||||
{
|
||||
std::string report = i->first.substr (7);
|
||||
std::string report = i.first.substr (7);
|
||||
std::string::size_type columns = report.find (".columns");
|
||||
if (columns != std::string::npos)
|
||||
reports.push_back (report.substr (0, columns));
|
||||
|
@ -96,12 +95,11 @@ int CmdReports::execute (std::string& output)
|
|||
view.intraColorOdd (alternate);
|
||||
}
|
||||
|
||||
std::vector <std::string>::iterator report;
|
||||
for (report = reports.begin (); report != reports.end (); ++report)
|
||||
for (auto& report : reports)
|
||||
{
|
||||
int row = view.addRow ();
|
||||
view.set (row, 0, *report);
|
||||
view.set (row, 1, context.commands[*report]->description ());
|
||||
view.set (row, 0, report);
|
||||
view.set (row, 1, context.commands[report]->description ());
|
||||
}
|
||||
|
||||
out << optionalBlankLine ()
|
||||
|
|
|
@ -213,33 +213,32 @@ int CmdShow::execute (std::string& output)
|
|||
recognized += "_forcecolor ";
|
||||
|
||||
std::vector <std::string> unrecognized;
|
||||
Config::const_iterator i;
|
||||
for (i = context.config.begin (); i != context.config.end (); ++i)
|
||||
for (auto& i : context.config)
|
||||
{
|
||||
// Disallow partial matches by tacking a leading and trailing space on each
|
||||
// variable name.
|
||||
std::string pattern = " " + i->first + " ";
|
||||
std::string pattern = " " + i.first + " ";
|
||||
if (recognized.find (pattern) == std::string::npos)
|
||||
{
|
||||
// These are special configuration variables, because their name is
|
||||
// dynamic.
|
||||
if (i->first.substr (0, 14) != "color.keyword." &&
|
||||
i->first.substr (0, 14) != "color.project." &&
|
||||
i->first.substr (0, 10) != "color.tag." &&
|
||||
i->first.substr (0, 10) != "color.uda." &&
|
||||
i->first.substr (0, 8) != "context." &&
|
||||
i->first.substr (0, 8) != "holiday." &&
|
||||
i->first.substr (0, 7) != "report." &&
|
||||
i->first.substr (0, 6) != "alias." &&
|
||||
i->first.substr (0, 5) != "hook." &&
|
||||
i->first.substr (0, 4) != "uda." &&
|
||||
i->first.substr (0, 8) != "default." &&
|
||||
i->first.substr (0, 21) != "urgency.user.project." &&
|
||||
i->first.substr (0, 17) != "urgency.user.tag." &&
|
||||
i->first.substr (0, 21) != "urgency.user.keyword." &&
|
||||
i->first.substr (0, 12) != "urgency.uda.")
|
||||
if (i.first.substr (0, 14) != "color.keyword." &&
|
||||
i.first.substr (0, 14) != "color.project." &&
|
||||
i.first.substr (0, 10) != "color.tag." &&
|
||||
i.first.substr (0, 10) != "color.uda." &&
|
||||
i.first.substr (0, 8) != "context." &&
|
||||
i.first.substr (0, 8) != "holiday." &&
|
||||
i.first.substr (0, 7) != "report." &&
|
||||
i.first.substr (0, 6) != "alias." &&
|
||||
i.first.substr (0, 5) != "hook." &&
|
||||
i.first.substr (0, 4) != "uda." &&
|
||||
i.first.substr (0, 8) != "default." &&
|
||||
i.first.substr (0, 21) != "urgency.user.project." &&
|
||||
i.first.substr (0, 17) != "urgency.user.tag." &&
|
||||
i.first.substr (0, 21) != "urgency.user.keyword." &&
|
||||
i.first.substr (0, 12) != "urgency.uda.")
|
||||
{
|
||||
unrecognized.push_back (i->first);
|
||||
unrecognized.push_back (i.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -249,9 +248,9 @@ int CmdShow::execute (std::string& output)
|
|||
Config default_config;
|
||||
default_config.setDefaults ();
|
||||
|
||||
for (i = context.config.begin (); i != context.config.end (); ++i)
|
||||
if (i->second != default_config.get (i->first))
|
||||
default_values.push_back (i->first);
|
||||
for (auto& i : context.config)
|
||||
if (i.second != default_config.get (i.first))
|
||||
default_values.push_back (i.first);
|
||||
|
||||
// Create output view.
|
||||
ViewText view;
|
||||
|
@ -278,35 +277,35 @@ int CmdShow::execute (std::string& output)
|
|||
section = "";
|
||||
|
||||
std::string::size_type loc;
|
||||
for (i = context.config.begin (); i != context.config.end (); ++i)
|
||||
for (auto& i : context.config)
|
||||
{
|
||||
loc = i->first.find (section, 0);
|
||||
loc = i.first.find (section, 0);
|
||||
if (loc != std::string::npos)
|
||||
{
|
||||
// Look for unrecognized.
|
||||
Color color;
|
||||
if (std::find (unrecognized.begin (), unrecognized.end (), i->first) != unrecognized.end ())
|
||||
if (std::find (unrecognized.begin (), unrecognized.end (), i.first) != unrecognized.end ())
|
||||
{
|
||||
issue_error = true;
|
||||
color = error;
|
||||
}
|
||||
else if (std::find (default_values.begin (), default_values.end (), i->first) != default_values.end ())
|
||||
else if (std::find (default_values.begin (), default_values.end (), i.first) != default_values.end ())
|
||||
{
|
||||
issue_warning = true;
|
||||
color = warning;
|
||||
}
|
||||
|
||||
std::string value = i->second;
|
||||
std::string value = i.second;
|
||||
int row = view.addRow ();
|
||||
view.set (row, 0, i->first, color);
|
||||
view.set (row, 0, i.first, color);
|
||||
view.set (row, 1, value, color);
|
||||
|
||||
if (default_config[i->first] != value &&
|
||||
default_config[i->first] != "")
|
||||
if (default_config[i.first] != value &&
|
||||
default_config[i.first] != "")
|
||||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, std::string (" ") + STRING_CMD_SHOW_CONF_DEFAULT, color);
|
||||
view.set (row, 1, default_config[i->first], color);
|
||||
view.set (row, 1, default_config[i.first], color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -331,9 +330,8 @@ int CmdShow::execute (std::string& output)
|
|||
{
|
||||
out << STRING_CMD_SHOW_UNREC << "\n";
|
||||
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = unrecognized.begin (); i != unrecognized.end (); ++i)
|
||||
out << " " << *i << "\n";
|
||||
for (auto& i : unrecognized)
|
||||
out << " " << i << "\n";
|
||||
|
||||
if (context.color ())
|
||||
out << "\n" << format (STRING_CMD_SHOW_DIFFER_COLOR, error.colorize ("color"));
|
||||
|
@ -408,10 +406,9 @@ int CmdShowRaw::execute (std::string& output)
|
|||
std::sort (all.begin (), all.end ());
|
||||
|
||||
// Display them all.
|
||||
std::vector <std::string>::iterator i;
|
||||
std::stringstream out;
|
||||
for (i = all.begin (); i != all.end (); ++i)
|
||||
out << *i << '=' << context.config.get (*i) << "\n";
|
||||
for (auto& i : all)
|
||||
out << i << '=' << context.config.get (i) << "\n";
|
||||
|
||||
output = out.str ();
|
||||
return 0;
|
||||
|
|
|
@ -66,34 +66,33 @@ int CmdStart::execute (std::string& output)
|
|||
std::map <std::string, std::string> projectChanges;
|
||||
|
||||
bool nagged = false;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
if (! task->has ("start"))
|
||||
if (! task.has ("start"))
|
||||
{
|
||||
Task before (*task);
|
||||
Task before (task);
|
||||
|
||||
// Start the specified task.
|
||||
std::string question = format (STRING_CMD_START_CONFIRM,
|
||||
task->id,
|
||||
task->get ("description"));
|
||||
task->modify (Task::modAnnotate);
|
||||
task->setAsNow ("start");
|
||||
task.id,
|
||||
task.get ("description"));
|
||||
task.modify (Task::modAnnotate);
|
||||
task.setAsNow ("start");
|
||||
|
||||
if (context.config.getBoolean ("journal.time"))
|
||||
task->addAnnotation (context.config.get ("journal.time.start.annotation"));
|
||||
task.addAnnotation (context.config.get ("journal.time.start.annotation"));
|
||||
|
||||
if (permission (*task, taskDifferences (before, *task) + question, filtered.size ()))
|
||||
if (permission (task, taskDifferences (before, task) + question, filtered.size ()))
|
||||
{
|
||||
updateRecurrenceMask (*task);
|
||||
context.tdb2.modify (*task);
|
||||
updateRecurrenceMask (task);
|
||||
context.tdb2.modify (task);
|
||||
++count;
|
||||
feedback_affected (STRING_CMD_START_TASK, *task);
|
||||
feedback_affected (STRING_CMD_START_TASK, task);
|
||||
if (!nagged)
|
||||
nagged = nag (*task);
|
||||
dependencyChainOnStart (*task);
|
||||
nagged = nag (task);
|
||||
dependencyChainOnStart (task);
|
||||
if (context.verbose ("project"))
|
||||
projectChanges[task->get ("project")] = onProjectChange (*task, false);
|
||||
projectChanges[task.get ("project")] = onProjectChange (task, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -106,18 +105,17 @@ int CmdStart::execute (std::string& output)
|
|||
else
|
||||
{
|
||||
std::cout << format (STRING_CMD_START_ALREADY,
|
||||
task->id,
|
||||
task->get ("description"))
|
||||
task.id,
|
||||
task.get ("description"))
|
||||
<< "\n";
|
||||
rc = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Now list the project changes.
|
||||
std::map <std::string, std::string>::iterator i;
|
||||
for (i = projectChanges.begin (); i != projectChanges.end (); ++i)
|
||||
if (i->first != "")
|
||||
context.footnote (i->second);
|
||||
for (auto& change : projectChanges)
|
||||
if (change.first != "")
|
||||
context.footnote (change.second);
|
||||
|
||||
feedback_affected (count == 1 ? STRING_CMD_START_1 : STRING_CMD_START_N, count);
|
||||
return rc;
|
||||
|
|
|
@ -67,16 +67,15 @@ int CmdStats::execute (std::string& output)
|
|||
// Count the undo transactions.
|
||||
std::vector <std::string> undoTxns = context.tdb2.undo.get_lines ();
|
||||
int undoCount = 0;
|
||||
std::vector <std::string>::iterator tx;
|
||||
for (tx = undoTxns.begin (); tx != undoTxns.end (); ++tx)
|
||||
if (*tx == "---")
|
||||
for (auto& tx : undoTxns)
|
||||
if (tx == "---")
|
||||
++undoCount;
|
||||
|
||||
// Count the backlog transactions.
|
||||
std::vector <std::string> backlogTxns = context.tdb2.backlog.get_lines ();
|
||||
int backlogCount = 0;
|
||||
for (tx = backlogTxns.begin (); tx != backlogTxns.end (); ++tx)
|
||||
if ((*tx)[0] == '{')
|
||||
for (auto& tx : backlogTxns)
|
||||
if (tx[0] == '{')
|
||||
++backlogCount;
|
||||
|
||||
// Get all the tasks.
|
||||
|
@ -103,12 +102,11 @@ int CmdStats::execute (std::string& output)
|
|||
std::map <std::string, int> allTags;
|
||||
std::map <std::string, int> allProjects;
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
++totalT;
|
||||
|
||||
Task::status status = task->getStatus ();
|
||||
Task::status status = task.getStatus ();
|
||||
switch (status)
|
||||
{
|
||||
case Task::deleted: ++deletedT; break;
|
||||
|
@ -118,37 +116,37 @@ int CmdStats::execute (std::string& output)
|
|||
case Task::waiting: ++waitingT; break;
|
||||
}
|
||||
|
||||
if (task->is_blocked) ++blockedT;
|
||||
if (task->is_blocking) ++blockingT;
|
||||
if (task.is_blocked) ++blockedT;
|
||||
if (task.is_blocking) ++blockingT;
|
||||
|
||||
time_t entry = strtol (task->get ("entry").c_str (), NULL, 10);
|
||||
time_t entry = strtol (task.get ("entry").c_str (), NULL, 10);
|
||||
if (entry < earliest) earliest = entry;
|
||||
if (entry > latest) latest = entry;
|
||||
|
||||
if (status == Task::completed)
|
||||
{
|
||||
time_t end = strtol (task->get ("end").c_str (), NULL, 10);
|
||||
time_t end = strtol (task.get ("end").c_str (), NULL, 10);
|
||||
daysPending += (end - entry) / 86400.0;
|
||||
}
|
||||
|
||||
if (status == Task::pending)
|
||||
daysPending += (now.toEpoch () - entry) / 86400.0;
|
||||
|
||||
descLength += task->get ("description").length ();
|
||||
descLength += task.get ("description").length ();
|
||||
|
||||
std::map <std::string, std::string> annotations;
|
||||
task->getAnnotations (annotations);
|
||||
task.getAnnotations (annotations);
|
||||
annotationsT += annotations.size ();
|
||||
|
||||
std::vector <std::string> tags;
|
||||
task->getTags (tags);
|
||||
if (tags.size ()) ++taggedT;
|
||||
task.getTags (tags);
|
||||
if (tags.size ())
|
||||
++taggedT;
|
||||
|
||||
std::vector <std::string>::iterator t;
|
||||
for (t = tags.begin (); t != tags.end (); ++t)
|
||||
allTags[*t] = 0;
|
||||
for (auto& tag : tags)
|
||||
allTags[tag] = 0;
|
||||
|
||||
std::string project = task->get ("project");
|
||||
std::string project = task.get ("project");
|
||||
if (project != "")
|
||||
allProjects[project] = 0;
|
||||
}
|
||||
|
|
|
@ -64,33 +64,32 @@ int CmdStop::execute (std::string& output)
|
|||
// Accumulated project change notifications.
|
||||
std::map <std::string, std::string> projectChanges;
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
if (task->has ("start"))
|
||||
if (task.has ("start"))
|
||||
{
|
||||
Task before (*task);
|
||||
Task before (task);
|
||||
|
||||
// Stop the specified task.
|
||||
std::string question = format (STRING_CMD_STOP_CONFIRM,
|
||||
task->id,
|
||||
task->get ("description"));
|
||||
task.id,
|
||||
task.get ("description"));
|
||||
|
||||
task->modify (Task::modAnnotate);
|
||||
task->remove ("start");
|
||||
task.modify (Task::modAnnotate);
|
||||
task.remove ("start");
|
||||
|
||||
if (context.config.getBoolean ("journal.time"))
|
||||
task->addAnnotation (context.config.get ("journal.time.stop.annotation"));
|
||||
task.addAnnotation (context.config.get ("journal.time.stop.annotation"));
|
||||
|
||||
if (permission (*task, taskDifferences (before, *task) + question, filtered.size ()))
|
||||
if (permission (task, taskDifferences (before, task) + question, filtered.size ()))
|
||||
{
|
||||
updateRecurrenceMask (*task);
|
||||
context.tdb2.modify (*task);
|
||||
updateRecurrenceMask (task);
|
||||
context.tdb2.modify (task);
|
||||
++count;
|
||||
feedback_affected (STRING_CMD_STOP_TASK, *task);
|
||||
dependencyChainOnStart (*task);
|
||||
feedback_affected (STRING_CMD_STOP_TASK, task);
|
||||
dependencyChainOnStart (task);
|
||||
if (context.verbose ("project"))
|
||||
projectChanges[task->get ("project")] = onProjectChange (*task, false);
|
||||
projectChanges[task.get ("project")] = onProjectChange (task, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -103,18 +102,17 @@ int CmdStop::execute (std::string& output)
|
|||
else
|
||||
{
|
||||
std::cout << format (STRING_CMD_STOP_ALREADY,
|
||||
task->id,
|
||||
task->get ("description"))
|
||||
task.id,
|
||||
task.get ("description"))
|
||||
<< "\n";
|
||||
rc = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Now list the project changes.
|
||||
std::map <std::string, std::string>::iterator i;
|
||||
for (i = projectChanges.begin (); i != projectChanges.end (); ++i)
|
||||
if (i->first != "")
|
||||
context.footnote (i->second);
|
||||
for (auto& change : projectChanges)
|
||||
if (change.first != "")
|
||||
context.footnote (change.second);
|
||||
|
||||
feedback_affected (count == 1 ? STRING_CMD_STOP_1 : STRING_CMD_STOP_N, count);
|
||||
return rc;
|
||||
|
|
|
@ -67,10 +67,9 @@ int CmdSummary::execute (std::string& output)
|
|||
|
||||
// Generate unique list of project names from all pending tasks.
|
||||
std::map <std::string, bool> allProjects;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
if (showAllProjects || task->getStatus () == Task::pending)
|
||||
allProjects[task->get ("project")] = false;
|
||||
for (auto& task : filtered)
|
||||
if (showAllProjects || task.getStatus () == Task::pending)
|
||||
allProjects[task.get ("project")] = false;
|
||||
|
||||
// Initialize counts, sum.
|
||||
std::map <std::string, int> countPending;
|
||||
|
@ -80,47 +79,49 @@ int CmdSummary::execute (std::string& output)
|
|||
time_t now = time (NULL);
|
||||
|
||||
// Initialize counters.
|
||||
std::map <std::string, bool>::iterator project;
|
||||
for (project = allProjects.begin (); project != allProjects.end (); ++project)
|
||||
for (auto& project : allProjects)
|
||||
{
|
||||
countPending [project->first] = 0;
|
||||
countCompleted [project->first] = 0;
|
||||
sumEntry [project->first] = 0.0;
|
||||
counter [project->first] = 0;
|
||||
countPending [project.first] = 0;
|
||||
countCompleted [project.first] = 0;
|
||||
sumEntry [project.first] = 0.0;
|
||||
counter [project.first] = 0;
|
||||
}
|
||||
|
||||
// Count the various tasks.
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
std::string project = task->get ("project");
|
||||
std::string project = task.get ("project");
|
||||
std::vector <std::string> projects = extractParents (project);
|
||||
projects.push_back (project);
|
||||
|
||||
std::vector <std::string>::const_iterator parent;
|
||||
for (parent = projects.begin (); parent != projects.end (); ++parent)
|
||||
++counter[*parent];
|
||||
for (auto& parent : projects)
|
||||
++counter[parent];
|
||||
|
||||
if (task->getStatus () == Task::pending ||
|
||||
task->getStatus () == Task::waiting)
|
||||
for (parent = projects.begin (); parent != projects.end (); ++parent)
|
||||
if (task.getStatus () == Task::pending ||
|
||||
task.getStatus () == Task::waiting)
|
||||
{
|
||||
for (auto& parent : projects)
|
||||
{
|
||||
++countPending[*parent];
|
||||
++countPending[parent];
|
||||
|
||||
time_t entry = strtol (task->get ("entry").c_str (), NULL, 10);
|
||||
time_t entry = strtol (task.get ("entry").c_str (), NULL, 10);
|
||||
if (entry)
|
||||
sumEntry[*parent] = sumEntry[*parent] + (double) (now - entry);
|
||||
sumEntry[parent] = sumEntry[parent] + (double) (now - entry);
|
||||
}
|
||||
}
|
||||
|
||||
else if (task->getStatus () == Task::completed)
|
||||
for (parent = projects.begin (); parent != projects.end (); ++parent)
|
||||
else if (task.getStatus () == Task::completed)
|
||||
{
|
||||
for (auto& parent : projects)
|
||||
{
|
||||
++countCompleted[*parent];
|
||||
++countCompleted[parent];
|
||||
|
||||
time_t entry = strtol (task->get ("entry").c_str (), NULL, 10);
|
||||
time_t end = strtol (task->get ("end").c_str (), NULL, 10);
|
||||
time_t entry = strtol (task.get ("entry").c_str (), NULL, 10);
|
||||
time_t end = strtol (task.get ("end").c_str (), NULL, 10);
|
||||
if (entry && end)
|
||||
sumEntry[*parent] = sumEntry[*parent] + (double) (end - entry);
|
||||
sumEntry[parent] = sumEntry[parent] + (double) (end - entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create a table for output.
|
||||
|
@ -140,35 +141,33 @@ int CmdSummary::execute (std::string& output)
|
|||
|
||||
int barWidth = 30;
|
||||
std::vector <std::string> processed;
|
||||
std::map <std::string, bool>::iterator i;
|
||||
for (i = allProjects.begin (); i != allProjects.end (); ++i)
|
||||
for (auto& i : allProjects)
|
||||
{
|
||||
if (showAllProjects || countPending[i->first] > 0)
|
||||
if (showAllProjects || countPending[i.first] > 0)
|
||||
{
|
||||
const std::vector <std::string> parents = extractParents (i->first);
|
||||
std::vector <std::string>::const_iterator parent;
|
||||
for (parent = parents.begin (); parent != parents.end (); parent++)
|
||||
const std::vector <std::string> parents = extractParents (i.first);
|
||||
for (auto& parent : parents)
|
||||
{
|
||||
if (std::find (processed.begin (), processed.end (), *parent)
|
||||
if (std::find (processed.begin (), processed.end (), parent)
|
||||
== processed.end ())
|
||||
{
|
||||
int row = view.addRow ();
|
||||
view.set (row, 0, indentProject (*parent));
|
||||
processed.push_back (*parent);
|
||||
view.set (row, 0, indentProject (parent));
|
||||
processed.push_back (parent);
|
||||
}
|
||||
}
|
||||
|
||||
int row = view.addRow ();
|
||||
view.set (row, 0, (i->first == ""
|
||||
view.set (row, 0, (i.first == ""
|
||||
? STRING_CMD_SUMMARY_NONE
|
||||
: indentProject (i->first, " ", '.')));
|
||||
: indentProject (i.first, " ", '.')));
|
||||
|
||||
view.set (row, 1, countPending[i->first]);
|
||||
if (counter[i->first])
|
||||
view.set (row, 2, Duration ((int) (sumEntry[i->first] / (double)counter[i->first])).format ());
|
||||
view.set (row, 1, countPending[i.first]);
|
||||
if (counter[i.first])
|
||||
view.set (row, 2, Duration ((int) (sumEntry[i.first] / (double)counter[i.first])).format ());
|
||||
|
||||
int c = countCompleted[i->first];
|
||||
int p = countPending[i->first];
|
||||
int c = countCompleted[i.first];
|
||||
int p = countPending[i.first];
|
||||
int completedBar = 0;
|
||||
if (c + p)
|
||||
completedBar = (c * barWidth) / (c + p);
|
||||
|
@ -191,7 +190,7 @@ int CmdSummary::execute (std::string& output)
|
|||
if (c + p)
|
||||
sprintf (percent, "%d%%", 100 * c / (c + p));
|
||||
view.set (row, 3, percent);
|
||||
processed.push_back (i->first);
|
||||
processed.push_back (i.first);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,10 +57,9 @@ int CmdSync::execute (std::string& output)
|
|||
// Loog for the 'init' keyword to indicate one-time pending.data upload.
|
||||
bool first_time_init = false;
|
||||
std::vector <std::string> words = context.cli.getWords ();
|
||||
std::vector <std::string>::iterator word;
|
||||
for (word = words.begin (); word != words.end (); ++word)
|
||||
for (auto& word : words)
|
||||
{
|
||||
if (closeEnough ("initialize", *word, 4))
|
||||
if (closeEnough ("initialize", word, 4))
|
||||
{
|
||||
if (!context.config.getBoolean ("confirmation") ||
|
||||
confirm (STRING_CMD_SYNC_INIT))
|
||||
|
@ -125,24 +124,22 @@ int CmdSync::execute (std::string& output)
|
|||
// deltas is meaningless.
|
||||
context.tdb2.backlog._file.truncate ();
|
||||
|
||||
std::vector <Task> pending = context.tdb2.pending.get_tasks ();
|
||||
std::vector <Task>::iterator i;
|
||||
for (i = pending.begin (); i != pending.end (); ++i)
|
||||
auto pending = context.tdb2.pending.get_tasks ();
|
||||
for (auto& i : pending)
|
||||
{
|
||||
payload += i->composeJSON () + "\n";
|
||||
payload += i.composeJSON () + "\n";
|
||||
++upload_count;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector <std::string> lines = context.tdb2.backlog.get_lines ();
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = lines.begin (); i != lines.end (); ++i)
|
||||
for (auto& i : lines)
|
||||
{
|
||||
if ((*i)[0] == '{')
|
||||
if (i[0] == '{')
|
||||
++upload_count;
|
||||
|
||||
payload += *i + "\n";
|
||||
payload += i + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,14 +187,13 @@ int CmdSync::execute (std::string& output)
|
|||
context.tdb2.all_tasks ();
|
||||
|
||||
std::string sync_key = "";
|
||||
std::vector <std::string>::iterator line;
|
||||
for (line = lines.begin (); line != lines.end (); ++line)
|
||||
for (auto& line : lines)
|
||||
{
|
||||
if ((*line)[0] == '{')
|
||||
if (line[0] == '{')
|
||||
{
|
||||
++download_count;
|
||||
|
||||
Task from_server (*line);
|
||||
Task from_server (line);
|
||||
std::string uuid = from_server.get ("uuid");
|
||||
|
||||
// Is it a new task from the server, or an update to an existing one?
|
||||
|
@ -225,9 +221,9 @@ int CmdSync::execute (std::string& output)
|
|||
context.tdb2.add (from_server, false);
|
||||
}
|
||||
}
|
||||
else if (*line != "")
|
||||
else if (line != "")
|
||||
{
|
||||
sync_key = *line;
|
||||
sync_key = line;
|
||||
context.debug ("Sync key " + sync_key);
|
||||
}
|
||||
|
||||
|
|
|
@ -54,15 +54,11 @@ int CmdTags::execute (std::string& output)
|
|||
std::stringstream out;
|
||||
|
||||
// Get all the tasks.
|
||||
std::vector <Task> tasks = context.tdb2.pending.get_tasks ();
|
||||
auto tasks = context.tdb2.pending.get_tasks ();
|
||||
|
||||
if (context.config.getBoolean ("list.all.tags"))
|
||||
{
|
||||
std::vector <Task> extra = context.tdb2.completed.get_tasks ();
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = extra.begin (); task != extra.end (); ++task)
|
||||
tasks.push_back (*task);
|
||||
}
|
||||
for (auto& task : context.tdb2.completed.get_tasks ())
|
||||
tasks.push_back (task);
|
||||
|
||||
int quantity = tasks.size ();
|
||||
|
||||
|
@ -74,18 +70,16 @@ int CmdTags::execute (std::string& output)
|
|||
// Scan all the tasks for their project name, building a map using project
|
||||
// names as keys.
|
||||
std::map <std::string, int> unique;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
std::vector <std::string> tags;
|
||||
task->getTags (tags);
|
||||
task.getTags (tags);
|
||||
|
||||
std::vector <std::string>::iterator tag;
|
||||
for (tag = tags.begin (); tag != tags.end (); ++tag)
|
||||
if (unique.find (*tag) != unique.end ())
|
||||
unique[*tag]++;
|
||||
for (auto& tag : tags)
|
||||
if (unique.find (tag) != unique.end ())
|
||||
unique[tag]++;
|
||||
else
|
||||
unique[*tag] = 1;
|
||||
unique[tag] = 1;
|
||||
}
|
||||
|
||||
if (unique.size ())
|
||||
|
@ -101,19 +95,18 @@ int CmdTags::execute (std::string& output)
|
|||
|
||||
Color bold ("bold");
|
||||
bool special = false;
|
||||
std::map <std::string, int>::iterator i;
|
||||
for (i = unique.begin (); i != unique.end (); ++i)
|
||||
for (auto& i : unique)
|
||||
{
|
||||
// Highlight the special tags.
|
||||
special = (context.color () &&
|
||||
(i->first == "nocolor" ||
|
||||
i->first == "nonag" ||
|
||||
i->first == "nocal" ||
|
||||
i->first == "next")) ? true : false;
|
||||
(i.first == "nocolor" ||
|
||||
i.first == "nonag" ||
|
||||
i.first == "nocal" ||
|
||||
i.first == "next")) ? true : false;
|
||||
|
||||
int row = view.addRow ();
|
||||
view.set (row, 0, i->first, special ? bold : Color ());
|
||||
view.set (row, 1, i->second, special ? bold : Color ());
|
||||
view.set (row, 0, i.first, special ? bold : Color ());
|
||||
view.set (row, 1, i.second, special ? bold : Color ());
|
||||
}
|
||||
|
||||
out << optionalBlankLine ()
|
||||
|
@ -156,15 +149,11 @@ CmdCompletionTags::CmdCompletionTags ()
|
|||
int CmdCompletionTags::execute (std::string& output)
|
||||
{
|
||||
// Get all the tasks.
|
||||
std::vector <Task> tasks = context.tdb2.pending.get_tasks ();
|
||||
auto tasks = context.tdb2.pending.get_tasks ();
|
||||
|
||||
if (context.config.getBoolean ("complete.all.tags"))
|
||||
{
|
||||
std::vector <Task> extra = context.tdb2.completed.get_tasks ();
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = extra.begin (); task != extra.end (); ++task)
|
||||
tasks.push_back (*task);
|
||||
}
|
||||
for (auto& task : context.tdb2.completed.get_tasks ())
|
||||
tasks.push_back (task);
|
||||
|
||||
// Apply filter.
|
||||
Filter filter;
|
||||
|
@ -174,15 +163,13 @@ int CmdCompletionTags::execute (std::string& output)
|
|||
// Scan all the tasks for their tags, building a map using tag
|
||||
// names as keys.
|
||||
std::map <std::string, int> unique;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
std::vector <std::string> tags;
|
||||
task->getTags (tags);
|
||||
task.getTags (tags);
|
||||
|
||||
std::vector <std::string>::iterator tag;
|
||||
for (tag = tags.begin (); tag != tags.end (); ++tag)
|
||||
unique[*tag] = 0;
|
||||
for (auto& tag : tags)
|
||||
unique[tag] = 0;
|
||||
}
|
||||
|
||||
// add built-in tags to map
|
||||
|
@ -192,9 +179,8 @@ int CmdCompletionTags::execute (std::string& output)
|
|||
unique["next"] = 0;
|
||||
|
||||
std::stringstream out;
|
||||
std::map <std::string, int>::iterator it;
|
||||
for (it = unique.begin (); it != unique.end (); ++it)
|
||||
out << it->first << "\n";
|
||||
for (auto& it : unique)
|
||||
out << it.first << "\n";
|
||||
|
||||
output = out.str ();
|
||||
return 0;
|
||||
|
|
|
@ -102,43 +102,41 @@ int CmdTimesheet::execute (std::string& output)
|
|||
Color label (context.config.get ("color.label"));
|
||||
completed.colorHeader (label);
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = all.begin (); task != all.end (); ++task)
|
||||
for (auto& task : all)
|
||||
{
|
||||
// If task completed within range.
|
||||
if (task->getStatus () == Task::completed)
|
||||
if (task.getStatus () == Task::completed)
|
||||
{
|
||||
Date compDate (task->get_date ("end"));
|
||||
Date compDate (task.get_date ("end"));
|
||||
if (compDate >= start && compDate < end)
|
||||
{
|
||||
Color c;
|
||||
if (context.color ())
|
||||
autoColorize (*task, c);
|
||||
autoColorize (task, c);
|
||||
|
||||
int row = completed.addRow ();
|
||||
std::string format = context.config.get ("dateformat.report");
|
||||
if (format == "")
|
||||
format = context.config.get ("dateformat");
|
||||
completed.set (row, 1, task->get ("project"), c);
|
||||
completed.set (row, 1, task.get ("project"), c);
|
||||
|
||||
if(task->has ("due"))
|
||||
if(task.has ("due"))
|
||||
{
|
||||
Date dt (task->get_date ("due"));
|
||||
Date dt (task.get_date ("due"));
|
||||
completed.set (row, 2, dt.toString (format));
|
||||
}
|
||||
|
||||
std::string description = task->get ("description");
|
||||
std::string description = task.get ("description");
|
||||
int indent = context.config.getInteger ("indent.annotation");
|
||||
|
||||
std::map <std::string, std::string> annotations;
|
||||
task->getAnnotations (annotations);
|
||||
std::map <std::string, std::string>::iterator ann;
|
||||
for (ann = annotations.begin (); ann != annotations.end (); ++ann)
|
||||
task.getAnnotations (annotations);
|
||||
for (auto& ann : annotations)
|
||||
description += "\n"
|
||||
+ std::string (indent, ' ')
|
||||
+ Date (ann->first.substr (11)).toString (context.config.get ("dateformat"))
|
||||
+ Date (ann.first.substr (11)).toString (context.config.get ("dateformat"))
|
||||
+ " "
|
||||
+ ann->second;
|
||||
+ ann.second;
|
||||
|
||||
completed.set (row, 3, description, c);
|
||||
}
|
||||
|
@ -160,43 +158,42 @@ int CmdTimesheet::execute (std::string& output)
|
|||
started.add (Column::factory ("string", STRING_COLUMN_LABEL_DESC));
|
||||
started.colorHeader (label);
|
||||
|
||||
for (task = all.begin (); task != all.end (); ++task)
|
||||
for (auto& task : all)
|
||||
{
|
||||
// If task started within range, but not completed withing range.
|
||||
if (task->getStatus () == Task::pending &&
|
||||
task->has ("start"))
|
||||
if (task.getStatus () == Task::pending &&
|
||||
task.has ("start"))
|
||||
{
|
||||
Date startDate (task->get_date ("start"));
|
||||
Date startDate (task.get_date ("start"));
|
||||
if (startDate >= start && startDate < end)
|
||||
{
|
||||
Color c;
|
||||
if (context.color ())
|
||||
autoColorize (*task, c);
|
||||
autoColorize (task, c);
|
||||
|
||||
int row = started.addRow ();
|
||||
std::string format = context.config.get ("dateformat.report");
|
||||
if (format == "")
|
||||
format = context.config.get ("dateformat");
|
||||
started.set (row, 1, task->get ("project"), c);
|
||||
started.set (row, 1, task.get ("project"), c);
|
||||
|
||||
if(task->has ("due"))
|
||||
if (task.has ("due"))
|
||||
{
|
||||
Date dt (task->get_date ("due"));
|
||||
Date dt (task.get_date ("due"));
|
||||
started.set (row, 2, dt.toString (format));
|
||||
}
|
||||
|
||||
std::string description = task->get ("description");
|
||||
std::string description = task.get ("description");
|
||||
int indent = context.config.getInteger ("indent.annotation");
|
||||
|
||||
std::map <std::string, std::string> annotations;
|
||||
task->getAnnotations (annotations);
|
||||
std::map <std::string, std::string>::iterator ann;
|
||||
for (ann = annotations.begin (); ann != annotations.end (); ++ann)
|
||||
task.getAnnotations (annotations);
|
||||
for (auto& ann : annotations)
|
||||
description += "\n"
|
||||
+ std::string (indent, ' ')
|
||||
+ Date (ann->first.substr (11)).toString (context.config.get ("dateformat"))
|
||||
+ Date (ann.first.substr (11)).toString (context.config.get ("dateformat"))
|
||||
+ " "
|
||||
+ ann->second;
|
||||
+ ann.second;
|
||||
|
||||
started.set (row, 3, description, c);
|
||||
}
|
||||
|
|
|
@ -55,15 +55,14 @@ int CmdUDAs::execute (std::string& output)
|
|||
std::stringstream out;
|
||||
|
||||
std::vector <std::string> udas;
|
||||
Config::const_iterator name;
|
||||
for (name = context.config.begin (); name != context.config.end (); ++name)
|
||||
for (auto& name : context.config)
|
||||
{
|
||||
if (name->first.substr (0, 4) == "uda." &&
|
||||
name->first.find (".type") != std::string::npos)
|
||||
if (name.first.substr (0, 4) == "uda." &&
|
||||
name.first.find (".type") != std::string::npos)
|
||||
{
|
||||
std::string::size_type period = name->first.find ('.', 4);
|
||||
std::string::size_type period = name.first.find ('.', 4);
|
||||
if (period != std::string::npos)
|
||||
udas.push_back (name->first.substr (4, period - 4));
|
||||
udas.push_back (name.first.substr (4, period - 4));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,25 +89,23 @@ int CmdUDAs::execute (std::string& output)
|
|||
Color label (context.config.get ("color.label"));
|
||||
view.colorHeader (label);
|
||||
|
||||
std::vector <std::string>::iterator uda;
|
||||
for (uda = udas.begin (); uda != udas.end (); ++uda)
|
||||
for (auto& uda : udas)
|
||||
{
|
||||
std::string type = context.config.get ("uda." + *uda + ".type");
|
||||
std::string label = context.config.get ("uda." + *uda + ".label");
|
||||
std::string values = context.config.get ("uda." + *uda + ".values");
|
||||
std::string defval = context.config.get ("uda." + *uda + ".default");
|
||||
std::string type = context.config.get ("uda." + uda + ".type");
|
||||
std::string label = context.config.get ("uda." + uda + ".label");
|
||||
std::string values = context.config.get ("uda." + uda + ".values");
|
||||
std::string defval = context.config.get ("uda." + uda + ".default");
|
||||
if (label == "")
|
||||
label = *uda;
|
||||
label = uda;
|
||||
|
||||
// Count UDA usage by UDA.
|
||||
int count = 0;
|
||||
std::vector <Task>::iterator i;
|
||||
for (i = filtered.begin (); i != filtered.end (); ++i)
|
||||
if (i->has (*uda))
|
||||
for (auto& i : filtered)
|
||||
if (i.has (uda))
|
||||
++count;
|
||||
|
||||
int row = view.addRow ();
|
||||
view.set (row, 0, *uda);
|
||||
view.set (row, 0, uda);
|
||||
view.set (row, 1, type);
|
||||
view.set (row, 2, label);
|
||||
view.set (row, 3, values);
|
||||
|
@ -132,14 +129,12 @@ int CmdUDAs::execute (std::string& output)
|
|||
|
||||
// Orphans are task attributes that are not represented in context.columns.
|
||||
std::map <std::string, int> orphans;
|
||||
std::vector <Task>::iterator i;
|
||||
for (i = filtered.begin (); i != filtered.end (); ++i)
|
||||
for (auto& i : filtered)
|
||||
{
|
||||
std::map <std::string, std::string>::iterator att;
|
||||
for (att = i->begin (); att != i->end (); ++att)
|
||||
if (att->first.substr (0, 11) != "annotation_" &&
|
||||
context.columns.find (att->first) == context.columns.end ())
|
||||
orphans[att->first]++;
|
||||
for (auto& att : i)
|
||||
if (att.first.substr (0, 11) != "annotation_" &&
|
||||
context.columns.find (att.first) == context.columns.end ())
|
||||
orphans[att.first]++;
|
||||
}
|
||||
|
||||
if (orphans.size ())
|
||||
|
@ -153,12 +148,11 @@ int CmdUDAs::execute (std::string& output)
|
|||
Color label (context.config.get ("color.label"));
|
||||
orphanView.colorHeader (label);
|
||||
|
||||
std::map <std::string, int>::iterator o;
|
||||
for (o = orphans.begin (); o != orphans.end (); ++o)
|
||||
for (auto& o : orphans)
|
||||
{
|
||||
int row = orphanView.addRow ();
|
||||
orphanView.set (row, 0, o->first);
|
||||
orphanView.set (row, 1, o->second);
|
||||
orphanView.set (row, 0, o.first);
|
||||
orphanView.set (row, 1, o.second);
|
||||
}
|
||||
|
||||
out << optionalBlankLine ()
|
||||
|
@ -188,15 +182,14 @@ CmdCompletionUDAs::CmdCompletionUDAs ()
|
|||
int CmdCompletionUDAs::execute (std::string& output)
|
||||
{
|
||||
std::vector <std::string> udas;
|
||||
Config::const_iterator name;
|
||||
for (name = context.config.begin (); name != context.config.end (); ++name)
|
||||
for (auto& name : context.config)
|
||||
{
|
||||
if (name->first.substr (0, 4) == "uda." &&
|
||||
name->first.find (".type") != std::string::npos)
|
||||
if (name.first.substr (0, 4) == "uda." &&
|
||||
name.first.find (".type") != std::string::npos)
|
||||
{
|
||||
std::string::size_type period = name->first.find ('.', 4);
|
||||
std::string::size_type period = name.first.find ('.', 4);
|
||||
if (period != std::string::npos)
|
||||
udas.push_back (name->first.substr (4, period - 4));
|
||||
udas.push_back (name.first.substr (4, period - 4));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,9 +45,8 @@ CmdUndo::CmdUndo ()
|
|||
int CmdUndo::execute (std::string& output)
|
||||
{
|
||||
// Detect attempts to modify the task.
|
||||
std::vector <A>::iterator a;
|
||||
for (a = context.cli._args.begin (); a != context.cli._args.end (); ++a)
|
||||
if (a->hasTag ("MODIFICATION"))
|
||||
for (auto& a : context.cli._args)
|
||||
if (a.hasTag ("MODIFICATION"))
|
||||
throw std::string (STRING_CMD_UNDO_MODS);
|
||||
|
||||
context.tdb2.revert ();
|
||||
|
|
|
@ -62,20 +62,19 @@ int CmdUrgency::execute (std::string& output)
|
|||
|
||||
// Display urgency for the selected tasks.
|
||||
std::stringstream out;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
if (task->id)
|
||||
if (task.id)
|
||||
{
|
||||
out << format (STRING_CMD_URGENCY_RESULT,
|
||||
task->id, task->urgency ())
|
||||
task.id, task.urgency ())
|
||||
<< "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
out << format (STRING_CMD_URGENCY_RESULT,
|
||||
task->get ("uuid"),
|
||||
task->urgency ())
|
||||
task.get ("uuid"),
|
||||
task.urgency ())
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue