summaryrefslogtreecommitdiff
path: root/src/taskmanager.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/taskmanager.cc')
-rw-r--r--src/taskmanager.cc80
1 files changed, 51 insertions, 29 deletions
diff --git a/src/taskmanager.cc b/src/taskmanager.cc
index 89de0b3..1ca0b63 100644
--- a/src/taskmanager.cc
+++ b/src/taskmanager.cc
@@ -44,29 +44,45 @@ static bool isProtected(taskid_t id)
return id < FIRST_TASK_ID;
}
-TaskManager::TaskManager() {
+TaskManager::TaskManager(std::string file) {
idCount = FIRST_TASK_ID;
- task_t t;
- t.title = "root";
- t.id = ROOT_ID;
- tree.insertAsChild(0, ROOT_ID, t);
+ this->file = file;
+
+ FILE *fp = fopen(file.c_str(), "r");
+ if(fp) {
+ std::string xml;
+ while(!feof(fp)) {
+ char buf[64];
+ size_t sz = fread(buf, 1, sizeof(buf), fp);
+ xml.append(buf, sz);
+ }
+ tree.fromXML(xml);
+ fclose(fp);
+ } else {
+
+ // Create new basis config
+ task_t t;
+ t.title = "root";
+ t.id = ROOT_ID;
+ tree.insertAsChild(0, ROOT_ID, t);
- t.title = "Finished";
- t.id = FINISHED_ID;
- tree.insertAsChild(ROOT_ID, FINISHED_ID, t);
+ t.title = "Finished";
+ t.id = FINISHED_ID;
+ tree.insertAsChild(ROOT_ID, FINISHED_ID, t);
- t.title = "Backlog";
- t.id = BACKLOG_ID;
- tree.insertAsChild(ROOT_ID, BACKLOG_ID, t);
+ t.title = "Backlog";
+ t.id = BACKLOG_ID;
+ tree.insertAsChild(ROOT_ID, BACKLOG_ID, t);
- t.title = "Lost+Found";
- t.id = LOSTFOUND_ID;
- tree.insertAsChild(ROOT_ID, LOSTFOUND_ID, t);
+ t.title = "Lost+Found";
+ t.id = LOSTFOUND_ID;
+ tree.insertAsChild(ROOT_ID, LOSTFOUND_ID, t);
- t.title = "Projects";
- t.id = PROJECTS_ID;
- tree.insertAsChild(ROOT_ID, PROJECTS_ID, t);
+ t.title = "Projects";
+ t.id = PROJECTS_ID;
+ tree.insertAsChild(ROOT_ID, PROJECTS_ID, t);
+ }
tree.toStdOut();
}
@@ -87,18 +103,6 @@ TaskIdListPair TaskManager::moveTask(taskid_t id, taskid_t to)
if(isProtected(id)) return TaskIdListPair();
- /*
-
- TaskIdList affectedTasks;
-
- try {
- affectedTasks = tree.move(id, to);
- }
- catch (std::exception& e) {
- throw e;
- }
- */
-
task_t t = tree.data(id);
t.parentid = to;
@@ -109,6 +113,8 @@ TaskIdListPair TaskManager::moveTask(taskid_t id, taskid_t to)
tilpair.first = tilremove;
tilpair.second = tilcreate;
+ flushTasks();
+
return tilpair;
}
@@ -128,6 +134,8 @@ TaskIdList TaskManager::removeTask(taskid_t id)
throw e;
}
+ flushTasks();
+
return affectedTasks;
}
@@ -145,6 +153,8 @@ TaskIdList TaskManager::updateTask(taskid_t id, task_t t)
throw e;
}
+ flushTasks();
+
return affectedTasks;
}
@@ -165,6 +175,8 @@ TaskIdList TaskManager::createTask(taskid_t parentid, taskid_t *pid)
throw e;
}
+ flushTasks();
+
return affectedTasks;
}
@@ -201,6 +213,16 @@ TaskIdList TaskManager::ancestorList(taskid_t id)
}
*/
+void TaskManager::flushTasks()
+{
+ FILE *fp = fopen(file.c_str(), "w");
+ if(!fp) return;
+ std::string xml = tree.toXML();
+ fwrite(xml.c_str(), xml.size(), 1, fp);
+ fclose(fp);
+}
+
+
#if 0
TaskList tasklist;