1/*
2 SPDX-FileCopyrightText: 2012 Sebastian Kügler <sebas@kde.org>
3 SPDX-FileCopyrightText: 2023 Alexander Lohnau <alexander.lohnau@gmx.de>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KPACKAGE_PACKAGEJOB_H
9#define KPACKAGE_PACKAGEJOB_H
10
11#include <kpackage/package_export.h>
12
13#include <KJob>
14#include <memory>
15
16namespace KPackage
17{
18class PackageJobPrivate;
19class Package;
20class PackageStructure;
21
22/**
23 * @class PackageJob kpackage/packagejob.h <KPackage/PackageJob>
24 * @short KJob subclass that allows async install/update/uninstall operations for packages
25 */
26class KPACKAGE_EXPORT PackageJob : public KJob
27{
28 Q_OBJECT
29
30public:
31 /**
32 * Error codes for the install/update/remove jobs
33 */
34 enum JobError {
35 InvalidPackageStructure = KJob::UserDefinedError + 1, /**< Could not find/load the given package structure */
36 RootCreationError, /**< Cannot create package root directory */
37 PackageFileNotFoundError, /**< The package file does not exist */
38 UnsupportedArchiveFormatError, /**< The archive format of the package is not supported */
39 PackageOpenError, /**< Can't open the package file for reading */
40 PluginIdInvalidError, /**< The plugin id is not specified in the metadata.json file or contains
41 characters different from letters, digits, dots and underscores */
42 UpdatePackageTypeMismatchError, /**< A package with this plugin id was already installed, but has a different type in the metadata.json file */
43 OldVersionRemovalError, /**< Failed to remove the old version of the package during an upgrade */
44 NewerVersionAlreadyInstalledError, /**< We tried to update, but the same version or a newer one is already installed */
45 PackageAlreadyInstalledError, /**< The package is already installed and a normal install (not update) was performed */
46 PackageMoveError, /**< Failure to move a package from the system temporary folder to its final destination */
47 PackageCopyError, /**< Failure to copy a package folder from somewhere in the filesystem to its final destination */
48 PackageUninstallError, /**< Failure to uninstall a package */
49 };
50
51 ~PackageJob() override;
52 /// Installs the given package. The returned job is already started
53 static PackageJob *install(const QString &packageFormat, const QString &sourcePackage, const QString &packageRoot = QString());
54 /// Installs the given package. The returned job is already started
55 static PackageJob *update(const QString &packageFormat, const QString &sourcePackage, const QString &packageRoot = QString());
56 /// Installs the given package. The returned job is already started
57 static PackageJob *uninstall(const QString &packageFormat, const QString &pluginId, const QString &packageRoot = QString());
58
59 KPackage::Package package() const;
60
61private:
62 friend class PackageJobThread;
63 enum OperationType {
64 Install,
65 Update,
66 Uninstall,
67 };
68 void start() override;
69
70 KPACKAGE_NO_EXPORT explicit PackageJob(OperationType type, const Package &package, const QString &src, const QString &dest);
71 KPACKAGE_NO_EXPORT void setupNotificationsOnJobFinished(const QString &messageName);
72
73 const std::unique_ptr<PackageJobPrivate> d;
74 friend PackageJobPrivate;
75};
76
77}
78
79#endif
80

source code of kpackage/src/kpackage/packagejob.h