[plasma/union] src: Add an install method to PackageHandler

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

Add an install method to PackageHandler

It will install the package to a platform provided location.

M  +20   -0    src/PackageHandler.cpp
M  +36   -0    src/PackageHandler.h

https://invent.kde.org/plasma/union/-/commit/112da6cad06d681715fd0884772f779b3cd45b62

diff --git a/src/PackageHandler.cpp b/src/PackageHandler.cpp
index 53947f23..490b7861 100644
--- a/src/PackageHandler.cpp
+++ b/src/PackageHandler.cpp
@@ -70,3 +70,23 @@ QList<StylePackage> PackageHandler::allPackages()
 
     return result;
 }
+
+PackageHandler::Error PackageHandler::install(const StylePackage &package)
+{
+    if (!package.isValid()) {
+        return Error::InvalidPackage;
+    }
+
+    auto destination = d->platform->stylePackageInstallPath() / package.path().filename();
+    if (fs::exists(destination)) {
+        return Error::AlreadyInstalled;
+    }
+
+    std::error_code ec;
+    fs::copy(package.path(), destination, fs::copy_options::recursive, ec);
+    if (ec) {
+        return Error::FilesystemError;
+    }
+
+    return Error::None;
+}
diff --git a/src/PackageHandler.h b/src/PackageHandler.h
index 8498184b..c82e7896 100644
--- a/src/PackageHandler.h
+++ b/src/PackageHandler.h
@@ -22,6 +22,30 @@ class PlatformPlugin;
 class UNION_EXPORT PackageHandler
 {
 public:
+    /*!
+     * \enum PackageHandler::Error
+     *
+     * Errors that can occur during a package operation.
+     *
+     * \value None
+     *      No error occurred and the operation was successful.
+     * \value InvalidPackage
+     *      The operation failed because an invalid package was provided.
+     * \value AlreadyInstalled
+     *      The operation failed because the provided package was already
+     *      installed.
+     * \value FilesystemError
+     *      The operation failed because a file system error occurred during the
+     *      operation. Note that this can be anything from insufficient
+     *      permissions to disk failure.
+     */
+    enum class Error {
+        None,
+        InvalidPackage,
+        AlreadyInstalled,
+        FilesystemError,
+    };
+
     PackageHandler(const std::shared_ptr<PlatformPlugin> &platformPlugin);
     ~PackageHandler();
 
@@ -35,6 +59,18 @@ public:
      */
     QList<StylePackage> allPackages();
 
+    /*!
+     * Install a package.
+     *
+     * This will install the package \p package if it is valid by copying the
+     * contents to a platform-specific installation directory. It will return
+     * Error::None if installation was successful. Installation
+     * will fail and return Error::AlreadyInstalled if the package is already
+     * installed. It may also return Error::FilesystemError if any operating
+     * system error occurs.
+     */
+    Error install(const StylePackage &package);
+
 private:
     class Private;
     const std::unique_ptr<Private> d;