summaryrefslogtreecommitdiffstats
path: root/kio/kfile/kurlrequester.h
blob: fa40d065672435da848852130c858ac6fc9a605d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/* This file is part of the KDE libraries
    Copyright (C) 1999,2000,2001 Carsten Pfeiffer <[email protected]>

    library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License version 2, as published by the Free Software Foundation.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/


#ifndef KURLREQUESTER_H
#define KURLREQUESTER_H

#include <tqhbox.h>

#include <keditlistbox.h>
#include <kfile.h>
#include <kpushbutton.h>
#include <kurl.h>

class KComboBox;
class KFileDialog;
class KLineEdit;
class KURLCompletion;
class KURLDragPushButton;

class TQString;
class TQTimer;

/**
 * This class is a widget showing a lineedit and a button, which invokes a
 * filedialog. File name completion is available in the lineedit.
 *
 * The defaults for the filedialog are to ask for one existing local file, i.e.
 * KFileDialog::setMode( KFile::File | KFile::ExistingOnly | KFile::LocalOnly )
 * The default filter is "*", i.e. show all files, and the start directory is
 * the current working directory, or the last directory where a file has been
 * selected.
 *
 * You can change this behavior by using setMode() or setFilter().
 *
 * \image html kurlrequester.png "KDE URL Requester"
 *
 * @short A widget to request a filename/url from the user
 * @author Carsten Pfeiffer <[email protected]>
 */
class KIO_EXPORT KURLRequester : public TQHBox
{
    Q_OBJECT
    Q_PROPERTY( TQString url READ url WRITE setURL )
    Q_PROPERTY( bool showLocalProtocol READ showLocalProtocol WRITE setShowLocalProtocol )
    Q_PROPERTY( TQString filter READ filter WRITE setFilter )
    Q_PROPERTY( uint mode READ mode WRITE setMode )

public:
    /**
     * Constructs a KURLRequester widget.
     */
    KURLRequester( TQWidget *parent=0, const char *name=0 );

    /**
     * Constructs a KURLRequester widget with the initial URL @p url.
     * // TODO KDE4: Use KURL instead
     */
    KURLRequester( const TQString& url, TQWidget *parent=0, const char *name=0 );

    /**
     * Special constructor, which creates a KURLRequester widget with a custom
     * edit-widget. The edit-widget can be either a KComboBox or a KLineEdit
     * (or inherited thereof). Note: for geometry management reasons, the
     * edit-widget is reparented to have the KURLRequester as parent.
     */
    KURLRequester( TQWidget *editWidget, TQWidget *parent, const char *name=0 );
    /**
     * Destructs the KURLRequester.
     */
    ~KURLRequester();

    /**
     * @returns the current url in the lineedit. May be malformed, if the user
     * entered something weird. ~user or environment variables are substituted
     * for local files.
     * // TODO KDE4: Use KURL so that the result is properly defined
     */
    TQString url() const;

    /**
     * Enables/disables showing file:/ in the lineedit, when a local file has
     * been selected in the filedialog or was set via setURL().
     * Default is false, not showing file:/
     * @see showLocalProtocol
     */
    void setShowLocalProtocol( bool b );

    /**
     * Sets the mode of the file dialog.
     * Note: you can only select one file with the filedialog,
     * so KFile::Files doesn't make much sense.
     * @see KFileDialog::setMode()
     */
    void setMode( uint m );

    /**
    * Returns the current mode
    * @see KFileDialog::mode()
    * @since 3.3
    */
    uint mode() const;


    /**
     * Sets the filter for the file dialog.
     * @see KFileDialog::setFilter()
     */
    void setFilter( const TQString& filter );

    /**
    * Returns the current filter for the file dialog.
    * @see KFileDialog::filter()
    * @since 3.3
    */
    TQString filter() const;

    /**
     * @returns whether local files will be prefixed with file:/ in the
     * lineedit
     * @see setShowLocalProtocol
     */
    bool showLocalProtocol() const { return myShowLocalProt; }
    // ## KDE4: there's no reason to keep this, it should always be false

    /**
     * @returns a pointer to the filedialog
     * You can use this to customize the dialog, e.g. to specify a filter.
     * Never returns 0L.
     *
     * Remove in KDE4? KURLRequester should use KDirSelectDialog for
     * (mode & KFile::Directory) && !(mode & KFile::File)
     */
    virtual KFileDialog * fileDialog() const;

    /**
     * @returns a pointer to the lineedit, either the default one, or the
     * special one, if you used the special constructor.
     *
     * It is provided so that you can e.g. set an own completion object
     * (e.g. KShellCompletion) into it.
     */
    KLineEdit * lineEdit() const;

    /**
     * @returns a pointer to the combobox, in case you have set one using the
     * special constructor. Returns 0L otherwise.
     */
    KComboBox * comboBox() const;

    /**
     * @returns a pointer to the pushbutton. It is provided so that you can
     * specify an own pixmap or a text, if you really need to.
     */
    KPushButton * button() const;

    /**
     * @returns the KURLCompletion object used in the lineedit/combobox.
     */
    KURLCompletion *completionObject() const { return myCompletion; }

    /**
     * @returns an object, suitable for use with KEditListBox. It allows you
     * to put this KURLRequester into a KEditListBox.
     * Basically, do it like this:
     * \code
     * KURLRequester *req = new KURLRequester( someWidget );
     * [...]
     * KEditListBox *editListBox = new KEditListBox( i18n("Some Title"), req->customEditor(), someWidget );
     * \endcode
     * @since 3.1
     */
    KEditListBox::CustomEditor customEditor();

public slots:
    /**
     * Sets the url in the lineedit to @p url. Depending on the state of
     * showLocalProtocol(), file:/ on local files will be shown or not.
     * @since 3.1
     * // TODO KDE4: Use KURL instead
     */
    void setURL( const TQString& url );

    /**
     * Sets the url in the lineedit to @p url.
     * @since 3.4
     * // TODO KDE4: rename to setURL
     */
    void setKURL( const KURL& url );

    /**
     * Sets the caption of the file dialog.
     * @since 3.1
     */
    virtual void setCaption( const TQString& caption );

    /**
     * Clears the lineedit/combobox.
     */
    void clear();

signals:
    // forwards from LineEdit
    /**
     * Emitted when the text in the lineedit changes.
     * The parameter contains the contents of the lineedit.
     * @since 3.1
     */
    void textChanged( const TQString& );

    /**
     * Emitted when return or enter was pressed in the lineedit.
     */
    void returnPressed();

    /**
     * Emitted when return or enter was pressed in the lineedit.
     * The parameter contains the contents of the lineedit.
     */
    void returnPressed( const TQString& );

    /**
     * Emitted before the filedialog is going to open. Connect
     * to this signal to "configure" the filedialog, e.g. set the
     * filefilter, the mode, a preview-widget, etc. It's usually
     * not necessary to set a URL for the filedialog, as it will
     * get set properly from the editfield contents.
     *
     * If you use multiple KURLRequesters, you can connect all of them
     * to the same slot and use the given KURLRequester pointer to know
     * which one is going to open.
     */
    void openFileDialog( KURLRequester * );

    /**
     * Emitted when the user changed the URL via the file dialog.
     * The parameter contains the contents of the lineedit.
     * // TODO KDE4: Use KURL instead
     */
    void urlSelected( const TQString& );

protected:
    void		init();

    KURLCompletion *    myCompletion;


private:
    KURLDragPushButton * myButton;
    bool 		myShowLocalProt;
    mutable KFileDialog * myFileDialog;


protected slots:
    /**
     * Called when the button is pressed to open the filedialog.
     * Also called when KStdAccel::Open (default is Ctrl-O) is pressed.
     */
    void slotOpenDialog();

private slots:
    void slotUpdateURL();

protected:
    virtual void virtual_hook( int id, void* data );
    bool eventFilter( TQObject *obj, TQEvent *ev );
private:
    class KURLRequesterPrivate;
    KURLRequesterPrivate *d;
};

/**
 * URL requester with a combo box, for use in Designer
 */
class KIO_EXPORT KURLComboRequester : public KURLRequester
{
    Q_OBJECT
public:
    /**
     * Constructs a KURLRequester widget with a combobox.
     */
    KURLComboRequester( TQWidget *parent=0, const char *name=0 );
};


#endif // KURLREQUESTER_H