mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-08-03 12:46:29 -04:00
Merge pull request #1132 from kiwix/Issue#1073-file-not-found-page
Added Custom File-Not-Found page for Tabs
This commit is contained in:
commit
319f9e5d6a
@ -168,5 +168,10 @@
|
||||
"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",
|
||||
"zim-name": "Zim Name",
|
||||
"zim-path": "Zim File Path"
|
||||
}
|
||||
|
@ -175,5 +175,10 @@
|
||||
"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.",
|
||||
"zim-name": "The term for the name of a Zim file",
|
||||
"zim-path": "The term for the path of a Zim file"
|
||||
}
|
||||
|
@ -906,5 +906,6 @@ void ContentManager::updateLibraryFromDir(QString monitorDir)
|
||||
|
||||
void ContentManager::handleDisappearedZimFile(QString bookId)
|
||||
{
|
||||
mp_library->removeBookFromLibraryById(bookId);
|
||||
if (!KiwixApp::instance()->getTabWidget()->getTabZimIds().contains(bookId))
|
||||
mp_library->removeBookFromLibraryById(bookId);
|
||||
}
|
||||
|
@ -106,10 +106,10 @@ void KiwixApp::init()
|
||||
mp_manager->asyncUpdateLibraryFromDir(monitorDir);
|
||||
});
|
||||
|
||||
setupDirectoryMonitoring();
|
||||
|
||||
/* Restore Tabs before directory monitoring to ensure we know what tabs user had. */
|
||||
restoreTabs();
|
||||
restoreWindowState();
|
||||
setupDirectoryMonitoring();
|
||||
}
|
||||
|
||||
void KiwixApp::setupDirectoryMonitoring()
|
||||
|
@ -284,6 +284,15 @@ QStringList TabBar::getTabUrls() const {
|
||||
return idList;
|
||||
}
|
||||
|
||||
QStringList TabBar::getTabZimIds() const
|
||||
{
|
||||
QStringList idList;
|
||||
for (int index = 0; index <= mp_stackedWidget->count(); index++)
|
||||
if (ZimView* zv = qobject_cast<ZimView*>(mp_stackedWidget->widget(index)))
|
||||
idList.push_back(zv->getWebView()->zimId());
|
||||
return idList;
|
||||
}
|
||||
|
||||
void TabBar::closeTab(int index)
|
||||
{
|
||||
// The first and last tabs (i.e. the library tab and the + (new tab) button)
|
||||
|
@ -50,6 +50,7 @@ public:
|
||||
void openFindInPageBar();
|
||||
void closeTabsByZimId(const QString &id);
|
||||
QStringList getTabUrls() const;
|
||||
QStringList getTabZimIds() const;
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
|
@ -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,46 @@ UrlSchemeHandler::handleSearchRequest(QWebEngineUrlRequestJob* request)
|
||||
request->reply("text/html", buffer);
|
||||
}
|
||||
|
||||
void
|
||||
UrlSchemeHandler::replyZimNotFoundPage(QWebEngineUrlRequestJob *request,
|
||||
const QString &zimId)
|
||||
{
|
||||
QBuffer *buffer = new QBuffer;
|
||||
QString path = "N/A", name = "N/A";
|
||||
try
|
||||
{
|
||||
auto& book = KiwixApp::instance()->getLibrary()->getBookById(zimId);
|
||||
path = QString::fromStdString(book.getPath());
|
||||
name = QString::fromStdString(book.getName());
|
||||
}
|
||||
catch (...) { /* Blank */ }
|
||||
|
||||
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>"
|
||||
"<p>" +
|
||||
gt("zim-name") + ": <b>" + name +
|
||||
"</b></p>"
|
||||
"<p>" +
|
||||
gt("zim-path") + ": <b>" + path +
|
||||
"</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)
|
||||
{
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user