| Line | Source Code | Coverage |
|---|
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | static QString *lastVisitedDir() { static QGlobalStatic<QString > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QString *x = new QString; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QString > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); } | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | typedef QString (*_qt_filedialog_existing_directory_hook)(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options); | - |
| 15 | __attribute__((visibility("default"))) _qt_filedialog_existing_directory_hook qt_filedialog_existing_directory_hook = 0; | - |
| 16 | | - |
| 17 | typedef QString (*_qt_filedialog_open_filename_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options); | - |
| 18 | __attribute__((visibility("default"))) _qt_filedialog_open_filename_hook qt_filedialog_open_filename_hook = 0; | - |
| 19 | | - |
| 20 | typedef QStringList (*_qt_filedialog_open_filenames_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options); | - |
| 21 | __attribute__((visibility("default"))) _qt_filedialog_open_filenames_hook qt_filedialog_open_filenames_hook = 0; | - |
| 22 | | - |
| 23 | typedef QString (*_qt_filedialog_save_filename_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options); | - |
| 24 | __attribute__((visibility("default"))) _qt_filedialog_save_filename_hook qt_filedialog_save_filename_hook = 0; | - |
| 25 | | - |
| 26 | | - |
| 27 | | - |
| 28 | | - |
| 29 | | - |
| 30 | | - |
| 31 | | - |
| 32 | | - |
| 33 | | - |
| 34 | | - |
| 35 | | - |
| 36 | | - |
| 37 | | - |
| 38 | | - |
| 39 | QFileDialog::QFileDialog(QWidget *parent, Qt::WindowFlags f) | - |
| 40 | : QDialog(*new QFileDialogPrivate, parent, f) | - |
| 41 | { | - |
| 42 | QFileDialogPrivate * const d = d_func(); | - |
| 43 | d->init(); | - |
| 44 | d->lineEdit()->selectAll(); | - |
| 45 | } | - |
| 46 | QFileDialog::QFileDialog(QWidget *parent, | - |
| 47 | const QString &caption, | - |
| 48 | const QString &directory, | - |
| 49 | const QString &filter) | - |
| 50 | : QDialog(*new QFileDialogPrivate, parent, 0) | - |
| 51 | { | - |
| 52 | QFileDialogPrivate * const d = d_func(); | - |
| 53 | d->init(directory, filter, caption); | - |
| 54 | d->lineEdit()->selectAll(); | - |
| 55 | } | - |
| 56 | | - |
| 57 | | - |
| 58 | | - |
| 59 | | - |
| 60 | QFileDialog::QFileDialog(const QFileDialogArgs &args) | - |
| 61 | : QDialog(*new QFileDialogPrivate, args.parent, 0) | - |
| 62 | { | - |
| 63 | QFileDialogPrivate * const d = d_func(); | - |
| 64 | d->init(args.directory, args.filter, args.caption); | - |
| 65 | setFileMode(args.mode); | - |
| 66 | setOptions(args.options); | - |
| 67 | selectFile(args.selection); | - |
| 68 | d->lineEdit()->selectAll(); | - |
| 69 | } | - |
| 70 | | - |
| 71 | | - |
| 72 | | - |
| 73 | | - |
| 74 | QFileDialog::~QFileDialog() | - |
| 75 | { | - |
| 76 | | - |
| 77 | QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); | - |
| 78 | settings.beginGroup(QLatin1String("Qt")); | - |
| 79 | settings.setValue(QLatin1String("filedialog"), saveState()); | - |
| 80 | | - |
| 81 | } | - |
| 82 | void QFileDialog::setSidebarUrls(const QList<QUrl> &urls) | - |
| 83 | { | - |
| 84 | QFileDialogPrivate * const d = d_func(); | - |
| 85 | d->qFileDialogUi->sidebar->setUrls(urls); | - |
| 86 | } | - |
| 87 | | - |
| 88 | | - |
| 89 | | - |
| 90 | | - |
| 91 | | - |
| 92 | QList<QUrl> QFileDialog::sidebarUrls() const | - |
| 93 | { | - |
| 94 | const QFileDialogPrivate * const d = d_func(); | - |
| 95 | return d->qFileDialogUi->sidebar->urls(); | - |
| 96 | } | - |
| 97 | | - |
| 98 | static const qint32 QFileDialogMagic = 0xbe; | - |
| 99 | QByteArray QFileDialog::saveState() const | - |
| 100 | { | - |
| 101 | const QFileDialogPrivate * const d = d_func(); | - |
| 102 | int version = 3; | - |
| 103 | QByteArray data; | - |
| 104 | QDataStream stream(&data, QIODevice::WriteOnly); | - |
| 105 | | - |
| 106 | stream << qint32(QFileDialogMagic); | - |
| 107 | stream << qint32(version); | - |
| 108 | stream << d->qFileDialogUi->splitter->saveState(); | - |
| 109 | stream << d->qFileDialogUi->sidebar->urls(); | - |
| 110 | stream << history(); | - |
| 111 | stream << *lastVisitedDir(); | - |
| 112 | stream << d->qFileDialogUi->treeView->header()->saveState(); | - |
| 113 | stream << qint32(viewMode()); | - |
| 114 | return data; | - |
| 115 | } | - |
| 116 | bool QFileDialog::restoreState(const QByteArray &state) | - |
| 117 | { | - |
| 118 | QFileDialogPrivate * const d = d_func(); | - |
| 119 | int version = 3; | - |
| 120 | QByteArray sd = state; | - |
| 121 | QDataStream stream(&sd, QIODevice::ReadOnly); | - |
| 122 | if (stream.atEnd()) | - |
| 123 | return false; | - |
| 124 | QByteArray splitterState; | - |
| 125 | QByteArray headerData; | - |
| 126 | QList<QUrl> bookmarks; | - |
| 127 | QStringList history; | - |
| 128 | QString currentDirectory; | - |
| 129 | qint32 marker; | - |
| 130 | qint32 v; | - |
| 131 | qint32 viewMode; | - |
| 132 | stream >> marker; | - |
| 133 | stream >> v; | - |
| 134 | if (marker != QFileDialogMagic || v != version) | - |
| 135 | return false; | - |
| 136 | | - |
| 137 | stream >> splitterState | - |
| 138 | >> bookmarks | - |
| 139 | >> history | - |
| 140 | >> currentDirectory | - |
| 141 | >> headerData | - |
| 142 | >> viewMode; | - |
| 143 | | - |
| 144 | if (!d->qFileDialogUi->splitter->restoreState(splitterState)) | - |
| 145 | return false; | - |
| 146 | QList<int> list = d->qFileDialogUi->splitter->sizes(); | - |
| 147 | if (list.count() >= 2 && list.at(0) == 0 && list.at(1) == 0) { | - |
| 148 | for (int i = 0; i < list.count(); ++i) | - |
| 149 | list[i] = d->qFileDialogUi->splitter->widget(i)->sizeHint().width(); | - |
| 150 | d->qFileDialogUi->splitter->setSizes(list); | - |
| 151 | } | - |
| 152 | | - |
| 153 | d->qFileDialogUi->sidebar->setUrls(bookmarks); | - |
| 154 | while (history.count() > 5) | - |
| 155 | history.pop_front(); | - |
| 156 | setHistory(history); | - |
| 157 | setDirectory(lastVisitedDir()->isEmpty() ? currentDirectory : *lastVisitedDir()); | - |
| 158 | QHeaderView *headerView = d->qFileDialogUi->treeView->header(); | - |
| 159 | if (!headerView->restoreState(headerData)) | - |
| 160 | return false; | - |
| 161 | | - |
| 162 | QList<QAction*> actions = headerView->actions(); | - |
| 163 | QAbstractItemModel *abstractModel = d->model; | - |
| 164 | | - |
| 165 | if (d->proxyModel) | - |
| 166 | abstractModel = d->proxyModel; | - |
| 167 | | - |
| 168 | int total = qMin(abstractModel->columnCount(QModelIndex()), actions.count() + 1); | - |
| 169 | for (int i = 1; i < total; ++i) | - |
| 170 | actions.at(i - 1)->setChecked(!headerView->isSectionHidden(i)); | - |
| 171 | | - |
| 172 | setViewMode(ViewMode(viewMode)); | - |
| 173 | return true; | - |
| 174 | } | - |
| 175 | | - |
| 176 | | - |
| 177 | | - |
| 178 | | - |
| 179 | void QFileDialog::changeEvent(QEvent *e) | - |
| 180 | { | - |
| 181 | QFileDialogPrivate * const d = d_func(); | - |
| 182 | if (e->type() == QEvent::LanguageChange) { | - |
| 183 | d->retranslateWindowTitle(); | - |
| 184 | d->retranslateStrings(); | - |
| 185 | } | - |
| 186 | QDialog::changeEvent(e); | - |
| 187 | } | - |
| 188 | | - |
| 189 | QFileDialogPrivate::QFileDialogPrivate() | - |
| 190 | : | - |
| 191 | | - |
| 192 | proxyModel(0), | - |
| 193 | | - |
| 194 | model(0), | - |
| 195 | currentHistoryLocation(-1), | - |
| 196 | renameAction(0), | - |
| 197 | deleteAction(0), | - |
| 198 | showHiddenAction(0), | - |
| 199 | useDefaultCaption(true), | - |
| 200 | defaultFileTypes(true), | - |
| 201 | qFileDialogUi(0), | - |
| 202 | options(new QFileDialogOptions) | - |
| 203 | { | - |
| 204 | } | - |
| 205 | | - |
| 206 | QFileDialogPrivate::~QFileDialogPrivate() | - |
| 207 | { | - |
| 208 | } | - |
| 209 | | - |
| 210 | void QFileDialogPrivate::initHelper(QPlatformDialogHelper *h) | - |
| 211 | { | - |
| 212 | QFileDialog *d = q_func(); | - |
| 213 | QObject::connect(h, "2""fileSelected(QString)", d, "2""fileSelected(QString)"); | - |
| 214 | QObject::connect(h, "2""filesSelected(QStringList)", d, "2""filesSelected(QStringList)"); | - |
| 215 | QObject::connect(h, "2""currentChanged(QString)", d, "2""currentChanged(QString)"); | - |
| 216 | QObject::connect(h, "2""directoryEntered(QString)", d, "2""directoryEntered(QString)"); | - |
| 217 | QObject::connect(h, "2""directoryEntered(QString)", d, "1""_q_nativeEnterDirectory(QString)"); | - |
| 218 | QObject::connect(h, "2""filterSelected(QString)", d, "2""filterSelected(QString)"); | - |
| 219 | static_cast<QPlatformFileDialogHelper *>(h)->setOptions(options); | - |
| 220 | } | 0 |
| 221 | | - |
| 222 | void QFileDialogPrivate::helperPrepareShow(QPlatformDialogHelper *) | - |
| 223 | { | - |
| 224 | QFileDialog * const q = q_func(); | - |
| 225 | options->setWindowTitle(q->windowTitle()); | - |
| 226 | options->setViewMode(static_cast<QFileDialogOptions::ViewMode>(q->viewMode())); | - |
| 227 | options->setHistory(q->history()); | - |
| 228 | options->setSidebarUrls(qFileDialogUi->sidebar->urls()); | - |
| 229 | const QDir directory = q->directory(); | - |
| 230 | options->setInitialDirectory(directory.exists() ? | - |
| 231 | directory.absolutePath() : | - |
| 232 | QString()); | - |
| 233 | options->setInitiallySelectedNameFilter(q->selectedNameFilter()); | - |
| 234 | options->setInitiallySelectedFiles(userSelectedFiles()); | - |
| 235 | } | - |
| 236 | | - |
| 237 | void QFileDialogPrivate::helperDone(QDialog::DialogCode code, QPlatformDialogHelper *) | - |
| 238 | { | - |
| 239 | if (code == QDialog::Accepted) { | - |
| 240 | QFileDialog * const q = q_func(); | - |
| 241 | q->setViewMode(static_cast<QFileDialog::ViewMode>(options->viewMode())); | - |
| 242 | q->setSidebarUrls(options->sidebarUrls()); | - |
| 243 | q->setHistory(options->history()); | - |
| 244 | } | - |
| 245 | } | - |
| 246 | | - |
| 247 | void QFileDialogPrivate::retranslateWindowTitle() | - |
| 248 | { | - |
| 249 | QFileDialog * const q = q_func(); | - |
| 250 | if (!useDefaultCaption || setWindowTitle != q->windowTitle()) | - |
| 251 | return; | - |
| 252 | if (q->acceptMode() == QFileDialog::AcceptOpen) { | - |
| 253 | const QFileDialog::FileMode fileMode = q->fileMode(); | - |
| 254 | if (fileMode == QFileDialog::DirectoryOnly || fileMode == QFileDialog::Directory) | - |
| 255 | q->setWindowTitle(QFileDialog::tr("Find Directory")); | - |
| 256 | else | - |
| 257 | q->setWindowTitle(QFileDialog::tr("Open")); | - |
| 258 | } else | - |
| 259 | q->setWindowTitle(QFileDialog::tr("Save As")); | - |
| 260 | | - |
| 261 | setWindowTitle = q->windowTitle(); | - |
| 262 | } | - |
| 263 | | - |
| 264 | void QFileDialogPrivate::setLastVisitedDirectory(const QString &dir) | - |
| 265 | { | - |
| 266 | *lastVisitedDir() = dir; | - |
| 267 | } | - |
| 268 | | - |
| 269 | void QFileDialogPrivate::updateFileNameLabel() | - |
| 270 | { | - |
| 271 | if (!options->isLabelExplicitlySet(QFileDialogOptions::FileName)) { | - |
| 272 | switch (q_func()->fileMode()) { | - |
| 273 | case QFileDialog::DirectoryOnly: | - |
| 274 | case QFileDialog::Directory: | - |
| 275 | setLabelTextControl(QFileDialog::FileName, QFileDialog::tr("Directory:")); | - |
| 276 | break; | - |
| 277 | default: | - |
| 278 | setLabelTextControl(QFileDialog::FileName, QFileDialog::tr("File &name:")); | - |
| 279 | break; | - |
| 280 | } | - |
| 281 | } | - |
| 282 | } | - |
| 283 | | - |
| 284 | void QFileDialogPrivate::updateOkButtonText(bool saveAsOnFolder) | - |
| 285 | { | - |
| 286 | QFileDialog * const q = q_func(); | - |
| 287 | | - |
| 288 | if (saveAsOnFolder) { | - |
| 289 | setLabelTextControl(QFileDialog::Accept, QFileDialog::tr("&Open")); | - |
| 290 | } else if (options->isLabelExplicitlySet(QFileDialogOptions::Accept)) { | - |
| 291 | setLabelTextControl(QFileDialog::Accept, options->labelText(QFileDialogOptions::Accept)); | - |
| 292 | return; | - |
| 293 | } else { | - |
| 294 | switch (q->fileMode()) { | - |
| 295 | case QFileDialog::DirectoryOnly: | - |
| 296 | case QFileDialog::Directory: | - |
| 297 | setLabelTextControl(QFileDialog::Accept, QFileDialog::tr("&Choose")); | - |
| 298 | break; | - |
| 299 | default: | - |
| 300 | setLabelTextControl(QFileDialog::Accept, | - |
| 301 | q->acceptMode() == QFileDialog::AcceptOpen ? | - |
| 302 | QFileDialog::tr("&Open") : | - |
| 303 | QFileDialog::tr("&Save")); | - |
| 304 | break; | - |
| 305 | } | - |
| 306 | } | - |
| 307 | } | - |
| 308 | | - |
| 309 | void QFileDialogPrivate::retranslateStrings() | - |
| 310 | { | - |
| 311 | QFileDialog * const q = q_func(); | - |
| 312 | | - |
| 313 | if (defaultFileTypes) | - |
| 314 | q->setNameFilter(QFileDialog::tr("All Files (*)")); | - |
| 315 | | - |
| 316 | QList<QAction*> actions = qFileDialogUi->treeView->header()->actions(); | - |
| 317 | QAbstractItemModel *abstractModel = model; | - |
| 318 | | - |
| 319 | if (proxyModel) | - |
| 320 | abstractModel = proxyModel; | - |
| 321 | | - |
| 322 | int total = qMin(abstractModel->columnCount(QModelIndex()), actions.count() + 1); | - |
| 323 | for (int i = 1; i < total; ++i) { | - |
| 324 | actions.at(i - 1)->setText(QFileDialog::tr("Show ") + abstractModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); | - |
| 325 | } | - |
| 326 | | - |
| 327 | | - |
| 328 | renameAction->setText(QFileDialog::tr("&Rename")); | - |
| 329 | deleteAction->setText(QFileDialog::tr("&Delete")); | - |
| 330 | showHiddenAction->setText(QFileDialog::tr("Show &hidden files")); | - |
| 331 | newFolderAction->setText(QFileDialog::tr("&New Folder")); | - |
| 332 | qFileDialogUi->retranslateUi(q); | - |
| 333 | updateFileNameLabel(); | - |
| 334 | } | - |
| 335 | | - |
| 336 | void QFileDialogPrivate::emitFilesSelected(const QStringList &files) | - |
| 337 | { | - |
| 338 | QFileDialog * const q = q_func(); | - |
| 339 | q->filesSelected(files); | - |
| 340 | if (files.count() == 1) | - |
| 341 | q->fileSelected(files.first()); | - |
| 342 | } | - |
| 343 | | - |
| 344 | bool QFileDialogPrivate::canBeNativeDialog() | - |
| 345 | { | - |
| 346 | QFileDialog * const q = q_func(); | - |
| 347 | if (nativeDialogInUse) | - |
| 348 | return true; | - |
| 349 | if (q->testAttribute(Qt::WA_DontShowOnScreen)) | - |
| 350 | return false; | - |
| 351 | if (q->options() & QFileDialog::DontUseNativeDialog) | - |
| 352 | return false; | - |
| 353 | | - |
| 354 | QLatin1String staticName(QFileDialog::staticMetaObject.className()); | - |
| 355 | QLatin1String dynamicName(q->metaObject()->className()); | - |
| 356 | return (staticName == dynamicName); | - |
| 357 | } | - |
| 358 | void QFileDialog::setOption(Option option, bool on) | - |
| 359 | { | - |
| 360 | const QFileDialog::Options previousOptions = options(); | - |
| 361 | if (!(previousOptions & option) != !on) | - |
| 362 | setOptions(previousOptions ^ option); | - |
| 363 | } | - |
| 364 | bool QFileDialog::testOption(Option option) const | - |
| 365 | { | - |
| 366 | const QFileDialogPrivate * const d = d_func(); | - |
| 367 | return d->options->testOption(static_cast<QFileDialogOptions::FileDialogOption>(option)); | - |
| 368 | } | - |
| 369 | void QFileDialog::setOptions(Options options) | - |
| 370 | { | - |
| 371 | QFileDialogPrivate * const d = d_func(); | - |
| 372 | | - |
| 373 | Options changed = (options ^ QFileDialog::options()); | - |
| 374 | if (!changed) | - |
| 375 | return; | - |
| 376 | | - |
| 377 | d->options->setOptions(QFileDialogOptions::FileDialogOptions(int(options))); | - |
| 378 | if (changed & DontResolveSymlinks) | - |
| 379 | d->model->setResolveSymlinks(!(options & DontResolveSymlinks)); | - |
| 380 | if (changed & ReadOnly) { | - |
| 381 | bool ro = (options & ReadOnly); | - |
| 382 | d->model->setReadOnly(ro); | - |
| 383 | d->qFileDialogUi->newFolderButton->setEnabled(!ro); | - |
| 384 | d->renameAction->setEnabled(!ro); | - |
| 385 | d->deleteAction->setEnabled(!ro); | - |
| 386 | } | - |
| 387 | if (changed & HideNameFilterDetails) | - |
| 388 | setNameFilters(d->options->nameFilters()); | - |
| 389 | | - |
| 390 | if (changed & ShowDirsOnly) | - |
| 391 | setFilter((options & ShowDirsOnly) ? filter() & ~QDir::Files : filter() | QDir::Files); | - |
| 392 | } | - |
| 393 | | - |
| 394 | QFileDialog::Options QFileDialog::options() const | - |
| 395 | { | - |
| 396 | const QFileDialogPrivate * const d = d_func(); | - |
| 397 | return QFileDialog::Options(int(d->options->options())); | - |
| 398 | } | - |
| 399 | void QFileDialog::open(QObject *receiver, const char *member) | - |
| 400 | { | - |
| 401 | QFileDialogPrivate * const d = d_func(); | - |
| 402 | const char *signal = (fileMode() == ExistingFiles) ? "2""filesSelected(QStringList)" | - |
| 403 | : "2""fileSelected(QString)"; | - |
| 404 | connect(this, signal, receiver, member); | - |
| 405 | d->signalToDisconnectOnClose = signal; | - |
| 406 | d->receiverToDisconnectOnClose = receiver; | - |
| 407 | d->memberToDisconnectOnClose = member; | - |
| 408 | | - |
| 409 | QDialog::open(); | - |
| 410 | } | - |
| 411 | | - |
| 412 | | - |
| 413 | | - |
| 414 | | - |
| 415 | | - |
| 416 | void QFileDialog::setVisible(bool visible) | - |
| 417 | { | - |
| 418 | QFileDialogPrivate * const d = d_func(); | - |
| 419 | if (visible){ | - |
| 420 | if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden)) | - |
| 421 | return; | - |
| 422 | } else if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden)) | - |
| 423 | return; | - |
| 424 | | - |
| 425 | if (d->canBeNativeDialog()){ | - |
| 426 | if (d->setNativeDialogVisible(visible)){ | - |
| 427 | | - |
| 428 | | - |
| 429 | setAttribute(Qt::WA_DontShowOnScreen); | - |
| 430 | | - |
| 431 | | - |
| 432 | d->completer->setModel(0); | - |
| 433 | | - |
| 434 | } else { | - |
| 435 | setAttribute(Qt::WA_DontShowOnScreen, false); | - |
| 436 | | - |
| 437 | if (d->proxyModel != 0) | - |
| 438 | d->completer->setModel(d->proxyModel); | - |
| 439 | else | - |
| 440 | d->completer->setModel(d->model); | - |
| 441 | | - |
| 442 | } | - |
| 443 | } | - |
| 444 | | - |
| 445 | if (!d->nativeDialogInUse) | - |
| 446 | d->qFileDialogUi->fileNameEdit->setFocus(); | - |
| 447 | | - |
| 448 | QDialog::setVisible(visible); | - |
| 449 | } | - |
| 450 | | - |
| 451 | | - |
| 452 | | - |
| 453 | | - |
| 454 | | - |
| 455 | void QFileDialogPrivate::_q_goToUrl(const QUrl &url) | - |
| 456 | { | - |
| 457 | | - |
| 458 | | - |
| 459 | QFileSystemModelPrivate::QFileSystemNode *node = model->d_func()->node(url.toLocalFile(), true); | - |
| 460 | QModelIndex idx = model->d_func()->index(node); | - |
| 461 | _q_enterDirectory(idx); | - |
| 462 | } | - |
| 463 | void QFileDialog::setDirectory(const QString &directory) | - |
| 464 | { | - |
| 465 | QFileDialogPrivate * const d = d_func(); | - |
| 466 | QString newDirectory = directory; | - |
| 467 | QFileInfo info(directory); | - |
| 468 | | - |
| 469 | if (!directory.isEmpty()) | - |
| 470 | newDirectory = QDir::cleanPath(directory); | - |
| 471 | | - |
| 472 | if (!directory.isEmpty() && newDirectory.isEmpty()) | - |
| 473 | return; | - |
| 474 | | - |
| 475 | d->setLastVisitedDirectory(newDirectory); | - |
| 476 | | - |
| 477 | if (d->nativeDialogInUse){ | - |
| 478 | d->setDirectory_sys(newDirectory); | - |
| 479 | return; | - |
| 480 | } | - |
| 481 | if (d->rootPath() == newDirectory) | - |
| 482 | return; | - |
| 483 | QModelIndex root = d->model->setRootPath(newDirectory); | - |
| 484 | d->qFileDialogUi->newFolderButton->setEnabled(d->model->flags(root) & Qt::ItemIsDropEnabled); | - |
| 485 | if (root != d->rootIndex()) { | - |
| 486 | | - |
| 487 | if (directory.endsWith(QLatin1Char('/'))) | - |
| 488 | d->completer->setCompletionPrefix(newDirectory); | - |
| 489 | else | - |
| 490 | d->completer->setCompletionPrefix(newDirectory + QLatin1Char('/')); | - |
| 491 | | - |
| 492 | d->setRootIndex(root); | - |
| 493 | } | - |
| 494 | d->qFileDialogUi->listView->selectionModel()->clear(); | - |
| 495 | } | - |
| 496 | | - |
| 497 | | - |
| 498 | | - |
| 499 | | - |
| 500 | QDir QFileDialog::directory() const | - |
| 501 | { | - |
| 502 | const QFileDialogPrivate * const d = d_func(); | - |
| 503 | return QDir(d->nativeDialogInUse ? d->directory_sys() : d->rootPath()); | - |
| 504 | } | - |
| 505 | | - |
| 506 | | - |
| 507 | | - |
| 508 | | - |
| 509 | | - |
| 510 | | - |
| 511 | void QFileDialog::selectFile(const QString &filename) | - |
| 512 | { | - |
| 513 | QFileDialogPrivate * const d = d_func(); | - |
| 514 | if (filename.isEmpty()) | - |
| 515 | return; | - |
| 516 | | - |
| 517 | if (d->nativeDialogInUse){ | - |
| 518 | d->selectFile_sys(filename); | - |
| 519 | return; | - |
| 520 | } | - |
| 521 | | - |
| 522 | if (!QDir::isRelativePath(filename)) { | - |
| 523 | QFileInfo info(filename); | - |
| 524 | QString filenamePath = info.absoluteDir().path(); | - |
| 525 | | - |
| 526 | if (d->model->rootPath() != filenamePath) | - |
| 527 | setDirectory(filenamePath); | - |
| 528 | } | - |
| 529 | | - |
| 530 | QModelIndex index = d->model->index(filename); | - |
| 531 | QString file; | - |
| 532 | if (!index.isValid()) { | - |
| 533 | | - |
| 534 | QString text = filename; | - |
| 535 | if (QFileInfo(filename).isAbsolute()) { | - |
| 536 | QString current = d->rootPath(); | - |
| 537 | text.remove(current); | - |
| 538 | if (text.at(0) == QDir::separator() | - |
| 539 | | - |
| 540 | | - |
| 541 | | - |
| 542 | | - |
| 543 | ) | - |
| 544 | text = text.remove(0,1); | - |
| 545 | } | - |
| 546 | file = text; | - |
| 547 | } else { | - |
| 548 | file = index.data().toString(); | - |
| 549 | } | - |
| 550 | d->qFileDialogUi->listView->selectionModel()->clear(); | - |
| 551 | if (!isVisible() || !d->lineEdit()->hasFocus()) | - |
| 552 | d->lineEdit()->setText(file); | - |
| 553 | } | - |
| 554 | | - |
| 555 | | - |
| 556 | QString qt_tildeExpansion(const QString &path, bool *expanded = 0) | - |
| 557 | { | - |
| 558 | if (expanded != 0) | - |
| 559 | *expanded = false; | - |
| 560 | if (!path.startsWith(QLatin1Char('~'))) | - |
| 561 | return path; | - |
| 562 | QString ret = path; | - |
| 563 | QStringList tokens = ret.split(QDir::separator()); | - |
| 564 | if (tokens.first() == QLatin1String("~")) { | - |
| 565 | ret.replace(0, 1, QDir::homePath()); | - |
| 566 | } else { | - |
| 567 | QString userName = tokens.first(); | - |
| 568 | userName.remove(0, 1); | - |
| 569 | | - |
| 570 | passwd pw; | - |
| 571 | passwd *tmpPw; | - |
| 572 | char buf[200]; | - |
| 573 | const int bufSize = sizeof(buf); | - |
| 574 | int err = 0; | - |
| 575 | | - |
| 576 | | - |
| 577 | | - |
| 578 | err = getpwnam_r(userName.toLocal8Bit().constData(), &pw, buf, bufSize, &tmpPw); | - |
| 579 | | - |
| 580 | if (err || !tmpPw) | - |
| 581 | return ret; | - |
| 582 | const QString homePath = QString::fromLocal8Bit(pw.pw_dir); | - |
| 583 | | - |
| 584 | | - |
| 585 | | - |
| 586 | | - |
| 587 | | - |
| 588 | | - |
| 589 | ret.replace(0, tokens.first().length(), homePath); | - |
| 590 | } | - |
| 591 | if (expanded != 0) | - |
| 592 | *expanded = true; | - |
| 593 | return ret; | - |
| 594 | } | - |
| 595 | | - |
| 596 | | - |
| 597 | | - |
| 598 | | - |
| 599 | | - |
| 600 | QStringList QFileDialogPrivate::typedFiles() const | - |
| 601 | { | - |
| 602 | const QFileDialog * const q = q_func(); | - |
| 603 | QStringList files; | - |
| 604 | QString editText = lineEdit()->text(); | - |
| 605 | if (!editText.contains(QLatin1Char('"'))) { | - |
| 606 | | - |
| 607 | const QString prefix = q->directory().absolutePath() + QDir::separator(); | - |
| 608 | if (QFile::exists(prefix + editText)) | - |
| 609 | files << editText; | - |
| 610 | else | - |
| 611 | files << qt_tildeExpansion(editText); | - |
| 612 | | - |
| 613 | | - |
| 614 | | - |
| 615 | | - |
| 616 | } else { | - |
| 617 | | - |
| 618 | | - |
| 619 | QStringList tokens = editText.split(QLatin1Char('\"')); | - |
| 620 | for (int i=0; i<tokens.size(); ++i) { | - |
| 621 | if ((i % 2) == 0) | - |
| 622 | continue; | - |
| 623 | | - |
| 624 | const QString token = tokens.at(i); | - |
| 625 | const QString prefix = q->directory().absolutePath() + QDir::separator(); | - |
| 626 | if (QFile::exists(prefix + token)) | - |
| 627 | files << token; | - |
| 628 | else | - |
| 629 | files << qt_tildeExpansion(token); | - |
| 630 | | - |
| 631 | | - |
| 632 | | - |
| 633 | } | - |
| 634 | } | - |
| 635 | return addDefaultSuffixToFiles(files); | - |
| 636 | } | - |
| 637 | | - |
| 638 | | - |
| 639 | | - |
| 640 | | - |
| 641 | QStringList QFileDialogPrivate::userSelectedFiles() const | - |
| 642 | { | - |
| 643 | if (nativeDialogInUse) | - |
| 644 | return addDefaultSuffixToFiles(selectedFiles_sys()); | - |
| 645 | | - |
| 646 | QStringList files; | - |
| 647 | for (QForeachContainer<__typeof__(qFileDialogUi->listView->selectionModel()->selectedRows())> _container_(qFileDialogUi->listView->selectionModel()->selectedRows()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QModelIndex &index = *_container_.i;; __extension__ ({--_container_.brk; break;})) | - |
| 648 | files.append(index.data(QFileSystemModel::FilePathRole).toString()); | - |
| 649 | | - |
| 650 | if (files.isEmpty() && !lineEdit()->text().isEmpty()) | - |
| 651 | files = typedFiles(); | - |
| 652 | | - |
| 653 | return files; | - |
| 654 | } | - |
| 655 | | - |
| 656 | QStringList QFileDialogPrivate::addDefaultSuffixToFiles(const QStringList filesToFix) const | - |
| 657 | { | - |
| 658 | QStringList files; | - |
| 659 | for (int i=0; i<filesToFix.size(); ++i) { | - |
| 660 | QString name = toInternal(filesToFix.at(i)); | - |
| 661 | QFileInfo info(name); | - |
| 662 | | - |
| 663 | const QString defaultSuffix = options->defaultSuffix(); | - |
| 664 | if (!defaultSuffix.isEmpty() && !info.isDir() && name.lastIndexOf(QLatin1Char('.')) == -1) | - |
| 665 | name += QLatin1Char('.') + defaultSuffix; | - |
| 666 | if (info.isAbsolute()) { | - |
| 667 | files.append(name); | - |
| 668 | } else { | - |
| 669 | | - |
| 670 | | - |
| 671 | | - |
| 672 | QString path = rootPath(); | - |
| 673 | if (!path.endsWith(QLatin1Char('/'))) | - |
| 674 | path += QLatin1Char('/'); | - |
| 675 | path += name; | - |
| 676 | files.append(path); | - |
| 677 | } | - |
| 678 | } | - |
| 679 | return files; | - |
| 680 | } | - |
| 681 | QStringList QFileDialog::selectedFiles() const | - |
| 682 | { | - |
| 683 | const QFileDialogPrivate * const d = d_func(); | - |
| 684 | | - |
| 685 | QStringList files = d->userSelectedFiles(); | - |
| 686 | if (files.isEmpty()) { | - |
| 687 | const FileMode fm = fileMode(); | - |
| 688 | if (fm != ExistingFile && fm != ExistingFiles) | - |
| 689 | files.append(d->rootIndex().data(QFileSystemModel::FilePathRole).toString()); | - |
| 690 | } | - |
| 691 | return files; | - |
| 692 | } | - |
| 693 | | - |
| 694 | | - |
| 695 | | - |
| 696 | | - |
| 697 | | - |
| 698 | QStringList qt_make_filter_list(const QString &filter) | - |
| 699 | { | - |
| 700 | QString f(filter); | - |
| 701 | | - |
| 702 | if (f.isEmpty()) | - |
| 703 | return QStringList(); | - |
| 704 | | - |
| 705 | QString sep(QLatin1String(";;")); | - |
| 706 | int i = f.indexOf(sep, 0); | - |
| 707 | if (i == -1) { | - |
| 708 | if (f.indexOf(QLatin1Char('\n'), 0) != -1) { | - |
| 709 | sep = QLatin1Char('\n'); | - |
| 710 | i = f.indexOf(sep, 0); | - |
| 711 | } | - |
| 712 | } | - |
| 713 | | - |
| 714 | return f.split(sep); | - |
| 715 | } | - |
| 716 | void QFileDialog::setNameFilter(const QString &filter) | - |
| 717 | { | - |
| 718 | setNameFilters(qt_make_filter_list(filter)); | - |
| 719 | } | - |
| 720 | void QFileDialog::setNameFilterDetailsVisible(bool enabled) | - |
| 721 | { | - |
| 722 | setOption(HideNameFilterDetails, !enabled); | - |
| 723 | } | - |
| 724 | | - |
| 725 | bool QFileDialog::isNameFilterDetailsVisible() const | - |
| 726 | { | - |
| 727 | return !testOption(HideNameFilterDetails); | - |
| 728 | } | - |
| 729 | | - |
| 730 | | - |
| 731 | | - |
| 732 | | - |
| 733 | | - |
| 734 | QStringList qt_strip_filters(const QStringList &filters) | - |
| 735 | { | - |
| 736 | QStringList strippedFilters; | - |
| 737 | QRegExp r(QString::fromLatin1(QPlatformFileDialogHelper::filterRegExp)); | - |
| 738 | for (int i = 0; i < filters.count(); ++i) { | - |
| 739 | QString filterName; | - |
| 740 | int index = r.indexIn(filters[i]); | - |
| 741 | if (index >= 0) | - |
| 742 | filterName = r.cap(1); | - |
| 743 | strippedFilters.append(filterName.simplified()); | - |
| 744 | } | - |
| 745 | return strippedFilters; | - |
| 746 | } | - |
| 747 | void QFileDialog::setNameFilters(const QStringList &filters) | - |
| 748 | { | - |
| 749 | QFileDialogPrivate * const d = d_func(); | - |
| 750 | d->defaultFileTypes = (filters == QStringList(QFileDialog::tr("All Files (*)"))); | - |
| 751 | QStringList cleanedFilters; | - |
| 752 | for (int i = 0; i < filters.count(); ++i) { | - |
| 753 | cleanedFilters << filters[i].simplified(); | - |
| 754 | } | - |
| 755 | d->options->setNameFilters(cleanedFilters); | - |
| 756 | | - |
| 757 | d->qFileDialogUi->fileTypeCombo->clear(); | - |
| 758 | if (cleanedFilters.isEmpty()) | - |
| 759 | return; | - |
| 760 | | - |
| 761 | if (testOption(HideNameFilterDetails)) | - |
| 762 | d->qFileDialogUi->fileTypeCombo->addItems(qt_strip_filters(cleanedFilters)); | - |
| 763 | else | - |
| 764 | d->qFileDialogUi->fileTypeCombo->addItems(cleanedFilters); | - |
| 765 | | - |
| 766 | d->_q_useNameFilter(0); | - |
| 767 | } | - |
| 768 | | - |
| 769 | | - |
| 770 | | - |
| 771 | | - |
| 772 | | - |
| 773 | | - |
| 774 | | - |
| 775 | QStringList QFileDialog::nameFilters() const | - |
| 776 | { | - |
| 777 | return d_func()->options->nameFilters(); | - |
| 778 | } | - |
| 779 | void QFileDialog::selectNameFilter(const QString &filter) | - |
| 780 | { | - |
| 781 | QFileDialogPrivate * const d = d_func(); | - |
| 782 | if (d->nativeDialogInUse) { | - |
| 783 | d->selectNameFilter_sys(filter); | - |
| 784 | return; | - |
| 785 | } | - |
| 786 | int i = -1; | - |
| 787 | if (testOption(HideNameFilterDetails)) { | - |
| 788 | const QStringList filters = qt_strip_filters(qt_make_filter_list(filter)); | - |
| 789 | if (!filters.isEmpty()) | - |
| 790 | i = d->qFileDialogUi->fileTypeCombo->findText(filters.first()); | - |
| 791 | } else { | - |
| 792 | i = d->qFileDialogUi->fileTypeCombo->findText(filter); | - |
| 793 | } | - |
| 794 | if (i >= 0) { | - |
| 795 | d->qFileDialogUi->fileTypeCombo->setCurrentIndex(i); | - |
| 796 | d->_q_useNameFilter(d->qFileDialogUi->fileTypeCombo->currentIndex()); | - |
| 797 | } | - |
| 798 | } | - |
| 799 | QString QFileDialog::selectedNameFilter() const | - |
| 800 | { | - |
| 801 | const QFileDialogPrivate * const d = d_func(); | - |
| 802 | if (d->nativeDialogInUse) | - |
| 803 | return d->selectedNameFilter_sys(); | - |
| 804 | | - |
| 805 | return d->qFileDialogUi->fileTypeCombo->currentText(); | - |
| 806 | } | - |
| 807 | QDir::Filters QFileDialog::filter() const | - |
| 808 | { | - |
| 809 | const QFileDialogPrivate * const d = d_func(); | - |
| 810 | return d->model->filter(); | - |
| 811 | } | - |
| 812 | void QFileDialog::setFilter(QDir::Filters filters) | - |
| 813 | { | - |
| 814 | QFileDialogPrivate * const d = d_func(); | - |
| 815 | d->model->setFilter(filters); | - |
| 816 | d->options->setFilter(filters); | - |
| 817 | if (d->nativeDialogInUse){ | - |
| 818 | d->setFilter_sys(); | - |
| 819 | return; | - |
| 820 | } | - |
| 821 | | - |
| 822 | d->showHiddenAction->setChecked((filters & QDir::Hidden)); | - |
| 823 | } | - |
| 824 | void QFileDialog::setViewMode(QFileDialog::ViewMode mode) | - |
| 825 | { | - |
| 826 | QFileDialogPrivate * const d = d_func(); | - |
| 827 | if (mode == Detail) | - |
| 828 | d->_q_showDetailsView(); | - |
| 829 | else | - |
| 830 | d->_q_showListView(); | - |
| 831 | } | - |
| 832 | | - |
| 833 | QFileDialog::ViewMode QFileDialog::viewMode() const | - |
| 834 | { | - |
| 835 | const QFileDialogPrivate * const d = d_func(); | - |
| 836 | return (d->qFileDialogUi->stackedWidget->currentWidget() == d->qFileDialogUi->listView->parent() ? QFileDialog::List : QFileDialog::Detail); | - |
| 837 | } | - |
| 838 | void QFileDialog::setFileMode(QFileDialog::FileMode mode) | - |
| 839 | { | - |
| 840 | QFileDialogPrivate * const d = d_func(); | - |
| 841 | d->options->setFileMode(static_cast<QFileDialogOptions::FileMode>(mode)); | - |
| 842 | d->retranslateWindowTitle(); | - |
| 843 | | - |
| 844 | | - |
| 845 | setOption(ShowDirsOnly, mode == DirectoryOnly); | - |
| 846 | | - |
| 847 | | - |
| 848 | QAbstractItemView::SelectionMode selectionMode; | - |
| 849 | if (mode == QFileDialog::ExistingFiles) | - |
| 850 | selectionMode = QAbstractItemView::ExtendedSelection; | - |
| 851 | else | - |
| 852 | selectionMode = QAbstractItemView::SingleSelection; | - |
| 853 | d->qFileDialogUi->listView->setSelectionMode(selectionMode); | - |
| 854 | d->qFileDialogUi->treeView->setSelectionMode(selectionMode); | - |
| 855 | | - |
| 856 | d->model->setFilter(d->filterForMode(filter())); | - |
| 857 | | - |
| 858 | if (mode == DirectoryOnly || mode == Directory) { | - |
| 859 | d->qFileDialogUi->fileTypeCombo->clear(); | - |
| 860 | d->qFileDialogUi->fileTypeCombo->addItem(tr("Directories")); | - |
| 861 | d->qFileDialogUi->fileTypeCombo->setEnabled(false); | - |
| 862 | } | - |
| 863 | d->updateFileNameLabel(); | - |
| 864 | d->updateOkButtonText(); | - |
| 865 | if (d->nativeDialogInUse){ | - |
| 866 | d->setFilter_sys(); | - |
| 867 | return; | - |
| 868 | } | - |
| 869 | | - |
| 870 | d->qFileDialogUi->fileTypeCombo->setEnabled(!testOption(ShowDirsOnly)); | - |
| 871 | d->_q_updateOkButton(); | - |
| 872 | } | - |
| 873 | | - |
| 874 | QFileDialog::FileMode QFileDialog::fileMode() const | - |
| 875 | { | - |
| 876 | const QFileDialogPrivate * const d = d_func(); | - |
| 877 | return static_cast<FileMode>(d->options->fileMode()); | - |
| 878 | } | - |
| 879 | void QFileDialog::setAcceptMode(QFileDialog::AcceptMode mode) | - |
| 880 | { | - |
| 881 | QFileDialogPrivate * const d = d_func(); | - |
| 882 | d->options->setAcceptMode(static_cast<QFileDialogOptions::AcceptMode>(mode)); | - |
| 883 | QDialogButtonBox::StandardButton button = (mode == AcceptOpen ? QDialogButtonBox::Open : QDialogButtonBox::Save); | - |
| 884 | d->qFileDialogUi->buttonBox->setStandardButtons(button | QDialogButtonBox::Cancel); | - |
| 885 | d->qFileDialogUi->buttonBox->button(button)->setEnabled(false); | - |
| 886 | d->_q_updateOkButton(); | - |
| 887 | if (mode == AcceptSave) { | - |
| 888 | d->qFileDialogUi->lookInCombo->setEditable(false); | - |
| 889 | } | - |
| 890 | d->retranslateWindowTitle(); | - |
| 891 | | - |
| 892 | d->deletePlatformHelper(); | - |
| 893 | | - |
| 894 | setAttribute(Qt::WA_DontShowOnScreen, false); | - |
| 895 | } | - |
| 896 | | - |
| 897 | | - |
| 898 | | - |
| 899 | | - |
| 900 | | - |
| 901 | QModelIndex QFileDialogPrivate::rootIndex() const { | - |
| 902 | return mapToSource(qFileDialogUi->listView->rootIndex()); | - |
| 903 | } | - |
| 904 | | - |
| 905 | QAbstractItemView *QFileDialogPrivate::currentView() const { | - |
| 906 | if (!qFileDialogUi->stackedWidget) | - |
| 907 | return 0; | - |
| 908 | if (qFileDialogUi->stackedWidget->currentWidget() == qFileDialogUi->listView->parent()) | - |
| 909 | return qFileDialogUi->listView; | - |
| 910 | return qFileDialogUi->treeView; | - |
| 911 | } | - |
| 912 | | - |
| 913 | QLineEdit *QFileDialogPrivate::lineEdit() const { | - |
| 914 | return (QLineEdit*)qFileDialogUi->fileNameEdit; | - |
| 915 | } | - |
| 916 | | - |
| 917 | int QFileDialogPrivate::maxNameLength(const QString &path) | - |
| 918 | { | - |
| 919 | | - |
| 920 | return ::pathconf(QFile::encodeName(path).data(), _PC_NAME_MAX); | - |
| 921 | return -1; | - |
| 922 | } | - |
| 923 | | - |
| 924 | | - |
| 925 | | - |
| 926 | | - |
| 927 | void QFileDialogPrivate::setRootIndex(const QModelIndex &index) const { | - |
| 928 | qt_noop(); | - |
| 929 | QModelIndex idx = mapFromSource(index); | - |
| 930 | qFileDialogUi->treeView->setRootIndex(idx); | - |
| 931 | qFileDialogUi->listView->setRootIndex(idx); | - |
| 932 | } | - |
| 933 | | - |
| 934 | | - |
| 935 | | - |
| 936 | | - |
| 937 | QModelIndex QFileDialogPrivate::select(const QModelIndex &index) const { | - |
| 938 | qt_noop(); | - |
| 939 | | - |
| 940 | QModelIndex idx = mapFromSource(index); | - |
| 941 | if (idx.isValid() && !qFileDialogUi->listView->selectionModel()->isSelected(idx)) | - |
| 942 | qFileDialogUi->listView->selectionModel()->select(idx, | - |
| 943 | QItemSelectionModel::Select | QItemSelectionModel::Rows); | - |
| 944 | return idx; | - |
| 945 | } | - |
| 946 | | - |
| 947 | QFileDialog::AcceptMode QFileDialog::acceptMode() const | - |
| 948 | { | - |
| 949 | const QFileDialogPrivate * const d = d_func(); | - |
| 950 | return static_cast<AcceptMode>(d->options->acceptMode()); | - |
| 951 | } | - |
| 952 | void QFileDialog::setReadOnly(bool enabled) | - |
| 953 | { | - |
| 954 | setOption(ReadOnly, enabled); | - |
| 955 | } | - |
| 956 | | - |
| 957 | bool QFileDialog::isReadOnly() const | - |
| 958 | { | - |
| 959 | return testOption(ReadOnly); | - |
| 960 | } | - |
| 961 | void QFileDialog::setResolveSymlinks(bool enabled) | - |
| 962 | { | - |
| 963 | setOption(DontResolveSymlinks, !enabled); | - |
| 964 | } | - |
| 965 | | - |
| 966 | bool QFileDialog::resolveSymlinks() const | - |
| 967 | { | - |
| 968 | return !testOption(DontResolveSymlinks); | - |
| 969 | } | - |
| 970 | void QFileDialog::setConfirmOverwrite(bool enabled) | - |
| 971 | { | - |
| 972 | setOption(DontConfirmOverwrite, !enabled); | - |
| 973 | } | - |
| 974 | | - |
| 975 | bool QFileDialog::confirmOverwrite() const | - |
| 976 | { | - |
| 977 | return !testOption(DontConfirmOverwrite); | - |
| 978 | } | - |
| 979 | void QFileDialog::setDefaultSuffix(const QString &suffix) | - |
| 980 | { | - |
| 981 | QFileDialogPrivate * const d = d_func(); | - |
| 982 | d->options->setDefaultSuffix(suffix); | - |
| 983 | } | - |
| 984 | | - |
| 985 | QString QFileDialog::defaultSuffix() const | - |
| 986 | { | - |
| 987 | const QFileDialogPrivate * const d = d_func(); | - |
| 988 | return d->options->defaultSuffix(); | - |
| 989 | } | - |
| 990 | | - |
| 991 | | - |
| 992 | | - |
| 993 | | - |
| 994 | | - |
| 995 | void QFileDialog::setHistory(const QStringList &paths) | - |
| 996 | { | - |
| 997 | QFileDialogPrivate * const d = d_func(); | - |
| 998 | d->qFileDialogUi->lookInCombo->setHistory(paths); | - |
| 999 | } | - |
| 1000 | | - |
| 1001 | void QFileDialogComboBox::setHistory(const QStringList &paths) | - |
| 1002 | { | - |
| 1003 | m_history = paths; | - |
| 1004 | | - |
| 1005 | QList<QUrl> list; | - |
| 1006 | QModelIndex idx = d_ptr->model->index(d_ptr->rootPath()); | - |
| 1007 | | - |
| 1008 | QUrl url = QUrl::fromLocalFile(QDir::toNativeSeparators(idx.data(QFileSystemModel::FilePathRole).toString())); | - |
| 1009 | if (url.isValid()) | - |
| 1010 | list.append(url); | - |
| 1011 | urlModel->setUrls(list); | - |
| 1012 | } | - |
| 1013 | | - |
| 1014 | | - |
| 1015 | | - |
| 1016 | | - |
| 1017 | QStringList QFileDialog::history() const | - |
| 1018 | { | - |
| 1019 | const QFileDialogPrivate * const d = d_func(); | - |
| 1020 | QStringList currentHistory = d->qFileDialogUi->lookInCombo->history(); | - |
| 1021 | | - |
| 1022 | QString newHistory = QDir::toNativeSeparators(d->rootIndex().data(QFileSystemModel::FilePathRole).toString()); | - |
| 1023 | if (!currentHistory.contains(newHistory)) | - |
| 1024 | currentHistory << newHistory; | - |
| 1025 | return currentHistory; | - |
| 1026 | } | - |
| 1027 | void QFileDialog::setItemDelegate(QAbstractItemDelegate *delegate) | - |
| 1028 | { | - |
| 1029 | QFileDialogPrivate * const d = d_func(); | - |
| 1030 | d->qFileDialogUi->listView->setItemDelegate(delegate); | - |
| 1031 | d->qFileDialogUi->treeView->setItemDelegate(delegate); | - |
| 1032 | } | - |
| 1033 | | - |
| 1034 | | - |
| 1035 | | - |
| 1036 | | - |
| 1037 | QAbstractItemDelegate *QFileDialog::itemDelegate() const | - |
| 1038 | { | - |
| 1039 | const QFileDialogPrivate * const d = d_func(); | - |
| 1040 | return d->qFileDialogUi->listView->itemDelegate(); | - |
| 1041 | } | - |
| 1042 | | - |
| 1043 | | - |
| 1044 | | - |
| 1045 | | - |
| 1046 | void QFileDialog::setIconProvider(QFileIconProvider *provider) | - |
| 1047 | { | - |
| 1048 | QFileDialogPrivate * const d = d_func(); | - |
| 1049 | d->model->setIconProvider(provider); | - |
| 1050 | | - |
| 1051 | d->qFileDialogUi->sidebar->setUrls(d->qFileDialogUi->sidebar->urls()); | - |
| 1052 | } | - |
| 1053 | | - |
| 1054 | | - |
| 1055 | | - |
| 1056 | | - |
| 1057 | QFileIconProvider *QFileDialog::iconProvider() const | - |
| 1058 | { | - |
| 1059 | const QFileDialogPrivate * const d = d_func(); | - |
| 1060 | return d->model->iconProvider(); | - |
| 1061 | } | - |
| 1062 | | - |
| 1063 | void QFileDialogPrivate::setLabelTextControl(QFileDialog::DialogLabel label, const QString &text) | - |
| 1064 | { | - |
| 1065 | switch (label) { | - |
| 1066 | case QFileDialog::LookIn: | - |
| 1067 | qFileDialogUi->lookInLabel->setText(text); | - |
| 1068 | break; | - |
| 1069 | case QFileDialog::FileName: | - |
| 1070 | qFileDialogUi->fileNameLabel->setText(text); | - |
| 1071 | break; | - |
| 1072 | case QFileDialog::FileType: | - |
| 1073 | qFileDialogUi->fileTypeLabel->setText(text); | - |
| 1074 | break; | - |
| 1075 | case QFileDialog::Accept: | - |
| 1076 | if (q_func()->acceptMode() == QFileDialog::AcceptOpen) { | - |
| 1077 | if (QPushButton *button = qFileDialogUi->buttonBox->button(QDialogButtonBox::Open)) | - |
| 1078 | button->setText(text); | - |
| 1079 | } else { | - |
| 1080 | if (QPushButton *button = qFileDialogUi->buttonBox->button(QDialogButtonBox::Save)) | - |
| 1081 | button->setText(text); | - |
| 1082 | } | - |
| 1083 | break; | - |
| 1084 | case QFileDialog::Reject: | - |
| 1085 | if (QPushButton *button = qFileDialogUi->buttonBox->button(QDialogButtonBox::Cancel)) | - |
| 1086 | button->setText(text); | - |
| 1087 | break; | - |
| 1088 | } | - |
| 1089 | } | - |
| 1090 | | - |
| 1091 | | - |
| 1092 | | - |
| 1093 | | - |
| 1094 | | - |
| 1095 | void QFileDialog::setLabelText(DialogLabel label, const QString &text) | - |
| 1096 | { | - |
| 1097 | QFileDialogPrivate * const d = d_func(); | - |
| 1098 | d->options->setLabelText(static_cast<QFileDialogOptions::DialogLabel>(label), text); | - |
| 1099 | d->setLabelTextControl(label, text); | - |
| 1100 | } | - |
| 1101 | | - |
| 1102 | | - |
| 1103 | | - |
| 1104 | | - |
| 1105 | QString QFileDialog::labelText(DialogLabel label) const | - |
| 1106 | { | - |
| 1107 | QPushButton *button; | - |
| 1108 | const QFileDialogPrivate * const d = d_func(); | - |
| 1109 | switch (label) { | - |
| 1110 | case LookIn: | - |
| 1111 | return d->qFileDialogUi->lookInLabel->text(); | - |
| 1112 | case FileName: | - |
| 1113 | return d->qFileDialogUi->fileNameLabel->text(); | - |
| 1114 | case FileType: | - |
| 1115 | return d->qFileDialogUi->fileTypeLabel->text(); | - |
| 1116 | case Accept: | - |
| 1117 | if (acceptMode() == AcceptOpen) | - |
| 1118 | button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Open); | - |
| 1119 | else | - |
| 1120 | button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Save); | - |
| 1121 | if (button) | - |
| 1122 | return button->text(); | - |
| 1123 | case Reject: | - |
| 1124 | button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Cancel); | - |
| 1125 | if (button) | - |
| 1126 | return button->text(); | - |
| 1127 | } | - |
| 1128 | return QString(); | - |
| 1129 | } | - |
| 1130 | QString QFileDialog::getOpenFileName(QWidget *parent, | - |
| 1131 | const QString &caption, | - |
| 1132 | const QString &dir, | - |
| 1133 | const QString &filter, | - |
| 1134 | QString *selectedFilter, | - |
| 1135 | Options options) | - |
| 1136 | { | - |
| 1137 | if (qt_filedialog_open_filename_hook && !(options & DontUseNativeDialog)) | - |
| 1138 | return qt_filedialog_open_filename_hook(parent, caption, dir, filter, selectedFilter, options); | - |
| 1139 | QFileDialogArgs args; | - |
| 1140 | args.parent = parent; | - |
| 1141 | args.caption = caption; | - |
| 1142 | args.directory = QFileDialogPrivate::workingDirectory(dir); | - |
| 1143 | args.selection = QFileDialogPrivate::initialSelection(dir); | - |
| 1144 | args.filter = filter; | - |
| 1145 | args.mode = ExistingFile; | - |
| 1146 | args.options = options; | - |
| 1147 | | - |
| 1148 | | - |
| 1149 | | - |
| 1150 | | - |
| 1151 | | - |
| 1152 | | - |
| 1153 | | - |
| 1154 | QFileDialog dialog(args); | - |
| 1155 | if (selectedFilter && !selectedFilter->isEmpty()) | - |
| 1156 | dialog.selectNameFilter(*selectedFilter); | - |
| 1157 | if (dialog.exec() == QDialog::Accepted) { | - |
| 1158 | if (selectedFilter) | - |
| 1159 | *selectedFilter = dialog.selectedNameFilter(); | - |
| 1160 | return dialog.selectedFiles().value(0); | - |
| 1161 | } | - |
| 1162 | return QString(); | - |
| 1163 | } | - |
| 1164 | QStringList QFileDialog::getOpenFileNames(QWidget *parent, | - |
| 1165 | const QString &caption, | - |
| 1166 | const QString &dir, | - |
| 1167 | const QString &filter, | - |
| 1168 | QString *selectedFilter, | - |
| 1169 | Options options) | - |
| 1170 | { | - |
| 1171 | if (qt_filedialog_open_filenames_hook && !(options & DontUseNativeDialog)) | - |
| 1172 | return qt_filedialog_open_filenames_hook(parent, caption, dir, filter, selectedFilter, options); | - |
| 1173 | QFileDialogArgs args; | - |
| 1174 | args.parent = parent; | - |
| 1175 | args.caption = caption; | - |
| 1176 | args.directory = QFileDialogPrivate::workingDirectory(dir); | - |
| 1177 | args.selection = QFileDialogPrivate::initialSelection(dir); | - |
| 1178 | args.filter = filter; | - |
| 1179 | args.mode = ExistingFiles; | - |
| 1180 | args.options = options; | - |
| 1181 | QFileDialog dialog(args); | - |
| 1182 | if (selectedFilter && !selectedFilter->isEmpty()) | - |
| 1183 | dialog.selectNameFilter(*selectedFilter); | - |
| 1184 | if (dialog.exec() == QDialog::Accepted) { | - |
| 1185 | if (selectedFilter) | - |
| 1186 | *selectedFilter = dialog.selectedNameFilter(); | - |
| 1187 | return dialog.selectedFiles(); | - |
| 1188 | } | - |
| 1189 | return QStringList(); | - |
| 1190 | } | - |
| 1191 | QString QFileDialog::getSaveFileName(QWidget *parent, | - |
| 1192 | const QString &caption, | - |
| 1193 | const QString &dir, | - |
| 1194 | const QString &filter, | - |
| 1195 | QString *selectedFilter, | - |
| 1196 | Options options) | - |
| 1197 | { | - |
| 1198 | if (qt_filedialog_save_filename_hook && !(options & DontUseNativeDialog)) | - |
| 1199 | return qt_filedialog_save_filename_hook(parent, caption, dir, filter, selectedFilter, options); | - |
| 1200 | QFileDialogArgs args; | - |
| 1201 | args.parent = parent; | - |
| 1202 | args.caption = caption; | - |
| 1203 | args.directory = QFileDialogPrivate::workingDirectory(dir); | - |
| 1204 | args.selection = QFileDialogPrivate::initialSelection(dir); | - |
| 1205 | args.filter = filter; | - |
| 1206 | args.mode = AnyFile; | - |
| 1207 | args.options = options; | - |
| 1208 | QFileDialog dialog(args); | - |
| 1209 | dialog.setAcceptMode(AcceptSave); | - |
| 1210 | if (selectedFilter && !selectedFilter->isEmpty()) | - |
| 1211 | dialog.selectNameFilter(*selectedFilter); | - |
| 1212 | if (dialog.exec() == QDialog::Accepted) { | - |
| 1213 | if (selectedFilter) | - |
| 1214 | *selectedFilter = dialog.selectedNameFilter(); | - |
| 1215 | return dialog.selectedFiles().value(0); | - |
| 1216 | } | - |
| 1217 | | - |
| 1218 | return QString(); | - |
| 1219 | } | - |
| 1220 | QString QFileDialog::getExistingDirectory(QWidget *parent, | - |
| 1221 | const QString &caption, | - |
| 1222 | const QString &dir, | - |
| 1223 | Options options) | - |
| 1224 | { | - |
| 1225 | if (qt_filedialog_existing_directory_hook && !(options & DontUseNativeDialog)) | - |
| 1226 | return qt_filedialog_existing_directory_hook(parent, caption, dir, options); | - |
| 1227 | QFileDialogArgs args; | - |
| 1228 | args.parent = parent; | - |
| 1229 | args.caption = caption; | - |
| 1230 | args.directory = QFileDialogPrivate::workingDirectory(dir); | - |
| 1231 | args.mode = (options & ShowDirsOnly ? DirectoryOnly : Directory); | - |
| 1232 | args.options = options; | - |
| 1233 | QFileDialog dialog(args); | - |
| 1234 | if (dialog.exec() == QDialog::Accepted) { | - |
| 1235 | return dialog.selectedFiles().value(0); | - |
| 1236 | } | - |
| 1237 | return QString(); | - |
| 1238 | } | - |
| 1239 | | - |
| 1240 | inline static QString _qt_get_directory(const QString &path) | - |
| 1241 | { | - |
| 1242 | QFileInfo info = QFileInfo(QDir::current(), path); | - |
| 1243 | if (info.exists() && info.isDir()) | - |
| 1244 | return QDir::cleanPath(info.absoluteFilePath()); | - |
| 1245 | info.setFile(info.absolutePath()); | - |
| 1246 | if (info.exists() && info.isDir()) | - |
| 1247 | return info.absoluteFilePath(); | - |
| 1248 | return QString(); | - |
| 1249 | } | - |
| 1250 | | - |
| 1251 | | - |
| 1252 | | - |
| 1253 | | - |
| 1254 | | - |
| 1255 | QString QFileDialogPrivate::workingDirectory(const QString &path) | - |
| 1256 | { | - |
| 1257 | if (!path.isEmpty()) { | - |
| 1258 | QString directory = _qt_get_directory(path); | - |
| 1259 | if (!directory.isEmpty()) | - |
| 1260 | return directory; | - |
| 1261 | } | - |
| 1262 | QString directory = _qt_get_directory(*lastVisitedDir()); | - |
| 1263 | if (!directory.isEmpty()) | - |
| 1264 | return directory; | - |
| 1265 | return QDir::currentPath(); | - |
| 1266 | } | - |
| 1267 | QString QFileDialogPrivate::initialSelection(const QString &path) | - |
| 1268 | { | - |
| 1269 | if (!path.isEmpty()) { | - |
| 1270 | QFileInfo info(path); | - |
| 1271 | if (!info.isDir()) | - |
| 1272 | return info.fileName(); | - |
| 1273 | } | - |
| 1274 | return QString(); | - |
| 1275 | } | - |
| 1276 | | - |
| 1277 | | - |
| 1278 | | - |
| 1279 | | - |
| 1280 | void QFileDialog::done(int result) | - |
| 1281 | { | - |
| 1282 | QFileDialogPrivate * const d = d_func(); | - |
| 1283 | | - |
| 1284 | QDialog::done(result); | - |
| 1285 | | - |
| 1286 | if (d->receiverToDisconnectOnClose) { | - |
| 1287 | disconnect(this, d->signalToDisconnectOnClose, | - |
| 1288 | d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose); | - |
| 1289 | d->receiverToDisconnectOnClose = 0; | - |
| 1290 | } | - |
| 1291 | d->memberToDisconnectOnClose.clear(); | - |
| 1292 | d->signalToDisconnectOnClose.clear(); | - |
| 1293 | } | - |
| 1294 | | - |
| 1295 | | - |
| 1296 | | - |
| 1297 | | - |
| 1298 | void QFileDialog::accept() | - |
| 1299 | { | - |
| 1300 | QFileDialogPrivate * const d = d_func(); | - |
| 1301 | QStringList files = selectedFiles(); | - |
| 1302 | if (files.isEmpty()) | - |
| 1303 | return; | - |
| 1304 | if (d->nativeDialogInUse){ | - |
| 1305 | d->emitFilesSelected(files); | - |
| 1306 | QDialog::accept(); | - |
| 1307 | return; | - |
| 1308 | } | - |
| 1309 | | - |
| 1310 | QString lineEditText = d->lineEdit()->text(); | - |
| 1311 | | - |
| 1312 | | - |
| 1313 | if (lineEditText == QLatin1String("..")) { | - |
| 1314 | d->_q_navigateToParent(); | - |
| 1315 | bool block = d->qFileDialogUi->fileNameEdit->blockSignals(true); | - |
| 1316 | d->lineEdit()->selectAll(); | - |
| 1317 | d->qFileDialogUi->fileNameEdit->blockSignals(block); | - |
| 1318 | return; | - |
| 1319 | } | - |
| 1320 | | - |
| 1321 | switch (fileMode()) { | - |
| 1322 | case DirectoryOnly: | - |
| 1323 | case Directory: { | - |
| 1324 | QString fn = files.first(); | - |
| 1325 | QFileInfo info(fn); | - |
| 1326 | if (!info.exists()) | - |
| 1327 | info = QFileInfo(d->getEnvironmentVariable(fn)); | - |
| 1328 | if (!info.exists()) { | - |
| 1329 | | - |
| 1330 | QString message = tr("%1\nDirectory not found.\nPlease verify the " | - |
| 1331 | "correct directory name was given."); | - |
| 1332 | QMessageBox::warning(this, windowTitle(), message.arg(info.fileName())); | - |
| 1333 | | - |
| 1334 | return; | - |
| 1335 | } | - |
| 1336 | if (info.isDir()) { | - |
| 1337 | d->emitFilesSelected(files); | - |
| 1338 | QDialog::accept(); | - |
| 1339 | } | - |
| 1340 | return; | - |
| 1341 | } | - |
| 1342 | | - |
| 1343 | case AnyFile: { | - |
| 1344 | QString fn = files.first(); | - |
| 1345 | QFileInfo info(fn); | - |
| 1346 | if (info.isDir()) { | - |
| 1347 | setDirectory(info.absoluteFilePath()); | - |
| 1348 | return; | - |
| 1349 | } | - |
| 1350 | | - |
| 1351 | if (!info.exists()) { | - |
| 1352 | int maxNameLength = d->maxNameLength(info.path()); | - |
| 1353 | if (maxNameLength >= 0 && info.fileName().length() > maxNameLength) | - |
| 1354 | return; | - |
| 1355 | } | - |
| 1356 | | - |
| 1357 | | - |
| 1358 | if (!info.exists() || !confirmOverwrite() || acceptMode() == AcceptOpen) { | - |
| 1359 | d->emitFilesSelected(QStringList(fn)); | - |
| 1360 | QDialog::accept(); | - |
| 1361 | | - |
| 1362 | } else { | - |
| 1363 | if (QMessageBox::warning(this, windowTitle(), | - |
| 1364 | tr("%1 already exists.\nDo you want to replace it?") | - |
| 1365 | .arg(info.fileName()), | - |
| 1366 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No) | - |
| 1367 | == QMessageBox::Yes) { | - |
| 1368 | d->emitFilesSelected(QStringList(fn)); | - |
| 1369 | QDialog::accept(); | - |
| 1370 | } | - |
| 1371 | | - |
| 1372 | } | - |
| 1373 | return; | - |
| 1374 | } | - |
| 1375 | | - |
| 1376 | case ExistingFile: | - |
| 1377 | case ExistingFiles: | - |
| 1378 | for (int i = 0; i < files.count(); ++i) { | - |
| 1379 | QFileInfo info(files.at(i)); | - |
| 1380 | if (!info.exists()) | - |
| 1381 | info = QFileInfo(d->getEnvironmentVariable(files.at(i))); | - |
| 1382 | if (!info.exists()) { | - |
| 1383 | | - |
| 1384 | QString message = tr("%1\nFile not found.\nPlease verify the " | - |
| 1385 | "correct file name was given."); | - |
| 1386 | QMessageBox::warning(this, windowTitle(), message.arg(info.fileName())); | - |
| 1387 | | - |
| 1388 | return; | - |
| 1389 | } | - |
| 1390 | if (info.isDir()) { | - |
| 1391 | setDirectory(info.absoluteFilePath()); | - |
| 1392 | d->lineEdit()->clear(); | - |
| 1393 | return; | - |
| 1394 | } | - |
| 1395 | } | - |
| 1396 | d->emitFilesSelected(files); | - |
| 1397 | QDialog::accept(); | - |
| 1398 | return; | - |
| 1399 | } | - |
| 1400 | } | - |
| 1401 | | - |
| 1402 | | - |
| 1403 | | - |
| 1404 | | - |
| 1405 | | - |
| 1406 | | - |
| 1407 | void QFileDialogPrivate::init(const QString &directory, const QString &nameFilter, | - |
| 1408 | const QString &caption) | - |
| 1409 | { | - |
| 1410 | QFileDialog * const q = q_func(); | - |
| 1411 | if (!caption.isEmpty()) { | - |
| 1412 | useDefaultCaption = false; | - |
| 1413 | setWindowTitle = caption; | - |
| 1414 | q->setWindowTitle(caption); | - |
| 1415 | } | - |
| 1416 | | - |
| 1417 | createWidgets(); | - |
| 1418 | createMenuActions(); | - |
| 1419 | retranslateStrings(); | - |
| 1420 | q->setFileMode(QFileDialog::AnyFile); | - |
| 1421 | | - |
| 1422 | | - |
| 1423 | QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); | - |
| 1424 | settings.beginGroup(QLatin1String("Qt")); | - |
| 1425 | if (!directory.isEmpty()) | - |
| 1426 | setLastVisitedDirectory(workingDirectory(directory)); | - |
| 1427 | q->restoreState(settings.value(QLatin1String("filedialog")).toByteArray()); | - |
| 1428 | if (!nameFilter.isEmpty()) | - |
| 1429 | q->setNameFilter(nameFilter); | - |
| 1430 | q->setAcceptMode(QFileDialog::AcceptOpen); | - |
| 1431 | q->setDirectory(workingDirectory(directory)); | - |
| 1432 | q->selectFile(initialSelection(directory)); | - |
| 1433 | | - |
| 1434 | _q_updateOkButton(); | - |
| 1435 | q->resize(q->sizeHint()); | - |
| 1436 | } | - |
| 1437 | | - |
| 1438 | | - |
| 1439 | | - |
| 1440 | | - |
| 1441 | | - |
| 1442 | | - |
| 1443 | void QFileDialogPrivate::createWidgets() | - |
| 1444 | { | - |
| 1445 | QFileDialog * const q = q_func(); | - |
| 1446 | model = new QFileSystemModel(q); | - |
| 1447 | options->setFilter(model->filter()); | - |
| 1448 | model->setObjectName(QLatin1String("qt_filesystem_model")); | - |
| 1449 | if (QPlatformFileDialogHelper *helper = platformFileDialogHelper()) | - |
| 1450 | model->setNameFilterDisables(helper->defaultNameFilterDisables()); | - |
| 1451 | else | - |
| 1452 | model->setNameFilterDisables(false); | - |
| 1453 | model->d_func()->disableRecursiveSort = true; | - |
| 1454 | QFileDialog::connect(model, "2""fileRenamed(QString,QString,QString)", q, "1""_q_fileRenamed(QString,QString,QString)"); | - |
| 1455 | QFileDialog::connect(model, "2""rootPathChanged(QString)", | - |
| 1456 | q, "1""_q_pathChanged(QString)"); | - |
| 1457 | QFileDialog::connect(model, "2""rowsInserted(QModelIndex,int,int)", | - |
| 1458 | q, "1""_q_rowsInserted(QModelIndex)"); | - |
| 1459 | model->setReadOnly(false); | - |
| 1460 | | - |
| 1461 | qFileDialogUi.reset(new Ui_QFileDialog()); | - |
| 1462 | qFileDialogUi->setupUi(q); | - |
| 1463 | | - |
| 1464 | QList<QUrl> initialBookmarks; | - |
| 1465 | initialBookmarks << QUrl::fromLocalFile(QLatin1String("")) | - |
| 1466 | << QUrl::fromLocalFile(QDir::homePath()); | - |
| 1467 | qFileDialogUi->sidebar->setModelAndUrls(model, initialBookmarks); | - |
| 1468 | QFileDialog::connect(qFileDialogUi->sidebar, "2""goToUrl(QUrl)", | - |
| 1469 | q, "1""_q_goToUrl(QUrl)"); | - |
| 1470 | | - |
| 1471 | QObject::connect(qFileDialogUi->buttonBox, "2""accepted()", q, "1""accept()"); | - |
| 1472 | QObject::connect(qFileDialogUi->buttonBox, "2""rejected()", q, "1""reject()"); | - |
| 1473 | | - |
| 1474 | qFileDialogUi->lookInCombo->setFileDialogPrivate(this); | - |
| 1475 | QObject::connect(qFileDialogUi->lookInCombo, "2""activated(QString)", q, "1""_q_goToDirectory(QString)"); | - |
| 1476 | | - |
| 1477 | qFileDialogUi->lookInCombo->setInsertPolicy(QComboBox::NoInsert); | - |
| 1478 | qFileDialogUi->lookInCombo->setDuplicatesEnabled(false); | - |
| 1479 | | - |
| 1480 | | - |
| 1481 | qFileDialogUi->fileNameEdit->setFileDialogPrivate(this); | - |
| 1482 | | - |
| 1483 | qFileDialogUi->fileNameLabel->setBuddy(qFileDialogUi->fileNameEdit); | - |
| 1484 | | - |
| 1485 | | - |
| 1486 | completer = new QFSCompleter(model, q); | - |
| 1487 | qFileDialogUi->fileNameEdit->setCompleter(completer); | - |
| 1488 | | - |
| 1489 | QObject::connect(qFileDialogUi->fileNameEdit, "2""textChanged(QString)", | - |
| 1490 | q, "1""_q_autoCompleteFileName(QString)"); | - |
| 1491 | QObject::connect(qFileDialogUi->fileNameEdit, "2""textChanged(QString)", | - |
| 1492 | q, "1""_q_updateOkButton()"); | - |
| 1493 | | - |
| 1494 | QObject::connect(qFileDialogUi->fileNameEdit, "2""returnPressed()", q, "1""accept()"); | - |
| 1495 | | - |
| 1496 | | - |
| 1497 | qFileDialogUi->fileTypeCombo->setDuplicatesEnabled(false); | - |
| 1498 | qFileDialogUi->fileTypeCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength); | - |
| 1499 | qFileDialogUi->fileTypeCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); | - |
| 1500 | QObject::connect(qFileDialogUi->fileTypeCombo, "2""activated(int)", | - |
| 1501 | q, "1""_q_useNameFilter(int)"); | - |
| 1502 | QObject::connect(qFileDialogUi->fileTypeCombo, "2""activated(QString)", | - |
| 1503 | q, "2""filterSelected(QString)"); | - |
| 1504 | | - |
| 1505 | qFileDialogUi->listView->setFileDialogPrivate(this); | - |
| 1506 | qFileDialogUi->listView->setModel(model); | - |
| 1507 | QObject::connect(qFileDialogUi->listView, "2""activated(QModelIndex)", | - |
| 1508 | q, "1""_q_enterDirectory(QModelIndex)"); | - |
| 1509 | QObject::connect(qFileDialogUi->listView, "2""customContextMenuRequested(QPoint)", | - |
| 1510 | q, "1""_q_showContextMenu(QPoint)"); | - |
| 1511 | | - |
| 1512 | QShortcut *shortcut = new QShortcut(qFileDialogUi->listView); | - |
| 1513 | shortcut->setKey(QKeySequence(QLatin1String("Delete"))); | - |
| 1514 | QObject::connect(shortcut, "2""activated()", q, "1""_q_deleteCurrent()"); | - |
| 1515 | | - |
| 1516 | | - |
| 1517 | qFileDialogUi->treeView->setFileDialogPrivate(this); | - |
| 1518 | qFileDialogUi->treeView->setModel(model); | - |
| 1519 | QHeaderView *treeHeader = qFileDialogUi->treeView->header(); | - |
| 1520 | QFontMetrics fm(q->font()); | - |
| 1521 | treeHeader->resizeSection(0, fm.width(QLatin1String("wwwwwwwwwwwwwwwwwwwwwwwwww"))); | - |
| 1522 | treeHeader->resizeSection(1, fm.width(QLatin1String("128.88 GB"))); | - |
| 1523 | treeHeader->resizeSection(2, fm.width(QLatin1String("mp3Folder"))); | - |
| 1524 | treeHeader->resizeSection(3, fm.width(QLatin1String("10/29/81 02:02PM"))); | - |
| 1525 | treeHeader->setContextMenuPolicy(Qt::ActionsContextMenu); | - |
| 1526 | | - |
| 1527 | QActionGroup *showActionGroup = new QActionGroup(q); | - |
| 1528 | showActionGroup->setExclusive(false); | - |
| 1529 | QObject::connect(showActionGroup, "2""triggered(QAction*)", | - |
| 1530 | q, "1""_q_showHeader(QAction*)");; | - |
| 1531 | | - |
| 1532 | QAbstractItemModel *abstractModel = model; | - |
| 1533 | | - |
| 1534 | if (proxyModel) | - |
| 1535 | abstractModel = proxyModel; | - |
| 1536 | | - |
| 1537 | for (int i = 1; i < abstractModel->columnCount(QModelIndex()); ++i) { | - |
| 1538 | QAction *showHeader = new QAction(showActionGroup); | - |
| 1539 | showHeader->setCheckable(true); | - |
| 1540 | showHeader->setChecked(true); | - |
| 1541 | treeHeader->addAction(showHeader); | - |
| 1542 | } | - |
| 1543 | | - |
| 1544 | QScopedPointer<QItemSelectionModel> selModel(qFileDialogUi->treeView->selectionModel()); | - |
| 1545 | qFileDialogUi->treeView->setSelectionModel(qFileDialogUi->listView->selectionModel()); | - |
| 1546 | | - |
| 1547 | QObject::connect(qFileDialogUi->treeView, "2""activated(QModelIndex)", | - |
| 1548 | q, "1""_q_enterDirectory(QModelIndex)"); | - |
| 1549 | QObject::connect(qFileDialogUi->treeView, "2""customContextMenuRequested(QPoint)", | - |
| 1550 | q, "1""_q_showContextMenu(QPoint)"); | - |
| 1551 | | - |
| 1552 | shortcut = new QShortcut(qFileDialogUi->treeView); | - |
| 1553 | shortcut->setKey(QKeySequence(QLatin1String("Delete"))); | - |
| 1554 | QObject::connect(shortcut, "2""activated()", q, "1""_q_deleteCurrent()"); | - |
| 1555 | | - |
| 1556 | | - |
| 1557 | | - |
| 1558 | QItemSelectionModel *selections = qFileDialogUi->listView->selectionModel(); | - |
| 1559 | QObject::connect(selections, "2""selectionChanged(QItemSelection,QItemSelection)", | - |
| 1560 | q, "1""_q_selectionChanged()"); | - |
| 1561 | QObject::connect(selections, "2""currentChanged(QModelIndex,QModelIndex)", | - |
| 1562 | q, "1""_q_currentChanged(QModelIndex)"); | - |
| 1563 | qFileDialogUi->splitter->setStretchFactor(qFileDialogUi->splitter->indexOf(qFileDialogUi->splitter->widget(1)), QSizePolicy::Expanding); | - |
| 1564 | | - |
| 1565 | createToolButtons(); | - |
| 1566 | } | - |
| 1567 | | - |
| 1568 | void QFileDialogPrivate::_q_showHeader(QAction *action) | - |
| 1569 | { | - |
| 1570 | QFileDialog * const q = q_func(); | - |
| 1571 | QActionGroup *actionGroup = qobject_cast<QActionGroup*>(q->sender()); | - |
| 1572 | qFileDialogUi->treeView->header()->setSectionHidden(actionGroup->actions().indexOf(action) + 1, !action->isChecked()); | - |
| 1573 | } | - |
| 1574 | void QFileDialog::setProxyModel(QAbstractProxyModel *proxyModel) | - |
| 1575 | { | - |
| 1576 | QFileDialogPrivate * const d = d_func(); | - |
| 1577 | if ((!proxyModel && !d->proxyModel) | - |
| 1578 | || (proxyModel == d->proxyModel)) | - |
| 1579 | return; | - |
| 1580 | | - |
| 1581 | QModelIndex idx = d->rootIndex(); | - |
| 1582 | if (d->proxyModel) { | - |
| 1583 | disconnect(d->proxyModel, "2""rowsInserted(QModelIndex,int,int)", | - |
| 1584 | this, "1""_q_rowsInserted(QModelIndex)"); | - |
| 1585 | } else { | - |
| 1586 | disconnect(d->model, "2""rowsInserted(QModelIndex,int,int)", | - |
| 1587 | this, "1""_q_rowsInserted(QModelIndex)"); | - |
| 1588 | } | - |
| 1589 | | - |
| 1590 | if (proxyModel != 0) { | - |
| 1591 | proxyModel->setParent(this); | - |
| 1592 | d->proxyModel = proxyModel; | - |
| 1593 | proxyModel->setSourceModel(d->model); | - |
| 1594 | d->qFileDialogUi->listView->setModel(d->proxyModel); | - |
| 1595 | d->qFileDialogUi->treeView->setModel(d->proxyModel); | - |
| 1596 | | - |
| 1597 | d->completer->setModel(d->proxyModel); | - |
| 1598 | d->completer->proxyModel = d->proxyModel; | - |
| 1599 | | - |
| 1600 | connect(d->proxyModel, "2""rowsInserted(QModelIndex,int,int)", | - |
| 1601 | this, "1""_q_rowsInserted(QModelIndex)"); | - |
| 1602 | } else { | - |
| 1603 | d->proxyModel = 0; | - |
| 1604 | d->qFileDialogUi->listView->setModel(d->model); | - |
| 1605 | d->qFileDialogUi->treeView->setModel(d->model); | - |
| 1606 | | - |
| 1607 | d->completer->setModel(d->model); | - |
| 1608 | d->completer->sourceModel = d->model; | - |
| 1609 | d->completer->proxyModel = 0; | - |
| 1610 | | - |
| 1611 | connect(d->model, "2""rowsInserted(QModelIndex,int,int)", | - |
| 1612 | this, "1""_q_rowsInserted(QModelIndex)"); | - |
| 1613 | } | - |
| 1614 | QScopedPointer<QItemSelectionModel> selModel(d->qFileDialogUi->treeView->selectionModel()); | - |
| 1615 | d->qFileDialogUi->treeView->setSelectionModel(d->qFileDialogUi->listView->selectionModel()); | - |
| 1616 | | - |
| 1617 | d->setRootIndex(idx); | - |
| 1618 | | - |
| 1619 | | - |
| 1620 | QItemSelectionModel *selections = d->qFileDialogUi->listView->selectionModel(); | - |
| 1621 | QObject::connect(selections, "2""selectionChanged(QItemSelection,QItemSelection)", | - |
| 1622 | this, "1""_q_selectionChanged()"); | - |
| 1623 | QObject::connect(selections, "2""currentChanged(QModelIndex,QModelIndex)", | - |
| 1624 | this, "1""_q_currentChanged(QModelIndex)"); | - |
| 1625 | } | - |
| 1626 | | - |
| 1627 | | - |
| 1628 | | - |
| 1629 | | - |
| 1630 | | - |
| 1631 | | - |
| 1632 | QAbstractProxyModel *QFileDialog::proxyModel() const | - |
| 1633 | { | - |
| 1634 | const QFileDialogPrivate * const d = d_func(); | - |
| 1635 | return d->proxyModel; | - |
| 1636 | } | - |
| 1637 | | - |
| 1638 | | - |
| 1639 | | - |
| 1640 | | - |
| 1641 | | - |
| 1642 | | - |
| 1643 | | - |
| 1644 | void QFileDialogPrivate::createToolButtons() | - |
| 1645 | { | - |
| 1646 | QFileDialog * const q = q_func(); | - |
| 1647 | qFileDialogUi->backButton->setIcon(q->style()->standardIcon(QStyle::SP_ArrowBack, 0, q)); | - |
| 1648 | qFileDialogUi->backButton->setAutoRaise(true); | - |
| 1649 | qFileDialogUi->backButton->setEnabled(false); | - |
| 1650 | QObject::connect(qFileDialogUi->backButton, "2""clicked()", q, "1""_q_navigateBackward()"); | - |
| 1651 | | - |
| 1652 | qFileDialogUi->forwardButton->setIcon(q->style()->standardIcon(QStyle::SP_ArrowForward, 0, q)); | - |
| 1653 | qFileDialogUi->forwardButton->setAutoRaise(true); | - |
| 1654 | qFileDialogUi->forwardButton->setEnabled(false); | - |
| 1655 | QObject::connect(qFileDialogUi->forwardButton, "2""clicked()", q, "1""_q_navigateForward()"); | - |
| 1656 | | - |
| 1657 | qFileDialogUi->toParentButton->setIcon(q->style()->standardIcon(QStyle::SP_FileDialogToParent, 0, q)); | - |
| 1658 | qFileDialogUi->toParentButton->setAutoRaise(true); | - |
| 1659 | qFileDialogUi->toParentButton->setEnabled(false); | - |
| 1660 | QObject::connect(qFileDialogUi->toParentButton, "2""clicked()", q, "1""_q_navigateToParent()"); | - |
| 1661 | | - |
| 1662 | qFileDialogUi->listModeButton->setIcon(q->style()->standardIcon(QStyle::SP_FileDialogListView, 0, q)); | - |
| 1663 | qFileDialogUi->listModeButton->setAutoRaise(true); | - |
| 1664 | qFileDialogUi->listModeButton->setDown(true); | - |
| 1665 | QObject::connect(qFileDialogUi->listModeButton, "2""clicked()", q, "1""_q_showListView()"); | - |
| 1666 | | - |
| 1667 | qFileDialogUi->detailModeButton->setIcon(q->style()->standardIcon(QStyle::SP_FileDialogDetailedView, 0, q)); | - |
| 1668 | qFileDialogUi->detailModeButton->setAutoRaise(true); | - |
| 1669 | QObject::connect(qFileDialogUi->detailModeButton, "2""clicked()", q, "1""_q_showDetailsView()"); | - |
| 1670 | | - |
| 1671 | QSize toolSize(qFileDialogUi->fileNameEdit->sizeHint().height(), qFileDialogUi->fileNameEdit->sizeHint().height()); | - |
| 1672 | qFileDialogUi->backButton->setFixedSize(toolSize); | - |
| 1673 | qFileDialogUi->listModeButton->setFixedSize(toolSize); | - |
| 1674 | qFileDialogUi->detailModeButton->setFixedSize(toolSize); | - |
| 1675 | qFileDialogUi->forwardButton->setFixedSize(toolSize); | - |
| 1676 | qFileDialogUi->toParentButton->setFixedSize(toolSize); | - |
| 1677 | | - |
| 1678 | qFileDialogUi->newFolderButton->setIcon(q->style()->standardIcon(QStyle::SP_FileDialogNewFolder, 0, q)); | - |
| 1679 | qFileDialogUi->newFolderButton->setFixedSize(toolSize); | - |
| 1680 | qFileDialogUi->newFolderButton->setAutoRaise(true); | - |
| 1681 | qFileDialogUi->newFolderButton->setEnabled(false); | - |
| 1682 | QObject::connect(qFileDialogUi->newFolderButton, "2""clicked()", q, "1""_q_createDirectory()"); | - |
| 1683 | } | - |
| 1684 | | - |
| 1685 | | - |
| 1686 | | - |
| 1687 | | - |
| 1688 | | - |
| 1689 | | - |
| 1690 | void QFileDialogPrivate::createMenuActions() | - |
| 1691 | { | - |
| 1692 | QFileDialog * const q = q_func(); | - |
| 1693 | | - |
| 1694 | QAction *goHomeAction = new QAction(q); | - |
| 1695 | | - |
| 1696 | goHomeAction->setShortcut(Qt::CTRL + Qt::Key_H + Qt::SHIFT); | - |
| 1697 | | - |
| 1698 | QObject::connect(goHomeAction, "2""triggered()", q, "1""_q_goHome()"); | - |
| 1699 | q->addAction(goHomeAction); | - |
| 1700 | | - |
| 1701 | | - |
| 1702 | | - |
| 1703 | QAction *goToParent = new QAction(q); | - |
| 1704 | goToParent->setObjectName(QLatin1String("qt_goto_parent_action")); | - |
| 1705 | | - |
| 1706 | goToParent->setShortcut(Qt::CTRL + Qt::UpArrow); | - |
| 1707 | | - |
| 1708 | QObject::connect(goToParent, "2""triggered()", q, "1""_q_navigateToParent()"); | - |
| 1709 | q->addAction(goToParent); | - |
| 1710 | | - |
| 1711 | renameAction = new QAction(q); | - |
| 1712 | renameAction->setEnabled(false); | - |
| 1713 | renameAction->setObjectName(QLatin1String("qt_rename_action")); | - |
| 1714 | QObject::connect(renameAction, "2""triggered()", q, "1""_q_renameCurrent()"); | - |
| 1715 | | - |
| 1716 | deleteAction = new QAction(q); | - |
| 1717 | deleteAction->setEnabled(false); | - |
| 1718 | deleteAction->setObjectName(QLatin1String("qt_delete_action")); | - |
| 1719 | QObject::connect(deleteAction, "2""triggered()", q, "1""_q_deleteCurrent()"); | - |
| 1720 | | - |
| 1721 | showHiddenAction = new QAction(q); | - |
| 1722 | showHiddenAction->setObjectName(QLatin1String("qt_show_hidden_action")); | - |
| 1723 | showHiddenAction->setCheckable(true); | - |
| 1724 | QObject::connect(showHiddenAction, "2""triggered()", q, "1""_q_showHidden()"); | - |
| 1725 | | - |
| 1726 | newFolderAction = new QAction(q); | - |
| 1727 | newFolderAction->setObjectName(QLatin1String("qt_new_folder_action")); | - |
| 1728 | QObject::connect(newFolderAction, "2""triggered()", q, "1""_q_createDirectory()"); | - |
| 1729 | } | - |
| 1730 | | - |
| 1731 | void QFileDialogPrivate::_q_goHome() | - |
| 1732 | { | - |
| 1733 | QFileDialog * const q = q_func(); | - |
| 1734 | q->setDirectory(QDir::homePath()); | - |
| 1735 | } | - |
| 1736 | | - |
| 1737 | | - |
| 1738 | | - |
| 1739 | | - |
| 1740 | | - |
| 1741 | | - |
| 1742 | void QFileDialogPrivate::_q_pathChanged(const QString &newPath) | - |
| 1743 | { | - |
| 1744 | QFileDialog * const q = q_func(); | - |
| 1745 | QDir dir(model->rootDirectory()); | - |
| 1746 | qFileDialogUi->toParentButton->setEnabled(dir.exists()); | - |
| 1747 | qFileDialogUi->sidebar->selectUrl(QUrl::fromLocalFile(newPath)); | - |
| 1748 | q->setHistory(qFileDialogUi->lookInCombo->history()); | - |
| 1749 | | - |
| 1750 | if (currentHistoryLocation < 0 || currentHistory.value(currentHistoryLocation) != QDir::toNativeSeparators(newPath)) { | - |
| 1751 | while (currentHistoryLocation >= 0 && currentHistoryLocation + 1 < currentHistory.count()) { | - |
| 1752 | currentHistory.removeLast(); | - |
| 1753 | } | - |
| 1754 | currentHistory.append(QDir::toNativeSeparators(newPath)); | - |
| 1755 | ++currentHistoryLocation; | - |
| 1756 | } | - |
| 1757 | qFileDialogUi->forwardButton->setEnabled(currentHistory.size() - currentHistoryLocation > 1); | - |
| 1758 | qFileDialogUi->backButton->setEnabled(currentHistoryLocation > 0); | - |
| 1759 | } | - |
| 1760 | | - |
| 1761 | | - |
| 1762 | | - |
| 1763 | | - |
| 1764 | | - |
| 1765 | | - |
| 1766 | void QFileDialogPrivate::_q_navigateBackward() | - |
| 1767 | { | - |
| 1768 | QFileDialog * const q = q_func(); | - |
| 1769 | if (!currentHistory.isEmpty() && currentHistoryLocation > 0) { | - |
| 1770 | --currentHistoryLocation; | - |
| 1771 | QString previousHistory = currentHistory.at(currentHistoryLocation); | - |
| 1772 | q->setDirectory(previousHistory); | - |
| 1773 | } | - |
| 1774 | } | - |
| 1775 | | - |
| 1776 | | - |
| 1777 | | - |
| 1778 | | - |
| 1779 | | - |
| 1780 | | - |
| 1781 | void QFileDialogPrivate::_q_navigateForward() | - |
| 1782 | { | - |
| 1783 | QFileDialog * const q = q_func(); | - |
| 1784 | if (!currentHistory.isEmpty() && currentHistoryLocation < currentHistory.size() - 1) { | - |
| 1785 | ++currentHistoryLocation; | - |
| 1786 | QString nextHistory = currentHistory.at(currentHistoryLocation); | - |
| 1787 | q->setDirectory(nextHistory); | - |
| 1788 | } | - |
| 1789 | } | - |
| 1790 | | - |
| 1791 | | - |
| 1792 | | - |
| 1793 | | - |
| 1794 | | - |
| 1795 | | - |
| 1796 | | - |
| 1797 | void QFileDialogPrivate::_q_navigateToParent() | - |
| 1798 | { | - |
| 1799 | QFileDialog * const q = q_func(); | - |
| 1800 | QDir dir(model->rootDirectory()); | - |
| 1801 | QString newDirectory; | - |
| 1802 | if (dir.isRoot()) { | - |
| 1803 | newDirectory = model->myComputer().toString(); | - |
| 1804 | } else { | - |
| 1805 | dir.cdUp(); | - |
| 1806 | newDirectory = dir.absolutePath(); | - |
| 1807 | } | - |
| 1808 | q->setDirectory(newDirectory); | - |
| 1809 | q->directoryEntered(newDirectory); | - |
| 1810 | } | - |
| 1811 | | - |
| 1812 | | - |
| 1813 | | - |
| 1814 | | - |
| 1815 | | - |
| 1816 | | - |
| 1817 | void QFileDialogPrivate::_q_createDirectory() | - |
| 1818 | { | - |
| 1819 | QFileDialog * const q = q_func(); | - |
| 1820 | qFileDialogUi->listView->clearSelection(); | - |
| 1821 | | - |
| 1822 | QString newFolderString = QFileDialog::tr("New Folder"); | - |
| 1823 | QString folderName = newFolderString; | - |
| 1824 | QString prefix = q->directory().absolutePath() + QDir::separator(); | - |
| 1825 | if (QFile::exists(prefix + folderName)) { | - |
| 1826 | qlonglong suffix = 2; | - |
| 1827 | while (QFile::exists(prefix + folderName)) { | - |
| 1828 | folderName = newFolderString + QString::number(suffix++); | - |
| 1829 | } | - |
| 1830 | } | - |
| 1831 | | - |
| 1832 | QModelIndex parent = rootIndex(); | - |
| 1833 | QModelIndex index = model->mkdir(parent, folderName); | - |
| 1834 | if (!index.isValid()) | - |
| 1835 | return; | - |
| 1836 | | - |
| 1837 | index = select(index); | - |
| 1838 | if (index.isValid()) { | - |
| 1839 | qFileDialogUi->treeView->setCurrentIndex(index); | - |
| 1840 | currentView()->edit(index); | - |
| 1841 | } | - |
| 1842 | } | - |
| 1843 | | - |
| 1844 | void QFileDialogPrivate::_q_showListView() | - |
| 1845 | { | - |
| 1846 | qFileDialogUi->listModeButton->setDown(true); | - |
| 1847 | qFileDialogUi->detailModeButton->setDown(false); | - |
| 1848 | qFileDialogUi->treeView->hide(); | - |
| 1849 | qFileDialogUi->listView->show(); | - |
| 1850 | qFileDialogUi->stackedWidget->setCurrentWidget(qFileDialogUi->listView->parentWidget()); | - |
| 1851 | qFileDialogUi->listView->doItemsLayout(); | - |
| 1852 | } | - |
| 1853 | | - |
| 1854 | void QFileDialogPrivate::_q_showDetailsView() | - |
| 1855 | { | - |
| 1856 | qFileDialogUi->listModeButton->setDown(false); | - |
| 1857 | qFileDialogUi->detailModeButton->setDown(true); | - |
| 1858 | qFileDialogUi->listView->hide(); | - |
| 1859 | qFileDialogUi->treeView->show(); | - |
| 1860 | qFileDialogUi->stackedWidget->setCurrentWidget(qFileDialogUi->treeView->parentWidget()); | - |
| 1861 | qFileDialogUi->treeView->doItemsLayout(); | - |
| 1862 | } | - |
| 1863 | | - |
| 1864 | | - |
| 1865 | | - |
| 1866 | | - |
| 1867 | | - |
| 1868 | | - |
| 1869 | void QFileDialogPrivate::_q_showContextMenu(const QPoint &position) | - |
| 1870 | { | - |
| 1871 | | - |
| 1872 | | - |
| 1873 | | - |
| 1874 | QFileDialog * const q = q_func(); | - |
| 1875 | QAbstractItemView *view = 0; | - |
| 1876 | if (q->viewMode() == QFileDialog::Detail) | - |
| 1877 | view = qFileDialogUi->treeView; | - |
| 1878 | else | - |
| 1879 | view = qFileDialogUi->listView; | - |
| 1880 | QModelIndex index = view->indexAt(position); | - |
| 1881 | index = mapToSource(index.sibling(index.row(), 0)); | - |
| 1882 | | - |
| 1883 | QMenu menu(view); | - |
| 1884 | if (index.isValid()) { | - |
| 1885 | | - |
| 1886 | const bool ro = model && model->isReadOnly(); | - |
| 1887 | QFile::Permissions p(index.parent().data(QFileSystemModel::FilePermissions).toInt()); | - |
| 1888 | renameAction->setEnabled(!ro && p & QFile::WriteUser); | - |
| 1889 | menu.addAction(renameAction); | - |
| 1890 | deleteAction->setEnabled(!ro && p & QFile::WriteUser); | - |
| 1891 | menu.addAction(deleteAction); | - |
| 1892 | menu.addSeparator(); | - |
| 1893 | } | - |
| 1894 | menu.addAction(showHiddenAction); | - |
| 1895 | if (qFileDialogUi->newFolderButton->isVisible()) { | - |
| 1896 | newFolderAction->setEnabled(qFileDialogUi->newFolderButton->isEnabled()); | - |
| 1897 | menu.addAction(newFolderAction); | - |
| 1898 | } | - |
| 1899 | menu.exec(view->viewport()->mapToGlobal(position)); | - |
| 1900 | | - |
| 1901 | } | - |
| 1902 | | - |
| 1903 | | - |
| 1904 | | - |
| 1905 | | - |
| 1906 | void QFileDialogPrivate::_q_renameCurrent() | - |
| 1907 | { | - |
| 1908 | QFileDialog * const q = q_func(); | - |
| 1909 | QModelIndex index = qFileDialogUi->listView->currentIndex(); | - |
| 1910 | index = index.sibling(index.row(), 0); | - |
| 1911 | if (q->viewMode() == QFileDialog::List) | - |
| 1912 | qFileDialogUi->listView->edit(index); | - |
| 1913 | else | - |
| 1914 | qFileDialogUi->treeView->edit(index); | - |
| 1915 | } | - |
| 1916 | | - |
| 1917 | bool QFileDialogPrivate::removeDirectory(const QString &path) | - |
| 1918 | { | - |
| 1919 | QModelIndex modelIndex = model->index(path); | - |
| 1920 | return model->remove(modelIndex); | - |
| 1921 | } | - |
| 1922 | | - |
| 1923 | | - |
| 1924 | | - |
| 1925 | | - |
| 1926 | | - |
| 1927 | | - |
| 1928 | void QFileDialogPrivate::_q_deleteCurrent() | - |
| 1929 | { | - |
| 1930 | if (model->isReadOnly()) | - |
| 1931 | return; | - |
| 1932 | | - |
| 1933 | QModelIndexList list = qFileDialogUi->listView->selectionModel()->selectedRows(); | - |
| 1934 | for (int i = list.count() - 1; i >= 0; --i) { | - |
| 1935 | QModelIndex index = list.at(i); | - |
| 1936 | if (index == qFileDialogUi->listView->rootIndex()) | - |
| 1937 | continue; | - |
| 1938 | | - |
| 1939 | index = mapToSource(index.sibling(index.row(), 0)); | - |
| 1940 | if (!index.isValid()) | - |
| 1941 | continue; | - |
| 1942 | | - |
| 1943 | QString fileName = index.data(QFileSystemModel::FileNameRole).toString(); | - |
| 1944 | QString filePath = index.data(QFileSystemModel::FilePathRole).toString(); | - |
| 1945 | bool isDir = model->isDir(index); | - |
| 1946 | | - |
| 1947 | QFile::Permissions p(index.parent().data(QFileSystemModel::FilePermissions).toInt()); | - |
| 1948 | | - |
| 1949 | QFileDialog * const q = q_func(); | - |
| 1950 | if (!(p & QFile::WriteUser) && (QMessageBox::warning(q_func(), QFileDialog::tr("Delete"), | - |
| 1951 | QFileDialog::tr("'%1' is write protected.\nDo you want to delete it anyway?") | - |
| 1952 | .arg(fileName), | - |
| 1953 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No)) | - |
| 1954 | return; | - |
| 1955 | else if (QMessageBox::warning(q_func(), QFileDialog::tr("Delete"), | - |
| 1956 | QFileDialog::tr("Are you sure you want to delete '%1'?") | - |
| 1957 | .arg(fileName), | - |
| 1958 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No) | - |
| 1959 | return; | - |
| 1960 | | - |
| 1961 | | - |
| 1962 | | - |
| 1963 | | - |
| 1964 | | - |
| 1965 | | - |
| 1966 | | - |
| 1967 | if (isDir) { | - |
| 1968 | if (!removeDirectory(filePath)) { | - |
| 1969 | | - |
| 1970 | QMessageBox::warning(q, q->windowTitle(), | - |
| 1971 | QFileDialog::tr("Could not delete directory.")); | - |
| 1972 | | - |
| 1973 | } | - |
| 1974 | } else { | - |
| 1975 | model->remove(index); | - |
| 1976 | } | - |
| 1977 | } | - |
| 1978 | } | - |
| 1979 | | - |
| 1980 | void QFileDialogPrivate::_q_autoCompleteFileName(const QString &text) | - |
| 1981 | { | - |
| 1982 | if (text.startsWith(QLatin1String("//")) || text.startsWith(QLatin1Char('\\'))) { | - |
| 1983 | qFileDialogUi->listView->selectionModel()->clearSelection(); | - |
| 1984 | return; | - |
| 1985 | } | - |
| 1986 | | - |
| 1987 | QStringList multipleFiles = typedFiles(); | - |
| 1988 | if (multipleFiles.count() > 0) { | - |
| 1989 | QModelIndexList oldFiles = qFileDialogUi->listView->selectionModel()->selectedRows(); | - |
| 1990 | QModelIndexList newFiles; | - |
| 1991 | for (int i = 0; i < multipleFiles.count(); ++i) { | - |
| 1992 | QModelIndex idx = model->index(multipleFiles.at(i)); | - |
| 1993 | if (oldFiles.contains(idx)) | - |
| 1994 | oldFiles.removeAll(idx); | - |
| 1995 | else | - |
| 1996 | newFiles.append(idx); | - |
| 1997 | } | - |
| 1998 | for (int i = 0; i < newFiles.count(); ++i) | - |
| 1999 | select(newFiles.at(i)); | - |
| 2000 | if (lineEdit()->hasFocus()) | - |
| 2001 | for (int i = 0; i < oldFiles.count(); ++i) | - |
| 2002 | qFileDialogUi->listView->selectionModel()->select(oldFiles.at(i), | - |
| 2003 | QItemSelectionModel::Toggle | QItemSelectionModel::Rows); | - |
| 2004 | } | - |
| 2005 | } | - |
| 2006 | | - |
| 2007 | | - |
| 2008 | | - |
| 2009 | | - |
| 2010 | void QFileDialogPrivate::_q_updateOkButton() | - |
| 2011 | { | - |
| 2012 | QFileDialog * const q = q_func(); | - |
| 2013 | QPushButton *button = qFileDialogUi->buttonBox->button((q->acceptMode() == QFileDialog::AcceptOpen) | - |
| 2014 | ? QDialogButtonBox::Open : QDialogButtonBox::Save); | - |
| 2015 | if (!button) | - |
| 2016 | return; | - |
| 2017 | const QFileDialog::FileMode fileMode = q->fileMode(); | - |
| 2018 | | - |
| 2019 | bool enableButton = true; | - |
| 2020 | bool isOpenDirectory = false; | - |
| 2021 | | - |
| 2022 | QStringList files = q->selectedFiles(); | - |
| 2023 | QString lineEditText = lineEdit()->text(); | - |
| 2024 | | - |
| 2025 | if (lineEditText.startsWith(QLatin1String("//")) || lineEditText.startsWith(QLatin1Char('\\'))) { | - |
| 2026 | button->setEnabled(true); | - |
| 2027 | updateOkButtonText(); | - |
| 2028 | return; | - |
| 2029 | } | - |
| 2030 | | - |
| 2031 | if (files.isEmpty()) { | - |
| 2032 | enableButton = false; | - |
| 2033 | } else if (lineEditText == QLatin1String("..")) { | - |
| 2034 | isOpenDirectory = true; | - |
| 2035 | } else { | - |
| 2036 | switch (fileMode) { | - |
| 2037 | case QFileDialog::DirectoryOnly: | - |
| 2038 | case QFileDialog::Directory: { | - |
| 2039 | QString fn = files.first(); | - |
| 2040 | QModelIndex idx = model->index(fn); | - |
| 2041 | if (!idx.isValid()) | - |
| 2042 | idx = model->index(getEnvironmentVariable(fn)); | - |
| 2043 | if (!idx.isValid() || !model->isDir(idx)) | - |
| 2044 | enableButton = false; | - |
| 2045 | break; | - |
| 2046 | } | - |
| 2047 | case QFileDialog::AnyFile: { | - |
| 2048 | QString fn = files.first(); | - |
| 2049 | QFileInfo info(fn); | - |
| 2050 | QModelIndex idx = model->index(fn); | - |
| 2051 | QString fileDir; | - |
| 2052 | QString fileName; | - |
| 2053 | if (info.isDir()) { | - |
| 2054 | fileDir = info.canonicalFilePath(); | - |
| 2055 | } else { | - |
| 2056 | fileDir = fn.mid(0, fn.lastIndexOf(QLatin1Char('/'))); | - |
| 2057 | fileName = fn.mid(fileDir.length() + 1); | - |
| 2058 | } | - |
| 2059 | if (lineEditText.contains(QLatin1String(".."))) { | - |
| 2060 | fileDir = info.canonicalFilePath(); | - |
| 2061 | fileName = info.fileName(); | - |
| 2062 | } | - |
| 2063 | | - |
| 2064 | if (fileDir == q->directory().canonicalPath() && fileName.isEmpty()) { | - |
| 2065 | enableButton = false; | - |
| 2066 | break; | - |
| 2067 | } | - |
| 2068 | if (idx.isValid() && model->isDir(idx)) { | - |
| 2069 | isOpenDirectory = true; | - |
| 2070 | enableButton = true; | - |
| 2071 | break; | - |
| 2072 | } | - |
| 2073 | if (!idx.isValid()) { | - |
| 2074 | int maxLength = maxNameLength(fileDir); | - |
| 2075 | enableButton = maxLength < 0 || fileName.length() <= maxLength; | - |
| 2076 | } | - |
| 2077 | break; | - |
| 2078 | } | - |
| 2079 | case QFileDialog::ExistingFile: | - |
| 2080 | case QFileDialog::ExistingFiles: | - |
| 2081 | for (int i = 0; i < files.count(); ++i) { | - |
| 2082 | QModelIndex idx = model->index(files.at(i)); | - |
| 2083 | if (!idx.isValid()) | - |
| 2084 | idx = model->index(getEnvironmentVariable(files.at(i))); | - |
| 2085 | if (!idx.isValid()) { | - |
| 2086 | enableButton = false; | - |
| 2087 | break; | - |
| 2088 | } | - |
| 2089 | if (idx.isValid() && model->isDir(idx)) { | - |
| 2090 | isOpenDirectory = true; | - |
| 2091 | break; | - |
| 2092 | } | - |
| 2093 | } | - |
| 2094 | break; | - |
| 2095 | default: | - |
| 2096 | break; | - |
| 2097 | } | - |
| 2098 | } | - |
| 2099 | | - |
| 2100 | button->setEnabled(enableButton); | - |
| 2101 | updateOkButtonText(isOpenDirectory); | - |
| 2102 | } | - |
| 2103 | | - |
| 2104 | | - |
| 2105 | | - |
| 2106 | | - |
| 2107 | void QFileDialogPrivate::_q_currentChanged(const QModelIndex &index) | - |
| 2108 | { | - |
| 2109 | _q_updateOkButton(); | - |
| 2110 | q_func()->currentChanged(index.data(QFileSystemModel::FilePathRole).toString()); | - |
| 2111 | } | - |
| 2112 | | - |
| 2113 | | - |
| 2114 | | - |
| 2115 | | - |
| 2116 | | - |
| 2117 | | - |
| 2118 | | - |
| 2119 | void QFileDialogPrivate::_q_enterDirectory(const QModelIndex &index) | - |
| 2120 | { | - |
| 2121 | QFileDialog * const q = q_func(); | - |
| 2122 | | - |
| 2123 | QModelIndex sourceIndex = index.model() == proxyModel ? mapToSource(index) : index; partially evaluated: index.model() == proxyModel| no Evaluation Count:0 | yes Evaluation Count:5 |
| 0-5 |
| 2124 | QString path = sourceIndex.data(QFileSystemModel::FilePathRole).toString(); | - |
| 2125 | if (path.isEmpty() || model->isDir(sourceIndex)) { partially evaluated: path.isEmpty()| no Evaluation Count:0 | yes Evaluation Count:5 |
partially evaluated: model->isDir(sourceIndex)| yes Evaluation Count:5 | no Evaluation Count:0 |
| 0-5 |
| 2126 | const QFileDialog::FileMode fileMode = q->fileMode(); | - |
| 2127 | q->setDirectory(path); | - |
| 2128 | q->directoryEntered(path); | - |
| 2129 | if (fileMode == QFileDialog::Directory evaluated: fileMode == QFileDialog::Directory| yes Evaluation Count:2 | yes Evaluation Count:3 |
| 2-3 |
| 2130 | || fileMode == QFileDialog::DirectoryOnly) { partially evaluated: fileMode == QFileDialog::DirectoryOnly| no Evaluation Count:0 | yes Evaluation Count:3 |
| 0-3 |
| 2131 | | - |
| 2132 | lineEdit()->setText(QString()); | - |
| 2133 | lineEdit()->clear(); | - |
| 2134 | } executed: }Execution Count:2 | 2 |
| 2135 | } else { executed: }Execution Count:5 | 5 |
| 2136 | | - |
| 2137 | if (!q->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) never evaluated: !q->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) | 0 |
| 2138 | || q->fileMode() != QFileDialog::ExistingFiles || !(QGuiApplication::keyboardModifiers() & Qt::CTRL)) { never evaluated: q->fileMode() != QFileDialog::ExistingFiles never evaluated: !(QGuiApplication::keyboardModifiers() & Qt::CTRL) | 0 |
| 2139 | q->accept(); | - |
| 2140 | } | 0 |
| 2141 | } | 0 |
| 2142 | } | - |
| 2143 | | - |
| 2144 | | - |
| 2145 | | - |
| 2146 | | - |
| 2147 | | - |
| 2148 | | - |
| 2149 | | - |
| 2150 | void QFileDialogPrivate::_q_goToDirectory(const QString &path) | - |
| 2151 | { | - |
| 2152 | | - |
| 2153 | QFileDialog * const q = q_func(); | - |
| 2154 | | - |
| 2155 | QModelIndex index = qFileDialogUi->lookInCombo->model()->index(qFileDialogUi->lookInCombo->currentIndex(), | - |
| 2156 | qFileDialogUi->lookInCombo->modelColumn(), | - |
| 2157 | qFileDialogUi->lookInCombo->rootModelIndex()); | - |
| 2158 | QString path2 = path; | - |
| 2159 | if (!index.isValid()) | - |
| 2160 | index = mapFromSource(model->index(getEnvironmentVariable(path))); | - |
| 2161 | else { | - |
| 2162 | path2 = index.data((Qt::UserRole + 1)).toUrl().toLocalFile(); | - |
| 2163 | index = mapFromSource(model->index(path2)); | - |
| 2164 | } | - |
| 2165 | QDir dir(path2); | - |
| 2166 | if (!dir.exists()) | - |
| 2167 | dir = getEnvironmentVariable(path2); | - |
| 2168 | | - |
| 2169 | if (dir.exists() || path2.isEmpty() || path2 == model->myComputer().toString()) { | - |
| 2170 | _q_enterDirectory(index); | - |
| 2171 | | - |
| 2172 | } else { | - |
| 2173 | QString message = QFileDialog::tr("%1\nDirectory not found.\nPlease verify the " | - |
| 2174 | "correct directory name was given."); | - |
| 2175 | QMessageBox::warning(q, q->windowTitle(), message.arg(path2)); | - |
| 2176 | | - |
| 2177 | } | - |
| 2178 | } | - |
| 2179 | | - |
| 2180 | | - |
| 2181 | | - |
| 2182 | | - |
| 2183 | | - |
| 2184 | | - |
| 2185 | | - |
| 2186 | void QFileDialogPrivate::_q_useNameFilter(int index) | - |
| 2187 | { | - |
| 2188 | QStringList nameFilters = options->nameFilters(); | - |
| 2189 | if (index == nameFilters.size()) { | - |
| 2190 | QAbstractItemModel *comboModel = qFileDialogUi->fileTypeCombo->model(); | - |
| 2191 | nameFilters.append(comboModel->index(comboModel->rowCount() - 1, 0).data().toString()); | - |
| 2192 | options->setNameFilters(nameFilters); | - |
| 2193 | } | - |
| 2194 | | - |
| 2195 | QString nameFilter = nameFilters.at(index); | - |
| 2196 | QStringList newNameFilters = QPlatformFileDialogHelper::cleanFilterList(nameFilter); | - |
| 2197 | if (q_func()->acceptMode() == QFileDialog::AcceptSave) { | - |
| 2198 | QString newNameFilterExtension; | - |
| 2199 | if (newNameFilters.count() > 0) | - |
| 2200 | newNameFilterExtension = QFileInfo(newNameFilters.at(0)).suffix(); | - |
| 2201 | | - |
| 2202 | QString fileName = lineEdit()->text(); | - |
| 2203 | const QString fileNameExtension = QFileInfo(fileName).suffix(); | - |
| 2204 | if (!fileNameExtension.isEmpty() && !newNameFilterExtension.isEmpty()) { | - |
| 2205 | const int fileNameExtensionLength = fileNameExtension.count(); | - |
| 2206 | fileName.replace(fileName.count() - fileNameExtensionLength, | - |
| 2207 | fileNameExtensionLength, newNameFilterExtension); | - |
| 2208 | qFileDialogUi->listView->clearSelection(); | - |
| 2209 | lineEdit()->setText(fileName); | - |
| 2210 | } | - |
| 2211 | } | - |
| 2212 | | - |
| 2213 | model->setNameFilters(newNameFilters); | - |
| 2214 | } | - |
| 2215 | | - |
| 2216 | | - |
| 2217 | | - |
| 2218 | | - |
| 2219 | | - |
| 2220 | | - |
| 2221 | | - |
| 2222 | void QFileDialogPrivate::_q_selectionChanged() | - |
| 2223 | { | - |
| 2224 | const QFileDialog::FileMode fileMode = q_func()->fileMode(); | - |
| 2225 | QModelIndexList indexes = qFileDialogUi->listView->selectionModel()->selectedRows(); | - |
| 2226 | bool stripDirs = (fileMode != QFileDialog::DirectoryOnly && fileMode != QFileDialog::Directory); | - |
| 2227 | | - |
| 2228 | QStringList allFiles; | - |
| 2229 | for (int i = 0; i < indexes.count(); ++i) { | - |
| 2230 | if (stripDirs && model->isDir(mapToSource(indexes.at(i)))) | - |
| 2231 | continue; | - |
| 2232 | allFiles.append(indexes.at(i).data().toString()); | - |
| 2233 | } | - |
| 2234 | if (allFiles.count() > 1) | - |
| 2235 | for (int i = 0; i < allFiles.count(); ++i) { | - |
| 2236 | allFiles.replace(i, QString(QLatin1Char('"') + allFiles.at(i) + QLatin1Char('"'))); | - |
| 2237 | } | - |
| 2238 | | - |
| 2239 | QString finalFiles = allFiles.join(QLatin1Char(' ')); | - |
| 2240 | if (!finalFiles.isEmpty() && !lineEdit()->hasFocus() && lineEdit()->isVisible()) | - |
| 2241 | lineEdit()->setText(finalFiles); | - |
| 2242 | else | - |
| 2243 | _q_updateOkButton(); | - |
| 2244 | } | - |
| 2245 | | - |
| 2246 | | - |
| 2247 | | - |
| 2248 | | - |
| 2249 | | - |
| 2250 | | - |
| 2251 | void QFileDialogPrivate::_q_showHidden() | - |
| 2252 | { | - |
| 2253 | QFileDialog * const q = q_func(); | - |
| 2254 | QDir::Filters dirFilters = q->filter(); | - |
| 2255 | if (showHiddenAction->isChecked()) | - |
| 2256 | dirFilters |= QDir::Hidden; | - |
| 2257 | else | - |
| 2258 | dirFilters &= ~QDir::Hidden; | - |
| 2259 | q->setFilter(dirFilters); | - |
| 2260 | } | - |
| 2261 | | - |
| 2262 | | - |
| 2263 | | - |
| 2264 | | - |
| 2265 | | - |
| 2266 | | - |
| 2267 | | - |
| 2268 | void QFileDialogPrivate::_q_rowsInserted(const QModelIndex &parent) | - |
| 2269 | { | - |
| 2270 | if (!qFileDialogUi->treeView | - |
| 2271 | || parent != qFileDialogUi->treeView->rootIndex() | - |
| 2272 | || !qFileDialogUi->treeView->selectionModel() | - |
| 2273 | || qFileDialogUi->treeView->selectionModel()->hasSelection() | - |
| 2274 | || qFileDialogUi->treeView->model()->rowCount(parent) == 0) | - |
| 2275 | return; | - |
| 2276 | } | - |
| 2277 | | - |
| 2278 | void QFileDialogPrivate::_q_fileRenamed(const QString &path, const QString oldName, const QString newName) | - |
| 2279 | { | - |
| 2280 | const QFileDialog::FileMode fileMode = q_func()->fileMode(); | - |
| 2281 | if (fileMode == QFileDialog::Directory || fileMode == QFileDialog::DirectoryOnly) { | - |
| 2282 | if (path == rootPath() && lineEdit()->text() == oldName) | - |
| 2283 | lineEdit()->setText(newName); | - |
| 2284 | } | - |
| 2285 | } | - |
| 2286 | | - |
| 2287 | void QFileDialogPrivate::_q_nativeEnterDirectory(const QString &directory) | - |
| 2288 | { | - |
| 2289 | if (!directory.isEmpty()) never evaluated: !directory.isEmpty() | 0 |
| 2290 | *lastVisitedDir() = directory; never executed: *lastVisitedDir() = directory; | 0 |
| 2291 | } | 0 |
| 2292 | bool QFileDialogPrivate::itemViewKeyboardEvent(QKeyEvent *event) { | - |
| 2293 | | - |
| 2294 | QFileDialog * const q = q_func(); | - |
| 2295 | switch (event->key()) { | - |
| 2296 | case Qt::Key_Backspace: | - |
| 2297 | _q_navigateToParent(); | - |
| 2298 | return true; | - |
| 2299 | case Qt::Key_Back: | - |
| 2300 | | - |
| 2301 | | - |
| 2302 | | - |
| 2303 | | - |
| 2304 | case Qt::Key_Left: | - |
| 2305 | if (event->key() == Qt::Key_Back || event->modifiers() == Qt::AltModifier) { | - |
| 2306 | _q_navigateBackward(); | - |
| 2307 | return true; | - |
| 2308 | } | - |
| 2309 | break; | - |
| 2310 | case Qt::Key_Escape: | - |
| 2311 | q->hide(); | - |
| 2312 | return true; | - |
| 2313 | default: | - |
| 2314 | break; | - |
| 2315 | } | - |
| 2316 | return false; | - |
| 2317 | } | - |
| 2318 | | - |
| 2319 | QString QFileDialogPrivate::getEnvironmentVariable(const QString &string) | - |
| 2320 | { | - |
| 2321 | | - |
| 2322 | if (string.size() > 1 && string.startsWith(QLatin1Char('$'))) { | - |
| 2323 | return QString::fromLocal8Bit(getenv(string.mid(1).toLatin1().constData())); | - |
| 2324 | } | - |
| 2325 | | - |
| 2326 | | - |
| 2327 | | - |
| 2328 | | - |
| 2329 | | - |
| 2330 | return string; | - |
| 2331 | } | - |
| 2332 | | - |
| 2333 | void QFileDialogComboBox::setFileDialogPrivate(QFileDialogPrivate *d_pointer) { | - |
| 2334 | d_ptr = d_pointer; | - |
| 2335 | urlModel = new QUrlModel(this); | - |
| 2336 | urlModel->showFullPath = true; | - |
| 2337 | urlModel->setFileSystemModel(d_ptr->model); | - |
| 2338 | setModel(urlModel); | - |
| 2339 | } | - |
| 2340 | | - |
| 2341 | void QFileDialogComboBox::showPopup() | - |
| 2342 | { | - |
| 2343 | if (model()->rowCount() > 1) | - |
| 2344 | QComboBox::showPopup(); | - |
| 2345 | | - |
| 2346 | urlModel->setUrls(QList<QUrl>()); | - |
| 2347 | QList<QUrl> list; | - |
| 2348 | QModelIndex idx = d_ptr->model->index(d_ptr->rootPath()); | - |
| 2349 | while (idx.isValid()) { | - |
| 2350 | QUrl url = QUrl::fromLocalFile(idx.data(QFileSystemModel::FilePathRole).toString()); | - |
| 2351 | if (url.isValid()) | - |
| 2352 | list.append(url); | - |
| 2353 | idx = idx.parent(); | - |
| 2354 | } | - |
| 2355 | | - |
| 2356 | list.append(QUrl::fromLocalFile(QLatin1String(""))); | - |
| 2357 | urlModel->addUrls(list, 0); | - |
| 2358 | idx = model()->index(model()->rowCount() - 1, 0); | - |
| 2359 | | - |
| 2360 | | - |
| 2361 | QList<QUrl> urls; | - |
| 2362 | for (int i = 0; i < m_history.count(); ++i) { | - |
| 2363 | QUrl path = QUrl::fromLocalFile(m_history.at(i)); | - |
| 2364 | if (!urls.contains(path)) | - |
| 2365 | urls.prepend(path); | - |
| 2366 | } | - |
| 2367 | if (urls.count() > 0) { | - |
| 2368 | model()->insertRow(model()->rowCount()); | - |
| 2369 | idx = model()->index(model()->rowCount()-1, 0); | - |
| 2370 | | - |
| 2371 | model()->setData(idx, QFileDialog::tr("Recent Places")); | - |
| 2372 | QStandardItemModel *m = qobject_cast<QStandardItemModel*>(model()); | - |
| 2373 | if (m) { | - |
| 2374 | Qt::ItemFlags flags = m->flags(idx); | - |
| 2375 | flags &= ~Qt::ItemIsEnabled; | - |
| 2376 | m->item(idx.row(), idx.column())->setFlags(flags); | - |
| 2377 | } | - |
| 2378 | urlModel->addUrls(urls, -1, false); | - |
| 2379 | } | - |
| 2380 | setCurrentIndex(0); | - |
| 2381 | | - |
| 2382 | QComboBox::showPopup(); | - |
| 2383 | } | - |
| 2384 | | - |
| 2385 | | - |
| 2386 | void QFileDialogComboBox::paintEvent(QPaintEvent *) | - |
| 2387 | { | - |
| 2388 | QStylePainter painter(this); | - |
| 2389 | painter.setPen(palette().color(QPalette::Text)); | - |
| 2390 | | - |
| 2391 | | - |
| 2392 | QStyleOptionComboBox opt; | - |
| 2393 | initStyleOption(&opt); | - |
| 2394 | | - |
| 2395 | QRect editRect = style()->subControlRect(QStyle::CC_ComboBox, &opt, | - |
| 2396 | QStyle::SC_ComboBoxEditField, this); | - |
| 2397 | int size = editRect.width() - opt.iconSize.width() - 4; | - |
| 2398 | opt.currentText = opt.fontMetrics.elidedText(opt.currentText, Qt::ElideMiddle, size); | - |
| 2399 | painter.drawComplexControl(QStyle::CC_ComboBox, opt); | - |
| 2400 | | - |
| 2401 | | - |
| 2402 | painter.drawControl(QStyle::CE_ComboBoxLabel, opt); | - |
| 2403 | } | - |
| 2404 | | - |
| 2405 | QFileDialogListView::QFileDialogListView(QWidget *parent) : QListView(parent) | - |
| 2406 | { | - |
| 2407 | } | - |
| 2408 | | - |
| 2409 | void QFileDialogListView::setFileDialogPrivate(QFileDialogPrivate *d_pointer) | - |
| 2410 | { | - |
| 2411 | d_ptr = d_pointer; | - |
| 2412 | setSelectionBehavior(QAbstractItemView::SelectRows); | - |
| 2413 | setWrapping(true); | - |
| 2414 | setResizeMode(QListView::Adjust); | - |
| 2415 | setEditTriggers(QAbstractItemView::EditKeyPressed); | - |
| 2416 | setContextMenuPolicy(Qt::CustomContextMenu); | - |
| 2417 | | - |
| 2418 | setDragDropMode(QAbstractItemView::InternalMove); | - |
| 2419 | | - |
| 2420 | } | - |
| 2421 | | - |
| 2422 | QSize QFileDialogListView::sizeHint() const | - |
| 2423 | { | - |
| 2424 | int height = qMax(10, sizeHintForRow(0)); | - |
| 2425 | return QSize(QListView::sizeHint().width() * 2, height * 30); | - |
| 2426 | } | - |
| 2427 | | - |
| 2428 | void QFileDialogListView::keyPressEvent(QKeyEvent *e) | - |
| 2429 | { | - |
| 2430 | | - |
| 2431 | | - |
| 2432 | | - |
| 2433 | | - |
| 2434 | | - |
| 2435 | | - |
| 2436 | | - |
| 2437 | if (!d_ptr->itemViewKeyboardEvent(e)) | - |
| 2438 | QListView::keyPressEvent(e); | - |
| 2439 | e->accept(); | - |
| 2440 | } | - |
| 2441 | | - |
| 2442 | QFileDialogTreeView::QFileDialogTreeView(QWidget *parent) : QTreeView(parent) | - |
| 2443 | { | - |
| 2444 | } | - |
| 2445 | | - |
| 2446 | void QFileDialogTreeView::setFileDialogPrivate(QFileDialogPrivate *d_pointer) | - |
| 2447 | { | - |
| 2448 | d_ptr = d_pointer; | - |
| 2449 | setSelectionBehavior(QAbstractItemView::SelectRows); | - |
| 2450 | setRootIsDecorated(false); | - |
| 2451 | setItemsExpandable(false); | - |
| 2452 | setSortingEnabled(true); | - |
| 2453 | header()->setSortIndicator(0, Qt::AscendingOrder); | - |
| 2454 | header()->setStretchLastSection(false); | - |
| 2455 | setTextElideMode(Qt::ElideMiddle); | - |
| 2456 | setEditTriggers(QAbstractItemView::EditKeyPressed); | - |
| 2457 | setContextMenuPolicy(Qt::CustomContextMenu); | - |
| 2458 | | - |
| 2459 | setDragDropMode(QAbstractItemView::InternalMove); | - |
| 2460 | | - |
| 2461 | } | - |
| 2462 | | - |
| 2463 | void QFileDialogTreeView::keyPressEvent(QKeyEvent *e) | - |
| 2464 | { | - |
| 2465 | | - |
| 2466 | | - |
| 2467 | | - |
| 2468 | | - |
| 2469 | | - |
| 2470 | | - |
| 2471 | | - |
| 2472 | if (!d_ptr->itemViewKeyboardEvent(e)) | - |
| 2473 | QTreeView::keyPressEvent(e); | - |
| 2474 | e->accept(); | - |
| 2475 | } | - |
| 2476 | | - |
| 2477 | QSize QFileDialogTreeView::sizeHint() const | - |
| 2478 | { | - |
| 2479 | int height = qMax(10, sizeHintForRow(0)); | - |
| 2480 | QSize sizeHint = header()->sizeHint(); | - |
| 2481 | return QSize(sizeHint.width() * 4, height * 30); | - |
| 2482 | } | - |
| 2483 | | - |
| 2484 | | - |
| 2485 | | - |
| 2486 | | - |
| 2487 | | - |
| 2488 | void QFileDialogLineEdit::keyPressEvent(QKeyEvent *e) | - |
| 2489 | { | - |
| 2490 | | - |
| 2491 | | - |
| 2492 | | - |
| 2493 | | - |
| 2494 | | - |
| 2495 | | - |
| 2496 | | - |
| 2497 | int key = e->key(); | - |
| 2498 | QLineEdit::keyPressEvent(e); | - |
| 2499 | if (key != Qt::Key_Escape) | - |
| 2500 | e->accept(); | - |
| 2501 | if (hideOnEsc && (key == Qt::Key_Escape || key == Qt::Key_Return || key == Qt::Key_Enter)) { | - |
| 2502 | e->accept(); | - |
| 2503 | hide(); | - |
| 2504 | d_ptr->currentView()->setFocus(Qt::ShortcutFocusReason); | - |
| 2505 | } | - |
| 2506 | } | - |
| 2507 | | - |
| 2508 | | - |
| 2509 | | - |
| 2510 | QString QFSCompleter::pathFromIndex(const QModelIndex &index) const | - |
| 2511 | { | - |
| 2512 | const QFileSystemModel *dirModel; | - |
| 2513 | if (proxyModel) | - |
| 2514 | dirModel = qobject_cast<const QFileSystemModel *>(proxyModel->sourceModel()); | - |
| 2515 | else | - |
| 2516 | dirModel = sourceModel; | - |
| 2517 | QString currentLocation = dirModel->rootPath(); | - |
| 2518 | QString path = index.data(QFileSystemModel::FilePathRole).toString(); | - |
| 2519 | if (!currentLocation.isEmpty() && path.startsWith(currentLocation)) { | - |
| 2520 | | - |
| 2521 | if (currentLocation == QDir::separator()) | - |
| 2522 | return path.mid(currentLocation.length()); | - |
| 2523 | | - |
| 2524 | if (currentLocation.endsWith(QLatin1Char('/'))) | - |
| 2525 | return path.mid(currentLocation.length()); | - |
| 2526 | else | - |
| 2527 | return path.mid(currentLocation.length()+1); | - |
| 2528 | } | - |
| 2529 | return index.data(QFileSystemModel::FilePathRole).toString(); | - |
| 2530 | } | - |
| 2531 | | - |
| 2532 | QStringList QFSCompleter::splitPath(const QString &path) const | - |
| 2533 | { | - |
| 2534 | if (path.isEmpty()) | - |
| 2535 | return QStringList(completionPrefix()); | - |
| 2536 | | - |
| 2537 | QString pathCopy = QDir::toNativeSeparators(path); | - |
| 2538 | QString sep = QDir::separator(); | - |
| 2539 | bool expanded; | - |
| 2540 | pathCopy = qt_tildeExpansion(pathCopy, &expanded); | - |
| 2541 | if (expanded) { | - |
| 2542 | QFileSystemModel *dirModel; | - |
| 2543 | if (proxyModel) | - |
| 2544 | dirModel = qobject_cast<QFileSystemModel *>(proxyModel->sourceModel()); | - |
| 2545 | else | - |
| 2546 | dirModel = sourceModel; | - |
| 2547 | dirModel->fetchMore(dirModel->index(pathCopy)); | - |
| 2548 | } | - |
| 2549 | | - |
| 2550 | | - |
| 2551 | QRegExp re(QLatin1Char('[') + QRegExp::escape(sep) + QLatin1Char(']')); | - |
| 2552 | QStringList parts = pathCopy.split(re); | - |
| 2553 | if (pathCopy[0] == sep[0]) | - |
| 2554 | parts[0] = sep[0]; | - |
| 2555 | | - |
| 2556 | | - |
| 2557 | | - |
| 2558 | | - |
| 2559 | | - |
| 2560 | bool startsFromRoot = pathCopy[0] == sep[0]; | - |
| 2561 | | - |
| 2562 | if (parts.count() == 1 || (parts.count() > 1 && !startsFromRoot)) { | - |
| 2563 | const QFileSystemModel *dirModel; | - |
| 2564 | if (proxyModel) | - |
| 2565 | dirModel = qobject_cast<const QFileSystemModel *>(proxyModel->sourceModel()); | - |
| 2566 | else | - |
| 2567 | dirModel = sourceModel; | - |
| 2568 | QString currentLocation = QDir::toNativeSeparators(dirModel->rootPath()); | - |
| 2569 | | - |
| 2570 | | - |
| 2571 | | - |
| 2572 | | - |
| 2573 | if (currentLocation.contains(sep) && path != currentLocation) { | - |
| 2574 | QStringList currentLocationList = splitPath(currentLocation); | - |
| 2575 | while (!currentLocationList.isEmpty() | - |
| 2576 | && parts.count() > 0 | - |
| 2577 | && parts.at(0) == QLatin1String("..")) { | - |
| 2578 | parts.removeFirst(); | - |
| 2579 | currentLocationList.removeLast(); | - |
| 2580 | } | - |
| 2581 | if (!currentLocationList.isEmpty() && currentLocationList.last().isEmpty()) | - |
| 2582 | currentLocationList.removeLast(); | - |
| 2583 | return currentLocationList + parts; | - |
| 2584 | } | - |
| 2585 | } | - |
| 2586 | return parts; | - |
| 2587 | } | - |
| 2588 | | - |
| 2589 | | - |
| 2590 | | - |
| 2591 | | - |
| 2592 | | - |
| 2593 | | - |
| 2594 | | - |
| | |