From f7dc7c17af52e8300cb188c4fb3e4a8b1638e8f9 Mon Sep 17 00:00:00 2001 From: Jonas Suhr Christensen Date: Thu, 22 Mar 2012 16:31:28 +0100 Subject: Fixed order of task in init. Now are tasks only (hopefully) added after its parent. Added write and read. --- src/task.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/task.cc') 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 + +#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, "\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, " \n", t.id, t.parent_id); + r |= fprintf(fp, " %s\n", xml_encode(t.title).c_str()); + r |= fprintf(fp, " %s\n", xml_encode(t.desc).c_str()); + r |= fprintf(fp, " )\n"); + + if(!r) { + fclose(fp); + return false; + } + } + + if(!fprintf(fp, "\n")) { + fclose(fp); + return false; + } + + fclose(fp); + return true; +} -- cgit v1.2.3