Skip to content

Commit 1416de7

Browse files
committed
misc
1 parent 5f5f64b commit 1416de7

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

breakdown/breakdown.cpp

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <QDebug>
3030
#include <QIcon>
3131
#include <QNetworkAccessManager>
32+
#include <QXmlStreamReader>
3233

3334
#if QT_VERSION >= 0x050000
3435
#include <QtConcurrent/QtConcurrentRun>
@@ -134,6 +135,11 @@ void BreakDown::setupWidgets()
134135
SIGNAL(parseDumpFinished(QString,QString,bool)),
135136
this,
136137
SLOT(handleParseDumpFinished(QString,QString,bool)));
138+
139+
connect(this,
140+
SIGNAL(parseReportsXMLFinished(QVector<QStringList>)),
141+
this,
142+
SLOT(populateReportsTree(QVector<QStringList>)));
137143
}
138144

139145
void BreakDown::setLineEditCursorPosition()
@@ -533,7 +539,6 @@ void BreakDown::handleParseDumpFinished(const QString &json,
533539

534540
void BreakDown::downloadReportXML(const QUrl &url)
535541
{
536-
qDebug() << "download xml from" << url;
537542
if (url.isEmpty()) { return; }
538543

539544
ui->statusBar->showMessage(tr("Downloading XML ..."), -1);
@@ -565,8 +570,9 @@ void BreakDown::downloadReportXMLFinished(QNetworkReply *reply)
565570
!reply->errorString().isEmpty())
566571
{
567572
ui->statusBar->showMessage(reply->errorString(), -1);
573+
} else {
574+
parseReportsXML(xml);
568575
}
569-
qDebug() << "remote reply" << xml;
570576

571577
reply->deleteLater();
572578
if (nam) { nam->deleteLater(); }
@@ -576,6 +582,31 @@ void BreakDown::parseReportsXML(const QString &xml)
576582
{
577583
qDebug() << "parse xml" << xml;
578584
if (xml.isEmpty()) { return; }
585+
586+
QXmlStreamReader reader(xml);
587+
if (reader.hasError()) {
588+
qDebug() << "BAD XML!";
589+
return;
590+
}
591+
592+
QVector<QStringList> reports;
593+
while (!reader.atEnd() && !reader.hasError()) {
594+
if (reader.readNext() == QXmlStreamReader::StartElement &&
595+
reader.name() == "report")
596+
{
597+
QStringList report;
598+
while (reader.readNextStartElement()) {
599+
if (reader.name() == "uuid") { report << reader.readElementText(); }
600+
else if (reader.name() == "dmp") { report << reader.readElementText(); }
601+
else if (reader.name() == "txt") { report << reader.readElementText(); }
602+
else { reader.skipCurrentElement(); }
603+
}
604+
if (report.size()==3) { reports.append(report); }
605+
}
606+
}
607+
if (reports.size()>0) {
608+
emit parseReportsXMLFinished(reports);
609+
}
579610
}
580611

581612
void BreakDown::handleAuthenticationRequired(QNetworkReply *reply,
@@ -619,6 +650,21 @@ void BreakDown::handleAuthenticationRequired(QNetworkReply *reply,
619650
}
620651
}
621652

653+
void BreakDown::populateReportsTree(QVector<QStringList> reports)
654+
{
655+
if (reports.size()==0) { return; }
656+
ui->reportsTree->clear();
657+
for (int i = 0; i < reports.size(); ++i) {
658+
if (reports.at(i).size()!=3) { continue; }
659+
QTreeWidgetItem *item = new QTreeWidgetItem(ui->reportsTree);
660+
item->setText(0, reports.at(i).at(0));
661+
item->setData(0, REPORTS_TREE_UUID, reports.at(i).at(0));
662+
item->setData(0, REPORTS_TREE_DMP, reports.at(i).at(1));
663+
item->setData(0, REPORTS_TREE_TXT, reports.at(i).at(2));
664+
ui->reportsTree->addTopLevelItem(item);
665+
}
666+
}
667+
622668
void BreakDown::on_actionClear_triggered()
623669
{
624670
clearReport();
@@ -640,7 +686,6 @@ void BreakDown::on_reportsTree_itemDoubleClicked(QTreeWidgetItem *item,
640686

641687
void BreakDown::on_actionUpdate_triggered()
642688
{
643-
qDebug() << "update reports!";
644689
QString server;
645690
QSettings settings;
646691
settings.beginGroup("auth");

breakdown/breakdown.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <QUrl>
2727
#include <QNetworkReply>
2828
#include <QAuthenticator>
29+
#include <QVector>
2930

3031
namespace Ui {
3132
class BreakDown;
@@ -41,6 +42,7 @@ class BreakDown : public QMainWindow
4142

4243
signals:
4344
void parseDumpFinished(const QString &json, const QString &uuid, bool failed);
45+
void parseReportsXMLFinished(QVector<QStringList> reports);
4446

4547
private slots:
4648
void loadSettings();
@@ -60,6 +62,7 @@ private slots:
6062
void downloadReportXMLFinished(QNetworkReply *reply);
6163
void parseReportsXML(const QString &xml);
6264
void handleAuthenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator);
65+
void populateReportsTree(QVector<QStringList> reports);
6366

6467
void on_actionClear_triggered();
6568

breakdown/breakdown.ui

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -860,18 +860,13 @@
860860
<item>
861861
<widget class="QTreeWidget" name="reportsTree">
862862
<attribute name="headerVisible">
863-
<bool>false</bool>
863+
<bool>true</bool>
864864
</attribute>
865865
<column>
866866
<property name="text">
867867
<string>UUID</string>
868868
</property>
869869
</column>
870-
<column>
871-
<property name="text">
872-
<string>Timestamp</string>
873-
</property>
874-
</column>
875870
</widget>
876871
</item>
877872
</layout>
@@ -915,6 +910,9 @@
915910
<property name="text">
916911
<string>Update</string>
917912
</property>
913+
<property name="shortcut">
914+
<string>Ctrl+U</string>
915+
</property>
918916
</action>
919917
</widget>
920918
<layoutdefault spacing="6" margin="11"/>

0 commit comments

Comments
 (0)