diff options
-rw-r--r-- | src/dialog.cpp | 49 | ||||
-rw-r--r-- | src/dialog.h | 2 | ||||
-rw-r--r-- | src/httpxmldownloader.cpp | 9 | ||||
-rw-r--r-- | src/httpxmldownloader.h | 4 | ||||
-rw-r--r-- | src/main.cpp | 15 | ||||
-rw-r--r-- | src/ui/dialog.ui | 10 |
6 files changed, 74 insertions, 15 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)); + +} diff --git a/src/dialog.h b/src/dialog.h index 8386e1d..d6391ac 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -61,6 +61,8 @@ class Dialog : public QDialog { public slots: void addSessionsAfterDownload(QNetworkReply* reply); + void addNewsAfterDownload(QNetworkReply* reply); + void addHelpAfterDownload(QNetworkReply* reply); }; #endif // DIALOG_H diff --git a/src/httpxmldownloader.cpp b/src/httpxmldownloader.cpp index 0d09e6f..208caf0 100644 --- a/src/httpxmldownloader.cpp +++ b/src/httpxmldownloader.cpp @@ -2,15 +2,14 @@ #include "httpxmldownloader.h" #include <QDebug> -httpxmldownloader::httpxmldownloader() { +HttpXmlDownloader::HttpXmlDownloader() { nam = new QNetworkAccessManager(this); } -QNetworkReply* httpxmldownloader::makeRequest(const QString& xmlurl) { +QNetworkReply* HttpXmlDownloader::makeRequest(const QString& xmlurl) { return nam->get(QNetworkRequest(QUrl(xmlurl))); } -void httpxmldownloader::connectSlot(QObject* obj, const char* slot) { - QObject::connect(nam, SIGNAL(finished(QNetworkReply*)), - obj, slot); +void HttpXmlDownloader::connectSlot(QObject* obj, const char* slot) { + QObject::connect(nam, SIGNAL(finished(QNetworkReply*)), obj, slot); } diff --git a/src/httpxmldownloader.h b/src/httpxmldownloader.h index c30e0f8..ef6444f 100644 --- a/src/httpxmldownloader.h +++ b/src/httpxmldownloader.h @@ -7,11 +7,11 @@ #include <QNetworkRequest> #include <QNetworkReply> -class httpxmldownloader : public QObject { +class HttpXmlDownloader : public QObject { Q_OBJECT QNetworkAccessManager* nam; public: - httpxmldownloader(); + HttpXmlDownloader(); QNetworkReply* makeRequest(const QString& xmlurl); void connectSlot(QObject* obj, const char* slot); }; diff --git a/src/main.cpp b/src/main.cpp index 722f80a..f20564d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -172,7 +172,9 @@ int main(int argc, char *argv[]) { Dialog w; - httpxmldownloader httpxmldownloader; + /* DOWNLOAD VSESSIONS */ + + HttpXmlDownloader httpxmldownloader; httpxmldownloader.connectSlot(&w, SLOT(addSessionsAfterDownload(QNetworkReply*))); if (!vSessionUrl.isEmpty()) { @@ -180,6 +182,17 @@ int main(int argc, char *argv[]) { httpxmldownloader.makeRequest(vSessionUrl); } + /* DOWNLOAD NEWS */ + HttpXmlDownloader news_downloader; + news_downloader.connectSlot(&w, SLOT(addNewsAfterDownload(QNetworkReply*))); + // TODO: url + news_downloader.makeRequest("http://localhost/news.php"); + + /* DOWNLOAD HELP-SECTION */ + HttpXmlDownloader help_downloader; + help_downloader.connectSlot(&w, SLOT(addHelpAfterDownload(QNetworkReply*))); + help_downloader.makeRequest("http://localhost/help.php"); + w.setTheme(); w.setWindowFlags(Qt::FramelessWindowHint); diff --git a/src/ui/dialog.ui b/src/ui/dialog.ui index fdbb402..55a1441 100644 --- a/src/ui/dialog.ui +++ b/src/ui/dialog.ui @@ -121,17 +121,13 @@ margin-bottom:0px;}</string> </property> <layout class="QHBoxLayout" name="horizontalLayout_9"> <item> - <widget class="QTextBrowser" name="textBrowser_2"> + <widget class="QTextBrowser" name="helpTextBrowser"> <property name="html"> <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Tabs</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Lorem ipsum</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Filter</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Dolor sit amet</p></body></html></string> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Loading...</p></body></html></string> </property> </widget> </item> @@ -151,7 +147,7 @@ p, li { white-space: pre-wrap; } </property> <layout class="QHBoxLayout" name="horizontalLayout_10"> <item> - <widget class="QTextBrowser" name="textBrowser_3"> + <widget class="QTextBrowser" name="newsTextBrowser"> <property name="html"> <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> |