UI} Options: Import without app restarting

This commit is contained in:
Nodir Temirkhodjaev 2024-09-28 15:04:18 +05:00
parent c72995cd85
commit f7e88f91df
3 changed files with 19 additions and 30 deletions

View File

@ -167,11 +167,12 @@ void OptionsController::exportBackup()
if (path.isEmpty()) if (path.isEmpty())
return; return;
if (confManager()->exportBackup(path)) { const bool ok = confManager()->exportBackup(path);
windowManager()->showInfoDialog(tr("Backup Exported Successfully"));
} else { const auto icon = ok ? QMessageBox::Information : QMessageBox::Critical;
windowManager()->showErrorBox(tr("Cannot Export Backup")); const auto title = ok ? tr("Backup Exported Successfully") : tr("Cannot Export Backup");
}
windowManager()->showMessageBox(icon, title, tr("Export Backup"));
} }
void OptionsController::importBackup() void OptionsController::importBackup()
@ -182,14 +183,16 @@ void OptionsController::importBackup()
const bool ok = confManager()->importBackup(path); const bool ok = confManager()->importBackup(path);
windowManager()->processRestartRequired( const auto icon = ok ? QMessageBox::Information : QMessageBox::Critical;
ok ? tr("Backup Imported Successfully") : tr("Cannot Import Backup")); const auto title = ok ? tr("Backup Imported Successfully") : tr("Cannot Import Backup");
windowManager()->showMessageBox(icon, title, tr("Import Backup"));
} }
void OptionsController::confirmImportBackup() void OptionsController::confirmImportBackup()
{ {
windowManager()->showConfirmBox([&] { importBackup(); }, 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."), "Make sure that you have a fresh backup."),
tr("Import Backup")); tr("Import Backup"));
} }

View File

@ -654,12 +654,12 @@ bool WindowManager::checkPassword(bool temporary)
void WindowManager::showErrorBox(const QString &text, const QString &title, QWidget *parent) 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) 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<void()> &onConfirmed, const QString &text, void WindowManager::showConfirmBox(const std::function<void()> &onConfirmed, const QString &text,
@ -694,25 +694,12 @@ void WindowManager::showQuestionBox(const std::function<void(bool confirmed)> &o
DialogUtil::showDialog(box); 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( auto box = DialogUtil::createMessageBox(
{ {
.icon = QMessageBox::Warning, .icon = icon,
.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,
.buttons = QMessageBox::Ok, .buttons = QMessageBox::Ok,
.text = text, .text = text,
.title = title, .title = title,

View File

@ -1,6 +1,7 @@
#ifndef WINDOWMANAGER_H #ifndef WINDOWMANAGER_H
#define WINDOWMANAGER_H #define WINDOWMANAGER_H
#include <QMessageBox>
#include <QObject> #include <QObject>
#include <form/form_types.h> #include <form/form_types.h>
@ -132,10 +133,8 @@ public slots:
void showQuestionBox(const std::function<void(bool confirmed)> &onFinished, const QString &text, void showQuestionBox(const std::function<void(bool confirmed)> &onFinished, const QString &text,
const QString &title = QString(), QWidget *parent = nullptr); const QString &title = QString(), QWidget *parent = nullptr);
static void showErrorDialog( static void showMessageBox(QMessageBox::Icon icon, const QString &text,
const QString &text, const QString &title = QString(), QWidget *parent = nullptr); const QString &title = QString(), QWidget *parent = nullptr);
static void showInfoDialog(
const QString &text, const QString &title = QString(), QWidget *parent = nullptr);
static bool showPasswordDialog(QString &password, int *unlockType = nullptr); static bool showPasswordDialog(QString &password, int *unlockType = nullptr);