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 KPackage::PackageJob
24 * \inheaderfile KPackage/PackageJob
25 * \inmodule KPackage
26 *
27 * \brief KJob subclass that allows async install/update/uninstall operations for packages.
28 */
29class KPACKAGE_EXPORT PackageJob : public KJob
30{
31 Q_OBJECT
32
33public:
34 /*!
35 * Error codes for the install/update/remove jobs
36 *
37 * \value InvalidPackageStructure Could not find/load the given package structure
38 * \value RootCreationError Cannot create package root directory
39 * \value PackageFileNotFoundError The package file does not exist
40 * \value UnsupportedArchiveFormatError The archive format of the package is not supported
41 * \value PackageOpenError Can't open the package file for reading
42 * \value PluginIdInvalidError The plugin id is not specified in the metadata.json file or contains characters different from letters, digits, dots and
43 * underscores
44 * \value UpdatePackageTypeMismatchError A package with this plugin id was already installed, but has a different type in the metadata.json file
45 * \value OldVersionRemovalError Failed to remove the old version of the package during an upgrade
46 * \value NewerVersionAlreadyInstalledError We tried to update, but the same version or a newer one is already installed
47 * \value PackageAlreadyInstalledError The package is already installed and a normal install (not update) was performed
48 * \value PackageMoveError Failure to move a package from the system temporary folder to its final destination
49 * \value PackageCopyError Failure to copy a package folder from somewhere in the filesystem to its final destination
50 * \value PackageUninstallError Failure to uninstall a package
51 */
52 enum JobError {
53 InvalidPackageStructure = KJob::UserDefinedError + 1,
54 RootCreationError,
55 PackageFileNotFoundError,
56 UnsupportedArchiveFormatError,
57 PackageOpenError,
58 PluginIdInvalidError,
59 UpdatePackageTypeMismatchError,
60 OldVersionRemovalError,
61 NewerVersionAlreadyInstalledError,
62 PackageAlreadyInstalledError,
63 PackageMoveError,
64 PackageCopyError,
65 PackageUninstallError,
66 };
67
68 ~PackageJob() override;
69 /*!
70 * Installs the given package. The returned job is already started
71 */
72 static PackageJob *install(const QString &packageFormat, const QString &sourcePackage, const QString &packageRoot = QString());
73 /*!
74 * Installs the given package. The returned job is already started
75 */
76 static PackageJob *update(const QString &packageFormat, const QString &sourcePackage, const QString &packageRoot = QString());
77 /*!
78 * Installs the given package. The returned job is already started
79 */
80 static PackageJob *uninstall(const QString &packageFormat, const QString &pluginId, const QString &packageRoot = QString());
81
82 /*!
83 *
84 */
85 KPackage::Package package() const;
86
87private:
88 friend class PackageJobThread;
89 enum OperationType {
90 Install,
91 Update,
92 Uninstall,
93 };
94 void start() override;
95
96 KPACKAGE_NO_EXPORT explicit PackageJob(OperationType type, const Package &package, const QString &src, const QString &dest);
97 KPACKAGE_NO_EXPORT void setupNotificationsOnJobFinished(const QString &messageName);
98
99 const std::unique_ptr<PackageJobPrivate> d;
100 friend PackageJobPrivate;
101};
102
103}
104
105#endif
106

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