File indexing completed on 2024-12-01 09:53:40
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef OPENWITHDIALOG_H 0009 #define OPENWITHDIALOG_H 0010 0011 #include "kiowidgets_export.h" 0012 0013 #include <KService> 0014 #include <QDialog> 0015 #include <QUrl> 0016 0017 class KOpenWithDialogPrivate; 0018 0019 /** 0020 * @class KOpenWithDialog kopenwithdialog.h <KOpenWithDialog> 0021 * 0022 * "Open With" dialog box. 0023 * 0024 * @note To let the user choose an application and run it immediately, 0025 * use simpler KRun::displayOpenWithDialog(). 0026 * 0027 * If the Kiosk "shell_access" action is not authorized (see 0028 * KAuthorized::authorize()), arbitrary commands are not allowed; instead, the 0029 * user must browse to and choose an executable. 0030 * 0031 * @author David Faure <faure@kde.org> 0032 */ 0033 class KIOWIDGETS_EXPORT KOpenWithDialog : public QDialog 0034 { 0035 Q_OBJECT 0036 public: 0037 /** 0038 * Create a dialog that asks for a application to open a given 0039 * URL(s) with. 0040 * 0041 * @param urls the URLs that should be opened. The list can be empty, 0042 * if the dialog is used to choose an application but not for some particular URLs. 0043 * @param parent parent widget 0044 */ 0045 explicit KOpenWithDialog(const QList<QUrl> &urls, QWidget *parent = nullptr); 0046 0047 /** 0048 * Create a dialog that asks for a application to open a given 0049 * URL(s) with. 0050 * 0051 * @param urls is the URL that should be opened 0052 * @param text appears as a label on top of the entry box. Leave empty for default text (since 5.20). 0053 * @param value is the initial value of the line 0054 * @param parent parent widget 0055 */ 0056 KOpenWithDialog(const QList<QUrl> &urls, const QString &text, const QString &value, QWidget *parent = nullptr); 0057 0058 /** 0059 * Create a dialog to select a service for a given MIME type. 0060 * Note that this dialog doesn't apply to URLs. 0061 * 0062 * @param mimeType the MIME type we want to choose an application for. 0063 * @param value is the initial value of the line 0064 * @param parent parent widget 0065 */ 0066 KOpenWithDialog(const QString &mimeType, const QString &value, QWidget *parent = nullptr); 0067 0068 /** 0069 * Create a dialog that asks for a application for opening a given 0070 * URL (or more than one), when we already know the MIME type of the URL(s). 0071 * 0072 * @param urls is the URLs that should be opened 0073 * @param mimeType the MIME type of the URL 0074 * @param text appears as a label on top of the entry box. 0075 * @param value is the initial value of the line 0076 * @param parent parent widget 0077 * @since 5.71 0078 */ 0079 KOpenWithDialog(const QList<QUrl> &urls, const QString &mimeType, const QString &text, const QString &value, QWidget *parent = nullptr); 0080 0081 /** 0082 * Create a dialog to select an application 0083 * Note that this dialog doesn't apply to URLs. 0084 * 0085 * @param parent parent widget 0086 */ 0087 KOpenWithDialog(QWidget *parent = nullptr); 0088 0089 /** 0090 * Destructor 0091 */ 0092 ~KOpenWithDialog() override; 0093 0094 /** 0095 * @return the text the user entered 0096 */ 0097 QString text() const; 0098 /** 0099 * Hide the "Do not &close when command exits" Checkbox 0100 */ 0101 void hideNoCloseOnExit(); 0102 /** 0103 * Hide the "Run in &terminal" Checkbox 0104 */ 0105 void hideRunInTerminal(); 0106 /** 0107 * @return the chosen service in the application tree 0108 * Can be null, if the user typed some text and didn't select a service. 0109 */ 0110 KService::Ptr service() const; 0111 /** 0112 * Set whether a new .desktop file should be created if the user selects an 0113 * application for which no corresponding .desktop file can be found. 0114 * 0115 * Regardless of this setting a new .desktop file may still be created if 0116 * the user has chosen to remember the file association. 0117 * 0118 * The default is false: no .desktop files are created. 0119 */ 0120 void setSaveNewApplications(bool b); 0121 0122 public Q_SLOTS: // TODO KDE5: move all those slots to the private class! 0123 void slotSelected(const QString &_name, const QString &_exec); 0124 void slotHighlighted(const QString &_name, const QString &_exec); 0125 void slotTextChanged(); 0126 void slotTerminalToggled(bool); 0127 0128 protected Q_SLOTS: 0129 /** 0130 * Reimplemented from QDialog::accept() 0131 */ 0132 void accept() override; 0133 0134 private: 0135 bool eventFilter(QObject *object, QEvent *event) override; 0136 0137 friend class KOpenWithDialogPrivate; 0138 std::unique_ptr<KOpenWithDialogPrivate> const d; 0139 0140 Q_DISABLE_COPY(KOpenWithDialog) 0141 }; 0142 0143 #endif