2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2024 Felix Ernst <felixernst@kde.org>
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
8 #ifndef dolphinpackageinstaller_H
9 #define dolphinpackageinstaller_H
11 #include "config-dolphin.h"
14 #include <PackageKit/Transaction>
21 * @brief A KJob providing simple means to install a package.
23 class DolphinPackageInstaller
: public KJob
27 * @brief Installs a system package.
29 * @param packageName A name that can be resolved to a package.
30 * @param fallBackInstallationPageUrl This url will be opened if Dolphin was installed without the PackageKit library. A good choice for this parameter
31 * is an appstream url that will be opened in a software store like Discover
32 * e.g. "appstream://org.kde.filelight.desktop". The user is then expected to install the package themselves and
33 * KJob::result() will be emitted when it is detected that the installation finished successfully.
34 * @param isPackageInstalledCheck A function that can be regularly checked to determine if the installation was already successful.
36 explicit DolphinPackageInstaller(const QString
&packageName
,
37 const QUrl
&fallBackInstallationPageUrl
,
38 std::function
<bool()> isPackageInstalledCheck
,
39 QObject
*parent
= nullptr);
43 * Make sure to connect to the KJob::result() signal and show the KJob::errorString() to users there before calling this.
45 void start() override
;
47 /** @see KJob::errorString(). */
48 inline QString
errorString() const override
54 /** @see KJob::errorString(). */
55 inline void setErrorString(const QString
&errorString
)
57 m_errorString
= errorString
;
62 * Asynchronously installs a package uniquely identified by its @param packageId using PackageKit.
63 * For progress reporting this method will use DolphinPackageInstaller::connectTransactionToJobProgress().
64 * This method will call KJob::emitResult() once it failed or succeeded.
66 void install(const QString
&packageId
);
69 * Makes sure progress signals of @p transaction are forwarded to KJob's progress signals.
71 void connectTransactionToJobProgress(const PackageKit::Transaction
&transaction
);
74 /** Creates a nice user-facing error message from its parameters and then finishes this job with an @p error. */
75 void slotInstallationFailed(PackageKit::Transaction::Error error
, const QString
&details
);
79 /** The name of the package that is supposed to be installed. */
80 const QString m_packageName
;
82 /** @see DolphinPackageInstaller::DolphinPackageInstaller(). */
83 const QUrl m_fallBackInstallationPageUrl
;
85 /** @see DolphinPackageInstaller::DolphinPackageInstaller(). */
86 const std::function
<bool()> m_isPackageInstalledCheck
;
88 /** @see KJob::errorString(). */
89 QString m_errorString
;
92 #endif // dolphinpackageinstaller_H