From 059889ecfe4a2f309fcbafe1f7b404a45fdf56a8 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Wed, 10 Jan 2018 12:57:28 +0100 Subject: [PATCH] BrowserWindow: Don't show "Empty Page" in window title --- src/lib/app/browserwindow.cpp | 7 ++++++- src/lib/webengine/webview.cpp | 13 ++++++------- src/lib/webengine/webview.h | 4 +--- src/lib/webtab/webtab.cpp | 6 +++--- src/lib/webtab/webtab.h | 5 ++--- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/lib/app/browserwindow.cpp b/src/lib/app/browserwindow.cpp index 4a42935fd..4b821572c 100644 --- a/src/lib/app/browserwindow.cpp +++ b/src/lib/app/browserwindow.cpp @@ -968,7 +968,12 @@ void BrowserWindow::currentTabChanged() return; } - setWindowTitle(tr("%1 - Falkon").arg(view->webTab()->title())); + const QString title = view->webTab()->title(/*allowEmpty*/true); + if (title.isEmpty()) { + setWindowTitle(tr("Falkon")); + } else { + setWindowTitle(tr("%1 - Falkon").arg(title)); + } m_ipLabel->setText(view->getIp()); view->setFocus(); diff --git a/src/lib/webengine/webview.cpp b/src/lib/webengine/webview.cpp index 39449fe2f..36691df48 100644 --- a/src/lib/webengine/webview.cpp +++ b/src/lib/webengine/webview.cpp @@ -114,26 +114,25 @@ QIcon WebView::icon(bool allowNull) const return IconProvider::iconForUrl(url(), allowNull); } -QString WebView::title() const +QString WebView::title(bool allowEmpty) const { QString title = QWebEngineView::title(); + if (allowEmpty) { + return title; + } + if (title.isEmpty()) { title = url().toString(QUrl::RemoveFragment); } - if (title.isEmpty() || title == QLatin1String("about:blank")) { + if (title.isEmpty() || title == QL1S("about:blank")) { return tr("Empty Page"); } return title; } -bool WebView::isTitleEmpty() const -{ - return QWebEngineView::title().isEmpty(); -} - WebPage* WebView::page() const { return m_page; diff --git a/src/lib/webengine/webview.h b/src/lib/webengine/webview.h index 185a56409..a0a4af4a2 100644 --- a/src/lib/webengine/webview.h +++ b/src/lib/webengine/webview.h @@ -38,9 +38,7 @@ public: ~WebView(); QIcon icon(bool allowNull = false) const; - - QString title() const; - bool isTitleEmpty() const; + QString title(bool allowEmpty = false) const; WebPage* page() const; void setPage(WebPage* page); diff --git a/src/lib/webtab/webtab.cpp b/src/lib/webtab/webtab.cpp index 497732973..b4c411acc 100644 --- a/src/lib/webtab/webtab.cpp +++ b/src/lib/webtab/webtab.cpp @@ -227,10 +227,10 @@ QUrl WebTab::url() const } } -QString WebTab::title() const +QString WebTab::title(bool allowEmpty) const { if (isRestored()) { - return m_webView->title(); + return m_webView->title(allowEmpty); } else { return m_savedTab.title; @@ -426,7 +426,7 @@ void WebTab::showNotification(QWidget* notif) void WebTab::loadStarted() { - if (m_tabBar && m_webView->isTitleEmpty()) { + if (m_tabBar && m_webView->title(/*allowEmpty*/true).isEmpty()) { m_tabBar->setTabText(tabIndex(), tr("Loading...")); } } diff --git a/src/lib/webtab/webtab.h b/src/lib/webtab/webtab.h index 06d26139a..8ead83ed8 100644 --- a/src/lib/webtab/webtab.h +++ b/src/lib/webtab/webtab.h @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2010-2017 David Rosca +* Copyright (C) 2010-2018 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -64,7 +64,7 @@ public: TabIcon* tabIcon() const; QUrl url() const; - QString title() const; + QString title(bool allowEmpty = false) const; QIcon icon(bool allowNull = false) const; QWebEngineHistory* history() const; int zoomLevel() const; @@ -128,7 +128,6 @@ private: SavedTab m_savedTab; bool m_isPinned; - }; #endif // WEBTAB_H