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