- Implemented Task::setEnd.
- Updated all code to use Task::setEntry and Task::setEnd.
This commit is contained in:
Paul Beckingham 2011-07-10 11:07:00 -04:00
parent ad55fa2d79
commit ba723db9d7
3 changed files with 60 additions and 51 deletions

View file

@ -135,7 +135,17 @@ void Task::setEntry ()
{ {
char entryTime[16]; char entryTime[16];
sprintf (entryTime, "%u", (unsigned int) time (NULL)); sprintf (entryTime, "%u", (unsigned int) time (NULL));
set ("entry", entryTime); // No i18n set ("entry", entryTime);
recalc_urgency = true;
}
////////////////////////////////////////////////////////////////////////////////
void Task::setEnd ()
{
char endTime[16];
sprintf (endTime, "%u", (unsigned int) time (NULL));
set ("end", endTime);
recalc_urgency = true; recalc_urgency = true;
} }
@ -143,13 +153,13 @@ void Task::setEntry ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Task::status Task::getStatus () const Task::status Task::getStatus () const
{ {
return textToStatus (get ("status")); // No i18n return textToStatus (get ("status"));
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Task::setStatus (Task::status status) void Task::setStatus (Task::status status)
{ {
set ("status", statusToText (status)); // No i18n set ("status", statusToText (status));
recalc_urgency = true; recalc_urgency = true;
} }
@ -200,7 +210,7 @@ void Task::legacyParse (const std::string& line)
: line[37] == 'r' ? recurring : line[37] == 'r' ? recurring
: pending; : pending;
set ("status", statusToText (status)); // No i18n set ("status", statusToText (status));
size_t openTagBracket = line.find ("["); size_t openTagBracket = line.find ("[");
size_t closeTagBracket = line.find ("]", openTagBracket); size_t closeTagBracket = line.find ("]", openTagBracket);
@ -230,7 +240,7 @@ void Task::legacyParse (const std::string& line)
set (pair[0], pair[1]); set (pair[0], pair[1]);
} }
set ("description", line.substr (closeAttrBracket + 2)); // No i18n set ("description", line.substr (closeAttrBracket + 2));
} }
else else
throw std::string (STRING_TASK_PARSE_ATT_BRACK); throw std::string (STRING_TASK_PARSE_ATT_BRACK);
@ -257,7 +267,7 @@ void Task::legacyParse (const std::string& line)
: line[37] == 'r' ? recurring : line[37] == 'r' ? recurring
: pending; : pending;
set ("status", statusToText (status)); // No i18n set ("status", statusToText (status));
size_t openTagBracket = line.find ("["); size_t openTagBracket = line.find ("[");
size_t closeTagBracket = line.find ("]", openTagBracket); size_t closeTagBracket = line.find ("]", openTagBracket);
@ -327,11 +337,11 @@ void Task::legacyParse (const std::string& line)
{ {
std::string name = pair.substr (0, colon); std::string name = pair.substr (0, colon);
std::string value = pair.substr (colon + 2, pair.length () - colon - 3); std::string value = pair.substr (colon + 2, pair.length () - colon - 3);
set ("annotation_" + name, value); // No i18n set ("annotation_" + name, value);
} }
} }
set ("description", line.substr (closeAnnoBracket + 2)); // No i18n set ("description", line.substr (closeAnnoBracket + 2));
} }
else else
throw std::string (STRING_TASK_PARSE_ANNO_BRACK); throw std::string (STRING_TASK_PARSE_ANNO_BRACK);
@ -359,55 +369,55 @@ std::string Task::composeCSV () const
std::stringstream out; std::stringstream out;
// Deliberately no 'id'. // Deliberately no 'id'.
out << "'" << get ("uuid") << "',"; // No i18n out << "'" << get ("uuid") << "',";
out << "'" << get ("status") << "',"; // No i18n out << "'" << get ("status") << "',";
// Tags // Tags
std::vector <std::string> tags; std::vector <std::string> tags;
getTags (tags); getTags (tags);
std::string allTags; std::string allTags;
join (allTags, " ", tags); // No i18n join (allTags, " ", tags);
out << "'" << allTags << "',"; // No i18n out << "'" << allTags << "',";
out << get ("entry") << ","; // No i18n out << get ("entry") << ",";
out << get ("start") << ","; // No i18n out << get ("start") << ",";
if (has ("due")) if (has ("due"))
out << get ("due") << ","; // No i18n out << get ("due") << ",";
else else
out << ","; // No i18n out << ",";
if (has ("recur")) if (has ("recur"))
out << get ("recur") << ","; // No i18n out << get ("recur") << ",";
else else
out << ","; // No i18n out << ",";
out << get ("end") << ","; // No i18n out << get ("end") << ",";
if (has ("project")) if (has ("project"))
out << "'" << get ("project") << "',"; // No i18n out << "'" << get ("project") << "',";
else else
out << ","; // No i18n out << ",";
if (has ("priority")) if (has ("priority"))
out << "'" << get ("priority") << "',"; // No i18n out << "'" << get ("priority") << "',";
else else
out << ","; // No i18n out << ",";
if (has ("fg")) if (has ("fg"))
out << "'" << get ("fg") << "',"; // No i18n out << "'" << get ("fg") << "',";
else else
out << ","; // No i18n out << ",";
if (has ("bg")) if (has ("bg"))
out << "'" << get ("bg") << "',"; // No i18n out << "'" << get ("bg") << "',";
else else
out << ","; // No i18n out << ",";
// Convert single quotes to double quotes, because single quotes are used to // Convert single quotes to double quotes, because single quotes are used to
// delimit the values that need it. // delimit the values that need it.
std::string clean = get ("description"); // No i18n std::string clean = get ("description");
std::replace (clean.begin (), clean.end (), '\'', '"'); // No i18n std::replace (clean.begin (), clean.end (), '\'', '"');
out << "'" << clean << "'\n"; out << "'" << clean << "'\n";
return out.str (); return out.str ();
@ -558,7 +568,7 @@ void Task::getAnnotations (std::vector <Att>& annotations) const
Record::const_iterator ci; Record::const_iterator ci;
for (ci = this->begin (); ci != this->end (); ++ci) for (ci = this->begin (); ci != this->end (); ++ci)
if (ci->first.substr (0, 11) == "annotation_") // No i18n if (ci->first.substr (0, 11) == "annotation_")
annotations.push_back (ci->second); annotations.push_back (ci->second);
} }
@ -582,7 +592,7 @@ void Task::setAnnotations (const std::vector <Att>& annotations)
void Task::addAnnotation (const std::string& description) void Task::addAnnotation (const std::string& description)
{ {
std::stringstream s; std::stringstream s;
s << "annotation_" << time (NULL); // No i18n s << "annotation_" << time (NULL);
(*this)[s.str ()] = Att (s.str (), description); (*this)[s.str ()] = Att (s.str (), description);
} }
@ -594,7 +604,7 @@ void Task::removeAnnotations ()
Record::iterator i = this->begin (); Record::iterator i = this->begin ();
while (i != this->end ()) while (i != this->end ())
{ {
if (i->first.substr (0, 11) == "annotation_") // No i18n if (i->first.substr (0, 11) == "annotation_")
this->erase (i++); this->erase (i++);
else else
i++; i++;
@ -680,7 +690,7 @@ void Task::getDependencies (std::vector <std::string>& all) const
int Task::getTagCount () int Task::getTagCount ()
{ {
std::vector <std::string> tags; std::vector <std::string> tags;
split (tags, get ("tags"), ','); // No i18n split (tags, get ("tags"), ',');
return (int) tags.size (); return (int) tags.size ();
} }
@ -689,7 +699,7 @@ int Task::getTagCount ()
bool Task::hasTag (const std::string& tag) bool Task::hasTag (const std::string& tag)
{ {
std::vector <std::string> tags; std::vector <std::string> tags;
split (tags, get ("tags"), ','); // No i18n split (tags, get ("tags"), ',');
if (std::find (tags.begin (), tags.end (), tag) != tags.end ()) if (std::find (tags.begin (), tags.end (), tag) != tags.end ())
return true; return true;
@ -701,21 +711,21 @@ bool Task::hasTag (const std::string& tag)
void Task::addTag (const std::string& tag) void Task::addTag (const std::string& tag)
{ {
std::vector <std::string> tags; std::vector <std::string> tags;
split (tags, get ("tags"), ','); // No i18n split (tags, get ("tags"), ',');
if (std::find (tags.begin (), tags.end (), tag) == tags.end ()) if (std::find (tags.begin (), tags.end (), tag) == tags.end ())
{ {
tags.push_back (tag); tags.push_back (tag);
std::string combined; std::string combined;
join (combined, ",", tags); // No i18n join (combined, ",", tags);
set ("tags", combined); // No i18n set ("tags", combined);
} }
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Task::addTags (const std::vector <std::string>& tags) void Task::addTags (const std::vector <std::string>& tags)
{ {
remove ("tags"); // No i18n remove ("tags");
std::vector <std::string>::const_iterator it; std::vector <std::string>::const_iterator it;
for (it = tags.begin (); it != tags.end (); ++it) for (it = tags.begin (); it != tags.end (); ++it)
@ -725,14 +735,14 @@ void Task::addTags (const std::vector <std::string>& tags)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Task::getTags (std::vector<std::string>& tags) const void Task::getTags (std::vector<std::string>& tags) const
{ {
split (tags, get ("tags"), ','); // No i18n split (tags, get ("tags"), ',');
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Task::removeTag (const std::string& tag) void Task::removeTag (const std::string& tag)
{ {
std::vector <std::string> tags; std::vector <std::string> tags;
split (tags, get ("tags"), ','); // No i18n split (tags, get ("tags"), ',');
std::vector <std::string>::iterator i; std::vector <std::string>::iterator i;
i = std::find (tags.begin (), tags.end (), tag); i = std::find (tags.begin (), tags.end (), tag);
@ -740,8 +750,8 @@ void Task::removeTag (const std::string& tag)
{ {
tags.erase (i); tags.erase (i);
std::string combined; std::string combined;
join (combined, ",", tags); // No i18n join (combined, ",", tags);
set ("tags", combined); // No i18n set ("tags", combined);
} }
} }
@ -959,9 +969,9 @@ int Task::determineVersion (const std::string& line)
// uuid status [tags] [attributes] [annotations] description\n // uuid status [tags] [attributes] [annotations] description\n
// //
// Scan for the number of [] pairs. // Scan for the number of [] pairs.
std::string::size_type tagAtts = line.find ("] [", 0); // No i18n std::string::size_type tagAtts = line.find ("] [", 0);
std::string::size_type attsAnno = line.find ("] [", tagAtts + 1); // No i18n std::string::size_type attsAnno = line.find ("] [", tagAtts + 1);
std::string::size_type annoDesc = line.find ("] ", attsAnno + 1); // No i18n std::string::size_type annoDesc = line.find ("] ", attsAnno + 1);
if (tagAtts != std::string::npos && if (tagAtts != std::string::npos &&
attsAnno != std::string::npos && attsAnno != std::string::npos &&
annoDesc != std::string::npos) annoDesc != std::string::npos)
@ -977,7 +987,7 @@ int Task::determineVersion (const std::string& line)
// Scan for [, ] and :". // Scan for [, ] and :".
else if (line[0] == '[' && else if (line[0] == '[' &&
line[line.length () - 1] == ']' && line[line.length () - 1] == ']' &&
line.find ("uuid:\"") != std::string::npos) // No i18n line.find ("uuid:\"") != std::string::npos)
return 4; return 4;
// Version 1 looks like: // Version 1 looks like:
@ -987,9 +997,9 @@ int Task::determineVersion (const std::string& line)
// //
// Scan for the first character being either the bracket or X. // Scan for the first character being either the bracket or X.
else if (line.find ("X [") == 0 || else if (line.find ("X [") == 0 ||
line.find ("uuid") == std::string::npos || // No i18n line.find ("uuid") == std::string::npos ||
(line[0] == '[' && (line[0] == '[' &&
line.substr (line.length () - 1, 1) != "]")) // No i18n line.substr (line.length () - 1, 1) != "]"))
return 1; return 1;
// Version 5? // Version 5?

View file

@ -59,6 +59,7 @@ public:
static std::string statusToText (status); static std::string statusToText (status);
void setEntry (); void setEntry ();
void setEnd ();
status getStatus () const; status getStatus () const;
void setStatus (status); void setStatus (status);

View file

@ -75,9 +75,7 @@ void handleRecurrence ()
<< "\n"; << "\n";
// Determine the end date. // Determine the end date.
char endTime[16]; t->setEnd ();
sprintf (endTime, "%u", (unsigned int) time (NULL));
t->set ("end", endTime);
t->setStatus (Task::deleted); t->setStatus (Task::deleted);
context.tdb.update (*t); context.tdb.update (*t);
continue; continue;