From a4526772b9ad34d23f167a12505a016f83e8d2e1 Mon Sep 17 00:00:00 2001 From: spycrab Date: Thu, 19 Apr 2018 23:07:36 +0200 Subject: [PATCH] Qt: Add "Search subdirectories" checkbox --- .../DolphinQt2/GameList/GameListModel.cpp | 2 ++ .../Core/DolphinQt2/GameList/GameTracker.cpp | 33 ++++++++++++++----- Source/Core/DolphinQt2/GameList/GameTracker.h | 1 + Source/Core/DolphinQt2/Settings.cpp | 5 +++ Source/Core/DolphinQt2/Settings.h | 2 ++ Source/Core/DolphinQt2/Settings/PathPane.cpp | 12 +++++++ 6 files changed, 46 insertions(+), 9 deletions(-) diff --git a/Source/Core/DolphinQt2/GameList/GameListModel.cpp b/Source/Core/DolphinQt2/GameList/GameListModel.cpp index c1e6ce1af1..f332947b28 100644 --- a/Source/Core/DolphinQt2/GameList/GameListModel.cpp +++ b/Source/Core/DolphinQt2/GameList/GameListModel.cpp @@ -22,6 +22,8 @@ GameListModel::GameListModel(QObject* parent) : QAbstractTableModel(parent) [this](const QString& path) { RemoveGame(path.toStdString()); }); connect(&Settings::Instance(), &Settings::PathAdded, &m_tracker, &GameTracker::AddDirectory); connect(&Settings::Instance(), &Settings::PathRemoved, &m_tracker, &GameTracker::RemoveDirectory); + connect(&Settings::Instance(), &Settings::PathReloadRequested, &m_tracker, + &GameTracker::ReloadDirectory); for (const QString& dir : Settings::Instance().GetPaths()) m_tracker.AddDirectory(dir); diff --git a/Source/Core/DolphinQt2/GameList/GameTracker.cpp b/Source/Core/DolphinQt2/GameList/GameTracker.cpp index 4e4dfcb57b..d37869ee12 100644 --- a/Source/Core/DolphinQt2/GameList/GameTracker.cpp +++ b/Source/Core/DolphinQt2/GameList/GameTracker.cpp @@ -6,6 +6,7 @@ #include #include +#include "Core/ConfigManager.h" #include "DiscIO/DirectoryBlob.h" #include "DolphinQt2/GameList/GameTracker.h" #include "DolphinQt2/QtUtils/QueueOnObject.h" @@ -58,6 +59,12 @@ void GameTracker::RemoveDirectory(const QString& dir) m_load_thread.EmplaceItem(Command{CommandType::RemoveDirectory, dir}); } +void GameTracker::ReloadDirectory(const QString& dir) +{ + m_load_thread.EmplaceItem(Command{CommandType::RemoveDirectory, dir}); + m_load_thread.EmplaceItem(Command{CommandType::AddDirectory, dir}); +} + void GameTracker::UpdateDirectory(const QString& dir) { m_load_thread.EmplaceItem(Command{CommandType::UpdateDirectory, dir}); @@ -76,13 +83,21 @@ void GameTracker::AddDirectoryInternal(const QString& dir) UpdateDirectoryInternal(dir); } +static std::unique_ptr GetIterator(const QString& dir) +{ + return std::make_unique(dir, game_filters, QDir::NoFilter, + SConfig::GetInstance().m_RecursiveISOFolder ? + QDirIterator::Subdirectories : + QDirIterator::NoIteratorFlags); +} + void GameTracker::RemoveDirectoryInternal(const QString& dir) { removePath(dir); - QDirIterator it(dir, game_filters, QDir::NoFilter, QDirIterator::Subdirectories); - while (it.hasNext()) + auto it = GetIterator(dir); + while (it->hasNext()) { - QString path = QFileInfo(it.next()).canonicalFilePath(); + QString path = QFileInfo(it->next()).canonicalFilePath(); if (m_tracked_files.contains(path)) { m_tracked_files[path].remove(dir); @@ -98,10 +113,10 @@ void GameTracker::RemoveDirectoryInternal(const QString& dir) void GameTracker::UpdateDirectoryInternal(const QString& dir) { - QDirIterator it(dir, game_filters, QDir::NoFilter, QDirIterator::Subdirectories); - while (it.hasNext()) + auto it = GetIterator(dir); + while (it->hasNext()) { - QString path = QFileInfo(it.next()).canonicalFilePath(); + QString path = QFileInfo(it->next()).canonicalFilePath(); if (m_tracked_files.contains(path)) { @@ -147,7 +162,7 @@ void GameTracker::UpdateFileInternal(const QString& file) QSet GameTracker::FindMissingFiles(const QString& dir) { - QDirIterator it(dir, game_filters, QDir::NoFilter, QDirIterator::Subdirectories); + auto it = GetIterator(dir); QSet missing_files; @@ -157,9 +172,9 @@ QSet GameTracker::FindMissingFiles(const QString& dir) missing_files.insert(key); } - while (it.hasNext()) + while (it->hasNext()) { - QString path = QFileInfo(it.next()).canonicalFilePath(); + QString path = QFileInfo(it->next()).canonicalFilePath(); if (m_tracked_files.contains(path)) missing_files.remove(path); } diff --git a/Source/Core/DolphinQt2/GameList/GameTracker.h b/Source/Core/DolphinQt2/GameList/GameTracker.h index 73d1e097c4..b6bc8835a1 100644 --- a/Source/Core/DolphinQt2/GameList/GameTracker.h +++ b/Source/Core/DolphinQt2/GameList/GameTracker.h @@ -28,6 +28,7 @@ public: void AddDirectory(const QString& dir); void RemoveDirectory(const QString& dir); + void ReloadDirectory(const QString& dir); signals: void GameLoaded(std::shared_ptr game); diff --git a/Source/Core/DolphinQt2/Settings.cpp b/Source/Core/DolphinQt2/Settings.cpp index 3c3f1a1fed..4b93b7578b 100644 --- a/Source/Core/DolphinQt2/Settings.cpp +++ b/Source/Core/DolphinQt2/Settings.cpp @@ -80,6 +80,11 @@ void Settings::RemovePath(const QString& qpath) emit PathRemoved(qpath); } +void Settings::ReloadPath(const QString& qpath) +{ + emit PathReloadRequested(qpath); +} + QString Settings::GetDefaultGame() const { return QString::fromStdString(SConfig::GetInstance().m_strDefaultISO); diff --git a/Source/Core/DolphinQt2/Settings.h b/Source/Core/DolphinQt2/Settings.h index 0f6f3a97e4..f31abdaa46 100644 --- a/Source/Core/DolphinQt2/Settings.h +++ b/Source/Core/DolphinQt2/Settings.h @@ -61,6 +61,7 @@ public: void SetPreferredView(bool list); QString GetDefaultGame() const; void SetDefaultGame(QString path); + void ReloadPath(const QString& qpath); // Emulation int GetStateSlot() const; @@ -119,6 +120,7 @@ signals: void PathAdded(const QString&); void PathRemoved(const QString&); void DefaultGameChanged(const QString&); + void PathReloadRequested(const QString&); void HideCursorChanged(); void VolumeChanged(int volume); void NANDRefresh(); diff --git a/Source/Core/DolphinQt2/Settings/PathPane.cpp b/Source/Core/DolphinQt2/Settings/PathPane.cpp index 76ca08edfa..3554876708 100644 --- a/Source/Core/DolphinQt2/Settings/PathPane.cpp +++ b/Source/Core/DolphinQt2/Settings/PathPane.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include #include #include #include @@ -81,9 +82,20 @@ QGroupBox* PathPane::MakeGameFolderBox() hlayout->addStretch(); QPushButton* add = new QPushButton(tr("Add")); QPushButton* remove = new QPushButton(tr("Remove")); + + auto* checkbox = new QCheckBox(tr("Search Subfolders")); + checkbox->setChecked(SConfig::GetInstance().m_RecursiveISOFolder); + hlayout->addWidget(add); hlayout->addWidget(remove); vlayout->addLayout(hlayout); + vlayout->addWidget(checkbox); + + connect(checkbox, &QCheckBox::toggled, this, [this](bool checked) { + SConfig::GetInstance().m_RecursiveISOFolder = checked; + for (const auto& path : Settings::Instance().GetPaths()) + Settings::Instance().ReloadPath(path); + }); connect(add, &QPushButton::clicked, this, &PathPane::Browse); connect(remove, &QPushButton::clicked, this, &PathPane::RemovePath);