Skip to content

Commit

Permalink
paths setting tab
Browse files Browse the repository at this point in the history
  • Loading branch information
ElBread3 committed Oct 9, 2024
1 parent fe3ad66 commit 39c88ed
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/qt_gui/settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,55 @@ SettingsDialog::SettingsDialog(std::span<const QString> 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<std::filesystem::path> 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<std::filesystem::path> 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,
Expand Down
70 changes: 70 additions & 0 deletions src/qt_gui/settings_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,76 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="pathsTab">
<attribute name="title">
<string>Paths</string>
</attribute>
<layout class="QVBoxLayout" name="inputTabVLayout" stretch="0">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QGroupBox" name="gameFoldersGroupBox">
<property name="title">
<string>Game Folders</string>
</property>
<widget class="QListWidget" name="gameFoldersListWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>20</y>
<width>401</width>
<height>331</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="addFolderButton">
<property name="geometry">
<rect>
<x>100</x>
<y>360</y>
<width>80</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>Add...</string>
</property>
</widget>
<widget class="QPushButton" name="removeFolderButton">
<property name="geometry">
<rect>
<x>210</x>
<y>360</y>
<width>80</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>Remove</string>
</property>
</widget>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Policy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="debugTab">
<attribute name="title">
<string>Debug</string>
Expand Down

0 comments on commit 39c88ed

Please sign in to comment.