karm

plannerparser.cpp
1//
2// C++ Implementation: plannerparser
3//
4// Description:
5/*
6
7this class is here to import tasks from a planner project file to karm.
8the import shall not be limited to karm (kPlaTo sends greetings)
9it imports planner's top-level-tasks on the same level-depth as current_item.
10if there is no current_item, planner's top-level-tasks will become top-level-tasks in karm.
11it imports as well the level-depth of each task, as its name, as its percent-complete.
12test cases:
13 - deleting all tasks away, then import!
14 - having started with an empty ics, import!
15 - with current_item being a top-level-task, import!
16 - with current_item being a subtask, import!
17
18
19 Author: Thorsten Staerk <Thorsten@Staerk.de>, (C) 2004
20
21 Copyright: See COPYING file that comes with this distribution
22
23
24*/
25
26#include "plannerparser.h"
27
28
30 // if there is a task one level above current_item, make it the father of all imported tasks. Set level accordingly.
31 // import as well if there a no task in the taskview as if there are.
32 // if there are, put the top-level tasks of planner on the same level as current_item.
33 // So you have the chance as well to have the planner tasks at top-level as at a whatever-so-deep sublevel.
34 {
35 kdDebug() << "entering constructor to import planner tasks" << endl;
36 _taskView=tv;
37 level=0;
38 if (_taskView->current_item()) if (_taskView->current_item()->parent())
39 {
40 task = _taskView->current_item()->parent();
41 level=1;
42 }
43 }
44
46 {
47 withInTasks=false; // becomes true as soon as parsing occurres <tasks>
48 return true;
49 }
50
51 bool PlannerParser::startElement( const TQString&, const TQString&, const TQString& qName, const TQXmlAttributes& att )
52 {
53 kdDebug() << "entering startElement" << endl;
54 TQString taskName;
55 int taskComplete=0;
56
57 // only <task>s within <tasks> are processed
58 if (qName == TQString::fromLatin1("tasks")) withInTasks=true;
59 if ((qName == TQString::fromLatin1("task")) && (withInTasks))
60 {
61
62 // find out name and percent-complete
63 for (int i=0; i<att.length(); i++)
64 {
65 if (att.qName(i) == TQString::fromLatin1("name")) taskName=att.value(i);
66 if (att.qName(i)==TQString::fromLatin1("percent-complete")) taskComplete=att.value(i).toInt();
67 }
68
69 // at the moment, task is still the old task or the old father task (if an endElement occurred) or not existing (if the
70 // new task is a top-level-task). Make task the parenttask, if existing.
71 DesktopList dl;
72 if (level++>0)
73 {
74 parentTask=task;
75 task = new Task(taskName, 0, 0, dl, parentTask);
76 task->setUid(_taskView->storage()->addTask(task, parentTask));
77 }
78 else
79 {
80 task = new Task(taskName, 0, 0, dl, _taskView);
81 kdDebug() << "added" << taskName << endl;
82 task->setUid(_taskView->storage()->addTask(task, 0));
83 }
84
85 task->setPercentComplete(taskComplete, _taskView->storage());
86 }
87 return true;
88 }
89
90 bool PlannerParser::endElement( const TQString&, const TQString&, const TQString& qName)
91 {
92 // only <task>s within <tasks> increased level, so only decrease for <task>s within <tasks>
93 if (withInTasks)
94 {
95 if (qName=="task") if (level-->=0) task=task->parent();
96 if (qName=="tasks") withInTasks=false;
97 }
98 return true;
99 }
100
TQString addTask(const Task *task, const Task *parent)
Add this task from iCalendar file.
PlannerParser(TaskView *tv)
Stores the active TaskView in this parser.
bool endElement(const TQString &, const TQString &, const TQString &qName)
given by the framework from qxml.
bool startElement(const TQString &, const TQString &, const TQString &qName, const TQXmlAttributes &att)
given by the framework from qxml.
bool startDocument()
given by the framework from qxml.
Container and interface for the tasks.
Definition: taskview.h:43
KarmStorage * storage()
Returns a pointer to storage object.
Definition: taskview.cpp:114
Task * current_item() const
Return the current item in the view, cast to a Task pointer.
Definition: taskview.cpp:177
A class representing a task.
Definition: task.h:42
void setPercentComplete(const int percent, KarmStorage *storage)
Update percent complete for this task.
Definition: task.cpp:149
void setUid(const TQString uid)
Set unique id for the task.
Definition: task.cpp:128