Skip to content

Commit

Permalink
File-not-found tab now displays zim name and path
Browse files Browse the repository at this point in the history
Zim name and path is displayed to helped user to work out what to do with the tab.
  • Loading branch information
ShaopengLin committed Jul 28, 2024
1 parent eb08aad commit 40a9eba
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
4 changes: 3 additions & 1 deletion resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,7 @@
"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-id": "Zim Id",
"zim-name": "Zim Name",
"zim-path": "Zim File Path"
}
4 changes: 3 additions & 1 deletion resources/i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,7 @@
"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-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"
}
9 changes: 9 additions & 0 deletions src/tabbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/tabbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class TabBar : public QTabBar
void openFindInPageBar();
void closeTabsByZimId(const QString &id);
QStringList getTabUrls() const;
QStringList getTabZimIds() const;

protected:
void mousePressEvent(QMouseEvent *event);
Expand Down
9 changes: 9 additions & 0 deletions src/urlschemehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ 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 contentHtml = "<section><div>"
"<h1>" +
gt("file-not-found-title") +
Expand All @@ -191,6 +194,12 @@ UrlSchemeHandler::replyZimNotFoundPage(QWebEngineUrlRequestJob *request,
"<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);
Expand Down

0 comments on commit 40a9eba

Please sign in to comment.