mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-08-03 20:56:49 -04:00
Added custom file-not-found page
Page is displayed when zim file is missing.
This commit is contained in:
parent
6ff18a8b0d
commit
368fafb6bc
@ -168,5 +168,8 @@
|
|||||||
"no-pictures": "No Pictures",
|
"no-pictures": "No Pictures",
|
||||||
"no-videos": "No Videos",
|
"no-videos": "No Videos",
|
||||||
"open-previous-tabs-at-startup": "Open previous tabs at startup",
|
"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"
|
||||||
}
|
}
|
||||||
|
@ -175,5 +175,8 @@
|
|||||||
"no-details": "A content type for Zim files representing it only has an introduction.",
|
"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-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.",
|
"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."
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ UrlSchemeHandler::handleContentRequest(QWebEngineUrlRequestJob *request)
|
|||||||
try {
|
try {
|
||||||
archive = library->getArchive(zim_id);
|
archive = library->getArchive(zim_id);
|
||||||
} catch (std::out_of_range& e) {
|
} catch (std::out_of_range& e) {
|
||||||
request->fail(QWebEngineUrlRequestJob::UrlNotFound);
|
replyZimNotFoundPage(request, zim_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -176,6 +176,31 @@ UrlSchemeHandler::handleSearchRequest(QWebEngineUrlRequestJob* request)
|
|||||||
request->reply("text/html", buffer);
|
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
|
void
|
||||||
UrlSchemeHandler::requestStarted(QWebEngineUrlRequestJob *request)
|
UrlSchemeHandler::requestStarted(QWebEngineUrlRequestJob *request)
|
||||||
{
|
{
|
||||||
|
@ -13,6 +13,8 @@ private:
|
|||||||
void handleMetaRequest(QWebEngineUrlRequestJob *request);
|
void handleMetaRequest(QWebEngineUrlRequestJob *request);
|
||||||
void handleContentRequest(QWebEngineUrlRequestJob *request);
|
void handleContentRequest(QWebEngineUrlRequestJob *request);
|
||||||
void handleSearchRequest(QWebEngineUrlRequestJob *request);
|
void handleSearchRequest(QWebEngineUrlRequestJob *request);
|
||||||
|
|
||||||
|
void replyZimNotFoundPage(QWebEngineUrlRequestJob *request, const QString& zimId);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // URLSCHEMEHANDLER_H
|
#endif // URLSCHEMEHANDLER_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user