From a99ba3ae391f02d25111b8850c11bed88673a452 Mon Sep 17 00:00:00 2001 From: ShaopengLin Date: Mon, 28 Oct 2024 14:27:14 -0400 Subject: [PATCH] Introduce isHTMLContent in webview.cpp Refactor the way to determine Zim MimeType. --- src/webview.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/webview.cpp b/src/webview.cpp index 6fdb8a4e..c3c3813c 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -153,18 +153,23 @@ zim::Item getZimItem(const QUrl& url) return entry.getItem(true); } +bool isHTMLContent(const zim::Item& item) +{ + auto mimeType = QByteArray::fromStdString(item.getMimetype()); + mimeType = mimeType.split(';')[0]; + return mimeType == "text/html"; +} + void WebView::saveViewContent() { try { const auto item = getZimItem(url()); - auto mimeType = QByteArray::fromStdString(item.getMimetype()); - mimeType = mimeType.split(';')[0]; /* We have to sanitize here, as parsing will start once we pass the file name to either save or download method. */ QString suggestedFileName = QString::fromStdString(kiwix::getSlugifiedFileName(item.getTitle())); - if (mimeType == "text/html") + if (isHTMLContent(item)) page()->save(suggestedFileName + ".pdf"); else page()->download(this->url(), suggestedFileName);