From cda8eac19492dcfba19b9c04882dc45e582d0084 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sun, 12 Dec 2021 19:55:20 +0400 Subject: [PATCH] Handling of NoEntry in KiwixApp::openRandomUrl() --- resources/i18n/en.json | 1 + resources/i18n/ru.json | 1 + src/kiwixapp.cpp | 16 ++++++++++------ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/resources/i18n/en.json b/resources/i18n/en.json index 16abd5a..01fe48f 100644 --- a/resources/i18n/en.json +++ b/resources/i18n/en.json @@ -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", diff --git a/resources/i18n/ru.json b/resources/i18n/ru.json index e929a18..8767e5b 100644 --- a/resources/i18n/ru.json +++ b/resources/i18n/ru.json @@ -17,6 +17,7 @@ "open-zim": "Открыть Zim", "local-kiwix-server": "Локальный сервер Kiwix", "random-article": "Случайная статья", + "random-article-error":"Не удалось открыть случайную статью.", "home-page": "Домашняя страница", "main-menu": "Главное меню", "print": "Печать", diff --git a/src/kiwixapp.cpp b/src/kiwixapp.cpp index 3ef92fe..46144c9 100644 --- a/src/kiwixapp.cpp +++ b/src/kiwixapp.cpp @@ -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)