Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/dialogs/qfiledialog.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
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 The Qt Company. For licensing terms | - | ||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #define QT_NO_URL_CAST_FROM_STRING | - | ||||||||||||||||||
35 | - | |||||||||||||||||||
36 | #include <qvariant.h> | - | ||||||||||||||||||
37 | #include <private/qwidgetitemdata_p.h> | - | ||||||||||||||||||
38 | #include "qfiledialog.h" | - | ||||||||||||||||||
39 | - | |||||||||||||||||||
40 | #ifndef QT_NO_FILEDIALOG | - | ||||||||||||||||||
41 | #include "qfiledialog_p.h" | - | ||||||||||||||||||
42 | #include <private/qguiapplication_p.h> | - | ||||||||||||||||||
43 | #include <qfontmetrics.h> | - | ||||||||||||||||||
44 | #include <qaction.h> | - | ||||||||||||||||||
45 | #include <qheaderview.h> | - | ||||||||||||||||||
46 | #include <qshortcut.h> | - | ||||||||||||||||||
47 | #include <qgridlayout.h> | - | ||||||||||||||||||
48 | #include <qmenu.h> | - | ||||||||||||||||||
49 | #include <qmessagebox.h> | - | ||||||||||||||||||
50 | #include <qinputdialog.h> | - | ||||||||||||||||||
51 | #include <stdlib.h> | - | ||||||||||||||||||
52 | #include <qsettings.h> | - | ||||||||||||||||||
53 | #include <qdebug.h> | - | ||||||||||||||||||
54 | #include <qmimedatabase.h> | - | ||||||||||||||||||
55 | #include <qapplication.h> | - | ||||||||||||||||||
56 | #include <qstylepainter.h> | - | ||||||||||||||||||
57 | #if !defined(Q_OS_WINCE) | - | ||||||||||||||||||
58 | #include "ui_qfiledialog.h" | - | ||||||||||||||||||
59 | #else | - | ||||||||||||||||||
60 | #define Q_EMBEDDED_SMALLSCREEN | - | ||||||||||||||||||
61 | #include "ui_qfiledialog_embedded.h" | - | ||||||||||||||||||
62 | #if defined(Q_OS_WINCE) | - | ||||||||||||||||||
63 | extern bool qt_priv_ptr_valid; | - | ||||||||||||||||||
64 | #endif | - | ||||||||||||||||||
65 | #endif | - | ||||||||||||||||||
66 | #if defined(Q_OS_UNIX) | - | ||||||||||||||||||
67 | #include <pwd.h> | - | ||||||||||||||||||
68 | #include <unistd.h> // for pathconf() on OS X | - | ||||||||||||||||||
69 | #elif defined(Q_OS_WIN) | - | ||||||||||||||||||
70 | # include <QtCore/qt_windows.h> | - | ||||||||||||||||||
71 | #endif | - | ||||||||||||||||||
72 | - | |||||||||||||||||||
73 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
74 | - | |||||||||||||||||||
75 | Q_GLOBAL_STATIC(QUrl, lastVisitedDir) never executed: end of block never executed: guard.store(QtGlobalStatic::Destroyed); never executed: return &holder.value;
| 0 | ||||||||||||||||||
76 | - | |||||||||||||||||||
77 | /*! | - | ||||||||||||||||||
78 | \class QFileDialog | - | ||||||||||||||||||
79 | \brief The QFileDialog class provides a dialog that allow users to select files or directories. | - | ||||||||||||||||||
80 | \ingroup standard-dialogs | - | ||||||||||||||||||
81 | \inmodule QtWidgets | - | ||||||||||||||||||
82 | - | |||||||||||||||||||
83 | The QFileDialog class enables a user to traverse the file system in | - | ||||||||||||||||||
84 | order to select one or many files or a directory. | - | ||||||||||||||||||
85 | - | |||||||||||||||||||
86 | The easiest way to create a QFileDialog is to use the static functions. | - | ||||||||||||||||||
87 | - | |||||||||||||||||||
88 | \snippet code/src_gui_dialogs_qfiledialog.cpp 0 | - | ||||||||||||||||||
89 | - | |||||||||||||||||||
90 | In the above example, a modal QFileDialog is created using a static | - | ||||||||||||||||||
91 | function. The dialog initially displays the contents of the "/home/jana" | - | ||||||||||||||||||
92 | directory, and displays files matching the patterns given in the | - | ||||||||||||||||||
93 | string "Image Files (*.png *.jpg *.bmp)". The parent of the file dialog | - | ||||||||||||||||||
94 | is set to \e this, and the window title is set to "Open Image". | - | ||||||||||||||||||
95 | - | |||||||||||||||||||
96 | If you want to use multiple filters, separate each one with | - | ||||||||||||||||||
97 | \e two semicolons. For example: | - | ||||||||||||||||||
98 | - | |||||||||||||||||||
99 | \snippet code/src_gui_dialogs_qfiledialog.cpp 1 | - | ||||||||||||||||||
100 | - | |||||||||||||||||||
101 | You can create your own QFileDialog without using the static | - | ||||||||||||||||||
102 | functions. By calling setFileMode(), you can specify what the user must | - | ||||||||||||||||||
103 | select in the dialog: | - | ||||||||||||||||||
104 | - | |||||||||||||||||||
105 | \snippet code/src_gui_dialogs_qfiledialog.cpp 2 | - | ||||||||||||||||||
106 | - | |||||||||||||||||||
107 | In the above example, the mode of the file dialog is set to | - | ||||||||||||||||||
108 | AnyFile, meaning that the user can select any file, or even specify a | - | ||||||||||||||||||
109 | file that doesn't exist. This mode is useful for creating a | - | ||||||||||||||||||
110 | "Save As" file dialog. Use ExistingFile if the user must select an | - | ||||||||||||||||||
111 | existing file, or \l Directory if only a directory may be selected. | - | ||||||||||||||||||
112 | See the \l QFileDialog::FileMode enum for the complete list of modes. | - | ||||||||||||||||||
113 | - | |||||||||||||||||||
114 | The fileMode property contains the mode of operation for the dialog; | - | ||||||||||||||||||
115 | this indicates what types of objects the user is expected to select. | - | ||||||||||||||||||
116 | Use setNameFilter() to set the dialog's file filter. For example: | - | ||||||||||||||||||
117 | - | |||||||||||||||||||
118 | \snippet code/src_gui_dialogs_qfiledialog.cpp 3 | - | ||||||||||||||||||
119 | - | |||||||||||||||||||
120 | In the above example, the filter is set to \c{"Images (*.png *.xpm *.jpg)"}, | - | ||||||||||||||||||
121 | this means that only files with the extension \c png, \c xpm, | - | ||||||||||||||||||
122 | or \c jpg will be shown in the QFileDialog. You can apply | - | ||||||||||||||||||
123 | several filters by using setNameFilters(). Use selectNameFilter() to select | - | ||||||||||||||||||
124 | one of the filters you've given as the file dialog's default filter. | - | ||||||||||||||||||
125 | - | |||||||||||||||||||
126 | The file dialog has two view modes: \l{QFileDialog::}{List} and | - | ||||||||||||||||||
127 | \l{QFileDialog::}{Detail}. | - | ||||||||||||||||||
128 | \l{QFileDialog::}{List} presents the contents of the current directory | - | ||||||||||||||||||
129 | as a list of file and directory names. \l{QFileDialog::}{Detail} also | - | ||||||||||||||||||
130 | displays a list of file and directory names, but provides additional | - | ||||||||||||||||||
131 | information alongside each name, such as the file size and modification | - | ||||||||||||||||||
132 | date. Set the mode with setViewMode(): | - | ||||||||||||||||||
133 | - | |||||||||||||||||||
134 | \snippet code/src_gui_dialogs_qfiledialog.cpp 4 | - | ||||||||||||||||||
135 | - | |||||||||||||||||||
136 | The last important function you will need to use when creating your | - | ||||||||||||||||||
137 | own file dialog is selectedFiles(). | - | ||||||||||||||||||
138 | - | |||||||||||||||||||
139 | \snippet code/src_gui_dialogs_qfiledialog.cpp 5 | - | ||||||||||||||||||
140 | - | |||||||||||||||||||
141 | In the above example, a modal file dialog is created and shown. If | - | ||||||||||||||||||
142 | the user clicked OK, the file they selected is put in \c fileName. | - | ||||||||||||||||||
143 | - | |||||||||||||||||||
144 | The dialog's working directory can be set with setDirectory(). | - | ||||||||||||||||||
145 | Each file in the current directory can be selected using | - | ||||||||||||||||||
146 | the selectFile() function. | - | ||||||||||||||||||
147 | - | |||||||||||||||||||
148 | The \l{dialogs/standarddialogs}{Standard Dialogs} example shows | - | ||||||||||||||||||
149 | how to use QFileDialog as well as other built-in Qt dialogs. | - | ||||||||||||||||||
150 | - | |||||||||||||||||||
151 | By default, a platform-native file dialog will be used if the platform has | - | ||||||||||||||||||
152 | one. In that case, the widgets which would otherwise be used to construct the | - | ||||||||||||||||||
153 | dialog will not be instantiated, so related accessors such as layout() and | - | ||||||||||||||||||
154 | itemDelegate() will return null. You can set the \l DontUseNativeDialog option to | - | ||||||||||||||||||
155 | ensure that the widget-based implementation will be used instead of the | - | ||||||||||||||||||
156 | native dialog. | - | ||||||||||||||||||
157 | - | |||||||||||||||||||
158 | \sa QDir, QFileInfo, QFile, QColorDialog, QFontDialog, {Standard Dialogs Example}, | - | ||||||||||||||||||
159 | {Application Example} | - | ||||||||||||||||||
160 | */ | - | ||||||||||||||||||
161 | - | |||||||||||||||||||
162 | /*! | - | ||||||||||||||||||
163 | \enum QFileDialog::AcceptMode | - | ||||||||||||||||||
164 | - | |||||||||||||||||||
165 | \value AcceptOpen | - | ||||||||||||||||||
166 | \value AcceptSave | - | ||||||||||||||||||
167 | */ | - | ||||||||||||||||||
168 | - | |||||||||||||||||||
169 | /*! | - | ||||||||||||||||||
170 | \enum QFileDialog::ViewMode | - | ||||||||||||||||||
171 | - | |||||||||||||||||||
172 | This enum describes the view mode of the file dialog; i.e. what | - | ||||||||||||||||||
173 | information about each file will be displayed. | - | ||||||||||||||||||
174 | - | |||||||||||||||||||
175 | \value Detail Displays an icon, a name, and details for each item in | - | ||||||||||||||||||
176 | the directory. | - | ||||||||||||||||||
177 | \value List Displays only an icon and a name for each item in the | - | ||||||||||||||||||
178 | directory. | - | ||||||||||||||||||
179 | - | |||||||||||||||||||
180 | \sa setViewMode() | - | ||||||||||||||||||
181 | */ | - | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | /*! | - | ||||||||||||||||||
184 | \enum QFileDialog::FileMode | - | ||||||||||||||||||
185 | - | |||||||||||||||||||
186 | This enum is used to indicate what the user may select in the file | - | ||||||||||||||||||
187 | dialog; i.e. what the dialog will return if the user clicks OK. | - | ||||||||||||||||||
188 | - | |||||||||||||||||||
189 | \value AnyFile The name of a file, whether it exists or not. | - | ||||||||||||||||||
190 | \value ExistingFile The name of a single existing file. | - | ||||||||||||||||||
191 | \value Directory The name of a directory. Both files and | - | ||||||||||||||||||
192 | directories are displayed. However, the native Windows | - | ||||||||||||||||||
193 | file dialog does not support displaying files in the | - | ||||||||||||||||||
194 | directory chooser. | - | ||||||||||||||||||
195 | \value ExistingFiles The names of zero or more existing files. | - | ||||||||||||||||||
196 | - | |||||||||||||||||||
197 | This value is obsolete since Qt 4.5: | - | ||||||||||||||||||
198 | - | |||||||||||||||||||
199 | \value DirectoryOnly Use \c Directory and setOption(ShowDirsOnly, true) instead. | - | ||||||||||||||||||
200 | - | |||||||||||||||||||
201 | \sa setFileMode() | - | ||||||||||||||||||
202 | */ | - | ||||||||||||||||||
203 | - | |||||||||||||||||||
204 | /*! | - | ||||||||||||||||||
205 | \enum QFileDialog::Option | - | ||||||||||||||||||
206 | - | |||||||||||||||||||
207 | \value ShowDirsOnly Only show directories in the file dialog. By | - | ||||||||||||||||||
208 | default both files and directories are shown. (Valid only in the | - | ||||||||||||||||||
209 | \l Directory file mode.) | - | ||||||||||||||||||
210 | - | |||||||||||||||||||
211 | \value DontResolveSymlinks Don't resolve symlinks in the file | - | ||||||||||||||||||
212 | dialog. By default symlinks are resolved. | - | ||||||||||||||||||
213 | - | |||||||||||||||||||
214 | \value DontConfirmOverwrite Don't ask for confirmation if an | - | ||||||||||||||||||
215 | existing file is selected. By default confirmation is requested. | - | ||||||||||||||||||
216 | - | |||||||||||||||||||
217 | \value DontUseNativeDialog Don't use the native file dialog. By | - | ||||||||||||||||||
218 | default, the native file dialog is used unless you use a subclass | - | ||||||||||||||||||
219 | of QFileDialog that contains the Q_OBJECT macro, or the platform | - | ||||||||||||||||||
220 | does not have a native dialog of the type that you require. | - | ||||||||||||||||||
221 | - | |||||||||||||||||||
222 | \value ReadOnly Indicates that the model is readonly. | - | ||||||||||||||||||
223 | - | |||||||||||||||||||
224 | \value HideNameFilterDetails Indicates if the file name filter details are | - | ||||||||||||||||||
225 | hidden or not. | - | ||||||||||||||||||
226 | - | |||||||||||||||||||
227 | \value DontUseSheet In previous versions of Qt, the static | - | ||||||||||||||||||
228 | functions would create a sheet by default if the static function | - | ||||||||||||||||||
229 | was given a parent. This is no longer supported and does nothing in Qt 4.5, The | - | ||||||||||||||||||
230 | static functions will always be an application modal dialog. If | - | ||||||||||||||||||
231 | you want to use sheets, use QFileDialog::open() instead. | - | ||||||||||||||||||
232 | - | |||||||||||||||||||
233 | \value DontUseCustomDirectoryIcons Always use the default directory icon. | - | ||||||||||||||||||
234 | Some platforms allow the user to set a different icon. Custom icon lookup | - | ||||||||||||||||||
235 | cause a big performance impact over network or removable drives. | - | ||||||||||||||||||
236 | Setting this will enable the QFileIconProvider::DontUseCustomDirectoryIcons | - | ||||||||||||||||||
237 | option in the icon provider. This enum value was added in Qt 5.2. | - | ||||||||||||||||||
238 | */ | - | ||||||||||||||||||
239 | - | |||||||||||||||||||
240 | /*! | - | ||||||||||||||||||
241 | \enum QFileDialog::DialogLabel | - | ||||||||||||||||||
242 | - | |||||||||||||||||||
243 | \value LookIn | - | ||||||||||||||||||
244 | \value FileName | - | ||||||||||||||||||
245 | \value FileType | - | ||||||||||||||||||
246 | \value Accept | - | ||||||||||||||||||
247 | \value Reject | - | ||||||||||||||||||
248 | */ | - | ||||||||||||||||||
249 | - | |||||||||||||||||||
250 | /*! | - | ||||||||||||||||||
251 | \fn void QFileDialog::filesSelected(const QStringList &selected) | - | ||||||||||||||||||
252 | - | |||||||||||||||||||
253 | When the selection changes for local operations and the dialog is | - | ||||||||||||||||||
254 | accepted, this signal is emitted with the (possibly empty) list | - | ||||||||||||||||||
255 | of \a selected files. | - | ||||||||||||||||||
256 | - | |||||||||||||||||||
257 | \sa currentChanged(), QDialog::Accepted | - | ||||||||||||||||||
258 | */ | - | ||||||||||||||||||
259 | - | |||||||||||||||||||
260 | /*! | - | ||||||||||||||||||
261 | \fn void QFileDialog::urlsSelected(const QList<QUrl> &urls) | - | ||||||||||||||||||
262 | - | |||||||||||||||||||
263 | When the selection changes and the dialog is accepted, this signal is | - | ||||||||||||||||||
264 | emitted with the (possibly empty) list of selected \a urls. | - | ||||||||||||||||||
265 | - | |||||||||||||||||||
266 | \sa currentUrlChanged(), QDialog::Accepted | - | ||||||||||||||||||
267 | \since 5.2 | - | ||||||||||||||||||
268 | */ | - | ||||||||||||||||||
269 | - | |||||||||||||||||||
270 | /*! | - | ||||||||||||||||||
271 | \fn void QFileDialog::fileSelected(const QString &file) | - | ||||||||||||||||||
272 | - | |||||||||||||||||||
273 | When the selection changes for local operations and the dialog is | - | ||||||||||||||||||
274 | accepted, this signal is emitted with the (possibly empty) | - | ||||||||||||||||||
275 | selected \a file. | - | ||||||||||||||||||
276 | - | |||||||||||||||||||
277 | \sa currentChanged(), QDialog::Accepted | - | ||||||||||||||||||
278 | */ | - | ||||||||||||||||||
279 | - | |||||||||||||||||||
280 | /*! | - | ||||||||||||||||||
281 | \fn void QFileDialog::urlSelected(const QUrl &url) | - | ||||||||||||||||||
282 | - | |||||||||||||||||||
283 | When the selection changes and the dialog is accepted, this signal is | - | ||||||||||||||||||
284 | emitted with the (possibly empty) selected \a url. | - | ||||||||||||||||||
285 | - | |||||||||||||||||||
286 | \sa currentUrlChanged(), QDialog::Accepted | - | ||||||||||||||||||
287 | \since 5.2 | - | ||||||||||||||||||
288 | */ | - | ||||||||||||||||||
289 | - | |||||||||||||||||||
290 | /*! | - | ||||||||||||||||||
291 | \fn void QFileDialog::currentChanged(const QString &path) | - | ||||||||||||||||||
292 | - | |||||||||||||||||||
293 | When the current file changes for local operations, this signal is | - | ||||||||||||||||||
294 | emitted with the new file name as the \a path parameter. | - | ||||||||||||||||||
295 | - | |||||||||||||||||||
296 | \sa filesSelected() | - | ||||||||||||||||||
297 | */ | - | ||||||||||||||||||
298 | - | |||||||||||||||||||
299 | /*! | - | ||||||||||||||||||
300 | \fn void QFileDialog::currentUrlChanged(const QUrl &url) | - | ||||||||||||||||||
301 | - | |||||||||||||||||||
302 | When the current file changes, this signal is emitted with the | - | ||||||||||||||||||
303 | new file URL as the \a url parameter. | - | ||||||||||||||||||
304 | - | |||||||||||||||||||
305 | \sa urlsSelected() | - | ||||||||||||||||||
306 | \since 5.2 | - | ||||||||||||||||||
307 | */ | - | ||||||||||||||||||
308 | - | |||||||||||||||||||
309 | /*! | - | ||||||||||||||||||
310 | \fn void QFileDialog::directoryEntered(const QString &directory) | - | ||||||||||||||||||
311 | \since 4.3 | - | ||||||||||||||||||
312 | - | |||||||||||||||||||
313 | This signal is emitted for local operations when the user enters | - | ||||||||||||||||||
314 | a \a directory. | - | ||||||||||||||||||
315 | */ | - | ||||||||||||||||||
316 | - | |||||||||||||||||||
317 | /*! | - | ||||||||||||||||||
318 | \fn void QFileDialog::directoryUrlEntered(const QUrl &directory) | - | ||||||||||||||||||
319 | - | |||||||||||||||||||
320 | This signal is emitted when the user enters a \a directory. | - | ||||||||||||||||||
321 | - | |||||||||||||||||||
322 | \since 5.2 | - | ||||||||||||||||||
323 | */ | - | ||||||||||||||||||
324 | - | |||||||||||||||||||
325 | /*! | - | ||||||||||||||||||
326 | \fn void QFileDialog::filterSelected(const QString &filter) | - | ||||||||||||||||||
327 | \since 4.3 | - | ||||||||||||||||||
328 | - | |||||||||||||||||||
329 | This signal is emitted when the user selects a \a filter. | - | ||||||||||||||||||
330 | */ | - | ||||||||||||||||||
331 | - | |||||||||||||||||||
332 | QT_BEGIN_INCLUDE_NAMESPACE | - | ||||||||||||||||||
333 | #include <QMetaEnum> | - | ||||||||||||||||||
334 | #include <qshortcut.h> | - | ||||||||||||||||||
335 | QT_END_INCLUDE_NAMESPACE | - | ||||||||||||||||||
336 | - | |||||||||||||||||||
337 | /*! | - | ||||||||||||||||||
338 | \fn QFileDialog::QFileDialog(QWidget *parent, Qt::WindowFlags flags) | - | ||||||||||||||||||
339 | - | |||||||||||||||||||
340 | Constructs a file dialog with the given \a parent and widget \a flags. | - | ||||||||||||||||||
341 | */ | - | ||||||||||||||||||
342 | QFileDialog::QFileDialog(QWidget *parent, Qt::WindowFlags f) | - | ||||||||||||||||||
343 | : QDialog(*new QFileDialogPrivate, parent, f) | - | ||||||||||||||||||
344 | { | - | ||||||||||||||||||
345 | Q_D(QFileDialog); | - | ||||||||||||||||||
346 | d->init(); | - | ||||||||||||||||||
347 | } never executed: end of block | 0 | ||||||||||||||||||
348 | - | |||||||||||||||||||
349 | /*! | - | ||||||||||||||||||
350 | Constructs a file dialog with the given \a parent and \a caption that | - | ||||||||||||||||||
351 | initially displays the contents of the specified \a directory. | - | ||||||||||||||||||
352 | The contents of the directory are filtered before being shown in the | - | ||||||||||||||||||
353 | dialog, using a semicolon-separated list of filters specified by | - | ||||||||||||||||||
354 | \a filter. | - | ||||||||||||||||||
355 | */ | - | ||||||||||||||||||
356 | QFileDialog::QFileDialog(QWidget *parent, | - | ||||||||||||||||||
357 | const QString &caption, | - | ||||||||||||||||||
358 | const QString &directory, | - | ||||||||||||||||||
359 | const QString &filter) | - | ||||||||||||||||||
360 | : QDialog(*new QFileDialogPrivate, parent, 0) | - | ||||||||||||||||||
361 | { | - | ||||||||||||||||||
362 | Q_D(QFileDialog); | - | ||||||||||||||||||
363 | d->init(QUrl::fromLocalFile(directory), filter, caption); | - | ||||||||||||||||||
364 | } never executed: end of block | 0 | ||||||||||||||||||
365 | - | |||||||||||||||||||
366 | /*! | - | ||||||||||||||||||
367 | \internal | - | ||||||||||||||||||
368 | */ | - | ||||||||||||||||||
369 | QFileDialog::QFileDialog(const QFileDialogArgs &args) | - | ||||||||||||||||||
370 | : QDialog(*new QFileDialogPrivate, args.parent, 0) | - | ||||||||||||||||||
371 | { | - | ||||||||||||||||||
372 | Q_D(QFileDialog); | - | ||||||||||||||||||
373 | d->init(args.directory, args.filter, args.caption); | - | ||||||||||||||||||
374 | setFileMode(args.mode); | - | ||||||||||||||||||
375 | setOptions(args.options); | - | ||||||||||||||||||
376 | selectFile(args.selection); | - | ||||||||||||||||||
377 | } never executed: end of block | 0 | ||||||||||||||||||
378 | - | |||||||||||||||||||
379 | /*! | - | ||||||||||||||||||
380 | Destroys the file dialog. | - | ||||||||||||||||||
381 | */ | - | ||||||||||||||||||
382 | QFileDialog::~QFileDialog() | - | ||||||||||||||||||
383 | { | - | ||||||||||||||||||
384 | #ifndef QT_NO_SETTINGS | - | ||||||||||||||||||
385 | Q_D(QFileDialog); | - | ||||||||||||||||||
386 | d->saveSettings(); | - | ||||||||||||||||||
387 | #endif | - | ||||||||||||||||||
388 | } never executed: end of block | 0 | ||||||||||||||||||
389 | - | |||||||||||||||||||
390 | /*! | - | ||||||||||||||||||
391 | \since 4.3 | - | ||||||||||||||||||
392 | Sets the \a urls that are located in the sidebar. | - | ||||||||||||||||||
393 | - | |||||||||||||||||||
394 | For instance: | - | ||||||||||||||||||
395 | - | |||||||||||||||||||
396 | \snippet filedialogurls.cpp 0 | - | ||||||||||||||||||
397 | - | |||||||||||||||||||
398 | The file dialog will then look like this: | - | ||||||||||||||||||
399 | - | |||||||||||||||||||
400 | \image filedialogurls.png | - | ||||||||||||||||||
401 | - | |||||||||||||||||||
402 | \sa sidebarUrls() | - | ||||||||||||||||||
403 | */ | - | ||||||||||||||||||
404 | void QFileDialog::setSidebarUrls(const QList<QUrl> &urls) | - | ||||||||||||||||||
405 | { | - | ||||||||||||||||||
406 | Q_D(QFileDialog); | - | ||||||||||||||||||
407 | if (!d->nativeDialogInUse)
| 0 | ||||||||||||||||||
408 | d->qFileDialogUi->sidebar->setUrls(urls); never executed: d->qFileDialogUi->sidebar->setUrls(urls); | 0 | ||||||||||||||||||
409 | } never executed: end of block | 0 | ||||||||||||||||||
410 | - | |||||||||||||||||||
411 | /*! | - | ||||||||||||||||||
412 | \since 4.3 | - | ||||||||||||||||||
413 | Returns a list of urls that are currently in the sidebar | - | ||||||||||||||||||
414 | */ | - | ||||||||||||||||||
415 | QList<QUrl> QFileDialog::sidebarUrls() const | - | ||||||||||||||||||
416 | { | - | ||||||||||||||||||
417 | Q_D(const QFileDialog); | - | ||||||||||||||||||
418 | return (d->nativeDialogInUse ? QList<QUrl>() : d->qFileDialogUi->sidebar->urls()); never executed: return (d->nativeDialogInUse ? QList<QUrl>() : d->qFileDialogUi->sidebar->urls());
| 0 | ||||||||||||||||||
419 | } | - | ||||||||||||||||||
420 | - | |||||||||||||||||||
421 | static const qint32 QFileDialogMagic = 0xbe; | - | ||||||||||||||||||
422 | - | |||||||||||||||||||
423 | /*! | - | ||||||||||||||||||
424 | \since 4.3 | - | ||||||||||||||||||
425 | Saves the state of the dialog's layout, history and current directory. | - | ||||||||||||||||||
426 | - | |||||||||||||||||||
427 | Typically this is used in conjunction with QSettings to remember the size | - | ||||||||||||||||||
428 | for a future session. A version number is stored as part of the data. | - | ||||||||||||||||||
429 | */ | - | ||||||||||||||||||
430 | QByteArray QFileDialog::saveState() const | - | ||||||||||||||||||
431 | { | - | ||||||||||||||||||
432 | Q_D(const QFileDialog); | - | ||||||||||||||||||
433 | int version = 4; | - | ||||||||||||||||||
434 | QByteArray data; | - | ||||||||||||||||||
435 | QDataStream stream(&data, QIODevice::WriteOnly); | - | ||||||||||||||||||
436 | - | |||||||||||||||||||
437 | stream << qint32(QFileDialogMagic); | - | ||||||||||||||||||
438 | stream << qint32(version); | - | ||||||||||||||||||
439 | if (d->usingWidgets()) {
| 0 | ||||||||||||||||||
440 | stream << d->qFileDialogUi->splitter->saveState(); | - | ||||||||||||||||||
441 | stream << d->qFileDialogUi->sidebar->urls(); | - | ||||||||||||||||||
442 | } else { never executed: end of block | 0 | ||||||||||||||||||
443 | stream << d->splitterState; | - | ||||||||||||||||||
444 | stream << d->sidebarUrls; | - | ||||||||||||||||||
445 | } never executed: end of block | 0 | ||||||||||||||||||
446 | stream << history(); | - | ||||||||||||||||||
447 | stream << *lastVisitedDir(); | - | ||||||||||||||||||
448 | if (d->usingWidgets())
| 0 | ||||||||||||||||||
449 | stream << d->qFileDialogUi->treeView->header()->saveState(); never executed: stream << d->qFileDialogUi->treeView->header()->saveState(); | 0 | ||||||||||||||||||
450 | else | - | ||||||||||||||||||
451 | stream << d->headerData; never executed: stream << d->headerData; | 0 | ||||||||||||||||||
452 | stream << qint32(viewMode()); | - | ||||||||||||||||||
453 | return data; never executed: return data; | 0 | ||||||||||||||||||
454 | } | - | ||||||||||||||||||
455 | - | |||||||||||||||||||
456 | /*! | - | ||||||||||||||||||
457 | \since 4.3 | - | ||||||||||||||||||
458 | Restores the dialogs's layout, history and current directory to the \a state specified. | - | ||||||||||||||||||
459 | - | |||||||||||||||||||
460 | Typically this is used in conjunction with QSettings to restore the size | - | ||||||||||||||||||
461 | from a past session. | - | ||||||||||||||||||
462 | - | |||||||||||||||||||
463 | Returns \c false if there are errors | - | ||||||||||||||||||
464 | */ | - | ||||||||||||||||||
465 | bool QFileDialog::restoreState(const QByteArray &state) | - | ||||||||||||||||||
466 | { | - | ||||||||||||||||||
467 | Q_D(QFileDialog); | - | ||||||||||||||||||
468 | QByteArray sd = state; | - | ||||||||||||||||||
469 | QDataStream stream(&sd, QIODevice::ReadOnly); | - | ||||||||||||||||||
470 | if (stream.atEnd())
| 0 | ||||||||||||||||||
471 | return false; never executed: return false; | 0 | ||||||||||||||||||
472 | QStringList history; | - | ||||||||||||||||||
473 | QUrl currentDirectory; | - | ||||||||||||||||||
474 | qint32 marker; | - | ||||||||||||||||||
475 | qint32 v; | - | ||||||||||||||||||
476 | qint32 viewMode; | - | ||||||||||||||||||
477 | stream >> marker; | - | ||||||||||||||||||
478 | stream >> v; | - | ||||||||||||||||||
479 | // the code below only supports versions 3 and 4 | - | ||||||||||||||||||
480 | if (marker != QFileDialogMagic || (v != 3 && v != 4))
| 0 | ||||||||||||||||||
481 | return false; never executed: return false; | 0 | ||||||||||||||||||
482 | - | |||||||||||||||||||
483 | stream >> d->splitterState | - | ||||||||||||||||||
484 | >> d->sidebarUrls | - | ||||||||||||||||||
485 | >> history; | - | ||||||||||||||||||
486 | if (v == 3) {
| 0 | ||||||||||||||||||
487 | QString currentDirectoryString; | - | ||||||||||||||||||
488 | stream >> currentDirectoryString; | - | ||||||||||||||||||
489 | currentDirectory = QUrl::fromLocalFile(currentDirectoryString); | - | ||||||||||||||||||
490 | } else { never executed: end of block | 0 | ||||||||||||||||||
491 | stream >> currentDirectory; | - | ||||||||||||||||||
492 | } never executed: end of block | 0 | ||||||||||||||||||
493 | stream >> d->headerData | - | ||||||||||||||||||
494 | >> viewMode; | - | ||||||||||||||||||
495 | - | |||||||||||||||||||
496 | setDirectoryUrl(lastVisitedDir()->isEmpty() ? currentDirectory : *lastVisitedDir()); | - | ||||||||||||||||||
497 | setViewMode(static_cast<QFileDialog::ViewMode>(viewMode)); | - | ||||||||||||||||||
498 | - | |||||||||||||||||||
499 | if (!d->usingWidgets())
| 0 | ||||||||||||||||||
500 | return true; never executed: return true; | 0 | ||||||||||||||||||
501 | - | |||||||||||||||||||
502 | return d->restoreWidgetState(history, -1); never executed: return d->restoreWidgetState(history, -1); | 0 | ||||||||||||||||||
503 | } | - | ||||||||||||||||||
504 | - | |||||||||||||||||||
505 | /*! | - | ||||||||||||||||||
506 | \reimp | - | ||||||||||||||||||
507 | */ | - | ||||||||||||||||||
508 | void QFileDialog::changeEvent(QEvent *e) | - | ||||||||||||||||||
509 | { | - | ||||||||||||||||||
510 | Q_D(QFileDialog); | - | ||||||||||||||||||
511 | if (e->type() == QEvent::LanguageChange) {
| 0 | ||||||||||||||||||
512 | d->retranslateWindowTitle(); | - | ||||||||||||||||||
513 | d->retranslateStrings(); | - | ||||||||||||||||||
514 | } never executed: end of block | 0 | ||||||||||||||||||
515 | QDialog::changeEvent(e); | - | ||||||||||||||||||
516 | } never executed: end of block | 0 | ||||||||||||||||||
517 | - | |||||||||||||||||||
518 | QFileDialogPrivate::QFileDialogPrivate() | - | ||||||||||||||||||
519 | : | - | ||||||||||||||||||
520 | #ifndef QT_NO_PROXYMODEL | - | ||||||||||||||||||
521 | proxyModel(0), | - | ||||||||||||||||||
522 | #endif | - | ||||||||||||||||||
523 | model(0), | - | ||||||||||||||||||
524 | currentHistoryLocation(-1), | - | ||||||||||||||||||
525 | renameAction(0), | - | ||||||||||||||||||
526 | deleteAction(0), | - | ||||||||||||||||||
527 | showHiddenAction(0), | - | ||||||||||||||||||
528 | useDefaultCaption(true), | - | ||||||||||||||||||
529 | defaultFileTypes(true), | - | ||||||||||||||||||
530 | qFileDialogUi(0), | - | ||||||||||||||||||
531 | options(new QFileDialogOptions) | - | ||||||||||||||||||
532 | { | - | ||||||||||||||||||
533 | } never executed: end of block | 0 | ||||||||||||||||||
534 | - | |||||||||||||||||||
535 | QFileDialogPrivate::~QFileDialogPrivate() | - | ||||||||||||||||||
536 | { | - | ||||||||||||||||||
537 | } | - | ||||||||||||||||||
538 | - | |||||||||||||||||||
539 | void QFileDialogPrivate::initHelper(QPlatformDialogHelper *h) | - | ||||||||||||||||||
540 | { | - | ||||||||||||||||||
541 | QFileDialog *d = q_func(); | - | ||||||||||||||||||
542 | QObject::connect(h, SIGNAL(fileSelected(QUrl)), d, SLOT(_q_emitUrlSelected(QUrl))); | - | ||||||||||||||||||
543 | QObject::connect(h, SIGNAL(filesSelected(QList<QUrl>)), d, SLOT(_q_emitUrlsSelected(QList<QUrl>))); | - | ||||||||||||||||||
544 | QObject::connect(h, SIGNAL(currentChanged(QUrl)), d, SLOT(_q_nativeCurrentChanged(QUrl))); | - | ||||||||||||||||||
545 | QObject::connect(h, SIGNAL(directoryEntered(QUrl)), d, SLOT(_q_nativeEnterDirectory(QUrl))); | - | ||||||||||||||||||
546 | QObject::connect(h, SIGNAL(filterSelected(QString)), d, SIGNAL(filterSelected(QString))); | - | ||||||||||||||||||
547 | static_cast<QPlatformFileDialogHelper *>(h)->setOptions(options); | - | ||||||||||||||||||
548 | nativeDialogInUse = true; | - | ||||||||||||||||||
549 | } never executed: end of block | 0 | ||||||||||||||||||
550 | - | |||||||||||||||||||
551 | void QFileDialogPrivate::helperPrepareShow(QPlatformDialogHelper *) | - | ||||||||||||||||||
552 | { | - | ||||||||||||||||||
553 | Q_Q(QFileDialog); | - | ||||||||||||||||||
554 | options->setWindowTitle(q->windowTitle()); | - | ||||||||||||||||||
555 | options->setHistory(q->history()); | - | ||||||||||||||||||
556 | if (usingWidgets())
| 0 | ||||||||||||||||||
557 | options->setSidebarUrls(qFileDialogUi->sidebar->urls()); never executed: options->setSidebarUrls(qFileDialogUi->sidebar->urls()); | 0 | ||||||||||||||||||
558 | if (options->initiallySelectedNameFilter().isEmpty())
| 0 | ||||||||||||||||||
559 | options->setInitiallySelectedNameFilter(q->selectedNameFilter()); never executed: options->setInitiallySelectedNameFilter(q->selectedNameFilter()); | 0 | ||||||||||||||||||
560 | if (options->initiallySelectedFiles().isEmpty())
| 0 | ||||||||||||||||||
561 | options->setInitiallySelectedFiles(userSelectedFiles()); never executed: options->setInitiallySelectedFiles(userSelectedFiles()); | 0 | ||||||||||||||||||
562 | } never executed: end of block | 0 | ||||||||||||||||||
563 | - | |||||||||||||||||||
564 | void QFileDialogPrivate::helperDone(QDialog::DialogCode code, QPlatformDialogHelper *) | - | ||||||||||||||||||
565 | { | - | ||||||||||||||||||
566 | if (code == QDialog::Accepted) {
| 0 | ||||||||||||||||||
567 | Q_Q(QFileDialog); | - | ||||||||||||||||||
568 | q->setViewMode(static_cast<QFileDialog::ViewMode>(options->viewMode())); | - | ||||||||||||||||||
569 | q->setSidebarUrls(options->sidebarUrls()); | - | ||||||||||||||||||
570 | q->setHistory(options->history()); | - | ||||||||||||||||||
571 | } never executed: end of block | 0 | ||||||||||||||||||
572 | } never executed: end of block | 0 | ||||||||||||||||||
573 | - | |||||||||||||||||||
574 | void QFileDialogPrivate::retranslateWindowTitle() | - | ||||||||||||||||||
575 | { | - | ||||||||||||||||||
576 | Q_Q(QFileDialog); | - | ||||||||||||||||||
577 | if (!useDefaultCaption || setWindowTitle != q->windowTitle())
| 0 | ||||||||||||||||||
578 | return; never executed: return; | 0 | ||||||||||||||||||
579 | if (q->acceptMode() == QFileDialog::AcceptOpen) {
| 0 | ||||||||||||||||||
580 | const QFileDialog::FileMode fileMode = q->fileMode(); | - | ||||||||||||||||||
581 | if (fileMode == QFileDialog::DirectoryOnly || fileMode == QFileDialog::Directory)
| 0 | ||||||||||||||||||
582 | q->setWindowTitle(QFileDialog::tr("Find Directory")); never executed: q->setWindowTitle(QFileDialog::tr("Find Directory")); | 0 | ||||||||||||||||||
583 | else | - | ||||||||||||||||||
584 | q->setWindowTitle(QFileDialog::tr("Open")); never executed: q->setWindowTitle(QFileDialog::tr("Open")); | 0 | ||||||||||||||||||
585 | } else | - | ||||||||||||||||||
586 | q->setWindowTitle(QFileDialog::tr("Save As")); never executed: q->setWindowTitle(QFileDialog::tr("Save As")); | 0 | ||||||||||||||||||
587 | - | |||||||||||||||||||
588 | setWindowTitle = q->windowTitle(); | - | ||||||||||||||||||
589 | } never executed: end of block | 0 | ||||||||||||||||||
590 | - | |||||||||||||||||||
591 | void QFileDialogPrivate::setLastVisitedDirectory(const QUrl &dir) | - | ||||||||||||||||||
592 | { | - | ||||||||||||||||||
593 | *lastVisitedDir() = dir; | - | ||||||||||||||||||
594 | } never executed: end of block | 0 | ||||||||||||||||||
595 | - | |||||||||||||||||||
596 | void QFileDialogPrivate::updateLookInLabel() | - | ||||||||||||||||||
597 | { | - | ||||||||||||||||||
598 | if (options->isLabelExplicitlySet(QFileDialogOptions::LookIn))
| 0 | ||||||||||||||||||
599 | setLabelTextControl(QFileDialog::LookIn, options->labelText(QFileDialogOptions::LookIn)); never executed: setLabelTextControl(QFileDialog::LookIn, options->labelText(QFileDialogOptions::LookIn)); | 0 | ||||||||||||||||||
600 | } never executed: end of block | 0 | ||||||||||||||||||
601 | - | |||||||||||||||||||
602 | void QFileDialogPrivate::updateFileNameLabel() | - | ||||||||||||||||||
603 | { | - | ||||||||||||||||||
604 | if (options->isLabelExplicitlySet(QFileDialogOptions::FileName)) {
| 0 | ||||||||||||||||||
605 | setLabelTextControl(QFileDialog::FileName, options->labelText(QFileDialogOptions::FileName)); | - | ||||||||||||||||||
606 | } else { never executed: end of block | 0 | ||||||||||||||||||
607 | switch (q_func()->fileMode()) { | - | ||||||||||||||||||
608 | case QFileDialog::DirectoryOnly: never executed: case QFileDialog::DirectoryOnly: | 0 | ||||||||||||||||||
609 | case QFileDialog::Directory: never executed: case QFileDialog::Directory: | 0 | ||||||||||||||||||
610 | setLabelTextControl(QFileDialog::FileName, QFileDialog::tr("Directory:")); | - | ||||||||||||||||||
611 | break; never executed: break; | 0 | ||||||||||||||||||
612 | default: never executed: default: | 0 | ||||||||||||||||||
613 | setLabelTextControl(QFileDialog::FileName, QFileDialog::tr("File &name:")); | - | ||||||||||||||||||
614 | break; never executed: break; | 0 | ||||||||||||||||||
615 | } | - | ||||||||||||||||||
616 | } | - | ||||||||||||||||||
617 | } | - | ||||||||||||||||||
618 | - | |||||||||||||||||||
619 | void QFileDialogPrivate::updateFileTypeLabel() | - | ||||||||||||||||||
620 | { | - | ||||||||||||||||||
621 | if (options->isLabelExplicitlySet(QFileDialogOptions::FileType))
| 0 | ||||||||||||||||||
622 | setLabelTextControl(QFileDialog::FileType, options->labelText(QFileDialogOptions::FileType)); never executed: setLabelTextControl(QFileDialog::FileType, options->labelText(QFileDialogOptions::FileType)); | 0 | ||||||||||||||||||
623 | } never executed: end of block | 0 | ||||||||||||||||||
624 | - | |||||||||||||||||||
625 | void QFileDialogPrivate::updateOkButtonText(bool saveAsOnFolder) | - | ||||||||||||||||||
626 | { | - | ||||||||||||||||||
627 | Q_Q(QFileDialog); | - | ||||||||||||||||||
628 | // 'Save as' at a folder: Temporarily change to "Open". | - | ||||||||||||||||||
629 | if (saveAsOnFolder) {
| 0 | ||||||||||||||||||
630 | setLabelTextControl(QFileDialog::Accept, QFileDialog::tr("&Open")); | - | ||||||||||||||||||
631 | } else if (options->isLabelExplicitlySet(QFileDialogOptions::Accept)) { never executed: end of block
| 0 | ||||||||||||||||||
632 | setLabelTextControl(QFileDialog::Accept, options->labelText(QFileDialogOptions::Accept)); | - | ||||||||||||||||||
633 | return; never executed: return; | 0 | ||||||||||||||||||
634 | } else { | - | ||||||||||||||||||
635 | switch (q->fileMode()) { | - | ||||||||||||||||||
636 | case QFileDialog::DirectoryOnly: never executed: case QFileDialog::DirectoryOnly: | 0 | ||||||||||||||||||
637 | case QFileDialog::Directory: never executed: case QFileDialog::Directory: | 0 | ||||||||||||||||||
638 | setLabelTextControl(QFileDialog::Accept, QFileDialog::tr("&Choose")); | - | ||||||||||||||||||
639 | break; never executed: break; | 0 | ||||||||||||||||||
640 | default: never executed: default: | 0 | ||||||||||||||||||
641 | setLabelTextControl(QFileDialog::Accept, | - | ||||||||||||||||||
642 | q->acceptMode() == QFileDialog::AcceptOpen ? | - | ||||||||||||||||||
643 | QFileDialog::tr("&Open") : | - | ||||||||||||||||||
644 | QFileDialog::tr("&Save")); | - | ||||||||||||||||||
645 | break; never executed: break; | 0 | ||||||||||||||||||
646 | } | - | ||||||||||||||||||
647 | } | - | ||||||||||||||||||
648 | } | - | ||||||||||||||||||
649 | - | |||||||||||||||||||
650 | void QFileDialogPrivate::updateCancelButtonText() | - | ||||||||||||||||||
651 | { | - | ||||||||||||||||||
652 | if (options->isLabelExplicitlySet(QFileDialogOptions::Reject))
| 0 | ||||||||||||||||||
653 | setLabelTextControl(QFileDialog::Reject, options->labelText(QFileDialogOptions::Reject)); never executed: setLabelTextControl(QFileDialog::Reject, options->labelText(QFileDialogOptions::Reject)); | 0 | ||||||||||||||||||
654 | } never executed: end of block | 0 | ||||||||||||||||||
655 | - | |||||||||||||||||||
656 | void QFileDialogPrivate::retranslateStrings() | - | ||||||||||||||||||
657 | { | - | ||||||||||||||||||
658 | Q_Q(QFileDialog); | - | ||||||||||||||||||
659 | /* WIDGETS */ | - | ||||||||||||||||||
660 | if (defaultFileTypes)
| 0 | ||||||||||||||||||
661 | q->setNameFilter(QFileDialog::tr("All Files (*)")); never executed: q->setNameFilter(QFileDialog::tr("All Files (*)")); | 0 | ||||||||||||||||||
662 | if (!usingWidgets())
| 0 | ||||||||||||||||||
663 | return; never executed: return; | 0 | ||||||||||||||||||
664 | - | |||||||||||||||||||
665 | QList<QAction*> actions = qFileDialogUi->treeView->header()->actions(); | - | ||||||||||||||||||
666 | QAbstractItemModel *abstractModel = model; | - | ||||||||||||||||||
667 | #ifndef QT_NO_PROXYMODEL | - | ||||||||||||||||||
668 | if (proxyModel)
| 0 | ||||||||||||||||||
669 | abstractModel = proxyModel; never executed: abstractModel = proxyModel; | 0 | ||||||||||||||||||
670 | #endif | - | ||||||||||||||||||
671 | int total = qMin(abstractModel->columnCount(QModelIndex()), actions.count() + 1); | - | ||||||||||||||||||
672 | for (int i = 1; i < total; ++i) {
| 0 | ||||||||||||||||||
673 | actions.at(i - 1)->setText(QFileDialog::tr("Show ") + abstractModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); | - | ||||||||||||||||||
674 | } never executed: end of block | 0 | ||||||||||||||||||
675 | - | |||||||||||||||||||
676 | /* MENU ACTIONS */ | - | ||||||||||||||||||
677 | renameAction->setText(QFileDialog::tr("&Rename")); | - | ||||||||||||||||||
678 | deleteAction->setText(QFileDialog::tr("&Delete")); | - | ||||||||||||||||||
679 | showHiddenAction->setText(QFileDialog::tr("Show &hidden files")); | - | ||||||||||||||||||
680 | newFolderAction->setText(QFileDialog::tr("&New Folder")); | - | ||||||||||||||||||
681 | qFileDialogUi->retranslateUi(q); | - | ||||||||||||||||||
682 | updateLookInLabel(); | - | ||||||||||||||||||
683 | updateFileNameLabel(); | - | ||||||||||||||||||
684 | updateFileTypeLabel(); | - | ||||||||||||||||||
685 | updateCancelButtonText(); | - | ||||||||||||||||||
686 | } never executed: end of block | 0 | ||||||||||||||||||
687 | - | |||||||||||||||||||
688 | void QFileDialogPrivate::emitFilesSelected(const QStringList &files) | - | ||||||||||||||||||
689 | { | - | ||||||||||||||||||
690 | Q_Q(QFileDialog); | - | ||||||||||||||||||
691 | emit q->filesSelected(files); | - | ||||||||||||||||||
692 | if (files.count() == 1)
| 0 | ||||||||||||||||||
693 | emit q->fileSelected(files.first()); never executed: q->fileSelected(files.first()); | 0 | ||||||||||||||||||
694 | } never executed: end of block | 0 | ||||||||||||||||||
695 | - | |||||||||||||||||||
696 | bool QFileDialogPrivate::canBeNativeDialog() const | - | ||||||||||||||||||
697 | { | - | ||||||||||||||||||
698 | // Don't use Q_Q here! This function is called from ~QDialog, | - | ||||||||||||||||||
699 | // so Q_Q calling q_func() invokes undefined behavior (invalid cast in q_func()). | - | ||||||||||||||||||
700 | const QDialog * const q = static_cast<const QDialog*>(q_ptr); | - | ||||||||||||||||||
701 | if (nativeDialogInUse)
| 0 | ||||||||||||||||||
702 | return true; never executed: return true; | 0 | ||||||||||||||||||
703 | if (q->testAttribute(Qt::WA_DontShowOnScreen))
| 0 | ||||||||||||||||||
704 | return false; never executed: return false; | 0 | ||||||||||||||||||
705 | if (options->options() & QFileDialog::DontUseNativeDialog)
| 0 | ||||||||||||||||||
706 | return false; never executed: return false; | 0 | ||||||||||||||||||
707 | - | |||||||||||||||||||
708 | QLatin1String staticName(QFileDialog::staticMetaObject.className()); | - | ||||||||||||||||||
709 | QLatin1String dynamicName(q->metaObject()->className()); | - | ||||||||||||||||||
710 | return (staticName == dynamicName); never executed: return (staticName == dynamicName); | 0 | ||||||||||||||||||
711 | } | - | ||||||||||||||||||
712 | - | |||||||||||||||||||
713 | bool QFileDialogPrivate::usingWidgets() const | - | ||||||||||||||||||
714 | { | - | ||||||||||||||||||
715 | return !nativeDialogInUse && qFileDialogUi; never executed: return !nativeDialogInUse && qFileDialogUi;
| 0 | ||||||||||||||||||
716 | } | - | ||||||||||||||||||
717 | - | |||||||||||||||||||
718 | /*! | - | ||||||||||||||||||
719 | \since 4.5 | - | ||||||||||||||||||
720 | Sets the given \a option to be enabled if \a on is true; otherwise, | - | ||||||||||||||||||
721 | clears the given \a option. | - | ||||||||||||||||||
722 | - | |||||||||||||||||||
723 | \sa options, testOption() | - | ||||||||||||||||||
724 | */ | - | ||||||||||||||||||
725 | void QFileDialog::setOption(Option option, bool on) | - | ||||||||||||||||||
726 | { | - | ||||||||||||||||||
727 | const QFileDialog::Options previousOptions = options(); | - | ||||||||||||||||||
728 | if (!(previousOptions & option) != !on)
| 0 | ||||||||||||||||||
729 | setOptions(previousOptions ^ option); never executed: setOptions(previousOptions ^ option); | 0 | ||||||||||||||||||
730 | } never executed: end of block | 0 | ||||||||||||||||||
731 | - | |||||||||||||||||||
732 | /*! | - | ||||||||||||||||||
733 | \since 4.5 | - | ||||||||||||||||||
734 | - | |||||||||||||||||||
735 | Returns \c true if the given \a option is enabled; otherwise, returns | - | ||||||||||||||||||
736 | false. | - | ||||||||||||||||||
737 | - | |||||||||||||||||||
738 | \sa options, setOption() | - | ||||||||||||||||||
739 | */ | - | ||||||||||||||||||
740 | bool QFileDialog::testOption(Option option) const | - | ||||||||||||||||||
741 | { | - | ||||||||||||||||||
742 | Q_D(const QFileDialog); | - | ||||||||||||||||||
743 | return d->options->testOption(static_cast<QFileDialogOptions::FileDialogOption>(option)); never executed: return d->options->testOption(static_cast<QFileDialogOptions::FileDialogOption>(option)); | 0 | ||||||||||||||||||
744 | } | - | ||||||||||||||||||
745 | - | |||||||||||||||||||
746 | /*! | - | ||||||||||||||||||
747 | \property QFileDialog::options | - | ||||||||||||||||||
748 | \brief the various options that affect the look and feel of the dialog | - | ||||||||||||||||||
749 | \since 4.5 | - | ||||||||||||||||||
750 | - | |||||||||||||||||||
751 | By default, all options are disabled. | - | ||||||||||||||||||
752 | - | |||||||||||||||||||
753 | Options should be set before showing the dialog. Setting them while the | - | ||||||||||||||||||
754 | dialog is visible is not guaranteed to have an immediate effect on the | - | ||||||||||||||||||
755 | dialog (depending on the option and on the platform). | - | ||||||||||||||||||
756 | - | |||||||||||||||||||
757 | \sa setOption(), testOption() | - | ||||||||||||||||||
758 | */ | - | ||||||||||||||||||
759 | void QFileDialog::setOptions(Options options) | - | ||||||||||||||||||
760 | { | - | ||||||||||||||||||
761 | Q_D(QFileDialog); | - | ||||||||||||||||||
762 | - | |||||||||||||||||||
763 | Options changed = (options ^ QFileDialog::options()); | - | ||||||||||||||||||
764 | if (!changed)
| 0 | ||||||||||||||||||
765 | return; never executed: return; | 0 | ||||||||||||||||||
766 | - | |||||||||||||||||||
767 | d->options->setOptions(QFileDialogOptions::FileDialogOptions(int(options))); | - | ||||||||||||||||||
768 | - | |||||||||||||||||||
769 | if ((options & DontUseNativeDialog) && !d->usingWidgets())
| 0 | ||||||||||||||||||
770 | d->createWidgets(); never executed: d->createWidgets(); | 0 | ||||||||||||||||||
771 | - | |||||||||||||||||||
772 | if (d->usingWidgets()) {
| 0 | ||||||||||||||||||
773 | if (changed & DontResolveSymlinks)
| 0 | ||||||||||||||||||
774 | d->model->setResolveSymlinks(!(options & DontResolveSymlinks)); never executed: d->model->setResolveSymlinks(!(options & DontResolveSymlinks)); | 0 | ||||||||||||||||||
775 | if (changed & ReadOnly) {
| 0 | ||||||||||||||||||
776 | bool ro = (options & ReadOnly); | - | ||||||||||||||||||
777 | d->model->setReadOnly(ro); | - | ||||||||||||||||||
778 | d->qFileDialogUi->newFolderButton->setEnabled(!ro); | - | ||||||||||||||||||
779 | d->renameAction->setEnabled(!ro); | - | ||||||||||||||||||
780 | d->deleteAction->setEnabled(!ro); | - | ||||||||||||||||||
781 | } never executed: end of block | 0 | ||||||||||||||||||
782 | - | |||||||||||||||||||
783 | if (changed & DontUseCustomDirectoryIcons) {
| 0 | ||||||||||||||||||
784 | QFileIconProvider::Options providerOptions = iconProvider()->options(); | - | ||||||||||||||||||
785 | if (options & DontUseCustomDirectoryIcons)
| 0 | ||||||||||||||||||
786 | providerOptions |= QFileIconProvider::DontUseCustomDirectoryIcons; never executed: providerOptions |= QFileIconProvider::DontUseCustomDirectoryIcons; | 0 | ||||||||||||||||||
787 | else | - | ||||||||||||||||||
788 | providerOptions &= ~QFileIconProvider::DontUseCustomDirectoryIcons; never executed: providerOptions &= ~QFileIconProvider::DontUseCustomDirectoryIcons; | 0 | ||||||||||||||||||
789 | iconProvider()->setOptions(providerOptions); | - | ||||||||||||||||||
790 | } never executed: end of block | 0 | ||||||||||||||||||
791 | } never executed: end of block | 0 | ||||||||||||||||||
792 | - | |||||||||||||||||||
793 | if (changed & HideNameFilterDetails)
| 0 | ||||||||||||||||||
794 | setNameFilters(d->options->nameFilters()); never executed: setNameFilters(d->options->nameFilters()); | 0 | ||||||||||||||||||
795 | - | |||||||||||||||||||
796 | if (changed & ShowDirsOnly)
| 0 | ||||||||||||||||||
797 | setFilter((options & ShowDirsOnly) ? filter() & ~QDir::Files : filter() | QDir::Files); never executed: setFilter((options & ShowDirsOnly) ? filter() & ~QDir::Files : filter() | QDir::Files); | 0 | ||||||||||||||||||
798 | } never executed: end of block | 0 | ||||||||||||||||||
799 | - | |||||||||||||||||||
800 | QFileDialog::Options QFileDialog::options() const | - | ||||||||||||||||||
801 | { | - | ||||||||||||||||||
802 | Q_D(const QFileDialog); | - | ||||||||||||||||||
803 | return QFileDialog::Options(int(d->options->options())); never executed: return QFileDialog::Options(int(d->options->options())); | 0 | ||||||||||||||||||
804 | } | - | ||||||||||||||||||
805 | - | |||||||||||||||||||
806 | /*! | - | ||||||||||||||||||
807 | \overload | - | ||||||||||||||||||
808 | - | |||||||||||||||||||
809 | \since 4.5 | - | ||||||||||||||||||
810 | - | |||||||||||||||||||
811 | This function connects one of its signals to the slot specified by \a receiver | - | ||||||||||||||||||
812 | and \a member. The specific signal depends is filesSelected() if fileMode is | - | ||||||||||||||||||
813 | ExistingFiles and fileSelected() if fileMode is anything else. | - | ||||||||||||||||||
814 | - | |||||||||||||||||||
815 | The signal will be disconnected from the slot when the dialog is closed. | - | ||||||||||||||||||
816 | */ | - | ||||||||||||||||||
817 | void QFileDialog::open(QObject *receiver, const char *member) | - | ||||||||||||||||||
818 | { | - | ||||||||||||||||||
819 | Q_D(QFileDialog); | - | ||||||||||||||||||
820 | const char *signal = (fileMode() == ExistingFiles) ? SIGNAL(filesSelected(QStringList))
| 0 | ||||||||||||||||||
821 | : SIGNAL(fileSelected(QString)); | - | ||||||||||||||||||
822 | connect(this, signal, receiver, member); | - | ||||||||||||||||||
823 | d->signalToDisconnectOnClose = signal; | - | ||||||||||||||||||
824 | d->receiverToDisconnectOnClose = receiver; | - | ||||||||||||||||||
825 | d->memberToDisconnectOnClose = member; | - | ||||||||||||||||||
826 | - | |||||||||||||||||||
827 | QDialog::open(); | - | ||||||||||||||||||
828 | } never executed: end of block | 0 | ||||||||||||||||||
829 | - | |||||||||||||||||||
830 | - | |||||||||||||||||||
831 | /*! | - | ||||||||||||||||||
832 | \reimp | - | ||||||||||||||||||
833 | */ | - | ||||||||||||||||||
834 | void QFileDialog::setVisible(bool visible) | - | ||||||||||||||||||
835 | { | - | ||||||||||||||||||
836 | Q_D(QFileDialog); | - | ||||||||||||||||||
837 | if (visible){
| 0 | ||||||||||||||||||
838 | if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden))
| 0 | ||||||||||||||||||
839 | return; never executed: return; | 0 | ||||||||||||||||||
840 | } else if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden)) never executed: end of block
| 0 | ||||||||||||||||||
841 | return; never executed: return; | 0 | ||||||||||||||||||
842 | - | |||||||||||||||||||
843 | if (d->canBeNativeDialog()){
| 0 | ||||||||||||||||||
844 | if (d->setNativeDialogVisible(visible)){
| 0 | ||||||||||||||||||
845 | // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below | - | ||||||||||||||||||
846 | // updates the state correctly, but skips showing the non-native version: | - | ||||||||||||||||||
847 | setAttribute(Qt::WA_DontShowOnScreen); | - | ||||||||||||||||||
848 | #ifndef QT_NO_FSCOMPLETER | - | ||||||||||||||||||
849 | // So the completer doesn't try to complete and therefore show a popup | - | ||||||||||||||||||
850 | if (!d->nativeDialogInUse)
| 0 | ||||||||||||||||||
851 | d->completer->setModel(0); never executed: d->completer->setModel(0); | 0 | ||||||||||||||||||
852 | #endif | - | ||||||||||||||||||
853 | } else { never executed: end of block | 0 | ||||||||||||||||||
854 | d->createWidgets(); | - | ||||||||||||||||||
855 | setAttribute(Qt::WA_DontShowOnScreen, false); | - | ||||||||||||||||||
856 | #ifndef QT_NO_FSCOMPLETER | - | ||||||||||||||||||
857 | if (!d->nativeDialogInUse) {
| 0 | ||||||||||||||||||
858 | if (d->proxyModel != 0)
| 0 | ||||||||||||||||||
859 | d->completer->setModel(d->proxyModel); never executed: d->completer->setModel(d->proxyModel); | 0 | ||||||||||||||||||
860 | else | - | ||||||||||||||||||
861 | d->completer->setModel(d->model); never executed: d->completer->setModel(d->model); | 0 | ||||||||||||||||||
862 | } | - | ||||||||||||||||||
863 | #endif | - | ||||||||||||||||||
864 | } never executed: end of block | 0 | ||||||||||||||||||
865 | } | - | ||||||||||||||||||
866 | - | |||||||||||||||||||
867 | if (d->usingWidgets())
| 0 | ||||||||||||||||||
868 | d->qFileDialogUi->fileNameEdit->setFocus(); never executed: d->qFileDialogUi->fileNameEdit->setFocus(); | 0 | ||||||||||||||||||
869 | - | |||||||||||||||||||
870 | QDialog::setVisible(visible); | - | ||||||||||||||||||
871 | } never executed: end of block | 0 | ||||||||||||||||||
872 | - | |||||||||||||||||||
873 | /*! | - | ||||||||||||||||||
874 | \internal | - | ||||||||||||||||||
875 | set the directory to url | - | ||||||||||||||||||
876 | */ | - | ||||||||||||||||||
877 | void QFileDialogPrivate::_q_goToUrl(const QUrl &url) | - | ||||||||||||||||||
878 | { | - | ||||||||||||||||||
879 | //The shortcut in the side bar may have a parent that is not fetched yet (e.g. an hidden file) | - | ||||||||||||||||||
880 | //so we force the fetching | - | ||||||||||||||||||
881 | QFileSystemModelPrivate::QFileSystemNode *node = model->d_func()->node(url.toLocalFile(), true); | - | ||||||||||||||||||
882 | QModelIndex idx = model->d_func()->index(node); | - | ||||||||||||||||||
883 | _q_enterDirectory(idx); | - | ||||||||||||||||||
884 | } never executed: end of block | 0 | ||||||||||||||||||
885 | - | |||||||||||||||||||
886 | /*! | - | ||||||||||||||||||
887 | \fn void QFileDialog::setDirectory(const QDir &directory) | - | ||||||||||||||||||
888 | - | |||||||||||||||||||
889 | \overload | - | ||||||||||||||||||
890 | */ | - | ||||||||||||||||||
891 | - | |||||||||||||||||||
892 | /*! | - | ||||||||||||||||||
893 | Sets the file dialog's current \a directory. | - | ||||||||||||||||||
894 | - | |||||||||||||||||||
895 | \note On iOS, if you set \a directory to \l{QStandardPaths::standardLocations()} | - | ||||||||||||||||||
896 | {QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).last()}, | - | ||||||||||||||||||
897 | a native image picker dialog will be used for accessing the user's photo album. | - | ||||||||||||||||||
898 | The filename returned can be loaded using QFile and related APIs. | - | ||||||||||||||||||
899 | For this to be enabled, the Info.plist assigned to QMAKE_INFO_PLIST in the | - | ||||||||||||||||||
900 | project file must contain the key \c NSPhotoLibraryUsageDescription. See | - | ||||||||||||||||||
901 | Info.plist documentation from Apple for more information regarding this key. | - | ||||||||||||||||||
902 | This feature was added in Qt 5.5. | - | ||||||||||||||||||
903 | */ | - | ||||||||||||||||||
904 | void QFileDialog::setDirectory(const QString &directory) | - | ||||||||||||||||||
905 | { | - | ||||||||||||||||||
906 | Q_D(QFileDialog); | - | ||||||||||||||||||
907 | QString newDirectory = directory; | - | ||||||||||||||||||
908 | //we remove .. and . from the given path if exist | - | ||||||||||||||||||
909 | if (!directory.isEmpty())
| 0 | ||||||||||||||||||
910 | newDirectory = QDir::cleanPath(directory); never executed: newDirectory = QDir::cleanPath(directory); | 0 | ||||||||||||||||||
911 | - | |||||||||||||||||||
912 | if (!directory.isEmpty() && newDirectory.isEmpty())
| 0 | ||||||||||||||||||
913 | return; never executed: return; | 0 | ||||||||||||||||||
914 | - | |||||||||||||||||||
915 | QUrl newDirUrl = QUrl::fromLocalFile(newDirectory); | - | ||||||||||||||||||
916 | QFileDialogPrivate::setLastVisitedDirectory(newDirUrl); | - | ||||||||||||||||||
917 | - | |||||||||||||||||||
918 | d->options->setInitialDirectory(QUrl::fromLocalFile(directory)); | - | ||||||||||||||||||
919 | if (!d->usingWidgets()) {
| 0 | ||||||||||||||||||
920 | d->setDirectory_sys(newDirUrl); | - | ||||||||||||||||||
921 | return; never executed: return; | 0 | ||||||||||||||||||
922 | } | - | ||||||||||||||||||
923 | if (d->rootPath() == newDirectory)
| 0 | ||||||||||||||||||
924 | return; never executed: return; | 0 | ||||||||||||||||||
925 | QModelIndex root = d->model->setRootPath(newDirectory); | - | ||||||||||||||||||
926 | if (!d->nativeDialogInUse) {
| 0 | ||||||||||||||||||
927 | d->qFileDialogUi->newFolderButton->setEnabled(d->model->flags(root) & Qt::ItemIsDropEnabled); | - | ||||||||||||||||||
928 | if (root != d->rootIndex()) {
| 0 | ||||||||||||||||||
929 | #ifndef QT_NO_FSCOMPLETER | - | ||||||||||||||||||
930 | if (directory.endsWith(QLatin1Char('/')))
| 0 | ||||||||||||||||||
931 | d->completer->setCompletionPrefix(newDirectory); never executed: d->completer->setCompletionPrefix(newDirectory); | 0 | ||||||||||||||||||
932 | else | - | ||||||||||||||||||
933 | d->completer->setCompletionPrefix(newDirectory + QLatin1Char('/')); never executed: d->completer->setCompletionPrefix(newDirectory + QLatin1Char('/')); | 0 | ||||||||||||||||||
934 | #endif | - | ||||||||||||||||||
935 | d->setRootIndex(root); | - | ||||||||||||||||||
936 | } never executed: end of block | 0 | ||||||||||||||||||
937 | d->qFileDialogUi->listView->selectionModel()->clear(); | - | ||||||||||||||||||
938 | } never executed: end of block | 0 | ||||||||||||||||||
939 | } never executed: end of block | 0 | ||||||||||||||||||
940 | - | |||||||||||||||||||
941 | /*! | - | ||||||||||||||||||
942 | Returns the directory currently being displayed in the dialog. | - | ||||||||||||||||||
943 | */ | - | ||||||||||||||||||
944 | QDir QFileDialog::directory() const | - | ||||||||||||||||||
945 | { | - | ||||||||||||||||||
946 | Q_D(const QFileDialog); | - | ||||||||||||||||||
947 | if (d->nativeDialogInUse) {
| 0 | ||||||||||||||||||
948 | QString dir = d->directory_sys().toLocalFile(); | - | ||||||||||||||||||
949 | return QDir(dir.isEmpty() ? d->options->initialDirectory().toLocalFile() : dir); never executed: return QDir(dir.isEmpty() ? d->options->initialDirectory().toLocalFile() : dir); | 0 | ||||||||||||||||||
950 | } | - | ||||||||||||||||||
951 | return d->rootPath(); never executed: return d->rootPath(); | 0 | ||||||||||||||||||
952 | } | - | ||||||||||||||||||
953 | - | |||||||||||||||||||
954 | /*! | - | ||||||||||||||||||
955 | Sets the file dialog's current \a directory url. | - | ||||||||||||||||||
956 | - | |||||||||||||||||||
957 | \note The non-native QFileDialog supports only local files. | - | ||||||||||||||||||
958 | - | |||||||||||||||||||
959 | \note On Windows, it is possible to pass URLs representing | - | ||||||||||||||||||
960 | one of the \e {virtual folders}, such as "Computer" or "Network". | - | ||||||||||||||||||
961 | This is done by passing a QUrl using the scheme \c clsid followed | - | ||||||||||||||||||
962 | by the CLSID value with the curly braces removed. For example the URL | - | ||||||||||||||||||
963 | \c clsid:374DE290-123F-4565-9164-39C4925E467B denotes the download | - | ||||||||||||||||||
964 | location. For a complete list of possible values, see the MSDN documentation on | - | ||||||||||||||||||
965 | \l{https://msdn.microsoft.com/en-us/library/windows/desktop/dd378457.aspx}{KNOWNFOLDERID}. | - | ||||||||||||||||||
966 | This feature was added in Qt 5.5. | - | ||||||||||||||||||
967 | - | |||||||||||||||||||
968 | \sa QUuid | - | ||||||||||||||||||
969 | \since 5.2 | - | ||||||||||||||||||
970 | */ | - | ||||||||||||||||||
971 | void QFileDialog::setDirectoryUrl(const QUrl &directory) | - | ||||||||||||||||||
972 | { | - | ||||||||||||||||||
973 | Q_D(QFileDialog); | - | ||||||||||||||||||
974 | if (!directory.isValid())
| 0 | ||||||||||||||||||
975 | return; never executed: return; | 0 | ||||||||||||||||||
976 | - | |||||||||||||||||||
977 | QFileDialogPrivate::setLastVisitedDirectory(directory); | - | ||||||||||||||||||
978 | d->options->setInitialDirectory(directory); | - | ||||||||||||||||||
979 | - | |||||||||||||||||||
980 | if (d->nativeDialogInUse)
| 0 | ||||||||||||||||||
981 | d->setDirectory_sys(directory); never executed: d->setDirectory_sys(directory); | 0 | ||||||||||||||||||
982 | else if (directory.isLocalFile())
| 0 | ||||||||||||||||||
983 | setDirectory(directory.toLocalFile()); never executed: setDirectory(directory.toLocalFile()); | 0 | ||||||||||||||||||
984 | else if (d->usingWidgets())
| 0 | ||||||||||||||||||
985 | qWarning("Non-native QFileDialog supports only local files"); never executed: QMessageLogger(__FILE__, 985, __PRETTY_FUNCTION__).warning("Non-native QFileDialog supports only local files"); | 0 | ||||||||||||||||||
986 | } never executed: end of block | 0 | ||||||||||||||||||
987 | - | |||||||||||||||||||
988 | /*! | - | ||||||||||||||||||
989 | Returns the url of the directory currently being displayed in the dialog. | - | ||||||||||||||||||
990 | - | |||||||||||||||||||
991 | \since 5.2 | - | ||||||||||||||||||
992 | */ | - | ||||||||||||||||||
993 | QUrl QFileDialog::directoryUrl() const | - | ||||||||||||||||||
994 | { | - | ||||||||||||||||||
995 | Q_D(const QFileDialog); | - | ||||||||||||||||||
996 | if (d->nativeDialogInUse)
| 0 | ||||||||||||||||||
997 | return d->directory_sys(); never executed: return d->directory_sys(); | 0 | ||||||||||||||||||
998 | else | - | ||||||||||||||||||
999 | return QUrl::fromLocalFile(directory().absolutePath()); never executed: return QUrl::fromLocalFile(directory().absolutePath()); | 0 | ||||||||||||||||||
1000 | } | - | ||||||||||||||||||
1001 | - | |||||||||||||||||||
1002 | // FIXME Qt 5.4: Use upcoming QVolumeInfo class to determine this information? | - | ||||||||||||||||||
1003 | static inline bool isCaseSensitiveFileSystem(const QString &path) | - | ||||||||||||||||||
1004 | { | - | ||||||||||||||||||
1005 | Q_UNUSED(path) | - | ||||||||||||||||||
1006 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||
1007 | // Return case insensitive unconditionally, even if someone has a case sensitive | - | ||||||||||||||||||
1008 | // file system mounted, wrongly capitalized drive letters will cause mismatches. | - | ||||||||||||||||||
1009 | return false; | - | ||||||||||||||||||
1010 | #elif defined(Q_OS_OSX) | - | ||||||||||||||||||
1011 | return pathconf(QFile::encodeName(path).constData(), _PC_CASE_SENSITIVE); | - | ||||||||||||||||||
1012 | #else | - | ||||||||||||||||||
1013 | return true; never executed: return true; | 0 | ||||||||||||||||||
1014 | #endif | - | ||||||||||||||||||
1015 | } | - | ||||||||||||||||||
1016 | - | |||||||||||||||||||
1017 | // Determine the file name to be set on the line edit from the path | - | ||||||||||||||||||
1018 | // passed to selectFile() in mode QFileDialog::AcceptSave. | - | ||||||||||||||||||
1019 | static inline QString fileFromPath(const QString &rootPath, QString path) | - | ||||||||||||||||||
1020 | { | - | ||||||||||||||||||
1021 | if (!QFileInfo(path).isAbsolute())
| 0 | ||||||||||||||||||
1022 | return path; never executed: return path; | 0 | ||||||||||||||||||
1023 | if (path.startsWith(rootPath, isCaseSensitiveFileSystem(rootPath) ? Qt::CaseSensitive : Qt::CaseInsensitive))
| 0 | ||||||||||||||||||
1024 | path.remove(0, rootPath.size()); never executed: path.remove(0, rootPath.size()); | 0 | ||||||||||||||||||
1025 | - | |||||||||||||||||||
1026 | if (path.isEmpty())
| 0 | ||||||||||||||||||
1027 | return path; never executed: return path; | 0 | ||||||||||||||||||
1028 | - | |||||||||||||||||||
1029 | if (path.at(0) == QDir::separator()
| 0 | ||||||||||||||||||
1030 | #ifdef Q_OS_WIN | - | ||||||||||||||||||
1031 | //On Windows both cases can happen | - | ||||||||||||||||||
1032 | || path.at(0) == QLatin1Char('/') | - | ||||||||||||||||||
1033 | #endif | - | ||||||||||||||||||
1034 | ) { | - | ||||||||||||||||||
1035 | path.remove(0, 1); | - | ||||||||||||||||||
1036 | } never executed: end of block | 0 | ||||||||||||||||||
1037 | return path; never executed: return path; | 0 | ||||||||||||||||||
1038 | } | - | ||||||||||||||||||
1039 | - | |||||||||||||||||||
1040 | /*! | - | ||||||||||||||||||
1041 | Selects the given \a filename in the file dialog. | - | ||||||||||||||||||
1042 | - | |||||||||||||||||||
1043 | \sa selectedFiles() | - | ||||||||||||||||||
1044 | */ | - | ||||||||||||||||||
1045 | void QFileDialog::selectFile(const QString &filename) | - | ||||||||||||||||||
1046 | { | - | ||||||||||||||||||
1047 | Q_D(QFileDialog); | - | ||||||||||||||||||
1048 | if (filename.isEmpty())
| 0 | ||||||||||||||||||
1049 | return; never executed: return; | 0 | ||||||||||||||||||
1050 | - | |||||||||||||||||||
1051 | if (!d->usingWidgets()) {
| 0 | ||||||||||||||||||
1052 | QUrl url = QUrl::fromLocalFile(filename); | - | ||||||||||||||||||
1053 | if (QFileInfo(filename).isRelative()) {
| 0 | ||||||||||||||||||
1054 | QDir dir(d->options->initialDirectory().toLocalFile()); | - | ||||||||||||||||||
1055 | url = QUrl::fromLocalFile(dir.absoluteFilePath(filename)); | - | ||||||||||||||||||
1056 | } never executed: end of block | 0 | ||||||||||||||||||
1057 | d->selectFile_sys(url); | - | ||||||||||||||||||
1058 | d->options->setInitiallySelectedFiles(QList<QUrl>() << url); | - | ||||||||||||||||||
1059 | return; never executed: return; | 0 | ||||||||||||||||||
1060 | } | - | ||||||||||||||||||
1061 | - | |||||||||||||||||||
1062 | if (!QDir::isRelativePath(filename)) {
| 0 | ||||||||||||||||||
1063 | QFileInfo info(filename); | - | ||||||||||||||||||
1064 | QString filenamePath = info.absoluteDir().path(); | - | ||||||||||||||||||
1065 | - | |||||||||||||||||||
1066 | if (d->model->rootPath() != filenamePath)
| 0 | ||||||||||||||||||
1067 | setDirectory(filenamePath); never executed: setDirectory(filenamePath); | 0 | ||||||||||||||||||
1068 | } never executed: end of block | 0 | ||||||||||||||||||
1069 | - | |||||||||||||||||||
1070 | QModelIndex index = d->model->index(filename); | - | ||||||||||||||||||
1071 | d->qFileDialogUi->listView->selectionModel()->clear(); | - | ||||||||||||||||||
1072 | if (!isVisible() || !d->lineEdit()->hasFocus())
| 0 | ||||||||||||||||||
1073 | d->lineEdit()->setText(index.isValid() ? index.data().toString() : fileFromPath(d->rootPath(), filename)); never executed: d->lineEdit()->setText(index.isValid() ? index.data().toString() : fileFromPath(d->rootPath(), filename)); | 0 | ||||||||||||||||||
1074 | } never executed: end of block | 0 | ||||||||||||||||||
1075 | - | |||||||||||||||||||
1076 | /*! | - | ||||||||||||||||||
1077 | Selects the given \a url in the file dialog. | - | ||||||||||||||||||
1078 | - | |||||||||||||||||||
1079 | \note The non-native QFileDialog supports only local files. | - | ||||||||||||||||||
1080 | - | |||||||||||||||||||
1081 | \sa selectedUrls() | - | ||||||||||||||||||
1082 | \since 5.2 | - | ||||||||||||||||||
1083 | */ | - | ||||||||||||||||||
1084 | void QFileDialog::selectUrl(const QUrl &url) | - | ||||||||||||||||||
1085 | { | - | ||||||||||||||||||
1086 | Q_D(QFileDialog); | - | ||||||||||||||||||
1087 | if (!url.isValid())
| 0 | ||||||||||||||||||
1088 | return; never executed: return; | 0 | ||||||||||||||||||
1089 | - | |||||||||||||||||||
1090 | if (d->nativeDialogInUse)
| 0 | ||||||||||||||||||
1091 | d->selectFile_sys(url); never executed: d->selectFile_sys(url); | 0 | ||||||||||||||||||
1092 | else if (url.isLocalFile())
| 0 | ||||||||||||||||||
1093 | selectFile(url.toLocalFile()); never executed: selectFile(url.toLocalFile()); | 0 | ||||||||||||||||||
1094 | else | - | ||||||||||||||||||
1095 | qWarning("Non-native QFileDialog supports only local files"); never executed: QMessageLogger(__FILE__, 1095, __PRETTY_FUNCTION__).warning("Non-native QFileDialog supports only local files"); | 0 | ||||||||||||||||||
1096 | } | - | ||||||||||||||||||
1097 | - | |||||||||||||||||||
1098 | #ifdef Q_OS_UNIX | - | ||||||||||||||||||
1099 | Q_AUTOTEST_EXPORT QString qt_tildeExpansion(const QString &path, bool *expanded = 0) | - | ||||||||||||||||||
1100 | { | - | ||||||||||||||||||
1101 | if (expanded != 0)
| 0 | ||||||||||||||||||
1102 | *expanded = false; never executed: *expanded = false; | 0 | ||||||||||||||||||
1103 | if (!path.startsWith(QLatin1Char('~')))
| 0 | ||||||||||||||||||
1104 | return path; never executed: return path; | 0 | ||||||||||||||||||
1105 | QString ret = path; | - | ||||||||||||||||||
1106 | QStringList tokens = ret.split(QDir::separator()); | - | ||||||||||||||||||
1107 | if (tokens.first() == QLatin1String("~")) {
| 0 | ||||||||||||||||||
1108 | ret.replace(0, 1, QDir::homePath()); | - | ||||||||||||||||||
1109 | } else { never executed: end of block | 0 | ||||||||||||||||||
1110 | QString userName = tokens.first(); | - | ||||||||||||||||||
1111 | userName.remove(0, 1); | - | ||||||||||||||||||
1112 | #if defined(Q_OS_VXWORKS) | - | ||||||||||||||||||
1113 | const QString homePath = QDir::homePath(); | - | ||||||||||||||||||
1114 | #elif defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) | - | ||||||||||||||||||
1115 | passwd pw; | - | ||||||||||||||||||
1116 | passwd *tmpPw; | - | ||||||||||||||||||
1117 | char buf[200]; | - | ||||||||||||||||||
1118 | const int bufSize = sizeof(buf); | - | ||||||||||||||||||
1119 | int err = 0; | - | ||||||||||||||||||
1120 | #if defined(Q_OS_SOLARIS) && (_POSIX_C_SOURCE - 0 < 199506L) | - | ||||||||||||||||||
1121 | tmpPw = getpwnam_r(userName.toLocal8Bit().constData(), &pw, buf, bufSize); | - | ||||||||||||||||||
1122 | #else | - | ||||||||||||||||||
1123 | err = getpwnam_r(userName.toLocal8Bit().constData(), &pw, buf, bufSize, &tmpPw); | - | ||||||||||||||||||
1124 | #endif | - | ||||||||||||||||||
1125 | if (err || !tmpPw)
| 0 | ||||||||||||||||||
1126 | return ret; never executed: return ret; | 0 | ||||||||||||||||||
1127 | const QString homePath = QString::fromLocal8Bit(pw.pw_dir); | - | ||||||||||||||||||
1128 | #else | - | ||||||||||||||||||
1129 | passwd *pw = getpwnam(userName.toLocal8Bit().constData()); | - | ||||||||||||||||||
1130 | if (!pw) | - | ||||||||||||||||||
1131 | return ret; | - | ||||||||||||||||||
1132 | const QString homePath = QString::fromLocal8Bit(pw->pw_dir); | - | ||||||||||||||||||
1133 | #endif | - | ||||||||||||||||||
1134 | ret.replace(0, tokens.first().length(), homePath); | - | ||||||||||||||||||
1135 | } never executed: end of block | 0 | ||||||||||||||||||
1136 | if (expanded != 0)
| 0 | ||||||||||||||||||
1137 | *expanded = true; never executed: *expanded = true; | 0 | ||||||||||||||||||
1138 | return ret; never executed: return ret; | 0 | ||||||||||||||||||
1139 | } | - | ||||||||||||||||||
1140 | #endif | - | ||||||||||||||||||
1141 | - | |||||||||||||||||||
1142 | /** | - | ||||||||||||||||||
1143 | Returns the text in the line edit which can be one or more file names | - | ||||||||||||||||||
1144 | */ | - | ||||||||||||||||||
1145 | QStringList QFileDialogPrivate::typedFiles() const | - | ||||||||||||||||||
1146 | { | - | ||||||||||||||||||
1147 | Q_Q(const QFileDialog); | - | ||||||||||||||||||
1148 | QStringList files; | - | ||||||||||||||||||
1149 | QString editText = lineEdit()->text(); | - | ||||||||||||||||||
1150 | if (!editText.contains(QLatin1Char('"'))) {
| 0 | ||||||||||||||||||
1151 | #ifdef Q_OS_UNIX | - | ||||||||||||||||||
1152 | const QString prefix = q->directory().absolutePath() + QDir::separator(); | - | ||||||||||||||||||
1153 | if (QFile::exists(prefix + editText))
| 0 | ||||||||||||||||||
1154 | files << editText; never executed: files << editText; | 0 | ||||||||||||||||||
1155 | else | - | ||||||||||||||||||
1156 | files << qt_tildeExpansion(editText); never executed: files << qt_tildeExpansion(editText); | 0 | ||||||||||||||||||
1157 | #else | - | ||||||||||||||||||
1158 | files << editText; | - | ||||||||||||||||||
1159 | Q_UNUSED(q) | - | ||||||||||||||||||
1160 | #endif | - | ||||||||||||||||||
1161 | } else { | - | ||||||||||||||||||
1162 | // " is used to separate files like so: "file1" "file2" "file3" ... | - | ||||||||||||||||||
1163 | // ### need escape character for filenames with quotes (") | - | ||||||||||||||||||
1164 | QStringList tokens = editText.split(QLatin1Char('\"')); | - | ||||||||||||||||||
1165 | for (int i=0; i<tokens.size(); ++i) {
| 0 | ||||||||||||||||||
1166 | if ((i % 2) == 0)
| 0 | ||||||||||||||||||
1167 | continue; // Every even token is a separator never executed: continue; | 0 | ||||||||||||||||||
1168 | #ifdef Q_OS_UNIX | - | ||||||||||||||||||
1169 | const QString token = tokens.at(i); | - | ||||||||||||||||||
1170 | const QString prefix = q->directory().absolutePath() + QDir::separator(); | - | ||||||||||||||||||
1171 | if (QFile::exists(prefix + token))
| 0 | ||||||||||||||||||
1172 | files << token; never executed: files << token; | 0 | ||||||||||||||||||
1173 | else | - | ||||||||||||||||||
1174 | files << qt_tildeExpansion(token); never executed: files << qt_tildeExpansion(token); | 0 | ||||||||||||||||||
1175 | #else | - | ||||||||||||||||||
1176 | files << toInternal(tokens.at(i)); | - | ||||||||||||||||||
1177 | #endif | - | ||||||||||||||||||
1178 | } | - | ||||||||||||||||||
1179 | } never executed: end of block | 0 | ||||||||||||||||||
1180 | return addDefaultSuffixToFiles(files); never executed: return addDefaultSuffixToFiles(files); | 0 | ||||||||||||||||||
1181 | } | - | ||||||||||||||||||
1182 | - | |||||||||||||||||||
1183 | // Return selected files without defaulting to the root of the file system model | - | ||||||||||||||||||
1184 | // used for initializing QFileDialogOptions for native dialogs. The default is | - | ||||||||||||||||||
1185 | // not suitable for native dialogs since it mostly equals directory(). | - | ||||||||||||||||||
1186 | QList<QUrl> QFileDialogPrivate::userSelectedFiles() const | - | ||||||||||||||||||
1187 | { | - | ||||||||||||||||||
1188 | QList<QUrl> files; | - | ||||||||||||||||||
1189 | - | |||||||||||||||||||
1190 | if (!usingWidgets())
| 0 | ||||||||||||||||||
1191 | return addDefaultSuffixToUrls(selectedFiles_sys()); never executed: return addDefaultSuffixToUrls(selectedFiles_sys()); | 0 | ||||||||||||||||||
1192 | - | |||||||||||||||||||
1193 | const QModelIndexList selectedRows = qFileDialogUi->listView->selectionModel()->selectedRows(); | - | ||||||||||||||||||
1194 | files.reserve(selectedRows.size()); | - | ||||||||||||||||||
1195 | foreach (const QModelIndex &index, selectedRows) | - | ||||||||||||||||||
1196 | files.append(QUrl::fromLocalFile(index.data(QFileSystemModel::FilePathRole).toString())); never executed: files.append(QUrl::fromLocalFile(index.data(QFileSystemModel::FilePathRole).toString())); | 0 | ||||||||||||||||||
1197 | - | |||||||||||||||||||
1198 | if (files.isEmpty() && !lineEdit()->text().isEmpty()) {
| 0 | ||||||||||||||||||
1199 | const QStringList typedFilesList = typedFiles(); | - | ||||||||||||||||||
1200 | files.reserve(typedFilesList.size()); | - | ||||||||||||||||||
1201 | foreach (const QString &path, typedFilesList) | - | ||||||||||||||||||
1202 | files.append(QUrl::fromLocalFile(path)); never executed: files.append(QUrl::fromLocalFile(path)); | 0 | ||||||||||||||||||
1203 | } never executed: end of block | 0 | ||||||||||||||||||
1204 | - | |||||||||||||||||||
1205 | return files; never executed: return files; | 0 | ||||||||||||||||||
1206 | } | - | ||||||||||||||||||
1207 | - | |||||||||||||||||||
1208 | QStringList QFileDialogPrivate::addDefaultSuffixToFiles(const QStringList &filesToFix) const | - | ||||||||||||||||||
1209 | { | - | ||||||||||||||||||
1210 | QStringList files; | - | ||||||||||||||||||
1211 | for (int i=0; i<filesToFix.size(); ++i) {
| 0 | ||||||||||||||||||
1212 | QString name = toInternal(filesToFix.at(i)); | - | ||||||||||||||||||
1213 | QFileInfo info(name); | - | ||||||||||||||||||
1214 | // if the filename has no suffix, add the default suffix | - | ||||||||||||||||||
1215 | const QString defaultSuffix = options->defaultSuffix(); | - | ||||||||||||||||||
1216 | if (!defaultSuffix.isEmpty() && !info.isDir() && name.lastIndexOf(QLatin1Char('.')) == -1)
| 0 | ||||||||||||||||||
1217 | name += QLatin1Char('.') + defaultSuffix; never executed: name += QLatin1Char('.') + defaultSuffix; | 0 | ||||||||||||||||||
1218 | if (info.isAbsolute()) {
| 0 | ||||||||||||||||||
1219 | files.append(name); | - | ||||||||||||||||||
1220 | } else { never executed: end of block | 0 | ||||||||||||||||||
1221 | // at this point the path should only have Qt path separators. | - | ||||||||||||||||||
1222 | // This check is needed since we might be at the root directory | - | ||||||||||||||||||
1223 | // and on Windows it already ends with slash. | - | ||||||||||||||||||
1224 | QString path = rootPath(); | - | ||||||||||||||||||
1225 | if (!path.endsWith(QLatin1Char('/')))
| 0 | ||||||||||||||||||
1226 | path += QLatin1Char('/'); never executed: path += QLatin1Char('/'); | 0 | ||||||||||||||||||
1227 | path += name; | - | ||||||||||||||||||
1228 | files.append(path); | - | ||||||||||||||||||
1229 | } never executed: end of block | 0 | ||||||||||||||||||
1230 | } | - | ||||||||||||||||||
1231 | return files; never executed: return files; | 0 | ||||||||||||||||||
1232 | } | - | ||||||||||||||||||
1233 | - | |||||||||||||||||||
1234 | QList<QUrl> QFileDialogPrivate::addDefaultSuffixToUrls(const QList<QUrl> &urlsToFix) const | - | ||||||||||||||||||
1235 | { | - | ||||||||||||||||||
1236 | QList<QUrl> urls; | - | ||||||||||||||||||
1237 | const int numUrlsToFix = urlsToFix.size(); | - | ||||||||||||||||||
1238 | urls.reserve(numUrlsToFix); | - | ||||||||||||||||||
1239 | for (int i = 0; i < numUrlsToFix; ++i) {
| 0 | ||||||||||||||||||
1240 | QUrl url = urlsToFix.at(i); | - | ||||||||||||||||||
1241 | // if the filename has no suffix, add the default suffix | - | ||||||||||||||||||
1242 | const QString defaultSuffix = options->defaultSuffix(); | - | ||||||||||||||||||
1243 | if (!defaultSuffix.isEmpty() && !url.path().endsWith(QLatin1Char('/')) && url.path().lastIndexOf(QLatin1Char('.')) == -1)
| 0 | ||||||||||||||||||
1244 | url.setPath(url.path() + QLatin1Char('.') + defaultSuffix); never executed: url.setPath(url.path() + QLatin1Char('.') + defaultSuffix); | 0 | ||||||||||||||||||
1245 | urls.append(url); | - | ||||||||||||||||||
1246 | } never executed: end of block | 0 | ||||||||||||||||||
1247 | return urls; never executed: return urls; | 0 | ||||||||||||||||||
1248 | } | - | ||||||||||||||||||
1249 | - | |||||||||||||||||||
1250 | - | |||||||||||||||||||
1251 | /*! | - | ||||||||||||||||||
1252 | Returns a list of strings containing the absolute paths of the | - | ||||||||||||||||||
1253 | selected files in the dialog. If no files are selected, or | - | ||||||||||||||||||
1254 | the mode is not ExistingFiles or ExistingFile, selectedFiles() contains the current path in the viewport. | - | ||||||||||||||||||
1255 | - | |||||||||||||||||||
1256 | \sa selectedNameFilter(), selectFile() | - | ||||||||||||||||||
1257 | */ | - | ||||||||||||||||||
1258 | QStringList QFileDialog::selectedFiles() const | - | ||||||||||||||||||
1259 | { | - | ||||||||||||||||||
1260 | Q_D(const QFileDialog); | - | ||||||||||||||||||
1261 | - | |||||||||||||||||||
1262 | QStringList files; | - | ||||||||||||||||||
1263 | const QList<QUrl> userSelectedFiles = d->userSelectedFiles(); | - | ||||||||||||||||||
1264 | files.reserve(userSelectedFiles.size()); | - | ||||||||||||||||||
1265 | foreach (const QUrl &file, userSelectedFiles) | - | ||||||||||||||||||
1266 | files.append(file.toLocalFile()); never executed: files.append(file.toLocalFile()); | 0 | ||||||||||||||||||
1267 | if (files.isEmpty() && d->usingWidgets()) {
| 0 | ||||||||||||||||||
1268 | const FileMode fm = fileMode(); | - | ||||||||||||||||||
1269 | if (fm != ExistingFile && fm != ExistingFiles)
| 0 | ||||||||||||||||||
1270 | files.append(d->rootIndex().data(QFileSystemModel::FilePathRole).toString()); never executed: files.append(d->rootIndex().data(QFileSystemModel::FilePathRole).toString()); | 0 | ||||||||||||||||||
1271 | } never executed: end of block | 0 | ||||||||||||||||||
1272 | return files; never executed: return files; | 0 | ||||||||||||||||||
1273 | } | - | ||||||||||||||||||
1274 | - | |||||||||||||||||||
1275 | /*! | - | ||||||||||||||||||
1276 | Returns a list of urls containing the selected files in the dialog. | - | ||||||||||||||||||
1277 | If no files are selected, or the mode is not ExistingFiles or | - | ||||||||||||||||||
1278 | ExistingFile, selectedUrls() contains the current path in the viewport. | - | ||||||||||||||||||
1279 | - | |||||||||||||||||||
1280 | \sa selectedNameFilter(), selectUrl() | - | ||||||||||||||||||
1281 | \since 5.2 | - | ||||||||||||||||||
1282 | */ | - | ||||||||||||||||||
1283 | QList<QUrl> QFileDialog::selectedUrls() const | - | ||||||||||||||||||
1284 | { | - | ||||||||||||||||||
1285 | Q_D(const QFileDialog); | - | ||||||||||||||||||
1286 | if (d->nativeDialogInUse) {
| 0 | ||||||||||||||||||
1287 | return d->userSelectedFiles(); never executed: return d->userSelectedFiles(); | 0 | ||||||||||||||||||
1288 | } else { | - | ||||||||||||||||||
1289 | QList<QUrl> urls; | - | ||||||||||||||||||
1290 | const QStringList selectedFileList = selectedFiles(); | - | ||||||||||||||||||
1291 | urls.reserve(selectedFileList.size()); | - | ||||||||||||||||||
1292 | foreach (const QString &file, selectedFileList) | - | ||||||||||||||||||
1293 | urls.append(QUrl::fromLocalFile(file)); never executed: urls.append(QUrl::fromLocalFile(file)); | 0 | ||||||||||||||||||
1294 | return urls; never executed: return urls; | 0 | ||||||||||||||||||
1295 | } | - | ||||||||||||||||||
1296 | } | - | ||||||||||||||||||
1297 | - | |||||||||||||||||||
1298 | /* | - | ||||||||||||||||||
1299 | Makes a list of filters from ;;-separated text. | - | ||||||||||||||||||
1300 | Used by the mac and windows implementations | - | ||||||||||||||||||
1301 | */ | - | ||||||||||||||||||
1302 | QStringList qt_make_filter_list(const QString &filter) | - | ||||||||||||||||||
1303 | { | - | ||||||||||||||||||
1304 | QString f(filter); | - | ||||||||||||||||||
1305 | - | |||||||||||||||||||
1306 | if (f.isEmpty())
| 0 | ||||||||||||||||||
1307 | return QStringList(); never executed: return QStringList(); | 0 | ||||||||||||||||||
1308 | - | |||||||||||||||||||
1309 | QString sep(QLatin1String(";;")); | - | ||||||||||||||||||
1310 | int i = f.indexOf(sep, 0); | - | ||||||||||||||||||
1311 | if (i == -1) {
| 0 | ||||||||||||||||||
1312 | if (f.indexOf(QLatin1Char('\n'), 0) != -1) {
| 0 | ||||||||||||||||||
1313 | sep = QLatin1Char('\n'); | - | ||||||||||||||||||
1314 | i = f.indexOf(sep, 0); | - | ||||||||||||||||||
1315 | } never executed: end of block | 0 | ||||||||||||||||||
1316 | } never executed: end of block | 0 | ||||||||||||||||||
1317 | - | |||||||||||||||||||
1318 | return f.split(sep); never executed: return f.split(sep); | 0 | ||||||||||||||||||
1319 | } | - | ||||||||||||||||||
1320 | - | |||||||||||||||||||
1321 | /*! | - | ||||||||||||||||||
1322 | \since 4.4 | - | ||||||||||||||||||
1323 | - | |||||||||||||||||||
1324 | Sets the filter used in the file dialog to the given \a filter. | - | ||||||||||||||||||
1325 | - | |||||||||||||||||||
1326 | If \a filter contains a pair of parentheses containing one or more | - | ||||||||||||||||||
1327 | filename-wildcard patterns, separated by spaces, then only the | - | ||||||||||||||||||
1328 | text contained in the parentheses is used as the filter. This means | - | ||||||||||||||||||
1329 | that these calls are all equivalent: | - | ||||||||||||||||||
1330 | - | |||||||||||||||||||
1331 | \snippet code/src_gui_dialogs_qfiledialog.cpp 6 | - | ||||||||||||||||||
1332 | - | |||||||||||||||||||
1333 | \sa setMimeTypeFilters(), setNameFilters() | - | ||||||||||||||||||
1334 | */ | - | ||||||||||||||||||
1335 | void QFileDialog::setNameFilter(const QString &filter) | - | ||||||||||||||||||
1336 | { | - | ||||||||||||||||||
1337 | setNameFilters(qt_make_filter_list(filter)); | - | ||||||||||||||||||
1338 | } never executed: end of block | 0 | ||||||||||||||||||
1339 | - | |||||||||||||||||||
1340 | - | |||||||||||||||||||
1341 | /*! | - | ||||||||||||||||||
1342 | \property QFileDialog::nameFilterDetailsVisible | - | ||||||||||||||||||
1343 | \obsolete | - | ||||||||||||||||||
1344 | \brief This property holds whether the filter details is shown or not. | - | ||||||||||||||||||
1345 | \since 4.4 | - | ||||||||||||||||||
1346 | - | |||||||||||||||||||
1347 | When this property is \c true (the default), the filter details are shown | - | ||||||||||||||||||
1348 | in the combo box. When the property is set to false, these are hidden. | - | ||||||||||||||||||
1349 | - | |||||||||||||||||||
1350 | Use setOption(HideNameFilterDetails, !\e enabled) or | - | ||||||||||||||||||
1351 | !testOption(HideNameFilterDetails). | - | ||||||||||||||||||
1352 | */ | - | ||||||||||||||||||
1353 | void QFileDialog::setNameFilterDetailsVisible(bool enabled) | - | ||||||||||||||||||
1354 | { | - | ||||||||||||||||||
1355 | setOption(HideNameFilterDetails, !enabled); | - | ||||||||||||||||||
1356 | } never executed: end of block | 0 | ||||||||||||||||||
1357 | - | |||||||||||||||||||
1358 | bool QFileDialog::isNameFilterDetailsVisible() const | - | ||||||||||||||||||
1359 | { | - | ||||||||||||||||||
1360 | return !testOption(HideNameFilterDetails); never executed: return !testOption(HideNameFilterDetails); | 0 | ||||||||||||||||||
1361 | } | - | ||||||||||||||||||
1362 | - | |||||||||||||||||||
1363 | - | |||||||||||||||||||
1364 | /* | - | ||||||||||||||||||
1365 | Strip the filters by removing the details, e.g. (*.*). | - | ||||||||||||||||||
1366 | */ | - | ||||||||||||||||||
1367 | QStringList qt_strip_filters(const QStringList &filters) | - | ||||||||||||||||||
1368 | { | - | ||||||||||||||||||
1369 | QStringList strippedFilters; | - | ||||||||||||||||||
1370 | QRegExp r(QString::fromLatin1(QPlatformFileDialogHelper::filterRegExp)); | - | ||||||||||||||||||
1371 | const int numFilters = filters.count(); | - | ||||||||||||||||||
1372 | strippedFilters.reserve(numFilters); | - | ||||||||||||||||||
1373 | for (int i = 0; i < numFilters; ++i) {
| 0 | ||||||||||||||||||
1374 | QString filterName; | - | ||||||||||||||||||
1375 | int index = r.indexIn(filters[i]); | - | ||||||||||||||||||
1376 | if (index >= 0)
| 0 | ||||||||||||||||||
1377 | filterName = r.cap(1); never executed: filterName = r.cap(1); | 0 | ||||||||||||||||||
1378 | strippedFilters.append(filterName.simplified()); | - | ||||||||||||||||||
1379 | } never executed: end of block | 0 | ||||||||||||||||||
1380 | return strippedFilters; never executed: return strippedFilters; | 0 | ||||||||||||||||||
1381 | } | - | ||||||||||||||||||
1382 | - | |||||||||||||||||||
1383 | - | |||||||||||||||||||
1384 | /*! | - | ||||||||||||||||||
1385 | \since 4.4 | - | ||||||||||||||||||
1386 | - | |||||||||||||||||||
1387 | Sets the \a filters used in the file dialog. | - | ||||||||||||||||||
1388 | - | |||||||||||||||||||
1389 | Note that the filter \b{*.*} is not portable, because the historical | - | ||||||||||||||||||
1390 | assumption that the file extension determines the file type is not | - | ||||||||||||||||||
1391 | consistent on every operating system. It is possible to have a file with no | - | ||||||||||||||||||
1392 | dot in its name (for example, \c Makefile). In a native Windows file | - | ||||||||||||||||||
1393 | dialog, \b{*.*} will match such files, while in other types of file dialogs | - | ||||||||||||||||||
1394 | it may not. So it is better to use \b{*} if you mean to select any file. | - | ||||||||||||||||||
1395 | - | |||||||||||||||||||
1396 | \snippet code/src_gui_dialogs_qfiledialog.cpp 7 | - | ||||||||||||||||||
1397 | - | |||||||||||||||||||
1398 | \l setMimeTypeFilters() has the advantage of providing all possible name | - | ||||||||||||||||||
1399 | filters for each file type. For example, JPEG images have three possible | - | ||||||||||||||||||
1400 | extensions; if your application can open such files, selecting the | - | ||||||||||||||||||
1401 | \c image/jpeg mime type as a filter will allow you to open all of them. | - | ||||||||||||||||||
1402 | */ | - | ||||||||||||||||||
1403 | void QFileDialog::setNameFilters(const QStringList &filters) | - | ||||||||||||||||||
1404 | { | - | ||||||||||||||||||
1405 | Q_D(QFileDialog); | - | ||||||||||||||||||
1406 | d->defaultFileTypes = (filters == QStringList(QFileDialog::tr("All Files (*)"))); | - | ||||||||||||||||||
1407 | QStringList cleanedFilters; | - | ||||||||||||||||||
1408 | const int numFilters = filters.count(); | - | ||||||||||||||||||
1409 | cleanedFilters.reserve(numFilters); | - | ||||||||||||||||||
1410 | for (int i = 0; i < numFilters; ++i) {
| 0 | ||||||||||||||||||
1411 | cleanedFilters << filters[i].simplified(); | - | ||||||||||||||||||
1412 | } never executed: end of block | 0 | ||||||||||||||||||
1413 | d->options->setNameFilters(cleanedFilters); | - | ||||||||||||||||||
1414 | - | |||||||||||||||||||
1415 | if (!d->usingWidgets())
| 0 | ||||||||||||||||||
1416 | return; never executed: return; | 0 | ||||||||||||||||||
1417 | - | |||||||||||||||||||
1418 | d->qFileDialogUi->fileTypeCombo->clear(); | - | ||||||||||||||||||
1419 | if (cleanedFilters.isEmpty())
| 0 | ||||||||||||||||||
1420 | return; never executed: return; | 0 | ||||||||||||||||||
1421 | - | |||||||||||||||||||
1422 | if (testOption(HideNameFilterDetails))
| 0 | ||||||||||||||||||
1423 | d->qFileDialogUi->fileTypeCombo->addItems(qt_strip_filters(cleanedFilters)); never executed: d->qFileDialogUi->fileTypeCombo->addItems(qt_strip_filters(cleanedFilters)); | 0 | ||||||||||||||||||
1424 | else | - | ||||||||||||||||||
1425 | d->qFileDialogUi->fileTypeCombo->addItems(cleanedFilters); never executed: d->qFileDialogUi->fileTypeCombo->addItems(cleanedFilters); | 0 | ||||||||||||||||||
1426 | - | |||||||||||||||||||
1427 | d->_q_useNameFilter(0); | - | ||||||||||||||||||
1428 | } never executed: end of block | 0 | ||||||||||||||||||
1429 | - | |||||||||||||||||||
1430 | /*! | - | ||||||||||||||||||
1431 | \since 4.4 | - | ||||||||||||||||||
1432 | - | |||||||||||||||||||
1433 | Returns the file type filters that are in operation on this file | - | ||||||||||||||||||
1434 | dialog. | - | ||||||||||||||||||
1435 | */ | - | ||||||||||||||||||
1436 | QStringList QFileDialog::nameFilters() const | - | ||||||||||||||||||
1437 | { | - | ||||||||||||||||||
1438 | return d_func()->options->nameFilters(); never executed: return d_func()->options->nameFilters(); | 0 | ||||||||||||||||||
1439 | } | - | ||||||||||||||||||
1440 | - | |||||||||||||||||||
1441 | /*! | - | ||||||||||||||||||
1442 | \since 4.4 | - | ||||||||||||||||||
1443 | - | |||||||||||||||||||
1444 | Sets the current file type \a filter. Multiple filters can be | - | ||||||||||||||||||
1445 | passed in \a filter by separating them with semicolons or spaces. | - | ||||||||||||||||||
1446 | - | |||||||||||||||||||
1447 | \sa setNameFilter(), setNameFilters(), selectedNameFilter() | - | ||||||||||||||||||
1448 | */ | - | ||||||||||||||||||
1449 | void QFileDialog::selectNameFilter(const QString &filter) | - | ||||||||||||||||||
1450 | { | - | ||||||||||||||||||
1451 | Q_D(QFileDialog); | - | ||||||||||||||||||
1452 | d->options->setInitiallySelectedNameFilter(filter); | - | ||||||||||||||||||
1453 | if (!d->usingWidgets()) {
| 0 | ||||||||||||||||||
1454 | d->selectNameFilter_sys(filter); | - | ||||||||||||||||||
1455 | return; never executed: return; | 0 | ||||||||||||||||||
1456 | } | - | ||||||||||||||||||
1457 | int i = -1; | - | ||||||||||||||||||
1458 | if (testOption(HideNameFilterDetails)) {
| 0 | ||||||||||||||||||
1459 | const QStringList filters = qt_strip_filters(qt_make_filter_list(filter)); | - | ||||||||||||||||||
1460 | if (!filters.isEmpty())
| 0 | ||||||||||||||||||
1461 | i = d->qFileDialogUi->fileTypeCombo->findText(filters.first()); never executed: i = d->qFileDialogUi->fileTypeCombo->findText(filters.first()); | 0 | ||||||||||||||||||
1462 | } else { never executed: end of block | 0 | ||||||||||||||||||
1463 | i = d->qFileDialogUi->fileTypeCombo->findText(filter); | - | ||||||||||||||||||
1464 | } never executed: end of block | 0 | ||||||||||||||||||
1465 | if (i >= 0) {
| 0 | ||||||||||||||||||
1466 | d->qFileDialogUi->fileTypeCombo->setCurrentIndex(i); | - | ||||||||||||||||||
1467 | d->_q_useNameFilter(d->qFileDialogUi->fileTypeCombo->currentIndex()); | - | ||||||||||||||||||
1468 | } never executed: end of block | 0 | ||||||||||||||||||
1469 | } never executed: end of block | 0 | ||||||||||||||||||
1470 | - | |||||||||||||||||||
1471 | /*! | - | ||||||||||||||||||
1472 | \since 4.4 | - | ||||||||||||||||||
1473 | - | |||||||||||||||||||
1474 | Returns the filter that the user selected in the file dialog. | - | ||||||||||||||||||
1475 | - | |||||||||||||||||||
1476 | \sa selectedFiles() | - | ||||||||||||||||||
1477 | */ | - | ||||||||||||||||||
1478 | QString QFileDialog::selectedNameFilter() const | - | ||||||||||||||||||
1479 | { | - | ||||||||||||||||||
1480 | Q_D(const QFileDialog); | - | ||||||||||||||||||
1481 | if (!d->usingWidgets())
| 0 | ||||||||||||||||||
1482 | return d->selectedNameFilter_sys(); never executed: return d->selectedNameFilter_sys(); | 0 | ||||||||||||||||||
1483 | - | |||||||||||||||||||
1484 | return d->qFileDialogUi->fileTypeCombo->currentText(); never executed: return d->qFileDialogUi->fileTypeCombo->currentText(); | 0 | ||||||||||||||||||
1485 | } | - | ||||||||||||||||||
1486 | - | |||||||||||||||||||
1487 | /*! | - | ||||||||||||||||||
1488 | \since 4.4 | - | ||||||||||||||||||
1489 | - | |||||||||||||||||||
1490 | Returns the filter that is used when displaying files. | - | ||||||||||||||||||
1491 | - | |||||||||||||||||||
1492 | \sa setFilter() | - | ||||||||||||||||||
1493 | */ | - | ||||||||||||||||||
1494 | QDir::Filters QFileDialog::filter() const | - | ||||||||||||||||||
1495 | { | - | ||||||||||||||||||
1496 | Q_D(const QFileDialog); | - | ||||||||||||||||||
1497 | if (d->usingWidgets())
| 0 | ||||||||||||||||||
1498 | return d->model->filter(); never executed: return d->model->filter(); | 0 | ||||||||||||||||||
1499 | return d->options->filter(); never executed: return d->options->filter(); | 0 | ||||||||||||||||||
1500 | } | - | ||||||||||||||||||
1501 | - | |||||||||||||||||||
1502 | /*! | - | ||||||||||||||||||
1503 | \since 4.4 | - | ||||||||||||||||||
1504 | - | |||||||||||||||||||
1505 | Sets the filter used by the model to \a filters. The filter is used | - | ||||||||||||||||||
1506 | to specify the kind of files that should be shown. | - | ||||||||||||||||||
1507 | - | |||||||||||||||||||
1508 | \sa filter() | - | ||||||||||||||||||
1509 | */ | - | ||||||||||||||||||
1510 | - | |||||||||||||||||||
1511 | void QFileDialog::setFilter(QDir::Filters filters) | - | ||||||||||||||||||
1512 | { | - | ||||||||||||||||||
1513 | Q_D(QFileDialog); | - | ||||||||||||||||||
1514 | d->options->setFilter(filters); | - | ||||||||||||||||||
1515 | if (!d->usingWidgets()) {
| 0 | ||||||||||||||||||
1516 | d->setFilter_sys(); | - | ||||||||||||||||||
1517 | return; never executed: return; | 0 | ||||||||||||||||||
1518 | } | - | ||||||||||||||||||
1519 | - | |||||||||||||||||||
1520 | d->model->setFilter(filters); | - | ||||||||||||||||||
1521 | d->showHiddenAction->setChecked((filters & QDir::Hidden)); | - | ||||||||||||||||||
1522 | } never executed: end of block | 0 | ||||||||||||||||||
1523 | - | |||||||||||||||||||
1524 | #ifndef QT_NO_MIMETYPE | - | ||||||||||||||||||
1525 | - | |||||||||||||||||||
1526 | static QString nameFilterForMime(const QString &mimeType) | - | ||||||||||||||||||
1527 | { | - | ||||||||||||||||||
1528 | QMimeDatabase db; | - | ||||||||||||||||||
1529 | QMimeType mime(db.mimeTypeForName(mimeType)); | - | ||||||||||||||||||
1530 | if (mime.isValid()) {
| 0 | ||||||||||||||||||
1531 | if (mime.isDefault()) {
| 0 | ||||||||||||||||||
1532 | return QFileDialog::tr("All files (*)"); never executed: return QFileDialog::tr("All files (*)"); | 0 | ||||||||||||||||||
1533 | } else { | - | ||||||||||||||||||
1534 | const QString patterns = mime.globPatterns().join(QLatin1Char(' ')); | - | ||||||||||||||||||
1535 | return mime.comment() + QStringLiteral(" (") + patterns + QLatin1Char(')'); never executed: return mime.comment() + ([]() -> QString { enum { Size = sizeof(u"" " (")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" " (" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()) + patterns + QLatin1Char(')'); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
1536 | } | - | ||||||||||||||||||
1537 | } | - | ||||||||||||||||||
1538 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
1539 | } | - | ||||||||||||||||||
1540 | - | |||||||||||||||||||
1541 | /*! | - | ||||||||||||||||||
1542 | \since 5.2 | - | ||||||||||||||||||
1543 | - | |||||||||||||||||||
1544 | Sets the \a filters used in the file dialog, from a list of MIME types. | - | ||||||||||||||||||
1545 | - | |||||||||||||||||||
1546 | Convenience method for setNameFilters(). | - | ||||||||||||||||||
1547 | Uses QMimeType to create a name filter from the glob patterns and description | - | ||||||||||||||||||
1548 | defined in each MIME type. | - | ||||||||||||||||||
1549 | - | |||||||||||||||||||
1550 | Use application/octet-stream for the "All files (*)" filter, since that | - | ||||||||||||||||||
1551 | is the base MIME type for all files. | - | ||||||||||||||||||
1552 | - | |||||||||||||||||||
1553 | Calling setMimeTypeFilters overrides any previously set name filters, | - | ||||||||||||||||||
1554 | and changes the return value of nameFilters(). | - | ||||||||||||||||||
1555 | - | |||||||||||||||||||
1556 | \snippet code/src_gui_dialogs_qfiledialog.cpp 13 | - | ||||||||||||||||||
1557 | */ | - | ||||||||||||||||||
1558 | void QFileDialog::setMimeTypeFilters(const QStringList &filters) | - | ||||||||||||||||||
1559 | { | - | ||||||||||||||||||
1560 | Q_D(QFileDialog); | - | ||||||||||||||||||
1561 | QStringList nameFilters; | - | ||||||||||||||||||
1562 | foreach (const QString &mimeType, filters) { | - | ||||||||||||||||||
1563 | const QString text = nameFilterForMime(mimeType); | - | ||||||||||||||||||
1564 | if (!text.isEmpty())
| 0 | ||||||||||||||||||
1565 | nameFilters.append(text); never executed: nameFilters.append(text); | 0 | ||||||||||||||||||
1566 | } never executed: end of block | 0 | ||||||||||||||||||
1567 | setNameFilters(nameFilters); | - | ||||||||||||||||||
1568 | d->options->setMimeTypeFilters(filters); | - | ||||||||||||||||||
1569 | } never executed: end of block | 0 | ||||||||||||||||||
1570 | - | |||||||||||||||||||
1571 | /*! | - | ||||||||||||||||||
1572 | \since 5.2 | - | ||||||||||||||||||
1573 | - | |||||||||||||||||||
1574 | Returns the MIME type filters that are in operation on this file | - | ||||||||||||||||||
1575 | dialog. | - | ||||||||||||||||||
1576 | */ | - | ||||||||||||||||||
1577 | QStringList QFileDialog::mimeTypeFilters() const | - | ||||||||||||||||||
1578 | { | - | ||||||||||||||||||
1579 | return d_func()->options->mimeTypeFilters(); never executed: return d_func()->options->mimeTypeFilters(); | 0 | ||||||||||||||||||
1580 | } | - | ||||||||||||||||||
1581 | - | |||||||||||||||||||
1582 | /*! | - | ||||||||||||||||||
1583 | \since 5.2 | - | ||||||||||||||||||
1584 | - | |||||||||||||||||||
1585 | Sets the current MIME type \a filter. | - | ||||||||||||||||||
1586 | - | |||||||||||||||||||
1587 | */ | - | ||||||||||||||||||
1588 | void QFileDialog::selectMimeTypeFilter(const QString &filter) | - | ||||||||||||||||||
1589 | { | - | ||||||||||||||||||
1590 | const QString text = nameFilterForMime(filter); | - | ||||||||||||||||||
1591 | if (!text.isEmpty())
| 0 | ||||||||||||||||||
1592 | selectNameFilter(text); never executed: selectNameFilter(text); | 0 | ||||||||||||||||||
1593 | } never executed: end of block | 0 | ||||||||||||||||||
1594 | - | |||||||||||||||||||
1595 | #endif // QT_NO_MIMETYPE | - | ||||||||||||||||||
1596 | - | |||||||||||||||||||
1597 | /*! | - | ||||||||||||||||||
1598 | \property QFileDialog::viewMode | - | ||||||||||||||||||
1599 | \brief the way files and directories are displayed in the dialog | - | ||||||||||||||||||
1600 | - | |||||||||||||||||||
1601 | By default, the \c Detail mode is used to display information about | - | ||||||||||||||||||
1602 | files and directories. | - | ||||||||||||||||||
1603 | - | |||||||||||||||||||
1604 | \sa ViewMode | - | ||||||||||||||||||
1605 | */ | - | ||||||||||||||||||
1606 | void QFileDialog::setViewMode(QFileDialog::ViewMode mode) | - | ||||||||||||||||||
1607 | { | - | ||||||||||||||||||
1608 | Q_D(QFileDialog); | - | ||||||||||||||||||
1609 | d->options->setViewMode(static_cast<QFileDialogOptions::ViewMode>(mode)); | - | ||||||||||||||||||
1610 | if (!d->usingWidgets())
| 0 | ||||||||||||||||||
1611 | return; never executed: return; | 0 | ||||||||||||||||||
1612 | if (mode == Detail)
| 0 | ||||||||||||||||||
1613 | d->_q_showDetailsView(); never executed: d->_q_showDetailsView(); | 0 | ||||||||||||||||||
1614 | else | - | ||||||||||||||||||
1615 | d->_q_showListView(); never executed: d->_q_showListView(); | 0 | ||||||||||||||||||
1616 | } | - | ||||||||||||||||||
1617 | - | |||||||||||||||||||
1618 | QFileDialog::ViewMode QFileDialog::viewMode() const | - | ||||||||||||||||||
1619 | { | - | ||||||||||||||||||
1620 | Q_D(const QFileDialog); | - | ||||||||||||||||||
1621 | if (!d->usingWidgets())
| 0 | ||||||||||||||||||
1622 | return static_cast<QFileDialog::ViewMode>(d->options->viewMode()); never executed: return static_cast<QFileDialog::ViewMode>(d->options->viewMode()); | 0 | ||||||||||||||||||
1623 | return (d->qFileDialogUi->stackedWidget->currentWidget() == d->qFileDialogUi->listView->parent() ? QFileDialog::List : QFileDialog::Detail); never executed: return (d->qFileDialogUi->stackedWidget->currentWidget() == d->qFileDialogUi->listView->parent() ? QFileDialog::List : QFileDialog::Detail);
| 0 | ||||||||||||||||||
1624 | } | - | ||||||||||||||||||
1625 | - | |||||||||||||||||||
1626 | /*! | - | ||||||||||||||||||
1627 | \property QFileDialog::fileMode | - | ||||||||||||||||||
1628 | \brief the file mode of the dialog | - | ||||||||||||||||||
1629 | - | |||||||||||||||||||
1630 | The file mode defines the number and type of items that the user is | - | ||||||||||||||||||
1631 | expected to select in the dialog. | - | ||||||||||||||||||
1632 | - | |||||||||||||||||||
1633 | By default, this property is set to AnyFile. | - | ||||||||||||||||||
1634 | - | |||||||||||||||||||
1635 | This function will set the labels for the FileName and | - | ||||||||||||||||||
1636 | \l{QFileDialog::}{Accept} \l{DialogLabel}s. It is possible to set | - | ||||||||||||||||||
1637 | custom text after the call to setFileMode(). | - | ||||||||||||||||||
1638 | - | |||||||||||||||||||
1639 | \sa FileMode | - | ||||||||||||||||||
1640 | */ | - | ||||||||||||||||||
1641 | void QFileDialog::setFileMode(QFileDialog::FileMode mode) | - | ||||||||||||||||||
1642 | { | - | ||||||||||||||||||
1643 | Q_D(QFileDialog); | - | ||||||||||||||||||
1644 | d->options->setFileMode(static_cast<QFileDialogOptions::FileMode>(mode)); | - | ||||||||||||||||||
1645 | - | |||||||||||||||||||
1646 | // keep ShowDirsOnly option in sync with fileMode (BTW, DirectoryOnly is obsolete) | - | ||||||||||||||||||
1647 | setOption(ShowDirsOnly, mode == DirectoryOnly); | - | ||||||||||||||||||
1648 | - | |||||||||||||||||||
1649 | if (!d->usingWidgets())
| 0 | ||||||||||||||||||
1650 | return; never executed: return; | 0 | ||||||||||||||||||
1651 | - | |||||||||||||||||||
1652 | d->retranslateWindowTitle(); | - | ||||||||||||||||||
1653 | - | |||||||||||||||||||
1654 | // set selection mode and behavior | - | ||||||||||||||||||
1655 | QAbstractItemView::SelectionMode selectionMode; | - | ||||||||||||||||||
1656 | if (mode == QFileDialog::ExistingFiles)
| 0 | ||||||||||||||||||
1657 | selectionMode = QAbstractItemView::ExtendedSelection; never executed: selectionMode = QAbstractItemView::ExtendedSelection; | 0 | ||||||||||||||||||
1658 | else | - | ||||||||||||||||||
1659 | selectionMode = QAbstractItemView::SingleSelection; never executed: selectionMode = QAbstractItemView::SingleSelection; | 0 | ||||||||||||||||||
1660 | d->qFileDialogUi->listView->setSelectionMode(selectionMode); | - | ||||||||||||||||||
1661 | d->qFileDialogUi->treeView->setSelectionMode(selectionMode); | - | ||||||||||||||||||
1662 | // set filter | - | ||||||||||||||||||
1663 | d->model->setFilter(d->filterForMode(filter())); | - | ||||||||||||||||||
1664 | // setup file type for directory | - | ||||||||||||||||||
1665 | if (mode == DirectoryOnly || mode == Directory) {
| 0 | ||||||||||||||||||
1666 | d->qFileDialogUi->fileTypeCombo->clear(); | - | ||||||||||||||||||
1667 | d->qFileDialogUi->fileTypeCombo->addItem(tr("Directories")); | - | ||||||||||||||||||
1668 | d->qFileDialogUi->fileTypeCombo->setEnabled(false); | - | ||||||||||||||||||
1669 | } never executed: end of block | 0 | ||||||||||||||||||
1670 | d->updateFileNameLabel(); | - | ||||||||||||||||||
1671 | d->updateOkButtonText(); | - | ||||||||||||||||||
1672 | d->qFileDialogUi->fileTypeCombo->setEnabled(!testOption(ShowDirsOnly)); | - | ||||||||||||||||||
1673 | d->_q_updateOkButton(); | - | ||||||||||||||||||
1674 | } never executed: end of block | 0 | ||||||||||||||||||
1675 | - | |||||||||||||||||||
1676 | QFileDialog::FileMode QFileDialog::fileMode() const | - | ||||||||||||||||||
1677 | { | - | ||||||||||||||||||
1678 | Q_D(const QFileDialog); | - | ||||||||||||||||||
1679 | return static_cast<FileMode>(d->options->fileMode()); never executed: return static_cast<FileMode>(d->options->fileMode()); | 0 | ||||||||||||||||||
1680 | } | - | ||||||||||||||||||
1681 | - | |||||||||||||||||||
1682 | /*! | - | ||||||||||||||||||
1683 | \property QFileDialog::acceptMode | - | ||||||||||||||||||
1684 | \brief the accept mode of the dialog | - | ||||||||||||||||||
1685 | - | |||||||||||||||||||
1686 | The action mode defines whether the dialog is for opening or saving files. | - | ||||||||||||||||||
1687 | - | |||||||||||||||||||
1688 | By default, this property is set to \l{AcceptOpen}. | - | ||||||||||||||||||
1689 | - | |||||||||||||||||||
1690 | \sa AcceptMode | - | ||||||||||||||||||
1691 | */ | - | ||||||||||||||||||
1692 | void QFileDialog::setAcceptMode(QFileDialog::AcceptMode mode) | - | ||||||||||||||||||
1693 | { | - | ||||||||||||||||||
1694 | Q_D(QFileDialog); | - | ||||||||||||||||||
1695 | d->options->setAcceptMode(static_cast<QFileDialogOptions::AcceptMode>(mode)); | - | ||||||||||||||||||
1696 | // clear WA_DontShowOnScreen so that d->canBeNativeDialog() doesn't return false incorrectly | - | ||||||||||||||||||
1697 | setAttribute(Qt::WA_DontShowOnScreen, false); | - | ||||||||||||||||||
1698 | if (!d->usingWidgets())
| 0 | ||||||||||||||||||
1699 | return; never executed: return; | 0 | ||||||||||||||||||
1700 | QDialogButtonBox::StandardButton button = (mode == AcceptOpen ? QDialogButtonBox::Open : QDialogButtonBox::Save);
| 0 | ||||||||||||||||||
1701 | d->qFileDialogUi->buttonBox->setStandardButtons(button | QDialogButtonBox::Cancel); | - | ||||||||||||||||||
1702 | d->qFileDialogUi->buttonBox->button(button)->setEnabled(false); | - | ||||||||||||||||||
1703 | d->_q_updateOkButton(); | - | ||||||||||||||||||
1704 | if (mode == AcceptSave) {
| 0 | ||||||||||||||||||
1705 | d->qFileDialogUi->lookInCombo->setEditable(false); | - | ||||||||||||||||||
1706 | } never executed: end of block | 0 | ||||||||||||||||||
1707 | d->retranslateWindowTitle(); | - | ||||||||||||||||||
1708 | } never executed: end of block | 0 | ||||||||||||||||||
1709 | - | |||||||||||||||||||
1710 | /*! | - | ||||||||||||||||||
1711 | \property QFileDialog::supportedSchemes | - | ||||||||||||||||||
1712 | \brief the URL schemes that the file dialog should allow navigating to. | - | ||||||||||||||||||
1713 | \since 5.6 | - | ||||||||||||||||||
1714 | - | |||||||||||||||||||
1715 | Setting this property allows to restrict the type of URLs the | - | ||||||||||||||||||
1716 | user will be able to select. It is a way for the application to declare | - | ||||||||||||||||||
1717 | the protocols it will support to fetch the file content. An empty list | - | ||||||||||||||||||
1718 | means that no restriction is applied (the default). | - | ||||||||||||||||||
1719 | Supported for local files ("file" scheme) is implicit and always enabled; | - | ||||||||||||||||||
1720 | it is not necessary to include it in the restriction. | - | ||||||||||||||||||
1721 | */ | - | ||||||||||||||||||
1722 | - | |||||||||||||||||||
1723 | void QFileDialog::setSupportedSchemes(const QStringList &schemes) | - | ||||||||||||||||||
1724 | { | - | ||||||||||||||||||
1725 | Q_D(QFileDialog); | - | ||||||||||||||||||
1726 | d->options->setSupportedSchemes(schemes); | - | ||||||||||||||||||
1727 | } never executed: end of block | 0 | ||||||||||||||||||
1728 | - | |||||||||||||||||||
1729 | QStringList QFileDialog::supportedSchemes() const | - | ||||||||||||||||||
1730 | { | - | ||||||||||||||||||
1731 | return d_func()->options->supportedSchemes(); never executed: return d_func()->options->supportedSchemes(); | 0 | ||||||||||||||||||
1732 | } | - | ||||||||||||||||||
1733 | - | |||||||||||||||||||
1734 | /* | - | ||||||||||||||||||
1735 | Returns the file system model index that is the root index in the | - | ||||||||||||||||||
1736 | views | - | ||||||||||||||||||
1737 | */ | - | ||||||||||||||||||
1738 | QModelIndex QFileDialogPrivate::rootIndex() const { | - | ||||||||||||||||||
1739 | return mapToSource(qFileDialogUi->listView->rootIndex()); never executed: return mapToSource(qFileDialogUi->listView->rootIndex()); | 0 | ||||||||||||||||||
1740 | } | - | ||||||||||||||||||
1741 | - | |||||||||||||||||||
1742 | QAbstractItemView *QFileDialogPrivate::currentView() const { | - | ||||||||||||||||||
1743 | if (!qFileDialogUi->stackedWidget)
| 0 | ||||||||||||||||||
1744 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
1745 | if (qFileDialogUi->stackedWidget->currentWidget() == qFileDialogUi->listView->parent())
| 0 | ||||||||||||||||||
1746 | return qFileDialogUi->listView; never executed: return qFileDialogUi->listView; | 0 | ||||||||||||||||||
1747 | return qFileDialogUi->treeView; never executed: return qFileDialogUi->treeView; | 0 | ||||||||||||||||||
1748 | } | - | ||||||||||||||||||
1749 | - | |||||||||||||||||||
1750 | QLineEdit *QFileDialogPrivate::lineEdit() const { | - | ||||||||||||||||||
1751 | return (QLineEdit*)qFileDialogUi->fileNameEdit; never executed: return (QLineEdit*)qFileDialogUi->fileNameEdit; | 0 | ||||||||||||||||||
1752 | } | - | ||||||||||||||||||
1753 | - | |||||||||||||||||||
1754 | int QFileDialogPrivate::maxNameLength(const QString &path) | - | ||||||||||||||||||
1755 | { | - | ||||||||||||||||||
1756 | #if defined(Q_OS_UNIX) | - | ||||||||||||||||||
1757 | return ::pathconf(QFile::encodeName(path).data(), _PC_NAME_MAX); never executed: return ::pathconf(QFile::encodeName(path).data(), _PC_NAME_MAX); | 0 | ||||||||||||||||||
1758 | #elif defined(Q_OS_WINCE) || defined(Q_OS_WINRT) | - | ||||||||||||||||||
1759 | Q_UNUSED(path); | - | ||||||||||||||||||
1760 | return MAX_PATH; | - | ||||||||||||||||||
1761 | #elif defined(Q_OS_WIN) | - | ||||||||||||||||||
1762 | DWORD maxLength; | - | ||||||||||||||||||
1763 | const QString drive = path.left(3); | - | ||||||||||||||||||
1764 | if (::GetVolumeInformation(reinterpret_cast<const wchar_t *>(drive.utf16()), NULL, 0, NULL, &maxLength, NULL, NULL, 0) == false) | - | ||||||||||||||||||
1765 | return -1; | - | ||||||||||||||||||
1766 | return maxLength; | - | ||||||||||||||||||
1767 | #else | - | ||||||||||||||||||
1768 | Q_UNUSED(path); | - | ||||||||||||||||||
1769 | #endif | - | ||||||||||||||||||
1770 | return -1; dead code: return -1; | - | ||||||||||||||||||
1771 | } | - | ||||||||||||||||||
1772 | - | |||||||||||||||||||
1773 | /* | - | ||||||||||||||||||
1774 | Sets the view root index to be the file system model index | - | ||||||||||||||||||
1775 | */ | - | ||||||||||||||||||
1776 | void QFileDialogPrivate::setRootIndex(const QModelIndex &index) const { | - | ||||||||||||||||||
1777 | Q_ASSERT(index.isValid() ? index.model() == model : true); | - | ||||||||||||||||||
1778 | QModelIndex idx = mapFromSource(index); | - | ||||||||||||||||||
1779 | qFileDialogUi->treeView->setRootIndex(idx); | - | ||||||||||||||||||
1780 | qFileDialogUi->listView->setRootIndex(idx); | - | ||||||||||||||||||
1781 | } never executed: end of block | 0 | ||||||||||||||||||
1782 | /* | - | ||||||||||||||||||
1783 | Select a file system model index | - | ||||||||||||||||||
1784 | returns the index that was selected (or not depending upon sortfilterproxymodel) | - | ||||||||||||||||||
1785 | */ | - | ||||||||||||||||||
1786 | QModelIndex QFileDialogPrivate::select(const QModelIndex &index) const { | - | ||||||||||||||||||
1787 | Q_ASSERT(index.isValid() ? index.model() == model : true); | - | ||||||||||||||||||
1788 | - | |||||||||||||||||||
1789 | QModelIndex idx = mapFromSource(index); | - | ||||||||||||||||||
1790 | if (idx.isValid() && !qFileDialogUi->listView->selectionModel()->isSelected(idx))
| 0 | ||||||||||||||||||
1791 | qFileDialogUi->listView->selectionModel()->select(idx, never executed: qFileDialogUi->listView->selectionModel()->select(idx, QItemSelectionModel::Select | QItemSelectionModel::Rows); | 0 | ||||||||||||||||||
1792 | QItemSelectionModel::Select | QItemSelectionModel::Rows); never executed: qFileDialogUi->listView->selectionModel()->select(idx, QItemSelectionModel::Select | QItemSelectionModel::Rows); | 0 | ||||||||||||||||||
1793 | return idx; never executed: return idx; | 0 | ||||||||||||||||||
1794 | } | - | ||||||||||||||||||
1795 | - | |||||||||||||||||||
1796 | QFileDialog::AcceptMode QFileDialog::acceptMode() const | - | ||||||||||||||||||
1797 | { | - | ||||||||||||||||||
1798 | Q_D(const QFileDialog); | - | ||||||||||||||||||
1799 | return static_cast<AcceptMode>(d->options->acceptMode()); never executed: return static_cast<AcceptMode>(d->options->acceptMode()); | 0 | ||||||||||||||||||
1800 | } | - | ||||||||||||||||||
1801 | - | |||||||||||||||||||
1802 | /*! | - | ||||||||||||||||||
1803 | \property QFileDialog::readOnly | - | ||||||||||||||||||
1804 | \obsolete | - | ||||||||||||||||||
1805 | \brief Whether the filedialog is read-only | - | ||||||||||||||||||
1806 | - | |||||||||||||||||||
1807 | If this property is set to false, the file dialog will allow renaming, | - | ||||||||||||||||||
1808 | and deleting of files and directories and creating directories. | - | ||||||||||||||||||
1809 | - | |||||||||||||||||||
1810 | Use setOption(ReadOnly, \e enabled) or testOption(ReadOnly) instead. | - | ||||||||||||||||||
1811 | */ | - | ||||||||||||||||||
1812 | void QFileDialog::setReadOnly(bool enabled) | - | ||||||||||||||||||
1813 | { | - | ||||||||||||||||||
1814 | setOption(ReadOnly, enabled); | - | ||||||||||||||||||
1815 | } never executed: end of block | 0 | ||||||||||||||||||
1816 | - | |||||||||||||||||||
1817 | bool QFileDialog::isReadOnly() const | - | ||||||||||||||||||
1818 | { | - | ||||||||||||||||||
1819 | return testOption(ReadOnly); never executed: return testOption(ReadOnly); | 0 | ||||||||||||||||||
1820 | } | - | ||||||||||||||||||
1821 | - | |||||||||||||||||||
1822 | /*! | - | ||||||||||||||||||
1823 | \property QFileDialog::resolveSymlinks | - | ||||||||||||||||||
1824 | \obsolete | - | ||||||||||||||||||
1825 | \brief whether the filedialog should resolve shortcuts | - | ||||||||||||||||||
1826 | - | |||||||||||||||||||
1827 | If this property is set to true, the file dialog will resolve | - | ||||||||||||||||||
1828 | shortcuts or symbolic links. | - | ||||||||||||||||||
1829 | - | |||||||||||||||||||
1830 | Use setOption(DontResolveSymlinks, !\a enabled) or | - | ||||||||||||||||||
1831 | !testOption(DontResolveSymlinks). | - | ||||||||||||||||||
1832 | */ | - | ||||||||||||||||||
1833 | void QFileDialog::setResolveSymlinks(bool enabled) | - | ||||||||||||||||||
1834 | { | - | ||||||||||||||||||
1835 | setOption(DontResolveSymlinks, !enabled); | - | ||||||||||||||||||
1836 | } never executed: end of block | 0 | ||||||||||||||||||
1837 | - | |||||||||||||||||||
1838 | bool QFileDialog::resolveSymlinks() const | - | ||||||||||||||||||
1839 | { | - | ||||||||||||||||||
1840 | return !testOption(DontResolveSymlinks); never executed: return !testOption(DontResolveSymlinks); | 0 | ||||||||||||||||||
1841 | } | - | ||||||||||||||||||
1842 | - | |||||||||||||||||||
1843 | /*! | - | ||||||||||||||||||
1844 | \property QFileDialog::confirmOverwrite | - | ||||||||||||||||||
1845 | \obsolete | - | ||||||||||||||||||
1846 | \brief whether the filedialog should ask before accepting a selected file, | - | ||||||||||||||||||
1847 | when the accept mode is AcceptSave | - | ||||||||||||||||||
1848 | - | |||||||||||||||||||
1849 | Use setOption(DontConfirmOverwrite, !\e enabled) or | - | ||||||||||||||||||
1850 | !testOption(DontConfirmOverwrite) instead. | - | ||||||||||||||||||
1851 | */ | - | ||||||||||||||||||
1852 | void QFileDialog::setConfirmOverwrite(bool enabled) | - | ||||||||||||||||||
1853 | { | - | ||||||||||||||||||
1854 | setOption(DontConfirmOverwrite, !enabled); | - | ||||||||||||||||||
1855 | } never executed: end of block | 0 | ||||||||||||||||||
1856 | - | |||||||||||||||||||
1857 | bool QFileDialog::confirmOverwrite() const | - | ||||||||||||||||||
1858 | { | - | ||||||||||||||||||
1859 | return !testOption(DontConfirmOverwrite); never executed: return !testOption(DontConfirmOverwrite); | 0 | ||||||||||||||||||
1860 | } | - | ||||||||||||||||||
1861 | - | |||||||||||||||||||
1862 | /*! | - | ||||||||||||||||||
1863 | \property QFileDialog::defaultSuffix | - | ||||||||||||||||||
1864 | \brief suffix added to the filename if no other suffix was specified | - | ||||||||||||||||||
1865 | - | |||||||||||||||||||
1866 | This property specifies a string that will be added to the | - | ||||||||||||||||||
1867 | filename if it has no suffix already. The suffix is typically | - | ||||||||||||||||||
1868 | used to indicate the file type (e.g. "txt" indicates a text | - | ||||||||||||||||||
1869 | file). | - | ||||||||||||||||||
1870 | - | |||||||||||||||||||
1871 | If the first character is a dot ('.'), it is removed. | - | ||||||||||||||||||
1872 | */ | - | ||||||||||||||||||
1873 | void QFileDialog::setDefaultSuffix(const QString &suffix) | - | ||||||||||||||||||
1874 | { | - | ||||||||||||||||||
1875 | Q_D(QFileDialog); | - | ||||||||||||||||||
1876 | d->options->setDefaultSuffix(suffix); | - | ||||||||||||||||||
1877 | } never executed: end of block | 0 | ||||||||||||||||||
1878 | - | |||||||||||||||||||
1879 | QString QFileDialog::defaultSuffix() const | - | ||||||||||||||||||
1880 | { | - | ||||||||||||||||||
1881 | Q_D(const QFileDialog); | - | ||||||||||||||||||
1882 | return d->options->defaultSuffix(); never executed: return d->options->defaultSuffix(); | 0 | ||||||||||||||||||
1883 | } | - | ||||||||||||||||||
1884 | - | |||||||||||||||||||
1885 | /*! | - | ||||||||||||||||||
1886 | Sets the browsing history of the filedialog to contain the given | - | ||||||||||||||||||
1887 | \a paths. | - | ||||||||||||||||||
1888 | */ | - | ||||||||||||||||||
1889 | void QFileDialog::setHistory(const QStringList &paths) | - | ||||||||||||||||||
1890 | { | - | ||||||||||||||||||
1891 | Q_D(QFileDialog); | - | ||||||||||||||||||
1892 | if (d->usingWidgets())
| 0 | ||||||||||||||||||
1893 | d->qFileDialogUi->lookInCombo->setHistory(paths); never executed: d->qFileDialogUi->lookInCombo->setHistory(paths); | 0 | ||||||||||||||||||
1894 | } never executed: end of block | 0 | ||||||||||||||||||
1895 | - | |||||||||||||||||||
1896 | void QFileDialogComboBox::setHistory(const QStringList &paths) | - | ||||||||||||||||||
1897 | { | - | ||||||||||||||||||
1898 | m_history = paths; | - | ||||||||||||||||||
1899 | // Only populate the first item, showPopup will populate the rest if needed | - | ||||||||||||||||||
1900 | QList<QUrl> list; | - | ||||||||||||||||||
1901 | QModelIndex idx = d_ptr->model->index(d_ptr->rootPath()); | - | ||||||||||||||||||
1902 | //On windows the popup display the "C:\", convert to nativeSeparators | - | ||||||||||||||||||
1903 | QUrl url = QUrl::fromLocalFile(QDir::toNativeSeparators(idx.data(QFileSystemModel::FilePathRole).toString())); | - | ||||||||||||||||||
1904 | if (url.isValid())
| 0 | ||||||||||||||||||
1905 | list.append(url); never executed: list.append(url); | 0 | ||||||||||||||||||
1906 | urlModel->setUrls(list); | - | ||||||||||||||||||
1907 | } never executed: end of block | 0 | ||||||||||||||||||
1908 | - | |||||||||||||||||||
1909 | /*! | - | ||||||||||||||||||
1910 | Returns the browsing history of the filedialog as a list of paths. | - | ||||||||||||||||||
1911 | */ | - | ||||||||||||||||||
1912 | QStringList QFileDialog::history() const | - | ||||||||||||||||||
1913 | { | - | ||||||||||||||||||
1914 | Q_D(const QFileDialog); | - | ||||||||||||||||||
1915 | if (!d->usingWidgets())
| 0 | ||||||||||||||||||
1916 | return QStringList(); never executed: return QStringList(); | 0 | ||||||||||||||||||
1917 | QStringList currentHistory = d->qFileDialogUi->lookInCombo->history(); | - | ||||||||||||||||||
1918 | //On windows the popup display the "C:\", convert to nativeSeparators | - | ||||||||||||||||||
1919 | QString newHistory = QDir::toNativeSeparators(d->rootIndex().data(QFileSystemModel::FilePathRole).toString()); | - | ||||||||||||||||||
1920 | if (!currentHistory.contains(newHistory))
| 0 | ||||||||||||||||||
1921 | currentHistory << newHistory; never executed: currentHistory << newHistory; | 0 | ||||||||||||||||||
1922 | return currentHistory; never executed: return currentHistory; | 0 | ||||||||||||||||||
1923 | } | - | ||||||||||||||||||
1924 | - | |||||||||||||||||||
1925 | /*! | - | ||||||||||||||||||
1926 | Sets the item delegate used to render items in the views in the | - | ||||||||||||||||||
1927 | file dialog to the given \a delegate. | - | ||||||||||||||||||
1928 | - | |||||||||||||||||||
1929 | \warning You should not share the same instance of a delegate between views. | - | ||||||||||||||||||
1930 | Doing so can cause incorrect or unintuitive editing behavior since each | - | ||||||||||||||||||
1931 | view connected to a given delegate may receive the \l{QAbstractItemDelegate::}{closeEditor()} | - | ||||||||||||||||||
1932 | signal, and attempt to access, modify or close an editor that has already been closed. | - | ||||||||||||||||||
1933 | - | |||||||||||||||||||
1934 | Note that the model used is QFileSystemModel. It has custom item data roles, which is | - | ||||||||||||||||||
1935 | described by the \l{QFileSystemModel::}{Roles} enum. You can use a QFileIconProvider if | - | ||||||||||||||||||
1936 | you only want custom icons. | - | ||||||||||||||||||
1937 | - | |||||||||||||||||||
1938 | \sa itemDelegate(), setIconProvider(), QFileSystemModel | - | ||||||||||||||||||
1939 | */ | - | ||||||||||||||||||
1940 | void QFileDialog::setItemDelegate(QAbstractItemDelegate *delegate) | - | ||||||||||||||||||
1941 | { | - | ||||||||||||||||||
1942 | Q_D(QFileDialog); | - | ||||||||||||||||||
1943 | if (!d->usingWidgets())
| 0 | ||||||||||||||||||
1944 | return; never executed: return; | 0 | ||||||||||||||||||
1945 | d->qFileDialogUi->listView->setItemDelegate(delegate); | - | ||||||||||||||||||
1946 | d->qFileDialogUi->treeView->setItemDelegate(delegate); | - | ||||||||||||||||||
1947 | } never executed: end of block | 0 | ||||||||||||||||||
1948 | - | |||||||||||||||||||
1949 | /*! | - | ||||||||||||||||||
1950 | Returns the item delegate used to render the items in the views in the filedialog. | - | ||||||||||||||||||
1951 | */ | - | ||||||||||||||||||
1952 | QAbstractItemDelegate *QFileDialog::itemDelegate() const | - | ||||||||||||||||||
1953 | { | - | ||||||||||||||||||
1954 | Q_D(const QFileDialog); | - | ||||||||||||||||||
1955 | if (!d->usingWidgets())
| 0 | ||||||||||||||||||
1956 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
1957 | return d->qFileDialogUi->listView->itemDelegate(); never executed: return d->qFileDialogUi->listView->itemDelegate(); | 0 | ||||||||||||||||||
1958 | } | - | ||||||||||||||||||
1959 | - | |||||||||||||||||||
1960 | /*! | - | ||||||||||||||||||
1961 | Sets the icon provider used by the filedialog to the specified \a provider. | - | ||||||||||||||||||
1962 | */ | - | ||||||||||||||||||
1963 | void QFileDialog::setIconProvider(QFileIconProvider *provider) | - | ||||||||||||||||||
1964 | { | - | ||||||||||||||||||
1965 | Q_D(QFileDialog); | - | ||||||||||||||||||
1966 | if (!d->usingWidgets())
| 0 | ||||||||||||||||||
1967 | return; never executed: return; | 0 | ||||||||||||||||||
1968 | d->model->setIconProvider(provider); | - | ||||||||||||||||||
1969 | //It forces the refresh of all entries in the side bar, then we can get new icons | - | ||||||||||||||||||
1970 | d->qFileDialogUi->sidebar->setUrls(d->qFileDialogUi->sidebar->urls()); | - | ||||||||||||||||||
1971 | } never executed: end of block | 0 | ||||||||||||||||||
1972 | - | |||||||||||||||||||
1973 | /*! | - | ||||||||||||||||||
1974 | Returns the icon provider used by the filedialog. | - | ||||||||||||||||||
1975 | */ | - | ||||||||||||||||||
1976 | QFileIconProvider *QFileDialog::iconProvider() const | - | ||||||||||||||||||
1977 | { | - | ||||||||||||||||||
1978 | Q_D(const QFileDialog); | - | ||||||||||||||||||
1979 | if (!d->model)
| 0 | ||||||||||||||||||
1980 | return Q_NULLPTR; never executed: return nullptr; | 0 | ||||||||||||||||||
1981 | return d->model->iconProvider(); never executed: return d->model->iconProvider(); | 0 | ||||||||||||||||||
1982 | } | - | ||||||||||||||||||
1983 | - | |||||||||||||||||||
1984 | void QFileDialogPrivate::setLabelTextControl(QFileDialog::DialogLabel label, const QString &text) | - | ||||||||||||||||||
1985 | { | - | ||||||||||||||||||
1986 | if (!qFileDialogUi)
| 0 | ||||||||||||||||||
1987 | return; never executed: return; | 0 | ||||||||||||||||||
1988 | switch (label) { | - | ||||||||||||||||||
1989 | case QFileDialog::LookIn: never executed: case QFileDialog::LookIn: | 0 | ||||||||||||||||||
1990 | qFileDialogUi->lookInLabel->setText(text); | - | ||||||||||||||||||
1991 | break; never executed: break; | 0 | ||||||||||||||||||
1992 | case QFileDialog::FileName: never executed: case QFileDialog::FileName: | 0 | ||||||||||||||||||
1993 | qFileDialogUi->fileNameLabel->setText(text); | - | ||||||||||||||||||
1994 | break; never executed: break; | 0 | ||||||||||||||||||
1995 | case QFileDialog::FileType: never executed: case QFileDialog::FileType: | 0 | ||||||||||||||||||
1996 | qFileDialogUi->fileTypeLabel->setText(text); | - | ||||||||||||||||||
1997 | break; never executed: break; | 0 | ||||||||||||||||||
1998 | case QFileDialog::Accept: never executed: case QFileDialog::Accept: | 0 | ||||||||||||||||||
1999 | if (q_func()->acceptMode() == QFileDialog::AcceptOpen) {
| 0 | ||||||||||||||||||
2000 | if (QPushButton *button = qFileDialogUi->buttonBox->button(QDialogButtonBox::Open))
| 0 | ||||||||||||||||||
2001 | button->setText(text); never executed: button->setText(text); | 0 | ||||||||||||||||||
2002 | } else { never executed: end of block | 0 | ||||||||||||||||||
2003 | if (QPushButton *button = qFileDialogUi->buttonBox->button(QDialogButtonBox::Save))
| 0 | ||||||||||||||||||
2004 | button->setText(text); never executed: button->setText(text); | 0 | ||||||||||||||||||
2005 | } never executed: end of block | 0 | ||||||||||||||||||
2006 | break; never executed: break; | 0 | ||||||||||||||||||
2007 | case QFileDialog::Reject: never executed: case QFileDialog::Reject: | 0 | ||||||||||||||||||
2008 | if (QPushButton *button = qFileDialogUi->buttonBox->button(QDialogButtonBox::Cancel))
| 0 | ||||||||||||||||||
2009 | button->setText(text); never executed: button->setText(text); | 0 | ||||||||||||||||||
2010 | break; never executed: break; | 0 | ||||||||||||||||||
2011 | } | - | ||||||||||||||||||
2012 | } never executed: end of block | 0 | ||||||||||||||||||
2013 | - | |||||||||||||||||||
2014 | /*! | - | ||||||||||||||||||
2015 | Sets the \a text shown in the filedialog in the specified \a label. | - | ||||||||||||||||||
2016 | */ | - | ||||||||||||||||||
2017 | - | |||||||||||||||||||
2018 | void QFileDialog::setLabelText(DialogLabel label, const QString &text) | - | ||||||||||||||||||
2019 | { | - | ||||||||||||||||||
2020 | Q_D(QFileDialog); | - | ||||||||||||||||||
2021 | d->options->setLabelText(static_cast<QFileDialogOptions::DialogLabel>(label), text); | - | ||||||||||||||||||
2022 | d->setLabelTextControl(label, text); | - | ||||||||||||||||||
2023 | } never executed: end of block | 0 | ||||||||||||||||||
2024 | - | |||||||||||||||||||
2025 | /*! | - | ||||||||||||||||||
2026 | Returns the text shown in the filedialog in the specified \a label. | - | ||||||||||||||||||
2027 | */ | - | ||||||||||||||||||
2028 | QString QFileDialog::labelText(DialogLabel label) const | - | ||||||||||||||||||
2029 | { | - | ||||||||||||||||||
2030 | Q_D(const QFileDialog); | - | ||||||||||||||||||
2031 | if (!d->usingWidgets())
| 0 | ||||||||||||||||||
2032 | return d->options->labelText(static_cast<QFileDialogOptions::DialogLabel>(label)); never executed: return d->options->labelText(static_cast<QFileDialogOptions::DialogLabel>(label)); | 0 | ||||||||||||||||||
2033 | QPushButton *button; | - | ||||||||||||||||||
2034 | switch (label) { | - | ||||||||||||||||||
2035 | case LookIn: never executed: case LookIn: | 0 | ||||||||||||||||||
2036 | return d->qFileDialogUi->lookInLabel->text(); never executed: return d->qFileDialogUi->lookInLabel->text(); | 0 | ||||||||||||||||||
2037 | case FileName: never executed: case FileName: | 0 | ||||||||||||||||||
2038 | return d->qFileDialogUi->fileNameLabel->text(); never executed: return d->qFileDialogUi->fileNameLabel->text(); | 0 | ||||||||||||||||||
2039 | case FileType: never executed: case FileType: | 0 | ||||||||||||||||||
2040 | return d->qFileDialogUi->fileTypeLabel->text(); never executed: return d->qFileDialogUi->fileTypeLabel->text(); | 0 | ||||||||||||||||||
2041 | case Accept: never executed: case Accept: | 0 | ||||||||||||||||||
2042 | if (acceptMode() == AcceptOpen)
| 0 | ||||||||||||||||||
2043 | button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Open); never executed: button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Open); | 0 | ||||||||||||||||||
2044 | else | - | ||||||||||||||||||
2045 | button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Save); never executed: button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Save); | 0 | ||||||||||||||||||
2046 | if (button)
| 0 | ||||||||||||||||||
2047 | return button->text(); never executed: return button->text(); | 0 | ||||||||||||||||||
2048 | break; never executed: break; | 0 | ||||||||||||||||||
2049 | case Reject: never executed: case Reject: | 0 | ||||||||||||||||||
2050 | button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Cancel); | - | ||||||||||||||||||
2051 | if (button)
| 0 | ||||||||||||||||||
2052 | return button->text(); never executed: return button->text(); | 0 | ||||||||||||||||||
2053 | break; never executed: break; | 0 | ||||||||||||||||||
2054 | } | - | ||||||||||||||||||
2055 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
2056 | } | - | ||||||||||||||||||
2057 | - | |||||||||||||||||||
2058 | /*! | - | ||||||||||||||||||
2059 | This is a convenience static function that returns an existing file | - | ||||||||||||||||||
2060 | selected by the user. If the user presses Cancel, it returns a null string. | - | ||||||||||||||||||
2061 | - | |||||||||||||||||||
2062 | \snippet code/src_gui_dialogs_qfiledialog.cpp 8 | - | ||||||||||||||||||
2063 | - | |||||||||||||||||||
2064 | The function creates a modal file dialog with the given \a parent widget. | - | ||||||||||||||||||
2065 | If \a parent is not 0, the dialog will be shown centered over the parent | - | ||||||||||||||||||
2066 | widget. | - | ||||||||||||||||||
2067 | - | |||||||||||||||||||
2068 | The file dialog's working directory will be set to \a dir. If \a dir | - | ||||||||||||||||||
2069 | includes a file name, the file will be selected. Only files that match the | - | ||||||||||||||||||
2070 | given \a filter are shown. The filter selected is set to \a selectedFilter. | - | ||||||||||||||||||
2071 | The parameters \a dir, \a selectedFilter, and \a filter may be empty | - | ||||||||||||||||||
2072 | strings. If you want multiple filters, separate them with ';;', for | - | ||||||||||||||||||
2073 | example: | - | ||||||||||||||||||
2074 | - | |||||||||||||||||||
2075 | \code | - | ||||||||||||||||||
2076 | "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)" | - | ||||||||||||||||||
2077 | \endcode | - | ||||||||||||||||||
2078 | - | |||||||||||||||||||
2079 | The \a options argument holds various options about how to run the dialog, | - | ||||||||||||||||||
2080 | see the QFileDialog::Option enum for more information on the flags you can | - | ||||||||||||||||||
2081 | pass. | - | ||||||||||||||||||
2082 | - | |||||||||||||||||||
2083 | The dialog's caption is set to \a caption. If \a caption is not specified | - | ||||||||||||||||||
2084 | then a default caption will be used. | - | ||||||||||||||||||
2085 | - | |||||||||||||||||||
2086 | On Windows, and \macos, this static function will use the | - | ||||||||||||||||||
2087 | native file dialog and not a QFileDialog. | - | ||||||||||||||||||
2088 | - | |||||||||||||||||||
2089 | On Windows the dialog will spin a blocking modal event loop that will not | - | ||||||||||||||||||
2090 | dispatch any QTimers, and if \a parent is not 0 then it will position the | - | ||||||||||||||||||
2091 | dialog just below the parent's title bar. | - | ||||||||||||||||||
2092 | - | |||||||||||||||||||
2093 | On Unix/X11, the normal behavior of the file dialog is to resolve and | - | ||||||||||||||||||
2094 | follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp}, | - | ||||||||||||||||||
2095 | the file dialog will change to \c{/var/tmp} after entering \c{/usr/tmp}. If | - | ||||||||||||||||||
2096 | \a options includes DontResolveSymlinks, the file dialog will treat | - | ||||||||||||||||||
2097 | symlinks as regular directories. | - | ||||||||||||||||||
2098 | - | |||||||||||||||||||
2099 | \warning Do not delete \a parent during the execution of the dialog. If you | - | ||||||||||||||||||
2100 | want to do this, you should create the dialog yourself using one of the | - | ||||||||||||||||||
2101 | QFileDialog constructors. | - | ||||||||||||||||||
2102 | - | |||||||||||||||||||
2103 | \sa getOpenFileNames(), getSaveFileName(), getExistingDirectory() | - | ||||||||||||||||||
2104 | */ | - | ||||||||||||||||||
2105 | QString QFileDialog::getOpenFileName(QWidget *parent, | - | ||||||||||||||||||
2106 | const QString &caption, | - | ||||||||||||||||||
2107 | const QString &dir, | - | ||||||||||||||||||
2108 | const QString &filter, | - | ||||||||||||||||||
2109 | QString *selectedFilter, | - | ||||||||||||||||||
2110 | Options options) | - | ||||||||||||||||||
2111 | { | - | ||||||||||||||||||
2112 | const QStringList schemes = QStringList(QStringLiteral("file")); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
2113 | const QUrl selectedUrl = getOpenFileUrl(parent, caption, QUrl::fromLocalFile(dir), filter, selectedFilter, options, schemes); | - | ||||||||||||||||||
2114 | return selectedUrl.toLocalFile(); never executed: return selectedUrl.toLocalFile(); | 0 | ||||||||||||||||||
2115 | } | - | ||||||||||||||||||
2116 | - | |||||||||||||||||||
2117 | /*! | - | ||||||||||||||||||
2118 | This is a convenience static function that returns an existing file | - | ||||||||||||||||||
2119 | selected by the user. If the user presses Cancel, it returns an | - | ||||||||||||||||||
2120 | empty url. | - | ||||||||||||||||||
2121 | - | |||||||||||||||||||
2122 | The function is used similarly to QFileDialog::getOpenFileName(). In | - | ||||||||||||||||||
2123 | particular \a parent, \a caption, \a dir, \a filter, \a selectedFilter | - | ||||||||||||||||||
2124 | and \a options are used in the exact same way. | - | ||||||||||||||||||
2125 | - | |||||||||||||||||||
2126 | The main difference with QFileDialog::getOpenFileName() comes from | - | ||||||||||||||||||
2127 | the ability offered to the user to select a remote file. That's why | - | ||||||||||||||||||
2128 | the return type and the type of \a dir is QUrl. | - | ||||||||||||||||||
2129 | - | |||||||||||||||||||
2130 | The \a supportedSchemes argument allows to restrict the type of URLs the | - | ||||||||||||||||||
2131 | user will be able to select. It is a way for the application to declare | - | ||||||||||||||||||
2132 | the protocols it will support to fetch the file content. An empty list | - | ||||||||||||||||||
2133 | means that no restriction is applied (the default). | - | ||||||||||||||||||
2134 | Supported for local files ("file" scheme) is implicit and always enabled; | - | ||||||||||||||||||
2135 | it is not necessary to include it in the restriction. | - | ||||||||||||||||||
2136 | - | |||||||||||||||||||
2137 | When possible, this static function will use the native file dialog and | - | ||||||||||||||||||
2138 | not a QFileDialog. On platforms which don't support selecting remote | - | ||||||||||||||||||
2139 | files, Qt will allow to select only local files. | - | ||||||||||||||||||
2140 | - | |||||||||||||||||||
2141 | \sa getOpenFileName(), getOpenFileUrls(), getSaveFileUrl(), getExistingDirectoryUrl() | - | ||||||||||||||||||
2142 | \since 5.2 | - | ||||||||||||||||||
2143 | */ | - | ||||||||||||||||||
2144 | QUrl QFileDialog::getOpenFileUrl(QWidget *parent, | - | ||||||||||||||||||
2145 | const QString &caption, | - | ||||||||||||||||||
2146 | const QUrl &dir, | - | ||||||||||||||||||
2147 | const QString &filter, | - | ||||||||||||||||||
2148 | QString *selectedFilter, | - | ||||||||||||||||||
2149 | Options options, | - | ||||||||||||||||||
2150 | const QStringList &supportedSchemes) | - | ||||||||||||||||||
2151 | { | - | ||||||||||||||||||
2152 | QFileDialogArgs args; | - | ||||||||||||||||||
2153 | args.parent = parent; | - | ||||||||||||||||||
2154 | args.caption = caption; | - | ||||||||||||||||||
2155 | args.directory = QFileDialogPrivate::workingDirectory(dir); | - | ||||||||||||||||||
2156 | args.selection = QFileDialogPrivate::initialSelection(dir); | - | ||||||||||||||||||
2157 | args.filter = filter; | - | ||||||||||||||||||
2158 | args.mode = ExistingFile; | - | ||||||||||||||||||
2159 | args.options = options; | - | ||||||||||||||||||
2160 | - | |||||||||||||||||||
2161 | QFileDialog dialog(args); | - | ||||||||||||||||||
2162 | dialog.setSupportedSchemes(supportedSchemes); | - | ||||||||||||||||||
2163 | if (selectedFilter && !selectedFilter->isEmpty())
| 0 | ||||||||||||||||||
2164 | dialog.selectNameFilter(*selectedFilter); never executed: dialog.selectNameFilter(*selectedFilter); | 0 | ||||||||||||||||||
2165 | if (dialog.exec() == QDialog::Accepted) {
| 0 | ||||||||||||||||||
2166 | if (selectedFilter)
| 0 | ||||||||||||||||||
2167 | *selectedFilter = dialog.selectedNameFilter(); never executed: *selectedFilter = dialog.selectedNameFilter(); | 0 | ||||||||||||||||||
2168 | return dialog.selectedUrls().value(0); never executed: return dialog.selectedUrls().value(0); | 0 | ||||||||||||||||||
2169 | } | - | ||||||||||||||||||
2170 | return QUrl(); never executed: return QUrl(); | 0 | ||||||||||||||||||
2171 | } | - | ||||||||||||||||||
2172 | - | |||||||||||||||||||
2173 | /*! | - | ||||||||||||||||||
2174 | This is a convenience static function that will return one or more existing | - | ||||||||||||||||||
2175 | files selected by the user. | - | ||||||||||||||||||
2176 | - | |||||||||||||||||||
2177 | \snippet code/src_gui_dialogs_qfiledialog.cpp 9 | - | ||||||||||||||||||
2178 | - | |||||||||||||||||||
2179 | This function creates a modal file dialog with the given \a parent widget. | - | ||||||||||||||||||
2180 | If \a parent is not 0, the dialog will be shown centered over the parent | - | ||||||||||||||||||
2181 | widget. | - | ||||||||||||||||||
2182 | - | |||||||||||||||||||
2183 | The file dialog's working directory will be set to \a dir. If \a dir | - | ||||||||||||||||||
2184 | includes a file name, the file will be selected. The filter is set to | - | ||||||||||||||||||
2185 | \a filter so that only those files which match the filter are shown. The | - | ||||||||||||||||||
2186 | filter selected is set to \a selectedFilter. The parameters \a dir, | - | ||||||||||||||||||
2187 | \a selectedFilter and \a filter may be empty strings. If you need multiple | - | ||||||||||||||||||
2188 | filters, separate them with ';;', for instance: | - | ||||||||||||||||||
2189 | - | |||||||||||||||||||
2190 | \code | - | ||||||||||||||||||
2191 | "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)" | - | ||||||||||||||||||
2192 | \endcode | - | ||||||||||||||||||
2193 | - | |||||||||||||||||||
2194 | The dialog's caption is set to \a caption. If \a caption is not specified | - | ||||||||||||||||||
2195 | then a default caption will be used. | - | ||||||||||||||||||
2196 | - | |||||||||||||||||||
2197 | On Windows, and \macos, this static function will use the | - | ||||||||||||||||||
2198 | native file dialog and not a QFileDialog. | - | ||||||||||||||||||
2199 | - | |||||||||||||||||||
2200 | On Windows the dialog will spin a blocking modal event loop that will not | - | ||||||||||||||||||
2201 | dispatch any QTimers, and if \a parent is not 0 then it will position the | - | ||||||||||||||||||
2202 | dialog just below the parent's title bar. | - | ||||||||||||||||||
2203 | - | |||||||||||||||||||
2204 | On Unix/X11, the normal behavior of the file dialog is to resolve and | - | ||||||||||||||||||
2205 | follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp}, | - | ||||||||||||||||||
2206 | the file dialog will change to \c{/var/tmp} after entering \c{/usr/tmp}. | - | ||||||||||||||||||
2207 | The \a options argument holds various options about how to run the dialog, | - | ||||||||||||||||||
2208 | see the QFileDialog::Option enum for more information on the flags you can | - | ||||||||||||||||||
2209 | pass. | - | ||||||||||||||||||
2210 | - | |||||||||||||||||||
2211 | \warning Do not delete \a parent during the execution of the dialog. If you | - | ||||||||||||||||||
2212 | want to do this, you should create the dialog yourself using one of the | - | ||||||||||||||||||
2213 | QFileDialog constructors. | - | ||||||||||||||||||
2214 | - | |||||||||||||||||||
2215 | \sa getOpenFileName(), getSaveFileName(), getExistingDirectory() | - | ||||||||||||||||||
2216 | */ | - | ||||||||||||||||||
2217 | QStringList QFileDialog::getOpenFileNames(QWidget *parent, | - | ||||||||||||||||||
2218 | const QString &caption, | - | ||||||||||||||||||
2219 | const QString &dir, | - | ||||||||||||||||||
2220 | const QString &filter, | - | ||||||||||||||||||
2221 | QString *selectedFilter, | - | ||||||||||||||||||
2222 | Options options) | - | ||||||||||||||||||
2223 | { | - | ||||||||||||||||||
2224 | const QStringList schemes = QStringList(QStringLiteral("file")); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
2225 | const QList<QUrl> selectedUrls = getOpenFileUrls(parent, caption, QUrl::fromLocalFile(dir), filter, selectedFilter, options, schemes); | - | ||||||||||||||||||
2226 | QStringList fileNames; | - | ||||||||||||||||||
2227 | fileNames.reserve(selectedUrls.size()); | - | ||||||||||||||||||
2228 | foreach (const QUrl &url, selectedUrls) | - | ||||||||||||||||||
2229 | fileNames << url.toLocalFile(); never executed: fileNames << url.toLocalFile(); | 0 | ||||||||||||||||||
2230 | return fileNames; never executed: return fileNames; | 0 | ||||||||||||||||||
2231 | } | - | ||||||||||||||||||
2232 | - | |||||||||||||||||||
2233 | /*! | - | ||||||||||||||||||
2234 | This is a convenience static function that will return or or more existing | - | ||||||||||||||||||
2235 | files selected by the user. If the user presses Cancel, it returns an | - | ||||||||||||||||||
2236 | empty list. | - | ||||||||||||||||||
2237 | - | |||||||||||||||||||
2238 | The function is used similarly to QFileDialog::getOpenFileNames(). In | - | ||||||||||||||||||
2239 | particular \a parent, \a caption, \a dir, \a filter, \a selectedFilter | - | ||||||||||||||||||
2240 | and \a options are used in the exact same way. | - | ||||||||||||||||||
2241 | - | |||||||||||||||||||
2242 | The main difference with QFileDialog::getOpenFileNames() comes from | - | ||||||||||||||||||
2243 | the ability offered to the user to select remote files. That's why | - | ||||||||||||||||||
2244 | the return type and the type of \a dir are respectively QList<QUrl> | - | ||||||||||||||||||
2245 | and QUrl. | - | ||||||||||||||||||
2246 | - | |||||||||||||||||||
2247 | The \a supportedSchemes argument allows to restrict the type of URLs the | - | ||||||||||||||||||
2248 | user will be able to select. It is a way for the application to declare | - | ||||||||||||||||||
2249 | the protocols it will support to fetch the file content. An empty list | - | ||||||||||||||||||
2250 | means that no restriction is applied (the default). | - | ||||||||||||||||||
2251 | Supported for local files ("file" scheme) is implicit and always enabled; | - | ||||||||||||||||||
2252 | it is not necessary to include it in the restriction. | - | ||||||||||||||||||
2253 | - | |||||||||||||||||||
2254 | When possible, this static function will use the native file dialog and | - | ||||||||||||||||||
2255 | not a QFileDialog. On platforms which don't support selecting remote | - | ||||||||||||||||||
2256 | files, Qt will allow to select only local files. | - | ||||||||||||||||||
2257 | - | |||||||||||||||||||
2258 | \sa getOpenFileNames(), getOpenFileUrl(), getSaveFileUrl(), getExistingDirectoryUrl() | - | ||||||||||||||||||
2259 | \since 5.2 | - | ||||||||||||||||||
2260 | */ | - | ||||||||||||||||||
2261 | QList<QUrl> QFileDialog::getOpenFileUrls(QWidget *parent, | - | ||||||||||||||||||
2262 | const QString &caption, | - | ||||||||||||||||||
2263 | const QUrl &dir, | - | ||||||||||||||||||
2264 | const QString &filter, | - | ||||||||||||||||||
2265 | QString *selectedFilter, | - | ||||||||||||||||||
2266 | Options options, | - | ||||||||||||||||||
2267 | const QStringList &supportedSchemes) | - | ||||||||||||||||||
2268 | { | - | ||||||||||||||||||
2269 | QFileDialogArgs args; | - | ||||||||||||||||||
2270 | args.parent = parent; | - | ||||||||||||||||||
2271 | args.caption = caption; | - | ||||||||||||||||||
2272 | args.directory = QFileDialogPrivate::workingDirectory(dir); | - | ||||||||||||||||||
2273 | args.selection = QFileDialogPrivate::initialSelection(dir); | - | ||||||||||||||||||
2274 | args.filter = filter; | - | ||||||||||||||||||
2275 | args.mode = ExistingFiles; | - | ||||||||||||||||||
2276 | args.options = options; | - | ||||||||||||||||||
2277 | - | |||||||||||||||||||
2278 | QFileDialog dialog(args); | - | ||||||||||||||||||
2279 | dialog.setSupportedSchemes(supportedSchemes); | - | ||||||||||||||||||
2280 | if (selectedFilter && !selectedFilter->isEmpty())
| 0 | ||||||||||||||||||
2281 | dialog.selectNameFilter(*selectedFilter); never executed: dialog.selectNameFilter(*selectedFilter); | 0 | ||||||||||||||||||
2282 | if (dialog.exec() == QDialog::Accepted) {
| 0 | ||||||||||||||||||
2283 | if (selectedFilter)
| 0 | ||||||||||||||||||
2284 | *selectedFilter = dialog.selectedNameFilter(); never executed: *selectedFilter = dialog.selectedNameFilter(); | 0 | ||||||||||||||||||
2285 | return dialog.selectedUrls(); never executed: return dialog.selectedUrls(); | 0 | ||||||||||||||||||
2286 | } | - | ||||||||||||||||||
2287 | return QList<QUrl>(); never executed: return QList<QUrl>(); | 0 | ||||||||||||||||||
2288 | } | - | ||||||||||||||||||
2289 | - | |||||||||||||||||||
2290 | /*! | - | ||||||||||||||||||
2291 | This is a convenience static function that will return a file name selected | - | ||||||||||||||||||
2292 | by the user. The file does not have to exist. | - | ||||||||||||||||||
2293 | - | |||||||||||||||||||
2294 | It creates a modal file dialog with the given \a parent widget. If | - | ||||||||||||||||||
2295 | \a parent is not 0, the dialog will be shown centered over the parent | - | ||||||||||||||||||
2296 | widget. | - | ||||||||||||||||||
2297 | - | |||||||||||||||||||
2298 | \snippet code/src_gui_dialogs_qfiledialog.cpp 11 | - | ||||||||||||||||||
2299 | - | |||||||||||||||||||
2300 | The file dialog's working directory will be set to \a dir. If \a dir | - | ||||||||||||||||||
2301 | includes a file name, the file will be selected. Only files that match the | - | ||||||||||||||||||
2302 | \a filter are shown. The filter selected is set to \a selectedFilter. The | - | ||||||||||||||||||
2303 | parameters \a dir, \a selectedFilter, and \a filter may be empty strings. | - | ||||||||||||||||||
2304 | Multiple filters are separated with ';;'. For instance: | - | ||||||||||||||||||
2305 | - | |||||||||||||||||||
2306 | \code | - | ||||||||||||||||||
2307 | "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)" | - | ||||||||||||||||||
2308 | \endcode | - | ||||||||||||||||||
2309 | - | |||||||||||||||||||
2310 | The \a options argument holds various options about how to run the dialog, | - | ||||||||||||||||||
2311 | see the QFileDialog::Option enum for more information on the flags you can | - | ||||||||||||||||||
2312 | pass. | - | ||||||||||||||||||
2313 | - | |||||||||||||||||||
2314 | The default filter can be chosen by setting \a selectedFilter to the | - | ||||||||||||||||||
2315 | desired value. | - | ||||||||||||||||||
2316 | - | |||||||||||||||||||
2317 | The dialog's caption is set to \a caption. If \a caption is not specified, | - | ||||||||||||||||||
2318 | a default caption will be used. | - | ||||||||||||||||||
2319 | - | |||||||||||||||||||
2320 | On Windows, and \macos, this static function will use the | - | ||||||||||||||||||
2321 | native file dialog and not a QFileDialog. | - | ||||||||||||||||||
2322 | - | |||||||||||||||||||
2323 | On Windows the dialog will spin a blocking modal event loop that will not | - | ||||||||||||||||||
2324 | dispatch any QTimers, and if \a parent is not 0 then it will position the | - | ||||||||||||||||||
2325 | dialog just below the parent's title bar. On \macos, with its native file | - | ||||||||||||||||||
2326 | dialog, the filter argument is ignored. | - | ||||||||||||||||||
2327 | - | |||||||||||||||||||
2328 | On Unix/X11, the normal behavior of the file dialog is to resolve and | - | ||||||||||||||||||
2329 | follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp}, | - | ||||||||||||||||||
2330 | the file dialog will change to \c{/var/tmp} after entering \c{/usr/tmp}. If | - | ||||||||||||||||||
2331 | \a options includes DontResolveSymlinks the file dialog will treat symlinks | - | ||||||||||||||||||
2332 | as regular directories. | - | ||||||||||||||||||
2333 | - | |||||||||||||||||||
2334 | \warning Do not delete \a parent during the execution of the dialog. If you | - | ||||||||||||||||||
2335 | want to do this, you should create the dialog yourself using one of the | - | ||||||||||||||||||
2336 | QFileDialog constructors. | - | ||||||||||||||||||
2337 | - | |||||||||||||||||||
2338 | \sa getOpenFileName(), getOpenFileNames(), getExistingDirectory() | - | ||||||||||||||||||
2339 | */ | - | ||||||||||||||||||
2340 | QString QFileDialog::getSaveFileName(QWidget *parent, | - | ||||||||||||||||||
2341 | const QString &caption, | - | ||||||||||||||||||
2342 | const QString &dir, | - | ||||||||||||||||||
2343 | const QString &filter, | - | ||||||||||||||||||
2344 | QString *selectedFilter, | - | ||||||||||||||||||
2345 | Options options) | - | ||||||||||||||||||
2346 | { | - | ||||||||||||||||||
2347 | const QStringList schemes = QStringList(QStringLiteral("file")); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
2348 | const QUrl selectedUrl = getSaveFileUrl(parent, caption, QUrl::fromLocalFile(dir), filter, selectedFilter, options, schemes); | - | ||||||||||||||||||
2349 | return selectedUrl.toLocalFile(); never executed: return selectedUrl.toLocalFile(); | 0 | ||||||||||||||||||
2350 | } | - | ||||||||||||||||||
2351 | - | |||||||||||||||||||
2352 | /*! | - | ||||||||||||||||||
2353 | This is a convenience static function that returns a file selected by | - | ||||||||||||||||||
2354 | the user. The file does not have to exist. If the user presses Cancel, | - | ||||||||||||||||||
2355 | it returns an empty url. | - | ||||||||||||||||||
2356 | - | |||||||||||||||||||
2357 | The function is used similarly to QFileDialog::getSaveFileName(). In | - | ||||||||||||||||||
2358 | particular \a parent, \a caption, \a dir, \a filter, \a selectedFilter | - | ||||||||||||||||||
2359 | and \a options are used in the exact same way. | - | ||||||||||||||||||
2360 | - | |||||||||||||||||||
2361 | The main difference with QFileDialog::getSaveFileName() comes from | - | ||||||||||||||||||
2362 | the ability offered to the user to select a remote file. That's why | - | ||||||||||||||||||
2363 | the return type and the type of \a dir is QUrl. | - | ||||||||||||||||||
2364 | - | |||||||||||||||||||
2365 | The \a supportedSchemes argument allows to restrict the type of URLs the | - | ||||||||||||||||||
2366 | user will be able to select. It is a way for the application to declare | - | ||||||||||||||||||
2367 | the protocols it will support to save the file content. An empty list | - | ||||||||||||||||||
2368 | means that no restriction is applied (the default). | - | ||||||||||||||||||
2369 | Supported for local files ("file" scheme) is implicit and always enabled; | - | ||||||||||||||||||
2370 | it is not necessary to include it in the restriction. | - | ||||||||||||||||||
2371 | - | |||||||||||||||||||
2372 | When possible, this static function will use the native file dialog and | - | ||||||||||||||||||
2373 | not a QFileDialog. On platforms which don't support selecting remote | - | ||||||||||||||||||
2374 | files, Qt will allow to select only local files. | - | ||||||||||||||||||
2375 | - | |||||||||||||||||||
2376 | \sa getSaveFileName(), getOpenFileUrl(), getOpenFileUrls(), getExistingDirectoryUrl() | - | ||||||||||||||||||
2377 | \since 5.2 | - | ||||||||||||||||||
2378 | */ | - | ||||||||||||||||||
2379 | QUrl QFileDialog::getSaveFileUrl(QWidget *parent, | - | ||||||||||||||||||
2380 | const QString &caption, | - | ||||||||||||||||||
2381 | const QUrl &dir, | - | ||||||||||||||||||
2382 | const QString &filter, | - | ||||||||||||||||||
2383 | QString *selectedFilter, | - | ||||||||||||||||||
2384 | Options options, | - | ||||||||||||||||||
2385 | const QStringList &supportedSchemes) | - | ||||||||||||||||||
2386 | { | - | ||||||||||||||||||
2387 | QFileDialogArgs args; | - | ||||||||||||||||||
2388 | args.parent = parent; | - | ||||||||||||||||||
2389 | args.caption = caption; | - | ||||||||||||||||||
2390 | args.directory = QFileDialogPrivate::workingDirectory(dir); | - | ||||||||||||||||||
2391 | args.selection = QFileDialogPrivate::initialSelection(dir); | - | ||||||||||||||||||
2392 | args.filter = filter; | - | ||||||||||||||||||
2393 | args.mode = AnyFile; | - | ||||||||||||||||||
2394 | args.options = options; | - | ||||||||||||||||||
2395 | - | |||||||||||||||||||
2396 | QFileDialog dialog(args); | - | ||||||||||||||||||
2397 | dialog.setSupportedSchemes(supportedSchemes); | - | ||||||||||||||||||
2398 | dialog.setAcceptMode(AcceptSave); | - | ||||||||||||||||||
2399 | if (selectedFilter && !selectedFilter->isEmpty())
| 0 | ||||||||||||||||||
2400 | dialog.selectNameFilter(*selectedFilter); never executed: dialog.selectNameFilter(*selectedFilter); | 0 | ||||||||||||||||||
2401 | if (dialog.exec() == QDialog::Accepted) {
| 0 | ||||||||||||||||||
2402 | if (selectedFilter)
| 0 | ||||||||||||||||||
2403 | *selectedFilter = dialog.selectedNameFilter(); never executed: *selectedFilter = dialog.selectedNameFilter(); | 0 | ||||||||||||||||||
2404 | return dialog.selectedUrls().value(0); never executed: return dialog.selectedUrls().value(0); | 0 | ||||||||||||||||||
2405 | } | - | ||||||||||||||||||
2406 | return QUrl(); never executed: return QUrl(); | 0 | ||||||||||||||||||
2407 | } | - | ||||||||||||||||||
2408 | - | |||||||||||||||||||
2409 | /*! | - | ||||||||||||||||||
2410 | This is a convenience static function that will return an existing | - | ||||||||||||||||||
2411 | directory selected by the user. | - | ||||||||||||||||||
2412 | - | |||||||||||||||||||
2413 | \snippet code/src_gui_dialogs_qfiledialog.cpp 12 | - | ||||||||||||||||||
2414 | - | |||||||||||||||||||
2415 | This function creates a modal file dialog with the given \a parent widget. | - | ||||||||||||||||||
2416 | If \a parent is not 0, the dialog will be shown centered over the parent | - | ||||||||||||||||||
2417 | widget. | - | ||||||||||||||||||
2418 | - | |||||||||||||||||||
2419 | The dialog's working directory is set to \a dir, and the caption is set to | - | ||||||||||||||||||
2420 | \a caption. Either of these may be an empty string in which case the | - | ||||||||||||||||||
2421 | current directory and a default caption will be used respectively. | - | ||||||||||||||||||
2422 | - | |||||||||||||||||||
2423 | The \a options argument holds various options about how to run the dialog, | - | ||||||||||||||||||
2424 | see the QFileDialog::Option enum for more information on the flags you can | - | ||||||||||||||||||
2425 | pass. To ensure a native file dialog, \l{QFileDialog::}{ShowDirsOnly} must | - | ||||||||||||||||||
2426 | be set. | - | ||||||||||||||||||
2427 | - | |||||||||||||||||||
2428 | On Windows and \macos, this static function will use the | - | ||||||||||||||||||
2429 | native file dialog and not a QFileDialog. However, the native Windows file | - | ||||||||||||||||||
2430 | dialog does not support displaying files in the directory chooser. You need | - | ||||||||||||||||||
2431 | to pass \l{QFileDialog::}{DontUseNativeDialog} to display files using a | - | ||||||||||||||||||
2432 | QFileDialog. On Windows CE, if the device has no native file dialog, a | - | ||||||||||||||||||
2433 | QFileDialog will be used. | - | ||||||||||||||||||
2434 | - | |||||||||||||||||||
2435 | On Unix/X11, the normal behavior of the file dialog is to resolve and | - | ||||||||||||||||||
2436 | follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp}, | - | ||||||||||||||||||
2437 | the file dialog will change to \c{/var/tmp} after entering \c{/usr/tmp}. If | - | ||||||||||||||||||
2438 | \a options includes DontResolveSymlinks, the file dialog will treat | - | ||||||||||||||||||
2439 | symlinks as regular directories. | - | ||||||||||||||||||
2440 | - | |||||||||||||||||||
2441 | On Windows, the dialog will spin a blocking modal event loop that will not | - | ||||||||||||||||||
2442 | dispatch any QTimers, and if \a parent is not 0 then it will position the | - | ||||||||||||||||||
2443 | dialog just below the parent's title bar. | - | ||||||||||||||||||
2444 | - | |||||||||||||||||||
2445 | \warning Do not delete \a parent during the execution of the dialog. If you | - | ||||||||||||||||||
2446 | want to do this, you should create the dialog yourself using one of the | - | ||||||||||||||||||
2447 | QFileDialog constructors. | - | ||||||||||||||||||
2448 | - | |||||||||||||||||||
2449 | \sa getOpenFileName(), getOpenFileNames(), getSaveFileName() | - | ||||||||||||||||||
2450 | */ | - | ||||||||||||||||||
2451 | QString QFileDialog::getExistingDirectory(QWidget *parent, | - | ||||||||||||||||||
2452 | const QString &caption, | - | ||||||||||||||||||
2453 | const QString &dir, | - | ||||||||||||||||||
2454 | Options options) | - | ||||||||||||||||||
2455 | { | - | ||||||||||||||||||
2456 | const QStringList schemes = QStringList(QStringLiteral("file")); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
2457 | const QUrl selectedUrl = getExistingDirectoryUrl(parent, caption, QUrl::fromLocalFile(dir), options, schemes); | - | ||||||||||||||||||
2458 | return selectedUrl.toLocalFile(); never executed: return selectedUrl.toLocalFile(); | 0 | ||||||||||||||||||
2459 | } | - | ||||||||||||||||||
2460 | - | |||||||||||||||||||
2461 | /*! | - | ||||||||||||||||||
2462 | This is a convenience static function that will return an existing | - | ||||||||||||||||||
2463 | directory selected by the user. If the user presses Cancel, it | - | ||||||||||||||||||
2464 | returns an empty url. | - | ||||||||||||||||||
2465 | - | |||||||||||||||||||
2466 | The function is used similarly to QFileDialog::getExistingDirectory(). | - | ||||||||||||||||||
2467 | In particular \a parent, \a caption, \a dir and \a options are used | - | ||||||||||||||||||
2468 | in the exact same way. | - | ||||||||||||||||||
2469 | - | |||||||||||||||||||
2470 | The main difference with QFileDialog::getExistingDirectory() comes from | - | ||||||||||||||||||
2471 | the ability offered to the user to select a remote directory. That's why | - | ||||||||||||||||||
2472 | the return type and the type of \a dir is QUrl. | - | ||||||||||||||||||
2473 | - | |||||||||||||||||||
2474 | The \a supportedSchemes argument allows to restrict the type of URLs the | - | ||||||||||||||||||
2475 | user will be able to select. It is a way for the application to declare | - | ||||||||||||||||||
2476 | the protocols it will support to fetch the file content. An empty list | - | ||||||||||||||||||
2477 | means that no restriction is applied (the default). | - | ||||||||||||||||||
2478 | Supported for local files ("file" scheme) is implicit and always enabled; | - | ||||||||||||||||||
2479 | it is not necessary to include it in the restriction. | - | ||||||||||||||||||
2480 | - | |||||||||||||||||||
2481 | When possible, this static function will use the native file dialog and | - | ||||||||||||||||||
2482 | not a QFileDialog. On platforms which don't support selecting remote | - | ||||||||||||||||||
2483 | files, Qt will allow to select only local files. | - | ||||||||||||||||||
2484 | - | |||||||||||||||||||
2485 | \sa getExistingDirectory(), getOpenFileUrl(), getOpenFileUrls(), getSaveFileUrl() | - | ||||||||||||||||||
2486 | \since 5.2 | - | ||||||||||||||||||
2487 | */ | - | ||||||||||||||||||
2488 | QUrl QFileDialog::getExistingDirectoryUrl(QWidget *parent, | - | ||||||||||||||||||
2489 | const QString &caption, | - | ||||||||||||||||||
2490 | const QUrl &dir, | - | ||||||||||||||||||
2491 | Options options, | - | ||||||||||||||||||
2492 | const QStringList &supportedSchemes) | - | ||||||||||||||||||
2493 | { | - | ||||||||||||||||||
2494 | QFileDialogArgs args; | - | ||||||||||||||||||
2495 | args.parent = parent; | - | ||||||||||||||||||
2496 | args.caption = caption; | - | ||||||||||||||||||
2497 | args.directory = QFileDialogPrivate::workingDirectory(dir); | - | ||||||||||||||||||
2498 | args.mode = (options & ShowDirsOnly ? DirectoryOnly : Directory);
| 0 | ||||||||||||||||||
2499 | args.options = options; | - | ||||||||||||||||||
2500 | - | |||||||||||||||||||
2501 | QFileDialog dialog(args); | - | ||||||||||||||||||
2502 | dialog.setSupportedSchemes(supportedSchemes); | - | ||||||||||||||||||
2503 | if (dialog.exec() == QDialog::Accepted)
| 0 | ||||||||||||||||||
2504 | return dialog.selectedUrls().value(0); never executed: return dialog.selectedUrls().value(0); | 0 | ||||||||||||||||||
2505 | return QUrl(); never executed: return QUrl(); | 0 | ||||||||||||||||||
2506 | } | - | ||||||||||||||||||
2507 | - | |||||||||||||||||||
2508 | inline static QUrl _qt_get_directory(const QUrl &url) | - | ||||||||||||||||||
2509 | { | - | ||||||||||||||||||
2510 | if (url.isLocalFile()) {
| 0 | ||||||||||||||||||
2511 | QFileInfo info = QFileInfo(QDir::current(), url.toLocalFile()); | - | ||||||||||||||||||
2512 | if (info.exists() && info.isDir())
| 0 | ||||||||||||||||||
2513 | return QUrl::fromLocalFile(QDir::cleanPath(info.absoluteFilePath())); never executed: return QUrl::fromLocalFile(QDir::cleanPath(info.absoluteFilePath())); | 0 | ||||||||||||||||||
2514 | info.setFile(info.absolutePath()); | - | ||||||||||||||||||
2515 | if (info.exists() && info.isDir())
| 0 | ||||||||||||||||||
2516 | return QUrl::fromLocalFile(info.absoluteFilePath()); never executed: return QUrl::fromLocalFile(info.absoluteFilePath()); | 0 | ||||||||||||||||||
2517 | return QUrl(); never executed: return QUrl(); | 0 | ||||||||||||||||||
2518 | } else { | - | ||||||||||||||||||
2519 | return url; never executed: return url; | 0 | ||||||||||||||||||
2520 | } | - | ||||||||||||||||||
2521 | } | - | ||||||||||||||||||
2522 | /* | - | ||||||||||||||||||
2523 | Get the initial directory URL | - | ||||||||||||||||||
2524 | - | |||||||||||||||||||
2525 | \sa initialSelection() | - | ||||||||||||||||||
2526 | */ | - | ||||||||||||||||||
2527 | QUrl QFileDialogPrivate::workingDirectory(const QUrl &url) | - | ||||||||||||||||||
2528 | { | - | ||||||||||||||||||
2529 | if (!url.isEmpty()) {
| 0 | ||||||||||||||||||
2530 | QUrl directory = _qt_get_directory(url); | - | ||||||||||||||||||
2531 | if (!directory.isEmpty())
| 0 | ||||||||||||||||||
2532 | return directory; never executed: return directory; | 0 | ||||||||||||||||||
2533 | } never executed: end of block | 0 | ||||||||||||||||||
2534 | QUrl directory = _qt_get_directory(*lastVisitedDir()); | - | ||||||||||||||||||
2535 | if (!directory.isEmpty())
| 0 | ||||||||||||||||||
2536 | return directory; never executed: return directory; | 0 | ||||||||||||||||||
2537 | return QUrl::fromLocalFile(QDir::currentPath()); never executed: return QUrl::fromLocalFile(QDir::currentPath()); | 0 | ||||||||||||||||||
2538 | } | - | ||||||||||||||||||
2539 | - | |||||||||||||||||||
2540 | /* | - | ||||||||||||||||||
2541 | Get the initial selection given a path. The initial directory | - | ||||||||||||||||||
2542 | can contain both the initial directory and initial selection | - | ||||||||||||||||||
2543 | /home/user/foo.txt | - | ||||||||||||||||||
2544 | - | |||||||||||||||||||
2545 | \sa workingDirectory() | - | ||||||||||||||||||
2546 | */ | - | ||||||||||||||||||
2547 | QString QFileDialogPrivate::initialSelection(const QUrl &url) | - | ||||||||||||||||||
2548 | { | - | ||||||||||||||||||
2549 | if (url.isEmpty())
| 0 | ||||||||||||||||||
2550 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
2551 | if (url.isLocalFile()) {
| 0 | ||||||||||||||||||
2552 | QFileInfo info(url.toLocalFile()); | - | ||||||||||||||||||
2553 | if (!info.isDir())
| 0 | ||||||||||||||||||
2554 | return info.fileName(); never executed: return info.fileName(); | 0 | ||||||||||||||||||
2555 | else | - | ||||||||||||||||||
2556 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
2557 | } | - | ||||||||||||||||||
2558 | // With remote URLs we can only assume. | - | ||||||||||||||||||
2559 | return url.fileName(); never executed: return url.fileName(); | 0 | ||||||||||||||||||
2560 | } | - | ||||||||||||||||||
2561 | - | |||||||||||||||||||
2562 | /*! | - | ||||||||||||||||||
2563 | \reimp | - | ||||||||||||||||||
2564 | */ | - | ||||||||||||||||||
2565 | void QFileDialog::done(int result) | - | ||||||||||||||||||
2566 | { | - | ||||||||||||||||||
2567 | Q_D(QFileDialog); | - | ||||||||||||||||||
2568 | - | |||||||||||||||||||
2569 | QDialog::done(result); | - | ||||||||||||||||||
2570 | - | |||||||||||||||||||
2571 | if (d->receiverToDisconnectOnClose) {
| 0 | ||||||||||||||||||
2572 | disconnect(this, d->signalToDisconnectOnClose, | - | ||||||||||||||||||
2573 | d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose); | - | ||||||||||||||||||
2574 | d->receiverToDisconnectOnClose = 0; | - | ||||||||||||||||||
2575 | } never executed: end of block | 0 | ||||||||||||||||||
2576 | d->memberToDisconnectOnClose.clear(); | - | ||||||||||||||||||
2577 | d->signalToDisconnectOnClose.clear(); | - | ||||||||||||||||||
2578 | } never executed: end of block | 0 | ||||||||||||||||||
2579 | - | |||||||||||||||||||
2580 | /*! | - | ||||||||||||||||||
2581 | \reimp | - | ||||||||||||||||||
2582 | */ | - | ||||||||||||||||||
2583 | void QFileDialog::accept() | - | ||||||||||||||||||
2584 | { | - | ||||||||||||||||||
2585 | Q_D(QFileDialog); | - | ||||||||||||||||||
2586 | if (!d->usingWidgets()) {
| 0 | ||||||||||||||||||
2587 | const QList<QUrl> urls = selectedUrls(); | - | ||||||||||||||||||
2588 | if (urls.isEmpty())
| 0 | ||||||||||||||||||
2589 | return; never executed: return; | 0 | ||||||||||||||||||
2590 | d->_q_emitUrlsSelected(urls); | - | ||||||||||||||||||
2591 | if (urls.count() == 1)
| 0 | ||||||||||||||||||
2592 | d->_q_emitUrlSelected(urls.first()); never executed: d->_q_emitUrlSelected(urls.first()); | 0 | ||||||||||||||||||
2593 | QDialog::accept(); | - | ||||||||||||||||||
2594 | return; never executed: return; | 0 | ||||||||||||||||||
2595 | } | - | ||||||||||||||||||
2596 | - | |||||||||||||||||||
2597 | QStringList files = selectedFiles(); | - | ||||||||||||||||||
2598 | if (files.isEmpty())
| 0 | ||||||||||||||||||
2599 | return; never executed: return; | 0 | ||||||||||||||||||
2600 | QString lineEditText = d->lineEdit()->text(); | - | ||||||||||||||||||
2601 | // "hidden feature" type .. and then enter, and it will move up a dir | - | ||||||||||||||||||
2602 | // special case for ".." | - | ||||||||||||||||||
2603 | if (lineEditText == QLatin1String("..")) {
| 0 | ||||||||||||||||||
2604 | d->_q_navigateToParent(); | - | ||||||||||||||||||
2605 | const QSignalBlocker blocker(d->qFileDialogUi->fileNameEdit); | - | ||||||||||||||||||
2606 | d->lineEdit()->selectAll(); | - | ||||||||||||||||||
2607 | return; never executed: return; | 0 | ||||||||||||||||||
2608 | } | - | ||||||||||||||||||
2609 | - | |||||||||||||||||||
2610 | switch (fileMode()) { | - | ||||||||||||||||||
2611 | case DirectoryOnly: never executed: case DirectoryOnly: | 0 | ||||||||||||||||||
2612 | case Directory: { never executed: case Directory: | 0 | ||||||||||||||||||
2613 | QString fn = files.first(); | - | ||||||||||||||||||
2614 | QFileInfo info(fn); | - | ||||||||||||||||||
2615 | if (!info.exists())
| 0 | ||||||||||||||||||
2616 | info = QFileInfo(d->getEnvironmentVariable(fn)); never executed: info = QFileInfo(d->getEnvironmentVariable(fn)); | 0 | ||||||||||||||||||
2617 | if (!info.exists()) {
| 0 | ||||||||||||||||||
2618 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||||||||
2619 | QString message = tr("%1\nDirectory not found.\nPlease verify the " | - | ||||||||||||||||||
2620 | "correct directory name was given."); | - | ||||||||||||||||||
2621 | QMessageBox::warning(this, windowTitle(), message.arg(info.fileName())); | - | ||||||||||||||||||
2622 | #endif // QT_NO_MESSAGEBOX | - | ||||||||||||||||||
2623 | return; never executed: return; | 0 | ||||||||||||||||||
2624 | } | - | ||||||||||||||||||
2625 | if (info.isDir()) {
| 0 | ||||||||||||||||||
2626 | d->emitFilesSelected(files); | - | ||||||||||||||||||
2627 | QDialog::accept(); | - | ||||||||||||||||||
2628 | } never executed: end of block | 0 | ||||||||||||||||||
2629 | return; never executed: return; | 0 | ||||||||||||||||||
2630 | } | - | ||||||||||||||||||
2631 | - | |||||||||||||||||||
2632 | case AnyFile: { never executed: case AnyFile: | 0 | ||||||||||||||||||
2633 | QString fn = files.first(); | - | ||||||||||||||||||
2634 | QFileInfo info(fn); | - | ||||||||||||||||||
2635 | if (info.isDir()) {
| 0 | ||||||||||||||||||
2636 | setDirectory(info.absoluteFilePath()); | - | ||||||||||||||||||
2637 | return; never executed: return; | 0 | ||||||||||||||||||
2638 | } | - | ||||||||||||||||||
2639 | - | |||||||||||||||||||
2640 | if (!info.exists()) {
| 0 | ||||||||||||||||||
2641 | int maxNameLength = d->maxNameLength(info.path()); | - | ||||||||||||||||||
2642 | if (maxNameLength >= 0 && info.fileName().length() > maxNameLength)
| 0 | ||||||||||||||||||
2643 | return; never executed: return; | 0 | ||||||||||||||||||
2644 | } never executed: end of block | 0 | ||||||||||||||||||
2645 | - | |||||||||||||||||||
2646 | // check if we have to ask for permission to overwrite the file | - | ||||||||||||||||||
2647 | if (!info.exists() || !confirmOverwrite() || acceptMode() == AcceptOpen) {
| 0 | ||||||||||||||||||
2648 | d->emitFilesSelected(QStringList(fn)); | - | ||||||||||||||||||
2649 | QDialog::accept(); | - | ||||||||||||||||||
2650 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||||||||
2651 | } else { never executed: end of block | 0 | ||||||||||||||||||
2652 | if (QMessageBox::warning(this, windowTitle(),
| 0 | ||||||||||||||||||
2653 | tr("%1 already exists.\nDo you want to replace it?")
| 0 | ||||||||||||||||||
2654 | .arg(info.fileName()),
| 0 | ||||||||||||||||||
2655 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
| 0 | ||||||||||||||||||
2656 | == QMessageBox::Yes) {
| 0 | ||||||||||||||||||
2657 | d->emitFilesSelected(QStringList(fn)); | - | ||||||||||||||||||
2658 | QDialog::accept(); | - | ||||||||||||||||||
2659 | } never executed: end of block | 0 | ||||||||||||||||||
2660 | #endif | - | ||||||||||||||||||
2661 | } never executed: end of block | 0 | ||||||||||||||||||
2662 | return; never executed: return; | 0 | ||||||||||||||||||
2663 | } | - | ||||||||||||||||||
2664 | - | |||||||||||||||||||
2665 | case ExistingFile: never executed: case ExistingFile: | 0 | ||||||||||||||||||
2666 | case ExistingFiles: never executed: case ExistingFiles: | 0 | ||||||||||||||||||
2667 | for (int i = 0; i < files.count(); ++i) {
| 0 | ||||||||||||||||||
2668 | QFileInfo info(files.at(i)); | - | ||||||||||||||||||
2669 | if (!info.exists())
| 0 | ||||||||||||||||||
2670 | info = QFileInfo(d->getEnvironmentVariable(files.at(i))); never executed: info = QFileInfo(d->getEnvironmentVariable(files.at(i))); | 0 | ||||||||||||||||||
2671 | if (!info.exists()) {
| 0 | ||||||||||||||||||
2672 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||||||||
2673 | QString message = tr("%1\nFile not found.\nPlease verify the " | - | ||||||||||||||||||
2674 | "correct file name was given."); | - | ||||||||||||||||||
2675 | QMessageBox::warning(this, windowTitle(), message.arg(info.fileName())); | - | ||||||||||||||||||
2676 | #endif // QT_NO_MESSAGEBOX | - | ||||||||||||||||||
2677 | return; never executed: return; | 0 | ||||||||||||||||||
2678 | } | - | ||||||||||||||||||
2679 | if (info.isDir()) {
| 0 | ||||||||||||||||||
2680 | setDirectory(info.absoluteFilePath()); | - | ||||||||||||||||||
2681 | d->lineEdit()->clear(); | - | ||||||||||||||||||
2682 | return; never executed: return; | 0 | ||||||||||||||||||
2683 | } | - | ||||||||||||||||||
2684 | } never executed: end of block | 0 | ||||||||||||||||||
2685 | d->emitFilesSelected(files); | - | ||||||||||||||||||
2686 | QDialog::accept(); | - | ||||||||||||||||||
2687 | return; never executed: return; | 0 | ||||||||||||||||||
2688 | } | - | ||||||||||||||||||
2689 | } never executed: end of block | 0 | ||||||||||||||||||
2690 | - | |||||||||||||||||||
2691 | #ifndef QT_NO_SETTINGS | - | ||||||||||||||||||
2692 | void QFileDialogPrivate::saveSettings() | - | ||||||||||||||||||
2693 | { | - | ||||||||||||||||||
2694 | Q_Q(QFileDialog); | - | ||||||||||||||||||
2695 | QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); | - | ||||||||||||||||||
2696 | settings.beginGroup(QLatin1String("FileDialog")); | - | ||||||||||||||||||
2697 | - | |||||||||||||||||||
2698 | if (usingWidgets()) {
| 0 | ||||||||||||||||||
2699 | settings.setValue(QLatin1String("sidebarWidth"), qFileDialogUi->splitter->sizes().first()); | - | ||||||||||||||||||
2700 | settings.setValue(QLatin1String("shortcuts"), QUrl::toStringList(qFileDialogUi->sidebar->urls())); | - | ||||||||||||||||||
2701 | settings.setValue(QLatin1String("treeViewHeader"), qFileDialogUi->treeView->header()->saveState()); | - | ||||||||||||||||||
2702 | } never executed: end of block | 0 | ||||||||||||||||||
2703 | QStringList historyUrls; | - | ||||||||||||||||||
2704 | const QStringList history = q->history(); | - | ||||||||||||||||||
2705 | historyUrls.reserve(history.size()); | - | ||||||||||||||||||
2706 | foreach (const QString &path, history) | - | ||||||||||||||||||
2707 | historyUrls << QUrl::fromLocalFile(path).toString(); never executed: historyUrls << QUrl::fromLocalFile(path).toString(); | 0 | ||||||||||||||||||
2708 | settings.setValue(QLatin1String("history"), historyUrls); | - | ||||||||||||||||||
2709 | settings.setValue(QLatin1String("lastVisited"), lastVisitedDir()->toString()); | - | ||||||||||||||||||
2710 | const QMetaEnum &viewModeMeta = q->metaObject()->enumerator(q->metaObject()->indexOfEnumerator("ViewMode")); | - | ||||||||||||||||||
2711 | settings.setValue(QLatin1String("viewMode"), QLatin1String(viewModeMeta.key(q->viewMode()))); | - | ||||||||||||||||||
2712 | settings.setValue(QLatin1String("qtVersion"), QLatin1String(QT_VERSION_STR)); | - | ||||||||||||||||||
2713 | } never executed: end of block | 0 | ||||||||||||||||||
2714 | - | |||||||||||||||||||
2715 | bool QFileDialogPrivate::restoreFromSettings() | - | ||||||||||||||||||
2716 | { | - | ||||||||||||||||||
2717 | Q_Q(QFileDialog); | - | ||||||||||||||||||
2718 | QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); | - | ||||||||||||||||||
2719 | if (!settings.childGroups().contains(QLatin1String("FileDialog")))
| 0 | ||||||||||||||||||
2720 | return false; never executed: return false; | 0 | ||||||||||||||||||
2721 | settings.beginGroup(QLatin1String("FileDialog")); | - | ||||||||||||||||||
2722 | - | |||||||||||||||||||
2723 | q->setDirectoryUrl(lastVisitedDir()->isEmpty() ? settings.value(QLatin1String("lastVisited")).toUrl() : *lastVisitedDir()); | - | ||||||||||||||||||
2724 | - | |||||||||||||||||||
2725 | QByteArray viewModeStr = settings.value(QLatin1String("viewMode")).toString().toLatin1(); | - | ||||||||||||||||||
2726 | const QMetaEnum &viewModeMeta = q->metaObject()->enumerator(q->metaObject()->indexOfEnumerator("ViewMode")); | - | ||||||||||||||||||
2727 | bool ok = false; | - | ||||||||||||||||||
2728 | int viewMode = viewModeMeta.keyToValue(viewModeStr.constData(), &ok); | - | ||||||||||||||||||
2729 | if (!ok)
| 0 | ||||||||||||||||||
2730 | viewMode = QFileDialog::List; never executed: viewMode = QFileDialog::List; | 0 | ||||||||||||||||||
2731 | q->setViewMode(static_cast<QFileDialog::ViewMode>(viewMode)); | - | ||||||||||||||||||
2732 | - | |||||||||||||||||||
2733 | sidebarUrls = QUrl::fromStringList(settings.value(QLatin1String("shortcuts")).toStringList()); | - | ||||||||||||||||||
2734 | headerData = settings.value(QLatin1String("treeViewHeader")).toByteArray(); | - | ||||||||||||||||||
2735 | - | |||||||||||||||||||
2736 | if (!usingWidgets())
| 0 | ||||||||||||||||||
2737 | return true; never executed: return true; | 0 | ||||||||||||||||||
2738 | - | |||||||||||||||||||
2739 | QStringList history; | - | ||||||||||||||||||
2740 | foreach (const QString &urlStr, settings.value(QLatin1String("history")).toStringList()) { | - | ||||||||||||||||||
2741 | QUrl url(urlStr); | - | ||||||||||||||||||
2742 | if (url.isLocalFile())
| 0 | ||||||||||||||||||
2743 | history << url.toLocalFile(); never executed: history << url.toLocalFile(); | 0 | ||||||||||||||||||
2744 | } never executed: end of block | 0 | ||||||||||||||||||
2745 | - | |||||||||||||||||||
2746 | return restoreWidgetState(history, settings.value(QLatin1String("sidebarWidth"), -1).toInt()); never executed: return restoreWidgetState(history, settings.value(QLatin1String("sidebarWidth"), -1).toInt()); | 0 | ||||||||||||||||||
2747 | } | - | ||||||||||||||||||
2748 | #endif // QT_NO_SETTINGS | - | ||||||||||||||||||
2749 | - | |||||||||||||||||||
2750 | bool QFileDialogPrivate::restoreWidgetState(QStringList &history, int splitterPosition) | - | ||||||||||||||||||
2751 | { | - | ||||||||||||||||||
2752 | Q_Q(QFileDialog); | - | ||||||||||||||||||
2753 | if (splitterPosition >= 0) {
| 0 | ||||||||||||||||||
2754 | QList<int> splitterSizes; | - | ||||||||||||||||||
2755 | splitterSizes.append(splitterPosition); | - | ||||||||||||||||||
2756 | splitterSizes.append(qFileDialogUi->splitter->widget(1)->sizeHint().width()); | - | ||||||||||||||||||
2757 | qFileDialogUi->splitter->setSizes(splitterSizes); | - | ||||||||||||||||||
2758 | } else { never executed: end of block | 0 | ||||||||||||||||||
2759 | if (!qFileDialogUi->splitter->restoreState(splitterState))
| 0 | ||||||||||||||||||
2760 | return false; never executed: return false; | 0 | ||||||||||||||||||
2761 | QList<int> list = qFileDialogUi->splitter->sizes(); | - | ||||||||||||||||||
2762 | if (list.count() >= 2 && (list.at(0) == 0 || list.at(1) == 0)) {
| 0 | ||||||||||||||||||
2763 | for (int i = 0; i < list.count(); ++i)
| 0 | ||||||||||||||||||
2764 | list[i] = qFileDialogUi->splitter->widget(i)->sizeHint().width(); never executed: list[i] = qFileDialogUi->splitter->widget(i)->sizeHint().width(); | 0 | ||||||||||||||||||
2765 | qFileDialogUi->splitter->setSizes(list); | - | ||||||||||||||||||
2766 | } never executed: end of block | 0 | ||||||||||||||||||
2767 | } never executed: end of block | 0 | ||||||||||||||||||
2768 | - | |||||||||||||||||||
2769 | qFileDialogUi->sidebar->setUrls(sidebarUrls); | - | ||||||||||||||||||
2770 | while (history.count() > 5)
| 0 | ||||||||||||||||||
2771 | history.pop_front(); never executed: history.pop_front(); | 0 | ||||||||||||||||||
2772 | q->setHistory(history); | - | ||||||||||||||||||
2773 | - | |||||||||||||||||||
2774 | QHeaderView *headerView = qFileDialogUi->treeView->header(); | - | ||||||||||||||||||
2775 | if (!headerView->restoreState(headerData))
| 0 | ||||||||||||||||||
2776 | return false; never executed: return false; | 0 | ||||||||||||||||||
2777 | - | |||||||||||||||||||
2778 | QList<QAction*> actions = headerView->actions(); | - | ||||||||||||||||||
2779 | QAbstractItemModel *abstractModel = model; | - | ||||||||||||||||||
2780 | #ifndef QT_NO_PROXYMODEL | - | ||||||||||||||||||
2781 | if (proxyModel)
| 0 | ||||||||||||||||||
2782 | abstractModel = proxyModel; never executed: abstractModel = proxyModel; | 0 | ||||||||||||||||||
2783 | #endif | - | ||||||||||||||||||
2784 | int total = qMin(abstractModel->columnCount(QModelIndex()), actions.count() + 1); | - | ||||||||||||||||||
2785 | for (int i = 1; i < total; ++i)
| 0 | ||||||||||||||||||
2786 | actions.at(i - 1)->setChecked(!headerView->isSectionHidden(i)); never executed: actions.at(i - 1)->setChecked(!headerView->isSectionHidden(i)); | 0 | ||||||||||||||||||
2787 | - | |||||||||||||||||||
2788 | return true; never executed: return true; | 0 | ||||||||||||||||||
2789 | } | - | ||||||||||||||||||
2790 | - | |||||||||||||||||||
2791 | /*! | - | ||||||||||||||||||
2792 | \internal | - | ||||||||||||||||||
2793 | - | |||||||||||||||||||
2794 | Create widgets, layout and set default values | - | ||||||||||||||||||
2795 | */ | - | ||||||||||||||||||
2796 | void QFileDialogPrivate::init(const QUrl &directory, const QString &nameFilter, | - | ||||||||||||||||||
2797 | const QString &caption) | - | ||||||||||||||||||
2798 | { | - | ||||||||||||||||||
2799 | Q_Q(QFileDialog); | - | ||||||||||||||||||
2800 | if (!caption.isEmpty()) {
| 0 | ||||||||||||||||||
2801 | useDefaultCaption = false; | - | ||||||||||||||||||
2802 | setWindowTitle = caption; | - | ||||||||||||||||||
2803 | q->setWindowTitle(caption); | - | ||||||||||||||||||
2804 | } never executed: end of block | 0 | ||||||||||||||||||
2805 | - | |||||||||||||||||||
2806 | q->setAcceptMode(QFileDialog::AcceptOpen); | - | ||||||||||||||||||
2807 | nativeDialogInUse = (canBeNativeDialog() && platformFileDialogHelper() != 0);
| 0 | ||||||||||||||||||
2808 | if (!nativeDialogInUse)
| 0 | ||||||||||||||||||
2809 | createWidgets(); never executed: createWidgets(); | 0 | ||||||||||||||||||
2810 | q->setFileMode(QFileDialog::AnyFile); | - | ||||||||||||||||||
2811 | if (!nameFilter.isEmpty())
| 0 | ||||||||||||||||||
2812 | q->setNameFilter(nameFilter); never executed: q->setNameFilter(nameFilter); | 0 | ||||||||||||||||||
2813 | q->setDirectoryUrl(workingDirectory(directory)); | - | ||||||||||||||||||
2814 | q->selectFile(initialSelection(directory)); | - | ||||||||||||||||||
2815 | - | |||||||||||||||||||
2816 | #ifndef QT_NO_SETTINGS | - | ||||||||||||||||||
2817 | // Try to restore from the FileDialog settings group; if it fails, fall back | - | ||||||||||||||||||
2818 | // to the pre-5.5 QByteArray serialized settings. | - | ||||||||||||||||||
2819 | if (!restoreFromSettings()) {
| 0 | ||||||||||||||||||
2820 | const QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); | - | ||||||||||||||||||
2821 | q->restoreState(settings.value(QLatin1String("Qt/filedialog")).toByteArray()); | - | ||||||||||||||||||
2822 | } never executed: end of block | 0 | ||||||||||||||||||
2823 | #endif | - | ||||||||||||||||||
2824 | - | |||||||||||||||||||
2825 | #if defined(Q_EMBEDDED_SMALLSCREEN) | - | ||||||||||||||||||
2826 | qFileDialogUi->lookInLabel->setVisible(false); | - | ||||||||||||||||||
2827 | qFileDialogUi->fileNameLabel->setVisible(false); | - | ||||||||||||||||||
2828 | qFileDialogUi->fileTypeLabel->setVisible(false); | - | ||||||||||||||||||
2829 | qFileDialogUi->sidebar->hide(); | - | ||||||||||||||||||
2830 | #endif | - | ||||||||||||||||||
2831 | - | |||||||||||||||||||
2832 | const QSize sizeHint = q->sizeHint(); | - | ||||||||||||||||||
2833 | if (sizeHint.isValid())
| 0 | ||||||||||||||||||
2834 | q->resize(sizeHint); never executed: q->resize(sizeHint); | 0 | ||||||||||||||||||
2835 | } never executed: end of block | 0 | ||||||||||||||||||
2836 | - | |||||||||||||||||||
2837 | /*! | - | ||||||||||||||||||
2838 | \internal | - | ||||||||||||||||||
2839 | - | |||||||||||||||||||
2840 | Create the widgets, set properties and connections | - | ||||||||||||||||||
2841 | */ | - | ||||||||||||||||||
2842 | void QFileDialogPrivate::createWidgets() | - | ||||||||||||||||||
2843 | { | - | ||||||||||||||||||
2844 | if (qFileDialogUi)
| 0 | ||||||||||||||||||
2845 | return; never executed: return; | 0 | ||||||||||||||||||
2846 | Q_Q(QFileDialog); | - | ||||||||||||||||||
2847 | - | |||||||||||||||||||
2848 | // This function is sometimes called late (e.g as a fallback from setVisible). In that case we | - | ||||||||||||||||||
2849 | // need to ensure that the following UI code (setupUI in particular) doesn't reset any explicitly | - | ||||||||||||||||||
2850 | // set window state or geometry. | - | ||||||||||||||||||
2851 | QSize preSize = q->testAttribute(Qt::WA_Resized) ? q->size() : QSize();
| 0 | ||||||||||||||||||
2852 | Qt::WindowStates preState = q->windowState(); | - | ||||||||||||||||||
2853 | - | |||||||||||||||||||
2854 | model = new QFileSystemModel(q); | - | ||||||||||||||||||
2855 | model->setFilter(options->filter()); | - | ||||||||||||||||||
2856 | model->setObjectName(QLatin1String("qt_filesystem_model")); | - | ||||||||||||||||||
2857 | if (QPlatformFileDialogHelper *helper = platformFileDialogHelper())
| 0 | ||||||||||||||||||
2858 | model->setNameFilterDisables(helper->defaultNameFilterDisables()); never executed: model->setNameFilterDisables(helper->defaultNameFilterDisables()); | 0 | ||||||||||||||||||
2859 | else | - | ||||||||||||||||||
2860 | model->setNameFilterDisables(false); never executed: model->setNameFilterDisables(false); | 0 | ||||||||||||||||||
2861 | if (nativeDialogInUse)
| 0 | ||||||||||||||||||
2862 | deletePlatformHelper(); never executed: deletePlatformHelper(); | 0 | ||||||||||||||||||
2863 | model->d_func()->disableRecursiveSort = true; | - | ||||||||||||||||||
2864 | QFileDialog::connect(model, SIGNAL(fileRenamed(QString,QString,QString)), q, SLOT(_q_fileRenamed(QString,QString,QString))); | - | ||||||||||||||||||
2865 | QFileDialog::connect(model, SIGNAL(rootPathChanged(QString)), | - | ||||||||||||||||||
2866 | q, SLOT(_q_pathChanged(QString))); | - | ||||||||||||||||||
2867 | QFileDialog::connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
2868 | q, SLOT(_q_rowsInserted(QModelIndex))); | - | ||||||||||||||||||
2869 | model->setReadOnly(false); | - | ||||||||||||||||||
2870 | - | |||||||||||||||||||
2871 | qFileDialogUi.reset(new Ui_QFileDialog()); | - | ||||||||||||||||||
2872 | qFileDialogUi->setupUi(q); | - | ||||||||||||||||||
2873 | - | |||||||||||||||||||
2874 | QList<QUrl> initialBookmarks; | - | ||||||||||||||||||
2875 | initialBookmarks << QUrl(QLatin1String("file:")) | - | ||||||||||||||||||
2876 | << QUrl::fromLocalFile(QDir::homePath()); | - | ||||||||||||||||||
2877 | qFileDialogUi->sidebar->setModelAndUrls(model, initialBookmarks); | - | ||||||||||||||||||
2878 | QFileDialog::connect(qFileDialogUi->sidebar, SIGNAL(goToUrl(QUrl)), | - | ||||||||||||||||||
2879 | q, SLOT(_q_goToUrl(QUrl))); | - | ||||||||||||||||||
2880 | - | |||||||||||||||||||
2881 | QObject::connect(qFileDialogUi->buttonBox, SIGNAL(accepted()), q, SLOT(accept())); | - | ||||||||||||||||||
2882 | QObject::connect(qFileDialogUi->buttonBox, SIGNAL(rejected()), q, SLOT(reject())); | - | ||||||||||||||||||
2883 | - | |||||||||||||||||||
2884 | qFileDialogUi->lookInCombo->setFileDialogPrivate(this); | - | ||||||||||||||||||
2885 | QObject::connect(qFileDialogUi->lookInCombo, SIGNAL(activated(QString)), q, SLOT(_q_goToDirectory(QString))); | - | ||||||||||||||||||
2886 | - | |||||||||||||||||||
2887 | qFileDialogUi->lookInCombo->setInsertPolicy(QComboBox::NoInsert); | - | ||||||||||||||||||
2888 | qFileDialogUi->lookInCombo->setDuplicatesEnabled(false); | - | ||||||||||||||||||
2889 | - | |||||||||||||||||||
2890 | // filename | - | ||||||||||||||||||
2891 | qFileDialogUi->fileNameEdit->setFileDialogPrivate(this); | - | ||||||||||||||||||
2892 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||
2893 | qFileDialogUi->fileNameLabel->setBuddy(qFileDialogUi->fileNameEdit); | - | ||||||||||||||||||
2894 | #endif | - | ||||||||||||||||||
2895 | #ifndef QT_NO_FSCOMPLETER | - | ||||||||||||||||||
2896 | completer = new QFSCompleter(model, q); | - | ||||||||||||||||||
2897 | qFileDialogUi->fileNameEdit->setCompleter(completer); | - | ||||||||||||||||||
2898 | #endif // QT_NO_FSCOMPLETER | - | ||||||||||||||||||
2899 | - | |||||||||||||||||||
2900 | qFileDialogUi->fileNameEdit->setInputMethodHints(Qt::ImhNoPredictiveText); | - | ||||||||||||||||||
2901 | - | |||||||||||||||||||
2902 | QObject::connect(qFileDialogUi->fileNameEdit, SIGNAL(textChanged(QString)), | - | ||||||||||||||||||
2903 | q, SLOT(_q_autoCompleteFileName(QString))); | - | ||||||||||||||||||
2904 | QObject::connect(qFileDialogUi->fileNameEdit, SIGNAL(textChanged(QString)), | - | ||||||||||||||||||
2905 | q, SLOT(_q_updateOkButton())); | - | ||||||||||||||||||
2906 | - | |||||||||||||||||||
2907 | QObject::connect(qFileDialogUi->fileNameEdit, SIGNAL(returnPressed()), q, SLOT(accept())); | - | ||||||||||||||||||
2908 | - | |||||||||||||||||||
2909 | // filetype | - | ||||||||||||||||||
2910 | qFileDialogUi->fileTypeCombo->setDuplicatesEnabled(false); | - | ||||||||||||||||||
2911 | qFileDialogUi->fileTypeCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength); | - | ||||||||||||||||||
2912 | qFileDialogUi->fileTypeCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); | - | ||||||||||||||||||
2913 | QObject::connect(qFileDialogUi->fileTypeCombo, SIGNAL(activated(int)), | - | ||||||||||||||||||
2914 | q, SLOT(_q_useNameFilter(int))); | - | ||||||||||||||||||
2915 | QObject::connect(qFileDialogUi->fileTypeCombo, SIGNAL(activated(QString)), | - | ||||||||||||||||||
2916 | q, SIGNAL(filterSelected(QString))); | - | ||||||||||||||||||
2917 | - | |||||||||||||||||||
2918 | qFileDialogUi->listView->setFileDialogPrivate(this); | - | ||||||||||||||||||
2919 | qFileDialogUi->listView->setModel(model); | - | ||||||||||||||||||
2920 | QObject::connect(qFileDialogUi->listView, SIGNAL(activated(QModelIndex)), | - | ||||||||||||||||||
2921 | q, SLOT(_q_enterDirectory(QModelIndex))); | - | ||||||||||||||||||
2922 | QObject::connect(qFileDialogUi->listView, SIGNAL(customContextMenuRequested(QPoint)), | - | ||||||||||||||||||
2923 | q, SLOT(_q_showContextMenu(QPoint))); | - | ||||||||||||||||||
2924 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||
2925 | QShortcut *shortcut = new QShortcut(qFileDialogUi->listView); | - | ||||||||||||||||||
2926 | shortcut->setKey(QKeySequence(QLatin1String("Delete"))); | - | ||||||||||||||||||
2927 | QObject::connect(shortcut, SIGNAL(activated()), q, SLOT(_q_deleteCurrent())); | - | ||||||||||||||||||
2928 | #endif | - | ||||||||||||||||||
2929 | - | |||||||||||||||||||
2930 | qFileDialogUi->treeView->setFileDialogPrivate(this); | - | ||||||||||||||||||
2931 | qFileDialogUi->treeView->setModel(model); | - | ||||||||||||||||||
2932 | QHeaderView *treeHeader = qFileDialogUi->treeView->header(); | - | ||||||||||||||||||
2933 | QFontMetrics fm(q->font()); | - | ||||||||||||||||||
2934 | treeHeader->resizeSection(0, fm.width(QLatin1String("wwwwwwwwwwwwwwwwwwwwwwwwww"))); | - | ||||||||||||||||||
2935 | treeHeader->resizeSection(1, fm.width(QLatin1String("128.88 GB"))); | - | ||||||||||||||||||
2936 | treeHeader->resizeSection(2, fm.width(QLatin1String("mp3Folder"))); | - | ||||||||||||||||||
2937 | treeHeader->resizeSection(3, fm.width(QLatin1String("10/29/81 02:02PM"))); | - | ||||||||||||||||||
2938 | treeHeader->setContextMenuPolicy(Qt::ActionsContextMenu); | - | ||||||||||||||||||
2939 | - | |||||||||||||||||||
2940 | QActionGroup *showActionGroup = new QActionGroup(q); | - | ||||||||||||||||||
2941 | showActionGroup->setExclusive(false); | - | ||||||||||||||||||
2942 | QObject::connect(showActionGroup, SIGNAL(triggered(QAction*)), | - | ||||||||||||||||||
2943 | q, SLOT(_q_showHeader(QAction*)));; | - | ||||||||||||||||||
2944 | - | |||||||||||||||||||
2945 | QAbstractItemModel *abstractModel = model; | - | ||||||||||||||||||
2946 | #ifndef QT_NO_PROXYMODEL | - | ||||||||||||||||||
2947 | if (proxyModel)
| 0 | ||||||||||||||||||
2948 | abstractModel = proxyModel; never executed: abstractModel = proxyModel; | 0 | ||||||||||||||||||
2949 | #endif | - | ||||||||||||||||||
2950 | for (int i = 1; i < abstractModel->columnCount(QModelIndex()); ++i) {
| 0 | ||||||||||||||||||
2951 | QAction *showHeader = new QAction(showActionGroup); | - | ||||||||||||||||||
2952 | showHeader->setCheckable(true); | - | ||||||||||||||||||
2953 | showHeader->setChecked(true); | - | ||||||||||||||||||
2954 | treeHeader->addAction(showHeader); | - | ||||||||||||||||||
2955 | } never executed: end of block | 0 | ||||||||||||||||||
2956 | - | |||||||||||||||||||
2957 | QScopedPointer<QItemSelectionModel> selModel(qFileDialogUi->treeView->selectionModel()); | - | ||||||||||||||||||
2958 | qFileDialogUi->treeView->setSelectionModel(qFileDialogUi->listView->selectionModel()); | - | ||||||||||||||||||
2959 | - | |||||||||||||||||||
2960 | QObject::connect(qFileDialogUi->treeView, SIGNAL(activated(QModelIndex)), | - | ||||||||||||||||||
2961 | q, SLOT(_q_enterDirectory(QModelIndex))); | - | ||||||||||||||||||
2962 | QObject::connect(qFileDialogUi->treeView, SIGNAL(customContextMenuRequested(QPoint)), | - | ||||||||||||||||||
2963 | q, SLOT(_q_showContextMenu(QPoint))); | - | ||||||||||||||||||
2964 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||
2965 | shortcut = new QShortcut(qFileDialogUi->treeView); | - | ||||||||||||||||||
2966 | shortcut->setKey(QKeySequence(QLatin1String("Delete"))); | - | ||||||||||||||||||
2967 | QObject::connect(shortcut, SIGNAL(activated()), q, SLOT(_q_deleteCurrent())); | - | ||||||||||||||||||
2968 | #endif | - | ||||||||||||||||||
2969 | - | |||||||||||||||||||
2970 | // Selections | - | ||||||||||||||||||
2971 | QItemSelectionModel *selections = qFileDialogUi->listView->selectionModel(); | - | ||||||||||||||||||
2972 | QObject::connect(selections, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), | - | ||||||||||||||||||
2973 | q, SLOT(_q_selectionChanged())); | - | ||||||||||||||||||
2974 | QObject::connect(selections, SIGNAL(currentChanged(QModelIndex,QModelIndex)), | - | ||||||||||||||||||
2975 | q, SLOT(_q_currentChanged(QModelIndex))); | - | ||||||||||||||||||
2976 | qFileDialogUi->splitter->setStretchFactor(qFileDialogUi->splitter->indexOf(qFileDialogUi->splitter->widget(1)), QSizePolicy::Expanding); | - | ||||||||||||||||||
2977 | - | |||||||||||||||||||
2978 | createToolButtons(); | - | ||||||||||||||||||
2979 | createMenuActions(); | - | ||||||||||||||||||
2980 | - | |||||||||||||||||||
2981 | #ifndef QT_NO_SETTINGS | - | ||||||||||||||||||
2982 | // Try to restore from the FileDialog settings group; if it fails, fall back | - | ||||||||||||||||||
2983 | // to the pre-5.5 QByteArray serialized settings. | - | ||||||||||||||||||
2984 | if (!restoreFromSettings()) {
| 0 | ||||||||||||||||||
2985 | const QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); | - | ||||||||||||||||||
2986 | q->restoreState(settings.value(QLatin1String("Qt/filedialog")).toByteArray()); | - | ||||||||||||||||||
2987 | } never executed: end of block | 0 | ||||||||||||||||||
2988 | #endif | - | ||||||||||||||||||
2989 | - | |||||||||||||||||||
2990 | // Initial widget states from options | - | ||||||||||||||||||
2991 | q->setFileMode(static_cast<QFileDialog::FileMode>(options->fileMode())); | - | ||||||||||||||||||
2992 | q->setAcceptMode(static_cast<QFileDialog::AcceptMode>(options->acceptMode())); | - | ||||||||||||||||||
2993 | q->setViewMode(static_cast<QFileDialog::ViewMode>(options->viewMode())); | - | ||||||||||||||||||
2994 | q->setOptions(static_cast<QFileDialog::Options>(static_cast<int>(options->options()))); | - | ||||||||||||||||||
2995 | if (!options->sidebarUrls().isEmpty())
| 0 | ||||||||||||||||||
2996 | q->setSidebarUrls(options->sidebarUrls()); never executed: q->setSidebarUrls(options->sidebarUrls()); | 0 | ||||||||||||||||||
2997 | q->setDirectoryUrl(options->initialDirectory()); | - | ||||||||||||||||||
2998 | #ifndef QT_NO_MIMETYPE | - | ||||||||||||||||||
2999 | if (!options->mimeTypeFilters().isEmpty())
| 0 | ||||||||||||||||||
3000 | q->setMimeTypeFilters(options->mimeTypeFilters()); never executed: q->setMimeTypeFilters(options->mimeTypeFilters()); | 0 | ||||||||||||||||||
3001 | else | - | ||||||||||||||||||
3002 | #endif | - | ||||||||||||||||||
3003 | if (!options->nameFilters().isEmpty())
| 0 | ||||||||||||||||||
3004 | q->setNameFilters(options->nameFilters()); never executed: q->setNameFilters(options->nameFilters()); | 0 | ||||||||||||||||||
3005 | q->selectNameFilter(options->initiallySelectedNameFilter()); | - | ||||||||||||||||||
3006 | q->setDefaultSuffix(options->defaultSuffix()); | - | ||||||||||||||||||
3007 | q->setHistory(options->history()); | - | ||||||||||||||||||
3008 | if (options->initiallySelectedFiles().count() == 1)
| 0 | ||||||||||||||||||
3009 | q->selectFile(options->initiallySelectedFiles().first().fileName()); never executed: q->selectFile(options->initiallySelectedFiles().first().fileName()); | 0 | ||||||||||||||||||
3010 | foreach (const QUrl &url, options->initiallySelectedFiles()) | - | ||||||||||||||||||
3011 | q->selectUrl(url); never executed: q->selectUrl(url); | 0 | ||||||||||||||||||
3012 | lineEdit()->selectAll(); | - | ||||||||||||||||||
3013 | _q_updateOkButton(); | - | ||||||||||||||||||
3014 | retranslateStrings(); | - | ||||||||||||||||||
3015 | q->resize(preSize.isValid() ? preSize : q->sizeHint()); | - | ||||||||||||||||||
3016 | q->setWindowState(preState); | - | ||||||||||||||||||
3017 | } never executed: end of block | 0 | ||||||||||||||||||
3018 | - | |||||||||||||||||||
3019 | void QFileDialogPrivate::_q_showHeader(QAction *action) | - | ||||||||||||||||||
3020 | { | - | ||||||||||||||||||
3021 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3022 | QActionGroup *actionGroup = qobject_cast<QActionGroup*>(q->sender()); | - | ||||||||||||||||||
3023 | qFileDialogUi->treeView->header()->setSectionHidden(actionGroup->actions().indexOf(action) + 1, !action->isChecked()); | - | ||||||||||||||||||
3024 | } never executed: end of block | 0 | ||||||||||||||||||
3025 | - | |||||||||||||||||||
3026 | #ifndef QT_NO_PROXYMODEL | - | ||||||||||||||||||
3027 | /*! | - | ||||||||||||||||||
3028 | \since 4.3 | - | ||||||||||||||||||
3029 | - | |||||||||||||||||||
3030 | Sets the model for the views to the given \a proxyModel. This is useful if you | - | ||||||||||||||||||
3031 | want to modify the underlying model; for example, to add columns, filter | - | ||||||||||||||||||
3032 | data or add drives. | - | ||||||||||||||||||
3033 | - | |||||||||||||||||||
3034 | Any existing proxy model will be removed, but not deleted. The file dialog | - | ||||||||||||||||||
3035 | will take ownership of the \a proxyModel. | - | ||||||||||||||||||
3036 | - | |||||||||||||||||||
3037 | \sa proxyModel() | - | ||||||||||||||||||
3038 | */ | - | ||||||||||||||||||
3039 | void QFileDialog::setProxyModel(QAbstractProxyModel *proxyModel) | - | ||||||||||||||||||
3040 | { | - | ||||||||||||||||||
3041 | Q_D(QFileDialog); | - | ||||||||||||||||||
3042 | if (!d->usingWidgets())
| 0 | ||||||||||||||||||
3043 | return; never executed: return; | 0 | ||||||||||||||||||
3044 | if ((!proxyModel && !d->proxyModel)
| 0 | ||||||||||||||||||
3045 | || (proxyModel == d->proxyModel))
| 0 | ||||||||||||||||||
3046 | return; never executed: return; | 0 | ||||||||||||||||||
3047 | - | |||||||||||||||||||
3048 | QModelIndex idx = d->rootIndex(); | - | ||||||||||||||||||
3049 | if (d->proxyModel) {
| 0 | ||||||||||||||||||
3050 | disconnect(d->proxyModel, SIGNAL(rowsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
3051 | this, SLOT(_q_rowsInserted(QModelIndex))); | - | ||||||||||||||||||
3052 | } else { never executed: end of block | 0 | ||||||||||||||||||
3053 | disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
3054 | this, SLOT(_q_rowsInserted(QModelIndex))); | - | ||||||||||||||||||
3055 | } never executed: end of block | 0 | ||||||||||||||||||
3056 | - | |||||||||||||||||||
3057 | if (proxyModel != 0) {
| 0 | ||||||||||||||||||
3058 | proxyModel->setParent(this); | - | ||||||||||||||||||
3059 | d->proxyModel = proxyModel; | - | ||||||||||||||||||
3060 | proxyModel->setSourceModel(d->model); | - | ||||||||||||||||||
3061 | d->qFileDialogUi->listView->setModel(d->proxyModel); | - | ||||||||||||||||||
3062 | d->qFileDialogUi->treeView->setModel(d->proxyModel); | - | ||||||||||||||||||
3063 | #ifndef QT_NO_FSCOMPLETER | - | ||||||||||||||||||
3064 | d->completer->setModel(d->proxyModel); | - | ||||||||||||||||||
3065 | d->completer->proxyModel = d->proxyModel; | - | ||||||||||||||||||
3066 | #endif | - | ||||||||||||||||||
3067 | connect(d->proxyModel, SIGNAL(rowsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
3068 | this, SLOT(_q_rowsInserted(QModelIndex))); | - | ||||||||||||||||||
3069 | } else { never executed: end of block | 0 | ||||||||||||||||||
3070 | d->proxyModel = 0; | - | ||||||||||||||||||
3071 | d->qFileDialogUi->listView->setModel(d->model); | - | ||||||||||||||||||
3072 | d->qFileDialogUi->treeView->setModel(d->model); | - | ||||||||||||||||||
3073 | #ifndef QT_NO_FSCOMPLETER | - | ||||||||||||||||||
3074 | d->completer->setModel(d->model); | - | ||||||||||||||||||
3075 | d->completer->sourceModel = d->model; | - | ||||||||||||||||||
3076 | d->completer->proxyModel = 0; | - | ||||||||||||||||||
3077 | #endif | - | ||||||||||||||||||
3078 | connect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
3079 | this, SLOT(_q_rowsInserted(QModelIndex))); | - | ||||||||||||||||||
3080 | } never executed: end of block | 0 | ||||||||||||||||||
3081 | QScopedPointer<QItemSelectionModel> selModel(d->qFileDialogUi->treeView->selectionModel()); | - | ||||||||||||||||||
3082 | d->qFileDialogUi->treeView->setSelectionModel(d->qFileDialogUi->listView->selectionModel()); | - | ||||||||||||||||||
3083 | - | |||||||||||||||||||
3084 | d->setRootIndex(idx); | - | ||||||||||||||||||
3085 | - | |||||||||||||||||||
3086 | // reconnect selection | - | ||||||||||||||||||
3087 | QItemSelectionModel *selections = d->qFileDialogUi->listView->selectionModel(); | - | ||||||||||||||||||
3088 | QObject::connect(selections, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), | - | ||||||||||||||||||
3089 | this, SLOT(_q_selectionChanged())); | - | ||||||||||||||||||
3090 | QObject::connect(selections, SIGNAL(currentChanged(QModelIndex,QModelIndex)), | - | ||||||||||||||||||
3091 | this, SLOT(_q_currentChanged(QModelIndex))); | - | ||||||||||||||||||
3092 | } never executed: end of block | 0 | ||||||||||||||||||
3093 | - | |||||||||||||||||||
3094 | /*! | - | ||||||||||||||||||
3095 | Returns the proxy model used by the file dialog. By default no proxy is set. | - | ||||||||||||||||||
3096 | - | |||||||||||||||||||
3097 | \sa setProxyModel() | - | ||||||||||||||||||
3098 | */ | - | ||||||||||||||||||
3099 | QAbstractProxyModel *QFileDialog::proxyModel() const | - | ||||||||||||||||||
3100 | { | - | ||||||||||||||||||
3101 | Q_D(const QFileDialog); | - | ||||||||||||||||||
3102 | return d->proxyModel; never executed: return d->proxyModel; | 0 | ||||||||||||||||||
3103 | } | - | ||||||||||||||||||
3104 | #endif // QT_NO_PROXYMODEL | - | ||||||||||||||||||
3105 | - | |||||||||||||||||||
3106 | /*! | - | ||||||||||||||||||
3107 | \internal | - | ||||||||||||||||||
3108 | - | |||||||||||||||||||
3109 | Create tool buttons, set properties and connections | - | ||||||||||||||||||
3110 | */ | - | ||||||||||||||||||
3111 | void QFileDialogPrivate::createToolButtons() | - | ||||||||||||||||||
3112 | { | - | ||||||||||||||||||
3113 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3114 | qFileDialogUi->backButton->setIcon(q->style()->standardIcon(QStyle::SP_ArrowBack, 0, q)); | - | ||||||||||||||||||
3115 | qFileDialogUi->backButton->setAutoRaise(true); | - | ||||||||||||||||||
3116 | qFileDialogUi->backButton->setEnabled(false); | - | ||||||||||||||||||
3117 | QObject::connect(qFileDialogUi->backButton, SIGNAL(clicked()), q, SLOT(_q_navigateBackward())); | - | ||||||||||||||||||
3118 | - | |||||||||||||||||||
3119 | qFileDialogUi->forwardButton->setIcon(q->style()->standardIcon(QStyle::SP_ArrowForward, 0, q)); | - | ||||||||||||||||||
3120 | qFileDialogUi->forwardButton->setAutoRaise(true); | - | ||||||||||||||||||
3121 | qFileDialogUi->forwardButton->setEnabled(false); | - | ||||||||||||||||||
3122 | QObject::connect(qFileDialogUi->forwardButton, SIGNAL(clicked()), q, SLOT(_q_navigateForward())); | - | ||||||||||||||||||
3123 | - | |||||||||||||||||||
3124 | qFileDialogUi->toParentButton->setIcon(q->style()->standardIcon(QStyle::SP_FileDialogToParent, 0, q)); | - | ||||||||||||||||||
3125 | qFileDialogUi->toParentButton->setAutoRaise(true); | - | ||||||||||||||||||
3126 | qFileDialogUi->toParentButton->setEnabled(false); | - | ||||||||||||||||||
3127 | QObject::connect(qFileDialogUi->toParentButton, SIGNAL(clicked()), q, SLOT(_q_navigateToParent())); | - | ||||||||||||||||||
3128 | - | |||||||||||||||||||
3129 | qFileDialogUi->listModeButton->setIcon(q->style()->standardIcon(QStyle::SP_FileDialogListView, 0, q)); | - | ||||||||||||||||||
3130 | qFileDialogUi->listModeButton->setAutoRaise(true); | - | ||||||||||||||||||
3131 | qFileDialogUi->listModeButton->setDown(true); | - | ||||||||||||||||||
3132 | QObject::connect(qFileDialogUi->listModeButton, SIGNAL(clicked()), q, SLOT(_q_showListView())); | - | ||||||||||||||||||
3133 | - | |||||||||||||||||||
3134 | qFileDialogUi->detailModeButton->setIcon(q->style()->standardIcon(QStyle::SP_FileDialogDetailedView, 0, q)); | - | ||||||||||||||||||
3135 | qFileDialogUi->detailModeButton->setAutoRaise(true); | - | ||||||||||||||||||
3136 | QObject::connect(qFileDialogUi->detailModeButton, SIGNAL(clicked()), q, SLOT(_q_showDetailsView())); | - | ||||||||||||||||||
3137 | - | |||||||||||||||||||
3138 | QSize toolSize(qFileDialogUi->fileNameEdit->sizeHint().height(), qFileDialogUi->fileNameEdit->sizeHint().height()); | - | ||||||||||||||||||
3139 | qFileDialogUi->backButton->setFixedSize(toolSize); | - | ||||||||||||||||||
3140 | qFileDialogUi->listModeButton->setFixedSize(toolSize); | - | ||||||||||||||||||
3141 | qFileDialogUi->detailModeButton->setFixedSize(toolSize); | - | ||||||||||||||||||
3142 | qFileDialogUi->forwardButton->setFixedSize(toolSize); | - | ||||||||||||||||||
3143 | qFileDialogUi->toParentButton->setFixedSize(toolSize); | - | ||||||||||||||||||
3144 | - | |||||||||||||||||||
3145 | qFileDialogUi->newFolderButton->setIcon(q->style()->standardIcon(QStyle::SP_FileDialogNewFolder, 0, q)); | - | ||||||||||||||||||
3146 | qFileDialogUi->newFolderButton->setFixedSize(toolSize); | - | ||||||||||||||||||
3147 | qFileDialogUi->newFolderButton->setAutoRaise(true); | - | ||||||||||||||||||
3148 | qFileDialogUi->newFolderButton->setEnabled(false); | - | ||||||||||||||||||
3149 | QObject::connect(qFileDialogUi->newFolderButton, SIGNAL(clicked()), q, SLOT(_q_createDirectory())); | - | ||||||||||||||||||
3150 | } never executed: end of block | 0 | ||||||||||||||||||
3151 | - | |||||||||||||||||||
3152 | /*! | - | ||||||||||||||||||
3153 | \internal | - | ||||||||||||||||||
3154 | - | |||||||||||||||||||
3155 | Create actions which will be used in the right click. | - | ||||||||||||||||||
3156 | */ | - | ||||||||||||||||||
3157 | void QFileDialogPrivate::createMenuActions() | - | ||||||||||||||||||
3158 | { | - | ||||||||||||||||||
3159 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3160 | - | |||||||||||||||||||
3161 | QAction *goHomeAction = new QAction(q); | - | ||||||||||||||||||
3162 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||
3163 | goHomeAction->setShortcut(Qt::CTRL + Qt::Key_H + Qt::SHIFT); | - | ||||||||||||||||||
3164 | #endif | - | ||||||||||||||||||
3165 | QObject::connect(goHomeAction, SIGNAL(triggered()), q, SLOT(_q_goHome())); | - | ||||||||||||||||||
3166 | q->addAction(goHomeAction); | - | ||||||||||||||||||
3167 | - | |||||||||||||||||||
3168 | // ### TODO add Desktop & Computer actions | - | ||||||||||||||||||
3169 | - | |||||||||||||||||||
3170 | QAction *goToParent = new QAction(q); | - | ||||||||||||||||||
3171 | goToParent->setObjectName(QLatin1String("qt_goto_parent_action")); | - | ||||||||||||||||||
3172 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||
3173 | goToParent->setShortcut(Qt::CTRL + Qt::UpArrow); | - | ||||||||||||||||||
3174 | #endif | - | ||||||||||||||||||
3175 | QObject::connect(goToParent, SIGNAL(triggered()), q, SLOT(_q_navigateToParent())); | - | ||||||||||||||||||
3176 | q->addAction(goToParent); | - | ||||||||||||||||||
3177 | - | |||||||||||||||||||
3178 | renameAction = new QAction(q); | - | ||||||||||||||||||
3179 | renameAction->setEnabled(false); | - | ||||||||||||||||||
3180 | renameAction->setObjectName(QLatin1String("qt_rename_action")); | - | ||||||||||||||||||
3181 | QObject::connect(renameAction, SIGNAL(triggered()), q, SLOT(_q_renameCurrent())); | - | ||||||||||||||||||
3182 | - | |||||||||||||||||||
3183 | deleteAction = new QAction(q); | - | ||||||||||||||||||
3184 | deleteAction->setEnabled(false); | - | ||||||||||||||||||
3185 | deleteAction->setObjectName(QLatin1String("qt_delete_action")); | - | ||||||||||||||||||
3186 | QObject::connect(deleteAction, SIGNAL(triggered()), q, SLOT(_q_deleteCurrent())); | - | ||||||||||||||||||
3187 | - | |||||||||||||||||||
3188 | showHiddenAction = new QAction(q); | - | ||||||||||||||||||
3189 | showHiddenAction->setObjectName(QLatin1String("qt_show_hidden_action")); | - | ||||||||||||||||||
3190 | showHiddenAction->setCheckable(true); | - | ||||||||||||||||||
3191 | QObject::connect(showHiddenAction, SIGNAL(triggered()), q, SLOT(_q_showHidden())); | - | ||||||||||||||||||
3192 | - | |||||||||||||||||||
3193 | newFolderAction = new QAction(q); | - | ||||||||||||||||||
3194 | newFolderAction->setObjectName(QLatin1String("qt_new_folder_action")); | - | ||||||||||||||||||
3195 | QObject::connect(newFolderAction, SIGNAL(triggered()), q, SLOT(_q_createDirectory())); | - | ||||||||||||||||||
3196 | } never executed: end of block | 0 | ||||||||||||||||||
3197 | - | |||||||||||||||||||
3198 | void QFileDialogPrivate::_q_goHome() | - | ||||||||||||||||||
3199 | { | - | ||||||||||||||||||
3200 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3201 | q->setDirectory(QDir::homePath()); | - | ||||||||||||||||||
3202 | } never executed: end of block | 0 | ||||||||||||||||||
3203 | - | |||||||||||||||||||
3204 | /*! | - | ||||||||||||||||||
3205 | \internal | - | ||||||||||||||||||
3206 | - | |||||||||||||||||||
3207 | Update history with new path, buttons, and combo | - | ||||||||||||||||||
3208 | */ | - | ||||||||||||||||||
3209 | void QFileDialogPrivate::_q_pathChanged(const QString &newPath) | - | ||||||||||||||||||
3210 | { | - | ||||||||||||||||||
3211 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3212 | QDir dir(model->rootDirectory()); | - | ||||||||||||||||||
3213 | qFileDialogUi->toParentButton->setEnabled(dir.exists()); | - | ||||||||||||||||||
3214 | qFileDialogUi->sidebar->selectUrl(QUrl::fromLocalFile(newPath)); | - | ||||||||||||||||||
3215 | q->setHistory(qFileDialogUi->lookInCombo->history()); | - | ||||||||||||||||||
3216 | - | |||||||||||||||||||
3217 | if (currentHistoryLocation < 0 || currentHistory.value(currentHistoryLocation) != QDir::toNativeSeparators(newPath)) {
| 0 | ||||||||||||||||||
3218 | while (currentHistoryLocation >= 0 && currentHistoryLocation + 1 < currentHistory.count()) {
| 0 | ||||||||||||||||||
3219 | currentHistory.removeLast(); | - | ||||||||||||||||||
3220 | } never executed: end of block | 0 | ||||||||||||||||||
3221 | currentHistory.append(QDir::toNativeSeparators(newPath)); | - | ||||||||||||||||||
3222 | ++currentHistoryLocation; | - | ||||||||||||||||||
3223 | } never executed: end of block | 0 | ||||||||||||||||||
3224 | qFileDialogUi->forwardButton->setEnabled(currentHistory.size() - currentHistoryLocation > 1); | - | ||||||||||||||||||
3225 | qFileDialogUi->backButton->setEnabled(currentHistoryLocation > 0); | - | ||||||||||||||||||
3226 | } never executed: end of block | 0 | ||||||||||||||||||
3227 | - | |||||||||||||||||||
3228 | /*! | - | ||||||||||||||||||
3229 | \internal | - | ||||||||||||||||||
3230 | - | |||||||||||||||||||
3231 | Navigates to the last directory viewed in the dialog. | - | ||||||||||||||||||
3232 | */ | - | ||||||||||||||||||
3233 | void QFileDialogPrivate::_q_navigateBackward() | - | ||||||||||||||||||
3234 | { | - | ||||||||||||||||||
3235 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3236 | if (!currentHistory.isEmpty() && currentHistoryLocation > 0) {
| 0 | ||||||||||||||||||
3237 | --currentHistoryLocation; | - | ||||||||||||||||||
3238 | QString previousHistory = currentHistory.at(currentHistoryLocation); | - | ||||||||||||||||||
3239 | q->setDirectory(previousHistory); | - | ||||||||||||||||||
3240 | } never executed: end of block | 0 | ||||||||||||||||||
3241 | } never executed: end of block | 0 | ||||||||||||||||||
3242 | - | |||||||||||||||||||
3243 | /*! | - | ||||||||||||||||||
3244 | \internal | - | ||||||||||||||||||
3245 | - | |||||||||||||||||||
3246 | Navigates to the last directory viewed in the dialog. | - | ||||||||||||||||||
3247 | */ | - | ||||||||||||||||||
3248 | void QFileDialogPrivate::_q_navigateForward() | - | ||||||||||||||||||
3249 | { | - | ||||||||||||||||||
3250 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3251 | if (!currentHistory.isEmpty() && currentHistoryLocation < currentHistory.size() - 1) {
| 0 | ||||||||||||||||||
3252 | ++currentHistoryLocation; | - | ||||||||||||||||||
3253 | QString nextHistory = currentHistory.at(currentHistoryLocation); | - | ||||||||||||||||||
3254 | q->setDirectory(nextHistory); | - | ||||||||||||||||||
3255 | } never executed: end of block | 0 | ||||||||||||||||||
3256 | } never executed: end of block | 0 | ||||||||||||||||||
3257 | - | |||||||||||||||||||
3258 | /*! | - | ||||||||||||||||||
3259 | \internal | - | ||||||||||||||||||
3260 | - | |||||||||||||||||||
3261 | Navigates to the parent directory of the currently displayed directory | - | ||||||||||||||||||
3262 | in the dialog. | - | ||||||||||||||||||
3263 | */ | - | ||||||||||||||||||
3264 | void QFileDialogPrivate::_q_navigateToParent() | - | ||||||||||||||||||
3265 | { | - | ||||||||||||||||||
3266 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3267 | QDir dir(model->rootDirectory()); | - | ||||||||||||||||||
3268 | QString newDirectory; | - | ||||||||||||||||||
3269 | if (dir.isRoot()) {
| 0 | ||||||||||||||||||
3270 | newDirectory = model->myComputer().toString(); | - | ||||||||||||||||||
3271 | } else { never executed: end of block | 0 | ||||||||||||||||||
3272 | dir.cdUp(); | - | ||||||||||||||||||
3273 | newDirectory = dir.absolutePath(); | - | ||||||||||||||||||
3274 | } never executed: end of block | 0 | ||||||||||||||||||
3275 | q->setDirectory(newDirectory); | - | ||||||||||||||||||
3276 | emit q->directoryEntered(newDirectory); | - | ||||||||||||||||||
3277 | } never executed: end of block | 0 | ||||||||||||||||||
3278 | - | |||||||||||||||||||
3279 | /*! | - | ||||||||||||||||||
3280 | \internal | - | ||||||||||||||||||
3281 | - | |||||||||||||||||||
3282 | Creates a new directory, first asking the user for a suitable name. | - | ||||||||||||||||||
3283 | */ | - | ||||||||||||||||||
3284 | void QFileDialogPrivate::_q_createDirectory() | - | ||||||||||||||||||
3285 | { | - | ||||||||||||||||||
3286 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3287 | qFileDialogUi->listView->clearSelection(); | - | ||||||||||||||||||
3288 | - | |||||||||||||||||||
3289 | QString newFolderString = QFileDialog::tr("New Folder"); | - | ||||||||||||||||||
3290 | QString folderName = newFolderString; | - | ||||||||||||||||||
3291 | QString prefix = q->directory().absolutePath() + QDir::separator(); | - | ||||||||||||||||||
3292 | if (QFile::exists(prefix + folderName)) {
| 0 | ||||||||||||||||||
3293 | qlonglong suffix = 2; | - | ||||||||||||||||||
3294 | while (QFile::exists(prefix + folderName)) {
| 0 | ||||||||||||||||||
3295 | folderName = newFolderString + QString::number(suffix++); | - | ||||||||||||||||||
3296 | } never executed: end of block | 0 | ||||||||||||||||||
3297 | } never executed: end of block | 0 | ||||||||||||||||||
3298 | - | |||||||||||||||||||
3299 | QModelIndex parent = rootIndex(); | - | ||||||||||||||||||
3300 | QModelIndex index = model->mkdir(parent, folderName); | - | ||||||||||||||||||
3301 | if (!index.isValid())
| 0 | ||||||||||||||||||
3302 | return; never executed: return; | 0 | ||||||||||||||||||
3303 | - | |||||||||||||||||||
3304 | index = select(index); | - | ||||||||||||||||||
3305 | if (index.isValid()) {
| 0 | ||||||||||||||||||
3306 | qFileDialogUi->treeView->setCurrentIndex(index); | - | ||||||||||||||||||
3307 | currentView()->edit(index); | - | ||||||||||||||||||
3308 | } never executed: end of block | 0 | ||||||||||||||||||
3309 | } never executed: end of block | 0 | ||||||||||||||||||
3310 | - | |||||||||||||||||||
3311 | void QFileDialogPrivate::_q_showListView() | - | ||||||||||||||||||
3312 | { | - | ||||||||||||||||||
3313 | qFileDialogUi->listModeButton->setDown(true); | - | ||||||||||||||||||
3314 | qFileDialogUi->detailModeButton->setDown(false); | - | ||||||||||||||||||
3315 | qFileDialogUi->treeView->hide(); | - | ||||||||||||||||||
3316 | qFileDialogUi->listView->show(); | - | ||||||||||||||||||
3317 | qFileDialogUi->stackedWidget->setCurrentWidget(qFileDialogUi->listView->parentWidget()); | - | ||||||||||||||||||
3318 | qFileDialogUi->listView->doItemsLayout(); | - | ||||||||||||||||||
3319 | } never executed: end of block | 0 | ||||||||||||||||||
3320 | - | |||||||||||||||||||
3321 | void QFileDialogPrivate::_q_showDetailsView() | - | ||||||||||||||||||
3322 | { | - | ||||||||||||||||||
3323 | qFileDialogUi->listModeButton->setDown(false); | - | ||||||||||||||||||
3324 | qFileDialogUi->detailModeButton->setDown(true); | - | ||||||||||||||||||
3325 | qFileDialogUi->listView->hide(); | - | ||||||||||||||||||
3326 | qFileDialogUi->treeView->show(); | - | ||||||||||||||||||
3327 | qFileDialogUi->stackedWidget->setCurrentWidget(qFileDialogUi->treeView->parentWidget()); | - | ||||||||||||||||||
3328 | qFileDialogUi->treeView->doItemsLayout(); | - | ||||||||||||||||||
3329 | } never executed: end of block | 0 | ||||||||||||||||||
3330 | - | |||||||||||||||||||
3331 | /*! | - | ||||||||||||||||||
3332 | \internal | - | ||||||||||||||||||
3333 | - | |||||||||||||||||||
3334 | Show the context menu for the file/dir under position | - | ||||||||||||||||||
3335 | */ | - | ||||||||||||||||||
3336 | void QFileDialogPrivate::_q_showContextMenu(const QPoint &position) | - | ||||||||||||||||||
3337 | { | - | ||||||||||||||||||
3338 | #ifdef QT_NO_MENU | - | ||||||||||||||||||
3339 | Q_UNUSED(position); | - | ||||||||||||||||||
3340 | #else | - | ||||||||||||||||||
3341 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3342 | QAbstractItemView *view = 0; | - | ||||||||||||||||||
3343 | if (q->viewMode() == QFileDialog::Detail)
| 0 | ||||||||||||||||||
3344 | view = qFileDialogUi->treeView; never executed: view = qFileDialogUi->treeView; | 0 | ||||||||||||||||||
3345 | else | - | ||||||||||||||||||
3346 | view = qFileDialogUi->listView; never executed: view = qFileDialogUi->listView; | 0 | ||||||||||||||||||
3347 | QModelIndex index = view->indexAt(position); | - | ||||||||||||||||||
3348 | index = mapToSource(index.sibling(index.row(), 0)); | - | ||||||||||||||||||
3349 | - | |||||||||||||||||||
3350 | QMenu menu(view); | - | ||||||||||||||||||
3351 | if (index.isValid()) {
| 0 | ||||||||||||||||||
3352 | // file context menu | - | ||||||||||||||||||
3353 | const bool ro = model && model->isReadOnly();
| 0 | ||||||||||||||||||
3354 | QFile::Permissions p(index.parent().data(QFileSystemModel::FilePermissions).toInt()); | - | ||||||||||||||||||
3355 | renameAction->setEnabled(!ro && p & QFile::WriteUser); | - | ||||||||||||||||||
3356 | menu.addAction(renameAction); | - | ||||||||||||||||||
3357 | deleteAction->setEnabled(!ro && p & QFile::WriteUser); | - | ||||||||||||||||||
3358 | menu.addAction(deleteAction); | - | ||||||||||||||||||
3359 | menu.addSeparator(); | - | ||||||||||||||||||
3360 | } never executed: end of block | 0 | ||||||||||||||||||
3361 | menu.addAction(showHiddenAction); | - | ||||||||||||||||||
3362 | if (qFileDialogUi->newFolderButton->isVisible()) {
| 0 | ||||||||||||||||||
3363 | newFolderAction->setEnabled(qFileDialogUi->newFolderButton->isEnabled()); | - | ||||||||||||||||||
3364 | menu.addAction(newFolderAction); | - | ||||||||||||||||||
3365 | } never executed: end of block | 0 | ||||||||||||||||||
3366 | menu.exec(view->viewport()->mapToGlobal(position)); | - | ||||||||||||||||||
3367 | #endif // QT_NO_MENU | - | ||||||||||||||||||
3368 | } never executed: end of block | 0 | ||||||||||||||||||
3369 | - | |||||||||||||||||||
3370 | /*! | - | ||||||||||||||||||
3371 | \internal | - | ||||||||||||||||||
3372 | */ | - | ||||||||||||||||||
3373 | void QFileDialogPrivate::_q_renameCurrent() | - | ||||||||||||||||||
3374 | { | - | ||||||||||||||||||
3375 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3376 | QModelIndex index = qFileDialogUi->listView->currentIndex(); | - | ||||||||||||||||||
3377 | index = index.sibling(index.row(), 0); | - | ||||||||||||||||||
3378 | if (q->viewMode() == QFileDialog::List)
| 0 | ||||||||||||||||||
3379 | qFileDialogUi->listView->edit(index); never executed: qFileDialogUi->listView->edit(index); | 0 | ||||||||||||||||||
3380 | else | - | ||||||||||||||||||
3381 | qFileDialogUi->treeView->edit(index); never executed: qFileDialogUi->treeView->edit(index); | 0 | ||||||||||||||||||
3382 | } | - | ||||||||||||||||||
3383 | - | |||||||||||||||||||
3384 | bool QFileDialogPrivate::removeDirectory(const QString &path) | - | ||||||||||||||||||
3385 | { | - | ||||||||||||||||||
3386 | QModelIndex modelIndex = model->index(path); | - | ||||||||||||||||||
3387 | return model->remove(modelIndex); never executed: return model->remove(modelIndex); | 0 | ||||||||||||||||||
3388 | } | - | ||||||||||||||||||
3389 | - | |||||||||||||||||||
3390 | /*! | - | ||||||||||||||||||
3391 | \internal | - | ||||||||||||||||||
3392 | - | |||||||||||||||||||
3393 | Deletes the currently selected item in the dialog. | - | ||||||||||||||||||
3394 | */ | - | ||||||||||||||||||
3395 | void QFileDialogPrivate::_q_deleteCurrent() | - | ||||||||||||||||||
3396 | { | - | ||||||||||||||||||
3397 | if (model->isReadOnly())
| 0 | ||||||||||||||||||
3398 | return; never executed: return; | 0 | ||||||||||||||||||
3399 | - | |||||||||||||||||||
3400 | QModelIndexList list = qFileDialogUi->listView->selectionModel()->selectedRows(); | - | ||||||||||||||||||
3401 | for (int i = list.count() - 1; i >= 0; --i) {
| 0 | ||||||||||||||||||
3402 | QModelIndex index = list.at(i); | - | ||||||||||||||||||
3403 | if (index == qFileDialogUi->listView->rootIndex())
| 0 | ||||||||||||||||||
3404 | continue; never executed: continue; | 0 | ||||||||||||||||||
3405 | - | |||||||||||||||||||
3406 | index = mapToSource(index.sibling(index.row(), 0)); | - | ||||||||||||||||||
3407 | if (!index.isValid())
| 0 | ||||||||||||||||||
3408 | continue; never executed: continue; | 0 | ||||||||||||||||||
3409 | - | |||||||||||||||||||
3410 | QString fileName = index.data(QFileSystemModel::FileNameRole).toString(); | - | ||||||||||||||||||
3411 | QString filePath = index.data(QFileSystemModel::FilePathRole).toString(); | - | ||||||||||||||||||
3412 | bool isDir = model->isDir(index); | - | ||||||||||||||||||
3413 | - | |||||||||||||||||||
3414 | QFile::Permissions p(index.parent().data(QFileSystemModel::FilePermissions).toInt()); | - | ||||||||||||||||||
3415 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||||||||
3416 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3417 | if (!(p & QFile::WriteUser) && (QMessageBox::warning(q_func(), QFileDialog::tr("Delete"),
| 0 | ||||||||||||||||||
3418 | QFileDialog::tr("'%1' is write protected.\nDo you want to delete it anyway?")
| 0 | ||||||||||||||||||
3419 | .arg(fileName),
| 0 | ||||||||||||||||||
3420 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No))
| 0 | ||||||||||||||||||
3421 | return; never executed: return; | 0 | ||||||||||||||||||
3422 | else if (QMessageBox::warning(q_func(), QFileDialog::tr("Delete"),
| 0 | ||||||||||||||||||
3423 | QFileDialog::tr("Are you sure you want to delete '%1'?")
| 0 | ||||||||||||||||||
3424 | .arg(fileName),
| 0 | ||||||||||||||||||
3425 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No)
| 0 | ||||||||||||||||||
3426 | return; never executed: return; | 0 | ||||||||||||||||||
3427 | - | |||||||||||||||||||
3428 | #else | - | ||||||||||||||||||
3429 | if (!(p & QFile::WriteUser)) | - | ||||||||||||||||||
3430 | return; | - | ||||||||||||||||||
3431 | #endif // QT_NO_MESSAGEBOX | - | ||||||||||||||||||
3432 | - | |||||||||||||||||||
3433 | // the event loop has run, we can NOT reuse index because the model might have removed it. | - | ||||||||||||||||||
3434 | if (isDir) {
| 0 | ||||||||||||||||||
3435 | if (!removeDirectory(filePath)) {
| 0 | ||||||||||||||||||
3436 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||||||||
3437 | QMessageBox::warning(q, q->windowTitle(), | - | ||||||||||||||||||
3438 | QFileDialog::tr("Could not delete directory.")); | - | ||||||||||||||||||
3439 | #endif | - | ||||||||||||||||||
3440 | } never executed: end of block | 0 | ||||||||||||||||||
3441 | } else { never executed: end of block | 0 | ||||||||||||||||||
3442 | model->remove(index); | - | ||||||||||||||||||
3443 | } never executed: end of block | 0 | ||||||||||||||||||
3444 | } | - | ||||||||||||||||||
3445 | } never executed: end of block | 0 | ||||||||||||||||||
3446 | - | |||||||||||||||||||
3447 | void QFileDialogPrivate::_q_autoCompleteFileName(const QString &text) | - | ||||||||||||||||||
3448 | { | - | ||||||||||||||||||
3449 | if (text.startsWith(QLatin1String("//")) || text.startsWith(QLatin1Char('\\'))) {
| 0 | ||||||||||||||||||
3450 | qFileDialogUi->listView->selectionModel()->clearSelection(); | - | ||||||||||||||||||
3451 | return; never executed: return; | 0 | ||||||||||||||||||
3452 | } | - | ||||||||||||||||||
3453 | - | |||||||||||||||||||
3454 | QStringList multipleFiles = typedFiles(); | - | ||||||||||||||||||
3455 | if (multipleFiles.count() > 0) {
| 0 | ||||||||||||||||||
3456 | QModelIndexList oldFiles = qFileDialogUi->listView->selectionModel()->selectedRows(); | - | ||||||||||||||||||
3457 | QModelIndexList newFiles; | - | ||||||||||||||||||
3458 | for (int i = 0; i < multipleFiles.count(); ++i) {
| 0 | ||||||||||||||||||
3459 | QModelIndex idx = model->index(multipleFiles.at(i)); | - | ||||||||||||||||||
3460 | if (oldFiles.contains(idx))
| 0 | ||||||||||||||||||
3461 | oldFiles.removeAll(idx); never executed: oldFiles.removeAll(idx); | 0 | ||||||||||||||||||
3462 | else | - | ||||||||||||||||||
3463 | newFiles.append(idx); never executed: newFiles.append(idx); | 0 | ||||||||||||||||||
3464 | } | - | ||||||||||||||||||
3465 | for (int i = 0; i < newFiles.count(); ++i)
| 0 | ||||||||||||||||||
3466 | select(newFiles.at(i)); never executed: select(newFiles.at(i)); | 0 | ||||||||||||||||||
3467 | if (lineEdit()->hasFocus())
| 0 | ||||||||||||||||||
3468 | for (int i = 0; i < oldFiles.count(); ++i)
| 0 | ||||||||||||||||||
3469 | qFileDialogUi->listView->selectionModel()->select(oldFiles.at(i), never executed: qFileDialogUi->listView->selectionModel()->select(oldFiles.at(i), QItemSelectionModel::Toggle | QItemSelectionModel::Rows); | 0 | ||||||||||||||||||
3470 | QItemSelectionModel::Toggle | QItemSelectionModel::Rows); never executed: qFileDialogUi->listView->selectionModel()->select(oldFiles.at(i), QItemSelectionModel::Toggle | QItemSelectionModel::Rows); | 0 | ||||||||||||||||||
3471 | } never executed: end of block | 0 | ||||||||||||||||||
3472 | } never executed: end of block | 0 | ||||||||||||||||||
3473 | - | |||||||||||||||||||
3474 | /*! | - | ||||||||||||||||||
3475 | \internal | - | ||||||||||||||||||
3476 | */ | - | ||||||||||||||||||
3477 | void QFileDialogPrivate::_q_updateOkButton() | - | ||||||||||||||||||
3478 | { | - | ||||||||||||||||||
3479 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3480 | QPushButton *button = qFileDialogUi->buttonBox->button((q->acceptMode() == QFileDialog::AcceptOpen) | - | ||||||||||||||||||
3481 | ? QDialogButtonBox::Open : QDialogButtonBox::Save); | - | ||||||||||||||||||
3482 | if (!button)
| 0 | ||||||||||||||||||
3483 | return; never executed: return; | 0 | ||||||||||||||||||
3484 | const QFileDialog::FileMode fileMode = q->fileMode(); | - | ||||||||||||||||||
3485 | - | |||||||||||||||||||
3486 | bool enableButton = true; | - | ||||||||||||||||||
3487 | bool isOpenDirectory = false; | - | ||||||||||||||||||
3488 | - | |||||||||||||||||||
3489 | QStringList files = q->selectedFiles(); | - | ||||||||||||||||||
3490 | QString lineEditText = lineEdit()->text(); | - | ||||||||||||||||||
3491 | - | |||||||||||||||||||
3492 | if (lineEditText.startsWith(QLatin1String("//")) || lineEditText.startsWith(QLatin1Char('\\'))) {
| 0 | ||||||||||||||||||
3493 | button->setEnabled(true); | - | ||||||||||||||||||
3494 | updateOkButtonText(); | - | ||||||||||||||||||
3495 | return; never executed: return; | 0 | ||||||||||||||||||
3496 | } | - | ||||||||||||||||||
3497 | - | |||||||||||||||||||
3498 | if (files.isEmpty()) {
| 0 | ||||||||||||||||||
3499 | enableButton = false; | - | ||||||||||||||||||
3500 | } else if (lineEditText == QLatin1String("..")) { never executed: end of block
| 0 | ||||||||||||||||||
3501 | isOpenDirectory = true; | - | ||||||||||||||||||
3502 | } else { never executed: end of block | 0 | ||||||||||||||||||
3503 | switch (fileMode) { | - | ||||||||||||||||||
3504 | case QFileDialog::DirectoryOnly: never executed: case QFileDialog::DirectoryOnly: | 0 | ||||||||||||||||||
3505 | case QFileDialog::Directory: { never executed: case QFileDialog::Directory: | 0 | ||||||||||||||||||
3506 | QString fn = files.first(); | - | ||||||||||||||||||
3507 | QModelIndex idx = model->index(fn); | - | ||||||||||||||||||
3508 | if (!idx.isValid())
| 0 | ||||||||||||||||||
3509 | idx = model->index(getEnvironmentVariable(fn)); never executed: idx = model->index(getEnvironmentVariable(fn)); | 0 | ||||||||||||||||||
3510 | if (!idx.isValid() || !model->isDir(idx))
| 0 | ||||||||||||||||||
3511 | enableButton = false; never executed: enableButton = false; | 0 | ||||||||||||||||||
3512 | break; never executed: break; | 0 | ||||||||||||||||||
3513 | } | - | ||||||||||||||||||
3514 | case QFileDialog::AnyFile: { never executed: case QFileDialog::AnyFile: | 0 | ||||||||||||||||||
3515 | QString fn = files.first(); | - | ||||||||||||||||||
3516 | QFileInfo info(fn); | - | ||||||||||||||||||
3517 | QModelIndex idx = model->index(fn); | - | ||||||||||||||||||
3518 | QString fileDir; | - | ||||||||||||||||||
3519 | QString fileName; | - | ||||||||||||||||||
3520 | if (info.isDir()) {
| 0 | ||||||||||||||||||
3521 | fileDir = info.canonicalFilePath(); | - | ||||||||||||||||||
3522 | } else { never executed: end of block | 0 | ||||||||||||||||||
3523 | fileDir = fn.mid(0, fn.lastIndexOf(QLatin1Char('/'))); | - | ||||||||||||||||||
3524 | fileName = fn.mid(fileDir.length() + 1); | - | ||||||||||||||||||
3525 | } never executed: end of block | 0 | ||||||||||||||||||
3526 | if (lineEditText.contains(QLatin1String(".."))) {
| 0 | ||||||||||||||||||
3527 | fileDir = info.canonicalFilePath(); | - | ||||||||||||||||||
3528 | fileName = info.fileName(); | - | ||||||||||||||||||
3529 | } never executed: end of block | 0 | ||||||||||||||||||
3530 | - | |||||||||||||||||||
3531 | if (fileDir == q->directory().canonicalPath() && fileName.isEmpty()) {
| 0 | ||||||||||||||||||
3532 | enableButton = false; | - | ||||||||||||||||||
3533 | break; never executed: break; | 0 | ||||||||||||||||||
3534 | } | - | ||||||||||||||||||
3535 | if (idx.isValid() && model->isDir(idx)) {
| 0 | ||||||||||||||||||
3536 | isOpenDirectory = true; | - | ||||||||||||||||||
3537 | enableButton = true; | - | ||||||||||||||||||
3538 | break; never executed: break; | 0 | ||||||||||||||||||
3539 | } | - | ||||||||||||||||||
3540 | if (!idx.isValid()) {
| 0 | ||||||||||||||||||
3541 | int maxLength = maxNameLength(fileDir); | - | ||||||||||||||||||
3542 | enableButton = maxLength < 0 || fileName.length() <= maxLength;
| 0 | ||||||||||||||||||
3543 | } never executed: end of block | 0 | ||||||||||||||||||
3544 | break; never executed: break; | 0 | ||||||||||||||||||
3545 | } | - | ||||||||||||||||||
3546 | case QFileDialog::ExistingFile: never executed: case QFileDialog::ExistingFile: | 0 | ||||||||||||||||||
3547 | case QFileDialog::ExistingFiles: never executed: case QFileDialog::ExistingFiles: | 0 | ||||||||||||||||||
3548 | for (int i = 0; i < files.count(); ++i) {
| 0 | ||||||||||||||||||
3549 | QModelIndex idx = model->index(files.at(i)); | - | ||||||||||||||||||
3550 | if (!idx.isValid())
| 0 | ||||||||||||||||||
3551 | idx = model->index(getEnvironmentVariable(files.at(i))); never executed: idx = model->index(getEnvironmentVariable(files.at(i))); | 0 | ||||||||||||||||||
3552 | if (!idx.isValid()) {
| 0 | ||||||||||||||||||
3553 | enableButton = false; | - | ||||||||||||||||||
3554 | break; never executed: break; | 0 | ||||||||||||||||||
3555 | } | - | ||||||||||||||||||
3556 | if (idx.isValid() && model->isDir(idx)) {
| 0 | ||||||||||||||||||
3557 | isOpenDirectory = true; | - | ||||||||||||||||||
3558 | break; never executed: break; | 0 | ||||||||||||||||||
3559 | } | - | ||||||||||||||||||
3560 | } never executed: end of block | 0 | ||||||||||||||||||
3561 | break; never executed: break; | 0 | ||||||||||||||||||
3562 | default: never executed: default: | 0 | ||||||||||||||||||
3563 | break; never executed: break; | 0 | ||||||||||||||||||
3564 | } | - | ||||||||||||||||||
3565 | } | - | ||||||||||||||||||
3566 | - | |||||||||||||||||||
3567 | button->setEnabled(enableButton); | - | ||||||||||||||||||
3568 | updateOkButtonText(isOpenDirectory); | - | ||||||||||||||||||
3569 | } never executed: end of block | 0 | ||||||||||||||||||
3570 | - | |||||||||||||||||||
3571 | /*! | - | ||||||||||||||||||
3572 | \internal | - | ||||||||||||||||||
3573 | */ | - | ||||||||||||||||||
3574 | void QFileDialogPrivate::_q_currentChanged(const QModelIndex &index) | - | ||||||||||||||||||
3575 | { | - | ||||||||||||||||||
3576 | _q_updateOkButton(); | - | ||||||||||||||||||
3577 | emit q_func()->currentChanged(index.data(QFileSystemModel::FilePathRole).toString()); | - | ||||||||||||||||||
3578 | } never executed: end of block | 0 | ||||||||||||||||||
3579 | - | |||||||||||||||||||
3580 | /*! | - | ||||||||||||||||||
3581 | \internal | - | ||||||||||||||||||
3582 | - | |||||||||||||||||||
3583 | This is called when the user double clicks on a file with the corresponding | - | ||||||||||||||||||
3584 | model item \a index. | - | ||||||||||||||||||
3585 | */ | - | ||||||||||||||||||
3586 | void QFileDialogPrivate::_q_enterDirectory(const QModelIndex &index) | - | ||||||||||||||||||
3587 | { | - | ||||||||||||||||||
3588 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3589 | // My Computer or a directory | - | ||||||||||||||||||
3590 | QModelIndex sourceIndex = index.model() == proxyModel ? mapToSource(index) : index;
| 0 | ||||||||||||||||||
3591 | QString path = sourceIndex.data(QFileSystemModel::FilePathRole).toString(); | - | ||||||||||||||||||
3592 | if (path.isEmpty() || model->isDir(sourceIndex)) {
| 0 | ||||||||||||||||||
3593 | const QFileDialog::FileMode fileMode = q->fileMode(); | - | ||||||||||||||||||
3594 | q->setDirectory(path); | - | ||||||||||||||||||
3595 | emit q->directoryEntered(path); | - | ||||||||||||||||||
3596 | if (fileMode == QFileDialog::Directory
| 0 | ||||||||||||||||||
3597 | || fileMode == QFileDialog::DirectoryOnly) {
| 0 | ||||||||||||||||||
3598 | // ### find out why you have to do both of these. | - | ||||||||||||||||||
3599 | lineEdit()->setText(QString()); | - | ||||||||||||||||||
3600 | lineEdit()->clear(); | - | ||||||||||||||||||
3601 | } never executed: end of block | 0 | ||||||||||||||||||
3602 | } else { never executed: end of block | 0 | ||||||||||||||||||
3603 | // Do not accept when shift-clicking to multi-select a file in environments with single-click-activation (KDE) | - | ||||||||||||||||||
3604 | if (!q->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, Q_NULLPTR, qFileDialogUi->treeView)
| 0 | ||||||||||||||||||
3605 | || q->fileMode() != QFileDialog::ExistingFiles || !(QGuiApplication::keyboardModifiers() & Qt::CTRL)) {
| 0 | ||||||||||||||||||
3606 | q->accept(); | - | ||||||||||||||||||
3607 | } never executed: end of block | 0 | ||||||||||||||||||
3608 | } never executed: end of block | 0 | ||||||||||||||||||
3609 | } | - | ||||||||||||||||||
3610 | - | |||||||||||||||||||
3611 | /*! | - | ||||||||||||||||||
3612 | \internal | - | ||||||||||||||||||
3613 | - | |||||||||||||||||||
3614 | Changes the file dialog's current directory to the one specified | - | ||||||||||||||||||
3615 | by \a path. | - | ||||||||||||||||||
3616 | */ | - | ||||||||||||||||||
3617 | void QFileDialogPrivate::_q_goToDirectory(const QString &path) | - | ||||||||||||||||||
3618 | { | - | ||||||||||||||||||
3619 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||||||||
3620 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3621 | #endif | - | ||||||||||||||||||
3622 | QModelIndex index = qFileDialogUi->lookInCombo->model()->index(qFileDialogUi->lookInCombo->currentIndex(), | - | ||||||||||||||||||
3623 | qFileDialogUi->lookInCombo->modelColumn(), | - | ||||||||||||||||||
3624 | qFileDialogUi->lookInCombo->rootModelIndex()); | - | ||||||||||||||||||
3625 | QString path2 = path; | - | ||||||||||||||||||
3626 | if (!index.isValid())
| 0 | ||||||||||||||||||
3627 | index = mapFromSource(model->index(getEnvironmentVariable(path))); never executed: index = mapFromSource(model->index(getEnvironmentVariable(path))); | 0 | ||||||||||||||||||
3628 | else { | - | ||||||||||||||||||
3629 | path2 = index.data(UrlRole).toUrl().toLocalFile(); | - | ||||||||||||||||||
3630 | index = mapFromSource(model->index(path2)); | - | ||||||||||||||||||
3631 | } never executed: end of block | 0 | ||||||||||||||||||
3632 | QDir dir(path2); | - | ||||||||||||||||||
3633 | if (!dir.exists())
| 0 | ||||||||||||||||||
3634 | dir = getEnvironmentVariable(path2); never executed: dir = getEnvironmentVariable(path2); | 0 | ||||||||||||||||||
3635 | - | |||||||||||||||||||
3636 | if (dir.exists() || path2.isEmpty() || path2 == model->myComputer().toString()) {
| 0 | ||||||||||||||||||
3637 | _q_enterDirectory(index); | - | ||||||||||||||||||
3638 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||||||||
3639 | } else { never executed: end of block | 0 | ||||||||||||||||||
3640 | QString message = QFileDialog::tr("%1\nDirectory not found.\nPlease verify the " | - | ||||||||||||||||||
3641 | "correct directory name was given."); | - | ||||||||||||||||||
3642 | QMessageBox::warning(q, q->windowTitle(), message.arg(path2)); | - | ||||||||||||||||||
3643 | #endif // QT_NO_MESSAGEBOX | - | ||||||||||||||||||
3644 | } never executed: end of block | 0 | ||||||||||||||||||
3645 | } | - | ||||||||||||||||||
3646 | - | |||||||||||||||||||
3647 | /*! | - | ||||||||||||||||||
3648 | \internal | - | ||||||||||||||||||
3649 | - | |||||||||||||||||||
3650 | Sets the current name filter to be nameFilter and | - | ||||||||||||||||||
3651 | update the qFileDialogUi->fileNameEdit when in AcceptSave mode with the new extension. | - | ||||||||||||||||||
3652 | */ | - | ||||||||||||||||||
3653 | void QFileDialogPrivate::_q_useNameFilter(int index) | - | ||||||||||||||||||
3654 | { | - | ||||||||||||||||||
3655 | QStringList nameFilters = options->nameFilters(); | - | ||||||||||||||||||
3656 | if (index == nameFilters.size()) {
| 0 | ||||||||||||||||||
3657 | QAbstractItemModel *comboModel = qFileDialogUi->fileTypeCombo->model(); | - | ||||||||||||||||||
3658 | nameFilters.append(comboModel->index(comboModel->rowCount() - 1, 0).data().toString()); | - | ||||||||||||||||||
3659 | options->setNameFilters(nameFilters); | - | ||||||||||||||||||
3660 | } never executed: end of block | 0 | ||||||||||||||||||
3661 | - | |||||||||||||||||||
3662 | QString nameFilter = nameFilters.at(index); | - | ||||||||||||||||||
3663 | QStringList newNameFilters = QPlatformFileDialogHelper::cleanFilterList(nameFilter); | - | ||||||||||||||||||
3664 | if (q_func()->acceptMode() == QFileDialog::AcceptSave) {
| 0 | ||||||||||||||||||
3665 | QString newNameFilterExtension; | - | ||||||||||||||||||
3666 | if (newNameFilters.count() > 0)
| 0 | ||||||||||||||||||
3667 | newNameFilterExtension = QFileInfo(newNameFilters.at(0)).suffix(); never executed: newNameFilterExtension = QFileInfo(newNameFilters.at(0)).suffix(); | 0 | ||||||||||||||||||
3668 | - | |||||||||||||||||||
3669 | QString fileName = lineEdit()->text(); | - | ||||||||||||||||||
3670 | const QString fileNameExtension = QFileInfo(fileName).suffix(); | - | ||||||||||||||||||
3671 | if (!fileNameExtension.isEmpty() && !newNameFilterExtension.isEmpty()) {
| 0 | ||||||||||||||||||
3672 | const int fileNameExtensionLength = fileNameExtension.count(); | - | ||||||||||||||||||
3673 | fileName.replace(fileName.count() - fileNameExtensionLength, | - | ||||||||||||||||||
3674 | fileNameExtensionLength, newNameFilterExtension); | - | ||||||||||||||||||
3675 | qFileDialogUi->listView->clearSelection(); | - | ||||||||||||||||||
3676 | lineEdit()->setText(fileName); | - | ||||||||||||||||||
3677 | } never executed: end of block | 0 | ||||||||||||||||||
3678 | } never executed: end of block | 0 | ||||||||||||||||||
3679 | - | |||||||||||||||||||
3680 | model->setNameFilters(newNameFilters); | - | ||||||||||||||||||
3681 | } never executed: end of block | 0 | ||||||||||||||||||
3682 | - | |||||||||||||||||||
3683 | /*! | - | ||||||||||||||||||
3684 | \internal | - | ||||||||||||||||||
3685 | - | |||||||||||||||||||
3686 | This is called when the model index corresponding to the current file is changed | - | ||||||||||||||||||
3687 | from \a index to \a current. | - | ||||||||||||||||||
3688 | */ | - | ||||||||||||||||||
3689 | void QFileDialogPrivate::_q_selectionChanged() | - | ||||||||||||||||||
3690 | { | - | ||||||||||||||||||
3691 | const QFileDialog::FileMode fileMode = q_func()->fileMode(); | - | ||||||||||||||||||
3692 | QModelIndexList indexes = qFileDialogUi->listView->selectionModel()->selectedRows(); | - | ||||||||||||||||||
3693 | bool stripDirs = (fileMode != QFileDialog::DirectoryOnly && fileMode != QFileDialog::Directory);
| 0 | ||||||||||||||||||
3694 | - | |||||||||||||||||||
3695 | QStringList allFiles; | - | ||||||||||||||||||
3696 | for (int i = 0; i < indexes.count(); ++i) {
| 0 | ||||||||||||||||||
3697 | if (stripDirs && model->isDir(mapToSource(indexes.at(i))))
| 0 | ||||||||||||||||||
3698 | continue; never executed: continue; | 0 | ||||||||||||||||||
3699 | allFiles.append(indexes.at(i).data().toString()); | - | ||||||||||||||||||
3700 | } never executed: end of block | 0 | ||||||||||||||||||
3701 | if (allFiles.count() > 1)
| 0 | ||||||||||||||||||
3702 | for (int i = 0; i < allFiles.count(); ++i) {
| 0 | ||||||||||||||||||
3703 | allFiles.replace(i, QString(QLatin1Char('"') + allFiles.at(i) + QLatin1Char('"'))); | - | ||||||||||||||||||
3704 | } never executed: end of block | 0 | ||||||||||||||||||
3705 | - | |||||||||||||||||||
3706 | QString finalFiles = allFiles.join(QLatin1Char(' ')); | - | ||||||||||||||||||
3707 | if (!finalFiles.isEmpty() && !lineEdit()->hasFocus() && lineEdit()->isVisible())
| 0 | ||||||||||||||||||
3708 | lineEdit()->setText(finalFiles); never executed: lineEdit()->setText(finalFiles); | 0 | ||||||||||||||||||
3709 | else | - | ||||||||||||||||||
3710 | _q_updateOkButton(); never executed: _q_updateOkButton(); | 0 | ||||||||||||||||||
3711 | } | - | ||||||||||||||||||
3712 | - | |||||||||||||||||||
3713 | /*! | - | ||||||||||||||||||
3714 | \internal | - | ||||||||||||||||||
3715 | - | |||||||||||||||||||
3716 | Includes hidden files and directories in the items displayed in the dialog. | - | ||||||||||||||||||
3717 | */ | - | ||||||||||||||||||
3718 | void QFileDialogPrivate::_q_showHidden() | - | ||||||||||||||||||
3719 | { | - | ||||||||||||||||||
3720 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3721 | QDir::Filters dirFilters = q->filter(); | - | ||||||||||||||||||
3722 | if (showHiddenAction->isChecked())
| 0 | ||||||||||||||||||
3723 | dirFilters |= QDir::Hidden; never executed: dirFilters |= QDir::Hidden; | 0 | ||||||||||||||||||
3724 | else | - | ||||||||||||||||||
3725 | dirFilters &= ~QDir::Hidden; never executed: dirFilters &= ~QDir::Hidden; | 0 | ||||||||||||||||||
3726 | q->setFilter(dirFilters); | - | ||||||||||||||||||
3727 | } never executed: end of block | 0 | ||||||||||||||||||
3728 | - | |||||||||||||||||||
3729 | /*! | - | ||||||||||||||||||
3730 | \internal | - | ||||||||||||||||||
3731 | - | |||||||||||||||||||
3732 | When parent is root and rows have been inserted when none was there before | - | ||||||||||||||||||
3733 | then select the first one. | - | ||||||||||||||||||
3734 | */ | - | ||||||||||||||||||
3735 | void QFileDialogPrivate::_q_rowsInserted(const QModelIndex &parent) | - | ||||||||||||||||||
3736 | { | - | ||||||||||||||||||
3737 | if (!qFileDialogUi->treeView
| 0 | ||||||||||||||||||
3738 | || parent != qFileDialogUi->treeView->rootIndex()
| 0 | ||||||||||||||||||
3739 | || !qFileDialogUi->treeView->selectionModel()
| 0 | ||||||||||||||||||
3740 | || qFileDialogUi->treeView->selectionModel()->hasSelection()
| 0 | ||||||||||||||||||
3741 | || qFileDialogUi->treeView->model()->rowCount(parent) == 0)
| 0 | ||||||||||||||||||
3742 | return; never executed: return; | 0 | ||||||||||||||||||
3743 | } never executed: end of block | 0 | ||||||||||||||||||
3744 | - | |||||||||||||||||||
3745 | void QFileDialogPrivate::_q_fileRenamed(const QString &path, const QString &oldName, const QString &newName) | - | ||||||||||||||||||
3746 | { | - | ||||||||||||||||||
3747 | const QFileDialog::FileMode fileMode = q_func()->fileMode(); | - | ||||||||||||||||||
3748 | if (fileMode == QFileDialog::Directory || fileMode == QFileDialog::DirectoryOnly) {
| 0 | ||||||||||||||||||
3749 | if (path == rootPath() && lineEdit()->text() == oldName)
| 0 | ||||||||||||||||||
3750 | lineEdit()->setText(newName); never executed: lineEdit()->setText(newName); | 0 | ||||||||||||||||||
3751 | } never executed: end of block | 0 | ||||||||||||||||||
3752 | } never executed: end of block | 0 | ||||||||||||||||||
3753 | - | |||||||||||||||||||
3754 | void QFileDialogPrivate::_q_emitUrlSelected(const QUrl &file) | - | ||||||||||||||||||
3755 | { | - | ||||||||||||||||||
3756 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3757 | emit q->urlSelected(file); | - | ||||||||||||||||||
3758 | if (file.isLocalFile())
| 0 | ||||||||||||||||||
3759 | emit q->fileSelected(file.toLocalFile()); never executed: q->fileSelected(file.toLocalFile()); | 0 | ||||||||||||||||||
3760 | } never executed: end of block | 0 | ||||||||||||||||||
3761 | - | |||||||||||||||||||
3762 | void QFileDialogPrivate::_q_emitUrlsSelected(const QList<QUrl> &files) | - | ||||||||||||||||||
3763 | { | - | ||||||||||||||||||
3764 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3765 | emit q->urlsSelected(files); | - | ||||||||||||||||||
3766 | QStringList localFiles; | - | ||||||||||||||||||
3767 | foreach (const QUrl &file, files) | - | ||||||||||||||||||
3768 | if (file.isLocalFile())
| 0 | ||||||||||||||||||
3769 | localFiles.append(file.toLocalFile()); never executed: localFiles.append(file.toLocalFile()); | 0 | ||||||||||||||||||
3770 | if (!localFiles.isEmpty())
| 0 | ||||||||||||||||||
3771 | emit q->filesSelected(localFiles); never executed: q->filesSelected(localFiles); | 0 | ||||||||||||||||||
3772 | } never executed: end of block | 0 | ||||||||||||||||||
3773 | - | |||||||||||||||||||
3774 | void QFileDialogPrivate::_q_nativeCurrentChanged(const QUrl &file) | - | ||||||||||||||||||
3775 | { | - | ||||||||||||||||||
3776 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3777 | emit q->currentUrlChanged(file); | - | ||||||||||||||||||
3778 | if (file.isLocalFile())
| 0 | ||||||||||||||||||
3779 | emit q->currentChanged(file.toLocalFile()); never executed: q->currentChanged(file.toLocalFile()); | 0 | ||||||||||||||||||
3780 | } never executed: end of block | 0 | ||||||||||||||||||
3781 | - | |||||||||||||||||||
3782 | void QFileDialogPrivate::_q_nativeEnterDirectory(const QUrl &directory) | - | ||||||||||||||||||
3783 | { | - | ||||||||||||||||||
3784 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3785 | emit q->directoryUrlEntered(directory); | - | ||||||||||||||||||
3786 | if (!directory.isEmpty()) { // Windows native dialogs occasionally emit signals with empty strings.
| 0 | ||||||||||||||||||
3787 | *lastVisitedDir() = directory; | - | ||||||||||||||||||
3788 | if (directory.isLocalFile())
| 0 | ||||||||||||||||||
3789 | emit q->directoryEntered(directory.toLocalFile()); never executed: q->directoryEntered(directory.toLocalFile()); | 0 | ||||||||||||||||||
3790 | } never executed: end of block | 0 | ||||||||||||||||||
3791 | } never executed: end of block | 0 | ||||||||||||||||||
3792 | - | |||||||||||||||||||
3793 | /*! | - | ||||||||||||||||||
3794 | \internal | - | ||||||||||||||||||
3795 | - | |||||||||||||||||||
3796 | For the list and tree view watch keys to goto parent and back in the history | - | ||||||||||||||||||
3797 | - | |||||||||||||||||||
3798 | returns \c true if handled | - | ||||||||||||||||||
3799 | */ | - | ||||||||||||||||||
3800 | bool QFileDialogPrivate::itemViewKeyboardEvent(QKeyEvent *event) { | - | ||||||||||||||||||
3801 | - | |||||||||||||||||||
3802 | Q_Q(QFileDialog); | - | ||||||||||||||||||
3803 | - | |||||||||||||||||||
3804 | if (event->matches(QKeySequence::Cancel)) {
| 0 | ||||||||||||||||||
3805 | q->reject(); | - | ||||||||||||||||||
3806 | return true; never executed: return true; | 0 | ||||||||||||||||||
3807 | } | - | ||||||||||||||||||
3808 | - | |||||||||||||||||||
3809 | switch (event->key()) { | - | ||||||||||||||||||
3810 | case Qt::Key_Backspace: never executed: case Qt::Key_Backspace: | 0 | ||||||||||||||||||
3811 | _q_navigateToParent(); | - | ||||||||||||||||||
3812 | return true; never executed: return true; | 0 | ||||||||||||||||||
3813 | case Qt::Key_Back: never executed: case Qt::Key_Back: | 0 | ||||||||||||||||||
3814 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
3815 | if (QApplication::keypadNavigationEnabled()) | - | ||||||||||||||||||
3816 | return false; | - | ||||||||||||||||||
3817 | #endif | - | ||||||||||||||||||
3818 | case Qt::Key_Left: never executed: case Qt::Key_Left: | 0 | ||||||||||||||||||
3819 | if (event->key() == Qt::Key_Back || event->modifiers() == Qt::AltModifier) {
| 0 | ||||||||||||||||||
3820 | _q_navigateBackward(); | - | ||||||||||||||||||
3821 | return true; never executed: return true; | 0 | ||||||||||||||||||
3822 | } | - | ||||||||||||||||||
3823 | break; never executed: break; | 0 | ||||||||||||||||||
3824 | default: never executed: default: | 0 | ||||||||||||||||||
3825 | break; never executed: break; | 0 | ||||||||||||||||||
3826 | } | - | ||||||||||||||||||
3827 | return false; never executed: return false; | 0 | ||||||||||||||||||
3828 | } | - | ||||||||||||||||||
3829 | - | |||||||||||||||||||
3830 | QString QFileDialogPrivate::getEnvironmentVariable(const QString &string) | - | ||||||||||||||||||
3831 | { | - | ||||||||||||||||||
3832 | #ifdef Q_OS_UNIX | - | ||||||||||||||||||
3833 | if (string.size() > 1 && string.startsWith(QLatin1Char('$'))) {
| 0 | ||||||||||||||||||
3834 | return QString::fromLocal8Bit(qgetenv(string.mid(1).toLatin1().constData())); never executed: return QString::fromLocal8Bit(qgetenv(string.mid(1).toLatin1().constData())); | 0 | ||||||||||||||||||
3835 | } | - | ||||||||||||||||||
3836 | #else | - | ||||||||||||||||||
3837 | if (string.size() > 2 && string.startsWith(QLatin1Char('%')) && string.endsWith(QLatin1Char('%'))) { | - | ||||||||||||||||||
3838 | return QString::fromLocal8Bit(qgetenv(string.mid(1, string.size() - 2).toLatin1().constData())); | - | ||||||||||||||||||
3839 | } | - | ||||||||||||||||||
3840 | #endif | - | ||||||||||||||||||
3841 | return string; never executed: return string; | 0 | ||||||||||||||||||
3842 | } | - | ||||||||||||||||||
3843 | - | |||||||||||||||||||
3844 | void QFileDialogComboBox::setFileDialogPrivate(QFileDialogPrivate *d_pointer) { | - | ||||||||||||||||||
3845 | d_ptr = d_pointer; | - | ||||||||||||||||||
3846 | urlModel = new QUrlModel(this); | - | ||||||||||||||||||
3847 | urlModel->showFullPath = true; | - | ||||||||||||||||||
3848 | urlModel->setFileSystemModel(d_ptr->model); | - | ||||||||||||||||||
3849 | setModel(urlModel); | - | ||||||||||||||||||
3850 | } never executed: end of block | 0 | ||||||||||||||||||
3851 | - | |||||||||||||||||||
3852 | void QFileDialogComboBox::showPopup() | - | ||||||||||||||||||
3853 | { | - | ||||||||||||||||||
3854 | if (model()->rowCount() > 1)
| 0 | ||||||||||||||||||
3855 | QComboBox::showPopup(); never executed: QComboBox::showPopup(); | 0 | ||||||||||||||||||
3856 | - | |||||||||||||||||||
3857 | urlModel->setUrls(QList<QUrl>()); | - | ||||||||||||||||||
3858 | QList<QUrl> list; | - | ||||||||||||||||||
3859 | QModelIndex idx = d_ptr->model->index(d_ptr->rootPath()); | - | ||||||||||||||||||
3860 | while (idx.isValid()) {
| 0 | ||||||||||||||||||
3861 | QUrl url = QUrl::fromLocalFile(idx.data(QFileSystemModel::FilePathRole).toString()); | - | ||||||||||||||||||
3862 | if (url.isValid())
| 0 | ||||||||||||||||||
3863 | list.append(url); never executed: list.append(url); | 0 | ||||||||||||||||||
3864 | idx = idx.parent(); | - | ||||||||||||||||||
3865 | } never executed: end of block | 0 | ||||||||||||||||||
3866 | // add "my computer" | - | ||||||||||||||||||
3867 | list.append(QUrl(QLatin1String("file:"))); | - | ||||||||||||||||||
3868 | urlModel->addUrls(list, 0); | - | ||||||||||||||||||
3869 | idx = model()->index(model()->rowCount() - 1, 0); | - | ||||||||||||||||||
3870 | - | |||||||||||||||||||
3871 | // append history | - | ||||||||||||||||||
3872 | QList<QUrl> urls; | - | ||||||||||||||||||
3873 | for (int i = 0; i < m_history.count(); ++i) {
| 0 | ||||||||||||||||||
3874 | QUrl path = QUrl::fromLocalFile(m_history.at(i)); | - | ||||||||||||||||||
3875 | if (!urls.contains(path))
| 0 | ||||||||||||||||||
3876 | urls.prepend(path); never executed: urls.prepend(path); | 0 | ||||||||||||||||||
3877 | } never executed: end of block | 0 | ||||||||||||||||||
3878 | if (urls.count() > 0) {
| 0 | ||||||||||||||||||
3879 | model()->insertRow(model()->rowCount()); | - | ||||||||||||||||||
3880 | idx = model()->index(model()->rowCount()-1, 0); | - | ||||||||||||||||||
3881 | // ### TODO maybe add a horizontal line before this | - | ||||||||||||||||||
3882 | model()->setData(idx, QFileDialog::tr("Recent Places")); | - | ||||||||||||||||||
3883 | QStandardItemModel *m = qobject_cast<QStandardItemModel*>(model()); | - | ||||||||||||||||||
3884 | if (m) {
| 0 | ||||||||||||||||||
3885 | Qt::ItemFlags flags = m->flags(idx); | - | ||||||||||||||||||
3886 | flags &= ~Qt::ItemIsEnabled; | - | ||||||||||||||||||
3887 | m->item(idx.row(), idx.column())->setFlags(flags); | - | ||||||||||||||||||
3888 | } never executed: end of block | 0 | ||||||||||||||||||
3889 | urlModel->addUrls(urls, -1, false); | - | ||||||||||||||||||
3890 | } never executed: end of block | 0 | ||||||||||||||||||
3891 | setCurrentIndex(0); | - | ||||||||||||||||||
3892 | - | |||||||||||||||||||
3893 | QComboBox::showPopup(); | - | ||||||||||||||||||
3894 | } never executed: end of block | 0 | ||||||||||||||||||
3895 | - | |||||||||||||||||||
3896 | // Exact same as QComboBox::paintEvent(), except we elide the text. | - | ||||||||||||||||||
3897 | void QFileDialogComboBox::paintEvent(QPaintEvent *) | - | ||||||||||||||||||
3898 | { | - | ||||||||||||||||||
3899 | QStylePainter painter(this); | - | ||||||||||||||||||
3900 | painter.setPen(palette().color(QPalette::Text)); | - | ||||||||||||||||||
3901 | - | |||||||||||||||||||
3902 | // draw the combobox frame, focusrect and selected etc. | - | ||||||||||||||||||
3903 | QStyleOptionComboBox opt; | - | ||||||||||||||||||
3904 | initStyleOption(&opt); | - | ||||||||||||||||||
3905 | - | |||||||||||||||||||
3906 | QRect editRect = style()->subControlRect(QStyle::CC_ComboBox, &opt, | - | ||||||||||||||||||
3907 | QStyle::SC_ComboBoxEditField, this); | - | ||||||||||||||||||
3908 | int size = editRect.width() - opt.iconSize.width() - 4; | - | ||||||||||||||||||
3909 | opt.currentText = opt.fontMetrics.elidedText(opt.currentText, Qt::ElideMiddle, size); | - | ||||||||||||||||||
3910 | painter.drawComplexControl(QStyle::CC_ComboBox, opt); | - | ||||||||||||||||||
3911 | - | |||||||||||||||||||
3912 | // draw the icon and text | - | ||||||||||||||||||
3913 | painter.drawControl(QStyle::CE_ComboBoxLabel, opt); | - | ||||||||||||||||||
3914 | } never executed: end of block | 0 | ||||||||||||||||||
3915 | - | |||||||||||||||||||
3916 | QFileDialogListView::QFileDialogListView(QWidget *parent) : QListView(parent) | - | ||||||||||||||||||
3917 | { | - | ||||||||||||||||||
3918 | } never executed: end of block | 0 | ||||||||||||||||||
3919 | - | |||||||||||||||||||
3920 | void QFileDialogListView::setFileDialogPrivate(QFileDialogPrivate *d_pointer) | - | ||||||||||||||||||
3921 | { | - | ||||||||||||||||||
3922 | d_ptr = d_pointer; | - | ||||||||||||||||||
3923 | setSelectionBehavior(QAbstractItemView::SelectRows); | - | ||||||||||||||||||
3924 | setWrapping(true); | - | ||||||||||||||||||
3925 | setResizeMode(QListView::Adjust); | - | ||||||||||||||||||
3926 | setEditTriggers(QAbstractItemView::EditKeyPressed); | - | ||||||||||||||||||
3927 | setContextMenuPolicy(Qt::CustomContextMenu); | - | ||||||||||||||||||
3928 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||
3929 | setDragDropMode(QAbstractItemView::InternalMove); | - | ||||||||||||||||||
3930 | #endif | - | ||||||||||||||||||
3931 | } never executed: end of block | 0 | ||||||||||||||||||
3932 | - | |||||||||||||||||||
3933 | QSize QFileDialogListView::sizeHint() const | - | ||||||||||||||||||
3934 | { | - | ||||||||||||||||||
3935 | int height = qMax(10, sizeHintForRow(0)); | - | ||||||||||||||||||
3936 | return QSize(QListView::sizeHint().width() * 2, height * 30); never executed: return QSize(QListView::sizeHint().width() * 2, height * 30); | 0 | ||||||||||||||||||
3937 | } | - | ||||||||||||||||||
3938 | - | |||||||||||||||||||
3939 | void QFileDialogListView::keyPressEvent(QKeyEvent *e) | - | ||||||||||||||||||
3940 | { | - | ||||||||||||||||||
3941 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
3942 | if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) { | - | ||||||||||||||||||
3943 | QListView::keyPressEvent(e); | - | ||||||||||||||||||
3944 | return; | - | ||||||||||||||||||
3945 | } | - | ||||||||||||||||||
3946 | #endif // QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
3947 | - | |||||||||||||||||||
3948 | if (!d_ptr->itemViewKeyboardEvent(e))
| 0 | ||||||||||||||||||
3949 | QListView::keyPressEvent(e); never executed: QListView::keyPressEvent(e); | 0 | ||||||||||||||||||
3950 | e->accept(); | - | ||||||||||||||||||
3951 | } never executed: end of block | 0 | ||||||||||||||||||
3952 | - | |||||||||||||||||||
3953 | QFileDialogTreeView::QFileDialogTreeView(QWidget *parent) : QTreeView(parent) | - | ||||||||||||||||||
3954 | { | - | ||||||||||||||||||
3955 | } never executed: end of block | 0 | ||||||||||||||||||
3956 | - | |||||||||||||||||||
3957 | void QFileDialogTreeView::setFileDialogPrivate(QFileDialogPrivate *d_pointer) | - | ||||||||||||||||||
3958 | { | - | ||||||||||||||||||
3959 | d_ptr = d_pointer; | - | ||||||||||||||||||
3960 | setSelectionBehavior(QAbstractItemView::SelectRows); | - | ||||||||||||||||||
3961 | setRootIsDecorated(false); | - | ||||||||||||||||||
3962 | setItemsExpandable(false); | - | ||||||||||||||||||
3963 | setSortingEnabled(true); | - | ||||||||||||||||||
3964 | header()->setSortIndicator(0, Qt::AscendingOrder); | - | ||||||||||||||||||
3965 | header()->setStretchLastSection(false); | - | ||||||||||||||||||
3966 | setTextElideMode(Qt::ElideMiddle); | - | ||||||||||||||||||
3967 | setEditTriggers(QAbstractItemView::EditKeyPressed); | - | ||||||||||||||||||
3968 | setContextMenuPolicy(Qt::CustomContextMenu); | - | ||||||||||||||||||
3969 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||
3970 | setDragDropMode(QAbstractItemView::InternalMove); | - | ||||||||||||||||||
3971 | #endif | - | ||||||||||||||||||
3972 | } never executed: end of block | 0 | ||||||||||||||||||
3973 | - | |||||||||||||||||||
3974 | void QFileDialogTreeView::keyPressEvent(QKeyEvent *e) | - | ||||||||||||||||||
3975 | { | - | ||||||||||||||||||
3976 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
3977 | if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) { | - | ||||||||||||||||||
3978 | QTreeView::keyPressEvent(e); | - | ||||||||||||||||||
3979 | return; | - | ||||||||||||||||||
3980 | } | - | ||||||||||||||||||
3981 | #endif // QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
3982 | - | |||||||||||||||||||
3983 | if (!d_ptr->itemViewKeyboardEvent(e))
| 0 | ||||||||||||||||||
3984 | QTreeView::keyPressEvent(e); never executed: QTreeView::keyPressEvent(e); | 0 | ||||||||||||||||||
3985 | e->accept(); | - | ||||||||||||||||||
3986 | } never executed: end of block | 0 | ||||||||||||||||||
3987 | - | |||||||||||||||||||
3988 | QSize QFileDialogTreeView::sizeHint() const | - | ||||||||||||||||||
3989 | { | - | ||||||||||||||||||
3990 | int height = qMax(10, sizeHintForRow(0)); | - | ||||||||||||||||||
3991 | QSize sizeHint = header()->sizeHint(); | - | ||||||||||||||||||
3992 | return QSize(sizeHint.width() * 4, height * 30); never executed: return QSize(sizeHint.width() * 4, height * 30); | 0 | ||||||||||||||||||
3993 | } | - | ||||||||||||||||||
3994 | - | |||||||||||||||||||
3995 | /*! | - | ||||||||||||||||||
3996 | // FIXME: this is a hack to avoid propagating key press events | - | ||||||||||||||||||
3997 | // to the dialog and from there to the "Ok" button | - | ||||||||||||||||||
3998 | */ | - | ||||||||||||||||||
3999 | void QFileDialogLineEdit::keyPressEvent(QKeyEvent *e) | - | ||||||||||||||||||
4000 | { | - | ||||||||||||||||||
4001 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
4002 | if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) { | - | ||||||||||||||||||
4003 | QLineEdit::keyPressEvent(e); | - | ||||||||||||||||||
4004 | return; | - | ||||||||||||||||||
4005 | } | - | ||||||||||||||||||
4006 | #endif // QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
4007 | - | |||||||||||||||||||
4008 | int key = e->key(); | - | ||||||||||||||||||
4009 | QLineEdit::keyPressEvent(e); | - | ||||||||||||||||||
4010 | if (!e->matches(QKeySequence::Cancel) && key != Qt::Key_Back)
| 0 | ||||||||||||||||||
4011 | e->accept(); never executed: e->accept(); | 0 | ||||||||||||||||||
4012 | } never executed: end of block | 0 | ||||||||||||||||||
4013 | - | |||||||||||||||||||
4014 | #ifndef QT_NO_FSCOMPLETER | - | ||||||||||||||||||
4015 | - | |||||||||||||||||||
4016 | QString QFSCompleter::pathFromIndex(const QModelIndex &index) const | - | ||||||||||||||||||
4017 | { | - | ||||||||||||||||||
4018 | const QFileSystemModel *dirModel; | - | ||||||||||||||||||
4019 | if (proxyModel)
| 0 | ||||||||||||||||||
4020 | dirModel = qobject_cast<const QFileSystemModel *>(proxyModel->sourceModel()); never executed: dirModel = qobject_cast<const QFileSystemModel *>(proxyModel->sourceModel()); | 0 | ||||||||||||||||||
4021 | else | - | ||||||||||||||||||
4022 | dirModel = sourceModel; never executed: dirModel = sourceModel; | 0 | ||||||||||||||||||
4023 | QString currentLocation = dirModel->rootPath(); | - | ||||||||||||||||||
4024 | QString path = index.data(QFileSystemModel::FilePathRole).toString(); | - | ||||||||||||||||||
4025 | if (!currentLocation.isEmpty() && path.startsWith(currentLocation)) {
| 0 | ||||||||||||||||||
4026 | #if defined(Q_OS_UNIX) || defined(Q_OS_WINCE) | - | ||||||||||||||||||
4027 | if (currentLocation == QDir::separator())
| 0 | ||||||||||||||||||
4028 | return path.mid(currentLocation.length()); never executed: return path.mid(currentLocation.length()); | 0 | ||||||||||||||||||
4029 | #endif | - | ||||||||||||||||||
4030 | if (currentLocation.endsWith(QLatin1Char('/')))
| 0 | ||||||||||||||||||
4031 | return path.mid(currentLocation.length()); never executed: return path.mid(currentLocation.length()); | 0 | ||||||||||||||||||
4032 | else | - | ||||||||||||||||||
4033 | return path.mid(currentLocation.length()+1); never executed: return path.mid(currentLocation.length()+1); | 0 | ||||||||||||||||||
4034 | } | - | ||||||||||||||||||
4035 | return index.data(QFileSystemModel::FilePathRole).toString(); never executed: return index.data(QFileSystemModel::FilePathRole).toString(); | 0 | ||||||||||||||||||
4036 | } | - | ||||||||||||||||||
4037 | - | |||||||||||||||||||
4038 | QStringList QFSCompleter::splitPath(const QString &path) const | - | ||||||||||||||||||
4039 | { | - | ||||||||||||||||||
4040 | if (path.isEmpty())
| 0 | ||||||||||||||||||
4041 | return QStringList(completionPrefix()); never executed: return QStringList(completionPrefix()); | 0 | ||||||||||||||||||
4042 | - | |||||||||||||||||||
4043 | QString pathCopy = QDir::toNativeSeparators(path); | - | ||||||||||||||||||
4044 | QString sep = QDir::separator(); | - | ||||||||||||||||||
4045 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||
4046 | if (pathCopy == QLatin1String("\\") || pathCopy == QLatin1String("\\\\")) | - | ||||||||||||||||||
4047 | return QStringList(pathCopy); | - | ||||||||||||||||||
4048 | QString doubleSlash(QLatin1String("\\\\")); | - | ||||||||||||||||||
4049 | if (pathCopy.startsWith(doubleSlash)) | - | ||||||||||||||||||
4050 | pathCopy = pathCopy.mid(2); | - | ||||||||||||||||||
4051 | else | - | ||||||||||||||||||
4052 | doubleSlash.clear(); | - | ||||||||||||||||||
4053 | #elif defined(Q_OS_UNIX) | - | ||||||||||||||||||
4054 | bool expanded; | - | ||||||||||||||||||
4055 | pathCopy = qt_tildeExpansion(pathCopy, &expanded); | - | ||||||||||||||||||
4056 | if (expanded) {
| 0 | ||||||||||||||||||
4057 | QFileSystemModel *dirModel; | - | ||||||||||||||||||
4058 | if (proxyModel)
| 0 | ||||||||||||||||||
4059 | dirModel = qobject_cast<QFileSystemModel *>(proxyModel->sourceModel()); never executed: dirModel = qobject_cast<QFileSystemModel *>(proxyModel->sourceModel()); | 0 | ||||||||||||||||||
4060 | else | - | ||||||||||||||||||
4061 | dirModel = sourceModel; never executed: dirModel = sourceModel; | 0 | ||||||||||||||||||
4062 | dirModel->fetchMore(dirModel->index(pathCopy)); | - | ||||||||||||||||||
4063 | } never executed: end of block | 0 | ||||||||||||||||||
4064 | #endif | - | ||||||||||||||||||
4065 | - | |||||||||||||||||||
4066 | QRegExp re(QLatin1Char('[') + QRegExp::escape(sep) + QLatin1Char(']')); | - | ||||||||||||||||||
4067 | - | |||||||||||||||||||
4068 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||
4069 | QStringList parts = pathCopy.split(re, QString::SkipEmptyParts); | - | ||||||||||||||||||
4070 | if (!doubleSlash.isEmpty() && !parts.isEmpty()) | - | ||||||||||||||||||
4071 | parts[0].prepend(doubleSlash); | - | ||||||||||||||||||
4072 | if (pathCopy.endsWith(sep)) | - | ||||||||||||||||||
4073 | parts.append(QString()); | - | ||||||||||||||||||
4074 | #else | - | ||||||||||||||||||
4075 | QStringList parts = pathCopy.split(re); | - | ||||||||||||||||||
4076 | if (pathCopy[0] == sep[0]) // read the "/" at the beginning as the split removed it
| 0 | ||||||||||||||||||
4077 | parts[0] = sep[0]; never executed: parts[0] = sep[0]; | 0 | ||||||||||||||||||
4078 | #endif | - | ||||||||||||||||||
4079 | - | |||||||||||||||||||
4080 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||
4081 | bool startsFromRoot = !parts.isEmpty() && parts[0].endsWith(QLatin1Char(':')); | - | ||||||||||||||||||
4082 | #else | - | ||||||||||||||||||
4083 | bool startsFromRoot = pathCopy[0] == sep[0]; | - | ||||||||||||||||||
4084 | #endif | - | ||||||||||||||||||
4085 | if (parts.count() == 1 || (parts.count() > 1 && !startsFromRoot)) {
| 0 | ||||||||||||||||||
4086 | const QFileSystemModel *dirModel; | - | ||||||||||||||||||
4087 | if (proxyModel)
| 0 | ||||||||||||||||||
4088 | dirModel = qobject_cast<const QFileSystemModel *>(proxyModel->sourceModel()); never executed: dirModel = qobject_cast<const QFileSystemModel *>(proxyModel->sourceModel()); | 0 | ||||||||||||||||||
4089 | else | - | ||||||||||||||||||
4090 | dirModel = sourceModel; never executed: dirModel = sourceModel; | 0 | ||||||||||||||||||
4091 | QString currentLocation = QDir::toNativeSeparators(dirModel->rootPath()); | - | ||||||||||||||||||
4092 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||
4093 | if (currentLocation.endsWith(QLatin1Char(':'))) | - | ||||||||||||||||||
4094 | currentLocation.append(sep); | - | ||||||||||||||||||
4095 | #endif | - | ||||||||||||||||||
4096 | if (currentLocation.contains(sep) && path != currentLocation) {
| 0 | ||||||||||||||||||
4097 | QStringList currentLocationList = splitPath(currentLocation); | - | ||||||||||||||||||
4098 | while (!currentLocationList.isEmpty()
| 0 | ||||||||||||||||||
4099 | && parts.count() > 0
| 0 | ||||||||||||||||||
4100 | && parts.at(0) == QLatin1String("..")) {
| 0 | ||||||||||||||||||
4101 | parts.removeFirst(); | - | ||||||||||||||||||
4102 | currentLocationList.removeLast(); | - | ||||||||||||||||||
4103 | } never executed: end of block | 0 | ||||||||||||||||||
4104 | if (!currentLocationList.isEmpty() && currentLocationList.last().isEmpty())
| 0 | ||||||||||||||||||
4105 | currentLocationList.removeLast(); never executed: currentLocationList.removeLast(); | 0 | ||||||||||||||||||
4106 | return currentLocationList + parts; never executed: return currentLocationList + parts; | 0 | ||||||||||||||||||
4107 | } | - | ||||||||||||||||||
4108 | } never executed: end of block | 0 | ||||||||||||||||||
4109 | return parts; never executed: return parts; | 0 | ||||||||||||||||||
4110 | } | - | ||||||||||||||||||
4111 | - | |||||||||||||||||||
4112 | #endif // QT_NO_COMPLETER | - | ||||||||||||||||||
4113 | - | |||||||||||||||||||
4114 | - | |||||||||||||||||||
4115 | QT_END_NAMESPACE | - | ||||||||||||||||||
4116 | - | |||||||||||||||||||
4117 | #include "moc_qfiledialog.cpp" | - | ||||||||||||||||||
4118 | - | |||||||||||||||||||
4119 | #endif // QT_NO_FILEDIALOG | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |