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 ** |
667 d->renameAction->setEnabled(!ro); |
667 d->renameAction->setEnabled(!ro); |
668 d->deleteAction->setEnabled(!ro); |
668 d->deleteAction->setEnabled(!ro); |
669 } |
669 } |
670 if (changed & HideNameFilterDetails) |
670 if (changed & HideNameFilterDetails) |
671 setNameFilters(d->nameFilters); |
671 setNameFilters(d->nameFilters); |
|
672 |
|
673 if (changed & ShowDirsOnly) |
|
674 setFilter((options & ShowDirsOnly) ? filter() & ~QDir::Files : filter() | QDir::Files); |
672 } |
675 } |
673 |
676 |
674 QFileDialog::Options QFileDialog::options() const |
677 QFileDialog::Options QFileDialog::options() const |
675 { |
678 { |
676 Q_D(const QFileDialog); |
679 Q_D(const QFileDialog); |
993 { |
996 { |
994 return !testOption(HideNameFilterDetails); |
997 return !testOption(HideNameFilterDetails); |
995 } |
998 } |
996 |
999 |
997 |
1000 |
|
1001 /* |
|
1002 Strip the filters by removing the details, e.g. (*.*). |
|
1003 */ |
|
1004 QStringList qt_strip_filters(const QStringList &filters) |
|
1005 { |
|
1006 QStringList strippedFilters; |
|
1007 QRegExp r(QString::fromLatin1(qt_file_dialog_filter_reg_exp)); |
|
1008 for (int i = 0; i < filters.count(); ++i) { |
|
1009 QString filterName; |
|
1010 int index = r.indexIn(filters[i]); |
|
1011 if (index >= 0) |
|
1012 filterName = r.cap(1); |
|
1013 strippedFilters.append(filterName.simplified()); |
|
1014 } |
|
1015 return strippedFilters; |
|
1016 } |
|
1017 |
|
1018 |
998 /*! |
1019 /*! |
999 \since 4.4 |
1020 \since 4.4 |
1000 |
1021 |
1001 Sets the \a filters used in the file dialog. |
1022 Sets the \a filters used in the file dialog. |
1002 |
1023 |
1019 |
1040 |
1020 d->qFileDialogUi->fileTypeCombo->clear(); |
1041 d->qFileDialogUi->fileTypeCombo->clear(); |
1021 if (cleanedFilters.isEmpty()) |
1042 if (cleanedFilters.isEmpty()) |
1022 return; |
1043 return; |
1023 |
1044 |
1024 if (testOption(HideNameFilterDetails)) { |
1045 if (testOption(HideNameFilterDetails)) |
1025 QStringList strippedFilters; |
1046 d->qFileDialogUi->fileTypeCombo->addItems(qt_strip_filters(cleanedFilters)); |
1026 QRegExp r(QString::fromLatin1(qt_file_dialog_filter_reg_exp)); |
1047 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); |
1048 d->qFileDialogUi->fileTypeCombo->addItems(cleanedFilters); |
1037 } |
1049 |
1038 d->_q_useNameFilter(0); |
1050 d->_q_useNameFilter(0); |
1039 } |
1051 } |
1040 |
1052 |
1041 /*! |
1053 /*! |
1042 \obsolete |
1054 \obsolete |
1083 Q_D(QFileDialog); |
1095 Q_D(QFileDialog); |
1084 if (d->nativeDialogInUse) { |
1096 if (d->nativeDialogInUse) { |
1085 d->selectNameFilter_sys(filter); |
1097 d->selectNameFilter_sys(filter); |
1086 return; |
1098 return; |
1087 } |
1099 } |
1088 |
1100 int i; |
1089 int i = d->qFileDialogUi->fileTypeCombo->findText(filter); |
1101 if (testOption(HideNameFilterDetails)) { |
|
1102 i = d->qFileDialogUi->fileTypeCombo->findText(qt_strip_filters(qt_make_filter_list(filter)).first()); |
|
1103 } else { |
|
1104 i = d->qFileDialogUi->fileTypeCombo->findText(filter); |
|
1105 } |
1090 if (i >= 0) { |
1106 if (i >= 0) { |
1091 d->qFileDialogUi->fileTypeCombo->setCurrentIndex(i); |
1107 d->qFileDialogUi->fileTypeCombo->setCurrentIndex(i); |
1092 d->_q_useNameFilter(d->qFileDialogUi->fileTypeCombo->currentIndex()); |
1108 d->_q_useNameFilter(d->qFileDialogUi->fileTypeCombo->currentIndex()); |
1093 } |
1109 } |
1094 } |
1110 } |
1204 \sa FileMode |
1220 \sa FileMode |
1205 */ |
1221 */ |
1206 void QFileDialog::setFileMode(QFileDialog::FileMode mode) |
1222 void QFileDialog::setFileMode(QFileDialog::FileMode mode) |
1207 { |
1223 { |
1208 Q_D(QFileDialog); |
1224 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; |
1225 d->fileMode = mode; |
1216 d->retranslateWindowTitle(); |
1226 d->retranslateWindowTitle(); |
1217 |
1227 |
1218 // keep ShowDirsOnly option in sync with fileMode (BTW, DirectoryOnly is obsolete) |
1228 // keep ShowDirsOnly option in sync with fileMode (BTW, DirectoryOnly is obsolete) |
1219 setOption(ShowDirsOnly, mode == DirectoryOnly); |
1229 setOption(ShowDirsOnly, mode == DirectoryOnly); |
1245 setLabelText(FileName, tr("File &name:")); |
1255 setLabelText(FileName, tr("File &name:")); |
1246 d->fileNameLabelExplicitlySat = false; |
1256 d->fileNameLabelExplicitlySat = false; |
1247 } |
1257 } |
1248 } |
1258 } |
1249 setLabelText(Accept, buttonText); |
1259 setLabelText(Accept, buttonText); |
|
1260 if (d->nativeDialogInUse){ |
|
1261 d->setFilter_sys(); |
|
1262 return; |
|
1263 } |
|
1264 |
1250 d->qFileDialogUi->fileTypeCombo->setEnabled(!testOption(ShowDirsOnly)); |
1265 d->qFileDialogUi->fileTypeCombo->setEnabled(!testOption(ShowDirsOnly)); |
1251 d->_q_updateOkButton(); |
1266 d->_q_updateOkButton(); |
1252 } |
1267 } |
1253 |
1268 |
1254 QFileDialog::FileMode QFileDialog::fileMode() const |
1269 QFileDialog::FileMode QFileDialog::fileMode() const |
1282 setLabelText(Accept, (mode == AcceptOpen ? tr("&Open") : tr("&Save"))); |
1297 setLabelText(Accept, (mode == AcceptOpen ? tr("&Open") : tr("&Save"))); |
1283 if (mode == AcceptSave) { |
1298 if (mode == AcceptSave) { |
1284 d->qFileDialogUi->lookInCombo->setEditable(false); |
1299 d->qFileDialogUi->lookInCombo->setEditable(false); |
1285 } |
1300 } |
1286 d->retranslateWindowTitle(); |
1301 d->retranslateWindowTitle(); |
|
1302 #if defined(Q_WS_MAC) |
|
1303 d->deleteNativeDialog_sys(); |
|
1304 setAttribute(Qt::WA_DontShowOnScreen, false); |
|
1305 #endif |
1287 } |
1306 } |
1288 |
1307 |
1289 /* |
1308 /* |
1290 Returns the file system model index that is the root index in the |
1309 Returns the file system model index that is the root index in the |
1291 views |
1310 views |
3227 else |
3246 else |
3228 dirModel = sourceModel; |
3247 dirModel = sourceModel; |
3229 QString currentLocation = dirModel->rootPath(); |
3248 QString currentLocation = dirModel->rootPath(); |
3230 QString path = index.data(QFileSystemModel::FilePathRole).toString(); |
3249 QString path = index.data(QFileSystemModel::FilePathRole).toString(); |
3231 if (!currentLocation.isEmpty() && path.startsWith(currentLocation)) { |
3250 if (!currentLocation.isEmpty() && path.startsWith(currentLocation)) { |
|
3251 #if defined(Q_OS_UNIX) || defined(Q_OS_WINCE) |
|
3252 if (currentLocation == QDir::separator()) |
|
3253 return path.mid(currentLocation.length()); |
|
3254 #endif |
3232 return path.mid(currentLocation.length() + 1); |
3255 return path.mid(currentLocation.length() + 1); |
3233 } |
3256 } |
3234 return index.data(QFileSystemModel::FilePathRole).toString(); |
3257 return index.data(QFileSystemModel::FilePathRole).toString(); |
3235 } |
3258 } |
3236 |
3259 |
3282 if (proxyModel) |
3305 if (proxyModel) |
3283 dirModel = qobject_cast<const QFileSystemModel *>(proxyModel->sourceModel()); |
3306 dirModel = qobject_cast<const QFileSystemModel *>(proxyModel->sourceModel()); |
3284 else |
3307 else |
3285 dirModel = sourceModel; |
3308 dirModel = sourceModel; |
3286 QString currentLocation = QDir::toNativeSeparators(dirModel->rootPath()); |
3309 QString currentLocation = QDir::toNativeSeparators(dirModel->rootPath()); |
|
3310 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) |
|
3311 if (currentLocation.endsWith(QLatin1Char(':'))) |
|
3312 currentLocation.append(sep); |
|
3313 #endif |
3287 if (currentLocation.contains(sep) && path != currentLocation) { |
3314 if (currentLocation.contains(sep) && path != currentLocation) { |
3288 QStringList currentLocationList = splitPath(currentLocation); |
3315 QStringList currentLocationList = splitPath(currentLocation); |
3289 while (!currentLocationList.isEmpty() |
3316 while (!currentLocationList.isEmpty() |
3290 && parts.count() > 0 |
3317 && parts.count() > 0 |
3291 && parts.at(0) == QLatin1String("..")) { |
3318 && parts.at(0) == QLatin1String("..")) { |