2 * Copyright (C) 2004 by Thorsten Staerk <dev@staerk.de>
3 * 2007 the ktimetracker developers
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the
17 * Free Software Foundation, Inc.
18 * 51 Franklin Street, Fifth Floor
19 * Boston, MA 02110-1301 USA.
25 this class is here to import tasks from a planner project file to karm.
26 the import shall not be limited to karm (kPlaTo sends greetings)
27 it imports planner's top-level-tasks on the same level-depth as currentItem.
28 if there is no currentItem, planner's top-level-tasks will become top-level-tasks in karm.
29 it imports as well the level-depth of each task, as its name, as its percent-complete.
31 - deleting all tasks away, then import!
32 - having started with an empty ics, import!
33 - with currentItem being a top-level-task, import!
34 - with currentItem being a subtask, import!
37 #include "plannerparser.h"
42 PlannerParser::PlannerParser(TaskView
* tv
)
43 // if there is a task one level above currentItem, make it the father of all imported tasks. Set level accordingly.
44 // import as well if there a no task in the taskview as if there are.
45 // if there are, put the top-level tasks of planner on the same level as currentItem.
46 // So you have the chance as well to have the planner tasks at top-level as at a whatever-so-deep sublevel.
48 kDebug() <<"entering constructor to import planner tasks";
51 if (_taskView
->currentItem()) if (_taskView
->currentItem()->parent())
53 task
= _taskView
->currentItem()->parent();
58 bool PlannerParser::startDocument()
60 withInTasks
=false; // becomes true as soon as parsing occurres <tasks>
64 bool PlannerParser::startElement( const QString
&, const QString
&, const QString
& qName
, const QXmlAttributes
& att
)
66 kDebug() << "entering function";
70 // only <task>s within <tasks> are processed
71 if (qName
== QString::fromLatin1("tasks")) withInTasks
=true;
72 if ((qName
== QString::fromLatin1("task")) && (withInTasks
))
75 // find out name and percent-complete
76 for (int i
=0; i
<att
.length(); i
++)
78 if (att
.qName(i
) == QString::fromLatin1("name")) taskName
=att
.value(i
);
79 if (att
.qName(i
)==QString::fromLatin1("percent-complete")) taskComplete
=att
.value(i
).toInt();
82 // at the moment, task is still the old task or the old father task (if an endElement occurred) or not existing (if the
83 // new task is a top-level-task). Make task the parenttask, if existing.
88 task
= new Task(taskName
, 0, 0, dl
, parentTask
);
89 task
->setUid(_taskView
->storage()->addTask(task
, parentTask
));
93 task
= new Task(taskName
, 0, 0, dl
, _taskView
);
94 kDebug() <<"added" << taskName
;
95 task
->setUid(_taskView
->storage()->addTask(task
, 0));
98 task
->setPercentComplete(taskComplete
, _taskView
->storage());
103 bool PlannerParser::endElement( const QString
&, const QString
&, const QString
& qName
)
105 // only <task>s within <tasks> increased level, so only decrease for <task>s within <tasks>
108 if (qName
=="task") if (level
-->=0) task
=task
->parent();
109 if (qName
=="tasks") withInTasks
=false;