diff --git a/resources/i18n/en.json b/resources/i18n/en.json index beff86f29..b13b5707d 100644 --- a/resources/i18n/en.json +++ b/resources/i18n/en.json @@ -167,5 +167,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": "We can't find the Zim file corresponding to this page. Please check that your file exists.", + "zim-url": "Zim Url" } diff --git a/resources/i18n/qqq.json b/resources/i18n/qqq.json index 43efac4cd..90894c4c8 100644 --- a/resources/i18n/qqq.json +++ b/resources/i18n/qqq.json @@ -174,5 +174,8 @@ "clear-filter": "Represents the action of clearing the filters selected for a filter type.", "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." + "no-videos": "A content type for Zim files that does not contain videos.", + "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-url": "The Zim Url path for the currently displayed tab" } diff --git a/src/urlschemehandler.cpp b/src/urlschemehandler.cpp index d592ef9ef..027216690 100644 --- a/src/urlschemehandler.cpp +++ b/src/urlschemehandler.cpp @@ -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, qurl); return; } try { @@ -176,6 +176,30 @@ UrlSchemeHandler::handleSearchRequest(QWebEngineUrlRequestJob* request) request->reply("text/html", buffer); } +void UrlSchemeHandler::replyZimNotFoundPage(QWebEngineUrlRequestJob *request, + const QUrl &url) +{ + QBuffer *buffer = new QBuffer; + QString contentHtml = "
" + "

" + + gt("file-not-found-title") + + "

" + "

" + + gt("file-not-found-text") + + "

" + "

" + + gt("zim-url") + ": " + url.url() + + "

" + "
"; + + 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) { diff --git a/src/urlschemehandler.h b/src/urlschemehandler.h index e7e227ac4..40a7c3a84 100644 --- a/src/urlschemehandler.h +++ b/src/urlschemehandler.h @@ -13,6 +13,8 @@ class UrlSchemeHandler : public QWebEngineUrlSchemeHandler void handleMetaRequest(QWebEngineUrlRequestJob *request); void handleContentRequest(QWebEngineUrlRequestJob *request); void handleSearchRequest(QWebEngineUrlRequestJob *request); + + void replyZimNotFoundPage(QWebEngineUrlRequestJob *request, const QUrl& url); }; #endif // URLSCHEMEHANDLER_H