1 /*
2     This file is part of the KDE libraries
3     SPDX-FileCopyrightText: 2020 Ahmad Samir <a.samirh78@gmail.com>
4 
5     SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7 
8 #ifndef OPENOREXECUTEFILEINTERFACE_H
9 #define OPENOREXECUTEFILEINTERFACE_H
10 
11 #include <QObject>
12 #include <kiogui_export.h>
13 
14 class KJob;
15 
16 namespace KIO
17 {
18 class OpenOrExecuteFileInterfacePrivate;
19 
20 /**
21  * @class OpenOrExecuteFileInterface openorexecutefileinterface.h <KIO/OpenOrExecuteFileInterface>
22  * @brief The OpenOrExecuteFileInterface class allows OpenUrlJob to ask
23  * the user about how to handle various types of executable files, basically
24  * whether to run/execute the file, or in the case of text-based ones (shell
25  * scripts and .desktop files) open them as text.
26  *
27  * This extension mechanism for jobs is similar to KIO::JobUiDelegateExtension,
28  * OpenWithHandlerInterface and UntrustedProgramHandlerInterface.
29  *
30  * @since 5.73
31  */
32 class KIOGUI_EXPORT OpenOrExecuteFileInterface : public QObject
33 {
34     Q_OBJECT
35 protected:
36     /**
37      * Constructor
38      */
39     explicit OpenOrExecuteFileInterface(QObject *parent = nullptr);
40 
41     /**
42      * Destructor
43      */
44     ~OpenOrExecuteFileInterface() override;
45 
46 public:
47     /**
48      * Show a dialog to ask the user how to handle various types of executable
49      * files, basically whether to run/execute the file, or in the case of text-based
50      * ones (shell scripts and .desktop files) open them as text.
51      *
52      * @param job the job calling this. This is useful if you need to
53      * get any of its properties
54      * @param mimetype the MIME type of the file being handled
55      *
56      * Implementations of this method must emit either executeFile or canceled.
57      *
58      * The default implementation in this base class simply emits canceled().
59      * Any application using KIO::JobUiDelegate (from KIOWidgets) will benefit
60      * from an automatically registered subclass which implements this method,
61      * which in turn uses ExecutableFileOpenDialog (from KIOWidgets).
62      */
63     virtual void promptUserOpenOrExecute(KJob *job, const QString &mimetype);
64 
65 Q_SIGNALS:
66     /**
67      * Emitted by promptUserOpenOrExecute() once the user chooses an action.
68      * @param enable \c true if the user selected to execute/run the file or
69      * \c false if the user selected to open the file as text (the latter is
70      * only valid for shell scripts and .desktop files)
71      */
72     void executeFile(bool enable);
73 
74     /**
75      * Emitted by promptUserOpenOrExecute() if user selects cancel.
76      */
77     void canceled();
78 
79 private:
80     QScopedPointer<OpenOrExecuteFileInterfacePrivate> d;
81 };
82 
83 }
84 
85 #endif // OPENOREXECUTEFILEINTERFACE_H
86