summaryrefslogtreecommitdiff
path: root/src/task.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/task.cc')
-rw-r--r--src/task.cc54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/task.cc b/src/task.cc
index 9940fc6..03c1e56 100644
--- a/src/task.cc
+++ b/src/task.cc
@@ -27,7 +27,13 @@
*/
#include "task.h"
+#include <stdio.h>
+
+#include "xml_encode_decode.h"
+
+
TaskList tasklist;
+
static int id_count = 0;
int current_id_count() {
@@ -47,3 +53,51 @@ task_t create_task(std::string title, std::string desc,
return t;
}
+
+TaskList load_tasklist_from_file(std::string file) {
+ TaskList list;
+
+ // create MuniaDb class which handles tasks, db-flush and db-init.
+
+ return list;
+}
+
+bool save_tasklist_to_file(TaskList list, std::string file) {
+
+ FILE* fp;
+
+ if(! (fp = fopen(file.c_str(), "w"))) {
+ return false;
+ }
+
+ if(!fprintf(fp, "<tasklist>\n")) {
+ fclose(fp);
+ return false;
+ }
+
+ TaskList::iterator it;
+ for(it = tasklist.begin(); it != tasklist.end(); it++) {
+ task_t t = *it;
+ int r = 1;
+
+// printf("Flushing task %d\n", t.id);
+
+ r |= fprintf(fp, " <task id=\"%d\" parent_id=\"%d\">\n", t.id, t.parent_id);
+ r |= fprintf(fp, " <title>%s</title>\n", xml_encode(t.title).c_str());
+ r |= fprintf(fp, " <desc>%s</desc>\n", xml_encode(t.desc).c_str());
+ r |= fprintf(fp, " </task>)\n");
+
+ if(!r) {
+ fclose(fp);
+ return false;
+ }
+ }
+
+ if(!fprintf(fp, "</tasklist>\n")) {
+ fclose(fp);
+ return false;
+ }
+
+ fclose(fp);
+ return true;
+}