- Fixed bug #1022, where dependencies were note released when a blocking task
  was completed (thanks to Arkady Grudzinsky).
- The Task object now caches ::is_blocked and ::is_blocking Booleans that are
  determined on pending.data load.
- Simplified and sped up color rule processing using cached values, reducing
  the number of map lookups, and removed loop invariants when the rules are
  not defined.
- Simplified urgency calculations given the cached values for blocked/blocking.
- On load, pending.data is scanned for accurate blocked/blocking status
  determination.
- Obsoleted and removed complex single-task dependency calculations.
- Sped up 'nag' processing by using cached values..
- Modified the 'show' command to consider color.blocking to be valid.
- Added default config value for color.blocking, and included it in the
  precedence list ahead of blocked, as it is more important.
- Updated taskrc.5 man page to include the new color.blocking rule, and its
  place in the rule precedence.
This commit is contained in:
Paul Beckingham 2012-07-09 01:18:11 -04:00
parent 02053f7300
commit 79e2c591f1
14 changed files with 182 additions and 178 deletions

View file

@ -27,7 +27,6 @@
#define L10N // Localization complete.
#include <iostream>
#include <stdlib.h>
#include <Context.h>
#include <Date.h>
@ -84,85 +83,80 @@ void initializeColorRules ()
}
////////////////////////////////////////////////////////////////////////////////
static void colorizeBlocked (Task& task, const std::string& rule, Color& c)
static void colorizeBlocked (Task& task, const Color& base, Color& c)
{
if (gsColor[rule].nontrivial ())
if (dependencyIsBlocked (task))
c.blend (gsColor[rule]);
if (task.is_blocked)
c.blend (base);
}
////////////////////////////////////////////////////////////////////////////////
static void colorizeTagged (Task& task, const std::string& rule, Color& c)
static void colorizeBlocking (Task& task, const Color& base, Color& c)
{
if (gsColor[rule].nontrivial ())
if (task.getTagCount ())
c.blend (gsColor[rule]);
if (task.is_blocking)
c.blend (base);
}
////////////////////////////////////////////////////////////////////////////////
static void colorizePriorityL (Task& task, const std::string& rule, Color& c)
static void colorizeTagged (Task& task, const Color& base, Color& c)
{
if (gsColor[rule].nontrivial ())
if (task.get ("priority") == "L")
c.blend (gsColor[rule]);
if (task.getTagCount ())
c.blend (base);
}
////////////////////////////////////////////////////////////////////////////////
static void colorizePriorityM (Task& task, const std::string& rule, Color& c)
static void colorizePriorityL (Task& task, const Color& base, Color& c)
{
if (gsColor[rule].nontrivial ())
if (task.get ("priority") == "M")
c.blend (gsColor[rule]);
if (task.get ("priority") == "L")
c.blend (base);
}
////////////////////////////////////////////////////////////////////////////////
static void colorizePriorityH (Task& task, const std::string& rule, Color& c)
static void colorizePriorityM (Task& task, const Color& base, Color& c)
{
if (gsColor[rule].nontrivial ())
if (task.get ("priority") == "H")
c.blend (gsColor[rule]);
if (task.get ("priority") == "M")
c.blend (base);
}
////////////////////////////////////////////////////////////////////////////////
static void colorizePriorityNone (Task& task, const std::string& rule, Color& c)
static void colorizePriorityH (Task& task, const Color& base, Color& c)
{
if (gsColor[rule].nontrivial ())
if (task.get ("priority") == "")
c.blend (gsColor[rule]);
if (task.get ("priority") == "H")
c.blend (base);
}
////////////////////////////////////////////////////////////////////////////////
static void colorizeActive (Task& task, const std::string& rule, Color& c)
static void colorizePriorityNone (Task& task, const Color& base, Color& c)
{
if (gsColor[rule].nontrivial ())
if (task.has ("start") &&
!task.has ("end"))
c.blend (gsColor[rule]);
if (task.get ("priority") == "")
c.blend (base);
}
////////////////////////////////////////////////////////////////////////////////
static void colorizeScheduled (Task& task, const std::string& rule, Color& c)
static void colorizeActive (Task& task, const Color& base, Color& c)
{
if (gsColor[rule].nontrivial ())
if (task.has ("scheduled") &&
Date (task.get_date ("scheduled")) <= now)
c.blend (gsColor[rule]);
if (task.has ("start") &&
!task.has ("end"))
c.blend (base);
}
////////////////////////////////////////////////////////////////////////////////
static void colorizeTag (Task& task, const std::string& rule, Color& c)
static void colorizeScheduled (Task& task, const Color& base, Color& c)
{
if (gsColor[rule].nontrivial ())
if (task.hasTag (rule.substr (10)))
c.blend (gsColor[rule]);
if (task.has ("scheduled") &&
Date (task.get_date ("scheduled")) <= now)
c.blend (base);
}
////////////////////////////////////////////////////////////////////////////////
static void colorizeProject (Task& task, const std::string& rule, Color& c)
static void colorizeTag (Task& task, const std::string& rule, const Color& base, Color& c)
{
if (!gsColor[rule].nontrivial ())
return;
if (task.hasTag (rule.substr (10)))
c.blend (base);
}
////////////////////////////////////////////////////////////////////////////////
static void colorizeProject (Task& task, const std::string& rule, const Color& base, Color& c)
{
// Observe the case sensitivity setting.
bool sensitive = context.config.getBoolean ("search.case.sensitive");
@ -172,38 +166,33 @@ static void colorizeProject (Task& task, const std::string& rule, Color& c)
// Match project names leftmost.
if (rule_trunc.length () <= project.length ())
if (compare (rule_trunc, project.substr (0, rule_trunc.length ()), sensitive))
c.blend (gsColor[rule]);
c.blend (base);
}
////////////////////////////////////////////////////////////////////////////////
static void colorizeProjectNone (Task& task, const std::string& rule, Color& c)
static void colorizeProjectNone (Task& task, const Color& base, Color& c)
{
if (gsColor[rule].nontrivial ())
if (task.get ("project") == "")
c.blend (gsColor[rule]);
if (task.get ("project") == "")
c.blend (base);
}
////////////////////////////////////////////////////////////////////////////////
static void colorizeTagNone (Task& task, const std::string& rule, Color& c)
static void colorizeTagNone (Task& task, const Color& base, Color& c)
{
if (gsColor[rule].nontrivial ())
if (task.getTagCount () == 0)
c.blend (gsColor[rule]);
if (task.getTagCount () == 0)
c.blend (base);
}
////////////////////////////////////////////////////////////////////////////////
static void colorizeKeyword (Task& task, const std::string& rule, Color& c)
static void colorizeKeyword (Task& task, const std::string& rule, const Color& base, Color& c)
{
if (!gsColor[rule].nontrivial ())
return;
// Observe the case sensitivity setting.
bool sensitive = context.config.getBoolean ("search.case.sensitive");
// The easiest thing to check is the description, because it is just one
// attribute.
if (find (task.get ("description"), rule.substr (14), sensitive) != std::string::npos)
c.blend (gsColor[rule]);
c.blend (base);
// Failing the description check, look at all annotations, returning on the
// first match.
@ -215,7 +204,7 @@ static void colorizeKeyword (Task& task, const std::string& rule, Color& c)
if (it->first.substr (0, 11) == "annotation_" &&
find (it->second, rule.substr (14), sensitive) != std::string::npos)
{
c.blend (gsColor[rule]);
c.blend (base);
return;
}
}
@ -223,11 +212,8 @@ static void colorizeKeyword (Task& task, const std::string& rule, Color& c)
}
////////////////////////////////////////////////////////////////////////////////
static void colorizeDue (Task& task, const std::string& rule, Color& c)
static void colorizeDue (Task& task, const Color& base, Color& c)
{
if (!gsColor[rule].nontrivial ())
return;
Task::status status = task.getStatus ();
if (task.has ("due") &&
@ -235,16 +221,13 @@ static void colorizeDue (Task& task, const std::string& rule, Color& c)
status != Task::deleted)
{
if (getDueState (task.get ("due")) == 1)
c.blend (gsColor[rule]);
c.blend (base);
}
}
////////////////////////////////////////////////////////////////////////////////
static void colorizeDueToday (Task& task, const std::string& rule, Color& c)
static void colorizeDueToday (Task& task, const Color& base, Color& c)
{
if (!gsColor[rule].nontrivial ())
return;
Task::status status = task.getStatus ();
if (task.has ("due") &&
@ -252,16 +235,13 @@ static void colorizeDueToday (Task& task, const std::string& rule, Color& c)
status != Task::deleted)
{
if (getDueState (task.get ("due")) == 2)
c.blend (gsColor[rule]);
c.blend (base);
}
}
////////////////////////////////////////////////////////////////////////////////
static void colorizeOverdue (Task& task, const std::string& rule, Color& c)
static void colorizeOverdue (Task& task, const Color& base, Color& c)
{
if (!gsColor[rule].nontrivial ())
return;
Task::status status = task.getStatus ();
if (task.has ("due") &&
@ -269,32 +249,29 @@ static void colorizeOverdue (Task& task, const std::string& rule, Color& c)
status != Task::deleted)
{
if (getDueState (task.get ("due")) == 3)
c.blend (gsColor[rule]);
c.blend (base);
}
}
////////////////////////////////////////////////////////////////////////////////
static void colorizeRecurring (Task& task, const std::string& rule, Color& c)
static void colorizeRecurring (Task& task, const Color& base, Color& c)
{
if (gsColor[rule].nontrivial ())
if (task.has ("recur"))
c.blend (gsColor[rule]);
if (task.has ("recur"))
c.blend (base);
}
////////////////////////////////////////////////////////////////////////////////
static void colorizeCompleted (Task& task, const std::string& rule, Color& c)
static void colorizeCompleted (Task& task, const Color& base, Color& c)
{
if (gsColor[rule].nontrivial ())
if (task.getStatus () == Task::completed)
c.blend (gsColor[rule]);
if (task.getStatus () == Task::completed)
c.blend (base);
}
////////////////////////////////////////////////////////////////////////////////
static void colorizeDeleted (Task& task, const std::string& rule, Color& c)
static void colorizeDeleted (Task& task, const Color& base, Color& c)
{
if (gsColor[rule].nontrivial ())
if (task.getStatus () == Task::completed)
c.blend (gsColor[rule]);
if (task.getStatus () == Task::completed)
c.blend (base);
}
////////////////////////////////////////////////////////////////////////////////
@ -314,27 +291,32 @@ void autoColorize (Task& task, Color& c)
std::vector <std::string>::reverse_iterator r;
for (r = gsPrecedence.rbegin (); r != gsPrecedence.rend (); ++r)
{
if (*r == "color.blocked") colorizeBlocked (task, *r, c);
else if (*r == "color.tagged") colorizeTagged (task, *r, c);
else if (*r == "color.pri.L") colorizePriorityL (task, *r, c);
else if (*r == "color.pri.M") colorizePriorityM (task, *r, c);
else if (*r == "color.pri.H") colorizePriorityH (task, *r, c);
else if (*r == "color.pri.none") colorizePriorityNone (task, *r, c);
else if (*r == "color.active") colorizeActive (task, *r, c);
else if (*r == "color.scheduled") colorizeScheduled (task, *r, c);
else if (*r == "color.project.none") colorizeProjectNone (task, *r, c);
else if (*r == "color.tag.none") colorizeTagNone (task, *r, c);
else if (*r == "color.due") colorizeDue (task, *r, c);
else if (*r == "color.due.today") colorizeDueToday (task, *r, c);
else if (*r == "color.overdue") colorizeOverdue (task, *r, c);
else if (*r == "color.recurring") colorizeRecurring (task, *r, c);
else if (*r == "color.completed") colorizeCompleted (task, *r, c);
else if (*r == "color.deleted") colorizeDeleted (task, *r, c);
Color base = gsColor[*r];
if (base.nontrivial ())
{
if (*r == "color.blocked") colorizeBlocked (task, base, c);
else if (*r == "color.blocking") colorizeBlocking (task, base, c);
else if (*r == "color.tagged") colorizeTagged (task, base, c);
else if (*r == "color.pri.L") colorizePriorityL (task, base, c);
else if (*r == "color.pri.M") colorizePriorityM (task, base, c);
else if (*r == "color.pri.H") colorizePriorityH (task, base, c);
else if (*r == "color.pri.none") colorizePriorityNone (task, base, c);
else if (*r == "color.active") colorizeActive (task, base, c);
else if (*r == "color.scheduled") colorizeScheduled (task, base, c);
else if (*r == "color.project.none") colorizeProjectNone (task, base, c);
else if (*r == "color.tag.none") colorizeTagNone (task, base, c);
else if (*r == "color.due") colorizeDue (task, base, c);
else if (*r == "color.due.today") colorizeDueToday (task, base, c);
else if (*r == "color.overdue") colorizeOverdue (task, base, c);
else if (*r == "color.recurring") colorizeRecurring (task, base, c);
else if (*r == "color.completed") colorizeCompleted (task, base, c);
else if (*r == "color.deleted") colorizeDeleted (task, base, c);
// Wildcards
else if (r->substr (0, 10) == "color.tag.") colorizeTag (task, *r, c);
else if (r->substr (0, 14) == "color.project.") colorizeProject (task, *r, c);
else if (r->substr (0, 14) == "color.keyword.") colorizeKeyword (task, *r, c);
// Wildcards
else if (r->substr (0, 10) == "color.tag.") colorizeTag (task, *r, base, c);
else if (r->substr (0, 14) == "color.project.") colorizeProject (task, *r, base, c);
else if (r->substr (0, 14) == "color.keyword.") colorizeKeyword (task, *r, base, c);
}
}
}