| 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) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at https://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 3 as published by the Free Software | - | ||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #define QT_NO_URL_CAST_FROM_STRING | - | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | #include <qvariant.h> | - | ||||||||||||||||||
| 43 | #include <private/qwidgetitemdata_p.h> | - | ||||||||||||||||||
| 44 | #include "qfiledialog.h" | - | ||||||||||||||||||
| 45 | - | |||||||||||||||||||
| 46 | #ifndef QT_NO_FILEDIALOG | - | ||||||||||||||||||
| 47 | #include "qfiledialog_p.h" | - | ||||||||||||||||||
| 48 | #include <private/qguiapplication_p.h> | - | ||||||||||||||||||
| 49 | #include <qfontmetrics.h> | - | ||||||||||||||||||
| 50 | #include <qaction.h> | - | ||||||||||||||||||
| 51 | #include <qheaderview.h> | - | ||||||||||||||||||
| 52 | #include <qshortcut.h> | - | ||||||||||||||||||
| 53 | #include <qgridlayout.h> | - | ||||||||||||||||||
| 54 | #include <qmenu.h> | - | ||||||||||||||||||
| 55 | #include <qmessagebox.h> | - | ||||||||||||||||||
| 56 | #include <qinputdialog.h> | - | ||||||||||||||||||
| 57 | #include <stdlib.h> | - | ||||||||||||||||||
| 58 | #include <qsettings.h> | - | ||||||||||||||||||
| 59 | #include <qdebug.h> | - | ||||||||||||||||||
| 60 | #include <qmimedatabase.h> | - | ||||||||||||||||||
| 61 | #include <qapplication.h> | - | ||||||||||||||||||
| 62 | #include <qstylepainter.h> | - | ||||||||||||||||||
| 63 | #if !defined(Q_OS_WINCE) | - | ||||||||||||||||||
| 64 | #include "ui_qfiledialog.h" | - | ||||||||||||||||||
| 65 | #else | - | ||||||||||||||||||
| 66 | #define Q_EMBEDDED_SMALLSCREEN | - | ||||||||||||||||||
| 67 | #include "ui_qfiledialog_embedded.h" | - | ||||||||||||||||||
| 68 | #if defined(Q_OS_WINCE) | - | ||||||||||||||||||
| 69 | extern bool qt_priv_ptr_valid; | - | ||||||||||||||||||
| 70 | #endif | - | ||||||||||||||||||
| 71 | #endif | - | ||||||||||||||||||
| 72 | #if defined(Q_OS_UNIX) | - | ||||||||||||||||||
| 73 | #include <pwd.h> | - | ||||||||||||||||||
| 74 | #include <unistd.h> // for pathconf() on OS X | - | ||||||||||||||||||
| 75 | #elif defined(Q_OS_WIN) | - | ||||||||||||||||||
| 76 | # include <QtCore/qt_windows.h> | - | ||||||||||||||||||
| 77 | #endif | - | ||||||||||||||||||
| 78 | - | |||||||||||||||||||
| 79 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 80 | - | |||||||||||||||||||
| 81 | Q_GLOBAL_STATIC(QUrl, lastVisitedDir) | - | ||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | /*! | - | ||||||||||||||||||
| 84 | \class QFileDialog | - | ||||||||||||||||||
| 85 | \brief The QFileDialog class provides a dialog that allow users to select files or directories. | - | ||||||||||||||||||
| 86 | \ingroup standard-dialogs | - | ||||||||||||||||||
| 87 | \inmodule QtWidgets | - | ||||||||||||||||||
| 88 | - | |||||||||||||||||||
| 89 | The QFileDialog class enables a user to traverse the file system in | - | ||||||||||||||||||
| 90 | order to select one or many files or a directory. | - | ||||||||||||||||||
| 91 | - | |||||||||||||||||||
| 92 | The easiest way to create a QFileDialog is to use the static functions. | - | ||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | \snippet code/src_gui_dialogs_qfiledialog.cpp 0 | - | ||||||||||||||||||
| 95 | - | |||||||||||||||||||
| 96 | In the above example, a modal QFileDialog is created using a static | - | ||||||||||||||||||
| 97 | function. The dialog initially displays the contents of the "/home/jana" | - | ||||||||||||||||||
| 98 | directory, and displays files matching the patterns given in the | - | ||||||||||||||||||
| 99 | string "Image Files (*.png *.jpg *.bmp)". The parent of the file dialog | - | ||||||||||||||||||
| 100 | is set to \e this, and the window title is set to "Open Image". | - | ||||||||||||||||||
| 101 | - | |||||||||||||||||||
| 102 | If you want to use multiple filters, separate each one with | - | ||||||||||||||||||
| 103 | \e two semicolons. For example: | - | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | \snippet code/src_gui_dialogs_qfiledialog.cpp 1 | - | ||||||||||||||||||
| 106 | - | |||||||||||||||||||
| 107 | You can create your own QFileDialog without using the static | - | ||||||||||||||||||
| 108 | functions. By calling setFileMode(), you can specify what the user must | - | ||||||||||||||||||
| 109 | select in the dialog: | - | ||||||||||||||||||
| 110 | - | |||||||||||||||||||
| 111 | \snippet code/src_gui_dialogs_qfiledialog.cpp 2 | - | ||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | In the above example, the mode of the file dialog is set to | - | ||||||||||||||||||
| 114 | AnyFile, meaning that the user can select any file, or even specify a | - | ||||||||||||||||||
| 115 | file that doesn't exist. This mode is useful for creating a | - | ||||||||||||||||||
| 116 | "Save As" file dialog. Use ExistingFile if the user must select an | - | ||||||||||||||||||
| 117 | existing file, or \l Directory if only a directory may be selected. | - | ||||||||||||||||||
| 118 | See the \l QFileDialog::FileMode enum for the complete list of modes. | - | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | The fileMode property contains the mode of operation for the dialog; | - | ||||||||||||||||||
| 121 | this indicates what types of objects the user is expected to select. | - | ||||||||||||||||||
| 122 | Use setNameFilter() to set the dialog's file filter. For example: | - | ||||||||||||||||||
| 123 | - | |||||||||||||||||||
| 124 | \snippet code/src_gui_dialogs_qfiledialog.cpp 3 | - | ||||||||||||||||||
| 125 | - | |||||||||||||||||||
| 126 | In the above example, the filter is set to \c{"Images (*.png *.xpm *.jpg)"}, | - | ||||||||||||||||||
| 127 | this means that only files with the extension \c png, \c xpm, | - | ||||||||||||||||||
| 128 | or \c jpg will be shown in the QFileDialog. You can apply | - | ||||||||||||||||||
| 129 | several filters by using setNameFilters(). Use selectNameFilter() to select | - | ||||||||||||||||||
| 130 | one of the filters you've given as the file dialog's default filter. | - | ||||||||||||||||||
| 131 | - | |||||||||||||||||||
| 132 | The file dialog has two view modes: \l{QFileDialog::}{List} and | - | ||||||||||||||||||
| 133 | \l{QFileDialog::}{Detail}. | - | ||||||||||||||||||
| 134 | \l{QFileDialog::}{List} presents the contents of the current directory | - | ||||||||||||||||||
| 135 | as a list of file and directory names. \l{QFileDialog::}{Detail} also | - | ||||||||||||||||||
| 136 | displays a list of file and directory names, but provides additional | - | ||||||||||||||||||
| 137 | information alongside each name, such as the file size and modification | - | ||||||||||||||||||
| 138 | date. Set the mode with setViewMode(): | - | ||||||||||||||||||
| 139 | - | |||||||||||||||||||
| 140 | \snippet code/src_gui_dialogs_qfiledialog.cpp 4 | - | ||||||||||||||||||
| 141 | - | |||||||||||||||||||
| 142 | The last important function you will need to use when creating your | - | ||||||||||||||||||
| 143 | own file dialog is selectedFiles(). | - | ||||||||||||||||||
| 144 | - | |||||||||||||||||||
| 145 | \snippet code/src_gui_dialogs_qfiledialog.cpp 5 | - | ||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | In the above example, a modal file dialog is created and shown. If | - | ||||||||||||||||||
| 148 | the user clicked OK, the file they selected is put in \c fileName. | - | ||||||||||||||||||
| 149 | - | |||||||||||||||||||
| 150 | The dialog's working directory can be set with setDirectory(). | - | ||||||||||||||||||
| 151 | Each file in the current directory can be selected using | - | ||||||||||||||||||
| 152 | the selectFile() function. | - | ||||||||||||||||||
| 153 | - | |||||||||||||||||||
| 154 | The \l{dialogs/standarddialogs}{Standard Dialogs} example shows | - | ||||||||||||||||||
| 155 | how to use QFileDialog as well as other built-in Qt dialogs. | - | ||||||||||||||||||
| 156 | - | |||||||||||||||||||
| 157 | By default, a platform-native file dialog will be used if the platform has | - | ||||||||||||||||||
| 158 | one. In that case, the widgets which would otherwise be used to construct the | - | ||||||||||||||||||
| 159 | dialog will not be instantiated, so related accessors such as layout() and | - | ||||||||||||||||||
| 160 | itemDelegate() will return null. You can set the \l DontUseNativeDialog option to | - | ||||||||||||||||||
| 161 | ensure that the widget-based implementation will be used instead of the | - | ||||||||||||||||||
| 162 | native dialog. | - | ||||||||||||||||||
| 163 | - | |||||||||||||||||||
| 164 | \sa QDir, QFileInfo, QFile, QColorDialog, QFontDialog, {Standard Dialogs Example}, | - | ||||||||||||||||||
| 165 | {Application Example} | - | ||||||||||||||||||
| 166 | */ | - | ||||||||||||||||||
| 167 | - | |||||||||||||||||||
| 168 | /*! | - | ||||||||||||||||||
| 169 | \enum QFileDialog::AcceptMode | - | ||||||||||||||||||
| 170 | - | |||||||||||||||||||
| 171 | \value AcceptOpen | - | ||||||||||||||||||
| 172 | \value AcceptSave | - | ||||||||||||||||||
| 173 | */ | - | ||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | /*! | - | ||||||||||||||||||
| 176 | \enum QFileDialog::ViewMode | - | ||||||||||||||||||
| 177 | - | |||||||||||||||||||
| 178 | This enum describes the view mode of the file dialog; i.e. what | - | ||||||||||||||||||
| 179 | information about each file will be displayed. | - | ||||||||||||||||||
| 180 | - | |||||||||||||||||||
| 181 | \value Detail Displays an icon, a name, and details for each item in | - | ||||||||||||||||||
| 182 | the directory. | - | ||||||||||||||||||
| 183 | \value List Displays only an icon and a name for each item in the | - | ||||||||||||||||||
| 184 | directory. | - | ||||||||||||||||||
| 185 | - | |||||||||||||||||||
| 186 | \sa setViewMode() | - | ||||||||||||||||||
| 187 | */ | - | ||||||||||||||||||
| 188 | - | |||||||||||||||||||
| 189 | /*! | - | ||||||||||||||||||
| 190 | \enum QFileDialog::FileMode | - | ||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | This enum is used to indicate what the user may select in the file | - | ||||||||||||||||||
| 193 | dialog; i.e. what the dialog will return if the user clicks OK. | - | ||||||||||||||||||
| 194 | - | |||||||||||||||||||
| 195 | \value AnyFile The name of a file, whether it exists or not. | - | ||||||||||||||||||
| 196 | \value ExistingFile The name of a single existing file. | - | ||||||||||||||||||
| 197 | \value Directory The name of a directory. Both files and | - | ||||||||||||||||||
| 198 | directories are displayed. However, the native Windows | - | ||||||||||||||||||
| 199 | file dialog does not support displaying files in the | - | ||||||||||||||||||
| 200 | directory chooser. | - | ||||||||||||||||||
| 201 | \value ExistingFiles The names of zero or more existing files. | - | ||||||||||||||||||
| 202 | - | |||||||||||||||||||
| 203 | This value is obsolete since Qt 4.5: | - | ||||||||||||||||||
| 204 | - | |||||||||||||||||||
| 205 | \value DirectoryOnly Use \c Directory and setOption(ShowDirsOnly, true) instead. | - | ||||||||||||||||||
| 206 | - | |||||||||||||||||||
| 207 | \sa setFileMode() | - | ||||||||||||||||||
| 208 | */ | - | ||||||||||||||||||
| 209 | - | |||||||||||||||||||
| 210 | /*! | - | ||||||||||||||||||
| 211 | \enum QFileDialog::Option | - | ||||||||||||||||||
| 212 | - | |||||||||||||||||||
| 213 | \value ShowDirsOnly Only show directories in the file dialog. By | - | ||||||||||||||||||
| 214 | default both files and directories are shown. (Valid only in the | - | ||||||||||||||||||
| 215 | \l Directory file mode.) | - | ||||||||||||||||||
| 216 | - | |||||||||||||||||||
| 217 | \value DontResolveSymlinks Don't resolve symlinks in the file | - | ||||||||||||||||||
| 218 | dialog. By default symlinks are resolved. | - | ||||||||||||||||||
| 219 | - | |||||||||||||||||||
| 220 | \value DontConfirmOverwrite Don't ask for confirmation if an | - | ||||||||||||||||||
| 221 | existing file is selected. By default confirmation is requested. | - | ||||||||||||||||||
| 222 | - | |||||||||||||||||||
| 223 | \value DontUseNativeDialog Don't use the native file dialog. By | - | ||||||||||||||||||
| 224 | default, the native file dialog is used unless you use a subclass | - | ||||||||||||||||||
| 225 | of QFileDialog that contains the Q_OBJECT macro, or the platform | - | ||||||||||||||||||
| 226 | does not have a native dialog of the type that you require. | - | ||||||||||||||||||
| 227 | - | |||||||||||||||||||
| 228 | \value ReadOnly Indicates that the model is readonly. | - | ||||||||||||||||||
| 229 | - | |||||||||||||||||||
| 230 | \value HideNameFilterDetails Indicates if the file name filter details are | - | ||||||||||||||||||
| 231 | hidden or not. | - | ||||||||||||||||||
| 232 | - | |||||||||||||||||||
| 233 | \value DontUseSheet In previous versions of Qt, the static | - | ||||||||||||||||||
| 234 | functions would create a sheet by default if the static function | - | ||||||||||||||||||
| 235 | was given a parent. This is no longer supported and does nothing in Qt 4.5, The | - | ||||||||||||||||||
| 236 | static functions will always be an application modal dialog. If | - | ||||||||||||||||||
| 237 | you want to use sheets, use QFileDialog::open() instead. | - | ||||||||||||||||||
| 238 | - | |||||||||||||||||||
| 239 | \value DontUseCustomDirectoryIcons Always use the default directory icon. | - | ||||||||||||||||||
| 240 | Some platforms allow the user to set a different icon. Custom icon lookup | - | ||||||||||||||||||
| 241 | cause a big performance impact over network or removable drives. | - | ||||||||||||||||||
| 242 | Setting this will enable the QFileIconProvider::DontUseCustomDirectoryIcons | - | ||||||||||||||||||
| 243 | option in the icon provider. This enum value was added in Qt 5.2. | - | ||||||||||||||||||
| 244 | */ | - | ||||||||||||||||||
| 245 | - | |||||||||||||||||||
| 246 | /*! | - | ||||||||||||||||||
| 247 | \enum QFileDialog::DialogLabel | - | ||||||||||||||||||
| 248 | - | |||||||||||||||||||
| 249 | \value LookIn | - | ||||||||||||||||||
| 250 | \value FileName | - | ||||||||||||||||||
| 251 | \value FileType | - | ||||||||||||||||||
| 252 | \value Accept | - | ||||||||||||||||||
| 253 | \value Reject | - | ||||||||||||||||||
| 254 | */ | - | ||||||||||||||||||
| 255 | - | |||||||||||||||||||
| 256 | /*! | - | ||||||||||||||||||
| 257 | \fn void QFileDialog::filesSelected(const QStringList &selected) | - | ||||||||||||||||||
| 258 | - | |||||||||||||||||||
| 259 | When the selection changes for local operations and the dialog is | - | ||||||||||||||||||
| 260 | accepted, this signal is emitted with the (possibly empty) list | - | ||||||||||||||||||
| 261 | of \a selected files. | - | ||||||||||||||||||
| 262 | - | |||||||||||||||||||
| 263 | \sa currentChanged(), QDialog::Accepted | - | ||||||||||||||||||
| 264 | */ | - | ||||||||||||||||||
| 265 | - | |||||||||||||||||||
| 266 | /*! | - | ||||||||||||||||||
| 267 | \fn void QFileDialog::urlsSelected(const QList<QUrl> &urls) | - | ||||||||||||||||||
| 268 | - | |||||||||||||||||||
| 269 | When the selection changes and the dialog is accepted, this signal is | - | ||||||||||||||||||
| 270 | emitted with the (possibly empty) list of selected \a urls. | - | ||||||||||||||||||
| 271 | - | |||||||||||||||||||
| 272 | \sa currentUrlChanged(), QDialog::Accepted | - | ||||||||||||||||||
| 273 | \since 5.2 | - | ||||||||||||||||||
| 274 | */ | - | ||||||||||||||||||
| 275 | - | |||||||||||||||||||
| 276 | /*! | - | ||||||||||||||||||
| 277 | \fn void QFileDialog::fileSelected(const QString &file) | - | ||||||||||||||||||
| 278 | - | |||||||||||||||||||
| 279 | When the selection changes for local operations and the dialog is | - | ||||||||||||||||||
| 280 | accepted, this signal is emitted with the (possibly empty) | - | ||||||||||||||||||
| 281 | selected \a file. | - | ||||||||||||||||||
| 282 | - | |||||||||||||||||||
| 283 | \sa currentChanged(), QDialog::Accepted | - | ||||||||||||||||||
| 284 | */ | - | ||||||||||||||||||
| 285 | - | |||||||||||||||||||
| 286 | /*! | - | ||||||||||||||||||
| 287 | \fn void QFileDialog::urlSelected(const QUrl &url) | - | ||||||||||||||||||
| 288 | - | |||||||||||||||||||
| 289 | When the selection changes and the dialog is accepted, this signal is | - | ||||||||||||||||||
| 290 | emitted with the (possibly empty) selected \a url. | - | ||||||||||||||||||
| 291 | - | |||||||||||||||||||
| 292 | \sa currentUrlChanged(), QDialog::Accepted | - | ||||||||||||||||||
| 293 | \since 5.2 | - | ||||||||||||||||||
| 294 | */ | - | ||||||||||||||||||
| 295 | - | |||||||||||||||||||
| 296 | /*! | - | ||||||||||||||||||
| 297 | \fn void QFileDialog::currentChanged(const QString &path) | - | ||||||||||||||||||
| 298 | - | |||||||||||||||||||
| 299 | When the current file changes for local operations, this signal is | - | ||||||||||||||||||
| 300 | emitted with the new file name as the \a path parameter. | - | ||||||||||||||||||
| 301 | - | |||||||||||||||||||
| 302 | \sa filesSelected() | - | ||||||||||||||||||
| 303 | */ | - | ||||||||||||||||||
| 304 | - | |||||||||||||||||||
| 305 | /*! | - | ||||||||||||||||||
| 306 | \fn void QFileDialog::currentUrlChanged(const QUrl &url) | - | ||||||||||||||||||
| 307 | - | |||||||||||||||||||
| 308 | When the current file changes, this signal is emitted with the | - | ||||||||||||||||||
| 309 | new file URL as the \a url parameter. | - | ||||||||||||||||||
| 310 | - | |||||||||||||||||||
| 311 | \sa urlsSelected() | - | ||||||||||||||||||
| 312 | \since 5.2 | - | ||||||||||||||||||
| 313 | */ | - | ||||||||||||||||||
| 314 | - | |||||||||||||||||||
| 315 | /*! | - | ||||||||||||||||||
| 316 | \fn void QFileDialog::directoryEntered(const QString &directory) | - | ||||||||||||||||||
| 317 | \since 4.3 | - | ||||||||||||||||||
| 318 | - | |||||||||||||||||||
| 319 | This signal is emitted for local operations when the user enters | - | ||||||||||||||||||
| 320 | a \a directory. | - | ||||||||||||||||||
| 321 | */ | - | ||||||||||||||||||
| 322 | - | |||||||||||||||||||
| 323 | /*! | - | ||||||||||||||||||
| 324 | \fn void QFileDialog::directoryUrlEntered(const QUrl &directory) | - | ||||||||||||||||||
| 325 | - | |||||||||||||||||||
| 326 | This signal is emitted when the user enters a \a directory. | - | ||||||||||||||||||
| 327 | - | |||||||||||||||||||
| 328 | \since 5.2 | - | ||||||||||||||||||
| 329 | */ | - | ||||||||||||||||||
| 330 | - | |||||||||||||||||||
| 331 | /*! | - | ||||||||||||||||||
| 332 | \fn void QFileDialog::filterSelected(const QString &filter) | - | ||||||||||||||||||
| 333 | \since 4.3 | - | ||||||||||||||||||
| 334 | - | |||||||||||||||||||
| 335 | This signal is emitted when the user selects a \a filter. | - | ||||||||||||||||||
| 336 | */ | - | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | QT_BEGIN_INCLUDE_NAMESPACE | - | ||||||||||||||||||
| 339 | #include <QMetaEnum> | - | ||||||||||||||||||
| 340 | #include <qshortcut.h> | - | ||||||||||||||||||
| 341 | QT_END_INCLUDE_NAMESPACE | - | ||||||||||||||||||
| 342 | - | |||||||||||||||||||
| 343 | /*! | - | ||||||||||||||||||
| 344 | \fn QFileDialog::QFileDialog(QWidget *parent, Qt::WindowFlags flags) | - | ||||||||||||||||||
| 345 | - | |||||||||||||||||||
| 346 | Constructs a file dialog with the given \a parent and widget \a flags. | - | ||||||||||||||||||
| 347 | */ | - | ||||||||||||||||||
| 348 | QFileDialog::QFileDialog(QWidget *parent, Qt::WindowFlags f) | - | ||||||||||||||||||
| 349 | : QDialog(*new QFileDialogPrivate, parent, f) | - | ||||||||||||||||||
| 350 | { | - | ||||||||||||||||||
| 351 | Q_D(QFileDialog); | - | ||||||||||||||||||
| 352 | d->init(); | - | ||||||||||||||||||
| 353 | } | - | ||||||||||||||||||
| 354 | - | |||||||||||||||||||
| 355 | /*! | - | ||||||||||||||||||
| 356 | Constructs a file dialog with the given \a parent and \a caption that | - | ||||||||||||||||||
| 357 | initially displays the contents of the specified \a directory. | - | ||||||||||||||||||
| 358 | The contents of the directory are filtered before being shown in the | - | ||||||||||||||||||
| 359 | dialog, using a semicolon-separated list of filters specified by | - | ||||||||||||||||||
| 360 | \a filter. | - | ||||||||||||||||||
| 361 | */ | - | ||||||||||||||||||
| 362 | QFileDialog::QFileDialog(QWidget *parent, | - | ||||||||||||||||||
| 363 | const QString &caption, | - | ||||||||||||||||||
| 364 | const QString &directory, | - | ||||||||||||||||||
| 365 | const QString &filter) | - | ||||||||||||||||||
| 366 | : QDialog(*new QFileDialogPrivate, parent, 0) | - | ||||||||||||||||||
| 367 | { | - | ||||||||||||||||||
| 368 | Q_D(QFileDialog); | - | ||||||||||||||||||
| 369 | d->init(QUrl::fromLocalFile(directory), filter, caption); | - | ||||||||||||||||||
| 370 | } | - | ||||||||||||||||||
| 371 | - | |||||||||||||||||||
| 372 | /*! | - | ||||||||||||||||||
| 373 | \internal | - | ||||||||||||||||||
| 374 | */ | - | ||||||||||||||||||
| 375 | QFileDialog::QFileDialog(const QFileDialogArgs &args) | - | ||||||||||||||||||
| 376 | : QDialog(*new QFileDialogPrivate, args.parent, 0) | - | ||||||||||||||||||
| 377 | { | - | ||||||||||||||||||
| 378 | Q_D(QFileDialog); | - | ||||||||||||||||||
| 379 | d->init(args.directory, args.filter, args.caption); | - | ||||||||||||||||||
| 380 | setFileMode(args.mode); | - | ||||||||||||||||||
| 381 | setOptions(args.options); | - | ||||||||||||||||||
| 382 | selectFile(args.selection); | - | ||||||||||||||||||
| 383 | } | - | ||||||||||||||||||
| 384 | - | |||||||||||||||||||
| 385 | /*! | - | ||||||||||||||||||
| 386 | Destroys the file dialog. | - | ||||||||||||||||||
| 387 | */ | - | ||||||||||||||||||
| 388 | QFileDialog::~QFileDialog() | - | ||||||||||||||||||
| 389 | { | - | ||||||||||||||||||
| 390 | #ifndef QT_NO_SETTINGS | - | ||||||||||||||||||
| 391 | Q_D(QFileDialog); | - | ||||||||||||||||||
| 392 | d->saveSettings(); | - | ||||||||||||||||||
| 393 | #endif | - | ||||||||||||||||||
| 394 | } | - | ||||||||||||||||||
| 395 | - | |||||||||||||||||||
| 396 | /*! | - | ||||||||||||||||||
| 397 | \since 4.3 | - | ||||||||||||||||||
| 398 | Sets the \a urls that are located in the sidebar. | - | ||||||||||||||||||
| 399 | - | |||||||||||||||||||
| 400 | For instance: | - | ||||||||||||||||||
| 401 | - | |||||||||||||||||||
| 402 | \snippet filedialogurls.cpp 0 | - | ||||||||||||||||||
| 403 | - | |||||||||||||||||||
| 404 | The file dialog will then look like this: | - | ||||||||||||||||||
| 405 | - | |||||||||||||||||||
| 406 | \image filedialogurls.png | - | ||||||||||||||||||
| 407 | - | |||||||||||||||||||
| 408 | \sa sidebarUrls() | - | ||||||||||||||||||
| 409 | */ | - | ||||||||||||||||||
| 410 | void QFileDialog::setSidebarUrls(const QList<QUrl> &urls) | - | ||||||||||||||||||
| 411 | { | - | ||||||||||||||||||
| 412 | Q_D(QFileDialog); | - | ||||||||||||||||||
| 413 | if (!d->nativeDialogInUse) | - | ||||||||||||||||||
| 414 | d->qFileDialogUi->sidebar->setUrls(urls); | - | ||||||||||||||||||
| 415 | } | - | ||||||||||||||||||
| 416 | - | |||||||||||||||||||
| 417 | /*! | - | ||||||||||||||||||
| 418 | \since 4.3 | - | ||||||||||||||||||
| 419 | Returns a list of urls that are currently in the sidebar | - | ||||||||||||||||||
| 420 | */ | - | ||||||||||||||||||
| 421 | QList<QUrl> QFileDialog::sidebarUrls() const | - | ||||||||||||||||||
| 422 | { | - | ||||||||||||||||||
| 423 | Q_D(const QFileDialog); | - | ||||||||||||||||||
| 424 | return (d->nativeDialogInUse ? QList<QUrl>() : d->qFileDialogUi->sidebar->urls()); | - | ||||||||||||||||||
| 425 | } | - | ||||||||||||||||||
| 426 | - | |||||||||||||||||||
| 427 | static const qint32 QFileDialogMagic = 0xbe; | - | ||||||||||||||||||
| 428 | - | |||||||||||||||||||
| 429 | /*! | - | ||||||||||||||||||
| 430 | \since 4.3 | - | ||||||||||||||||||
| 431 | Saves the state of the dialog's layout, history and current directory. | - | ||||||||||||||||||
| 432 | - | |||||||||||||||||||
| 433 | Typically this is used in conjunction with QSettings to remember the size | - | ||||||||||||||||||
| 434 | for a future session. A version number is stored as part of the data. | - | ||||||||||||||||||
| 435 | */ | - | ||||||||||||||||||
| 436 | QByteArray QFileDialog::saveState() const | - | ||||||||||||||||||
| 437 | { | - | ||||||||||||||||||
| 438 | Q_D(const QFileDialog); | - | ||||||||||||||||||
| 439 | int version = 4; | - | ||||||||||||||||||
| 440 | QByteArray data; | - | ||||||||||||||||||
| 441 | QDataStream stream(&data, QIODevice::WriteOnly); | - | ||||||||||||||||||
| 442 | - | |||||||||||||||||||
| 443 | stream << qint32(QFileDialogMagic); | - | ||||||||||||||||||
| 444 | stream << qint32(version); | - | ||||||||||||||||||
| 445 | if (d->usingWidgets()) { | - | ||||||||||||||||||
| 446 | stream << d->qFileDialogUi->splitter->saveState(); | - | ||||||||||||||||||
| 447 | stream << d->qFileDialogUi->sidebar->urls(); | - | ||||||||||||||||||
| 448 | } else { | - | ||||||||||||||||||
| 449 | stream << d->splitterState; | - | ||||||||||||||||||
| 450 | stream << d->sidebarUrls; | - | ||||||||||||||||||
| 451 | } | - | ||||||||||||||||||
| 452 | stream << history(); | - | ||||||||||||||||||
| 453 | stream << *lastVisitedDir(); | - | ||||||||||||||||||
| 454 | if (d->usingWidgets()) | - | ||||||||||||||||||
| 455 | stream << d->qFileDialogUi->treeView->header()->saveState(); | - | ||||||||||||||||||
| 456 | else | - | ||||||||||||||||||
| 457 | stream << d->headerData; | - | ||||||||||||||||||
| 458 | stream << qint32(viewMode()); | - | ||||||||||||||||||
| 459 | return data; | - | ||||||||||||||||||
| 460 | } | - | ||||||||||||||||||
| 461 | - | |||||||||||||||||||
| 462 | /*! | - | ||||||||||||||||||
| 463 | \since 4.3 | - | ||||||||||||||||||
| 464 | Restores the dialogs's layout, history and current directory to the \a state specified. | - | ||||||||||||||||||
| 465 | - | |||||||||||||||||||
| 466 | Typically this is used in conjunction with QSettings to restore the size | - | ||||||||||||||||||
| 467 | from a past session. | - | ||||||||||||||||||
| 468 | - | |||||||||||||||||||
| 469 | Returns \c false if there are errors | - | ||||||||||||||||||
| 470 | */ | - | ||||||||||||||||||
| 471 | bool QFileDialog::restoreState(const QByteArray &state) | - | ||||||||||||||||||
| 472 | { | - | ||||||||||||||||||
| 473 | Q_D(QFileDialog); | - | ||||||||||||||||||
| 474 | QByteArray sd = state; | - | ||||||||||||||||||
| 475 | QDataStream stream(&sd, QIODevice::ReadOnly); | - | ||||||||||||||||||
| 476 | if (stream.atEnd()) | - | ||||||||||||||||||
| 477 | return false; | - | ||||||||||||||||||
| 478 | QStringList history; | - | ||||||||||||||||||
| 479 | QUrl currentDirectory; | - | ||||||||||||||||||
| 480 | qint32 marker; | - | ||||||||||||||||||
| 481 | qint32 v; | - | ||||||||||||||||||
| 482 | qint32 viewMode; | - | ||||||||||||||||||
| 483 | stream >> marker; | - | ||||||||||||||||||
| 484 | stream >> v; | - | ||||||||||||||||||
| 485 | // the code below only supports versions 3 and 4 | - | ||||||||||||||||||
| 486 | if (marker != QFileDialogMagic || (v != 3 && v != 4)) | - | ||||||||||||||||||
| 487 | return false; | - | ||||||||||||||||||
| 488 | - | |||||||||||||||||||
| 489 | stream >> d->splitterState | - | ||||||||||||||||||
| 490 | >> d->sidebarUrls | - | ||||||||||||||||||
| 491 | >> history; | - | ||||||||||||||||||
| 492 | if (v == 3) { | - | ||||||||||||||||||
| 493 | QString currentDirectoryString; | - | ||||||||||||||||||
| 494 | stream >> currentDirectoryString; | - | ||||||||||||||||||
| 495 | currentDirectory = QUrl::fromLocalFile(currentDirectoryString); | - | ||||||||||||||||||
| 496 | } else { | - | ||||||||||||||||||
| 497 | stream >> currentDirectory; | - | ||||||||||||||||||
| 498 | } | - | ||||||||||||||||||
| 499 | stream >> d->headerData | - | ||||||||||||||||||
| 500 | >> viewMode; | - | ||||||||||||||||||
| 501 | - | |||||||||||||||||||
| 502 | setDirectoryUrl(lastVisitedDir()->isEmpty() ? currentDirectory : *lastVisitedDir()); | - | ||||||||||||||||||
| 503 | setViewMode(static_cast<QFileDialog::ViewMode>(viewMode)); | - | ||||||||||||||||||
| 504 | - | |||||||||||||||||||
| 505 | if (!d->usingWidgets()) | - | ||||||||||||||||||
| 506 | return true; | - | ||||||||||||||||||
| 507 | - | |||||||||||||||||||
| 508 | return d->restoreWidgetState(history, -1); | - | ||||||||||||||||||
| 509 | } | - | ||||||||||||||||||
| 510 | - | |||||||||||||||||||
| 511 | /*! | - | ||||||||||||||||||
| 512 | \reimp | - | ||||||||||||||||||
| 513 | */ | - | ||||||||||||||||||
| 514 | void QFileDialog::changeEvent(QEvent *e) | - | ||||||||||||||||||
| 515 | { | - | ||||||||||||||||||
| 516 | Q_D(QFileDialog); | - | ||||||||||||||||||
| 517 | if (e->type() == QEvent::LanguageChange) { | - | ||||||||||||||||||
| 518 | d->retranslateWindowTitle(); | - | ||||||||||||||||||
| 519 | d->retranslateStrings(); | - | ||||||||||||||||||
| 520 | } | - | ||||||||||||||||||
| 521 | QDialog::changeEvent(e); | - | ||||||||||||||||||
| 522 | } | - | ||||||||||||||||||
| 523 | - | |||||||||||||||||||
| 524 | QFileDialogPrivate::QFileDialogPrivate() | - | ||||||||||||||||||
| 525 | : | - | ||||||||||||||||||
| 526 | #ifndef QT_NO_PROXYMODEL | - | ||||||||||||||||||
| 527 | proxyModel(0), | - | ||||||||||||||||||
| 528 | #endif | - | ||||||||||||||||||
| 529 | model(0), | - | ||||||||||||||||||
| 530 | currentHistoryLocation(-1), | - | ||||||||||||||||||
| 531 | renameAction(0), | - | ||||||||||||||||||
| 532 | deleteAction(0), | - | ||||||||||||||||||
| 533 | showHiddenAction(0), | - | ||||||||||||||||||
| 534 | useDefaultCaption(true), | - | ||||||||||||||||||
| defaultFileTypes(true), | ||||||||||||||||||||
| 535 | qFileDialogUi(0), | - | ||||||||||||||||||
| 536 | options(new QFileDialogOptions) | - | ||||||||||||||||||
| 537 | { | - | ||||||||||||||||||
| 538 | } never executed: end of block | 0 | ||||||||||||||||||
| 539 | - | |||||||||||||||||||
| 540 | QFileDialogPrivate::~QFileDialogPrivate() | - | ||||||||||||||||||
| 541 | { | - | ||||||||||||||||||
| 542 | } | - | ||||||||||||||||||
| 543 | - | |||||||||||||||||||
| 544 | void QFileDialogPrivate::initHelper(QPlatformDialogHelper *h) | - | ||||||||||||||||||
| 545 | { | - | ||||||||||||||||||
| 546 | QFileDialog *d = q_func(); | - | ||||||||||||||||||
| 547 | QObject::connect(h, SIGNAL(fileSelected(QUrl)), d, SLOT(_q_emitUrlSelected(QUrl))); | - | ||||||||||||||||||
| 548 | QObject::connect(h, SIGNAL(filesSelected(QList<QUrl>)), d, SLOT(_q_emitUrlsSelected(QList<QUrl>))); | - | ||||||||||||||||||
| 549 | QObject::connect(h, SIGNAL(currentChanged(QUrl)), d, SLOT(_q_nativeCurrentChanged(QUrl))); | - | ||||||||||||||||||
| 550 | QObject::connect(h, SIGNAL(directoryEntered(QUrl)), d, SLOT(_q_nativeEnterDirectory(QUrl))); | - | ||||||||||||||||||
| 551 | QObject::connect(h, SIGNAL(filterSelected(QString)), d, SIGNAL(filterSelected(QString))); | - | ||||||||||||||||||
| 552 | static_cast<QPlatformFileDialogHelper *>(h)->setOptions(options); | - | ||||||||||||||||||
| 553 | nativeDialogInUse = true; | - | ||||||||||||||||||
| 554 | } | - | ||||||||||||||||||
| 555 | - | |||||||||||||||||||
| 556 | void QFileDialogPrivate::helperPrepareShow(QPlatformDialogHelper *) | - | ||||||||||||||||||
| 557 | { | - | ||||||||||||||||||
| 558 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 559 | options->setWindowTitle(q->windowTitle()); | - | ||||||||||||||||||
| 560 | options->setHistory(q->history()); | - | ||||||||||||||||||
| 561 | if (usingWidgets()) | - | ||||||||||||||||||
| 562 | options->setSidebarUrls(qFileDialogUi->sidebar->urls()); | - | ||||||||||||||||||
| 563 | if (options->initiallySelectedNameFilter().isEmpty()) | - | ||||||||||||||||||
| 564 | options->setInitiallySelectedNameFilter(q->selectedNameFilter()); | - | ||||||||||||||||||
| 565 | if (options->initiallySelectedFiles().isEmpty()) | - | ||||||||||||||||||
| 566 | options->setInitiallySelectedFiles(userSelectedFiles()); | - | ||||||||||||||||||
| 567 | } | - | ||||||||||||||||||
| 568 | - | |||||||||||||||||||
| 569 | void QFileDialogPrivate::helperDone(QDialog::DialogCode code, QPlatformDialogHelper *) | - | ||||||||||||||||||
| 570 | { | - | ||||||||||||||||||
| 571 | if (code == QDialog::Accepted) { | - | ||||||||||||||||||
| 572 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 573 | q->setViewMode(static_cast<QFileDialog::ViewMode>(options->viewMode())); | - | ||||||||||||||||||
| 574 | q->setSidebarUrls(options->sidebarUrls()); | - | ||||||||||||||||||
| 575 | q->setHistory(options->history()); | - | ||||||||||||||||||
| 576 | } | - | ||||||||||||||||||
| 577 | } | - | ||||||||||||||||||
| 578 | - | |||||||||||||||||||
| 579 | void QFileDialogPrivate::retranslateWindowTitle() | - | ||||||||||||||||||
| 580 | { | - | ||||||||||||||||||
| 581 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 582 | if (!useDefaultCaption || setWindowTitle != q->windowTitle()) | - | ||||||||||||||||||
| 583 | return; | - | ||||||||||||||||||
| 584 | if (q->acceptMode() == QFileDialog::AcceptOpen) { | - | ||||||||||||||||||
| 585 | const QFileDialog::FileMode fileMode = q->fileMode(); | - | ||||||||||||||||||
| 586 | if (fileMode == QFileDialog::DirectoryOnly || fileMode == QFileDialog::Directory) | - | ||||||||||||||||||
| 587 | q->setWindowTitle(QFileDialog::tr("Find Directory")); | - | ||||||||||||||||||
| 588 | else | - | ||||||||||||||||||
| 589 | q->setWindowTitle(QFileDialog::tr("Open")); | - | ||||||||||||||||||
| 590 | } else | - | ||||||||||||||||||
| 591 | q->setWindowTitle(QFileDialog::tr("Save As")); | - | ||||||||||||||||||
| 592 | - | |||||||||||||||||||
| 593 | setWindowTitle = q->windowTitle(); | - | ||||||||||||||||||
| 594 | } | - | ||||||||||||||||||
| 595 | - | |||||||||||||||||||
| 596 | void QFileDialogPrivate::setLastVisitedDirectory(const QUrl &dir) | - | ||||||||||||||||||
| 597 | { | - | ||||||||||||||||||
| 598 | *lastVisitedDir() = dir; | - | ||||||||||||||||||
| 599 | } | - | ||||||||||||||||||
| 600 | - | |||||||||||||||||||
| 601 | void QFileDialogPrivate::updateLookInLabel() | - | ||||||||||||||||||
| 602 | { | - | ||||||||||||||||||
| 603 | if (options->isLabelExplicitlySet(QFileDialogOptions::LookIn)) | - | ||||||||||||||||||
| 604 | setLabelTextControl(QFileDialog::LookIn, options->labelText(QFileDialogOptions::LookIn)); | - | ||||||||||||||||||
| 605 | } | - | ||||||||||||||||||
| 606 | - | |||||||||||||||||||
| 607 | void QFileDialogPrivate::updateFileNameLabel() | - | ||||||||||||||||||
| 608 | { | - | ||||||||||||||||||
| 609 | if (options->isLabelExplicitlySet(QFileDialogOptions::FileName)) { | - | ||||||||||||||||||
| 610 | setLabelTextControl(QFileDialog::FileName, options->labelText(QFileDialogOptions::FileName)); | - | ||||||||||||||||||
| 611 | } else { | - | ||||||||||||||||||
| 612 | switch (q_func()->fileMode()) { | - | ||||||||||||||||||
| 613 | case QFileDialog::DirectoryOnly: | - | ||||||||||||||||||
| 614 | case QFileDialog::Directory: | - | ||||||||||||||||||
| 615 | setLabelTextControl(QFileDialog::FileName, QFileDialog::tr("Directory:")); | - | ||||||||||||||||||
| 616 | break; | - | ||||||||||||||||||
| 617 | default: | - | ||||||||||||||||||
| 618 | setLabelTextControl(QFileDialog::FileName, QFileDialog::tr("File &name:")); | - | ||||||||||||||||||
| 619 | break; | - | ||||||||||||||||||
| 620 | } | - | ||||||||||||||||||
| 621 | } | - | ||||||||||||||||||
| 622 | } | - | ||||||||||||||||||
| 623 | - | |||||||||||||||||||
| 624 | void QFileDialogPrivate::updateFileTypeLabel() | - | ||||||||||||||||||
| 625 | { | - | ||||||||||||||||||
| 626 | if (options->isLabelExplicitlySet(QFileDialogOptions::FileType)) | - | ||||||||||||||||||
| 627 | setLabelTextControl(QFileDialog::FileType, options->labelText(QFileDialogOptions::FileType)); | - | ||||||||||||||||||
| 628 | } | - | ||||||||||||||||||
| 629 | - | |||||||||||||||||||
| 630 | void QFileDialogPrivate::updateOkButtonText(bool saveAsOnFolder) | - | ||||||||||||||||||
| 631 | { | - | ||||||||||||||||||
| 632 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 633 | // 'Save as' at a folder: Temporarily change to "Open". | - | ||||||||||||||||||
| 634 | if (saveAsOnFolder) { | - | ||||||||||||||||||
| 635 | setLabelTextControl(QFileDialog::Accept, QFileDialog::tr("&Open")); | - | ||||||||||||||||||
| 636 | } else if (options->isLabelExplicitlySet(QFileDialogOptions::Accept)) { | - | ||||||||||||||||||
| 637 | setLabelTextControl(QFileDialog::Accept, options->labelText(QFileDialogOptions::Accept)); | - | ||||||||||||||||||
| 638 | return; | - | ||||||||||||||||||
| 639 | } else { | - | ||||||||||||||||||
| 640 | switch (q->fileMode()) { | - | ||||||||||||||||||
| 641 | case QFileDialog::DirectoryOnly: | - | ||||||||||||||||||
| 642 | case QFileDialog::Directory: | - | ||||||||||||||||||
| 643 | setLabelTextControl(QFileDialog::Accept, QFileDialog::tr("&Choose")); | - | ||||||||||||||||||
| 644 | break; | - | ||||||||||||||||||
| 645 | default: | - | ||||||||||||||||||
| 646 | setLabelTextControl(QFileDialog::Accept, | - | ||||||||||||||||||
| 647 | q->acceptMode() == QFileDialog::AcceptOpen ? | - | ||||||||||||||||||
| 648 | QFileDialog::tr("&Open") : | - | ||||||||||||||||||
| 649 | QFileDialog::tr("&Save")); | - | ||||||||||||||||||
| 650 | break; | - | ||||||||||||||||||
| 651 | } | - | ||||||||||||||||||
| 652 | } | - | ||||||||||||||||||
| 653 | } | - | ||||||||||||||||||
| 654 | - | |||||||||||||||||||
| 655 | void QFileDialogPrivate::updateCancelButtonText() | - | ||||||||||||||||||
| 656 | { | - | ||||||||||||||||||
| 657 | if (options->isLabelExplicitlySet(QFileDialogOptions::Reject)) | - | ||||||||||||||||||
| 658 | setLabelTextControl(QFileDialog::Reject, options->labelText(QFileDialogOptions::Reject)); | - | ||||||||||||||||||
| 659 | } | - | ||||||||||||||||||
| 660 | - | |||||||||||||||||||
| 661 | void QFileDialogPrivate::retranslateStrings() | - | ||||||||||||||||||
| 662 | { | - | ||||||||||||||||||
| 663 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 664 | /* WIDGETS */ | - | ||||||||||||||||||
| 665 | if (defaultFileTypes)options->useDefaultNameFilters())
| 0 | ||||||||||||||||||
| 666 | q->setNameFilter(QFileDialogQFileDialogOptions::tr("All Files (*)"));defaultNameFilterString()); never executed: q->setNameFilter(QFileDialogOptions::defaultNameFilterString()); | 0 | ||||||||||||||||||
| 667 | if (!usingWidgets())(nativeDialogInUse)
| 0 | ||||||||||||||||||
| 668 | return; never executed: return; | 0 | ||||||||||||||||||
| 669 | - | |||||||||||||||||||
| 670 | QList<QAction*> actions = qFileDialogUi->treeView->header()->actions(); | - | ||||||||||||||||||
| 671 | QAbstractItemModel *abstractModel = model; | - | ||||||||||||||||||
| 672 | #ifndef QT_NO_PROXYMODEL | - | ||||||||||||||||||
| 673 | if (proxyModel)
| 0 | ||||||||||||||||||
| 674 | abstractModel = proxyModel; never executed: abstractModel = proxyModel; | 0 | ||||||||||||||||||
| 675 | #endif | - | ||||||||||||||||||
| 676 | int total = qMin(abstractModel->columnCount(QModelIndex()), actions.count() + 1); | - | ||||||||||||||||||
| 677 | for (int i = 1; i < total; ++i) {
| 0 | ||||||||||||||||||
| 678 | actions.at(i - 1)->setText(QFileDialog::tr("Show ") + abstractModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); | - | ||||||||||||||||||
| 679 | } never executed: end of block | 0 | ||||||||||||||||||
| 680 | - | |||||||||||||||||||
| 681 | /* MENU ACTIONS */ | - | ||||||||||||||||||
| 682 | renameAction->setText(QFileDialog::tr("&Rename")); | - | ||||||||||||||||||
| 683 | deleteAction->setText(QFileDialog::tr("&Delete")); | - | ||||||||||||||||||
| 684 | showHiddenAction->setText(QFileDialog::tr("Show &hidden files")); | - | ||||||||||||||||||
| 685 | newFolderAction->setText(QFileDialog::tr("&New Folder")); | - | ||||||||||||||||||
| 686 | qFileDialogUi->retranslateUi(q); | - | ||||||||||||||||||
| 687 | updateLookInLabel(); | - | ||||||||||||||||||
| 688 | updateFileNameLabel(); | - | ||||||||||||||||||
| 689 | updateFileTypeLabel(); | - | ||||||||||||||||||
| 690 | updateCancelButtonText(); | - | ||||||||||||||||||
| 691 | } never executed: end of block | 0 | ||||||||||||||||||
| 692 | - | |||||||||||||||||||
| 693 | void QFileDialogPrivate::emitFilesSelected(const QStringList &files) | - | ||||||||||||||||||
| 694 | { | - | ||||||||||||||||||
| 695 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 696 | emit q->filesSelected(files); | - | ||||||||||||||||||
| 697 | if (files.count() == 1) | - | ||||||||||||||||||
| 698 | emit q->fileSelected(files.first()); | - | ||||||||||||||||||
| 699 | } | - | ||||||||||||||||||
| 700 | - | |||||||||||||||||||
| 701 | bool QFileDialogPrivate::canBeNativeDialog() const | - | ||||||||||||||||||
| 702 | { | - | ||||||||||||||||||
| 703 | // Don't use Q_Q here! This function is called from ~QDialog, | - | ||||||||||||||||||
| 704 | // so Q_Q calling q_func() invokes undefined behavior (invalid cast in q_func()). | - | ||||||||||||||||||
| 705 | const QDialog * const q = static_cast<const QDialog*>(q_ptr); | - | ||||||||||||||||||
| 706 | if (nativeDialogInUse)
| 0 | ||||||||||||||||||
| 707 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 708 | if (QCoreApplication::testAttribute(Qt::AA_DontUseNativeDialogs)
| 0 | ||||||||||||||||||
| 709 | ||
| 0 | ||||||||||||||||||
return false;
| ||||||||||||||||||||
if
| ||||||||||||||||||||
| 710 | ||
| 0 | ||||||||||||||||||
| 711 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 712 | } | - | ||||||||||||||||||
| 713 | - | |||||||||||||||||||
| 714 | QLatin1String staticName(QFileDialog::staticMetaObject.className()); | - | ||||||||||||||||||
| 715 | QLatin1String dynamicName(q->metaObject()->className()); | - | ||||||||||||||||||
| 716 | return (staticName == dynamicName); never executed: return (staticName == dynamicName); | 0 | ||||||||||||||||||
| 717 | } | - | ||||||||||||||||||
| 718 | - | |||||||||||||||||||
| 719 | bool QFileDialogPrivate::usingWidgets() const | - | ||||||||||||||||||
| 720 | { | - | ||||||||||||||||||
| 721 | return !nativeDialogInUse && qFileDialogUi; | - | ||||||||||||||||||
| 722 | } | - | ||||||||||||||||||
| 723 | - | |||||||||||||||||||
| 724 | /*! | - | ||||||||||||||||||
| 725 | \since 4.5 | - | ||||||||||||||||||
| 726 | Sets the given \a option to be enabled if \a on is true; otherwise, | - | ||||||||||||||||||
| 727 | clears the given \a option. | - | ||||||||||||||||||
| 728 | - | |||||||||||||||||||
| 729 | \sa options, testOption() | - | ||||||||||||||||||
| 730 | */ | - | ||||||||||||||||||
| 731 | void QFileDialog::setOption(Option option, bool on) | - | ||||||||||||||||||
| 732 | { | - | ||||||||||||||||||
| 733 | const QFileDialog::Options previousOptions = options(); | - | ||||||||||||||||||
| 734 | if (!(previousOptions & option) != !on) | - | ||||||||||||||||||
| 735 | setOptions(previousOptions ^ option); | - | ||||||||||||||||||
| 736 | } | - | ||||||||||||||||||
| 737 | - | |||||||||||||||||||
| 738 | /*! | - | ||||||||||||||||||
| 739 | \since 4.5 | - | ||||||||||||||||||
| 740 | - | |||||||||||||||||||
| 741 | Returns \c true if the given \a option is enabled; otherwise, returns | - | ||||||||||||||||||
| 742 | false. | - | ||||||||||||||||||
| 743 | - | |||||||||||||||||||
| 744 | \sa options, setOption() | - | ||||||||||||||||||
| 745 | */ | - | ||||||||||||||||||
| 746 | bool QFileDialog::testOption(Option option) const | - | ||||||||||||||||||
| 747 | { | - | ||||||||||||||||||
| 748 | Q_D(const QFileDialog); | - | ||||||||||||||||||
| 749 | return d->options->testOption(static_cast<QFileDialogOptions::FileDialogOption>(option)); | - | ||||||||||||||||||
| 750 | } | - | ||||||||||||||||||
| 751 | - | |||||||||||||||||||
| 752 | /*! | - | ||||||||||||||||||
| 753 | \property QFileDialog::options | - | ||||||||||||||||||
| 754 | \brief the various options that affect the look and feel of the dialog | - | ||||||||||||||||||
| 755 | \since 4.5 | - | ||||||||||||||||||
| 756 | - | |||||||||||||||||||
| 757 | By default, all options are disabled. | - | ||||||||||||||||||
| 758 | - | |||||||||||||||||||
| 759 | Options should be set before showing the dialog. Setting them while the | - | ||||||||||||||||||
| 760 | dialog is visible is not guaranteed to have an immediate effect on the | - | ||||||||||||||||||
| 761 | dialog (depending on the option and on the platform). | - | ||||||||||||||||||
| 762 | - | |||||||||||||||||||
| 763 | \sa setOption(), testOption() | - | ||||||||||||||||||
| 764 | */ | - | ||||||||||||||||||
| 765 | void QFileDialog::setOptions(Options options) | - | ||||||||||||||||||
| 766 | { | - | ||||||||||||||||||
| 767 | Q_D(QFileDialog); | - | ||||||||||||||||||
| 768 | - | |||||||||||||||||||
| 769 | Options changed = (options ^ QFileDialog::options()); | - | ||||||||||||||||||
| 770 | if (!changed)
| 0 | ||||||||||||||||||
| 771 | return; never executed: return; | 0 | ||||||||||||||||||
| 772 | - | |||||||||||||||||||
| 773 | d->options->setOptions(QFileDialogOptions::FileDialogOptions(int(options))); | - | ||||||||||||||||||
| 774 | - | |||||||||||||||||||
| 775 | if ((options & DontUseNativeDialog) && !d->usingWidgets())
| 0 | ||||||||||||||||||
| 776 | d->createWidgets(); never executed: d->createWidgets(); | 0 | ||||||||||||||||||
| 777 | - | |||||||||||||||||||
| 778 | if (d->usingWidgets()) {
| 0 | ||||||||||||||||||
| 779 | if (changed & DontResolveSymlinks)
| 0 | ||||||||||||||||||
| 780 | d->model->setResolveSymlinks(!(options & DontResolveSymlinks)); never executed: d->model->setResolveSymlinks(!(options & DontResolveSymlinks)); | 0 | ||||||||||||||||||
| 781 | if (changed & ReadOnly) {
| 0 | ||||||||||||||||||
| 782 | bool ro = (options & ReadOnly); | - | ||||||||||||||||||
| 783 | d->model->setReadOnly(ro); | - | ||||||||||||||||||
| 784 | d->qFileDialogUi->newFolderButton->setEnabled(!ro); | - | ||||||||||||||||||
| 785 | d->renameAction->setEnabled(!ro); | - | ||||||||||||||||||
| 786 | d->deleteAction->setEnabled(!ro); | - | ||||||||||||||||||
| 787 | } never executed: end of block | 0 | ||||||||||||||||||
| 788 | - | |||||||||||||||||||
| 789 | if (changed & DontUseCustomDirectoryIcons) {
| 0 | ||||||||||||||||||
| 790 | QFileIconProvider::Options providerOptions = iconProvider()->options(); | - | ||||||||||||||||||
| 791 | if (options & DontUseCustomDirectoryIcons)providerOptions|=.setFlag(QFileIconProvider::DontUseCustomDirectoryIcons; | - | ||||||||||||||||||
| else | ||||||||||||||||||||
| providerOptions, | ||||||||||||||||||||
| 792 | options & = ~QFileIconProvider::DontUseCustomDirectoryIcons;); | - | ||||||||||||||||||
| 793 | iconProvider()->setOptions(providerOptions); | - | ||||||||||||||||||
| 794 | } never executed: end of block | 0 | ||||||||||||||||||
| 795 | } never executed: end of block | 0 | ||||||||||||||||||
| 796 | - | |||||||||||||||||||
| 797 | if (changed & HideNameFilterDetails)
| 0 | ||||||||||||||||||
| 798 | setNameFilters(d->options->nameFilters()); never executed: setNameFilters(d->options->nameFilters()); | 0 | ||||||||||||||||||
| 799 | - | |||||||||||||||||||
| 800 | if (changed & ShowDirsOnly)
| 0 | ||||||||||||||||||
| 801 | setFilter((options & ShowDirsOnly) ? filter() & ~QDir::Files : filter() | QDir::Files); never executed: setFilter((options & ShowDirsOnly) ? filter() & ~QDir::Files : filter() | QDir::Files); | 0 | ||||||||||||||||||
| 802 | } never executed: end of block | 0 | ||||||||||||||||||
| 803 | - | |||||||||||||||||||
| 804 | QFileDialog::Options QFileDialog::options() const | - | ||||||||||||||||||
| 805 | { | - | ||||||||||||||||||
| 806 | Q_D(const QFileDialog); | - | ||||||||||||||||||
| 807 | return QFileDialog::Options(int(d->options->options())); | - | ||||||||||||||||||
| 808 | } | - | ||||||||||||||||||
| 809 | - | |||||||||||||||||||
| 810 | /*! | - | ||||||||||||||||||
| 811 | \overload | - | ||||||||||||||||||
| 812 | - | |||||||||||||||||||
| 813 | \since 4.5 | - | ||||||||||||||||||
| 814 | - | |||||||||||||||||||
| 815 | This function connects one of its signals to the slot specified by \a receiver | - | ||||||||||||||||||
| 816 | and \a member. The specific signal depends is filesSelected() if fileMode is | - | ||||||||||||||||||
| 817 | ExistingFiles and fileSelected() if fileMode is anything else. | - | ||||||||||||||||||
| 818 | - | |||||||||||||||||||
| 819 | The signal will be disconnected from the slot when the dialog is closed. | - | ||||||||||||||||||
| 820 | */ | - | ||||||||||||||||||
| 821 | void QFileDialog::open(QObject *receiver, const char *member) | - | ||||||||||||||||||
| 822 | { | - | ||||||||||||||||||
| 823 | Q_D(QFileDialog); | - | ||||||||||||||||||
| 824 | const char *signal = (fileMode() == ExistingFiles) ? SIGNAL(filesSelected(QStringList)) | - | ||||||||||||||||||
| 825 | : SIGNAL(fileSelected(QString)); | - | ||||||||||||||||||
| 826 | connect(this, signal, receiver, member); | - | ||||||||||||||||||
| 827 | d->signalToDisconnectOnClose = signal; | - | ||||||||||||||||||
| 828 | d->receiverToDisconnectOnClose = receiver; | - | ||||||||||||||||||
| 829 | d->memberToDisconnectOnClose = member; | - | ||||||||||||||||||
| 830 | - | |||||||||||||||||||
| 831 | QDialog::open(); | - | ||||||||||||||||||
| 832 | } | - | ||||||||||||||||||
| 833 | - | |||||||||||||||||||
| 834 | - | |||||||||||||||||||
| 835 | /*! | - | ||||||||||||||||||
| 836 | \reimp | - | ||||||||||||||||||
| 837 | */ | - | ||||||||||||||||||
| 838 | void QFileDialog::setVisible(bool visible) | - | ||||||||||||||||||
| 839 | { | - | ||||||||||||||||||
| 840 | Q_D(QFileDialog); | - | ||||||||||||||||||
| 841 | if (visible){ | - | ||||||||||||||||||
| 842 | if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden)) | - | ||||||||||||||||||
| 843 | return; | - | ||||||||||||||||||
| 844 | } else if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden)) | - | ||||||||||||||||||
| 845 | return; | - | ||||||||||||||||||
| 846 | - | |||||||||||||||||||
| 847 | if (d->canBeNativeDialog()){ | - | ||||||||||||||||||
| 848 | if (d->setNativeDialogVisible(visible)){ | - | ||||||||||||||||||
| 849 | // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below | - | ||||||||||||||||||
| 850 | // updates the state correctly, but skips showing the non-native version: | - | ||||||||||||||||||
| 851 | setAttribute(Qt::WA_DontShowOnScreen); | - | ||||||||||||||||||
| 852 | #ifndef QT_NO_FSCOMPLETER | - | ||||||||||||||||||
| 853 | // So the completer doesn't try to complete and therefore show a popup | - | ||||||||||||||||||
| 854 | if (!d->nativeDialogInUse) | - | ||||||||||||||||||
| 855 | d->completer->setModel(0); | - | ||||||||||||||||||
| 856 | #endif | - | ||||||||||||||||||
| 857 | } else { | - | ||||||||||||||||||
| 858 | d->createWidgets(); | - | ||||||||||||||||||
| 859 | setAttribute(Qt::WA_DontShowOnScreen, false); | - | ||||||||||||||||||
| 860 | #ifndef QT_NO_FSCOMPLETER | - | ||||||||||||||||||
| 861 | if (!d->nativeDialogInUse) { | - | ||||||||||||||||||
| 862 | if (d->proxyModel != 0) | - | ||||||||||||||||||
| 863 | d->completer->setModel(d->proxyModel); | - | ||||||||||||||||||
| 864 | else | - | ||||||||||||||||||
| 865 | d->completer->setModel(d->model); | - | ||||||||||||||||||
| 866 | } | - | ||||||||||||||||||
| 867 | #endif | - | ||||||||||||||||||
| 868 | } | - | ||||||||||||||||||
| 869 | } | - | ||||||||||||||||||
| 870 | - | |||||||||||||||||||
| 871 | if (d->usingWidgets()) | - | ||||||||||||||||||
| 872 | d->qFileDialogUi->fileNameEdit->setFocus(); | - | ||||||||||||||||||
| 873 | - | |||||||||||||||||||
| 874 | QDialog::setVisible(visible); | - | ||||||||||||||||||
| 875 | } | - | ||||||||||||||||||
| 876 | - | |||||||||||||||||||
| 877 | /*! | - | ||||||||||||||||||
| 878 | \internal | - | ||||||||||||||||||
| 879 | set the directory to url | - | ||||||||||||||||||
| 880 | */ | - | ||||||||||||||||||
| 881 | void QFileDialogPrivate::_q_goToUrl(const QUrl &url) | - | ||||||||||||||||||
| 882 | { | - | ||||||||||||||||||
| 883 | //The shortcut in the side bar may have a parent that is not fetched yet (e.g. an hidden file) | - | ||||||||||||||||||
| 884 | //so we force the fetching | - | ||||||||||||||||||
| 885 | QFileSystemModelPrivate::QFileSystemNode *node = model->d_func()->node(url.toLocalFile(), true); | - | ||||||||||||||||||
| 886 | QModelIndex idx = model->d_func()->index(node); | - | ||||||||||||||||||
| 887 | _q_enterDirectory(idx); | - | ||||||||||||||||||
| 888 | } | - | ||||||||||||||||||
| 889 | - | |||||||||||||||||||
| 890 | /*! | - | ||||||||||||||||||
| 891 | \fn void QFileDialog::setDirectory(const QDir &directory) | - | ||||||||||||||||||
| 892 | - | |||||||||||||||||||
| 893 | \overload | - | ||||||||||||||||||
| 894 | */ | - | ||||||||||||||||||
| 895 | - | |||||||||||||||||||
| 896 | /*! | - | ||||||||||||||||||
| 897 | Sets the file dialog's current \a directory. | - | ||||||||||||||||||
| 898 | - | |||||||||||||||||||
| 899 | \note On iOS, if you set \a directory to \l{QStandardPaths::standardLocations()} | - | ||||||||||||||||||
| 900 | {QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).last()}, | - | ||||||||||||||||||
| 901 | a native image picker dialog will be used for accessing the user's photo album. | - | ||||||||||||||||||
| 902 | The filename returned can be loaded using QFile and related APIs. | - | ||||||||||||||||||
| 903 | For this to be enabled, the Info.plist assigned to QMAKE_INFO_PLIST in the | - | ||||||||||||||||||
| 904 | project file must contain the key \c NSPhotoLibraryUsageDescription. See | - | ||||||||||||||||||
| 905 | Info.plist documentation from Apple for more information regarding this key. | - | ||||||||||||||||||
| 906 | This feature was added in Qt 5.5. | - | ||||||||||||||||||
| 907 | */ | - | ||||||||||||||||||
| 908 | void QFileDialog::setDirectory(const QString &directory) | - | ||||||||||||||||||
| 909 | { | - | ||||||||||||||||||
| 910 | Q_D(QFileDialog); | - | ||||||||||||||||||
| 911 | QString newDirectory = directory; | - | ||||||||||||||||||
| 912 | //we remove .. and . from the given path if exist | - | ||||||||||||||||||
| 913 | if (!directory.isEmpty()) | - | ||||||||||||||||||
| 914 | newDirectory = QDir::cleanPath(directory); | - | ||||||||||||||||||
| 915 | - | |||||||||||||||||||
| 916 | if (!directory.isEmpty() && newDirectory.isEmpty()) | - | ||||||||||||||||||
| 917 | return; | - | ||||||||||||||||||
| 918 | - | |||||||||||||||||||
| 919 | QUrl newDirUrl = QUrl::fromLocalFile(newDirectory); | - | ||||||||||||||||||
| 920 | QFileDialogPrivate::setLastVisitedDirectory(newDirUrl); | - | ||||||||||||||||||
| 921 | - | |||||||||||||||||||
| 922 | d->options->setInitialDirectory(QUrl::fromLocalFile(directory)); | - | ||||||||||||||||||
| 923 | if (!d->usingWidgets()) { | - | ||||||||||||||||||
| 924 | d->setDirectory_sys(newDirUrl); | - | ||||||||||||||||||
| 925 | return; | - | ||||||||||||||||||
| 926 | } | - | ||||||||||||||||||
| 927 | if (d->rootPath() == newDirectory) | - | ||||||||||||||||||
| 928 | return; | - | ||||||||||||||||||
| 929 | QModelIndex root = d->model->setRootPath(newDirectory); | - | ||||||||||||||||||
| 930 | if (!d->nativeDialogInUse) { | - | ||||||||||||||||||
| 931 | d->qFileDialogUi->newFolderButton->setEnabled(d->model->flags(root) & Qt::ItemIsDropEnabled); | - | ||||||||||||||||||
| 932 | if (root != d->rootIndex()) { | - | ||||||||||||||||||
| 933 | #ifndef QT_NO_FSCOMPLETER | - | ||||||||||||||||||
| 934 | if (directory.endsWith(QLatin1Char('/'))) | - | ||||||||||||||||||
| 935 | d->completer->setCompletionPrefix(newDirectory); | - | ||||||||||||||||||
| 936 | else | - | ||||||||||||||||||
| 937 | d->completer->setCompletionPrefix(newDirectory + QLatin1Char('/')); | - | ||||||||||||||||||
| 938 | #endif | - | ||||||||||||||||||
| 939 | d->setRootIndex(root); | - | ||||||||||||||||||
| 940 | } | - | ||||||||||||||||||
| 941 | d->qFileDialogUi->listView->selectionModel()->clear(); | - | ||||||||||||||||||
| 942 | } | - | ||||||||||||||||||
| 943 | } | - | ||||||||||||||||||
| 944 | - | |||||||||||||||||||
| 945 | /*! | - | ||||||||||||||||||
| 946 | Returns the directory currently being displayed in the dialog. | - | ||||||||||||||||||
| 947 | */ | - | ||||||||||||||||||
| 948 | QDir QFileDialog::directory() const | - | ||||||||||||||||||
| 949 | { | - | ||||||||||||||||||
| 950 | Q_D(const QFileDialog); | - | ||||||||||||||||||
| 951 | if (d->nativeDialogInUse) { | - | ||||||||||||||||||
| 952 | QString dir = d->directory_sys().toLocalFile(); | - | ||||||||||||||||||
| 953 | return QDir(dir.isEmpty() ? d->options->initialDirectory().toLocalFile() : dir); | - | ||||||||||||||||||
| 954 | } | - | ||||||||||||||||||
| 955 | return d->rootPath(); | - | ||||||||||||||||||
| 956 | } | - | ||||||||||||||||||
| 957 | - | |||||||||||||||||||
| 958 | /*! | - | ||||||||||||||||||
| 959 | Sets the file dialog's current \a directory url. | - | ||||||||||||||||||
| 960 | - | |||||||||||||||||||
| 961 | \note The non-native QFileDialog supports only local files. | - | ||||||||||||||||||
| 962 | - | |||||||||||||||||||
| 963 | \note On Windows, it is possible to pass URLs representing | - | ||||||||||||||||||
| 964 | one of the \e {virtual folders}, such as "Computer" or "Network". | - | ||||||||||||||||||
| 965 | This is done by passing a QUrl using the scheme \c clsid followed | - | ||||||||||||||||||
| 966 | by the CLSID value with the curly braces removed. For example the URL | - | ||||||||||||||||||
| 967 | \c clsid:374DE290-123F-4565-9164-39C4925E467B denotes the download | - | ||||||||||||||||||
| 968 | location. For a complete list of possible values, see the MSDN documentation on | - | ||||||||||||||||||
| 969 | \l{https://msdn.microsoft.com/en-us/library/windows/desktop/dd378457.aspx}{KNOWNFOLDERID}. | - | ||||||||||||||||||
| 970 | This feature was added in Qt 5.5. | - | ||||||||||||||||||
| 971 | - | |||||||||||||||||||
| 972 | \sa QUuid | - | ||||||||||||||||||
| 973 | \since 5.2 | - | ||||||||||||||||||
| 974 | */ | - | ||||||||||||||||||
| 975 | void QFileDialog::setDirectoryUrl(const QUrl &directory) | - | ||||||||||||||||||
| 976 | { | - | ||||||||||||||||||
| 977 | Q_D(QFileDialog); | - | ||||||||||||||||||
| 978 | if (!directory.isValid())
| 0 | ||||||||||||||||||
| 979 | return; never executed: return; | 0 | ||||||||||||||||||
| 980 | - | |||||||||||||||||||
| 981 | QFileDialogPrivate::setLastVisitedDirectory(directory); | - | ||||||||||||||||||
| 982 | d->options->setInitialDirectory(directory); | - | ||||||||||||||||||
| 983 | - | |||||||||||||||||||
| 984 | if (d->nativeDialogInUse)
| 0 | ||||||||||||||||||
| 985 | d->setDirectory_sys(directory); never executed: d->setDirectory_sys(directory); | 0 | ||||||||||||||||||
| 986 | else if (directory.isLocalFile())
| 0 | ||||||||||||||||||
| 987 | setDirectory(directory.toLocalFile()); never executed: setDirectory(directory.toLocalFile()); | 0 | ||||||||||||||||||
| 988 | else if (Q_UNLIKELY(d->usingWidgets())()))
| 0 | ||||||||||||||||||
| 989 | qWarning("Non-native QFileDialog supports only local files"); never executed: QMessageLogger(__FILE__, 989, __PRETTY_FUNCTION__).warning("Non-native QFileDialog supports only local files"); | 0 | ||||||||||||||||||
| 990 | } never executed: end of block | 0 | ||||||||||||||||||
| 991 | - | |||||||||||||||||||
| 992 | /*! | - | ||||||||||||||||||
| 993 | Returns the url of the directory currently being displayed in the dialog. | - | ||||||||||||||||||
| 994 | - | |||||||||||||||||||
| 995 | \since 5.2 | - | ||||||||||||||||||
| 996 | */ | - | ||||||||||||||||||
| 997 | QUrl QFileDialog::directoryUrl() const | - | ||||||||||||||||||
| 998 | { | - | ||||||||||||||||||
| 999 | Q_D(const QFileDialog); | - | ||||||||||||||||||
| 1000 | if (d->nativeDialogInUse) | - | ||||||||||||||||||
| 1001 | return d->directory_sys(); | - | ||||||||||||||||||
| 1002 | else | - | ||||||||||||||||||
| 1003 | return QUrl::fromLocalFile(directory().absolutePath()); | - | ||||||||||||||||||
| 1004 | } | - | ||||||||||||||||||
| 1005 | - | |||||||||||||||||||
| 1006 | // FIXME Qt 5.4: Use upcoming QVolumeInfo class to determine this information? | - | ||||||||||||||||||
| 1007 | static inline bool isCaseSensitiveFileSystem(const QString &path) | - | ||||||||||||||||||
| 1008 | { | - | ||||||||||||||||||
| 1009 | Q_UNUSED(path) | - | ||||||||||||||||||
| 1010 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||
| 1011 | // Return case insensitive unconditionally, even if someone has a case sensitive | - | ||||||||||||||||||
| 1012 | // file system mounted, wrongly capitalized drive letters will cause mismatches. | - | ||||||||||||||||||
| 1013 | return false; | - | ||||||||||||||||||
| 1014 | #elif defined(Q_OS_OSX) | - | ||||||||||||||||||
| 1015 | return pathconf(QFile::encodeName(path).constData(), _PC_CASE_SENSITIVE); | - | ||||||||||||||||||
| 1016 | #else | - | ||||||||||||||||||
| 1017 | return true; | - | ||||||||||||||||||
| 1018 | #endif | - | ||||||||||||||||||
| 1019 | } | - | ||||||||||||||||||
| 1020 | - | |||||||||||||||||||
| 1021 | // Determine the file name to be set on the line edit from the path | - | ||||||||||||||||||
| 1022 | // passed to selectFile() in mode QFileDialog::AcceptSave. | - | ||||||||||||||||||
| 1023 | static inline QString fileFromPath(const QString &rootPath, QString path) | - | ||||||||||||||||||
| 1024 | { | - | ||||||||||||||||||
| 1025 | if (!QFileInfo(path).isAbsolute()) | - | ||||||||||||||||||
| 1026 | return path; | - | ||||||||||||||||||
| 1027 | if (path.startsWith(rootPath, isCaseSensitiveFileSystem(rootPath) ? Qt::CaseSensitive : Qt::CaseInsensitive)) | - | ||||||||||||||||||
| 1028 | path.remove(0, rootPath.size()); | - | ||||||||||||||||||
| 1029 | - | |||||||||||||||||||
| 1030 | if (path.isEmpty()) | - | ||||||||||||||||||
| 1031 | return path; | - | ||||||||||||||||||
| 1032 | - | |||||||||||||||||||
| 1033 | if (path.at(0) == QDir::separator() | - | ||||||||||||||||||
| 1034 | #ifdef Q_OS_WIN | - | ||||||||||||||||||
| 1035 | //On Windows both cases can happen | - | ||||||||||||||||||
| 1036 | || path.at(0) == QLatin1Char('/') | - | ||||||||||||||||||
| 1037 | #endif | - | ||||||||||||||||||
| 1038 | ) { | - | ||||||||||||||||||
| 1039 | path.remove(0, 1); | - | ||||||||||||||||||
| 1040 | } | - | ||||||||||||||||||
| 1041 | return path; | - | ||||||||||||||||||
| 1042 | } | - | ||||||||||||||||||
| 1043 | - | |||||||||||||||||||
| 1044 | /*! | - | ||||||||||||||||||
| 1045 | Selects the given \a filename in the file dialog. | - | ||||||||||||||||||
| 1046 | - | |||||||||||||||||||
| 1047 | \sa selectedFiles() | - | ||||||||||||||||||
| 1048 | */ | - | ||||||||||||||||||
| 1049 | void QFileDialog::selectFile(const QString &filename) | - | ||||||||||||||||||
| 1050 | { | - | ||||||||||||||||||
| 1051 | Q_D(QFileDialog); | - | ||||||||||||||||||
| 1052 | if (filename.isEmpty()) | - | ||||||||||||||||||
| 1053 | return; | - | ||||||||||||||||||
| 1054 | - | |||||||||||||||||||
| 1055 | if (!d->usingWidgets()) { | - | ||||||||||||||||||
| 1056 | QUrl url = QUrl::fromLocalFile(filename); | - | ||||||||||||||||||
| 1057 | if (QFileInfo(filename).isRelative()) { | - | ||||||||||||||||||
| 1058 | QDir dir(d->options->initialDirectory().toLocalFile()); | - | ||||||||||||||||||
| 1059 | url = QUrl::fromLocalFile(dir.absoluteFilePath(filename)); | - | ||||||||||||||||||
| 1060 | } | - | ||||||||||||||||||
| 1061 | d->selectFile_sys(url); | - | ||||||||||||||||||
| 1062 | d->options->setInitiallySelectedFiles(QList<QUrl>() << url); | - | ||||||||||||||||||
| 1063 | return; | - | ||||||||||||||||||
| 1064 | } | - | ||||||||||||||||||
| 1065 | - | |||||||||||||||||||
| 1066 | if (!QDir::isRelativePath(filename)) { | - | ||||||||||||||||||
| 1067 | QFileInfo info(filename); | - | ||||||||||||||||||
| 1068 | QString filenamePath = info.absoluteDir().path(); | - | ||||||||||||||||||
| 1069 | - | |||||||||||||||||||
| 1070 | if (d->model->rootPath() != filenamePath) | - | ||||||||||||||||||
| 1071 | setDirectory(filenamePath); | - | ||||||||||||||||||
| 1072 | } | - | ||||||||||||||||||
| 1073 | - | |||||||||||||||||||
| 1074 | QModelIndex index = d->model->index(filename); | - | ||||||||||||||||||
| 1075 | d->qFileDialogUi->listView->selectionModel()->clear(); | - | ||||||||||||||||||
| 1076 | if (!isVisible() || !d->lineEdit()->hasFocus()) | - | ||||||||||||||||||
| 1077 | d->lineEdit()->setText(index.isValid() ? index.data().toString() : fileFromPath(d->rootPath(), filename)); | - | ||||||||||||||||||
| 1078 | } | - | ||||||||||||||||||
| 1079 | - | |||||||||||||||||||
| 1080 | /*! | - | ||||||||||||||||||
| 1081 | Selects the given \a url in the file dialog. | - | ||||||||||||||||||
| 1082 | - | |||||||||||||||||||
| 1083 | \note The non-native QFileDialog supports only local files. | - | ||||||||||||||||||
| 1084 | - | |||||||||||||||||||
| 1085 | \sa selectedUrls() | - | ||||||||||||||||||
| 1086 | \since 5.2 | - | ||||||||||||||||||
| 1087 | */ | - | ||||||||||||||||||
| 1088 | void QFileDialog::selectUrl(const QUrl &url) | - | ||||||||||||||||||
| 1089 | { | - | ||||||||||||||||||
| 1090 | Q_D(QFileDialog); | - | ||||||||||||||||||
| 1091 | if (!url.isValid()) | - | ||||||||||||||||||
| 1092 | return; | - | ||||||||||||||||||
| 1093 | - | |||||||||||||||||||
| 1094 | if (d->nativeDialogInUse) | - | ||||||||||||||||||
| 1095 | d->selectFile_sys(url); | - | ||||||||||||||||||
| 1096 | else if (url.isLocalFile()) | - | ||||||||||||||||||
| 1097 | selectFile(url.toLocalFile()); | - | ||||||||||||||||||
| 1098 | else | - | ||||||||||||||||||
| 1099 | qWarning("Non-native QFileDialog supports only local files"); | - | ||||||||||||||||||
| 1100 | } | - | ||||||||||||||||||
| 1101 | - | |||||||||||||||||||
| 1102 | #ifdef Q_OS_UNIX | - | ||||||||||||||||||
| 1103 | Q_AUTOTEST_EXPORT QString qt_tildeExpansion(const QString &path, bool *expanded = 0) | - | ||||||||||||||||||
| 1104 | { | - | ||||||||||||||||||
| 1105 | if (expanded != 0)
| 0 | ||||||||||||||||||
*expanded = false;
| ||||||||||||||||||||
| 1106 | return path; never executed: return path; | 0 | ||||||||||||||||||
| 1107 | QString retint separatorPosition = path; | - | ||||||||||||||||||
| QStringList tokens = ret.splitindexOf(QDir::separator()); | ||||||||||||||||||||
| 1108 | if (tokens.first() == QLatin1String("~")) {
| 0 | ||||||||||||||||||
ret
| ||||||||||||||||||||
| 1109 | separatorPosition = path never executed: .replacesize();separatorPosition = path.size();never executed: separatorPosition = path.size(); | 0 | ||||||||||||||||||
| 1110 | if
| 0 | ||||||||||||||||||
| 1111 | return never executed: QDir::homePath());return QDir::homePath() + path.midRef(1);never executed: return QDir::homePath() + path.midRef(1); | 0 | ||||||||||||||||||
| } else { never executed: return QDir::homePath() + path.midRef(1); | ||||||||||||||||||||
| QString userName = tokens.first(); never executed: return QDir::homePath() + path.midRef(1); | ||||||||||||||||||||
| userName never executed: () + path.removemidRef(0,1);return QDir::homePath() + path.midRef(1);never executed: return QDir::homePath() + path.midRef(1); | ||||||||||||||||||||
| 1112 | } else { | - | ||||||||||||||||||
| 1113 | #if defined(Q_OS_VXWORKS) || defined(Q_OS_INTEGRITY) | - | ||||||||||||||||||
| 1114 | const QString homePath = QDir::homePath(); | - | ||||||||||||||||||
| #elif#else | ||||||||||||||||||||
| 1116 | const QByteArray userName = path.midRef(1, separatorPosition - 1).toLocal8Bit(); | - | ||||||||||||||||||
| 1117 | # if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) | - | ||||||||||||||||||
| 1118 | passwd pw; | - | ||||||||||||||||||
| 1119 | passwd *tmpPw; | - | ||||||||||||||||||
| 1120 | char buf[200]; | - | ||||||||||||||||||
| 1121 | const int bufSize = sizeof(buf); | - | ||||||||||||||||||
| 1122 | int err = 0; | - | ||||||||||||||||||
| #if# if defined(Q_OS_SOLARIS) && (_POSIX_C_SOURCE - 0 < 199506L) | ||||||||||||||||||||
| 1124 | tmpPw = getpwnam_r(userName.toLocal8Bit().constData(), &pw, buf, bufSize); | - | ||||||||||||||||||
| #else# else | ||||||||||||||||||||
| 1126 | err = getpwnam_r(userName.toLocal8Bit().constData(), &pw, buf, bufSize, &tmpPw); | - | ||||||||||||||||||
| #endif# endif | ||||||||||||||||||||
| 1128 | if (err || !tmpPw)
| 0 | ||||||||||||||||||
| 1129 | return retpath; never executed: return path; | 0 | ||||||||||||||||||
| 1130 | const QString homePath = QString::fromLocal8Bit(pw.pw_dir); | - | ||||||||||||||||||
| #else# else | ||||||||||||||||||||
| 1132 | passwd *pw = getpwnam(userName.toLocal8Bit().constData()); | - | ||||||||||||||||||
| 1133 | if (!pw) | - | ||||||||||||||||||
| 1134 | return retpath; | - | ||||||||||||||||||
| 1135 | const QString homePath = QString::fromLocal8Bit(pw->pw_dir); | - | ||||||||||||||||||
| 1136 | # endif | - | ||||||||||||||||||
| 1137 | #endif | - | ||||||||||||||||||
| 1138 | retreturn homePath + path.replacemidRef(0, tokens.first().length(), homePathseparatorPosition); never executed: return homePath + path.midRef(separatorPosition); | 0 | ||||||||||||||||||
| 1139 | } | - | ||||||||||||||||||
| if (expanded != 0) | ||||||||||||||||||||
| *expanded = true; | ||||||||||||||||||||
| return ret;} | ||||||||||||||||||||
| 1141 | #endif | - | ||||||||||||||||||
| 1142 | - | |||||||||||||||||||
| 1143 | /** | - | ||||||||||||||||||
| 1144 | Returns the text in the line edit which can be one or more file names | - | ||||||||||||||||||
| 1145 | */ | - | ||||||||||||||||||
| 1146 | QStringList QFileDialogPrivate::typedFiles() const | - | ||||||||||||||||||
| 1147 | { | - | ||||||||||||||||||
| 1148 | Q_Q(const QFileDialog); | - | ||||||||||||||||||
| 1149 | QStringList files; | - | ||||||||||||||||||
| 1150 | QString editText = lineEdit()->text(); | - | ||||||||||||||||||
| 1151 | if (!editText.contains(QLatin1Char('"'))) { | - | ||||||||||||||||||
| 1152 | #ifdef Q_OS_UNIX | - | ||||||||||||||||||
| 1153 | const QString prefix = q->directory().absolutePath() + QDir::separator(); | - | ||||||||||||||||||
| 1154 | if (QFile::exists(prefix + editText)) | - | ||||||||||||||||||
| 1155 | files << editText; | - | ||||||||||||||||||
| 1156 | else | - | ||||||||||||||||||
| 1157 | files << qt_tildeExpansion(editText); | - | ||||||||||||||||||
| 1158 | #else | - | ||||||||||||||||||
| 1159 | files << editText; | - | ||||||||||||||||||
| 1160 | Q_UNUSED(q) | - | ||||||||||||||||||
| 1161 | #endif | - | ||||||||||||||||||
| 1162 | } else { | - | ||||||||||||||||||
| 1163 | // " is used to separate files like so: "file1" "file2" "file3" ... | - | ||||||||||||||||||
| 1164 | // ### need escape character for filenames with quotes (") | - | ||||||||||||||||||
| 1165 | QStringList tokens = editText.split(QLatin1Char('\"')); | - | ||||||||||||||||||
| 1166 | for (int i=0; i<tokens.size(); ++i) { | - | ||||||||||||||||||
| 1167 | if ((i % 2) == 0) | - | ||||||||||||||||||
| 1168 | continue; // Every even token is a separator | - | ||||||||||||||||||
| 1169 | #ifdef Q_OS_UNIX | - | ||||||||||||||||||
| 1170 | const QString token = tokens.at(i); | - | ||||||||||||||||||
| 1171 | const QString prefix = q->directory().absolutePath() + QDir::separator(); | - | ||||||||||||||||||
| 1172 | if (QFile::exists(prefix + token)) | - | ||||||||||||||||||
| 1173 | files << token; | - | ||||||||||||||||||
| 1174 | else | - | ||||||||||||||||||
| 1175 | files << qt_tildeExpansion(token); | - | ||||||||||||||||||
| 1176 | #else | - | ||||||||||||||||||
| 1177 | files << toInternal(tokens.at(i)); | - | ||||||||||||||||||
| 1178 | #endif | - | ||||||||||||||||||
| 1179 | } | - | ||||||||||||||||||
| 1180 | } | - | ||||||||||||||||||
| 1181 | return addDefaultSuffixToFiles(files); | - | ||||||||||||||||||
| 1182 | } | - | ||||||||||||||||||
| 1183 | - | |||||||||||||||||||
| 1184 | // Return selected files without defaulting to the root of the file system model | - | ||||||||||||||||||
| 1185 | // used for initializing QFileDialogOptions for native dialogs. The default is | - | ||||||||||||||||||
| 1186 | // not suitable for native dialogs since it mostly equals directory(). | - | ||||||||||||||||||
| 1187 | QList<QUrl> QFileDialogPrivate::userSelectedFiles() const | - | ||||||||||||||||||
| 1188 | { | - | ||||||||||||||||||
| 1189 | QList<QUrl> files; | - | ||||||||||||||||||
| 1190 | - | |||||||||||||||||||
| 1191 | if (!usingWidgets())
| 0 | ||||||||||||||||||
| 1192 | return addDefaultSuffixToUrls(selectedFiles_sys()); never executed: return addDefaultSuffixToUrls(selectedFiles_sys()); | 0 | ||||||||||||||||||
| 1193 | - | |||||||||||||||||||
| 1194 | const QModelIndexList selectedRows = qFileDialogUi->listView->selectionModel()->selectedRows(); | - | ||||||||||||||||||
| 1195 | files.reserve(selectedRows.size()); | - | ||||||||||||||||||
| 1196 | foreachfor (const QModelIndex &index ,: selectedRows) | - | ||||||||||||||||||
| 1197 | files.append(QUrl::fromLocalFile(index.data(QFileSystemModel::FilePathRole).toString())); never executed: files.append(QUrl::fromLocalFile(index.data(QFileSystemModel::FilePathRole).toString())); | 0 | ||||||||||||||||||
| 1198 | - | |||||||||||||||||||
| 1199 | if (files.isEmpty() && !lineEdit()->text().isEmpty()) {
| 0 | ||||||||||||||||||
| 1200 | const QStringList typedFilesList = typedFiles(); | - | ||||||||||||||||||
| 1201 | files.reserve(typedFilesList.size()); | - | ||||||||||||||||||
| 1202 | foreachfor (const QString &path ,: typedFilesList) | - | ||||||||||||||||||
| 1203 | files.append(QUrl::fromLocalFile(path)); never executed: files.append(QUrl::fromLocalFile(path)); | 0 | ||||||||||||||||||
| 1204 | } never executed: end of block | 0 | ||||||||||||||||||
| 1205 | - | |||||||||||||||||||
| 1206 | return files; never executed: return files; | 0 | ||||||||||||||||||
| 1207 | } | - | ||||||||||||||||||
| 1208 | - | |||||||||||||||||||
| 1209 | QStringList QFileDialogPrivate::addDefaultSuffixToFiles(const QStringList &filesToFix) const | - | ||||||||||||||||||
| 1210 | { | - | ||||||||||||||||||
| 1211 | QStringList files; | - | ||||||||||||||||||
| 1212 | for (int i=0; i<filesToFix.size(); ++i) { | - | ||||||||||||||||||
| 1213 | QString name = toInternal(filesToFix.at(i)); | - | ||||||||||||||||||
| 1214 | QFileInfo info(name); | - | ||||||||||||||||||
| 1215 | // if the filename has no suffix, add the default suffix | - | ||||||||||||||||||
| 1216 | const QString defaultSuffix = options->defaultSuffix(); | - | ||||||||||||||||||
| 1217 | if (!defaultSuffix.isEmpty() && !info.isDir() && name.lastIndexOf(QLatin1Char('.')) == -1) | - | ||||||||||||||||||
| 1218 | name += QLatin1Char('.') + defaultSuffix; | - | ||||||||||||||||||
| 1219 | if (info.isAbsolute()) { | - | ||||||||||||||||||
| 1220 | files.append(name); | - | ||||||||||||||||||
| 1221 | } else { | - | ||||||||||||||||||
| 1222 | // at this point the path should only have Qt path separators. | - | ||||||||||||||||||
| 1223 | // This check is needed since we might be at the root directory | - | ||||||||||||||||||
| 1224 | // and on Windows it already ends with slash. | - | ||||||||||||||||||
| 1225 | QString path = rootPath(); | - | ||||||||||||||||||
| 1226 | if (!path.endsWith(QLatin1Char('/'))) | - | ||||||||||||||||||
| 1227 | path += QLatin1Char('/'); | - | ||||||||||||||||||
| 1228 | path += name; | - | ||||||||||||||||||
| 1229 | files.append(path); | - | ||||||||||||||||||
| 1230 | } | - | ||||||||||||||||||
| 1231 | } | - | ||||||||||||||||||
| 1232 | return files; | - | ||||||||||||||||||
| 1233 | } | - | ||||||||||||||||||
| 1234 | - | |||||||||||||||||||
| 1235 | QList<QUrl> QFileDialogPrivate::addDefaultSuffixToUrls(const QList<QUrl> &urlsToFix) const | - | ||||||||||||||||||
| 1236 | { | - | ||||||||||||||||||
| 1237 | QList<QUrl> urls; | - | ||||||||||||||||||
| 1238 | const int numUrlsToFix = urlsToFix.size(); | - | ||||||||||||||||||
| 1239 | urls.reserve(numUrlsToFix); | - | ||||||||||||||||||
| 1240 | for (int i = 0; i < numUrlsToFix; ++i) { | - | ||||||||||||||||||
| 1241 | QUrl url = urlsToFix.at(i); | - | ||||||||||||||||||
| 1242 | // if the filename has no suffix, add the default suffix | - | ||||||||||||||||||
| 1243 | const QString defaultSuffix = options->defaultSuffix(); | - | ||||||||||||||||||
| 1244 | if (!defaultSuffix.isEmpty() && !url.path().endsWith(QLatin1Char('/')) && url.path().lastIndexOf(QLatin1Char('.')) == -1) | - | ||||||||||||||||||
| 1245 | url.setPath(url.path() + QLatin1Char('.') + defaultSuffix); | - | ||||||||||||||||||
| 1246 | urls.append(url); | - | ||||||||||||||||||
| 1247 | } | - | ||||||||||||||||||
| 1248 | return urls; | - | ||||||||||||||||||
| 1249 | } | - | ||||||||||||||||||
| 1250 | - | |||||||||||||||||||
| 1251 | - | |||||||||||||||||||
| 1252 | /*! | - | ||||||||||||||||||
| 1253 | Returns a list of strings containing the absolute paths of the | - | ||||||||||||||||||
| 1254 | selected files in the dialog. If no files are selected, or | - | ||||||||||||||||||
| 1255 | the mode is not ExistingFiles or ExistingFile, selectedFiles() contains the current path in the viewport. | - | ||||||||||||||||||
| 1256 | - | |||||||||||||||||||
| 1257 | \sa selectedNameFilter(), selectFile() | - | ||||||||||||||||||
| 1258 | */ | - | ||||||||||||||||||
| 1259 | QStringList QFileDialog::selectedFiles() const | - | ||||||||||||||||||
| 1260 | { | - | ||||||||||||||||||
| 1261 | Q_D(const QFileDialog); | - | ||||||||||||||||||
| 1262 | - | |||||||||||||||||||
| 1263 | QStringList files; | - | ||||||||||||||||||
| 1264 | const QList<QUrl> userSelectedFiles = d->userSelectedFiles(); | - | ||||||||||||||||||
| 1265 | files.reserve(userSelectedFiles.size()); | - | ||||||||||||||||||
| 1266 | foreachfor (const QUrl &file ,: userSelectedFiles) | - | ||||||||||||||||||
| 1267 | files.append(file.toLocalFile()); never executed: files.append(file.toLocalFile()); | 0 | ||||||||||||||||||
| 1268 | if (files.isEmpty() && d->usingWidgets()) {
| 0 | ||||||||||||||||||
| 1269 | const FileMode fm = fileMode(); | - | ||||||||||||||||||
| 1270 | if (fm != ExistingFile && fm != ExistingFiles)
| 0 | ||||||||||||||||||
| 1271 | files.append(d->rootIndex().data(QFileSystemModel::FilePathRole).toString()); never executed: files.append(d->rootIndex().data(QFileSystemModel::FilePathRole).toString()); | 0 | ||||||||||||||||||
| 1272 | } never executed: end of block | 0 | ||||||||||||||||||
| 1273 | return files; never executed: return files; | 0 | ||||||||||||||||||
| 1274 | } | - | ||||||||||||||||||
| 1275 | - | |||||||||||||||||||
| 1276 | /*! | - | ||||||||||||||||||
| 1277 | Returns a list of urls containing the selected files in the dialog. | - | ||||||||||||||||||
| 1278 | If no files are selected, or the mode is not ExistingFiles or | - | ||||||||||||||||||
| 1279 | ExistingFile, selectedUrls() contains the current path in the viewport. | - | ||||||||||||||||||
| 1280 | - | |||||||||||||||||||
| 1281 | \sa selectedNameFilter(), selectUrl() | - | ||||||||||||||||||
| 1282 | \since 5.2 | - | ||||||||||||||||||
| 1283 | */ | - | ||||||||||||||||||
| 1284 | QList<QUrl> QFileDialog::selectedUrls() const | - | ||||||||||||||||||
| 1285 | { | - | ||||||||||||||||||
| 1286 | Q_D(const QFileDialog); | - | ||||||||||||||||||
| 1287 | if (d->nativeDialogInUse) {
| 0 | ||||||||||||||||||
| 1288 | return d->userSelectedFiles(); never executed: return d->userSelectedFiles(); | 0 | ||||||||||||||||||
| 1289 | } else { | - | ||||||||||||||||||
| 1290 | QList<QUrl> urls; | - | ||||||||||||||||||
| 1291 | const QStringList selectedFileList = selectedFiles(); | - | ||||||||||||||||||
| 1292 | urls.reserve(selectedFileList.size()); | - | ||||||||||||||||||
| 1293 | foreachfor (const QString &file ,: selectedFileList) | - | ||||||||||||||||||
| 1294 | urls.append(QUrl::fromLocalFile(file)); never executed: urls.append(QUrl::fromLocalFile(file)); | 0 | ||||||||||||||||||
| 1295 | return urls; never executed: return urls; | 0 | ||||||||||||||||||
| 1296 | } | - | ||||||||||||||||||
| 1297 | } | - | ||||||||||||||||||
| 1298 | - | |||||||||||||||||||
| 1299 | /* | - | ||||||||||||||||||
| 1300 | Makes a list of filters from ;;-separated text. | - | ||||||||||||||||||
| 1301 | Used by the mac and windows implementations | - | ||||||||||||||||||
| 1302 | */ | - | ||||||||||||||||||
| 1303 | QStringList qt_make_filter_list(const QString &filter) | - | ||||||||||||||||||
| 1304 | { | - | ||||||||||||||||||
| 1305 | QString f(filter); | - | ||||||||||||||||||
| 1306 | - | |||||||||||||||||||
| 1307 | if (f.isEmpty()) | - | ||||||||||||||||||
| 1308 | return QStringList(); | - | ||||||||||||||||||
| 1309 | - | |||||||||||||||||||
| 1310 | QString sep(QLatin1String(";;")); | - | ||||||||||||||||||
| 1311 | int i = f.indexOf(sep, 0); | - | ||||||||||||||||||
| 1312 | if (i == -1) { | - | ||||||||||||||||||
| 1313 | if (f.indexOf(QLatin1Char('\n'), 0) != -1) { | - | ||||||||||||||||||
| 1314 | sep = QLatin1Char('\n'); | - | ||||||||||||||||||
| 1315 | i = f.indexOf(sep, 0); | - | ||||||||||||||||||
| 1316 | } | - | ||||||||||||||||||
| 1317 | } | - | ||||||||||||||||||
| 1318 | - | |||||||||||||||||||
| 1319 | return f.split(sep); | - | ||||||||||||||||||
| 1320 | } | - | ||||||||||||||||||
| 1321 | - | |||||||||||||||||||
| 1322 | /*! | - | ||||||||||||||||||
| 1323 | \since 4.4 | - | ||||||||||||||||||
| 1324 | - | |||||||||||||||||||
| 1325 | Sets the filter used in the file dialog to the given \a filter. | - | ||||||||||||||||||
| 1326 | - | |||||||||||||||||||
| 1327 | If \a filter contains a pair of parentheses containing one or more | - | ||||||||||||||||||
| 1328 | filename-wildcard patterns, separated by spaces, then only the | - | ||||||||||||||||||
| 1329 | text contained in the parentheses is used as the filter. This means | - | ||||||||||||||||||
| 1330 | that these calls are all equivalent: | - | ||||||||||||||||||
| 1331 | - | |||||||||||||||||||
| 1332 | \snippet code/src_gui_dialogs_qfiledialog.cpp 6 | - | ||||||||||||||||||
| 1333 | - | |||||||||||||||||||
| 1334 | \sa setMimeTypeFilters(), setNameFilters() | - | ||||||||||||||||||
| 1335 | */ | - | ||||||||||||||||||
| 1336 | void QFileDialog::setNameFilter(const QString &filter) | - | ||||||||||||||||||
| 1337 | { | - | ||||||||||||||||||
| 1338 | setNameFilters(qt_make_filter_list(filter)); | - | ||||||||||||||||||
| 1339 | } | - | ||||||||||||||||||
| 1340 | - | |||||||||||||||||||
| 1341 | - | |||||||||||||||||||
| 1342 | /*! | - | ||||||||||||||||||
| 1343 | \property QFileDialog::nameFilterDetailsVisible | - | ||||||||||||||||||
| 1344 | \obsolete | - | ||||||||||||||||||
| 1345 | \brief This property holds whether the filter details is shown or not. | - | ||||||||||||||||||
| 1346 | \since 4.4 | - | ||||||||||||||||||
| 1347 | - | |||||||||||||||||||
| 1348 | When this property is \c true (the default), the filter details are shown | - | ||||||||||||||||||
| 1349 | in the combo box. When the property is set to false, these are hidden. | - | ||||||||||||||||||
| 1350 | - | |||||||||||||||||||
| 1351 | Use setOption(HideNameFilterDetails, !\e enabled) or | - | ||||||||||||||||||
| 1352 | !testOption(HideNameFilterDetails). | - | ||||||||||||||||||
| 1353 | */ | - | ||||||||||||||||||
| 1354 | void QFileDialog::setNameFilterDetailsVisible(bool enabled) | - | ||||||||||||||||||
| 1355 | { | - | ||||||||||||||||||
| 1356 | setOption(HideNameFilterDetails, !enabled); | - | ||||||||||||||||||
| 1357 | } | - | ||||||||||||||||||
| 1358 | - | |||||||||||||||||||
| 1359 | bool QFileDialog::isNameFilterDetailsVisible() const | - | ||||||||||||||||||
| 1360 | { | - | ||||||||||||||||||
| 1361 | return !testOption(HideNameFilterDetails); | - | ||||||||||||||||||
| 1362 | } | - | ||||||||||||||||||
| 1363 | - | |||||||||||||||||||
| 1364 | - | |||||||||||||||||||
| 1365 | /* | - | ||||||||||||||||||
| 1366 | Strip the filters by removing the details, e.g. (*.*). | - | ||||||||||||||||||
| 1367 | */ | - | ||||||||||||||||||
| 1368 | QStringList qt_strip_filters(const QStringList &filters) | - | ||||||||||||||||||
| 1369 | { | - | ||||||||||||||||||
| 1370 | QStringList strippedFilters; | - | ||||||||||||||||||
| 1371 | QRegExp r(QString::fromLatin1(QPlatformFileDialogHelper::filterRegExp)); | - | ||||||||||||||||||
| 1372 | const int numFilters = filters.count(); | - | ||||||||||||||||||
| 1373 | strippedFilters.reserve(numFilters); | - | ||||||||||||||||||
| 1374 | for (int i = 0; i < numFilters; ++i) { | - | ||||||||||||||||||
| 1375 | QString filterName; | - | ||||||||||||||||||
| 1376 | int index = r.indexIn(filters[i]); | - | ||||||||||||||||||
| 1377 | if (index >= 0) | - | ||||||||||||||||||
| 1378 | filterName = r.cap(1); | - | ||||||||||||||||||
| 1379 | strippedFilters.append(filterName.simplified()); | - | ||||||||||||||||||
| 1380 | } | - | ||||||||||||||||||
| 1381 | return strippedFilters; | - | ||||||||||||||||||
| 1382 | } | - | ||||||||||||||||||
| 1383 | - | |||||||||||||||||||
| 1384 | - | |||||||||||||||||||
| 1385 | /*! | - | ||||||||||||||||||
| 1386 | \since 4.4 | - | ||||||||||||||||||
| 1387 | - | |||||||||||||||||||
| 1388 | Sets the \a filters used in the file dialog. | - | ||||||||||||||||||
| 1389 | - | |||||||||||||||||||
| 1390 | Note that the filter \b{*.*} is not portable, because the historical | - | ||||||||||||||||||
| 1391 | assumption that the file extension determines the file type is not | - | ||||||||||||||||||
| 1392 | consistent on every operating system. It is possible to have a file with no | - | ||||||||||||||||||
| 1393 | dot in its name (for example, \c Makefile). In a native Windows file | - | ||||||||||||||||||
| 1394 | dialog, \b{*.*} will match such files, while in other types of file dialogs | - | ||||||||||||||||||
| 1395 | it may not. So it is better to use \b{*} if you mean to select any file. | - | ||||||||||||||||||
| 1396 | - | |||||||||||||||||||
| 1397 | \snippet code/src_gui_dialogs_qfiledialog.cpp 7 | - | ||||||||||||||||||
| 1398 | - | |||||||||||||||||||
| 1399 | \l setMimeTypeFilters() has the advantage of providing all possible name | - | ||||||||||||||||||
| 1400 | filters for each file type. For example, JPEG images have three possible | - | ||||||||||||||||||
| 1401 | extensions; if your application can open such files, selecting the | - | ||||||||||||||||||
| 1402 | \c image/jpeg mime type as a filter will allow you to open all of them. | - | ||||||||||||||||||
| 1403 | */ | - | ||||||||||||||||||
| 1404 | void QFileDialog::setNameFilters(const QStringList &filters) | - | ||||||||||||||||||
| 1405 | { | - | ||||||||||||||||||
| 1406 | Q_D(QFileDialog); | - | ||||||||||||||||||
| 1407 | d->defaultFileTypes = (filters == QStringList(QFileDialog::tr("All Files (*)")));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(); | - | ||||||||||||||||||
| 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()) { | - | ||||||||||||||||||
| 1454 | d->selectNameFilter_sys(filter); | - | ||||||||||||||||||
| 1455 | return; | - | ||||||||||||||||||
| 1456 | } | - | ||||||||||||||||||
| 1457 | int i = -1; | - | ||||||||||||||||||
| 1458 | if (testOption(HideNameFilterDetails)) { | - | ||||||||||||||||||
| 1459 | const QStringList filters = qt_strip_filters(qt_make_filter_list(filter)); | - | ||||||||||||||||||
| 1460 | if (!filters.isEmpty()) | - | ||||||||||||||||||
| 1461 | i = d->qFileDialogUi->fileTypeCombo->findText(filters.first()); | - | ||||||||||||||||||
| 1462 | } else { | - | ||||||||||||||||||
| 1463 | i = d->qFileDialogUi->fileTypeCombo->findText(filter); | - | ||||||||||||||||||
| 1464 | } | - | ||||||||||||||||||
| 1465 | if (i >= 0) { | - | ||||||||||||||||||
| 1466 | d->qFileDialogUi->fileTypeCombo->setCurrentIndex(i); | - | ||||||||||||||||||
| 1467 | d->_q_useNameFilter(d->qFileDialogUi->fileTypeCombo->currentIndex()); | - | ||||||||||||||||||
| 1468 | } | - | ||||||||||||||||||
| 1469 | } | - | ||||||||||||||||||
| 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()) | - | ||||||||||||||||||
| 1482 | return d->selectedNameFilter_sys(); | - | ||||||||||||||||||
| 1483 | - | |||||||||||||||||||
| 1484 | return d->qFileDialogUi->fileTypeCombo->currentText(); | - | ||||||||||||||||||
| 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()) | - | ||||||||||||||||||
| 1498 | return d->model->filter(); | - | ||||||||||||||||||
| 1499 | return d->options->filter(); | - | ||||||||||||||||||
| 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()) { | - | ||||||||||||||||||
| 1516 | d->setFilter_sys(); | - | ||||||||||||||||||
| 1517 | return; | - | ||||||||||||||||||
| 1518 | } | - | ||||||||||||||||||
| 1519 | - | |||||||||||||||||||
| 1520 | d->model->setFilter(filters); | - | ||||||||||||||||||
| 1521 | d->showHiddenAction->setChecked((filters & QDir::Hidden)); | - | ||||||||||||||||||
| 1522 | } | - | ||||||||||||||||||
| 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() + QStringLiteralQLatin1String(" (") + patterns + QLatin1Char(')'); never executed: return mime.comment() + QLatin1String(" (") + patterns + QLatin1Char(')'); | 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 | foreachfor (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(); | - | ||||||||||||||||||
| 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()) | - | ||||||||||||||||||
| 1592 | selectNameFilter(text); | - | ||||||||||||||||||
| 1593 | } | - | ||||||||||||||||||
| 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()) | - | ||||||||||||||||||
| 1611 | return; | - | ||||||||||||||||||
| 1612 | if (mode == Detail) | - | ||||||||||||||||||
| 1613 | d->_q_showDetailsView(); | - | ||||||||||||||||||
| 1614 | else | - | ||||||||||||||||||
| 1615 | d->_q_showListView(); | - | ||||||||||||||||||
| 1616 | } | - | ||||||||||||||||||
| 1617 | - | |||||||||||||||||||
| 1618 | QFileDialog::ViewMode QFileDialog::viewMode() const | - | ||||||||||||||||||
| 1619 | { | - | ||||||||||||||||||
| 1620 | Q_D(const QFileDialog); | - | ||||||||||||||||||
| 1621 | if (!d->usingWidgets()) | - | ||||||||||||||||||
| 1622 | return static_cast<QFileDialog::ViewMode>(d->options->viewMode()); | - | ||||||||||||||||||
| 1623 | return (d->qFileDialogUi->stackedWidget->currentWidget() == d->qFileDialogUi->listView->parent() ? QFileDialog::List : QFileDialog::Detail); | - | ||||||||||||||||||
| 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()) | - | ||||||||||||||||||
| 1650 | return; | - | ||||||||||||||||||
| 1651 | - | |||||||||||||||||||
| 1652 | d->retranslateWindowTitle(); | - | ||||||||||||||||||
| 1653 | - | |||||||||||||||||||
| 1654 | // set selection mode and behavior | - | ||||||||||||||||||
| 1655 | QAbstractItemView::SelectionMode selectionMode; | - | ||||||||||||||||||
| 1656 | if (mode == QFileDialog::ExistingFiles) | - | ||||||||||||||||||
| 1657 | selectionMode = QAbstractItemView::ExtendedSelection; | - | ||||||||||||||||||
| 1658 | else | - | ||||||||||||||||||
| 1659 | selectionMode = QAbstractItemView::SingleSelection; | - | ||||||||||||||||||
| 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) { | - | ||||||||||||||||||
| 1666 | d->qFileDialogUi->fileTypeCombo->clear(); | - | ||||||||||||||||||
| 1667 | d->qFileDialogUi->fileTypeCombo->addItem(tr("Directories")); | - | ||||||||||||||||||
| 1668 | d->qFileDialogUi->fileTypeCombo->setEnabled(false); | - | ||||||||||||||||||
| 1669 | } | - | ||||||||||||||||||
| 1670 | d->updateFileNameLabel(); | - | ||||||||||||||||||
| 1671 | d->updateOkButtonText(); | - | ||||||||||||||||||
| 1672 | d->qFileDialogUi->fileTypeCombo->setEnabled(!testOption(ShowDirsOnly)); | - | ||||||||||||||||||
| 1673 | d->_q_updateOkButton(); | - | ||||||||||||||||||
| 1674 | } | - | ||||||||||||||||||
| 1675 | - | |||||||||||||||||||
| 1676 | QFileDialog::FileMode QFileDialog::fileMode() const | - | ||||||||||||||||||
| 1677 | { | - | ||||||||||||||||||
| 1678 | Q_D(const QFileDialog); | - | ||||||||||||||||||
| 1679 | return static_cast<FileMode>(d->options->fileMode()); | - | ||||||||||||||||||
| 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()) | - | ||||||||||||||||||
| 1699 | return; | - | ||||||||||||||||||
| 1700 | QDialogButtonBox::StandardButton button = (mode == AcceptOpen ? QDialogButtonBox::Open : QDialogButtonBox::Save); | - | ||||||||||||||||||
| 1701 | d->qFileDialogUi->buttonBox->setStandardButtons(button | QDialogButtonBox::Cancel); | - | ||||||||||||||||||
| 1702 | d->qFileDialogUi->buttonBox->button(button)->setEnabled(false); | - | ||||||||||||||||||
| 1703 | d->_q_updateOkButton(); | - | ||||||||||||||||||
| 1704 | if (mode == AcceptSave) { | - | ||||||||||||||||||
| 1705 | d->qFileDialogUi->lookInCombo->setEditable(false); | - | ||||||||||||||||||
| 1706 | } | - | ||||||||||||||||||
| 1707 | d->retranslateWindowTitle(); | - | ||||||||||||||||||
| 1708 | } | - | ||||||||||||||||||
| 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 | } | - | ||||||||||||||||||
| 1728 | - | |||||||||||||||||||
| 1729 | QStringList QFileDialog::supportedSchemes() const | - | ||||||||||||||||||
| 1730 | { | - | ||||||||||||||||||
| 1731 | return d_func()->options->supportedSchemes(); | - | ||||||||||||||||||
| 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()); | - | ||||||||||||||||||
| 1740 | } | - | ||||||||||||||||||
| 1741 | - | |||||||||||||||||||
| 1742 | QAbstractItemView *QFileDialogPrivate::currentView() const { | - | ||||||||||||||||||
| 1743 | if (!qFileDialogUi->stackedWidget) | - | ||||||||||||||||||
| 1744 | return 0; | - | ||||||||||||||||||
| 1745 | if (qFileDialogUi->stackedWidget->currentWidget() == qFileDialogUi->listView->parent()) | - | ||||||||||||||||||
| 1746 | return qFileDialogUi->listView; | - | ||||||||||||||||||
| 1747 | return qFileDialogUi->treeView; | - | ||||||||||||||||||
| 1748 | } | - | ||||||||||||||||||
| 1749 | - | |||||||||||||||||||
| 1750 | QLineEdit *QFileDialogPrivate::lineEdit() const { | - | ||||||||||||||||||
| 1751 | return (QLineEdit*)qFileDialogUi->fileNameEdit; | - | ||||||||||||||||||
| 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); | - | ||||||||||||||||||
| 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 | } | - | ||||||||||||||||||
| 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)) | - | ||||||||||||||||||
| 1791 | qFileDialogUi->listView->selectionModel()->select(idx, | - | ||||||||||||||||||
| 1792 | QItemSelectionModel::Select | QItemSelectionModel::Rows); | - | ||||||||||||||||||
| 1793 | return idx; | - | ||||||||||||||||||
| 1794 | } | - | ||||||||||||||||||
| 1795 | - | |||||||||||||||||||
| 1796 | QFileDialog::AcceptMode QFileDialog::acceptMode() const | - | ||||||||||||||||||
| 1797 | { | - | ||||||||||||||||||
| 1798 | Q_D(const QFileDialog); | - | ||||||||||||||||||
| 1799 | return static_cast<AcceptMode>(d->options->acceptMode()); | - | ||||||||||||||||||
| 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 | } | - | ||||||||||||||||||
| 1816 | - | |||||||||||||||||||
| 1817 | bool QFileDialog::isReadOnly() const | - | ||||||||||||||||||
| 1818 | { | - | ||||||||||||||||||
| 1819 | return testOption(ReadOnly); | - | ||||||||||||||||||
| 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 | } | - | ||||||||||||||||||
| 1837 | - | |||||||||||||||||||
| 1838 | bool QFileDialog::resolveSymlinks() const | - | ||||||||||||||||||
| 1839 | { | - | ||||||||||||||||||
| 1840 | return !testOption(DontResolveSymlinks); | - | ||||||||||||||||||
| 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 | } | - | ||||||||||||||||||
| 1856 | - | |||||||||||||||||||
| 1857 | bool QFileDialog::confirmOverwrite() const | - | ||||||||||||||||||
| 1858 | { | - | ||||||||||||||||||
| 1859 | return !testOption(DontConfirmOverwrite); | - | ||||||||||||||||||
| 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 | } | - | ||||||||||||||||||
| 1878 | - | |||||||||||||||||||
| 1879 | QString QFileDialog::defaultSuffix() const | - | ||||||||||||||||||
| 1880 | { | - | ||||||||||||||||||
| 1881 | Q_D(const QFileDialog); | - | ||||||||||||||||||
| 1882 | return d->options->defaultSuffix(); | - | ||||||||||||||||||
| 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()) | - | ||||||||||||||||||
| 1893 | d->qFileDialogUi->lookInCombo->setHistory(paths); | - | ||||||||||||||||||
| 1894 | } | - | ||||||||||||||||||
| 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()) | - | ||||||||||||||||||
| 1905 | list.append(url); | - | ||||||||||||||||||
| 1906 | urlModel->setUrls(list); | - | ||||||||||||||||||
| 1907 | } | - | ||||||||||||||||||
| 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()) | - | ||||||||||||||||||
| 1916 | return QStringList(); | - | ||||||||||||||||||
| 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)) | - | ||||||||||||||||||
| 1921 | currentHistory << newHistory; | - | ||||||||||||||||||
| 1922 | return currentHistory; | - | ||||||||||||||||||
| 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()) | - | ||||||||||||||||||
| 1944 | return; | - | ||||||||||||||||||
| 1945 | d->qFileDialogUi->listView->setItemDelegate(delegate); | - | ||||||||||||||||||
| 1946 | d->qFileDialogUi->treeView->setItemDelegate(delegate); | - | ||||||||||||||||||
| 1947 | } | - | ||||||||||||||||||
| 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()) | - | ||||||||||||||||||
| 1956 | return 0; | - | ||||||||||||||||||
| 1957 | return d->qFileDialogUi->listView->itemDelegate(); | - | ||||||||||||||||||
| 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()) | - | ||||||||||||||||||
| 1967 | return; | - | ||||||||||||||||||
| 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 | } | - | ||||||||||||||||||
| 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) | - | ||||||||||||||||||
| 1980 | return Q_NULLPTR; | - | ||||||||||||||||||
| 1981 | return d->model->iconProvider(); | - | ||||||||||||||||||
| 1982 | } | - | ||||||||||||||||||
| 1983 | - | |||||||||||||||||||
| 1984 | void QFileDialogPrivate::setLabelTextControl(QFileDialog::DialogLabel label, const QString &text) | - | ||||||||||||||||||
| 1985 | { | - | ||||||||||||||||||
| 1986 | if (!qFileDialogUi) | - | ||||||||||||||||||
| 1987 | return; | - | ||||||||||||||||||
| 1988 | switch (label) { | - | ||||||||||||||||||
| 1989 | case QFileDialog::LookIn: | - | ||||||||||||||||||
| 1990 | qFileDialogUi->lookInLabel->setText(text); | - | ||||||||||||||||||
| 1991 | break; | - | ||||||||||||||||||
| 1992 | case QFileDialog::FileName: | - | ||||||||||||||||||
| 1993 | qFileDialogUi->fileNameLabel->setText(text); | - | ||||||||||||||||||
| 1994 | break; | - | ||||||||||||||||||
| 1995 | case QFileDialog::FileType: | - | ||||||||||||||||||
| 1996 | qFileDialogUi->fileTypeLabel->setText(text); | - | ||||||||||||||||||
| 1997 | break; | - | ||||||||||||||||||
| 1998 | case QFileDialog::Accept: | - | ||||||||||||||||||
| 1999 | if (q_func()->acceptMode() == QFileDialog::AcceptOpen) { | - | ||||||||||||||||||
| 2000 | if (QPushButton *button = qFileDialogUi->buttonBox->button(QDialogButtonBox::Open)) | - | ||||||||||||||||||
| 2001 | button->setText(text); | - | ||||||||||||||||||
| 2002 | } else { | - | ||||||||||||||||||
| 2003 | if (QPushButton *button = qFileDialogUi->buttonBox->button(QDialogButtonBox::Save)) | - | ||||||||||||||||||
| 2004 | button->setText(text); | - | ||||||||||||||||||
| 2005 | } | - | ||||||||||||||||||
| 2006 | break; | - | ||||||||||||||||||
| 2007 | case QFileDialog::Reject: | - | ||||||||||||||||||
| 2008 | if (QPushButton *button = qFileDialogUi->buttonBox->button(QDialogButtonBox::Cancel)) | - | ||||||||||||||||||
| 2009 | button->setText(text); | - | ||||||||||||||||||
| 2010 | break; | - | ||||||||||||||||||
| 2011 | } | - | ||||||||||||||||||
| 2012 | } | - | ||||||||||||||||||
| 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 | } | - | ||||||||||||||||||
| 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()) | - | ||||||||||||||||||
| 2032 | return d->options->labelText(static_cast<QFileDialogOptions::DialogLabel>(label)); | - | ||||||||||||||||||
| 2033 | QPushButton *button; | - | ||||||||||||||||||
| 2034 | switch (label) { | - | ||||||||||||||||||
| 2035 | case LookIn: | - | ||||||||||||||||||
| 2036 | return d->qFileDialogUi->lookInLabel->text(); | - | ||||||||||||||||||
| 2037 | case FileName: | - | ||||||||||||||||||
| 2038 | return d->qFileDialogUi->fileNameLabel->text(); | - | ||||||||||||||||||
| 2039 | case FileType: | - | ||||||||||||||||||
| 2040 | return d->qFileDialogUi->fileTypeLabel->text(); | - | ||||||||||||||||||
| 2041 | case Accept: | - | ||||||||||||||||||
| 2042 | if (acceptMode() == AcceptOpen) | - | ||||||||||||||||||
| 2043 | button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Open); | - | ||||||||||||||||||
| 2044 | else | - | ||||||||||||||||||
| 2045 | button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Save); | - | ||||||||||||||||||
| 2046 | if (button) | - | ||||||||||||||||||
| 2047 | return button->text(); | - | ||||||||||||||||||
| 2048 | break; | - | ||||||||||||||||||
| 2049 | case Reject: | - | ||||||||||||||||||
| 2050 | button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Cancel); | - | ||||||||||||||||||
| 2051 | if (button) | - | ||||||||||||||||||
| 2052 | return button->text(); | - | ||||||||||||||||||
| 2053 | break; | - | ||||||||||||||||||
| 2054 | } | - | ||||||||||||||||||
| 2055 | return QString(); | - | ||||||||||||||||||
| 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")); | - | ||||||||||||||||||
| 2113 | const QUrl selectedUrl = getOpenFileUrl(parent, caption, QUrl::fromLocalFile(dir), filter, selectedFilter, options, schemes); | - | ||||||||||||||||||
| 2114 | return selectedUrl.toLocalFile(); | - | ||||||||||||||||||
| 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()) | - | ||||||||||||||||||
| 2164 | dialog.selectNameFilter(*selectedFilter); | - | ||||||||||||||||||
| 2165 | if (dialog.exec() == QDialog::Accepted) { | - | ||||||||||||||||||
| 2166 | if (selectedFilter) | - | ||||||||||||||||||
| 2167 | *selectedFilter = dialog.selectedNameFilter(); | - | ||||||||||||||||||
| 2168 | return dialog.selectedUrls().value(0); | - | ||||||||||||||||||
| 2169 | } | - | ||||||||||||||||||
| 2170 | return QUrl(); | - | ||||||||||||||||||
| 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")); | - | ||||||||||||||||||
| 2225 | const QList<QUrl> selectedUrls = getOpenFileUrls(parent, caption, QUrl::fromLocalFile(dir), filter, selectedFilter, options, schemes); | - | ||||||||||||||||||
| 2226 | QStringList fileNames; | - | ||||||||||||||||||
| 2227 | fileNames.reserve(selectedUrls.size()); | - | ||||||||||||||||||
| 2228 | foreachfor (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()) | - | ||||||||||||||||||
| 2281 | dialog.selectNameFilter(*selectedFilter); | - | ||||||||||||||||||
| 2282 | if (dialog.exec() == QDialog::Accepted) { | - | ||||||||||||||||||
| 2283 | if (selectedFilter) | - | ||||||||||||||||||
| 2284 | *selectedFilter = dialog.selectedNameFilter(); | - | ||||||||||||||||||
| 2285 | return dialog.selectedUrls(); | - | ||||||||||||||||||
| 2286 | } | - | ||||||||||||||||||
| 2287 | return QList<QUrl>(); | - | ||||||||||||||||||
| 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")); | - | ||||||||||||||||||
| 2348 | const QUrl selectedUrl = getSaveFileUrl(parent, caption, QUrl::fromLocalFile(dir), filter, selectedFilter, options, schemes); | - | ||||||||||||||||||
| 2349 | return selectedUrl.toLocalFile(); | - | ||||||||||||||||||
| 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()) | - | ||||||||||||||||||
| 2400 | dialog.selectNameFilter(*selectedFilter); | - | ||||||||||||||||||
| 2401 | if (dialog.exec() == QDialog::Accepted) { | - | ||||||||||||||||||
| 2402 | if (selectedFilter) | - | ||||||||||||||||||
| 2403 | *selectedFilter = dialog.selectedNameFilter(); | - | ||||||||||||||||||
| 2404 | return dialog.selectedUrls().value(0); | - | ||||||||||||||||||
| 2405 | } | - | ||||||||||||||||||
| 2406 | return QUrl(); | - | ||||||||||||||||||
| 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. | - | ||||||||||||||||||
| 2433 | - | |||||||||||||||||||
| 2434 | On Unix/X11, the normal behavior of the file dialog is to resolve and | - | ||||||||||||||||||
| 2435 | follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp}, | - | ||||||||||||||||||
| 2436 | the file dialog will change to \c{/var/tmp} after entering \c{/usr/tmp}. If | - | ||||||||||||||||||
| 2437 | \a options includes DontResolveSymlinks, the file dialog will treat | - | ||||||||||||||||||
| 2438 | symlinks as regular directories. | - | ||||||||||||||||||
| 2439 | - | |||||||||||||||||||
| 2440 | On Windows, the dialog will spin a blocking modal event loop that will not | - | ||||||||||||||||||
| 2441 | dispatch any QTimers, and if \a parent is not 0 then it will position the | - | ||||||||||||||||||
| 2442 | dialog just below the parent's title bar. | - | ||||||||||||||||||
| 2443 | - | |||||||||||||||||||
| 2444 | \warning Do not delete \a parent during the execution of the dialog. If you | - | ||||||||||||||||||
| 2445 | want to do this, you should create the dialog yourself using one of the | - | ||||||||||||||||||
| 2446 | QFileDialog constructors. | - | ||||||||||||||||||
| 2447 | - | |||||||||||||||||||
| 2448 | \sa getOpenFileName(), getOpenFileNames(), getSaveFileName() | - | ||||||||||||||||||
| 2449 | */ | - | ||||||||||||||||||
| 2450 | QString QFileDialog::getExistingDirectory(QWidget *parent, | - | ||||||||||||||||||
| 2451 | const QString &caption, | - | ||||||||||||||||||
| 2452 | const QString &dir, | - | ||||||||||||||||||
| 2453 | Options options) | - | ||||||||||||||||||
| 2454 | { | - | ||||||||||||||||||
| 2455 | const QStringList schemes = QStringList(QStringLiteral("file")); | - | ||||||||||||||||||
| 2456 | const QUrl selectedUrl = getExistingDirectoryUrl(parent, caption, QUrl::fromLocalFile(dir), options, schemes); | - | ||||||||||||||||||
| 2457 | return selectedUrl.toLocalFile(); | - | ||||||||||||||||||
| 2458 | } | - | ||||||||||||||||||
| 2459 | - | |||||||||||||||||||
| 2460 | /*! | - | ||||||||||||||||||
| 2461 | This is a convenience static function that will return an existing | - | ||||||||||||||||||
| 2462 | directory selected by the user. If the user presses Cancel, it | - | ||||||||||||||||||
| 2463 | returns an empty url. | - | ||||||||||||||||||
| 2464 | - | |||||||||||||||||||
| 2465 | The function is used similarly to QFileDialog::getExistingDirectory(). | - | ||||||||||||||||||
| 2466 | In particular \a parent, \a caption, \a dir and \a options are used | - | ||||||||||||||||||
| 2467 | in the exact same way. | - | ||||||||||||||||||
| 2468 | - | |||||||||||||||||||
| 2469 | The main difference with QFileDialog::getExistingDirectory() comes from | - | ||||||||||||||||||
| 2470 | the ability offered to the user to select a remote directory. That's why | - | ||||||||||||||||||
| 2471 | the return type and the type of \a dir is QUrl. | - | ||||||||||||||||||
| 2472 | - | |||||||||||||||||||
| 2473 | The \a supportedSchemes argument allows to restrict the type of URLs the | - | ||||||||||||||||||
| 2474 | user will be able to select. It is a way for the application to declare | - | ||||||||||||||||||
| 2475 | the protocols it will support to fetch the file content. An empty list | - | ||||||||||||||||||
| 2476 | means that no restriction is applied (the default). | - | ||||||||||||||||||
| 2477 | Supported for local files ("file" scheme) is implicit and always enabled; | - | ||||||||||||||||||
| 2478 | it is not necessary to include it in the restriction. | - | ||||||||||||||||||
| 2479 | - | |||||||||||||||||||
| 2480 | When possible, this static function will use the native file dialog and | - | ||||||||||||||||||
| 2481 | not a QFileDialog. On platforms which don't support selecting remote | - | ||||||||||||||||||
| 2482 | files, Qt will allow to select only local files. | - | ||||||||||||||||||
| 2483 | - | |||||||||||||||||||
| 2484 | \sa getExistingDirectory(), getOpenFileUrl(), getOpenFileUrls(), getSaveFileUrl() | - | ||||||||||||||||||
| 2485 | \since 5.2 | - | ||||||||||||||||||
| 2486 | */ | - | ||||||||||||||||||
| 2487 | QUrl QFileDialog::getExistingDirectoryUrl(QWidget *parent, | - | ||||||||||||||||||
| 2488 | const QString &caption, | - | ||||||||||||||||||
| 2489 | const QUrl &dir, | - | ||||||||||||||||||
| 2490 | Options options, | - | ||||||||||||||||||
| 2491 | const QStringList &supportedSchemes) | - | ||||||||||||||||||
| 2492 | { | - | ||||||||||||||||||
| 2493 | QFileDialogArgs args; | - | ||||||||||||||||||
| 2494 | args.parent = parent; | - | ||||||||||||||||||
| 2495 | args.caption = caption; | - | ||||||||||||||||||
| 2496 | args.directory = QFileDialogPrivate::workingDirectory(dir); | - | ||||||||||||||||||
| 2497 | args.mode = (options & ShowDirsOnly ? DirectoryOnly : Directory); | - | ||||||||||||||||||
| 2498 | args.options = options; | - | ||||||||||||||||||
| 2499 | - | |||||||||||||||||||
| 2500 | QFileDialog dialog(args); | - | ||||||||||||||||||
| 2501 | dialog.setSupportedSchemes(supportedSchemes); | - | ||||||||||||||||||
| 2502 | if (dialog.exec() == QDialog::Accepted) | - | ||||||||||||||||||
| 2503 | return dialog.selectedUrls().value(0); | - | ||||||||||||||||||
| 2504 | return QUrl(); | - | ||||||||||||||||||
| 2505 | } | - | ||||||||||||||||||
| 2506 | - | |||||||||||||||||||
| 2507 | inline static QUrl _qt_get_directory(const QUrl &url) | - | ||||||||||||||||||
| 2508 | { | - | ||||||||||||||||||
| 2509 | if (url.isLocalFile()) { | - | ||||||||||||||||||
| 2510 | QFileInfo info = QFileInfo(QDir::current(), url.toLocalFile()); | - | ||||||||||||||||||
| 2511 | if (info.exists() && info.isDir()) | - | ||||||||||||||||||
| 2512 | return QUrl::fromLocalFile(QDir::cleanPath(info.absoluteFilePath())); | - | ||||||||||||||||||
| 2513 | info.setFile(info.absolutePath()); | - | ||||||||||||||||||
| 2514 | if (info.exists() && info.isDir()) | - | ||||||||||||||||||
| 2515 | return QUrl::fromLocalFile(info.absoluteFilePath()); | - | ||||||||||||||||||
| 2516 | return QUrl(); | - | ||||||||||||||||||
| 2517 | } else { | - | ||||||||||||||||||
| 2518 | return url; | - | ||||||||||||||||||
| 2519 | } | - | ||||||||||||||||||
| 2520 | } | - | ||||||||||||||||||
| 2521 | /* | - | ||||||||||||||||||
| 2522 | Get the initial directory URL | - | ||||||||||||||||||
| 2523 | - | |||||||||||||||||||
| 2524 | \sa initialSelection() | - | ||||||||||||||||||
| 2525 | */ | - | ||||||||||||||||||
| 2526 | QUrl QFileDialogPrivate::workingDirectory(const QUrl &url) | - | ||||||||||||||||||
| 2527 | { | - | ||||||||||||||||||
| 2528 | if (!url.isEmpty()) { | - | ||||||||||||||||||
| 2529 | QUrl directory = _qt_get_directory(url); | - | ||||||||||||||||||
| 2530 | if (!directory.isEmpty()) | - | ||||||||||||||||||
| 2531 | return directory; | - | ||||||||||||||||||
| 2532 | } | - | ||||||||||||||||||
| 2533 | QUrl directory = _qt_get_directory(*lastVisitedDir()); | - | ||||||||||||||||||
| 2534 | if (!directory.isEmpty()) | - | ||||||||||||||||||
| 2535 | return directory; | - | ||||||||||||||||||
| 2536 | return QUrl::fromLocalFile(QDir::currentPath()); | - | ||||||||||||||||||
| 2537 | } | - | ||||||||||||||||||
| 2538 | - | |||||||||||||||||||
| 2539 | /* | - | ||||||||||||||||||
| 2540 | Get the initial selection given a path. The initial directory | - | ||||||||||||||||||
| 2541 | can contain both the initial directory and initial selection | - | ||||||||||||||||||
| 2542 | /home/user/foo.txt | - | ||||||||||||||||||
| 2543 | - | |||||||||||||||||||
| 2544 | \sa workingDirectory() | - | ||||||||||||||||||
| 2545 | */ | - | ||||||||||||||||||
| 2546 | QString QFileDialogPrivate::initialSelection(const QUrl &url) | - | ||||||||||||||||||
| 2547 | { | - | ||||||||||||||||||
| 2548 | if (url.isEmpty()) | - | ||||||||||||||||||
| 2549 | return QString(); | - | ||||||||||||||||||
| 2550 | if (url.isLocalFile()) { | - | ||||||||||||||||||
| 2551 | QFileInfo info(url.toLocalFile()); | - | ||||||||||||||||||
| 2552 | if (!info.isDir()) | - | ||||||||||||||||||
| 2553 | return info.fileName(); | - | ||||||||||||||||||
| 2554 | else | - | ||||||||||||||||||
| 2555 | return QString(); | - | ||||||||||||||||||
| 2556 | } | - | ||||||||||||||||||
| 2557 | // With remote URLs we can only assume. | - | ||||||||||||||||||
| 2558 | return url.fileName(); | - | ||||||||||||||||||
| 2559 | } | - | ||||||||||||||||||
| 2560 | - | |||||||||||||||||||
| 2561 | /*! | - | ||||||||||||||||||
| 2562 | \reimp | - | ||||||||||||||||||
| 2563 | */ | - | ||||||||||||||||||
| 2564 | void QFileDialog::done(int result) | - | ||||||||||||||||||
| 2565 | { | - | ||||||||||||||||||
| 2566 | Q_D(QFileDialog); | - | ||||||||||||||||||
| 2567 | - | |||||||||||||||||||
| 2568 | QDialog::done(result); | - | ||||||||||||||||||
| 2569 | - | |||||||||||||||||||
| 2570 | if (d->receiverToDisconnectOnClose) { | - | ||||||||||||||||||
| 2571 | disconnect(this, d->signalToDisconnectOnClose, | - | ||||||||||||||||||
| 2572 | d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose); | - | ||||||||||||||||||
| 2573 | d->receiverToDisconnectOnClose = 0; | - | ||||||||||||||||||
| 2574 | } | - | ||||||||||||||||||
| 2575 | d->memberToDisconnectOnClose.clear(); | - | ||||||||||||||||||
| 2576 | d->signalToDisconnectOnClose.clear(); | - | ||||||||||||||||||
| 2577 | } | - | ||||||||||||||||||
| 2578 | - | |||||||||||||||||||
| 2579 | /*! | - | ||||||||||||||||||
| 2580 | \reimp | - | ||||||||||||||||||
| 2581 | */ | - | ||||||||||||||||||
| 2582 | void QFileDialog::accept() | - | ||||||||||||||||||
| 2583 | { | - | ||||||||||||||||||
| 2584 | Q_D(QFileDialog); | - | ||||||||||||||||||
| 2585 | if (!d->usingWidgets()) {
| 0 | ||||||||||||||||||
| 2586 | const QList<QUrl> urls = selectedUrls(); | - | ||||||||||||||||||
| 2587 | if (urls.isEmpty())
| 0 | ||||||||||||||||||
| 2588 | return; never executed: return; | 0 | ||||||||||||||||||
| 2589 | d->_q_emitUrlsSelected(urls); | - | ||||||||||||||||||
| 2590 | if (urls.count() == 1)
| 0 | ||||||||||||||||||
| 2591 | d->_q_emitUrlSelected(urls.first()); never executed: d->_q_emitUrlSelected(urls.first()); | 0 | ||||||||||||||||||
| 2592 | QDialog::accept(); | - | ||||||||||||||||||
| 2593 | return; never executed: return; | 0 | ||||||||||||||||||
| 2594 | } | - | ||||||||||||||||||
| 2595 | - | |||||||||||||||||||
| 2596 | const QStringList files = selectedFiles(); | - | ||||||||||||||||||
| 2597 | if (files.isEmpty())
| 0 | ||||||||||||||||||
| 2598 | return; never executed: return; | 0 | ||||||||||||||||||
| 2599 | QString lineEditText = d->lineEdit()->text(); | - | ||||||||||||||||||
| 2600 | // "hidden feature" type .. and then enter, and it will move up a dir | - | ||||||||||||||||||
| 2601 | // special case for ".." | - | ||||||||||||||||||
| 2602 | if (lineEditText == QLatin1String("..")) {
| 0 | ||||||||||||||||||
| 2603 | d->_q_navigateToParent(); | - | ||||||||||||||||||
| 2604 | const QSignalBlocker blocker(d->qFileDialogUi->fileNameEdit); | - | ||||||||||||||||||
| 2605 | d->lineEdit()->selectAll(); | - | ||||||||||||||||||
| 2606 | return; never executed: return; | 0 | ||||||||||||||||||
| 2607 | } | - | ||||||||||||||||||
| 2608 | - | |||||||||||||||||||
| 2609 | switch (fileMode()) { | - | ||||||||||||||||||
| 2610 | case DirectoryOnly: never executed: case DirectoryOnly: | 0 | ||||||||||||||||||
| 2611 | case Directory: { never executed: case Directory: | 0 | ||||||||||||||||||
| 2612 | QString fn = files.first(); | - | ||||||||||||||||||
| 2613 | QFileInfo info(fn); | - | ||||||||||||||||||
| 2614 | if (!info.exists())
| 0 | ||||||||||||||||||
| 2615 | info = QFileInfo(d->getEnvironmentVariable(fn)); never executed: info = QFileInfo(d->getEnvironmentVariable(fn)); | 0 | ||||||||||||||||||
| 2616 | if (!info.exists()) {
| 0 | ||||||||||||||||||
| 2617 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||||||||
| 2618 | QString message = tr("%1\nDirectory not found.\nPlease verify the " | - | ||||||||||||||||||
| 2619 | "correct directory name was given."); | - | ||||||||||||||||||
| 2620 | QMessageBox::warning(this, windowTitle(), message.arg(info.fileName())); | - | ||||||||||||||||||
| 2621 | #endif // QT_NO_MESSAGEBOX | - | ||||||||||||||||||
| 2622 | return; never executed: return; | 0 | ||||||||||||||||||
| 2623 | } | - | ||||||||||||||||||
| 2624 | if (info.isDir()) {
| 0 | ||||||||||||||||||
| 2625 | d->emitFilesSelected(files); | - | ||||||||||||||||||
| 2626 | QDialog::accept(); | - | ||||||||||||||||||
| 2627 | } never executed: end of block | 0 | ||||||||||||||||||
| 2628 | return; never executed: return; | 0 | ||||||||||||||||||
| 2629 | } | - | ||||||||||||||||||
| 2630 | - | |||||||||||||||||||
| 2631 | case AnyFile: { never executed: case AnyFile: | 0 | ||||||||||||||||||
| 2632 | QString fn = files.first(); | - | ||||||||||||||||||
| 2633 | QFileInfo info(fn); | - | ||||||||||||||||||
| 2634 | if (info.isDir()) {
| 0 | ||||||||||||||||||
| 2635 | setDirectory(info.absoluteFilePath()); | - | ||||||||||||||||||
| 2636 | return; never executed: return; | 0 | ||||||||||||||||||
| 2637 | } | - | ||||||||||||||||||
| 2638 | - | |||||||||||||||||||
| 2639 | if (!info.exists()) {
| 0 | ||||||||||||||||||
| 2640 | int maxNameLength = d->maxNameLength(info.path()); | - | ||||||||||||||||||
| 2641 | if (maxNameLength >= 0 && info.fileName().length() > maxNameLength)
| 0 | ||||||||||||||||||
| 2642 | return; never executed: return; | 0 | ||||||||||||||||||
| 2643 | } never executed: end of block | 0 | ||||||||||||||||||
| 2644 | - | |||||||||||||||||||
| 2645 | // check if we have to ask for permission to overwrite the file | - | ||||||||||||||||||
| 2646 | if (!info.exists() || !confirmOverwrite() || acceptMode() == AcceptOpen) {
| 0 | ||||||||||||||||||
| 2647 | d->emitFilesSelected(QStringList(fn)); | - | ||||||||||||||||||
| 2648 | QDialog::accept(); | - | ||||||||||||||||||
| 2649 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||||||||
| 2650 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2651 | if (QMessageBox::warning(this, windowTitle(),
| 0 | ||||||||||||||||||
| 2652 | tr("%1 already exists.\nDo you want to replace it?")
| 0 | ||||||||||||||||||
| 2653 | .arg(info.fileName()),
| 0 | ||||||||||||||||||
| 2654 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
| 0 | ||||||||||||||||||
| 2655 | == QMessageBox::Yes) {
| 0 | ||||||||||||||||||
| 2656 | d->emitFilesSelected(QStringList(fn)); | - | ||||||||||||||||||
| 2657 | QDialog::accept(); | - | ||||||||||||||||||
| 2658 | } never executed: end of block | 0 | ||||||||||||||||||
| 2659 | #endif | - | ||||||||||||||||||
| 2660 | } never executed: end of block | 0 | ||||||||||||||||||
| 2661 | return; never executed: return; | 0 | ||||||||||||||||||
| 2662 | } | - | ||||||||||||||||||
| 2663 | - | |||||||||||||||||||
| 2664 | case ExistingFile: never executed: case ExistingFile: | 0 | ||||||||||||||||||
| 2665 | case ExistingFiles: never executed: case ExistingFiles: | 0 | ||||||||||||||||||
| 2666 | for (int i = 0; i <const auto &file : files.count(); ++i) { | - | ||||||||||||||||||
| 2667 | QFileInfo info(files.at(i));file); | - | ||||||||||||||||||
| 2668 | if (!info.exists())
| 0 | ||||||||||||||||||
| 2669 | info = QFileInfo(d->getEnvironmentVariable(files.at(i)));file)); never executed: info = QFileInfo(d->getEnvironmentVariable(file)); | 0 | ||||||||||||||||||
| 2670 | if (!info.exists()) {
| 0 | ||||||||||||||||||
| 2671 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||||||||
| 2672 | QString message = tr("%1\nFile not found.\nPlease verify the " | - | ||||||||||||||||||
| 2673 | "correct file name was given."); | - | ||||||||||||||||||
| 2674 | QMessageBox::warning(this, windowTitle(), message.arg(info.fileName())); | - | ||||||||||||||||||
| 2675 | #endif // QT_NO_MESSAGEBOX | - | ||||||||||||||||||
| 2676 | return; never executed: return; | 0 | ||||||||||||||||||
| 2677 | } | - | ||||||||||||||||||
| 2678 | if (info.isDir()) {
| 0 | ||||||||||||||||||
| 2679 | setDirectory(info.absoluteFilePath()); | - | ||||||||||||||||||
| 2680 | d->lineEdit()->clear(); | - | ||||||||||||||||||
| 2681 | return; never executed: return; | 0 | ||||||||||||||||||
| 2682 | } | - | ||||||||||||||||||
| 2683 | } never executed: end of block | 0 | ||||||||||||||||||
| 2684 | d->emitFilesSelected(files); | - | ||||||||||||||||||
| 2685 | QDialog::accept(); | - | ||||||||||||||||||
| 2686 | return; never executed: return; | 0 | ||||||||||||||||||
| 2687 | } | - | ||||||||||||||||||
| 2688 | } never executed: end of block | 0 | ||||||||||||||||||
| 2689 | - | |||||||||||||||||||
| 2690 | #ifndef QT_NO_SETTINGS | - | ||||||||||||||||||
| 2691 | void QFileDialogPrivate::saveSettings() | - | ||||||||||||||||||
| 2692 | { | - | ||||||||||||||||||
| 2693 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 2694 | QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); | - | ||||||||||||||||||
| 2695 | settings.beginGroup(QLatin1String("FileDialog")); | - | ||||||||||||||||||
| 2696 | - | |||||||||||||||||||
| 2697 | if (usingWidgets()) {
| 0 | ||||||||||||||||||
| 2698 | settings.setValue(QLatin1String("sidebarWidth"), qFileDialogUi->splitter->sizes().firstconstFirst()); | - | ||||||||||||||||||
| 2699 | settings.setValue(QLatin1String("shortcuts"), QUrl::toStringList(qFileDialogUi->sidebar->urls())); | - | ||||||||||||||||||
| 2700 | settings.setValue(QLatin1String("treeViewHeader"), qFileDialogUi->treeView->header()->saveState()); | - | ||||||||||||||||||
| 2701 | } never executed: end of block | 0 | ||||||||||||||||||
| 2702 | QStringList historyUrls; | - | ||||||||||||||||||
| 2703 | const QStringList history = q->history(); | - | ||||||||||||||||||
| 2704 | historyUrls.reserve(history.size()); | - | ||||||||||||||||||
| 2705 | foreachfor (const QString &path ,: history) | - | ||||||||||||||||||
| 2706 | historyUrls << QUrl::fromLocalFile(path).toString(); never executed: historyUrls << QUrl::fromLocalFile(path).toString(); | 0 | ||||||||||||||||||
| 2707 | settings.setValue(QLatin1String("history"), historyUrls); | - | ||||||||||||||||||
| 2708 | settings.setValue(QLatin1String("lastVisited"), lastVisitedDir()->toString()); | - | ||||||||||||||||||
| 2709 | const QMetaEnum &viewModeMeta = q->metaObject()->enumerator(q->metaObject()->indexOfEnumerator("ViewMode")); | - | ||||||||||||||||||
| 2710 | settings.setValue(QLatin1String("viewMode"), QLatin1String(viewModeMeta.key(q->viewMode()))); | - | ||||||||||||||||||
| 2711 | settings.setValue(QLatin1String("qtVersion"), QLatin1String(QT_VERSION_STR)); | - | ||||||||||||||||||
| 2712 | } never executed: end of block | 0 | ||||||||||||||||||
| 2713 | - | |||||||||||||||||||
| 2714 | bool QFileDialogPrivate::restoreFromSettings() | - | ||||||||||||||||||
| 2715 | { | - | ||||||||||||||||||
| 2716 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 2717 | QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); | - | ||||||||||||||||||
| 2718 | if (!settings.childGroups().contains(QLatin1String("FileDialog")))
| 0 | ||||||||||||||||||
| 2719 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 2720 | settings.beginGroup(QLatin1String("FileDialog")); | - | ||||||||||||||||||
| 2721 | - | |||||||||||||||||||
| 2722 | q->setDirectoryUrl(lastVisitedDir()->isEmpty() ? settings.value(QLatin1String("lastVisited")).toUrl() : *lastVisitedDir()); | - | ||||||||||||||||||
| 2723 | - | |||||||||||||||||||
| 2724 | QByteArray viewModeStr = settings.value(QLatin1String("viewMode")).toString().toLatin1(); | - | ||||||||||||||||||
| 2725 | const QMetaEnum &viewModeMeta = q->metaObject()->enumerator(q->metaObject()->indexOfEnumerator("ViewMode")); | - | ||||||||||||||||||
| 2726 | bool ok = false; | - | ||||||||||||||||||
| 2727 | int viewMode = viewModeMeta.keyToValue(viewModeStr.constData(), &ok); | - | ||||||||||||||||||
| 2728 | if (!ok)
| 0 | ||||||||||||||||||
| 2729 | viewMode = QFileDialog::List; never executed: viewMode = QFileDialog::List; | 0 | ||||||||||||||||||
| 2730 | q->setViewMode(static_cast<QFileDialog::ViewMode>(viewMode)); | - | ||||||||||||||||||
| 2731 | - | |||||||||||||||||||
| 2732 | sidebarUrls = QUrl::fromStringList(settings.value(QLatin1String("shortcuts")).toStringList()); | - | ||||||||||||||||||
| 2733 | headerData = settings.value(QLatin1String("treeViewHeader")).toByteArray(); | - | ||||||||||||||||||
| 2734 | - | |||||||||||||||||||
| 2735 | if (!usingWidgets())
| 0 | ||||||||||||||||||
| 2736 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2737 | - | |||||||||||||||||||
| 2738 | QStringList history; | - | ||||||||||||||||||
| 2739 | foreach (const QString &urlStr,auto urlStrings = settings.value(QLatin1String("history")).toStringList())(); | - | ||||||||||||||||||
| 2740 | for (const QString &urlStr : urlStrings) { | - | ||||||||||||||||||
| 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 | - | |||||||||||||||||||
| 2771 | whilestatic const int MaxHistorySize = 5; | - | ||||||||||||||||||
| 2772 | if
| 0 | ||||||||||||||||||
| 2773 | history.pop_front();erase(history.begin(), history.end() - MaxHistorySize); never executed: history.erase(history.begin(), history.end() - MaxHistorySize); | 0 | ||||||||||||||||||
| 2774 | q->setHistory(history); | - | ||||||||||||||||||
| 2775 | - | |||||||||||||||||||
| 2776 | QHeaderView *headerView = qFileDialogUi->treeView->header(); | - | ||||||||||||||||||
| 2777 | if (!headerView->restoreState(headerData))
| 0 | ||||||||||||||||||
| 2778 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 2779 | - | |||||||||||||||||||
| 2780 | QList<QAction*> actions = headerView->actions(); | - | ||||||||||||||||||
| 2781 | QAbstractItemModel *abstractModel = model; | - | ||||||||||||||||||
| 2782 | #ifndef QT_NO_PROXYMODEL | - | ||||||||||||||||||
| 2783 | if (proxyModel)
| 0 | ||||||||||||||||||
| 2784 | abstractModel = proxyModel; never executed: abstractModel = proxyModel; | 0 | ||||||||||||||||||
| 2785 | #endif | - | ||||||||||||||||||
| 2786 | int total = qMin(abstractModel->columnCount(QModelIndex()), actions.count() + 1); | - | ||||||||||||||||||
| 2787 | for (int i = 1; i < total; ++i)
| 0 | ||||||||||||||||||
| 2788 | actions.at(i - 1)->setChecked(!headerView->isSectionHidden(i)); never executed: actions.at(i - 1)->setChecked(!headerView->isSectionHidden(i)); | 0 | ||||||||||||||||||
| 2789 | - | |||||||||||||||||||
| 2790 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2791 | } | - | ||||||||||||||||||
| 2792 | - | |||||||||||||||||||
| 2793 | /*! | - | ||||||||||||||||||
| 2794 | \internal | - | ||||||||||||||||||
| 2795 | - | |||||||||||||||||||
| 2796 | Create widgets, layout and set default values | - | ||||||||||||||||||
| 2797 | */ | - | ||||||||||||||||||
| 2798 | void QFileDialogPrivate::init(const QUrl &directory, const QString &nameFilter, | - | ||||||||||||||||||
| 2799 | const QString &caption) | - | ||||||||||||||||||
| 2800 | { | - | ||||||||||||||||||
| 2801 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 2802 | if (!caption.isEmpty()) {
| 0 | ||||||||||||||||||
| 2803 | useDefaultCaption = false; | - | ||||||||||||||||||
| 2804 | setWindowTitle = caption; | - | ||||||||||||||||||
| 2805 | q->setWindowTitle(caption); | - | ||||||||||||||||||
| 2806 | } never executed: end of block | 0 | ||||||||||||||||||
| 2807 | - | |||||||||||||||||||
| 2808 | q->setAcceptMode(QFileDialog::AcceptOpen); | - | ||||||||||||||||||
| 2809 | nativeDialogInUse = (canBeNativeDialog() &&platformFileDialogHelper() != 0);; | - | ||||||||||||||||||
| 2810 | if (!nativeDialogInUse)
| 0 | ||||||||||||||||||
| 2811 | createWidgets(); never executed: createWidgets(); | 0 | ||||||||||||||||||
| 2812 | q->setFileMode(QFileDialog::AnyFile); | - | ||||||||||||||||||
| 2813 | if (!nameFilter.isEmpty())
| 0 | ||||||||||||||||||
| 2814 | q->setNameFilter(nameFilter); never executed: q->setNameFilter(nameFilter); | 0 | ||||||||||||||||||
| 2815 | q->setDirectoryUrl(workingDirectory(directory)); | - | ||||||||||||||||||
| 2816 | q->selectFile(initialSelection(directory)); | - | ||||||||||||||||||
| 2817 | - | |||||||||||||||||||
| 2818 | #ifndef QT_NO_SETTINGS | - | ||||||||||||||||||
| 2819 | // Try to restore from the FileDialog settings group; if it fails, fall back | - | ||||||||||||||||||
| 2820 | // to the pre-5.5 QByteArray serialized settings. | - | ||||||||||||||||||
| 2821 | if (!restoreFromSettings()) {
| 0 | ||||||||||||||||||
| 2822 | const QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); | - | ||||||||||||||||||
| 2823 | q->restoreState(settings.value(QLatin1String("Qt/filedialog")).toByteArray()); | - | ||||||||||||||||||
| 2824 | } never executed: end of block | 0 | ||||||||||||||||||
| 2825 | #endif | - | ||||||||||||||||||
| 2826 | - | |||||||||||||||||||
| 2827 | #if defined(Q_EMBEDDED_SMALLSCREEN) | - | ||||||||||||||||||
| 2828 | qFileDialogUi->lookInLabel->setVisible(false); | - | ||||||||||||||||||
| 2829 | qFileDialogUi->fileNameLabel->setVisible(false); | - | ||||||||||||||||||
| 2830 | qFileDialogUi->fileTypeLabel->setVisible(false); | - | ||||||||||||||||||
| 2831 | qFileDialogUi->sidebar->hide(); | - | ||||||||||||||||||
| 2832 | #endif | - | ||||||||||||||||||
| 2833 | - | |||||||||||||||||||
| 2834 | const QSize sizeHint = q->sizeHint(); | - | ||||||||||||||||||
| 2835 | if (sizeHint.isValid())
| 0 | ||||||||||||||||||
| 2836 | q->resize(sizeHint); never executed: q->resize(sizeHint); | 0 | ||||||||||||||||||
| 2837 | } never executed: end of block | 0 | ||||||||||||||||||
| 2838 | - | |||||||||||||||||||
| 2839 | /*! | - | ||||||||||||||||||
| 2840 | \internal | - | ||||||||||||||||||
| 2841 | - | |||||||||||||||||||
| 2842 | Create the widgets, set properties and connections | - | ||||||||||||||||||
| 2843 | */ | - | ||||||||||||||||||
| 2844 | void QFileDialogPrivate::createWidgets() | - | ||||||||||||||||||
| 2845 | { | - | ||||||||||||||||||
| 2846 | if (qFileDialogUi)
| 0 | ||||||||||||||||||
| 2847 | return; never executed: return; | 0 | ||||||||||||||||||
| 2848 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 2849 | - | |||||||||||||||||||
| 2850 | // This function is sometimes called late (e.g as a fallback from setVisible). In that case we | - | ||||||||||||||||||
| 2851 | // need to ensure that the following UI code (setupUI in particular) doesn't reset any explicitly | - | ||||||||||||||||||
| 2852 | // set window state or geometry. | - | ||||||||||||||||||
| 2853 | QSize preSize = q->testAttribute(Qt::WA_Resized) ? q->size() : QSize();
| 0 | ||||||||||||||||||
| 2854 | Qt::WindowStates preState = q->windowState(); | - | ||||||||||||||||||
| 2855 | - | |||||||||||||||||||
| 2856 | model = new QFileSystemModel(q); | - | ||||||||||||||||||
| 2857 | model->setFilter(options->filter()); | - | ||||||||||||||||||
| 2858 | model->setObjectName(QLatin1String("qt_filesystem_model")); | - | ||||||||||||||||||
| 2859 | if (QPlatformFileDialogHelper *helper = platformFileDialogHelper())
| 0 | ||||||||||||||||||
| 2860 | model->setNameFilterDisables(helper->defaultNameFilterDisables()); never executed: model->setNameFilterDisables(helper->defaultNameFilterDisables()); | 0 | ||||||||||||||||||
| 2861 | else | - | ||||||||||||||||||
| 2862 | model->setNameFilterDisables(false); never executed: model->setNameFilterDisables(false); | 0 | ||||||||||||||||||
| 2863 | if (nativeDialogInUse)
| 0 | ||||||||||||||||||
| 2864 | deletePlatformHelper(); never executed: deletePlatformHelper(); | 0 | ||||||||||||||||||
| 2865 | model->d_func()->disableRecursiveSort = true; | - | ||||||||||||||||||
| 2866 | QFileDialog::connect(model, SIGNAL(fileRenamed(QString,QString,QString)), q, SLOT(_q_fileRenamed(QString,QString,QString))); | - | ||||||||||||||||||
| 2867 | QFileDialog::connect(model, SIGNAL(rootPathChanged(QString)), | - | ||||||||||||||||||
| 2868 | q, SLOT(_q_pathChanged(QString))); | - | ||||||||||||||||||
| 2869 | QFileDialog::connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
| 2870 | q, SLOT(_q_rowsInserted(QModelIndex))); | - | ||||||||||||||||||
| 2871 | model->setReadOnly(false); | - | ||||||||||||||||||
| 2872 | - | |||||||||||||||||||
| 2873 | qFileDialogUi.reset(new Ui_QFileDialog()); | - | ||||||||||||||||||
| 2874 | qFileDialogUi->setupUi(q); | - | ||||||||||||||||||
| 2875 | - | |||||||||||||||||||
| 2876 | QList<QUrl> initialBookmarks; | - | ||||||||||||||||||
| 2877 | initialBookmarks << QUrl(QLatin1String("file:")) | - | ||||||||||||||||||
| 2878 | << QUrl::fromLocalFile(QDir::homePath()); | - | ||||||||||||||||||
| 2879 | qFileDialogUi->sidebar->setModelAndUrls(model, initialBookmarks); | - | ||||||||||||||||||
| 2880 | QFileDialog::connect(qFileDialogUi->sidebar, SIGNAL(goToUrl(QUrl)), | - | ||||||||||||||||||
| 2881 | q, SLOT(_q_goToUrl(QUrl))); | - | ||||||||||||||||||
| 2882 | - | |||||||||||||||||||
| 2883 | QObject::connect(qFileDialogUi->buttonBox, SIGNAL(accepted()), q, SLOT(accept())); | - | ||||||||||||||||||
| 2884 | QObject::connect(qFileDialogUi->buttonBox, SIGNAL(rejected()), q, SLOT(reject())); | - | ||||||||||||||||||
| 2885 | - | |||||||||||||||||||
| 2886 | qFileDialogUi->lookInCombo->setFileDialogPrivate(this); | - | ||||||||||||||||||
| 2887 | QObject::connect(qFileDialogUi->lookInCombo, SIGNAL(activated(QString)), q, SLOT(_q_goToDirectory(QString))); | - | ||||||||||||||||||
| 2888 | - | |||||||||||||||||||
| 2889 | qFileDialogUi->lookInCombo->setInsertPolicy(QComboBox::NoInsert); | - | ||||||||||||||||||
| 2890 | qFileDialogUi->lookInCombo->setDuplicatesEnabled(false); | - | ||||||||||||||||||
| 2891 | - | |||||||||||||||||||
| 2892 | // filename | - | ||||||||||||||||||
| 2893 | qFileDialogUi->fileNameEdit->setFileDialogPrivate(this); | - | ||||||||||||||||||
| 2894 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||
| 2895 | qFileDialogUi->fileNameLabel->setBuddy(qFileDialogUi->fileNameEdit); | - | ||||||||||||||||||
| 2896 | #endif | - | ||||||||||||||||||
| 2897 | #ifndef QT_NO_FSCOMPLETER | - | ||||||||||||||||||
| 2898 | completer = new QFSCompleter(model, q); | - | ||||||||||||||||||
| 2899 | qFileDialogUi->fileNameEdit->setCompleter(completer); | - | ||||||||||||||||||
| 2900 | #endif // QT_NO_FSCOMPLETER | - | ||||||||||||||||||
| 2901 | - | |||||||||||||||||||
| 2902 | qFileDialogUi->fileNameEdit->setInputMethodHints(Qt::ImhNoPredictiveText); | - | ||||||||||||||||||
| 2903 | - | |||||||||||||||||||
| 2904 | QObject::connect(qFileDialogUi->fileNameEdit, SIGNAL(textChanged(QString)), | - | ||||||||||||||||||
| 2905 | q, SLOT(_q_autoCompleteFileName(QString))); | - | ||||||||||||||||||
| 2906 | QObject::connect(qFileDialogUi->fileNameEdit, SIGNAL(textChanged(QString)), | - | ||||||||||||||||||
| 2907 | q, SLOT(_q_updateOkButton())); | - | ||||||||||||||||||
| 2908 | - | |||||||||||||||||||
| 2909 | QObject::connect(qFileDialogUi->fileNameEdit, SIGNAL(returnPressed()), q, SLOT(accept())); | - | ||||||||||||||||||
| 2910 | - | |||||||||||||||||||
| 2911 | // filetype | - | ||||||||||||||||||
| 2912 | qFileDialogUi->fileTypeCombo->setDuplicatesEnabled(false); | - | ||||||||||||||||||
| 2913 | qFileDialogUi->fileTypeCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength); | - | ||||||||||||||||||
| 2914 | qFileDialogUi->fileTypeCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); | - | ||||||||||||||||||
| 2915 | QObject::connect(qFileDialogUi->fileTypeCombo, SIGNAL(activated(int)), | - | ||||||||||||||||||
| 2916 | q, SLOT(_q_useNameFilter(int))); | - | ||||||||||||||||||
| 2917 | QObject::connect(qFileDialogUi->fileTypeCombo, SIGNAL(activated(QString)), | - | ||||||||||||||||||
| 2918 | q, SIGNAL(filterSelected(QString))); | - | ||||||||||||||||||
| 2919 | - | |||||||||||||||||||
| 2920 | qFileDialogUi->listView->setFileDialogPrivate(this); | - | ||||||||||||||||||
| 2921 | qFileDialogUi->listView->setModel(model); | - | ||||||||||||||||||
| 2922 | QObject::connect(qFileDialogUi->listView, SIGNAL(activated(QModelIndex)), | - | ||||||||||||||||||
| 2923 | q, SLOT(_q_enterDirectory(QModelIndex))); | - | ||||||||||||||||||
| 2924 | QObject::connect(qFileDialogUi->listView, SIGNAL(customContextMenuRequested(QPoint)), | - | ||||||||||||||||||
| 2925 | q, SLOT(_q_showContextMenu(QPoint))); | - | ||||||||||||||||||
| 2926 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||
| 2927 | QShortcut *shortcut = new QShortcut(qFileDialogUi->listView); | - | ||||||||||||||||||
| 2928 | shortcut->setKey(QKeySequence(QLatin1String("Delete"))); | - | ||||||||||||||||||
| 2929 | QObject::connect(shortcut, SIGNAL(activated()), q, SLOT(_q_deleteCurrent())); | - | ||||||||||||||||||
| 2930 | #endif | - | ||||||||||||||||||
| 2931 | - | |||||||||||||||||||
| 2932 | qFileDialogUi->treeView->setFileDialogPrivate(this); | - | ||||||||||||||||||
| 2933 | qFileDialogUi->treeView->setModel(model); | - | ||||||||||||||||||
| 2934 | QHeaderView *treeHeader = qFileDialogUi->treeView->header(); | - | ||||||||||||||||||
| 2935 | QFontMetrics fm(q->font()); | - | ||||||||||||||||||
| 2936 | treeHeader->resizeSection(0, fm.width(QLatin1String("wwwwwwwwwwwwwwwwwwwwwwwwww"))); | - | ||||||||||||||||||
| 2937 | treeHeader->resizeSection(1, fm.width(QLatin1String("128.88 GB"))); | - | ||||||||||||||||||
| 2938 | treeHeader->resizeSection(2, fm.width(QLatin1String("mp3Folder"))); | - | ||||||||||||||||||
| 2939 | treeHeader->resizeSection(3, fm.width(QLatin1String("10/29/81 02:02PM"))); | - | ||||||||||||||||||
| 2940 | treeHeader->setContextMenuPolicy(Qt::ActionsContextMenu); | - | ||||||||||||||||||
| 2941 | - | |||||||||||||||||||
| 2942 | QActionGroup *showActionGroup = new QActionGroup(q); | - | ||||||||||||||||||
| 2943 | showActionGroup->setExclusive(false); | - | ||||||||||||||||||
| 2944 | QObject::connect(showActionGroup, SIGNAL(triggered(QAction*)), | - | ||||||||||||||||||
| 2945 | q, SLOT(_q_showHeader(QAction*)));; | - | ||||||||||||||||||
| 2946 | - | |||||||||||||||||||
| 2947 | QAbstractItemModel *abstractModel = model; | - | ||||||||||||||||||
| 2948 | #ifndef QT_NO_PROXYMODEL | - | ||||||||||||||||||
| 2949 | if (proxyModel)
| 0 | ||||||||||||||||||
| 2950 | abstractModel = proxyModel; never executed: abstractModel = proxyModel; | 0 | ||||||||||||||||||
| 2951 | #endif | - | ||||||||||||||||||
| 2952 | for (int i = 1; i < abstractModel->columnCount(QModelIndex()); ++i) {
| 0 | ||||||||||||||||||
| 2953 | QAction *showHeader = new QAction(showActionGroup); | - | ||||||||||||||||||
| 2954 | showHeader->setCheckable(true); | - | ||||||||||||||||||
| 2955 | showHeader->setChecked(true); | - | ||||||||||||||||||
| 2956 | treeHeader->addAction(showHeader); | - | ||||||||||||||||||
| 2957 | } never executed: end of block | 0 | ||||||||||||||||||
| 2958 | - | |||||||||||||||||||
| 2959 | QScopedPointer<QItemSelectionModel> selModel(qFileDialogUi->treeView->selectionModel()); | - | ||||||||||||||||||
| 2960 | qFileDialogUi->treeView->setSelectionModel(qFileDialogUi->listView->selectionModel()); | - | ||||||||||||||||||
| 2961 | - | |||||||||||||||||||
| 2962 | QObject::connect(qFileDialogUi->treeView, SIGNAL(activated(QModelIndex)), | - | ||||||||||||||||||
| 2963 | q, SLOT(_q_enterDirectory(QModelIndex))); | - | ||||||||||||||||||
| 2964 | QObject::connect(qFileDialogUi->treeView, SIGNAL(customContextMenuRequested(QPoint)), | - | ||||||||||||||||||
| 2965 | q, SLOT(_q_showContextMenu(QPoint))); | - | ||||||||||||||||||
| 2966 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||
| 2967 | shortcut = new QShortcut(qFileDialogUi->treeView); | - | ||||||||||||||||||
| 2968 | shortcut->setKey(QKeySequence(QLatin1String("Delete"))); | - | ||||||||||||||||||
| 2969 | QObject::connect(shortcut, SIGNAL(activated()), q, SLOT(_q_deleteCurrent())); | - | ||||||||||||||||||
| 2970 | #endif | - | ||||||||||||||||||
| 2971 | - | |||||||||||||||||||
| 2972 | // Selections | - | ||||||||||||||||||
| 2973 | QItemSelectionModel *selections = qFileDialogUi->listView->selectionModel(); | - | ||||||||||||||||||
| 2974 | QObject::connect(selections, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), | - | ||||||||||||||||||
| 2975 | q, SLOT(_q_selectionChanged())); | - | ||||||||||||||||||
| 2976 | QObject::connect(selections, SIGNAL(currentChanged(QModelIndex,QModelIndex)), | - | ||||||||||||||||||
| 2977 | q, SLOT(_q_currentChanged(QModelIndex))); | - | ||||||||||||||||||
| 2978 | qFileDialogUi->splitter->setStretchFactor(qFileDialogUi->splitter->indexOf(qFileDialogUi->splitter->widget(1)), QSizePolicy::Expanding); | - | ||||||||||||||||||
| 2979 | - | |||||||||||||||||||
| 2980 | createToolButtons(); | - | ||||||||||||||||||
| 2981 | createMenuActions(); | - | ||||||||||||||||||
| 2982 | - | |||||||||||||||||||
| 2983 | #ifndef QT_NO_SETTINGS | - | ||||||||||||||||||
| 2984 | // Try to restore from the FileDialog settings group; if it fails, fall back | - | ||||||||||||||||||
| 2985 | // to the pre-5.5 QByteArray serialized settings. | - | ||||||||||||||||||
| 2986 | if (!restoreFromSettings()) {
| 0 | ||||||||||||||||||
| 2987 | const QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); | - | ||||||||||||||||||
| 2988 | q->restoreState(settings.value(QLatin1String("Qt/filedialog")).toByteArray()); | - | ||||||||||||||||||
| 2989 | } never executed: end of block | 0 | ||||||||||||||||||
| 2990 | #endif | - | ||||||||||||||||||
| 2991 | - | |||||||||||||||||||
| 2992 | // Initial widget states from options | - | ||||||||||||||||||
| 2993 | q->setFileMode(static_cast<QFileDialog::FileMode>(options->fileMode())); | - | ||||||||||||||||||
| 2994 | q->setAcceptMode(static_cast<QFileDialog::AcceptMode>(options->acceptMode())); | - | ||||||||||||||||||
| 2995 | q->setViewMode(static_cast<QFileDialog::ViewMode>(options->viewMode())); | - | ||||||||||||||||||
| 2996 | q->setOptions(static_cast<QFileDialog::Options>(static_cast<int>(options->options()))); | - | ||||||||||||||||||
| 2997 | if (!options->sidebarUrls().isEmpty())
| 0 | ||||||||||||||||||
| 2998 | q->setSidebarUrls(options->sidebarUrls()); never executed: q->setSidebarUrls(options->sidebarUrls()); | 0 | ||||||||||||||||||
| 2999 | q->setDirectoryUrl(options->initialDirectory()); | - | ||||||||||||||||||
| 3000 | #ifndef QT_NO_MIMETYPE | - | ||||||||||||||||||
| 3001 | if (!options->mimeTypeFilters().isEmpty())
| 0 | ||||||||||||||||||
| 3002 | q->setMimeTypeFilters(options->mimeTypeFilters()); never executed: q->setMimeTypeFilters(options->mimeTypeFilters()); | 0 | ||||||||||||||||||
| 3003 | else | - | ||||||||||||||||||
| 3004 | #endif | - | ||||||||||||||||||
| 3005 | if (!options->nameFilters().isEmpty())
| 0 | ||||||||||||||||||
| 3006 | q->setNameFilters(options->nameFilters()); never executed: q->setNameFilters(options->nameFilters()); | 0 | ||||||||||||||||||
| 3007 | q->selectNameFilter(options->initiallySelectedNameFilter()); | - | ||||||||||||||||||
| 3008 | q->setDefaultSuffix(options->defaultSuffix()); | - | ||||||||||||||||||
| 3009 | q->setHistory(options->history()); | - | ||||||||||||||||||
| 3010 | if (const auto initiallySelectedFiles = options->initiallySelectedFiles().count(); | - | ||||||||||||||||||
| 3011 | if (initiallySelectedFiles.size
| 0 | ||||||||||||||||||
| 3012 | q->selectFile(options->initiallySelectedFiles()..first().fileName()); never executed: q->selectFile(initiallySelectedFiles.first().fileName()); | 0 | ||||||||||||||||||
| 3013 | foreachfor (const QUrl &url , options->: initiallySelectedFiles())) | - | ||||||||||||||||||
| 3014 | q->selectUrl(url); never executed: q->selectUrl(url); | 0 | ||||||||||||||||||
| 3015 | lineEdit()->selectAll(); | - | ||||||||||||||||||
| 3016 | _q_updateOkButton(); | - | ||||||||||||||||||
| 3017 | retranslateStrings(); | - | ||||||||||||||||||
| 3018 | q->resize(preSize.isValid() ? preSize : q->sizeHint()); | - | ||||||||||||||||||
| 3019 | q->setWindowState(preState); | - | ||||||||||||||||||
| 3020 | } never executed: end of block | 0 | ||||||||||||||||||
| 3021 | - | |||||||||||||||||||
| 3022 | void QFileDialogPrivate::_q_showHeader(QAction *action) | - | ||||||||||||||||||
| 3023 | { | - | ||||||||||||||||||
| 3024 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3025 | QActionGroup *actionGroup = qobject_cast<QActionGroup*>(q->sender()); | - | ||||||||||||||||||
| 3026 | qFileDialogUi->treeView->header()->setSectionHidden(actionGroup->actions().indexOf(action) + 1, !action->isChecked()); | - | ||||||||||||||||||
| 3027 | } | - | ||||||||||||||||||
| 3028 | - | |||||||||||||||||||
| 3029 | #ifndef QT_NO_PROXYMODEL | - | ||||||||||||||||||
| 3030 | /*! | - | ||||||||||||||||||
| 3031 | \since 4.3 | - | ||||||||||||||||||
| 3032 | - | |||||||||||||||||||
| 3033 | Sets the model for the views to the given \a proxyModel. This is useful if you | - | ||||||||||||||||||
| 3034 | want to modify the underlying model; for example, to add columns, filter | - | ||||||||||||||||||
| 3035 | data or add drives. | - | ||||||||||||||||||
| 3036 | - | |||||||||||||||||||
| 3037 | Any existing proxy model will be removed, but not deleted. The file dialog | - | ||||||||||||||||||
| 3038 | will take ownership of the \a proxyModel. | - | ||||||||||||||||||
| 3039 | - | |||||||||||||||||||
| 3040 | \sa proxyModel() | - | ||||||||||||||||||
| 3041 | */ | - | ||||||||||||||||||
| 3042 | void QFileDialog::setProxyModel(QAbstractProxyModel *proxyModel) | - | ||||||||||||||||||
| 3043 | { | - | ||||||||||||||||||
| 3044 | Q_D(QFileDialog); | - | ||||||||||||||||||
| 3045 | if (!d->usingWidgets()) | - | ||||||||||||||||||
| 3046 | return; | - | ||||||||||||||||||
| 3047 | if ((!proxyModel && !d->proxyModel) | - | ||||||||||||||||||
| 3048 | || (proxyModel == d->proxyModel)) | - | ||||||||||||||||||
| 3049 | return; | - | ||||||||||||||||||
| 3050 | - | |||||||||||||||||||
| 3051 | QModelIndex idx = d->rootIndex(); | - | ||||||||||||||||||
| 3052 | if (d->proxyModel) { | - | ||||||||||||||||||
| 3053 | disconnect(d->proxyModel, SIGNAL(rowsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
| 3054 | this, SLOT(_q_rowsInserted(QModelIndex))); | - | ||||||||||||||||||
| 3055 | } else { | - | ||||||||||||||||||
| 3056 | disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
| 3057 | this, SLOT(_q_rowsInserted(QModelIndex))); | - | ||||||||||||||||||
| 3058 | } | - | ||||||||||||||||||
| 3059 | - | |||||||||||||||||||
| 3060 | if (proxyModel != 0) { | - | ||||||||||||||||||
| 3061 | proxyModel->setParent(this); | - | ||||||||||||||||||
| 3062 | d->proxyModel = proxyModel; | - | ||||||||||||||||||
| 3063 | proxyModel->setSourceModel(d->model); | - | ||||||||||||||||||
| 3064 | d->qFileDialogUi->listView->setModel(d->proxyModel); | - | ||||||||||||||||||
| 3065 | d->qFileDialogUi->treeView->setModel(d->proxyModel); | - | ||||||||||||||||||
| 3066 | #ifndef QT_NO_FSCOMPLETER | - | ||||||||||||||||||
| 3067 | d->completer->setModel(d->proxyModel); | - | ||||||||||||||||||
| 3068 | d->completer->proxyModel = d->proxyModel; | - | ||||||||||||||||||
| 3069 | #endif | - | ||||||||||||||||||
| 3070 | connect(d->proxyModel, SIGNAL(rowsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
| 3071 | this, SLOT(_q_rowsInserted(QModelIndex))); | - | ||||||||||||||||||
| 3072 | } else { | - | ||||||||||||||||||
| 3073 | d->proxyModel = 0; | - | ||||||||||||||||||
| 3074 | d->qFileDialogUi->listView->setModel(d->model); | - | ||||||||||||||||||
| 3075 | d->qFileDialogUi->treeView->setModel(d->model); | - | ||||||||||||||||||
| 3076 | #ifndef QT_NO_FSCOMPLETER | - | ||||||||||||||||||
| 3077 | d->completer->setModel(d->model); | - | ||||||||||||||||||
| 3078 | d->completer->sourceModel = d->model; | - | ||||||||||||||||||
| 3079 | d->completer->proxyModel = 0; | - | ||||||||||||||||||
| 3080 | #endif | - | ||||||||||||||||||
| 3081 | connect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
| 3082 | this, SLOT(_q_rowsInserted(QModelIndex))); | - | ||||||||||||||||||
| 3083 | } | - | ||||||||||||||||||
| 3084 | QScopedPointer<QItemSelectionModel> selModel(d->qFileDialogUi->treeView->selectionModel()); | - | ||||||||||||||||||
| 3085 | d->qFileDialogUi->treeView->setSelectionModel(d->qFileDialogUi->listView->selectionModel()); | - | ||||||||||||||||||
| 3086 | - | |||||||||||||||||||
| 3087 | d->setRootIndex(idx); | - | ||||||||||||||||||
| 3088 | - | |||||||||||||||||||
| 3089 | // reconnect selection | - | ||||||||||||||||||
| 3090 | QItemSelectionModel *selections = d->qFileDialogUi->listView->selectionModel(); | - | ||||||||||||||||||
| 3091 | QObject::connect(selections, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), | - | ||||||||||||||||||
| 3092 | this, SLOT(_q_selectionChanged())); | - | ||||||||||||||||||
| 3093 | QObject::connect(selections, SIGNAL(currentChanged(QModelIndex,QModelIndex)), | - | ||||||||||||||||||
| 3094 | this, SLOT(_q_currentChanged(QModelIndex))); | - | ||||||||||||||||||
| 3095 | } | - | ||||||||||||||||||
| 3096 | - | |||||||||||||||||||
| 3097 | /*! | - | ||||||||||||||||||
| 3098 | Returns the proxy model used by the file dialog. By default no proxy is set. | - | ||||||||||||||||||
| 3099 | - | |||||||||||||||||||
| 3100 | \sa setProxyModel() | - | ||||||||||||||||||
| 3101 | */ | - | ||||||||||||||||||
| 3102 | QAbstractProxyModel *QFileDialog::proxyModel() const | - | ||||||||||||||||||
| 3103 | { | - | ||||||||||||||||||
| 3104 | Q_D(const QFileDialog); | - | ||||||||||||||||||
| 3105 | return d->proxyModel; | - | ||||||||||||||||||
| 3106 | } | - | ||||||||||||||||||
| 3107 | #endif // QT_NO_PROXYMODEL | - | ||||||||||||||||||
| 3108 | - | |||||||||||||||||||
| 3109 | /*! | - | ||||||||||||||||||
| 3110 | \internal | - | ||||||||||||||||||
| 3111 | - | |||||||||||||||||||
| 3112 | Create tool buttons, set properties and connections | - | ||||||||||||||||||
| 3113 | */ | - | ||||||||||||||||||
| 3114 | void QFileDialogPrivate::createToolButtons() | - | ||||||||||||||||||
| 3115 | { | - | ||||||||||||||||||
| 3116 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3117 | qFileDialogUi->backButton->setIcon(q->style()->standardIcon(QStyle::SP_ArrowBack, 0, q)); | - | ||||||||||||||||||
| 3118 | qFileDialogUi->backButton->setAutoRaise(true); | - | ||||||||||||||||||
| 3119 | qFileDialogUi->backButton->setEnabled(false); | - | ||||||||||||||||||
| 3120 | QObject::connect(qFileDialogUi->backButton, SIGNAL(clicked()), q, SLOT(_q_navigateBackward())); | - | ||||||||||||||||||
| 3121 | - | |||||||||||||||||||
| 3122 | qFileDialogUi->forwardButton->setIcon(q->style()->standardIcon(QStyle::SP_ArrowForward, 0, q)); | - | ||||||||||||||||||
| 3123 | qFileDialogUi->forwardButton->setAutoRaise(true); | - | ||||||||||||||||||
| 3124 | qFileDialogUi->forwardButton->setEnabled(false); | - | ||||||||||||||||||
| 3125 | QObject::connect(qFileDialogUi->forwardButton, SIGNAL(clicked()), q, SLOT(_q_navigateForward())); | - | ||||||||||||||||||
| 3126 | - | |||||||||||||||||||
| 3127 | qFileDialogUi->toParentButton->setIcon(q->style()->standardIcon(QStyle::SP_FileDialogToParent, 0, q)); | - | ||||||||||||||||||
| 3128 | qFileDialogUi->toParentButton->setAutoRaise(true); | - | ||||||||||||||||||
| 3129 | qFileDialogUi->toParentButton->setEnabled(false); | - | ||||||||||||||||||
| 3130 | QObject::connect(qFileDialogUi->toParentButton, SIGNAL(clicked()), q, SLOT(_q_navigateToParent())); | - | ||||||||||||||||||
| 3131 | - | |||||||||||||||||||
| 3132 | qFileDialogUi->listModeButton->setIcon(q->style()->standardIcon(QStyle::SP_FileDialogListView, 0, q)); | - | ||||||||||||||||||
| 3133 | qFileDialogUi->listModeButton->setAutoRaise(true); | - | ||||||||||||||||||
| 3134 | qFileDialogUi->listModeButton->setDown(true); | - | ||||||||||||||||||
| 3135 | QObject::connect(qFileDialogUi->listModeButton, SIGNAL(clicked()), q, SLOT(_q_showListView())); | - | ||||||||||||||||||
| 3136 | - | |||||||||||||||||||
| 3137 | qFileDialogUi->detailModeButton->setIcon(q->style()->standardIcon(QStyle::SP_FileDialogDetailedView, 0, q)); | - | ||||||||||||||||||
| 3138 | qFileDialogUi->detailModeButton->setAutoRaise(true); | - | ||||||||||||||||||
| 3139 | QObject::connect(qFileDialogUi->detailModeButton, SIGNAL(clicked()), q, SLOT(_q_showDetailsView())); | - | ||||||||||||||||||
| 3140 | - | |||||||||||||||||||
| 3141 | QSize toolSize(qFileDialogUi->fileNameEdit->sizeHint().height(), qFileDialogUi->fileNameEdit->sizeHint().height()); | - | ||||||||||||||||||
| 3142 | qFileDialogUi->backButton->setFixedSize(toolSize); | - | ||||||||||||||||||
| 3143 | qFileDialogUi->listModeButton->setFixedSize(toolSize); | - | ||||||||||||||||||
| 3144 | qFileDialogUi->detailModeButton->setFixedSize(toolSize); | - | ||||||||||||||||||
| 3145 | qFileDialogUi->forwardButton->setFixedSize(toolSize); | - | ||||||||||||||||||
| 3146 | qFileDialogUi->toParentButton->setFixedSize(toolSize); | - | ||||||||||||||||||
| 3147 | - | |||||||||||||||||||
| 3148 | qFileDialogUi->newFolderButton->setIcon(q->style()->standardIcon(QStyle::SP_FileDialogNewFolder, 0, q)); | - | ||||||||||||||||||
| 3149 | qFileDialogUi->newFolderButton->setFixedSize(toolSize); | - | ||||||||||||||||||
| 3150 | qFileDialogUi->newFolderButton->setAutoRaise(true); | - | ||||||||||||||||||
| 3151 | qFileDialogUi->newFolderButton->setEnabled(false); | - | ||||||||||||||||||
| 3152 | QObject::connect(qFileDialogUi->newFolderButton, SIGNAL(clicked()), q, SLOT(_q_createDirectory())); | - | ||||||||||||||||||
| 3153 | } | - | ||||||||||||||||||
| 3154 | - | |||||||||||||||||||
| 3155 | /*! | - | ||||||||||||||||||
| 3156 | \internal | - | ||||||||||||||||||
| 3157 | - | |||||||||||||||||||
| 3158 | Create actions which will be used in the right click. | - | ||||||||||||||||||
| 3159 | */ | - | ||||||||||||||||||
| 3160 | void QFileDialogPrivate::createMenuActions() | - | ||||||||||||||||||
| 3161 | { | - | ||||||||||||||||||
| 3162 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3163 | - | |||||||||||||||||||
| 3164 | QAction *goHomeAction = new QAction(q); | - | ||||||||||||||||||
| 3165 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||
| 3166 | goHomeAction->setShortcut(Qt::CTRL + Qt::Key_H + Qt::SHIFT); | - | ||||||||||||||||||
| 3167 | #endif | - | ||||||||||||||||||
| 3168 | QObject::connect(goHomeAction, SIGNAL(triggered()), q, SLOT(_q_goHome())); | - | ||||||||||||||||||
| 3169 | q->addAction(goHomeAction); | - | ||||||||||||||||||
| 3170 | - | |||||||||||||||||||
| 3171 | // ### TODO add Desktop & Computer actions | - | ||||||||||||||||||
| 3172 | - | |||||||||||||||||||
| 3173 | QAction *goToParent = new QAction(q); | - | ||||||||||||||||||
| 3174 | goToParent->setObjectName(QLatin1String("qt_goto_parent_action")); | - | ||||||||||||||||||
| 3175 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||
| 3176 | goToParent->setShortcut(Qt::CTRL + Qt::UpArrow); | - | ||||||||||||||||||
| 3177 | #endif | - | ||||||||||||||||||
| 3178 | QObject::connect(goToParent, SIGNAL(triggered()), q, SLOT(_q_navigateToParent())); | - | ||||||||||||||||||
| 3179 | q->addAction(goToParent); | - | ||||||||||||||||||
| 3180 | - | |||||||||||||||||||
| 3181 | renameAction = new QAction(q); | - | ||||||||||||||||||
| 3182 | renameAction->setEnabled(false); | - | ||||||||||||||||||
| 3183 | renameAction->setObjectName(QLatin1String("qt_rename_action")); | - | ||||||||||||||||||
| 3184 | QObject::connect(renameAction, SIGNAL(triggered()), q, SLOT(_q_renameCurrent())); | - | ||||||||||||||||||
| 3185 | - | |||||||||||||||||||
| 3186 | deleteAction = new QAction(q); | - | ||||||||||||||||||
| 3187 | deleteAction->setEnabled(false); | - | ||||||||||||||||||
| 3188 | deleteAction->setObjectName(QLatin1String("qt_delete_action")); | - | ||||||||||||||||||
| 3189 | QObject::connect(deleteAction, SIGNAL(triggered()), q, SLOT(_q_deleteCurrent())); | - | ||||||||||||||||||
| 3190 | - | |||||||||||||||||||
| 3191 | showHiddenAction = new QAction(q); | - | ||||||||||||||||||
| 3192 | showHiddenAction->setObjectName(QLatin1String("qt_show_hidden_action")); | - | ||||||||||||||||||
| 3193 | showHiddenAction->setCheckable(true); | - | ||||||||||||||||||
| 3194 | QObject::connect(showHiddenAction, SIGNAL(triggered()), q, SLOT(_q_showHidden())); | - | ||||||||||||||||||
| 3195 | - | |||||||||||||||||||
| 3196 | newFolderAction = new QAction(q); | - | ||||||||||||||||||
| 3197 | newFolderAction->setObjectName(QLatin1String("qt_new_folder_action")); | - | ||||||||||||||||||
| 3198 | QObject::connect(newFolderAction, SIGNAL(triggered()), q, SLOT(_q_createDirectory())); | - | ||||||||||||||||||
| 3199 | } | - | ||||||||||||||||||
| 3200 | - | |||||||||||||||||||
| 3201 | void QFileDialogPrivate::_q_goHome() | - | ||||||||||||||||||
| 3202 | { | - | ||||||||||||||||||
| 3203 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3204 | q->setDirectory(QDir::homePath()); | - | ||||||||||||||||||
| 3205 | } | - | ||||||||||||||||||
| 3206 | - | |||||||||||||||||||
| 3207 | /*! | - | ||||||||||||||||||
| 3208 | \internal | - | ||||||||||||||||||
| 3209 | - | |||||||||||||||||||
| 3210 | Update history with new path, buttons, and combo | - | ||||||||||||||||||
| 3211 | */ | - | ||||||||||||||||||
| 3212 | void QFileDialogPrivate::_q_pathChanged(const QString &newPath) | - | ||||||||||||||||||
| 3213 | { | - | ||||||||||||||||||
| 3214 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3215 | QDir dir(model->rootDirectory()); | - | ||||||||||||||||||
| 3216 | qFileDialogUi->toParentButton->setEnabled(dir.exists()); | - | ||||||||||||||||||
| 3217 | qFileDialogUi->sidebar->selectUrl(QUrl::fromLocalFile(newPath)); | - | ||||||||||||||||||
| 3218 | q->setHistory(qFileDialogUi->lookInCombo->history()); | - | ||||||||||||||||||
| 3219 | - | |||||||||||||||||||
| 3220 | if (currentHistoryLocation < 0 || currentHistory.value(currentHistoryLocation) != QDir::toNativeSeparators(newPath)) { | - | ||||||||||||||||||
| 3221 | while (currentHistoryLocation >= 0 && currentHistoryLocation + 1 < currentHistory.count()) { | - | ||||||||||||||||||
| 3222 | currentHistory.removeLast(); | - | ||||||||||||||||||
| 3223 | } | - | ||||||||||||||||||
| 3224 | currentHistory.append(QDir::toNativeSeparators(newPath)); | - | ||||||||||||||||||
| 3225 | ++currentHistoryLocation; | - | ||||||||||||||||||
| 3226 | } | - | ||||||||||||||||||
| 3227 | qFileDialogUi->forwardButton->setEnabled(currentHistory.size() - currentHistoryLocation > 1); | - | ||||||||||||||||||
| 3228 | qFileDialogUi->backButton->setEnabled(currentHistoryLocation > 0); | - | ||||||||||||||||||
| 3229 | } | - | ||||||||||||||||||
| 3230 | - | |||||||||||||||||||
| 3231 | /*! | - | ||||||||||||||||||
| 3232 | \internal | - | ||||||||||||||||||
| 3233 | - | |||||||||||||||||||
| 3234 | Navigates to the last directory viewed in the dialog. | - | ||||||||||||||||||
| 3235 | */ | - | ||||||||||||||||||
| 3236 | void QFileDialogPrivate::_q_navigateBackward() | - | ||||||||||||||||||
| 3237 | { | - | ||||||||||||||||||
| 3238 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3239 | if (!currentHistory.isEmpty() && currentHistoryLocation > 0) { | - | ||||||||||||||||||
| 3240 | --currentHistoryLocation; | - | ||||||||||||||||||
| 3241 | QString previousHistory = currentHistory.at(currentHistoryLocation); | - | ||||||||||||||||||
| 3242 | q->setDirectory(previousHistory); | - | ||||||||||||||||||
| 3243 | } | - | ||||||||||||||||||
| 3244 | } | - | ||||||||||||||||||
| 3245 | - | |||||||||||||||||||
| 3246 | /*! | - | ||||||||||||||||||
| 3247 | \internal | - | ||||||||||||||||||
| 3248 | - | |||||||||||||||||||
| 3249 | Navigates to the last directory viewed in the dialog. | - | ||||||||||||||||||
| 3250 | */ | - | ||||||||||||||||||
| 3251 | void QFileDialogPrivate::_q_navigateForward() | - | ||||||||||||||||||
| 3252 | { | - | ||||||||||||||||||
| 3253 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3254 | if (!currentHistory.isEmpty() && currentHistoryLocation < currentHistory.size() - 1) { | - | ||||||||||||||||||
| 3255 | ++currentHistoryLocation; | - | ||||||||||||||||||
| 3256 | QString nextHistory = currentHistory.at(currentHistoryLocation); | - | ||||||||||||||||||
| 3257 | q->setDirectory(nextHistory); | - | ||||||||||||||||||
| 3258 | } | - | ||||||||||||||||||
| 3259 | } | - | ||||||||||||||||||
| 3260 | - | |||||||||||||||||||
| 3261 | /*! | - | ||||||||||||||||||
| 3262 | \internal | - | ||||||||||||||||||
| 3263 | - | |||||||||||||||||||
| 3264 | Navigates to the parent directory of the currently displayed directory | - | ||||||||||||||||||
| 3265 | in the dialog. | - | ||||||||||||||||||
| 3266 | */ | - | ||||||||||||||||||
| 3267 | void QFileDialogPrivate::_q_navigateToParent() | - | ||||||||||||||||||
| 3268 | { | - | ||||||||||||||||||
| 3269 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3270 | QDir dir(model->rootDirectory()); | - | ||||||||||||||||||
| 3271 | QString newDirectory; | - | ||||||||||||||||||
| 3272 | if (dir.isRoot()) { | - | ||||||||||||||||||
| 3273 | newDirectory = model->myComputer().toString(); | - | ||||||||||||||||||
| 3274 | } else { | - | ||||||||||||||||||
| 3275 | dir.cdUp(); | - | ||||||||||||||||||
| 3276 | newDirectory = dir.absolutePath(); | - | ||||||||||||||||||
| 3277 | } | - | ||||||||||||||||||
| 3278 | q->setDirectory(newDirectory); | - | ||||||||||||||||||
| 3279 | emit q->directoryEntered(newDirectory); | - | ||||||||||||||||||
| 3280 | } | - | ||||||||||||||||||
| 3281 | - | |||||||||||||||||||
| 3282 | /*! | - | ||||||||||||||||||
| 3283 | \internal | - | ||||||||||||||||||
| 3284 | - | |||||||||||||||||||
| 3285 | Creates a new directory, first asking the user for a suitable name. | - | ||||||||||||||||||
| 3286 | */ | - | ||||||||||||||||||
| 3287 | void QFileDialogPrivate::_q_createDirectory() | - | ||||||||||||||||||
| 3288 | { | - | ||||||||||||||||||
| 3289 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3290 | qFileDialogUi->listView->clearSelection(); | - | ||||||||||||||||||
| 3291 | - | |||||||||||||||||||
| 3292 | QString newFolderString = QFileDialog::tr("New Folder"); | - | ||||||||||||||||||
| 3293 | QString folderName = newFolderString; | - | ||||||||||||||||||
| 3294 | QString prefix = q->directory().absolutePath() + QDir::separator(); | - | ||||||||||||||||||
| 3295 | if (QFile::exists(prefix + folderName)) { | - | ||||||||||||||||||
| 3296 | qlonglong suffix = 2; | - | ||||||||||||||||||
| 3297 | while (QFile::exists(prefix + folderName)) { | - | ||||||||||||||||||
| 3298 | folderName = newFolderString + QString::number(suffix++); | - | ||||||||||||||||||
| 3299 | } | - | ||||||||||||||||||
| 3300 | } | - | ||||||||||||||||||
| 3301 | - | |||||||||||||||||||
| 3302 | QModelIndex parent = rootIndex(); | - | ||||||||||||||||||
| 3303 | QModelIndex index = model->mkdir(parent, folderName); | - | ||||||||||||||||||
| 3304 | if (!index.isValid()) | - | ||||||||||||||||||
| 3305 | return; | - | ||||||||||||||||||
| 3306 | - | |||||||||||||||||||
| 3307 | index = select(index); | - | ||||||||||||||||||
| 3308 | if (index.isValid()) { | - | ||||||||||||||||||
| 3309 | qFileDialogUi->treeView->setCurrentIndex(index); | - | ||||||||||||||||||
| 3310 | currentView()->edit(index); | - | ||||||||||||||||||
| 3311 | } | - | ||||||||||||||||||
| 3312 | } | - | ||||||||||||||||||
| 3313 | - | |||||||||||||||||||
| 3314 | void QFileDialogPrivate::_q_showListView() | - | ||||||||||||||||||
| 3315 | { | - | ||||||||||||||||||
| 3316 | qFileDialogUi->listModeButton->setDown(true); | - | ||||||||||||||||||
| 3317 | qFileDialogUi->detailModeButton->setDown(false); | - | ||||||||||||||||||
| 3318 | qFileDialogUi->treeView->hide(); | - | ||||||||||||||||||
| 3319 | qFileDialogUi->listView->show(); | - | ||||||||||||||||||
| 3320 | qFileDialogUi->stackedWidget->setCurrentWidget(qFileDialogUi->listView->parentWidget()); | - | ||||||||||||||||||
| 3321 | qFileDialogUi->listView->doItemsLayout(); | - | ||||||||||||||||||
| 3322 | } | - | ||||||||||||||||||
| 3323 | - | |||||||||||||||||||
| 3324 | void QFileDialogPrivate::_q_showDetailsView() | - | ||||||||||||||||||
| 3325 | { | - | ||||||||||||||||||
| 3326 | qFileDialogUi->listModeButton->setDown(false); | - | ||||||||||||||||||
| 3327 | qFileDialogUi->detailModeButton->setDown(true); | - | ||||||||||||||||||
| 3328 | qFileDialogUi->listView->hide(); | - | ||||||||||||||||||
| 3329 | qFileDialogUi->treeView->show(); | - | ||||||||||||||||||
| 3330 | qFileDialogUi->stackedWidget->setCurrentWidget(qFileDialogUi->treeView->parentWidget()); | - | ||||||||||||||||||
| 3331 | qFileDialogUi->treeView->doItemsLayout(); | - | ||||||||||||||||||
| 3332 | } | - | ||||||||||||||||||
| 3333 | - | |||||||||||||||||||
| 3334 | /*! | - | ||||||||||||||||||
| 3335 | \internal | - | ||||||||||||||||||
| 3336 | - | |||||||||||||||||||
| 3337 | Show the context menu for the file/dir under position | - | ||||||||||||||||||
| 3338 | */ | - | ||||||||||||||||||
| 3339 | void QFileDialogPrivate::_q_showContextMenu(const QPoint &position) | - | ||||||||||||||||||
| 3340 | { | - | ||||||||||||||||||
| 3341 | #ifdef QT_NO_MENU | - | ||||||||||||||||||
| 3342 | Q_UNUSED(position); | - | ||||||||||||||||||
| 3343 | #else | - | ||||||||||||||||||
| 3344 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3345 | QAbstractItemView *view = 0; | - | ||||||||||||||||||
| 3346 | if (q->viewMode() == QFileDialog::Detail) | - | ||||||||||||||||||
| 3347 | view = qFileDialogUi->treeView; | - | ||||||||||||||||||
| 3348 | else | - | ||||||||||||||||||
| 3349 | view = qFileDialogUi->listView; | - | ||||||||||||||||||
| 3350 | QModelIndex index = view->indexAt(position); | - | ||||||||||||||||||
| 3351 | index = mapToSource(index.sibling(index.row(), 0)); | - | ||||||||||||||||||
| 3352 | - | |||||||||||||||||||
| 3353 | QMenu menu(view); | - | ||||||||||||||||||
| 3354 | if (index.isValid()) { | - | ||||||||||||||||||
| 3355 | // file context menu | - | ||||||||||||||||||
| 3356 | const bool ro = model && model->isReadOnly(); | - | ||||||||||||||||||
| 3357 | QFile::Permissions p(index.parent().data(QFileSystemModel::FilePermissions).toInt()); | - | ||||||||||||||||||
| 3358 | renameAction->setEnabled(!ro && p & QFile::WriteUser); | - | ||||||||||||||||||
| 3359 | menu.addAction(renameAction); | - | ||||||||||||||||||
| 3360 | deleteAction->setEnabled(!ro && p & QFile::WriteUser); | - | ||||||||||||||||||
| 3361 | menu.addAction(deleteAction); | - | ||||||||||||||||||
| 3362 | menu.addSeparator(); | - | ||||||||||||||||||
| 3363 | } | - | ||||||||||||||||||
| 3364 | menu.addAction(showHiddenAction); | - | ||||||||||||||||||
| 3365 | if (qFileDialogUi->newFolderButton->isVisible()) { | - | ||||||||||||||||||
| 3366 | newFolderAction->setEnabled(qFileDialogUi->newFolderButton->isEnabled()); | - | ||||||||||||||||||
| 3367 | menu.addAction(newFolderAction); | - | ||||||||||||||||||
| 3368 | } | - | ||||||||||||||||||
| 3369 | menu.exec(view->viewport()->mapToGlobal(position)); | - | ||||||||||||||||||
| 3370 | #endif // QT_NO_MENU | - | ||||||||||||||||||
| 3371 | } | - | ||||||||||||||||||
| 3372 | - | |||||||||||||||||||
| 3373 | /*! | - | ||||||||||||||||||
| 3374 | \internal | - | ||||||||||||||||||
| 3375 | */ | - | ||||||||||||||||||
| 3376 | void QFileDialogPrivate::_q_renameCurrent() | - | ||||||||||||||||||
| 3377 | { | - | ||||||||||||||||||
| 3378 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3379 | QModelIndex index = qFileDialogUi->listView->currentIndex(); | - | ||||||||||||||||||
| 3380 | index = index.sibling(index.row(), 0); | - | ||||||||||||||||||
| 3381 | if (q->viewMode() == QFileDialog::List) | - | ||||||||||||||||||
| 3382 | qFileDialogUi->listView->edit(index); | - | ||||||||||||||||||
| 3383 | else | - | ||||||||||||||||||
| 3384 | qFileDialogUi->treeView->edit(index); | - | ||||||||||||||||||
| 3385 | } | - | ||||||||||||||||||
| 3386 | - | |||||||||||||||||||
| 3387 | bool QFileDialogPrivate::removeDirectory(const QString &path) | - | ||||||||||||||||||
| 3388 | { | - | ||||||||||||||||||
| 3389 | QModelIndex modelIndex = model->index(path); | - | ||||||||||||||||||
| 3390 | return model->remove(modelIndex); | - | ||||||||||||||||||
| 3391 | } | - | ||||||||||||||||||
| 3392 | - | |||||||||||||||||||
| 3393 | /*! | - | ||||||||||||||||||
| 3394 | \internal | - | ||||||||||||||||||
| 3395 | - | |||||||||||||||||||
| 3396 | Deletes the currently selected item in the dialog. | - | ||||||||||||||||||
| 3397 | */ | - | ||||||||||||||||||
| 3398 | void QFileDialogPrivate::_q_deleteCurrent() | - | ||||||||||||||||||
| 3399 | { | - | ||||||||||||||||||
| 3400 | if (model->isReadOnly()) | - | ||||||||||||||||||
| 3401 | return; | - | ||||||||||||||||||
| 3402 | - | |||||||||||||||||||
| 3403 | QModelIndexList list = qFileDialogUi->listView->selectionModel()->selectedRows(); | - | ||||||||||||||||||
| 3404 | for (int i = list.count() - 1; i >= 0; --i) { | - | ||||||||||||||||||
| 3405 | QModelIndex index = list.at(i); | - | ||||||||||||||||||
| 3406 | if (index == qFileDialogUi->listView->rootIndex()) | - | ||||||||||||||||||
| 3407 | continue; | - | ||||||||||||||||||
| 3408 | - | |||||||||||||||||||
| 3409 | index = mapToSource(index.sibling(index.row(), 0)); | - | ||||||||||||||||||
| 3410 | if (!index.isValid()) | - | ||||||||||||||||||
| 3411 | continue; | - | ||||||||||||||||||
| 3412 | - | |||||||||||||||||||
| 3413 | QString fileName = index.data(QFileSystemModel::FileNameRole).toString(); | - | ||||||||||||||||||
| 3414 | QString filePath = index.data(QFileSystemModel::FilePathRole).toString(); | - | ||||||||||||||||||
| 3415 | bool isDir = model->isDir(index); | - | ||||||||||||||||||
| 3416 | - | |||||||||||||||||||
| 3417 | QFile::Permissions p(index.parent().data(QFileSystemModel::FilePermissions).toInt()); | - | ||||||||||||||||||
| 3418 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||||||||
| 3419 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3420 | if (!(p & QFile::WriteUser) && (QMessageBox::warning(q_func(), QFileDialog::tr("Delete"), | - | ||||||||||||||||||
| 3421 | QFileDialog::tr("'%1' is write protected.\nDo you want to delete it anyway?") | - | ||||||||||||||||||
| 3422 | .arg(fileName), | - | ||||||||||||||||||
| 3423 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No)) | - | ||||||||||||||||||
| 3424 | return; | - | ||||||||||||||||||
| 3425 | else if (QMessageBox::warning(q_func(), QFileDialog::tr("Delete"), | - | ||||||||||||||||||
| 3426 | QFileDialog::tr("Are you sure you want to delete '%1'?") | - | ||||||||||||||||||
| 3427 | .arg(fileName), | - | ||||||||||||||||||
| 3428 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No) | - | ||||||||||||||||||
| 3429 | return; | - | ||||||||||||||||||
| 3430 | - | |||||||||||||||||||
| 3431 | #else | - | ||||||||||||||||||
| 3432 | if (!(p & QFile::WriteUser)) | - | ||||||||||||||||||
| 3433 | return; | - | ||||||||||||||||||
| 3434 | #endif // QT_NO_MESSAGEBOX | - | ||||||||||||||||||
| 3435 | - | |||||||||||||||||||
| 3436 | // the event loop has run, we can NOT reuse index because the model might have removed it. | - | ||||||||||||||||||
| 3437 | if (isDir) { | - | ||||||||||||||||||
| 3438 | if (!removeDirectory(filePath)) { | - | ||||||||||||||||||
| 3439 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||||||||
| 3440 | QMessageBox::warning(q, q->windowTitle(), | - | ||||||||||||||||||
| 3441 | QFileDialog::tr("Could not delete directory.")); | - | ||||||||||||||||||
| 3442 | #endif | - | ||||||||||||||||||
| 3443 | } | - | ||||||||||||||||||
| 3444 | } else { | - | ||||||||||||||||||
| 3445 | model->remove(index); | - | ||||||||||||||||||
| 3446 | } | - | ||||||||||||||||||
| 3447 | } | - | ||||||||||||||||||
| 3448 | } | - | ||||||||||||||||||
| 3449 | - | |||||||||||||||||||
| 3450 | void QFileDialogPrivate::_q_autoCompleteFileName(const QString &text) | - | ||||||||||||||||||
| 3451 | { | - | ||||||||||||||||||
| 3452 | if (text.startsWith(QLatin1String("//")) || text.startsWith(QLatin1Char('\\'))) {
| 0 | ||||||||||||||||||
| 3453 | qFileDialogUi->listView->selectionModel()->clearSelection(); | - | ||||||||||||||||||
| 3454 | return; never executed: return; | 0 | ||||||||||||||||||
| 3455 | } | - | ||||||||||||||||||
| 3456 | - | |||||||||||||||||||
| 3457 | const QStringList multipleFiles = typedFiles(); | - | ||||||||||||||||||
| 3458 | if (multipleFiles.count() > 0) {
| 0 | ||||||||||||||||||
| 3459 | QModelIndexList oldFiles = qFileDialogUi->listView->selectionModel()->selectedRows(); | - | ||||||||||||||||||
| 3460 | QModelIndexListQVector<QModelIndex> newFiles; | - | ||||||||||||||||||
| 3461 | for (int i = 0; i <const auto &file : multipleFiles.count(); ++i) { | - | ||||||||||||||||||
| 3462 | QModelIndex idx = model->index(multipleFiles.at(i));file); | - | ||||||||||||||||||
| 3463 | if (oldFiles.contains(idx))oldFiles.removeAll(idx);
| 0 | ||||||||||||||||||
else
| ||||||||||||||||||||
| 3464 | newFiles.append(idx); never executed: newFiles.append(idx); | 0 | ||||||||||||||||||
| 3465 | } never executed: end of block | 0 | ||||||||||||||||||
| 3466 | for (int i = 0; i < newFiles.count(); ++i)
| 0 | ||||||||||||||||||
| 3467 | select(newFiles.at(i)); never executed: select(newFiles.at(i)); | 0 | ||||||||||||||||||
| 3468 | if (lineEdit()->hasFocus())
| 0 | ||||||||||||||||||
| 3469 | for (int i = 0; i < oldFiles.count(); ++i)
| 0 | ||||||||||||||||||
| 3470 | qFileDialogUi->listView->selectionModel()->select(oldFiles.at(i), never executed: qFileDialogUi->listView->selectionModel()->select(oldFiles.at(i), QItemSelectionModel::Toggle | QItemSelectionModel::Rows); | 0 | ||||||||||||||||||
| 3471 | QItemSelectionModel::Toggle | QItemSelectionModel::Rows); never executed: qFileDialogUi->listView->selectionModel()->select(oldFiles.at(i), QItemSelectionModel::Toggle | QItemSelectionModel::Rows); | 0 | ||||||||||||||||||
| 3472 | } never executed: end of block | 0 | ||||||||||||||||||
| 3473 | } never executed: end of block | 0 | ||||||||||||||||||
| 3474 | - | |||||||||||||||||||
| 3475 | /*! | - | ||||||||||||||||||
| 3476 | \internal | - | ||||||||||||||||||
| 3477 | */ | - | ||||||||||||||||||
| 3478 | void QFileDialogPrivate::_q_updateOkButton() | - | ||||||||||||||||||
| 3479 | { | - | ||||||||||||||||||
| 3480 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3481 | QPushButton *button = qFileDialogUi->buttonBox->button((q->acceptMode() == QFileDialog::AcceptOpen) | - | ||||||||||||||||||
| 3482 | ? QDialogButtonBox::Open : QDialogButtonBox::Save); | - | ||||||||||||||||||
| 3483 | if (!button)
| 0 | ||||||||||||||||||
| 3484 | return; never executed: return; | 0 | ||||||||||||||||||
| 3485 | const QFileDialog::FileMode fileMode = q->fileMode(); | - | ||||||||||||||||||
| 3486 | - | |||||||||||||||||||
| 3487 | bool enableButton = true; | - | ||||||||||||||||||
| 3488 | bool isOpenDirectory = false; | - | ||||||||||||||||||
| 3489 | - | |||||||||||||||||||
| 3490 | const QStringList files = q->selectedFiles(); | - | ||||||||||||||||||
| 3491 | QString lineEditText = lineEdit()->text(); | - | ||||||||||||||||||
| 3492 | - | |||||||||||||||||||
| 3493 | if (lineEditText.startsWith(QLatin1String("//")) || lineEditText.startsWith(QLatin1Char('\\'))) {
| 0 | ||||||||||||||||||
| 3494 | button->setEnabled(true); | - | ||||||||||||||||||
| 3495 | updateOkButtonText(); | - | ||||||||||||||||||
| 3496 | return; never executed: return; | 0 | ||||||||||||||||||
| 3497 | } | - | ||||||||||||||||||
| 3498 | - | |||||||||||||||||||
| 3499 | if (files.isEmpty()) {
| 0 | ||||||||||||||||||
| 3500 | enableButton = false; | - | ||||||||||||||||||
| 3501 | } else if (lineEditText == QLatin1String("..")) { never executed: end of block
| 0 | ||||||||||||||||||
| 3502 | isOpenDirectory = true; | - | ||||||||||||||||||
| 3503 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 3504 | switch (fileMode) { | - | ||||||||||||||||||
| 3505 | case QFileDialog::DirectoryOnly: never executed: case QFileDialog::DirectoryOnly: | 0 | ||||||||||||||||||
| 3506 | case QFileDialog::Directory: { never executed: case QFileDialog::Directory: | 0 | ||||||||||||||||||
| 3507 | QString fn = files.first(); | - | ||||||||||||||||||
| 3508 | QModelIndex idx = model->index(fn); | - | ||||||||||||||||||
| 3509 | if (!idx.isValid())
| 0 | ||||||||||||||||||
| 3510 | idx = model->index(getEnvironmentVariable(fn)); never executed: idx = model->index(getEnvironmentVariable(fn)); | 0 | ||||||||||||||||||
| 3511 | if (!idx.isValid() || !model->isDir(idx))
| 0 | ||||||||||||||||||
| 3512 | enableButton = false; never executed: enableButton = false; | 0 | ||||||||||||||||||
| 3513 | break; never executed: break; | 0 | ||||||||||||||||||
| 3514 | } | - | ||||||||||||||||||
| 3515 | case QFileDialog::AnyFile: { never executed: case QFileDialog::AnyFile: | 0 | ||||||||||||||||||
| 3516 | QString fn = files.first(); | - | ||||||||||||||||||
| 3517 | QFileInfo info(fn); | - | ||||||||||||||||||
| 3518 | QModelIndex idx = model->index(fn); | - | ||||||||||||||||||
| 3519 | QString fileDir; | - | ||||||||||||||||||
| 3520 | QString fileName; | - | ||||||||||||||||||
| 3521 | if (info.isDir()) {
| 0 | ||||||||||||||||||
| 3522 | fileDir = info.canonicalFilePath(); | - | ||||||||||||||||||
| 3523 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 3524 | fileDir = fn.mid(0, fn.lastIndexOf(QLatin1Char('/'))); | - | ||||||||||||||||||
| 3525 | fileName = fn.mid(fileDir.length() + 1); | - | ||||||||||||||||||
| 3526 | } never executed: end of block | 0 | ||||||||||||||||||
| 3527 | if (lineEditText.contains(QLatin1String(".."))) {
| 0 | ||||||||||||||||||
| 3528 | fileDir = info.canonicalFilePath(); | - | ||||||||||||||||||
| 3529 | fileName = info.fileName(); | - | ||||||||||||||||||
| 3530 | } never executed: end of block | 0 | ||||||||||||||||||
| 3531 | - | |||||||||||||||||||
| 3532 | if (fileDir == q->directory().canonicalPath() && fileName.isEmpty()) {
| 0 | ||||||||||||||||||
| 3533 | enableButton = false; | - | ||||||||||||||||||
| 3534 | break; never executed: break; | 0 | ||||||||||||||||||
| 3535 | } | - | ||||||||||||||||||
| 3536 | if (idx.isValid() && model->isDir(idx)) {
| 0 | ||||||||||||||||||
| 3537 | isOpenDirectory = true; | - | ||||||||||||||||||
| 3538 | enableButton = true; | - | ||||||||||||||||||
| 3539 | break; never executed: break; | 0 | ||||||||||||||||||
| 3540 | } | - | ||||||||||||||||||
| 3541 | if (!idx.isValid()) {
| 0 | ||||||||||||||||||
| 3542 | int maxLength = maxNameLength(fileDir); | - | ||||||||||||||||||
| 3543 | enableButton = maxLength < 0 || fileName.length() <= maxLength;
| 0 | ||||||||||||||||||
| 3544 | } never executed: end of block | 0 | ||||||||||||||||||
| 3545 | break; never executed: break; | 0 | ||||||||||||||||||
| 3546 | } | - | ||||||||||||||||||
| 3547 | case QFileDialog::ExistingFile: never executed: case QFileDialog::ExistingFile: | 0 | ||||||||||||||||||
| 3548 | case QFileDialog::ExistingFiles: never executed: case QFileDialog::ExistingFiles: | 0 | ||||||||||||||||||
| 3549 | for (int i = 0; i <const auto &file : files.count(); ++i) { | - | ||||||||||||||||||
| 3550 | QModelIndex idx = model->index(files.at(i));file); | - | ||||||||||||||||||
| 3551 | if (!idx.isValid())
| 0 | ||||||||||||||||||
| 3552 | idx = model->index(getEnvironmentVariable(files.at(i)));file)); never executed: idx = model->index(getEnvironmentVariable(file)); | 0 | ||||||||||||||||||
| 3553 | if (!idx.isValid()) {
| 0 | ||||||||||||||||||
| 3554 | enableButton = false; | - | ||||||||||||||||||
| 3555 | break; never executed: break; | 0 | ||||||||||||||||||
| 3556 | } | - | ||||||||||||||||||
| 3557 | if (idx.isValid() && model->isDir(idx)) {
| 0 | ||||||||||||||||||
| 3558 | isOpenDirectory = true; | - | ||||||||||||||||||
| 3559 | break; never executed: break; | 0 | ||||||||||||||||||
| 3560 | } | - | ||||||||||||||||||
| 3561 | } never executed: end of block | 0 | ||||||||||||||||||
| 3562 | break; never executed: break; | 0 | ||||||||||||||||||
| 3563 | default: never executed: default: | 0 | ||||||||||||||||||
| 3564 | break; never executed: break; | 0 | ||||||||||||||||||
| 3565 | } | - | ||||||||||||||||||
| 3566 | } | - | ||||||||||||||||||
| 3567 | - | |||||||||||||||||||
| 3568 | button->setEnabled(enableButton); | - | ||||||||||||||||||
| 3569 | updateOkButtonText(isOpenDirectory); | - | ||||||||||||||||||
| 3570 | } never executed: end of block | 0 | ||||||||||||||||||
| 3571 | - | |||||||||||||||||||
| 3572 | /*! | - | ||||||||||||||||||
| 3573 | \internal | - | ||||||||||||||||||
| 3574 | */ | - | ||||||||||||||||||
| 3575 | void QFileDialogPrivate::_q_currentChanged(const QModelIndex &index) | - | ||||||||||||||||||
| 3576 | { | - | ||||||||||||||||||
| 3577 | _q_updateOkButton(); | - | ||||||||||||||||||
| 3578 | emit q_func()->currentChanged(index.data(QFileSystemModel::FilePathRole).toString()); | - | ||||||||||||||||||
| 3579 | } | - | ||||||||||||||||||
| 3580 | - | |||||||||||||||||||
| 3581 | /*! | - | ||||||||||||||||||
| 3582 | \internal | - | ||||||||||||||||||
| 3583 | - | |||||||||||||||||||
| 3584 | This is called when the user double clicks on a file with the corresponding | - | ||||||||||||||||||
| 3585 | model item \a index. | - | ||||||||||||||||||
| 3586 | */ | - | ||||||||||||||||||
| 3587 | void QFileDialogPrivate::_q_enterDirectory(const QModelIndex &index) | - | ||||||||||||||||||
| 3588 | { | - | ||||||||||||||||||
| 3589 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3590 | // My Computer or a directory | - | ||||||||||||||||||
| 3591 | QModelIndex sourceIndex = index.model() == proxyModel ? mapToSource(index) : index; | - | ||||||||||||||||||
| 3592 | QString path = sourceIndex.data(QFileSystemModel::FilePathRole).toString(); | - | ||||||||||||||||||
| 3593 | if (path.isEmpty() || model->isDir(sourceIndex)) { | - | ||||||||||||||||||
| 3594 | const QFileDialog::FileMode fileMode = q->fileMode(); | - | ||||||||||||||||||
| 3595 | q->setDirectory(path); | - | ||||||||||||||||||
| 3596 | emit q->directoryEntered(path); | - | ||||||||||||||||||
| 3597 | if (fileMode == QFileDialog::Directory | - | ||||||||||||||||||
| 3598 | || fileMode == QFileDialog::DirectoryOnly) { | - | ||||||||||||||||||
| 3599 | // ### find out why you have to do both of these. | - | ||||||||||||||||||
| 3600 | lineEdit()->setText(QString()); | - | ||||||||||||||||||
| 3601 | lineEdit()->clear(); | - | ||||||||||||||||||
| 3602 | } | - | ||||||||||||||||||
| 3603 | } else { | - | ||||||||||||||||||
| 3604 | // Do not accept when shift-clicking to multi-select a file in environments with single-click-activation (KDE) | - | ||||||||||||||||||
| 3605 | if (!q->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, Q_NULLPTR, qFileDialogUi->treeView) | - | ||||||||||||||||||
| 3606 | || q->fileMode() != QFileDialog::ExistingFiles || !(QGuiApplication::keyboardModifiers() & Qt::CTRL)) { | - | ||||||||||||||||||
| 3607 | q->accept(); | - | ||||||||||||||||||
| 3608 | } | - | ||||||||||||||||||
| 3609 | } | - | ||||||||||||||||||
| 3610 | } | - | ||||||||||||||||||
| 3611 | - | |||||||||||||||||||
| 3612 | /*! | - | ||||||||||||||||||
| 3613 | \internal | - | ||||||||||||||||||
| 3614 | - | |||||||||||||||||||
| 3615 | Changes the file dialog's current directory to the one specified | - | ||||||||||||||||||
| 3616 | by \a path. | - | ||||||||||||||||||
| 3617 | */ | - | ||||||||||||||||||
| 3618 | void QFileDialogPrivate::_q_goToDirectory(const QString &path) | - | ||||||||||||||||||
| 3619 | { | - | ||||||||||||||||||
| 3620 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||||||||
| 3621 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3622 | #endif | - | ||||||||||||||||||
| 3623 | QModelIndex index = qFileDialogUi->lookInCombo->model()->index(qFileDialogUi->lookInCombo->currentIndex(), | - | ||||||||||||||||||
| 3624 | qFileDialogUi->lookInCombo->modelColumn(), | - | ||||||||||||||||||
| 3625 | qFileDialogUi->lookInCombo->rootModelIndex()); | - | ||||||||||||||||||
| 3626 | QString path2 = path; | - | ||||||||||||||||||
| 3627 | if (!index.isValid()) | - | ||||||||||||||||||
| 3628 | index = mapFromSource(model->index(getEnvironmentVariable(path))); | - | ||||||||||||||||||
| 3629 | else { | - | ||||||||||||||||||
| 3630 | path2 = index.data(UrlRole).toUrl().toLocalFile(); | - | ||||||||||||||||||
| 3631 | index = mapFromSource(model->index(path2)); | - | ||||||||||||||||||
| 3632 | } | - | ||||||||||||||||||
| 3633 | QDir dir(path2); | - | ||||||||||||||||||
| 3634 | if (!dir.exists()) | - | ||||||||||||||||||
| 3635 | dir = getEnvironmentVariable(path2); | - | ||||||||||||||||||
| 3636 | - | |||||||||||||||||||
| 3637 | if (dir.exists() || path2.isEmpty() || path2 == model->myComputer().toString()) { | - | ||||||||||||||||||
| 3638 | _q_enterDirectory(index); | - | ||||||||||||||||||
| 3639 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||||||||
| 3640 | } else { | - | ||||||||||||||||||
| 3641 | QString message = QFileDialog::tr("%1\nDirectory not found.\nPlease verify the " | - | ||||||||||||||||||
| 3642 | "correct directory name was given."); | - | ||||||||||||||||||
| 3643 | QMessageBox::warning(q, q->windowTitle(), message.arg(path2)); | - | ||||||||||||||||||
| 3644 | #endif // QT_NO_MESSAGEBOX | - | ||||||||||||||||||
| 3645 | } | - | ||||||||||||||||||
| 3646 | } | - | ||||||||||||||||||
| 3647 | - | |||||||||||||||||||
| 3648 | /*! | - | ||||||||||||||||||
| 3649 | \internal | - | ||||||||||||||||||
| 3650 | - | |||||||||||||||||||
| 3651 | Sets the current name filter to be nameFilter and | - | ||||||||||||||||||
| 3652 | update the qFileDialogUi->fileNameEdit when in AcceptSave mode with the new extension. | - | ||||||||||||||||||
| 3653 | */ | - | ||||||||||||||||||
| 3654 | void QFileDialogPrivate::_q_useNameFilter(int index) | - | ||||||||||||||||||
| 3655 | { | - | ||||||||||||||||||
| 3656 | QStringList nameFilters = options->nameFilters(); | - | ||||||||||||||||||
| 3657 | if (index == nameFilters.size()) { | - | ||||||||||||||||||
| 3658 | QAbstractItemModel *comboModel = qFileDialogUi->fileTypeCombo->model(); | - | ||||||||||||||||||
| 3659 | nameFilters.append(comboModel->index(comboModel->rowCount() - 1, 0).data().toString()); | - | ||||||||||||||||||
| 3660 | options->setNameFilters(nameFilters); | - | ||||||||||||||||||
| 3661 | } | - | ||||||||||||||||||
| 3662 | - | |||||||||||||||||||
| 3663 | QString nameFilter = nameFilters.at(index); | - | ||||||||||||||||||
| 3664 | QStringList newNameFilters = QPlatformFileDialogHelper::cleanFilterList(nameFilter); | - | ||||||||||||||||||
| 3665 | if (q_func()->acceptMode() == QFileDialog::AcceptSave) { | - | ||||||||||||||||||
| 3666 | QString newNameFilterExtension; | - | ||||||||||||||||||
| 3667 | if (newNameFilters.count() > 0) | - | ||||||||||||||||||
| 3668 | newNameFilterExtension = QFileInfo(newNameFilters.at(0)).suffix(); | - | ||||||||||||||||||
| 3669 | - | |||||||||||||||||||
| 3670 | QString fileName = lineEdit()->text(); | - | ||||||||||||||||||
| 3671 | const QString fileNameExtension = QFileInfo(fileName).suffix(); | - | ||||||||||||||||||
| 3672 | if (!fileNameExtension.isEmpty() && !newNameFilterExtension.isEmpty()) { | - | ||||||||||||||||||
| 3673 | const int fileNameExtensionLength = fileNameExtension.count(); | - | ||||||||||||||||||
| 3674 | fileName.replace(fileName.count() - fileNameExtensionLength, | - | ||||||||||||||||||
| 3675 | fileNameExtensionLength, newNameFilterExtension); | - | ||||||||||||||||||
| 3676 | qFileDialogUi->listView->clearSelection(); | - | ||||||||||||||||||
| 3677 | lineEdit()->setText(fileName); | - | ||||||||||||||||||
| 3678 | } | - | ||||||||||||||||||
| 3679 | } | - | ||||||||||||||||||
| 3680 | - | |||||||||||||||||||
| 3681 | model->setNameFilters(newNameFilters); | - | ||||||||||||||||||
| 3682 | } | - | ||||||||||||||||||
| 3683 | - | |||||||||||||||||||
| 3684 | /*! | - | ||||||||||||||||||
| 3685 | \internal | - | ||||||||||||||||||
| 3686 | - | |||||||||||||||||||
| 3687 | This is called when the model index corresponding to the current file is changed | - | ||||||||||||||||||
| 3688 | from \a index to \a current. | - | ||||||||||||||||||
| 3689 | */ | - | ||||||||||||||||||
| 3690 | void QFileDialogPrivate::_q_selectionChanged() | - | ||||||||||||||||||
| 3691 | { | - | ||||||||||||||||||
| 3692 | const QFileDialog::FileMode fileMode = q_func()->fileMode(); | - | ||||||||||||||||||
| 3693 | const QModelIndexList indexes = qFileDialogUi->listView->selectionModel()->selectedRows(); | - | ||||||||||||||||||
| 3694 | bool stripDirs = (fileMode != QFileDialog::DirectoryOnly && fileMode != QFileDialog::Directory);
| 0 | ||||||||||||||||||
| 3695 | - | |||||||||||||||||||
| 3696 | QStringList allFiles; | - | ||||||||||||||||||
| 3697 | for (int i = 0; i <const auto &index : indexes.count(); ++i) { | - | ||||||||||||||||||
| 3698 | if (stripDirs && model->isDir(mapToSource(indexes.at(i))))index)))
| 0 | ||||||||||||||||||
| 3699 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 3700 | allFiles.append(indexesindex.at(i).data().toString()); | - | ||||||||||||||||||
| 3701 | } never executed: end of block | 0 | ||||||||||||||||||
| 3702 | if (allFiles.count() > 1)
| 0 | ||||||||||||||||||
| 3703 | for (int i = 0; i < allFiles.count(); ++i) {
| 0 | ||||||||||||||||||
| 3704 | allFiles.replace(i, QString(QLatin1Char('"') + allFiles.at(i) + QLatin1Char('"'))); | - | ||||||||||||||||||
| 3705 | } never executed: end of block | 0 | ||||||||||||||||||
| 3706 | - | |||||||||||||||||||
| 3707 | QString finalFiles = allFiles.join(QLatin1Char(' ')); | - | ||||||||||||||||||
| 3708 | if (!finalFiles.isEmpty() && !lineEdit()->hasFocus() && lineEdit()->isVisible())
| 0 | ||||||||||||||||||
| 3709 | lineEdit()->setText(finalFiles); never executed: lineEdit()->setText(finalFiles); | 0 | ||||||||||||||||||
| 3710 | else | - | ||||||||||||||||||
| 3711 | _q_updateOkButton(); never executed: _q_updateOkButton(); | 0 | ||||||||||||||||||
| 3712 | } | - | ||||||||||||||||||
| 3713 | - | |||||||||||||||||||
| 3714 | /*! | - | ||||||||||||||||||
| 3715 | \internal | - | ||||||||||||||||||
| 3716 | - | |||||||||||||||||||
| 3717 | Includes hidden files and directories in the items displayed in the dialog. | - | ||||||||||||||||||
| 3718 | */ | - | ||||||||||||||||||
| 3719 | void QFileDialogPrivate::_q_showHidden() | - | ||||||||||||||||||
| 3720 | { | - | ||||||||||||||||||
| 3721 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3722 | QDir::Filters dirFilters = q->filter(); | - | ||||||||||||||||||
| 3723 | if (showHiddenAction->isChecked()) | - | ||||||||||||||||||
| dirFilters |= QDir::Hidden; | ||||||||||||||||||||
| elsedirFilters&= ~.setFlag(QDir::Hidden;, showHiddenAction->isChecked()); | ||||||||||||||||||||
| 3724 | q->setFilter(dirFilters); | - | ||||||||||||||||||
| 3725 | } never executed: end of block | 0 | ||||||||||||||||||
| 3726 | - | |||||||||||||||||||
| 3727 | /*! | - | ||||||||||||||||||
| 3728 | \internal | - | ||||||||||||||||||
| 3729 | - | |||||||||||||||||||
| 3730 | When parent is root and rows have been inserted when none was there before | - | ||||||||||||||||||
| 3731 | then select the first one. | - | ||||||||||||||||||
| 3732 | */ | - | ||||||||||||||||||
| 3733 | void QFileDialogPrivate::_q_rowsInserted(const QModelIndex &parent) | - | ||||||||||||||||||
| 3734 | { | - | ||||||||||||||||||
| 3735 | if (!qFileDialogUi->treeView | - | ||||||||||||||||||
| 3736 | || parent != qFileDialogUi->treeView->rootIndex() | - | ||||||||||||||||||
| 3737 | || !qFileDialogUi->treeView->selectionModel() | - | ||||||||||||||||||
| 3738 | || qFileDialogUi->treeView->selectionModel()->hasSelection() | - | ||||||||||||||||||
| 3739 | || qFileDialogUi->treeView->model()->rowCount(parent) == 0) | - | ||||||||||||||||||
| 3740 | return; | - | ||||||||||||||||||
| 3741 | } | - | ||||||||||||||||||
| 3742 | - | |||||||||||||||||||
| 3743 | void QFileDialogPrivate::_q_fileRenamed(const QString &path, const QString &oldName, const QString &newName) | - | ||||||||||||||||||
| 3744 | { | - | ||||||||||||||||||
| 3745 | const QFileDialog::FileMode fileMode = q_func()->fileMode(); | - | ||||||||||||||||||
| 3746 | if (fileMode == QFileDialog::Directory || fileMode == QFileDialog::DirectoryOnly) { | - | ||||||||||||||||||
| 3747 | if (path == rootPath() && lineEdit()->text() == oldName) | - | ||||||||||||||||||
| 3748 | lineEdit()->setText(newName); | - | ||||||||||||||||||
| 3749 | } | - | ||||||||||||||||||
| 3750 | } | - | ||||||||||||||||||
| 3751 | - | |||||||||||||||||||
| 3752 | void QFileDialogPrivate::_q_emitUrlSelected(const QUrl &file) | - | ||||||||||||||||||
| 3753 | { | - | ||||||||||||||||||
| 3754 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3755 | emit q->urlSelected(file); | - | ||||||||||||||||||
| 3756 | if (file.isLocalFile()) | - | ||||||||||||||||||
| 3757 | emit q->fileSelected(file.toLocalFile()); | - | ||||||||||||||||||
| 3758 | } | - | ||||||||||||||||||
| 3759 | - | |||||||||||||||||||
| 3760 | void QFileDialogPrivate::_q_emitUrlsSelected(const QList<QUrl> &files) | - | ||||||||||||||||||
| 3761 | { | - | ||||||||||||||||||
| 3762 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3763 | emit q->urlsSelected(files); | - | ||||||||||||||||||
| 3764 | QStringList localFiles; | - | ||||||||||||||||||
| 3765 | foreachfor (const QUrl &file ,: files) | - | ||||||||||||||||||
| 3766 | if (file.isLocalFile())
| 0 | ||||||||||||||||||
| 3767 | localFiles.append(file.toLocalFile()); never executed: localFiles.append(file.toLocalFile()); | 0 | ||||||||||||||||||
| 3768 | if (!localFiles.isEmpty())
| 0 | ||||||||||||||||||
| 3769 | emit q->filesSelected(localFiles); never executed: q->filesSelected(localFiles); | 0 | ||||||||||||||||||
| 3770 | } never executed: end of block | 0 | ||||||||||||||||||
| 3771 | - | |||||||||||||||||||
| 3772 | void QFileDialogPrivate::_q_nativeCurrentChanged(const QUrl &file) | - | ||||||||||||||||||
| 3773 | { | - | ||||||||||||||||||
| 3774 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3775 | emit q->currentUrlChanged(file); | - | ||||||||||||||||||
| 3776 | if (file.isLocalFile()) | - | ||||||||||||||||||
| 3777 | emit q->currentChanged(file.toLocalFile()); | - | ||||||||||||||||||
| 3778 | } | - | ||||||||||||||||||
| 3779 | - | |||||||||||||||||||
| 3780 | void QFileDialogPrivate::_q_nativeEnterDirectory(const QUrl &directory) | - | ||||||||||||||||||
| 3781 | { | - | ||||||||||||||||||
| 3782 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3783 | emit q->directoryUrlEntered(directory); | - | ||||||||||||||||||
| 3784 | if (!directory.isEmpty()) { // Windows native dialogs occasionally emit signals with empty strings. | - | ||||||||||||||||||
| 3785 | *lastVisitedDir() = directory; | - | ||||||||||||||||||
| 3786 | if (directory.isLocalFile()) | - | ||||||||||||||||||
| 3787 | emit q->directoryEntered(directory.toLocalFile()); | - | ||||||||||||||||||
| 3788 | } | - | ||||||||||||||||||
| 3789 | } | - | ||||||||||||||||||
| 3790 | - | |||||||||||||||||||
| 3791 | /*! | - | ||||||||||||||||||
| 3792 | \internal | - | ||||||||||||||||||
| 3793 | - | |||||||||||||||||||
| 3794 | For the list and tree view watch keys to goto parent and back in the history | - | ||||||||||||||||||
| 3795 | - | |||||||||||||||||||
| 3796 | returns \c true if handled | - | ||||||||||||||||||
| 3797 | */ | - | ||||||||||||||||||
| 3798 | bool QFileDialogPrivate::itemViewKeyboardEvent(QKeyEvent *event) { | - | ||||||||||||||||||
| 3799 | - | |||||||||||||||||||
| 3800 | Q_Q(QFileDialog); | - | ||||||||||||||||||
| 3801 | - | |||||||||||||||||||
| 3802 | if (event->matches(QKeySequence::Cancel)) { | - | ||||||||||||||||||
| 3803 | q->reject(); | - | ||||||||||||||||||
| 3804 | return true; | - | ||||||||||||||||||
| 3805 | } | - | ||||||||||||||||||
| 3806 | - | |||||||||||||||||||
| 3807 | switch (event->key()) { | - | ||||||||||||||||||
| 3808 | case Qt::Key_Backspace: | - | ||||||||||||||||||
| 3809 | _q_navigateToParent(); | - | ||||||||||||||||||
| 3810 | return true; | - | ||||||||||||||||||
| 3811 | case Qt::Key_Back: | - | ||||||||||||||||||
| 3812 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 3813 | if (QApplication::keypadNavigationEnabled()) | - | ||||||||||||||||||
| 3814 | return false; | - | ||||||||||||||||||
| 3815 | #endif | - | ||||||||||||||||||
| 3816 | case Qt::Key_Left: | - | ||||||||||||||||||
| 3817 | if (event->key() == Qt::Key_Back || event->modifiers() == Qt::AltModifier) { | - | ||||||||||||||||||
| 3818 | _q_navigateBackward(); | - | ||||||||||||||||||
| 3819 | return true; | - | ||||||||||||||||||
| 3820 | } | - | ||||||||||||||||||
| 3821 | break; | - | ||||||||||||||||||
| 3822 | default: | - | ||||||||||||||||||
| 3823 | break; | - | ||||||||||||||||||
| 3824 | } | - | ||||||||||||||||||
| 3825 | return false; | - | ||||||||||||||||||
| 3826 | } | - | ||||||||||||||||||
| 3827 | - | |||||||||||||||||||
| 3828 | QString QFileDialogPrivate::getEnvironmentVariable(const QString &string) | - | ||||||||||||||||||
| 3829 | { | - | ||||||||||||||||||
| 3830 | #ifdef Q_OS_UNIX | - | ||||||||||||||||||
| 3831 | if (string.size() > 1 && string.startsWith(QLatin1Char('$'))) {
| 0 | ||||||||||||||||||
| 3832 | return QString::fromLocal8Bit(qgetenv(string.midmidRef(1).toLatin1().constData())); never executed: return QString::fromLocal8Bit(qgetenv(string.midRef(1).toLatin1().constData())); | 0 | ||||||||||||||||||
| 3833 | } | - | ||||||||||||||||||
| 3834 | #else | - | ||||||||||||||||||
| 3835 | if (string.size() > 2 && string.startsWith(QLatin1Char('%')) && string.endsWith(QLatin1Char('%'))) { | - | ||||||||||||||||||
| 3836 | return QString::fromLocal8Bit(qgetenv(string.midmidRef(1, string.size() - 2).toLatin1().constData())); | - | ||||||||||||||||||
| 3837 | } | - | ||||||||||||||||||
| 3838 | #endif | - | ||||||||||||||||||
| 3839 | return string; never executed: return string; | 0 | ||||||||||||||||||
| 3840 | } | - | ||||||||||||||||||
| 3841 | - | |||||||||||||||||||
| 3842 | void QFileDialogComboBox::setFileDialogPrivate(QFileDialogPrivate *d_pointer) { | - | ||||||||||||||||||
| 3843 | d_ptr = d_pointer; | - | ||||||||||||||||||
| 3844 | urlModel = new QUrlModel(this); | - | ||||||||||||||||||
| 3845 | urlModel->showFullPath = true; | - | ||||||||||||||||||
| 3846 | urlModel->setFileSystemModel(d_ptr->model); | - | ||||||||||||||||||
| 3847 | setModel(urlModel); | - | ||||||||||||||||||
| 3848 | } | - | ||||||||||||||||||
| 3849 | - | |||||||||||||||||||
| 3850 | void QFileDialogComboBox::showPopup() | - | ||||||||||||||||||
| 3851 | { | - | ||||||||||||||||||
| 3852 | if (model()->rowCount() > 1) | - | ||||||||||||||||||
| 3853 | QComboBox::showPopup(); | - | ||||||||||||||||||
| 3854 | - | |||||||||||||||||||
| 3855 | urlModel->setUrls(QList<QUrl>()); | - | ||||||||||||||||||
| 3856 | QList<QUrl> list; | - | ||||||||||||||||||
| 3857 | QModelIndex idx = d_ptr->model->index(d_ptr->rootPath()); | - | ||||||||||||||||||
| 3858 | while (idx.isValid()) { | - | ||||||||||||||||||
| 3859 | QUrl url = QUrl::fromLocalFile(idx.data(QFileSystemModel::FilePathRole).toString()); | - | ||||||||||||||||||
| 3860 | if (url.isValid()) | - | ||||||||||||||||||
| 3861 | list.append(url); | - | ||||||||||||||||||
| 3862 | idx = idx.parent(); | - | ||||||||||||||||||
| 3863 | } | - | ||||||||||||||||||
| 3864 | // add "my computer" | - | ||||||||||||||||||
| 3865 | list.append(QUrl(QLatin1String("file:"))); | - | ||||||||||||||||||
| 3866 | urlModel->addUrls(list, 0); | - | ||||||||||||||||||
| 3867 | idx = model()->index(model()->rowCount() - 1, 0); | - | ||||||||||||||||||
| 3868 | - | |||||||||||||||||||
| 3869 | // append history | - | ||||||||||||||||||
| 3870 | QList<QUrl> urls; | - | ||||||||||||||||||
| 3871 | for (int i = 0; i < m_history.count(); ++i) { | - | ||||||||||||||||||
| 3872 | QUrl path = QUrl::fromLocalFile(m_history.at(i)); | - | ||||||||||||||||||
| 3873 | if (!urls.contains(path)) | - | ||||||||||||||||||
| 3874 | urls.prepend(path); | - | ||||||||||||||||||
| 3875 | } | - | ||||||||||||||||||
| 3876 | if (urls.count() > 0) { | - | ||||||||||||||||||
| 3877 | model()->insertRow(model()->rowCount()); | - | ||||||||||||||||||
| 3878 | idx = model()->index(model()->rowCount()-1, 0); | - | ||||||||||||||||||
| 3879 | // ### TODO maybe add a horizontal line before this | - | ||||||||||||||||||
| 3880 | model()->setData(idx, QFileDialog::tr("Recent Places")); | - | ||||||||||||||||||
| 3881 | QStandardItemModel *m = qobject_cast<QStandardItemModel*>(model()); | - | ||||||||||||||||||
| 3882 | if (m) { | - | ||||||||||||||||||
| 3883 | Qt::ItemFlags flags = m->flags(idx); | - | ||||||||||||||||||
| 3884 | flags &= ~Qt::ItemIsEnabled; | - | ||||||||||||||||||
| 3885 | m->item(idx.row(), idx.column())->setFlags(flags); | - | ||||||||||||||||||
| 3886 | } | - | ||||||||||||||||||
| 3887 | urlModel->addUrls(urls, -1, false); | - | ||||||||||||||||||
| 3888 | } | - | ||||||||||||||||||
| 3889 | setCurrentIndex(0); | - | ||||||||||||||||||
| 3890 | - | |||||||||||||||||||
| 3891 | QComboBox::showPopup(); | - | ||||||||||||||||||
| 3892 | } | - | ||||||||||||||||||
| 3893 | - | |||||||||||||||||||
| 3894 | // Exact same as QComboBox::paintEvent(), except we elide the text. | - | ||||||||||||||||||
| 3895 | void QFileDialogComboBox::paintEvent(QPaintEvent *) | - | ||||||||||||||||||
| 3896 | { | - | ||||||||||||||||||
| 3897 | QStylePainter painter(this); | - | ||||||||||||||||||
| 3898 | painter.setPen(palette().color(QPalette::Text)); | - | ||||||||||||||||||
| 3899 | - | |||||||||||||||||||
| 3900 | // draw the combobox frame, focusrect and selected etc. | - | ||||||||||||||||||
| 3901 | QStyleOptionComboBox opt; | - | ||||||||||||||||||
| 3902 | initStyleOption(&opt); | - | ||||||||||||||||||
| 3903 | - | |||||||||||||||||||
| 3904 | QRect editRect = style()->subControlRect(QStyle::CC_ComboBox, &opt, | - | ||||||||||||||||||
| 3905 | QStyle::SC_ComboBoxEditField, this); | - | ||||||||||||||||||
| 3906 | int size = editRect.width() - opt.iconSize.width() - 4; | - | ||||||||||||||||||
| 3907 | opt.currentText = opt.fontMetrics.elidedText(opt.currentText, Qt::ElideMiddle, size); | - | ||||||||||||||||||
| 3908 | painter.drawComplexControl(QStyle::CC_ComboBox, opt); | - | ||||||||||||||||||
| 3909 | - | |||||||||||||||||||
| 3910 | // draw the icon and text | - | ||||||||||||||||||
| 3911 | painter.drawControl(QStyle::CE_ComboBoxLabel, opt); | - | ||||||||||||||||||
| 3912 | } | - | ||||||||||||||||||
| 3913 | - | |||||||||||||||||||
| 3914 | QFileDialogListView::QFileDialogListView(QWidget *parent) : QListView(parent) | - | ||||||||||||||||||
| 3915 | { | - | ||||||||||||||||||
| 3916 | } | - | ||||||||||||||||||
| 3917 | - | |||||||||||||||||||
| 3918 | void QFileDialogListView::setFileDialogPrivate(QFileDialogPrivate *d_pointer) | - | ||||||||||||||||||
| 3919 | { | - | ||||||||||||||||||
| 3920 | d_ptr = d_pointer; | - | ||||||||||||||||||
| 3921 | setSelectionBehavior(QAbstractItemView::SelectRows); | - | ||||||||||||||||||
| 3922 | setWrapping(true); | - | ||||||||||||||||||
| 3923 | setResizeMode(QListView::Adjust); | - | ||||||||||||||||||
| 3924 | setEditTriggers(QAbstractItemView::EditKeyPressed); | - | ||||||||||||||||||
| 3925 | setContextMenuPolicy(Qt::CustomContextMenu); | - | ||||||||||||||||||
| 3926 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||
| 3927 | setDragDropMode(QAbstractItemView::InternalMove); | - | ||||||||||||||||||
| 3928 | #endif | - | ||||||||||||||||||
| 3929 | } | - | ||||||||||||||||||
| 3930 | - | |||||||||||||||||||
| 3931 | QSize QFileDialogListView::sizeHint() const | - | ||||||||||||||||||
| 3932 | { | - | ||||||||||||||||||
| 3933 | int height = qMax(10, sizeHintForRow(0)); | - | ||||||||||||||||||
| 3934 | return QSize(QListView::sizeHint().width() * 2, height * 30); | - | ||||||||||||||||||
| 3935 | } | - | ||||||||||||||||||
| 3936 | - | |||||||||||||||||||
| 3937 | void QFileDialogListView::keyPressEvent(QKeyEvent *e) | - | ||||||||||||||||||
| 3938 | { | - | ||||||||||||||||||
| 3939 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 3940 | if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) { | - | ||||||||||||||||||
| 3941 | QListView::keyPressEvent(e); | - | ||||||||||||||||||
| 3942 | return; | - | ||||||||||||||||||
| 3943 | } | - | ||||||||||||||||||
| 3944 | #endif // QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 3945 | - | |||||||||||||||||||
| 3946 | if (!d_ptr->itemViewKeyboardEvent(e)) | - | ||||||||||||||||||
| 3947 | QListView::keyPressEvent(e); | - | ||||||||||||||||||
| 3948 | e->accept(); | - | ||||||||||||||||||
| 3949 | } | - | ||||||||||||||||||
| 3950 | - | |||||||||||||||||||
| 3951 | QFileDialogTreeView::QFileDialogTreeView(QWidget *parent) : QTreeView(parent) | - | ||||||||||||||||||
| 3952 | { | - | ||||||||||||||||||
| 3953 | } | - | ||||||||||||||||||
| 3954 | - | |||||||||||||||||||
| 3955 | void QFileDialogTreeView::setFileDialogPrivate(QFileDialogPrivate *d_pointer) | - | ||||||||||||||||||
| 3956 | { | - | ||||||||||||||||||
| 3957 | d_ptr = d_pointer; | - | ||||||||||||||||||
| 3958 | setSelectionBehavior(QAbstractItemView::SelectRows); | - | ||||||||||||||||||
| 3959 | setRootIsDecorated(false); | - | ||||||||||||||||||
| 3960 | setItemsExpandable(false); | - | ||||||||||||||||||
| 3961 | setSortingEnabled(true); | - | ||||||||||||||||||
| 3962 | header()->setSortIndicator(0, Qt::AscendingOrder); | - | ||||||||||||||||||
| 3963 | header()->setStretchLastSection(false); | - | ||||||||||||||||||
| 3964 | setTextElideMode(Qt::ElideMiddle); | - | ||||||||||||||||||
| 3965 | setEditTriggers(QAbstractItemView::EditKeyPressed); | - | ||||||||||||||||||
| 3966 | setContextMenuPolicy(Qt::CustomContextMenu); | - | ||||||||||||||||||
| 3967 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||
| 3968 | setDragDropMode(QAbstractItemView::InternalMove); | - | ||||||||||||||||||
| 3969 | #endif | - | ||||||||||||||||||
| 3970 | } | - | ||||||||||||||||||
| 3971 | - | |||||||||||||||||||
| 3972 | void QFileDialogTreeView::keyPressEvent(QKeyEvent *e) | - | ||||||||||||||||||
| 3973 | { | - | ||||||||||||||||||
| 3974 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 3975 | if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) { | - | ||||||||||||||||||
| 3976 | QTreeView::keyPressEvent(e); | - | ||||||||||||||||||
| 3977 | return; | - | ||||||||||||||||||
| 3978 | } | - | ||||||||||||||||||
| 3979 | #endif // QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 3980 | - | |||||||||||||||||||
| 3981 | if (!d_ptr->itemViewKeyboardEvent(e)) | - | ||||||||||||||||||
| 3982 | QTreeView::keyPressEvent(e); | - | ||||||||||||||||||
| 3983 | e->accept(); | - | ||||||||||||||||||
| 3984 | } | - | ||||||||||||||||||
| 3985 | - | |||||||||||||||||||
| 3986 | QSize QFileDialogTreeView::sizeHint() const | - | ||||||||||||||||||
| 3987 | { | - | ||||||||||||||||||
| 3988 | int height = qMax(10, sizeHintForRow(0)); | - | ||||||||||||||||||
| 3989 | QSize sizeHint = header()->sizeHint(); | - | ||||||||||||||||||
| 3990 | return QSize(sizeHint.width() * 4, height * 30); | - | ||||||||||||||||||
| 3991 | } | - | ||||||||||||||||||
| 3992 | - | |||||||||||||||||||
| 3993 | /*! | - | ||||||||||||||||||
| 3994 | // FIXME: this is a hack to avoid propagating key press events | - | ||||||||||||||||||
| 3995 | // to the dialog and from there to the "Ok" button | - | ||||||||||||||||||
| 3996 | */ | - | ||||||||||||||||||
| 3997 | void QFileDialogLineEdit::keyPressEvent(QKeyEvent *e) | - | ||||||||||||||||||
| 3998 | { | - | ||||||||||||||||||
| 3999 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 4000 | if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) { | - | ||||||||||||||||||
| 4001 | QLineEdit::keyPressEvent(e); | - | ||||||||||||||||||
| 4002 | return; | - | ||||||||||||||||||
| 4003 | } | - | ||||||||||||||||||
| 4004 | #endif // QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
| 4005 | - | |||||||||||||||||||
| 4006 | int key = e->key(); | - | ||||||||||||||||||
| 4007 | QLineEdit::keyPressEvent(e); | - | ||||||||||||||||||
| 4008 | if (!e->matches(QKeySequence::Cancel) && key != Qt::Key_Back) | - | ||||||||||||||||||
| 4009 | e->accept(); | - | ||||||||||||||||||
| 4010 | } | - | ||||||||||||||||||
| 4011 | - | |||||||||||||||||||
| 4012 | #ifndef QT_NO_FSCOMPLETER | - | ||||||||||||||||||
| 4013 | - | |||||||||||||||||||
| 4014 | QString QFSCompleter::pathFromIndex(const QModelIndex &index) const | - | ||||||||||||||||||
| 4015 | { | - | ||||||||||||||||||
| 4016 | const QFileSystemModel *dirModel; | - | ||||||||||||||||||
| 4017 | if (proxyModel) | - | ||||||||||||||||||
| 4018 | dirModel = qobject_cast<const QFileSystemModel *>(proxyModel->sourceModel()); | - | ||||||||||||||||||
| 4019 | else | - | ||||||||||||||||||
| 4020 | dirModel = sourceModel; | - | ||||||||||||||||||
| 4021 | QString currentLocation = dirModel->rootPath(); | - | ||||||||||||||||||
| 4022 | QString path = index.data(QFileSystemModel::FilePathRole).toString(); | - | ||||||||||||||||||
| 4023 | if (!currentLocation.isEmpty() && path.startsWith(currentLocation)) { | - | ||||||||||||||||||
| 4024 | #if defined(Q_OS_UNIX) || defined(Q_OS_WINCE) | - | ||||||||||||||||||
| 4025 | if (currentLocation == QDir::separator()) | - | ||||||||||||||||||
| 4026 | return path.mid(currentLocation.length()); | - | ||||||||||||||||||
| 4027 | #endif | - | ||||||||||||||||||
| 4028 | if (currentLocation.endsWith(QLatin1Char('/'))) | - | ||||||||||||||||||
| 4029 | return path.mid(currentLocation.length()); | - | ||||||||||||||||||
| 4030 | else | - | ||||||||||||||||||
| 4031 | return path.mid(currentLocation.length()+1); | - | ||||||||||||||||||
| 4032 | } | - | ||||||||||||||||||
| 4033 | return index.data(QFileSystemModel::FilePathRole).toString(); | - | ||||||||||||||||||
| 4034 | } | - | ||||||||||||||||||
| 4035 | - | |||||||||||||||||||
| 4036 | QStringList QFSCompleter::splitPath(const QString &path) const | - | ||||||||||||||||||
| 4037 | { | - | ||||||||||||||||||
| 4038 | if (path.isEmpty())
| 0 | ||||||||||||||||||
| 4039 | return QStringList(completionPrefix()); never executed: return QStringList(completionPrefix()); | 0 | ||||||||||||||||||
| 4040 | - | |||||||||||||||||||
| 4041 | QString pathCopy = QDir::toNativeSeparators(path); | - | ||||||||||||||||||
| 4042 | QString sep = QDir::separator(); | - | ||||||||||||||||||
| 4043 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||
| 4044 | if (pathCopy == QLatin1String("\\") || pathCopy == QLatin1String("\\\\")) | - | ||||||||||||||||||
| 4045 | return QStringList(pathCopy); | - | ||||||||||||||||||
| 4046 | QString doubleSlash(QLatin1String("\\\\")); | - | ||||||||||||||||||
| 4047 | if (pathCopy.startsWith(doubleSlash)) | - | ||||||||||||||||||
| 4048 | pathCopy = pathCopy.mid(2); | - | ||||||||||||||||||
| 4049 | else | - | ||||||||||||||||||
| 4050 | doubleSlash.clear(); | - | ||||||||||||||||||
| 4051 | #elif defined(Q_OS_UNIX) | - | ||||||||||||||||||
| 4052 | bool{ | - | ||||||||||||||||||
| 4053 | QString expanded; | - | ||||||||||||||||||
| pathCopytildeExpanded = qt_tildeExpansion(pathCopy, &expanded); | ||||||||||||||||||||
| 4054 |
| 0 | ||||||||||||||||||
| ||||||||||||||||||||
| 4055 | QFileSystemModel *dirModel; | - | ||||||||||||||||||
| 4056 |
| 0 | ||||||||||||||||||
| ||||||||||||||||||||
| 4057 | never executed: dirModel = qobject_cast<QFileSystemModel *>(proxyModel->sourceModel());dirModel = qobject_cast<QFileSystemModel *>(proxyModel->sourceModel());never executed: dirModel = qobject_cast<QFileSystemModel *>(proxyModel->sourceModel()); | 0 | ||||||||||||||||||
| else never executed: dirModel = qobject_cast<QFileSystemModel *>(proxyModel->sourceModel()); | ||||||||||||||||||||
| 4058 | else | - | ||||||||||||||||||
| 4059 | never executed: dirModel = sourceModel;dirModel = sourceModel;never executed: dirModel = sourceModel; | 0 | ||||||||||||||||||
| never executed: dirModel = sourceModel; | ||||||||||||||||||||
| 4060 | dirModel->fetchMore(dirModel->index(pathCopytildeExpanded)); | - | ||||||||||||||||||
| 4061 | } never executed: end of block | 0 | ||||||||||||||||||
| 4062 | pathCopy = std::move(tildeExpanded); | - | ||||||||||||||||||
| 4063 | } | - | ||||||||||||||||||
| 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.lastconstLast().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 |