1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
namespace Dino.Entities {
public class Settings : Object {
private Database db;
public Settings.from_db(Database db) {
this.db = db;
send_typing_ = col_to_bool_or_default("send_typing", true);
send_marker_ = col_to_bool_or_default("send_marker", true);
notifications_ = col_to_bool_or_default("notifications", true);
convert_utf8_smileys_ = col_to_bool_or_default("convert_utf8_smileys", true);
check_spelling = col_to_bool_or_default("check_spelling", true);
default_encryption = col_to_encryption_or_default("default_encryption", Encryption.OMEMO);
send_button = col_to_bool_or_default("send_button", false);
enter_newline = col_to_bool_or_default("enter_newline", false);
quit_ctrl_q = col_to_bool_or_default("quit_ctrl_q", true);
}
private bool col_to_bool_or_default(string key, bool def) {
string? val = db.settings.select({db.settings.value}).with(db.settings.key, "=", key)[db.settings.value];
return val != null ? bool.parse(val) : def;
}
private Encryption col_to_encryption_or_default(string key, Encryption def) {
var sval = db.settings.value;
string? val = db.settings.select({sval}).with(db.settings.key, "=", key)[sval];
return val != null ? Encryption.parse(val) : def;
}
private bool send_typing_;
public bool send_typing {
get { return send_typing_; }
set {
db.settings.upsert()
.value(db.settings.key, "send_typing", true)
.value(db.settings.value, value.to_string())
.perform();
send_typing_ = value;
}
}
private bool send_marker_;
public bool send_marker {
get { return send_marker_; }
set {
db.settings.upsert()
.value(db.settings.key, "send_marker", true)
.value(db.settings.value, value.to_string())
.perform();
send_marker_ = value;
}
}
private bool notifications_;
public bool notifications {
get { return notifications_; }
set {
db.settings.upsert()
.value(db.settings.key, "notifications", true)
.value(db.settings.value, value.to_string())
.perform();
notifications_ = value;
}
}
private bool convert_utf8_smileys_;
public bool convert_utf8_smileys {
get { return convert_utf8_smileys_; }
set {
db.settings.upsert()
.value(db.settings.key, "convert_utf8_smileys", true)
.value(db.settings.value, value.to_string())
.perform();
convert_utf8_smileys_ = value;
}
}
private bool check_spelling_;
public bool check_spelling {
get { return check_spelling_; }
set {
db.settings.upsert()
.value(db.settings.key, "check_spelling", true)
.value(db.settings.value, value.to_string())
.perform();
check_spelling_ = value;
}
}
private Encryption default_encryption_;
public Encryption default_encryption {
get { return default_encryption_; }
set {
string valstr = value.to_string();
db.settings.upsert()
.value(db.settings.key, "default_encryption", true)
.value(db.settings.value, valstr)
.perform();
default_encryption_ = value;
}
}
public signal void send_button_update(bool visible);
private bool send_button_;
public bool send_button {
get { return send_button_; }
set {
db.settings.upsert()
.value(db.settings.key, "send_button", true)
.value(db.settings.value, value.to_string())
.perform();
send_button_ = value;
send_button_update(value);
}
}
private bool enter_newline_;
public bool enter_newline {
get { return enter_newline_; }
set {
db.settings.upsert()
.value(db.settings.key, "enter_newline", true)
.value(db.settings.value, value.to_string())
.perform();
enter_newline_ = value;
}
}
public signal void quit_ctrl_q_update(bool active);
private bool quit_ctrl_q_;
public bool quit_ctrl_q {
get { return quit_ctrl_q_; }
set {
db.settings.upsert()
.value(db.settings.key, "quit_ctrl_q", true)
.value(db.settings.value, value.to_string())
.perform();
quit_ctrl_q_ = value;
quit_ctrl_q_update(value);
}
}
}
}
|