Fix timer stuff (#580)

* Add and sort Network files to chatterino project file
This commit is contained in:
pajlada
2018-07-07 15:50:05 +02:00
committed by GitHub
parent 55269587f5
commit 2ea3643100
5 changed files with 62 additions and 45 deletions
+6 -6
View File
@@ -105,7 +105,6 @@ void NetworkRequest::execute()
// Get requests try to load from cache, then perform the request
if (this->data->useQuickLoadCache_) {
if (this->tryLoadCachedFile()) {
Log("Loaded from cache");
// Successfully loaded from cache
return;
}
@@ -167,8 +166,7 @@ void NetworkRequest::doRequest()
this->timer->start();
auto onUrlRequested = [data = std::move(this->data), timer = std::move(this->timer),
worker]() mutable {
auto onUrlRequested = [data = this->data, timer = this->timer, worker]() mutable {
QNetworkReply *reply = nullptr;
switch (data->requestType_) {
case NetworkRequestType::Get: {
@@ -205,7 +203,8 @@ void NetworkRequest::doRequest()
bool directAction = (data->caller_ == nullptr);
auto handleReply = [data = std::move(data), timer = std::move(timer), reply]() mutable {
auto handleReply = [data, timer, reply]() mutable {
// TODO(pajlada): A reply was received, kill the timeout timer
if (reply->error() != QNetworkReply::NetworkError::NoError) {
if (data->onError_) {
data->onError_(reply->error());
@@ -225,7 +224,8 @@ void NetworkRequest::doRequest()
};
if (data->caller_ != nullptr) {
QObject::connect(worker, &NetworkWorker::doneUrl, data->caller_, std::move(handleReply));
QObject::connect(worker, &NetworkWorker::doneUrl, data->caller_,
std::move(handleReply));
QObject::connect(reply, &QNetworkReply::finished, worker, [worker]() mutable {
emit worker->doneUrl();
@@ -241,7 +241,7 @@ void NetworkRequest::doRequest()
}
};
QObject::connect(&requester, &NetworkRequester::requestUrl, worker, std::move(onUrlRequested));
QObject::connect(&requester, &NetworkRequester::requestUrl, worker, onUrlRequested);
emit requester.requestUrl();
}