Catch exception when importing files and display error message

This commit is contained in:
Jan Käberich 2021-05-12 22:05:50 +02:00
parent 2fac430381
commit 3d4d3c9468
4 changed files with 93 additions and 72 deletions

View file

@ -15,11 +15,17 @@ void InformationBox::ShowMessage(QString title, QString message, QString message
QSettings s;
if(!s.contains(hashToSettingsKey(hash))) {
auto box = new InformationBox(title, message, hash, nullptr);
auto box = new InformationBox(title, message, QMessageBox::Information, hash, nullptr);
box->show();
}
}
void InformationBox::ShowError(QString title, QString message)
{
auto box = new InformationBox(title, message, QMessageBox::Information, 0, nullptr);
box->show();
}
bool InformationBox::AskQuestion(QString title, QString question, bool defaultAnswer, QString messageID)
{
// check if the user still wants to see this message
@ -32,7 +38,7 @@ bool InformationBox::AskQuestion(QString title, QString question, bool defaultAn
QSettings s;
if(!s.contains(hashToSettingsKey(hash))) {
auto box = new InformationBox(title, question, hash, nullptr);
auto box = new InformationBox(title, question, QMessageBox::Question, hash, nullptr);
box->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
int ret = box->exec();
if(ret == QMessageBox::Yes) {
@ -46,17 +52,21 @@ bool InformationBox::AskQuestion(QString title, QString question, bool defaultAn
}
}
InformationBox::InformationBox(QString title, QString message, unsigned int hash, QWidget *parent)
InformationBox::InformationBox(QString title, QString message, Icon icon, unsigned int hash, QWidget *parent)
: QMessageBox(parent),
hash(hash)
{
setWindowTitle(title);
setText(message);
setAttribute(Qt::WA_DeleteOnClose, true);
setIcon(QMessageBox::Information);
setIcon(icon);
auto cb = new QCheckBox("Do not show this message again");
setCheckBox(cb);
if(hash == 0) {
cb->setVisible(false);
}
}
InformationBox::~InformationBox()