From 24aaf7978b1c4c685f086641ab5794a5b5ea3541 Mon Sep 17 00:00:00 2001 From: Nils Schwabe Date: Mon, 24 Mar 2014 16:10:16 +0100 Subject: added news and help download --- src/dialog.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/dialog.cpp') diff --git a/src/dialog.cpp b/src/dialog.cpp index 9fdbaa9..4e65d16 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "ui_dialog.h" #include "sessiontreeitem.h" @@ -483,3 +484,51 @@ void Dialog::on_helpNewsButton_clicked() { ui->newsBox->show(); } } + +void Dialog::addNewsAfterDownload(QNetworkReply* reply) { + if (reply->error() != QNetworkReply::NoError) { + if (debugMode) { + qDebug() << "Could not get news."; + } + return; + } + QByteArray data = reply->readAll(); + QDomDocument doc; + if (!doc.setContent(data)) { + qDebug() << "News XML contains errors."; + return; + } + QDomElement newsNode = doc.firstChildElement("news"); + QDateTime timestamp; + timestamp.setTime_t(newsNode.firstChildElement("date").text().toInt()); + + if (ChooserSettings::getSetting("last-news").toUInt() > timestamp.toTime_t()) { + return; + } + + // format and print news + ui->newsTextBrowser->setText(QString("

" + newsNode.firstChildElement("headline").text() + "

" + + timestamp.toString(Qt::SystemLocaleShortDate) + "

" + + newsNode.firstChildElement("info").text() + "

")); + + on_helpNewsButton_clicked(); +} + +void Dialog::addHelpAfterDownload(QNetworkReply* reply) { + if (reply->error() != QNetworkReply::NoError) { + if (debugMode) { + qDebug() << "Could not get news."; + } + return; + } + QByteArray data = reply->readAll(); + + QDomDocument doc; + if (!doc.setContent(data)) { + qDebug() << "Help file contains errors."; + return; + } + + ui->helpTextBrowser->setText(QString(data)); + +} -- cgit v1.2.3-55-g7522