Skip to content
Permalink
Browse files

Add signals to enable/disable Refresh button

Makes it impossible to spam Refresh button and looks better overall.
  • Loading branch information...
CookiePLMonster committed Oct 9, 2019
1 parent cc6ffef commit 68694e003938252eac35960969aa4834a66c9207
@@ -34,7 +34,7 @@ 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, [] {
connect(&Settings::Instance(), &Settings::AutoRefreshToggled, [] {
const auto paths = Settings::Instance().GetPaths();

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, {}});
});

@@ -80,9 +80,18 @@ GameTracker::GameTracker(QObject* parent) : QFileSystemWatcher(parent)
m_cache.Clear(UICommon::GameFileCache::DeleteOnDisk::Yes);
break;
case CommandType::BeginRefresh:
for (auto& file : m_tracked_files.keys())
emit GameRemoved(file.toStdString());
m_tracked_files.clear();
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;
}
});
@@ -189,6 +198,8 @@ void GameTracker::RefreshAll()
m_load_thread.EmplaceItem(Command{CommandType::RemoveDirectory, dir});
m_load_thread.EmplaceItem(Command{CommandType::AddDirectory, dir});
}

m_load_thread.EmplaceItem(Command{CommandType::EndRefresh});
}

void GameTracker::UpdateDirectory(const QString& dir)
@@ -74,6 +74,7 @@ class GameTracker final : public QFileSystemWatcher
UpdateMetadata,
PurgeCache,
BeginRefresh,
EndRefresh,
};

struct Command
@@ -91,6 +92,8 @@ class GameTracker final : public QFileSystemWatcher
Common::Event m_initial_games_emitted_event;
bool m_initial_games_emitted = 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>)
@@ -141,6 +141,11 @@ void Settings::RefreshGameList()
emit GameListRefreshRequested();
}

void Settings::NotifyRefreshGameListComplete()
{
emit GameListRefreshCompleted();
}

void Settings::RefreshMetadata()
{
emit MetadataRefreshRequested();
@@ -75,6 +75,7 @@ class Settings final : public QObject
QString GetDefaultGame() const;
void SetDefaultGame(QString path);
void RefreshGameList();
void NotifyRefreshGameListComplete();
void RefreshMetadata();
void NotifyMetadataRefreshComplete();
void ReloadTitleDB();
@@ -150,6 +151,7 @@ class Settings final : public QObject
void PathRemoved(const QString&);
void DefaultGameChanged(const QString&);
void GameListRefreshRequested();
void GameListRefreshCompleted();
void TitleDBReloadRequested();
void MetadataRefreshRequested();
void MetadataRefreshCompleted();
@@ -32,20 +32,23 @@ ToolBar::ToolBar(QWidget* parent) : QToolBar(parent)
connect(&Settings::Instance(), &Settings::ThemeChanged, this, &ToolBar::UpdateIcons);
UpdateIcons();

connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
connect(&Settings::Instance(), &Settings::EmulationStateChanged,
[this](Core::State state) { OnEmulationStateChanged(state); });

connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this,
connect(Host::GetInstance(), &Host::UpdateDisasmDialog,
[this] { OnEmulationStateChanged(Core::GetState()); });

connect(&Settings::Instance(), &Settings::DebugModeToggled, this, &ToolBar::OnDebugModeToggled);

connect(&Settings::Instance(), &Settings::ToolBarVisibilityChanged, this, &ToolBar::setVisible);
connect(this, &ToolBar::visibilityChanged, &Settings::Instance(), &Settings::SetToolBarVisible);

connect(&Settings::Instance(), &Settings::WidgetLockChanged, this,
connect(&Settings::Instance(), &Settings::WidgetLockChanged,
[this](bool locked) { setMovable(!locked); });

connect(&Settings::Instance(), &Settings::GameListRefreshCompleted,
[this] { m_refresh_action->setEnabled(true); });

OnEmulationStateChanged(Core::GetState());
OnDebugModeToggled(Settings::Instance().IsDebugModeEnabled());
}
@@ -109,7 +112,10 @@ void ToolBar::MakeActions()
m_set_pc_action = addAction(tr("Set PC"), this, &ToolBar::SetPCPressed);

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();

0 comments on commit 68694e0

Please sign in to comment.
You can’t perform that action at this time.