summaryrefslogtreecommitdiffstats
path: root/kplato/kptreportview.cpp
blob: b346eef285f026063bd8e1c26ace51c26da967e2 (plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
/* This file is part of the KDE project
   Copyright (C) 2003 - 2005 Dag Andersen <danders@get2net.dk>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation;
   version 2 of the License.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include "kptreportview.h"

#include "kptview.h"
#include "kptpart.h"
#include "kptcontext.h"

#include <mreportviewer.h>
#include <mpagecollection.h>

#include <KoStore.h>

#include <kdebug.h>
#include <tdeaction.h>
#include <kstdaction.h>
#include <tdetoolbar.h>
#include <kstandarddirs.h>
#include <kurl.h>
#include <tdemessagebox.h>
#include <tdeio/netaccess.h>
#include <tdelocale.h>
#include <tdeglobal.h>
#include <kdesktopfile.h>
#include <tdefiledialog.h>

#include <tqfile.h>
#include <tqfileinfo.h>
#include <tqheader.h>
#include <tqpopupmenu.h>
#include <tqlayout.h>
#include <tqdom.h>
#include <tqstringlist.h>

namespace KPlato
{

class ReportTagsPrivate {
public:

    ReportTagsPrivate()
    :   m_project(0),
        m_task(0),
        m_resourcegroup(0),
        m_resource(0),
        alltasksLevel("-1"),
        summarytasksLevel("-1"),
        tasksLevel("-1"),
        milestonesLevel("-1"),
        resourcegroupsLevel("-1"),
        resourcesLevel("-1")
    {}

    ~ReportTagsPrivate() {}

    TQString getData(TQString source, TQString tag) const {
        if (tag.contains("."))
            return getData(tag);

        return getData(source + "." + tag);
    }

    TQString getData(TQString tag) const {
        //kdDebug()<<k_funcinfo<<"tag="<<tag<<endl;
        TDELocale *l = TDEGlobal::locale();
        if (!tag.contains('.')) {
            // global tags
            if (tag == "currentdate") {
                return l->formatDate(TQDate::currentDate(), true);
            }
            return TQString();
        }
        if (tag.section(".", 0, 0) == "project") {
            if (tag.section(".", 1, 1) == "name")
                return (m_project ? m_project->name() : TQString());
            if (tag.section(".", 1, 1) == "leader")
                return (m_project ? m_project->leader() : TQString());

        } else if (tag.section(".", 0, 0) == "task") {
            if (tag.section(".", 1, 1) == "name")
                return (m_task ? m_task->name() : TQString());
            if (tag.section(".", 1, 1) == "responsible")
                return (m_task ? m_task->leader() : TQString());
            else if (tag.section(".", 1, 1) == "wbs")
                return (m_task ? m_task->wbs() : TQString());
            else if (tag.section(".", 1, 1) == "start")
                return (m_task ? l->formatDateTime(m_task->startTime()) : TQString());
            else if (tag.section(".", 1, 1) == "starttime")
                return (m_task ? l->formatTime(m_task->startTime().time()) : TQString());
            else if (tag.section(".", 1, 1) == "startdate")
                return (m_task ? l->formatDate(m_task->startTime().date(), true) : TQString());
            else if (tag.section(".", 1, 1) == "duration") {
                    return (m_task ? m_task->duration().toString(Duration::Format_i18nDayTime) : TQString());
            } else if (tag.section(".", 1, 1) == "plannedcost") {
                return (m_task ? l->formatMoney(m_task->plannedCost()) : TQString());
            }
        } else if (tag.section(".", 0, 0) == "resourcegroup") {
            if (tag.section(".", 1, 1) == "name")
                return (m_resourcegroup ? m_resourcegroup->name() : TQString());
        
        } else if (tag.section(".", 0, 0) == "resource") {
            if (tag.section(".", 1, 1) == "name")
                return (m_resource ? m_resource->name() : TQString());
            if (tag.section(".", 1, 1) == "type")
                return (m_resource ? m_resource->typeToString() : TQString());
            if (tag.section(".", 1, 1) == "email")
                return (m_resource ? m_resource->email() : TQString());
            if (tag.section(".", 1, 1) == "availablefrom")
                return (m_resource ? l->formatDate(m_resource->availableFrom().date(), true) : TQString());
            if (tag.section(".", 1, 1) == "availableuntil")
                return (m_resource ? l->formatDate(m_resource->availableUntil().date(), true) : TQString());
            if (tag.section(".", 1, 1) == "units")
                return (m_resource ? TQString("%1%").arg(m_resource->units()) : TQString());
            if (tag.section(".", 1, 1) == "normalrate")
                return (m_resource ? l->formatMoney(m_resource->normalRate()) : TQString());
            if (tag.section(".", 1, 1) == "overtimerate")
                return (m_resource ? l->formatMoney(m_resource->overtimeRate()) : TQString());
        }
	return TQString();
    }

    Project *m_project;
    Task *m_task;
    ResourceGroup *m_resourcegroup;
    Resource *m_resource;

    TQString alltasksLevel;
    TQStringList alltasksProps;
    TQString summarytasksLevel;
    TQStringList summarytasksProps;
    TQString tasksLevel;
    TQStringList tasksProps;
    TQString milestonesLevel;
    TQStringList milestonesProps;
    TQString resourcegroupsLevel;
    TQStringList resourcegroupsProps;
    TQString resourcesLevel;
    TQStringList resourcesProps;

};

class KugarReportViewer : public Kugar::MReportViewer {
public:
    KugarReportViewer(TQWidget *parent = 0, const char *name = 0)
    : MReportViewer(parent, name)
    {}
    
    int currentPage() {
        return report ? report->getCurrentIndex() : 0;
    }
    int pageCount() {
        return report ? report->pageCount() : 0;
    }
};

ReportView::ReportView(View *view, TQWidget *parent)
    : TQSplitter(parent),
    m_mainview(view),
    m_reportTags(0)
{
    //kdDebug()<<k_funcinfo<<endl;
    m_reportList = new TDEListView(this);
#if KDE_IS_VERSION(3,3,9)
    m_reportList->setShadeSortColumn(false);
#endif
    m_reportList->addColumn(i18n("Report Template"));
    m_reportList->header()->setStretchEnabled(true, 0);
    m_reportList->header()->setSortIndicator(0);
    
    m_reportview = new KugarReportViewer(this);

    initReportList();
    
	connect(m_reportList, TQ_SIGNAL(clicked(TQListViewItem*)), TQ_SLOT(slotReportListClicked(TQListViewItem*)));
	connect(m_reportList, TQ_SIGNAL(selectionChanged(TQListViewItem*)), TQ_SLOT(slotReportListSelectionChanged(TQListViewItem*)));

	//setCentralWidget(m_reportview);

	// Create the user interface.
	//KStdAction::print(this,TQ_SLOT(slotPrint()),actionCollection());
	//KStdAction::quit(this,TQ_SLOT(slotFileQuit()),actionCollection());

//	KStdAction::showToolbar(this,TQ_SLOT(slotViewToolBar()),actionCollection());
//	KStdAction::showStatusbar(this,TQ_SLOT(slotViewStatusBar()),actionCollection());

// 	statusBar();

//	createGUI();

}


ReportView::~ReportView() {
   //safe
   delete m_reportTags;
}

void ReportView::initReportList() {
//FIXME: We need a solution that takes care project specific reports.
    //kdDebug()<<k_funcinfo<<endl;
    TQStringList list;
    m_reportList->clear();
    TDEStandardDirs std;
    TQStringList reportDesktopFiles = std.findAllResources("data", "kplato/reports/*.desktop", true, true);
    for (TQStringList::iterator it = reportDesktopFiles.begin(); it != reportDesktopFiles.end(); ++it) {
        KDesktopFile file((*it), true);
        TQString name = file.readName();
        if (!name.isNull()) {
            //kdDebug()<<" file: "<<*it<<" name="<<name<<endl;
            TQString url = file.readURL();
            if (!url.isNull()) {
                if (url.left(1) != "/" || url.left(6) != "file:/") {
                    TQString path = (*it).left((*it).findRev('/', -1)+1); // include '/'
                    url = path + url;
                }
                m_reportList->insertItem(new ReportItem(m_reportList, name, url));
            }
        }
    }
}

void ReportView::draw(const TQString &report) {
    //kdDebug()<<k_funcinfo<<endl;
    m_reportview->clearReport();
    m_reportTags = new ReportTagsPrivate();
    getTemplateFile(report);
    m_reportview->setReportTemplate(templateDoc.toString());
    setReportData();
    m_reportview->renderReport();
    m_reportview->show();
    delete m_reportTags;
    m_reportTags=0L;
    enableNavigationBtn();
}

void ReportView::setup(KPrinter &printer) {
    //kdDebug()<<k_funcinfo<<endl;
    m_reportview->setupPrinter(printer);
}

void ReportView::print(KPrinter &printer) {
    //kdDebug()<<k_funcinfo<<endl;
	m_reportview->printReport(printer);
}

// Generate report data based on info from the template file
void ReportView::setReportData() {
    TQString s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    s+="<KugarData>\n";
    s += setReportDetail();
    s+="</KugarData>\n";
    //kdDebug()<<s<<endl;
    m_reportview->setReportData(s);
}

TQString ReportView::setReportDetail() {
    //kdDebug()<<k_funcinfo<<endl;
    TQString s;
    if (m_reportTags->alltasksLevel != "-1") {
        //kdDebug()<<k_funcinfo<<"alltasks level="<<m_reportTags->alltasksLevel<<endl;
        if (m_reportTags->summarytasksLevel == "-1") {
            m_reportTags->summarytasksLevel = m_reportTags->alltasksLevel;
            m_reportTags->summarytasksProps = m_reportTags->alltasksProps;
        }
        if (m_reportTags->tasksLevel == "-1") {
            m_reportTags->tasksLevel = m_reportTags->alltasksLevel;
            m_reportTags->tasksProps = m_reportTags->alltasksProps;
        }
        if (m_reportTags->milestonesLevel == "-1") {
            m_reportTags->milestonesLevel = m_reportTags->alltasksLevel;
            m_reportTags->milestonesProps = m_reportTags->alltasksProps;
        }
        s+= setTaskChildren(&(mainView()->getProject()));
    
    } else if (m_reportTags->summarytasksLevel == "0") {
        // make a report that has summarytasks as starting points
        TQPtrListIterator<Node> it(mainView()->getProject().childNodeIterator());
        for (; it.current(); ++it) {
            if (it.current()->type() == Node::Type_Summarytask) {
                s += setTaskDetail(it.current());
                // Now do subtasks
                s+= setTaskChildren(it.current());
            }
        }

    } else if (m_reportTags->tasksLevel == "0") {
        // make a report that has tasks as starting points
        TQPtrListIterator<Node> it(mainView()->getProject().childNodeIterator());
        for (; it.current(); ++it) {
            if (it.current()->type() == Node::Type_Task) {
                s += setTaskDetail(it.current());
            }
            if (it.current()->type() == Node::Type_Summarytask) {
                s+= setTaskChildren(it.current());
                if (m_reportTags->summarytasksLevel != "-1") {
                    s += setTaskDetail(it.current());
                }
            }
        }

    } else if (m_reportTags->milestonesLevel == "0") {

    } else if (m_reportTags->resourcegroupsLevel == "0") {
        // make a report that has resourcegroups as starting points
        TQPtrListIterator<ResourceGroup> it(mainView()->getProject().resourceGroups());
        for (; it.current(); ++it) {
            s += setResourceGroupDetail(it.current());
        }

    } else if (m_reportTags->resourcesLevel == "0") {
        // make a report that has resources as starting points
        TQPtrListIterator<ResourceGroup> it(mainView()->getProject().resourceGroups());
        for (; it.current(); ++it) {
            TQPtrListIterator<Resource> rit(it.current()->resources());
            for (; rit.current(); ++rit) {
                s += setResourceDetail(rit.current());
            }
        }
    }
    //kdDebug()<<k_funcinfo<<s<<endl;
    return s;
}

TQString ReportView::setResourceGroupDetail(ResourceGroup *group) {
    //kdDebug()<<k_funcinfo<<group->name()<<endl;
    TQString s;
    if (m_reportTags->resourcegroupsLevel != "-1") {
        m_reportTags->m_resourcegroup = group;
        //kdDebug()<<k_funcinfo<<group->name()<<": level="<<m_reportTags->resourcegroupsLevel<<endl;
        s = setDetail("resourcegroup", m_reportTags->resourcegroupsProps, m_reportTags->resourcegroupsLevel);
        TQPtrListIterator<Resource> rit(group->resources());
        for (; rit.current(); ++rit) {
            s += setResourceDetail(rit.current());
        }
    }
    return s;
}

TQString ReportView::setResourceDetail(Resource *res) {
    //kdDebug()<<k_funcinfo<<res->name()<<endl;
    TQString s;
    if (m_reportTags->resourcesLevel != "-1") {
        m_reportTags->m_resource = res;
        //kdDebug()<<k_funcinfo<<res->name()<<": level="<<m_reportTags->resourcesLevel<<endl;
        s = setDetail("resource", m_reportTags->resourcesProps, m_reportTags->resourcesLevel);
    }
    return s;
}

TQString ReportView::setTaskChildren(Node *node) {
    //kdDebug()<<k_funcinfo<<endl;
    TQString s;
    TQPtrListIterator<Node> it(node->childNodeIterator());
    for (; it.current(); ++it) {
        s += setTaskDetail(it.current());
        if (it.current()->type() == Node::Type_Summarytask)
            s+= setTaskChildren(it.current());
    }
    return s;
}

TQString ReportView::setTaskDetail(Node *node) {
    //kdDebug()<<k_funcinfo<<endl;
    TQString s;
    TQStringList props;
    TQString level = "-1";
    if (node->type() == Node::Type_Task) {
        props = m_reportTags->tasksProps;
        level = m_reportTags->tasksLevel;
    } else if (node->type() == Node::Type_Summarytask) {
        props = m_reportTags->summarytasksProps;
        level = m_reportTags->summarytasksLevel;
    } else if (node->type() == Node::Type_Milestone) {
        props = m_reportTags->milestonesProps;
        level = m_reportTags->milestonesLevel;
    }
    if (level != "-1") {
        m_reportTags->m_task = static_cast<Task *>(node);
        s = setDetail("task", props, level);
    }
    return s;
}

TQString ReportView::setDetail(const TQString & source, TQStringList &properties, TQString &level) {
    TQString s = "<Row";
    s += " level=\"" + level + "\"";
    for (unsigned int i=0; i < properties.count(); ++i) {
        //kdDebug()<<k_funcinfo<<"Property: "<<properties[i]<<endl;
        s += " " + properties[i].section('=', 0, 0) + "="; // Field
        TQString data = m_reportTags->getData(source, properties[i].section('=', 1, 1));
        if (data.isNull())
            data = "";
        data = data.replace('<', "&lt;");
        data = data.replace('>', "&gt;");
        data = data.replace('"', "&quot;");
        
        s += "\"" + data + "\""; // Property
        //kdDebug()<<k_funcinfo<<s<<endl;
    }
    s += "/>\n";
    return s;
}

// Most of this is from KoDocument::loadNativeFormat
void ReportView::openTemplateFile(const TQString &file) {
    if (!TQFileInfo(file).isFile()) {
        KMessageBox::sorry( this, i18n("Cannot find report template file!"),
                                                        i18n("Generate Report"));
        return;
    }
    TQFile in;
    in.setName(file);
    if (!in.open(IO_ReadOnly)) {
        KMessageBox::sorry( this, i18n("Cannot open report template file!"),
                                                        i18n("Generate Report"));
        return;
    }
    // Try to find out whether it is a mime multi part file
    char buf[5];
    if ( in.readBlock( buf, 4 ) < 4 )
    {
        in.close();
        KMessageBox::sorry( this, i18n("Cannot read report template file!"),
                                                        i18n("Generate Report"));
        return;
    }

    if (strncasecmp( buf, "<?xm", 4 ) == 0) { // xml file?
        in.at(0);
        // fake
        //m_reportview->setReportTemplate(&in);
        loadTemplate(in);
        in.close();
        return;
    }
    in.close();
    KoStore* store=KoStore::createStore(file, KoStore::Read);
    if (!store)
    {
        KMessageBox::sorry( this, i18n("Cannot open report template file!"),
                                                    i18n("Generate Report"));
        return;
    }
    bool b = store->open("maindoc.xml");
    if ( !b )
    {
        KMessageBox::sorry( this, i18n("Cannot find the proper report template file!"),
                                                    i18n("Generate Report"));
        delete store;
        return;
    }
    loadTemplate(*(store->device()));
    store->close();
}

void ReportView::loadTemplate(TQIODevice &dev) {
    TQString errorMsg;
    int errorLine;
    int errorColumn;
    if (!templateDoc.setContent( &dev , &errorMsg, &errorLine, &errorColumn)) {
        TQString msg = "Parsing template file failed with ";
        KMessageBox::sorry( this, msg + errorMsg, i18n("Generate Report"));
        return;
    }
    loadTemplate(templateDoc);
}

void ReportView::loadTemplate(TQDomDocument &doc) {
    TQDomNode tpl;
    TQDomNode child;
    for (tpl = doc.firstChild(); !tpl.isNull(); tpl = tpl.nextSibling())
        if (tpl.nodeName() == "KugarTemplate")
            break;

    if (tpl.isNull())
        return;

    m_reportTags->m_project = &(mainView()->getPart()->getProject());
    // Get all the child report elements
    TQDomNodeList children = tpl.childNodes();
    int childCount = children.length();

    for(int j = 0; j < childCount; j++){
        child = children.item(j);
        if(child.nodeType() == TQDomNode::ElementNode) {
            TQDomElement e = child.toElement();
            //kdDebug()<<child.nodeName()<<endl;
            // Report Header
            if(child.nodeName() == "ReportHeader") {
                handleHeader(child);
            } else if (child.nodeName() == "PageHeader") {
                handleHeader(child);
            } else if(child.nodeName() == "DetailHeader") {
                handleHeader(child);
            } else if(child.nodeName() == "Detail") {
                handleDetail(e);
            } else if(child.nodeName() == "DetailFooter") {
                handleHeader(child);
            } else if(child.nodeName() == "PageFooter") {
                handleHeader(child);
            } else if(child.nodeName() == "ReportFooter") {
                handleHeader(child);
            } else if(child.nodeName() == "KPlato") {
                handleKPlato(e);
            }
        }
    }
}

void ReportView::handleHeader(TQDomNode &node) {
    TQDomNode child;
    TQDomNodeList children = node.childNodes();
    int childCount = children.length();
    for (int j = 0; j < childCount; j++) {
        child = children.item(j);
        if (child.nodeName() == "Label") {
            TQDomNode n = child.attributes().namedItem("Text");
            TQString s = n.nodeValue();
            if (!s.isEmpty()) {
                // Translate labels
                s = i18n(n.nodeValue().latin1()); //NOTE: Not sure if latin1 is ok
            }
            TQString r = s;
            int i = 0, j = 0;
            do {
                i = j;
                if ( ((i = s.find('[', i)) != -1) && ((j = s.find(']', i+1)) != -1) ) {
                    TQString tag = s.mid(i, j-i+1);
                    TQString data = m_reportTags->getData(tag.mid(1, tag.length()-2));
                    r = r.replace(tag, data);
                }
            } while (i != -1 && j != -1);
            n.setNodeValue(r);
            //kdDebug()<<" new Text="<<n.nodeValue()<<endl;
        } else if (child.nodeName() == "Field") {
            TQDomElement e = child.toElement();
            if (!e.isElement()) {
                continue; // !!!!!
            }
            TQString s = e.attribute("Field");
            TQString data = m_reportTags->getData(s);
            e.setAttribute("Text", data);
            //kdDebug()<<" new Text="<<e.attribute("Text")<<endl;
        }
    }
}

TQStringList ReportView::getProperties(TQDomElement &elem) {
    TQStringList props;
    TQDomNodeList list(elem.childNodes());
    int childCount = list.length();
    for (int j = 0; j < childCount; j++) {
        TQDomNode child = list.item(j);
        if (child.nodeName() == "Field") {
            props.append(child.attributes().namedItem("Field").nodeValue()+"="+child.attributes().namedItem("Field").nodeValue());
        }
    }
    return props;
}

void ReportView::handleKPlato(TQDomElement &elem) {
    TQDomNodeList list(elem.childNodes());
    int childCount = list.length();
    for (int j = 0; j < childCount; j++) {
        TQDomNode child = list.item(j);
        if (child.nodeName() == "Detail") {
            TQDomElement e = child.toElement();
            if (!e.isElement()) {
                continue; // !!!!!
            }
            TQString source = e.attribute("SelectFrom");
            TQString level = e.attribute("Level", "-1");
            //kdDebug()<<k_funcinfo<<"SelectFrom="<<source<<" Level="<<level<<endl;
            if (source.isNull() || level == "-1")
                continue;
        
            TQStringList list = TQStringList::split(" ", source);
            TQStringList::iterator it = list.begin();
            for (; it != list.end(); ++it) {
                //kdDebug()<<k_funcinfo<<(*it)<<endl;
                if ((*it) == "alltasks") {
                    m_reportTags->alltasksLevel = level;
                }
                if ((*it) == "summarytasks") {
                    m_reportTags->summarytasksLevel = level;
                }
                if ((*it) == "tasks") {
                    m_reportTags->tasksLevel = level;
                }
                if ((*it) == "milestones") {
                    m_reportTags->milestonesLevel = level;
                }
                if ((*it) == "resourcegroups") {
                    m_reportTags->resourcegroupsLevel = level;
                }
                if ((*it) == "resources") {
                    m_reportTags->resourcesLevel = level;
                }
            }
        }
    }
}

void ReportView::handleDetail(TQDomElement &elem) {
    //kdDebug()<<k_funcinfo<<endl;
    TQString level = elem.attribute("Level", "-1");
    if (level == "-1") {
        return;
    }
    
    if (level == m_reportTags->alltasksLevel) {
        m_reportTags->alltasksProps = getProperties(elem);
    }
    if (level ==  m_reportTags->summarytasksLevel) {
        m_reportTags->summarytasksProps = getProperties(elem);
    }
    if (level == m_reportTags->tasksLevel) {
        m_reportTags->tasksProps = getProperties(elem);
    }
    if (level == m_reportTags->milestonesLevel) {
        m_reportTags->milestonesProps = getProperties(elem);
    }
    if (level == m_reportTags->resourcegroupsLevel) {
        m_reportTags->resourcegroupsProps = getProperties(elem);
    }
    if (level == m_reportTags->resourcesLevel) {
        m_reportTags->resourcesProps = getProperties(elem);
    }
}

void ReportView::replaceTags(TQDomNode &node) {
    if (node.isNull())
        return;
}

void ReportView::getTemplateFile(const TQString &tpl) {

	KURL url(tpl);
	TQString localtpl;
	bool isTemp = false;

	if (!url.isValid())
	{
			KMessageBox::sorry(this,i18n("Malformed template filename: %1").arg(url.prettyURL()));
	}
	else
	{
		if (TDEIO::NetAccess::download(url,localtpl,this))
			isTemp = true;
		else
			KMessageBox::sorry(this,i18n("Unable to download template file: %1").arg(url.prettyURL()));
	}

	if (!localtpl.isNull())
	{
        openTemplateFile(localtpl);
		if (isTemp)
			TDEIO::NetAccess::removeTempFile(localtpl);
	}
}

void ReportView::enableNavigationBtn() {
    //kdDebug()<<k_funcinfo<<"curr="<<m_reportview->currentPage()<<" count="<<m_reportview->pageCount()<<endl;
    emit setFirstPageActionEnabled(m_reportview->currentPage() > 0);
    emit setNextPageActionEnabled(m_reportview->currentPage() < m_reportview->pageCount()-1);
    emit setPriorPageActionEnabled(m_reportview->currentPage() > 0);
    emit setLastPageActionEnabled(m_reportview->currentPage() < m_reportview->pageCount()-1);
}
void ReportView::slotFirstPage() {
    m_reportview->slotFirstPage();
    enableNavigationBtn();
}

void ReportView::slotNextPage() {
    m_reportview->slotNextPage();
    enableNavigationBtn();
}

void ReportView::slotPrevPage() {
    m_reportview->slotPrevPage();
    enableNavigationBtn();
}

void ReportView::slotLastPage() {
    m_reportview->slotLastPage();
    enableNavigationBtn();
}

bool ReportView::setContext(Context::Reportview &context) {
    Q_UNUSED(context);
    //kdDebug()<<k_funcinfo<<endl;
    return true;
}

void ReportView::getContext(Context::Reportview &context) const {
    Q_UNUSED(context);
    //kdDebug()<<k_funcinfo<<endl;
}

void ReportView::slotReportListClicked(TQListViewItem* item) {
    if (item == m_reportList->selectedItem())
        slotReportListSelectionChanged(item);
}

void ReportView::slotReportListSelectionChanged(TQListViewItem* item) {
    ReportItem *ri = dynamic_cast<ReportItem*>(item);
    if (ri == 0)
        return;
    draw(ri->url);
}


}  //KPlato namespace

#include "kptreportview.moc"