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 m_reportList->setShadeSortColumn(false);
181 m_reportList->addColumn(i18n("Report Template"));
182 m_reportList->header()->setStretchEnabled(true, 0);
183 m_reportList->header()->setSortIndicator(0);
184
185 m_reportview = new KugarReportViewer(this);
186
187 initReportList();
188
189 connect(m_reportList, TQ_SIGNAL(clicked(TQListViewItem*)), TQ_SLOT(slotReportListClicked(TQListViewItem*)));
190 connect(m_reportList, TQ_SIGNAL(selectionChanged(TQListViewItem*)), TQ_SLOT(slotReportListSelectionChanged(TQListViewItem*)));
191
192 //setCentralWidget(m_reportview);
193
194 // Create the user interface.
195 //KStdAction::print(this,TQ_SLOT(slotPrint()),actionCollection());
196 //KStdAction::quit(this,TQ_SLOT(slotFileQuit()),actionCollection());
197
198// KStdAction::showToolbar(this,TQ_SLOT(slotViewToolBar()),actionCollection());
199// KStdAction::showStatusbar(this,TQ_SLOT(slotViewStatusBar()),actionCollection());
200
201// statusBar();
202
203// createGUI();
204
205}
206
207
208ReportView::~ReportView() {
209 //safe
210 delete m_reportTags;
211}
212
213void ReportView::initReportList() {
214//FIXME: We need a solution that takes care project specific reports.
215 //kdDebug()<<k_funcinfo<<endl;
216 TQStringList list;
217 m_reportList->clear();
218 TDEStandardDirs std;
219 TQStringList reportDesktopFiles = std.findAllResources("data", "kplato/reports/*.desktop", true, true);
220 for (TQStringList::iterator it = reportDesktopFiles.begin(); it != reportDesktopFiles.end(); ++it) {
221 KDesktopFile file((*it), true);
222 TQString name = file.readName();
223 if (!name.isNull()) {
224 //kdDebug()<<" file: "<<*it<<" name="<<name<<endl;
225 TQString url = file.readURL();
226 if (!url.isNull()) {
227 if (url.left(1) != "/" || url.left(6) != "file:/") {
228 TQString path = (*it).left((*it).findRev('/', -1)+1); // include '/'
229 url = path + url;
230 }
231 m_reportList->insertItem(new ReportItem(m_reportList, name, url));
232 }
233 }
234 }
235}
236
237void ReportView::draw(const TQString &report) {
238 //kdDebug()<<k_funcinfo<<endl;
239 m_reportview->clearReport();
240 m_reportTags = new ReportTagsPrivate();
241 getTemplateFile(report);
242 m_reportview->setReportTemplate(templateDoc.toString());
243 setReportData();
244 m_reportview->renderReport();
245 m_reportview->show();
246 delete m_reportTags;
247 m_reportTags=0L;
248 enableNavigationBtn();
249}
250
251void ReportView::setup(KPrinter &printer) {
252 //kdDebug()<<k_funcinfo<<endl;
253 m_reportview->setupPrinter(printer);
254}
255
256void ReportView::print(KPrinter &printer) {
257 //kdDebug()<<k_funcinfo<<endl;
258 m_reportview->printReport(printer);
259}
260
261// Generate report data based on info from the template file
262void ReportView::setReportData() {
263 TQString s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
264 s+="<KugarData>\n";
265 s += setReportDetail();
266 s+="</KugarData>\n";
267 //kdDebug()<<s<<endl;
268 m_reportview->setReportData(s);
269}
270
271TQString ReportView::setReportDetail() {
272 //kdDebug()<<k_funcinfo<<endl;
273 TQString s;
274 if (m_reportTags->alltasksLevel != "-1") {
275 //kdDebug()<<k_funcinfo<<"alltasks level="<<m_reportTags->alltasksLevel<<endl;
276 if (m_reportTags->summarytasksLevel == "-1") {
277 m_reportTags->summarytasksLevel = m_reportTags->alltasksLevel;
278 m_reportTags->summarytasksProps = m_reportTags->alltasksProps;
279 }
280 if (m_reportTags->tasksLevel == "-1") {
281 m_reportTags->tasksLevel = m_reportTags->alltasksLevel;
282 m_reportTags->tasksProps = m_reportTags->alltasksProps;
283 }
284 if (m_reportTags->milestonesLevel == "-1") {
285 m_reportTags->milestonesLevel = m_reportTags->alltasksLevel;
286 m_reportTags->milestonesProps = m_reportTags->alltasksProps;
287 }
288 s+= setTaskChildren(&(mainView()->getProject()));
289
290 } else if (m_reportTags->summarytasksLevel == "0") {
291 // make a report that has summarytasks as starting points
292 TQPtrListIterator<Node> it(mainView()->getProject().childNodeIterator());
293 for (; it.current(); ++it) {
294 if (it.current()->type() == Node::Type_Summarytask) {
295 s += setTaskDetail(it.current());
296 // Now do subtasks
297 s+= setTaskChildren(it.current());
298 }
299 }
300
301 } else if (m_reportTags->tasksLevel == "0") {
302 // make a report that has tasks as starting points
303 TQPtrListIterator<Node> it(mainView()->getProject().childNodeIterator());
304 for (; it.current(); ++it) {
305 if (it.current()->type() == Node::Type_Task) {
306 s += setTaskDetail(it.current());
307 }
308 if (it.current()->type() == Node::Type_Summarytask) {
309 s+= setTaskChildren(it.current());
310 if (m_reportTags->summarytasksLevel != "-1") {
311 s += setTaskDetail(it.current());
312 }
313 }
314 }
315
316 } else if (m_reportTags->milestonesLevel == "0") {
317
318 } else if (m_reportTags->resourcegroupsLevel == "0") {
319 // make a report that has resourcegroups as starting points
320 TQPtrListIterator<ResourceGroup> it(mainView()->getProject().resourceGroups());
321 for (; it.current(); ++it) {
322 s += setResourceGroupDetail(it.current());
323 }
324
325 } else if (m_reportTags->resourcesLevel == "0") {
326 // make a report that has resources as starting points
327 TQPtrListIterator<ResourceGroup> it(mainView()->getProject().resourceGroups());
328 for (; it.current(); ++it) {
329 TQPtrListIterator<Resource> rit(it.current()->resources());
330 for (; rit.current(); ++rit) {
331 s += setResourceDetail(rit.current());
332 }
333 }
334 }
335 //kdDebug()<<k_funcinfo<<s<<endl;
336 return s;
337}
338
339TQString ReportView::setResourceGroupDetail(ResourceGroup *group) {
340 //kdDebug()<<k_funcinfo<<group->name()<<endl;
341 TQString s;
342 if (m_reportTags->resourcegroupsLevel != "-1") {
343 m_reportTags->m_resourcegroup = group;
344 //kdDebug()<<k_funcinfo<<group->name()<<": level="<<m_reportTags->resourcegroupsLevel<<endl;
345 s = setDetail("resourcegroup", m_reportTags->resourcegroupsProps, m_reportTags->resourcegroupsLevel);
346 TQPtrListIterator<Resource> rit(group->resources());
347 for (; rit.current(); ++rit) {
348 s += setResourceDetail(rit.current());
349 }
350 }
351 return s;
352}
353
354TQString ReportView::setResourceDetail(Resource *res) {
355 //kdDebug()<<k_funcinfo<<res->name()<<endl;
356 TQString s;
357 if (m_reportTags->resourcesLevel != "-1") {
358 m_reportTags->m_resource = res;
359 //kdDebug()<<k_funcinfo<<res->name()<<": level="<<m_reportTags->resourcesLevel<<endl;
360 s = setDetail("resource", m_reportTags->resourcesProps, m_reportTags->resourcesLevel);
361 }
362 return s;
363}
364
365TQString ReportView::setTaskChildren(Node *node) {
366 //kdDebug()<<k_funcinfo<<endl;
367 TQString s;
368 TQPtrListIterator<Node> it(node->childNodeIterator());
369 for (; it.current(); ++it) {
370 s += setTaskDetail(it.current());
371 if (it.current()->type() == Node::Type_Summarytask)
372 s+= setTaskChildren(it.current());
373 }
374 return s;
375}
376
377TQString ReportView::setTaskDetail(Node *node) {
378 //kdDebug()<<k_funcinfo<<endl;
379 TQString s;
380 TQStringList props;
381 TQString level = "-1";
382 if (node->type() == Node::Type_Task) {
383 props = m_reportTags->tasksProps;
384 level = m_reportTags->tasksLevel;
385 } else if (node->type() == Node::Type_Summarytask) {
386 props = m_reportTags->summarytasksProps;
387 level = m_reportTags->summarytasksLevel;
388 } else if (node->type() == Node::Type_Milestone) {
389 props = m_reportTags->milestonesProps;
390 level = m_reportTags->milestonesLevel;
391 }
392 if (level != "-1") {
393 m_reportTags->m_task = static_cast<Task *>(node);
394 s = setDetail("task", props, level);
395 }
396 return s;
397}
398
399TQString ReportView::setDetail(const TQString & source, TQStringList &properties, TQString &level) {
400 TQString s = "<Row";
401 s += " level=\"" + level + "\"";
402 for (unsigned int i=0; i < properties.count(); ++i) {
403 //kdDebug()<<k_funcinfo<<"Property: "<<properties[i]<<endl;
404 s += " " + properties[i].section('=', 0, 0) + "="; // Field
405 TQString data = m_reportTags->getData(source, properties[i].section('=', 1, 1));
406 if (data.isNull())
407 data = "";
408 data = data.replace('<', "&lt;");
409 data = data.replace('>', "&gt;");
410 data = data.replace('"', "&quot;");
411
412 s += "\"" + data + "\""; // Property
413 //kdDebug()<<k_funcinfo<<s<<endl;
414 }
415 s += "/>\n";
416 return s;
417}
418
419// Most of this is from KoDocument::loadNativeFormat
420void ReportView::openTemplateFile(const TQString &file) {
421 if (!TQFileInfo(file).isFile()) {
422 KMessageBox::sorry( this, i18n("Cannot find report template file!"),
423 i18n("Generate Report"));
424 return;
425 }
426 TQFile in;
427 in.setName(file);
428 if (!in.open(IO_ReadOnly)) {
429 KMessageBox::sorry( this, i18n("Cannot open report template file!"),
430 i18n("Generate Report"));
431 return;
432 }
433 // Try to find out whether it is a mime multi part file
434 char buf[5];
435 if ( in.readBlock( buf, 4 ) < 4 )
436 {
437 in.close();
438 KMessageBox::sorry( this, i18n("Cannot read report template file!"),
439 i18n("Generate Report"));
440 return;
441 }
442
443 if (strncasecmp( buf, "<?xm", 4 ) == 0) { // xml file?
444 in.at(0);
445 // fake
446 //m_reportview->setReportTemplate(&in);
447 loadTemplate(in);
448 in.close();
449 return;
450 }
451 in.close();
452 KoStore* store=KoStore::createStore(file, KoStore::Read);
453 if (!store)
454 {
455 KMessageBox::sorry( this, i18n("Cannot open report template file!"),
456 i18n("Generate Report"));
457 return;
458 }
459 bool b = store->open("maindoc.xml");
460 if ( !b )
461 {
462 KMessageBox::sorry( this, i18n("Cannot find the proper report template file!"),
463 i18n("Generate Report"));
464 delete store;
465 return;
466 }
467 loadTemplate(*(store->device()));
468 store->close();
469}
470
471void ReportView::loadTemplate(TQIODevice &dev) {
472 TQString errorMsg;
473 int errorLine;
474 int errorColumn;
475 if (!templateDoc.setContent( &dev , &errorMsg, &errorLine, &errorColumn)) {
476 TQString msg = "Parsing template file failed with ";
477 KMessageBox::sorry( this, msg + errorMsg, i18n("Generate Report"));
478 return;
479 }
480 loadTemplate(templateDoc);
481}
482
483void ReportView::loadTemplate(TQDomDocument &doc) {
484 TQDomNode tpl;
485 TQDomNode child;
486 for (tpl = doc.firstChild(); !tpl.isNull(); tpl = tpl.nextSibling())
487 if (tpl.nodeName() == "KugarTemplate")
488 break;
489
490 if (tpl.isNull())
491 return;
492
493 m_reportTags->m_project = &(mainView()->getPart()->getProject());
494 // Get all the child report elements
495 TQDomNodeList children = tpl.childNodes();
496 int childCount = children.length();
497
498 for(int j = 0; j < childCount; j++){
499 child = children.item(j);
500 if(child.nodeType() == TQDomNode::ElementNode) {
501 TQDomElement e = child.toElement();
502 //kdDebug()<<child.nodeName()<<endl;
503 // Report Header
504 if(child.nodeName() == "ReportHeader") {
505 handleHeader(child);
506 } else if (child.nodeName() == "PageHeader") {
507 handleHeader(child);
508 } else if(child.nodeName() == "DetailHeader") {
509 handleHeader(child);
510 } else if(child.nodeName() == "Detail") {
511 handleDetail(e);
512 } else if(child.nodeName() == "DetailFooter") {
513 handleHeader(child);
514 } else if(child.nodeName() == "PageFooter") {
515 handleHeader(child);
516 } else if(child.nodeName() == "ReportFooter") {
517 handleHeader(child);
518 } else if(child.nodeName() == "KPlato") {
519 handleKPlato(e);
520 }
521 }
522 }
523}
524
525void ReportView::handleHeader(TQDomNode &node) {
526 TQDomNode child;
527 TQDomNodeList children = node.childNodes();
528 int childCount = children.length();
529 for (int j = 0; j < childCount; j++) {
530 child = children.item(j);
531 if (child.nodeName() == "Label") {
532 TQDomNode n = child.attributes().namedItem("Text");
533 TQString s = n.nodeValue();
534 if (!s.isEmpty()) {
535 // Translate labels
536 s = i18n(n.nodeValue().latin1()); //NOTE: Not sure if latin1 is ok
537 }
538 TQString r = s;
539 int i = 0, j = 0;
540 do {
541 i = j;
542 if ( ((i = s.find('[', i)) != -1) && ((j = s.find(']', i+1)) != -1) ) {
543 TQString tag = s.mid(i, j-i+1);
544 TQString data = m_reportTags->getData(tag.mid(1, tag.length()-2));
545 r = r.replace(tag, data);
546 }
547 } while (i != -1 && j != -1);
548 n.setNodeValue(r);
549 //kdDebug()<<" new Text="<<n.nodeValue()<<endl;
550 } else if (child.nodeName() == "Field") {
551 TQDomElement e = child.toElement();
552 if (!e.isElement()) {
553 continue; // !!!!!
554 }
555 TQString s = e.attribute("Field");
556 TQString data = m_reportTags->getData(s);
557 e.setAttribute("Text", data);
558 //kdDebug()<<" new Text="<<e.attribute("Text")<<endl;
559 }
560 }
561}
562
563TQStringList ReportView::getProperties(TQDomElement &elem) {
564 TQStringList props;
565 TQDomNodeList list(elem.childNodes());
566 int childCount = list.length();
567 for (int j = 0; j < childCount; j++) {
568 TQDomNode child = list.item(j);
569 if (child.nodeName() == "Field") {
570 props.append(child.attributes().namedItem("Field").nodeValue()+"="+child.attributes().namedItem("Field").nodeValue());
571 }
572 }
573 return props;
574}
575
576void ReportView::handleKPlato(TQDomElement &elem) {
577 TQDomNodeList list(elem.childNodes());
578 int childCount = list.length();
579 for (int j = 0; j < childCount; j++) {
580 TQDomNode child = list.item(j);
581 if (child.nodeName() == "Detail") {
582 TQDomElement e = child.toElement();
583 if (!e.isElement()) {
584 continue; // !!!!!
585 }
586 TQString source = e.attribute("SelectFrom");
587 TQString level = e.attribute("Level", "-1");
588 //kdDebug()<<k_funcinfo<<"SelectFrom="<<source<<" Level="<<level<<endl;
589 if (source.isNull() || level == "-1")
590 continue;
591
592 TQStringList list = TQStringList::split(" ", source);
593 TQStringList::iterator it = list.begin();
594 for (; it != list.end(); ++it) {
595 //kdDebug()<<k_funcinfo<<(*it)<<endl;
596 if ((*it) == "alltasks") {
597 m_reportTags->alltasksLevel = level;
598 }
599 if ((*it) == "summarytasks") {
600 m_reportTags->summarytasksLevel = level;
601 }
602 if ((*it) == "tasks") {
603 m_reportTags->tasksLevel = level;
604 }
605 if ((*it) == "milestones") {
606 m_reportTags->milestonesLevel = level;
607 }
608 if ((*it) == "resourcegroups") {
609 m_reportTags->resourcegroupsLevel = level;
610 }
611 if ((*it) == "resources") {
612 m_reportTags->resourcesLevel = level;
613 }
614 }
615 }
616 }
617}
618
619void ReportView::handleDetail(TQDomElement &elem) {
620 //kdDebug()<<k_funcinfo<<endl;
621 TQString level = elem.attribute("Level", "-1");
622 if (level == "-1") {
623 return;
624 }
625
626 if (level == m_reportTags->alltasksLevel) {
627 m_reportTags->alltasksProps = getProperties(elem);
628 }
629 if (level == m_reportTags->summarytasksLevel) {
630 m_reportTags->summarytasksProps = getProperties(elem);
631 }
632 if (level == m_reportTags->tasksLevel) {
633 m_reportTags->tasksProps = getProperties(elem);
634 }
635 if (level == m_reportTags->milestonesLevel) {
636 m_reportTags->milestonesProps = getProperties(elem);
637 }
638 if (level == m_reportTags->resourcegroupsLevel) {
639 m_reportTags->resourcegroupsProps = getProperties(elem);
640 }
641 if (level == m_reportTags->resourcesLevel) {
642 m_reportTags->resourcesProps = getProperties(elem);
643 }
644}
645
646void ReportView::replaceTags(TQDomNode &node) {
647 if (node.isNull())
648 return;
649}
650
651void ReportView::getTemplateFile(const TQString &tpl) {
652
653 KURL url(tpl);
654 TQString localtpl;
655 bool isTemp = false;
656
657 if (!url.isValid())
658 {
659 KMessageBox::sorry(this,i18n("Malformed template filename: %1").arg(url.prettyURL()));
660 }
661 else
662 {
663 if (TDEIO::NetAccess::download(url,localtpl,this))
664 isTemp = true;
665 else
666 KMessageBox::sorry(this,i18n("Unable to download template file: %1").arg(url.prettyURL()));
667 }
668
669 if (!localtpl.isNull())
670 {
671 openTemplateFile(localtpl);
672 if (isTemp)
673 TDEIO::NetAccess::removeTempFile(localtpl);
674 }
675}
676
677void ReportView::enableNavigationBtn() {
678 //kdDebug()<<k_funcinfo<<"curr="<<m_reportview->currentPage()<<" count="<<m_reportview->pageCount()<<endl;
679 emit setFirstPageActionEnabled(m_reportview->currentPage() > 0);
680 emit setNextPageActionEnabled(m_reportview->currentPage() < m_reportview->pageCount()-1);
681 emit setPriorPageActionEnabled(m_reportview->currentPage() > 0);
682 emit setLastPageActionEnabled(m_reportview->currentPage() < m_reportview->pageCount()-1);
683}
684void ReportView::slotFirstPage() {
685 m_reportview->slotFirstPage();
686 enableNavigationBtn();
687}
688
689void ReportView::slotNextPage() {
690 m_reportview->slotNextPage();
691 enableNavigationBtn();
692}
693
694void ReportView::slotPrevPage() {
695 m_reportview->slotPrevPage();
696 enableNavigationBtn();
697}
698
699void ReportView::slotLastPage() {
700 m_reportview->slotLastPage();
701 enableNavigationBtn();
702}
703
704bool ReportView::setContext(Context::Reportview &context) {
705 Q_UNUSED(context);
706 //kdDebug()<<k_funcinfo<<endl;
707 return true;
708}
709
710void ReportView::getContext(Context::Reportview &context) const {
711 Q_UNUSED(context);
712 //kdDebug()<<k_funcinfo<<endl;
713}
714
715void ReportView::slotReportListClicked(TQListViewItem* item) {
716 if (item == m_reportList->selectedItem())
717 slotReportListSelectionChanged(item);
718}
719
720void ReportView::slotReportListSelectionChanged(TQListViewItem* item) {
721 ReportItem *ri = dynamic_cast<ReportItem*>(item);
722 if (ri == 0)
723 return;
724 draw(ri->url);
725}
726
727
728} //KPlato namespace
729
730#include "kptreportview.moc"