Qt: Add "Search subdirectories" checkbox

This commit is contained in:
spycrab 2018-04-19 23:07:36 +02:00
parent 396204248d
commit a4526772b9
6 changed files with 46 additions and 9 deletions

View File

@ -22,6 +22,8 @@ GameListModel::GameListModel(QObject* parent) : QAbstractTableModel(parent)
[this](const QString& path) { RemoveGame(path.toStdString()); }); [this](const QString& path) { RemoveGame(path.toStdString()); });
connect(&Settings::Instance(), &Settings::PathAdded, &m_tracker, &GameTracker::AddDirectory); connect(&Settings::Instance(), &Settings::PathAdded, &m_tracker, &GameTracker::AddDirectory);
connect(&Settings::Instance(), &Settings::PathRemoved, &m_tracker, &GameTracker::RemoveDirectory); 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()) for (const QString& dir : Settings::Instance().GetPaths())
m_tracker.AddDirectory(dir); m_tracker.AddDirectory(dir);

View File

@ -6,6 +6,7 @@
#include <QDirIterator> #include <QDirIterator>
#include <QFile> #include <QFile>
#include "Core/ConfigManager.h"
#include "DiscIO/DirectoryBlob.h" #include "DiscIO/DirectoryBlob.h"
#include "DolphinQt2/GameList/GameTracker.h" #include "DolphinQt2/GameList/GameTracker.h"
#include "DolphinQt2/QtUtils/QueueOnObject.h" #include "DolphinQt2/QtUtils/QueueOnObject.h"
@ -58,6 +59,12 @@ void GameTracker::RemoveDirectory(const QString& dir)
m_load_thread.EmplaceItem(Command{CommandType::RemoveDirectory, 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) void GameTracker::UpdateDirectory(const QString& dir)
{ {
m_load_thread.EmplaceItem(Command{CommandType::UpdateDirectory, dir}); m_load_thread.EmplaceItem(Command{CommandType::UpdateDirectory, dir});
@ -76,13 +83,21 @@ void GameTracker::AddDirectoryInternal(const QString& dir)
UpdateDirectoryInternal(dir); UpdateDirectoryInternal(dir);
} }
static std::unique_ptr<QDirIterator> GetIterator(const QString& dir)
{
return std::make_unique<QDirIterator>(dir, game_filters, QDir::NoFilter,
SConfig::GetInstance().m_RecursiveISOFolder ?
QDirIterator::Subdirectories :
QDirIterator::NoIteratorFlags);
}
void GameTracker::RemoveDirectoryInternal(const QString& dir) void GameTracker::RemoveDirectoryInternal(const QString& dir)
{ {
removePath(dir); removePath(dir);
QDirIterator it(dir, game_filters, QDir::NoFilter, QDirIterator::Subdirectories); auto it = GetIterator(dir);
while (it.hasNext()) while (it->hasNext())
{ {
QString path = QFileInfo(it.next()).canonicalFilePath(); QString path = QFileInfo(it->next()).canonicalFilePath();
if (m_tracked_files.contains(path)) if (m_tracked_files.contains(path))
{ {
m_tracked_files[path].remove(dir); m_tracked_files[path].remove(dir);
@ -98,10 +113,10 @@ void GameTracker::RemoveDirectoryInternal(const QString& dir)
void GameTracker::UpdateDirectoryInternal(const QString& dir) void GameTracker::UpdateDirectoryInternal(const QString& dir)
{ {
QDirIterator it(dir, game_filters, QDir::NoFilter, QDirIterator::Subdirectories); auto it = GetIterator(dir);
while (it.hasNext()) while (it->hasNext())
{ {
QString path = QFileInfo(it.next()).canonicalFilePath(); QString path = QFileInfo(it->next()).canonicalFilePath();
if (m_tracked_files.contains(path)) if (m_tracked_files.contains(path))
{ {
@ -147,7 +162,7 @@ void GameTracker::UpdateFileInternal(const QString& file)
QSet<QString> GameTracker::FindMissingFiles(const QString& dir) QSet<QString> GameTracker::FindMissingFiles(const QString& dir)
{ {
QDirIterator it(dir, game_filters, QDir::NoFilter, QDirIterator::Subdirectories); auto it = GetIterator(dir);
QSet<QString> missing_files; QSet<QString> missing_files;
@ -157,9 +172,9 @@ QSet<QString> GameTracker::FindMissingFiles(const QString& dir)
missing_files.insert(key); 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)) if (m_tracked_files.contains(path))
missing_files.remove(path); missing_files.remove(path);
} }

View File

@ -28,6 +28,7 @@ public:
void AddDirectory(const QString& dir); void AddDirectory(const QString& dir);
void RemoveDirectory(const QString& dir); void RemoveDirectory(const QString& dir);
void ReloadDirectory(const QString& dir);
signals: signals:
void GameLoaded(std::shared_ptr<const UICommon::GameFile> game); void GameLoaded(std::shared_ptr<const UICommon::GameFile> game);

View File

@ -80,6 +80,11 @@ void Settings::RemovePath(const QString& qpath)
emit PathRemoved(qpath); emit PathRemoved(qpath);
} }
void Settings::ReloadPath(const QString& qpath)
{
emit PathReloadRequested(qpath);
}
QString Settings::GetDefaultGame() const QString Settings::GetDefaultGame() const
{ {
return QString::fromStdString(SConfig::GetInstance().m_strDefaultISO); return QString::fromStdString(SConfig::GetInstance().m_strDefaultISO);

View File

@ -61,6 +61,7 @@ public:
void SetPreferredView(bool list); void SetPreferredView(bool list);
QString GetDefaultGame() const; QString GetDefaultGame() const;
void SetDefaultGame(QString path); void SetDefaultGame(QString path);
void ReloadPath(const QString& qpath);
// Emulation // Emulation
int GetStateSlot() const; int GetStateSlot() const;
@ -119,6 +120,7 @@ signals:
void PathAdded(const QString&); void PathAdded(const QString&);
void PathRemoved(const QString&); void PathRemoved(const QString&);
void DefaultGameChanged(const QString&); void DefaultGameChanged(const QString&);
void PathReloadRequested(const QString&);
void HideCursorChanged(); void HideCursorChanged();
void VolumeChanged(int volume); void VolumeChanged(int volume);
void NANDRefresh(); void NANDRefresh();

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <QCheckBox>
#include <QFileDialog> #include <QFileDialog>
#include <QGroupBox> #include <QGroupBox>
#include <QLabel> #include <QLabel>
@ -81,9 +82,20 @@ QGroupBox* PathPane::MakeGameFolderBox()
hlayout->addStretch(); hlayout->addStretch();
QPushButton* add = new QPushButton(tr("Add")); QPushButton* add = new QPushButton(tr("Add"));
QPushButton* remove = new QPushButton(tr("Remove")); QPushButton* remove = new QPushButton(tr("Remove"));
auto* checkbox = new QCheckBox(tr("Search Subfolders"));
checkbox->setChecked(SConfig::GetInstance().m_RecursiveISOFolder);
hlayout->addWidget(add); hlayout->addWidget(add);
hlayout->addWidget(remove); hlayout->addWidget(remove);
vlayout->addLayout(hlayout); 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(add, &QPushButton::clicked, this, &PathPane::Browse);
connect(remove, &QPushButton::clicked, this, &PathPane::RemovePath); connect(remove, &QPushButton::clicked, this, &PathPane::RemovePath);