diff options
Diffstat (limited to 'launcher/pages/modplatform')
23 files changed, 76 insertions, 92 deletions
diff --git a/launcher/pages/modplatform/ImportPage.cpp b/launcher/pages/modplatform/ImportPage.cpp index c2369bdc..dd02e839 100644 --- a/launcher/pages/modplatform/ImportPage.cpp +++ b/launcher/pages/modplatform/ImportPage.cpp @@ -1,7 +1,7 @@ #include "ImportPage.h" #include "ui_ImportPage.h" -#include "MultiMC.h" +#include "Launcher.h" #include "dialogs/NewInstanceDialog.h" #include <QFileDialog> #include <QValidator> diff --git a/launcher/pages/modplatform/ImportPage.h b/launcher/pages/modplatform/ImportPage.h index 67e3c201..cc8a0d1f 100644 --- a/launcher/pages/modplatform/ImportPage.h +++ b/launcher/pages/modplatform/ImportPage.h @@ -18,7 +18,7 @@ #include <QWidget> #include "pages/BasePage.h" -#include <MultiMC.h> +#include <Launcher.h> #include "tasks/Task.h" namespace Ui @@ -41,7 +41,7 @@ public: } virtual QIcon icon() const override { - return MMC->getThemedIcon("viewfolder"); + return LAUNCHER->getThemedIcon("viewfolder"); } virtual QString id() const override { diff --git a/launcher/pages/modplatform/VanillaPage.cpp b/launcher/pages/modplatform/VanillaPage.cpp index 02638315..1cf5bbc7 100644 --- a/launcher/pages/modplatform/VanillaPage.cpp +++ b/launcher/pages/modplatform/VanillaPage.cpp @@ -1,7 +1,7 @@ #include "VanillaPage.h" #include "ui_VanillaPage.h" -#include "MultiMC.h" +#include "Launcher.h" #include <meta/Index.h> #include <meta/VersionList.h> diff --git a/launcher/pages/modplatform/VanillaPage.h b/launcher/pages/modplatform/VanillaPage.h index af6fd392..e090d8bb 100644 --- a/launcher/pages/modplatform/VanillaPage.h +++ b/launcher/pages/modplatform/VanillaPage.h @@ -18,7 +18,7 @@ #include <QWidget> #include "pages/BasePage.h" -#include <MultiMC.h> +#include <Launcher.h> #include "tasks/Task.h" namespace Ui @@ -41,7 +41,7 @@ public: } virtual QIcon icon() const override { - return MMC->getThemedIcon("minecraft"); + return LAUNCHER->getThemedIcon("minecraft"); } virtual QString id() const override { diff --git a/launcher/pages/modplatform/atlauncher/AtlListModel.cpp b/launcher/pages/modplatform/atlauncher/AtlListModel.cpp index f3be6198..99d12601 100644 --- a/launcher/pages/modplatform/atlauncher/AtlListModel.cpp +++ b/launcher/pages/modplatform/atlauncher/AtlListModel.cpp @@ -1,7 +1,7 @@ #include "AtlListModel.h" #include <BuildConfig.h> -#include <MultiMC.h> +#include <Launcher.h> #include <Env.h> #include <Json.h> @@ -48,7 +48,7 @@ QVariant ListModel::data(const QModelIndex &index, int role) const { return (m_logoMap.value(pack.safeName)); } - auto icon = MMC->getThemedIcon("atlauncher-placeholder"); + auto icon = LAUNCHER->getThemedIcon("atlauncher-placeholder"); auto url = QString(BuildConfig.ATL_DOWNLOAD_SERVER_URL + "launcher/images/%1.png").arg(pack.safeName.toLower()); ((ListModel *)this)->requestLogo(pack.safeName, url); diff --git a/launcher/pages/modplatform/atlauncher/AtlPage.cpp b/launcher/pages/modplatform/atlauncher/AtlPage.cpp index 245edc59..0367bc48 100644 --- a/launcher/pages/modplatform/atlauncher/AtlPage.cpp +++ b/launcher/pages/modplatform/atlauncher/AtlPage.cpp @@ -133,7 +133,7 @@ QVector<QString> AtlPage::chooseOptionalMods(QVector<ATLauncher::VersionMod> mod } QString AtlPage::chooseVersion(Meta::VersionListPtr vlist, QString minecraftVersion) { - VersionSelectDialog vselect(vlist.get(), "Choose Version", MMC->activeWindow(), false); + VersionSelectDialog vselect(vlist.get(), "Choose Version", LAUNCHER->activeWindow(), false); if (minecraftVersion != Q_NULLPTR) { vselect.setExactFilter(BaseVersionList::ParentVersionRole, minecraftVersion); vselect.setEmptyString(tr("No versions are currently available for Minecraft %1").arg(minecraftVersion)); diff --git a/launcher/pages/modplatform/atlauncher/AtlPage.h b/launcher/pages/modplatform/atlauncher/AtlPage.h index 7d46bc5b..84c40656 100644 --- a/launcher/pages/modplatform/atlauncher/AtlPage.h +++ b/launcher/pages/modplatform/atlauncher/AtlPage.h @@ -21,7 +21,7 @@ #include <QWidget> #include <modplatform/atlauncher/ATLPackInstallTask.h> -#include "MultiMC.h" +#include "Launcher.h" #include "pages/BasePage.h" #include "tasks/Task.h" @@ -45,7 +45,7 @@ public: } virtual QIcon icon() const override { - return MMC->getThemedIcon("atlauncher"); + return LAUNCHER->getThemedIcon("atlauncher"); } virtual QString id() const override { diff --git a/launcher/pages/modplatform/flame/FlameModel.cpp b/launcher/pages/modplatform/flame/FlameModel.cpp index 228a88c5..6dd29d21 100644 --- a/launcher/pages/modplatform/flame/FlameModel.cpp +++ b/launcher/pages/modplatform/flame/FlameModel.cpp @@ -1,5 +1,5 @@ #include "FlameModel.h" -#include "MultiMC.h" +#include "Launcher.h" #include <Json.h> #include <MMCStrings.h> @@ -62,7 +62,7 @@ QVariant ListModel::data(const QModelIndex &index, int role) const { return (m_logoMap.value(pack.logoName)); } - QIcon icon = MMC->getThemedIcon("screenshot-placeholder"); + QIcon icon = LAUNCHER->getThemedIcon("screenshot-placeholder"); ((ListModel *)this)->requestLogo(pack.logoName, pack.logoUrl); return icon; } diff --git a/launcher/pages/modplatform/flame/FlamePage.cpp b/launcher/pages/modplatform/flame/FlamePage.cpp index ade58431..8f798df6 100644 --- a/launcher/pages/modplatform/flame/FlamePage.cpp +++ b/launcher/pages/modplatform/flame/FlamePage.cpp @@ -1,7 +1,7 @@ #include "FlamePage.h" #include "ui_FlamePage.h" -#include "MultiMC.h" +#include "Launcher.h" #include <Json.h> #include "dialogs/NewInstanceDialog.h" #include <InstanceImportTask.h> diff --git a/launcher/pages/modplatform/flame/FlamePage.h b/launcher/pages/modplatform/flame/FlamePage.h index 467bb44b..c3d2630a 100644 --- a/launcher/pages/modplatform/flame/FlamePage.h +++ b/launcher/pages/modplatform/flame/FlamePage.h @@ -18,7 +18,7 @@ #include <QWidget> #include "pages/BasePage.h" -#include <MultiMC.h> +#include <Launcher.h> #include "tasks/Task.h" #include <modplatform/flame/FlamePackIndex.h> @@ -46,7 +46,7 @@ public: } virtual QIcon icon() const override { - return MMC->getThemedIcon("flame"); + return LAUNCHER->getThemedIcon("flame"); } virtual QString id() const override { diff --git a/launcher/pages/modplatform/ftb/FtbFilterModel.cpp b/launcher/pages/modplatform/ftb/FtbFilterModel.cpp index dec3a017..793b8769 100644 --- a/launcher/pages/modplatform/ftb/FtbFilterModel.cpp +++ b/launcher/pages/modplatform/ftb/FtbFilterModel.cpp @@ -36,9 +36,21 @@ FilterModel::Sorting FilterModel::getCurrentSorting() return currentSorting; } +void FilterModel::setSearchTerm(const QString& term) +{ + searchTerm = term.trimmed(); + invalidate(); +} + bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { - return true; + if (searchTerm.isEmpty()) { + return true; + } + + auto index = sourceModel()->index(sourceRow, 0, sourceParent); + auto pack = sourceModel()->data(index, Qt::UserRole).value<ModpacksCH::Modpack>(); + return pack.name.contains(searchTerm, Qt::CaseInsensitive); } bool FilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const diff --git a/launcher/pages/modplatform/ftb/FtbFilterModel.h b/launcher/pages/modplatform/ftb/FtbFilterModel.h index 4fe2a274..2e712c7d 100644 --- a/launcher/pages/modplatform/ftb/FtbFilterModel.h +++ b/launcher/pages/modplatform/ftb/FtbFilterModel.h @@ -19,6 +19,7 @@ public: QString translateCurrentSorting(); void setSorting(Sorting sorting); Sorting getCurrentSorting(); + void setSearchTerm(const QString& term); protected: bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; @@ -27,6 +28,7 @@ protected: private: QMap<QString, Sorting> sortings; Sorting currentSorting; + QString searchTerm { "" }; }; diff --git a/launcher/pages/modplatform/ftb/FtbListModel.cpp b/launcher/pages/modplatform/ftb/FtbListModel.cpp index 98973f2e..c4c2c83e 100644 --- a/launcher/pages/modplatform/ftb/FtbListModel.cpp +++ b/launcher/pages/modplatform/ftb/FtbListModel.cpp @@ -2,7 +2,7 @@ #include "BuildConfig.h" #include "Env.h" -#include "MultiMC.h" +#include "Launcher.h" #include "Json.h" #include <QPainter> @@ -46,7 +46,7 @@ QVariant ListModel::data(const QModelIndex &index, int role) const } else if(role == Qt::DecorationRole) { - QIcon placeholder = MMC->getThemedIcon("screenshot-placeholder"); + QIcon placeholder = LAUNCHER->getThemedIcon("screenshot-placeholder"); auto iter = m_logoMap.find(pack.name); if (iter != m_logoMap.end()) { @@ -74,24 +74,6 @@ QVariant ListModel::data(const QModelIndex &index, int role) const return QVariant(); } -void ListModel::performSearch() -{ - auto *netJob = new NetJob("Ftb::Search"); - QString searchUrl; - if(currentSearchTerm.isEmpty()) { - searchUrl = BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/all"; - } - else { - searchUrl = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/search/25?term=%1") - .arg(currentSearchTerm); - } - 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::getLogo(const QString &logo, const QString &logoUrl, LogoCallback callback) { if(m_logoMap.contains(logo)) @@ -104,28 +86,23 @@ void ListModel::getLogo(const QString &logo, const QString &logoUrl, LogoCallbac } } -void ListModel::searchWithTerm(const QString &term) +void ListModel::request() { - if(searchState != Failed && currentSearchTerm == term && currentSearchTerm.isNull() == term.isNull()) { - // unless the search has failed, then there is no need to perform an identical search. - return; - } - currentSearchTerm = term; - - if(jobPtr) { - jobPtr->abort(); - jobPtr.reset(); - } - beginResetModel(); modpacks.clear(); endResetModel(); - searchState = None; - performSearch(); + auto *netJob = new NetJob("Ftb::Request"); + auto url = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/all"); + netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), &response)); + jobPtr = netJob; + jobPtr->start(); + + QObject::connect(netJob, &NetJob::succeeded, this, &ListModel::requestFinished); + QObject::connect(netJob, &NetJob::failed, this, &ListModel::requestFailed); } -void ListModel::searchRequestFinished() +void ListModel::requestFinished() { jobPtr.reset(); remainingPacks.clear(); @@ -150,12 +127,10 @@ void ListModel::searchRequestFinished() } } -void ListModel::searchRequestFailed(QString reason) +void ListModel::requestFailed(QString reason) { jobPtr.reset(); remainingPacks.clear(); - - searchState = Failed; } void ListModel::requestPack() diff --git a/launcher/pages/modplatform/ftb/FtbListModel.h b/launcher/pages/modplatform/ftb/FtbListModel.h index de94e6ba..2d6e91da 100644 --- a/launcher/pages/modplatform/ftb/FtbListModel.h +++ b/launcher/pages/modplatform/ftb/FtbListModel.h @@ -30,13 +30,13 @@ public: int columnCount(const QModelIndex &parent) const override; QVariant data(const QModelIndex &index, int role) const override; + void request(); + void getLogo(const QString &logo, const QString &logoUrl, LogoCallback callback); - void searchWithTerm(const QString & term); private slots: - void performSearch(); - void searchRequestFinished(); - void searchRequestFailed(QString reason); + void requestFinished(); + void requestFailed(QString reason); void requestPack(); void packRequestFinished(); @@ -52,14 +52,6 @@ private: QList<ModpacksCH::Modpack> modpacks; LogoMap m_logoMap; - QString currentSearchTerm; - enum SearchState { - None, - CanPossiblyFetchMore, - ResetRequested, - Finished, - Failed, - } searchState = None; NetJobPtr jobPtr; int currentPack; QList<int> remainingPacks; diff --git a/launcher/pages/modplatform/ftb/FtbPage.cpp b/launcher/pages/modplatform/ftb/FtbPage.cpp index b7f35c5d..bafcfac9 100644 --- a/launcher/pages/modplatform/ftb/FtbPage.cpp +++ b/launcher/pages/modplatform/ftb/FtbPage.cpp @@ -32,7 +32,7 @@ FtbPage::FtbPage(NewInstanceDialog* dialog, QWidget *parent) } ui->sortByBox->setCurrentText(filterModel->translateCurrentSorting()); - connect(ui->searchButton, &QPushButton::clicked, this, &FtbPage::triggerSearch); + connect(ui->searchEdit, &QLineEdit::textChanged, this, &FtbPage::triggerSearch); connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FtbPage::onSortingSelectionChanged); connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FtbPage::onSelectionChanged); connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FtbPage::onVersionSelectionChanged); @@ -63,7 +63,12 @@ bool FtbPage::shouldDisplay() const void FtbPage::openedImpl() { - triggerSearch(); + if(!initialised) + { + listModel->request(); + initialised = true; + } + suggestCurrent(); } @@ -96,7 +101,7 @@ void FtbPage::suggestCurrent() void FtbPage::triggerSearch() { - listModel->searchWithTerm(ui->searchEdit->text()); + filterModel->setSearchTerm(ui->searchEdit->text()); } void FtbPage::onSortingSelectionChanged(QString data) diff --git a/launcher/pages/modplatform/ftb/FtbPage.h b/launcher/pages/modplatform/ftb/FtbPage.h index c9c93897..0a4a6cea 100644 --- a/launcher/pages/modplatform/ftb/FtbPage.h +++ b/launcher/pages/modplatform/ftb/FtbPage.h @@ -20,7 +20,7 @@ #include <QWidget> -#include "MultiMC.h" +#include "Launcher.h" #include "pages/BasePage.h" #include "tasks/Task.h" @@ -44,7 +44,7 @@ public: } virtual QIcon icon() const override { - return MMC->getThemedIcon("ftb_logo"); + return LAUNCHER->getThemedIcon("ftb_logo"); } virtual QString id() const override { @@ -65,6 +65,7 @@ private: private slots: void triggerSearch(); + void onSortingSelectionChanged(QString data); void onSelectionChanged(QModelIndex first, QModelIndex second); void onVersionSelectionChanged(QString data); @@ -77,4 +78,6 @@ private: ModpacksCH::Modpack selected; QString selectedVersion; + + bool initialised { false }; }; diff --git a/launcher/pages/modplatform/ftb/FtbPage.ui b/launcher/pages/modplatform/ftb/FtbPage.ui index 135afc6d..e9c783e3 100644 --- a/launcher/pages/modplatform/ftb/FtbPage.ui +++ b/launcher/pages/modplatform/ftb/FtbPage.ui @@ -36,12 +36,8 @@ <property name="placeholderText"> <string>Search and filter ...</string> </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QPushButton" name="searchButton"> - <property name="text"> - <string>Search</string> + <property name="clearButtonEnabled"> + <bool>true</bool> </property> </widget> </item> @@ -49,15 +45,15 @@ <layout class="QGridLayout" name="gridLayout_3"> <item row="0" column="0"> <widget class="QTreeView" name="packView"> + <property name="alternatingRowColors"> + <bool>true</bool> + </property> <property name="iconSize"> <size> <width>48</width> <height>48</height> </size> </property> - <property name="alternatingRowColors"> - <bool>true</bool> - </property> </widget> </item> <item row="0" column="1"> @@ -76,7 +72,6 @@ </widget> <tabstops> <tabstop>searchEdit</tabstop> - <tabstop>searchButton</tabstop> <tabstop>versionSelectionBox</tabstop> </tabstops> <resources/> diff --git a/launcher/pages/modplatform/legacy_ftb/ListModel.cpp b/launcher/pages/modplatform/legacy_ftb/ListModel.cpp index 32596fb3..78063c5f 100644 --- a/launcher/pages/modplatform/legacy_ftb/ListModel.cpp +++ b/launcher/pages/modplatform/legacy_ftb/ListModel.cpp @@ -1,5 +1,5 @@ #include "ListModel.h" -#include "MultiMC.h" +#include "Launcher.h" #include <MMCStrings.h> #include <Version.h> @@ -130,7 +130,7 @@ QVariant ListModel::data(const QModelIndex &index, int role) const { return (m_logoMap.value(pack.logo)); } - QIcon icon = MMC->getThemedIcon("screenshot-placeholder"); + QIcon icon = LAUNCHER->getThemedIcon("screenshot-placeholder"); ((ListModel *)this)->requestLogo(pack.logo); return icon; } diff --git a/launcher/pages/modplatform/legacy_ftb/Page.cpp b/launcher/pages/modplatform/legacy_ftb/Page.cpp index a438f76c..6b6a7dcd 100644 --- a/launcher/pages/modplatform/legacy_ftb/Page.cpp +++ b/launcher/pages/modplatform/legacy_ftb/Page.cpp @@ -3,7 +3,7 @@ #include <QInputDialog> -#include "MultiMC.h" +#include "Launcher.h" #include "dialogs/CustomMessageBox.h" #include "dialogs/NewInstanceDialog.h" #include "modplatform/legacy_ftb/PackFetchTask.h" diff --git a/launcher/pages/modplatform/legacy_ftb/Page.h b/launcher/pages/modplatform/legacy_ftb/Page.h index e840216e..6159cd9d 100644 --- a/launcher/pages/modplatform/legacy_ftb/Page.h +++ b/launcher/pages/modplatform/legacy_ftb/Page.h @@ -20,7 +20,7 @@ #include <QTextBrowser> #include "pages/BasePage.h" -#include <MultiMC.h> +#include <Launcher.h> #include "tasks/Task.h" #include "modplatform/legacy_ftb/PackHelpers.h" #include "modplatform/legacy_ftb/PackFetchTask.h" @@ -54,7 +54,7 @@ public: } QIcon icon() const override { - return MMC->getThemedIcon("ftb_logo"); + return LAUNCHER->getThemedIcon("ftb_logo"); } QString id() const override { diff --git a/launcher/pages/modplatform/technic/TechnicModel.cpp b/launcher/pages/modplatform/technic/TechnicModel.cpp index def30783..cac6fef1 100644 --- a/launcher/pages/modplatform/technic/TechnicModel.cpp +++ b/launcher/pages/modplatform/technic/TechnicModel.cpp @@ -15,7 +15,7 @@ #include "TechnicModel.h" #include "Env.h" -#include "MultiMC.h" +#include "Launcher.h" #include "Json.h" #include <QIcon> @@ -47,7 +47,7 @@ QVariant Technic::ListModel::data(const QModelIndex& index, int role) const { return (m_logoMap.value(pack.logoName)); } - QIcon icon = MMC->getThemedIcon("screenshot-placeholder"); + QIcon icon = LAUNCHER->getThemedIcon("screenshot-placeholder"); ((ListModel *)this)->requestLogo(pack.logoName, pack.logoUrl); return icon; } diff --git a/launcher/pages/modplatform/technic/TechnicPage.cpp b/launcher/pages/modplatform/technic/TechnicPage.cpp index e836f767..4f27e685 100644 --- a/launcher/pages/modplatform/technic/TechnicPage.cpp +++ b/launcher/pages/modplatform/technic/TechnicPage.cpp @@ -16,7 +16,7 @@ #include "TechnicPage.h" #include "ui_TechnicPage.h" -#include "MultiMC.h" +#include "Launcher.h" #include "dialogs/NewInstanceDialog.h" #include "TechnicModel.h" #include <QKeyEvent> diff --git a/launcher/pages/modplatform/technic/TechnicPage.h b/launcher/pages/modplatform/technic/TechnicPage.h index 27e1258a..f0619a52 100644 --- a/launcher/pages/modplatform/technic/TechnicPage.h +++ b/launcher/pages/modplatform/technic/TechnicPage.h @@ -18,7 +18,7 @@ #include <QWidget> #include "pages/BasePage.h" -#include <MultiMC.h> +#include <Launcher.h> #include "tasks/Task.h" #include "TechnicData.h" @@ -46,7 +46,7 @@ public: } virtual QIcon icon() const override { - return MMC->getThemedIcon("technic"); + return LAUNCHER->getThemedIcon("technic"); } virtual QString id() const override { |