File indexing completed on 2025-01-12 06:42:03
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 PluginIdInvalidError, /**< The plugin id is not specified in the metadata.json file or contains 0041 characters different from letters, digits, dots and underscores */ 0042 UpdatePackageTypeMismatchError, /**< A package with this plugin id was already installed, but has a different type in the metadata.json file */ 0043 OldVersionRemovalError, /**< Failed to remove the old version of the package during an upgrade */ 0044 NewerVersionAlreadyInstalledError, /**< We tried to update, but the same version or a newer one is already installed */ 0045 PackageAlreadyInstalledError, /**< The package is already installed and a normal install (not update) was performed */ 0046 PackageMoveError, /**< Failure to move a package from the system temporary folder to its final destination */ 0047 PackageCopyError, /**< Failure to copy a package folder from somewhere in the filesystem to its final destination */ 0048 PackageUninstallError, /**< Failure to uninstall a package */ 0049 }; 0050 0051 ~PackageJob() override; 0052 /// Installs the given package. The returned job is already started 0053 static PackageJob *install(const QString &packageFormat, const QString &sourcePackage, const QString &packageRoot = QString()); 0054 /// Installs the given package. The returned job is already started 0055 static PackageJob *update(const QString &packageFormat, const QString &sourcePackage, const QString &packageRoot = QString()); 0056 /// Installs the given package. The returned job is already started 0057 static PackageJob *uninstall(const QString &packageFormat, const QString &pluginId, const QString &packageRoot = QString()); 0058 0059 KPackage::Package package() const; 0060 0061 private: 0062 friend class PackageJobThread; 0063 enum OperationType { 0064 Install, 0065 Update, 0066 Uninstall, 0067 }; 0068 void start() override; 0069 0070 KPACKAGE_NO_EXPORT explicit PackageJob(OperationType type, const Package &package, const QString &src, const QString &dest); 0071 KPACKAGE_NO_EXPORT void setupNotificationsOnJobFinished(const QString &messageName); 0072 0073 const std::unique_ptr<PackageJobPrivate> d; 0074 friend PackageJobPrivate; 0075 }; 0076 0077 } 0078 0079 #endif