|
1 #include <QFile> |
|
2 #include <QFileInfo> |
|
3 #include <QDomDocument> |
|
4 #include <QDomElement> |
|
5 #include <QDomNode> |
|
6 #include <QMessageBox> |
|
7 |
|
8 #include <QtGlobal> |
|
9 #include <QRegExp> |
|
10 |
|
11 #include <QGridLayout> |
|
12 #include <QLabel> |
|
13 |
|
14 #include <iostream> |
|
15 |
|
16 using namespace std; |
|
17 |
|
18 #include "AtAGlance.h" |
|
19 |
|
20 AtAGlance::AtAGlance(QString filename, QWidget *parent) |
|
21 { |
|
22 setAttribute(Qt::WA_DeleteOnClose); |
|
23 |
|
24 QFile file(filename); |
|
25 QFileInfo fi(file); |
|
26 this->setWindowTitle("Status " + fi.baseName()); |
|
27 |
|
28 m_buildStatus = new BuildStatus(); |
|
29 m_buildStatus->setTime(fi.lastModified()); |
|
30 |
|
31 if (!file.open(QIODevice::ReadOnly)) { |
|
32 QMessageBox::warning(this, tr("Build Log Viewer"), tr("Cannot open log.")); |
|
33 return ; |
|
34 } |
|
35 m_log = new QDomDocument("Build Log"); |
|
36 if (!m_log->setContent(&file)) { |
|
37 QMessageBox::warning(this, tr("Build Log Viewer"), tr("Cannot set content.")); |
|
38 file.close(); |
|
39 return ; |
|
40 } |
|
41 file.close(); |
|
42 } |
|
43 |
|
44 AtAGlance::~AtAGlance() |
|
45 { |
|
46 delete m_log; |
|
47 delete m_buildStatus; |
|
48 } |
|
49 |
|
50 // Walk Dom tree. |
|
51 void AtAGlance::traveAndPopulate() |
|
52 { |
|
53 this->traveAndPopulate(m_log->documentElement()); |
|
54 } |
|
55 void AtAGlance::traveAndPopulate(QDomElement e) |
|
56 { |
|
57 QString name = e.tagName(); |
|
58 |
|
59 if (e.isNull()) |
|
60 { |
|
61 return; |
|
62 } |
|
63 |
|
64 // if this is an info tags, look for |
|
65 // <info>System Definition file sf/app/organizer/package_definition.xml</info> |
|
66 if (name.compare("info",Qt::CaseInsensitive)== 0 ) |
|
67 { |
|
68 // example |
|
69 // System Definition file sf/app/organizer/package_definition.xml |
|
70 QRegExp re("^System Definition file .*package_definition.*$"); |
|
71 re.setPatternSyntax(QRegExp::Wildcard); |
|
72 |
|
73 string blah = e.text().toStdString(); |
|
74 |
|
75 if (re.exactMatch( e.text() ) ) |
|
76 { |
|
77 std::cout << "info: " << e.text().toStdString()<< std::endl; |
|
78 } |
|
79 } |
|
80 |
|
81 // if this is a status tag and the exit attribute is failed, the build failed. |
|
82 if (name.compare("status",Qt::CaseInsensitive)== 0 ) |
|
83 { |
|
84 m_buildStatus->setStatus(false); |
|
85 } |
|
86 |
|
87 QString text_debug; |
|
88 QDomElement e1 = e.firstChild().toElement(); |
|
89 while(!e1.isNull()) |
|
90 { |
|
91 this->traveAndPopulate(e1); |
|
92 e1 = e1.nextSibling().toElement(); |
|
93 name = e1.tagName(); |
|
94 text_debug = e1.text(); |
|
95 } |
|
96 } |
|
97 |
|
98 void AtAGlance::decideOnLayout() |
|
99 { |
|
100 QGridLayout *layout = new QGridLayout(this); |
|
101 |
|
102 layout->addWidget(new QLabel("What: "), 1, 1); |
|
103 layout->addWidget(new QLabel("When: "), 2, 1); |
|
104 layout->addWidget(new QLabel("Status: "), 3, 1); |
|
105 } |