Update showMessage()

This removes the previous default error message.
KiwixApp::showMessage() now accepts title, text and MessageBox icon
This commit is contained in:
Nikhil Tanwar 2022-01-16 17:39:15 +05:30 committed by Matthieu Gautier
parent f14d633fd3
commit 90afbf3f92
4 changed files with 16 additions and 19 deletions

View File

@ -15,6 +15,7 @@
"home-page":"Home page", "home-page":"Home page",
"main-menu":"Main menu", "main-menu":"Main menu",
"print":"Print", "print":"Print",
"print-page-error": "An error has occured while printing.",
"new-tab":"New tab", "new-tab":"New tab",
"close-tab":"Close tab", "close-tab":"Close tab",
"close":"Close", "close":"Close",

View File

@ -128,13 +128,8 @@ void ContentManager::openBook(const QString &id)
tabBar->closeTab(1); tabBar->closeTab(1);
auto text = gt("zim-open-fail-text"); auto text = gt("zim-open-fail-text");
text = text.replace("{{ZIM}}", QString::fromStdString(mp_library->getBookById(id).getPath())); text = text.replace("{{ZIM}}", QString::fromStdString(mp_library->getBookById(id).getPath()));
QMessageBox msgBox( auto title = gt("zim-open-fail-title");
QMessageBox::Warning, //Icon KiwixApp::instance()->showMessage(text, title, QMessageBox::Warning);
gt("zim-open-fail-title"), //Title
text, //Text
QMessageBox::Ok //Buttons
);
msgBox.exec();
mp_library->removeBookFromLibraryById(id); mp_library->removeBookFromLibraryById(id);
tabBar->setCurrentIndex(0); tabBar->setCurrentIndex(0);
emit(booksChanged()); emit(booksChanged());

View File

@ -178,13 +178,7 @@ void KiwixApp::openZimFile(const QString &zimfile)
} catch (const std::exception& e) { } catch (const std::exception& e) {
auto text = gt("zim-open-fail-text"); auto text = gt("zim-open-fail-text");
text = text.replace("{{ZIM}}", validZimFile); text = text.replace("{{ZIM}}", validZimFile);
QMessageBox msgBox( showMessage(text, gt("zim-open-fail-title"), QMessageBox::Warning);
QMessageBox::Warning, //Icon
gt("zim-open-fail-title"), //Title
text, //Text
QMessageBox::Ok //Buttons
);
msgBox.exec();
return; return;
} }
openUrl(QUrl("zim://"+zimId+".zim/")); openUrl(QUrl("zim://"+zimId+".zim/"));
@ -204,7 +198,7 @@ void KiwixApp::printPage()
return; return;
webview->page()->print(printer, [=](bool success) { webview->page()->print(printer, [=](bool success) {
if (!success) { if (!success) {
showMessage("An error has occured while printing."); showMessage(gt("print-page-error"), gt("error-title"), QMessageBox::Critical);
} }
delete printer; delete printer;
}); });
@ -235,13 +229,19 @@ void KiwixApp::openRandomUrl(bool newTab)
url.setPath("/" + QString::fromStdString(entry.getPath())); url.setPath("/" + QString::fromStdString(entry.getPath()));
openUrl(url, newTab); openUrl(url, newTab);
} catch ( const kiwix::NoEntry& ) { } catch ( const kiwix::NoEntry& ) {
showMessage(gt("random-article-error")); showMessage(gt("random-article-error"), gt("error-title"), QMessageBox::Information);
} }
} }
void KiwixApp::showMessage(const QString &message) void KiwixApp::showMessage(const QString &message, const QString &title, const enum QMessageBox::Icon &icon)
{ {
mp_errorDialog->showMessage(message); QMessageBox msgBox(
icon, //Icon
title, //Title
message, //Text
QMessageBox::Ok //Buttons
);
msgBox.exec();
} }
QAction *KiwixApp::getAction(KiwixApp::Actions action) QAction *KiwixApp::getAction(KiwixApp::Actions action)

View File

@ -14,6 +14,7 @@
#include <QtSingleApplication> #include <QtSingleApplication>
#include <QApplication> #include <QApplication>
#include <QErrorMessage> #include <QErrorMessage>
#include <QMessageBox>
#include <QTranslator> #include <QTranslator>
#include <kiwix/name_mapper.h> #include <kiwix/name_mapper.h>
@ -66,7 +67,7 @@ public:
void openRandomUrl(bool newTab=true); void openRandomUrl(bool newTab=true);
void showMessage(const QString& message); void showMessage(const QString& message, const QString& title, const enum QMessageBox::Icon& icon);
KProfile* getProfile() { return &m_profile; } KProfile* getProfile() { return &m_profile; }
Library* getLibrary() { return &m_library; } Library* getLibrary() { return &m_library; }