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",
"main-menu":"Main menu",
"print":"Print",
"print-page-error": "An error has occured while printing.",
"new-tab":"New tab",
"close-tab":"Close tab",
"close":"Close",

View File

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

View File

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

View File

@ -14,6 +14,7 @@
#include <QtSingleApplication>
#include <QApplication>
#include <QErrorMessage>
#include <QMessageBox>
#include <QTranslator>
#include <kiwix/name_mapper.h>
@ -66,7 +67,7 @@ public:
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; }
Library* getLibrary() { return &m_library; }