author | Sebastian Brannstrom <sebastianb@symbian.org> |
Tue, 10 Aug 2010 19:10:57 +0100 | |
changeset 22 | d5911f90500d |
parent 3 | e6d1a78b6db9 |
permissions | -rwxr-xr-x |
1 | 1 |
#include <QFile> |
2 |
#include <QFileInfo> |
|
3 |
#include <QDomDocument> |
|
4 |
#include <QDomElement> |
|
5 |
#include <QDomNode> |
|
6 |
#include <QMessageBox> |
|
3
e6d1a78b6db9
wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
2
diff
changeset
|
7 |
#include <QGroupBox> |
1 | 8 |
|
9 |
#include <QtGlobal> |
|
10 |
#include <QRegExp> |
|
2
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
11 |
#include <QStringList> |
1 | 12 |
|
13 |
#include <QGridLayout> |
|
14 |
#include <QLabel> |
|
15 |
||
16 |
#include <iostream> |
|
17 |
||
18 |
using namespace std; |
|
19 |
||
20 |
#include "AtAGlance.h" |
|
21 |
||
22 |
AtAGlance::AtAGlance(QString filename, QWidget *parent) |
|
3
e6d1a78b6db9
wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
2
diff
changeset
|
23 |
: QWidget(parent), ui(new Ui::BuildResultsForm) |
1 | 24 |
{ |
3
e6d1a78b6db9
wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
2
diff
changeset
|
25 |
ui->setupUi(this); |
1 | 26 |
setAttribute(Qt::WA_DeleteOnClose); |
27 |
||
28 |
QFile file(filename); |
|
29 |
QFileInfo fi(file); |
|
30 |
this->setWindowTitle("Status " + fi.baseName()); |
|
31 |
||
32 |
m_buildStatus = new BuildStatus(); |
|
33 |
m_buildStatus->setTime(fi.lastModified()); |
|
34 |
||
35 |
if (!file.open(QIODevice::ReadOnly)) { |
|
36 |
QMessageBox::warning(this, tr("Build Log Viewer"), tr("Cannot open log.")); |
|
37 |
return ; |
|
38 |
} |
|
39 |
m_log = new QDomDocument("Build Log"); |
|
40 |
if (!m_log->setContent(&file)) { |
|
41 |
QMessageBox::warning(this, tr("Build Log Viewer"), tr("Cannot set content.")); |
|
42 |
file.close(); |
|
43 |
return ; |
|
44 |
} |
|
45 |
file.close(); |
|
46 |
} |
|
47 |
||
48 |
AtAGlance::~AtAGlance() |
|
49 |
{ |
|
50 |
delete m_log; |
|
51 |
delete m_buildStatus; |
|
52 |
} |
|
53 |
||
54 |
// Walk Dom tree. |
|
55 |
void AtAGlance::traveAndPopulate() |
|
56 |
{ |
|
57 |
this->traveAndPopulate(m_log->documentElement()); |
|
58 |
} |
|
2
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
59 |
|
1 | 60 |
void AtAGlance::traveAndPopulate(QDomElement e) |
61 |
{ |
|
62 |
QString name = e.tagName(); |
|
63 |
||
64 |
if (e.isNull()) |
|
65 |
{ |
|
66 |
return; |
|
67 |
} |
|
68 |
||
69 |
// if this is an info tags, look for |
|
70 |
// <info>System Definition file sf/app/organizer/package_definition.xml</info> |
|
71 |
if (name.compare("info",Qt::CaseInsensitive)== 0 ) |
|
72 |
{ |
|
73 |
// example |
|
74 |
// System Definition file sf/app/organizer/package_definition.xml |
|
2
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
75 |
QRegExp re("System*package_definition.xml"); |
1 | 76 |
re.setPatternSyntax(QRegExp::Wildcard); |
77 |
||
78 |
if (re.exactMatch( e.text() ) ) |
|
79 |
{ |
|
2
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
80 |
QRegExp reToken("*package_definition.xml"); |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
81 |
// Which regex syntax should be used? Wildcard is ... |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
82 |
reToken.setPatternSyntax(QRegExp::Wildcard); |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
83 |
|
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
84 |
QStringList tokens = e.text().split(" "); |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
85 |
QStringList::const_iterator constIterator; |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
86 |
for (constIterator = tokens.constBegin(); |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
87 |
constIterator != tokens.constEnd(); |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
88 |
++constIterator) |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
89 |
{ |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
90 |
if (reToken.exactMatch(*constIterator)) |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
91 |
{ |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
92 |
m_buildStatus->setName((*constIterator).toLocal8Bit().constData()); |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
93 |
} |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
94 |
} |
1 | 95 |
} |
96 |
} |
|
97 |
||
98 |
// if this is a status tag and the exit attribute is failed, the build failed. |
|
99 |
if (name.compare("status",Qt::CaseInsensitive)== 0 ) |
|
100 |
{ |
|
2
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
101 |
QString rc = e.attribute("exit"); |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
102 |
if (!rc.isEmpty() && (rc.compare("failed", Qt::CaseInsensitive) == 0)) |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
103 |
{ |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
104 |
m_buildStatus->setStatus(false); |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
105 |
} |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
106 |
} |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
107 |
|
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
108 |
// unforunately, the build log isn't valid xml. The recipe tag often contains |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
109 |
// trace output from a shell program in addition to the status tag. Sigh. |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
110 |
// So this condition looks for the status tag in the body for the recipe tag. |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
111 |
// here is what the status tag should look like: |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
112 |
// <status exit='ok' attempt='1' /> |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
113 |
if (name.compare("recipe",Qt::CaseInsensitive)== 0 ) |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
114 |
{ |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
115 |
QRegExp re("*status exit*fail*"); |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
116 |
re.setPatternSyntax(QRegExp::Wildcard); |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
117 |
if (re.exactMatch(e.text())) |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
118 |
{ |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
119 |
m_buildStatus->setStatus(false); |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
120 |
} |
1 | 121 |
} |
122 |
||
123 |
QString text_debug; |
|
124 |
QDomElement e1 = e.firstChild().toElement(); |
|
2
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
125 |
name = e1.tagName(); |
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
126 |
text_debug = e1.text(); |
1 | 127 |
while(!e1.isNull()) |
128 |
{ |
|
129 |
this->traveAndPopulate(e1); |
|
130 |
e1 = e1.nextSibling().toElement(); |
|
131 |
name = e1.tagName(); |
|
132 |
text_debug = e1.text(); |
|
133 |
} |
|
134 |
} |
|
135 |
||
136 |
void AtAGlance::decideOnLayout() |
|
137 |
{ |
|
3
e6d1a78b6db9
wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
2
diff
changeset
|
138 |
// QHBoxLayout *hLayout = new QHBoxLayout(this); |
e6d1a78b6db9
wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
2
diff
changeset
|
139 |
// QGroupBox *groupBox = new QGroupBox( "Synopsis of Build" ); |
1 | 140 |
QGridLayout *layout = new QGridLayout(this); |
141 |
||
142 |
layout->addWidget(new QLabel("What: "), 1, 1); |
|
2
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
143 |
layout->addWidget(new QLabel(*m_buildStatus->name()),1,2); |
1 | 144 |
layout->addWidget(new QLabel("When: "), 2, 1); |
2
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
145 |
layout->addWidget(new QLabel(m_buildStatus->time()) ,2,2); |
1 | 146 |
layout->addWidget(new QLabel("Status: "), 3, 1); |
2
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
147 |
layout->addWidget(new QLabel(*m_buildStatus->status()),3,2); |
3
e6d1a78b6db9
wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
2
diff
changeset
|
148 |
|
e6d1a78b6db9
wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
2
diff
changeset
|
149 |
// hLayout->addWidget(layout); |
1 | 150 |
} |