Qt 4.8
qfiledialog.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <qvariant.h>
43 #include <private/qwidgetitemdata_p.h>
44 #include "qfiledialog.h"
45 
46 #ifndef QT_NO_FILEDIALOG
47 #include "qfiledialog_p.h"
48 #include <qfontmetrics.h>
49 #include <qaction.h>
50 #include <qheaderview.h>
51 #include <qshortcut.h>
52 #include <qgridlayout.h>
53 #include <qmenu.h>
54 #include <qmessagebox.h>
55 #include <qinputdialog.h>
56 #include <stdlib.h>
57 #include <qsettings.h>
58 #include <qdebug.h>
59 #include <qapplication.h>
60 #include <qstylepainter.h>
62 #if !defined(Q_WS_WINCE) && !defined(Q_OS_SYMBIAN)
63 #include "ui_qfiledialog.h"
64 #else
65 #define Q_EMBEDDED_SMALLSCREEN
66 #include "ui_qfiledialog_embedded.h"
67 #if defined(Q_OS_WINCE)
68 extern bool qt_priv_ptr_valid;
69 #endif
70 #if defined(Q_OS_UNIX)
71 #include <pwd.h>
72 #endif
73 #endif
74 
76 
77 Q_GLOBAL_STATIC(QString, lastVisitedDir)
78 
79 /*
80  \internal
81 
82  Exported hooks that can be used to customize the static functions.
83  */
84 typedef QString (*_qt_filedialog_existing_directory_hook)(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options);
86 
87 typedef QString (*_qt_filedialog_open_filename_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options);
89 
90 typedef QStringList (*_qt_filedialog_open_filenames_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options);
92 
93 typedef QString (*_qt_filedialog_save_filename_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options);
95 
330 #if defined(Q_WS_WIN) || defined(Q_WS_MAC)
331 bool Q_GUI_EXPORT qt_use_native_dialogs = true; // for the benefit of testing tools, until we have a proper API
332 #endif
333 
335 #ifdef Q_WS_WIN
336 #include <qwindowsstyle.h>
337 #endif
338 #include <qshortcut.h>
339 #ifdef Q_WS_MAC
340 #include <qmacstyle_mac.h>
341 #endif
343 
349 QFileDialog::QFileDialog(QWidget *parent, Qt::WindowFlags f)
350  : QDialog(*new QFileDialogPrivate, parent, f)
351 {
352  Q_D(QFileDialog);
353  d->init();
354  d->lineEdit()->selectAll();
355 }
356 
365  const QString &caption,
366  const QString &directory,
367  const QString &filter)
368  : QDialog(*new QFileDialogPrivate, parent, 0)
369 {
370  Q_D(QFileDialog);
371  d->init(directory, filter, caption);
372  d->lineEdit()->selectAll();
373 }
374 
379  : QDialog(*new QFileDialogPrivate, args.parent, 0)
380 {
381  Q_D(QFileDialog);
382  d->init(args.directory, args.filter, args.caption);
383  setFileMode(args.mode);
384  setOptions(args.options);
385  selectFile(args.selection);
386  d->lineEdit()->selectAll();
387 }
388 
393 {
394  Q_D(QFileDialog);
395 #ifndef QT_NO_SETTINGS
396  QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
397  settings.beginGroup(QLatin1String("Qt"));
398  settings.setValue(QLatin1String("filedialog"), saveState());
399 #endif
400  d->deleteNativeDialog_sys();
401 }
402 
421 {
422  Q_D(QFileDialog);
423  d->qFileDialogUi->sidebar->setUrls(urls);
424 }
425 
431 {
432  Q_D(const QFileDialog);
433  return d->qFileDialogUi->sidebar->urls();
434 }
435 
436 static const qint32 QFileDialogMagic = 0xbe;
437 
439 "^(.*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$";
440 
452 {
453  Q_D(const QFileDialog);
454  int version = 3;
457 
458  stream << qint32(QFileDialogMagic);
459  stream << qint32(version);
460  stream << d->qFileDialogUi->splitter->saveState();
461  stream << d->qFileDialogUi->sidebar->urls();
462  stream << history();
463  stream << *lastVisitedDir();
464  stream << d->qFileDialogUi->treeView->header()->saveState();
465  stream << qint32(viewMode());
466  return data;
467 }
468 
482 {
483  Q_D(QFileDialog);
484  int version = 3;
485  QByteArray sd = state;
487  if (stream.atEnd())
488  return false;
489  QByteArray splitterState;
490  QByteArray headerData;
491  QList<QUrl> bookmarks;
493  QString currentDirectory;
494  qint32 marker;
495  qint32 v;
497  stream >> marker;
498  stream >> v;
499  if (marker != QFileDialogMagic || v != version)
500  return false;
501 
502  stream >> splitterState
503  >> bookmarks
504  >> history
505  >> currentDirectory
506  >> headerData
507  >> viewMode;
508 
509  if (!d->qFileDialogUi->splitter->restoreState(splitterState))
510  return false;
511  QList<int> list = d->qFileDialogUi->splitter->sizes();
512  if (list.count() >= 2 && list.at(0) == 0 && list.at(1) == 0) {
513  for (int i = 0; i < list.count(); ++i)
514  list[i] = d->qFileDialogUi->splitter->widget(i)->sizeHint().width();
515  d->qFileDialogUi->splitter->setSizes(list);
516  }
517 
518  d->qFileDialogUi->sidebar->setUrls(bookmarks);
519  while (history.count() > 5)
520  history.pop_front();
521  setHistory(history);
522  setDirectory(lastVisitedDir()->isEmpty() ? currentDirectory : *lastVisitedDir());
523  QHeaderView *headerView = d->qFileDialogUi->treeView->header();
524  if (!headerView->restoreState(headerData))
525  return false;
526 
527  QList<QAction*> actions = headerView->actions();
528  QAbstractItemModel *abstractModel = d->model;
529 #ifndef QT_NO_PROXYMODEL
530  if (d->proxyModel)
531  abstractModel = d->proxyModel;
532 #endif
533  int total = qMin(abstractModel->columnCount(QModelIndex()), actions.count() + 1);
534  for (int i = 1; i < total; ++i)
535  actions.at(i - 1)->setChecked(!headerView->isSectionHidden(i));
536 
537  setViewMode(ViewMode(viewMode));
538  return true;
539 }
540 
545 {
546  Q_D(QFileDialog);
547  if (e->type() == QEvent::LanguageChange) {
548  d->retranslateWindowTitle();
549  d->retranslateStrings();
550  }
552 }
553 
555  :
556 #ifndef QT_NO_PROXYMODEL
557  proxyModel(0),
558 #endif
559  model(0),
562  currentHistoryLocation(-1),
563  renameAction(0),
564  deleteAction(0),
565  showHiddenAction(0),
566  useDefaultCaption(true),
567  defaultFileTypes(true),
568  fileNameLabelExplicitlySat(false),
569  nativeDialogInUse(false),
570 #ifdef Q_WS_MAC
571  mDelegate(0),
572 #ifndef QT_MAC_USE_COCOA
573  mDialog(0),
574  mDialogStarted(false),
575  mDialogClosed(true),
576 #endif
577 #endif
578  qFileDialogUi(0)
579 {
580 }
581 
583 {
584 }
585 
587 {
588  Q_Q(QFileDialog);
589  if (!useDefaultCaption || setWindowTitle != q->windowTitle())
590  return;
593  q->setWindowTitle(QFileDialog::tr("Find Directory"));
594  else
595  q->setWindowTitle(QFileDialog::tr("Open"));
596  } else
597  q->setWindowTitle(QFileDialog::tr("Save As"));
598 
599  setWindowTitle = q->windowTitle();
600 }
601 
603 {
604  *lastVisitedDir() = dir;
605 }
606 
608 {
609  Q_Q(QFileDialog);
610  /* WIDGETS */
611  if (defaultFileTypes)
612  q->setNameFilter(QFileDialog::tr("All Files (*)"));
613 
614  QList<QAction*> actions = qFileDialogUi->treeView->header()->actions();
615  QAbstractItemModel *abstractModel = model;
616 #ifndef QT_NO_PROXYMODEL
617  if (proxyModel)
618  abstractModel = proxyModel;
619 #endif
620  int total = qMin(abstractModel->columnCount(QModelIndex()), actions.count() + 1);
621  for (int i = 1; i < total; ++i) {
622  actions.at(i - 1)->setText(QFileDialog::tr("Show ") + abstractModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString());
623  }
624 
625  /* MENU ACTIONS */
626  renameAction->setText(QFileDialog::tr("&Rename"));
627  deleteAction->setText(QFileDialog::tr("&Delete"));
628  showHiddenAction->setText(QFileDialog::tr("Show &hidden files"));
629  newFolderAction->setText(QFileDialog::tr("&New Folder"));
630  qFileDialogUi->retranslateUi(q);
631 
634  q->setLabelText(QFileDialog::FileName, QFileDialog::tr("Directory:"));
635  } else {
636  q->setLabelText(QFileDialog::FileName, QFileDialog::tr("File &name:"));
637  }
639  }
640 }
641 
643 {
644  Q_Q(QFileDialog);
645  emit q->filesSelected(files);
646  if (files.count() == 1)
647  emit q->fileSelected(files.first());
648 }
649 
651 {
652  Q_Q(QFileDialog);
653  if (nativeDialogInUse)
654  return true;
655  if (q->testAttribute(Qt::WA_DontShowOnScreen))
656  return false;
658  return false;
659 
661  QLatin1String dynamicName(q->metaObject()->className());
662  return (staticName == dynamicName);
663 }
664 
675 void QFileDialog::setOption(Option option, bool on)
676 {
677  Q_D(QFileDialog);
678  if (!(d->opts & option) != !on)
679  setOptions(d->opts ^ option);
680 }
681 
693 bool QFileDialog::testOption(Option option) const
694 {
695  Q_D(const QFileDialog);
696  return (d->opts & option) != 0;
697 }
698 
715 void QFileDialog::setOptions(Options options)
716 {
717  Q_D(QFileDialog);
718 
719  Options changed = (options ^ d->opts);
720  if (!changed)
721  return;
722 
723  d->opts = options;
724  if (changed & DontResolveSymlinks)
725  d->model->setResolveSymlinks(!(options & DontResolveSymlinks));
726  if (changed & ReadOnly) {
727  bool ro = (options & ReadOnly);
728  d->model->setReadOnly(ro);
729  d->qFileDialogUi->newFolderButton->setEnabled(!ro);
730  d->renameAction->setEnabled(!ro);
731  d->deleteAction->setEnabled(!ro);
732  }
733  if (changed & HideNameFilterDetails)
734  setNameFilters(d->nameFilters);
735 
736  if (changed & ShowDirsOnly)
737  setFilter((options & ShowDirsOnly) ? filter() & ~QDir::Files : filter() | QDir::Files);
738 
739  if (changed & DontUseCustomDirectoryIcons)
740  iconProvider()->d_ptr->setUseCustomDirectoryIcons(!(options & DontUseCustomDirectoryIcons));
741 }
742 
743 QFileDialog::Options QFileDialog::options() const
744 {
745  Q_D(const QFileDialog);
746  return d->opts;
747 }
748 
763 void QFileDialog::open(QObject *receiver, const char *member)
764 {
765  Q_D(QFileDialog);
766  const char *signal = (fileMode() == ExistingFiles) ? SIGNAL(filesSelected(QStringList))
767  : SIGNAL(fileSelected(QString));
768  connect(this, signal, receiver, member);
769  d->signalToDisconnectOnClose = signal;
770  d->receiverToDisconnectOnClose = receiver;
771  d->memberToDisconnectOnClose = member;
772 
773  QDialog::open();
774 }
775 
776 
780 void QFileDialog::setVisible(bool visible)
781 {
782  Q_D(QFileDialog);
783  if (visible){
784  if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden))
785  return;
786  } else if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden))
787  return;
788 
789  if (d->canBeNativeDialog()){
790  if (d->setVisible_sys(visible)){
791  d->nativeDialogInUse = true;
792  // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below
793  // updates the state correctly, but skips showing the non-native version:
794  setAttribute(Qt::WA_DontShowOnScreen);
795 #ifndef QT_NO_FSCOMPLETER
796  //So the completer don't try to complete and therefore to show a popup
797  d->completer->setModel(0);
798 #endif
799  } else {
800  d->nativeDialogInUse = false;
801  setAttribute(Qt::WA_DontShowOnScreen, false);
802 #ifndef QT_NO_FSCOMPLETER
803  if (d->proxyModel != 0)
804  d->completer->setModel(d->proxyModel);
805  else
806  d->completer->setModel(d->model);
807 #endif
808  }
809  }
810 
811  if (!d->nativeDialogInUse)
812  d->qFileDialogUi->fileNameEdit->setFocus();
813 
814  QDialog::setVisible(visible);
815 }
816 
822 {
823  //The shortcut in the side bar may have a parent that is not fetched yet (e.g. an hidden file)
824  //so we force the fetching
825  QFileSystemModelPrivate::QFileSystemNode *node = model->d_func()->node(url.toLocalFile(), true);
826  QModelIndex idx = model->d_func()->index(node);
827  _q_enterDirectory(idx);
828 }
829 
839 void QFileDialog::setDirectory(const QString &directory)
840 {
841  Q_D(QFileDialog);
842  QString newDirectory = directory;
843  QFileInfo info(directory);
844  //we remove .. and . from the given path if exist
845  if (!directory.isEmpty())
846  newDirectory = QDir::cleanPath(directory);
847 
848  if (!directory.isEmpty() && newDirectory.isEmpty())
849  return;
850 
851  d->setLastVisitedDirectory(newDirectory);
852 
853  if (d->nativeDialogInUse){
854  d->setDirectory_sys(newDirectory);
855  return;
856  }
857  if (d->rootPath() == newDirectory)
858  return;
859  QModelIndex root = d->model->setRootPath(newDirectory);
860  d->qFileDialogUi->newFolderButton->setEnabled(d->model->flags(root) & Qt::ItemIsDropEnabled);
861  if (root != d->rootIndex()) {
862 #ifndef QT_NO_FSCOMPLETER
863  if (directory.endsWith(QLatin1Char('/')))
864  d->completer->setCompletionPrefix(newDirectory);
865  else
866  d->completer->setCompletionPrefix(newDirectory + QLatin1Char('/'));
867 #endif
868  d->setRootIndex(root);
869  }
870  d->qFileDialogUi->listView->selectionModel()->clear();
871 }
872 
877 {
878  Q_D(const QFileDialog);
879  return QDir(d->nativeDialogInUse ? d->directory_sys() : d->rootPath());
880 }
881 
887 void QFileDialog::selectFile(const QString &filename)
888 {
889  Q_D(QFileDialog);
890  if (filename.isEmpty())
891  return;
892 
893  if (d->nativeDialogInUse){
894  d->selectFile_sys(filename);
895  return;
896  }
897 
898  if (!QDir::isRelativePath(filename)) {
899  QFileInfo info(filename);
900  QString filenamePath = info.absoluteDir().path();
901 
902  if (d->model->rootPath() != filenamePath)
903  setDirectory(filenamePath);
904  }
905 
906  QModelIndex index = d->model->index(filename);
907  QString file;
908  if (!index.isValid()) {
909  // save as dialog where we want to input a default value
910  QString text = filename;
911  if (QFileInfo(filename).isAbsolute()) {
912  QString current = d->rootPath();
913  text.remove(current);
914  if (text.at(0) == QDir::separator()
915 #ifdef Q_OS_WIN
916  //On Windows both cases can happen
917  || text.at(0) == QLatin1Char('/')
918 #endif
919  )
920  text = text.remove(0,1);
921  }
922  file = text;
923  } else {
924  file = index.data().toString();
925  }
926  d->qFileDialogUi->listView->selectionModel()->clear();
927  if (!isVisible() || !d->lineEdit()->hasFocus())
928  d->lineEdit()->setText(file);
929 }
930 
931 #ifdef Q_OS_UNIX
932 Q_AUTOTEST_EXPORT QString qt_tildeExpansion(const QString &path, bool *expanded = 0)
933 {
934  if (expanded != 0)
935  *expanded = false;
936  if (!path.startsWith(QLatin1Char('~')))
937  return path;
938  QString ret = path;
939 #if !defined(Q_OS_INTEGRITY)
940  QStringList tokens = ret.split(QDir::separator());
941  if (tokens.first() == QLatin1String("~")) {
942  ret.replace(0, 1, QDir::homePath());
943  } else {
944  QString userName = tokens.first();
945  userName.remove(0, 1);
946 #if defined(Q_OS_VXWORKS)
947  const QString homePath = QDir::homePath();
948 #elif defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD)
949  passwd pw;
950  passwd *tmpPw;
951  char buf[200];
952  const int bufSize = sizeof(buf);
953  int err = 0;
954 #if defined(Q_OS_SOLARIS) && defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE - 0 < 199506L)
955  tmpPw = getpwnam_r(userName.toLocal8Bit().constData(), &pw, buf, bufSize);
956 #else
957  err = getpwnam_r(userName.toLocal8Bit().constData(), &pw, buf, bufSize, &tmpPw);
958 #endif
959  if (err || !tmpPw)
960  return ret;
961  const QString homePath = QString::fromLocal8Bit(pw.pw_dir);
962 #else
963  passwd *pw = getpwnam(userName.toLocal8Bit().constData());
964  if (!pw)
965  return ret;
966  const QString homePath = QString::fromLocal8Bit(pw->pw_dir);
967 #endif
968  ret.replace(0, tokens.first().length(), homePath);
969  }
970  if (expanded != 0)
971  *expanded = true;
972 #endif
973  return ret;
974 }
975 #endif
976 
981 {
982 #ifdef Q_OS_UNIX
983  Q_Q(const QFileDialog);
984 #endif
985  QStringList files;
986  QString editText = lineEdit()->text();
987  if (!editText.contains(QLatin1Char('"'))) {
988 #ifdef Q_OS_UNIX
989  const QString prefix = q->directory().absolutePath() + QDir::separator();
990  if (QFile::exists(prefix + editText))
991  files << editText;
992  else
993  files << qt_tildeExpansion(editText);
994 #else
995  files << editText;
996 #endif
997  } else {
998  // " is used to separate files like so: "file1" "file2" "file3" ...
999  // ### need escape character for filenames with quotes (")
1000  QStringList tokens = editText.split(QLatin1Char('\"'));
1001  for (int i=0; i<tokens.size(); ++i) {
1002  if ((i % 2) == 0)
1003  continue; // Every even token is a separator
1004 #ifdef Q_OS_UNIX
1005  const QString token = tokens.at(i);
1006  const QString prefix = q->directory().absolutePath() + QDir::separator();
1007  if (QFile::exists(prefix + token))
1008  files << token;
1009  else
1010  files << qt_tildeExpansion(token);
1011 #else
1012  files << toInternal(tokens.at(i));
1013 #endif
1014  }
1015  }
1016  return addDefaultSuffixToFiles(files);
1017 }
1018 
1020 {
1021  QStringList files;
1022  for (int i=0; i<filesToFix.size(); ++i) {
1023  QString name = toInternal(filesToFix.at(i));
1024  QFileInfo info(name);
1025  // if the filename has no suffix, add the default suffix
1026  if (!defaultSuffix.isEmpty() && !info.isDir() && name.lastIndexOf(QLatin1Char('.')) == -1)
1027  name += QLatin1Char('.') + defaultSuffix;
1028  if (info.isAbsolute()) {
1029  files.append(name);
1030  } else {
1031  // at this point the path should only have Qt path separators.
1032  // This check is needed since we might be at the root directory
1033  // and on Windows it already ends with slash.
1034  QString path = rootPath();
1035  if (!path.endsWith(QLatin1Char('/')))
1036  path += QLatin1Char('/');
1037  path += name;
1038  files.append(path);
1039  }
1040  }
1041  return files;
1042 }
1043 
1044 
1053 {
1054  Q_D(const QFileDialog);
1055  if (d->nativeDialogInUse)
1056  return d->addDefaultSuffixToFiles(d->selectedFiles_sys());
1057 
1058  QModelIndexList indexes = d->qFileDialogUi->listView->selectionModel()->selectedRows();
1059  QStringList files;
1060  for (int i = 0; i < indexes.count(); ++i)
1061  files.append(indexes.at(i).data(QFileSystemModel::FilePathRole).toString());
1062 
1063  if (files.isEmpty() && !d->lineEdit()->text().isEmpty())
1064  files = d->typedFiles();
1065 
1066  if (files.isEmpty() && !(d->fileMode == ExistingFile || d->fileMode == ExistingFiles))
1067  files.append(d->rootIndex().data(QFileSystemModel::FilePathRole).toString());
1068  return files;
1069 }
1070 
1071 /*
1072  Makes a list of filters from ;;-separated text.
1073  Used by the mac and windows implementations
1074 */
1076 {
1077  QString f(filter);
1078 
1079  if (f.isEmpty())
1080  return QStringList();
1081 
1082  QString sep(QLatin1String(";;"));
1083  int i = f.indexOf(sep, 0);
1084  if (i == -1) {
1085  if (f.indexOf(QLatin1Char('\n'), 0) != -1) {
1086  sep = QLatin1Char('\n');
1087  i = f.indexOf(sep, 0);
1088  }
1089  }
1090 
1091  return f.split(sep);
1092 }
1093 
1109 {
1110  setNameFilters(qt_make_filter_list(filter));
1111 }
1112 
1121 void QFileDialog::setFilter(const QString &filter)
1122 {
1123  setNameFilter(filter);
1124 }
1125 
1142 {
1143  setOption(HideNameFilterDetails, !enabled);
1144 }
1145 
1147 {
1148  return !testOption(HideNameFilterDetails);
1149 }
1150 
1151 
1152 /*
1153  Strip the filters by removing the details, e.g. (*.*).
1154 */
1156 {
1157  QStringList strippedFilters;
1158  QRegExp r(QString::fromLatin1(qt_file_dialog_filter_reg_exp));
1159  for (int i = 0; i < filters.count(); ++i) {
1160  QString filterName;
1161  int index = r.indexIn(filters[i]);
1162  if (index >= 0)
1163  filterName = r.cap(1);
1164  strippedFilters.append(filterName.simplified());
1165  }
1166  return strippedFilters;
1167 }
1168 
1169 
1181 {
1182  Q_D(QFileDialog);
1183  d->defaultFileTypes = (filters == QStringList(QFileDialog::tr("All Files (*)")));
1184  QStringList cleanedFilters;
1185  for (int i = 0; i < filters.count(); ++i) {
1186  cleanedFilters << filters[i].simplified();
1187  }
1188  d->nameFilters = cleanedFilters;
1189 
1190  if (d->nativeDialogInUse){
1191  d->setNameFilters_sys(cleanedFilters);
1192  return;
1193  }
1194 
1195  d->qFileDialogUi->fileTypeCombo->clear();
1196  if (cleanedFilters.isEmpty())
1197  return;
1198 
1199  if (testOption(HideNameFilterDetails))
1200  d->qFileDialogUi->fileTypeCombo->addItems(qt_strip_filters(cleanedFilters));
1201  else
1202  d->qFileDialogUi->fileTypeCombo->addItems(cleanedFilters);
1203 
1204  d->_q_useNameFilter(0);
1205 }
1206 
1216 {
1217  setNameFilters(filters);
1218 }
1219 
1230 {
1231  return d_func()->nameFilters;
1232 }
1233 
1244 {
1245  return nameFilters();
1246 }
1247 
1260 {
1261  Q_D(QFileDialog);
1262  if (d->nativeDialogInUse) {
1263  d->selectNameFilter_sys(filter);
1264  return;
1265  }
1266  int i = -1;
1267  if (testOption(HideNameFilterDetails)) {
1269  if (!filters.isEmpty())
1270  i = d->qFileDialogUi->fileTypeCombo->findText(filters.first());
1271  } else {
1272  i = d->qFileDialogUi->fileTypeCombo->findText(filter);
1273  }
1274  if (i >= 0) {
1275  d->qFileDialogUi->fileTypeCombo->setCurrentIndex(i);
1276  d->_q_useNameFilter(d->qFileDialogUi->fileTypeCombo->currentIndex());
1277  }
1278 }
1279 
1290 {
1291  selectNameFilter(filter);
1292 }
1293 
1305 {
1306  Q_D(const QFileDialog);
1307  if (d->nativeDialogInUse)
1308  return d->selectedNameFilter_sys();
1309 
1310  return d->qFileDialogUi->fileTypeCombo->currentText();
1311 }
1312 
1322 {
1323  return selectedNameFilter();
1324 }
1325 
1336 QDir::Filters QFileDialog::filter() const
1337 {
1338  Q_D(const QFileDialog);
1339  return d->model->filter();
1340 }
1341 
1354 void QFileDialog::setFilter(QDir::Filters filters)
1355 {
1356  Q_D(QFileDialog);
1357  d->model->setFilter(filters);
1358  if (d->nativeDialogInUse){
1359  d->setFilter_sys();
1360  return;
1361  }
1362 
1363  d->showHiddenAction->setChecked((filters & QDir::Hidden));
1364 }
1365 
1379 {
1380  Q_D(QFileDialog);
1381  if (mode == Detail)
1382  d->_q_showDetailsView();
1383  else
1384  d->_q_showListView();
1385 }
1386 
1388 {
1389  Q_D(const QFileDialog);
1390  return (d->qFileDialogUi->stackedWidget->currentWidget() == d->qFileDialogUi->listView->parent() ? QFileDialog::List : QFileDialog::Detail);
1391 }
1392 
1412 {
1413  Q_D(QFileDialog);
1414  d->fileMode = mode;
1415  d->retranslateWindowTitle();
1416 
1417  // keep ShowDirsOnly option in sync with fileMode (BTW, DirectoryOnly is obsolete)
1418  setOption(ShowDirsOnly, mode == DirectoryOnly);
1419 
1420  // set selection mode and behavior
1421  QAbstractItemView::SelectionMode selectionMode;
1422  if (mode == QFileDialog::ExistingFiles)
1423  selectionMode = QAbstractItemView::ExtendedSelection;
1424  else
1425  selectionMode = QAbstractItemView::SingleSelection;
1426  d->qFileDialogUi->listView->setSelectionMode(selectionMode);
1427  d->qFileDialogUi->treeView->setSelectionMode(selectionMode);
1428  // set filter
1429  d->model->setFilter(d->filterForMode(filter()));
1430  // setup file type for directory
1431  QString buttonText = (d->acceptMode == AcceptOpen ? tr("&Open") : tr("&Save"));
1432  if (mode == DirectoryOnly || mode == Directory) {
1433  d->qFileDialogUi->fileTypeCombo->clear();
1434  d->qFileDialogUi->fileTypeCombo->addItem(tr("Directories"));
1435  d->qFileDialogUi->fileTypeCombo->setEnabled(false);
1436 
1437  if (!d->fileNameLabelExplicitlySat){
1438  setLabelText(FileName, tr("Directory:"));
1439  d->fileNameLabelExplicitlySat = false;
1440  }
1441  buttonText = tr("&Choose");
1442  } else {
1443  if (!d->fileNameLabelExplicitlySat){
1444  setLabelText(FileName, tr("File &name:"));
1445  d->fileNameLabelExplicitlySat = false;
1446  }
1447  }
1448  setLabelText(Accept, buttonText);
1449  if (d->nativeDialogInUse){
1450  d->setFilter_sys();
1451  return;
1452  }
1453 
1454  d->qFileDialogUi->fileTypeCombo->setEnabled(!testOption(ShowDirsOnly));
1455  d->_q_updateOkButton();
1456 }
1457 
1459 {
1460  Q_D(const QFileDialog);
1461  return d->fileMode;
1462 }
1463 
1478 {
1479  Q_D(QFileDialog);
1480  d->acceptMode = mode;
1481  bool directoryMode = (d->fileMode == Directory || d->fileMode == DirectoryOnly);
1483  d->qFileDialogUi->buttonBox->setStandardButtons(button | QDialogButtonBox::Cancel);
1484  d->qFileDialogUi->buttonBox->button(button)->setEnabled(false);
1485  d->_q_updateOkButton();
1486  if (mode == AcceptOpen && directoryMode)
1487  setLabelText(Accept, tr("&Choose"));
1488  else
1489  setLabelText(Accept, (mode == AcceptOpen ? tr("&Open") : tr("&Save")));
1490  if (mode == AcceptSave) {
1491  d->qFileDialogUi->lookInCombo->setEditable(false);
1492  }
1493  d->retranslateWindowTitle();
1494 #if defined(Q_WS_MAC)
1495  d->deleteNativeDialog_sys();
1496  setAttribute(Qt::WA_DontShowOnScreen, false);
1497 #endif
1498 }
1499 
1500 /*
1501  Returns the file system model index that is the root index in the
1502  views
1503 */
1505  return mapToSource(qFileDialogUi->listView->rootIndex());
1506 }
1507 
1509  if (!qFileDialogUi->stackedWidget)
1510  return 0;
1511  if (qFileDialogUi->stackedWidget->currentWidget() == qFileDialogUi->listView->parent())
1512  return qFileDialogUi->listView;
1513  return qFileDialogUi->treeView;
1514 }
1515 
1517  return (QLineEdit*)qFileDialogUi->fileNameEdit;
1518 }
1519 
1520 /*
1521  Sets the view root index to be the file system model index
1522 */
1524  Q_ASSERT(index.isValid() ? index.model() == model : true);
1525  QModelIndex idx = mapFromSource(index);
1526  qFileDialogUi->treeView->setRootIndex(idx);
1527  qFileDialogUi->listView->setRootIndex(idx);
1528 }
1529 /*
1530  Select a file system model index
1531  returns the index that was selected (or not depending upon sortfilterproxymodel)
1532 */
1534  Q_ASSERT(index.isValid() ? index.model() == model : true);
1535 
1536  QModelIndex idx = mapFromSource(index);
1537  if (idx.isValid() && !qFileDialogUi->listView->selectionModel()->isSelected(idx))
1538  qFileDialogUi->listView->selectionModel()->select(idx,
1540  return idx;
1541 }
1542 
1544 {
1545  Q_D(const QFileDialog);
1546  return d->acceptMode;
1547 }
1548 
1563 {
1564  setOption(ReadOnly, enabled);
1565 }
1566 
1568 {
1569  return testOption(ReadOnly);
1570 }
1571 
1587 {
1588  setOption(DontResolveSymlinks, !enabled);
1589 }
1590 
1591 bool QFileDialog::resolveSymlinks() const
1592 {
1593  return !testOption(DontResolveSymlinks);
1594 }
1595 
1609 {
1610  setOption(DontConfirmOverwrite, !enabled);
1611 }
1612 
1613 bool QFileDialog::confirmOverwrite() const
1614 {
1615  return !testOption(DontConfirmOverwrite);
1616 }
1617 
1631 {
1632  Q_D(QFileDialog);
1633  d->defaultSuffix = suffix;
1634 }
1635 
1637 {
1638  Q_D(const QFileDialog);
1639  return d->defaultSuffix;
1640 }
1641 
1647 {
1648  Q_D(QFileDialog);
1649  d->qFileDialogUi->lookInCombo->setHistory(paths);
1650 }
1651 
1653 {
1654  m_history = paths;
1655  // Only populate the first item, showPopup will populate the rest if needed
1656  QList<QUrl> list;
1657  QModelIndex idx = d_ptr->model->index(d_ptr->rootPath());
1658  //On windows the popup display the "C:\", convert to nativeSeparators
1660  if (url.isValid())
1661  list.append(url);
1662  urlModel->setUrls(list);
1663 }
1664 
1669 {
1670  Q_D(const QFileDialog);
1671  QStringList currentHistory = d->qFileDialogUi->lookInCombo->history();
1672  //On windows the popup display the "C:\", convert to nativeSeparators
1673  QString newHistory = QDir::toNativeSeparators(d->rootIndex().data(QFileSystemModel::FilePathRole).toString());
1674  if (!currentHistory.contains(newHistory))
1675  currentHistory << newHistory;
1676  return currentHistory;
1677 }
1678 
1695 {
1696  Q_D(QFileDialog);
1697  d->qFileDialogUi->listView->setItemDelegate(delegate);
1698  d->qFileDialogUi->treeView->setItemDelegate(delegate);
1699 }
1700 
1705 {
1706  Q_D(const QFileDialog);
1707  return d->qFileDialogUi->listView->itemDelegate();
1708 }
1709 
1714 {
1715  Q_D(QFileDialog);
1716  d->model->setIconProvider(provider);
1717  //It forces the refresh of all entries in the side bar, then we can get new icons
1718  d->qFileDialogUi->sidebar->setUrls(d->qFileDialogUi->sidebar->urls());
1719 }
1720 
1725 {
1726  Q_D(const QFileDialog);
1727  return d->model->iconProvider();
1728 }
1729 
1734 {
1735  Q_D(QFileDialog);
1736  QPushButton *button;
1737  switch (label) {
1738  case LookIn:
1739  d->qFileDialogUi->lookInLabel->setText(text);
1740  break;
1741  case FileName:
1742  d->qFileDialogUi->fileNameLabel->setText(text);
1743  d->fileNameLabelExplicitlySat = true;
1744  break;
1745  case FileType:
1746  d->qFileDialogUi->fileTypeLabel->setText(text);
1747  break;
1748  case Accept:
1749  d->acceptLabel = text;
1750  if (acceptMode() == AcceptOpen)
1751  button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Open);
1752  else
1753  button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Save);
1754  if (button)
1755  button->setText(text);
1756  break;
1757  case Reject:
1758  button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Cancel);
1759  if (button)
1760  button->setText(text);
1761  break;
1762  }
1763 }
1764 
1769 {
1770  QPushButton *button;
1771  Q_D(const QFileDialog);
1772  switch (label) {
1773  case LookIn:
1774  return d->qFileDialogUi->lookInLabel->text();
1775  case FileName:
1776  return d->qFileDialogUi->fileNameLabel->text();
1777  case FileType:
1778  return d->qFileDialogUi->fileTypeLabel->text();
1779  case Accept:
1780  if (acceptMode() == AcceptOpen)
1781  button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Open);
1782  else
1783  button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Save);
1784  if (button)
1785  return button->text();
1786  case Reject:
1787  button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Cancel);
1788  if (button)
1789  return button->text();
1790  }
1791  return QString();
1792 }
1793 
1794 /*
1795  For the native file dialogs
1796 */
1797 
1798 #if defined(Q_WS_WIN)
1800  QString *initialDirectory,
1801  QString *selectedFilter);
1802 
1804  QString *initialDirectory,
1805  QString *selectedFilter);
1806 
1808  QString *initialDirectory,
1809  QString *selectedFilter);
1810 
1812 #endif
1813 
1814 /*
1815  For Symbian file dialogs
1816 */
1817 #if defined(Q_WS_S60)
1818 extern QString qtSymbianGetOpenFileName(const QString &caption,
1819  const QString &dir,
1820  const QString &filter);
1821 
1822 extern QStringList qtSymbianGetOpenFileNames(const QString &caption,
1823  const QString &dir,
1824  const QString &filter);
1825 
1826 extern QString qtSymbianGetSaveFileName(const QString &caption,
1827  const QString &dir);
1828 
1829 extern QString qtSymbianGetExistingDirectory(const QString &caption,
1830  const QString &dir);
1831 #endif
1832 
1885  const QString &caption,
1886  const QString &dir,
1887  const QString &filter,
1888  QString *selectedFilter,
1889  Options options)
1890 {
1891  if (qt_filedialog_open_filename_hook && !(options & DontUseNativeDialog))
1892  return qt_filedialog_open_filename_hook(parent, caption, dir, filter, selectedFilter, options);
1893 #if defined(Q_WS_S60)
1894  if (QSysInfo::s60Version() > QSysInfo::SV_S60_5_0 && !(options & DontUseNativeDialog))
1895  return qtSymbianGetOpenFileName(caption, dir, filter);
1896 #endif
1897  QFileDialogArgs args;
1898  args.parent = parent;
1899  args.caption = caption;
1902  args.filter = filter;
1903  args.mode = ExistingFile;
1904  args.options = options;
1905 #if defined(Q_WS_WIN)
1906  if (qt_use_native_dialogs && !(args.options & DontUseNativeDialog)) {
1907  return qt_win_get_open_file_name(args, &(args.directory), selectedFilter);
1908  }
1909 #endif
1910 
1911  // create a qt dialog
1912  QFileDialog dialog(args);
1913  if (selectedFilter && !selectedFilter->isEmpty())
1914  dialog.selectNameFilter(*selectedFilter);
1915  if (dialog.exec() == QDialog::Accepted) {
1916  if (selectedFilter)
1917  *selectedFilter = dialog.selectedFilter();
1918  return dialog.selectedFiles().value(0);
1919  }
1920  return QString();
1921 }
1922 
1977  const QString &caption,
1978  const QString &dir,
1979  const QString &filter,
1980  QString *selectedFilter,
1981  Options options)
1982 {
1983  if (qt_filedialog_open_filenames_hook && !(options & DontUseNativeDialog))
1984  return qt_filedialog_open_filenames_hook(parent, caption, dir, filter, selectedFilter, options);
1985 #if defined(Q_WS_S60)
1986  if (QSysInfo::s60Version() > QSysInfo::SV_S60_5_0 && !(options & DontUseNativeDialog))
1987  return qtSymbianGetOpenFileNames(caption, dir, filter);
1988 #endif
1989  QFileDialogArgs args;
1990  args.parent = parent;
1991  args.caption = caption;
1994  args.filter = filter;
1995  args.mode = ExistingFiles;
1996  args.options = options;
1997 
1998 #if defined(Q_WS_WIN)
1999  if (qt_use_native_dialogs && !(args.options & DontUseNativeDialog)) {
2000  return qt_win_get_open_file_names(args, &(args.directory), selectedFilter);
2001  }
2002 #endif
2003 
2004  // create a qt dialog
2005  QFileDialog dialog(args);
2006  if (selectedFilter && !selectedFilter->isEmpty())
2007  dialog.selectNameFilter(*selectedFilter);
2008  if (dialog.exec() == QDialog::Accepted) {
2009  if (selectedFilter)
2010  *selectedFilter = dialog.selectedFilter();
2011  return dialog.selectedFiles();
2012  }
2013  return QStringList();
2014 }
2015 
2071  const QString &caption,
2072  const QString &dir,
2073  const QString &filter,
2074  QString *selectedFilter,
2075  Options options)
2076 {
2077  if (qt_filedialog_save_filename_hook && !(options & DontUseNativeDialog))
2078  return qt_filedialog_save_filename_hook(parent, caption, dir, filter, selectedFilter, options);
2079 #if defined(Q_WS_S60)
2080  if (QSysInfo::s60Version() > QSysInfo::SV_S60_5_0 && !(options & DontUseNativeDialog))
2081  return qtSymbianGetSaveFileName(caption, dir);
2082 #endif
2083  QFileDialogArgs args;
2084  args.parent = parent;
2085  args.caption = caption;
2088  args.filter = filter;
2089  args.mode = AnyFile;
2090  args.options = options;
2091 
2092 #if defined(Q_WS_WIN)
2093  if (qt_use_native_dialogs && !(args.options & DontUseNativeDialog)) {
2094  return qt_win_get_save_file_name(args, &(args.directory), selectedFilter);
2095  }
2096 #endif
2097 
2098  // create a qt dialog
2099  QFileDialog dialog(args);
2100  dialog.setAcceptMode(AcceptSave);
2101  if (selectedFilter && !selectedFilter->isEmpty())
2102  dialog.selectNameFilter(*selectedFilter);
2103  if (dialog.exec() == QDialog::Accepted) {
2104  if (selectedFilter)
2105  *selectedFilter = dialog.selectedFilter();
2106  return dialog.selectedFiles().value(0);
2107  }
2108 
2109  return QString();
2110 }
2111 
2155  const QString &caption,
2156  const QString &dir,
2157  Options options)
2158 {
2159  if (qt_filedialog_existing_directory_hook && !(options & DontUseNativeDialog))
2160  return qt_filedialog_existing_directory_hook(parent, caption, dir, options);
2161 #if defined(Q_WS_S60)
2162  if (QSysInfo::s60Version() > QSysInfo::SV_S60_5_0 && !(options & DontUseNativeDialog))
2163  return qtSymbianGetExistingDirectory(caption, dir);
2164 #endif
2165  QFileDialogArgs args;
2166  args.parent = parent;
2167  args.caption = caption;
2169  args.mode = (options & ShowDirsOnly ? DirectoryOnly : Directory);
2170  args.options = options;
2171 
2172 #if defined(Q_WS_WIN)
2173  if (qt_use_native_dialogs && !(args.options & DontUseNativeDialog) && (options & ShowDirsOnly)
2174 #if defined(Q_WS_WINCE)
2176 #endif
2177  ) {
2178  return qt_win_get_existing_directory(args);
2179  }
2180 #endif
2181 
2182  // create a qt dialog
2183  QFileDialog dialog(args);
2184  if (dialog.exec() == QDialog::Accepted) {
2185  return dialog.selectedFiles().value(0);
2186  }
2187  return QString();
2188 }
2189 
2190 inline static QString _qt_get_directory(const QString &path)
2191 {
2193  if (info.exists() && info.isDir())
2194  return QDir::cleanPath(info.absoluteFilePath());
2195  info.setFile(info.absolutePath());
2196  if (info.exists() && info.isDir())
2197  return info.absoluteFilePath();
2198  return QString();
2199 }
2200 /*
2201  Get the initial directory path
2202 
2203  \sa initialSelection()
2204  */
2206 {
2207  if (!path.isEmpty()) {
2208  QString directory = _qt_get_directory(path);
2209  if (!directory.isEmpty())
2210  return directory;
2211  }
2212  QString directory = _qt_get_directory(*lastVisitedDir());
2213  if (!directory.isEmpty())
2214  return directory;
2215  return QDir::currentPath();
2216 }
2217 
2218 /*
2219  Get the initial selection given a path. The initial directory
2220  can contain both the initial directory and initial selection
2221  /home/user/foo.txt
2222 
2223  \sa workingDirectory()
2224  */
2226 {
2227  if (!path.isEmpty()) {
2228  QFileInfo info(path);
2229  if (!info.isDir())
2230  return info.fileName();
2231  }
2232  return QString();
2233 }
2234 
2238 void QFileDialog::done(int result)
2239 {
2240  Q_D(QFileDialog);
2241 
2242  QDialog::done(result);
2243 
2244  if (d->receiverToDisconnectOnClose) {
2245  disconnect(this, d->signalToDisconnectOnClose,
2246  d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
2247  d->receiverToDisconnectOnClose = 0;
2248  }
2249  d->memberToDisconnectOnClose.clear();
2250  d->signalToDisconnectOnClose.clear();
2251 }
2252 
2257 {
2258  Q_D(QFileDialog);
2259  QStringList files = selectedFiles();
2260  if (files.isEmpty())
2261  return;
2262  if (d->nativeDialogInUse){
2263  d->emitFilesSelected(files);
2264  QDialog::accept();
2265  return;
2266  }
2267 
2268  QString lineEditText = d->lineEdit()->text();
2269  // "hidden feature" type .. and then enter, and it will move up a dir
2270  // special case for ".."
2271  if (lineEditText == QLatin1String("..")) {
2272  d->_q_navigateToParent();
2273  bool block = d->qFileDialogUi->fileNameEdit->blockSignals(true);
2274  d->lineEdit()->selectAll();
2275  d->qFileDialogUi->fileNameEdit->blockSignals(block);
2276  return;
2277  }
2278 
2279  switch (d->fileMode) {
2280  case DirectoryOnly:
2281  case Directory: {
2282  QString fn = files.first();
2283  QFileInfo info(fn);
2284  if (!info.exists())
2285  info = QFileInfo(d->getEnvironmentVariable(fn));
2286  if (!info.exists()) {
2287 #ifndef QT_NO_MESSAGEBOX
2288  QString message = tr("%1\nDirectory not found.\nPlease verify the "
2289  "correct directory name was given.");
2290  QMessageBox::warning(this, windowTitle(), message.arg(info.fileName()));
2291 #endif // QT_NO_MESSAGEBOX
2292  return;
2293  }
2294  if (info.isDir()) {
2295  d->emitFilesSelected(files);
2296  QDialog::accept();
2297  }
2298  return;
2299  }
2300 
2301  case AnyFile: {
2302  QString fn = files.first();
2303  QFileInfo info(fn);
2304  if (info.isDir()) {
2305  setDirectory(info.absoluteFilePath());
2306  return;
2307  }
2308 
2309  if (!info.exists()) {
2310  int maxNameLength = d->maxNameLength(info.path());
2311  if (maxNameLength >= 0 && info.fileName().length() > maxNameLength)
2312  return;
2313  }
2314 
2315  // check if we have to ask for permission to overwrite the file
2316  if (!info.exists() || !confirmOverwrite() || acceptMode() == AcceptOpen) {
2317  d->emitFilesSelected(QStringList(fn));
2318  QDialog::accept();
2319 #ifndef QT_NO_MESSAGEBOX
2320  } else {
2321  if (QMessageBox::warning(this, windowTitle(),
2322  tr("%1 already exists.\nDo you want to replace it?")
2323  .arg(info.fileName()),
2325  == QMessageBox::Yes) {
2326  d->emitFilesSelected(QStringList(fn));
2327  QDialog::accept();
2328  }
2329 #endif
2330  }
2331  return;
2332  }
2333 
2334  case ExistingFile:
2335  case ExistingFiles:
2336  for (int i = 0; i < files.count(); ++i) {
2337  QFileInfo info(files.at(i));
2338  if (!info.exists())
2339  info = QFileInfo(d->getEnvironmentVariable(files.at(i)));
2340  if (!info.exists()) {
2341 #ifndef QT_NO_MESSAGEBOX
2342  QString message = tr("%1\nFile not found.\nPlease verify the "
2343  "correct file name was given.");
2344  QMessageBox::warning(this, windowTitle(), message.arg(info.fileName()));
2345 #endif // QT_NO_MESSAGEBOX
2346  return;
2347  }
2348  if (info.isDir()) {
2349  setDirectory(info.absoluteFilePath());
2350  d->lineEdit()->clear();
2351  return;
2352  }
2353  }
2354  d->emitFilesSelected(files);
2355  QDialog::accept();
2356  return;
2357  }
2358 }
2359 
2365 void QFileDialogPrivate::init(const QString &directory, const QString &nameFilter,
2366  const QString &caption)
2367 {
2368  Q_Q(QFileDialog);
2369  if (!caption.isEmpty()) {
2370  useDefaultCaption = false;
2371  setWindowTitle = caption;
2372  q->setWindowTitle(caption);
2373  }
2374 
2375  createWidgets();
2378  q->setFileMode(fileMode);
2379 
2380 #ifndef QT_NO_SETTINGS
2381  QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
2382  settings.beginGroup(QLatin1String("Qt"));
2383  if (!directory.isEmpty())
2385  q->restoreState(settings.value(QLatin1String("filedialog")).toByteArray());
2386 #endif
2387 
2388 #if defined(Q_EMBEDDED_SMALLSCREEN)
2389  qFileDialogUi->lookInLabel->setVisible(false);
2390  qFileDialogUi->fileNameLabel->setVisible(false);
2391  qFileDialogUi->fileTypeLabel->setVisible(false);
2392  qFileDialogUi->sidebar->hide();
2393 #endif
2394  // Default case
2395  if (!nameFilter.isEmpty())
2396  q->setNameFilter(nameFilter);
2397  q->setAcceptMode(QFileDialog::AcceptOpen);
2398  q->setDirectory(workingDirectory(directory));
2399  q->selectFile(initialSelection(directory));
2400 
2402  q->resize(q->sizeHint());
2403 }
2404 
2411 {
2412  Q_Q(QFileDialog);
2413  model = new QFileSystemModel(q);
2414  model->setObjectName(QLatin1String("qt_filesystem_model"));
2415 #ifdef Q_WS_MAC
2417 #else
2418  model->setNameFilterDisables(false);
2419 #endif
2420  model->d_func()->disableRecursiveSort = true;
2422  QFileDialog::connect(model, SIGNAL(rootPathChanged(QString)),
2423  q, SLOT(_q_pathChanged(QString)));
2424  QFileDialog::connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
2426  model->setReadOnly(false);
2427 
2428  qFileDialogUi.reset(new Ui_QFileDialog());
2429  qFileDialogUi->setupUi(q);
2430 
2431  QList<QUrl> initialBookmarks;
2432  initialBookmarks << QUrl::fromLocalFile(QLatin1String(""))
2434  qFileDialogUi->sidebar->init(model, initialBookmarks);
2435  QFileDialog::connect(qFileDialogUi->sidebar, SIGNAL(goToUrl(QUrl)),
2436  q, SLOT(_q_goToUrl(QUrl)));
2437 
2438  QObject::connect(qFileDialogUi->buttonBox, SIGNAL(accepted()), q, SLOT(accept()));
2439  QObject::connect(qFileDialogUi->buttonBox, SIGNAL(rejected()), q, SLOT(reject()));
2440 
2441 
2442  qFileDialogUi->lookInCombo->init(this);
2443  QObject::connect(qFileDialogUi->lookInCombo, SIGNAL(activated(QString)), q, SLOT(_q_goToDirectory(QString)));
2444 
2445  qFileDialogUi->lookInCombo->setInsertPolicy(QComboBox::NoInsert);
2446  qFileDialogUi->lookInCombo->setDuplicatesEnabled(false);
2447 
2448  // filename
2449  qFileDialogUi->fileNameEdit->init(this);
2450 #ifndef QT_NO_SHORTCUT
2451  qFileDialogUi->fileNameLabel->setBuddy(qFileDialogUi->fileNameEdit);
2452 #endif
2453 #ifndef QT_NO_FSCOMPLETER
2454  completer = new QFSCompleter(model, q);
2455  qFileDialogUi->fileNameEdit->setCompleter(completer);
2456 #endif // QT_NO_FSCOMPLETER
2457  QObject::connect(qFileDialogUi->fileNameEdit, SIGNAL(textChanged(QString)),
2459  QObject::connect(qFileDialogUi->fileNameEdit, SIGNAL(textChanged(QString)),
2460  q, SLOT(_q_updateOkButton()));
2461 
2462  QObject::connect(qFileDialogUi->fileNameEdit, SIGNAL(returnPressed()), q, SLOT(accept()));
2463 
2464  // filetype
2465  qFileDialogUi->fileTypeCombo->setDuplicatesEnabled(false);
2466  qFileDialogUi->fileTypeCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
2467  qFileDialogUi->fileTypeCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
2468  QObject::connect(qFileDialogUi->fileTypeCombo, SIGNAL(activated(int)),
2469  q, SLOT(_q_useNameFilter(int)));
2470  QObject::connect(qFileDialogUi->fileTypeCombo, SIGNAL(activated(QString)),
2471  q, SIGNAL(filterSelected(QString)));
2472 
2473  qFileDialogUi->listView->init(this);
2474  qFileDialogUi->listView->setModel(model);
2475  QObject::connect(qFileDialogUi->listView, SIGNAL(activated(QModelIndex)),
2477  QObject::connect(qFileDialogUi->listView, SIGNAL(customContextMenuRequested(QPoint)),
2479 #ifndef QT_NO_SHORTCUT
2480  QShortcut *shortcut = new QShortcut(qFileDialogUi->listView);
2481  shortcut->setKey(QKeySequence(QLatin1String("Delete")));
2482  QObject::connect(shortcut, SIGNAL(activated()), q, SLOT(_q_deleteCurrent()));
2483 #endif
2484 
2485  qFileDialogUi->treeView->init(this);
2486  qFileDialogUi->treeView->setModel(model);
2487  QHeaderView *treeHeader = qFileDialogUi->treeView->header();
2488  QFontMetrics fm(q->font());
2489  treeHeader->resizeSection(0, fm.width(QLatin1String("wwwwwwwwwwwwwwwwwwwwwwwwww")));
2490  treeHeader->resizeSection(1, fm.width(QLatin1String("128.88 GB")));
2491  treeHeader->resizeSection(2, fm.width(QLatin1String("mp3Folder")));
2492  treeHeader->resizeSection(3, fm.width(QLatin1String("10/29/81 02:02PM")));
2494 
2495  QActionGroup *showActionGroup = new QActionGroup(q);
2496  showActionGroup->setExclusive(false);
2497  QObject::connect(showActionGroup, SIGNAL(triggered(QAction*)),
2498  q, SLOT(_q_showHeader(QAction*)));;
2499 
2500  QAbstractItemModel *abstractModel = model;
2501 #ifndef QT_NO_PROXYMODEL
2502  if (proxyModel)
2503  abstractModel = proxyModel;
2504 #endif
2505  for (int i = 1; i < abstractModel->columnCount(QModelIndex()); ++i) {
2506  QAction *showHeader = new QAction(showActionGroup);
2507  showHeader->setCheckable(true);
2508  showHeader->setChecked(true);
2509  treeHeader->addAction(showHeader);
2510  }
2511 
2512  QScopedPointer<QItemSelectionModel> selModel(qFileDialogUi->treeView->selectionModel());
2513  qFileDialogUi->treeView->setSelectionModel(qFileDialogUi->listView->selectionModel());
2514 
2515  QObject::connect(qFileDialogUi->treeView, SIGNAL(activated(QModelIndex)),
2517  QObject::connect(qFileDialogUi->treeView, SIGNAL(customContextMenuRequested(QPoint)),
2519 #ifndef QT_NO_SHORTCUT
2520  shortcut = new QShortcut(qFileDialogUi->treeView);
2521  shortcut->setKey(QKeySequence(QLatin1String("Delete")));
2522  QObject::connect(shortcut, SIGNAL(activated()), q, SLOT(_q_deleteCurrent()));
2523 #endif
2524 
2525  // Selections
2526  QItemSelectionModel *selections = qFileDialogUi->listView->selectionModel();
2527  QObject::connect(selections, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
2528  q, SLOT(_q_selectionChanged()));
2529  QObject::connect(selections, SIGNAL(currentChanged(QModelIndex,QModelIndex)),
2531  qFileDialogUi->splitter->setStretchFactor(qFileDialogUi->splitter->indexOf(qFileDialogUi->splitter->widget(1)), QSizePolicy::Expanding);
2532 
2534 }
2535 
2537 {
2538  Q_Q(QFileDialog);
2539  QActionGroup *actionGroup = qobject_cast<QActionGroup*>(q->sender());
2540  qFileDialogUi->treeView->header()->setSectionHidden(actionGroup->actions().indexOf(action) + 1, !action->isChecked());
2541 }
2542 
2543 #ifndef QT_NO_PROXYMODEL
2544 
2560 {
2561  Q_D(QFileDialog);
2562  if ((!proxyModel && !d->proxyModel)
2563  || (proxyModel == d->proxyModel))
2564  return;
2565 
2566  QModelIndex idx = d->rootIndex();
2567  if (d->proxyModel) {
2568  disconnect(d->proxyModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
2569  this, SLOT(_q_rowsInserted(QModelIndex)));
2570  } else {
2571  disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
2572  this, SLOT(_q_rowsInserted(QModelIndex)));
2573  }
2574 
2575  if (proxyModel != 0) {
2576  proxyModel->setParent(this);
2577  d->proxyModel = proxyModel;
2578  proxyModel->setSourceModel(d->model);
2579  d->qFileDialogUi->listView->setModel(d->proxyModel);
2580  d->qFileDialogUi->treeView->setModel(d->proxyModel);
2581 #ifndef QT_NO_FSCOMPLETER
2582  d->completer->setModel(d->proxyModel);
2583  d->completer->proxyModel = d->proxyModel;
2584 #endif
2585  connect(d->proxyModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
2586  this, SLOT(_q_rowsInserted(QModelIndex)));
2587  } else {
2588  d->proxyModel = 0;
2589  d->qFileDialogUi->listView->setModel(d->model);
2590  d->qFileDialogUi->treeView->setModel(d->model);
2591 #ifndef QT_NO_FSCOMPLETER
2592  d->completer->setModel(d->model);
2593  d->completer->sourceModel = d->model;
2594  d->completer->proxyModel = 0;
2595 #endif
2596  connect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
2597  this, SLOT(_q_rowsInserted(QModelIndex)));
2598  }
2599  QScopedPointer<QItemSelectionModel> selModel(d->qFileDialogUi->treeView->selectionModel());
2600  d->qFileDialogUi->treeView->setSelectionModel(d->qFileDialogUi->listView->selectionModel());
2601 
2602  d->setRootIndex(idx);
2603 
2604  // reconnect selection
2605  QItemSelectionModel *selections = d->qFileDialogUi->listView->selectionModel();
2606  QObject::connect(selections, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
2607  this, SLOT(_q_selectionChanged()));
2608  QObject::connect(selections, SIGNAL(currentChanged(QModelIndex,QModelIndex)),
2610 }
2611 
2618 {
2619  Q_D(const QFileDialog);
2620  return d->proxyModel;
2621 }
2622 #endif // QT_NO_PROXYMODEL
2623 
2630 {
2631  Q_Q(QFileDialog);
2632  qFileDialogUi->backButton->setIcon(q->style()->standardIcon(QStyle::SP_ArrowBack, 0, q));
2633  qFileDialogUi->backButton->setAutoRaise(true);
2634  qFileDialogUi->backButton->setEnabled(false);
2635  QObject::connect(qFileDialogUi->backButton, SIGNAL(clicked()), q, SLOT(_q_navigateBackward()));
2636 
2637  qFileDialogUi->forwardButton->setIcon(q->style()->standardIcon(QStyle::SP_ArrowForward, 0, q));
2638  qFileDialogUi->forwardButton->setAutoRaise(true);
2639  qFileDialogUi->forwardButton->setEnabled(false);
2640  QObject::connect(qFileDialogUi->forwardButton, SIGNAL(clicked()), q, SLOT(_q_navigateForward()));
2641 
2642  qFileDialogUi->toParentButton->setIcon(q->style()->standardIcon(QStyle::SP_FileDialogToParent, 0, q));
2643  qFileDialogUi->toParentButton->setAutoRaise(true);
2644  qFileDialogUi->toParentButton->setEnabled(false);
2645  QObject::connect(qFileDialogUi->toParentButton, SIGNAL(clicked()), q, SLOT(_q_navigateToParent()));
2646 
2647  qFileDialogUi->listModeButton->setIcon(q->style()->standardIcon(QStyle::SP_FileDialogListView, 0, q));
2648  qFileDialogUi->listModeButton->setAutoRaise(true);
2649  qFileDialogUi->listModeButton->setDown(true);
2650  QObject::connect(qFileDialogUi->listModeButton, SIGNAL(clicked()), q, SLOT(_q_showListView()));
2651 
2652  qFileDialogUi->detailModeButton->setIcon(q->style()->standardIcon(QStyle::SP_FileDialogDetailedView, 0, q));
2653  qFileDialogUi->detailModeButton->setAutoRaise(true);
2654  QObject::connect(qFileDialogUi->detailModeButton, SIGNAL(clicked()), q, SLOT(_q_showDetailsView()));
2655 
2656  QSize toolSize(qFileDialogUi->fileNameEdit->sizeHint().height(), qFileDialogUi->fileNameEdit->sizeHint().height());
2657  qFileDialogUi->backButton->setFixedSize(toolSize);
2658  qFileDialogUi->listModeButton->setFixedSize(toolSize);
2659  qFileDialogUi->detailModeButton->setFixedSize(toolSize);
2660  qFileDialogUi->forwardButton->setFixedSize(toolSize);
2661  qFileDialogUi->toParentButton->setFixedSize(toolSize);
2662 
2663  qFileDialogUi->newFolderButton->setIcon(q->style()->standardIcon(QStyle::SP_FileDialogNewFolder, 0, q));
2664  qFileDialogUi->newFolderButton->setFixedSize(toolSize);
2665  qFileDialogUi->newFolderButton->setAutoRaise(true);
2666  qFileDialogUi->newFolderButton->setEnabled(false);
2667  QObject::connect(qFileDialogUi->newFolderButton, SIGNAL(clicked()), q, SLOT(_q_createDirectory()));
2668 }
2669 
2679 {
2680  Q_Q(QFileDialog);
2681 
2682  QAction *goHomeAction = new QAction(q);
2683 #ifndef QT_NO_SHORTCUT
2684  goHomeAction->setShortcut(Qt::CTRL + Qt::Key_H + Qt::SHIFT);
2685 #endif
2686  QObject::connect(goHomeAction, SIGNAL(triggered()), q, SLOT(_q_goHome()));
2687  q->addAction(goHomeAction);
2688 
2689  // ### TODO add Desktop & Computer actions
2690 
2691  QAction *goToParent = new QAction(q);
2692  goToParent->setObjectName(QLatin1String("qt_goto_parent_action"));
2693 #ifndef QT_NO_SHORTCUT
2694  goToParent->setShortcut(Qt::CTRL + Qt::UpArrow);
2695 #endif
2696  QObject::connect(goToParent, SIGNAL(triggered()), q, SLOT(_q_navigateToParent()));
2697  q->addAction(goToParent);
2698 
2699  renameAction = new QAction(q);
2700  renameAction->setEnabled(false);
2701  renameAction->setObjectName(QLatin1String("qt_rename_action"));
2703 
2704  deleteAction = new QAction(q);
2705  deleteAction->setEnabled(false);
2706  deleteAction->setObjectName(QLatin1String("qt_delete_action"));
2708 
2709  showHiddenAction = new QAction(q);
2710  showHiddenAction->setObjectName(QLatin1String("qt_show_hidden_action"));
2713 
2714  newFolderAction = new QAction(q);
2715  newFolderAction->setObjectName(QLatin1String("qt_new_folder_action"));
2717 }
2718 
2720 {
2721  Q_Q(QFileDialog);
2722  q->setDirectory(QDir::homePath());
2723 }
2724 
2731 {
2732  Q_Q(QFileDialog);
2733  QDir dir(model->rootDirectory());
2734  qFileDialogUi->toParentButton->setEnabled(dir.exists());
2735  qFileDialogUi->sidebar->selectUrl(QUrl::fromLocalFile(newPath));
2736  q->setHistory(qFileDialogUi->lookInCombo->history());
2737 
2741  }
2744  }
2745  qFileDialogUi->forwardButton->setEnabled(currentHistory.size() - currentHistoryLocation > 1);
2746  qFileDialogUi->backButton->setEnabled(currentHistoryLocation > 0);
2747 }
2748 
2758 {
2759  Q_Q(QFileDialog);
2762  QString previousHistory = currentHistory.at(currentHistoryLocation);
2763  q->setDirectory(previousHistory);
2764  }
2765 }
2766 
2776 {
2777  Q_Q(QFileDialog);
2781  q->setDirectory(nextHistory);
2782  }
2783 }
2784 
2795 {
2796  Q_Q(QFileDialog);
2797  QDir dir(model->rootDirectory());
2798  QString newDirectory;
2799  if (dir.isRoot()) {
2800  newDirectory = model->myComputer().toString();
2801  } else {
2802  dir.cdUp();
2803  newDirectory = dir.absolutePath();
2804  }
2805  q->setDirectory(newDirectory);
2806  emit q->directoryEntered(newDirectory);
2807 }
2808 
2818 {
2819  Q_Q(QFileDialog);
2820  qFileDialogUi->listView->clearSelection();
2821 
2822  QString newFolderString = QFileDialog::tr("New Folder");
2823  QString folderName = newFolderString;
2824  QString prefix = q->directory().absolutePath() + QDir::separator();
2825  if (QFile::exists(prefix + folderName)) {
2826  qlonglong suffix = 2;
2827  while (QFile::exists(prefix + folderName)) {
2828  folderName = newFolderString + QString::number(suffix++);
2829  }
2830  }
2831 
2832  QModelIndex parent = rootIndex();
2833  QModelIndex index = model->mkdir(parent, folderName);
2834  if (!index.isValid())
2835  return;
2836 
2837  index = select(index);
2838  if (index.isValid()) {
2839  qFileDialogUi->treeView->setCurrentIndex(index);
2840  currentView()->edit(index);
2841  }
2842 }
2843 
2845 {
2846  qFileDialogUi->listModeButton->setDown(true);
2847  qFileDialogUi->detailModeButton->setDown(false);
2848  qFileDialogUi->treeView->hide();
2849  qFileDialogUi->listView->show();
2850  qFileDialogUi->stackedWidget->setCurrentWidget(qFileDialogUi->listView->parentWidget());
2851  qFileDialogUi->listView->doItemsLayout();
2852 }
2853 
2855 {
2856  qFileDialogUi->listModeButton->setDown(false);
2857  qFileDialogUi->detailModeButton->setDown(true);
2858  qFileDialogUi->listView->hide();
2859  qFileDialogUi->treeView->show();
2860  qFileDialogUi->stackedWidget->setCurrentWidget(qFileDialogUi->treeView->parentWidget());
2861  qFileDialogUi->treeView->doItemsLayout();
2862 }
2863 
2870 {
2871 #ifdef QT_NO_MENU
2872  Q_UNUSED(position);
2873 #else
2874  Q_Q(QFileDialog);
2875  QAbstractItemView *view = 0;
2876  if (q->viewMode() == QFileDialog::Detail)
2877  view = qFileDialogUi->treeView;
2878  else
2879  view = qFileDialogUi->listView;
2880  QModelIndex index = view->indexAt(position);
2881  index = mapToSource(index.sibling(index.row(), 0));
2882 
2883  QMenu menu(view);
2884  if (index.isValid()) {
2885  // file context menu
2886  QFile::Permissions p(index.parent().data(QFileSystemModel::FilePermissions).toInt());
2888  menu.addAction(renameAction);
2889  deleteAction->setEnabled(p & QFile::WriteUser);
2890  menu.addAction(deleteAction);
2891  menu.addSeparator();
2892  }
2894  if (qFileDialogUi->newFolderButton->isVisible()) {
2895  newFolderAction->setEnabled(qFileDialogUi->newFolderButton->isEnabled());
2896  menu.addAction(newFolderAction);
2897  }
2898  menu.exec(view->viewport()->mapToGlobal(position));
2899 #endif // QT_NO_MENU
2900 }
2901 
2906 {
2907  Q_Q(QFileDialog);
2908  QModelIndex index = qFileDialogUi->listView->currentIndex();
2909  index = index.sibling(index.row(), 0);
2910  if (q->viewMode() == QFileDialog::List)
2911  qFileDialogUi->listView->edit(index);
2912  else
2913  qFileDialogUi->treeView->edit(index);
2914 }
2915 
2917 {
2918  QModelIndex modelIndex = model->index(path);
2919  return model->remove(modelIndex);
2920 }
2921 
2931 {
2932  if (model->isReadOnly())
2933  return;
2934 
2935  QModelIndexList list = qFileDialogUi->listView->selectionModel()->selectedRows();
2936  for (int i = list.count() - 1; i >= 0; --i) {
2937  QModelIndex index = list.at(i);
2938  if (index == qFileDialogUi->listView->rootIndex())
2939  continue;
2940 
2941  index = mapToSource(index.sibling(index.row(), 0));
2942  if (!index.isValid())
2943  continue;
2944 
2947  bool isDir = model->isDir(index);
2948 
2949  QFile::Permissions p(index.parent().data(QFileSystemModel::FilePermissions).toInt());
2950 #ifndef QT_NO_MESSAGEBOX
2951  Q_Q(QFileDialog);
2952  if (!(p & QFile::WriteUser) && (QMessageBox::warning(q_func(), q_func()->windowTitle(),
2953  QFileDialog::tr("'%1' is write protected.\nDo you want to delete it anyway?")
2954  .arg(fileName),
2956  return;
2957  else if (QMessageBox::warning(q_func(), q_func()->windowTitle(),
2958  QFileDialog::tr("Are sure you want to delete '%1'?")
2959  .arg(fileName),
2961  return;
2962 
2963 #else
2964  if (!(p & QFile::WriteUser))
2965  return;
2966 #endif // QT_NO_MESSAGEBOX
2967 
2968  // the event loop has run, we can NOT reuse index because the model might have removed it.
2969  if (isDir) {
2970  if (!removeDirectory(filePath)) {
2971 #ifndef QT_NO_MESSAGEBOX
2972  QMessageBox::warning(q, q->windowTitle(),
2973  QFileDialog::tr("Could not delete directory."));
2974 #endif
2975  }
2976  } else {
2977  model->remove(index);
2978  }
2979  }
2980 }
2981 
2983 {
2984  if (text.startsWith(QLatin1String("//")) || text.startsWith(QLatin1Char('\\'))) {
2985  qFileDialogUi->listView->selectionModel()->clearSelection();
2986  return;
2987  }
2988 
2989  QStringList multipleFiles = typedFiles();
2990  if (multipleFiles.count() > 0) {
2991  QModelIndexList oldFiles = qFileDialogUi->listView->selectionModel()->selectedRows();
2992  QModelIndexList newFiles;
2993  for (int i = 0; i < multipleFiles.count(); ++i) {
2994  QModelIndex idx = model->index(multipleFiles.at(i));
2995  if (oldFiles.contains(idx))
2996  oldFiles.removeAll(idx);
2997  else
2998  newFiles.append(idx);
2999  }
3000  for (int i = 0; i < newFiles.count(); ++i)
3001  select(newFiles.at(i));
3002  if (lineEdit()->hasFocus())
3003  for (int i = 0; i < oldFiles.count(); ++i)
3004  qFileDialogUi->listView->selectionModel()->select(oldFiles.at(i),
3006  }
3007 }
3008 
3013 {
3014  Q_Q(QFileDialog);
3015  QPushButton *button = qFileDialogUi->buttonBox->button((acceptMode == QFileDialog::AcceptOpen)
3017  if (!button)
3018  return;
3019 
3020  bool enableButton = true;
3021  bool isOpenDirectory = false;
3022 
3023  QStringList files = q->selectedFiles();
3024  QString lineEditText = lineEdit()->text();
3025 
3026  if (lineEditText.startsWith(QLatin1String("//")) || lineEditText.startsWith(QLatin1Char('\\'))) {
3027  button->setEnabled(true);
3029  button->setText(acceptLabel);
3030  return;
3031  }
3032 
3033  if (files.isEmpty()) {
3034  enableButton = false;
3035  } else if (lineEditText == QLatin1String("..")) {
3036  isOpenDirectory = true;
3037  } else {
3038  switch (fileMode) {
3040  case QFileDialog::Directory: {
3041  QString fn = files.first();
3042  QModelIndex idx = model->index(fn);
3043  if (!idx.isValid())
3044  idx = model->index(getEnvironmentVariable(fn));
3045  if (!idx.isValid() || !model->isDir(idx))
3046  enableButton = false;
3047  break;
3048  }
3049  case QFileDialog::AnyFile: {
3050  QString fn = files.first();
3051  QFileInfo info(fn);
3052  QModelIndex idx = model->index(fn);
3053  QString fileDir;
3054  QString fileName;
3055  if (info.isDir()) {
3056  fileDir = info.canonicalFilePath();
3057  } else {
3058  fileDir = fn.mid(0, fn.lastIndexOf(QLatin1Char('/')));
3059  fileName = fn.mid(fileDir.length() + 1);
3060  }
3061  if (lineEditText.contains(QLatin1String(".."))) {
3062  fileDir = info.canonicalFilePath();
3063  fileName = info.fileName();
3064  }
3065 
3066  if (fileDir == q->directory().canonicalPath() && fileName.isEmpty()) {
3067  enableButton = false;
3068  break;
3069  }
3070  if (idx.isValid() && model->isDir(idx)) {
3071  isOpenDirectory = true;
3072  enableButton = true;
3073  break;
3074  }
3075  if (!idx.isValid()) {
3076  int maxLength = maxNameLength(fileDir);
3077  enableButton = maxLength < 0 || fileName.length() <= maxLength;
3078  }
3079  break;
3080  }
3083  for (int i = 0; i < files.count(); ++i) {
3084  QModelIndex idx = model->index(files.at(i));
3085  if (!idx.isValid())
3086  idx = model->index(getEnvironmentVariable(files.at(i)));
3087  if (!idx.isValid()) {
3088  enableButton = false;
3089  break;
3090  }
3091  if (idx.isValid() && model->isDir(idx)) {
3092  isOpenDirectory = true;
3093  break;
3094  }
3095  }
3096  break;
3097  default:
3098  break;
3099  }
3100  }
3101 
3102  button->setEnabled(enableButton);
3104  button->setText(isOpenDirectory ? QFileDialog::tr("&Open") : acceptLabel);
3105 }
3106 
3111 {
3113  emit q_func()->currentChanged(index.data(QFileSystemModel::FilePathRole).toString());
3114 }
3115 
3126 {
3127  Q_Q(QFileDialog);
3128  // My Computer or a directory
3129  QModelIndex sourceIndex = index.model() == proxyModel ? mapToSource(index) : index;
3130  QString path = sourceIndex.data(QFileSystemModel::FilePathRole).toString();
3131  if (path.isEmpty() || model->isDir(sourceIndex)) {
3132  q->setDirectory(path);
3133  emit q->directoryEntered(path);
3136  // ### find out why you have to do both of these.
3137  lineEdit()->setText(QString());
3138  lineEdit()->clear();
3139  }
3140  } else {
3141  // Do not accept when shift-clicking to multi-select a file in environments with single-click-activation (KDE)
3142  if (!q->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)
3144  q->accept();
3145  }
3146  }
3147 }
3148 
3159 {
3160  #ifndef QT_NO_MESSAGEBOX
3161  Q_Q(QFileDialog);
3162 #endif
3163  QModelIndex index = qFileDialogUi->lookInCombo->model()->index(qFileDialogUi->lookInCombo->currentIndex(),
3164  qFileDialogUi->lookInCombo->modelColumn(),
3165  qFileDialogUi->lookInCombo->rootModelIndex());
3166  QString path2 = path;
3167  if (!index.isValid())
3169  else {
3170  path2 = index.data(UrlRole).toUrl().toLocalFile();
3171  index = mapFromSource(model->index(path2));
3172  }
3173  QDir dir(path2);
3174  if (!dir.exists())
3175  dir = getEnvironmentVariable(path2);
3176 
3177  if (dir.exists() || path2.isEmpty() || path2 == model->myComputer().toString()) {
3178  _q_enterDirectory(index);
3179 #ifndef QT_NO_MESSAGEBOX
3180  } else {
3181  QString message = QFileDialog::tr("%1\nDirectory not found.\nPlease verify the "
3182  "correct directory name was given.");
3183  QMessageBox::warning(q, q->windowTitle(), message.arg(path2));
3184 #endif // QT_NO_MESSAGEBOX
3185  }
3186 }
3187 
3188 // Makes a list of filters from a normal filter string "Image Files (*.png *.jpg)"
3190 {
3191  QRegExp regexp(QString::fromLatin1(qt_file_dialog_filter_reg_exp));
3192  QString f = filter;
3193  int i = regexp.indexIn(f);
3194  if (i >= 0)
3195  f = regexp.cap(2);
3196  return f.split(QLatin1Char(' '), QString::SkipEmptyParts);
3197 }
3198 
3209 {
3210  if (index == nameFilters.size()) {
3211  QAbstractItemModel *comboModel = qFileDialogUi->fileTypeCombo->model();
3212  nameFilters.append(comboModel->index(comboModel->rowCount() - 1, 0).data().toString());
3213  }
3214 
3215  QString nameFilter = nameFilters.at(index);
3216  QStringList newNameFilters = qt_clean_filter_list(nameFilter);
3218  QString newNameFilterExtension;
3219  if (newNameFilters.count() > 0)
3220  newNameFilterExtension = QFileInfo(newNameFilters.at(0)).suffix();
3221 
3222  QString fileName = lineEdit()->text();
3223  const QString fileNameExtension = QFileInfo(fileName).suffix();
3224  if (!fileNameExtension.isEmpty() && !newNameFilterExtension.isEmpty()) {
3225  const int fileNameExtensionLength = fileNameExtension.count();
3226  fileName.replace(fileName.count() - fileNameExtensionLength,
3227  fileNameExtensionLength, newNameFilterExtension);
3228  qFileDialogUi->listView->clearSelection();
3229  lineEdit()->setText(fileName);
3230  }
3231  }
3232 
3233  model->setNameFilters(newNameFilters);
3234 }
3235 
3246 {
3247  QModelIndexList indexes = qFileDialogUi->listView->selectionModel()->selectedRows();
3249 
3250  QStringList allFiles;
3251  for (int i = 0; i < indexes.count(); ++i) {
3252  if (stripDirs && model->isDir(mapToSource(indexes.at(i))))
3253  continue;
3254  allFiles.append(indexes.at(i).data().toString());
3255  }
3256  if (allFiles.count() > 1)
3257  for (int i = 0; i < allFiles.count(); ++i) {
3258  allFiles.replace(i, QString(QLatin1Char('"') + allFiles.at(i) + QLatin1Char('"')));
3259  }
3260 
3261  QString finalFiles = allFiles.join(QLatin1String(" "));
3262  if (!finalFiles.isEmpty() && !lineEdit()->hasFocus() && lineEdit()->isVisible())
3263  lineEdit()->setText(finalFiles);
3264  else
3266 }
3267 
3277 {
3278  Q_Q(QFileDialog);
3279  QDir::Filters dirFilters = q->filter();
3280  if (showHiddenAction->isChecked())
3281  dirFilters |= QDir::Hidden;
3282  else
3283  dirFilters &= ~QDir::Hidden;
3284  q->setFilter(dirFilters);
3285 }
3286 
3297 {
3298  if (!qFileDialogUi->treeView
3299  || parent != qFileDialogUi->treeView->rootIndex()
3300  || !qFileDialogUi->treeView->selectionModel()
3301  || qFileDialogUi->treeView->selectionModel()->hasSelection()
3302  || qFileDialogUi->treeView->model()->rowCount(parent) == 0)
3303  return;
3304 }
3305 
3306 void QFileDialogPrivate::_q_fileRenamed(const QString &path, const QString oldName, const QString newName)
3307 {
3309  if (path == rootPath() && lineEdit()->text() == oldName)
3310  lineEdit()->setText(newName);
3311  }
3312 }
3313 
3322 
3323  Q_Q(QFileDialog);
3324  switch (event->key()) {
3325  case Qt::Key_Backspace:
3327  return true;
3328  case Qt::Key_Back:
3329 #ifdef QT_KEYPAD_NAVIGATION
3330  if (QApplication::keypadNavigationEnabled())
3331  return false;
3332 #endif
3333  case Qt::Key_Left:
3334  if (event->key() == Qt::Key_Back || event->modifiers() == Qt::AltModifier) {
3336  return true;
3337  }
3338  break;
3339  case Qt::Key_Escape:
3340  q->hide();
3341  return true;
3342  default:
3343  break;
3344  }
3345  return false;
3346 }
3347 
3349 {
3350 #ifdef Q_OS_UNIX
3351  if (string.size() > 1 && string.startsWith(QLatin1Char('$'))) {
3352  return QString::fromLocal8Bit(getenv(string.mid(1).toLatin1().constData()));
3353  }
3354 #else
3355  if (string.size() > 2 && string.startsWith(QLatin1Char('%')) && string.endsWith(QLatin1Char('%'))) {
3356  return QString::fromLocal8Bit(qgetenv(string.mid(1, string.size() - 2).toLatin1().constData()));
3357  }
3358 #endif
3359  return string;
3360 }
3361 
3363  d_ptr = d_pointer;
3364  urlModel = new QUrlModel(this);
3365  urlModel->showFullPath = true;
3366  urlModel->setFileSystemModel(d_ptr->model);
3367  setModel(urlModel);
3368 }
3369 
3371 {
3372  if (model()->rowCount() > 1)
3374 
3375  urlModel->setUrls(QList<QUrl>());
3376  QList<QUrl> list;
3377  QModelIndex idx = d_ptr->model->index(d_ptr->rootPath());
3378  while (idx.isValid()) {
3380  if (url.isValid())
3381  list.append(url);
3382  idx = idx.parent();
3383  }
3384  // add "my computer"
3386  urlModel->addUrls(list, 0);
3387  idx = model()->index(model()->rowCount() - 1, 0);
3388 
3389  // append history
3390  QList<QUrl> urls;
3391  for (int i = 0; i < m_history.count(); ++i) {
3392  QUrl path = QUrl::fromLocalFile(m_history.at(i));
3393  if (!urls.contains(path))
3394  urls.prepend(path);
3395  }
3396  if (urls.count() > 0) {
3397  model()->insertRow(model()->rowCount());
3398  idx = model()->index(model()->rowCount()-1, 0);
3399  // ### TODO maybe add a horizontal line before this
3400  model()->setData(idx, QFileDialog::tr("Recent Places"));
3402  if (m) {
3403  Qt::ItemFlags flags = m->flags(idx);
3404  flags &= ~Qt::ItemIsEnabled;
3405  m->item(idx.row(), idx.column())->setFlags(flags);
3406  }
3407  urlModel->addUrls(urls, -1, false);
3408  }
3409  setCurrentIndex(0);
3410 
3412 }
3413 
3414 // Exact same as QComboBox::paintEvent(), except we elide the text.
3416 {
3417  QStylePainter painter(this);
3418  painter.setPen(palette().color(QPalette::Text));
3419 
3420  // draw the combobox frame, focusrect and selected etc.
3422  initStyleOption(&opt);
3423 
3424  QRect editRect = style()->subControlRect(QStyle::CC_ComboBox, &opt,
3426  int size = editRect.width() - opt.iconSize.width() - 4;
3429 
3430  // draw the icon and text
3431  painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
3432 }
3433 
3435 {
3436 }
3437 
3439 {
3440  d_ptr = d_pointer;
3442  setWrapping(true);
3446 #ifndef QT_NO_DRAGANDDROP
3448 #endif
3449 }
3450 
3452 {
3453  int height = qMax(10, sizeHintForRow(0));
3454  return QSize(QListView::sizeHint().width() * 2, height * 30);
3455 }
3456 
3458 {
3459 #ifdef QT_KEYPAD_NAVIGATION
3460  if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) {
3462  return;
3463  }
3464 #endif // QT_KEYPAD_NAVIGATION
3465 
3466  if (!d_ptr->itemViewKeyboardEvent(e))
3468  e->accept();
3469 }
3470 
3472 {
3473 }
3474 
3476 {
3477  d_ptr = d_pointer;
3479  setRootIsDecorated(false);
3480  setItemsExpandable(false);
3481  setSortingEnabled(true);
3483  header()->setStretchLastSection(false);
3487 #ifndef QT_NO_DRAGANDDROP
3489 #endif
3490 }
3491 
3493 {
3494 #ifdef QT_KEYPAD_NAVIGATION
3495  if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) {
3497  return;
3498  }
3499 #endif // QT_KEYPAD_NAVIGATION
3500 
3501  if (!d_ptr->itemViewKeyboardEvent(e))
3503  e->accept();
3504 }
3505 
3507 {
3508  int height = qMax(10, sizeHintForRow(0));
3509  QSize sizeHint = header()->sizeHint();
3510  return QSize(sizeHint.width() * 4, height * 30);
3511 }
3512 
3518 {
3519 #ifdef QT_KEYPAD_NAVIGATION
3520  if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) {
3522  return;
3523  }
3524 #endif // QT_KEYPAD_NAVIGATION
3525 
3526  int key = e->key();
3528  if (key != Qt::Key_Escape)
3529  e->accept();
3530  if (hideOnEsc && (key == Qt::Key_Escape || key == Qt::Key_Return || key == Qt::Key_Enter)) {
3531  e->accept();
3532  hide();
3534  }
3535 }
3536 
3537 #ifndef QT_NO_FSCOMPLETER
3538 
3540 {
3541  const QFileSystemModel *dirModel;
3542  if (proxyModel)
3543  dirModel = qobject_cast<const QFileSystemModel *>(proxyModel->sourceModel());
3544  else
3545  dirModel = sourceModel;
3546  QString currentLocation = dirModel->rootPath();
3548  if (!currentLocation.isEmpty() && path.startsWith(currentLocation)) {
3549 #if defined(Q_OS_UNIX) || defined(Q_OS_WINCE)
3550  if (currentLocation == QDir::separator())
3551  return path.mid(currentLocation.length());
3552 #endif
3553  if (currentLocation.endsWith(QLatin1Char('/')))
3554  return path.mid(currentLocation.length());
3555  else
3556  return path.mid(currentLocation.length()+1);
3557  }
3559 }
3560 
3562 {
3563  if (path.isEmpty())
3564  return QStringList(completionPrefix());
3565 
3566  QString pathCopy = QDir::toNativeSeparators(path);
3567  QString sep = QDir::separator();
3568 #if defined(Q_OS_SYMBIAN)
3569  if (pathCopy == QLatin1String("\\"))
3570  return QStringList(pathCopy);
3571 #elif defined(Q_OS_WIN)
3572  if (pathCopy == QLatin1String("\\") || pathCopy == QLatin1String("\\\\"))
3573  return QStringList(pathCopy);
3574  QString doubleSlash(QLatin1String("\\\\"));
3575  if (pathCopy.startsWith(doubleSlash))
3576  pathCopy = pathCopy.mid(2);
3577  else
3578  doubleSlash.clear();
3579 #elif defined(Q_OS_UNIX)
3580  bool expanded;
3581  pathCopy = qt_tildeExpansion(pathCopy, &expanded);
3582  if (expanded) {
3583  QFileSystemModel *dirModel;
3584  if (proxyModel)
3585  dirModel = qobject_cast<QFileSystemModel *>(proxyModel->sourceModel());
3586  else
3587  dirModel = sourceModel;
3588  dirModel->fetchMore(dirModel->index(pathCopy));
3589  }
3590 #endif
3591 
3592  QRegExp re(QLatin1Char('[') + QRegExp::escape(sep) + QLatin1Char(']'));
3593 
3594 #if defined(Q_OS_SYMBIAN)
3595  QStringList parts = pathCopy.split(re, QString::SkipEmptyParts);
3596  if (pathCopy.endsWith(sep))
3597  parts.append(QString());
3598 #elif defined(Q_OS_WIN)
3599  QStringList parts = pathCopy.split(re, QString::SkipEmptyParts);
3600  if (!doubleSlash.isEmpty() && !parts.isEmpty())
3601  parts[0].prepend(doubleSlash);
3602  if (pathCopy.endsWith(sep))
3603  parts.append(QString());
3604 #else
3605  QStringList parts = pathCopy.split(re);
3606  if (pathCopy[0] == sep[0]) // read the "/" at the beginning as the split removed it
3607  parts[0] = sep[0];
3608 #endif
3609 
3610 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
3611  bool startsFromRoot = !parts.isEmpty() && parts[0].endsWith(QLatin1Char(':'));
3612 #else
3613  bool startsFromRoot = pathCopy[0] == sep[0];
3614 #endif
3615  if (parts.count() == 1 || (parts.count() > 1 && !startsFromRoot)) {
3616  const QFileSystemModel *dirModel;
3617  if (proxyModel)
3618  dirModel = qobject_cast<const QFileSystemModel *>(proxyModel->sourceModel());
3619  else
3620  dirModel = sourceModel;
3621  QString currentLocation = QDir::toNativeSeparators(dirModel->rootPath());
3622 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
3623  if (currentLocation.endsWith(QLatin1Char(':')))
3624  currentLocation.append(sep);
3625 #endif
3626  if (currentLocation.contains(sep) && path != currentLocation) {
3627  QStringList currentLocationList = splitPath(currentLocation);
3628  while (!currentLocationList.isEmpty()
3629  && parts.count() > 0
3630  && parts.at(0) == QLatin1String("..")) {
3631  parts.removeFirst();
3632  currentLocationList.removeLast();
3633  }
3634  if (!currentLocationList.isEmpty() && currentLocationList.last().isEmpty())
3635  currentLocationList.removeLast();
3636  return currentLocationList + parts;
3637  }
3638  }
3639  return parts;
3640 }
3641 
3642 #endif // QT_NO_COMPLETER
3643 
3644 #ifdef QT3_SUPPORT
3645 
3657 QString QFileDialog::selectedFile() const
3658 {
3659  QStringList files = selectedFiles();
3660  return files.size() ? files.at(0) : QString();
3661 }
3662 
3744 #endif // QT3_SUPPORT
3745 
3747 
3748 #include "moc_qfiledialog.cpp"
3749 
3750 #endif // QT_NO_FILEDIALOG
void _q_navigateForward()
Navigates to the last directory viewed in the dialog.
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
SelectionMode
This enum indicates how the view responds to user selections:
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
void init(QFileDialogPrivate *d_pointer)
T qobject_cast(QObject *object)
Definition: qobject.h:375
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
double d
Definition: qnumeric_p.h:62
QModelIndex mapFromSource(const QModelIndex &index) const
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
static const qint32 QFileDialogMagic
QString qt_win_get_existing_directory(const QFileDialogArgs &args)
bool isReadOnly() const
The QAbstractItemDelegate class is used to display and edit data items from a model.
void setValue(const QString &key, const QVariant &value)
Sets the value of setting key to value.
Definition: qsettings.cpp:3328
void keyPressEvent(QKeyEvent *)
Converts the given key press event into a line edit action.
Definition: qlineedit.cpp:1764
QSize sizeHint() const
void setSidebarUrls(const QList< QUrl > &urls)
Sets the urls that are located in the sidebar.
void _q_navigateBackward()
Navigates to the last directory viewed in the dialog.
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
The QKeyEvent class describes a key event.
Definition: qevent.h:224
The QItemSelectionModel class keeps track of a view&#39;s selected items.
QAbstractItemDelegate * itemDelegate() const
Returns the item delegate used to render the items in the views in the filedialog.
The QFileSystemModel class provides a data model for the local filesystem.
void setShortcut(const QKeySequence &shortcut)
Definition: qaction.cpp:450
void setDirectory(const QString &directory)
Sets the file dialog&#39;s current directory.
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
void _q_showContextMenu(const QPoint &position)
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for setting key.
Definition: qsettings.cpp:3460
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
Definition: qurl.cpp:4303
static mach_timebase_info_data_t info
void _q_enterDirectory(const QModelIndex &index)
This is called when the user double clicks on a file with the corresponding model item index...
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
QString cap(int nth=0) const
Returns the text captured by the nth subexpression.
Definition: qregexp.cpp:4310
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
Q_GUI_EXPORT _qt_filedialog_existing_directory_hook qt_filedialog_existing_directory_hook
Definition: qfiledialog.cpp:85
QString text() const
void setText(const QString &text)
int qint32
Definition: qglobal.h:937
QString defaultSuffix() const
QT_DEPRECATED void setFilter(const QString &filter)
Use setNameFilter() instead.
static QString getSaveFileName(QWidget *parent=0, const QString &caption=QString(), const QString &dir=QString(), const QString &filter=QString(), QString *selectedFilter=0, Options options=0)
This is a convenience static function that will return a file name selected by the user...
QSize iconSize
the icon size for the current item of the combo box
Definition: qstyleoption.h:807
QFileDialog::Options opts
EventRef event
Q_AUTOTEST_EXPORT QString qt_tildeExpansion(const QString &path, bool *expanded=0)
void setConfirmOverwrite(bool enabled)
void drawControl(QStyle::ControlElement ce, const QStyleOption &opt)
Use the widget&#39;s style to draw a control element ce specified by QStyleOption option.
Definition: qstylepainter.h:87
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
void setHistory(const QStringList &paths)
QAbstractProxyModel * proxyModel
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
QVariant data(int role=Qt::DisplayRole) const
Returns the data for the given role for the item referred to by the index.
void retranslateWindowTitle()
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Reimplemented Function
QFileDialog::FileMode mode
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
bool isAbsolute() const
Returns true if the file path name is absolute, otherwise returns false if the path is relative...
Definition: qfileinfo.h:111
The QDialog class is the base class of dialog windows.
Definition: qdialog.h:56
void setViewMode(ViewMode mode)
void setNameFilterDetailsVisible(bool enabled)
QStringList addDefaultSuffixToFiles(const QStringList filesToFix) const
int exec()
Shows the dialog as a modal dialog, blocking until the user closes it.
Definition: qdialog.cpp:524
void setStretchLastSection(bool stretch)
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
QDir directory() const
Returns the directory currently being displayed in the dialog.
bool isVisible() const
Definition: qwidget.h:1005
void setNameFilterDisables(bool enable)
QFileDialog::AcceptMode acceptMode
void setCheckable(bool)
Definition: qaction.cpp:1094
void keyPressEvent(QKeyEvent *e)
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
bool atEnd() const
Returns true if the I/O device has reached the end position (end of the stream or file) or if there i...
QString currentText
the text for the current item of the combo box
Definition: qstyleoption.h:805
bool itemViewKeyboardEvent(QKeyEvent *event)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void setVisible(bool visible)
Reimplemented Function
QDir absoluteDir() const
Returns the file&#39;s absolute path as a QDir object.
Definition: qfileinfo.cpp:873
QT_DEPRECATED QStringList filters() const
Use nameFilters() instead.
Q_GUI_EXPORT _qt_filedialog_open_filename_hook qt_filedialog_open_filename_hook
Definition: qfiledialog.cpp:88
QStandardItem * item(int row, int column=0) const
Returns the item for the given row and column if one has been set; otherwise returns 0...
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
virtual void setSourceModel(QAbstractItemModel *sourceModel)
Sets the given sourceModel to be processed by the proxy model.
void keyPressEvent(QKeyEvent *e)
FIXME: this is a hack to avoid propagating key press events to the dialog and from there to the "Ok" ...
#define SLOT(a)
Definition: qobjectdefs.h:226
void selectNameFilter(const QString &filter)
Sets the current file type filter.
QSize sizeHint() const
Returns a suitable size hint for this header.
bool Q_GUI_EXPORT qt_use_native_dialogs
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
bool confirmOverwrite() const
QString fileName() const
Returns the name of the file, excluding the path.
Definition: qfileinfo.cpp:726
virtual void accept()
Hides the modal dialog and sets the result code to Accepted.
Definition: qdialog.cpp:639
void setEditTriggers(EditTriggers triggers)
void beginGroup(const QString &prefix)
Appends prefix to the current group.
Definition: qsettings.cpp:3073
QT_DEPRECATED QString selectedFilter() const
Use selectedNameFilter() instead.
void setResizeMode(ResizeMode mode)
Definition: qlistview.cpp:337
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QStringList history() const
Returns the browsing history of the filedialog as a list of paths.
void _q_autoCompleteFileName(const QString &)
void setDefaultSuffix(const QString &suffix)
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
bool isNameFilterDetailsVisible() const
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
void removeLast()
Removes the last item in the list.
Definition: qlist.h:287
QString absoluteFilePath() const
Returns an absolute path including the file name.
Definition: qfileinfo.cpp:534
#define QT_END_INCLUDE_NAMESPACE
This macro is equivalent to QT_BEGIN_NAMESPACE.
Definition: qglobal.h:92
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool exists() const
Returns true if the file exists; otherwise returns false.
Definition: qfileinfo.cpp:675
void setRootIndex(const QModelIndex &index) const
QString pathFromIndex(const QModelIndex &index) const
Returns the path for the given index.
void pop_front()
This function is provided for STL compatibility.
Definition: qlist.h:302
void init(QFileDialogPrivate *d_pointer)
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
bool resolveSymlinks() const
The QStandardItemModel class provides a generic model for storing custom data.
void setOption(Option option, bool on=true)
Sets the given option to be enabled if on is true; otherwise, clears the given option.
bool restoreState(const QByteArray &state)
Restores the dialogs&#39;s layout, history and current directory to the state specified.
QString(* _qt_filedialog_existing_directory_hook)(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options)
Definition: qfiledialog.cpp:84
void fetchMore(const QModelIndex &parent)
Reimplemented Function
static QString _qt_get_directory(const QString &path)
void _q_deleteCurrent()
Deletes the currently selected item in the dialog.
static bool isRelativePath(const QString &path)
Returns true if path is relative; returns false if it is absolute.
Definition: qdir.cpp:2210
void _q_pathChanged(const QString &)
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
FileMode fileMode() const
The QString class provides a Unicode character string.
Definition: qstring.h:83
QFontMetrics fontMetrics
the font metrics that should be used when drawing text in the control
Definition: qstyleoption.h:91
bool hasFocus() const
Definition: qwidget.cpp:6583
T * qobject_cast(QObject *object)
Definition: qobject.h:375
static QString currentPath()
Returns the absolute path of the application&#39;s current directory.
Definition: qdir.cpp:1875
void keyPressEvent(QKeyEvent *e)
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
void resizeSection(int logicalIndex, int size)
Resizes the section specified by logicalIndex to size measured in pixels.
bool testOption(Option option) const
Returns true if the given option is enabled; otherwise, returns false.
QStringList qt_strip_filters(const QStringList &filters)
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenu.cpp:1453
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
Definition: qwidget.cpp:7596
#define Q_D(Class)
Definition: qglobal.h:2482
const char * qt_file_dialog_filter_reg_exp
static QString workingDirectory(const QString &path)
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
int height() const
QString(* _qt_filedialog_open_filename_hook)(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
Definition: qfiledialog.cpp:87
QStringList splitPath(const QString &path) const
Splits the given path into strings that are used to match at each level in the model().
QStringList(* _qt_filedialog_open_filenames_hook)(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
Definition: qfiledialog.cpp:90
void addAction(QAction *action)
Appends the action action to this widget&#39;s list of actions.
Definition: qwidget.cpp:3317
QFileDialogPrivate * d_ptr
static StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
Opens a warning message box with the given title and text in front of the specified parent widget...
void keyPressEvent(QKeyEvent *event)
Reimplemented Function
Definition: qtreeview.cpp:1984
bool isSectionHidden(int logicalIndex) const
Returns true if the section specified by logicalIndex is explicitly hidden from the user; otherwise r...
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
The QActionGroup class groups actions together.
Definition: qactiongroup.h:57
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
Definition: qvariant.cpp:2383
const char * className
Definition: qwizard.cpp:137
The QFileDialog class provides a dialog that allow users to select files or directories.
Definition: qfiledialog.h:66
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Returns the data for the given role and section in the header with the specified orientation.
void setEnabled(bool)
Definition: qaction.cpp:1192
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags=0) const
If the string text is wider than width, returns an elided version of the string (i.
QStringList qt_clean_filter_list(const QString &filter)
void setHistory(const QStringList &paths)
Sets the browsing history of the filedialog to contain the given paths.
QAbstractItemView * currentView() const
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
The QShortcut class is used to create keyboard shortcuts.
Definition: qshortcut.h:57
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define Q_Q(Class)
Definition: qglobal.h:2483
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
Definition: qfile.cpp:626
~QFileDialog()
Destroys the file dialog.
QWidgetData data
Definition: qwidget_p.h:755
void _q_fileRenamed(const QString &path, const QString oldName, const QString newName)
ViewMode viewMode() const
QWidget * viewport() const
Returns the viewport widget.
void done(int result)
Reimplemented Function
QStringList typedFiles() const
void setFileMode(FileMode mode)
QString qt_win_get_save_file_name(const QFileDialogArgs &args, QString *initialDirectory, QString *selectedFilter)
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index...
void _q_selectionChanged()
This is called when the model index corresponding to the current file is changed from index to curren...
QAction * renameAction
void expanded(const QModelIndex &index)
This signal is emitted when the item specified by index is expanded.
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QModelIndex mkdir(const QModelIndex &parent, const QString &name)
Create a directory with the name in the parent model index.
int width() const
Returns the width.
Definition: qsize.h:126
ViewMode
This enum describes the view mode of the file dialog; i.
Definition: qfiledialog.h:82
void changeEvent(QEvent *e)
Reimplemented Function
void setNameFilters(const QStringList &filters)
Sets the filters used in the file dialog.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QString selectedNameFilter() const
Returns the filter that the user selected in the file dialog.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void selectFile(const QString &filename)
Selects the given filename in the file dialog.
void setNameFilter(const QString &filter)
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
static FILE * stream
static bool isEmpty(const char *str)
int indexIn(const QString &str, int offset=0, CaretMode caretMode=CaretAtZero) const
Attempts to find a match in str from position offset (0 by default).
Definition: qregexp.cpp:4136
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise ret...
Definition: qfileinfo.cpp:990
QString qt_win_get_open_file_name(const QFileDialogArgs &args, QString *initialDirectory, QString *selectedFilter)
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool insertRow(int row, const QModelIndex &parent=QModelIndex())
Inserts a single row before the given row in the child items of the parent specified.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void setNameFilters(const QStringList &filters)
Sets the name filters to apply against the existing files.
int width() const
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
QString text
the line edit&#39;s text
Definition: qlineedit.h:72
void setItemDelegate(QAbstractItemDelegate *delegate)
Sets the item delegate used to render items in the views in the file dialog to the given delegate...
Qt::ItemFlags flags(const QModelIndex &index) const
Reimplemented Function
int row() const
Returns the row this model index refers to.
void emitFilesSelected(const QStringList &files)
void setResolveSymlinks(bool enabled)
const char * name
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
void showPopup()
Displays the list of items in the combobox.
static QDir current()
Returns the application&#39;s current directory.
Definition: qdir.h:209
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isDir(const QModelIndex &index) const
Returns true if the model item index represents a directory; otherwise returns false.
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
void setFile(const QString &file)
Sets the file that the QFileInfo provides information about to file.
Definition: qfileinfo.cpp:468
QWidgetData * data
Definition: qwidget.h:815
QString canonicalFilePath() const
Returns the canonical path including the file name, i.e.
Definition: qfileinfo.cpp:551
bool endsWith(const T &t) const
Returns true if this list is not empty and its last item is equal to value; otherwise returns false...
Definition: qlist.h:289
The QFileIconProvider class provides file icons for the QDirModel and the QFileSystemModel classes...
void setIconProvider(QFileIconProvider *provider)
Sets the icon provider used by the filedialog to the specified provider.
QAction * newFolderAction
void setText(const QString &text)
Definition: qaction.cpp:860
QLineEdit * lineEdit() const
void setTextElideMode(Qt::TextElideMode mode)
QAction * addSeparator()
This convenience function creates a new separator action, i.e.
Definition: qmenu.cpp:1583
QString rootPath() const
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
void removeFirst()
Removes the first item in the list.
Definition: qlist.h:286
void setDragDropMode(DragDropMode behavior)
QModelIndex select(const QModelIndex &index) const
QVariant myComputer(int role=Qt::DisplayRole) const
Returns the data stored under the given role for the item "My Computer".
void setKey(const QKeySequence &key)
Definition: qshortcut.cpp:254
QStringList qt_make_filter_list(const QString &filter)
void setSortingEnabled(bool enable)
Definition: qtreeview.cpp:898
QFileDialog::FileMode fileMode
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
void setRootIsDecorated(bool show)
Definition: qtreeview.cpp:421
void keyPressEvent(QKeyEvent *event)
This function is called with the given event when a key event is sent to the widget.
T value(int i) const
Returns the value at index position i in the list.
Definition: qlist.h:661
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082
QStringList nameFilters
QAction * showHiddenAction
void replace(int i, const T &t)
Replaces the item at index position i with value.
Definition: qlist.h:609
QString toLocalFile() const
Returns the path of this URL formatted as a local file path.
Definition: qurl.cpp:6412
QUrl toUrl() const
Returns the variant as a QUrl if the variant has type() Url ; otherwise returns an invalid QUrl...
Definition: qvariant.cpp:2528
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
int count() const
Definition: qstring.h:103
void setEnabled(bool)
Definition: qwidget.cpp:3447
QFileIconProvider * iconProvider() const
Returns the icon provider used by the filedialog.
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
#define QT_NO_PROXYMODEL
void hide()
Hides the widget.
Definition: qwidget.h:501
QModelIndex mapToSource(const QModelIndex &index) const
The QAbstractItemModel class provides the abstract interface for item model classes.
The QAbstractProxyModel class provides a base class for proxy item models that can do sorting...
void setProxyModel(QAbstractProxyModel *model)
Sets the model for the views to the given proxyModel.
void setExclusive(bool)
void setWrapping(bool enable)
Definition: qlistview.cpp:308
void setAcceptMode(AcceptMode mode)
virtual void done(int)
Closes the dialog and sets its result code to r.
Definition: qdialog.cpp:617
Options options() const
void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events passed in event...
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
QAction * exec()
Executes this menu synchronously.
Definition: qmenu.cpp:2101
void setText(const QString &)
Definition: qlineedit.cpp:401
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
static QStringList getOpenFileNames(QWidget *parent=0, const QString &caption=QString(), const QString &dir=QString(), const QString &filter=QString(), QString *selectedFilter=0, Options options=0)
This is a convenience static function that will return one or more existing files selected by the use...
QString join(const QString &sep) const
Joins all the string list&#39;s strings into a single string with each element separated by the given sep...
Definition: qstringlist.h:162
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
QWidget * parent
void setFocus()
Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its paren...
Definition: qwidget.h:432
Q_GUI_EXPORT _qt_filedialog_save_filename_hook qt_filedialog_save_filename_hook
Definition: qfiledialog.cpp:94
The QAbstractItemView class provides the basic functionality for item view classes.
static QString getExistingDirectory(QWidget *parent=0, const QString &caption=QString(), const QString &dir=QString(), Options options=ShowDirsOnly)
This is a convenience static function that will return an existing directory selected by the user...
static const char *const filters[3]
FileMode
This enum is used to indicate what the user may select in the file dialog; i.
Definition: qfiledialog.h:83
QT_DEPRECATED void selectFilter(const QString &filter)
Use selectNameFilter() instead.
bool qt_priv_ptr_valid
QFileDialog::Options options
void setOptions(Options options)
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
QStringList selectedFiles() const
Returns a list of strings containing the absolute paths of the selected files in the dialog...
The QItemSelection class manages information about selected items in a model.
QAbstractProxyModel * proxyModel() const
Returns the proxy model used by the file dialog.
static Qt::KeyboardModifiers keyboardModifiers()
Returns the current state of the modifier keys on the keyboard.
The QListView class provides a list or icon view onto a model.
Definition: qlistview.h:57
QString & append(QChar c)
Definition: qstring.cpp:1777
The QKeySequence class encapsulates a key sequence as used by shortcuts.
Definition: qkeysequence.h:72
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
QCompleter that can deal with QFileSystemModel.
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
void setChecked(bool)
Definition: qaction.cpp:1138
QFSCompleter * completer
void accept()
Reimplemented Function
void clear()
Clears the contents of the line edit.
Definition: qlineedit.cpp:1443
QStringList qt_win_get_open_file_names(const QFileDialogArgs &args, QString *initialDirectory, QString *selectedFilter)
QFileDialogTreeView(QWidget *parent)
void _q_createDirectory()
Creates a new directory, first asking the user for a suitable name.
QString simplified() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end, and that has each sequence o...
Definition: qstring.cpp:4415
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QFileDialog(QWidget *parent, Qt::WindowFlags f)
Constructs a file dialog with the given parent and widget flags.
StandardButton
These enums describe flags for standard buttons.
virtual void showPopup()
Displays the list of items in the combobox.
Definition: qcombobox.cpp:2447
QAction * deleteAction
QString suffix() const
Returns the suffix of the file.
Definition: qfileinfo.cpp:834
int key
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void _q_navigateToParent()
Navigates to the parent directory of the currently displayed directory in the dialog.
QByteArray suffix
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
QHeaderView * header() const
Returns the header for the tree view.
Definition: qtreeview.cpp:302
The QModelIndex class is used to locate data in a data model.
QStringList nameFilters() const
Returns the file type filters that are in operation on this file dialog.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QT_DEPRECATED void setFilters(const QStringList &filters)
Use setNameFilters() instead.
void setItemsExpandable(bool enable)
Definition: qtreeview.cpp:477
QList< QAction * > actions() const
Returns the (possibly empty) list of this widget&#39;s actions.
Definition: qwidget.cpp:3407
QModelIndex rootIndex() const
The QStyleOptionComboBox class is used to describe the parameter for drawing a combobox.
Definition: qstyleoption.h:796
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior)
void setLabelText(DialogLabel label, const QString &text)
Sets the text shown in the filedialog in the specified label.
QDir rootDirectory() const
The currently set directory.
static QString getOpenFileName(QWidget *parent=0, const QString &caption=QString(), const QString &dir=QString(), const QString &filter=QString(), QString *selectedFilter=0, Options options=0)
This is a convenience static function that returns an existing file selected by the user...
QFileDialogListView(QWidget *parent=0)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QStringList currentHistory
Definition: qnamespace.h:54
void _q_useNameFilter(int index)
Sets the current name filter to be nameFilter and update the qFileDialogUi->fileNameEdit when in Acce...
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
QList< QAction * > actions
Definition: qwidget_p.h:760
void edit(const QModelIndex &index)
Starts editing the item corresponding to the given index if it is editable.
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
bool restoreState(const QByteArray &state)
Restores the state of this header view.
bool isChecked() const
Definition: qaction.cpp:1151
void _q_goToDirectory(const QString &)
Changes the file dialog&#39;s current directory to the one specified by path.
void _q_rowsInserted(const QModelIndex &parent)
When parent is root and rows have been inserted when none was there before then select the first one...
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
QByteArray saveState() const
Saves the state of the dialog&#39;s layout, history and current directory.
quint16 index
QObject * parent
Definition: qobject.h:92
AcceptMode acceptMode() const
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
Definition: qglobal.h:91
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition: qurl.cpp:6374
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget...
Definition: qstylepainter.h:55
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
void setReadOnly(bool enable)
void open()
Shows the dialog as a window modal dialog, returning immediately.
Definition: qdialog.cpp:492
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void _q_goToUrl(const QUrl &url)
static QString toInternal(const QString &path)
void setLastVisitedDirectory(const QString &dir)
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
#define Q_WS_WINCE
Definition: qglobal.h:895
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
void _q_currentChanged(const QModelIndex &index)
void init(const QString &directory=QString(), const QString &nameFilter=QString(), const QString &caption=QString())
QString labelText(DialogLabel label) const
Returns the text shown in the filedialog in the specified label.
bool removeDirectory(const QString &path)
QList< QAction * > actions() const
Returns the list of this groups&#39;s actions.
int maxNameLength(const QString &path)
QString path() const
Returns the path.
Definition: qdir.cpp:605
bool remove(const QModelIndex &index) const
Removes the model item index from the file system model and deletes the corresponding file from the f...
static QString initialSelection(const QString &path)
void drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex &opt)
Use the widget&#39;s style to draw a complex control cc specified by the QStyleOptionComplex option...
Definition: qstylepainter.h:92
void setSortIndicator(int logicalIndex, Qt::SortOrder order)
Sets the sort indicator for the section specified by the given logicalIndex in the direction specifie...
QDir::Filters filter() const
Returns the filter that is used when displaying files.
QString path() const
Returns the file&#39;s path.
Definition: qfileinfo.cpp:615
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
QList< QUrl > sidebarUrls() const
QSize sizeHint() const
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
QFileDialogPrivate * d_ptr
Q_GUI_EXPORT _qt_filedialog_open_filenames_hook qt_filedialog_open_filenames_hook
Definition: qfiledialog.cpp:91
static QString toNativeSeparators(const QString &pathName)
Returns pathName with the &#39;/&#39; separators converted to separators that are appropriate for the underly...
Definition: qdir.cpp:812
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
qint64 qlonglong
Definition: qglobal.h:951
void _q_showHeader(QAction *)
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
void setVisible(bool visible)
Reimplemented Function
Definition: qdialog.cpp:756
QSize sizeHint() const
Reimplemented Function
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static QString fileName(const QString &fileUrl)
QString absolutePath() const
Returns a file&#39;s path absolute path.
Definition: qfileinfo.cpp:577
QString(* _qt_filedialog_save_filename_hook)(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
Definition: qfiledialog.cpp:93
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
void setReadOnly(bool enabled)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void createMenuActions()
Create actions which will be used in the right click.
virtual int sizeHintForRow(int row) const
Returns the height size hint for the specified row or -1 if there is no model.
void init(QFileDialogPrivate *d_pointer)
#define UrlRole
QString getEnvironmentVariable(const QString &string)
#define enabled
void _q_showHidden()
Includes hidden files and directories in the items displayed in the dialog.
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
void setFilter(Filters filter)
Sets the filter used by entryList() and entryInfoList() to filters.
Definition: qdir.cpp:1170
QFileSystemModel * model
#define text
Definition: qobjectdefs.h:80
QScopedPointer< Ui_QFileDialog > qFileDialogUi
int column() const
Returns the column this model index refers to.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58
Option
Some platforms allow the user to set a different icon.
Definition: qfiledialog.h:88
static QString escape(const QString &str)
Returns the string str with every regexp special character escaped with a backslash.
Definition: qregexp.cpp:4392
virtual QModelIndex indexAt(const QPoint &point) const =0
Returns the model index of the item at the viewport coordinates point.
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770
static QString homePath()
Returns the absolute path of the user&#39;s home directory.
Definition: qdir.cpp:1942