Skip to content
Permalink
Browse files

Merge pull request #7848 from jordan-woyak/config-change-callbacks

Common/Config: Add a utility class to defer config change callbacks.
  • Loading branch information...
lioncash committed Mar 3, 2019
2 parents 2eb9140 + bbc6bf5 commit 503b96c617997ccd2105481f6833e583b9905991
@@ -12,6 +12,7 @@ namespace Config
{
static Layers s_layers;
static std::list<ConfigChangedCallback> s_callbacks;
static u32 s_callback_guards = 0;

Layers* GetLayers()
{
@@ -53,6 +54,9 @@ void AddConfigChangedCallback(ConfigChangedCallback func)

void InvokeConfigChangedCallbacks()
{
if (s_callback_guards)
return;

for (const auto& callback : s_callbacks)
callback();
}
@@ -137,4 +141,18 @@ LayerType GetActiveLayerForConfig(const ConfigLocation& config)
// If config is not present in any layer, base layer is considered active.
return LayerType::Base;
}

ConfigChangeCallbackGuard::ConfigChangeCallbackGuard()
{
++s_callback_guards;
}

ConfigChangeCallbackGuard::~ConfigChangeCallbackGuard()
{
if (--s_callback_guards)
return;

InvokeConfigChangedCallbacks();
}

} // namespace Config
@@ -96,4 +96,15 @@ void SetBaseOrCurrent(const ConfigInfo<T>& info, const std::common_type_t<T>& va
else
Set<T>(LayerType::CurrentRun, info, value);
}
}

// Used to defer InvokeConfigChangedCallbacks until after the completion of many config changes.
class ConfigChangeCallbackGuard
{
public:
ConfigChangeCallbackGuard();
~ConfigChangeCallbackGuard();

ConfigChangeCallbackGuard(const ConfigChangeCallbackGuard&) = delete;
ConfigChangeCallbackGuard& operator=(const ConfigChangeCallbackGuard&) = delete;
};
} // namespace Config
@@ -173,6 +173,8 @@ LogManager::~LogManager()

void LogManager::SaveSettings()
{
Config::ConfigChangeCallbackGuard config_guard;

Config::SetBaseOrCurrent(LOGGER_WRITE_TO_FILE, IsListenerEnabled(LogListener::FILE_LISTENER));
Config::SetBaseOrCurrent(LOGGER_WRITE_TO_CONSOLE,
IsListenerEnabled(LogListener::CONSOLE_LISTENER));
@@ -1008,6 +1008,8 @@ std::shared_ptr<const UICommon::GameFile> NetPlayDialog::FindGameFile(const std:

void NetPlayDialog::SaveSettings()
{
Config::ConfigChangeCallbackGuard config_guard;

if (m_host_input_authority)
{
if (!IsHosting())
@@ -203,6 +203,8 @@ void NetPlaySetupDialog::ConnectWidgets()

void NetPlaySetupDialog::SaveSettings()
{
Config::ConfigChangeCallbackGuard config_guard;

Config::SetBaseOrCurrent(Config::NETPLAY_NICKNAME, m_nickname_edit->text().toStdString());
Config::SetBaseOrCurrent(m_connection_type->currentIndex() == 0 ? Config::NETPLAY_ADDRESS :
Config::NETPLAY_HOST_CODE,
@@ -332,6 +332,8 @@ void GameCubePane::LoadSettings()

void GameCubePane::SaveSettings()
{
Config::ConfigChangeCallbackGuard config_guard;

SConfig& params = SConfig::GetInstance();

// IPL Settings
@@ -282,6 +282,8 @@ static QString UpdateTrackFromIndex(int index)

void GeneralPane::OnSaveConfig()
{
Config::ConfigChangeCallbackGuard config_guard;

auto& settings = SConfig::GetInstance();
if (AutoUpdateChecker::SystemSupportsAutoUpdates())
{
@@ -221,6 +221,8 @@ void WiiPane::LoadConfig()

void WiiPane::OnSaveConfig()
{
Config::ConfigChangeCallbackGuard config_guard;

Config::SetBase(Config::SYSCONF_SCREENSAVER, m_screensaver_checkbox->isChecked());
Config::SetBase(Config::SYSCONF_PAL60, m_pal60_mode_checkbox->isChecked());
Settings::Instance().SetUSBKeyboardConnected(m_connect_keyboard_checkbox->isChecked());

0 comments on commit 503b96c

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