kplato

kptreportview.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 - 2005 Dag Andersen <danders@get2net.dk>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation;
00007    version 2 of the License.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kptreportview.h"
00021 
00022 #include "kptview.h"
00023 #include "kptpart.h"
00024 #include "kptcontext.h"
00025 
00026 #include <mreportviewer.h>
00027 #include <mpagecollection.h>
00028 
00029 #include <KoStore.h>
00030 
00031 #include <kdebug.h>
00032 #include <kaction.h>
00033 #include <kstdaction.h>
00034 #include <ktoolbar.h>
00035 #include <kstandarddirs.h>
00036 #include <kurl.h>
00037 #include <kmessagebox.h>
00038 #include <kio/netaccess.h>
00039 #include <klocale.h>
00040 #include <kglobal.h>
00041 #include <kdesktopfile.h>
00042 #include <kfiledialog.h>
00043 
00044 #include <qfile.h>
00045 #include <qfileinfo.h>
00046 #include <qheader.h>
00047 #include <qpopupmenu.h>
00048 #include <qlayout.h>
00049 #include <qdom.h>
00050 #include <qstringlist.h>
00051 
00052 namespace KPlato
00053 {
00054 
00055 class ReportTagsPrivate {
00056 public:
00057 
00058     ReportTagsPrivate()
00059     :   m_project(0),
00060         m_task(0),
00061         m_resourcegroup(0),
00062         m_resource(0),
00063         alltasksLevel("-1"),
00064         summarytasksLevel("-1"),
00065         tasksLevel("-1"),
00066         milestonesLevel("-1"),
00067         resourcegroupsLevel("-1"),
00068         resourcesLevel("-1")
00069     {}
00070 
00071     ~ReportTagsPrivate() {}
00072 
00073     QString getData(QString source, QString tag) const {
00074         if (tag.contains("."))
00075             return getData(tag);
00076 
00077         return getData(source + "." + tag);
00078     }
00079 
00080     QString getData(QString tag) const {
00081         //kdDebug()<<k_funcinfo<<"tag="<<tag<<endl;
00082         KLocale *l = KGlobal::locale();
00083         if (!tag.contains('.')) {
00084             // global tags
00085             if (tag == "currentdate") {
00086                 return l->formatDate(QDate::currentDate(), true);
00087             }
00088             return QString::null;
00089         }
00090         if (tag.section(".", 0, 0) == "project") {
00091             if (tag.section(".", 1, 1) == "name")
00092                 return (m_project ? m_project->name() : QString::null);
00093             if (tag.section(".", 1, 1) == "leader")
00094                 return (m_project ? m_project->leader() : QString::null);
00095 
00096         } else if (tag.section(".", 0, 0) == "task") {
00097             if (tag.section(".", 1, 1) == "name")
00098                 return (m_task ? m_task->name() : QString::null);
00099             if (tag.section(".", 1, 1) == "responsible")
00100                 return (m_task ? m_task->leader() : QString::null);
00101             else if (tag.section(".", 1, 1) == "wbs")
00102                 return (m_task ? m_task->wbs() : QString::null);
00103             else if (tag.section(".", 1, 1) == "start")
00104                 return (m_task ? l->formatDateTime(m_task->startTime()) : QString::null);
00105             else if (tag.section(".", 1, 1) == "starttime")
00106                 return (m_task ? l->formatTime(m_task->startTime().time()) : QString::null);
00107             else if (tag.section(".", 1, 1) == "startdate")
00108                 return (m_task ? l->formatDate(m_task->startTime().date(), true) : QString::null);
00109             else if (tag.section(".", 1, 1) == "duration") {
00110                     return (m_task ? m_task->duration().toString(Duration::Format_i18nDayTime) : QString::null);
00111             } else if (tag.section(".", 1, 1) == "plannedcost") {
00112                 return (m_task ? l->formatMoney(m_task->plannedCost()) : QString::null);
00113             }
00114         } else if (tag.section(".", 0, 0) == "resourcegroup") {
00115             if (tag.section(".", 1, 1) == "name")
00116                 return (m_resourcegroup ? m_resourcegroup->name() : QString::null);
00117         
00118         } else if (tag.section(".", 0, 0) == "resource") {
00119             if (tag.section(".", 1, 1) == "name")
00120                 return (m_resource ? m_resource->name() : QString::null);
00121             if (tag.section(".", 1, 1) == "type")
00122                 return (m_resource ? m_resource->typeToString() : QString::null);
00123             if (tag.section(".", 1, 1) == "email")
00124                 return (m_resource ? m_resource->email() : QString::null);
00125             if (tag.section(".", 1, 1) == "availablefrom")
00126                 return (m_resource ? l->formatDate(m_resource->availableFrom().date(), true) : QString::null);
00127             if (tag.section(".", 1, 1) == "availableuntil")
00128                 return (m_resource ? l->formatDate(m_resource->availableUntil().date(), true) : QString::null);
00129             if (tag.section(".", 1, 1) == "units")
00130                 return (m_resource ? QString("%1%").arg(m_resource->units()) : QString::null);
00131             if (tag.section(".", 1, 1) == "normalrate")
00132                 return (m_resource ? l->formatMoney(m_resource->normalRate()) : QString::null);
00133             if (tag.section(".", 1, 1) == "overtimerate")
00134                 return (m_resource ? l->formatMoney(m_resource->overtimeRate()) : QString::null);
00135         }
00136     return QString::null;
00137     }
00138 
00139     Project *m_project;
00140     Task *m_task;
00141     ResourceGroup *m_resourcegroup;
00142     Resource *m_resource;
00143 
00144     QString alltasksLevel;
00145     QStringList alltasksProps;
00146     QString summarytasksLevel;
00147     QStringList summarytasksProps;
00148     QString tasksLevel;
00149     QStringList tasksProps;
00150     QString milestonesLevel;
00151     QStringList milestonesProps;
00152     QString resourcegroupsLevel;
00153     QStringList resourcegroupsProps;
00154     QString resourcesLevel;
00155     QStringList resourcesProps;
00156 
00157 };
00158 
00159 class KugarReportViewer : public Kugar::MReportViewer {
00160 public:
00161     KugarReportViewer(QWidget *parent = 0, const char *name = 0)
00162     : MReportViewer(parent, name)
00163     {}
00164     
00165     int currentPage() {
00166         return report ? report->getCurrentIndex() : 0;
00167     }
00168     int pageCount() {
00169         return report ? report->pageCount() : 0;
00170     }
00171 };
00172 
00173 ReportView::ReportView(View *view, QWidget *parent)
00174     : QSplitter(parent),
00175     m_mainview(view),
00176     m_reportTags(0)
00177 {
00178     //kdDebug()<<k_funcinfo<<endl;
00179     m_reportList = new KListView(this);
00180 #if KDE_IS_VERSION(3,3,9)
00181     m_reportList->setShadeSortColumn(false);
00182 #endif
00183     m_reportList->addColumn(i18n("Report Template"));
00184     m_reportList->header()->setStretchEnabled(true, 0);
00185     m_reportList->header()->setSortIndicator(0);
00186     
00187     m_reportview = new KugarReportViewer(this);
00188 
00189     initReportList();
00190     
00191     connect(m_reportList, SIGNAL(clicked(QListViewItem*)), SLOT(slotReportListClicked(QListViewItem*)));
00192     connect(m_reportList, SIGNAL(selectionChanged(QListViewItem*)), SLOT(slotReportListSelectionChanged(QListViewItem*)));
00193 
00194     //setCentralWidget(m_reportview);
00195 
00196     // Create the user interface.
00197     //KStdAction::print(this,SLOT(slotPrint()),actionCollection());
00198     //KStdAction::quit(this,SLOT(slotFileQuit()),actionCollection());
00199 
00200 //  KStdAction::showToolbar(this,SLOT(slotViewToolBar()),actionCollection());
00201 //  KStdAction::showStatusbar(this,SLOT(slotViewStatusBar()),actionCollection());
00202 
00203 //  statusBar();
00204 
00205 //  createGUI();
00206 
00207 }
00208 
00209 
00210 ReportView::~ReportView() {
00211    //safe
00212    delete m_reportTags;
00213 }
00214 
00215 void ReportView::initReportList() {
00216 //FIXME: We need a solution that takes care project specific reports.
00217     //kdDebug()<<k_funcinfo<<endl;
00218     QStringList list;
00219     m_reportList->clear();
00220     KStandardDirs std;
00221     QStringList reportDesktopFiles = std.findAllResources("data", "kplato/reports/*.desktop", true, true);
00222     for (QStringList::iterator it = reportDesktopFiles.begin(); it != reportDesktopFiles.end(); ++it) {
00223         KDesktopFile file((*it), true);
00224         QString name = file.readName();
00225         if (!name.isNull()) {
00226             //kdDebug()<<" file: "<<*it<<" name="<<name<<endl;
00227             QString url = file.readURL();
00228             if (!url.isNull()) {
00229                 if (url.left(1) != "/" || url.left(6) != "file:/") {
00230                     QString path = (*it).left((*it).findRev('/', -1)+1); // include '/'
00231                     url = path + url;
00232                 }
00233                 m_reportList->insertItem(new ReportItem(m_reportList, name, url));
00234             }
00235         }
00236     }
00237 }
00238 
00239 void ReportView::draw(const QString &report) {
00240     //kdDebug()<<k_funcinfo<<endl;
00241     m_reportview->clearReport();
00242     m_reportTags = new ReportTagsPrivate();
00243     getTemplateFile(report);
00244     m_reportview->setReportTemplate(templateDoc.toString());
00245     setReportData();
00246     m_reportview->renderReport();
00247     m_reportview->show();
00248     delete m_reportTags;
00249     m_reportTags=0L;
00250     enableNavigationBtn();
00251 }
00252 
00253 void ReportView::setup(KPrinter &printer) {
00254     //kdDebug()<<k_funcinfo<<endl;
00255     m_reportview->setupPrinter(printer);
00256 }
00257 
00258 void ReportView::print(KPrinter &printer) {
00259     //kdDebug()<<k_funcinfo<<endl;
00260     m_reportview->printReport(printer);
00261 }
00262 
00263 // Generate report data based on info from the template file
00264 void ReportView::setReportData() {
00265     QString s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
00266     s+="<KugarData>\n";
00267     s += setReportDetail();
00268     s+="</KugarData>\n";
00269     //kdDebug()<<s<<endl;
00270     m_reportview->setReportData(s);
00271 }
00272 
00273 QString ReportView::setReportDetail() {
00274     //kdDebug()<<k_funcinfo<<endl;
00275     QString s;
00276     if (m_reportTags->alltasksLevel != "-1") {
00277         //kdDebug()<<k_funcinfo<<"alltasks level="<<m_reportTags->alltasksLevel<<endl;
00278         if (m_reportTags->summarytasksLevel == "-1") {
00279             m_reportTags->summarytasksLevel = m_reportTags->alltasksLevel;
00280             m_reportTags->summarytasksProps = m_reportTags->alltasksProps;
00281         }
00282         if (m_reportTags->tasksLevel == "-1") {
00283             m_reportTags->tasksLevel = m_reportTags->alltasksLevel;
00284             m_reportTags->tasksProps = m_reportTags->alltasksProps;
00285         }
00286         if (m_reportTags->milestonesLevel == "-1") {
00287             m_reportTags->milestonesLevel = m_reportTags->alltasksLevel;
00288             m_reportTags->milestonesProps = m_reportTags->alltasksProps;
00289         }
00290         s+= setTaskChildren(&(mainView()->getProject()));
00291     
00292     } else if (m_reportTags->summarytasksLevel == "0") {
00293         // make a report that has summarytasks as starting points
00294         QPtrListIterator<Node> it(mainView()->getProject().childNodeIterator());
00295         for (; it.current(); ++it) {
00296             if (it.current()->type() == Node::Type_Summarytask) {
00297                 s += setTaskDetail(it.current());
00298                 // Now do subtasks
00299                 s+= setTaskChildren(it.current());
00300             }
00301         }
00302 
00303     } else if (m_reportTags->tasksLevel == "0") {
00304         // make a report that has tasks as starting points
00305         QPtrListIterator<Node> it(mainView()->getProject().childNodeIterator());
00306         for (; it.current(); ++it) {
00307             if (it.current()->type() == Node::Type_Task) {
00308                 s += setTaskDetail(it.current());
00309             }
00310             if (it.current()->type() == Node::Type_Summarytask) {
00311                 s+= setTaskChildren(it.current());
00312                 if (m_reportTags->summarytasksLevel != "-1") {
00313                     s += setTaskDetail(it.current());
00314                 }
00315             }
00316         }
00317 
00318     } else if (m_reportTags->milestonesLevel == "0") {
00319 
00320     } else if (m_reportTags->resourcegroupsLevel == "0") {
00321         // make a report that has resourcegroups as starting points
00322         QPtrListIterator<ResourceGroup> it(mainView()->getProject().resourceGroups());
00323         for (; it.current(); ++it) {
00324             s += setResourceGroupDetail(it.current());
00325         }
00326 
00327     } else if (m_reportTags->resourcesLevel == "0") {
00328         // make a report that has resources as starting points
00329         QPtrListIterator<ResourceGroup> it(mainView()->getProject().resourceGroups());
00330         for (; it.current(); ++it) {
00331             QPtrListIterator<Resource> rit(it.current()->resources());
00332             for (; rit.current(); ++rit) {
00333                 s += setResourceDetail(rit.current());
00334             }
00335         }
00336     }
00337     //kdDebug()<<k_funcinfo<<s<<endl;
00338     return s;
00339 }
00340 
00341 QString ReportView::setResourceGroupDetail(ResourceGroup *group) {
00342     //kdDebug()<<k_funcinfo<<group->name()<<endl;
00343     QString s;
00344     if (m_reportTags->resourcegroupsLevel != "-1") {
00345         m_reportTags->m_resourcegroup = group;
00346         //kdDebug()<<k_funcinfo<<group->name()<<": level="<<m_reportTags->resourcegroupsLevel<<endl;
00347         s = setDetail("resourcegroup", m_reportTags->resourcegroupsProps, m_reportTags->resourcegroupsLevel);
00348         QPtrListIterator<Resource> rit(group->resources());
00349         for (; rit.current(); ++rit) {
00350             s += setResourceDetail(rit.current());
00351         }
00352     }
00353     return s;
00354 }
00355 
00356 QString ReportView::setResourceDetail(Resource *res) {
00357     //kdDebug()<<k_funcinfo<<res->name()<<endl;
00358     QString s;
00359     if (m_reportTags->resourcesLevel != "-1") {
00360         m_reportTags->m_resource = res;
00361         //kdDebug()<<k_funcinfo<<res->name()<<": level="<<m_reportTags->resourcesLevel<<endl;
00362         s = setDetail("resource", m_reportTags->resourcesProps, m_reportTags->resourcesLevel);
00363     }
00364     return s;
00365 }
00366 
00367 QString ReportView::setTaskChildren(Node *node) {
00368     //kdDebug()<<k_funcinfo<<endl;
00369     QString s;
00370     QPtrListIterator<Node> it(node->childNodeIterator());
00371     for (; it.current(); ++it) {
00372         s += setTaskDetail(it.current());
00373         if (it.current()->type() == Node::Type_Summarytask)
00374             s+= setTaskChildren(it.current());
00375     }
00376     return s;
00377 }
00378 
00379 QString ReportView::setTaskDetail(Node *node) {
00380     //kdDebug()<<k_funcinfo<<endl;
00381     QString s;
00382     QStringList props;
00383     QString level = "-1";
00384     if (node->type() == Node::Type_Task) {
00385         props = m_reportTags->tasksProps;
00386         level = m_reportTags->tasksLevel;
00387     } else if (node->type() == Node::Type_Summarytask) {
00388         props = m_reportTags->summarytasksProps;
00389         level = m_reportTags->summarytasksLevel;
00390     } else if (node->type() == Node::Type_Milestone) {
00391         props = m_reportTags->milestonesProps;
00392         level = m_reportTags->milestonesLevel;
00393     }
00394     if (level != "-1") {
00395         m_reportTags->m_task = static_cast<Task *>(node);
00396         s = setDetail("task", props, level);
00397     }
00398     return s;
00399 }
00400 
00401 QString ReportView::setDetail(const QString & source, QStringList &properties, QString &level) {
00402     QString s = "<Row";
00403     s += " level=\"" + level + "\"";
00404     for (unsigned int i=0; i < properties.count(); ++i) {
00405         //kdDebug()<<k_funcinfo<<"Property: "<<properties[i]<<endl;
00406         s += " " + properties[i].section('=', 0, 0) + "="; // Field
00407         QString data = m_reportTags->getData(source, properties[i].section('=', 1, 1));
00408         if (data.isNull())
00409             data = "";
00410         data = data.replace('<', "&lt;");
00411         data = data.replace('>', "&gt;");
00412         data = data.replace('"', "&quot;");
00413         
00414         s += "\"" + data + "\""; // Property
00415         //kdDebug()<<k_funcinfo<<s<<endl;
00416     }
00417     s += "/>\n";
00418     return s;
00419 }
00420 
00421 // Most of this is from KoDocument::loadNativeFormat
00422 void ReportView::openTemplateFile(const QString &file) {
00423     if (!QFileInfo(file).isFile()) {
00424         KMessageBox::sorry( this, i18n("Cannot find report template file!"),
00425                                                         i18n("Generate Report"));
00426         return;
00427     }
00428     QFile in;
00429     in.setName(file);
00430     if (!in.open(IO_ReadOnly)) {
00431         KMessageBox::sorry( this, i18n("Cannot open report template file!"),
00432                                                         i18n("Generate Report"));
00433         return;
00434     }
00435     // Try to find out whether it is a mime multi part file
00436     char buf[5];
00437     if ( in.readBlock( buf, 4 ) < 4 )
00438     {
00439         in.close();
00440         KMessageBox::sorry( this, i18n("Cannot read report template file!"),
00441                                                         i18n("Generate Report"));
00442         return;
00443     }
00444 
00445     if (strncasecmp( buf, "<?xm", 4 ) == 0) { // xml file?
00446         in.at(0);
00447         // fake
00448         //m_reportview->setReportTemplate(&in);
00449         loadTemplate(in);
00450         in.close();
00451         return;
00452     }
00453     in.close();
00454     KoStore* store=KoStore::createStore(file, KoStore::Read);
00455     if (!store)
00456     {
00457         KMessageBox::sorry( this, i18n("Cannot open report template file!"),
00458                                                     i18n("Generate Report"));
00459         return;
00460     }
00461     bool b = store->open("maindoc.xml");
00462     if ( !b )
00463     {
00464         KMessageBox::sorry( this, i18n("Cannot find the proper report template file!"),
00465                                                     i18n("Generate Report"));
00466         delete store;
00467         return;
00468     }
00469     loadTemplate(*(store->device()));
00470     store->close();
00471 }
00472 
00473 void ReportView::loadTemplate(QIODevice &dev) {
00474     QString errorMsg;
00475     int errorLine;
00476     int errorColumn;
00477     if (!templateDoc.setContent( &dev , &errorMsg, &errorLine, &errorColumn)) {
00478         QString msg = "Parsing template file failed with ";
00479         KMessageBox::sorry( this, msg + errorMsg, i18n("Generate Report"));
00480         return;
00481     }
00482     loadTemplate(templateDoc);
00483 }
00484 
00485 void ReportView::loadTemplate(QDomDocument &doc) {
00486     QDomNode tpl;
00487     QDomNode child;
00488     for (tpl = doc.firstChild(); !tpl.isNull(); tpl = tpl.nextSibling())
00489         if (tpl.nodeName() == "KugarTemplate")
00490             break;
00491 
00492     if (tpl.isNull())
00493         return;
00494 
00495     m_reportTags->m_project = &(mainView()->getPart()->getProject());
00496     // Get all the child report elements
00497     QDomNodeList children = tpl.childNodes();
00498     int childCount = children.length();
00499 
00500     for(int j = 0; j < childCount; j++){
00501         child = children.item(j);
00502         if(child.nodeType() == QDomNode::ElementNode) {
00503             QDomElement e = child.toElement();
00504             //kdDebug()<<child.nodeName()<<endl;
00505             // Report Header
00506             if(child.nodeName() == "ReportHeader") {
00507                 handleHeader(child);
00508             } else if (child.nodeName() == "PageHeader") {
00509                 handleHeader(child);
00510             } else if(child.nodeName() == "DetailHeader") {
00511                 handleHeader(child);
00512             } else if(child.nodeName() == "Detail") {
00513                 handleDetail(e);
00514             } else if(child.nodeName() == "DetailFooter") {
00515                 handleHeader(child);
00516             } else if(child.nodeName() == "PageFooter") {
00517                 handleHeader(child);
00518             } else if(child.nodeName() == "ReportFooter") {
00519                 handleHeader(child);
00520             } else if(child.nodeName() == "KPlato") {
00521                 handleKPlato(e);
00522             }
00523         }
00524     }
00525 }
00526 
00527 void ReportView::handleHeader(QDomNode &node) {
00528     QDomNode child;
00529     QDomNodeList children = node.childNodes();
00530     int childCount = children.length();
00531     for (int j = 0; j < childCount; j++) {
00532         child = children.item(j);
00533         if (child.nodeName() == "Label") {
00534             QDomNode n = child.attributes().namedItem("Text");
00535             QString s = n.nodeValue();
00536             if (!s.isEmpty()) {
00537                 // Translate labels
00538                 s = i18n(n.nodeValue().latin1()); //NOTE: Not sure if latin1 is ok
00539             }
00540             QString r = s;
00541             int i = 0, j = 0;
00542             do {
00543                 i = j;
00544                 if ( ((i = s.find('[', i)) != -1) && ((j = s.find(']', i+1)) != -1) ) {
00545                     QString tag = s.mid(i, j-i+1);
00546                     QString data = m_reportTags->getData(tag.mid(1, tag.length()-2));
00547                     r = r.replace(tag, data);
00548                 }
00549             } while (i != -1 && j != -1);
00550             n.setNodeValue(r);
00551             //kdDebug()<<" new Text="<<n.nodeValue()<<endl;
00552         } else if (child.nodeName() == "Field") {
00553             QDomElement e = child.toElement();
00554             if (!e.isElement()) {
00555                 continue; // !!!!!
00556             }
00557             QString s = e.attribute("Field");
00558             QString data = m_reportTags->getData(s);
00559             e.setAttribute("Text", data);
00560             //kdDebug()<<" new Text="<<e.attribute("Text")<<endl;
00561         }
00562     }
00563 }
00564 
00565 QStringList ReportView::getProperties(QDomElement &elem) {
00566     QStringList props;
00567     QDomNodeList list(elem.childNodes());
00568     int childCount = list.length();
00569     for (int j = 0; j < childCount; j++) {
00570         QDomNode child = list.item(j);
00571         if (child.nodeName() == "Field") {
00572             props.append(child.attributes().namedItem("Field").nodeValue()+"="+child.attributes().namedItem("Field").nodeValue());
00573         }
00574     }
00575     return props;
00576 }
00577 
00578 void ReportView::handleKPlato(QDomElement &elem) {
00579     QDomNodeList list(elem.childNodes());
00580     int childCount = list.length();
00581     for (int j = 0; j < childCount; j++) {
00582         QDomNode child = list.item(j);
00583         if (child.nodeName() == "Detail") {
00584             QDomElement e = child.toElement();
00585             if (!e.isElement()) {
00586                 continue; // !!!!!
00587             }
00588             QString source = e.attribute("SelectFrom");
00589             QString level = e.attribute("Level", "-1");
00590             //kdDebug()<<k_funcinfo<<"SelectFrom="<<source<<" Level="<<level<<endl;
00591             if (source.isNull() || level == "-1")
00592                 continue;
00593         
00594             QStringList list = QStringList::split(" ", source);
00595             QStringList::iterator it = list.begin();
00596             for (; it != list.end(); ++it) {
00597                 //kdDebug()<<k_funcinfo<<(*it)<<endl;
00598                 if ((*it) == "alltasks") {
00599                     m_reportTags->alltasksLevel = level;
00600                 }
00601                 if ((*it) == "summarytasks") {
00602                     m_reportTags->summarytasksLevel = level;
00603                 }
00604                 if ((*it) == "tasks") {
00605                     m_reportTags->tasksLevel = level;
00606                 }
00607                 if ((*it) == "milestones") {
00608                     m_reportTags->milestonesLevel = level;
00609                 }
00610                 if ((*it) == "resourcegroups") {
00611                     m_reportTags->resourcegroupsLevel = level;
00612                 }
00613                 if ((*it) == "resources") {
00614                     m_reportTags->resourcesLevel = level;
00615                 }
00616             }
00617         }
00618     }
00619 }
00620 
00621 void ReportView::handleDetail(QDomElement &elem) {
00622     //kdDebug()<<k_funcinfo<<endl;
00623     QString level = elem.attribute("Level", "-1");
00624     if (level == "-1") {
00625         return;
00626     }
00627     
00628     if (level == m_reportTags->alltasksLevel) {
00629         m_reportTags->alltasksProps = getProperties(elem);
00630     }
00631     if (level ==  m_reportTags->summarytasksLevel) {
00632         m_reportTags->summarytasksProps = getProperties(elem);
00633     }
00634     if (level == m_reportTags->tasksLevel) {
00635         m_reportTags->tasksProps = getProperties(elem);
00636     }
00637     if (level == m_reportTags->milestonesLevel) {
00638         m_reportTags->milestonesProps = getProperties(elem);
00639     }
00640     if (level == m_reportTags->resourcegroupsLevel) {
00641         m_reportTags->resourcegroupsProps = getProperties(elem);
00642     }
00643     if (level == m_reportTags->resourcesLevel) {
00644         m_reportTags->resourcesProps = getProperties(elem);
00645     }
00646 }
00647 
00648 void ReportView::replaceTags(QDomNode &node) {
00649     if (node.isNull())
00650         return;
00651 }
00652 
00653 void ReportView::getTemplateFile(const QString &tpl) {
00654 
00655     KURL url(tpl);
00656     QString localtpl;
00657     bool isTemp = false;
00658 
00659     if (!url.isValid())
00660     {
00661             KMessageBox::sorry(this,i18n("Malformed template filename: %1").arg(url.prettyURL()));
00662     }
00663     else
00664     {
00665         if (KIO::NetAccess::download(url,localtpl,this))
00666             isTemp = true;
00667         else
00668             KMessageBox::sorry(this,i18n("Unable to download template file: %1").arg(url.prettyURL()));
00669     }
00670 
00671     if (!localtpl.isNull())
00672     {
00673         openTemplateFile(localtpl);
00674         if (isTemp)
00675             KIO::NetAccess::removeTempFile(localtpl);
00676     }
00677 }
00678 
00679 void ReportView::enableNavigationBtn() {
00680     //kdDebug()<<k_funcinfo<<"curr="<<m_reportview->currentPage()<<" count="<<m_reportview->pageCount()<<endl;
00681     emit setFirstPageActionEnabled(m_reportview->currentPage() > 0);
00682     emit setNextPageActionEnabled(m_reportview->currentPage() < m_reportview->pageCount()-1);
00683     emit setPriorPageActionEnabled(m_reportview->currentPage() > 0);
00684     emit setLastPageActionEnabled(m_reportview->currentPage() < m_reportview->pageCount()-1);
00685 }
00686 void ReportView::slotFirstPage() {
00687     m_reportview->slotFirstPage();
00688     enableNavigationBtn();
00689 }
00690 
00691 void ReportView::slotNextPage() {
00692     m_reportview->slotNextPage();
00693     enableNavigationBtn();
00694 }
00695 
00696 void ReportView::slotPrevPage() {
00697     m_reportview->slotPrevPage();
00698     enableNavigationBtn();
00699 }
00700 
00701 void ReportView::slotLastPage() {
00702     m_reportview->slotLastPage();
00703     enableNavigationBtn();
00704 }
00705 
00706 bool ReportView::setContext(Context::Reportview &context) {
00707     Q_UNUSED(context);
00708     //kdDebug()<<k_funcinfo<<endl;
00709     return true;
00710 }
00711 
00712 void ReportView::getContext(Context::Reportview &context) const {
00713     Q_UNUSED(context);
00714     //kdDebug()<<k_funcinfo<<endl;
00715 }
00716 
00717 void ReportView::slotReportListClicked(QListViewItem* item) {
00718     if (item == m_reportList->selectedItem())
00719         slotReportListSelectionChanged(item);
00720 }
00721 
00722 void ReportView::slotReportListSelectionChanged(QListViewItem* item) {
00723     ReportItem *ri = dynamic_cast<ReportItem*>(item);
00724     if (ri == 0)
00725         return;
00726     draw(ri->url);
00727 }
00728 
00729 
00730 }  //KPlato namespace
00731 
00732 #include "kptreportview.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys