#include "dolphindockwidget.h"
#include "dolphincontextmenu.h"
#include "dolphinnewfilemenu.h"
-#include "dolphinplacesmodelsingleton.h"
#include "dolphinrecenttabsmenu.h"
#include "dolphintabwidget.h"
#include "dolphinviewcontainer.h"
#include <KAuthorized>
#include <KConfig>
#include <KFileItemListProperties>
-#include <KFilePlacesModel>
#include <KHelpMenu>
#include <KIO/JobUiDelegate>
#include <KIO/OpenFileManagerWindowJob>
connect(m_tabWidget, &DolphinTabWidget::tabCountChanged,
this, &DolphinMainWindow::tabCountChanged);
connect(m_tabWidget, &DolphinTabWidget::currentUrlChanged,
- this, &DolphinMainWindow::setUrlAsCaption);
+ this, &DolphinMainWindow::updateWindowTitle);
setCentralWidget(m_tabWidget);
setupActions();
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)
const bool splitView = GeneralSettings::splitView();
m_tabWidget->currentTabPage()->setSplitViewEnabled(splitView);
updateSplitAction();
- setUrlAsCaption(activeViewContainer()->url());
+ updateWindowTitle();
}
emit settingsChanged();
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
{
const int tabCount = count();
for (int i = 0; i < tabCount; ++i) {
+ tabBar()->setTabText(i, tabName());
tabPageAt(i)->refreshViews();
}
}
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
{
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.
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("&&"));
}
/**
* 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 */
#include "views/viewproperties.h"
#include <KFileItemActions>
+#include <KFilePlacesModel>
#include <KIO/PreviewJob>
#include <KLocalizedString>
#include <KMessageWidget>
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()) {
*/
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