From f7e88f91df658e030dedc5418499314bafdafab3 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Sat, 28 Sep 2024 15:04:18 +0500 Subject: [PATCH] UI} Options: Import without app restarting --- src/ui/form/opt/optionscontroller.cpp | 19 +++++++++++-------- src/ui/manager/windowmanager.cpp | 23 +++++------------------ src/ui/manager/windowmanager.h | 7 +++---- 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/src/ui/form/opt/optionscontroller.cpp b/src/ui/form/opt/optionscontroller.cpp index a06b26ed..37c942d0 100644 --- a/src/ui/form/opt/optionscontroller.cpp +++ b/src/ui/form/opt/optionscontroller.cpp @@ -167,11 +167,12 @@ void OptionsController::exportBackup() if (path.isEmpty()) return; - if (confManager()->exportBackup(path)) { - windowManager()->showInfoDialog(tr("Backup Exported Successfully")); - } else { - windowManager()->showErrorBox(tr("Cannot Export Backup")); - } + const bool ok = confManager()->exportBackup(path); + + const auto icon = ok ? QMessageBox::Information : QMessageBox::Critical; + const auto title = ok ? tr("Backup Exported Successfully") : tr("Cannot Export Backup"); + + windowManager()->showMessageBox(icon, title, tr("Export Backup")); } void OptionsController::importBackup() @@ -182,14 +183,16 @@ void OptionsController::importBackup() const bool ok = confManager()->importBackup(path); - windowManager()->processRestartRequired( - ok ? tr("Backup Imported Successfully") : tr("Cannot Import Backup")); + const auto icon = ok ? QMessageBox::Information : QMessageBox::Critical; + const auto title = ok ? tr("Backup Imported Successfully") : tr("Cannot Import Backup"); + + windowManager()->showMessageBox(icon, title, tr("Import Backup")); } void OptionsController::confirmImportBackup() { windowManager()->showConfirmBox([&] { importBackup(); }, - tr("Program will be restarted after successful import. Continue?\n\n" + tr("All Options and Programs will be replaced after successful import. Continue?\n\n" "Make sure that you have a fresh backup."), tr("Import Backup")); } diff --git a/src/ui/manager/windowmanager.cpp b/src/ui/manager/windowmanager.cpp index 16548796..4076e50b 100644 --- a/src/ui/manager/windowmanager.cpp +++ b/src/ui/manager/windowmanager.cpp @@ -654,12 +654,12 @@ bool WindowManager::checkPassword(bool temporary) void WindowManager::showErrorBox(const QString &text, const QString &title, QWidget *parent) { - showErrorDialog(text, title, parent); + showMessageBox(QMessageBox::Warning, text, title, parent); } void WindowManager::showInfoBox(const QString &text, const QString &title, QWidget *parent) { - showInfoDialog(text, title, parent); + showMessageBox(QMessageBox::Information, text, title, parent); } void WindowManager::showConfirmBox(const std::function &onConfirmed, const QString &text, @@ -694,25 +694,12 @@ void WindowManager::showQuestionBox(const std::function &o DialogUtil::showDialog(box); } -void WindowManager::showErrorDialog(const QString &text, const QString &title, QWidget *parent) +void WindowManager::showMessageBox( + QMessageBox::Icon icon, const QString &text, const QString &title, QWidget *parent) { auto box = DialogUtil::createMessageBox( { - .icon = QMessageBox::Warning, - .buttons = QMessageBox::Ok, - .text = text, - .title = title, - }, - parent); - - DialogUtil::showDialog(box); -} - -void WindowManager::showInfoDialog(const QString &text, const QString &title, QWidget *parent) -{ - auto box = DialogUtil::createMessageBox( - { - .icon = QMessageBox::Information, + .icon = icon, .buttons = QMessageBox::Ok, .text = text, .title = title, diff --git a/src/ui/manager/windowmanager.h b/src/ui/manager/windowmanager.h index eb3b52e0..186ac698 100644 --- a/src/ui/manager/windowmanager.h +++ b/src/ui/manager/windowmanager.h @@ -1,6 +1,7 @@ #ifndef WINDOWMANAGER_H #define WINDOWMANAGER_H +#include #include #include
@@ -132,10 +133,8 @@ public slots: void showQuestionBox(const std::function &onFinished, const QString &text, const QString &title = QString(), QWidget *parent = nullptr); - static void showErrorDialog( - const QString &text, const QString &title = QString(), QWidget *parent = nullptr); - static void showInfoDialog( - const QString &text, const QString &title = QString(), QWidget *parent = nullptr); + static void showMessageBox(QMessageBox::Icon icon, const QString &text, + const QString &title = QString(), QWidget *parent = nullptr); static bool showPasswordDialog(QString &password, int *unlockType = nullptr);