kplato

kptreportview.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003 - 2005 Dag Andersen <danders@get2net.dk>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation;
7 version 2 of the License.
8
9 This library 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 GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kptreportview.h"
21
22#include "kptview.h"
23#include "kptpart.h"
24#include "kptcontext.h"
25
26#include <mreportviewer.h>
27#include <mpagecollection.h>
28
29#include <KoStore.h>
30
31#include <kdebug.h>
32#include <tdeaction.h>
33#include <kstdaction.h>
34#include <tdetoolbar.h>
35#include <kstandarddirs.h>
36#include <kurl.h>
37#include <tdemessagebox.h>
38#include <tdeio/netaccess.h>
39#include <tdelocale.h>
40#include <tdeglobal.h>
41#include <kdesktopfile.h>
42#include <tdefiledialog.h>
43
44#include <tqfile.h>
45#include <tqfileinfo.h>
46#include <tqheader.h>
47#include <tqpopupmenu.h>
48#include <tqlayout.h>
49#include <tqdom.h>
50#include <tqstringlist.h>
51
52namespace KPlato
53{
54
55class ReportTagsPrivate {
56public:
57
58 ReportTagsPrivate()
59 : m_project(0),
60 m_task(0),
61 m_resourcegroup(0),
62 m_resource(0),
63 alltasksLevel("-1"),
64 summarytasksLevel("-1"),
65 tasksLevel("-1"),
66 milestonesLevel("-1"),
67 resourcegroupsLevel("-1"),
68 resourcesLevel("-1")
69 {}
70
71 ~ReportTagsPrivate() {}
72
73 TQString getData(TQString source, TQString tag) const {
74 if (tag.contains("."))
75 return getData(tag);
76
77 return getData(source + "." + tag);
78 }
79
80 TQString getData(TQString tag) const {
81 //kdDebug()<<k_funcinfo<<"tag="<<tag<<endl;
82 TDELocale *l = TDEGlobal::locale();
83 if (!tag.contains('.')) {
84 // global tags
85 if (tag == "currentdate") {
86 return l->formatDate(TQDate::currentDate(), true);
87 }
88 return TQString();
89 }
90 if (tag.section(".", 0, 0) == "project") {
91 if (tag.section(".", 1, 1) == "name")
92 return (m_project ? m_project->name() : TQString());
93 if (tag.section(".", 1, 1) == "leader")
94 return (m_project ? m_project->leader() : TQString());
95
96 } else if (tag.section(".", 0, 0) == "task") {
97 if (tag.section(".", 1, 1) == "name")
98 return (m_task ? m_task->name() : TQString());
99 if (tag.section(".", 1, 1) == "responsible")
100 return (m_task ? m_task->leader() : TQString());
101 else if (tag.section(".", 1, 1) == "wbs")
102 return (m_task ? m_task->wbs() : TQString());
103 else if (tag.section(".", 1, 1) == "start")
104 return (m_task ? l->formatDateTime(m_task->startTime()) : TQString());
105 else if (tag.section(".", 1, 1) == "starttime")
106 return (m_task ? l->formatTime(m_task->startTime().time()) : TQString());
107 else if (tag.section(".", 1, 1) == "startdate")
108 return (m_task ? l->formatDate(m_task->startTime().date(), true) : TQString());
109 else if (tag.section(".", 1, 1) == "duration") {
110 return (m_task ? m_task->duration().toString(Duration::Format_i18nDayTime) : TQString());
111 } else if (tag.section(".", 1, 1) == "plannedcost") {
112 return (m_task ? l->formatMoney(m_task->plannedCost()) : TQString());
113 }
114 } else if (tag.section(".", 0, 0) == "resourcegroup") {
115 if (tag.section(".", 1, 1) == "name")
116 return (m_resourcegroup ? m_resourcegroup->name() : TQString());
117
118 } else if (tag.section(".", 0, 0) == "resource") {
119 if (tag.section(".", 1, 1) == "name")
120 return (m_resource ? m_resource->name() : TQString());
121 if (tag.section(".", 1, 1) == "type")
122 return (m_resource ? m_resource->typeToString() : TQString());
123 if (tag.section(".", 1, 1) == "email")
124 return (m_resource ? m_resource->email() : TQString());
125 if (tag.section(".", 1, 1) == "availablefrom")
126 return (m_resource ? l->formatDate(m_resource->availableFrom().date(), true) : TQString());
127 if (tag.section(".", 1, 1) == "availableuntil")
128 return (m_resource ? l->formatDate(m_resource->availableUntil().date(), true) : TQString());
129 if (tag.section(".", 1, 1) == "units")
130 return (m_resource ? TQString("%1%").arg(m_resource->units()) : TQString());
131 if (tag.section(".", 1, 1) == "normalrate")
132 return (m_resource ? l->formatMoney(m_resource->normalRate()) : TQString());
133 if (tag.section(".", 1, 1) == "overtimerate")
134 return (m_resource ? l->formatMoney(m_resource->overtimeRate()) : TQString());
135 }
136 return TQString();
137 }
138
139 Project *m_project;
140 Task *m_task;
141 ResourceGroup *m_resourcegroup;
142 Resource *m_resource;
143
144 TQString alltasksLevel;
145 TQStringList alltasksProps;
146 TQString summarytasksLevel;
147 TQStringList summarytasksProps;
148 TQString tasksLevel;
149 TQStringList tasksProps;
150 TQString milestonesLevel;
151 TQStringList milestonesProps;
152 TQString resourcegroupsLevel;
153 TQStringList resourcegroupsProps;
154 TQString resourcesLevel;
155 TQStringList resourcesProps;
156
157};
158
159class KugarReportViewer : public Kugar::MReportViewer {
160public:
161 KugarReportViewer(TQWidget *parent = 0, const char *name = 0)
162 : MReportViewer(parent, name)
163 {}
164
165 int currentPage() {
166 return report ? report->getCurrentIndex() : 0;
167 }
168 int pageCount() {
169 return report ? report->pageCount() : 0;
170 }
171};
172
173ReportView::ReportView(View *view, TQWidget *parent)
174 : TQSplitter(parent),
175 m_mainview(view),
176 m_reportTags(0)
177{
178 //kdDebug()<<k_funcinfo<<endl;
179 m_reportList = new TDEListView(this);
180#if KDE_IS_VERSION(3,3,9)
181 m_reportList->setShadeSortColumn(false);
182#endif
183 m_reportList->addColumn(i18n("Report Template"));
184 m_reportList->header()->setStretchEnabled(true, 0);
185 m_reportList->header()->setSortIndicator(0);
186
187 m_reportview = new KugarReportViewer(this);
188
189 initReportList();
190
191 connect(m_reportList, TQ_SIGNAL(clicked(TQListViewItem*)), TQ_SLOT(slotReportListClicked(TQListViewItem*)));
192 connect(m_reportList, TQ_SIGNAL(selectionChanged(TQListViewItem*)), TQ_SLOT(slotReportListSelectionChanged(TQListViewItem*)));
193
194 //setCentralWidget(m_reportview);
195
196 // Create the user interface.
197 //KStdAction::print(this,TQ_SLOT(slotPrint()),actionCollection());
198 //KStdAction::quit(this,TQ_SLOT(slotFileQuit()),actionCollection());
199
200// KStdAction::showToolbar(this,TQ_SLOT(slotViewToolBar()),actionCollection());
201// KStdAction::showStatusbar(this,TQ_SLOT(slotViewStatusBar()),actionCollection());
202
203// statusBar();
204
205// createGUI();
206
207}
208
209
210ReportView::~ReportView() {
211 //safe
212 delete m_reportTags;
213}
214
215void ReportView::initReportList() {
216//FIXME: We need a solution that takes care project specific reports.
217 //kdDebug()<<k_funcinfo<<endl;
218 TQStringList list;
219 m_reportList->clear();
220 TDEStandardDirs std;
221 TQStringList reportDesktopFiles = std.findAllResources("data", "kplato/reports/*.desktop", true, true);
222 for (TQStringList::iterator it = reportDesktopFiles.begin(); it != reportDesktopFiles.end(); ++it) {
223 KDesktopFile file((*it), true);
224 TQString name = file.readName();
225 if (!name.isNull()) {
226 //kdDebug()<<" file: "<<*it<<" name="<<name<<endl;
227 TQString url = file.readURL();
228 if (!url.isNull()) {
229 if (url.left(1) != "/" || url.left(6) != "file:/") {
230 TQString path = (*it).left((*it).findRev('/', -1)+1); // include '/'
231 url = path + url;
232 }
233 m_reportList->insertItem(new ReportItem(m_reportList, name, url));
234 }
235 }
236 }
237}
238
239void ReportView::draw(const TQString &report) {
240 //kdDebug()<<k_funcinfo<<endl;
241 m_reportview->clearReport();
242 m_reportTags = new ReportTagsPrivate();
243 getTemplateFile(report);
244 m_reportview->setReportTemplate(templateDoc.toString());
245 setReportData();
246 m_reportview->renderReport();
247 m_reportview->show();
248 delete m_reportTags;
249 m_reportTags=0L;
250 enableNavigationBtn();
251}
252
253void ReportView::setup(KPrinter &printer) {
254 //kdDebug()<<k_funcinfo<<endl;
255 m_reportview->setupPrinter(printer);
256}
257
258void ReportView::print(KPrinter &printer) {
259 //kdDebug()<<k_funcinfo<<endl;
260 m_reportview->printReport(printer);
261}
262
263// Generate report data based on info from the template file
264void ReportView::setReportData() {
265 TQString s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
266 s+="<KugarData>\n";
267 s += setReportDetail();
268 s+="</KugarData>\n";
269 //kdDebug()<<s<<endl;
270 m_reportview->setReportData(s);
271}
272
273TQString ReportView::setReportDetail() {
274 //kdDebug()<<k_funcinfo<<endl;
275 TQString s;
276 if (m_reportTags->alltasksLevel != "-1") {
277 //kdDebug()<<k_funcinfo<<"alltasks level="<<m_reportTags->alltasksLevel<<endl;
278 if (m_reportTags->summarytasksLevel == "-1") {
279 m_reportTags->summarytasksLevel = m_reportTags->alltasksLevel;
280 m_reportTags->summarytasksProps = m_reportTags->alltasksProps;
281 }
282 if (m_reportTags->tasksLevel == "-1") {
283 m_reportTags->tasksLevel = m_reportTags->alltasksLevel;
284 m_reportTags->tasksProps = m_reportTags->alltasksProps;
285 }
286 if (m_reportTags->milestonesLevel == "-1") {
287 m_reportTags->milestonesLevel = m_reportTags->alltasksLevel;
288 m_reportTags->milestonesProps = m_reportTags->alltasksProps;
289 }
290 s+= setTaskChildren(&(mainView()->getProject()));
291
292 } else if (m_reportTags->summarytasksLevel == "0") {
293 // make a report that has summarytasks as starting points
294 TQPtrListIterator<Node> it(mainView()->getProject().childNodeIterator());
295 for (; it.current(); ++it) {
296 if (it.current()->type() == Node::Type_Summarytask) {
297 s += setTaskDetail(it.current());
298 // Now do subtasks
299 s+= setTaskChildren(it.current());
300 }
301 }
302
303 } else if (m_reportTags->tasksLevel == "0") {
304 // make a report that has tasks as starting points
305 TQPtrListIterator<Node> it(mainView()->getProject().childNodeIterator());
306 for (; it.current(); ++it) {
307 if (it.current()->type() == Node::Type_Task) {
308 s += setTaskDetail(it.current());
309 }
310 if (it.current()->type() == Node::Type_Summarytask) {
311 s+= setTaskChildren(it.current());
312 if (m_reportTags->summarytasksLevel != "-1") {
313 s += setTaskDetail(it.current());
314 }
315 }
316 }
317
318 } else if (m_reportTags->milestonesLevel == "0") {
319
320 } else if (m_reportTags->resourcegroupsLevel == "0") {
321 // make a report that has resourcegroups as starting points
322 TQPtrListIterator<ResourceGroup> it(mainView()->getProject().resourceGroups());
323 for (; it.current(); ++it) {
324 s += setResourceGroupDetail(it.current());
325 }
326
327 } else if (m_reportTags->resourcesLevel == "0") {
328 // make a report that has resources as starting points
329 TQPtrListIterator<ResourceGroup> it(mainView()->getProject().resourceGroups());
330 for (; it.current(); ++it) {
331 TQPtrListIterator<Resource> rit(it.current()->resources());
332 for (; rit.current(); ++rit) {
333 s += setResourceDetail(rit.current());
334 }
335 }
336 }
337 //kdDebug()<<k_funcinfo<<s<<endl;
338 return s;
339}
340
341TQString ReportView::setResourceGroupDetail(ResourceGroup *group) {
342 //kdDebug()<<k_funcinfo<<group->name()<<endl;
343 TQString s;
344 if (m_reportTags->resourcegroupsLevel != "-1") {
345 m_reportTags->m_resourcegroup = group;
346 //kdDebug()<<k_funcinfo<<group->name()<<": level="<<m_reportTags->resourcegroupsLevel<<endl;
347 s = setDetail("resourcegroup", m_reportTags->resourcegroupsProps, m_reportTags->resourcegroupsLevel);
348 TQPtrListIterator<Resource> rit(group->resources());
349 for (; rit.current(); ++rit) {
350 s += setResourceDetail(rit.current());
351 }
352 }
353 return s;
354}
355
356TQString ReportView::setResourceDetail(Resource *res) {
357 //kdDebug()<<k_funcinfo<<res->name()<<endl;
358 TQString s;
359 if (m_reportTags->resourcesLevel != "-1") {
360 m_reportTags->m_resource = res;
361 //kdDebug()<<k_funcinfo<<res->name()<<": level="<<m_reportTags->resourcesLevel<<endl;
362 s = setDetail("resource", m_reportTags->resourcesProps, m_reportTags->resourcesLevel);
363 }
364 return s;
365}
366
367TQString ReportView::setTaskChildren(Node *node) {
368 //kdDebug()<<k_funcinfo<<endl;
369 TQString s;
370 TQPtrListIterator<Node> it(node->childNodeIterator());
371 for (; it.current(); ++it) {
372 s += setTaskDetail(it.current());
373 if (it.current()->type() == Node::Type_Summarytask)
374 s+= setTaskChildren(it.current());
375 }
376 return s;
377}
378
379TQString ReportView::setTaskDetail(Node *node) {
380 //kdDebug()<<k_funcinfo<<endl;
381 TQString s;
382 TQStringList props;
383 TQString level = "-1";
384 if (node->type() == Node::Type_Task) {
385 props = m_reportTags->tasksProps;
386 level = m_reportTags->tasksLevel;
387 } else if (node->type() == Node::Type_Summarytask) {
388 props = m_reportTags->summarytasksProps;
389 level = m_reportTags->summarytasksLevel;
390 } else if (node->type() == Node::Type_Milestone) {
391 props = m_reportTags->milestonesProps;
392 level = m_reportTags->milestonesLevel;
393 }
394 if (level != "-1") {
395 m_reportTags->m_task = static_cast<Task *>(node);
396 s = setDetail("task", props, level);
397 }
398 return s;
399}
400
401TQString ReportView::setDetail(const TQString & source, TQStringList &properties, TQString &level) {
402 TQString s = "<Row";
403 s += " level=\"" + level + "\"";
404 for (unsigned int i=0; i < properties.count(); ++i) {
405 //kdDebug()<<k_funcinfo<<"Property: "<<properties[i]<<endl;
406 s += " " + properties[i].section('=', 0, 0) + "="; // Field
407 TQString data = m_reportTags->getData(source, properties[i].section('=', 1, 1));
408 if (data.isNull())
409 data = "";
410 data = data.replace('<', "&lt;");
411 data = data.replace('>', "&gt;");
412 data = data.replace('"', "&quot;");
413
414 s += "\"" + data + "\""; // Property
415 //kdDebug()<<k_funcinfo<<s<<endl;
416 }
417 s += "/>\n";
418 return s;
419}
420
421// Most of this is from KoDocument::loadNativeFormat
422void ReportView::openTemplateFile(const TQString &file) {
423 if (!TQFileInfo(file).isFile()) {
424 KMessageBox::sorry( this, i18n("Cannot find report template file!"),
425 i18n("Generate Report"));
426 return;
427 }
428 TQFile in;
429 in.setName(file);
430 if (!in.open(IO_ReadOnly)) {
431 KMessageBox::sorry( this, i18n("Cannot open report template file!"),
432 i18n("Generate Report"));
433 return;
434 }
435 // Try to find out whether it is a mime multi part file
436 char buf[5];
437 if ( in.readBlock( buf, 4 ) < 4 )
438 {
439 in.close();
440 KMessageBox::sorry( this, i18n("Cannot read report template file!"),
441 i18n("Generate Report"));
442 return;
443 }
444
445 if (strncasecmp( buf, "<?xm", 4 ) == 0) { // xml file?
446 in.at(0);
447 // fake
448 //m_reportview->setReportTemplate(&in);
449 loadTemplate(in);
450 in.close();
451 return;
452 }
453 in.close();
454 KoStore* store=KoStore::createStore(file, KoStore::Read);
455 if (!store)
456 {
457 KMessageBox::sorry( this, i18n("Cannot open report template file!"),
458 i18n("Generate Report"));
459 return;
460 }
461 bool b = store->open("maindoc.xml");
462 if ( !b )
463 {
464 KMessageBox::sorry( this, i18n("Cannot find the proper report template file!"),
465 i18n("Generate Report"));
466 delete store;
467 return;
468 }
469 loadTemplate(*(store->device()));
470 store->close();
471}
472
473void ReportView::loadTemplate(TQIODevice &dev) {
474 TQString errorMsg;
475 int errorLine;
476 int errorColumn;
477 if (!templateDoc.setContent( &dev , &errorMsg, &errorLine, &errorColumn)) {
478 TQString msg = "Parsing template file failed with ";
479 KMessageBox::sorry( this, msg + errorMsg, i18n("Generate Report"));
480 return;
481 }
482 loadTemplate(templateDoc);
483}
484
485void ReportView::loadTemplate(TQDomDocument &doc) {
486 TQDomNode tpl;
487 TQDomNode child;
488 for (tpl = doc.firstChild(); !tpl.isNull(); tpl = tpl.nextSibling())
489 if (tpl.nodeName() == "KugarTemplate")
490 break;
491
492 if (tpl.isNull())
493 return;
494
495 m_reportTags->m_project = &(mainView()->getPart()->getProject());
496 // Get all the child report elements
497 TQDomNodeList children = tpl.childNodes();
498 int childCount = children.length();
499
500 for(int j = 0; j < childCount; j++){
501 child = children.item(j);
502 if(child.nodeType() == TQDomNode::ElementNode) {
503 TQDomElement e = child.toElement();
504 //kdDebug()<<child.nodeName()<<endl;
505 // Report Header
506 if(child.nodeName() == "ReportHeader") {
507 handleHeader(child);
508 } else if (child.nodeName() == "PageHeader") {
509 handleHeader(child);
510 } else if(child.nodeName() == "DetailHeader") {
511 handleHeader(child);
512 } else if(child.nodeName() == "Detail") {
513 handleDetail(e);
514 } else if(child.nodeName() == "DetailFooter") {
515 handleHeader(child);
516 } else if(child.nodeName() == "PageFooter") {
517 handleHeader(child);
518 } else if(child.nodeName() == "ReportFooter") {
519 handleHeader(child);
520 } else if(child.nodeName() == "KPlato") {
521 handleKPlato(e);
522 }
523 }
524 }
525}
526
527void ReportView::handleHeader(TQDomNode &node) {
528 TQDomNode child;
529 TQDomNodeList children = node.childNodes();
530 int childCount = children.length();
531 for (int j = 0; j < childCount; j++) {
532 child = children.item(j);
533 if (child.nodeName() == "Label") {
534 TQDomNode n = child.attributes().namedItem("Text");
535 TQString s = n.nodeValue();
536 if (!s.isEmpty()) {
537 // Translate labels
538 s = i18n(n.nodeValue().latin1()); //NOTE: Not sure if latin1 is ok
539 }
540 TQString r = s;
541 int i = 0, j = 0;
542 do {
543 i = j;
544 if ( ((i = s.find('[', i)) != -1) && ((j = s.find(']', i+1)) != -1) ) {
545 TQString tag = s.mid(i, j-i+1);
546 TQString data = m_reportTags->getData(tag.mid(1, tag.length()-2));
547 r = r.replace(tag, data);
548 }
549 } while (i != -1 && j != -1);
550 n.setNodeValue(r);
551 //kdDebug()<<" new Text="<<n.nodeValue()<<endl;
552 } else if (child.nodeName() == "Field") {
553 TQDomElement e = child.toElement();
554 if (!e.isElement()) {
555 continue; // !!!!!
556 }
557 TQString s = e.attribute("Field");
558 TQString data = m_reportTags->getData(s);
559 e.setAttribute("Text", data);
560 //kdDebug()<<" new Text="<<e.attribute("Text")<<endl;
561 }
562 }
563}
564
565TQStringList ReportView::getProperties(TQDomElement &elem) {
566 TQStringList props;
567 TQDomNodeList list(elem.childNodes());
568 int childCount = list.length();
569 for (int j = 0; j < childCount; j++) {
570 TQDomNode child = list.item(j);
571 if (child.nodeName() == "Field") {
572 props.append(child.attributes().namedItem("Field").nodeValue()+"="+child.attributes().namedItem("Field").nodeValue());
573 }
574 }
575 return props;
576}
577
578void ReportView::handleKPlato(TQDomElement &elem) {
579 TQDomNodeList list(elem.childNodes());
580 int childCount = list.length();
581 for (int j = 0; j < childCount; j++) {
582 TQDomNode child = list.item(j);
583 if (child.nodeName() == "Detail") {
584 TQDomElement e = child.toElement();
585 if (!e.isElement()) {
586 continue; // !!!!!
587 }
588 TQString source = e.attribute("SelectFrom");
589 TQString level = e.attribute("Level", "-1");
590 //kdDebug()<<k_funcinfo<<"SelectFrom="<<source<<" Level="<<level<<endl;
591 if (source.isNull() || level == "-1")
592 continue;
593
594 TQStringList list = TQStringList::split(" ", source);
595 TQStringList::iterator it = list.begin();
596 for (; it != list.end(); ++it) {
597 //kdDebug()<<k_funcinfo<<(*it)<<endl;
598 if ((*it) == "alltasks") {
599 m_reportTags->alltasksLevel = level;
600 }
601 if ((*it) == "summarytasks") {
602 m_reportTags->summarytasksLevel = level;
603 }
604 if ((*it) == "tasks") {
605 m_reportTags->tasksLevel = level;
606 }
607 if ((*it) == "milestones") {
608 m_reportTags->milestonesLevel = level;
609 }
610 if ((*it) == "resourcegroups") {
611 m_reportTags->resourcegroupsLevel = level;
612 }
613 if ((*it) == "resources") {
614 m_reportTags->resourcesLevel = level;
615 }
616 }
617 }
618 }
619}
620
621void ReportView::handleDetail(TQDomElement &elem) {
622 //kdDebug()<<k_funcinfo<<endl;
623 TQString level = elem.attribute("Level", "-1");
624 if (level == "-1") {
625 return;
626 }
627
628 if (level == m_reportTags->alltasksLevel) {
629 m_reportTags->alltasksProps = getProperties(elem);
630 }
631 if (level == m_reportTags->summarytasksLevel) {
632 m_reportTags->summarytasksProps = getProperties(elem);
633 }
634 if (level == m_reportTags->tasksLevel) {
635 m_reportTags->tasksProps = getProperties(elem);
636 }
637 if (level == m_reportTags->milestonesLevel) {
638 m_reportTags->milestonesProps = getProperties(elem);
639 }
640 if (level == m_reportTags->resourcegroupsLevel) {
641 m_reportTags->resourcegroupsProps = getProperties(elem);
642 }
643 if (level == m_reportTags->resourcesLevel) {
644 m_reportTags->resourcesProps = getProperties(elem);
645 }
646}
647
648void ReportView::replaceTags(TQDomNode &node) {
649 if (node.isNull())
650 return;
651}
652
653void ReportView::getTemplateFile(const TQString &tpl) {
654
655 KURL url(tpl);
656 TQString localtpl;
657 bool isTemp = false;
658
659 if (!url.isValid())
660 {
661 KMessageBox::sorry(this,i18n("Malformed template filename: %1").arg(url.prettyURL()));
662 }
663 else
664 {
665 if (TDEIO::NetAccess::download(url,localtpl,this))
666 isTemp = true;
667 else
668 KMessageBox::sorry(this,i18n("Unable to download template file: %1").arg(url.prettyURL()));
669 }
670
671 if (!localtpl.isNull())
672 {
673 openTemplateFile(localtpl);
674 if (isTemp)
675 TDEIO::NetAccess::removeTempFile(localtpl);
676 }
677}
678
679void ReportView::enableNavigationBtn() {
680 //kdDebug()<<k_funcinfo<<"curr="<<m_reportview->currentPage()<<" count="<<m_reportview->pageCount()<<endl;
681 emit setFirstPageActionEnabled(m_reportview->currentPage() > 0);
682 emit setNextPageActionEnabled(m_reportview->currentPage() < m_reportview->pageCount()-1);
683 emit setPriorPageActionEnabled(m_reportview->currentPage() > 0);
684 emit setLastPageActionEnabled(m_reportview->currentPage() < m_reportview->pageCount()-1);
685}
686void ReportView::slotFirstPage() {
687 m_reportview->slotFirstPage();
688 enableNavigationBtn();
689}
690
691void ReportView::slotNextPage() {
692 m_reportview->slotNextPage();
693 enableNavigationBtn();
694}
695
696void ReportView::slotPrevPage() {
697 m_reportview->slotPrevPage();
698 enableNavigationBtn();
699}
700
701void ReportView::slotLastPage() {
702 m_reportview->slotLastPage();
703 enableNavigationBtn();
704}
705
706bool ReportView::setContext(Context::Reportview &context) {
707 Q_UNUSED(context);
708 //kdDebug()<<k_funcinfo<<endl;
709 return true;
710}
711
712void ReportView::getContext(Context::Reportview &context) const {
713 Q_UNUSED(context);
714 //kdDebug()<<k_funcinfo<<endl;
715}
716
717void ReportView::slotReportListClicked(TQListViewItem* item) {
718 if (item == m_reportList->selectedItem())
719 slotReportListSelectionChanged(item);
720}
721
722void ReportView::slotReportListSelectionChanged(TQListViewItem* item) {
723 ReportItem *ri = dynamic_cast<ReportItem*>(item);
724 if (ri == 0)
725 return;
726 draw(ri->url);
727}
728
729
730} //KPlato namespace
731
732#include "kptreportview.moc"