| 6 | #include "net/NetJob.h" |
| 7 | |
| 8 | void NetworkModAPI::searchMods(CallerType* caller, SearchArgs&& args) const |
| 9 | { |
| 10 | auto netJob = new NetJob(QString("%1::Search").arg(caller->debugName()), APPLICATION->network()); |
| 11 | auto searchUrl = getModSearchURL(args); |
| 12 | |
| 13 | auto response = new QByteArray(); |
| 14 | netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), response)); |
| 15 | |
| 16 | QObject::connect(netJob, &NetJob::started, caller, [caller, netJob] { caller->setActiveJob(netJob); }); |
| 17 | QObject::connect(netJob, &NetJob::failed, caller, &CallerType::searchRequestFailed); |
| 18 | QObject::connect(netJob, &NetJob::succeeded, caller, [caller, response] { |
| 19 | QJsonParseError parse_error{}; |
| 20 | QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); |
| 21 | if (parse_error.error != QJsonParseError::NoError) { |
| 22 | qWarning() << "Error while parsing JSON response from " << caller->debugName() << " at " << parse_error.offset |
| 23 | << " reason: " << parse_error.errorString(); |
| 24 | qWarning() << *response; |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | caller->searchRequestFinished(doc); |
| 29 | }); |
| 30 | |
| 31 | netJob->start(); |
| 32 | } |
| 33 | |
| 34 | void NetworkModAPI::getModInfo(ModPlatform::IndexedPack& pack, std::function<void(QJsonDocument&, ModPlatform::IndexedPack&)> callback) |
| 35 | { |
no test coverage detected