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.
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")
@@ -571,7 +571,7 @@ bool Att::match (const Att& other) const
}
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 ()));
if (other.mValue == "" || ! (variable < literal))
return false;
@@ -601,7 +601,7 @@ bool Att::match (const Att& other) const
}
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 ()));
if (! (variable > literal))
return false;

View File

@@ -371,23 +371,6 @@ void Config::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.
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
// 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)
const int Config::getInteger (const std::string& key)
{
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 ())
{
@@ -424,29 +412,9 @@ bool Config::get (const std::string& key, const bool default_value)
value == "enable" || // TODO i18n
value == "enabled") // TODO i18n
return true;
return false;
}
return default_value;
}
////////////////////////////////////////////////////////////////////////////////
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;
return false;
}
////////////////////////////////////////////////////////////////////////////////

View File

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

View File

@@ -98,11 +98,11 @@ void Context::initialize ()
{
config.set ("curses", "off");
if (! config.get (std::string ("_forcecolor"), false))
if (! config.getBoolean ("_forcecolor"))
config.set ("color", "off");
}
if (config.get ("color", true))
if (config.getBoolean ("color"))
initializeColorRules ();
// Load appropriate stringtable as soon after the config file as possible, to
@@ -154,16 +154,16 @@ int Context::run ()
}
// Dump all debug messages.
if (config.get (std::string ("debug"), false))
if (config.getBoolean ("debug"))
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;
else
std::cout << *d << std::endl;
// Dump all 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;
else
std::cout << *h << std::endl;
@@ -173,7 +173,7 @@ int Context::run ()
// Dump all 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;
else
std::cout << *f << std::endl;
@@ -268,8 +268,10 @@ void Context::shadow ()
// Run report. Use shadow.command, using default.command as a fallback
// with "list" as a default.
std::string command = config.get ("shadow.command",
config.get ("default.command", "list"));
std::string command = config.get ("shadow.command");
if (command == "")
command = config.get ("default.command");
split (args, command, ' ');
initialize ();
@@ -292,7 +294,7 @@ void Context::shadow ()
config.set ("color", oldColor);
// 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]");
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];
switch (c)
{
case 'm': sprintf (buffer, "%d", this->month ()); break;
case 'M': sprintf (buffer, "%02d", this->month ()); break;
case 'd': sprintf (buffer, "%d", this->day ()); break;
case 'D': sprintf (buffer, "%02d", this->day ()); break;
case 'y': sprintf (buffer, "%02d", this->year () % 100); break;
case 'Y': sprintf (buffer, "%d", this->year ()); break;
case 'a': sprintf (buffer, "%.3s", 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, "%.9s", Date::monthName(month()).c_str() ); break;
case 'V': sprintf (buffer, "%02d", Date::weekOfYear(Date::dayOfWeek(context.config.get ("weekstart", "Sunday")))); break;
default: sprintf (buffer, "%c", c); break;
case 'm': sprintf (buffer, "%d", this->month ()); break;
case 'M': sprintf (buffer, "%02d", this->month ()); break;
case 'd': sprintf (buffer, "%d", this->day ()); break;
case 'D': sprintf (buffer, "%02d", this->day ()); break;
case 'y': sprintf (buffer, "%02d", this->year () % 100); break;
case 'Y': sprintf (buffer, "%d", this->year ()); break;
case 'a': sprintf (buffer, "%.3s", 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, "%.9s", Date::monthName (month ()).c_str ()); break;
case 'V': sprintf (buffer, "%02d", Date::weekOfYear (Date::dayOfWeek (context.config.get ("weekstart")))); break;
default: sprintf (buffer, "%c", c); break;
}
formatted += buffer;

View File

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

View File

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

View File

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

View File

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

View File

@@ -80,7 +80,7 @@ static std::string findDate (
if (value != "")
{
Date dt (value, context.config.get ("dateformat", "m/d/Y"));
Date dt (value, context.config.get ("dateformat"));
char epoch [16];
sprintf (epoch, "%d", (int)dt.toEpoch ());
return std::string (epoch);
@@ -100,7 +100,7 @@ static std::string formatDate (
if (value.length ())
{
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;
@@ -162,7 +162,7 @@ static std::string formatTask (Task task)
foreach (anno, annotations)
{
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;
}
@@ -499,7 +499,7 @@ static void parseTask (Task& task, const std::string& after)
std::string::size_type gap = value.find (" ");
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,
// that the seconds will be different, thus unique, thus not squashed.
@@ -534,7 +534,7 @@ void editFile (Task& task)
spit (file.str (), before);
// 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");
if (editor == "" && peditor) editor = std::string (peditor);
peditor = getenv ("EDITOR");
@@ -604,7 +604,7 @@ int handleEdit (std::string &outs)
std::stringstream out;
std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true));
context.tdb.lock (context.config.getBoolean ("locking"));
handleRecurrence ();
Filter filter;
context.tdb.loadPending (tasks, filter);

View File

@@ -168,12 +168,12 @@ static void decorateTask (Task& task)
task.setStatus (Task::pending);
// 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 != "")
task.set ("project", defaultProject);
// 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") &&
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;
context.tdb.lock (context.config.get ("locking", true));
context.tdb.lock (context.config.getBoolean ("locking"));
std::vector <std::string>::const_iterator 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;
context.tdb.lock (context.config.get ("locking", true));
context.tdb.lock (context.config.getBoolean ("locking"));
std::vector <std::string>::const_iterator 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;
context.tdb.lock (context.config.get ("locking", true));
context.tdb.lock (context.config.getBoolean ("locking"));
std::vector <std::string>::const_iterator 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;
context.tdb.lock (context.config.get ("locking", true));
context.tdb.lock (context.config.getBoolean ("locking"));
std::vector <std::string>::const_iterator 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;
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;
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;
context.tdb.lock (context.config.get ("locking", true));
context.tdb.lock (context.config.getBoolean ("locking"));
// Set up mappings. Assume no fields match.
std::map <std::string, int> mapping;

View File

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

View File

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

View File

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

View File

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

View File

@@ -589,7 +589,7 @@ std::string renderAttribute (const std::string& name, const std::string& value)
if (a.type (name) == "date")
{
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;