~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/qt3support/dialogs/q3filedialog.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the Qt 3 compatibility classes of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#ifndef Q3FILEDIALOG_H
 
30
#define Q3FILEDIALOG_H
 
31
 
 
32
class QAbstractButton;
 
33
class QPushButton;
 
34
class QLabel;
 
35
class QWidget;
 
36
class QFileDialog;
 
37
class QTimer;
 
38
class Q3NetworkOperation;
 
39
class QLineEdit;
 
40
class Q3ListViewItem;
 
41
class Q3ListBoxItem;
 
42
class Q3FileDialogPrivate;
 
43
class Q3FileDialogQFileListView;
 
44
 
 
45
#include "QtCore/qdir.h"
 
46
#include "QtGui/qdialog.h"
 
47
#include "Qt3Support/q3urloperator.h"
 
48
#include "Qt3Support/q3valuelist.h"
 
49
#include "QtNetwork/qurlinfo.h"
 
50
 
 
51
#ifndef QT_NO_FILEDIALOG
 
52
 
 
53
class Q_COMPAT_EXPORT Q3FileIconProvider : public QObject
 
54
{
 
55
    Q_OBJECT
 
56
public:
 
57
    Q3FileIconProvider(QObject * parent = 0, const char* name = 0);
 
58
    virtual const QPixmap * pixmap(const QFileInfo &);
 
59
 
 
60
private:
 
61
    Q_DISABLE_COPY(Q3FileIconProvider)
 
62
};
 
63
 
 
64
class Q_COMPAT_EXPORT Q3FilePreview
 
65
{
 
66
public:
 
67
    Q3FilePreview();
 
68
    virtual ~Q3FilePreview() {}
 
69
    virtual void previewUrl(const Q3Url &url) = 0;
 
70
 
 
71
};
 
72
 
 
73
class Q_COMPAT_EXPORT Q3FileDialog : public QDialog
 
74
{
 
75
    Q_OBJECT
 
76
    Q_ENUMS(Mode ViewMode PreviewMode)
 
77
    // ##### Why are this read-only properties ?
 
78
    Q_PROPERTY(QString selectedFile READ selectedFile)
 
79
    Q_PROPERTY(QString selectedFilter READ selectedFilter)
 
80
    Q_PROPERTY(QStringList selectedFiles READ selectedFiles)
 
81
    // #### Should not we be able to set the path ?
 
82
    Q_PROPERTY(QString dirPath READ dirPath)
 
83
    Q_PROPERTY(bool showHiddenFiles READ showHiddenFiles WRITE setShowHiddenFiles)
 
84
    Q_PROPERTY(Mode mode READ mode WRITE setMode)
 
85
    Q_PROPERTY(ViewMode viewMode READ viewMode WRITE setViewMode)
 
86
    Q_PROPERTY(PreviewMode previewMode READ previewMode WRITE setPreviewMode)
 
87
    Q_PROPERTY(bool infoPreview READ isInfoPreviewEnabled WRITE setInfoPreviewEnabled)
 
88
    Q_PROPERTY(bool contentsPreview READ isContentsPreviewEnabled WRITE setContentsPreviewEnabled)
 
89
 
 
90
public:
 
91
    Q3FileDialog(const QString& dirName, const QString& filter = QString(),
 
92
                 QWidget* parent=0, const char* name=0, bool modal = false);
 
93
    Q3FileDialog(QWidget* parent=0, const char* name=0, bool modal = false);
 
94
    ~Q3FileDialog();
 
95
 
 
96
    // recommended static functions
 
97
 
 
98
    static QString getOpenFileName(const QString &initially = QString(),
 
99
                                    const QString &filter = QString(),
 
100
                                    QWidget *parent = 0, const char* name = 0,
 
101
                                    const QString &caption = QString(),
 
102
                                    QString *selectedFilter = 0,
 
103
                                    bool resolveSymlinks = true);
 
104
    static QString getSaveFileName(const QString &initially = QString(),
 
105
                                    const QString &filter = QString(),
 
106
                                    QWidget *parent = 0, const char* name = 0,
 
107
                                    const QString &caption = QString(),
 
108
                                    QString *selectedFilter = 0,
 
109
                                    bool resolveSymlinks = true);
 
110
    static QString getExistingDirectory(const QString &dir = QString(),
 
111
                                         QWidget *parent = 0,
 
112
                                         const char* name = 0,
 
113
                                         const QString &caption = QString(),
 
114
                                         bool dirOnly = true,
 
115
                                         bool resolveSymlinks = true);
 
116
    static QStringList getOpenFileNames(const QString &filter= QString(),
 
117
                                         const QString &dir = QString(),
 
118
                                         QWidget *parent = 0,
 
119
                                         const char* name = 0,
 
120
                                         const QString &caption = QString(),
 
121
                                         QString *selectedFilter = 0,
 
122
                                         bool resolveSymlinks = true);
 
123
 
 
124
    // other static functions
 
125
 
 
126
    static void setIconProvider(Q3FileIconProvider *);
 
127
    static Q3FileIconProvider * iconProvider();
 
128
 
 
129
    // non-static function for special needs
 
130
 
 
131
    QString selectedFile() const;
 
132
    QString selectedFilter() const;
 
133
    virtual void setSelectedFilter(const QString&);
 
134
    virtual void setSelectedFilter(int);
 
135
 
 
136
    void setSelection(const QString &);
 
137
 
 
138
    void selectAll(bool b);
 
139
 
 
140
    QStringList selectedFiles() const;
 
141
 
 
142
    QString dirPath() const;
 
143
 
 
144
    void setDir(const QDir &);
 
145
    const QDir *dir() const;
 
146
 
 
147
    void setShowHiddenFiles(bool s);
 
148
    bool showHiddenFiles() const;
 
149
 
 
150
    void rereadDir();
 
151
    void resortDir();
 
152
 
 
153
    enum Mode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly };
 
154
    void setMode(Mode);
 
155
    Mode mode() const;
 
156
 
 
157
    enum ViewMode { Detail, List };
 
158
    enum PreviewMode { NoPreview, Contents, Info };
 
159
    void setViewMode(ViewMode m);
 
160
    ViewMode viewMode() const;
 
161
    void setPreviewMode(PreviewMode m);
 
162
    PreviewMode previewMode() const;
 
163
 
 
164
    bool eventFilter(QObject *, QEvent *);
 
165
 
 
166
    bool isInfoPreviewEnabled() const;
 
167
    bool isContentsPreviewEnabled() const;
 
168
    void setInfoPreviewEnabled(bool);
 
169
    void setContentsPreviewEnabled(bool);
 
170
 
 
171
    void setInfoPreview(QWidget *w, Q3FilePreview *preview);
 
172
    void setContentsPreview(QWidget *w, Q3FilePreview *preview);
 
173
 
 
174
    Q3Url url() const;
 
175
 
 
176
    void addFilter(const QString &filter);
 
177
 
 
178
public slots:
 
179
    void done(int);
 
180
    void setDir(const QString&);
 
181
    void setUrl(const Q3UrlOperator &url);
 
182
    void setFilter(const QString&);
 
183
    void setFilters(const QString&);
 
184
    void setFilters(const char **);
 
185
    void setFilters(const QStringList&);
 
186
 
 
187
protected:
 
188
    void resizeEvent(QResizeEvent *);
 
189
    void keyPressEvent(QKeyEvent *);
 
190
 
 
191
    void addWidgets(QLabel *, QWidget *, QPushButton *);
 
192
    void addToolButton(QAbstractButton *b, bool separator = false);
 
193
    void addLeftWidget(QWidget *w);
 
194
    void addRightWidget(QWidget *w);
 
195
 
 
196
signals:
 
197
    void fileHighlighted(const QString&);
 
198
    void fileSelected(const QString&);
 
199
    void filesSelected(const QStringList&);
 
200
    void dirEntered(const QString&);
 
201
    void filterSelected(const QString&);
 
202
 
 
203
private slots:
 
204
    void detailViewSelectionChanged();
 
205
    void listBoxSelectionChanged();
 
206
    void changeMode(int);
 
207
    void fileNameEditReturnPressed();
 
208
    void stopCopy();
 
209
    void removeProgressDia();
 
210
 
 
211
    void fileSelected(int);
 
212
    void fileHighlighted(int);
 
213
    void dirSelected(int);
 
214
    void pathSelected(int);
 
215
 
 
216
    void updateFileNameEdit(Q3ListViewItem *);
 
217
    void selectDirectoryOrFile(Q3ListViewItem *);
 
218
    void popupContextMenu(Q3ListViewItem *, const QPoint &, int);
 
219
    void popupContextMenu(Q3ListBoxItem *, const QPoint &);
 
220
    void updateFileNameEdit(Q3ListBoxItem *);
 
221
    void selectDirectoryOrFile(Q3ListBoxItem *);
 
222
    void fileNameEditDone();
 
223
 
 
224
    void okClicked();
 
225
    void filterClicked(); // not used
 
226
    void cancelClicked();
 
227
 
 
228
    void cdUpClicked();
 
229
    void newFolderClicked();
 
230
 
 
231
    void fixupNameEdit();
 
232
 
 
233
    void doMimeTypeLookup();
 
234
 
 
235
    void updateGeometries();
 
236
    void modeButtonsDestroyed();
 
237
    void urlStart(Q3NetworkOperation *op);
 
238
    void urlFinished(Q3NetworkOperation *op);
 
239
    void dataTransferProgress(int bytesDone, int bytesTotal, Q3NetworkOperation *);
 
240
    void insertEntry(const Q3ValueList<QUrlInfo> &fi, Q3NetworkOperation *op);
 
241
    void removeEntry(Q3NetworkOperation *);
 
242
    void createdDirectory(const QUrlInfo &info, Q3NetworkOperation *);
 
243
    void itemChanged(Q3NetworkOperation *);
 
244
    void goBack();
 
245
 
 
246
private:
 
247
    Q_DISABLE_COPY(Q3FileDialog)
 
248
 
 
249
    enum PopupAction {
 
250
        PA_Open = 0,
 
251
        PA_Delete,
 
252
        PA_Rename,
 
253
        PA_SortName,
 
254
        PA_SortSize,
 
255
        PA_SortType,
 
256
        PA_SortDate,
 
257
        PA_SortUnsorted,
 
258
        PA_Cancel,
 
259
        PA_Reload,
 
260
        PA_Hidden
 
261
    };
 
262
 
 
263
    void init();
 
264
    bool trySetSelection(bool isDir, const Q3UrlOperator &, bool);
 
265
    void deleteFile(const QString &filename);
 
266
    void popupContextMenu(const QString &filename, bool withSort,
 
267
                           PopupAction &action, const QPoint &p);
 
268
    void updatePreviews(const Q3Url &u);
 
269
 
 
270
    QString fileName;
 
271
 
 
272
    friend class Q3FileDialogQFileListView;
 
273
    friend class QFileListBox;
 
274
 
 
275
    Q3FileDialogPrivate *d;
 
276
    Q3FileDialogQFileListView  *files;
 
277
 
 
278
    QLineEdit  *nameEdit; // also filter
 
279
    QPushButton *okB;
 
280
    QPushButton *cancelB;
 
281
 
 
282
#if defined(Q_WS_WIN)
 
283
    static QString winGetOpenFileName(const QString &initialSelection,
 
284
                                       const QString &filter,
 
285
                                       QString* workingDirectory,
 
286
                                       QWidget *parent = 0,
 
287
                                       const char* name = 0,
 
288
                                       const QString& caption = QString(),
 
289
                                       QString* selectedFilter = 0);
 
290
    static QString winGetSaveFileName(const QString &initialSelection,
 
291
                                       const QString &filter,
 
292
                                       QString* workingDirectory,
 
293
                                       QWidget *parent = 0,
 
294
                                       const char* name = 0,
 
295
                                       const QString& caption = QString(),
 
296
                                       QString* selectedFilter = 0);
 
297
    static QStringList winGetOpenFileNames(const QString &filter,
 
298
                                            QString* workingDirectory,
 
299
                                            QWidget *parent = 0,
 
300
                                            const char* name = 0,
 
301
                                            const QString& caption = QString(),
 
302
                                            QString* selectedFilter = 0);
 
303
    static QString winGetExistingDirectory(const QString &initialDirectory,
 
304
                                            QWidget* parent = 0,
 
305
                                            const char* name = 0,
 
306
                                            const QString& caption = QString());
 
307
    static QString resolveLinkFile(const QString& linkfile);
 
308
    int old_qt_ntfs_permission_lookup;
 
309
#endif
 
310
#if defined(Q_WS_MAC)
 
311
    static QString macGetSaveFileName(const QString &, const QString &,
 
312
                                       QString *, QWidget *, const char*,
 
313
                                       const QString&, QString *);
 
314
    static QStringList macGetOpenFileNames(const QString &, QString*,
 
315
                                            QWidget *, const char *,
 
316
                                            const QString&, QString *,
 
317
                                            bool = true, bool = false);
 
318
#endif
 
319
};
 
320
 
 
321
#endif
 
322
 
 
323
#endif // Q3FILEDIALOG_H