+void DolphinViewContainer::connectUrlNavigator(DolphinUrlNavigator *urlNavigator)
+{
+ Q_CHECK_PTR(urlNavigator);
+ Q_ASSERT(!m_urlNavigatorConnected);
+ Q_ASSERT(m_urlNavigator.get() != urlNavigator);
+ Q_CHECK_PTR(m_view);
+
+ urlNavigator->setLocationUrl(m_view->url());
+ urlNavigator->setShowHiddenFolders(m_view->hiddenFilesShown());
+ urlNavigator->setSortHiddenFoldersLast(m_view->sortHiddenLast());
+ if (m_urlNavigatorVisualState) {
+ urlNavigator->setVisualState(*m_urlNavigatorVisualState.get());
+ m_urlNavigatorVisualState.reset();
+ }
+ urlNavigator->setActive(isActive());
+
+ // Url changes are still done via m_urlNavigator.
+ connect(urlNavigator, &DolphinUrlNavigator::urlChanged, m_urlNavigator.get(), &DolphinUrlNavigator::setLocationUrl);
+ 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());
+
+ m_urlNavigatorConnected = urlNavigator;
+}
+
+void DolphinViewContainer::disconnectUrlNavigator()
+{
+ if (!m_urlNavigatorConnected) {
+ return;
+ }
+
+ disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::urlChanged, m_urlNavigator.get(), &DolphinUrlNavigator::setLocationUrl);
+ 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;
+}
+
+void DolphinViewContainer::setSearchBarVisible(bool visible)
+{
+ if (!visible) {
+ if (isSearchBarVisible()) {
+ m_searchBar->setVisible(false, WithAnimation);
+ }
+ return;
+ }
+
+ if (!m_searchBar) {
+ m_searchBar = new Search::Bar(std::make_shared<const Search::DolphinQuery>(m_urlNavigator->locationUrl(), QUrl{} /** will be set below. */), this);
+ connect(m_searchBar, &Search::Bar::urlChangeRequested, this, [this](const QUrl &url) {
+ m_view->setViewPropertiesContext(isSearchUrl(url) ? QStringLiteral("search") : QString());
+ setGrabFocusOnUrlChange(false); // Prevent loss of focus while typing or refining a search.
+ setUrl(url);
+ setGrabFocusOnUrlChange(true);
+ });
+ connect(m_searchBar, &Search::Bar::focusViewRequest, this, &DolphinViewContainer::requestFocus);
+ connect(m_searchBar, &Search::Bar::showMessage, this, [this](const QString &message, KMessageWidget::MessageType messageType) {
+ showMessage(message, messageType);
+ });
+ connect(m_searchBar,
+ &Search::Bar::showInstallationProgress,
+ m_statusBar,
+ [this](const QString ¤tlyRunningTaskTitle, int installationProgressPercent) {
+ m_statusBar->showProgress(currentlyRunningTaskTitle, installationProgressPercent, DolphinStatusBar::CancelLoading::Disallowed);
+ });
+ connect(m_searchBar, &Search::Bar::visibilityChanged, this, &DolphinViewContainer::searchBarVisibilityChanged);
+ m_topLayout->addWidget(m_searchBar, positionFor.searchBar, 0);
+ }
+
+ m_searchBar->setVisible(true, WithAnimation);
+
+ // The Search::Bar has been set visible but its state does not yet match with this view container or view.
+ // The view might for example already be searching because it was opened with a search URL. The Search::Bar needs to be updated to show the parameters of
+ // that search. And even if there is no search URL loaded in the view currently, we still need to figure out where the Search::Bar should be searching if
+ // the user starts a search from there. Let's figure out the search location in this method and let the DolphinQuery constructor figure out the rest from
+ // the current m_urlNavigator->locationUrl().
+ for (int i = m_urlNavigator->historyIndex(); i < m_urlNavigator->historySize(); i++) {
+ QUrl url = m_urlNavigator->locationUrl(i);
+ if (isSearchUrl(url)) {
+ // The previous location was a search URL. Try to see if that search URL has a valid search path so we keep searching in the same location.
+ const auto searchPath = Search::DolphinQuery(url, QUrl{}).searchPath(); // DolphinQuery is great at extracting the search path from a search URL.
+ if (searchPath.isValid()) {
+ m_searchBar->updateStateToMatch(std::make_shared<const Search::DolphinQuery>(m_urlNavigator->locationUrl(), searchPath));
+ return;
+ }
+ } else if (url.scheme() == QLatin1String("tags")) {
+ continue; // We avoid setting a tags url as the backup search path because a DolphinQuery constructed from a tags url will already search tagged
+ // items everywhere.
+ } else {
+ m_searchBar->updateStateToMatch(std::make_shared<const Search::DolphinQuery>(m_urlNavigator->locationUrl(), url));
+ return;
+ }
+ }
+ // We could not find any URL fit for searching in the history. This might happen because this view only ever loaded a search which searches "Everywhere"
+ // and therefore there is no specific search path to choose from. But the Search::Bar *needs* to know a search path because the user might switch from
+ // searching "Everywhere" to "Here" and it is everybody's guess what "Here" is supposed to mean in that context… We'll simply fall back to the user's home
+ // path for lack of a better option.
+ m_searchBar->updateStateToMatch(std::make_shared<const Search::DolphinQuery>(m_urlNavigator->locationUrl(), QUrl::fromUserInput(QDir::homePath())));
+}
+
+bool DolphinViewContainer::isSearchBarVisible() const
+{
+ return m_searchBar && m_searchBar->isVisible() && m_searchBar->isEnabled();
+}
+
+void DolphinViewContainer::setFocusToSearchBar()
+{
+ Q_ASSERT(isSearchBarVisible());
+ m_searchBar->selectAll();
+}
+
+void DolphinViewContainer::setSelectionModeEnabled(bool enabled, KActionCollection *actionCollection, SelectionMode::BottomBar::Contents bottomBarContents)