Added custom file-not-found page

Page is displayed when zim file is missing.
This commit is contained in:
ShaopengLin 2024-07-28 13:01:35 -04:00
parent 6ff18a8b0d
commit 368fafb6bc
4 changed files with 36 additions and 3 deletions

View File

@ -168,5 +168,8 @@
"no-pictures": "No Pictures",
"no-videos": "No Videos",
"open-previous-tabs-at-startup": "Open previous tabs at startup",
"preview-book-in-web-browser": "Preview book in web browser"
"preview-book-in-web-browser": "Preview book in web browser",
"file-not-found-title": "ZIM File Not Found",
"file-not-found-text": "ZIM file doesn't exist or is not readable",
"zim-id": "ZIM Id"
}

View File

@ -175,5 +175,8 @@
"no-details": "A content type for Zim files representing it only has an introduction.",
"no-pictures": "A content type for Zim files that does not contain pictures.",
"no-videos": "A content type for Zim files that does not contain videos.",
"path-was-copied": "Tooltip confirming that the download path from settings was copied."
"path-was-copied": "Tooltip confirming that the download path from settings was copied.",
"file-not-found-title": "Error title text displayed when the desktop application cannot find the Zim file needed to display the web page.",
"file-not-found-text": "Error description text for when the desktop application cannot find the Zim file needed to display the web page.",
"zim-id": "The term for the unique identifier of a zim file."
}

View File

@ -44,7 +44,7 @@ UrlSchemeHandler::handleContentRequest(QWebEngineUrlRequestJob *request)
try {
archive = library->getArchive(zim_id);
} catch (std::out_of_range& e) {
request->fail(QWebEngineUrlRequestJob::UrlNotFound);
replyZimNotFoundPage(request, zim_id);
return;
}
try {
@ -176,6 +176,31 @@ UrlSchemeHandler::handleSearchRequest(QWebEngineUrlRequestJob* request)
request->reply("text/html", buffer);
}
void
UrlSchemeHandler::replyZimNotFoundPage(QWebEngineUrlRequestJob *request,
const QString &zimId)
{
QBuffer *buffer = new QBuffer;
QString contentHtml = "<section><div>"
"<h1>" +
gt("file-not-found-title") +
"</h1>"
"<p>" +
gt("file-not-found-text") +
"</p>"
"<p>" +
gt("zim-id") + ": <b>" + zimId +
"</b></p>"
"</div></section>";
buffer->open(QIODevice::WriteOnly);
buffer->write(contentHtml.toStdString().c_str());
buffer->close();
connect(request, SIGNAL(destroyed()), buffer, SLOT(deleteLater()));
request->reply("text/html", buffer);
}
void
UrlSchemeHandler::requestStarted(QWebEngineUrlRequestJob *request)
{

View File

@ -13,6 +13,8 @@ private:
void handleMetaRequest(QWebEngineUrlRequestJob *request);
void handleContentRequest(QWebEngineUrlRequestJob *request);
void handleSearchRequest(QWebEngineUrlRequestJob *request);
void replyZimNotFoundPage(QWebEngineUrlRequestJob *request, const QString& zimId);
};
#endif // URLSCHEMEHANDLER_H