diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -92,6 +92,8 @@ void setTabsToHomeIfMountPathOpen(const QString& mountPath); + QString getCaption(const QUrl& url, DolphinViewContainer* activeViewContainer) const; + public slots: /** * Pastes the clipboard data into the currently selected folder diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -195,6 +195,44 @@ m_tabWidget->openFiles(files, splitView); } +QString DolphinMainWindow::getCaption(const QUrl& url, DolphinViewContainer* activeViewContainer) const +{ + 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(); + return schemePrefix + 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()); + } + + QString fileName = url.adjusted(QUrl::StripTrailingSlash).fileName(); + if (fileName.isEmpty()) { + fileName = '/'; + } + + if (activeViewContainer && activeViewContainer->isSearchModeEnabled()) { + if(activeViewContainer->currentSearchText().isEmpty()){ + return i18n("Search"); + } else { + return i18n("Search for %1", activeViewContainer->currentSearchText()); + } + } + + return schemePrefix + fileName; +} + void DolphinMainWindow::showCommand(CommandType command) { DolphinStatusBar* statusBar = m_activeViewContainer->statusBar(); @@ -1003,44 +1041,7 @@ void DolphinMainWindow::setUrlAsCaption(const QUrl& url) { - 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(getCaption(url, m_activeViewContainer)); } void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath) diff --git a/src/dolphintabwidget.h b/src/dolphintabwidget.h --- a/src/dolphintabwidget.h +++ b/src/dolphintabwidget.h @@ -23,6 +23,7 @@ #include #include +class DolphinMainWindow; class DolphinViewContainer; class DolphinTabPage; class KConfigGroup; @@ -32,7 +33,7 @@ Q_OBJECT public: - explicit DolphinTabWidget(QWidget* parent); + explicit DolphinTabWidget(DolphinMainWindow* parent); /** * @return Tab page at the current index (can be 0 if tabs count is smaller than 1) @@ -196,6 +197,8 @@ QString tabName(const QUrl& url) const; private: + DolphinMainWindow* m_mainWindow; + /** Caches the (negated) places panel visibility */ bool m_placesSelectorVisible; diff --git a/src/dolphintabwidget.cpp b/src/dolphintabwidget.cpp --- a/src/dolphintabwidget.cpp +++ b/src/dolphintabwidget.cpp @@ -19,6 +19,7 @@ #include "dolphintabwidget.h" +#include "dolphinmainwindow.h" #include "dolphintabbar.h" #include "dolphintabpage.h" #include "dolphinviewcontainer.h" @@ -31,8 +32,9 @@ #include #include -DolphinTabWidget::DolphinTabWidget(QWidget* parent) : +DolphinTabWidget::DolphinTabWidget(DolphinMainWindow* parent) : QTabWidget(parent), + m_mainWindow(parent), m_placesSelectorVisible(true), m_lastViewedTab(0) { @@ -116,6 +118,7 @@ { const int tabCount = count(); for (int i = 0; i < tabCount; ++i) { + tabBar()->setTabText(i, tabName(tabPageAt(i)->activeViewContainer()->url())); tabPageAt(i)->refreshViews(); } } @@ -355,18 +358,5 @@ QString DolphinTabWidget::tabName(const QUrl& url) 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("&&")); - } - } - return name; + return m_mainWindow->getCaption(url, currentTabPage() ? currentTabPage()->activeViewContainer() : nullptr); }