summaryrefslogtreecommitdiff
path: root/src/rulesDialog.cpp
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2024-03-15 15:41:31 -0400
committerLouie S <louie@example.com>2024-03-15 15:41:31 -0400
commitd732bd0f74225828455c5863444b0211faf586d0 (patch)
tree4c605e694cc02521c9fddb05a710c62d66a97e55 /src/rulesDialog.cpp
parent3e1d2e46ceea202120b4ff814fbd872bc6fc60f3 (diff)
Add backend for rules dialog
Diffstat (limited to 'src/rulesDialog.cpp')
-rw-r--r--src/rulesDialog.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/rulesDialog.cpp b/src/rulesDialog.cpp
index b856ebb..be8b9d3 100644
--- a/src/rulesDialog.cpp
+++ b/src/rulesDialog.cpp
@@ -59,7 +59,6 @@ void RulesDialog::drawRules() {
}
void RulesDialog::addRule() {
- // TODO handle in db backend to insert instead of updating if id is 0
Rule *new_rule = new Rule(0, this->entry_id, Rule::before);
RuleLayout *new_layout = new RuleLayout(*new_rule);
@@ -76,6 +75,33 @@ void RulesDialog::deleteRule(int i) {
if(i >= this->rules.size()) return;
this->updateRulesList();
+ // mark as needing to be deleted from database if id > 0
+ if(this->rules[i]->id > 0)
+ this->deleted_rules.append(*this->rules[i]);
this->rules.removeAt(i);
this->drawRules();
}
+
+void RulesDialog::accept() {
+ int i;
+ BackendDB database;
+
+ this->updateRulesList();
+
+ // update rules in database
+ for(i = 0; i < this->rules.size(); ++i) {
+ // insert - this is a new rule
+ if(this->rules[i]->id == 0)
+ database.insertRule(*this->rules[i]);
+ // update - this is an existing rule
+ else
+ database.updateRule(*this->rules[i]);
+ }
+
+ // delete deleted rules in database
+ for(i = 0; i < this->deleted_rules.size(); ++i) {
+ database.removeRule(this->deleted_rules[i]);
+ }
+
+ QDialog::accept();
+}