Config - defaults

- Implemented replacement Config::get* methods.
- Replaced all calls throughout the code, with the new methods which
  have no static values as defaults.
This commit is contained in:
Paul Beckingham 2010-01-15 20:55:06 -05:00
parent 0faf7fa8ee
commit cb821c2a25
16 changed files with 234 additions and 265 deletions

View file

@ -331,7 +331,7 @@ bool Att::validNameValue (
{ {
// Validate and convert to epoch. // Validate and convert to epoch.
if (value != "") if (value != "")
value = Date (value, context.config.get ("dateformat", "m/d/Y")).toEpochString (); value = Date (value, context.config.get ("dateformat")).toEpochString ();
} }
else if (name == "recur") else if (name == "recur")
@ -571,7 +571,7 @@ bool Att::match (const Att& other) const
} }
else if (which == "date") else if (which == "date")
{ {
Date literal (mValue.c_str (), context.config.get ("dateformat", "m/d/Y")); Date literal (mValue.c_str (), context.config.get ("dateformat"));
Date variable ((time_t)atoi (other.mValue.c_str ())); Date variable ((time_t)atoi (other.mValue.c_str ()));
if (other.mValue == "" || ! (variable < literal)) if (other.mValue == "" || ! (variable < literal))
return false; return false;
@ -601,7 +601,7 @@ bool Att::match (const Att& other) const
} }
else if (which == "date") else if (which == "date")
{ {
Date literal (mValue.c_str (), context.config.get ("dateformat", "m/d/Y")); Date literal (mValue.c_str (), context.config.get ("dateformat"));
Date variable ((time_t)atoi (other.mValue.c_str ())); Date variable ((time_t)atoi (other.mValue.c_str ()));
if (! (variable > literal)) if (! (variable > literal))
return false; return false;

View file

@ -371,23 +371,6 @@ void Config::clear ()
std::map <std::string, std::string>::clear (); std::map <std::string, std::string>::clear ();
} }
////////////////////////////////////////////////////////////////////////////////
// Return the configuration value given the specified key.
const std::string Config::get (const char* key)
{
return this->get (std::string (key));
}
////////////////////////////////////////////////////////////////////////////////
// Return the configuration value given the specified key. If a default_value
// is present, it will be the returned value in the event of a missing key.
const std::string Config::get (
const char* key,
const char* default_value)
{
return this->get (std::string (key), std::string (default_value));
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Return the configuration value given the specified key. // Return the configuration value given the specified key.
const std::string Config::get (const std::string& key) const std::string Config::get (const std::string& key)
@ -396,20 +379,25 @@ const std::string Config::get (const std::string& key)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Return the configuration value given the specified key. If a default_value const int Config::getInteger (const std::string& key)
// is present, it will be the returned value in the event of a missing key.
const std::string Config::get (
const std::string& key,
const std::string& default_value)
{ {
if ((*this).find (key) != (*this).end ()) if ((*this).find (key) != (*this).end ())
return (*this)[key]; return atoi ((*this)[key].c_str ());
return default_value; return 0;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool Config::get (const std::string& key, const bool default_value) const double Config::getReal (const std::string& key)
{
if ((*this).find (key) != (*this).end ())
return atof ((*this)[key].c_str ());
return 0.0;
}
////////////////////////////////////////////////////////////////////////////////
const bool Config::getBoolean (const std::string& key)
{ {
if ((*this).find (key) != (*this).end ()) if ((*this).find (key) != (*this).end ())
{ {
@ -424,29 +412,9 @@ bool Config::get (const std::string& key, const bool default_value)
value == "enable" || // TODO i18n value == "enable" || // TODO i18n
value == "enabled") // TODO i18n value == "enabled") // TODO i18n
return true; return true;
return false;
} }
return default_value; return false;
}
////////////////////////////////////////////////////////////////////////////////
int Config::get (const std::string& key, const int default_value)
{
if ((*this).find (key) != (*this).end ())
return atoi ((*this)[key].c_str ());
return default_value;
}
////////////////////////////////////////////////////////////////////////////////
double Config::get (const std::string& key, const double default_value)
{
if ((*this).find (key) != (*this).end ())
return atof ((*this)[key].c_str ());
return default_value;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -48,21 +48,10 @@ public:
void setDefaults (); void setDefaults ();
void clear (); void clear ();
/*
const std::string get (const std::string&); const std::string get (const std::string&);
const std::string getInteger (const std::string&); const int getInteger (const std::string&);
const std::string getReal (const std::string&); const double getReal (const std::string&);
const std::string getBoolean (const std::string&); const bool getBoolean (const std::string&);
*/
// <OBSOLETE>
const std::string get (const char*);
const std::string get (const char*, const char*);
const std::string get (const std::string&);
const std::string get (const std::string&, const std::string&);
bool get (const std::string&, const bool);
int get (const std::string&, const int);
double get (const std::string&, const double);
// </OBSOLETE>
void set (const std::string&, const int); void set (const std::string&, const int);
void set (const std::string&, const double); void set (const std::string&, const double);

View file

@ -98,11 +98,11 @@ void Context::initialize ()
{ {
config.set ("curses", "off"); config.set ("curses", "off");
if (! config.get (std::string ("_forcecolor"), false)) if (! config.getBoolean ("_forcecolor"))
config.set ("color", "off"); config.set ("color", "off");
} }
if (config.get ("color", true)) if (config.getBoolean ("color"))
initializeColorRules (); initializeColorRules ();
// Load appropriate stringtable as soon after the config file as possible, to // Load appropriate stringtable as soon after the config file as possible, to
@ -154,16 +154,16 @@ int Context::run ()
} }
// Dump all debug messages. // Dump all debug messages.
if (config.get (std::string ("debug"), false)) if (config.getBoolean ("debug"))
foreach (d, debugMessages) foreach (d, debugMessages)
if (config.get ("color", true) || config.get (std::string ("_forcecolor"), false)) if (config.getBoolean ("color") || config.getBoolean ("_forcecolor"))
std::cout << colorizeDebug (*d) << std::endl; std::cout << colorizeDebug (*d) << std::endl;
else else
std::cout << *d << std::endl; std::cout << *d << std::endl;
// Dump all headers. // Dump all headers.
foreach (h, headers) foreach (h, headers)
if (config.get ("color", true) || config.get (std::string ("_forcecolor"), false)) if (config.getBoolean ("color") || config.getBoolean ("_forcecolor"))
std::cout << colorizeHeader (*h) << std::endl; std::cout << colorizeHeader (*h) << std::endl;
else else
std::cout << *h << std::endl; std::cout << *h << std::endl;
@ -173,7 +173,7 @@ int Context::run ()
// Dump all footnotes. // Dump all footnotes.
foreach (f, footnotes) foreach (f, footnotes)
if (config.get ("color", true) || config.get (std::string ("_forcecolor"), false)) if (config.getBoolean ("color") || config.getBoolean ("_forcecolor"))
std::cout << colorizeFootnote (*f) << std::endl; std::cout << colorizeFootnote (*f) << std::endl;
else else
std::cout << *f << std::endl; std::cout << *f << std::endl;
@ -268,8 +268,10 @@ void Context::shadow ()
// Run report. Use shadow.command, using default.command as a fallback // Run report. Use shadow.command, using default.command as a fallback
// with "list" as a default. // with "list" as a default.
std::string command = config.get ("shadow.command", std::string command = config.get ("shadow.command");
config.get ("default.command", "list")); if (command == "")
command = config.get ("default.command");
split (args, command, ' '); split (args, command, ' ');
initialize (); initialize ();
@ -292,7 +294,7 @@ void Context::shadow ()
config.set ("color", oldColor); config.set ("color", oldColor);
// Optionally display a notification that the shadow file was updated. // Optionally display a notification that the shadow file was updated.
if (config.get (std::string ("shadow.notify"), false)) if (config.getBoolean ("shadow.notify"))
footnote (std::string ("[Shadow file '") + shadowFile + "' updated]"); footnote (std::string ("[Shadow file '") + shadowFile + "' updated]");
inShadow = false; inShadow = false;

View file

@ -322,18 +322,18 @@ const std::string Date::toString (const std::string& format /*= "m/d/Y" */) cons
char c = localFormat[i]; char c = localFormat[i];
switch (c) switch (c)
{ {
case 'm': sprintf (buffer, "%d", this->month ()); break; case 'm': sprintf (buffer, "%d", this->month ()); break;
case 'M': sprintf (buffer, "%02d", this->month ()); break; case 'M': sprintf (buffer, "%02d", this->month ()); break;
case 'd': sprintf (buffer, "%d", this->day ()); break; case 'd': sprintf (buffer, "%d", this->day ()); break;
case 'D': sprintf (buffer, "%02d", this->day ()); break; case 'D': sprintf (buffer, "%02d", this->day ()); break;
case 'y': sprintf (buffer, "%02d", this->year () % 100); break; case 'y': sprintf (buffer, "%02d", this->year () % 100); break;
case 'Y': sprintf (buffer, "%d", this->year ()); break; case 'Y': sprintf (buffer, "%d", this->year ()); break;
case 'a': sprintf (buffer, "%.3s", Date::dayName(dayOfWeek()).c_str() ); break; case 'a': sprintf (buffer, "%.3s", Date::dayName (dayOfWeek ()).c_str ()); break;
case 'A': sprintf (buffer, "%s", Date::dayName(dayOfWeek()).c_str() ); break; case 'A': sprintf (buffer, "%s", Date::dayName (dayOfWeek ()).c_str ()); break;
case 'b': sprintf (buffer, "%.3s", Date::monthName(month()).c_str() ); break; case 'b': sprintf (buffer, "%.3s", Date::monthName (month ()).c_str ()); break;
case 'B': sprintf (buffer, "%.9s", Date::monthName(month()).c_str() ); break; case 'B': sprintf (buffer, "%.9s", Date::monthName (month ()).c_str ()); break;
case 'V': sprintf (buffer, "%02d", Date::weekOfYear(Date::dayOfWeek(context.config.get ("weekstart", "Sunday")))); break; case 'V': sprintf (buffer, "%02d", Date::weekOfYear (Date::dayOfWeek (context.config.get ("weekstart")))); break;
default: sprintf (buffer, "%c", c); break; default: sprintf (buffer, "%c", c); break;
} }
formatted += buffer; formatted += buffer;

View file

@ -40,7 +40,7 @@ Permission::Permission ()
, quit (false) , quit (false)
{ {
// Turning confirmations off is the same as entering "all". // Turning confirmations off is the same as entering "all".
if (context.config.get ("confirmation", true) == false) if (context.config.getBoolean ("confirmation") == false)
allConfirmed = true; allConfirmed = true;
} }

View file

@ -881,10 +881,12 @@ void Table::sort (std::vector <int>& order)
else else
{ {
Date dl ((std::string)*left, context.config.get("reportdateformat", std::string format = context.config.get ("reportdateformat");
context.config.get("dateformat","m/d/Y"))); if (format == "")
Date dr ((std::string)*right, context.config.get("reportdateformat", format = context.config.get ("dateformat");
context.config.get("dateformat","m/d/Y")));
Date dl ((std::string)*left, format);
Date dr ((std::string)*right, format);
if (dl > dr) if (dl > dr)
SWAP SWAP
} }
@ -901,10 +903,12 @@ void Table::sort (std::vector <int>& order)
else else
{ {
Date dl ((std::string)*left, context.config.get("reportdateformat", std::string format = context.config.get ("reportdateformat");
context.config.get("dateformat","m/d/Y"))); if (format == "")
Date dr ((std::string)*right, context.config.get("reportdateformat", format = context.config.get ("dateformat");
context.config.get("dateformat","m/d/Y")));
Date dl ((std::string)*left, format);
Date dr ((std::string)*right, format);
if (dl < dr) if (dl < dr)
SWAP SWAP
} }

View file

@ -70,12 +70,12 @@ int handleAdd (std::string &outs)
// Override with default.project, if not specified. // Override with default.project, if not specified.
if (context.task.get ("project") == "") if (context.task.get ("project") == "")
context.task.set ("project", context.config.get ("default.project", "")); context.task.set ("project", context.config.get ("default.project"));
// Override with default.priority, if not specified. // Override with default.priority, if not specified.
if (context.task.get ("priority") == "") if (context.task.get ("priority") == "")
{ {
std::string defaultPriority = context.config.get ("default.priority", ""); std::string defaultPriority = context.config.get ("default.priority");
if (Att::validNameValue ("priority", "", defaultPriority)) if (Att::validNameValue ("priority", "", defaultPriority))
context.task.set ("priority", defaultPriority); context.task.set ("priority", defaultPriority);
} }
@ -96,7 +96,7 @@ int handleAdd (std::string &outs)
// Only valid tasks can be added. // Only valid tasks can be added.
context.task.validate (); context.task.validate ();
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
context.tdb.add (context.task); context.tdb.add (context.task);
#ifdef FEATURE_NEW_ID #ifdef FEATURE_NEW_ID
@ -123,7 +123,7 @@ int handleProjects (std::string &outs)
context.filter.push_back (Att ("status", "pending")); context.filter.push_back (Att ("status", "pending"));
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
int quantity = context.tdb.loadPending (tasks, context.filter); int quantity = context.tdb.loadPending (tasks, context.filter);
context.tdb.commit (); context.tdb.commit ();
context.tdb.unlock (); context.tdb.unlock ();
@ -161,8 +161,8 @@ int handleProjects (std::string &outs)
table.addColumn ("Pri:M"); table.addColumn ("Pri:M");
table.addColumn ("Pri:H"); table.addColumn ("Pri:H");
if (context.config.get ("color", true) || if (context.config.getBoolean ("color") ||
context.config.get (std::string ("_forcecolor"), false)) context.config.getBoolean ("_forcecolor"))
{ {
table.setColumnUnderline (0); table.setColumnUnderline (0);
table.setColumnUnderline (1); table.setColumnUnderline (1);
@ -211,10 +211,10 @@ int handleProjects (std::string &outs)
int handleCompletionProjects (std::string &outs) int handleCompletionProjects (std::string &outs)
{ {
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter; Filter filter;
if (context.config.get (std::string ("complete.all.projects"), false)) if (context.config.getBoolean ("complete.all.projects"))
context.tdb.load (tasks, filter); context.tdb.load (tasks, filter);
else else
context.tdb.loadPending (tasks, filter); context.tdb.loadPending (tasks, filter);
@ -246,7 +246,7 @@ int handleTags (std::string &outs)
context.filter.push_back (Att ("status", "pending")); context.filter.push_back (Att ("status", "pending"));
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
int quantity = context.tdb.loadPending (tasks, context.filter); int quantity = context.tdb.loadPending (tasks, context.filter);
context.tdb.commit (); context.tdb.commit ();
context.tdb.unlock (); context.tdb.unlock ();
@ -273,8 +273,8 @@ int handleTags (std::string &outs)
table.addColumn ("Tag"); table.addColumn ("Tag");
table.addColumn ("Count"); table.addColumn ("Count");
if (context.config.get ("color", true) || if (context.config.getBoolean ("color") ||
context.config.get (std::string ("_forcecolor"), false)) context.config.getBoolean ("_forcecolor"))
{ {
table.setColumnUnderline (0); table.setColumnUnderline (0);
table.setColumnUnderline (1); table.setColumnUnderline (1);
@ -312,10 +312,10 @@ int handleTags (std::string &outs)
int handleCompletionTags (std::string &outs) int handleCompletionTags (std::string &outs)
{ {
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter; Filter filter;
if (context.config.get (std::string ("complete.all.tags"), false)) if (context.config.getBoolean ("complete.all.tags"))
context.tdb.load (tasks, filter); context.tdb.load (tasks, filter);
else else
context.tdb.loadPending (tasks, filter); context.tdb.loadPending (tasks, filter);
@ -387,7 +387,7 @@ int handleCompletionVersion (std::string &outs)
int handleCompletionIDs (std::string &outs) int handleCompletionIDs (std::string &outs)
{ {
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter; Filter filter;
context.tdb.loadPending (tasks, filter); context.tdb.loadPending (tasks, filter);
context.tdb.commit (); context.tdb.commit ();
@ -414,7 +414,7 @@ void handleUndo ()
{ {
context.disallowModification (); context.disallowModification ();
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
context.tdb.undo (); context.tdb.undo ();
context.tdb.unlock (); context.tdb.unlock ();
} }
@ -449,11 +449,11 @@ int handleVersion (std::string &outs)
Color bold ("bold"); Color bold ("bold");
out << std::endl out << std::endl
<< ((context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) << ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor"))
? bold.colorize (PACKAGE) ? bold.colorize (PACKAGE)
: PACKAGE) : PACKAGE)
<< " " << " "
<< ((context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) << ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor"))
? bold.colorize (VERSION) ? bold.colorize (VERSION)
: VERSION) : VERSION)
<< " built for " << " built for "
@ -512,11 +512,11 @@ int handleConfig (std::string &outs)
// Create a table for output. // Create a table for output.
Table table; Table table;
table.setTableWidth (width); table.setTableWidth (width);
table.setDateFormat (context.config.get ("dateformat", "m/d/Y")); table.setDateFormat (context.config.get ("dateformat"));
table.addColumn ("Config variable"); table.addColumn ("Config variable");
table.addColumn ("Value"); table.addColumn ("Value");
if (context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor"))
{ {
table.setColumnUnderline (0); table.setColumnUnderline (0);
table.setColumnUnderline (1); table.setColumnUnderline (1);
@ -643,7 +643,7 @@ int handleDelete (std::string &outs)
context.disallowModification (); context.disallowModification ();
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter; Filter filter;
context.tdb.loadPending (tasks, filter); context.tdb.loadPending (tasks, filter);
@ -664,7 +664,7 @@ int handleDelete (std::string &outs)
<< task->get ("description") << task->get ("description")
<< "'?"; << "'?";
if (!context.config.get (std::string ("confirmation"), false) || confirm (question.str ())) if (!context.config.getBoolean ("confirmation") || confirm (question.str ()))
{ {
// Check for the more complex case of a recurring task. If this is a // Check for the more complex case of a recurring task. If this is a
// recurring task, get confirmation to delete them all. // recurring task, get confirmation to delete them all.
@ -684,7 +684,7 @@ int handleDelete (std::string &outs)
sibling->set ("end", endTime); sibling->set ("end", endTime);
context.tdb.update (*sibling); context.tdb.update (*sibling);
if (context.config.get ("echo.command", true)) if (context.config.getBoolean ("echo.command"))
out << "Deleting recurring task " out << "Deleting recurring task "
<< sibling->id << sibling->id
<< " '" << " '"
@ -717,7 +717,7 @@ int handleDelete (std::string &outs)
task->set ("end", endTime); task->set ("end", endTime);
context.tdb.update (*task); context.tdb.update (*task);
if (context.config.get ("echo.command", true)) if (context.config.getBoolean ("echo.command"))
out << "Deleting task " out << "Deleting task "
<< task->id << task->id
<< " '" << " '"
@ -748,7 +748,7 @@ int handleStart (std::string &outs)
context.disallowModification (); context.disallowModification ();
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter; Filter filter;
context.tdb.loadPending (tasks, filter); context.tdb.loadPending (tasks, filter);
@ -766,7 +766,7 @@ int handleStart (std::string &outs)
context.tdb.update (*task); context.tdb.update (*task);
if (context.config.get ("echo.command", true)) if (context.config.getBoolean ("echo.command"))
out << "Started " out << "Started "
<< task->id << task->id
<< " '" << " '"
@ -804,7 +804,7 @@ int handleStop (std::string &outs)
context.disallowModification (); context.disallowModification ();
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter; Filter filter;
context.tdb.loadPending (tasks, filter); context.tdb.loadPending (tasks, filter);
@ -818,7 +818,7 @@ int handleStop (std::string &outs)
task->remove ("start"); task->remove ("start");
context.tdb.update (*task); context.tdb.update (*task);
if (context.config.get ("echo.command", true)) if (context.config.getBoolean ("echo.command"))
out << "Stopped " out << "Stopped "
<< task->id << task->id
<< " '" << " '"
@ -853,7 +853,7 @@ int handleDone (std::string &outs)
std::stringstream out; std::stringstream out;
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter; Filter filter;
context.tdb.loadPending (tasks, filter); context.tdb.loadPending (tasks, filter);
@ -862,7 +862,7 @@ int handleDone (std::string &outs)
context.filter.applySequence (tasks, context.sequence); context.filter.applySequence (tasks, context.sequence);
Permission permission; Permission permission;
if (context.sequence.size () > (size_t) context.config.get ("bulk", 2)) if (context.sequence.size () > (size_t) context.config.getInteger ("bulk"))
permission.bigSequence (); permission.bigSequence ();
bool nagged = false; bool nagged = false;
@ -894,7 +894,7 @@ int handleDone (std::string &outs)
{ {
context.tdb.update (*task); context.tdb.update (*task);
if (context.config.get ("echo.command", true)) if (context.config.getBoolean ("echo.command"))
out << "Completed " out << "Completed "
<< task->id << task->id
<< " '" << " '"
@ -923,7 +923,7 @@ int handleDone (std::string &outs)
context.tdb.commit (); context.tdb.commit ();
context.tdb.unlock (); context.tdb.unlock ();
if (context.config.get ("echo.command", true)) if (context.config.getBoolean ("echo.command"))
out << "Marked " out << "Marked "
<< count << count
<< " task" << " task"
@ -960,7 +960,7 @@ int handleExport (std::string &outs)
// Get all the tasks. // Get all the tasks.
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
handleRecurrence (); handleRecurrence ();
context.tdb.load (tasks, context.filter); context.tdb.load (tasks, context.filter);
context.tdb.commit (); context.tdb.commit ();
@ -986,7 +986,7 @@ int handleModify (std::string &outs)
std::stringstream out; std::stringstream out;
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter; Filter filter;
context.tdb.loadPending (tasks, filter); context.tdb.loadPending (tasks, filter);
@ -995,7 +995,7 @@ int handleModify (std::string &outs)
context.filter.applySequence (tasks, context.sequence); context.filter.applySequence (tasks, context.sequence);
Permission permission; Permission permission;
if (context.sequence.size () > (size_t) context.config.get ("bulk", 2)) if (context.sequence.size () > (size_t) context.config.getInteger ("bulk"))
permission.bigSequence (); permission.bigSequence ();
foreach (task, tasks) foreach (task, tasks)
@ -1066,7 +1066,7 @@ int handleModify (std::string &outs)
context.tdb.commit (); context.tdb.commit ();
context.tdb.unlock (); context.tdb.unlock ();
if (context.config.get ("echo.command", true)) if (context.config.getBoolean ("echo.command"))
out << "Modified " << count << " task" << (count == 1 ? "" : "s") << std::endl; out << "Modified " << count << " task" << (count == 1 ? "" : "s") << std::endl;
outs = out.str (); outs = out.str ();
@ -1080,7 +1080,7 @@ int handleAppend (std::string &outs)
std::stringstream out; std::stringstream out;
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter; Filter filter;
context.tdb.loadPending (tasks, filter); context.tdb.loadPending (tasks, filter);
@ -1089,7 +1089,7 @@ int handleAppend (std::string &outs)
context.filter.applySequence (tasks, context.sequence); context.filter.applySequence (tasks, context.sequence);
Permission permission; Permission permission;
if (context.sequence.size () > (size_t) context.config.get ("bulk", 2)) if (context.sequence.size () > (size_t) context.config.getInteger ("bulk"))
permission.bigSequence (); permission.bigSequence ();
foreach (task, tasks) foreach (task, tasks)
@ -1117,7 +1117,7 @@ int handleAppend (std::string &outs)
{ {
context.tdb.update (*other); context.tdb.update (*other);
if (context.config.get ("echo.command", true)) if (context.config.getBoolean ("echo.command"))
out << "Appended '" out << "Appended '"
<< context.task.get ("description") << context.task.get ("description")
<< "' to task " << "' to task "
@ -1134,7 +1134,7 @@ int handleAppend (std::string &outs)
context.tdb.commit (); context.tdb.commit ();
context.tdb.unlock (); context.tdb.unlock ();
if (context.config.get ("echo.command", true)) if (context.config.getBoolean ("echo.command"))
out << "Appended " << count << " task" << (count == 1 ? "" : "s") << std::endl; out << "Appended " << count << " task" << (count == 1 ? "" : "s") << std::endl;
outs = out.str (); outs = out.str ();
@ -1148,7 +1148,7 @@ int handlePrepend (std::string &outs)
std::stringstream out; std::stringstream out;
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter; Filter filter;
context.tdb.loadPending (tasks, filter); context.tdb.loadPending (tasks, filter);
@ -1157,7 +1157,7 @@ int handlePrepend (std::string &outs)
context.filter.applySequence (tasks, context.sequence); context.filter.applySequence (tasks, context.sequence);
Permission permission; Permission permission;
if (context.sequence.size () > (size_t) context.config.get ("bulk", 2)) if (context.sequence.size () > (size_t) context.config.getInteger ("bulk"))
permission.bigSequence (); permission.bigSequence ();
foreach (task, tasks) foreach (task, tasks)
@ -1185,7 +1185,7 @@ int handlePrepend (std::string &outs)
{ {
context.tdb.update (*other); context.tdb.update (*other);
if (context.config.get ("echo.command", true)) if (context.config.getBoolean ("echo.command"))
out << "Prepended '" out << "Prepended '"
<< context.task.get ("description") << context.task.get ("description")
<< "' to task " << "' to task "
@ -1202,7 +1202,7 @@ int handlePrepend (std::string &outs)
context.tdb.commit (); context.tdb.commit ();
context.tdb.unlock (); context.tdb.unlock ();
if (context.config.get ("echo.command", true)) if (context.config.getBoolean ("echo.command"))
out << "Prepended " << count << " task" << (count == 1 ? "" : "s") << std::endl; out << "Prepended " << count << " task" << (count == 1 ? "" : "s") << std::endl;
outs = out.str (); outs = out.str ();
@ -1216,7 +1216,7 @@ int handleDuplicate (std::string &outs)
int count = 0; int count = 0;
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter; Filter filter;
context.tdb.loadPending (tasks, filter); context.tdb.loadPending (tasks, filter);
@ -1259,7 +1259,7 @@ int handleDuplicate (std::string &outs)
context.tdb.add (dup); context.tdb.add (dup);
if (context.config.get ("echo.command", true)) if (context.config.getBoolean ("echo.command"))
out << "Duplicated " out << "Duplicated "
<< task->id << task->id
<< " '" << " '"
@ -1269,7 +1269,7 @@ int handleDuplicate (std::string &outs)
++count; ++count;
} }
if (context.config.get ("echo.command", true)) if (context.config.getBoolean ("echo.command"))
{ {
out << "Duplicated " << count << " task" << (count == 1 ? "" : "s") << std::endl; out << "Duplicated " << count << " task" << (count == 1 ? "" : "s") << std::endl;
#ifdef FEATURE_NEW_ID #ifdef FEATURE_NEW_ID
@ -1294,7 +1294,7 @@ void handleShell ()
{ {
// Display some kind of welcome message. // Display some kind of welcome message.
Color bold (Color::nocolor, Color::nocolor, false, true, false); Color bold (Color::nocolor, Color::nocolor, false, true, false);
std::cout << ((context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) std::cout << ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor"))
? bold.colorize (PACKAGE_STRING) ? bold.colorize (PACKAGE_STRING)
: PACKAGE_STRING) : PACKAGE_STRING)
<< " shell" << " shell"
@ -1318,7 +1318,7 @@ void handleShell ()
do do
{ {
std::cout << context.config.get ("shell.prompt", "task>") << " "; std::cout << context.config.get ("shell.prompt") << " ";
command = ""; command = "";
std::getline (std::cin, command); std::getline (std::cin, command);
@ -1370,7 +1370,7 @@ int handleColor (std::string &outs)
int rc = 0; int rc = 0;
std::stringstream out; std::stringstream out;
if (context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor"))
{ {
// If there is something in the description, then assume that is a color, // If there is something in the description, then assume that is a color,
// and display it as a sample. // and display it as a sample.
@ -1515,7 +1515,7 @@ int handleAnnotate (std::string &outs)
std::stringstream out; std::stringstream out;
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter; Filter filter;
context.tdb.loadPending (tasks, filter); context.tdb.loadPending (tasks, filter);
@ -1523,7 +1523,7 @@ int handleAnnotate (std::string &outs)
context.filter.applySequence (tasks, context.sequence); context.filter.applySequence (tasks, context.sequence);
Permission permission; Permission permission;
if (context.sequence.size () > (size_t) context.config.get ("bulk", 2)) if (context.sequence.size () > (size_t) context.config.getInteger ("bulk"))
permission.bigSequence (); permission.bigSequence ();
foreach (task, tasks) foreach (task, tasks)
@ -1537,7 +1537,7 @@ int handleAnnotate (std::string &outs)
{ {
context.tdb.update (*task); context.tdb.update (*task);
if (context.config.get ("echo.command", true)) if (context.config.getBoolean ("echo.command"))
out << "Annotated " out << "Annotated "
<< task->id << task->id
<< " with '" << " with '"

View file

@ -82,7 +82,7 @@ int handleCustomReport (const std::string& report, std::string &outs)
// Get all the tasks. // Get all the tasks.
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
handleRecurrence (); handleRecurrence ();
context.tdb.load (tasks, context.filter); context.tdb.load (tasks, context.filter);
context.tdb.commit (); context.tdb.commit ();
@ -161,7 +161,7 @@ int runCustomReport (
Table table; Table table;
table.setTableWidth (context.getWidth ()); table.setTableWidth (context.getWidth ());
table.setDateFormat (context.config.get ("dateformat", "m/d/Y")); table.setDateFormat (context.config.get ("dateformat"));
foreach (task, tasks) foreach (task, tasks)
table.addRow (); table.addRow ();
@ -251,7 +251,7 @@ int runCustomReport (
if (entered.length ()) if (entered.length ())
{ {
Date dt (::atoi (entered.c_str ())); Date dt (::atoi (entered.c_str ()));
entered = dt.toString (context.config.get ("dateformat", "m/d/Y")); entered = dt.toString (context.config.get ("dateformat"));
table.addCell (row, columnCount, entered); table.addCell (row, columnCount, entered);
} }
} }
@ -270,7 +270,7 @@ int runCustomReport (
if (entered.length ()) if (entered.length ())
{ {
Date dt (::atoi (entered.c_str ())); Date dt (::atoi (entered.c_str ()));
entered = dt.toStringWithTime (context.config.get ("dateformat", "m/d/Y")); entered = dt.toStringWithTime (context.config.get ("dateformat"));
table.addCell (row, columnCount, entered); table.addCell (row, columnCount, entered);
} }
} }
@ -289,7 +289,7 @@ int runCustomReport (
if (started.length ()) if (started.length ())
{ {
Date dt (::atoi (started.c_str ())); Date dt (::atoi (started.c_str ()));
started = dt.toString (context.config.get ("dateformat", "m/d/Y")); started = dt.toString (context.config.get ("dateformat"));
table.addCell (row, columnCount, started); table.addCell (row, columnCount, started);
} }
} }
@ -308,7 +308,7 @@ int runCustomReport (
if (started.length ()) if (started.length ())
{ {
Date dt (::atoi (started.c_str ())); Date dt (::atoi (started.c_str ()));
started = dt.toStringWithTime (context.config.get ("dateformat", "m/d/Y")); started = dt.toStringWithTime (context.config.get ("dateformat"));
table.addCell (row, columnCount, started); table.addCell (row, columnCount, started);
} }
} }
@ -327,7 +327,7 @@ int runCustomReport (
if (started.length ()) if (started.length ())
{ {
Date dt (::atoi (started.c_str ())); Date dt (::atoi (started.c_str ()));
started = dt.toString (context.config.get ("dateformat", "m/d/Y")); started = dt.toString (context.config.get ("dateformat"));
table.addCell (row, columnCount, started); table.addCell (row, columnCount, started);
} }
} }
@ -339,6 +339,8 @@ int runCustomReport (
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
std::string format = context.config.get ("dateformat");
std::string started; std::string started;
for (unsigned int row = 0; row < tasks.size(); ++row) for (unsigned int row = 0; row < tasks.size(); ++row)
{ {
@ -346,7 +348,7 @@ int runCustomReport (
if (started.length ()) if (started.length ())
{ {
Date dt (::atoi (started.c_str ())); Date dt (::atoi (started.c_str ()));
started = dt.toStringWithTime (context.config.get ("dateformat", "m/d/Y")); started = dt.toStringWithTime (format);
table.addCell (row, columnCount, started); table.addCell (row, columnCount, started);
} }
} }
@ -358,13 +360,14 @@ int runCustomReport (
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::left); table.setColumnJustification (columnCount, Table::left);
std::string format = context.config.get ("reportdateformat");
if (format == "")
format = context.config.get ("dateformat");
int row = 0; int row = 0;
std::string due; std::string due;
foreach (task, tasks) foreach (task, tasks)
table.addCell (row++, columnCount, table.addCell (row++, columnCount, getDueDate (*task, format));
getDueDate (*task,
context.config.get ("reportdateformat",
context.config.get ("dateformat", "m/d/Y"))));
dueColumn = columnCount; dueColumn = columnCount;
} }
@ -511,7 +514,7 @@ int runCustomReport (
if (wait != "") if (wait != "")
{ {
Date dt (::atoi (wait.c_str ())); Date dt (::atoi (wait.c_str ()));
wait = dt.toString (context.config.get ("dateformat", "m/d/Y")); wait = dt.toString (context.config.get ("dateformat"));
table.addCell (row++, columnCount, wait); table.addCell (row++, columnCount, wait);
} }
} }
@ -519,8 +522,8 @@ int runCustomReport (
// Common to all columns. // Common to all columns.
// Add underline. // Add underline.
if ((context.config.get (std::string ("color"), true) || context.config.get (std::string ("_forcecolor"), false)) && if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) &&
context.config.get (std::string ("fontunderline"), "true")) context.config.getBoolean ("fontunderline"))
table.setColumnUnderline (columnCount); table.setColumnUnderline (columnCount);
else else
table.setTableDashedUnderline (); table.setTableDashedUnderline ();
@ -581,8 +584,8 @@ int runCustomReport (
// Now auto colorize all rows. // Now auto colorize all rows.
std::string due; std::string due;
Color color_due (context.config.get ("color.due", "green")); Color color_due (context.config.get ("color.due"));
Color color_overdue (context.config.get ("color.overdue", "red")); Color color_overdue (context.config.get ("color.overdue"));
bool imminent; bool imminent;
bool overdue; bool overdue;
@ -602,7 +605,7 @@ int runCustomReport (
} }
} }
if (context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor"))
{ {
Color c (tasks[row].get ("fg") + " " + tasks[row].get ("bg")); Color c (tasks[row].get ("fg") + " " + tasks[row].get ("bg"));
autoColorize (tasks[row], c); autoColorize (tasks[row], c);
@ -617,15 +620,15 @@ int runCustomReport (
} }
// If an alternating row color is specified, notify the table. // If an alternating row color is specified, notify the table.
if (context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor"))
{ {
Color alternate (context.config.get ("color.alternate", "")); Color alternate (context.config.get ("color.alternate"));
if (alternate.nontrivial ()) if (alternate.nontrivial ())
table.setTableAlternateColor (alternate); table.setTableAlternateColor (alternate);
} }
// Limit the number of rows according to the report definition. // Limit the number of rows according to the report definition.
int maximum = context.config.get (std::string ("report.") + report + ".limit", (int)0); int maximum = context.config.getInteger (std::string ("report.") + report + ".limit");
// If the custom report has a defined limit, then allow a numeric override. // If the custom report has a defined limit, then allow a numeric override.
// This is an integer specified as a filter (limit:10). // This is an integer specified as a filter (limit:10).

View file

@ -80,7 +80,7 @@ static std::string findDate (
if (value != "") if (value != "")
{ {
Date dt (value, context.config.get ("dateformat", "m/d/Y")); Date dt (value, context.config.get ("dateformat"));
char epoch [16]; char epoch [16];
sprintf (epoch, "%d", (int)dt.toEpoch ()); sprintf (epoch, "%d", (int)dt.toEpoch ());
return std::string (epoch); return std::string (epoch);
@ -100,7 +100,7 @@ static std::string formatDate (
if (value.length ()) if (value.length ())
{ {
Date dt (::atoi (value.c_str ())); Date dt (::atoi (value.c_str ()));
value = dt.toString (context.config.get ("dateformat", "m/d/Y")); value = dt.toString (context.config.get ("dateformat"));
} }
return value; return value;
@ -162,7 +162,7 @@ static std::string formatTask (Task task)
foreach (anno, annotations) foreach (anno, annotations)
{ {
Date dt (::atoi (anno->name ().substr (11).c_str ())); Date dt (::atoi (anno->name ().substr (11).c_str ()));
before << " Annotation: " << dt.toString (context.config.get ("dateformat", "m/d/Y")) before << " Annotation: " << dt.toString (context.config.get ("dateformat"))
<< " " << anno->value () << std::endl; << " " << anno->value () << std::endl;
} }
@ -499,7 +499,7 @@ static void parseTask (Task& task, const std::string& after)
std::string::size_type gap = value.find (" "); std::string::size_type gap = value.find (" ");
if (gap != std::string::npos) if (gap != std::string::npos)
{ {
Date when (value.substr (0, gap), context.config.get ("dateformat", "m/d/Y")); Date when (value.substr (0, gap), context.config.get ("dateformat"));
// This guarantees that if more than one annotation has the same date, // This guarantees that if more than one annotation has the same date,
// that the seconds will be different, thus unique, thus not squashed. // that the seconds will be different, thus unique, thus not squashed.
@ -534,7 +534,7 @@ void editFile (Task& task)
spit (file.str (), before); spit (file.str (), before);
// Determine correct editor: .taskrc:editor > $VISUAL > $EDITOR > vi // Determine correct editor: .taskrc:editor > $VISUAL > $EDITOR > vi
std::string editor = context.config.get ("editor", ""); std::string editor = context.config.get ("editor");
char* peditor = getenv ("VISUAL"); char* peditor = getenv ("VISUAL");
if (editor == "" && peditor) editor = std::string (peditor); if (editor == "" && peditor) editor = std::string (peditor);
peditor = getenv ("EDITOR"); peditor = getenv ("EDITOR");
@ -604,7 +604,7 @@ int handleEdit (std::string &outs)
std::stringstream out; std::stringstream out;
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
handleRecurrence (); handleRecurrence ();
Filter filter; Filter filter;
context.tdb.loadPending (tasks, filter); context.tdb.loadPending (tasks, filter);

View file

@ -168,12 +168,12 @@ static void decorateTask (Task& task)
task.setStatus (Task::pending); task.setStatus (Task::pending);
// Override with default.project, if not specified. // Override with default.project, if not specified.
std::string defaultProject = context.config.get ("default.project", ""); std::string defaultProject = context.config.get ("default.project");
if (!task.has ("project") && defaultProject != "") if (!task.has ("project") && defaultProject != "")
task.set ("project", defaultProject); task.set ("project", defaultProject);
// Override with default.priority, if not specified. // Override with default.priority, if not specified.
std::string defaultPriority = context.config.get ("default.priority", ""); std::string defaultPriority = context.config.get ("default.priority");
if (!task.has ("priority") && if (!task.has ("priority") &&
defaultPriority != "" && defaultPriority != "" &&
Att::validNameValue ("priority", "", defaultPriority)) Att::validNameValue ("priority", "", defaultPriority))
@ -185,7 +185,7 @@ static std::string importTask_1_4_3 (const std::vector <std::string>& lines)
{ {
std::vector <std::string> failed; std::vector <std::string> failed;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
std::vector <std::string>::const_iterator it; std::vector <std::string>::const_iterator it;
for (it = lines.begin (); it != lines.end (); ++it) for (it = lines.begin (); it != lines.end (); ++it)
@ -342,7 +342,7 @@ static std::string importTask_1_5_0 (const std::vector <std::string>& lines)
{ {
std::vector <std::string> failed; std::vector <std::string> failed;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
std::vector <std::string>::const_iterator it; std::vector <std::string>::const_iterator it;
for (it = lines.begin (); it != lines.end (); ++it) for (it = lines.begin (); it != lines.end (); ++it)
@ -504,7 +504,7 @@ static std::string importTask_1_6_0 (const std::vector <std::string>& lines)
{ {
std::vector <std::string> failed; std::vector <std::string> failed;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
std::vector <std::string>::const_iterator it; std::vector <std::string>::const_iterator it;
for (it = lines.begin (); it != lines.end (); ++it) for (it = lines.begin (); it != lines.end (); ++it)
@ -715,7 +715,7 @@ static std::string importTodoSh_2_0 (const std::vector <std::string>& lines)
{ {
std::vector <std::string> failed; std::vector <std::string> failed;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
std::vector <std::string>::const_iterator it; std::vector <std::string>::const_iterator it;
for (it = lines.begin (); it != lines.end (); ++it) for (it = lines.begin (); it != lines.end (); ++it)
@ -840,7 +840,7 @@ static std::string importText (const std::vector <std::string>& lines)
std::vector <std::string> failed; std::vector <std::string> failed;
int count = 0; int count = 0;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
std::vector <std::string>::const_iterator it; std::vector <std::string>::const_iterator it;
for (it = lines.begin (); it != lines.end (); ++it) for (it = lines.begin (); it != lines.end (); ++it)
@ -904,7 +904,7 @@ static std::string importCSV (const std::vector <std::string>& lines)
{ {
std::vector <std::string> failed; std::vector <std::string> failed;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
// Set up mappings. Assume no fields match. // Set up mappings. Assume no fields match.
std::map <std::string, int> mapping; std::map <std::string, int> mapping;

View file

@ -137,10 +137,10 @@ int Context::interactive ()
int Context::getWidth () int Context::getWidth ()
{ {
// Determine window size, and set table accordingly. // Determine window size, and set table accordingly.
int width = config.get ("defaultwidth", (int) 80); int width = config.getInteger ("defaultwidth");
#ifdef HAVE_LIBNCURSES #ifdef HAVE_LIBNCURSES
if (config.get ("curses", true)) if (config.getBoolean ("curses"))
{ {
#ifdef FEATURE_NCURSES_COLS #ifdef FEATURE_NCURSES_COLS
initscr (); initscr ();

View file

@ -390,7 +390,7 @@ int getDueState (const std::string& due)
if (dt < thisDay) if (dt < thisDay)
return 2; return 2;
int imminentperiod = context.config.get ("due", 7); int imminentperiod = context.config.getInteger ("due");
if (imminentperiod == 0) if (imminentperiod == 0)
return 1; return 1;
@ -406,7 +406,7 @@ int getDueState (const std::string& due)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool nag (Task& task) bool nag (Task& task)
{ {
std::string nagMessage = context.config.get ("nag", ""); std::string nagMessage = context.config.get ("nag");
if (nagMessage != "") if (nagMessage != "")
{ {
// Load all pending tasks. // Load all pending tasks.

View file

@ -66,7 +66,7 @@ int shortUsage (std::string &outs)
table.setColumnWidth (1, Table::minimum); table.setColumnWidth (1, Table::minimum);
table.setColumnWidth (2, Table::flexible); table.setColumnWidth (2, Table::flexible);
table.setTableWidth (context.getWidth ()); table.setTableWidth (context.getWidth ());
table.setDateFormat (context.config.get ("dateformat", "m/d/Y")); table.setDateFormat (context.config.get ("dateformat"));
int row = table.addRow (); int row = table.addRow ();
table.addCell (row, 0, "Usage:"); table.addCell (row, 0, "Usage:");
@ -199,8 +199,9 @@ int shortUsage (std::string &outs)
foreach (report, all) foreach (report, all)
{ {
std::string command = std::string ("task ") + *report + std::string (" [tags] [attrs] desc..."); std::string command = std::string ("task ") + *report + std::string (" [tags] [attrs] desc...");
std::string description = context.config.get ( std::string description = context.config.get (std::string ("report.") + *report + ".description");
std::string ("report.") + *report + ".description", std::string ("(missing description)")); if (description == "")
description = "(missing description)";
row = table.addRow (); row = table.addRow ();
table.addCell (row, 1, command); table.addCell (row, 1, command);
@ -300,7 +301,7 @@ int handleInfo (std::string &outs)
int rc = 0; int rc = 0;
// Get all the tasks. // Get all the tasks.
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
handleRecurrence (); handleRecurrence ();
context.tdb.loadPending (tasks, context.filter); context.tdb.loadPending (tasks, context.filter);
context.tdb.commit (); context.tdb.commit ();
@ -315,13 +316,13 @@ int handleInfo (std::string &outs)
{ {
Table table; Table table;
table.setTableWidth (context.getWidth ()); table.setTableWidth (context.getWidth ());
table.setDateFormat (context.config.get ("dateformat", "m/d/Y")); table.setDateFormat (context.config.get ("dateformat"));
table.addColumn ("Name"); table.addColumn ("Name");
table.addColumn ("Value"); table.addColumn ("Value");
if ((context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) && if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) &&
context.config.get (std::string ("fontunderline"), "true")) context.config.getBoolean ("fontunderline"))
{ {
table.setColumnUnderline (0); table.setColumnUnderline (0);
table.setColumnUnderline (1); table.setColumnUnderline (1);
@ -412,20 +413,24 @@ int handleInfo (std::string &outs)
table.addCell (row, 0, "Due"); table.addCell (row, 0, "Due");
Date dt (atoi (task->get ("due").c_str ())); Date dt (atoi (task->get ("due").c_str ()));
std::string due = getDueDate (*task, context.config.get("reportdateformat", context.config.get("dateformat","m/d/Y"))); std::string format = context.config.get ("reportdateformat");
if (format == "")
format = context.config.get ("dateformat");
std::string due = getDueDate (*task, format);
table.addCell (row, 1, due); table.addCell (row, 1, due);
overdue = (dt < now) ? true : false; overdue = (dt < now) ? true : false;
int imminentperiod = context.config.get ("due", 7); int imminentperiod = context.config.getInteger ("due");
Date imminentDay = now + imminentperiod * 86400; Date imminentDay = now + imminentperiod * 86400;
imminent = dt < imminentDay ? true : false; imminent = dt < imminentDay ? true : false;
if (context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor"))
{ {
if (overdue) if (overdue)
table.setCellColor (row, 1, Color (context.config.get ("color.overdue", "red"))); table.setCellColor (row, 1, Color (context.config.get ("color.overdue")));
else if (imminent) else if (imminent)
table.setCellColor (row, 1, Color (context.config.get ("color.due", "green"))); table.setCellColor (row, 1, Color (context.config.get ("color.due")));
} }
} }
@ -435,7 +440,7 @@ int handleInfo (std::string &outs)
row = table.addRow (); row = table.addRow ();
table.addCell (row, 0, "Waiting until"); table.addCell (row, 0, "Waiting until");
Date dt (atoi (task->get ("wait").c_str ())); Date dt (atoi (task->get ("wait").c_str ()));
table.addCell (row, 1, dt.toString (context.config.get ("dateformat", "m/d/Y"))); table.addCell (row, 1, dt.toString (context.config.get ("dateformat")));
} }
// start // start
@ -444,7 +449,7 @@ int handleInfo (std::string &outs)
row = table.addRow (); row = table.addRow ();
table.addCell (row, 0, "Start"); table.addCell (row, 0, "Start");
Date dt (atoi (task->get ("start").c_str ())); Date dt (atoi (task->get ("start").c_str ()));
table.addCell (row, 1, dt.toString (context.config.get ("dateformat", "m/d/Y"))); table.addCell (row, 1, dt.toString (context.config.get ("dateformat")));
} }
// end // end
@ -453,7 +458,7 @@ int handleInfo (std::string &outs)
row = table.addRow (); row = table.addRow ();
table.addCell (row, 0, "End"); table.addCell (row, 0, "End");
Date dt (atoi (task->get ("end").c_str ())); Date dt (atoi (task->get ("end").c_str ()));
table.addCell (row, 1, dt.toString (context.config.get ("dateformat", "m/d/Y"))); table.addCell (row, 1, dt.toString (context.config.get ("dateformat")));
} }
// tags ... // tags ...
@ -478,7 +483,7 @@ int handleInfo (std::string &outs)
row = table.addRow (); row = table.addRow ();
table.addCell (row, 0, "Entered"); table.addCell (row, 0, "Entered");
Date dt (atoi (task->get ("entry").c_str ())); Date dt (atoi (task->get ("entry").c_str ()));
std::string entry = dt.toString (context.config.get ("dateformat", "m/d/Y")); std::string entry = dt.toString (context.config.get ("dateformat"));
std::string age; std::string age;
std::string created = task->get ("entry"); std::string created = task->get ("entry");
@ -531,7 +536,7 @@ int handleReportSummary (std::string &outs)
int rc = 0; int rc = 0;
// Scan the pending tasks. // Scan the pending tasks.
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
handleRecurrence (); handleRecurrence ();
context.tdb.load (tasks, context.filter); context.tdb.load (tasks, context.filter);
context.tdb.commit (); context.tdb.commit ();
@ -594,8 +599,8 @@ int handleReportSummary (std::string &outs)
table.addColumn ("Complete"); table.addColumn ("Complete");
table.addColumn ("0% 100%"); table.addColumn ("0% 100%");
if ((context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) && if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) &&
context.config.get (std::string ("fontunderline"), "true")) context.config.getBoolean ("fontunderline"))
{ {
table.setColumnUnderline (0); table.setColumnUnderline (0);
table.setColumnUnderline (1); table.setColumnUnderline (1);
@ -610,7 +615,7 @@ int handleReportSummary (std::string &outs)
table.setColumnJustification (3, Table::right); table.setColumnJustification (3, Table::right);
table.sortOn (0, Table::ascendingCharacter); table.sortOn (0, Table::ascendingCharacter);
table.setDateFormat (context.config.get ("dateformat", "m/d/Y")); table.setDateFormat (context.config.get ("dateformat"));
int barWidth = 30; int barWidth = 30;
foreach (i, allProjects) foreach (i, allProjects)
@ -632,7 +637,7 @@ int handleReportSummary (std::string &outs)
int completedBar = (c * barWidth) / (c + p); int completedBar = (c * barWidth) / (c + p);
std::string bar; std::string bar;
if (context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor"))
{ {
bar = "\033[42m"; bar = "\033[42m";
for (int b = 0; b < completedBar; ++b) for (int b = 0; b < completedBar; ++b)
@ -726,7 +731,7 @@ int handleReportNext (std::string &outs)
// Get all the tasks. // Get all the tasks.
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
handleRecurrence (); handleRecurrence ();
context.tdb.load (tasks, context.filter); context.tdb.load (tasks, context.filter);
context.tdb.commit (); context.tdb.commit ();
@ -778,7 +783,7 @@ int handleReportHistory (std::string &outs)
// Scan the pending tasks. // Scan the pending tasks.
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
handleRecurrence (); handleRecurrence ();
context.tdb.load (tasks, context.filter); context.tdb.load (tasks, context.filter);
context.tdb.commit (); context.tdb.commit ();
@ -822,7 +827,7 @@ int handleReportHistory (std::string &outs)
// Now build the table. // Now build the table.
Table table; Table table;
table.setDateFormat (context.config.get ("dateformat", "m/d/Y")); table.setDateFormat (context.config.get ("dateformat"));
table.addColumn ("Year"); table.addColumn ("Year");
table.addColumn ("Month"); table.addColumn ("Month");
table.addColumn ("Added"); table.addColumn ("Added");
@ -830,8 +835,8 @@ int handleReportHistory (std::string &outs)
table.addColumn ("Deleted"); table.addColumn ("Deleted");
table.addColumn ("Net"); table.addColumn ("Net");
if ((context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) && if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) &&
context.config.get (std::string ("fontunderline"), "true")) context.config.getBoolean ("fontunderline"))
{ {
table.setColumnUnderline (0); table.setColumnUnderline (0);
table.setColumnUnderline (1); table.setColumnUnderline (1);
@ -894,7 +899,7 @@ int handleReportHistory (std::string &outs)
} }
table.addCell (row, 5, net); table.addCell (row, 5, net);
if ((context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) && net) if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && net)
table.setCellColor (row, 5, net > 0 ? Color (Color::red) : table.setCellColor (row, 5, net > 0 ? Color (Color::red) :
Color (Color::green)); Color (Color::green));
} }
@ -905,7 +910,7 @@ int handleReportHistory (std::string &outs)
row = table.addRow (); row = table.addRow ();
table.addCell (row, 1, "Average"); table.addCell (row, 1, "Average");
if (context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor"))
table.setRowColor (row, Color (Color::nocolor, Color::nocolor, false, true, false)); table.setRowColor (row, Color (Color::nocolor, Color::nocolor, false, true, false));
table.addCell (row, 2, totalAdded / (table.rowCount () - 2)); table.addCell (row, 2, totalAdded / (table.rowCount () - 2));
table.addCell (row, 3, totalCompleted / (table.rowCount () - 2)); table.addCell (row, 3, totalCompleted / (table.rowCount () - 2));
@ -938,7 +943,7 @@ int handleReportGHistory (std::string &outs)
// Scan the pending tasks. // Scan the pending tasks.
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
handleRecurrence (); handleRecurrence ();
context.tdb.load (tasks, context.filter); context.tdb.load (tasks, context.filter);
context.tdb.commit (); context.tdb.commit ();
@ -984,13 +989,13 @@ int handleReportGHistory (std::string &outs)
// Now build the table. // Now build the table.
Table table; Table table;
table.setDateFormat (context.config.get ("dateformat", "m/d/Y")); table.setDateFormat (context.config.get ("dateformat"));
table.addColumn ("Year"); table.addColumn ("Year");
table.addColumn ("Month"); table.addColumn ("Month");
table.addColumn ("Number Added/Completed/Deleted"); table.addColumn ("Number Added/Completed/Deleted");
if ((context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) && if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) &&
context.config.get (std::string ("fontunderline"), "true")) context.config.getBoolean ("fontunderline"))
{ {
table.setColumnUnderline (0); table.setColumnUnderline (0);
table.setColumnUnderline (1); table.setColumnUnderline (1);
@ -1049,7 +1054,7 @@ int handleReportGHistory (std::string &outs)
unsigned int deletedBar = (widthOfBar * deletedGroup[i->first]) / maxLine; unsigned int deletedBar = (widthOfBar * deletedGroup[i->first]) / maxLine;
std::string bar = ""; std::string bar = "";
if (context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor"))
{ {
char number[24]; char number[24];
std::string aBar = ""; std::string aBar = "";
@ -1109,7 +1114,7 @@ int handleReportGHistory (std::string &outs)
<< table.render () << table.render ()
<< std::endl; << std::endl;
if (context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor"))
out << "Legend: " out << "Legend: "
<< color_added.colorize ("added") << color_added.colorize ("added")
<< ", " << ", "
@ -1135,7 +1140,7 @@ int handleReportTimesheet (std::string &outs)
{ {
// Scan the pending tasks. // Scan the pending tasks.
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
handleRecurrence (); handleRecurrence ();
context.tdb.load (tasks, context.filter); context.tdb.load (tasks, context.filter);
context.tdb.commit (); context.tdb.commit ();
@ -1145,7 +1150,7 @@ int handleReportTimesheet (std::string &outs)
int width = context.getWidth (); int width = context.getWidth ();
// What day of the week does the user consider the first? // What day of the week does the user consider the first?
int weekStart = Date::dayOfWeek (context.config.get ("weekstart", "Sunday")); int weekStart = Date::dayOfWeek (context.config.get ("weekstart"));
if (weekStart != 0 && weekStart != 1) if (weekStart != 0 && weekStart != 1)
throw std::string ("The 'weekstart' configuration variable may " throw std::string ("The 'weekstart' configuration variable may "
"only contain 'Sunday' or 'Monday'."); "only contain 'Sunday' or 'Monday'.");
@ -1164,7 +1169,7 @@ int handleReportTimesheet (std::string &outs)
if (context.sequence.size () == 1) if (context.sequence.size () == 1)
quantity = context.sequence[0]; quantity = context.sequence[0];
bool color = context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false); bool color = context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor");
std::stringstream out; std::stringstream out;
for (int week = 0; week < quantity; ++week) for (int week = 0; week < quantity; ++week)
@ -1172,9 +1177,9 @@ int handleReportTimesheet (std::string &outs)
Date endString (end); Date endString (end);
endString -= 86400; endString -= 86400;
std::string title = start.toString (context.config.get ("dateformat", "m/d/Y")) std::string title = start.toString (context.config.get ("dateformat"))
+ " - " + " - "
+ endString.toString (context.config.get ("dateformat", "m/d/Y")); + endString.toString (context.config.get ("dateformat"));
Color bold (Color::nocolor, Color::nocolor, false, true, false); Color bold (Color::nocolor, Color::nocolor, false, true, false);
out << std::endl out << std::endl
@ -1189,7 +1194,7 @@ int handleReportTimesheet (std::string &outs)
completed.addColumn ("Due"); completed.addColumn ("Due");
completed.addColumn ("Description"); completed.addColumn ("Description");
if (color && context.config.get (std::string ("fontunderline"), "true")) if (color && context.config.getBoolean ("fontunderline"))
{ {
completed.setColumnUnderline (1); completed.setColumnUnderline (1);
completed.setColumnUnderline (2); completed.setColumnUnderline (2);
@ -1218,7 +1223,7 @@ int handleReportTimesheet (std::string &outs)
{ {
int row = completed.addRow (); int row = completed.addRow ();
completed.addCell (row, 1, task->get ("project")); completed.addCell (row, 1, task->get ("project"));
completed.addCell (row, 2, getDueDate (*task,context.config.get("dateformat","m/d/Y"))); completed.addCell (row, 2, getDueDate (*task, context.config.get("dateformat")));
completed.addCell (row, 3, getFullDescription (*task)); completed.addCell (row, 3, getFullDescription (*task));
if (color) if (color)
@ -1245,7 +1250,7 @@ int handleReportTimesheet (std::string &outs)
started.addColumn ("Due"); started.addColumn ("Due");
started.addColumn ("Description"); started.addColumn ("Description");
if (color && context.config.get (std::string ("fontunderline"), "true")) if (color && context.config.getBoolean ("fontunderline"))
{ {
completed.setColumnUnderline (1); completed.setColumnUnderline (1);
completed.setColumnUnderline (2); completed.setColumnUnderline (2);
@ -1274,7 +1279,7 @@ int handleReportTimesheet (std::string &outs)
{ {
int row = started.addRow (); int row = started.addRow ();
started.addCell (row, 1, task->get ("project")); started.addCell (row, 1, task->get ("project"));
started.addCell (row, 2, getDueDate (*task,context.config.get("dateformat","m/d/Y"))); started.addCell (row, 2, getDueDate (*task, context.config.get ("dateformat")));
started.addCell (row, 3, getFullDescription (*task)); started.addCell (row, 3, getFullDescription (*task));
if (color) if (color)
@ -1312,10 +1317,10 @@ std::string renderMonths (
int monthsPerLine) int monthsPerLine)
{ {
Table table; Table table;
table.setDateFormat (context.config.get ("dateformat", "m/d/Y")); table.setDateFormat (context.config.get ("dateformat"));
// What day of the week does the user consider the first? // What day of the week does the user consider the first?
int weekStart = Date::dayOfWeek (context.config.get ("weekstart", "Sunday")); int weekStart = Date::dayOfWeek (context.config.get ("weekstart"));
if (weekStart != 0 && weekStart != 1) if (weekStart != 0 && weekStart != 1)
throw std::string ("The 'weekstart' configuration variable may " throw std::string ("The 'weekstart' configuration variable may "
"only contain 'Sunday' or 'Monday'."); "only contain 'Sunday' or 'Monday'.");
@ -1346,8 +1351,8 @@ std::string renderMonths (
table.addColumn ("Sa"); table.addColumn ("Sa");
} }
if ((context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) && if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) &&
context.config.get (std::string ("fontunderline"), "true")) context.config.getBoolean ("fontunderline"))
{ {
table.setColumnUnderline (i + 1); table.setColumnUnderline (i + 1);
table.setColumnUnderline (i + 2); table.setColumnUnderline (i + 2);
@ -1418,7 +1423,7 @@ std::string renderMonths (
int dow = temp.dayOfWeek (); int dow = temp.dayOfWeek ();
int woy = temp.weekOfYear (weekStart); int woy = temp.weekOfYear (weekStart);
if (context.config.get ("displayweeknumber", true)) if (context.config.getBoolean ("displayweeknumber"))
table.addCell (row, (8 * mpl), woy); table.addCell (row, (8 * mpl), woy);
// Calculate column id. // Calculate column id.
@ -1431,12 +1436,12 @@ std::string renderMonths (
table.addCell (row, thisCol, d); table.addCell (row, thisCol, d);
Color color_today (context.config.get ("color.calendar.today", "black on cyan")); Color color_today (context.config.get ("color.calendar.today"));
Color color_due (context.config.get ("color.calendar.due", "black on green")); Color color_due (context.config.get ("color.calendar.due"));
Color color_overdue (context.config.get ("color.calendar.overdue", "black on red")); Color color_overdue (context.config.get ("color.calendar.overdue"));
Color color_weekend (context.config.get ("color.calendar.weekend", "black on white")); Color color_weekend (context.config.get ("color.calendar.weekend"));
if (context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor"))
{ {
if (dow == 0 || dow == 6) if (dow == 0 || dow == 6)
table.setCellColor (row, thisCol, color_weekend); table.setCellColor (row, thisCol, color_weekend);
@ -1454,7 +1459,7 @@ std::string renderMonths (
{ {
Date due (atoi (task->get ("due").c_str ())); Date due (atoi (task->get ("due").c_str ()));
if ((context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) && if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) &&
due.day () == d && due.day () == d &&
due.month () == months[mpl] && due.month () == months[mpl] &&
due.year () == years[mpl]) due.year () == years[mpl])
@ -1480,7 +1485,7 @@ int handleReportCalendar (std::string &outs)
// Each month requires 28 text columns width. See how many will actually // Each month requires 28 text columns width. See how many will actually
// fit. But if a preference is specified, and it fits, use it. // fit. But if a preference is specified, and it fits, use it.
int width = context.getWidth (); int width = context.getWidth ();
int preferredMonthsPerLine = (context.config.get (std::string ("monthsperline"), 0)); int preferredMonthsPerLine = (context.config.getInteger ("monthsperline"));
int monthsThatFit = width / 26; int monthsThatFit = width / 26;
int monthsPerLine = monthsThatFit; int monthsPerLine = monthsThatFit;
@ -1490,7 +1495,7 @@ int handleReportCalendar (std::string &outs)
// Get all the tasks. // Get all the tasks.
std::vector <Task> tasks; std::vector <Task> tasks;
Filter filter; Filter filter;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
handleRecurrence (); handleRecurrence ();
context.tdb.loadPending (tasks, filter); context.tdb.loadPending (tasks, filter);
context.tdb.commit (); context.tdb.commit ();
@ -1640,12 +1645,12 @@ int handleReportCalendar (std::string &outs)
} }
} }
Color color_today (context.config.get ("color.calendar.today", "black on cyan")); Color color_today (context.config.get ("color.calendar.today"));
Color color_due (context.config.get ("color.calendar.due", "black on green")); Color color_due (context.config.get ("color.calendar.due"));
Color color_overdue (context.config.get ("color.calendar.overdue", "black on red")); Color color_overdue (context.config.get ("color.calendar.overdue"));
Color color_weekend (context.config.get ("color.calendar.weekend", "black on white")); Color color_weekend (context.config.get ("color.calendar.weekend"));
if (context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor"))
out << "Legend: " out << "Legend: "
<< color_today.colorize ("today") << color_today.colorize ("today")
<< ", " << ", "
@ -1658,7 +1663,7 @@ int handleReportCalendar (std::string &outs)
<< optionalBlankLine () << optionalBlankLine ()
<< std::endl; << std::endl;
if (context.config.get (std::string ("calendar.details"), false)) if (context.config.getBoolean ("calendar.details"))
{ {
--details_mFrom; --details_mFrom;
if (details_mFrom == 0) if (details_mFrom == 0)
@ -1676,12 +1681,12 @@ int handleReportCalendar (std::string &outs)
} }
Date date_after (details_mFrom, details_dFrom, details_yFrom); Date date_after (details_mFrom, details_dFrom, details_yFrom);
std::string after = date_after.toString (context.config.get ("dateformat", "m/d/Y")); std::string after = date_after.toString (context.config.get ("dateformat"));
Date date_before (mTo, 1, yTo);
std::string before = date_before.toString (context.config.get ("dateformat", "m/d/Y"));
std::string report = context.config.get ("calendar.details.report", "list"); Date date_before (mTo, 1, yTo);
std::string before = date_before.toString (context.config.get ("dateformat"));
std::string report = context.config.get ("calendar.details.report");
std::string report_filter = context.config.get ("report." + report + ".filter"); std::string report_filter = context.config.get ("report." + report + ".filter");
report_filter += " due.after:" + after + " due.before:" + before; report_filter += " due.after:" + after + " due.before:" + before;
@ -1734,7 +1739,7 @@ int handleReportStats (std::string &outs)
// Get all the tasks. // Get all the tasks.
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.getBoolean ("locking"));
handleRecurrence (); handleRecurrence ();
context.tdb.load (tasks, context.filter); context.tdb.load (tasks, context.filter);
context.tdb.commit (); context.tdb.commit ();
@ -1801,12 +1806,12 @@ int handleReportStats (std::string &outs)
Table table; Table table;
table.setTableWidth (context.getWidth ()); table.setTableWidth (context.getWidth ());
table.setTableIntraPadding (2); table.setTableIntraPadding (2);
table.setDateFormat (context.config.get ("dateformat", "m/d/Y")); table.setDateFormat (context.config.get ("dateformat"));
table.addColumn ("Category"); table.addColumn ("Category");
table.addColumn ("Data"); table.addColumn ("Data");
if ((context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) && if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) &&
context.config.get (std::string ("fontunderline"), "true")) context.config.getBoolean ("fontunderline"))
{ {
table.setColumnUnderline (0); table.setColumnUnderline (0);
table.setColumnUnderline (1); table.setColumnUnderline (1);
@ -1879,12 +1884,12 @@ int handleReportStats (std::string &outs)
Date e (earliest); Date e (earliest);
row = table.addRow (); row = table.addRow ();
table.addCell (row, 0, "Oldest task"); table.addCell (row, 0, "Oldest task");
table.addCell (row, 1, e.toString (context.config.get ("dateformat", "m/d/Y"))); table.addCell (row, 1, e.toString (context.config.get ("dateformat")));
Date l (latest); Date l (latest);
row = table.addRow (); row = table.addRow ();
table.addCell (row, 0, "Newest task"); table.addCell (row, 0, "Newest task");
table.addCell (row, 1, l.toString (context.config.get ("dateformat", "m/d/Y"))); table.addCell (row, 1, l.toString (context.config.get ("dateformat")));
row = table.addRow (); row = table.addRow ();
table.addCell (row, 0, "Task used for"); table.addCell (row, 0, "Task used for");
@ -1946,7 +1951,7 @@ void gatherNextTasks (std::vector <Task>& tasks)
Date now; Date now;
// How many items per project? Default 2. // How many items per project? Default 2.
int limit = context.config.get ("next", 2); int limit = context.config.getInteger ("next");
// due:< 1wk, pri:* // due:< 1wk, pri:*
foreach (task, tasks) foreach (task, tasks)
@ -2115,7 +2120,7 @@ std::string getFullDescription (Task& task)
task.getAnnotations (annotations); task.getAnnotations (annotations);
if (annotations.size () != 0) if (annotations.size () != 0)
switch (context.config.get("annotation.details",2)) switch (context.config.getInteger ("annotation.details"))
{ {
case 0: case 0:
desc = "+" + desc; desc = "+" + desc;
@ -2126,7 +2131,7 @@ std::string getFullDescription (Task& task)
desc = "+" + desc; desc = "+" + desc;
Att anno (annotations.back()); Att anno (annotations.back());
Date dt (atoi (anno.name ().substr (11).c_str ())); Date dt (atoi (anno.name ().substr (11).c_str ()));
std::string when = dt.toString (context.config.get ("dateformat", "m/d/Y")); std::string when = dt.toString (context.config.get ("dateformat"));
desc += "\n" + when + " " + anno.value (); desc += "\n" + when + " " + anno.value ();
} }
break; break;
@ -2134,7 +2139,7 @@ std::string getFullDescription (Task& task)
foreach (anno, annotations) foreach (anno, annotations)
{ {
Date dt (atoi (anno->name ().substr (11).c_str ())); Date dt (atoi (anno->name ().substr (11).c_str ()));
std::string when = dt.toString (context.config.get ("dateformat", "m/d/Y")); std::string when = dt.toString (context.config.get ("dateformat"));
desc += "\n" + when + " " + anno->value (); desc += "\n" + when + " " + anno->value ();
} }
break; break;
@ -2151,8 +2156,6 @@ std::string getDueDate (Task& task, const std::string& format)
{ {
Date d (atoi (due.c_str ())); Date d (atoi (due.c_str ()));
due = d.toString (format); due = d.toString (format);
//due = d.toString (context.config.get ("dateformat", "m/d/Y"));
//due = d.toString (context.config.get ("reportdateformat", context.config.get ("dateformat", "m/d/Y")));
} }
return due; return due;

View file

@ -352,7 +352,7 @@ std::string ucFirst (const std::string& input)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
const char* optionalBlankLine () const char* optionalBlankLine ()
{ {
if (context.config.get ("blanklines", true) == true) // no i18n if (context.config.getBoolean ("blanklines") == true) // no i18n
return newline; return newline;
return noline; return noline;

View file

@ -589,7 +589,7 @@ std::string renderAttribute (const std::string& name, const std::string& value)
if (a.type (name) == "date") if (a.type (name) == "date")
{ {
Date d ((time_t)::atoi (value.c_str ())); Date d ((time_t)::atoi (value.c_str ()));
return d.toString (context.config.get ("dateformat", "m/d/Y")); return d.toString (context.config.get ("dateformat"));
} }
return value; return value;