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())
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"));
}

View File

@ -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<void()> &onConfirmed, const QString &text,
@ -694,25 +694,12 @@ void WindowManager::showQuestionBox(const std::function<void(bool confirmed)> &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,

View File

@ -1,6 +1,7 @@
#ifndef WINDOWMANAGER_H
#define WINDOWMANAGER_H
#include <QMessageBox>
#include <QObject>
#include <form/form_types.h>
@ -132,10 +133,8 @@ public slots:
void showQuestionBox(const std::function<void(bool confirmed)> &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);