MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / searchMods

Method searchMods

launcher/modplatform/helpers/NetworkModAPI.cpp:8–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6#include "net/NetJob.h"
7
8void 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
34void NetworkModAPI::getModInfo(ModPlatform::IndexedPack& pack, std::function<void(QJsonDocument&, ModPlatform::IndexedPack&)> callback)
35{

Callers 1

Calls 9

QStringClass · 0.85
QUrlClass · 0.85
fromJsonFunction · 0.85
networkMethod · 0.80
addNetActionMethod · 0.80
debugNameMethod · 0.45
setActiveJobMethod · 0.45
searchRequestFinishedMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected