fix: abort search if we're already trying to download a pack

Meaning we don't have to wait for the searches to finish in the
background to finally start the modpack download, when we have already
selected it -_-

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2022-10-13 13:49:06 -03:00
parent 83654a193e
commit f26be00571
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
5 changed files with 31 additions and 0 deletions

View File

@ -139,6 +139,10 @@ NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, const QString
void NewInstanceDialog::reject()
{
APPLICATION->settings()->set("NewInstanceGeometry", saveGeometry().toBase64());
// This is just so that the pages get the close() call and can react to it, if needed.
m_container->prepareToClose();
QDialog::reject();
}
@ -146,6 +150,10 @@ void NewInstanceDialog::accept()
{
APPLICATION->settings()->set("NewInstanceGeometry", saveGeometry().toBase64());
importIconNow();
// This is just so that the pages get the close() call and can react to it, if needed.
m_container->prepareToClose();
QDialog::accept();
}

View File

@ -103,6 +103,8 @@ void ListModel::getLogo(const QString &logo, const QString &logoUrl, LogoCallbac
void ListModel::request()
{
m_aborted = false;
beginResetModel();
modpacks.clear();
endResetModel();
@ -117,6 +119,12 @@ void ListModel::request()
QObject::connect(netJob, &NetJob::failed, this, &ListModel::requestFailed);
}
void ListModel::abortRequest()
{
m_aborted = jobPtr->abort();
jobPtr.reset();
}
void ListModel::requestFinished()
{
jobPtr.reset();
@ -162,6 +170,9 @@ void ListModel::requestPack()
void ListModel::packRequestFinished()
{
if (!jobPtr || m_aborted)
return;
jobPtr.reset();
remainingPacks.removeOne(currentPack);

View File

@ -47,9 +47,12 @@ public:
QVariant data(const QModelIndex &index, int role) const override;
void request();
void abortRequest();
void getLogo(const QString &logo, const QString &logoUrl, LogoCallback callback);
[[nodiscard]] bool isMakingRequest() const { return jobPtr.get(); }
private slots:
void requestFinished();
void requestFailed(QString reason);
@ -65,6 +68,8 @@ private:
void requestLogo(QString file, QString url);
private:
bool m_aborted = false;
QList<ModpacksCH::Modpack> modpacks;
LogoMap m_logoMap;

View File

@ -114,6 +114,12 @@ void FtbPage::openedImpl()
suggestCurrent();
}
void FtbPage::closedImpl()
{
if (listModel->isMakingRequest())
listModel->abortRequest();
}
void FtbPage::suggestCurrent()
{
if(!isOpened)

View File

@ -78,6 +78,7 @@ public:
void retranslate() override;
void openedImpl() override;
void closedImpl() override;
bool eventFilter(QObject * watched, QEvent * event) override;