diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -412,10 +412,9 @@ void tabCountChanged(int count); /** - * Sets the window caption to url.fileName() if this is non-empty, - * "/" if the URL is "file:///", and url.protocol() otherwise. + * Updates the Window Title with the caption from the active view container */ - void setUrlAsCaption(const QUrl& url); + void updateWindowTitle(); /** * This slot is called when the user requested to unmount a removable media diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -25,7 +25,6 @@ #include "dolphindockwidget.h" #include "dolphincontextmenu.h" #include "dolphinnewfilemenu.h" -#include "dolphinplacesmodelsingleton.h" #include "dolphinrecenttabsmenu.h" #include "dolphintabwidget.h" #include "dolphinviewcontainer.h" @@ -49,7 +48,6 @@ #include #include #include -#include #include #include #include @@ -137,7 +135,7 @@ connect(m_tabWidget, &DolphinTabWidget::tabCountChanged, this, &DolphinMainWindow::tabCountChanged); connect(m_tabWidget, &DolphinTabWidget::currentUrlChanged, - this, &DolphinMainWindow::setUrlAsCaption); + this, &DolphinMainWindow::updateWindowTitle); setCentralWidget(m_tabWidget); setupActions(); @@ -1001,46 +999,9 @@ actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions); } -void DolphinMainWindow::setUrlAsCaption(const QUrl& url) +void DolphinMainWindow::updateWindowTitle() { - QString schemePrefix; - if (!url.isLocalFile()) { - schemePrefix.append(url.scheme() + " - "); - if (!url.host().isEmpty()) { - schemePrefix.append(url.host() + " - "); - } - } - - if (GeneralSettings::showFullPathInTitlebar()) { - const QString path = url.adjusted(QUrl::StripTrailingSlash).path(); - setWindowTitle(schemePrefix + path); - return; - } - - KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel(); - const auto& matchedPlaces = placesModel->match(placesModel->index(0,0), KFilePlacesModel::UrlRole, url, 1, Qt::MatchExactly); - - if (!matchedPlaces.isEmpty()) { - setWindowTitle(placesModel->text(matchedPlaces.first())); - return; - } - - QString fileName = url.adjusted(QUrl::StripTrailingSlash).fileName(); - if (fileName.isEmpty()) { - fileName = '/'; - } - - if (m_activeViewContainer->isSearchModeEnabled()) { - if(m_activeViewContainer->currentSearchText().isEmpty()){ - setWindowTitle(i18n("Search")); - } else { - const auto searchText = i18n("Search for %1", m_activeViewContainer->currentSearchText()); - setWindowTitle(searchText); - } - return; - } - - setWindowTitle(schemePrefix + fileName); + setWindowTitle(m_activeViewContainer->getCaption()); } void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath) @@ -1501,7 +1462,7 @@ const bool splitView = GeneralSettings::splitView(); m_tabWidget->currentTabPage()->setSplitViewEnabled(splitView); updateSplitAction(); - setUrlAsCaption(activeViewContainer()->url()); + updateWindowTitle(); } emit settingsChanged(); diff --git a/src/dolphintabwidget.h b/src/dolphintabwidget.h --- a/src/dolphintabwidget.h +++ b/src/dolphintabwidget.h @@ -193,7 +193,7 @@ /** * Returns the name of the tab for the URL \a url. */ - QString tabName(const QUrl& url) const; + QString tabName() const; private: /** Caches the (negated) places panel visibility */ diff --git a/src/dolphintabwidget.cpp b/src/dolphintabwidget.cpp --- a/src/dolphintabwidget.cpp +++ b/src/dolphintabwidget.cpp @@ -116,6 +116,7 @@ { const int tabCount = count(); for (int i = 0; i < tabCount; ++i) { + tabBar()->setTabText(i, tabName()); tabPageAt(i)->refreshViews(); } } @@ -160,7 +161,7 @@ this, &DolphinTabWidget::activeViewChanged); connect(tabPage, &DolphinTabPage::activeViewUrlChanged, this, &DolphinTabWidget::tabUrlChanged); - addTab(tabPage, QIcon::fromTheme(KIO::iconNameForUrl(primaryUrl)), tabName(primaryUrl)); + addTab(tabPage, QIcon::fromTheme(KIO::iconNameForUrl(primaryUrl)), tabName()); if (focusWidget) { // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened @@ -305,7 +306,7 @@ { const int index = indexOf(qobject_cast(sender())); if (index >= 0) { - tabBar()->setTabText(index, tabName(url)); + tabBar()->setTabText(index, tabName()); tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(url))); // Emit the currentUrlChanged signal if the url of the current tab has been changed. @@ -353,20 +354,13 @@ emit tabCountChanged(count()); } -QString DolphinTabWidget::tabName(const QUrl& url) const +QString DolphinTabWidget::tabName() const { - QString name; - if (url == QUrl(QStringLiteral("file:///"))) { - name = '/'; - } else { - name = url.adjusted(QUrl::StripTrailingSlash).fileName(); - if (name.isEmpty()) { - name = url.scheme(); - } else { - // Make sure that a '&' inside the directory name is displayed correctly - // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText() - name.replace('&', QLatin1String("&&")); - } + if (currentTabPage() == nullptr) { + return QString(); } - return name; + QString name = currentTabPage()->activeViewContainer()->getCaption(); + // Make sure that a '&' inside the directory name is displayed correctly + // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText() + return name.replace('&', QLatin1String("&&")); } diff --git a/src/dolphinviewcontainer.h b/src/dolphinviewcontainer.h --- a/src/dolphinviewcontainer.h +++ b/src/dolphinviewcontainer.h @@ -136,6 +136,13 @@ */ void reload(); + /** + * @return Returns a Caption suitable for display to the user. It is + * calculated depending on settings, if a search is active and other + * factors. + */ + QString getCaption() const; + public slots: /** * Sets the current active URL, where all actions are applied. The diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -31,6 +31,7 @@ #include "views/viewproperties.h" #include +#include #include #include #include @@ -409,6 +410,52 @@ m_messageWidget->hide(); } +QString DolphinViewContainer::getCaption() const +{ + if (GeneralSettings::showFullPathInTitlebar()) { + if (!url().isLocalFile()) { + return url().adjusted(QUrl::StripTrailingSlash).toString(); + } + return url().adjusted(QUrl::StripTrailingSlash).path(); + } + + KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel(); + const auto& matchedPlaces = placesModel->match(placesModel->index(0,0), KFilePlacesModel::UrlRole, url(), 1, Qt::MatchExactly); + + if (!matchedPlaces.isEmpty()) { + return placesModel->text(matchedPlaces.first()); + } + if (!url().isLocalFile()) { + QUrl adjustedUrl = url().adjusted(QUrl::StripTrailingSlash); + QString caption; + if (!adjustedUrl.fileName().isEmpty()) { + caption = adjustedUrl.fileName(); + } else if (!adjustedUrl.path().isEmpty() && adjustedUrl.path() != "/") { + caption = adjustedUrl.path(); + } else if (!adjustedUrl.host().isEmpty()) { + caption = adjustedUrl.host(); + } else { + caption = adjustedUrl.toString(); + } + return caption; + } + + QString fileName = url().adjusted(QUrl::StripTrailingSlash).fileName(); + if (fileName.isEmpty()) { + fileName = '/'; + } + + if (isSearchModeEnabled()) { + if(currentSearchText().isEmpty()){ + return i18n("Search"); + } else { + return i18n("Search for %1", currentSearchText()); + } + } + + return fileName; +} + void DolphinViewContainer::setUrl(const QUrl& newUrl) { if (newUrl != m_urlNavigator->locationUrl()) {