refactor: move url creation for mods to modplatform/

Moves all things related to creating the URLs of the mod platforms
that go to network tasks to a single place, so that:

1. Maintaining and fixing eventual issues is more straightforward.
2. Makes it possible to factor out more common code between the
   different modplatform pages
This commit is contained in:
flow
2022-03-02 23:01:23 -03:00
parent 0dd1c26cf3
commit 2d68308d49
14 changed files with 130 additions and 79 deletions

View File

@ -1,6 +1,8 @@
#include "ModModel.h"
#include "ModPage.h"
#include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h"
#include "ui/dialogs/ModDownloadDialog.h"
#include <QMessageBox>
@ -95,6 +97,24 @@ void ListModel::getLogo(const QString& logo, const QString& logoUrl, LogoCallbac
}
}
void ListModel::performPaginatedSearch()
{
QString mcVersion = ((MinecraftInstance*)((ModPage*)parent())->m_instance)->getPackProfile()->getComponentVersion("net.minecraft");
bool hasFabric = !((MinecraftInstance*)((ModPage*)parent())->m_instance)
->getPackProfile()
->getComponentVersion("net.fabricmc.fabric-loader")
.isEmpty();
auto netJob = new NetJob(QString("%1::Search").arg(m_parent->debugName()), APPLICATION->network());
auto searchUrl = m_parent->apiProvider()->getModSearchURL(nextSearchOffset, currentSearchTerm, getSorts()[currentSort], hasFabric, mcVersion);
netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response));
jobPtr = netJob;
jobPtr->start();
QObject::connect(netJob, &NetJob::succeeded, this, &ListModel::searchRequestFinished);
QObject::connect(netJob, &NetJob::failed, this, &ListModel::searchRequestFailed);
}
void ListModel::searchWithTerm(const QString& term, const int sort)
{
if (currentSearchTerm == term && currentSearchTerm.isNull() == term.isNull() && currentSort == sort) { return; }