Qt: Add game list excluded folders as well as files

Backport of https://github.com/PCSX2/pcsx2/pull/9730
This commit is contained in:
Stenzek 2024-05-05 22:11:03 +10:00
parent 4ca7753720
commit ffb5682b43
No known key found for this signature in database
6 changed files with 72 additions and 6 deletions

View file

@ -479,7 +479,8 @@ void GameList::DeleteCacheFile()
static bool IsPathExcluded(const std::vector<std::string>& excluded_paths, const std::string& path) static bool IsPathExcluded(const std::vector<std::string>& excluded_paths, const std::string& path)
{ {
return (std::find(excluded_paths.begin(), excluded_paths.end(), path) != excluded_paths.end()); return std::find_if(excluded_paths.begin(), excluded_paths.end(),
[&path](const std::string& entry) { return path.starts_with(entry); }) != excluded_paths.end();
} }
void GameList::ScanDirectory(const char* path, bool recursive, bool only_cache, void GameList::ScanDirectory(const char* path, bool recursive, bool only_cache,

View file

@ -44,9 +44,15 @@ GameListSettingsWidget::GameListSettingsWidget(SettingsWindow* dialog, QWidget*
&GameListSettingsWidget::onAddSearchDirectoryButtonClicked); &GameListSettingsWidget::onAddSearchDirectoryButtonClicked);
connect(m_ui.removeSearchDirectoryButton, &QPushButton::clicked, this, connect(m_ui.removeSearchDirectoryButton, &QPushButton::clicked, this,
&GameListSettingsWidget::onRemoveSearchDirectoryButtonClicked); &GameListSettingsWidget::onRemoveSearchDirectoryButtonClicked);
connect(m_ui.addExcludedPath, &QPushButton::clicked, this, &GameListSettingsWidget::onAddExcludedPathButtonClicked); connect(m_ui.searchDirectoryList->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&GameListSettingsWidget::onSearchDirectoriesSelectionChanged);
connect(m_ui.addExcludedFile, &QPushButton::clicked, this, &GameListSettingsWidget::onAddExcludedFileButtonClicked);
connect(m_ui.addExcludedFolder, &QPushButton::clicked, this,
&GameListSettingsWidget::onAddExcludedFolderButtonClicked);
connect(m_ui.removeExcludedPath, &QPushButton::clicked, this, connect(m_ui.removeExcludedPath, &QPushButton::clicked, this,
&GameListSettingsWidget::onRemoveExcludedPathButtonClicked); &GameListSettingsWidget::onRemoveExcludedPathButtonClicked);
connect(m_ui.excludedPaths, &QListWidget::itemSelectionChanged, this,
&GameListSettingsWidget::onExcludedPathsSelectionChanged);
connect(m_ui.rescanAllGames, &QPushButton::clicked, this, &GameListSettingsWidget::onRescanAllGamesClicked); connect(m_ui.rescanAllGames, &QPushButton::clicked, this, &GameListSettingsWidget::onRescanAllGamesClicked);
connect(m_ui.scanForNewGames, &QPushButton::clicked, this, &GameListSettingsWidget::onScanForNewGamesClicked); connect(m_ui.scanForNewGames, &QPushButton::clicked, this, &GameListSettingsWidget::onScanForNewGamesClicked);
@ -73,6 +79,8 @@ void GameListSettingsWidget::refreshExclusionList()
const std::vector<std::string> paths(Host::GetBaseStringListSetting("GameList", "ExcludedPaths")); const std::vector<std::string> paths(Host::GetBaseStringListSetting("GameList", "ExcludedPaths"));
for (const std::string& path : paths) for (const std::string& path : paths)
m_ui.excludedPaths->addItem(QString::fromStdString(path)); m_ui.excludedPaths->addItem(QString::fromStdString(path));
m_ui.removeExcludedPath->setEnabled(false);
} }
void GameListSettingsWidget::resizeEvent(QResizeEvent* event) void GameListSettingsWidget::resizeEvent(QResizeEvent* event)
@ -147,7 +155,12 @@ void GameListSettingsWidget::onRemoveSearchDirectoryButtonClicked()
m_search_directories_model->removeEntry(row); m_search_directories_model->removeEntry(row);
} }
void GameListSettingsWidget::onAddExcludedPathButtonClicked() void GameListSettingsWidget::onSearchDirectoriesSelectionChanged()
{
m_ui.removeSearchDirectoryButton->setEnabled(m_ui.searchDirectoryList->selectionModel()->hasSelection());
}
void GameListSettingsWidget::onAddExcludedFileButtonClicked()
{ {
QString path = QString path =
QDir::toNativeSeparators(QFileDialog::getOpenFileName(QtUtils::GetRootWidget(this), tr("Select Path"))); QDir::toNativeSeparators(QFileDialog::getOpenFileName(QtUtils::GetRootWidget(this), tr("Select Path")));
@ -157,6 +170,16 @@ void GameListSettingsWidget::onAddExcludedPathButtonClicked()
addExcludedPath(path.toStdString()); addExcludedPath(path.toStdString());
} }
void GameListSettingsWidget::onAddExcludedFolderButtonClicked()
{
QString path =
QDir::toNativeSeparators(QFileDialog::getExistingDirectory(QtUtils::GetRootWidget(this), tr("Select Directory")));
if (path.isEmpty())
return;
addExcludedPath(path.toStdString());
}
void GameListSettingsWidget::onRemoveExcludedPathButtonClicked() void GameListSettingsWidget::onRemoveExcludedPathButtonClicked()
{ {
const int row = m_ui.excludedPaths->currentRow(); const int row = m_ui.excludedPaths->currentRow();
@ -171,6 +194,11 @@ void GameListSettingsWidget::onRemoveExcludedPathButtonClicked()
g_main_window->refreshGameList(false); g_main_window->refreshGameList(false);
} }
void GameListSettingsWidget::onExcludedPathsSelectionChanged()
{
m_ui.removeExcludedPath->setEnabled(!m_ui.excludedPaths->selectedItems().isEmpty());
}
void GameListSettingsWidget::onRescanAllGamesClicked() void GameListSettingsWidget::onRescanAllGamesClicked()
{ {
g_main_window->refreshGameList(true); g_main_window->refreshGameList(true);

View file

@ -29,8 +29,11 @@ private Q_SLOTS:
void onDirectoryListContextMenuRequested(const QPoint& point); void onDirectoryListContextMenuRequested(const QPoint& point);
void onAddSearchDirectoryButtonClicked(); void onAddSearchDirectoryButtonClicked();
void onRemoveSearchDirectoryButtonClicked(); void onRemoveSearchDirectoryButtonClicked();
void onAddExcludedPathButtonClicked(); void onSearchDirectoriesSelectionChanged();
void onAddExcludedFileButtonClicked();
void onAddExcludedFolderButtonClicked();
void onRemoveExcludedPathButtonClicked(); void onRemoveExcludedPathButtonClicked();
void onExcludedPathsSelectionChanged();
void onScanForNewGamesClicked(); void onScanForNewGamesClicked();
void onRescanAllGamesClicked(); void onRescanAllGamesClicked();

View file

@ -105,7 +105,7 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QToolButton" name="addExcludedPath"> <widget class="QToolButton" name="addExcludedFile">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -113,11 +113,33 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Add</string> <string>File...</string>
</property>
<property name="icon">
<iconset theme="file-add-line"/>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="addExcludedFolder">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Folder...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset theme="folder-add-line"/> <iconset theme="folder-add-line"/>
</property> </property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -134,6 +156,9 @@
<property name="icon"> <property name="icon">
<iconset theme="folder-reduce-line"/> <iconset theme="folder-reduce-line"/>
</property> </property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>

View file

@ -251,6 +251,8 @@ void SetupWizardDialog::setupGameListPage()
&SetupWizardDialog::onAddSearchDirectoryButtonClicked); &SetupWizardDialog::onAddSearchDirectoryButtonClicked);
connect(m_ui.removeSearchDirectoryButton, &QPushButton::clicked, this, connect(m_ui.removeSearchDirectoryButton, &QPushButton::clicked, this,
&SetupWizardDialog::onRemoveSearchDirectoryButtonClicked); &SetupWizardDialog::onRemoveSearchDirectoryButtonClicked);
connect(m_ui.searchDirectoryList, &QTableWidget::itemSelectionChanged, this,
&SetupWizardDialog::onSearchDirectoryListSelectionChanged);
refreshDirectoryList(); refreshDirectoryList();
} }
@ -314,6 +316,11 @@ void SetupWizardDialog::onRemoveSearchDirectoryButtonClicked()
refreshDirectoryList(); refreshDirectoryList();
} }
void SetupWizardDialog::onSearchDirectoryListSelectionChanged()
{
m_ui.removeSearchDirectoryButton->setEnabled(!m_ui.searchDirectoryList->selectedItems().isEmpty());
}
void SetupWizardDialog::addPathToTable(const std::string& path, bool recursive) void SetupWizardDialog::addPathToTable(const std::string& path, bool recursive)
{ {
const int row = m_ui.searchDirectoryList->rowCount(); const int row = m_ui.searchDirectoryList->rowCount();
@ -359,6 +366,7 @@ void SetupWizardDialog::refreshDirectoryList()
addPathToTable(entry, true); addPathToTable(entry, true);
m_ui.searchDirectoryList->sortByColumn(0, Qt::AscendingOrder); m_ui.searchDirectoryList->sortByColumn(0, Qt::AscendingOrder);
m_ui.removeSearchDirectoryButton->setEnabled(false);
} }
void SetupWizardDialog::resizeDirectoryListColumns() void SetupWizardDialog::resizeDirectoryListColumns()

View file

@ -38,6 +38,7 @@ private Q_SLOTS:
void onDirectoryListContextMenuRequested(const QPoint& point); void onDirectoryListContextMenuRequested(const QPoint& point);
void onAddSearchDirectoryButtonClicked(); void onAddSearchDirectoryButtonClicked();
void onRemoveSearchDirectoryButtonClicked(); void onRemoveSearchDirectoryButtonClicked();
void onSearchDirectoryListSelectionChanged();
void refreshDirectoryList(); void refreshDirectoryList();
void resizeDirectoryListColumns(); void resizeDirectoryListColumns();