mirror of
https://github.com/tnodir/fort
synced 2024-11-15 05:57:57 +00:00
UI: Rules: Add Preset Rules bit mask
This commit is contained in:
parent
5aa81d53d2
commit
12d10a1b99
@ -20,13 +20,14 @@ const QLoggingCategory LC("confRule");
|
||||
|
||||
const char *const sqlInsertRule = "INSERT INTO rule(rule_id, enabled, blocked, exclusive,"
|
||||
" name, notes, rule_text, rule_type,"
|
||||
" accept_zones, reject_zones, mod_time)"
|
||||
" VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11);";
|
||||
" accept_zones, reject_zones, preset_rules, mod_time)"
|
||||
" VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12);";
|
||||
|
||||
const char *const sqlUpdateRule = "UPDATE rule"
|
||||
" SET enabled = ?2, blocked = ?3, exclusive = ?4,"
|
||||
" name = ?5, notes = ?6, rule_text = ?7, rule_type = ?8,"
|
||||
" accept_zones = ?9, reject_zones = ?10, mod_time = ?11"
|
||||
" accept_zones = ?9, reject_zones = ?10,"
|
||||
" preset_rules = ?11, mod_time = ?12"
|
||||
" WHERE rule_id = ?1;";
|
||||
|
||||
const char *const sqlSelectRuleIds = "SELECT rule_id FROM rule"
|
||||
@ -38,6 +39,10 @@ const char *const sqlDeleteAppRule = "UPDATE app"
|
||||
" SET app_rules = app_rules & ~?1"
|
||||
" WHERE (app_rules & ?1) <> 0;";
|
||||
|
||||
const char *const sqlDeletePresetRule = "UPDATE rule"
|
||||
" SET preset_rules = preset_rules & ~?1"
|
||||
" WHERE (preset_rules & ?1) <> 0;";
|
||||
|
||||
const char *const sqlUpdateRuleName = "UPDATE rule SET name = ?2 WHERE rule_id = ?1;";
|
||||
|
||||
const char *const sqlUpdateRuleEnabled = "UPDATE rule SET enabled = ?2 WHERE rule_id = ?1;";
|
||||
@ -108,6 +113,7 @@ bool ConfRuleManager::addOrUpdateRule(Rule &rule)
|
||||
rule.ruleType,
|
||||
rule.acceptZones,
|
||||
rule.rejectZones,
|
||||
rule.presetRules,
|
||||
DateUtil::now(),
|
||||
};
|
||||
|
||||
@ -140,8 +146,18 @@ bool ConfRuleManager::deleteRule(int ruleId)
|
||||
const quint32 ruleBit = (quint32(1) << (ruleId - 1));
|
||||
const QVariantList vars = { ruleBit };
|
||||
|
||||
// Delete the Rule from Programs
|
||||
DbUtil(sqliteDb(), &ok).sql(sqlDeleteAppRule).vars(vars).executeOk();
|
||||
const auto ruleType = Rule::getRuleTypeById(ruleId);
|
||||
|
||||
switch (ruleType) {
|
||||
case Rule::AppRule: {
|
||||
// Delete the App Rule from Programs
|
||||
DbUtil(sqliteDb(), &ok).sql(sqlDeleteAppRule).vars(vars).executeOk();
|
||||
} break;
|
||||
case Rule::PresetRule: {
|
||||
// Delete the Preset Rule from Rules
|
||||
DbUtil(sqliteDb(), &ok).sql(sqlDeletePresetRule).vars(vars).executeOk();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
commitTransaction(ok);
|
||||
|
@ -96,6 +96,7 @@ CREATE TABLE rule(
|
||||
rule_type INTEGER NOT NULL, -- app rules, global before/after apps, preset rules
|
||||
accept_zones INTEGER NOT NULL DEFAULT 0, -- zone ids bit mask
|
||||
reject_zones INTEGER NOT NULL DEFAULT 0, -- zone ids bit mask
|
||||
preset_rules INTEGER NOT NULL DEFAULT 0, -- rule ids bit mask
|
||||
mod_time INTEGER NOT NULL
|
||||
);
|
||||
|
||||
|
@ -9,7 +9,8 @@ bool Rule::isOptionsEqual(const Rule &o) const
|
||||
{
|
||||
return enabled == o.enabled && blocked == o.blocked && exclusive == o.exclusive
|
||||
&& acceptZones == o.acceptZones && rejectZones == o.rejectZones
|
||||
&& ruleName == o.ruleName && notes == o.notes && ruleText == o.ruleText;
|
||||
&& presetRules == o.presetRules && ruleName == o.ruleName && notes == o.notes
|
||||
&& ruleText == o.ruleText;
|
||||
}
|
||||
|
||||
Rule::RuleType Rule::getRuleTypeById(int ruleId)
|
||||
|
@ -39,6 +39,8 @@ public:
|
||||
quint32 acceptZones = 0;
|
||||
quint32 rejectZones = 0;
|
||||
|
||||
quint32 presetRules = 0;
|
||||
|
||||
QString ruleName;
|
||||
QString notes;
|
||||
QString ruleText;
|
||||
|
@ -329,7 +329,8 @@ bool RuleListModel::updateRuleRow(
|
||||
ruleRow.ruleType = Rule::RuleType(stmt.columnInt(7));
|
||||
ruleRow.acceptZones = stmt.columnUInt(8);
|
||||
ruleRow.rejectZones = stmt.columnUInt(9);
|
||||
ruleRow.modTime = stmt.columnDateTime(10);
|
||||
ruleRow.presetRules = stmt.columnUInt(10);
|
||||
ruleRow.modTime = stmt.columnDateTime(11);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -347,6 +348,7 @@ QString RuleListModel::sqlBase() const
|
||||
" rule_type,"
|
||||
" accept_zones,"
|
||||
" reject_zones,"
|
||||
" preset_rules,"
|
||||
" mod_time"
|
||||
" FROM rule t"
|
||||
" WHERE rule_type = :type";
|
||||
|
@ -95,7 +95,8 @@ bool ConfRuleManagerRpc::updateRuleEnabled(int ruleId, bool enabled)
|
||||
QVariantList ConfRuleManagerRpc::ruleToVarList(const Rule &rule)
|
||||
{
|
||||
return { rule.enabled, rule.blocked, rule.exclusive, rule.ruleType, rule.ruleId,
|
||||
rule.acceptZones, rule.rejectZones, rule.ruleName, rule.notes, rule.ruleText };
|
||||
rule.acceptZones, rule.rejectZones, rule.presetRules, rule.ruleName, rule.notes,
|
||||
rule.ruleText };
|
||||
}
|
||||
|
||||
Rule ConfRuleManagerRpc::varListToRule(const QVariantList &v)
|
||||
@ -108,9 +109,10 @@ Rule ConfRuleManagerRpc::varListToRule(const QVariantList &v)
|
||||
rule.ruleId = v.value(4).toInt();
|
||||
rule.acceptZones = v.value(5).toUInt();
|
||||
rule.rejectZones = v.value(6).toUInt();
|
||||
rule.ruleName = v.value(7).toString();
|
||||
rule.notes = v.value(8).toString();
|
||||
rule.ruleText = v.value(9).toString();
|
||||
rule.presetRules = v.value(7).toUInt();
|
||||
rule.ruleName = v.value(8).toString();
|
||||
rule.notes = v.value(9).toString();
|
||||
rule.ruleText = v.value(10).toString();
|
||||
return rule;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user