Resolved nerworkrequest.hpp merge conflict

This commit is contained in:
apa420 2018-05-14 15:47:25 +02:00
commit 1f21f1c379
2 changed files with 50 additions and 25 deletions

View file

@ -85,9 +85,26 @@ install [chatterino2-git](https://aur.archlinux.org/packages/chatterino2-git/) f
### Mac OSX ### Mac OSX
1. install Xcode and Xcode Command Line Utilites 1. install Xcode and Xcode Command Line Utilites
2. install Qt Creator 2. start Xcode, settings -> Locations, activate your Command Line Tools
3. install brew https://brew.sh/ 3. install Qt Creator
4. `brew install boost openssl rapidjson` 4. install brew https://brew.sh/
5. build the project using Qt Creator 5. `brew install boost openssl rapidjson`
6. build the project using Qt Creator
If the Project does not build at this point, you might need to add additional Paths/Libs, because brew does not install openssl and boost in the common path. You can get their path using
`brew info openssl`
`brew info boost`
The lines which you need to add to your project file should look similar to this
```
INCLUDEPATH += /usr/local/opt/openssl/include
LIBS += -L/usr/local/opt/openssl/lib
INCLUDEPATH += "/usr/local/Cellar/boost/1.67.0_1/include"
LIBS += -L"/usr/local/Cellar/boost/1.67.0_1/lib"
```
Test 1 Test 1

View file

@ -216,7 +216,7 @@ public:
if (this->data.caller != nullptr) { if (this->data.caller != nullptr) {
QObject::connect(worker, &NetworkWorker::doneUrl, this->data.caller, QObject::connect(worker, &NetworkWorker::doneUrl, this->data.caller,
[onFinished, data = this->data](auto reply) mutable { [ onFinished, data = this->data ](auto reply) mutable {
if (reply->error() != QNetworkReply::NetworkError::NoError) { if (reply->error() != QNetworkReply::NetworkError::NoError) {
// TODO: We might want to call an onError callback here // TODO: We might want to call an onError callback here
return; return;
@ -238,7 +238,7 @@ public:
QObject::connect( QObject::connect(
&requester, &NetworkRequester::requestUrl, worker, &requester, &NetworkRequester::requestUrl, worker,
[timer, data = std::move(this->data), worker, onFinished{std::move(onFinished)}]() { [ timer, data = std::move(this->data), worker, onFinished{std::move(onFinished)} ]() {
QNetworkReply *reply = NetworkManager::NaM.get(data.request); QNetworkReply *reply = NetworkManager::NaM.get(data.request);
if (timer != nullptr) { if (timer != nullptr) {
@ -253,21 +253,21 @@ public:
data.onReplyCreated(reply); data.onReplyCreated(reply);
} }
QObject::connect(reply, &QNetworkReply::finished, worker, QObject::connect(reply, &QNetworkReply::finished, worker, [
[data = std::move(data), worker, reply, data = std::move(data), worker, reply, onFinished = std::move(onFinished)
onFinished = std::move(onFinished)]() mutable { ]() mutable {
if (data.caller == nullptr) { if (data.caller == nullptr) {
QByteArray bytes = reply->readAll(); QByteArray bytes = reply->readAll();
data.writeToCache(bytes); data.writeToCache(bytes);
onFinished(bytes); onFinished(bytes);
reply->deleteLater(); reply->deleteLater();
} else { } else {
emit worker->doneUrl(reply); emit worker->doneUrl(reply);
} }
delete worker; delete worker;
}); });
}); });
emit requester.requestUrl(); emit requester.requestUrl();
@ -276,7 +276,7 @@ public:
template <typename FinishedCallback> template <typename FinishedCallback>
void getJSON(FinishedCallback onFinished) void getJSON(FinishedCallback onFinished)
{ {
this->get([onFinished{std::move(onFinished)}](const QByteArray &bytes) -> bool { this->get([onFinished{std::move(onFinished)}](const QByteArray &bytes)->bool {
auto object = parseJSONFromData(bytes); auto object = parseJSONFromData(bytes);
onFinished(object); onFinished(object);
@ -289,7 +289,7 @@ public:
template <typename FinishedCallback> template <typename FinishedCallback>
void getJSON2(FinishedCallback onFinished) void getJSON2(FinishedCallback onFinished)
{ {
this->get([onFinished{std::move(onFinished)}](const QByteArray &bytes) -> bool { this->get([onFinished{std::move(onFinished)}](const QByteArray &bytes)->bool {
auto object = parseJSONFromData2(bytes); auto object = parseJSONFromData2(bytes);
onFinished(object); onFinished(object);
@ -369,10 +369,18 @@ private:
worker->moveToThread(&NetworkManager::workerThread); worker->moveToThread(&NetworkManager::workerThread);
if (this->data.caller != nullptr) { if (this->data.caller != nullptr) {
QObject::connect(worker, &NetworkWorker::doneUrl, this->data.caller, QObject::connect(worker, &NetworkWorker::doneUrl,
[data = this->data](auto reply) mutable { this->data.caller, [data = this->data](auto reply) mutable {
auto &dat = data;
if (reply->error() != QNetworkReply::NetworkError::NoError) { if (reply->error() != QNetworkReply::NetworkError::NoError) {
// TODO: We might want to call an onError callback here // TODO: We might want to call an onError callback here
if (data.onError) {
data.onError(reply->error());
}
return; return;
} }
@ -391,7 +399,7 @@ private:
} }
QObject::connect(&requester, &NetworkRequester::requestUrl, worker, QObject::connect(&requester, &NetworkRequester::requestUrl, worker,
[timer, data = std::move(this->data), worker]() { [ timer, data = std::move(this->data), worker ]() {
QNetworkReply *reply; QNetworkReply *reply;
switch (data.requestType) { switch (data.requestType) {
case GetRequest: { case GetRequest: {
@ -427,7 +435,7 @@ private:
} }
QObject::connect(reply, &QNetworkReply::finished, worker, QObject::connect(reply, &QNetworkReply::finished, worker,
[data = std::move(data), worker, reply]() mutable { [ data = std::move(data), worker, reply ]() mutable {
if (data.caller == nullptr) { if (data.caller == nullptr) {
QByteArray bytes = reply->readAll(); QByteArray bytes = reply->readAll();
data.writeToCache(bytes); data.writeToCache(bytes);