mirror of
https://github.com/tnodir/fort
synced 2024-11-15 05:25:56 +00:00
UI: Options: Save user.ini changes on OK/Apply only
This commit is contained in:
parent
b5bcbac542
commit
ad09f4c129
@ -476,6 +476,28 @@ void ConfManager::setConfToEdit(FirewallConf *conf)
|
||||
m_confToEdit = conf;
|
||||
}
|
||||
|
||||
void ConfManager::initIniUserToEdit()
|
||||
{
|
||||
if (iniUserToEdit())
|
||||
return;
|
||||
|
||||
auto newIniUser = new IniUser(iniUser()->settings());
|
||||
|
||||
setIniUserToEdit(newIniUser);
|
||||
}
|
||||
|
||||
void ConfManager::setIniUserToEdit(IniUser *iniUser)
|
||||
{
|
||||
if (iniUserToEdit() == iniUser)
|
||||
return;
|
||||
|
||||
if (iniUserToEdit() && iniUserToEdit() != this->iniUser()) {
|
||||
delete m_iniUserToEdit;
|
||||
}
|
||||
|
||||
m_iniUserToEdit = iniUser;
|
||||
}
|
||||
|
||||
void ConfManager::setConf(FirewallConf *newConf)
|
||||
{
|
||||
conf()->deleteLater();
|
||||
@ -591,6 +613,9 @@ void ConfManager::applySavedConf(FirewallConf *newConf)
|
||||
|
||||
bool ConfManager::save(FirewallConf *newConf)
|
||||
{
|
||||
if (!newConf->anyEdited())
|
||||
return true;
|
||||
|
||||
if (!(validateConf(*newConf) && saveConf(*newConf)))
|
||||
return false;
|
||||
|
||||
@ -620,7 +645,7 @@ void ConfManager::saveIniUser(bool flagsChanged)
|
||||
iniUser()->clear();
|
||||
|
||||
if (flagsChanged) {
|
||||
emit iniUserChanged(true);
|
||||
emit iniUserChanged(/*onlyFlags=*/true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,12 +32,16 @@ public:
|
||||
FirewallConf *confToEdit() const { return m_confToEdit; }
|
||||
|
||||
IniUser *iniUser() const;
|
||||
IniUser *iniUserToEdit() const { return m_iniUserToEdit; }
|
||||
|
||||
void setUp() override;
|
||||
|
||||
void initConfToEdit();
|
||||
void setConfToEdit(FirewallConf *conf);
|
||||
|
||||
void initIniUserToEdit();
|
||||
void setIniUserToEdit(IniUser *iniUser);
|
||||
|
||||
bool loadConf(FirewallConf &conf);
|
||||
bool load();
|
||||
|
||||
@ -149,6 +153,8 @@ private:
|
||||
FirewallConf *m_conf = nullptr;
|
||||
FirewallConf *m_confToEdit = nullptr;
|
||||
|
||||
IniUser *m_iniUserToEdit = nullptr;
|
||||
|
||||
TriggerTimer m_appAlertedTimer;
|
||||
TriggerTimer m_appChangedTimer;
|
||||
TriggerTimer m_appUpdatedTimer;
|
||||
|
@ -9,11 +9,13 @@
|
||||
#include <manager/windowmanager.h>
|
||||
#include <model/zonelistmodel.h>
|
||||
#include <task/taskmanager.h>
|
||||
#include <user/iniuser.h>
|
||||
#include <util/ioc/ioccontainer.h>
|
||||
|
||||
OptionsController::OptionsController(QObject *parent) : QObject(parent)
|
||||
OptionsController::OptionsController(QObject *parent) :
|
||||
QObject(parent), m_iniUserEdited(false), m_iniUserFlagsChanged(false)
|
||||
{
|
||||
confManager()->initConfToEdit();
|
||||
initConfManagerToEdit();
|
||||
|
||||
connect(translationManager(), &TranslationManager::languageChanged, this,
|
||||
&OptionsController::retranslateUi);
|
||||
@ -22,6 +24,7 @@ OptionsController::OptionsController(QObject *parent) : QObject(parent)
|
||||
OptionsController::~OptionsController()
|
||||
{
|
||||
confManager()->setConfToEdit(nullptr);
|
||||
confManager()->setIniUserToEdit(nullptr);
|
||||
}
|
||||
|
||||
FortManager *OptionsController::fortManager() const
|
||||
@ -51,7 +54,7 @@ IniOptions *OptionsController::ini() const
|
||||
|
||||
IniUser *OptionsController::iniUser() const
|
||||
{
|
||||
return confManager()->iniUser();
|
||||
return confManager()->iniUserToEdit();
|
||||
}
|
||||
|
||||
TaskManager *OptionsController::taskManager() const
|
||||
@ -79,6 +82,11 @@ ZoneListModel *OptionsController::zoneListModel() const
|
||||
return IoC<ZoneListModel>();
|
||||
}
|
||||
|
||||
bool OptionsController::anyEdited() const
|
||||
{
|
||||
return m_iniUserEdited || conf()->anyEdited();
|
||||
}
|
||||
|
||||
void OptionsController::setOptEdited()
|
||||
{
|
||||
if (!conf()->optEdited()) {
|
||||
@ -111,6 +119,16 @@ void OptionsController::setTaskEdited()
|
||||
}
|
||||
}
|
||||
|
||||
void OptionsController::setIniUserEdited(bool flagsChanged)
|
||||
{
|
||||
m_iniUserFlagsChanged |= flagsChanged;
|
||||
|
||||
if (!m_iniUserEdited) {
|
||||
m_iniUserEdited = true;
|
||||
emitEdited(true);
|
||||
}
|
||||
}
|
||||
|
||||
void OptionsController::emitEdited(bool edited)
|
||||
{
|
||||
emit editedChanged(edited);
|
||||
@ -118,6 +136,8 @@ void OptionsController::emitEdited(bool edited)
|
||||
|
||||
void OptionsController::resetEdited()
|
||||
{
|
||||
m_iniUserEdited = m_iniUserFlagsChanged = false;
|
||||
|
||||
emitEdited(false);
|
||||
emit editResetted();
|
||||
}
|
||||
@ -134,21 +154,37 @@ void OptionsController::save(bool closeOnSuccess)
|
||||
{
|
||||
emit aboutToSave();
|
||||
|
||||
const bool isAnyEdited = conf()->anyEdited();
|
||||
if (!isAnyEdited) {
|
||||
emitEdited(false);
|
||||
} else if (!confManager()->save(conf())) {
|
||||
const bool isAnyEdited = this->anyEdited();
|
||||
|
||||
if (!confManager()->save(conf()))
|
||||
return;
|
||||
|
||||
if (m_iniUserEdited) {
|
||||
saveIniUser();
|
||||
}
|
||||
|
||||
if (closeOnSuccess) {
|
||||
closeWindow();
|
||||
} else if (isAnyEdited) {
|
||||
confManager()->initConfToEdit();
|
||||
initConfManagerToEdit();
|
||||
resetEdited();
|
||||
}
|
||||
}
|
||||
|
||||
void OptionsController::saveIniUser()
|
||||
{
|
||||
iniUser()->save();
|
||||
iniUser()->clear();
|
||||
|
||||
confManager()->saveIniUser(m_iniUserFlagsChanged);
|
||||
}
|
||||
|
||||
void OptionsController::initConfManagerToEdit()
|
||||
{
|
||||
confManager()->initConfToEdit();
|
||||
confManager()->initIniUserToEdit();
|
||||
}
|
||||
|
||||
void OptionsController::closeWindow()
|
||||
{
|
||||
windowManager()->closeOptionsWindow();
|
||||
|
@ -35,6 +35,8 @@ public:
|
||||
WindowManager *windowManager() const;
|
||||
ZoneListModel *zoneListModel() const;
|
||||
|
||||
bool anyEdited() const;
|
||||
|
||||
void initialize();
|
||||
|
||||
signals:
|
||||
@ -56,6 +58,8 @@ public slots:
|
||||
void setIniEdited();
|
||||
void setTaskEdited();
|
||||
|
||||
void setIniUserEdited(bool flagsChanged = false);
|
||||
|
||||
void emitEdited(bool edited = true);
|
||||
void resetEdited();
|
||||
|
||||
@ -66,6 +70,13 @@ public slots:
|
||||
|
||||
private:
|
||||
void save(bool closeOnSuccess);
|
||||
void saveIniUser();
|
||||
|
||||
void initConfManagerToEdit();
|
||||
|
||||
private:
|
||||
bool m_iniUserEdited : 1;
|
||||
bool m_iniUserFlagsChanged : 1;
|
||||
};
|
||||
|
||||
#endif // OPTIONSCONTROLLER_H
|
||||
|
@ -45,8 +45,8 @@ IniUser *OptionsWindow::iniUser() const
|
||||
|
||||
void OptionsWindow::cancelChanges()
|
||||
{
|
||||
if (ctrl()->conf() && ctrl()->conf()->anyEdited()) {
|
||||
emit ctrl()->cancelChanges(ini());
|
||||
if (ctrl()->anyEdited()) {
|
||||
ctrl()->resetEdited();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,8 +75,6 @@ void OptBasePage::setupController()
|
||||
connect(ctrl(), &OptionsController::aboutToSave, this, &OptBasePage::onAboutToSave);
|
||||
connect(ctrl(), &OptionsController::editResetted, this, &OptBasePage::onEditResetted);
|
||||
|
||||
connect(ctrl(), &OptionsController::cancelChanges, this, &OptBasePage::onCancelChanges);
|
||||
|
||||
connect(ctrl(), &OptionsController::afterSaveWindowState, this,
|
||||
&OptBasePage::onSaveWindowState);
|
||||
connect(ctrl(), &OptionsController::afterRestoreWindowState, this,
|
||||
|
@ -57,8 +57,6 @@ protected slots:
|
||||
virtual void onAboutToSave() { }
|
||||
virtual void onEditResetted() { }
|
||||
|
||||
virtual void onCancelChanges(IniOptions * /*oldIni*/) { }
|
||||
|
||||
virtual void onSaveWindowState(IniUser * /*ini*/) { }
|
||||
virtual void onRestoreWindowState(IniUser * /*ini*/) { }
|
||||
|
||||
|
@ -61,17 +61,13 @@ void moveProfile(const QString &profilePath, const QString &newProfilePath)
|
||||
|
||||
}
|
||||
|
||||
OptionsPage::OptionsPage(OptionsController *ctrl, QWidget *parent) : OptBasePage(ctrl, parent)
|
||||
OptionsPage::OptionsPage(OptionsController *ctrl, QWidget *parent) :
|
||||
OptBasePage(ctrl, parent), m_passwordEdited(false), m_languageEdited(false)
|
||||
{
|
||||
setupStartup();
|
||||
setupUi();
|
||||
}
|
||||
|
||||
void OptionsPage::setPasswordEdited(bool v)
|
||||
{
|
||||
m_passwordEdited = v;
|
||||
}
|
||||
|
||||
void OptionsPage::onAboutToSave()
|
||||
{
|
||||
// Startup
|
||||
@ -97,6 +93,12 @@ void OptionsPage::onEditResetted()
|
||||
// Password
|
||||
setPasswordEdited(false);
|
||||
retranslateEditPassword();
|
||||
|
||||
// Language
|
||||
if (languageEdited()) {
|
||||
setLanguageEdited(false);
|
||||
translationManager()->switchLanguageByName(confManager()->iniUser()->language());
|
||||
}
|
||||
}
|
||||
|
||||
void OptionsPage::saveAutoRunMode(int mode)
|
||||
@ -464,7 +466,7 @@ void OptionsPage::setupGlobalBox()
|
||||
|
||||
m_cbHotKeys = ControlUtil::createCheckBox(iniUser()->hotKeyEnabled(), [&](bool checked) {
|
||||
iniUser()->setHotKeyEnabled(checked);
|
||||
confManager()->saveIniUser(true);
|
||||
ctrl()->setIniUserEdited(/*flagsChanged=*/true);
|
||||
});
|
||||
|
||||
// Password Row
|
||||
@ -555,8 +557,9 @@ void OptionsPage::setupComboLanguage()
|
||||
m_comboLanguage =
|
||||
ControlUtil::createComboBox(translationManager()->displayLabels(), [&](int index) {
|
||||
if (translationManager()->switchLanguage(index)) {
|
||||
setLanguageEdited(true);
|
||||
iniUser()->setLanguage(translationManager()->localeName());
|
||||
confManager()->saveIniUser();
|
||||
ctrl()->setIniUserEdited();
|
||||
}
|
||||
});
|
||||
m_comboLanguage->setFixedWidth(200);
|
||||
@ -575,7 +578,7 @@ void OptionsPage::setupTrayBox()
|
||||
m_cbTrayAnimateAlert =
|
||||
ControlUtil::createCheckBox(iniUser()->trayAnimateAlert(), [&](bool checked) {
|
||||
iniUser()->setTrayAnimateAlert(checked);
|
||||
confManager()->saveIniUser(true);
|
||||
ctrl()->setIniUserEdited();
|
||||
});
|
||||
|
||||
// Tray Event & Action Rows
|
||||
@ -594,8 +597,11 @@ void OptionsPage::setupTrayBox()
|
||||
|
||||
void OptionsPage::refreshComboTrayAction()
|
||||
{
|
||||
const TrayIcon::ActionType actionType = windowManager()->trayIcon()->clickEventActionType(
|
||||
static_cast<TrayIcon::ClickType>(m_comboTrayEvent->currentIndex()));
|
||||
const TrayIcon::ClickType clickType =
|
||||
static_cast<TrayIcon::ClickType>(m_comboTrayEvent->currentIndex());
|
||||
|
||||
const TrayIcon::ActionType actionType = TrayIcon::clickEventActionType(iniUser(), clickType);
|
||||
|
||||
m_comboTrayAction->setCurrentIndex(actionType);
|
||||
}
|
||||
|
||||
@ -615,9 +621,12 @@ QLayout *OptionsPage::setupTrayActionLayout()
|
||||
m_labelTrayAction = ControlUtil::createLabel();
|
||||
|
||||
m_comboTrayAction = ControlUtil::createComboBox(QStringList(), [&](int index) {
|
||||
windowManager()->trayIcon()->setClickEventActionType(
|
||||
static_cast<TrayIcon::ClickType>(m_comboTrayEvent->currentIndex()),
|
||||
static_cast<TrayIcon::ActionType>(index));
|
||||
const TrayIcon::ClickType clickType =
|
||||
static_cast<TrayIcon::ClickType>(m_comboTrayEvent->currentIndex());
|
||||
const TrayIcon::ActionType actionType = static_cast<TrayIcon::ActionType>(index);
|
||||
|
||||
TrayIcon::setClickEventActionType(iniUser(), clickType, actionType);
|
||||
ctrl()->setIniUserEdited(/*flagsChanged=*/true);
|
||||
});
|
||||
m_comboTrayAction->setFixedWidth(200);
|
||||
|
||||
@ -626,10 +635,15 @@ QLayout *OptionsPage::setupTrayActionLayout()
|
||||
|
||||
void OptionsPage::setupConfirmationsBox()
|
||||
{
|
||||
m_cbConfirmTrayFlags = ControlUtil::createCheckBox(iniUser()->confirmTrayFlags(),
|
||||
[&](bool checked) { iniUser()->setConfirmTrayFlags(checked); });
|
||||
m_cbConfirmQuit = ControlUtil::createCheckBox(
|
||||
iniUser()->confirmQuit(), [&](bool checked) { iniUser()->setConfirmQuit(checked); });
|
||||
m_cbConfirmTrayFlags =
|
||||
ControlUtil::createCheckBox(iniUser()->confirmTrayFlags(), [&](bool checked) {
|
||||
iniUser()->setConfirmTrayFlags(checked);
|
||||
ctrl()->setIniUserEdited();
|
||||
});
|
||||
m_cbConfirmQuit = ControlUtil::createCheckBox(iniUser()->confirmQuit(), [&](bool checked) {
|
||||
iniUser()->setConfirmQuit(checked);
|
||||
ctrl()->setIniUserEdited();
|
||||
});
|
||||
|
||||
auto layout = new QVBoxLayout();
|
||||
layout->addWidget(m_cbConfirmTrayFlags);
|
||||
|
@ -11,7 +11,10 @@ public:
|
||||
explicit OptionsPage(OptionsController *ctrl = nullptr, QWidget *parent = nullptr);
|
||||
|
||||
bool passwordEdited() const { return m_passwordEdited; }
|
||||
void setPasswordEdited(bool v);
|
||||
void setPasswordEdited(bool v) { m_passwordEdited = v; }
|
||||
|
||||
bool languageEdited() const { return m_languageEdited; }
|
||||
void setLanguageEdited(bool v) { m_languageEdited = v; }
|
||||
|
||||
protected slots:
|
||||
void onAboutToSave() override;
|
||||
@ -57,7 +60,8 @@ private:
|
||||
void setupNewVersionUpdate();
|
||||
|
||||
private:
|
||||
bool m_passwordEdited = false;
|
||||
bool m_passwordEdited : 1;
|
||||
bool m_languageEdited : 1;
|
||||
|
||||
qint8 m_currentAutoRunMode = 0;
|
||||
|
||||
|
@ -135,7 +135,7 @@ void OptMainPage::setupOkApplyButtons()
|
||||
m_btApply->setEnabled(anyEdited);
|
||||
};
|
||||
|
||||
refreshOkApplyButtons(conf()->anyEdited());
|
||||
refreshOkApplyButtons(ctrl()->anyEdited());
|
||||
|
||||
connect(ctrl(), &OptionsController::editedChanged, this, refreshOkApplyButtons);
|
||||
}
|
||||
|
@ -242,9 +242,10 @@ void TrayIcon::updateTrayMenu(bool onlyFlags)
|
||||
updateAppGroupActions();
|
||||
}
|
||||
|
||||
updateTrayIconShape();
|
||||
updateTrayMenuFlags();
|
||||
updateTrayIconShape();
|
||||
updateHotKeys();
|
||||
updateClickActions();
|
||||
}
|
||||
|
||||
void TrayIcon::switchTrayMenu(bool /*checked*/)
|
||||
@ -301,8 +302,6 @@ void TrayIcon::setupUi()
|
||||
|
||||
setupTrayMenu();
|
||||
updateTrayMenu();
|
||||
|
||||
updateClickActions();
|
||||
}
|
||||
|
||||
void TrayIcon::setupTrayMenu()
|
||||
@ -588,23 +587,21 @@ void TrayIcon::removeHotKeys()
|
||||
hotKeyManager()->removeActions();
|
||||
}
|
||||
|
||||
TrayIcon::ActionType TrayIcon::clickEventActionType(ClickType clickType) const
|
||||
TrayIcon::ActionType TrayIcon::clickEventActionType(IniUser *iniUser, ClickType clickType)
|
||||
{
|
||||
const QString eventName = clickNameByType(clickType);
|
||||
const QString actionName = iniUser()->trayAction(eventName);
|
||||
const QString actionName = iniUser->trayAction(eventName);
|
||||
|
||||
const ActionType actionType = actionTypeByName(actionName);
|
||||
return (actionType != ActionNone) ? actionType : defaultActionTypeByClick(clickType);
|
||||
}
|
||||
|
||||
void TrayIcon::setClickEventActionType(ClickType clickType, ActionType actionType)
|
||||
void TrayIcon::setClickEventActionType(IniUser *iniUser, ClickType clickType, ActionType actionType)
|
||||
{
|
||||
const QString eventName = clickNameByType(clickType);
|
||||
const QString actionName = actionNameByType(actionType);
|
||||
|
||||
iniUser()->setTrayAction(eventName, actionName);
|
||||
|
||||
updateClickActions();
|
||||
iniUser->setTrayAction(eventName, actionName);
|
||||
}
|
||||
|
||||
void TrayIcon::updateClickActions()
|
||||
@ -622,7 +619,7 @@ QAction *TrayIcon::clickAction(ClickType clickType) const
|
||||
|
||||
QAction *TrayIcon::clickActionFromIni(ClickType clickType) const
|
||||
{
|
||||
const ActionType actionType = clickEventActionType(clickType);
|
||||
const ActionType actionType = clickEventActionType(iniUser(), clickType);
|
||||
|
||||
return clickActionByType(actionType);
|
||||
}
|
||||
|
@ -56,8 +56,9 @@ public:
|
||||
DriverManager *driverManager() const;
|
||||
WindowManager *windowManager() const;
|
||||
|
||||
ActionType clickEventActionType(ClickType clickType) const;
|
||||
void setClickEventActionType(ClickType clickType, ActionType actionType);
|
||||
static ActionType clickEventActionType(IniUser *iniUser, ClickType clickType);
|
||||
static void setClickEventActionType(
|
||||
IniUser *iniUser, ClickType clickType, ActionType actionType);
|
||||
|
||||
public slots:
|
||||
void updateTrayIcon(bool alerted = false);
|
||||
|
@ -10,6 +10,7 @@ public:
|
||||
explicit MapWrapper() = default;
|
||||
explicit MapWrapper(const QVariant &var);
|
||||
explicit MapWrapper(const MapWrapper &o);
|
||||
virtual ~MapWrapper() = default;
|
||||
|
||||
const QVariantMap &map() const { return m_map; }
|
||||
void setMap(const QVariantMap &map) { m_map = map; }
|
||||
|
Loading…
Reference in New Issue
Block a user