OSDN Git Service

Set main window's icon.
[tjqt4port/tj2qt4.git] / taskjuggler / HTMLIndexReportElement.cpp
1 /*
2  * HTMLIndexReportElement.cpp - TaskJuggler
3  *
4  * Copyright (c) 2001, 2002, 2003, 2004 by Chris Schlaeger <cs@kde.org>
5  *
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.
9  *
10  * $Id$
11  */
12
13 #include <stdlib.h>
14 #include <qdir.h>
15 #include <qfile.h>
16
17 #include "HTMLIndexReportElement.h"
18 #include "TableLineInfo.h"
19 #include "tjlib-internal.h"
20 #include "Project.h"
21 #include "Account.h"
22
23 HTMLIndexReportElement::HTMLIndexReportElement(Report* r,
24                                                    const QString& df,
25                                                    int dl) :
26     HTMLReportElement(r, df, dl)
27 {
28     columns.append(new TableColumnInfo(0, "Report"));
29     columns.append(new TableColumnInfo(0, "Comment"));
30 }
31
32 bool
33 HTMLIndexReportElement::generateReportLine(Report* report, int level)
34 {
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))
42     {
43         if (strncmp(sourceFilePath, absReportFilePath, sourceFilePath.length()) == 0)
44         {
45             reportRelPath += absReportFilePath.right(absReportFilePath.length() - sourceFilePath.length() - 2);
46             break;
47         }
48         else
49         {
50             reportRelPath = reportRelPath + ".." + QDir().separator();
51         }
52     }
53
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());
60
61     // Generate thumbnail
62     QFile thumb (thumbnailFile);
63     QFile reportQFile (report->getFullFileName() );
64     if (!thumb.exists() ||
65         QFileInfo(thumb).created() < QFileInfo(thumb).created() )
66     {
67         QString thumbnailCommand;
68         if (strncmp(report->getType(), "SVG", 3) == 0)
69         {
70             thumbnailCommand = "inkscape -h 40 -e '" + thumbnailFile + "' '" + report->getFullFileName() + "'";
71         }
72         else if (strncmp(report->getType(), "HTML", 4) != 0 || reportQFile.size() < 500000)
73         {
74             thumbnailCommand = "convert -geometry 40x -delay 100 '" + report->getFullFileName() + "' '" + thumbnailFile + "'";
75         }
76         system(thumbnailCommand.ascii());
77     }
78
79     s() << "<TR style=\"background-color:" << colors.getColorName("default") << "; \" ><TD>";
80     for (int i = 0 ; i < level; i++)
81         s() << "<ul>";
82
83     s() << "<strong>" << (report->getHeadline() == "" ?  QFileInfo(report->getFullFileName()).fileName() : report->getHeadline()) << "</strong>";
84     for (int i = 0 ; i < level; i++)
85         s() << "</ul>";
86
87     s() << "</TD><TD><A HREF='" << reportRelFile << "'>";
88     s() << "<img src='" << reportRelPath + QDir().separator() + ".thumbnails" + QDir().separator() + thumbnailFileName << "' />";
89     s() << "</A></TD>";
90
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();
97
98     s() << "</TR>\n";
99     for (Q3PtrListIterator<Report> ri(report->getChildrenReportListIterator()); *ri; ++ri)
100     {
101         s() << "\n";
102         generateReportLine(*ri, level + 1);
103     }
104
105     return true;
106 }
107
108 bool
109 HTMLIndexReportElement::generate()
110 {
111     QString previousReportType;
112
113     generateHeader();
114
115     s() << "<table align=\"center\" cellpadding=\"2\" "
116         << "style=\"background-color:" << colors.getColorName("default") << "\"";
117     s() << ">" << endl;
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\"";
122     s() << ">" << endl;
123     s() << "  </tr>" << endl;
124
125     for (Q3PtrListIterator<Report> ri(report->getProject()->getReportListIterator()); *ri != 0; ++ri)
126     {
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())
131         {
132             generateReportLine(*ri);
133         }
134     }
135     s() << " </thead>\n" << endl;
136     s() << "</table>" << endl;
137
138     return true;
139 }
140