1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef OPENWITHDIALOG_H
9#define OPENWITHDIALOG_H
10
11#include "kiowidgets_export.h"
12
13#include <KService>
14#include <QDialog>
15#include <QUrl>
16
17class KOpenWithDialogPrivate;
18
19/*!
20 * \class KOpenWithDialog
21 * \inmodule KIOWidgets
22 *
23 * \brief "Open With" dialog box.
24 *
25 * \note To let the user choose an application and run it immediately,
26 * use simpler KRun::displayOpenWithDialog().
27 *
28 * If the Kiosk "shell_access" action is not authorized (see
29 * KAuthorized::authorize()), arbitrary commands are not allowed; instead, the
30 * user must browse to and choose an executable.
31 */
32class KIOWIDGETS_EXPORT KOpenWithDialog : public QDialog
33{
34 Q_OBJECT
35public:
36 /*!
37 * Create a dialog that asks for a application to open a given
38 * URL(s) with.
39 *
40 * \a urls the URLs that should be opened. The list can be empty,
41 * if the dialog is used to choose an application but not for some particular URLs.
42 *
43 * \a parent parent widget
44 */
45 explicit KOpenWithDialog(const QList<QUrl> &urls, QWidget *parent = nullptr);
46
47 /*!
48 * Create a dialog that asks for a application to open a given
49 * URL(s) with.
50 *
51 * \a urls is the URL that should be opened
52 *
53 * \a text appears as a label on top of the entry box. Leave empty for default text (since 5.20).
54 *
55 * \a value is the initial value of the line
56 *
57 * \a parent parent widget
58 */
59 KOpenWithDialog(const QList<QUrl> &urls, const QString &text, const QString &value, QWidget *parent = nullptr);
60
61 /*!
62 * Create a dialog to select a service for a given MIME type.
63 * Note that this dialog doesn't apply to URLs.
64 *
65 * \a mimeType the MIME type we want to choose an application for.
66 *
67 * \a value is the initial value of the line
68 *
69 * \a parent parent widget
70 */
71 KOpenWithDialog(const QString &mimeType, const QString &value, QWidget *parent = nullptr);
72
73 /*!
74 * Create a dialog that asks for a application for opening a given
75 * URL (or more than one), when we already know the MIME type of the URL(s).
76 *
77 * \a urls is the URLs that should be opened
78 *
79 * \a mimeType the MIME type of the URL
80 *
81 * \a text appears as a label on top of the entry box.
82 *
83 * \a value is the initial value of the line
84 *
85 * \a parent parent widget
86 *
87 * \since 5.71
88 */
89 KOpenWithDialog(const QList<QUrl> &urls, const QString &mimeType, const QString &text, const QString &value, QWidget *parent = nullptr);
90
91 /*!
92 * Create a dialog to select an application
93 * Note that this dialog doesn't apply to URLs.
94 *
95 * \a parent parent widget
96 */
97 KOpenWithDialog(QWidget *parent = nullptr);
98
99 ~KOpenWithDialog() override;
100
101 /*!
102 * Returns the text the user entered
103 */
104 QString text() const;
105 /*!
106 * Hide the "Do not &close when command exits" Checkbox
107 */
108 void hideNoCloseOnExit();
109 /*!
110 * Hide the "Run in &terminal" Checkbox
111 */
112 void hideRunInTerminal();
113 /*!
114 * Returns the chosen service in the application tree
115 * Can be null, if the user typed some text and didn't select a service.
116 */
117 KService::Ptr service() const;
118 /*!
119 * Set whether a new .desktop file should be created if the user selects an
120 * application for which no corresponding .desktop file can be found.
121 *
122 * Regardless of this setting a new .desktop file may still be created if
123 * the user has chosen to remember the file association.
124 *
125 * The default is false: no .desktop files are created.
126 */
127 void setSaveNewApplications(bool b);
128
129public Q_SLOTS: // TODO KDE5: move all those slots to the private class!
130 void slotSelected(const QString &_name, const QString &_exec);
131 void slotHighlighted(const QString &_name, const QString &_exec);
132 void slotTextChanged();
133 void slotTerminalToggled(bool);
134
135protected Q_SLOTS:
136 void accept() override;
137
138private:
139 bool eventFilter(QObject *object, QEvent *event) override;
140
141 friend class KOpenWithDialogPrivate;
142 std::unique_ptr<KOpenWithDialogPrivate> const d;
143
144 Q_DISABLE_COPY(KOpenWithDialog)
145};
146
147#endif
148

source code of kio/src/widgets/kopenwithdialog.h