File indexing completed on 2025-01-19 03:41:34
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2020 Ahmad Samir <a.samirh78@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #ifndef OPENOREXECUTEFILEINTERFACE_H 0009 #define OPENOREXECUTEFILEINTERFACE_H 0010 0011 #include <QObject> 0012 #include <kiogui_export.h> 0013 0014 class KJob; 0015 0016 namespace KIO 0017 { 0018 class OpenOrExecuteFileInterfacePrivate; 0019 0020 /** 0021 * @class OpenOrExecuteFileInterface openorexecutefileinterface.h <KIO/OpenOrExecuteFileInterface> 0022 * @brief The OpenOrExecuteFileInterface class allows OpenUrlJob to ask 0023 * the user about how to handle various types of executable files, basically 0024 * whether to run/execute the file, or in the case of text-based ones (shell 0025 * scripts and .desktop files) open them as text. 0026 * 0027 * This extension mechanism for jobs is similar to KIO::JobUiDelegateExtension, 0028 * OpenWithHandlerInterface and UntrustedProgramHandlerInterface. 0029 * 0030 * @since 5.73 0031 */ 0032 class KIOGUI_EXPORT OpenOrExecuteFileInterface : public QObject 0033 { 0034 Q_OBJECT 0035 protected: 0036 /** 0037 * Constructor 0038 */ 0039 explicit OpenOrExecuteFileInterface(QObject *parent = nullptr); 0040 0041 /** 0042 * Destructor 0043 */ 0044 ~OpenOrExecuteFileInterface() override; 0045 0046 public: 0047 /** 0048 * Show a dialog to ask the user how to handle various types of executable 0049 * files, basically whether to run/execute the file, or in the case of text-based 0050 * ones (shell scripts and .desktop files) open them as text. 0051 * 0052 * @param job the job calling this. This is useful if you need to 0053 * get any of its properties 0054 * @param mimetype the MIME type of the file being handled 0055 * 0056 * Implementations of this method must emit either executeFile or canceled. 0057 * 0058 * The default implementation in this base class simply emits canceled(). 0059 * Any application using KIO::JobUiDelegate (from KIOWidgets) will benefit 0060 * from an automatically registered subclass which implements this method, 0061 * which in turn uses ExecutableFileOpenDialog (from KIOWidgets). 0062 */ 0063 virtual void promptUserOpenOrExecute(KJob *job, const QString &mimetype); 0064 0065 Q_SIGNALS: 0066 /** 0067 * Emitted by promptUserOpenOrExecute() once the user chooses an action. 0068 * @param enable \c true if the user selected to execute/run the file or 0069 * \c false if the user selected to open the file as text (the latter is 0070 * only valid for shell scripts and .desktop files) 0071 */ 0072 void executeFile(bool enable); 0073 0074 /** 0075 * Emitted by promptUserOpenOrExecute() if user selects cancel. 0076 */ 0077 void canceled(); 0078 0079 private: 0080 QScopedPointer<OpenOrExecuteFileInterfacePrivate> d; 0081 }; 0082 0083 } 0084 0085 #endif // OPENOREXECUTEFILEINTERFACE_H