UI: Options: Improve backup import result dialog

This commit is contained in:
Nodir Temirkhodjaev 2024-01-12 15:06:32 +03:00
parent b03f2f95fa
commit 3c9e5b17ac
5 changed files with 16 additions and 14 deletions

View File

@ -42,6 +42,7 @@ QMessageBox *DialogUtil::createMessageBox(const MessageBoxArg &ba, QWidget *pare
{
auto box = new QMessageBox(ba.icon, ba.title, ba.text, ba.buttons, parent);
box->setAttribute(Qt::WA_DeleteOnClose);
box->setInformativeText(ba.info);
setupModalDialog(box);
return box;
}

View File

@ -11,6 +11,7 @@ struct MessageBoxArg
QMessageBox::StandardButtons buttons;
const QString text;
const QString title;
const QString info;
};
class DialogUtil

View File

@ -188,13 +188,10 @@ void OptionsController::importBackup()
const QString inPath = FileUtil::pathSlash(path);
if (confManager()->importBackup(inPath)) {
windowManager()->showInfoDialog(tr("Backup Imported Successfully"));
} else {
windowManager()->showErrorBox(tr("Cannot Import Backup"));
}
const bool ok = confManager()->importBackup(inPath);
windowManager()->restart();
windowManager()->processRestartRequired(
ok ? tr("Backup Imported Successfully") : tr("Cannot Import Backup"));
}
void OptionsController::confirmImportBackup()

View File

@ -501,9 +501,9 @@ void WindowManager::restart()
QCoreApplication::quit();
}
void WindowManager::processRestartRequired()
void WindowManager::processRestartRequired(const QString &info)
{
showConfirmBox([&] { restart(); }, tr("Restart Now?"), tr("Restart Required"));
showConfirmBox([&] { restart(); }, tr("Restart Now?"), tr("Restart Required"), info);
}
bool WindowManager::checkWindowPassword(WindowCode code)
@ -551,7 +551,7 @@ void WindowManager::showInfoBox(const QString &text, const QString &title, QWidg
}
void WindowManager::showConfirmBox(const std::function<void()> &onConfirmed, const QString &text,
const QString &title, QWidget *parent)
const QString &title, const QString &info, QWidget *parent)
{
showQuestionBox(
[=](bool confirmed) {
@ -559,11 +559,11 @@ void WindowManager::showConfirmBox(const std::function<void()> &onConfirmed, con
onConfirmed();
}
},
text, title, parent);
text, title, info, parent);
}
void WindowManager::showQuestionBox(const std::function<void(bool confirmed)> &onFinished,
const QString &text, const QString &title, QWidget *parent)
const QString &text, const QString &title, const QString &info, QWidget *parent)
{
auto box = DialogUtil::createMessageBox(
{
@ -571,6 +571,7 @@ void WindowManager::showQuestionBox(const std::function<void(bool confirmed)> &o
.buttons = QMessageBox::Yes | QMessageBox::No,
.text = text,
.title = title,
.info = info,
},
parent);

View File

@ -105,7 +105,7 @@ public slots:
void quit();
void restart();
void processRestartRequired();
void processRestartRequired(const QString &info = {});
bool checkWindowPassword(WindowCode code);
bool checkPassword();
@ -115,9 +115,11 @@ public slots:
virtual void showInfoBox(
const QString &text, const QString &title = QString(), QWidget *parent = nullptr);
void showConfirmBox(const std::function<void()> &onConfirmed, const QString &text,
const QString &title = QString(), QWidget *parent = nullptr);
const QString &title = QString(), const QString &info = QString(),
QWidget *parent = nullptr);
void showQuestionBox(const std::function<void(bool confirmed)> &onFinished, const QString &text,
const QString &title = QString(), QWidget *parent = nullptr);
const QString &title = QString(), const QString &info = QString(),
QWidget *parent = nullptr);
static void showErrorDialog(
const QString &text, const QString &title = QString(), QWidget *parent = nullptr);