Skip to content

Commit

Permalink
Add Directory Monitoring handling to File-Not-Found page
Browse files Browse the repository at this point in the history
Directory Monitoring can remove zims from the library instance. We now only remove zims that are not opened by the user. There could be the case where library instance is directly modified inside kiwix-desktop, filesystem, etc that causes us to lose the zim information. We only display N/A in this case for path and name on the page.
  • Loading branch information
ShaopengLin committed Jul 28, 2024
1 parent 62ad897 commit e38ba4f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/contentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions src/kiwixapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 9 additions & 3 deletions src/urlschemehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,15 @@ UrlSchemeHandler::replyZimNotFoundPage(QWebEngineUrlRequestJob *request,
const QString &zimId)
{
QBuffer *buffer = new QBuffer;
auto& book = KiwixApp::instance()->getLibrary()->getBookById(zimId);
QString path = QString::fromStdString(book.getPath());
QString name = QString::fromStdString(book.getName());
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") +
Expand Down

0 comments on commit e38ba4f

Please sign in to comment.