X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/6e6fcf8da80b5b6821837054ae51eaa19edc24b8..7e10da6e2e0171fa30a1162e5767be2b95937c21:/src/dolphinviewcontainer.cpp diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 3fedef6fc..f2df638f6 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -33,6 +33,9 @@ #include #include +#ifndef QT_NO_ACCESSIBILITY +#include +#endif #include #include #include @@ -41,6 +44,7 @@ #include #include #include +#include // An overview of the widgets contained by this ViewContainer struct LayoutStructure { @@ -299,12 +303,15 @@ void DolphinViewContainer::connectUrlNavigator(DolphinUrlNavigator *urlNavigator // Url changes are still done via m_urlNavigator. connect(urlNavigator, &DolphinUrlNavigator::urlChanged, m_urlNavigator.get(), &DolphinUrlNavigator::setLocationUrl); - connect(urlNavigator, &DolphinUrlNavigator::urlsDropped, this, [=](const QUrl &destination, QDropEvent *event) { + connect(urlNavigator, &DolphinUrlNavigator::urlsDropped, this, [=, this](const QUrl &destination, QDropEvent *event) { m_view->dropUrls(destination, event, urlNavigator->dropWidget()); }); // Aside from these, only visual things need to be connected. connect(m_view, &DolphinView::urlChanged, urlNavigator, &DolphinUrlNavigator::setLocationUrl); connect(urlNavigator, &DolphinUrlNavigator::activated, this, &DolphinViewContainer::activate); + connect(urlNavigator, &DolphinUrlNavigator::requestToLoseFocus, m_view, [this]() { + m_view->setFocus(); + }); urlNavigator->setReadOnlyBadgeVisible(rootItem().isLocalFile() && !rootItem().isWritable()); @@ -321,6 +328,7 @@ void DolphinViewContainer::disconnectUrlNavigator() disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::urlsDropped, this, nullptr); disconnect(m_view, &DolphinView::urlChanged, m_urlNavigatorConnected, &DolphinUrlNavigator::setLocationUrl); disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::activated, this, &DolphinViewContainer::activate); + disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::requestToLoseFocus, m_view, nullptr); m_urlNavigatorVisualState = m_urlNavigatorConnected->visualState(); m_urlNavigatorConnected = nullptr; @@ -435,6 +443,14 @@ void DolphinViewContainer::showMessage(const QString &message, KMessageWidget::M m_messageWidget->hide(); } m_messageWidget->animatedShow(); + +#ifndef QT_NO_ACCESSIBILITY + if (QAccessible::isActive() && isActive()) { + // To announce the new message keyboard focus must be moved to the message label. However, we do not have direct access to the label that is internal + // to the KMessageWidget. Instead we setFocus() on the KMessageWidget and trust that it has set correct focus handling. + m_messageWidget->setFocus(); + } +#endif } void DolphinViewContainer::readSettings() @@ -481,7 +497,9 @@ void DolphinViewContainer::setSearchModeEnabled(bool enabled) if (url.isEmpty() || !url.isValid() || isSearchUrl(url)) { url = Dolphin::homeUrl(); } - m_urlNavigatorConnected->setLocationUrl(url); + if (m_urlNavigatorConnected) { + m_urlNavigatorConnected->setLocationUrl(url); + } } m_searchModeEnabled = enabled; @@ -533,6 +551,15 @@ QString DolphinViewContainer::captionWindowTitle() const QString DolphinViewContainer::caption() const { + // see KUrlNavigatorPrivate::firstButtonText(). + if (url().path().isEmpty() || url().path() == QLatin1Char('/')) { + QUrlQuery query(url()); + const QString title = query.queryItemValue(QStringLiteral("title")); + if (!title.isEmpty()) { + return title; + } + } + if (isSearchModeEnabled()) { if (currentSearchText().isEmpty()) { return i18n("Search"); @@ -542,12 +569,11 @@ QString DolphinViewContainer::caption() const } KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel(); - const QString pattern = url().adjusted(QUrl::StripTrailingSlash).toString(QUrl::FullyEncoded).append("/?"); - const auto &matchedPlaces = - placesModel->match(placesModel->index(0, 0), KFilePlacesModel::UrlRole, QRegularExpression::anchoredPattern(pattern), 1, Qt::MatchRegularExpression); - if (!matchedPlaces.isEmpty()) { - return placesModel->text(matchedPlaces.first()); + QModelIndex url_index = placesModel->closestItem(url()); + + if (url_index.isValid() && placesModel->url(url_index).matches(url(), QUrl::StripTrailingSlash)) { + return placesModel->text(url_index); } if (!url().isLocalFile()) { @@ -741,6 +767,18 @@ void DolphinViewContainer::slotfileMiddleClickActivated(const KFileItem &item) job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this)); connect(job, &KIO::OpenUrlJob::finished, this, &DolphinViewContainer::slotOpenUrlFinished); job->start(); + } else { + // If no 2nd service available, try to open archives in new tabs, regardless of the "Open archives as folder" setting. + const QUrl &url = DolphinView::openItemAsFolderUrl(item); + const auto modifiers = QGuiApplication::keyboardModifiers(); + if (!url.isEmpty()) { + // keep in sync with KUrlNavigator::slotNavigatorButtonClicked + if (modifiers & Qt::ShiftModifier) { + Q_EMIT activeTabRequested(url); + } else { + Q_EMIT tabRequested(url); + } + } } } @@ -858,6 +896,9 @@ void DolphinViewContainer::redirect(const QUrl &oldUrl, const QUrl &newUrl) // URL history. m_urlNavigator->saveLocationState(QByteArray()); m_urlNavigator->setLocationUrl(newUrl); + if (m_searchBox->isActive()) { + m_searchBox->setSearchPath(newUrl); + } setSearchModeEnabled(isSearchUrl(newUrl)); m_urlNavigator->blockSignals(block); @@ -954,10 +995,13 @@ void DolphinViewContainer::slotCurrentDirectoryRemoved() const QString dirPath = url().toLocalFile(); const QString newPath = getNearestExistingAncestorOfPath(dirPath); const QUrl newUrl = QUrl::fromLocalFile(newPath); - setUrl(newUrl); - } - - showMessage(xi18n("Current location changed, %1 is no longer accessible.", location), KMessageWidget::Warning); + // #473377: Delay changing the url to avoid modifying KCoreDirLister before KCoreDirListerCache::deleteDir() returns. + QTimer::singleShot(0, this, [&, newUrl, location] { + setUrl(newUrl); + showMessage(xi18n("Current location changed, %1 is no longer accessible.", location), KMessageWidget::Warning); + }); + } else + showMessage(xi18n("Current location changed, %1 is no longer accessible.", location), KMessageWidget::Warning); } void DolphinViewContainer::slotOpenUrlFinished(KJob *job)