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