Merge pull request #744 from kiwix/handling_of_NoEntry_in_openRandomUrl

Handling of NoEntry in KiwixApp::openRandomUrl()
This commit is contained in:
Kelson 2021-12-14 11:33:21 +01:00 committed by GitHub
commit 1d49c2ebc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)