Enhancements - rules.cpp

- Converted rules.cpp to work under 1.8.0.
- Relocated validReportColumns, validSortColumns to parse.cpp.
This commit is contained in:
Paul Beckingham 2009-06-11 20:35:58 -04:00
parent ac9dae9af8
commit 66011acbf8
5 changed files with 91 additions and 92 deletions

View file

@ -42,6 +42,8 @@ bool validPriority (const std::string&);
bool validDate (std::string&); bool validDate (std::string&);
bool validDuration (std::string&); bool validDuration (std::string&);
bool validDescription (const std::string&); bool validDescription (const std::string&);
void validReportColumns (const std::vector <std::string>&);
void validSortColumns (const std::vector <std::string>&, const std::vector <std::string>&);
// task.cpp // task.cpp
void gatherNextTasks (/*const TDB&,*/ T&, std::vector <T>&, std::vector <int>&); void gatherNextTasks (/*const TDB&,*/ T&, std::vector <T>&, std::vector <int>&);
@ -101,14 +103,11 @@ std::string handleReportActive ();
std::string handleReportOverdue (); std::string handleReportOverdue ();
std::string handleReportStats (); std::string handleReportStats ();
std::string handleReportTimesheet (); std::string handleReportTimesheet ();
std::string handleCustomReport (const std::string&); std::string handleCustomReport (const std::string&);
void validReportColumns (const std::vector <std::string>&);
void validSortColumns (const std::vector <std::string>&, const std::vector <std::string>&);
// rules.cpp // rules.cpp
void initializeColorRules (); void initializeColorRules ();
void autoColorize (T&, Text::color&, Text::color&); void autoColorize (Task&, Text::color&, Text::color&);
// import.cpp // import.cpp
std::string handleImport (); std::string handleImport ();

View file

@ -424,6 +424,7 @@ bool validDuration (std::string& input)
// | \d+ "-" \d+ ; // | \d+ "-" \d+ ;
// //
// description (whatever isn't one of the above) // description (whatever isn't one of the above)
/*
void parse ( void parse (
std::vector <std::string>& args, std::vector <std::string>& args,
std::string& command, std::string& command,
@ -552,6 +553,66 @@ void parse (
if (validDescription (descCandidate)) if (validDescription (descCandidate))
task.setDescription (descCandidate); task.setDescription (descCandidate);
} }
*/
////////////////////////////////////////////////////////////////////////////////
void validReportColumns (const std::vector <std::string>& columns)
{
std::vector <std::string> bad;
std::vector <std::string>::const_iterator it;
for (it = columns.begin (); it != columns.end (); ++it)
if (*it != "id" &&
*it != "uuid" &&
*it != "project" &&
*it != "priority" &&
*it != "entry" &&
*it != "start" &&
*it != "due" &&
*it != "age" &&
*it != "age_compact" &&
*it != "active" &&
*it != "tags" &&
*it != "recur" &&
*it != "recurrence_indicator" &&
*it != "tag_indicator" &&
*it != "description_only" &&
*it != "description")
bad.push_back (*it);
if (bad.size ())
{
std::string error;
join (error, ", ", bad);
throw std::string ("Unrecognized column name: ") + error;
}
}
////////////////////////////////////////////////////////////////////////////////
void validSortColumns (
const std::vector <std::string>& columns,
const std::vector <std::string>& sortColumns)
{
std::vector <std::string> bad;
std::vector <std::string>::const_iterator sc;
for (sc = sortColumns.begin (); sc != sortColumns.end (); ++sc)
{
std::vector <std::string>::const_iterator co;
for (co = columns.begin (); co != columns.end (); ++co)
if (sc->substr (0, sc->length () - 1) == *co)
break;
if (co == columns.end ())
bad.push_back (*sc);
}
if (bad.size ())
{
std::string error;
join (error, ", ", bad);
throw std::string ("Sort column is not part of the report: ") + error;
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -390,7 +390,7 @@ int getDueState (const std::string& due)
if (dt < midnight) if (dt < midnight)
return 2; return 2;
Date nextweek = midnight + 7 * 86400; Date nextweek = midnight + context.config.get ("due", 7) * 86400;
if (dt < nextweek) if (dt < nextweek)
return 1; return 1;
} }

View file

@ -3034,63 +3034,4 @@ std::string handleCustomReport (const std::string& report)
return out.str (); return out.str ();
} }
//////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void validReportColumns (const std::vector <std::string>& columns)
{
std::vector <std::string> bad;
std::vector <std::string>::const_iterator it;
for (it = columns.begin (); it != columns.end (); ++it)
if (*it != "id" &&
*it != "uuid" &&
*it != "project" &&
*it != "priority" &&
*it != "entry" &&
*it != "start" &&
*it != "due" &&
*it != "age" &&
*it != "age_compact" &&
*it != "active" &&
*it != "tags" &&
*it != "recur" &&
*it != "recurrence_indicator" &&
*it != "tag_indicator" &&
*it != "description_only" &&
*it != "description")
bad.push_back (*it);
if (bad.size ())
{
std::string error;
join (error, ", ", bad);
throw std::string ("Unrecognized column name: ") + error;
}
}
////////////////////////////////////////////////////////////////////////////////
void validSortColumns (
const std::vector <std::string>& columns,
const std::vector <std::string>& sortColumns)
{
std::vector <std::string> bad;
std::vector <std::string>::const_iterator sc;
for (sc = sortColumns.begin (); sc != sortColumns.end (); ++sc)
{
std::vector <std::string>::const_iterator co;
for (co = columns.begin (); co != columns.end (); ++co)
if (sc->substr (0, sc->length () - 1) == *co)
break;
if (co == columns.end ())
bad.push_back (*sc);
}
if (bad.size ())
{
std::string error;
join (error, ", ", bad);
throw std::string ("Sort column is not part of the report: ") + error;
}
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -32,6 +32,7 @@
#include "T.h" #include "T.h"
#include "text.h" #include "text.h"
#include "util.h" #include "util.h"
#include "main.h"
extern Context context; extern Context context;
@ -84,7 +85,7 @@ void initializeColorRules ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void autoColorize ( void autoColorize (
T& task, Task& task,
Text::color& fg, Text::color& fg,
Text::color& bg) Text::color& bg)
{ {
@ -95,9 +96,7 @@ void autoColorize (
if (gsFg["color.tagged"] != Text::nocolor || if (gsFg["color.tagged"] != Text::nocolor ||
gsBg["color.tagged"] != Text::nocolor) gsBg["color.tagged"] != Text::nocolor)
{ {
std::vector <std::string> tags; if (task.getTagCount ())
task.getTags (tags);
if (tags.size ())
{ {
fg = gsFg["color.tagged"]; fg = gsFg["color.tagged"];
bg = gsBg["color.tagged"]; bg = gsBg["color.tagged"];
@ -108,7 +107,7 @@ void autoColorize (
if (gsFg["color.pri.L"] != Text::nocolor || if (gsFg["color.pri.L"] != Text::nocolor ||
gsBg["color.pri.L"] != Text::nocolor) gsBg["color.pri.L"] != Text::nocolor)
{ {
if (task.getAttribute ("priority") == "L") if (task.get ("priority") == "L")
{ {
fg = gsFg["color.pri.L"]; fg = gsFg["color.pri.L"];
bg = gsBg["color.pri.L"]; bg = gsBg["color.pri.L"];
@ -119,7 +118,7 @@ void autoColorize (
if (gsFg["color.pri.M"] != Text::nocolor || if (gsFg["color.pri.M"] != Text::nocolor ||
gsBg["color.pri.M"] != Text::nocolor) gsBg["color.pri.M"] != Text::nocolor)
{ {
if (task.getAttribute ("priority") == "M") if (task.get ("priority") == "M")
{ {
fg = gsFg["color.pri.M"]; fg = gsFg["color.pri.M"];
bg = gsBg["color.pri.M"]; bg = gsBg["color.pri.M"];
@ -130,7 +129,7 @@ void autoColorize (
if (gsFg["color.pri.H"] != Text::nocolor || if (gsFg["color.pri.H"] != Text::nocolor ||
gsBg["color.pri.H"] != Text::nocolor) gsBg["color.pri.H"] != Text::nocolor)
{ {
if (task.getAttribute ("priority") == "H") if (task.get ("priority") == "H")
{ {
fg = gsFg["color.pri.H"]; fg = gsFg["color.pri.H"];
bg = gsBg["color.pri.H"]; bg = gsBg["color.pri.H"];
@ -141,7 +140,7 @@ void autoColorize (
if (gsFg["color.pri.none"] != Text::nocolor || if (gsFg["color.pri.none"] != Text::nocolor ||
gsBg["color.pri.none"] != Text::nocolor) gsBg["color.pri.none"] != Text::nocolor)
{ {
if (task.getAttribute ("priority") == "") if (task.get ("priority") == "")
{ {
fg = gsFg["color.pri.none"]; fg = gsFg["color.pri.none"];
bg = gsBg["color.pri.none"]; bg = gsBg["color.pri.none"];
@ -152,7 +151,7 @@ void autoColorize (
if (gsFg["color.active"] != Text::nocolor || if (gsFg["color.active"] != Text::nocolor ||
gsBg["color.active"] != Text::nocolor) gsBg["color.active"] != Text::nocolor)
{ {
if (task.getAttribute ("start") != "") if (task.has ("start"))
{ {
fg = gsFg["color.active"]; fg = gsFg["color.active"];
bg = gsBg["color.active"]; bg = gsBg["color.active"];
@ -180,7 +179,7 @@ void autoColorize (
if (it->first.substr (0, 14) == "color.project.") if (it->first.substr (0, 14) == "color.project.")
{ {
std::string value = it->first.substr (14, std::string::npos); std::string value = it->first.substr (14, std::string::npos);
if (task.getAttribute ("project") == value) if (task.get ("project") == value)
{ {
fg = gsFg[it->first]; fg = gsFg[it->first];
bg = gsBg[it->first]; bg = gsBg[it->first];
@ -194,7 +193,7 @@ void autoColorize (
if (it->first.substr (0, 14) == "color.keyword.") if (it->first.substr (0, 14) == "color.keyword.")
{ {
std::string value = lowerCase (it->first.substr (14, std::string::npos)); std::string value = lowerCase (it->first.substr (14, std::string::npos));
std::string desc = lowerCase (task.getDescription ()); std::string desc = lowerCase (task.get ("description"));
if (desc.find (value) != std::string::npos) if (desc.find (value) != std::string::npos)
{ {
fg = gsFg[it->first]; fg = gsFg[it->first];
@ -204,25 +203,24 @@ void autoColorize (
} }
// Colorization of the due and overdue. // Colorization of the due and overdue.
std::string due = task.getAttribute ("due"); if (task.has ("due"))
if (due != "")
{ {
Date dueDate (::atoi (due.c_str ())); std::string due = task.get ("due");
Date now; switch (getDueState (due))
Date then (now + context.config.get ("due", 7) * 86400);
// Overdue
if (dueDate < now)
{
fg = gsFg["color.overdue"];
bg = gsBg["color.overdue"];
}
// Imminent
else if (dueDate < then)
{ {
case 1: // imminent
fg = gsFg["color.due"]; fg = gsFg["color.due"];
bg = gsBg["color.due"]; bg = gsBg["color.due"];
break;
case 2: // overdue
fg = gsFg["color.overdue"];
bg = gsBg["color.overdue"];
break;
case 0: // not due at all
default:
break;
} }
} }
@ -230,7 +228,7 @@ void autoColorize (
if (gsFg["color.recurring"] != Text::nocolor || if (gsFg["color.recurring"] != Text::nocolor ||
gsBg["color.recurring"] != Text::nocolor) gsBg["color.recurring"] != Text::nocolor)
{ {
if (task.getAttribute ("recur") != "") if (task.has ("recur"))
{ {
fg = gsFg["color.recurring"]; fg = gsFg["color.recurring"];
bg = gsBg["color.recurring"]; bg = gsBg["color.recurring"];