From 935b2e8fb20741b14472a745a5720ef7da9a86ec Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sun, 27 Oct 2024 11:56:48 +0200 Subject: [PATCH 1/2] add open source filter Signed-off-by: Trial97 --- launcher/modplatform/ResourceAPI.h | 1 + launcher/modplatform/modrinth/ModrinthAPI.h | 2 ++ launcher/ui/pages/modplatform/ModModel.cpp | 4 +++- launcher/ui/pages/modplatform/flame/FlameModel.cpp | 2 +- .../pages/modplatform/modrinth/ModrinthModel.cpp | 2 +- launcher/ui/widgets/ModFilterWidget.cpp | 14 +++++++++++++- launcher/ui/widgets/ModFilterWidget.h | 4 +++- launcher/ui/widgets/ModFilterWidget.ui | 7 +++++++ 8 files changed, 31 insertions(+), 5 deletions(-) diff --git a/launcher/modplatform/ResourceAPI.h b/launcher/modplatform/ResourceAPI.h index b7364d9ab..502d1c301 100644 --- a/launcher/modplatform/ResourceAPI.h +++ b/launcher/modplatform/ResourceAPI.h @@ -76,6 +76,7 @@ class ResourceAPI { std::optional > versions; std::optional side; std::optional categoryIds; + bool openSource; }; struct SearchCallbacks { std::function on_succeed; diff --git a/launcher/modplatform/modrinth/ModrinthAPI.h b/launcher/modplatform/modrinth/ModrinthAPI.h index 070f59dad..3a5c21ed1 100644 --- a/launcher/modplatform/modrinth/ModrinthAPI.h +++ b/launcher/modplatform/modrinth/ModrinthAPI.h @@ -116,6 +116,8 @@ class ModrinthAPI : public NetworkResourceAPI { } if (args.categoryIds.has_value() && !args.categoryIds->empty()) facets_list.append(QString("[%1]").arg(getCategoriesFilters(args.categoryIds.value()))); + if (args.openSource) + facets_list.append("[\"open_source:true\"]"); facets_list.append(QString("[\"project_type:%1\"]").arg(resourceTypeParameter(args.type))); diff --git a/launcher/ui/pages/modplatform/ModModel.cpp b/launcher/ui/pages/modplatform/ModModel.cpp index 1f0329321..cfc262b62 100644 --- a/launcher/ui/pages/modplatform/ModModel.cpp +++ b/launcher/ui/pages/modplatform/ModModel.cpp @@ -39,7 +39,9 @@ ResourceAPI::SearchArgs ModModel::createSearchArguments() auto sort = getCurrentSortingMethodByIndex(); - return { ModPlatform::ResourceType::MOD, m_next_search_offset, m_search_term, sort, loaders, versions, side, categories }; + return { + ModPlatform::ResourceType::MOD, m_next_search_offset, m_search_term, sort, loaders, versions, side, categories, m_filter->openSource + }; } ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(QModelIndex& entry) diff --git a/launcher/ui/pages/modplatform/flame/FlameModel.cpp b/launcher/ui/pages/modplatform/flame/FlameModel.cpp index cfdb185ff..18a2adc49 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModel.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameModel.cpp @@ -189,7 +189,7 @@ void ListModel::performPaginatedSearch() auto netJob = makeShared("Flame::Search", APPLICATION->network()); auto searchUrl = FlameAPI().getSearchURL({ ModPlatform::ResourceType::MODPACK, nextSearchOffset, currentSearchTerm, sort, - m_filter->loaders, m_filter->versions, "", m_filter->categoryIds }); + m_filter->loaders, m_filter->versions, "", m_filter->categoryIds, m_filter->openSource }); netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(searchUrl.value()), response)); jobPtr = netJob; diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp index 417ff4080..416c69d28 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp @@ -155,7 +155,7 @@ void ModpackListModel::performPaginatedSearch() ResourceAPI::SortingMethod sort{}; sort.name = currentSort; auto searchUrl = ModrinthAPI().getSearchURL({ ModPlatform::ResourceType::MODPACK, nextSearchOffset, currentSearchTerm, sort, - m_filter->loaders, m_filter->versions, "", m_filter->categoryIds }); + m_filter->loaders, m_filter->versions, "", m_filter->categoryIds, m_filter->openSource }); auto netJob = makeShared("Modrinth::SearchModpack", APPLICATION->network()); netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(searchUrl.value()), m_allResponse)); diff --git a/launcher/ui/widgets/ModFilterWidget.cpp b/launcher/ui/widgets/ModFilterWidget.cpp index 68adcdb71..89d9bdb61 100644 --- a/launcher/ui/widgets/ModFilterWidget.cpp +++ b/launcher/ui/widgets/ModFilterWidget.cpp @@ -134,6 +134,7 @@ ModFilterWidget::ModFilterWidget(MinecraftInstance* instance, bool extended, QWi ui->versions->hide(); ui->showAllVersions->hide(); ui->environmentGroup->hide(); + ui->openSource->hide(); } ui->versions->setStyleSheet("combobox-popup: 0;"); @@ -159,6 +160,7 @@ ModFilterWidget::ModFilterWidget(MinecraftInstance* instance, bool extended, QWi } connect(ui->hideInstalled, &QCheckBox::stateChanged, this, &ModFilterWidget::onHideInstalledFilterChanged); + connect(ui->openSource, &QCheckBox::stateChanged, this, &ModFilterWidget::onOpenSourceFilterChanged); setHidden(true); loadVersionList(); @@ -208,6 +210,7 @@ void ModFilterWidget::loadVersionList() void ModFilterWidget::prepareBasicFilter() { + m_filter->openSource = false; if (m_instance) { m_filter->hideInstalled = false; m_filter->side = ""; // or "both" @@ -337,4 +340,13 @@ void ModFilterWidget::setCategories(const QList& categori } } -#include "ModFilterWidget.moc" \ No newline at end of file +void ModFilterWidget::onOpenSourceFilterChanged() +{ + auto open = ui->openSource->isChecked(); + m_filter_changed = open != m_filter->openSource; + m_filter->openSource = open; + if (m_filter_changed) + emit filterChanged(); +} + +#include "ModFilterWidget.moc" diff --git a/launcher/ui/widgets/ModFilterWidget.h b/launcher/ui/widgets/ModFilterWidget.h index 50f0e06c9..76668db92 100644 --- a/launcher/ui/widgets/ModFilterWidget.h +++ b/launcher/ui/widgets/ModFilterWidget.h @@ -64,11 +64,12 @@ class ModFilterWidget : public QTabWidget { QString side; bool hideInstalled; QStringList categoryIds; + bool openSource; bool operator==(const Filter& other) const { return hideInstalled == other.hideInstalled && side == other.side && loaders == other.loaders && versions == other.versions && - releases == other.releases && categoryIds == other.categoryIds; + releases == other.releases && categoryIds == other.categoryIds && openSource == other.openSource; } bool operator!=(const Filter& other) const { return !(*this == other); } @@ -107,6 +108,7 @@ class ModFilterWidget : public QTabWidget { void onSideFilterChanged(); void onHideInstalledFilterChanged(); void onShowAllVersionsChanged(); + void onOpenSourceFilterChanged(); private: Ui::ModFilterWidget* ui; diff --git a/launcher/ui/widgets/ModFilterWidget.ui b/launcher/ui/widgets/ModFilterWidget.ui index 236847094..604c35ef5 100644 --- a/launcher/ui/widgets/ModFilterWidget.ui +++ b/launcher/ui/widgets/ModFilterWidget.ui @@ -188,6 +188,13 @@ + + + + Open Source only + + + From 6338e2b3626e8ef6b17e8d9c3aa0a083586b3d4e Mon Sep 17 00:00:00 2001 From: Alexandru Ionut Tripon Date: Mon, 28 Oct 2024 00:34:41 +0200 Subject: [PATCH 2/2] Update launcher/ui/widgets/ModFilterWidget.ui Co-authored-by: TheKodeToad Signed-off-by: Alexandru Ionut Tripon --- launcher/ui/widgets/ModFilterWidget.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/widgets/ModFilterWidget.ui b/launcher/ui/widgets/ModFilterWidget.ui index 604c35ef5..c4d921e96 100644 --- a/launcher/ui/widgets/ModFilterWidget.ui +++ b/launcher/ui/widgets/ModFilterWidget.ui @@ -191,7 +191,7 @@ - Open Source only + Open source only