UI: Save only flags when needed.

This commit is contained in:
Nodir Temirkhodjaev 2017-09-07 10:34:18 +05:00
parent 3080159de7
commit 2177fc3b33
7 changed files with 65 additions and 12 deletions

View File

@ -145,12 +145,12 @@ void FortManager::showErrorBox(const QString &text)
QMessageBox::critical(&m_window, QString(), text);
}
bool FortManager::saveConf()
bool FortManager::saveConf(bool onlyFlags)
{
return saveSettings(m_firewallConfToEdit);
return saveSettings(m_firewallConfToEdit, onlyFlags);
}
bool FortManager::applyConf()
bool FortManager::applyConf(bool onlyFlags)
{
Q_ASSERT(m_firewallConfToEdit != nullConf());
@ -158,7 +158,7 @@ bool FortManager::applyConf()
newConf->copyTempFlags(*m_firewallConf);
return saveSettings(newConf);
return saveSettings(newConf, onlyFlags);
}
void FortManager::setFirewallConfToEdit(FirewallConf *conf)
@ -182,9 +182,10 @@ bool FortManager::loadSettings(FirewallConf *conf)
return updateDriverConf(conf);
}
bool FortManager::saveSettings(FirewallConf *newConf)
bool FortManager::saveSettings(FirewallConf *newConf, bool onlyFlags)
{
if (!m_fortSettings->writeConf(*newConf)) {
if (!(onlyFlags ? m_fortSettings->writeConfFlags(*newConf)
: m_fortSettings->writeConf(*newConf))) {
showErrorBox(m_fortSettings->errorMessage());
return false;
}
@ -194,7 +195,8 @@ bool FortManager::saveSettings(FirewallConf *newConf)
updateTrayMenu();
return updateDriverConf(m_firewallConf);
return onlyFlags ? updateDriverConfFlags(m_firewallConf)
: updateDriverConf(m_firewallConf);
}
bool FortManager::updateDriverConf(FirewallConf *conf)

View File

@ -43,8 +43,8 @@ public slots:
void showErrorBox(const QString &text);
bool saveConf();
bool applyConf();
bool saveConf(bool onlyFlags = false);
bool applyConf(bool onlyFlags = false);
void setAppLogBlocked(bool enable);
@ -63,7 +63,7 @@ private:
void setupEngine();
bool loadSettings(FirewallConf *conf);
bool saveSettings(FirewallConf *newConf);
bool saveSettings(FirewallConf *newConf, bool onlyFlags = false);
bool updateDriverConf(FirewallConf *conf);
bool updateDriverConfFlags(FirewallConf *conf);

View File

@ -19,6 +19,8 @@ BasePage {
firewallConf.addAppGroupByName(editGroupName.text);
barGroups.currentIndex = lastIndex;
resetGroupName();
setConfEdited();
}
function removeAppGroup(index) {
@ -26,12 +28,16 @@ BasePage {
var lastIndex = appGroupsCount - 1;
barGroups.currentIndex = (index < appGroupsCount)
? index : appGroupsCount - 1;
setConfEdited();
}
function renameAppGroup() {
const appGroup = appsColumn.appGroup;
appGroup.name = editGroupName.text;
resetGroupName();
setConfEdited();
}
function moveAppGroup(index, step) {
@ -43,6 +49,8 @@ BasePage {
firewallConf.moveAppGroup(index, toIndex);
barGroups.currentIndex = toIndex;
setConfEdited();
}
ColumnLayout {
@ -74,6 +82,8 @@ BasePage {
checked: firewallConf.appBlockAll
onToggled: {
firewallConf.appBlockAll = checked;
setConfFlagsEdited();
}
}
CheckBox {
@ -81,6 +91,8 @@ BasePage {
checked: firewallConf.appAllowAll
onToggled: {
firewallConf.appAllowAll = checked;
setConfFlagsEdited();
}
}
}

View File

@ -10,7 +10,25 @@ Page {
signal closed()
signal saved()
property bool confFlagsEdited
property bool confEdited
function setConfFlagsEdited() {
confFlagsEdited = true;
}
function setConfEdited() {
confEdited = true;
}
function resetConfEdited() {
confFlagsEdited = false;
confEdited = false;
}
onOpened: {
resetConfEdited();
tabBar.currentItem.forceActiveFocus();
}
@ -52,17 +70,23 @@ Page {
anchors.right: parent.right
Button {
enabled: confFlagsEdited || confEdited
text: QT_TRANSLATE_NOOP("qml", "OK")
onClicked: {
if (fortManager.saveConf()) {
if (fortManager.saveConf(confFlagsEdited)) {
mainPage.saved();
closeWindow();
}
}
}
Button {
enabled: confFlagsEdited || confEdited
text: QT_TRANSLATE_NOOP("qml", "Apply")
onClicked: fortManager.applyConf()
onClicked: {
if (fortManager.applyConf(confFlagsEdited)) {
resetConfEdited();
}
}
}
Button {
text: QT_TRANSLATE_NOOP("qml", "Cancel")

View File

@ -20,6 +20,9 @@ BasePage {
id: cbStart
text: QT_TRANSLATE_NOOP("qml", "Start with Windows")
checked: fortSettings.startWithWindows
onToggled: {
setConfFlagsEdited();
}
}
CheckBox {
id: cbFilter
@ -27,6 +30,8 @@ BasePage {
checked: firewallConf.filterEnabled
onToggled: {
firewallConf.filterEnabled = checked;
setConfFlagsEdited();
}
}
}

View File

@ -25,6 +25,8 @@ ColumnLayout {
checked: addressGroup.useAll
onToggled: {
addressGroup.useAll = checked;
setConfFlagsEdited();
}
}
}
@ -46,6 +48,8 @@ ColumnLayout {
onEditingFinished: {
addressGroup.text = textArea.text;
setConfEdited();
}
}
}

View File

@ -31,6 +31,8 @@ ColumnLayout {
checked: appGroup.enabled
onToggled: {
appGroup.enabled = checked;
setConfFlagsEdited();
}
}
}
@ -54,6 +56,8 @@ C:\\Program Files\\Internet Explorer\\iexplore.exe
onEditingFinished: {
appGroup.blockText = textArea.text;
setConfEdited();
}
}
@ -72,6 +76,8 @@ C:\\Program Files\\Skype\\Phone\\Skype.exe
onEditingFinished: {
appGroup.allowText = textArea.text;
setConfEdited();
}
}
}