26 Q_Q(QQuickFolderDialogImpl);
34 auto openButton = buttonBox->standardButton(QPlatformDialogHelper::Open);
36 qmlWarning(q).nospace() <<
"Can't update Open button's enabled state because it wasn't found";
40 openButton->setEnabled(!selectedFolder.isEmpty() && attached->breadcrumbBar()
41 && !attached->breadcrumbBar()->textField()->isVisible());
53 Q_Q(QQuickFolderDialogImpl);
55 if (!attached || !attached->folderDialogListView())
58 QString newSelectedFolderPath;
59 int newSelectedFolderIndex = 0;
60 const QString newFolderPath = QQmlFile::urlToLocalFileOrQrc(currentFolder);
61 if (!oldFolderPath.isEmpty() && !newFolderPath.isEmpty()) {
67 const int indexOfFolder = oldFolderPath.indexOf(newFolderPath);
68 if (indexOfFolder != -1) {
73 QStringList relativePaths = oldFolderPath.mid(indexOfFolder + newFolderPath.size()).split(QLatin1Char(
'/'), Qt::SkipEmptyParts);
74 newSelectedFolderPath = newFolderPath + QLatin1Char(
'/') + relativePaths.first();
77 const QDir newFolderDir(newFolderPath);
79 if (!newFolderDir.exists()) {
80 qmlWarning(q) <<
"Directory" << newSelectedFolderPath <<
"doesn't exist; can't get a file entry list for it";
84 const QFileInfoList dirs = newFolderDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::DirsFirst);
85 const QFileInfo newSelectedFileInfo(newSelectedFolderPath);
87 newSelectedFolderIndex = dirs.indexOf(newSelectedFileInfo);
91 if (newSelectedFolderPath.isEmpty()) {
98 QDir newFolderDir(newFolderPath);
99 if (newFolderDir.exists()) {
100 const QFileInfoList files = newFolderDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::DirsFirst);
101 if (!files.isEmpty())
102 newSelectedFolderPath = files.first().absoluteFilePath();
106 const bool folderSelected = !newSelectedFolderPath.isEmpty();
107 q->setSelectedFolder(folderSelected ? QUrl::fromLocalFile(newSelectedFolderPath) : QUrl());
113 QSignalBlocker blocker(attached->folderDialogListView());
114 attached->folderDialogListView()->setCurrentIndex(folderSelected ? newSelectedFolderIndex : -1);
116 if (folderSelected) {
117 if (QQuickItem *currentItem = attached->folderDialogListView()->currentItem())
118 currentItem->forceActiveFocus();
161void QQuickFolderDialogImpl::setCurrentFolder(
const QUrl ¤tFolder)
163 qCDebug(lcFolderDialogCurrentFolder) <<
"setCurrentFolder called with" << currentFolder;
164 Q_D(QQuickFolderDialogImpl);
165 if (currentFolder == d->currentFolder)
168 const QString oldFolderPath = QQmlFile::urlToLocalFileOrQrc(d->currentFolder);
170 d->currentFolder = currentFolder;
171 d->updateSelectedFolder(oldFolderPath);
172 emit currentFolderChanged(d->currentFolder);
181void QQuickFolderDialogImpl::setSelectedFolder(
const QUrl &selectedFolder)
183 Q_D(QQuickFolderDialogImpl);
184 qCDebug(lcFolderDialogSelectedFolder).nospace() <<
"setSelectedFolder called with selectedFolder "
185 << selectedFolder <<
" (d->selectedFolder is " << d->selectedFolder <<
")";
186 if (selectedFolder == d->selectedFolder)
189 d->selectedFolder = selectedFolder;
191 emit selectedFolderChanged(selectedFolder);
200void QQuickFolderDialogImpl::setOptions(
const QSharedPointer<QFileDialogOptions> &options)
202 qCDebug(lcFolderDialogOptions).nospace() <<
"setOptions called with:"
203 <<
" acceptMode=" << options->acceptMode()
204 <<
" fileMode=" << options->fileMode()
205 <<
" initialDirectory=" << options->initialDirectory();
207 Q_D(QQuickFolderDialogImpl);
208 d->options = options;
218void QQuickFolderDialogImpl::setAcceptLabel(
const QString &label)
220 Q_D(QQuickFolderDialogImpl);
221 d->acceptLabel = label;
222 QQuickFolderDialogImplAttached *attached = d->attachedOrWarn();
226 auto acceptButton = d->buttonBox->standardButton(QPlatformDialogHelper::Open);
228 qmlWarning(
this).nospace() <<
"Can't set accept label to " << label
229 <<
"; failed to find Open button in DialogButtonBox of " <<
this;
233 acceptButton->setText(!label.isEmpty()
234 ? label : QQuickDialogButtonBoxPrivate::buttonText(QPlatformDialogHelper::Open));
237void QQuickFolderDialogImpl::setRejectLabel(
const QString &label)
239 Q_D(QQuickFolderDialogImpl);
240 d->rejectLabel = label;
244 auto rejectButton = d->buttonBox->standardButton(QPlatformDialogHelper::Cancel);
246 qmlWarning(
this).nospace() <<
"Can't set reject label to " << label
247 <<
"; failed to find Open button in DialogButtonBox of " <<
this;
251 rejectButton->setText(!label.isEmpty()
252 ? label : QQuickDialogButtonBoxPrivate::buttonText(QPlatformDialogHelper::Cancel));
255void QQuickFolderDialogImpl::componentComplete()
257 Q_D(QQuickFolderDialogImpl);
258 QQuickDialog::componentComplete();
264 QQuickFolderDialogImplAttached *attached = d->attachedOrWarn();
268 Q_ASSERT(d->buttonBox);
269 const int buttonCount = d->buttonBox->count();
270 if (buttonCount == 0)
273 QQuickAbstractButton *rightMostButton = qobject_cast<QQuickAbstractButton *>(
274 d->buttonBox->itemAt(buttonCount - 1));
275 if (!rightMostButton) {
276 qmlWarning(
this) <<
"Can't find right-most button in DialogButtonBox";
280 auto keyNavigationAttached = QQuickKeyNavigationAttached::qmlAttachedProperties(rightMostButton);
281 if (!keyNavigationAttached) {
282 qmlWarning(
this) <<
"Can't create attached KeyNavigation object on" << QDebug::toString(rightMostButton);
286 keyNavigationAttached->setTab(attached->breadcrumbBar()->upButton());
289void QQuickFolderDialogImpl::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &data)
291 Q_D(QQuickFolderDialogImpl);
292 QQuickDialog::itemChange(change, data);
294 if (change != QQuickItem::ItemVisibleHasChanged || !isComponentComplete() || !data.boolValue)
297 QQuickFolderDialogImplAttached *attached = d->attachedOrWarn();
301 attached->folderDialogListView()->forceActiveFocus();
343void QQuickFolderDialogImplAttached::setFolderDialogListView(QQuickListView *folderDialogListView)
345 Q_D(QQuickFolderDialogImplAttached);
346 if (folderDialogListView == d->folderDialogListView)
349 d->folderDialogListView = folderDialogListView;
351 QObjectPrivate::connect(d->folderDialogListView, &QQuickListView::currentIndexChanged,
352 d, &QQuickFolderDialogImplAttachedPrivate::folderDialogListViewCurrentIndexChanged);
354 emit folderDialogListViewChanged();
363void QQuickFolderDialogImplAttached::setBreadcrumbBar(QQuickFolderBreadcrumbBar *breadcrumbBar)
365 Q_D(QQuickFolderDialogImplAttached);
366 if (breadcrumbBar == d->breadcrumbBar)
369 d->breadcrumbBar = breadcrumbBar;
370 emit breadcrumbBarChanged();