diff options
Diffstat (limited to 'src/dialog.cpp')
-rw-r--r-- | src/dialog.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
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 <QProcess> #include <QTimer> #include <QDesktopWidget> +#include <QDateTime> #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("<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>")); + + 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)); + +} |