Merge pull request #8399 from CookiePLMonster/gametracker-fixes

Qt: Game Tracker fixes
This commit is contained in:
Connor McLaughlin 2019-11-08 11:22:09 +10:00 committed by GitHub
commit 71b098a69d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 11 deletions

View File

@ -34,7 +34,7 @@ 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, [] { connect(&Settings::Instance(), &Settings::AutoRefreshToggled, [] {
const auto paths = Settings::Instance().GetPaths(); const auto paths = Settings::Instance().GetPaths();
for (const auto& path : paths) for (const auto& path : paths)
@ -44,7 +44,7 @@ GameTracker::GameTracker(QObject* parent) : QFileSystemWatcher(parent)
} }
}); });
connect(&Settings::Instance(), &Settings::MetadataRefreshRequested, this, [this] { connect(&Settings::Instance(), &Settings::MetadataRefreshRequested, [this] {
m_load_thread.EmplaceItem(Command{CommandType::UpdateMetadata, {}}); m_load_thread.EmplaceItem(Command{CommandType::UpdateMetadata, {}});
}); });
@ -56,6 +56,7 @@ GameTracker::GameTracker(QObject* parent) : QFileSystemWatcher(parent)
break; break;
case CommandType::Start: case CommandType::Start:
StartInternal(); StartInternal();
break;
case CommandType::AddDirectory: case CommandType::AddDirectory:
AddDirectoryInternal(command.path); AddDirectoryInternal(command.path);
break; break;
@ -78,6 +79,20 @@ GameTracker::GameTracker(QObject* parent) : QFileSystemWatcher(parent)
case CommandType::PurgeCache: case CommandType::PurgeCache:
m_cache.Clear(UICommon::GameFileCache::DeleteOnDisk::Yes); m_cache.Clear(UICommon::GameFileCache::DeleteOnDisk::Yes);
break; break;
case CommandType::BeginRefresh:
if (m_busy_count++ == 0)
{
for (auto& file : m_tracked_files.keys())
emit GameRemoved(file.toStdString());
m_tracked_files.clear();
}
break;
case CommandType::EndRefresh:
if (--m_busy_count == 0)
{
QueueOnObject(this, [] { Settings::Instance().NotifyRefreshGameListComplete(); });
}
break;
} }
}); });
@ -176,16 +191,15 @@ void GameTracker::RemoveDirectory(const QString& dir)
void GameTracker::RefreshAll() void GameTracker::RefreshAll()
{ {
for (auto& file : m_tracked_files.keys()) m_load_thread.EmplaceItem(Command{CommandType::BeginRefresh});
emit GameRemoved(file.toStdString());
m_tracked_files.clear();
for (const QString& dir : Settings::Instance().GetPaths()) for (const QString& dir : Settings::Instance().GetPaths())
{ {
m_load_thread.EmplaceItem(Command{CommandType::RemoveDirectory, dir}); m_load_thread.EmplaceItem(Command{CommandType::RemoveDirectory, dir});
m_load_thread.EmplaceItem(Command{CommandType::AddDirectory, dir}); m_load_thread.EmplaceItem(Command{CommandType::AddDirectory, dir});
} }
m_load_thread.EmplaceItem(Command{CommandType::EndRefresh});
} }
void GameTracker::UpdateDirectory(const QString& dir) void GameTracker::UpdateDirectory(const QString& dir)

View File

@ -72,7 +72,9 @@ private:
UpdateDirectory, UpdateDirectory,
UpdateFile, UpdateFile,
UpdateMetadata, UpdateMetadata,
PurgeCache PurgeCache,
BeginRefresh,
EndRefresh,
}; };
struct Command struct Command
@ -90,6 +92,8 @@ private:
Common::Event m_initial_games_emitted_event; Common::Event m_initial_games_emitted_event;
bool m_initial_games_emitted = false; bool m_initial_games_emitted = false;
bool m_started = false; bool m_started = false;
// Count of currently running refresh jobs
u32 m_busy_count = 0;
}; };
Q_DECLARE_METATYPE(std::shared_ptr<const UICommon::GameFile>) Q_DECLARE_METATYPE(std::shared_ptr<const UICommon::GameFile>)

View File

@ -141,6 +141,11 @@ void Settings::RefreshGameList()
emit GameListRefreshRequested(); emit GameListRefreshRequested();
} }
void Settings::NotifyRefreshGameListComplete()
{
emit GameListRefreshCompleted();
}
void Settings::RefreshMetadata() void Settings::RefreshMetadata()
{ {
emit MetadataRefreshRequested(); emit MetadataRefreshRequested();

View File

@ -75,6 +75,7 @@ public:
QString GetDefaultGame() const; QString GetDefaultGame() const;
void SetDefaultGame(QString path); void SetDefaultGame(QString path);
void RefreshGameList(); void RefreshGameList();
void NotifyRefreshGameListComplete();
void RefreshMetadata(); void RefreshMetadata();
void NotifyMetadataRefreshComplete(); void NotifyMetadataRefreshComplete();
void ReloadTitleDB(); void ReloadTitleDB();
@ -150,6 +151,7 @@ signals:
void PathRemoved(const QString&); void PathRemoved(const QString&);
void DefaultGameChanged(const QString&); void DefaultGameChanged(const QString&);
void GameListRefreshRequested(); void GameListRefreshRequested();
void GameListRefreshCompleted();
void TitleDBReloadRequested(); void TitleDBReloadRequested();
void MetadataRefreshRequested(); void MetadataRefreshRequested();
void MetadataRefreshCompleted(); void MetadataRefreshCompleted();

View File

@ -32,10 +32,10 @@ ToolBar::ToolBar(QWidget* parent) : QToolBar(parent)
connect(&Settings::Instance(), &Settings::ThemeChanged, this, &ToolBar::UpdateIcons); connect(&Settings::Instance(), &Settings::ThemeChanged, this, &ToolBar::UpdateIcons);
UpdateIcons(); UpdateIcons();
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, connect(&Settings::Instance(), &Settings::EmulationStateChanged,
[this](Core::State state) { OnEmulationStateChanged(state); }); [this](Core::State state) { OnEmulationStateChanged(state); });
connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this, connect(Host::GetInstance(), &Host::UpdateDisasmDialog,
[this] { OnEmulationStateChanged(Core::GetState()); }); [this] { OnEmulationStateChanged(Core::GetState()); });
connect(&Settings::Instance(), &Settings::DebugModeToggled, this, &ToolBar::OnDebugModeToggled); connect(&Settings::Instance(), &Settings::DebugModeToggled, this, &ToolBar::OnDebugModeToggled);
@ -43,9 +43,12 @@ ToolBar::ToolBar(QWidget* parent) : QToolBar(parent)
connect(&Settings::Instance(), &Settings::ToolBarVisibilityChanged, this, &ToolBar::setVisible); connect(&Settings::Instance(), &Settings::ToolBarVisibilityChanged, this, &ToolBar::setVisible);
connect(this, &ToolBar::visibilityChanged, &Settings::Instance(), &Settings::SetToolBarVisible); connect(this, &ToolBar::visibilityChanged, &Settings::Instance(), &Settings::SetToolBarVisible);
connect(&Settings::Instance(), &Settings::WidgetLockChanged, this, connect(&Settings::Instance(), &Settings::WidgetLockChanged,
[this](bool locked) { setMovable(!locked); }); [this](bool locked) { setMovable(!locked); });
connect(&Settings::Instance(), &Settings::GameListRefreshCompleted,
[this] { m_refresh_action->setEnabled(true); });
OnEmulationStateChanged(Core::GetState()); OnEmulationStateChanged(Core::GetState());
OnDebugModeToggled(Settings::Instance().IsDebugModeEnabled()); OnDebugModeToggled(Settings::Instance().IsDebugModeEnabled());
} }
@ -109,7 +112,10 @@ void ToolBar::MakeActions()
m_set_pc_action = addAction(tr("Set PC"), this, &ToolBar::SetPCPressed); m_set_pc_action = addAction(tr("Set PC"), this, &ToolBar::SetPCPressed);
m_open_action = addAction(tr("Open"), this, &ToolBar::OpenPressed); m_open_action = addAction(tr("Open"), this, &ToolBar::OpenPressed);
m_refresh_action = addAction(tr("Refresh"), this, &ToolBar::RefreshPressed); m_refresh_action = addAction(tr("Refresh"), [this] {
m_refresh_action->setEnabled(false);
emit RefreshPressed();
});
addSeparator(); addSeparator();