Skip to content

Commit

Permalink
Qt: Add option to disable auto-refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
spycrab committed Jun 6, 2018
1 parent 0dfd0cf commit ee47926
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 10 deletions.
46 changes: 40 additions & 6 deletions Source/Core/DolphinQt2/GameList/GameTracker.cpp
Expand Up @@ -30,6 +30,15 @@ GameTracker::GameTracker(QObject* parent) : QFileSystemWatcher(parent)


connect(this, &QFileSystemWatcher::directoryChanged, this, &GameTracker::UpdateDirectory); connect(this, &QFileSystemWatcher::directoryChanged, this, &GameTracker::UpdateDirectory);
connect(this, &QFileSystemWatcher::fileChanged, this, &GameTracker::UpdateFile); connect(this, &QFileSystemWatcher::fileChanged, this, &GameTracker::UpdateFile);
connect(&Settings::Instance(), &Settings::AutoRefreshToggled, this, [this] {
const auto paths = Settings::Instance().GetPaths();

for (const auto& path : paths)
{
Settings::Instance().RemovePath(path);
Settings::Instance().AddPath(path);
}
});


m_load_thread.Reset([this](Command command) { m_load_thread.Reset([this](Command command) {
switch (command.type) switch (command.type)
Expand Down Expand Up @@ -110,6 +119,31 @@ void GameTracker::StartInternal()
m_cache.Save(); m_cache.Save();
} }


bool GameTracker::AddPath(const QString& dir)
{
if (Settings::Instance().IsAutoRefreshEnabled())
return addPath(dir);

m_tracked_paths.push_back(dir);

return true;
}

bool GameTracker::RemovePath(const QString& dir)
{
if (Settings::Instance().IsAutoRefreshEnabled())
return removePath(dir);

const auto index = m_tracked_paths.indexOf(dir);

if (index == -1)
return false;

m_tracked_paths.remove(index);

return true;
}

void GameTracker::AddDirectory(const QString& dir) void GameTracker::AddDirectory(const QString& dir)
{ {
m_load_thread.EmplaceItem(Command{CommandType::AddDirectory, dir}); m_load_thread.EmplaceItem(Command{CommandType::AddDirectory, dir});
Expand Down Expand Up @@ -140,7 +174,7 @@ void GameTracker::AddDirectoryInternal(const QString& dir)
{ {
if (!QFileInfo(dir).exists()) if (!QFileInfo(dir).exists())
return; return;
addPath(dir); AddPath(dir);
UpdateDirectoryInternal(dir); UpdateDirectoryInternal(dir);
} }


Expand All @@ -154,7 +188,7 @@ static std::unique_ptr<QDirIterator> GetIterator(const QString& dir)


void GameTracker::RemoveDirectoryInternal(const QString& dir) void GameTracker::RemoveDirectoryInternal(const QString& dir)
{ {
removePath(dir); RemovePath(dir);
auto it = GetIterator(dir); auto it = GetIterator(dir);
while (it->hasNext()) while (it->hasNext())
{ {
Expand All @@ -164,7 +198,7 @@ void GameTracker::RemoveDirectoryInternal(const QString& dir)
m_tracked_files[path].remove(dir); m_tracked_files[path].remove(dir);
if (m_tracked_files[path].empty()) if (m_tracked_files[path].empty())
{ {
removePath(path); RemovePath(path);
m_tracked_files.remove(path); m_tracked_files.remove(path);
if (m_started) if (m_started)
emit GameRemoved(path.toStdString()); emit GameRemoved(path.toStdString());
Expand All @@ -188,7 +222,7 @@ void GameTracker::UpdateDirectoryInternal(const QString& dir)
} }
else else
{ {
addPath(path); AddPath(path);
m_tracked_files[path] = QSet<QString>{dir}; m_tracked_files[path] = QSet<QString>{dir};
LoadGame(path); LoadGame(path);
} }
Expand All @@ -214,10 +248,10 @@ void GameTracker::UpdateFileInternal(const QString& file)
{ {
if (m_started) if (m_started)
GameRemoved(file.toStdString()); GameRemoved(file.toStdString());
addPath(file); AddPath(file);
LoadGame(file); LoadGame(file);
} }
else if (removePath(file)) else if (RemovePath(file))
{ {
m_tracked_files.remove(file); m_tracked_files.remove(file);
if (m_started) if (m_started)
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/DolphinQt2/GameList/GameTracker.h
Expand Up @@ -11,6 +11,7 @@
#include <QMap> #include <QMap>
#include <QSet> #include <QSet>
#include <QString> #include <QString>
#include <QVector>


#include "Common/Event.h" #include "Common/Event.h"
#include "Common/WorkQueueThread.h" #include "Common/WorkQueueThread.h"
Expand Down Expand Up @@ -54,6 +55,9 @@ class GameTracker final : public QFileSystemWatcher
QSet<QString> FindMissingFiles(const QString& dir); QSet<QString> FindMissingFiles(const QString& dir);
void LoadGame(const QString& path); void LoadGame(const QString& path);


bool AddPath(const QString& path);
bool RemovePath(const QString& path);

enum class CommandType enum class CommandType
{ {
LoadCache, LoadCache,
Expand All @@ -72,6 +76,7 @@ class GameTracker final : public QFileSystemWatcher


// game path -> directories that track it // game path -> directories that track it
QMap<QString, QSet<QString>> m_tracked_files; QMap<QString, QSet<QString>> m_tracked_files;
QVector<QString> m_tracked_paths;
Common::WorkQueueThread<Command> m_load_thread; Common::WorkQueueThread<Command> m_load_thread;
UICommon::GameFileCache m_cache; UICommon::GameFileCache m_cache;
Common::Event m_cache_loaded_event; Common::Event m_cache_loaded_event;
Expand Down
15 changes: 15 additions & 0 deletions Source/Core/DolphinQt2/Settings.cpp
Expand Up @@ -133,6 +133,21 @@ void Settings::ReloadTitleDB()
emit TitleDBReloadRequested(); emit TitleDBReloadRequested();
} }


bool Settings::IsAutoRefreshEnabled() const
{
return GetQSettings().value(QStringLiteral("gamelist/autorefresh"), true).toBool();
}

void Settings::SetAutoRefreshEnabled(bool enabled)
{
if (IsAutoRefreshEnabled() == enabled)
return;

GetQSettings().setValue(QStringLiteral("gamelist/autorefresh"), enabled);

emit AutoRefreshToggled(enabled);
}

QString Settings::GetDefaultGame() const QString Settings::GetDefaultGame() const
{ {
return QString::fromStdString(SConfig::GetInstance().m_strDefaultISO); return QString::fromStdString(SConfig::GetInstance().m_strDefaultISO);
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/DolphinQt2/Settings.h
Expand Up @@ -71,6 +71,8 @@ class Settings final : public QObject
void SetDefaultGame(QString path); void SetDefaultGame(QString path);
void ReloadPath(const QString& qpath); void ReloadPath(const QString& qpath);
void ReloadTitleDB(); void ReloadTitleDB();
bool IsAutoRefreshEnabled() const;
void SetAutoRefreshEnabled(bool enabled);


// Emulation // Emulation
int GetStateSlot() const; int GetStateSlot() const;
Expand Down Expand Up @@ -137,6 +139,7 @@ class Settings final : public QObject
void DefaultGameChanged(const QString&); void DefaultGameChanged(const QString&);
void PathReloadRequested(const QString&); void PathReloadRequested(const QString&);
void TitleDBReloadRequested(); void TitleDBReloadRequested();
void AutoRefreshToggled(bool enabled);
void HideCursorChanged(); void HideCursorChanged();
void KeepWindowOnTopChanged(bool top); void KeepWindowOnTopChanged(bool top);
void VolumeChanged(int volume); void VolumeChanged(int volume);
Expand Down
15 changes: 11 additions & 4 deletions Source/Core/DolphinQt2/Settings/PathPane.cpp
Expand Up @@ -127,20 +127,27 @@ QGroupBox* PathPane::MakeGameFolderBox()


m_remove_path->setEnabled(false); m_remove_path->setEnabled(false);


auto* checkbox = new QCheckBox(tr("Search Subfolders")); auto* recursive_checkbox = new QCheckBox(tr("Search Subfolders"));
checkbox->setChecked(SConfig::GetInstance().m_RecursiveISOFolder); recursive_checkbox->setChecked(SConfig::GetInstance().m_RecursiveISOFolder);

auto* auto_checkbox = new QCheckBox(tr("Check for Game List Changes in the Background"));
auto_checkbox->setChecked(Settings::Instance().IsAutoRefreshEnabled());


hlayout->addWidget(add); hlayout->addWidget(add);
hlayout->addWidget(m_remove_path); hlayout->addWidget(m_remove_path);
vlayout->addLayout(hlayout); vlayout->addLayout(hlayout);
vlayout->addWidget(checkbox); vlayout->addWidget(recursive_checkbox);
vlayout->addWidget(auto_checkbox);


connect(checkbox, &QCheckBox::toggled, this, [](bool checked) { connect(recursive_checkbox, &QCheckBox::toggled, this, [](bool checked) {
SConfig::GetInstance().m_RecursiveISOFolder = checked; SConfig::GetInstance().m_RecursiveISOFolder = checked;
for (const auto& path : Settings::Instance().GetPaths()) for (const auto& path : Settings::Instance().GetPaths())
Settings::Instance().ReloadPath(path); Settings::Instance().ReloadPath(path);
}); });


connect(auto_checkbox, &QCheckBox::toggled, &Settings::Instance(),
&Settings::SetAutoRefreshEnabled);

connect(add, &QPushButton::pressed, this, &PathPane::Browse); connect(add, &QPushButton::pressed, this, &PathPane::Browse);
connect(m_remove_path, &QPushButton::pressed, this, &PathPane::RemovePath); connect(m_remove_path, &QPushButton::pressed, this, &PathPane::RemovePath);


Expand Down

0 comments on commit ee47926

Please sign in to comment.