File indexing completed on 2024-05-12 15:43:56

0001 /*
0002     SPDX-FileCopyrightText: 2020 Dan Leinir Turthra Jensen <admin@leinir.dk>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #ifndef KPACKAGEJOB_H
0008 #define KPACKAGEJOB_H
0009 
0010 #include <KJob>
0011 
0012 namespace KNSCore
0013 {
0014 class KPackageJobPrivate;
0015 /**
0016  * @brief A job for performing basic actions on KPackage packages asynchronously
0017  *
0018  * The internals of KPackage's Package functions are synchronous, which makes it easy to work with in some cases,
0019  * but has the unfortunate side effect of blocking the UI. This job will perform those operations in a separate
0020  * thread, which allows you to perform the work in a fire-and-forget fashion (as suggested by KJob's documentation).
0021  *
0022  * @since 5.71
0023  */
0024 class KPackageJob : public KJob
0025 {
0026     Q_OBJECT
0027 public:
0028     /**
0029      * Create a job for installing the given package into the package root, and treat it as the given service type.
0030      *
0031      * @param sourcePackage The full path name to the package you wish to install (e.g. /tmp/downloaded-archive.tar.xz)
0032      * @param packageRoot The full path name to the location the package should be installed into (e.g. /home/username/.share/plasma/desktoptheme/)
0033      * @param serviceType The name of the type of KPackage you intend to install (e.g. Plasma/Theme)
0034      * @return A job which you can use to track the completion of the process (there will be useful details in error() and errorText() on failures)
0035      */
0036     static KPackageJob *install(const QString &sourcePackage, const QString &packageRoot, const QString &serviceType);
0037     /**
0038      * Create a job for updating the given package, or installing it if it is not already, the given package into the
0039      * package root, and treat it as the given service type.
0040      *
0041      * @param sourcePackage The full path name to the package you wish to update (e.g. /tmp/downloaded-archive.tar.xz)
0042      * @param packageRoot The full path name to the location the package should be installed into (e.g. /home/username/.share/plasma/desktoptheme/)
0043      * @param serviceType The name of the type of KPackage you intend to update (e.g. Plasma/Theme)
0044      * @return A job which you can use to track the completion of the process (there will be useful details in error() and errorText() on failures)
0045      */
0046     static KPackageJob *update(const QString &sourcePackage, const QString &packageRoot, const QString &serviceType);
0047     /**
0048      * Create a job for removing the given installed package
0049      *
0050      * @param packageName The name to the package you wish to remove (this is the plugin name, not the full path name, e.g. The.Package.Name)
0051      * @param packageRoot The full path name to the location the package is currently installed (e.g.
0052      * /home/username/.share/plasma/desktoptheme/The.Package.Name)
0053      * @param serviceType The name of the type of KPackage you intend to remove (e.g. Plasma/Theme)
0054      * @return A job which you can use to track the completion of the process (there will be useful details in error() and errorText() on failures)
0055      */
0056     static KPackageJob *uninstall(const QString &packageName, const QString &packageRoot, const QString &serviceType);
0057 
0058     ~KPackageJob() override;
0059 
0060     /**
0061      * Start the process asynchronously
0062      * @see KJob::start()
0063      */
0064     Q_SLOT void start() override;
0065 
0066 private:
0067     explicit KPackageJob(QObject *parent = nullptr);
0068     const std::unique_ptr<KPackageJobPrivate> d;
0069 };
0070 
0071 }
0072 
0073 #endif // KPACKAGEJOB_H