2 * HTMLIndexReportElement.cpp - TaskJuggler
4 * Copyright (c) 2001, 2002, 2003, 2004 by Chris Schlaeger <cs@kde.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
17 #include "HTMLIndexReportElement.h"
18 #include "TableLineInfo.h"
19 #include "tjlib-internal.h"
23 HTMLIndexReportElement::HTMLIndexReportElement(Report* r,
26 HTMLReportElement(r, df, dl)
28 columns.append(new TableColumnInfo(0, "Report"));
29 columns.append(new TableColumnInfo(0, "Comment"));
33 HTMLIndexReportElement::generateReportLine(Report* report, int level)
35 // Deduce report file name relativly to index directory.
36 QString absSourceFilePath = QFileInfo(defFileName).dir(true).canonicalPath();
37 QString absReportFilePath = QFileInfo(report->getFullFileName()).dir(true).canonicalPath();
38 QString reportRelPath = "";
39 for (QString sourceFilePath = defFileName.left(defFileName.findRev(QDir().separator())-1);
40 sourceFilePath.find('/') >= 0;
41 sourceFilePath = sourceFilePath.left(sourceFilePath.findRev(QDir().separator())-1))
43 if (strncmp(sourceFilePath, absReportFilePath, sourceFilePath.length()) == 0)
45 reportRelPath += absReportFilePath.right(absReportFilePath.length() - sourceFilePath.length() - 2);
50 reportRelPath = reportRelPath + ".." + QDir().separator();
54 QString thumbnailDir = absReportFilePath + QDir().separator() + ".thumbnails";
55 QString thumbnailFileName = QFileInfo(report->getFullFileName()).fileName() + ".gif";
56 QString thumbnailFile = thumbnailDir + QDir().separator() + thumbnailFileName;
57 QString reportRelFile = reportRelPath + QDir().separator() + QFileInfo(report->getFullFileName()).fileName();
58 // Make thumbnail directory in case it does not exists yet
59 QDir().mkdir(QFileInfo(thumbnailDir).absFilePath());
62 QFile thumb (thumbnailFile);
63 QFile reportQFile (report->getFullFileName() );
64 if (!thumb.exists() ||
65 QFileInfo(thumb).created() < QFileInfo(thumb).created() )
67 QString thumbnailCommand;
68 if (strncmp(report->getType(), "SVG", 3) == 0)
70 thumbnailCommand = "inkscape -h 40 -e '" + thumbnailFile + "' '" + report->getFullFileName() + "'";
72 else if (strncmp(report->getType(), "HTML", 4) != 0 || reportQFile.size() < 500000)
74 thumbnailCommand = "convert -geometry 40x -delay 100 '" + report->getFullFileName() + "' '" + thumbnailFile + "'";
76 system(thumbnailCommand.ascii());
79 s() << "<TR style=\"background-color:" << colors.getColorName("default") << "; \" ><TD>";
80 for (int i = 0 ; i < level; i++)
83 s() << "<strong>" << (report->getHeadline() == "" ? QFileInfo(report->getFullFileName()).fileName() : report->getHeadline()) << "</strong>";
84 for (int i = 0 ; i < level; i++)
87 s() << "</TD><TD><A HREF='" << reportRelFile << "'>";
88 s() << "<img src='" << reportRelPath + QDir().separator() + ".thumbnails" + QDir().separator() + thumbnailFileName << "' />";
91 s() << "<TD><i> ( " << report->getType() << " ) </i></TD>";
92 ElementHolder *elementHolder = dynamic_cast<ElementHolder*>(this);
93 if (elementHolder && elementHolder->getTable()->getCaption() != "")
94 s() << ": " << elementHolder->getTable()->getCaption();
95 else if (report->getCaption() != "")
96 s() << ": " << report->getCaption();
99 for (Q3PtrListIterator<Report> ri(report->getChildrenReportListIterator()); *ri; ++ri)
102 generateReportLine(*ri, level + 1);
109 HTMLIndexReportElement::generate()
111 QString previousReportType;
115 s() << "<table align=\"center\" cellpadding=\"2\" "
116 << "style=\"background-color:" << colors.getColorName("default") << "\"";
118 s() << " <thead>" << endl
119 << " <tr valign=\"middle\""
120 << " style=\"background-color:" << colors.getColorName("header") << "; "
121 << "font-size:110%; font-weight:bold; text-align:center\"";
123 s() << " </tr>" << endl;
125 for (Q3PtrListIterator<Report> ri(report->getProject()->getReportListIterator()); *ri != 0; ++ri)
127 // We generate all but Qt*Reports. Those are for the GUI version.
128 if (strncmp((*ri)->getType(), "Qt", 2) != 0
129 && (*ri)->getParentReport() == 0
130 && (*ri) != this->getReport())
132 generateReportLine(*ri);
135 s() << " </thead>\n" << endl;
136 s() << "</table>" << endl;