From 946e791d39a19f50d7604b1f57714f8f3a7f63cb Mon Sep 17 00:00:00 2001 From: Trial97 Date: Mon, 30 Sep 2024 21:50:07 +0300 Subject: [PATCH] sync modpack search field Signed-off-by: Trial97 --- launcher/CMakeLists.txt | 3 ++ launcher/ui/dialogs/NewInstanceDialog.cpp | 16 ++++++++++ launcher/ui/dialogs/NewInstanceDialog.h | 3 ++ .../modplatform/ModpackProviderBasePage.h | 29 +++++++++++++++++++ .../pages/modplatform/atlauncher/AtlPage.cpp | 10 +++++++ .../ui/pages/modplatform/atlauncher/AtlPage.h | 10 +++++-- .../ui/pages/modplatform/flame/FlamePage.cpp | 9 ++++++ .../ui/pages/modplatform/flame/FlamePage.h | 9 ++++-- .../modplatform/import_ftb/ImportFTBPage.cpp | 9 ++++++ .../modplatform/import_ftb/ImportFTBPage.h | 9 ++++-- .../ui/pages/modplatform/legacy_ftb/Page.cpp | 9 ++++++ .../ui/pages/modplatform/legacy_ftb/Page.h | 9 ++++-- .../modplatform/modrinth/ModrinthPage.cpp | 10 +++++++ .../pages/modplatform/modrinth/ModrinthPage.h | 9 ++++-- .../pages/modplatform/technic/TechnicPage.cpp | 10 +++++++ .../pages/modplatform/technic/TechnicPage.h | 9 ++++-- 16 files changed, 150 insertions(+), 13 deletions(-) create mode 100644 launcher/ui/pages/modplatform/ModpackProviderBasePage.h diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index bd6dfc5b6..dcbfe8fde 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -965,6 +965,9 @@ SET(LAUNCHER_SOURCES ui/pages/modplatform/ShaderPackPage.cpp ui/pages/modplatform/ShaderPackModel.cpp + + ui/pages/modplatform/ModpackProviderBasePage.h + ui/pages/modplatform/atlauncher/AtlFilterModel.cpp ui/pages/modplatform/atlauncher/AtlFilterModel.h ui/pages/modplatform/atlauncher/AtlListModel.cpp diff --git a/launcher/ui/dialogs/NewInstanceDialog.cpp b/launcher/ui/dialogs/NewInstanceDialog.cpp index 2e799d2a8..f16c50860 100644 --- a/launcher/ui/dialogs/NewInstanceDialog.cpp +++ b/launcher/ui/dialogs/NewInstanceDialog.cpp @@ -36,6 +36,7 @@ #include "NewInstanceDialog.h" #include "Application.h" +#include "ui/pages/modplatform/ModpackProviderBasePage.h" #include "ui/pages/modplatform/import_ftb/ImportFTBPage.h" #include "ui_NewInstanceDialog.h" @@ -140,6 +141,8 @@ NewInstanceDialog::NewInstanceDialog(const QString& initialGroup, auto geometry = screen->availableSize(); resize(width(), qMin(geometry.height() - 50, 710)); } + + connect(m_container, &PageContainer::selectedPageChanged, this, &NewInstanceDialog::selectedPageChanged); } void NewInstanceDialog::reject() @@ -316,3 +319,16 @@ void NewInstanceDialog::importIconNow() } APPLICATION->settings()->set("NewInstanceGeometry", saveGeometry().toBase64()); } + +void NewInstanceDialog::selectedPageChanged(BasePage* previous, BasePage* selected) +{ + auto prevPage = dynamic_cast(previous); + if (prevPage) { + m_searchTerm = prevPage->getSerachTerm(); + } + + auto nextPage = dynamic_cast(selected); + if (nextPage) { + nextPage->setSearchTerm(m_searchTerm); + } +} diff --git a/launcher/ui/dialogs/NewInstanceDialog.h b/launcher/ui/dialogs/NewInstanceDialog.h index 923579567..e97c9f543 100644 --- a/launcher/ui/dialogs/NewInstanceDialog.h +++ b/launcher/ui/dialogs/NewInstanceDialog.h @@ -82,6 +82,7 @@ class NewInstanceDialog : public QDialog, public BasePageProvider { private slots: void on_iconButton_clicked(); void on_instNameTextBox_textChanged(const QString& arg1); + void selectedPageChanged(BasePage* previous, BasePage* selected); private: Ui::NewInstanceDialog* ui = nullptr; @@ -98,5 +99,7 @@ class NewInstanceDialog : public QDialog, public BasePageProvider { QString importVersion; + QString m_searchTerm; + void importIconNow(); }; diff --git a/launcher/ui/pages/modplatform/ModpackProviderBasePage.h b/launcher/ui/pages/modplatform/ModpackProviderBasePage.h new file mode 100644 index 000000000..a3daa9a81 --- /dev/null +++ b/launcher/ui/pages/modplatform/ModpackProviderBasePage.h @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (c) 2023 Trial97 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "ui/pages/BasePage.h" + +class ModpackProviderBasePage : public BasePage { + public: + /** Programatically set the term in the search bar. */ + virtual void setSearchTerm(QString) = 0; + /** Get the current term in the search bar. */ + [[nodiscard]] virtual QString getSerachTerm() const = 0; +}; \ No newline at end of file diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlPage.cpp b/launcher/ui/pages/modplatform/atlauncher/AtlPage.cpp index d79b7621a..7c69b315e 100644 --- a/launcher/ui/pages/modplatform/atlauncher/AtlPage.cpp +++ b/launcher/ui/pages/modplatform/atlauncher/AtlPage.cpp @@ -164,3 +164,13 @@ void AtlPage::onVersionSelectionChanged(QString version) selectedVersion = version; suggestCurrent(); } + +void AtlPage::setSearchTerm(QString term) +{ + ui->searchEdit->setText(term); +} + +QString AtlPage::getSerachTerm() const +{ + return ui->searchEdit->text(); +} diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlPage.h b/launcher/ui/pages/modplatform/atlauncher/AtlPage.h index 6bc449649..73460232b 100644 --- a/launcher/ui/pages/modplatform/atlauncher/AtlPage.h +++ b/launcher/ui/pages/modplatform/atlauncher/AtlPage.h @@ -42,8 +42,7 @@ #include #include "Application.h" -#include "tasks/Task.h" -#include "ui/pages/BasePage.h" +#include "ui/pages/modplatform/ModpackProviderBasePage.h" namespace Ui { class AtlPage; @@ -51,7 +50,7 @@ class AtlPage; class NewInstanceDialog; -class AtlPage : public QWidget, public BasePage { +class AtlPage : public QWidget, public ModpackProviderBasePage { Q_OBJECT public: @@ -66,6 +65,11 @@ class AtlPage : public QWidget, public BasePage { void openedImpl() override; + /** Programatically set the term in the search bar. */ + virtual void setSearchTerm(QString) override; + /** Get the current term in the search bar. */ + [[nodiscard]] virtual QString getSerachTerm() const override; + private: void suggestCurrent(); diff --git a/launcher/ui/pages/modplatform/flame/FlamePage.cpp b/launcher/ui/pages/modplatform/flame/FlamePage.cpp index decb5de3b..4195683e7 100644 --- a/launcher/ui/pages/modplatform/flame/FlamePage.cpp +++ b/launcher/ui/pages/modplatform/flame/FlamePage.cpp @@ -299,3 +299,12 @@ void FlamePage::updateUi() ui->packDescription->setHtml(StringUtils::htmlListPatch(text + current.description)); ui->packDescription->flush(); } +QString FlamePage::getSerachTerm() const +{ + return ui->searchEdit->text(); +} + +void FlamePage::setSearchTerm(QString term) +{ + ui->searchEdit->setText(term); +} diff --git a/launcher/ui/pages/modplatform/flame/FlamePage.h b/launcher/ui/pages/modplatform/flame/FlamePage.h index 7590e1a95..45a3c6b22 100644 --- a/launcher/ui/pages/modplatform/flame/FlamePage.h +++ b/launcher/ui/pages/modplatform/flame/FlamePage.h @@ -40,7 +40,7 @@ #include #include #include -#include "ui/pages/BasePage.h" +#include "ui/pages/modplatform/ModpackProviderBasePage.h" #include "ui/widgets/ProgressWidget.h" namespace Ui { @@ -53,7 +53,7 @@ namespace Flame { class ListModel; } -class FlamePage : public QWidget, public BasePage { +class FlamePage : public QWidget, public ModpackProviderBasePage { Q_OBJECT public: @@ -72,6 +72,11 @@ class FlamePage : public QWidget, public BasePage { bool eventFilter(QObject* watched, QEvent* event) override; + /** Programatically set the term in the search bar. */ + virtual void setSearchTerm(QString) override; + /** Get the current term in the search bar. */ + [[nodiscard]] virtual QString getSerachTerm() const override; + private: void suggestCurrent(); diff --git a/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.cpp b/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.cpp index db59fe10a..15303bb22 100644 --- a/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.cpp +++ b/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.cpp @@ -135,4 +135,13 @@ void ImportFTBPage::triggerSearch() currentModel->setSearchTerm(ui->searchEdit->text()); } +void ImportFTBPage::setSearchTerm(QString term) +{ + ui->searchEdit->setText(term); +} + +QString ImportFTBPage::getSerachTerm() const +{ + return ui->searchEdit->text(); +} } // namespace FTBImportAPP diff --git a/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h b/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h index 00f013f6f..7afff5a9d 100644 --- a/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h +++ b/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h @@ -25,7 +25,7 @@ #include #include "modplatform/import_ftb/PackHelpers.h" -#include "ui/pages/BasePage.h" +#include "ui/pages/modplatform/ModpackProviderBasePage.h" #include "ui/pages/modplatform/import_ftb/ListModel.h" class NewInstanceDialog; @@ -35,7 +35,7 @@ namespace Ui { class ImportFTBPage; } -class ImportFTBPage : public QWidget, public BasePage { +class ImportFTBPage : public QWidget, public ModpackProviderBasePage { Q_OBJECT public: @@ -49,6 +49,11 @@ class ImportFTBPage : public QWidget, public BasePage { void openedImpl() override; void retranslate() override; + /** Programatically set the term in the search bar. */ + virtual void setSearchTerm(QString) override; + /** Get the current term in the search bar. */ + [[nodiscard]] virtual QString getSerachTerm() const override; + private: void suggestCurrent(); void onPackSelectionChanged(Modpack* pack = nullptr); diff --git a/launcher/ui/pages/modplatform/legacy_ftb/Page.cpp b/launcher/ui/pages/modplatform/legacy_ftb/Page.cpp index a587b5baf..226a30ee3 100644 --- a/launcher/ui/pages/modplatform/legacy_ftb/Page.cpp +++ b/launcher/ui/pages/modplatform/legacy_ftb/Page.cpp @@ -369,4 +369,13 @@ void Page::triggerSearch() currentModel->setSearchTerm(ui->searchEdit->text()); } +void Page::setSearchTerm(QString term) +{ + ui->searchEdit->setText(term); +} + +QString Page::getSerachTerm() const +{ + return ui->searchEdit->text(); +} } // namespace LegacyFTB diff --git a/launcher/ui/pages/modplatform/legacy_ftb/Page.h b/launcher/ui/pages/modplatform/legacy_ftb/Page.h index daef23342..a2dee24e9 100644 --- a/launcher/ui/pages/modplatform/legacy_ftb/Page.h +++ b/launcher/ui/pages/modplatform/legacy_ftb/Page.h @@ -43,7 +43,7 @@ #include "QObjectPtr.h" #include "modplatform/legacy_ftb/PackFetchTask.h" #include "modplatform/legacy_ftb/PackHelpers.h" -#include "ui/pages/BasePage.h" +#include "ui/pages/modplatform/ModpackProviderBasePage.h" class NewInstanceDialog; @@ -57,7 +57,7 @@ class ListModel; class FilterModel; class PrivatePackManager; -class Page : public QWidget, public BasePage { +class Page : public QWidget, public ModpackProviderBasePage { Q_OBJECT public: @@ -71,6 +71,11 @@ class Page : public QWidget, public BasePage { void openedImpl() override; void retranslate() override; + /** Programatically set the term in the search bar. */ + virtual void setSearchTerm(QString) override; + /** Get the current term in the search bar. */ + [[nodiscard]] virtual QString getSerachTerm() const override; + private: void suggestCurrent(); void onPackSelectionChanged(Modpack* pack = nullptr); diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp index 03461d85a..a000044fa 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp @@ -351,3 +351,13 @@ void ModrinthPage::onVersionSelectionChanged(int index) selectedVersion = ui->versionSelectionBox->currentData().toString(); suggestCurrent(); } + +void ModrinthPage::setSearchTerm(QString term) +{ + ui->searchEdit->setText(term); +} + +QString ModrinthPage::getSerachTerm() const +{ + return ui->searchEdit->text(); +} diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h index dadaeb0a0..dd99e0d29 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h @@ -38,9 +38,9 @@ #include "Application.h" #include "ui/dialogs/NewInstanceDialog.h" -#include "ui/pages/BasePage.h" #include "modplatform/modrinth/ModrinthPackManifest.h" +#include "ui/pages/modplatform/ModpackProviderBasePage.h" #include "ui/widgets/ProgressWidget.h" #include @@ -54,7 +54,7 @@ namespace Modrinth { class ModpackListModel; } -class ModrinthPage : public QWidget, public BasePage { +class ModrinthPage : public QWidget, public ModpackProviderBasePage { Q_OBJECT public: @@ -78,6 +78,11 @@ class ModrinthPage : public QWidget, public BasePage { void openedImpl() override; bool eventFilter(QObject* watched, QEvent* event) override; + /** Programatically set the term in the search bar. */ + virtual void setSearchTerm(QString) override; + /** Get the current term in the search bar. */ + [[nodiscard]] virtual QString getSerachTerm() const override; + private slots: void onSelectionChanged(QModelIndex first, QModelIndex second); void onVersionSelectionChanged(int index); diff --git a/launcher/ui/pages/modplatform/technic/TechnicPage.cpp b/launcher/ui/pages/modplatform/technic/TechnicPage.cpp index a8f06619f..50d267b1f 100644 --- a/launcher/ui/pages/modplatform/technic/TechnicPage.cpp +++ b/launcher/ui/pages/modplatform/technic/TechnicPage.cpp @@ -342,3 +342,13 @@ void TechnicPage::onVersionSelectionChanged(QString version) selectedVersion = version; selectVersion(); } + +void TechnicPage::setSearchTerm(QString term) +{ + ui->searchEdit->setText(term); +} + +QString TechnicPage::getSerachTerm() const +{ + return ui->searchEdit->text(); +} diff --git a/launcher/ui/pages/modplatform/technic/TechnicPage.h b/launcher/ui/pages/modplatform/technic/TechnicPage.h index 01439337d..d1f691b22 100644 --- a/launcher/ui/pages/modplatform/technic/TechnicPage.h +++ b/launcher/ui/pages/modplatform/technic/TechnicPage.h @@ -41,7 +41,7 @@ #include #include "TechnicData.h" #include "net/NetJob.h" -#include "ui/pages/BasePage.h" +#include "ui/pages/modplatform/ModpackProviderBasePage.h" #include "ui/widgets/ProgressWidget.h" namespace Ui { @@ -54,7 +54,7 @@ namespace Technic { class ListModel; } -class TechnicPage : public QWidget, public BasePage { +class TechnicPage : public QWidget, public ModpackProviderBasePage { Q_OBJECT public: @@ -71,6 +71,11 @@ class TechnicPage : public QWidget, public BasePage { bool eventFilter(QObject* watched, QEvent* event) override; + /** Programatically set the term in the search bar. */ + virtual void setSearchTerm(QString) override; + /** Get the current term in the search bar. */ + [[nodiscard]] virtual QString getSerachTerm() const override; + private: void suggestCurrent(); void metadataLoaded();