Use Taskchampion to store Taskwarrior data

This replaces the TF2 task files with a TaskChampion replica.
This commit is contained in:
Dustin J. Mitchell
2022-12-15 02:52:47 +00:00
committed by Dustin J. Mitchell
parent 4b814bc602
commit 5bb9857984
24 changed files with 537 additions and 1362 deletions

View File

@@ -144,6 +144,19 @@ Task::Task (const json::object* obj)
parseJSON (obj);
}
////////////////////////////////////////////////////////////////////////////////
Task::Task (tc::Task obj)
{
id = 0;
urgency_value = 0.0;
recalc_urgency = true;
is_blocked = false;
is_blocking = false;
annotation_count = 0;
parseTC (obj);
}
////////////////////////////////////////////////////////////////////////////////
Task::status Task::textToStatus (const std::string& input)
{
@@ -895,6 +908,29 @@ void Task::parseJSON (const json::object* root_obj)
}
}
////////////////////////////////////////////////////////////////////////////////
// Note that all fields undergo encode/decode.
void Task::parseTC (const tc::Task& task)
{
data = task.get_taskmap ();
// count annotations
annotation_count = 0;
for (auto i : data)
{
if (isAnnotationAttr (i.first))
{
++annotation_count;
}
}
data["uuid"] = task.get_uuid ();
id = Context::getContext ().tdb2.id (data["uuid"]);
is_blocking = task.is_blocking();
is_blocked = task.is_blocked();
}
////////////////////////////////////////////////////////////////////////////////
// No legacy formats are currently supported as of 2.4.0.
void Task::parseLegacy (const std::string& line)
@@ -1711,6 +1747,9 @@ void Task::substitute (
// 1) To provide missing attributes where possible
// 2) To provide suitable warnings about odd states
// 3) To generate errors when the inconsistencies are not fixable
// 4) To update status depending on other attributes
//
// Critically, note that despite the name this is not a read-only function.
//
void Task::validate (bool applyDefault /* = true */)
{
@@ -1938,6 +1977,31 @@ const std::string Task::decode (const std::string& value) const
return str_replace (modified, "&close;", "]");
}
////////////////////////////////////////////////////////////////////////////////
tc::Status Task::status2tc (const Task::status status)
{
switch (status) {
case Task::pending: return tc::Status::Pending;
case Task::completed: return tc::Status::Completed;
case Task::deleted: return tc::Status::Deleted;
case Task::waiting: return tc::Status::Pending; // waiting is no longer a status
case Task::recurring: return tc::Status::Recurring;
default: return tc::Status::Unknown;
}
}
////////////////////////////////////////////////////////////////////////////////
Task::status Task::tc2status (const tc::Status status)
{
switch (status) {
case tc::Status::Pending: return Task::pending;
case tc::Status::Completed: return Task::completed;
case tc::Status::Deleted: return Task::deleted;
case tc::Status::Recurring: return Task::recurring;
default: return Task::pending;
}
}
////////////////////////////////////////////////////////////////////////////////
int Task::determineVersion (const std::string& line)
{