summaryrefslogtreecommitdiffstats
path: root/src/dialog.cpp
diff options
context:
space:
mode:
authorSimon Rettberg2016-07-04 16:24:35 +0200
committerSimon Rettberg2016-07-04 16:24:35 +0200
commitc7f1b624c3bd64ce651eb72236ab9e142a7534a7 (patch)
treee4ee8747c367be147083f96b8200a27917bd0e72 /src/dialog.cpp
parentfixes build problem. (diff)
downloadvmchooser2-c7f1b624c3bd64ce651eb72236ab9e142a7534a7.tar.gz
vmchooser2-c7f1b624c3bd64ce651eb72236ab9e142a7534a7.tar.xz
vmchooser2-c7f1b624c3bd64ce651eb72236ab9e142a7534a7.zip
Parse XML reply for help text (just like news)
Diffstat (limited to 'src/dialog.cpp')
-rw-r--r--src/dialog.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/dialog.cpp b/src/dialog.cpp
index cd2b9b6..aefb6f9 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -571,13 +571,19 @@ void Dialog::addNewsAfterDownload(QNetworkReply* reply) {
return;
}
QDomElement newsNode = doc.firstChildElement("news");
+ QDomElement timeNode = newsNode.firstChildElement("date");
+ QDomElement infoNode = newsNode.firstChildElement("info");
QDateTime timestamp;
- timestamp.setTime_t(newsNode.firstChildElement("date").text().toInt());
+ timestamp.setTime_t(timeNode.text().toInt());
- // format and print news
- ui->newsTextBrowser->setText(QString("<p style='font-size:16px; margin-bottom: 2px;'>" + newsNode.firstChildElement("headline").text() + "</p> <small>"
- + timestamp.toString(Qt::SystemLocaleShortDate) + "</small><p>"
- + newsNode.firstChildElement("info").text() + "</p>"));
+ if (timeNode.isNull() || infoNode.isNull()) {
+ ui->newsTextBrowser->setText(QCoreApplication::instance()->translate("Dialog", "Could not get news. (//news/date or //news/info missing)"));
+ } else {
+ // format and print news
+ ui->newsTextBrowser->setText(QString("<p style='font-size:16px; margin-bottom: 2px;'>" + newsNode.firstChildElement("headline").text() + "</p> <small>"
+ + timestamp.toString(Qt::SystemLocaleShortDate) + "</small><p>"
+ + infoNode.text() + "</p>"));
+ }
if (ChooserSettings::getSetting("last-news").toUInt() < timestamp.toTime_t()) {
// show news if not seen before
@@ -640,7 +646,12 @@ void Dialog::addHelpAfterDownload(QNetworkReply* reply) {
return;
}
- ui->helpTextBrowser->setText(QString(data));
+ QDomElement newsNode = doc.firstChildElement("news").firstChildElement("info");
+ if (newsNode.isNull()) {
+ ui->helpTextBrowser->setText(QCoreApplication::instance()->translate("Dialog", "Could not get help (XML has no //news/info)"));
+ } else {
+ ui->helpTextBrowser->setText(newsNode.text());
+ }
// make backup
QFile file(help_backup_filename);