File indexing completed on 2024-09-08 03:38:57
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2020 David Faure <faure@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #ifndef UNTRUSTEDPROGRAMHANDLERINTERFACE_H 0009 #define UNTRUSTEDPROGRAMHANDLERINTERFACE_H 0010 0011 #include <QObject> 0012 #include <kiocore_export.h> 0013 class KJob; 0014 class QString; 0015 0016 namespace KIO 0017 { 0018 /** 0019 * @brief The UntrustedProgramHandlerInterface class allows ApplicationLauncherJob to 0020 * prompt the user about an untrusted executable or desktop file. 0021 * This extension mechanism for jobs is similar to KIO::JobUiDelegateExtension. 0022 * 0023 * The class also provides helper methods to set the execute bit so that the program 0024 * can be started. 0025 * @since 5.70 0026 */ 0027 class KIOCORE_EXPORT UntrustedProgramHandlerInterface : public QObject 0028 { 0029 Q_OBJECT 0030 protected: 0031 /** 0032 * Constructor 0033 */ 0034 explicit UntrustedProgramHandlerInterface(QObject *parent = nullptr); 0035 0036 /** 0037 * Destructor 0038 */ 0039 ~UntrustedProgramHandlerInterface() override; 0040 0041 public: 0042 /** 0043 * Show a warning to the user about the program not being trusted for execution. 0044 * This could be an executable which is not a script and without the execute bit. 0045 * Or it could be a desktop file outside the standard locations, without the execute bit. 0046 * @param job the job calling this. Useful to get the associated window. 0047 * @param programName the full path to the executable or desktop file 0048 * 0049 * If this function emits result(true), the caller should then call 0050 * either setExecuteBit or makeServiceFileExecutable; those helper methods 0051 * are provided by this class. 0052 * 0053 * The default implementation in this base class simply emits result(false). 0054 * Any application using KIO::JobUiDelegate (KIOWidgets) will benefit from an 0055 * automatically registered subclass which implements this method using QtWidgets. 0056 */ 0057 virtual void showUntrustedProgramWarning(KJob *job, const QString &programName); 0058 0059 /** 0060 * Helper function that attempts to make a desktop file executable. 0061 * In addition to the execute bit, this includes fixing its first line to ensure that 0062 * it says #!/usr/bin/env xdg-open. 0063 * @param fileName the full path to the file 0064 * @param errorString output parameter so the method can return an error message 0065 * @return true on success, false on error 0066 */ 0067 bool makeServiceFileExecutable(const QString &fileName, QString &errorString); 0068 0069 /** 0070 * Helper function that attempts to set execute bit for given file. 0071 * @param fileName the full path to the file 0072 * @param errorString output parameter so the method can return an error message 0073 * @return true on success, false on error 0074 */ 0075 bool setExecuteBit(const QString &fileName, QString &errorString); 0076 0077 Q_SIGNALS: 0078 /** 0079 * Implementations of this interface must emit result in showUntrustedProgramWarning. 0080 * @param confirmed true if the user confirms running this program, false on cancel 0081 */ 0082 void result(bool confirmed); 0083 0084 private: 0085 class Private; 0086 Private *const d; 0087 }; 0088 0089 } 0090 0091 #endif // UNTRUSTEDPROGRAMHANDLERINTERFACE_H