aboutsummaryrefslogtreecommitdiff
path: root/src/browsertab.cpp
diff options
context:
space:
mode:
authorMike Skec <skec@protonmail.ch>2020-12-27 18:43:19 +1100
committerFelix Queißner <felix@ib-queissner.de>2020-12-27 11:01:48 +0100
commitb6ac752e32e6871fbe3226334aabc8e9af7c294b (patch)
tree59aaaeaaca4abba586dce348d51f05a74ed447a4 /src/browsertab.cpp
parent5bfe89f71957910975ae576cf968cf1ec32db49e (diff)
downloadkristall-b6ac752e32e6871fbe3226334aabc8e9af7c294b.tar.gz
Added page title parsing for Gemini and HTML
Diffstat (limited to 'src/browsertab.cpp')
-rw-r--r--src/browsertab.cpp43
1 files changed, 39 insertions, 4 deletions
diff --git a/src/browsertab.cpp b/src/browsertab.cpp
index 70a1a66..c470d9e 100644
--- a/src/browsertab.cpp
+++ b/src/browsertab.cpp
@@ -451,10 +451,11 @@ void BrowserTab::on_requestComplete(const QByteArray &ref_data, const QString &m
}
this->successfully_loaded = true;
+ this->page_title = "";
+
renderPage(data, mime);
- QString title = this->current_location.toString();
- emit this->titleChanged(title);
+ this->updatePageTitle();
this->current_stats.file_size = ref_data.size();
this->current_stats.mime_type = mime;
@@ -496,7 +497,8 @@ void BrowserTab::renderPage(const QByteArray &data, const MimeType &mime)
data,
this->current_location,
doc_style,
- this->outline);
+ this->outline,
+ &this->page_title);
}
else if (not plaintext_only and mime.is("text","gophermap"))
{
@@ -512,7 +514,27 @@ void BrowserTab::renderPage(const QByteArray &data, const MimeType &mime)
document->setDefaultFont(doc_style.standard_font);
document->setDefaultStyleSheet(doc_style.toStyleSheet());
document->setDocumentMargin(doc_style.margin);
- document->setHtml(QString::fromUtf8(data));
+ QString page_html = QString::fromUtf8(data);
+ document->setHtml(page_html);
+
+ // Find page title in HTML
+ // Split so we only look in the <head>
+ QStringList head = page_html.split("</head>", Qt::KeepEmptyParts, Qt::CaseInsensitive);
+ if (head[0] != page_html)
+ {
+ // Split at first title tag.
+ QStringList a = head[0].split("<title>", Qt::KeepEmptyParts, Qt::CaseInsensitive);
+ if (a[0] != head[0])
+ {
+ // Split at second tag.
+ QStringList b = a[1].split("</title>", Qt::KeepEmptyParts, Qt::CaseInsensitive);
+ if (b[0] != a[1])
+ {
+ QString title = b[0];
+ this->page_title = title;
+ }
+ }
+ }
}
else if (not plaintext_only and mime.is("text","x-kristall-theme"))
{
@@ -633,6 +655,19 @@ void BrowserTab::rerenderPage()
this->renderPage(this->current_buffer, this->current_mime);
}
+void BrowserTab::updatePageTitle()
+{
+ if (page_title.isEmpty())
+ {
+ page_title = this->current_location.toString();
+ }
+
+ // TODO: Shorten lengthy titles?
+
+ emit this->titleChanged(this->page_title);
+}
+
+
void BrowserTab::on_inputRequired(const QString &query, const bool is_sensitive)
{
this->network_timeout_timer.stop();