equal
deleted
inserted
replaced
1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the QtGui module of the Qt Toolkit. |
7 ** This file is part of the QtGui module of the Qt Toolkit. |
8 ** |
8 ** |
227 of QFileDialog that contains the Q_OBJECT macro. |
227 of QFileDialog that contains the Q_OBJECT macro. |
228 |
228 |
229 \value ReadOnly Indicates that the model is readonly. |
229 \value ReadOnly Indicates that the model is readonly. |
230 |
230 |
231 \value HideNameFilterDetails Indicates if the is hidden or not. |
231 \value HideNameFilterDetails Indicates if the is hidden or not. |
232 This value is obsolete and does nothing since Qt 4.5: |
|
233 |
232 |
234 \value DontUseSheet In previous versions of Qt, the static |
233 \value DontUseSheet In previous versions of Qt, the static |
235 functions would create a sheet by default if the static function |
234 functions would create a sheet by default if the static function |
236 was given a parent. This is no longer supported in Qt 4.5, The |
235 was given a parent. This is no longer supported and does nothing in Qt 4.5, The |
237 static functions will always be an application modal dialog. If |
236 static functions will always be an application modal dialog. If |
238 you want to use sheets, use QFileDialog::open() instead. |
237 you want to use sheets, use QFileDialog::open() instead. |
239 |
238 |
240 */ |
239 */ |
241 |
240 |
667 d->renameAction->setEnabled(!ro); |
666 d->renameAction->setEnabled(!ro); |
668 d->deleteAction->setEnabled(!ro); |
667 d->deleteAction->setEnabled(!ro); |
669 } |
668 } |
670 if (changed & HideNameFilterDetails) |
669 if (changed & HideNameFilterDetails) |
671 setNameFilters(d->nameFilters); |
670 setNameFilters(d->nameFilters); |
|
671 |
|
672 if (changed & ShowDirsOnly) |
|
673 setFilter((options & ShowDirsOnly) ? filter() & ~QDir::Files : filter() | QDir::Files); |
672 } |
674 } |
673 |
675 |
674 QFileDialog::Options QFileDialog::options() const |
676 QFileDialog::Options QFileDialog::options() const |
675 { |
677 { |
676 Q_D(const QFileDialog); |
678 Q_D(const QFileDialog); |
993 { |
995 { |
994 return !testOption(HideNameFilterDetails); |
996 return !testOption(HideNameFilterDetails); |
995 } |
997 } |
996 |
998 |
997 |
999 |
|
1000 /* |
|
1001 Strip the filters by removing the details, e.g. (*.*). |
|
1002 */ |
|
1003 QStringList qt_strip_filters(const QStringList &filters) |
|
1004 { |
|
1005 QStringList strippedFilters; |
|
1006 QRegExp r(QString::fromLatin1(qt_file_dialog_filter_reg_exp)); |
|
1007 for (int i = 0; i < filters.count(); ++i) { |
|
1008 QString filterName; |
|
1009 int index = r.indexIn(filters[i]); |
|
1010 if (index >= 0) |
|
1011 filterName = r.cap(1); |
|
1012 strippedFilters.append(filterName.simplified()); |
|
1013 } |
|
1014 return strippedFilters; |
|
1015 } |
|
1016 |
|
1017 |
998 /*! |
1018 /*! |
999 \since 4.4 |
1019 \since 4.4 |
1000 |
1020 |
1001 Sets the \a filters used in the file dialog. |
1021 Sets the \a filters used in the file dialog. |
1002 |
1022 |
1019 |
1039 |
1020 d->qFileDialogUi->fileTypeCombo->clear(); |
1040 d->qFileDialogUi->fileTypeCombo->clear(); |
1021 if (cleanedFilters.isEmpty()) |
1041 if (cleanedFilters.isEmpty()) |
1022 return; |
1042 return; |
1023 |
1043 |
1024 if (testOption(HideNameFilterDetails)) { |
1044 if (testOption(HideNameFilterDetails)) |
1025 QStringList strippedFilters; |
1045 d->qFileDialogUi->fileTypeCombo->addItems(qt_strip_filters(cleanedFilters)); |
1026 QRegExp r(QString::fromLatin1(qt_file_dialog_filter_reg_exp)); |
1046 else |
1027 for (int i = 0; i < cleanedFilters.count(); ++i) { |
|
1028 QString filterName; |
|
1029 int index = r.indexIn(cleanedFilters[i]); |
|
1030 if (index >= 0) |
|
1031 filterName = r.cap(1); |
|
1032 strippedFilters.append(filterName.simplified()); |
|
1033 } |
|
1034 d->qFileDialogUi->fileTypeCombo->addItems(strippedFilters); |
|
1035 } else { |
|
1036 d->qFileDialogUi->fileTypeCombo->addItems(cleanedFilters); |
1047 d->qFileDialogUi->fileTypeCombo->addItems(cleanedFilters); |
1037 } |
1048 |
1038 d->_q_useNameFilter(0); |
1049 d->_q_useNameFilter(0); |
1039 } |
1050 } |
1040 |
1051 |
1041 /*! |
1052 /*! |
1042 \obsolete |
1053 \obsolete |
1083 Q_D(QFileDialog); |
1094 Q_D(QFileDialog); |
1084 if (d->nativeDialogInUse) { |
1095 if (d->nativeDialogInUse) { |
1085 d->selectNameFilter_sys(filter); |
1096 d->selectNameFilter_sys(filter); |
1086 return; |
1097 return; |
1087 } |
1098 } |
1088 |
1099 int i; |
1089 int i = d->qFileDialogUi->fileTypeCombo->findText(filter); |
1100 if (testOption(HideNameFilterDetails)) { |
|
1101 i = d->qFileDialogUi->fileTypeCombo->findText(qt_strip_filters(qt_make_filter_list(filter)).first()); |
|
1102 } else { |
|
1103 i = d->qFileDialogUi->fileTypeCombo->findText(filter); |
|
1104 } |
1090 if (i >= 0) { |
1105 if (i >= 0) { |
1091 d->qFileDialogUi->fileTypeCombo->setCurrentIndex(i); |
1106 d->qFileDialogUi->fileTypeCombo->setCurrentIndex(i); |
1092 d->_q_useNameFilter(d->qFileDialogUi->fileTypeCombo->currentIndex()); |
1107 d->_q_useNameFilter(d->qFileDialogUi->fileTypeCombo->currentIndex()); |
1093 } |
1108 } |
1094 } |
1109 } |
1204 \sa FileMode |
1219 \sa FileMode |
1205 */ |
1220 */ |
1206 void QFileDialog::setFileMode(QFileDialog::FileMode mode) |
1221 void QFileDialog::setFileMode(QFileDialog::FileMode mode) |
1207 { |
1222 { |
1208 Q_D(QFileDialog); |
1223 Q_D(QFileDialog); |
1209 if (d->nativeDialogInUse){ |
|
1210 d->model->setFilter(d->filterForMode(filter())); |
|
1211 d->setFilter_sys(); |
|
1212 return; |
|
1213 } |
|
1214 |
|
1215 d->fileMode = mode; |
1224 d->fileMode = mode; |
1216 d->retranslateWindowTitle(); |
1225 d->retranslateWindowTitle(); |
1217 |
1226 |
1218 // keep ShowDirsOnly option in sync with fileMode (BTW, DirectoryOnly is obsolete) |
1227 // keep ShowDirsOnly option in sync with fileMode (BTW, DirectoryOnly is obsolete) |
1219 setOption(ShowDirsOnly, mode == DirectoryOnly); |
1228 setOption(ShowDirsOnly, mode == DirectoryOnly); |
1245 setLabelText(FileName, tr("File &name:")); |
1254 setLabelText(FileName, tr("File &name:")); |
1246 d->fileNameLabelExplicitlySat = false; |
1255 d->fileNameLabelExplicitlySat = false; |
1247 } |
1256 } |
1248 } |
1257 } |
1249 setLabelText(Accept, buttonText); |
1258 setLabelText(Accept, buttonText); |
|
1259 if (d->nativeDialogInUse){ |
|
1260 d->setFilter_sys(); |
|
1261 return; |
|
1262 } |
|
1263 |
1250 d->qFileDialogUi->fileTypeCombo->setEnabled(!testOption(ShowDirsOnly)); |
1264 d->qFileDialogUi->fileTypeCombo->setEnabled(!testOption(ShowDirsOnly)); |
1251 d->_q_updateOkButton(); |
1265 d->_q_updateOkButton(); |
1252 } |
1266 } |
1253 |
1267 |
1254 QFileDialog::FileMode QFileDialog::fileMode() const |
1268 QFileDialog::FileMode QFileDialog::fileMode() const |
1282 setLabelText(Accept, (mode == AcceptOpen ? tr("&Open") : tr("&Save"))); |
1296 setLabelText(Accept, (mode == AcceptOpen ? tr("&Open") : tr("&Save"))); |
1283 if (mode == AcceptSave) { |
1297 if (mode == AcceptSave) { |
1284 d->qFileDialogUi->lookInCombo->setEditable(false); |
1298 d->qFileDialogUi->lookInCombo->setEditable(false); |
1285 } |
1299 } |
1286 d->retranslateWindowTitle(); |
1300 d->retranslateWindowTitle(); |
|
1301 #if defined(Q_WS_MAC) |
|
1302 d->deleteNativeDialog_sys(); |
|
1303 setAttribute(Qt::WA_DontShowOnScreen, false); |
|
1304 #endif |
1287 } |
1305 } |
1288 |
1306 |
1289 /* |
1307 /* |
1290 Returns the file system model index that is the root index in the |
1308 Returns the file system model index that is the root index in the |
1291 views |
1309 views |
3227 else |
3245 else |
3228 dirModel = sourceModel; |
3246 dirModel = sourceModel; |
3229 QString currentLocation = dirModel->rootPath(); |
3247 QString currentLocation = dirModel->rootPath(); |
3230 QString path = index.data(QFileSystemModel::FilePathRole).toString(); |
3248 QString path = index.data(QFileSystemModel::FilePathRole).toString(); |
3231 if (!currentLocation.isEmpty() && path.startsWith(currentLocation)) { |
3249 if (!currentLocation.isEmpty() && path.startsWith(currentLocation)) { |
|
3250 #if defined(Q_OS_UNIX) || defined(Q_OS_WINCE) |
|
3251 if (currentLocation == QDir::separator()) |
|
3252 return path.mid(currentLocation.length()); |
|
3253 #endif |
3232 return path.mid(currentLocation.length() + 1); |
3254 return path.mid(currentLocation.length() + 1); |
3233 } |
3255 } |
3234 return index.data(QFileSystemModel::FilePathRole).toString(); |
3256 return index.data(QFileSystemModel::FilePathRole).toString(); |
3235 } |
3257 } |
3236 |
3258 |
3282 if (proxyModel) |
3304 if (proxyModel) |
3283 dirModel = qobject_cast<const QFileSystemModel *>(proxyModel->sourceModel()); |
3305 dirModel = qobject_cast<const QFileSystemModel *>(proxyModel->sourceModel()); |
3284 else |
3306 else |
3285 dirModel = sourceModel; |
3307 dirModel = sourceModel; |
3286 QString currentLocation = QDir::toNativeSeparators(dirModel->rootPath()); |
3308 QString currentLocation = QDir::toNativeSeparators(dirModel->rootPath()); |
|
3309 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) |
|
3310 if (currentLocation.endsWith(QLatin1Char(':'))) |
|
3311 currentLocation.append(sep); |
|
3312 #endif |
3287 if (currentLocation.contains(sep) && path != currentLocation) { |
3313 if (currentLocation.contains(sep) && path != currentLocation) { |
3288 QStringList currentLocationList = splitPath(currentLocation); |
3314 QStringList currentLocationList = splitPath(currentLocation); |
3289 while (!currentLocationList.isEmpty() |
3315 while (!currentLocationList.isEmpty() |
3290 && parts.count() > 0 |
3316 && parts.count() > 0 |
3291 && parts.at(0) == QLatin1String("..")) { |
3317 && parts.at(0) == QLatin1String("..")) { |