diff options
| -rw-r--r-- | src/dolphinmainwindow.cpp | 47 | ||||
| -rw-r--r-- | src/dolphinmainwindow.h | 5 | ||||
| -rw-r--r-- | src/dolphintabwidget.cpp | 26 | ||||
| -rw-r--r-- | src/dolphintabwidget.h | 2 | ||||
| -rw-r--r-- | src/dolphinviewcontainer.cpp | 47 | ||||
| -rw-r--r-- | src/dolphinviewcontainer.h | 7 |
6 files changed, 71 insertions, 63 deletions
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 3b905b4d3..23894f346 100644 --- 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 <KAuthorized> #include <KConfig> #include <KFileItemListProperties> -#include <KFilePlacesModel> #include <KHelpMenu> #include <KIO/JobUiDelegate> #include <KIO/OpenFileManagerWindowJob> @@ -137,7 +135,7 @@ DolphinMainWindow::DolphinMainWindow() : 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 @@ void DolphinMainWindow::tabCountChanged(int count) 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) @@ -1506,7 +1467,7 @@ void DolphinMainWindow::refreshViews() const bool splitView = GeneralSettings::splitView(); m_tabWidget->currentTabPage()->setSplitViewEnabled(splitView); updateSplitAction(); - setUrlAsCaption(activeViewContainer()->url()); + updateWindowTitle(); } emit settingsChanged(); diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 637f41f21..f2876a877 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -412,10 +412,9 @@ private slots: 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/dolphintabwidget.cpp b/src/dolphintabwidget.cpp index a5c2f8c98..600974f56 100644 --- a/src/dolphintabwidget.cpp +++ b/src/dolphintabwidget.cpp @@ -116,6 +116,7 @@ void DolphinTabWidget::refreshViews() { const int tabCount = count(); for (int i = 0; i < tabCount; ++i) { + tabBar()->setTabText(i, tabName()); tabPageAt(i)->refreshViews(); } } @@ -160,7 +161,7 @@ void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryU 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 @@ void DolphinTabWidget::tabUrlChanged(const QUrl& url) { const int index = indexOf(qobject_cast<QWidget*>(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 @@ void DolphinTabWidget::tabRemoved(int index) 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/dolphintabwidget.h b/src/dolphintabwidget.h index b4493f7ed..d781953dd 100644 --- a/src/dolphintabwidget.h +++ b/src/dolphintabwidget.h @@ -193,7 +193,7 @@ private: /** * 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/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index f473752dc..fc3090183 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -31,6 +31,7 @@ #include "views/viewproperties.h" #include <KFileItemActions> +#include <KFilePlacesModel> #include <KIO/PreviewJob> #include <KLocalizedString> #include <KMessageWidget> @@ -409,6 +410,52 @@ void DolphinViewContainer::reload() 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()) { diff --git a/src/dolphinviewcontainer.h b/src/dolphinviewcontainer.h index b5bcc78ad..5d8a34714 100644 --- a/src/dolphinviewcontainer.h +++ b/src/dolphinviewcontainer.h @@ -136,6 +136,13 @@ public: */ 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 |
