1/* This file is part of the KDE libraries
2 Copyright (C) 2000 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#ifndef OPENWITHDIALOG_H
21#define OPENWITHDIALOG_H
22
23#include <kio/kio_export.h>
24
25#include <kdialog.h>
26#include <kurl.h>
27#include <kservice.h>
28
29class KOpenWithDialogPrivate;
30
31/**
32 * "Open With" dialog box.
33 *
34 * @note To let the user choose an application and run it immediately,
35 * use simpler KRun::displayOpenWithDialog().
36 *
37 * @author David Faure <faure@kde.org>
38 */
39class KIO_EXPORT KOpenWithDialog : public KDialog
40{
41 Q_OBJECT
42public:
43
44 /**
45 * Create a dialog that asks for a application to open a given
46 * URL(s) with.
47 *
48 * @param urls the URLs that should be opened. The list can be empty,
49 * if the dialog is used to choose an application but not for some particular URLs.
50 * @param parent parent widget
51 */
52 explicit KOpenWithDialog(const KUrl::List &urls, QWidget *parent = 0);
53
54 /**
55 * Create a dialog that asks for a application to open a given
56 * URL(s) with.
57 *
58 * @param urls is the URL that should be opened
59 * @param text appears as a label on top of the entry box.
60 * @param value is the initial value of the line
61 * @param parent parent widget
62 */
63 KOpenWithDialog( const KUrl::List& urls, const QString& text, const QString& value,
64 QWidget *parent = 0 );
65
66 /**
67 * Create a dialog to select a service for a given mimetype.
68 * Note that this dialog doesn't apply to URLs.
69 *
70 * @param mimeType the mime type we want to choose an application for.
71 * @param value is the initial value of the line
72 * @param parent parent widget
73 */
74 KOpenWithDialog( const QString& mimeType, const QString& value,
75 QWidget *parent = 0 );
76
77 /**
78 * Create a dialog to select an application
79 * Note that this dialog doesn't apply to URLs.
80 *
81 * @param parent parent widget
82 */
83 KOpenWithDialog( QWidget *parent = 0 );
84
85 /**
86 * Destructor
87 */
88 ~KOpenWithDialog();
89
90 /**
91 * @return the text the user entered
92 */
93 QString text() const;
94 /**
95 * Hide the "Do not &close when command exits" Checkbox
96 */
97 void hideNoCloseOnExit();
98 /**
99 * Hide the "Run in &terminal" Checkbox
100 */
101 void hideRunInTerminal();
102 /**
103 * @return the chosen service in the application tree
104 * Can be null, if the user typed some text and didn't select a service.
105 */
106 KService::Ptr service() const;
107 /**
108 * Set whether a new .desktop file should be created if the user selects an
109 * application for which no corresponding .desktop file can be found.
110 *
111 * Regardless of this setting a new .desktop file may still be created if
112 * the user has chosen to remember the file association.
113 *
114 * The default is false: no .desktop files are created.
115 */
116 void setSaveNewApplications(bool b);
117
118public Q_SLOTS: // TODO KDE5: move all those slots to the private class!
119 void slotSelected( const QString&_name, const QString& _exec );
120 void slotHighlighted( const QString& _name, const QString& _exec );
121 void slotTextChanged();
122 void slotTerminalToggled(bool);
123
124protected Q_SLOTS:
125 /**
126 * Reimplemented from QDialog::accept()
127 */
128 virtual void accept();
129
130private:
131 friend class KOpenWithDialogPrivate;
132 KOpenWithDialogPrivate* const d;
133
134 Q_DISABLE_COPY(KOpenWithDialog)
135
136 Q_PRIVATE_SLOT(d, void _k_slotDbClick())
137 Q_PRIVATE_SLOT(d, void _k_slotFileSelected())
138};
139
140#endif
141