Skip to content

Commit

Permalink
Introduce isHTMLContent in webview.cpp
Browse files Browse the repository at this point in the history
Refactor the way to determine Zim MimeType.
  • Loading branch information
ShaopengLin committed Oct 28, 2024
1 parent b18a2cb commit a99ba3a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/webview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a99ba3a

Please sign in to comment.