Update URL and fix it to not break on redirects any more
parent
2522f41488
commit
0aaad3fba8
|
|
@ -203,8 +203,15 @@ void IntegrationPluginDateTime::searchGeoLocation()
|
||||||
qCDebug(dcDateTime()) << "Requesting geo location.";
|
qCDebug(dcDateTime()) << "Requesting geo location.";
|
||||||
|
|
||||||
QNetworkReply *reply = hardwareManager()->networkManager()->get(request);
|
QNetworkReply *reply = hardwareManager()->networkManager()->get(request);
|
||||||
connect(reply, &QNetworkReply::finished, this, &IntegrationPluginDateTime::onNetworkReplayFinished);
|
connect(reply, &QNetworkReply::finished, this, [reply, this](){
|
||||||
m_locationReplies.append(reply);
|
reply->deleteLater();
|
||||||
|
|
||||||
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
|
qCWarning(dcDateTime) << "Http error status for location request:" << reply->error();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
processGeoLocationData(reply->readAll());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntegrationPluginDateTime::processGeoLocationData(const QByteArray &data)
|
void IntegrationPluginDateTime::processGeoLocationData(const QByteArray &data)
|
||||||
|
|
@ -250,16 +257,22 @@ void IntegrationPluginDateTime::getTimes(const QString &latitude, const QString
|
||||||
urlQuery.addQueryItem("lng", longitude);
|
urlQuery.addQueryItem("lng", longitude);
|
||||||
urlQuery.addQueryItem("date", "today");
|
urlQuery.addQueryItem("date", "today");
|
||||||
|
|
||||||
QUrl url = QUrl("http://api.sunrise-sunset.org/json");
|
QUrl url = QUrl("https://api.sunrise-sunset.org/json");
|
||||||
url.setQuery(urlQuery.toString());
|
url.setQuery(urlQuery.toString());
|
||||||
|
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
request.setUrl(url);
|
request.setUrl(url);
|
||||||
|
|
||||||
QNetworkReply *reply = hardwareManager()->networkManager()->get(request);
|
QNetworkReply *reply = hardwareManager()->networkManager()->get(request);
|
||||||
connect(reply, &QNetworkReply::finished, this, &IntegrationPluginDateTime::onNetworkReplayFinished);
|
connect(reply, &QNetworkReply::finished, this, [reply, this](){
|
||||||
|
reply->deleteLater();
|
||||||
|
|
||||||
m_timeReplies.append(reply);
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
|
qCWarning(dcDateTime) << "Http error status for time request:" << reply->error();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
processTimesData(reply->readAll());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntegrationPluginDateTime::processTimesData(const QByteArray &data)
|
void IntegrationPluginDateTime::processTimesData(const QByteArray &data)
|
||||||
|
|
@ -304,30 +317,6 @@ void IntegrationPluginDateTime::processTimesData(const QByteArray &data)
|
||||||
updateTimes();
|
updateTimes();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntegrationPluginDateTime::onNetworkReplayFinished()
|
|
||||||
{
|
|
||||||
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
|
|
||||||
|
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
|
||||||
|
|
||||||
if (m_locationReplies.contains(reply)) {
|
|
||||||
m_locationReplies.removeAll(reply);
|
|
||||||
if (status != 200) {
|
|
||||||
qCWarning(dcDateTime) << "Http error status for location request:" << status << reply->error();
|
|
||||||
} else {
|
|
||||||
processGeoLocationData(reply->readAll());
|
|
||||||
}
|
|
||||||
} else if (m_timeReplies.contains(reply)) {
|
|
||||||
m_timeReplies.removeAll(reply);
|
|
||||||
if (status != 200) {
|
|
||||||
qCWarning(dcDateTime) << "Http error status for time request:" << status << reply->error();
|
|
||||||
} else {
|
|
||||||
processTimesData(reply->readAll());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reply->deleteLater();
|
|
||||||
}
|
|
||||||
|
|
||||||
void IntegrationPluginDateTime::onAlarm()
|
void IntegrationPluginDateTime::onAlarm()
|
||||||
{
|
{
|
||||||
Alarm *alarm = static_cast<Alarm *>(sender());
|
Alarm *alarm = static_cast<Alarm *>(sender());
|
||||||
|
|
|
||||||
|
|
@ -74,9 +74,6 @@ private:
|
||||||
QDateTime m_sunset;
|
QDateTime m_sunset;
|
||||||
QDateTime m_dawn;
|
QDateTime m_dawn;
|
||||||
|
|
||||||
QList<QNetworkReply *> m_locationReplies;
|
|
||||||
QList<QNetworkReply *> m_timeReplies;
|
|
||||||
|
|
||||||
void searchGeoLocation();
|
void searchGeoLocation();
|
||||||
void processGeoLocationData(const QByteArray &data);
|
void processGeoLocationData(const QByteArray &data);
|
||||||
|
|
||||||
|
|
@ -91,7 +88,6 @@ signals:
|
||||||
void dawn();
|
void dawn();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onNetworkReplayFinished();
|
|
||||||
void onAlarm();
|
void onAlarm();
|
||||||
void onCountdownTimeout();
|
void onCountdownTimeout();
|
||||||
void onCountdownRunningChanged(const bool &running);
|
void onCountdownRunningChanged(const bool &running);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue