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 * @brief The UntrustedProgramHandlerInterface class allows ApplicationLauncherJob to
20 * prompt the user about an untrusted executable or desktop file.
21 * This extension mechanism for jobs is similar to KIO::JobUiDelegateExtension.
22 *
23 * The class also provides helper methods to set the execute bit so that the program
24 * can be started.
25 * @since 5.70
26 */
27class KIOCORE_EXPORT UntrustedProgramHandlerInterface : public QObject
28{
29 Q_OBJECT
30protected:
31 /**
32 * Constructor
33 */
34 explicit UntrustedProgramHandlerInterface(QObject *parent = nullptr);
35
36 /**
37 * Destructor
38 */
39 ~UntrustedProgramHandlerInterface() override;
40
41public:
42 /**
43 * Show a warning to the user about the program not being trusted for execution.
44 * This could be an executable which is not a script and without the execute bit.
45 * Or it could be a desktop file outside the standard locations, without the execute bit.
46 * @param job the job calling this. Useful to get the associated window.
47 * @param programName the full path to the executable or desktop file
48 *
49 * If this function emits result(true), the caller should then call
50 * either setExecuteBit or makeServiceFileExecutable; those helper methods
51 * are provided by this class.
52 *
53 * The default implementation in this base class simply emits result(false).
54 * Any application using KIO::JobUiDelegate (KIOWidgets) will benefit from an
55 * automatically registered subclass which implements this method using QtWidgets.
56 */
57 virtual void showUntrustedProgramWarning(KJob *job, const QString &programName);
58
59 /**
60 * Helper function that attempts to make a desktop file executable.
61 * In addition to the execute bit, this includes fixing its first line to ensure that
62 * it says #!/usr/bin/env xdg-open.
63 * @param fileName the full path to the file
64 * @param errorString output parameter so the method can return an error message
65 * @return true on success, false on error
66 */
67 bool makeServiceFileExecutable(const QString &fileName, QString &errorString);
68
69 /**
70 * Helper function that attempts to set execute bit for given file.
71 * @param fileName the full path to the file
72 * @param errorString output parameter so the method can return an error message
73 * @return true on success, false on error
74 */
75 bool setExecuteBit(const QString &fileName, QString &errorString);
76
77Q_SIGNALS:
78 /**
79 * Implementations of this interface must emit result in showUntrustedProgramWarning.
80 * @param confirmed true if the user confirms running this program, false on cancel
81 */
82 void result(bool confirmed);
83
84private:
85 class Private;
86 Private *const d;
87};
88
89}
90
91#endif // UNTRUSTEDPROGRAMHANDLERINTERFACE_H
92

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