From 6dd777763cfa6247e847e93b1a20d154ec6c4529 Mon Sep 17 00:00:00 2001 From: enen92 <92enen@gmail.com> Date: Wed, 31 Jul 2019 10:50:04 +0100 Subject: [PATCH 1/2] [GUIControllerWindow] Subscribe to controller install events --- .../windows/GUIControllerWindow.cpp | 18 ++++++++++++++++++ .../controllers/windows/GUIControllerWindow.h | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/xbmc/games/controllers/windows/GUIControllerWindow.cpp b/xbmc/games/controllers/windows/GUIControllerWindow.cpp index afab9e26f6c93..21d787a8a0a31 100644 --- a/xbmc/games/controllers/windows/GUIControllerWindow.cpp +++ b/xbmc/games/controllers/windows/GUIControllerWindow.cpp @@ -189,10 +189,27 @@ void CGUIControllerWindow::OnEvent(const ADDON::CRepositoryUpdater::RepositoryUp UpdateButtons(); } +void CGUIControllerWindow::OnEvent(const ADDON::AddonEvent& event) +{ + using namespace ADDON; + + if (typeid(event) == typeid(AddonEvents::Enabled) || // also called on install, + typeid(event) == typeid(AddonEvents::Disabled) || // not called on uninstall + typeid(event) == typeid(AddonEvents::UnInstalled) || + typeid(event) == typeid(AddonEvents::ReInstalled)) + { + if (CServiceBroker::GetAddonMgr().HasType(event.id, ADDON_GAME_CONTROLLER)) + { + UpdateButtons(); + } + } +} + void CGUIControllerWindow::OnInitWindow(void) { // subscribe to events CServiceBroker::GetRepositoryUpdater().Events().Subscribe(this, &CGUIControllerWindow::OnEvent); + CServiceBroker::GetAddonMgr().Events().Subscribe(this, &CGUIControllerWindow::OnEvent); // Get active game add-on GameClientPtr gameClient; { @@ -241,6 +258,7 @@ void CGUIControllerWindow::OnInitWindow(void) void CGUIControllerWindow::OnDeinitWindow(int nextWindowID) { CServiceBroker::GetRepositoryUpdater().Events().Unsubscribe(this); + CServiceBroker::GetAddonMgr().Events().Unsubscribe(this); if (m_controllerList) { diff --git a/xbmc/games/controllers/windows/GUIControllerWindow.h b/xbmc/games/controllers/windows/GUIControllerWindow.h index 72fdbf1e7a0c1..a6cfcb262a031 100644 --- a/xbmc/games/controllers/windows/GUIControllerWindow.h +++ b/xbmc/games/controllers/windows/GUIControllerWindow.h @@ -42,9 +42,12 @@ namespace GAME void OnControllerSelected(unsigned int controllerIndex); void OnFeatureFocused(unsigned int featureIndex); void OnFeatureSelected(unsigned int featureIndex); - void OnEvent(const ADDON::CRepositoryUpdater::RepositoryUpdated& event); void UpdateButtons(void); + // Callbacks for events + void OnEvent(const ADDON::CRepositoryUpdater::RepositoryUpdated& event); + void OnEvent(const ADDON::AddonEvent& event); + // Action for the available button void GetMoreControllers(void); void GetAllControllers(); From c60767c5a6ebaa1a1bf4f891a3806fb3ff717230 Mon Sep 17 00:00:00 2001 From: enen92 <92enen@gmail.com> Date: Thu, 1 Aug 2019 11:31:57 +0100 Subject: [PATCH 2/2] [GUIControllerWindow] Subscribe to events at the end of initialization --- xbmc/games/controllers/windows/GUIControllerWindow.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xbmc/games/controllers/windows/GUIControllerWindow.cpp b/xbmc/games/controllers/windows/GUIControllerWindow.cpp index 21d787a8a0a31..2e225bdf28063 100644 --- a/xbmc/games/controllers/windows/GUIControllerWindow.cpp +++ b/xbmc/games/controllers/windows/GUIControllerWindow.cpp @@ -207,9 +207,6 @@ void CGUIControllerWindow::OnEvent(const ADDON::AddonEvent& event) void CGUIControllerWindow::OnInitWindow(void) { - // subscribe to events - CServiceBroker::GetRepositoryUpdater().Events().Subscribe(this, &CGUIControllerWindow::OnEvent); - CServiceBroker::GetAddonMgr().Events().Subscribe(this, &CGUIControllerWindow::OnEvent); // Get active game add-on GameClientPtr gameClient; { @@ -253,6 +250,10 @@ void CGUIControllerWindow::OnInitWindow(void) CServiceBroker::GetPeripherals().EnableButtonMapping(); UpdateButtons(); + + // subscribe to events + CServiceBroker::GetRepositoryUpdater().Events().Subscribe(this, &CGUIControllerWindow::OnEvent); + CServiceBroker::GetAddonMgr().Events().Subscribe(this, &CGUIControllerWindow::OnEvent); } void CGUIControllerWindow::OnDeinitWindow(int nextWindowID)