From 3d0f2b547f9fa1cdbca1c7ae7a67e95f32aff29f Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 19 Jan 2021 16:48:08 +0100 Subject: [PATCH] read news url from current.json file --- News.qml | 2 +- currentversionfetcher.cpp | 10 +++++++--- currentversionfetcher.h | 2 +- qmldownloader.cpp | 14 ++++++++++++-- qmldownloader.h | 6 +++++- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/News.qml b/News.qml index 58ba515..0be7356 100644 --- a/News.qml +++ b/News.qml @@ -94,7 +94,7 @@ Item { } Component.onCompleted: { - fetchNews('https://unvanquished.net/api/get_recent_posts/'); + fetchNews(downloader.newsUrl); } } diff --git a/currentversionfetcher.cpp b/currentversionfetcher.cpp index 0b770a9..8862959 100644 --- a/currentversionfetcher.cpp +++ b/currentversionfetcher.cpp @@ -80,10 +80,12 @@ void CurrentVersionFetcher::reply(QNetworkReply* reply) QString updaterUrl; QString gameVersion; QString gameUrl; + QString newsVersion; + QString newsUrl; if (reply->error() != QNetworkReply::NoError) { qDebug() << "CurrentVersionFetcher: network error"; - emit onCurrentVersions(updaterVersion, updaterUrl, gameVersion, gameUrl); + emit onCurrentVersions(updaterVersion, updaterUrl, gameVersion, gameUrl, newsUrl); return; } @@ -91,7 +93,7 @@ void CurrentVersionFetcher::reply(QNetworkReply* reply) QJsonDocument json = QJsonDocument::fromJson(reply->readAll(), &error); if (error.error != QJsonParseError::NoError) { qDebug() << "CurrentVersionFetcher: JSON parsing error"; - emit onCurrentVersions(updaterVersion, updaterUrl, gameVersion, gameUrl); + emit onCurrentVersions(updaterVersion, updaterUrl, gameVersion, gameUrl, newsUrl); return; } @@ -101,6 +103,8 @@ void CurrentVersionFetcher::reply(QNetworkReply* reply) ComponentVersionFetcher(jsonObject, "game", "all-all", &gameVersion, &gameUrl); - emit onCurrentVersions(updaterVersion, updaterUrl, gameVersion, gameUrl); + ComponentVersionFetcher(jsonObject, "news", "all-all", &newsVersion, &newsUrl); + + emit onCurrentVersions(updaterVersion, updaterUrl, gameVersion, gameUrl, newsUrl); } diff --git a/currentversionfetcher.h b/currentversionfetcher.h index 2527abf..411ec7c 100644 --- a/currentversionfetcher.h +++ b/currentversionfetcher.h @@ -14,7 +14,7 @@ class CurrentVersionFetcher : public QObject void fetchCurrentVersion(QString url); signals: - void onCurrentVersions(QString updaterVersion, QString updaterUrl, QString gameVersion, QString gameUrl); + void onCurrentVersions(QString updaterVersion, QString updaterUrl, QString gameVersion, QString gameUrl, QString newsUrl); private slots: void reply(QNetworkReply* reply); diff --git a/qmldownloader.cpp b/qmldownloader.cpp index f1986c0..7ec32fd 100644 --- a/qmldownloader.cpp +++ b/qmldownloader.cpp @@ -24,6 +24,10 @@ QmlDownloader::~QmlDownloader() stopAria(); } +QString QmlDownloader::newsUrl() const { + return latestNewsUrl_; +} + int QmlDownloader::downloadSpeed() const { return downloadSpeed_; } @@ -44,6 +48,10 @@ int QmlDownloader::completedSize() const { return completedSize_; } +void QmlDownloader::setNewsUrl(QString newsUrl) { + latestNewsUrl_ = newsUrl; +} + void QmlDownloader::setDownloadSpeed(int speed) { downloadSpeed_ = speed; downloadTime_.addSpeed(speed); @@ -198,17 +206,19 @@ void QmlDownloader::stopAria() // Initiates an asynchronous request for the latest available versions. void QmlDownloader::checkForUpdate() { - connect(&fetcher_, SIGNAL(onCurrentVersions(QString, QString, QString, QString)), this, SLOT(onCurrentVersions(QString, QString, QString, QString))); + connect(&fetcher_, SIGNAL(onCurrentVersions(QString, QString, QString, QString, QString)), this, SLOT(onCurrentVersions(QString, QString, QString, QString, QString))); fetcher_.fetchCurrentVersion("https://cdn.unvanquished.net/current.json"); } // Receives the results of the checkForUpdate request. -void QmlDownloader::onCurrentVersions(QString updaterVersion, QString updaterUrl, QString gameVersion, QString gameUrl) +void QmlDownloader::onCurrentVersions(QString updaterVersion, QString updaterUrl, QString gameVersion, QString gameUrl, QString newsUrl) { latestUpdaterVersion_ = updaterVersion; latestUpdaterUrl_ = updaterUrl; latestGameVersion_ = gameVersion; latestGameUrl_ = gameUrl; + + setNewsUrl(newsUrl); } // This runs after the splash screen has been displayed for the programmed amount of time (and the diff --git a/qmldownloader.h b/qmldownloader.h index 1bf4ae6..16e8f09 100644 --- a/qmldownloader.h +++ b/qmldownloader.h @@ -19,6 +19,7 @@ class QmlDownloader : public QObject { Q_OBJECT + Q_PROPERTY(QString newsUrl READ newsUrl) Q_PROPERTY(int downloadSpeed READ downloadSpeed NOTIFY downloadSpeedChanged) Q_PROPERTY(int uploadSpeed READ uploadSpeed NOTIFY uploadSpeedChanged) Q_PROPERTY(int eta READ eta NOTIFY etaChanged) @@ -37,6 +38,7 @@ class QmlDownloader : public QObject QmlDownloader(); ~QmlDownloader(); + QString newsUrl() const; int downloadSpeed() const; int uploadSpeed() const; int eta() const; @@ -59,12 +61,13 @@ class QmlDownloader : public QObject void stateChanged(DownloadState state); public slots: + void setNewsUrl(QString newsUrl); void setDownloadSpeed(int speed); void setUploadSpeed(int speed); void setTotalSize(int size); void setCompletedSize(int size); void onDownloadEvent(int event); - void onCurrentVersions(QString updaterVersion, QString updaterUrl, QString gameVersion, QString gameUrl); + void onCurrentVersions(QString updaterVersion, QString updaterUrl, QString gameVersion, QString gameUrl, QString newsUrl); Q_INVOKABLE void startUpdate(); Q_INVOKABLE void toggleDownload(); @@ -91,6 +94,7 @@ public slots: QString latestUpdaterUrl_; QString latestGameVersion_; QString latestGameUrl_; + QString latestNewsUrl_; DownloadState state_; std::unique_ptr temp_dir_;