From 39c88ed5880d54b209ef0750faee2e8861d093d0 Mon Sep 17 00:00:00 2001 From: ElBread3 <92335081+ElBread3@users.noreply.github.com> Date: Wed, 9 Oct 2024 13:01:22 -0500 Subject: [PATCH] paths setting tab --- src/qt_gui/settings_dialog.cpp | 49 ++++++++++++++++++++++++ src/qt_gui/settings_dialog.ui | 70 ++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) diff --git a/src/qt_gui/settings_dialog.cpp b/src/qt_gui/settings_dialog.cpp index efc4384555..2ffabe8bcd 100644 --- a/src/qt_gui/settings_dialog.cpp +++ b/src/qt_gui/settings_dialog.cpp @@ -220,6 +220,55 @@ SettingsDialog::SettingsDialog(std::span physical_devices, QWidge [](int val) { Config::setNullGpu(val); }); } +// PATH TAB + { + for (const auto& dir : Config::getGameInstallDirs()) { + QString path_string; + Common::FS::PathToQString(path_string, dir); + QListWidgetItem* item = new QListWidgetItem(path_string); + ui->gameFoldersListWidget->addItem(item); + } + + ui->removeFolderButton->setEnabled(false); + + connect(ui->addFolderButton, &QPushButton::clicked, this, [this]() { + QString file_path_string = + QFileDialog::getExistingDirectory(this, tr("Directory to install games")); + auto file_path = Common::FS::PathFromQString(file_path_string); + if (!file_path.empty()) { + std::vector install_dirs = Config::getGameInstallDirs(); + install_dirs.push_back(file_path); + Config::setGameInstallDirs(install_dirs); + QListWidgetItem* item = new QListWidgetItem(file_path_string); + ui->gameFoldersListWidget->addItem(item); + } + }); + + connect(ui->gameFoldersListWidget, &QListWidget::itemSelectionChanged, this, [this]() { + ui->removeFolderButton->setEnabled( + !ui->gameFoldersListWidget->selectedItems().isEmpty()); + }); + + connect(ui->removeFolderButton, &QPushButton::clicked, this, [this]() { + QListWidgetItem* selected_item = ui->gameFoldersListWidget->currentItem(); + QString item_path_string = selected_item ? selected_item->text() : QString(); + if (!item_path_string.isEmpty()) { + auto file_path = Common::FS::PathFromQString(item_path_string); + std::vector install_dirs = Config::getGameInstallDirs(); + + auto iterator = std::remove_if( + install_dirs.begin(), install_dirs.end(), + [&file_path](const std::filesystem::path& dir) { return file_path == dir; }); + + if (iterator != install_dirs.end()) { + install_dirs.erase(iterator, install_dirs.end()); + delete selected_item; + } + Config::setGameInstallDirs(install_dirs); + } + }); + } + // DEBUG TAB { connect(ui->debugDump, &QCheckBox::stateChanged, this, diff --git a/src/qt_gui/settings_dialog.ui b/src/qt_gui/settings_dialog.ui index 9637c5fec1..e1c064d5ac 100644 --- a/src/qt_gui/settings_dialog.ui +++ b/src/qt_gui/settings_dialog.ui @@ -918,6 +918,76 @@ + + + Paths + + + + + + + + Game Folders + + + + + 0 + 20 + 401 + 331 + + + + + + + 100 + 360 + 80 + 24 + + + + Add... + + + + + + 210 + 360 + 80 + 24 + + + + Remove + + + + + + + + Qt::Orientation::Horizontal + + + QSizePolicy::Policy::Preferred + + + + 40 + 20 + + + + + + + + Debug