UI: ConfManager: Remove "immediateFlags" arg from save().

This commit is contained in:
Nodir Temirkhodjaev 2021-05-05 10:22:22 +03:00
parent ec5d5c2864
commit b6eb4e2c41
7 changed files with 24 additions and 23 deletions

View File

@ -476,7 +476,7 @@ bool ConfManager::load(bool onlyFlags)
return true; return true;
} }
bool ConfManager::saveToDbIni(FirewallConf &newConf, bool onlyFlags) bool ConfManager::saveConf(FirewallConf &newConf, bool onlyFlags)
{ {
if (!onlyFlags && !saveToDb(newConf)) if (!onlyFlags && !saveToDb(newConf))
return false; return false;
@ -486,36 +486,34 @@ bool ConfManager::saveToDbIni(FirewallConf &newConf, bool onlyFlags)
return true; return true;
} }
void ConfManager::applySavedConf(FirewallConf *newConf, bool onlyFlags, bool immediateFlags) void ConfManager::applySavedConf(FirewallConf *newConf, bool onlyFlags)
{ {
if (conf() != newConf) { if (conf() != newConf) {
if (!onlyFlags) { if (onlyFlags) {
setConf(newConf);
} else if (!immediateFlags) {
conf()->copyFlags(*newConf); conf()->copyFlags(*newConf);
} else { } else {
conf()->copyImmediateFlags(*newConf); setConf(newConf);
} }
} }
emit confChanged(onlyFlags); emit confChanged(onlyFlags);
} }
bool ConfManager::save(FirewallConf *newConf, bool onlyFlags, bool immediateFlags) bool ConfManager::save(FirewallConf *newConf, bool onlyFlags)
{ {
++m_confVersion; // change version on each save attempt ++m_confVersion; // change version on each save attempt
if (!saveToDbIni(*newConf, onlyFlags)) if (!saveConf(*newConf, onlyFlags))
return false; return false;
applySavedConf(newConf, onlyFlags, immediateFlags); applySavedConf(newConf, onlyFlags);
return true; return true;
} }
bool ConfManager::saveFlags(bool immediateFlags) bool ConfManager::saveFlags()
{ {
return save(conf(), true, immediateFlags); return save(conf(), true);
} }
bool ConfManager::saveVariant(const QVariant &v, int confVersion, bool onlyFlags) bool ConfManager::saveVariant(const QVariant &v, int confVersion, bool onlyFlags)
@ -523,7 +521,7 @@ bool ConfManager::saveVariant(const QVariant &v, int confVersion, bool onlyFlags
auto conf = createConf(); auto conf = createConf();
conf->fromVariant(v, onlyFlags); conf->fromVariant(v, onlyFlags);
if (!saveToDbIni(*conf, onlyFlags)) { if (!saveConf(*conf, onlyFlags)) {
delete conf; delete conf;
return false; return false;
} }

View File

@ -45,11 +45,11 @@ public:
bool load(bool onlyFlags = false); bool load(bool onlyFlags = false);
virtual bool saveToDbIni(FirewallConf &newConf, bool onlyFlags); virtual bool saveConf(FirewallConf &newConf, bool onlyFlags);
void applySavedConf(FirewallConf *newConf, bool onlyFlags = false, bool immediateFlags = false); void applySavedConf(FirewallConf *newConf, bool onlyFlags = false);
bool save(FirewallConf *newConf, bool onlyFlags = false, bool immediateFlags = false); bool save(FirewallConf *newConf, bool onlyFlags = false);
bool saveFlags();
bool saveFlags(bool immediateFlags = false);
bool saveVariant(const QVariant &v, int confVersion, bool onlyFlags = false); bool saveVariant(const QVariant &v, int confVersion, bool onlyFlags = false);
bool loadTasks(const QList<TaskInfo *> &taskInfos); bool loadTasks(const QList<TaskInfo *> &taskInfos);

View File

@ -235,7 +235,7 @@ void ConnectionsWindow::setupLogAllowedIp()
conf()->setLogAllowedIp(checked); conf()->setLogAllowedIp(checked);
confManager()->saveFlags(true); confManager()->saveFlags();
}); });
m_cbLogAllowedIp->setVisible(false); // TODO: Collect allowed connections m_cbLogAllowedIp->setVisible(false); // TODO: Collect allowed connections
@ -249,7 +249,7 @@ void ConnectionsWindow::setupLogBlockedIp()
conf()->setLogBlockedIp(checked); conf()->setLogBlockedIp(checked);
confManager()->saveFlags(true); confManager()->saveFlags();
}); });
} }

View File

@ -110,7 +110,7 @@ void OptionsController::save(bool closeOnSuccess)
bool onlyFlags = true; bool onlyFlags = true;
if (confFlagsEdited() || confEdited()) { if (confFlagsEdited() || confEdited()) {
onlyFlags = confFlagsEdited() && !confEdited(); onlyFlags = confFlagsEdited() && !confEdited();
if (!confManager()->saveToDbIni(*conf(), onlyFlags)) if (!confManager()->saveConf(*conf(), onlyFlags))
return; return;
} }
@ -130,7 +130,10 @@ void OptionsController::save(bool closeOnSuccess)
void OptionsController::applyImmediateFlags() void OptionsController::applyImmediateFlags()
{ {
confManager()->save(conf(), true, true); FirewallConf *originConf = confManager()->conf();
originConf->copyImmediateFlags(*conf());
confManager()->saveFlags();
} }
void OptionsController::emitEditedChanged() void OptionsController::emitEditedChanged()

View File

@ -253,7 +253,7 @@ void ProgramsWindow::setupLogBlocked()
conf()->setLogBlocked(checked); conf()->setLogBlocked(checked);
confManager()->saveFlags(true); confManager()->saveFlags();
}); });
m_cbLogBlocked->setFont(ControlUtil::fontDemiBold()); m_cbLogBlocked->setFont(ControlUtil::fontDemiBold());

View File

@ -34,7 +34,7 @@ void ConfManagerRpc::onConfChanged(int confVersion, bool onlyFlags)
fortManager()->reloadOptionsWindow(tr("Settings changed by someone else")); fortManager()->reloadOptionsWindow(tr("Settings changed by someone else"));
} }
bool ConfManagerRpc::saveToDbIni(FirewallConf &newConf, bool onlyFlags) bool ConfManagerRpc::saveConf(FirewallConf &newConf, bool onlyFlags)
{ {
rpcManager()->invokeOnServer(Control::Rpc_ConfManager_save, rpcManager()->invokeOnServer(Control::Rpc_ConfManager_save,
{ newConf.toVariant(onlyFlags), confVersion(), onlyFlags }); { newConf.toVariant(onlyFlags), confVersion(), onlyFlags });

View File

@ -20,7 +20,7 @@ public:
protected: protected:
void setupAppEndTimer() override { } void setupAppEndTimer() override { }
bool saveToDbIni(FirewallConf &newConf, bool onlyFlags) override; bool saveConf(FirewallConf &newConf, bool onlyFlags) override;
}; };
#endif // CONFMANAGERRPC_H #endif // CONFMANAGERRPC_H