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::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) {
switch (command.type)
Expand Down Expand Up @@ -110,6 +119,31 @@ void GameTracker::StartInternal()
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)
{
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())
return;
addPath(dir);
AddPath(dir);
UpdateDirectoryInternal(dir);
}

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

void GameTracker::RemoveDirectoryInternal(const QString& dir)
{
removePath(dir);
RemovePath(dir);
auto it = GetIterator(dir);
while (it->hasNext())
{
Expand All @@ -164,7 +198,7 @@ void GameTracker::RemoveDirectoryInternal(const QString& dir)
m_tracked_files[path].remove(dir);
if (m_tracked_files[path].empty())
{
removePath(path);
RemovePath(path);
m_tracked_files.remove(path);
if (m_started)
emit GameRemoved(path.toStdString());
Expand All @@ -188,7 +222,7 @@ void GameTracker::UpdateDirectoryInternal(const QString& dir)
}
else
{
addPath(path);
AddPath(path);
m_tracked_files[path] = QSet<QString>{dir};
LoadGame(path);
}
Expand All @@ -214,10 +248,10 @@ void GameTracker::UpdateFileInternal(const QString& file)
{
if (m_started)
GameRemoved(file.toStdString());
addPath(file);
AddPath(file);
LoadGame(file);
}
else if (removePath(file))
else if (RemovePath(file))
{
m_tracked_files.remove(file);
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 <QSet>
#include <QString>
#include <QVector>

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

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

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

// game path -> directories that track it
QMap<QString, QSet<QString>> m_tracked_files;
QVector<QString> m_tracked_paths;
Common::WorkQueueThread<Command> m_load_thread;
UICommon::GameFileCache m_cache;
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();
}

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
{
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 ReloadPath(const QString& qpath);
void ReloadTitleDB();
bool IsAutoRefreshEnabled() const;
void SetAutoRefreshEnabled(bool enabled);

// Emulation
int GetStateSlot() const;
Expand Down Expand Up @@ -137,6 +139,7 @@ class Settings final : public QObject
void DefaultGameChanged(const QString&);
void PathReloadRequested(const QString&);
void TitleDBReloadRequested();
void AutoRefreshToggled(bool enabled);
void HideCursorChanged();
void KeepWindowOnTopChanged(bool top);
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);

auto* checkbox = new QCheckBox(tr("Search Subfolders"));
checkbox->setChecked(SConfig::GetInstance().m_RecursiveISOFolder);
auto* recursive_checkbox = new QCheckBox(tr("Search Subfolders"));
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(m_remove_path);
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;
for (const auto& path : Settings::Instance().GetPaths())
Settings::Instance().ReloadPath(path);
});

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

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

Expand Down

0 comments on commit ee47926

Please sign in to comment.