From 409c2b36ff8a8ce96a4d8eb5745a158b979e642d Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 2 Jul 2021 12:24:37 +1000 Subject: [PATCH] Qt: Add game list exclude path UI --- src/common/jit_code_buffer.h | 3 + src/duckstation-qt/gamelistsettingswidget.cpp | 47 ++++ src/duckstation-qt/gamelistsettingswidget.h | 7 +- src/duckstation-qt/gamelistsettingswidget.ui | 250 ++++++++++++------ src/duckstation-qt/mainwindow.cpp | 3 + src/duckstation-qt/qthostinterface.cpp | 20 ++ src/duckstation-qt/qthostinterface.h | 2 + 7 files changed, 243 insertions(+), 89 deletions(-) diff --git a/src/common/jit_code_buffer.h b/src/common/jit_code_buffer.h index bf2b07305..3c6b210ef 100644 --- a/src/common/jit_code_buffer.h +++ b/src/common/jit_code_buffer.h @@ -14,6 +14,9 @@ public: void Destroy(); void Reset(); + u8* GetCodePointer() const { return m_code_ptr; } + u32 GetTotalSize() const { return m_total_size; } + u8* GetFreeCodePointer() const { return m_free_code_ptr; } u32 GetFreeCodeSpace() const { return static_cast(m_code_size - m_code_used); } void CommitCode(u32 length); diff --git a/src/duckstation-qt/gamelistsettingswidget.cpp b/src/duckstation-qt/gamelistsettingswidget.cpp index a44c1e1db..20838700b 100644 --- a/src/duckstation-qt/gamelistsettingswidget.cpp +++ b/src/duckstation-qt/gamelistsettingswidget.cpp @@ -39,12 +39,36 @@ GameListSettingsWidget::GameListSettingsWidget(QtHostInterface* host_interface, &GameListSettingsWidget::onAddSearchDirectoryButtonClicked); connect(m_ui.removeSearchDirectoryButton, &QPushButton::clicked, this, &GameListSettingsWidget::onRemoveSearchDirectoryButtonClicked); + connect(m_ui.addExcludedPath, &QPushButton::clicked, this, &GameListSettingsWidget::onAddExcludedPathButtonClicked); + connect(m_ui.removeExcludedPath, &QPushButton::clicked, this, + &GameListSettingsWidget::onRemoveExcludedPathButtonClicked); connect(m_ui.rescanAllGames, &QPushButton::clicked, this, &GameListSettingsWidget::onRescanAllGamesClicked); connect(m_ui.scanForNewGames, &QPushButton::clicked, this, &GameListSettingsWidget::onScanForNewGamesClicked); + + refreshExclusionList(); } GameListSettingsWidget::~GameListSettingsWidget() = default; +bool GameListSettingsWidget::addExcludedPath(const std::string& path) +{ + if (!m_host_interface->AddValueToStringList("GameList", "ExcludedPaths", path.c_str())) + return false; + + m_ui.excludedPaths->addItem(QString::fromStdString(path)); + m_host_interface->refreshGameList(); + return true; +} + +void GameListSettingsWidget::refreshExclusionList() +{ + m_ui.excludedPaths->clear(); + + const std::vector paths(m_host_interface->GetSettingStringList("GameList", "ExcludedPaths")); + for (const std::string& path : paths) + m_ui.excludedPaths->addItem(QString::fromStdString(path)); +} + void GameListSettingsWidget::resizeEvent(QResizeEvent* event) { QWidget::resizeEvent(event); @@ -117,6 +141,29 @@ void GameListSettingsWidget::onRemoveSearchDirectoryButtonClicked() m_search_directories_model->removeEntry(row); } +void GameListSettingsWidget::onAddExcludedPathButtonClicked() +{ + QString path = + QDir::toNativeSeparators(QFileDialog::getOpenFileName(QtUtils::GetRootWidget(this), tr("Select Path"))); + if (path.isEmpty()) + return; + + addExcludedPath(path.toStdString()); +} + +void GameListSettingsWidget::onRemoveExcludedPathButtonClicked() +{ + const int row = m_ui.excludedPaths->currentRow(); + QListWidgetItem* item = (row >= 0) ? m_ui.excludedPaths->takeItem(row) : 0; + if (!item) + return; + + m_host_interface->RemoveValueFromStringList("GameList", "ExcludedPaths", item->text().toUtf8().constData()); + delete item; + + m_host_interface->refreshGameList(); +} + void GameListSettingsWidget::onRescanAllGamesClicked() { m_host_interface->refreshGameList(true, false); diff --git a/src/duckstation-qt/gamelistsettingswidget.h b/src/duckstation-qt/gamelistsettingswidget.h index 11bb9e699..a09248e86 100644 --- a/src/duckstation-qt/gamelistsettingswidget.h +++ b/src/duckstation-qt/gamelistsettingswidget.h @@ -1,5 +1,5 @@ #pragma once - +#include #include #include "ui_gamelistsettingswidget.h" @@ -16,6 +16,9 @@ public: GameListSettingsWidget(QtHostInterface* host_interface, QWidget* parent = nullptr); ~GameListSettingsWidget(); + bool addExcludedPath(const std::string& path); + void refreshExclusionList(); + public Q_SLOTS: void addSearchDirectory(QWidget* parent_widget); @@ -24,6 +27,8 @@ private Q_SLOTS: void onDirectoryListContextMenuRequested(const QPoint& point); void onAddSearchDirectoryButtonClicked(); void onRemoveSearchDirectoryButtonClicked(); + void onAddExcludedPathButtonClicked(); + void onRemoveExcludedPathButtonClicked(); void onScanForNewGamesClicked(); void onRescanAllGamesClicked(); diff --git a/src/duckstation-qt/gamelistsettingswidget.ui b/src/duckstation-qt/gamelistsettingswidget.ui index 28fc9af65..ae16a986d 100644 --- a/src/duckstation-qt/gamelistsettingswidget.ui +++ b/src/duckstation-qt/gamelistsettingswidget.ui @@ -6,14 +6,14 @@ 0 0 - 527 + 532 376 Form - + 0 @@ -26,8 +26,8 @@ 0 - - + + @@ -36,92 +36,166 @@ - + + + Qt::Horizontal + + + + 40 + 20 + + + - - - - - - 0 - 0 - - - - Add - - - - :/icons/list-add.png:/icons/list-add.png - - - - - - - - 0 - 0 - - - - Remove - - - - :/icons/list-remove.png:/icons/list-remove.png - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - Scan New - - - - :/icons/folder-open.png:/icons/folder-open.png - - - - - - - - 0 - 0 - - - - Rescan All - - - - :/icons/view-refresh.png:/icons/view-refresh.png - - - - + + + + 0 + 0 + + + + Add + + + + :/icons/list-add.png:/icons/list-add.png + + + + + + + + 0 + 0 + + + + Remove + + + + :/icons/list-remove.png:/icons/list-remove.png + + + + + + + + + + + + + + Excluded Paths + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Add + + + + :/icons/list-add.png:/icons/list-add.png + + + + + + + + 0 + 0 + + + + Remove + + + + :/icons/list-remove.png:/icons/list-remove.png + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Scan For New Games + + + + :/icons/folder-open.png:/icons/folder-open.png + + + + + + + + 0 + 0 + + + + Rescan All Games + + + + :/icons/view-refresh.png:/icons/view-refresh.png + + diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index 0693d3bea..c06885feb 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -693,6 +693,9 @@ void MainWindow::onGameListContextMenuRequested(const QPoint& point, const GameL menu.addSeparator(); } + connect(menu.addAction(tr("Exclude From List")), &QAction::triggered, + [this, entry]() { getSettingsDialog()->getGameListSettingsWidget()->addExcludedPath(entry->path); }); + connect(menu.addAction(tr("Add Search Directory...")), &QAction::triggered, [this]() { getSettingsDialog()->getGameListSettingsWidget()->addSearchDirectory(this); }); diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index fd321d3e7..b1b85182d 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -236,6 +236,26 @@ void QtHostInterface::SetStringListSettingValue(const char* section, const char* queueSettingsSave(); } +bool QtHostInterface::AddValueToStringList(const char* section, const char* key, const char* value) +{ + std::lock_guard guard(m_settings_mutex); + if (!m_settings_interface->AddToStringList(section, key, value)) + return false; + + queueSettingsSave(); + return true; +} + +bool QtHostInterface::RemoveValueFromStringList(const char* section, const char* key, const char* value) +{ + std::lock_guard guard(m_settings_mutex); + if (!m_settings_interface->RemoveFromStringList(section, key, value)) + return false; + + queueSettingsSave(); + return true; +} + void QtHostInterface::RemoveSettingValue(const char* section, const char* key) { std::lock_guard guard(m_settings_mutex); diff --git a/src/duckstation-qt/qthostinterface.h b/src/duckstation-qt/qthostinterface.h index a5d8a089a..aa33ef6fa 100644 --- a/src/duckstation-qt/qthostinterface.h +++ b/src/duckstation-qt/qthostinterface.h @@ -64,6 +64,8 @@ public: void SetFloatSettingValue(const char* section, const char* key, float value); void SetStringSettingValue(const char* section, const char* key, const char* value); void SetStringListSettingValue(const char* section, const char* key, const std::vector& values); + bool AddValueToStringList(const char* section, const char* key, const char* value); + bool RemoveValueFromStringList(const char* section, const char* key, const char* value); void RemoveSettingValue(const char* section, const char* key); TinyString TranslateString(const char* context, const char* str, const char* disambiguation = nullptr,