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); 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()); Q_ASSERT(m_firewallConfToEdit != nullConf());
@ -158,7 +158,7 @@ bool FortManager::applyConf()
newConf->copyTempFlags(*m_firewallConf); newConf->copyTempFlags(*m_firewallConf);
return saveSettings(newConf); return saveSettings(newConf, onlyFlags);
} }
void FortManager::setFirewallConfToEdit(FirewallConf *conf) void FortManager::setFirewallConfToEdit(FirewallConf *conf)
@ -182,9 +182,10 @@ bool FortManager::loadSettings(FirewallConf *conf)
return updateDriverConf(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()); showErrorBox(m_fortSettings->errorMessage());
return false; return false;
} }
@ -194,7 +195,8 @@ bool FortManager::saveSettings(FirewallConf *newConf)
updateTrayMenu(); updateTrayMenu();
return updateDriverConf(m_firewallConf); return onlyFlags ? updateDriverConfFlags(m_firewallConf)
: updateDriverConf(m_firewallConf);
} }
bool FortManager::updateDriverConf(FirewallConf *conf) bool FortManager::updateDriverConf(FirewallConf *conf)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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