From ae2337aff63933e9620e5d009effaa6b762e3f38 Mon Sep 17 00:00:00 2001 From: Sleepy Flower Girl Date: Thu, 31 May 2018 22:54:15 -0400 Subject: [PATCH] Add option to disable Discord Presence in Qt UI --- Source/Core/DolphinQt2/Settings.cpp | 20 +++++++++++++++++++ Source/Core/DolphinQt2/Settings.h | 3 +++ .../Core/DolphinQt2/Settings/GeneralPane.cpp | 15 ++++++++++++++ Source/Core/DolphinQt2/Settings/GeneralPane.h | 3 +++ Source/Core/UICommon/DiscordPresence.cpp | 1 + 5 files changed, 42 insertions(+) diff --git a/Source/Core/DolphinQt2/Settings.cpp b/Source/Core/DolphinQt2/Settings.cpp index b0f8869a6f..9da03cbc2f 100644 --- a/Source/Core/DolphinQt2/Settings.cpp +++ b/Source/Core/DolphinQt2/Settings.cpp @@ -19,6 +19,10 @@ #include "DolphinQt2/Settings.h" #include "InputCommon/InputConfig.h" +#ifdef USE_DISCORD_PRESENCE +#include "UICommon/DiscordPresence.h" +#endif + Settings::Settings() { qRegisterMetaType(); @@ -476,3 +480,19 @@ void Settings::SetBatchModeEnabled(bool batch) { m_batch = batch; } + +#ifdef USE_DISCORD_PRESENCE +void Settings::SetDiscordPresenceEnabled(bool enabled) +{ + if (SConfig::GetInstance().bUseDiscordPresence == enabled) + return; + + if (SConfig::GetInstance().bUseDiscordPresence) + Discord::Shutdown(); + + SConfig::GetInstance().bUseDiscordPresence = enabled; + + if (SConfig::GetInstance().bUseDiscordPresence) + Discord::Init(); +} +#endif diff --git a/Source/Core/DolphinQt2/Settings.h b/Source/Core/DolphinQt2/Settings.h index 606f4ba9b6..d8c833e105 100644 --- a/Source/Core/DolphinQt2/Settings.h +++ b/Source/Core/DolphinQt2/Settings.h @@ -127,6 +127,9 @@ public: // Other GameListModel* GetGameListModel() const; +#ifdef USE_DISCORD_PRESENCE + void SetDiscordPresenceEnabled(bool enabled); +#endif signals: void ConfigChanged(); void EmulationStateChanged(Core::State new_state); diff --git a/Source/Core/DolphinQt2/Settings/GeneralPane.cpp b/Source/Core/DolphinQt2/Settings/GeneralPane.cpp index ecc091db23..273859af7a 100644 --- a/Source/Core/DolphinQt2/Settings/GeneralPane.cpp +++ b/Source/Core/DolphinQt2/Settings/GeneralPane.cpp @@ -85,6 +85,9 @@ void GeneralPane::ConnectLayout() { connect(m_checkbox_dualcore, &QCheckBox::toggled, this, &GeneralPane::OnSaveConfig); connect(m_checkbox_cheats, &QCheckBox::toggled, this, &GeneralPane::OnSaveConfig); +#ifdef USE_DISCORD_PRESENCE + connect(m_checkbox_discord_presence, &QCheckBox::toggled, this, &GeneralPane::OnSaveConfig); +#endif if (AutoUpdateChecker::SystemSupportsAutoUpdates()) { @@ -123,6 +126,11 @@ void GeneralPane::CreateBasic() m_checkbox_cheats = new QCheckBox(tr("Enable Cheats")); basic_group_layout->addWidget(m_checkbox_cheats); +#ifdef USE_DISCORD_PRESENCE + m_checkbox_discord_presence = new QCheckBox(tr("Show Activity in Your Discord Status")); + basic_group_layout->addWidget(m_checkbox_discord_presence); +#endif + auto* speed_limit_layout = new QFormLayout; basic_group_layout->addLayout(speed_limit_layout); @@ -215,6 +223,9 @@ void GeneralPane::LoadConfig() #endif m_checkbox_dualcore->setChecked(SConfig::GetInstance().bCPUThread); m_checkbox_cheats->setChecked(Settings::Instance().GetCheatsEnabled()); +#ifdef USE_DISCORD_PRESENCE + m_checkbox_discord_presence->setChecked(SConfig::GetInstance().bUseDiscordPresence); +#endif int selection = qRound(SConfig::GetInstance().m_EmulationSpeed * 10); if (selection < m_combobox_speedlimit->count()) m_combobox_speedlimit->setCurrentIndex(selection); @@ -260,6 +271,10 @@ void GeneralPane::OnSaveConfig() UpdateTrackFromIndex(m_combobox_update_track->currentIndex())); } +#ifdef USE_DISCORD_PRESENCE + Settings::Instance().SetDiscordPresenceEnabled(m_checkbox_discord_presence->isChecked()); +#endif + #if defined(USE_ANALYTICS) && USE_ANALYTICS Settings::Instance().SetAnalyticsEnabled(m_checkbox_enable_analytics->isChecked()); #endif diff --git a/Source/Core/DolphinQt2/Settings/GeneralPane.h b/Source/Core/DolphinQt2/Settings/GeneralPane.h index d98cb76c16..90d53838e7 100644 --- a/Source/Core/DolphinQt2/Settings/GeneralPane.h +++ b/Source/Core/DolphinQt2/Settings/GeneralPane.h @@ -44,6 +44,9 @@ private: QComboBox* m_combobox_update_track; QCheckBox* m_checkbox_dualcore; QCheckBox* m_checkbox_cheats; +#ifdef USE_DISCORD_PRESENCE + QCheckBox* m_checkbox_discord_presence; +#endif QLabel* m_label_speedlimit; std::vector m_cpu_cores; diff --git a/Source/Core/UICommon/DiscordPresence.cpp b/Source/Core/UICommon/DiscordPresence.cpp index a7bc6f7209..4a8280ed7a 100644 --- a/Source/Core/UICommon/DiscordPresence.cpp +++ b/Source/Core/UICommon/DiscordPresence.cpp @@ -51,6 +51,7 @@ void Shutdown() if (!SConfig::GetInstance().bUseDiscordPresence) return; + Discord_ClearPresence(); Discord_Shutdown(); #endif }