Handling of NoEntry in KiwixApp::openRandomUrl()

This commit is contained in:
Veloman Yunkan 2021-12-12 19:55:20 +04:00
parent ccfd2a66e2
commit cda8eac194
3 changed files with 12 additions and 6 deletions

View File

@ -11,6 +11,7 @@
"open-zim":"Open Zim",
"local-kiwix-server":"Local Kiwix Server",
"random-article":"Random Article",
"random-article-error":"Failed to open a random article.",
"home-page":"Home page",
"main-menu":"Main menu",
"print":"Print",

View File

@ -17,6 +17,7 @@
"open-zim": "Открыть Zim",
"local-kiwix-server": "Локальный сервер Kiwix",
"random-article": "Случайная статья",
"random-article-error":"Не удалось открыть случайную статью.",
"home-page": "Домашняя страница",
"main-menu": "Главное меню",
"print": "Печать",

View File

@ -249,13 +249,17 @@ void KiwixApp::openRandomUrl(bool newTab)
return;
}
auto reader = m_library.getReader(zimId);
auto entry = reader->getRandomPage();
try {
auto entry = reader->getRandomPage();
QUrl url;
url.setScheme("zim");
url.setHost(zimId + ".zim");
url.setPath("/" + QString::fromStdString(entry.getPath()));
openUrl(url, newTab);
QUrl url;
url.setScheme("zim");
url.setHost(zimId + ".zim");
url.setPath("/" + QString::fromStdString(entry.getPath()));
openUrl(url, newTab);
} catch ( const kiwix::NoEntry& ) {
showMessage(gt("random-article-error"));
}
}
void KiwixApp::showMessage(const QString &message)