Paste P246

gwenview-startpage-browse
ActivePublic

Authored by rkflx on Jul 23 2018, 7:31 AM.
diff --git a/app/browsemainpage.cpp b/app/browsemainpage.cpp
index dfe02317..fb98f4ce 100644
--- a/app/browsemainpage.cpp
+++ b/app/browsemainpage.cpp
@@ -558,4 +558,31 @@ QToolButton* BrowseMainPage::toggleSideBarButton() const
return d->mToggleSideBarButton;
}
+QString BrowseMainPage::windowTitle(const QUrl& url) const
+{
+ // loosely based on DolphinMainWindow::setUrlAsCaption
+
+ const auto& matchedPlaces = d->mFilePlacesModel->match(d->mFilePlacesModel->index(0,0),
+ KFilePlacesModel::UrlRole, url,
+ 1, Qt::MatchExactly);
+ if (!matchedPlaces.isEmpty()) {
+ return d->mFilePlacesModel->text(matchedPlaces.first());
+ }
+
+ QString schemePrefix;
+ if (!url.isLocalFile()) {
+ schemePrefix += url.scheme() + QStringLiteral(": ");
+ if (!url.host().isEmpty()) {
+ schemePrefix += url.host() + QStringLiteral(" - ");
+ }
+ }
+
+ QString fileName = url.adjusted(QUrl::StripTrailingSlash).fileName();
+ if (fileName.isEmpty()) {
+ fileName = QLatin1Char('/');
+ }
+
+ return schemePrefix + fileName;
+}
+
} // namespace
diff --git a/app/browsemainpage.h b/app/browsemainpage.h
index f2b70a5f..cbe01d24 100644
--- a/app/browsemainpage.h
+++ b/app/browsemainpage.h
@@ -68,6 +68,8 @@ public:
QToolButton* toggleSideBarButton() const;
+ QString windowTitle(const QUrl& url) const;
+
private Q_SLOTS:
void editLocation();
void addFolderToPlaces();
diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp
index 9d6bf58a..29a25ecf 100644
--- a/app/mainwindow.cpp
+++ b/app/mainwindow.cpp
@@ -959,7 +959,11 @@ void MainWindow::setActiveViewModeAction(QAction* action)
// Switching to browse mode
d->mViewStackedWidget->setCurrentWidget(d->mBrowseMainPage);
d->mViewMainPage->reset();
- setCaption(QString());
+
+ // ContextManager::currentDirUrl is only set when the directory supports listing.
+ // Therefore use ContextManager::currentUrl here, which also works for http://example.com/example.png
+ const QUrl dirUrl = d->mContextManager->currentUrl().adjusted(QUrl::RemoveFilename);
+ setCaption(d->mBrowseMainPage->windowTitle(dirUrl));
}
d->autoAssignThumbnailProvider();
toggleSideBar(d->sideBarVisibility());
@@ -1213,6 +1217,10 @@ void MainWindow::slotCurrentDirUrlChanged(const QUrl &url)
} else {
d->mGoUpAction->setEnabled(false);
}
+
+ if (d->mCurrentMainPageId == BrowseMainPageId) {
+ setCaption(d->mBrowseMainPage->windowTitle(url));
+ }
}
void MainWindow::slotDirModelNewItems()
rkflx edited the content of this paste. (Show Details)Jul 23 2018, 7:31 AM
rkflx changed the title of this paste from untitled to gwenview-startpage-browse.