1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2020 David Faure <faure@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#ifndef UNTRUSTEDPROGRAMHANDLERINTERFACE_H
9#define UNTRUSTEDPROGRAMHANDLERINTERFACE_H
10
11#include <QObject>
12#include <kiocore_export.h>
13class KJob;
14class QString;
15
16namespace KIO
17{
18/*!
19 * \class KIO::UntrustedProgramHandlerInterface
20 * \inheaderfile KIO/UntrustedProgramHandlerInterface
21 * \inmodule KIOCore
22 *
23 * \brief The UntrustedProgramHandlerInterface class allows ApplicationLauncherJob to
24 * prompt the user about an untrusted executable or desktop file.
25 *
26 * This extension mechanism for jobs is similar to KIO::JobUiDelegateExtension.
27 *
28 * The class also provides helper methods to set the execute bit so that the program
29 * can be started.
30 * \since 5.70
31 */
32class KIOCORE_EXPORT UntrustedProgramHandlerInterface : public QObject
33{
34 Q_OBJECT
35protected:
36 /*!
37 * Constructor
38 */
39 explicit UntrustedProgramHandlerInterface(QObject *parent = nullptr);
40
41 ~UntrustedProgramHandlerInterface() override;
42
43public:
44 /*!
45 * Show a warning to the user about the program not being trusted for execution.
46 * This could be an executable which is not a script and without the execute bit.
47 * Or it could be a desktop file outside the standard locations, without the execute bit.
48 *
49 * \a job the job calling this. Useful to get the associated window.
50 *
51 * \a programName the full path to the executable or desktop file
52 *
53 * If this function emits result(true), the caller should then call
54 * either setExecuteBit or makeServiceFileExecutable; those helper methods
55 * are provided by this class.
56 *
57 * The default implementation in this base class simply emits result(false).
58 * Any application using KIO::JobUiDelegate (KIOWidgets) will benefit from an
59 * automatically registered subclass which implements this method using QtWidgets.
60 */
61 virtual void showUntrustedProgramWarning(KJob *job, const QString &programName);
62
63 /*!
64 * Helper function that attempts to make a desktop file executable.
65 * In addition to the execute bit, this includes fixing its first line to ensure that
66 * it says #!/usr/bin/env xdg-open.
67 *
68 * \a fileName the full path to the file
69 *
70 * \a errorString output parameter so the method can return an error message
71 *
72 * Returns \c true on success, \c false on error
73 */
74 bool makeServiceFileExecutable(const QString &fileName, QString &errorString);
75
76 /*!
77 * Helper function that attempts to set execute bit for given file.
78 *
79 * \a fileName the full path to the file
80 *
81 * \a errorString output parameter so the method can return an error message
82 *
83 * Returns \c true on success, \c false on error
84 */
85 bool setExecuteBit(const QString &fileName, QString &errorString);
86
87Q_SIGNALS:
88 /*!
89 * Implementations of this interface must emit result in showUntrustedProgramWarning.
90 *
91 * \a confirmed \c true if the user confirms running this program, \c false on cancel
92 */
93 void result(bool confirmed);
94
95private:
96 class Private;
97 Private *const d;
98};
99
100}
101
102#endif // UNTRUSTEDPROGRAMHANDLERINTERFACE_H
103

source code of kio/src/core/untrustedprogramhandlerinterface.h