1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the QtGui module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | #ifndef QFILEDIALOG_H |
43 | #define QFILEDIALOG_H |
44 | |
45 | #include <QtCore/qdir.h> |
46 | #include <QtCore/qstring.h> |
47 | #include <QtGui/qdialog.h> |
48 | |
49 | QT_BEGIN_HEADER |
50 | |
51 | QT_BEGIN_NAMESPACE |
52 | |
53 | QT_MODULE(Gui) |
54 | |
55 | #ifndef QT_NO_FILEDIALOG |
56 | |
57 | class QModelIndex; |
58 | class QItemSelection; |
59 | struct QFileDialogArgs; |
60 | class QFileIconProvider; |
61 | class QFileDialogPrivate; |
62 | class QAbstractItemDelegate; |
63 | class QAbstractProxyModel; |
64 | class QUrl; |
65 | |
66 | class Q_GUI_EXPORT QFileDialog : public QDialog |
67 | { |
68 | Q_OBJECT |
69 | Q_ENUMS(ViewMode FileMode AcceptMode Option) |
70 | Q_FLAGS(Options) |
71 | Q_PROPERTY(ViewMode viewMode READ viewMode WRITE setViewMode) |
72 | Q_PROPERTY(FileMode fileMode READ fileMode WRITE setFileMode) |
73 | Q_PROPERTY(AcceptMode acceptMode READ acceptMode WRITE setAcceptMode) |
74 | Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly DESIGNABLE false) |
75 | Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks DESIGNABLE false) |
76 | Q_PROPERTY(bool confirmOverwrite READ confirmOverwrite WRITE setConfirmOverwrite DESIGNABLE false) |
77 | Q_PROPERTY(QString defaultSuffix READ defaultSuffix WRITE setDefaultSuffix) |
78 | Q_PROPERTY(bool nameFilterDetailsVisible READ isNameFilterDetailsVisible |
79 | WRITE setNameFilterDetailsVisible DESIGNABLE false) |
80 | Q_PROPERTY(Options options READ options WRITE setOptions) |
81 | |
82 | public: |
83 | enum ViewMode { Detail, List }; |
84 | enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly }; |
85 | enum AcceptMode { AcceptOpen, AcceptSave }; |
86 | enum DialogLabel { LookIn, FileName, FileType, Accept, Reject }; |
87 | |
88 | // ### Rename to FileDialogOption and FileDialogOptions for Qt 5.0 |
89 | enum Option |
90 | { |
91 | ShowDirsOnly = 0x00000001, |
92 | DontResolveSymlinks = 0x00000002, |
93 | DontConfirmOverwrite = 0x00000004, |
94 | DontUseSheet = 0x00000008, |
95 | DontUseNativeDialog = 0x00000010, |
96 | ReadOnly = 0x00000020, |
97 | HideNameFilterDetails = 0x00000040, |
98 | DontUseCustomDirectoryIcons = 0x00000080 |
99 | }; |
100 | Q_DECLARE_FLAGS(Options, Option) |
101 | |
102 | QFileDialog(QWidget *parent, Qt::WindowFlags f); |
103 | explicit QFileDialog(QWidget *parent = 0, |
104 | const QString &caption = QString(), |
105 | const QString &directory = QString(), |
106 | const QString &filter = QString()); |
107 | ~QFileDialog(); |
108 | |
109 | void setDirectory(const QString &directory); |
110 | inline void setDirectory(const QDir &directory); |
111 | QDir directory() const; |
112 | |
113 | void selectFile(const QString &filename); |
114 | QStringList selectedFiles() const; |
115 | |
116 | #ifdef QT_DEPRECATED |
117 | QT_DEPRECATED void setFilter(const QString &filter); |
118 | QT_DEPRECATED void setFilters(const QStringList &filters); |
119 | QT_DEPRECATED QStringList filters() const; |
120 | QT_DEPRECATED void selectFilter(const QString &filter); |
121 | QT_DEPRECATED QString selectedFilter() const; |
122 | #endif |
123 | void setNameFilterDetailsVisible(bool enabled); |
124 | bool isNameFilterDetailsVisible() const; |
125 | |
126 | void setNameFilter(const QString &filter); |
127 | void setNameFilters(const QStringList &filters); |
128 | QStringList nameFilters() const; |
129 | void selectNameFilter(const QString &filter); |
130 | QString selectedNameFilter() const; |
131 | |
132 | QDir::Filters filter() const; |
133 | void setFilter(QDir::Filters filters); |
134 | |
135 | void setViewMode(ViewMode mode); |
136 | ViewMode viewMode() const; |
137 | |
138 | void setFileMode(FileMode mode); |
139 | FileMode fileMode() const; |
140 | |
141 | void setAcceptMode(AcceptMode mode); |
142 | AcceptMode acceptMode() const; |
143 | |
144 | void setReadOnly(bool enabled); |
145 | bool isReadOnly() const; |
146 | |
147 | void setResolveSymlinks(bool enabled); |
148 | bool resolveSymlinks() const; |
149 | |
150 | void (const QList<QUrl> &urls); |
151 | QList<QUrl> () const; |
152 | |
153 | QByteArray saveState() const; |
154 | bool restoreState(const QByteArray &state); |
155 | |
156 | void setConfirmOverwrite(bool enabled); |
157 | bool confirmOverwrite() const; |
158 | |
159 | void setDefaultSuffix(const QString &suffix); |
160 | QString defaultSuffix() const; |
161 | |
162 | void setHistory(const QStringList &paths); |
163 | QStringList history() const; |
164 | |
165 | void setItemDelegate(QAbstractItemDelegate *delegate); |
166 | QAbstractItemDelegate *itemDelegate() const; |
167 | |
168 | void setIconProvider(QFileIconProvider *provider); |
169 | QFileIconProvider *iconProvider() const; |
170 | |
171 | void setLabelText(DialogLabel label, const QString &text); |
172 | QString labelText(DialogLabel label) const; |
173 | |
174 | #ifndef QT_NO_PROXYMODEL |
175 | void setProxyModel(QAbstractProxyModel *model); |
176 | QAbstractProxyModel *proxyModel() const; |
177 | #endif |
178 | |
179 | void setOption(Option option, bool on = true); |
180 | bool testOption(Option option) const; |
181 | void setOptions(Options options); |
182 | Options options() const; |
183 | |
184 | #ifdef Q_NO_USING_KEYWORD |
185 | #ifndef Q_QDOC |
186 | void open() { QDialog::open(); } |
187 | #endif |
188 | #else |
189 | using QDialog::open; |
190 | #endif |
191 | void open(QObject *receiver, const char *member); |
192 | void setVisible(bool visible); |
193 | |
194 | Q_SIGNALS: |
195 | void fileSelected(const QString &file); |
196 | void filesSelected(const QStringList &files); |
197 | void currentChanged(const QString &path); |
198 | void directoryEntered(const QString &directory); |
199 | void filterSelected(const QString &filter); |
200 | |
201 | public: |
202 | #ifdef QT3_SUPPORT |
203 | typedef FileMode Mode; |
204 | inline QT3_SUPPORT void setMode(FileMode m) { setFileMode(m); } |
205 | inline QT3_SUPPORT FileMode mode() const { return fileMode(); } |
206 | inline QT3_SUPPORT void setDir(const QString &directory) { setDirectory(directory); } |
207 | inline QT3_SUPPORT void setDir( const QDir &directory ) { setDirectory(directory); } |
208 | QT3_SUPPORT QString selectedFile() const; |
209 | #endif |
210 | |
211 | static QString getOpenFileName(QWidget *parent = 0, |
212 | const QString &caption = QString(), |
213 | const QString &dir = QString(), |
214 | const QString &filter = QString(), |
215 | QString *selectedFilter = 0, |
216 | Options options = 0); |
217 | |
218 | static QString getSaveFileName(QWidget *parent = 0, |
219 | const QString &caption = QString(), |
220 | const QString &dir = QString(), |
221 | const QString &filter = QString(), |
222 | QString *selectedFilter = 0, |
223 | Options options = 0); |
224 | |
225 | static QString getExistingDirectory(QWidget *parent = 0, |
226 | const QString &caption = QString(), |
227 | const QString &dir = QString(), |
228 | Options options = ShowDirsOnly); |
229 | |
230 | static QStringList getOpenFileNames(QWidget *parent = 0, |
231 | const QString &caption = QString(), |
232 | const QString &dir = QString(), |
233 | const QString &filter = QString(), |
234 | QString *selectedFilter = 0, |
235 | Options options = 0); |
236 | |
237 | #ifdef QT3_SUPPORT |
238 | inline static QString QT3_SUPPORT getOpenFileName(const QString &dir, |
239 | const QString &filter = QString(), |
240 | QWidget *parent = 0, const char* name = 0, |
241 | const QString &caption = QString(), |
242 | QString *selectedFilter = 0, |
243 | bool resolveSymlinks = true) |
244 | { Q_UNUSED(name); |
245 | return getOpenFileName(parent, caption, dir, filter, selectedFilter, |
246 | resolveSymlinks ? Option(0) : DontResolveSymlinks); } |
247 | |
248 | inline static QString QT3_SUPPORT getSaveFileName(const QString &dir, |
249 | const QString &filter = QString(), |
250 | QWidget *parent = 0, const char* name = 0, |
251 | const QString &caption = QString(), |
252 | QString *selectedFilter = 0, |
253 | bool resolveSymlinks = true) |
254 | { Q_UNUSED(name); |
255 | return getSaveFileName(parent, caption, dir, filter, selectedFilter, |
256 | resolveSymlinks ? Option(0) : DontResolveSymlinks); } |
257 | |
258 | inline static QString QT3_SUPPORT getExistingDirectory(const QString &dir, |
259 | QWidget *parent = 0, |
260 | const char* name = 0, |
261 | const QString &caption = QString(), |
262 | bool dirOnly = true, |
263 | bool resolveSymlinks = true) |
264 | { Q_UNUSED(name); |
265 | return getExistingDirectory(parent, caption, dir, |
266 | Options((resolveSymlinks ? Option(0) : DontResolveSymlinks) |
267 | | (dirOnly ? ShowDirsOnly : Option(0)))); } |
268 | |
269 | inline static QStringList QT3_SUPPORT getOpenFileNames(const QString &filter, |
270 | const QString &dir = QString(), |
271 | QWidget *parent = 0, |
272 | const char* name = 0, |
273 | const QString &caption = QString(), |
274 | QString *selectedFilter = 0, |
275 | bool resolveSymlinks = true) |
276 | { Q_UNUSED(name); |
277 | return getOpenFileNames(parent, caption, dir, filter, selectedFilter, |
278 | resolveSymlinks ? Option(0) : DontResolveSymlinks); } |
279 | #endif // QT3_SUPPORT |
280 | |
281 | protected: |
282 | QFileDialog(const QFileDialogArgs &args); |
283 | void done(int result); |
284 | void accept(); |
285 | void changeEvent(QEvent *e); |
286 | |
287 | private: |
288 | Q_DECLARE_PRIVATE(QFileDialog) |
289 | Q_DISABLE_COPY(QFileDialog) |
290 | |
291 | Q_PRIVATE_SLOT(d_func(), void _q_pathChanged(const QString &)) |
292 | |
293 | Q_PRIVATE_SLOT(d_func(), void _q_navigateBackward()) |
294 | Q_PRIVATE_SLOT(d_func(), void _q_navigateForward()) |
295 | Q_PRIVATE_SLOT(d_func(), void _q_navigateToParent()) |
296 | Q_PRIVATE_SLOT(d_func(), void _q_createDirectory()) |
297 | Q_PRIVATE_SLOT(d_func(), void _q_showListView()) |
298 | Q_PRIVATE_SLOT(d_func(), void _q_showDetailsView()) |
299 | Q_PRIVATE_SLOT(d_func(), void _q_showContextMenu(const QPoint &)) |
300 | Q_PRIVATE_SLOT(d_func(), void _q_renameCurrent()) |
301 | Q_PRIVATE_SLOT(d_func(), void _q_deleteCurrent()) |
302 | Q_PRIVATE_SLOT(d_func(), void _q_showHidden()) |
303 | Q_PRIVATE_SLOT(d_func(), void _q_updateOkButton()) |
304 | Q_PRIVATE_SLOT(d_func(), void _q_currentChanged(const QModelIndex &index)) |
305 | Q_PRIVATE_SLOT(d_func(), void _q_enterDirectory(const QModelIndex &index)) |
306 | Q_PRIVATE_SLOT(d_func(), void _q_goToDirectory(const QString &path)) |
307 | Q_PRIVATE_SLOT(d_func(), void _q_useNameFilter(int index)) |
308 | Q_PRIVATE_SLOT(d_func(), void _q_selectionChanged()) |
309 | Q_PRIVATE_SLOT(d_func(), void _q_goToUrl(const QUrl &url)) |
310 | Q_PRIVATE_SLOT(d_func(), void _q_goHome()) |
311 | Q_PRIVATE_SLOT(d_func(), void _q_showHeader(QAction *)) |
312 | Q_PRIVATE_SLOT(d_func(), void _q_autoCompleteFileName(const QString &text)) |
313 | Q_PRIVATE_SLOT(d_func(), void _q_rowsInserted(const QModelIndex & parent)) |
314 | Q_PRIVATE_SLOT(d_func(), void _q_fileRenamed(const QString &path, |
315 | const QString oldName, const QString newName)) |
316 | #if defined(Q_WS_MAC) |
317 | Q_PRIVATE_SLOT(d_func(), void _q_macRunNativeAppModalPanel()) |
318 | #endif |
319 | }; |
320 | |
321 | inline void QFileDialog::setDirectory(const QDir &adirectory) |
322 | { setDirectory(adirectory.absolutePath()); } |
323 | |
324 | Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDialog::Options) |
325 | |
326 | #endif // QT_NO_FILEDIALOG |
327 | |
328 | QT_END_NAMESPACE |
329 | |
330 | QT_END_HEADER |
331 | |
332 | #endif // QFILEDIALOG_H |
333 | |