aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorenen92 <92enen@gmail.com>2024-10-14 11:57:22 +0100
committerenen92 <92enen@gmail.com>2024-10-14 17:08:00 +0100
commita6c001fa1882dfe722179e50240586a2cc6203e8 (patch)
tree4d1f1e0e9da2ee50925a4a8b31434d1314469f2e
parent5e098e7ed111df083fbf26c52f6f0bd0bc4c6c7a (diff)
[GUI] Introduce GUI Announcement Handlers
-rw-r--r--cmake/treedata/common/subdirs.txt1
-rw-r--r--xbmc/guilib/GUIComponent.cpp4
-rw-r--r--xbmc/guilib/GUIComponent.h2
-rw-r--r--xbmc/guilib/handlers/CMakeLists.txt7
-rw-r--r--xbmc/guilib/handlers/GUIAnnouncementHandlerContainer.cpp16
-rw-r--r--xbmc/guilib/handlers/GUIAnnouncementHandlerContainer.h29
-rw-r--r--xbmc/guilib/handlers/sources/GUISourcesAnnouncementHandler.cpp42
-rw-r--r--xbmc/guilib/handlers/sources/GUISourcesAnnouncementHandler.h26
-rw-r--r--xbmc/interfaces/IAnnouncer.h44
-rw-r--r--xbmc/network/upnp/UPnP.cpp21
10 files changed, 157 insertions, 35 deletions
diff --git a/cmake/treedata/common/subdirs.txt b/cmake/treedata/common/subdirs.txt
index 00bd9396e5..f4e46076fb 100644
--- a/cmake/treedata/common/subdirs.txt
+++ b/cmake/treedata/common/subdirs.txt
@@ -16,6 +16,7 @@ xbmc/dialogs dialogs
xbmc/favourites favourites
xbmc/guilib guilib
xbmc/guilib/guiinfo guilib_guiinfo
+xbmc/guilib/handlers guilib_announcement_handlers
xbmc/guilib/listproviders guilib_listproviders
xbmc/imagefiles imagefiles
xbmc/messaging messaging
diff --git a/xbmc/guilib/GUIComponent.cpp b/xbmc/guilib/GUIComponent.cpp
index 5c8b414fd8..449a85d073 100644
--- a/xbmc/guilib/GUIComponent.cpp
+++ b/xbmc/guilib/GUIComponent.cpp
@@ -18,6 +18,7 @@
#include "TextureManager.h"
#include "URL.h"
#include "dialogs/GUIDialogYesNo.h"
+#include "handlers/GUIAnnouncementHandlerContainer.h"
#include <memory>
@@ -28,7 +29,8 @@ CGUIComponent::CGUIComponent()
m_stereoscopicsManager(std::make_unique<CStereoscopicsManager>()),
m_guiInfoManager(std::make_unique<CGUIInfoManager>()),
m_guiColorManager(std::make_unique<CGUIColorManager>()),
- m_guiAudioManager(std::make_unique<CGUIAudioManager>())
+ m_guiAudioManager(std::make_unique<CGUIAudioManager>()),
+ m_announcementHandlerContainer(std::make_unique<CGUIAnnouncementHandlerContainer>())
{
}
diff --git a/xbmc/guilib/GUIComponent.h b/xbmc/guilib/GUIComponent.h
index b7eb75c58a..2e3e7aadff 100644
--- a/xbmc/guilib/GUIComponent.h
+++ b/xbmc/guilib/GUIComponent.h
@@ -18,6 +18,7 @@ class CStereoscopicsManager;
class CGUIInfoManager;
class CGUIColorManager;
class CGUIAudioManager;
+class CGUIAnnouncementHandlerContainer;
class CGUIComponent
{
@@ -47,4 +48,5 @@ protected:
std::unique_ptr<CGUIInfoManager> m_guiInfoManager;
std::unique_ptr<CGUIColorManager> m_guiColorManager;
std::unique_ptr<CGUIAudioManager> m_guiAudioManager;
+ std::unique_ptr<CGUIAnnouncementHandlerContainer> m_announcementHandlerContainer;
};
diff --git a/xbmc/guilib/handlers/CMakeLists.txt b/xbmc/guilib/handlers/CMakeLists.txt
new file mode 100644
index 0000000000..fc052e35df
--- /dev/null
+++ b/xbmc/guilib/handlers/CMakeLists.txt
@@ -0,0 +1,7 @@
+set(SOURCES GUIAnnouncementHandlerContainer.cpp
+ sources/GUISourcesAnnouncementHandler.cpp)
+
+set(HEADERS GUIAnnouncementHandlerContainer.h
+ sources/GUISourcesAnnouncementHandler.h)
+
+core_add_library(guilib_announcement_handlers)
diff --git a/xbmc/guilib/handlers/GUIAnnouncementHandlerContainer.cpp b/xbmc/guilib/handlers/GUIAnnouncementHandlerContainer.cpp
new file mode 100644
index 0000000000..f7a5fbae4a
--- /dev/null
+++ b/xbmc/guilib/handlers/GUIAnnouncementHandlerContainer.cpp
@@ -0,0 +1,16 @@
+/*
+ * Copyright (C) 2024 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "GUIAnnouncementHandlerContainer.h"
+
+#include "sources/GUISourcesAnnouncementHandler.h"
+
+CGUIAnnouncementHandlerContainer::CGUIAnnouncementHandlerContainer()
+{
+ m_announcementHandlers.emplace_back(std::make_unique<CGUISourcesAnnouncementHandler>());
+}
diff --git a/xbmc/guilib/handlers/GUIAnnouncementHandlerContainer.h b/xbmc/guilib/handlers/GUIAnnouncementHandlerContainer.h
new file mode 100644
index 0000000000..40122c5dbb
--- /dev/null
+++ b/xbmc/guilib/handlers/GUIAnnouncementHandlerContainer.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2024 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+#include "interfaces/IAnnouncer.h"
+
+#include <memory>
+#include <vector>
+
+/*!
+\brief This class is a container of announcement handlers per application component. It allows the GUI Layer
+to execute GUI Actions upon receiving announcements from other components effectively decoupling GUI
+from other components.
+*/
+class CGUIAnnouncementHandlerContainer final
+{
+public:
+ CGUIAnnouncementHandlerContainer();
+ ~CGUIAnnouncementHandlerContainer() = default;
+
+private:
+ std::vector<std::unique_ptr<ANNOUNCEMENT::IAnnouncer>> m_announcementHandlers;
+};
diff --git a/xbmc/guilib/handlers/sources/GUISourcesAnnouncementHandler.cpp b/xbmc/guilib/handlers/sources/GUISourcesAnnouncementHandler.cpp
new file mode 100644
index 0000000000..251f0e14ec
--- /dev/null
+++ b/xbmc/guilib/handlers/sources/GUISourcesAnnouncementHandler.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2024 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "GUISourcesAnnouncementHandler.h"
+
+#include "GUIUserMessages.h"
+#include "ServiceBroker.h"
+#include "guilib/GUIComponent.h"
+#include "guilib/GUIWindowManager.h"
+#include "interfaces/AnnouncementManager.h"
+
+CGUISourcesAnnouncementHandler::CGUISourcesAnnouncementHandler()
+{
+ CServiceBroker::GetAnnouncementManager()->AddAnnouncer(this);
+}
+
+CGUISourcesAnnouncementHandler::~CGUISourcesAnnouncementHandler()
+{
+ CServiceBroker::GetAnnouncementManager()->RemoveAnnouncer(this);
+}
+
+void CGUISourcesAnnouncementHandler::Announce(ANNOUNCEMENT::AnnouncementFlag flag,
+ const std::string& sender,
+ const std::string& message,
+ const CVariant& data)
+{
+ // We are only interested in sources changes
+ if ((flag & ANNOUNCEMENT::Sources) == 0)
+ return;
+
+ if (message == "OnAdded" || message == "OnRemoved" || message == "OnUpdated")
+ {
+ CGUIMessage message(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_UPDATE_PATH);
+ message.SetStringParam(data.asString());
+ CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(message);
+ }
+}
diff --git a/xbmc/guilib/handlers/sources/GUISourcesAnnouncementHandler.h b/xbmc/guilib/handlers/sources/GUISourcesAnnouncementHandler.h
new file mode 100644
index 0000000000..0ec166fdf1
--- /dev/null
+++ b/xbmc/guilib/handlers/sources/GUISourcesAnnouncementHandler.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2024 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+#include "interfaces/IAnnouncer.h"
+
+/*!
+\brief Handler for announcements of type sources
+*/
+class CGUISourcesAnnouncementHandler : public ANNOUNCEMENT::IAnnouncer
+{
+public:
+ CGUISourcesAnnouncementHandler();
+ ~CGUISourcesAnnouncementHandler();
+
+ void Announce(ANNOUNCEMENT::AnnouncementFlag flag,
+ const std::string& sender,
+ const std::string& message,
+ const CVariant& data) override;
+};
diff --git a/xbmc/interfaces/IAnnouncer.h b/xbmc/interfaces/IAnnouncer.h
index 7c20203573..513fb25937 100644
--- a/xbmc/interfaces/IAnnouncer.h
+++ b/xbmc/interfaces/IAnnouncer.h
@@ -13,33 +13,35 @@
class CVariant;
namespace ANNOUNCEMENT
{
- enum AnnouncementFlag
- {
- Player = 0x001,
- Playlist = 0x002,
- GUI = 0x004,
- System = 0x008,
- VideoLibrary = 0x010,
- AudioLibrary = 0x020,
- Application = 0x040,
- Input = 0x080,
- PVR = 0x100,
- Other = 0x200,
- Info = 0x400
- };
+enum AnnouncementFlag
+{
+ Player = 0x001,
+ Playlist = 0x002,
+ GUI = 0x004,
+ System = 0x008,
+ VideoLibrary = 0x010,
+ AudioLibrary = 0x020,
+ Application = 0x040,
+ Input = 0x080,
+ PVR = 0x100,
+ Other = 0x200,
+ Info = 0x400,
+ Sources = 0x800
+};
- const auto ANNOUNCE_ALL = (Player | Playlist | GUI | System | VideoLibrary | AudioLibrary | Application | Input | ANNOUNCEMENT::PVR | Other);
+const auto ANNOUNCE_ALL = (Player | Playlist | GUI | System | VideoLibrary | AudioLibrary |
+ Application | Input | ANNOUNCEMENT::PVR | Other);
- /*!
+/*!
\brief Returns a string representation for the
given AnnouncementFlag
\param notification Specific AnnouncementFlag
\return String representation of the given AnnouncementFlag
*/
- inline const char *AnnouncementFlagToString(const AnnouncementFlag &notification)
+inline const char* AnnouncementFlagToString(const AnnouncementFlag& notification)
+{
+ switch (notification)
{
- switch (notification)
- {
case Player:
return "Player";
case Playlist:
@@ -62,10 +64,12 @@ namespace ANNOUNCEMENT
return "Other";
case Info:
return "Info";
+ case Sources:
+ return "Sources";
default:
return "Unknown";
- }
}
+}
class IAnnouncer
{
diff --git a/xbmc/network/upnp/UPnP.cpp b/xbmc/network/upnp/UPnP.cpp
index 2acfc55069..371efbace2 100644
--- a/xbmc/network/upnp/UPnP.cpp
+++ b/xbmc/network/upnp/UPnP.cpp
@@ -13,7 +13,6 @@
#include "UPnP.h"
#include "FileItem.h"
-#include "GUIUserMessages.h"
#include "ServiceBroker.h"
#include "UPnPInternal.h"
#include "UPnPRenderer.h"
@@ -21,8 +20,7 @@
#include "UPnPSettings.h"
#include "URL.h"
#include "cores/playercorefactory/PlayerCoreFactory.h"
-#include "guilib/GUIComponent.h"
-#include "guilib/GUIWindowManager.h"
+#include "interfaces/AnnouncementManager.h"
#include "messaging/ApplicationMessenger.h"
#include "network/Network.h"
#include "profiles/ProfileManager.h"
@@ -171,19 +169,15 @@ public:
// PLT_MediaBrowser methods
bool OnMSAdded(PLT_DeviceDataReference& device) override
{
- CGUIMessage message(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_UPDATE_PATH);
- message.SetStringParam("upnp://");
- CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(message);
+ CServiceBroker::GetAnnouncementManager()->Announce(ANNOUNCEMENT::Sources, "OnAdded",
+ CVariant{"upnp://"});
return PLT_SyncMediaBrowser::OnMSAdded(device);
}
void OnMSRemoved(PLT_DeviceDataReference& device) override
{
- PLT_SyncMediaBrowser::OnMSRemoved(device);
-
- CGUIMessage message(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_UPDATE_PATH);
- message.SetStringParam("upnp://");
- CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(message);
+ CServiceBroker::GetAnnouncementManager()->Announce(ANNOUNCEMENT::Sources, "OnRemoved",
+ CVariant{"upnp://"});
PLT_SyncMediaBrowser::OnMSRemoved(device);
}
@@ -202,9 +196,8 @@ public:
}
m_logger->debug("notified container update {}", (const char*)path);
- CGUIMessage message(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_UPDATE_PATH);
- message.SetStringParam(path.GetChars());
- CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(message);
+ CServiceBroker::GetAnnouncementManager()->Announce(ANNOUNCEMENT::Sources, "OnUpdated",
+ CVariant{path.GetChars()});
}
bool MarkWatched(const CFileItem& item, const bool watched)