mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 03:26:05 -04:00
Set the tab's text to the title of the webView.
The `titleChanged` signal is emitted twice: - At beggining of loading with the Url of the page. - Once the parsing is done and the `<title></title>` html tag has been found.
This commit is contained in:
parent
81766be447
commit
cb21a6816e
@ -9,6 +9,8 @@ KTabWidget::KTabWidget(QWidget *parent) :
|
||||
KiwixWebView* KTabWidget::createNewTab(bool setCurrent)
|
||||
{
|
||||
KiwixWebView* webView = new KiwixWebView();
|
||||
QObject::connect(webView, &KiwixWebView::titleChanged, this,
|
||||
[=](const QString& str) { setTitleOf(webView, str); });
|
||||
// Ownership of webview is passed to the tabWidget
|
||||
addTab(webView, "");
|
||||
if (setCurrent) {
|
||||
@ -25,3 +27,13 @@ void KTabWidget::openUrl(std::shared_ptr<kiwix::Reader> reader, const QUrl& url,
|
||||
}
|
||||
webView->setUrl(url);
|
||||
}
|
||||
|
||||
void KTabWidget::setTitleOf(KiwixWebView* webView, const QString& title)
|
||||
{
|
||||
if (title.startsWith("zim://")) {
|
||||
auto url = QUrl(title);
|
||||
setTabText(indexOf(webView), url.path());
|
||||
} else {
|
||||
setTabText(indexOf(webView), title);
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ public:
|
||||
|
||||
KiwixWebView* createNewTab(bool setCurrent);
|
||||
void openUrl(std::shared_ptr<kiwix::Reader> reader, const QUrl &url, bool newTab);
|
||||
void setTitleOf(KiwixWebView* webView, const QString& title);
|
||||
};
|
||||
|
||||
#endif // KTABWIDGET_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user