[plasma/union] src: Create and expose an instance of PackageHandler in StyleRegistry

Arjen Hiemstra <[email protected]> Wed, 5 Aug 2026 10:33:23 +0000 (UTC)
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 94cb7ddf096ca43107265ddbe32796cb1479b3e1 by Arjen Hiemstra.
Committed on 05/08/2026 at 10:24.
Pushed by ahiemstra into branch 'master'.

Create and expose an instance of PackageHandler in StyleRegistry

This slightly changes startup by always loading the platform plugin,
then creating an instance of PackageHandler and passing it the platform
plugin.

M  +18   -7    src/StyleRegistry.cpp
M  +4    -2    src/StyleRegistry.h

https://invent.kde.org/plasma/union/-/commit/94cb7ddf096ca43107265ddbe32796cb1479b3e1

diff --git a/src/StyleRegistry.cpp b/src/StyleRegistry.cpp
index 3ff634e8..5e5d43ee 100644
--- a/src/StyleRegistry.cpp
+++ b/src/StyleRegistry.cpp
@@ -10,6 +10,7 @@
 #include <QPluginLoader>
 #include <QThread>
 
+#include "PackageHandler.h"
 #include "PluginRegistry.h"
 #include "Style.h"
 #include "StyleCache_p.h"
@@ -20,6 +21,8 @@
 using namespace Union;
 using namespace Qt::StringLiterals;
 
+namespace fs = std::filesystem;
+
 // This is implements the most minimal of PlatformPlugin that can be used as a
 // fallback if we have no existing platform plugin for the current platform.
 class FallbackPlatformPlugin : public PlatformPlugin
@@ -139,16 +142,21 @@ public:
 
     std::shared_ptr<PluginRegistry<PlatformPlugin>> platformRegistry;
     std::shared_ptr<PlatformPlugin> platform;
+
+    std::shared_ptr<PackageHandler> packageHandler;
 };
 
-StyleRegistry::StyleRegistry(std::unique_ptr<StyleRegistryPrivate> &&d)
+StyleRegistry::StyleRegistry(std::unique_ptr<StyleRegistryPrivate> &&_d)
     : QObject(nullptr)
-    , d(std::move(d))
+    , d(std::move(_d))
 {
     // Ensure we execute cleanup during QCoreApplication shutdown instead of
     // static variable cleanup so that any resources that require a valid
     // application are handled properly.
     qAddPostRoutine(StyleRegistry::cleanup);
+
+    d->loadPlatform();
+    d->packageHandler = std::make_shared<PackageHandler>(d->platform);
 }
 
 StyleRegistry::~StyleRegistry() = default;
@@ -229,15 +237,16 @@ void Union::StyleRegistry::addStyle(const std::shared_ptr<Style> &style)
     d->styles.insert(styleId, style);
 }
 
-std::shared_ptr<PlatformPlugin> Union::StyleRegistry::platform() const
+std::shared_ptr<PlatformPlugin> StyleRegistry::platform() const
 {
-    if (!d->platform) {
-        d->loadPlatform();
-    }
-
     return d->platform;
 }
 
+std::shared_ptr<PackageHandler> StyleRegistry::packageHandler() const
+{
+    return d->packageHandler;
+}
+
 void StyleRegistry::cleanup()
 {
     auto instance = StyleRegistry::instance();
@@ -246,6 +255,8 @@ void StyleRegistry::cleanup()
 
     instance->d->styles.clear();
 
+    instance->d->packageHandler.reset();
+
     instance->d->platform.reset();
     instance->d->platformRegistry.reset();
 }
diff --git a/src/StyleRegistry.h b/src/StyleRegistry.h
index 85f7697e..b4082598 100644
--- a/src/StyleRegistry.h
+++ b/src/StyleRegistry.h
@@ -14,7 +14,7 @@
 
 namespace Union
 {
-
+class PackageHandler;
 class Style;
 class StyleRegistryPrivate;
 
@@ -34,7 +34,7 @@ class UNION_EXPORT StyleRegistry : public QObject
     Q_OBJECT
 
 public:
-    StyleRegistry(std::unique_ptr<StyleRegistryPrivate> &&d);
+    StyleRegistry(std::unique_ptr<StyleRegistryPrivate> &&_d);
     ~StyleRegistry() override;
 
     /*!
@@ -73,6 +73,8 @@ public:
      * Returns the platform integration plugin for the current platform.
      */
     std::shared_ptr<PlatformPlugin> platform() const;
+
+    std::shared_ptr<PackageHandler> packageHandler() const;
     /*!
      * Returns the global instance of StyleRegistry.
      */