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
14class KJob;
15
16namespace KIO
17{
18class OpenOrExecuteFileInterfacePrivate;
19
20/*!
21 * \class KIO::OpenOrExecuteFileInterface
22 * \inheaderfile KIO/OpenOrExecuteFileInterface
23 * \inmodule KIOGui
24 *
25 * \brief The OpenOrExecuteFileInterface class allows OpenUrlJob to ask
26 * the user about how to handle various types of executable files, basically
27 * whether to run/execute the file, or in the case of text-based ones (shell
28 * scripts and .desktop files) open them as text.
29 *
30 * This extension mechanism for jobs is similar to KIO::JobUiDelegateExtension,
31 * OpenWithHandlerInterface and UntrustedProgramHandlerInterface.
32 *
33 * \since 5.73
34 */
35class KIOGUI_EXPORT OpenOrExecuteFileInterface : public QObject
36{
37 Q_OBJECT
38protected:
39 /*!
40 * Constructor
41 */
42 explicit OpenOrExecuteFileInterface(QObject *parent = nullptr);
43
44 ~OpenOrExecuteFileInterface() override;
45
46public:
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 * \a job the job calling this. This is useful if you need to
53 * get any of its properties
54 *
55 * \a mimetype the MIME type of the file being handled
56 *
57 * Implementations of this method must emit either executeFile or canceled.
58 *
59 * The default implementation in this base class simply emits canceled().
60 * Any application using KIO::JobUiDelegate (from KIOWidgets) will benefit
61 * from an automatically registered subclass which implements this method,
62 * which in turn uses ExecutableFileOpenDialog (from KIOWidgets).
63 */
64 virtual void promptUserOpenOrExecute(KJob *job, const QString &mimetype);
65
66Q_SIGNALS:
67 /*!
68 * Emitted by promptUserOpenOrExecute() once the user chooses an action.
69 *
70 * \a enable \c true if the user selected to execute/run the file or
71 * \c false if the user selected to open the file as text (the latter is
72 * only valid for shell scripts and .desktop files)
73 */
74 void executeFile(bool enable);
75
76 /*!
77 * Emitted by promptUserOpenOrExecute() if user selects cancel.
78 */
79 void canceled();
80
81private:
82 QScopedPointer<OpenOrExecuteFileInterfacePrivate> d;
83};
84
85}
86
87#endif // OPENOREXECUTEFILEINTERFACE_H
88

source code of kio/src/gui/openorexecutefileinterface.h