File indexing completed on 2023-11-26 10:45:17

0001 /*
0002     SPDX-FileCopyrightText: 2012 Sebastian K├╝gler <sebas@kde.org>
0003     SPDX-FileCopyrightText: 2023 Alexander Lohnau <alexander.lohnau@gmx.de>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KPACKAGE_PACKAGEJOB_H
0009 #define KPACKAGE_PACKAGEJOB_H
0010 
0011 #include <kpackage/package_export.h>
0012 
0013 #include <KJob>
0014 #include <memory>
0015 
0016 namespace KPackage
0017 {
0018 class PackageJobPrivate;
0019 class Package;
0020 class PackageStructure;
0021 
0022 /**
0023  * @class PackageJob kpackage/packagejob.h <KPackage/PackageJob>
0024  * @short KJob subclass that allows async install/update/uninstall operations for packages
0025  */
0026 class KPACKAGE_EXPORT PackageJob : public KJob
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     /**
0032      * Error codes for the install/update/remove jobs
0033      */
0034     enum JobError {
0035         InvalidPackageStructure = KJob::UserDefinedError + 1, /**< Could not find/load the given package structure */
0036         RootCreationError, /**< Cannot create package root directory */
0037         PackageFileNotFoundError, /**< The package file does not exist */
0038         UnsupportedArchiveFormatError, /**< The archive format of the package is not supported */
0039         PackageOpenError, /**< Can't open the package file for reading */
0040         MetadataFileMissingError, /**< The package doesn't have a metadata.json file */
0041         PluginIdInvalidError, /**< The plugin id is not specified in the metadata.json file or contains
0042                                     characters different from letters, digits, dots and underscores */
0043         UpdatePackageTypeMismatchError, /**< A package with this plugin id was already installed, but has a different type in the metadata.json file */
0044         OldVersionRemovalError, /**< Failed to remove the old version of the package during an upgrade */
0045         NewerVersionAlreadyInstalledError, /**< We tried to update, but the same version or a newer one is already installed */
0046         PackageAlreadyInstalledError, /**< The package is already installed and a normal install (not update) was performed */
0047         PackageMoveError, /**< Failure to move a package from the system temporary folder to its final destination */
0048         PackageCopyError, /**< Failure to copy a package folder from somewhere in the filesystem to its final destination */
0049         PackageUninstallError, /**< Failure to uninstall a package */
0050     };
0051 
0052     ~PackageJob() override;
0053     /// Installs the given package. The returned job is already started
0054     static PackageJob *install(const QString &packageFormat, const QString &sourcePackage, const QString &packageRoot = QString());
0055     /// Installs the given package. The returned job is already started
0056     static PackageJob *update(const QString &packageFormat, const QString &sourcePackage, const QString &packageRoot = QString());
0057     /// Installs the given package. The returned job is already started
0058     static PackageJob *uninstall(const QString &packageFormat, const QString &pluginId, const QString &packageRoot = QString());
0059 
0060     KPackage::Package package() const;
0061 
0062 private:
0063     friend class PackageJobThread;
0064     enum OperationType {
0065         Install,
0066         Update,
0067         Uninstall,
0068     };
0069     void start() override;
0070 
0071     KPACKAGE_NO_EXPORT explicit PackageJob(OperationType type, const Package &package, const QString &src, const QString &dest);
0072     KPACKAGE_NO_EXPORT void setupNotificationsOnJobFinished(const QString &messageName);
0073 
0074     const std::unique_ptr<PackageJobPrivate> d;
0075     friend PackageJobPrivate;
0076 };
0077 
0078 }
0079 
0080 #endif