You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
733 lines
25 KiB
733 lines
25 KiB
15 years ago
|
/* 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>
|
||
12 years ago
|
#include <tdeaction.h>
|
||
15 years ago
|
#include <kstdaction.h>
|
||
12 years ago
|
#include <tdetoolbar.h>
|
||
15 years ago
|
#include <kstandarddirs.h>
|
||
|
#include <kurl.h>
|
||
12 years ago
|
#include <tdemessagebox.h>
|
||
12 years ago
|
#include <tdeio/netaccess.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
|
#include <tdeglobal.h>
|
||
15 years ago
|
#include <kdesktopfile.h>
|
||
12 years ago
|
#include <tdefiledialog.h>
|
||
15 years ago
|
|
||
14 years ago
|
#include <tqfile.h>
|
||
|
#include <tqfileinfo.h>
|
||
|
#include <tqheader.h>
|
||
|
#include <tqpopupmenu.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
14 years ago
|
#include <tqdom.h>
|
||
|
#include <tqstringlist.h>
|
||
15 years ago
|
|
||
|
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() {}
|
||
|
|
||
14 years ago
|
TQString getData(TQString source, TQString tag) const {
|
||
14 years ago
|
if (tag.contains("."))
|
||
15 years ago
|
return getData(tag);
|
||
|
|
||
|
return getData(source + "." + tag);
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString getData(TQString tag) const {
|
||
15 years ago
|
//kdDebug()<<k_funcinfo<<"tag="<<tag<<endl;
|
||
12 years ago
|
TDELocale *l = TDEGlobal::locale();
|
||
14 years ago
|
if (!tag.contains('.')) {
|
||
15 years ago
|
// global tags
|
||
|
if (tag == "currentdate") {
|
||
13 years ago
|
return l->formatDate(TQDate::currentDate(), true);
|
||
15 years ago
|
}
|
||
14 years ago
|
return TQString();
|
||
15 years ago
|
}
|
||
|
if (tag.section(".", 0, 0) == "project") {
|
||
|
if (tag.section(".", 1, 1) == "name")
|
||
14 years ago
|
return (m_project ? m_project->name() : TQString());
|
||
15 years ago
|
if (tag.section(".", 1, 1) == "leader")
|
||
14 years ago
|
return (m_project ? m_project->leader() : TQString());
|
||
15 years ago
|
|
||
|
} else if (tag.section(".", 0, 0) == "task") {
|
||
|
if (tag.section(".", 1, 1) == "name")
|
||
14 years ago
|
return (m_task ? m_task->name() : TQString());
|
||
15 years ago
|
if (tag.section(".", 1, 1) == "responsible")
|
||
14 years ago
|
return (m_task ? m_task->leader() : TQString());
|
||
15 years ago
|
else if (tag.section(".", 1, 1) == "wbs")
|
||
14 years ago
|
return (m_task ? m_task->wbs() : TQString());
|
||
15 years ago
|
else if (tag.section(".", 1, 1) == "start")
|
||
14 years ago
|
return (m_task ? l->formatDateTime(m_task->startTime()) : TQString());
|
||
15 years ago
|
else if (tag.section(".", 1, 1) == "starttime")
|
||
14 years ago
|
return (m_task ? l->formatTime(m_task->startTime().time()) : TQString());
|
||
15 years ago
|
else if (tag.section(".", 1, 1) == "startdate")
|
||
14 years ago
|
return (m_task ? l->formatDate(m_task->startTime().date(), true) : TQString());
|
||
15 years ago
|
else if (tag.section(".", 1, 1) == "duration") {
|
||
14 years ago
|
return (m_task ? m_task->duration().toString(Duration::Format_i18nDayTime) : TQString());
|
||
15 years ago
|
} else if (tag.section(".", 1, 1) == "plannedcost") {
|
||
14 years ago
|
return (m_task ? l->formatMoney(m_task->plannedCost()) : TQString());
|
||
15 years ago
|
}
|
||
|
} else if (tag.section(".", 0, 0) == "resourcegroup") {
|
||
|
if (tag.section(".", 1, 1) == "name")
|
||
14 years ago
|
return (m_resourcegroup ? m_resourcegroup->name() : TQString());
|
||
15 years ago
|
|
||
|
} else if (tag.section(".", 0, 0) == "resource") {
|
||
|
if (tag.section(".", 1, 1) == "name")
|
||
14 years ago
|
return (m_resource ? m_resource->name() : TQString());
|
||
15 years ago
|
if (tag.section(".", 1, 1) == "type")
|
||
14 years ago
|
return (m_resource ? m_resource->typeToString() : TQString());
|
||
15 years ago
|
if (tag.section(".", 1, 1) == "email")
|
||
14 years ago
|
return (m_resource ? m_resource->email() : TQString());
|
||
15 years ago
|
if (tag.section(".", 1, 1) == "availablefrom")
|
||
14 years ago
|
return (m_resource ? l->formatDate(m_resource->availableFrom().date(), true) : TQString());
|
||
15 years ago
|
if (tag.section(".", 1, 1) == "availableuntil")
|
||
14 years ago
|
return (m_resource ? l->formatDate(m_resource->availableUntil().date(), true) : TQString());
|
||
15 years ago
|
if (tag.section(".", 1, 1) == "units")
|
||
13 years ago
|
return (m_resource ? TQString("%1%").arg(m_resource->units()) : TQString());
|
||
15 years ago
|
if (tag.section(".", 1, 1) == "normalrate")
|
||
14 years ago
|
return (m_resource ? l->formatMoney(m_resource->normalRate()) : TQString());
|
||
15 years ago
|
if (tag.section(".", 1, 1) == "overtimerate")
|
||
14 years ago
|
return (m_resource ? l->formatMoney(m_resource->overtimeRate()) : TQString());
|
||
15 years ago
|
}
|
||
14 years ago
|
return TQString();
|
||
15 years ago
|
}
|
||
|
|
||
|
Project *m_project;
|
||
|
Task *m_task;
|
||
|
ResourceGroup *m_resourcegroup;
|
||
|
Resource *m_resource;
|
||
|
|
||
14 years ago
|
TQString alltasksLevel;
|
||
|
TQStringList alltasksProps;
|
||
|
TQString summarytasksLevel;
|
||
|
TQStringList summarytasksProps;
|
||
|
TQString tasksLevel;
|
||
|
TQStringList tasksProps;
|
||
|
TQString milestonesLevel;
|
||
|
TQStringList milestonesProps;
|
||
|
TQString resourcegroupsLevel;
|
||
|
TQStringList resourcegroupsProps;
|
||
|
TQString resourcesLevel;
|
||
|
TQStringList resourcesProps;
|
||
15 years ago
|
|
||
|
};
|
||
|
|
||
|
class KugarReportViewer : public Kugar::MReportViewer {
|
||
|
public:
|
||
14 years ago
|
KugarReportViewer(TQWidget *parent = 0, const char *name = 0)
|
||
|
: MReportViewer(parent, name)
|
||
15 years ago
|
{}
|
||
|
|
||
|
int currentPage() {
|
||
|
return report ? report->getCurrentIndex() : 0;
|
||
|
}
|
||
|
int pageCount() {
|
||
|
return report ? report->pageCount() : 0;
|
||
|
}
|
||
|
};
|
||
|
|
||
14 years ago
|
ReportView::ReportView(View *view, TQWidget *parent)
|
||
|
: TQSplitter(parent),
|
||
15 years ago
|
m_mainview(view),
|
||
|
m_reportTags(0)
|
||
|
{
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
12 years ago
|
m_reportList = new TDEListView(this);
|
||
15 years ago
|
#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();
|
||
|
|
||
14 years ago
|
connect(m_reportList, TQT_SIGNAL(clicked(TQListViewItem*)), TQT_SLOT(slotReportListClicked(TQListViewItem*)));
|
||
|
connect(m_reportList, TQT_SIGNAL(selectionChanged(TQListViewItem*)), TQT_SLOT(slotReportListSelectionChanged(TQListViewItem*)));
|
||
15 years ago
|
|
||
|
//setCentralWidget(m_reportview);
|
||
|
|
||
|
// Create the user interface.
|
||
14 years ago
|
//KStdAction::print(this,TQT_SLOT(slotPrint()),actionCollection());
|
||
|
//KStdAction::quit(this,TQT_SLOT(slotFileQuit()),actionCollection());
|
||
15 years ago
|
|
||
14 years ago
|
// KStdAction::showToolbar(this,TQT_SLOT(slotViewToolBar()),actionCollection());
|
||
|
// KStdAction::showStatusbar(this,TQT_SLOT(slotViewStatusBar()),actionCollection());
|
||
15 years ago
|
|
||
|
// 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;
|
||
14 years ago
|
TQStringList list;
|
||
15 years ago
|
m_reportList->clear();
|
||
12 years ago
|
TDEStandardDirs std;
|
||
14 years ago
|
TQStringList reportDesktopFiles = std.findAllResources("data", "kplato/reports/*.desktop", true, true);
|
||
|
for (TQStringList::iterator it = reportDesktopFiles.begin(); it != reportDesktopFiles.end(); ++it) {
|
||
15 years ago
|
KDesktopFile file((*it), true);
|
||
14 years ago
|
TQString name = file.readName();
|
||
15 years ago
|
if (!name.isNull()) {
|
||
|
//kdDebug()<<" file: "<<*it<<" name="<<name<<endl;
|
||
14 years ago
|
TQString url = file.readURL();
|
||
15 years ago
|
if (!url.isNull()) {
|
||
|
if (url.left(1) != "/" || url.left(6) != "file:/") {
|
||
14 years ago
|
TQString path = (*it).left((*it).findRev('/', -1)+1); // include '/'
|
||
15 years ago
|
url = path + url;
|
||
|
}
|
||
|
m_reportList->insertItem(new ReportItem(m_reportList, name, url));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void ReportView::draw(const TQString &report) {
|
||
15 years ago
|
//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() {
|
||
14 years ago
|
TQString s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
||
15 years ago
|
s+="<KugarData>\n";
|
||
|
s += setReportDetail();
|
||
|
s+="</KugarData>\n";
|
||
|
//kdDebug()<<s<<endl;
|
||
|
m_reportview->setReportData(s);
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString ReportView::setReportDetail() {
|
||
15 years ago
|
//kdDebug()<<k_funcinfo<<endl;
|
||
14 years ago
|
TQString s;
|
||
15 years ago
|
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
|
||
14 years ago
|
TQPtrListIterator<Node> it(mainView()->getProject().childNodeIterator());
|
||
15 years ago
|
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
|
||
14 years ago
|
TQPtrListIterator<Node> it(mainView()->getProject().childNodeIterator());
|
||
15 years ago
|
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
|
||
14 years ago
|
TQPtrListIterator<ResourceGroup> it(mainView()->getProject().resourceGroups());
|
||
15 years ago
|
for (; it.current(); ++it) {
|
||
|
s += setResourceGroupDetail(it.current());
|
||
|
}
|
||
|
|
||
|
} else if (m_reportTags->resourcesLevel == "0") {
|
||
|
// make a report that has resources as starting points
|
||
14 years ago
|
TQPtrListIterator<ResourceGroup> it(mainView()->getProject().resourceGroups());
|
||
15 years ago
|
for (; it.current(); ++it) {
|
||
14 years ago
|
TQPtrListIterator<Resource> rit(it.current()->resources());
|
||
15 years ago
|
for (; rit.current(); ++rit) {
|
||
|
s += setResourceDetail(rit.current());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
//kdDebug()<<k_funcinfo<<s<<endl;
|
||
|
return s;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString ReportView::setResourceGroupDetail(ResourceGroup *group) {
|
||
15 years ago
|
//kdDebug()<<k_funcinfo<<group->name()<<endl;
|
||
14 years ago
|
TQString s;
|
||
15 years ago
|
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);
|
||
14 years ago
|
TQPtrListIterator<Resource> rit(group->resources());
|
||
15 years ago
|
for (; rit.current(); ++rit) {
|
||
|
s += setResourceDetail(rit.current());
|
||
|
}
|
||
|
}
|
||
|
return s;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString ReportView::setResourceDetail(Resource *res) {
|
||
15 years ago
|
//kdDebug()<<k_funcinfo<<res->name()<<endl;
|
||
14 years ago
|
TQString s;
|
||
15 years ago
|
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;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString ReportView::setTaskChildren(Node *node) {
|
||
15 years ago
|
//kdDebug()<<k_funcinfo<<endl;
|
||
14 years ago
|
TQString s;
|
||
|
TQPtrListIterator<Node> it(node->childNodeIterator());
|
||
15 years ago
|
for (; it.current(); ++it) {
|
||
|
s += setTaskDetail(it.current());
|
||
|
if (it.current()->type() == Node::Type_Summarytask)
|
||
|
s+= setTaskChildren(it.current());
|
||
|
}
|
||
|
return s;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString ReportView::setTaskDetail(Node *node) {
|
||
15 years ago
|
//kdDebug()<<k_funcinfo<<endl;
|
||
14 years ago
|
TQString s;
|
||
|
TQStringList props;
|
||
|
TQString level = "-1";
|
||
15 years ago
|
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;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString ReportView::setDetail(const TQString & source, TQStringList &properties, TQString &level) {
|
||
|
TQString s = "<Row";
|
||
15 years ago
|
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
|
||
14 years ago
|
TQString data = m_reportTags->getData(source, properties[i].section('=', 1, 1));
|
||
15 years ago
|
if (data.isNull())
|
||
|
data = "";
|
||
14 years ago
|
data = data.replace('<', "<");
|
||
|
data = data.replace('>', ">");
|
||
|
data = data.replace('"', """);
|
||
15 years ago
|
|
||
|
s += "\"" + data + "\""; // Property
|
||
|
//kdDebug()<<k_funcinfo<<s<<endl;
|
||
|
}
|
||
|
s += "/>\n";
|
||
|
return s;
|
||
|
}
|
||
|
|
||
|
// Most of this is from KoDocument::loadNativeFormat
|
||
14 years ago
|
void ReportView::openTemplateFile(const TQString &file) {
|
||
|
if (!TQFileInfo(file).isFile()) {
|
||
15 years ago
|
KMessageBox::sorry( this, i18n("Cannot find report template file!"),
|
||
|
i18n("Generate Report"));
|
||
|
return;
|
||
|
}
|
||
14 years ago
|
TQFile in;
|
||
15 years ago
|
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();
|
||
|
}
|
||
|
|
||
14 years ago
|
void ReportView::loadTemplate(TQIODevice &dev) {
|
||
|
TQString errorMsg;
|
||
15 years ago
|
int errorLine;
|
||
|
int errorColumn;
|
||
|
if (!templateDoc.setContent( &dev , &errorMsg, &errorLine, &errorColumn)) {
|
||
14 years ago
|
TQString msg = "Parsing template file failed with ";
|
||
15 years ago
|
KMessageBox::sorry( this, msg + errorMsg, i18n("Generate Report"));
|
||
|
return;
|
||
|
}
|
||
|
loadTemplate(templateDoc);
|
||
|
}
|
||
|
|
||
14 years ago
|
void ReportView::loadTemplate(TQDomDocument &doc) {
|
||
|
TQDomNode tpl;
|
||
|
TQDomNode child;
|
||
15 years ago
|
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
|
||
13 years ago
|
TQDomNodeList children = tpl.childNodes();
|
||
|
int childCount = children.length();
|
||
15 years ago
|
|
||
|
for(int j = 0; j < childCount; j++){
|
||
13 years ago
|
child = children.item(j);
|
||
14 years ago
|
if(child.nodeType() == TQDomNode::ElementNode) {
|
||
|
TQDomElement e = child.toElement();
|
||
15 years ago
|
//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);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void ReportView::handleHeader(TQDomNode &node) {
|
||
|
TQDomNode child;
|
||
13 years ago
|
TQDomNodeList children = node.childNodes();
|
||
|
int childCount = children.length();
|
||
15 years ago
|
for (int j = 0; j < childCount; j++) {
|
||
13 years ago
|
child = children.item(j);
|
||
15 years ago
|
if (child.nodeName() == "Label") {
|
||
14 years ago
|
TQDomNode n = child.attributes().namedItem("Text");
|
||
|
TQString s = n.nodeValue();
|
||
15 years ago
|
if (!s.isEmpty()) {
|
||
|
// Translate labels
|
||
|
s = i18n(n.nodeValue().latin1()); //NOTE: Not sure if latin1 is ok
|
||
|
}
|
||
14 years ago
|
TQString r = s;
|
||
15 years ago
|
int i = 0, j = 0;
|
||
|
do {
|
||
|
i = j;
|
||
14 years ago
|
if ( ((i = s.find('[', i)) != -1) && ((j = s.find(']', i+1)) != -1) ) {
|
||
14 years ago
|
TQString tag = s.mid(i, j-i+1);
|
||
|
TQString data = m_reportTags->getData(tag.mid(1, tag.length()-2));
|
||
14 years ago
|
r = r.replace(tag, data);
|
||
15 years ago
|
}
|
||
|
} while (i != -1 && j != -1);
|
||
|
n.setNodeValue(r);
|
||
|
//kdDebug()<<" new Text="<<n.nodeValue()<<endl;
|
||
|
} else if (child.nodeName() == "Field") {
|
||
14 years ago
|
TQDomElement e = child.toElement();
|
||
15 years ago
|
if (!e.isElement()) {
|
||
|
continue; // !!!!!
|
||
|
}
|
||
14 years ago
|
TQString s = e.attribute("Field");
|
||
|
TQString data = m_reportTags->getData(s);
|
||
15 years ago
|
e.setAttribute("Text", data);
|
||
|
//kdDebug()<<" new Text="<<e.attribute("Text")<<endl;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
TQStringList ReportView::getProperties(TQDomElement &elem) {
|
||
|
TQStringList props;
|
||
|
TQDomNodeList list(elem.childNodes());
|
||
15 years ago
|
int childCount = list.length();
|
||
|
for (int j = 0; j < childCount; j++) {
|
||
14 years ago
|
TQDomNode child = list.item(j);
|
||
15 years ago
|
if (child.nodeName() == "Field") {
|
||
|
props.append(child.attributes().namedItem("Field").nodeValue()+"="+child.attributes().namedItem("Field").nodeValue());
|
||
|
}
|
||
|
}
|
||
|
return props;
|
||
|
}
|
||
|
|
||
14 years ago
|
void ReportView::handleKPlato(TQDomElement &elem) {
|
||
|
TQDomNodeList list(elem.childNodes());
|
||
15 years ago
|
int childCount = list.length();
|
||
|
for (int j = 0; j < childCount; j++) {
|
||
14 years ago
|
TQDomNode child = list.item(j);
|
||
15 years ago
|
if (child.nodeName() == "Detail") {
|
||
14 years ago
|
TQDomElement e = child.toElement();
|
||
15 years ago
|
if (!e.isElement()) {
|
||
|
continue; // !!!!!
|
||
|
}
|
||
14 years ago
|
TQString source = e.attribute("SelectFrom");
|
||
|
TQString level = e.attribute("Level", "-1");
|
||
15 years ago
|
//kdDebug()<<k_funcinfo<<"SelectFrom="<<source<<" Level="<<level<<endl;
|
||
|
if (source.isNull() || level == "-1")
|
||
|
continue;
|
||
|
|
||
14 years ago
|
TQStringList list = TQStringList::split(" ", source);
|
||
|
TQStringList::iterator it = list.begin();
|
||
15 years ago
|
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;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void ReportView::handleDetail(TQDomElement &elem) {
|
||
15 years ago
|
//kdDebug()<<k_funcinfo<<endl;
|
||
14 years ago
|
TQString level = elem.attribute("Level", "-1");
|
||
15 years ago
|
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);
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void ReportView::replaceTags(TQDomNode &node) {
|
||
15 years ago
|
if (node.isNull())
|
||
|
return;
|
||
|
}
|
||
|
|
||
14 years ago
|
void ReportView::getTemplateFile(const TQString &tpl) {
|
||
15 years ago
|
|
||
|
KURL url(tpl);
|
||
14 years ago
|
TQString localtpl;
|
||
15 years ago
|
bool isTemp = false;
|
||
|
|
||
|
if (!url.isValid())
|
||
|
{
|
||
13 years ago
|
KMessageBox::sorry(this,i18n("Malformed template filename: %1").arg(url.prettyURL()));
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
12 years ago
|
if (TDEIO::NetAccess::download(url,localtpl,this))
|
||
15 years ago
|
isTemp = true;
|
||
|
else
|
||
13 years ago
|
KMessageBox::sorry(this,i18n("Unable to download template file: %1").arg(url.prettyURL()));
|
||
15 years ago
|
}
|
||
|
|
||
|
if (!localtpl.isNull())
|
||
|
{
|
||
|
openTemplateFile(localtpl);
|
||
|
if (isTemp)
|
||
12 years ago
|
TDEIO::NetAccess::removeTempFile(localtpl);
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
14 years ago
|
void ReportView::slotReportListClicked(TQListViewItem* item) {
|
||
15 years ago
|
if (item == m_reportList->selectedItem())
|
||
|
slotReportListSelectionChanged(item);
|
||
|
}
|
||
|
|
||
14 years ago
|
void ReportView::slotReportListSelectionChanged(TQListViewItem* item) {
|
||
15 years ago
|
ReportItem *ri = dynamic_cast<ReportItem*>(item);
|
||
|
if (ri == 0)
|
||
|
return;
|
||
|
draw(ri->url);
|
||
|
}
|
||
|
|
||
|
|
||
|
} //KPlato namespace
|
||
|
|
||
|
#include "kptreportview.moc"
|