diff options
author | Nils Schwabe | 2014-03-24 16:10:16 +0100 |
---|---|---|
committer | Nils Schwabe | 2014-03-24 16:10:16 +0100 |
commit | 24aaf7978b1c4c685f086641ab5794a5b5ea3541 (patch) | |
tree | 5402e7459055eb3b68709035eaca29af6e50785f /src/dialog.cpp | |
parent | added choosersettings which remember the last selected session (diff) | |
download | vmchooser2-24aaf7978b1c4c685f086641ab5794a5b5ea3541.tar.gz vmchooser2-24aaf7978b1c4c685f086641ab5794a5b5ea3541.tar.xz vmchooser2-24aaf7978b1c4c685f086641ab5794a5b5ea3541.zip |
added news and help download
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)); + +} |