Code Cleanup

- Replaced multiple Task:setX methods with Task::setAsNow (x).
This commit is contained in:
Paul Beckingham 2014-09-14 11:57:02 -04:00
parent cf5dbbb9ee
commit b5f3cfd9a3
6 changed files with 15 additions and 47 deletions

View file

@ -173,52 +173,24 @@ Task::status Task::textToStatus (const std::string& input)
std::string Task::statusToText (Task::status s) std::string Task::statusToText (Task::status s)
{ {
if (s == Task::pending) return "pending"; if (s == Task::pending) return "pending";
else if (s == Task::completed) return "completed";
else if (s == Task::deleted) return "deleted";
else if (s == Task::recurring) return "recurring"; else if (s == Task::recurring) return "recurring";
else if (s == Task::waiting) return "waiting"; else if (s == Task::waiting) return "waiting";
else if (s == Task::completed) return "completed";
else if (s == Task::deleted) return "deleted";
return "pending"; return "pending";
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Task::setEntry () void Task::setAsNow (const std::string& att)
{ {
char now[16]; char now[16];
sprintf (now, "%u", (unsigned int) time (NULL)); sprintf (now, "%u", (unsigned int) time (NULL));
set ("entry", now); set (att, now);
recalc_urgency = true; recalc_urgency = true;
} }
////////////////////////////////////////////////////////////////////////////////
void Task::setEnd ()
{
char now[16];
sprintf (now, "%u", (unsigned int) time (NULL));
set ("end", now);
recalc_urgency = true;
}
////////////////////////////////////////////////////////////////////////////////
void Task::setStart ()
{
char now[16];
sprintf (now, "%u", (unsigned int) time (NULL));
set ("start", now);
recalc_urgency = true;
}
////////////////////////////////////////////////////////////////////////////////
void Task::setModified ()
{
char now[16];
sprintf (now, "%u", (unsigned int) time (NULL));
set ("modified", now);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool Task::has (const std::string& name) const bool Task::has (const std::string& name) const
{ {
@ -1485,16 +1457,16 @@ void Task::validate (bool applyDefault /* = true */)
#ifdef PRODUCT_TASKWARRIOR #ifdef PRODUCT_TASKWARRIOR
// Provide an entry date unless user already specified one. // Provide an entry date unless user already specified one.
if (!has ("entry") || get ("entry") == "") if (!has ("entry") || get ("entry") == "")
setEntry (); setAsNow ("entry");
// Completed tasks need an end date, so inherit the entry date. // Completed tasks need an end date, so inherit the entry date.
if ((status == Task::completed || status == Task::deleted) && if ((status == Task::completed || status == Task::deleted) &&
(! has ("end") || get ("end") == "")) (! has ("end") || get ("end") == ""))
setEnd (); setAsNow ("end");
// Provide an entry date unless user already specified one. // Provide an entry date unless user already specified one.
if (!has ("modified") || get ("modified") == "") if (!has ("modified") || get ("modified") == "")
setModified (); setAsNow ("modified");
if (applyDefault) if (applyDefault)
{ {

View file

@ -90,11 +90,7 @@ public:
static status textToStatus (const std::string&); static status textToStatus (const std::string&);
static std::string statusToText (status); static std::string statusToText (status);
void setEntry (); void setAsNow (const std::string&);
void setEnd ();
void setStart ();
void setModified ();
bool has (const std::string&) const; bool has (const std::string&) const;
std::vector <std::string> all (); std::vector <std::string> all ();
const std::string get (const std::string&) const; const std::string get (const std::string&) const;

View file

@ -87,7 +87,7 @@ int CmdDelete::execute (std::string& output)
task->modify (Task::modAnnotate); task->modify (Task::modAnnotate);
task->setStatus (Task::deleted); task->setStatus (Task::deleted);
if (! task->has ("end")) if (! task->has ("end"))
task->setEnd (); task->setAsNow ("end");
if (permission (*task, question, filtered.size ())) if (permission (*task, question, filtered.size ()))
{ {
@ -112,7 +112,7 @@ int CmdDelete::execute (std::string& output)
sibling->modify (Task::modAnnotate); sibling->modify (Task::modAnnotate);
sibling->setStatus (Task::deleted); sibling->setStatus (Task::deleted);
if (! sibling->has ("end")) if (! sibling->has ("end"))
sibling->setEnd (); sibling->setAsNow ("end");
updateRecurrenceMask (*sibling); updateRecurrenceMask (*sibling);
context.tdb2.modify (*sibling); context.tdb2.modify (*sibling);
@ -126,7 +126,7 @@ int CmdDelete::execute (std::string& output)
context.tdb2.get (task->get ("parent"), parent); context.tdb2.get (task->get ("parent"), parent);
parent.setStatus (Task::deleted); parent.setStatus (Task::deleted);
if (! parent.has ("end")) if (! parent.has ("end"))
parent.setEnd (); parent.setAsNow ("end");
context.tdb2.modify (parent); context.tdb2.modify (parent);
} }
@ -145,7 +145,7 @@ int CmdDelete::execute (std::string& output)
child->modify (Task::modAnnotate); child->modify (Task::modAnnotate);
child->setStatus (Task::deleted); child->setStatus (Task::deleted);
if (! child->has ("end")) if (! child->has ("end"))
child->setEnd (); child->setAsNow ("end");
updateRecurrenceMask (*child); updateRecurrenceMask (*child);
context.tdb2.modify (*child); context.tdb2.modify (*child);

View file

@ -82,7 +82,7 @@ int CmdDone::execute (std::string& output)
task->modify (Task::modAnnotate); task->modify (Task::modAnnotate);
task->setStatus (Task::completed); task->setStatus (Task::completed);
if (! task->has ("end")) if (! task->has ("end"))
task->setEnd (); task->setAsNow ("end");
// Stop the task, if started. // Stop the task, if started.
if (task->has ("start")) if (task->has ("start"))

View file

@ -78,7 +78,7 @@ int CmdStart::execute (std::string& output)
task->id, task->id,
task->get ("description")); task->get ("description"));
task->modify (Task::modAnnotate); task->modify (Task::modAnnotate);
task->setStart (); task->setAsNow ("start");
if (context.config.getBoolean ("journal.time")) if (context.config.getBoolean ("journal.time"))
task->addAnnotation (context.config.get ("journal.time.start.annotation")); task->addAnnotation (context.config.get ("journal.time.start.annotation"));

View file

@ -93,7 +93,7 @@ void handleRecurrence ()
rec.id = context.tdb2.next_id (); // New ID. rec.id = context.tdb2.next_id (); // New ID.
rec.set ("uuid", uuid ()); // New UUID. rec.set ("uuid", uuid ()); // New UUID.
rec.set ("parent", t->get ("uuid")); // Remember mom. rec.set ("parent", t->get ("uuid")); // Remember mom.
rec.setEntry (); // New entry date. rec.setAsNow ("entry"); // New entry date.
char dueDate[16]; char dueDate[16];
sprintf (dueDate, "%u", (unsigned int) d->toEpoch ()); sprintf (dueDate, "%u", (unsigned int) d->toEpoch ());