karm

plannerparser.cpp

00001 //
00002 // C++ Implementation: plannerparser
00003 //
00004 // Description: 
00005 /*
00006 
00007 this class is here to import tasks from a planner project file to karm.
00008 the import shall not be limited to karm (kPlaTo sends greetings)
00009 it imports planner's top-level-tasks on the same level-depth as current_item.
00010 if there is no current_item, planner's top-level-tasks will become top-level-tasks in karm.
00011 it imports as well the level-depth of each task, as its name, as its percent-complete.
00012 test cases:
00013  - deleting all tasks away, then import!
00014  - having started with an empty ics, import!
00015  - with current_item being a top-level-task, import!
00016  - with current_item being a subtask, import!
00017 
00018 
00019  Author: Thorsten Staerk <Thorsten@Staerk.de>, (C) 2004
00020 
00021  Copyright: See COPYING file that comes with this distribution
00022 
00023 
00024 */
00025 
00026 #include "plannerparser.h"
00027 
00028 
00029   PlannerParser::PlannerParser(TaskView * tv)
00030   // if there is a task one level above current_item, make it the father of all imported tasks. Set level accordingly.
00031   // import as well if there a no task in the taskview as if there are.
00032   // if there are, put the top-level tasks of planner on the same level as current_item.
00033   // So you have the chance as well to have the planner tasks at top-level as at a whatever-so-deep sublevel.
00034   {
00035     kdDebug() << "entering constructor to import planner tasks" << endl;
00036     _taskView=tv;
00037     level=0;
00038     if (_taskView->current_item()) if (_taskView->current_item()->parent()) 
00039     {
00040       task = _taskView->current_item()->parent(); 
00041       level=1;
00042     }
00043   }
00044   
00045   bool PlannerParser::startDocument()
00046   {
00047     withInTasks=false; // becomes true as soon as parsing occurres <tasks>
00048     return true;
00049   }
00050   
00051   bool PlannerParser::startElement( const QString&, const QString&, const QString& qName, const QXmlAttributes& att )
00052   {
00053     kdDebug() << "entering startElement" << endl;
00054     QString taskName;
00055     int     taskComplete=0;
00056     
00057     // only <task>s within <tasks> are processed
00058     if (qName == QString::fromLatin1("tasks")) withInTasks=true;
00059     if ((qName == QString::fromLatin1("task")) && (withInTasks))
00060     {
00061     
00062       // find out name and percent-complete
00063       for (int i=0; i<att.length(); i++)
00064       {
00065         if (att.qName(i) == QString::fromLatin1("name")) taskName=att.value(i);
00066         if (att.qName(i)==QString::fromLatin1("percent-complete")) taskComplete=att.value(i).toInt();
00067       }
00068     
00069       // at the moment, task is still the old task or the old father task (if an endElement occurred) or not existing (if the
00070       // new task is a top-level-task). Make task the parenttask, if existing.
00071       DesktopList dl;
00072       if (level++>0) 
00073       {
00074         parentTask=task;
00075         task = new Task(taskName, 0, 0, dl, parentTask);
00076         task->setUid(_taskView->storage()->addTask(task, parentTask));
00077       }
00078       else
00079       {
00080         task = new Task(taskName, 0, 0, dl, _taskView);
00081         kdDebug() << "added" << taskName << endl;
00082         task->setUid(_taskView->storage()->addTask(task, 0));     
00083       }
00084     
00085       task->setPercentComplete(taskComplete, _taskView->storage());
00086     }
00087     return true;
00088  }
00089     
00090   bool PlannerParser::endElement( const QString&, const QString&, const QString& qName)
00091   {
00092     // only <task>s within <tasks> increased level, so only decrease for <task>s within <tasks>
00093     if (withInTasks)
00094     {
00095       if (qName=="task")  if (level-->=0) task=task->parent();
00096       if (qName=="tasks") withInTasks=false;
00097     }
00098     return true;
00099   }
00100 
KDE Home | KDE Accessibility Home | Description of Access Keys