Skip to content

Commit 5fdaf2f

Browse files
committed
read news url from current.json file
1 parent 6e6430f commit 5fdaf2f

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

News.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Item {
9494
}
9595

9696
Component.onCompleted: {
97-
fetchNews('https://unvanquished.net/api/get_recent_posts/');
97+
fetchNews(downloader.newsUrl);
9898
}
9999
}
100100

currentversionfetcher.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,20 @@ void CurrentVersionFetcher::reply(QNetworkReply* reply)
8080
QString updaterUrl;
8181
QString productVersion;
8282
QString productUrl;
83+
QString newsVersion;
84+
QString newsUrl;
8385

8486
if (reply->error() != QNetworkReply::NoError) {
8587
qDebug() << "CurrentVersionFetcher: network error";
86-
emit onCurrentVersions(updaterVersion, updaterUrl, productVersion, productUrl);
88+
emit onCurrentVersions(updaterVersion, updaterUrl, productVersion, productUrl, newsUrl);
8789
return;
8890
}
8991

9092
QJsonParseError error;
9193
QJsonDocument json = QJsonDocument::fromJson(reply->readAll(), &error);
9294
if (error.error != QJsonParseError::NoError) {
9395
qDebug() << "CurrentVersionFetcher: JSON parsing error";
94-
emit onCurrentVersions(updaterVersion, updaterUrl, productVersion, productUrl);
96+
emit onCurrentVersions(updaterVersion, updaterUrl, productVersion, productUrl, newsUrl);
9597
return;
9698
}
9799

@@ -101,6 +103,8 @@ void CurrentVersionFetcher::reply(QNetworkReply* reply)
101103

102104
ComponentVersionFetcher(jsonObject, "product", "all-all", &productVersion, &productUrl);
103105

104-
emit onCurrentVersions(updaterVersion, updaterUrl, productVersion, productUrl);
106+
ComponentVersionFetcher(jsonObject, "news", "all-all", &newsVersion, &newsUrl);
107+
108+
emit onCurrentVersions(updaterVersion, updaterUrl, productVersion, productUrl, newsUrl);
105109
}
106110

currentversionfetcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class CurrentVersionFetcher : public QObject
1414
void fetchCurrentVersion(QString url);
1515

1616
signals:
17-
void onCurrentVersions(QString updaterVersion, QString updaterUrl, QString productVersion, QString productUrl);
17+
void onCurrentVersions(QString updaterVersion, QString updaterUrl, QString productVersion, QString productUrl, QString newsUrl);
1818

1919
private slots:
2020
void reply(QNetworkReply* reply);

qmldownloader.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ QmlDownloader::~QmlDownloader()
2424
stopAria();
2525
}
2626

27+
QString QmlDownloader::newsUrl() const {
28+
return latestNewsUrl_;
29+
}
30+
2731
int QmlDownloader::downloadSpeed() const {
2832
return downloadSpeed_;
2933
}
@@ -44,6 +48,10 @@ int QmlDownloader::completedSize() const {
4448
return completedSize_;
4549
}
4650

51+
void QmlDownloader::setNewsUrl(QString newsUrl) {
52+
latestNewsUrl_ = newsUrl;
53+
}
54+
4755
void QmlDownloader::setDownloadSpeed(int speed) {
4856
downloadSpeed_ = speed;
4957
downloadTime_.addSpeed(speed);
@@ -198,17 +206,19 @@ void QmlDownloader::stopAria()
198206
// Initiates an asynchronous request for the latest available versions.
199207
void QmlDownloader::checkForUpdate()
200208
{
201-
connect(&fetcher_, SIGNAL(onCurrentVersions(QString, QString, QString, QString)), this, SLOT(onCurrentVersions(QString, QString, QString, QString)));
209+
connect(&fetcher_, SIGNAL(onCurrentVersions(QString, QString, QString, QString, QString)), this, SLOT(onCurrentVersions(QString, QString, QString, QString, QString)));
202210
fetcher_.fetchCurrentVersion("https://cdn.unvanquished.net/current.json");
203211
}
204212

205213
// Receives the results of the checkForUpdate request.
206-
void QmlDownloader::onCurrentVersions(QString updaterVersion, QString updaterUrl, QString productVersion, QString productUrl)
214+
void QmlDownloader::onCurrentVersions(QString updaterVersion, QString updaterUrl, QString productVersion, QString productUrl, QString newsUrl)
207215
{
208216
latestUpdaterVersion_ = updaterVersion;
209217
latestUpdaterUrl_ = updaterUrl;
210218
latestProductVersion_ = productVersion;
211219
latestProductUrl_ = productUrl;
220+
221+
setNewsUrl(newsUrl);
212222
}
213223

214224
// This runs after the splash screen has been displayed for the programmed amount of time (and the

qmldownloader.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
class QmlDownloader : public QObject
2020
{
2121
Q_OBJECT
22+
Q_PROPERTY(QString newsUrl READ newsUrl)
2223
Q_PROPERTY(int downloadSpeed READ downloadSpeed NOTIFY downloadSpeedChanged)
2324
Q_PROPERTY(int uploadSpeed READ uploadSpeed NOTIFY uploadSpeedChanged)
2425
Q_PROPERTY(int eta READ eta NOTIFY etaChanged)
@@ -37,6 +38,7 @@ class QmlDownloader : public QObject
3738

3839
QmlDownloader();
3940
~QmlDownloader();
41+
QString newsUrl() const;
4042
int downloadSpeed() const;
4143
int uploadSpeed() const;
4244
int eta() const;
@@ -59,12 +61,13 @@ class QmlDownloader : public QObject
5961
void stateChanged(DownloadState state);
6062

6163
public slots:
64+
void setNewsUrl(QString newsUrl);
6265
void setDownloadSpeed(int speed);
6366
void setUploadSpeed(int speed);
6467
void setTotalSize(int size);
6568
void setCompletedSize(int size);
6669
void onDownloadEvent(int event);
67-
void onCurrentVersions(QString updaterVersion, QString updaterUrl, QString productVersion, QString productUrl);
70+
void onCurrentVersions(QString updaterVersion, QString updaterUrl, QString productVersion, QString productUrl, QString newsUrl);
6871

6972
Q_INVOKABLE void startUpdate();
7073
Q_INVOKABLE void toggleDownload();
@@ -91,6 +94,7 @@ public slots:
9194
QString latestUpdaterUrl_;
9295
QString latestProductVersion_;
9396
QString latestProductUrl_;
97+
QString latestNewsUrl_;
9498
DownloadState state_;
9599
std::unique_ptr<QTemporaryDir> temp_dir_;
96100

0 commit comments

Comments
 (0)