aboutsummaryrefslogtreecommitdiff
path: root/src/yuzu/configuration/addon/mod_select_dialog.cpp
diff options
context:
space:
mode:
authorcrueter <crueter@eden-emu.dev>2026-02-06 06:37:30 +0100
committercrueter <crueter@eden-emu.dev>2026-02-06 06:37:30 +0100
commite07e269bd766aa1fc29951b958db2063c1a4048e (patch)
treec106879286f3bddaf4e5655210913b6e773facbf /src/yuzu/configuration/addon/mod_select_dialog.cpp
parent08232ce64275eaf388eba7005f4dae28fc18a0b7 (diff)
[desktop] Add mod importer from folder and zip (#3472)
Closes #3125 Adds buttons to the addons page that imports a mod (or mods) from zip or folder. Currently known to work with mods that provide proper romfs/exefs things, unsure about cheats and such. Also works on mods that just stuff things into the root of the zip. TODO: - [ ] test folder more thoroughly - [ ] cheats - [ ] test all sorts of mod pack types Signed-off-by: crueter <crueter@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3472 Reviewed-by: Lizzie <lizzie@eden-emu.dev>
Diffstat (limited to 'src/yuzu/configuration/addon/mod_select_dialog.cpp')
-rw-r--r--src/yuzu/configuration/addon/mod_select_dialog.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/yuzu/configuration/addon/mod_select_dialog.cpp b/src/yuzu/configuration/addon/mod_select_dialog.cpp
new file mode 100644
index 0000000000..e6c361b94f
--- /dev/null
+++ b/src/yuzu/configuration/addon/mod_select_dialog.cpp
@@ -0,0 +1,66 @@
+// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include <QFileInfo>
+#include <qnamespace.h>
+#include "mod_select_dialog.h"
+#include "ui_mod_select_dialog.h"
+
+ModSelectDialog::ModSelectDialog(const QStringList& mods, QWidget* parent)
+ : QDialog(parent), ui(new Ui::ModSelectDialog) {
+ ui->setupUi(this);
+
+ item_model = new QStandardItemModel(ui->treeView);
+ ui->treeView->setModel(item_model);
+
+ // We must register all custom types with the Qt Automoc system so that we are able to use it
+ // with signals/slots. In this case, QList falls under the umbrella of custom types.
+ qRegisterMetaType<QList<QStandardItem*>>("QList<QStandardItem*>");
+
+ for (const auto& mod : mods) {
+ const auto basename = QFileInfo(mod).fileName();
+
+ auto* const first_item = new QStandardItem;
+ first_item->setText(basename);
+ first_item->setData(mod);
+
+ first_item->setCheckable(true);
+ first_item->setCheckState(Qt::Checked);
+
+ item_model->appendRow(first_item);
+ }
+
+ ui->treeView->expandAll();
+ ui->treeView->resizeColumnToContents(0);
+
+ int rows = item_model->rowCount();
+ int height =
+ ui->treeView->contentsMargins().top() * 4 + ui->treeView->contentsMargins().bottom() * 4;
+ int width = 0;
+
+ for (int i = 0; i < rows; ++i) {
+ height += ui->treeView->sizeHintForRow(i);
+ width = qMax(width, item_model->item(i)->sizeHint().width());
+ }
+
+ width += ui->treeView->contentsMargins().left() * 4 + ui->treeView->contentsMargins().right() * 4;
+ ui->treeView->setMinimumHeight(qMin(height, 600));
+ ui->treeView->setMinimumWidth(qMin(width, 700));
+ adjustSize();
+
+ connect(this, &QDialog::accepted, this, [this]() {
+ QStringList selected_mods;
+
+ for (qsizetype i = 0; i < item_model->rowCount(); ++i) {
+ auto* const item = item_model->item(i);
+ if (item->checkState() == Qt::Checked)
+ selected_mods << item->data().toString();
+ }
+
+ emit modsSelected(selected_mods);
+ });
+}
+
+ModSelectDialog::~ModSelectDialog() {
+ delete ui;
+}