summaryrefslogtreecommitdiff
path: root/src/tasktree.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tasktree.cc')
-rw-r--r--src/tasktree.cc58
1 files changed, 55 insertions, 3 deletions
diff --git a/src/tasktree.cc b/src/tasktree.cc
index fc84efa..2576600 100644
--- a/src/tasktree.cc
+++ b/src/tasktree.cc
@@ -27,10 +27,39 @@
*/
#include "tasktree.h"
+#include "xmlparser.h"
+
#include "debug.h"
+#include "xml_encode_decode.h"
+
#define ROOT_PARENT_ID -1
+static inline std::string id2str(taskid_t id)
+{
+ char buf[32];
+ sprintf(buf, "%u", id);
+ return buf;
+}
+
+std::string node::toXML(std::string prefix)
+{
+ std::string xml;
+
+ xml += prefix + "<task id=\""+id2str(id)+"\">\n";
+ xml += prefix + " <title>" + xml_encode(data.title) + "</title>\n";
+ xml += prefix + " <children>\n";
+ NodeList::iterator ni = children.begin();
+ while(ni != children.end()) {
+ xml += (*ni)->toXML(prefix + " ");
+ ni++;
+ }
+ xml += prefix + " </children>\n";
+ xml += prefix + "</task>\n";
+
+ return xml;
+}
+
static void concatTaskIdLists(TaskIdList& pre, TaskIdList& post) {
pre.insert(pre.end(), post.begin(), post.end());
// for(TaskIdList::iterator it = post.begin();
@@ -187,7 +216,7 @@ task_t TaskTree::data(taskid_t id)
try {
node_t* node = id2node.at(id);
task_t tmp = node->data;
- t.id = tmp.id;
+ t.id = node->id;
t.title = tmp.title;
// printf("!!!!t.id and tmp.id in data: %d and %d\n", t.id, tmp.id);
if(node->parent) t.parentid = node->parent->id;
@@ -267,14 +296,18 @@ node_t* TaskTree::createNode(taskid_t id) {
}
void TaskTree::insertChild(node_t* parent, node_t* child) {
- parent->children.push_back(child);
+ if(parent) parent->children.push_back(child);
+ else {
+ rootid = child->id;
+ root = child;
+ }
child->parent = parent;
}
static void printNode(node_t* node, std::string prefix) {
if(!node) return;
task_t t = node->data;
- printf("%s- %u - %s (%p)\n", prefix.c_str(), t.id, t.title.c_str(), node);
+ printf("%s- %u - %s (%p)\n", prefix.c_str(), node->id, t.title.c_str(), node);
NodeList::iterator it;
for(it = node->children.begin(); it != node->children.end(); it++) {
@@ -287,6 +320,25 @@ void TaskTree::toStdOut() {
printNode(root, "");
}
+std::string TaskTree::toXML()
+{
+ node_t *root = id2node.at(rootid);
+
+ std::string xml;
+ xml += "<?xml version='1.0' encoding='UTF-8'?>\n";
+ xml += "<tasktree>\n";
+ xml += root->toXML(" ");
+ xml += "</tasktree>";
+
+ return xml;
+}
+
+void TaskTree::fromXML(std::string xml)
+{
+ XmlParser p(this);
+ p.parse(xml.c_str(), xml.size());
+}
+
#ifdef TEST_TASKTREE
//Additional dependency files