From 20e63e364b45894d481a35e019602183255e3496 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 25 Nov 2015 21:24:21 +0000 Subject: Finished basic /notify triggers --- src/config/preferences.c | 133 ++++++++++++++++++++++++++++++++--------------- src/config/preferences.h | 5 +- 2 files changed, 93 insertions(+), 45 deletions(-) (limited to 'src/config') diff --git a/src/config/preferences.c b/src/config/preferences.c index d8ddd159..fa371cf0 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -130,6 +130,19 @@ prefs_load(void) prefs_free_string(time); } + // move pre 0.4.8 notify settings + if (g_key_file_has_key(prefs, PREF_GROUP_NOTIFICATIONS, "room", NULL)) { + char *value = g_key_file_get_string(prefs, PREF_GROUP_NOTIFICATIONS, "room", NULL); + if (g_strcmp0(value, "on") == 0) { + g_key_file_set_boolean(prefs, PREF_GROUP_NOTIFICATIONS, "room", TRUE); + } else if (g_strcmp0(value, "off") == 0) { + g_key_file_set_boolean(prefs, PREF_GROUP_NOTIFICATIONS, "room", FALSE); + } else if (g_strcmp0(value, "mention") == 0) { + g_key_file_set_boolean(prefs, PREF_GROUP_NOTIFICATIONS, "room", FALSE); + g_key_file_set_boolean(prefs, PREF_GROUP_NOTIFICATIONS, "room.mention", TRUE); + } + } + _save_prefs(); boolean_choice_ac = autocomplete_new(); @@ -207,42 +220,43 @@ prefs_reset_room_trigger_ac(void) gboolean prefs_get_notify_chat(gboolean current_win, const char *const message) { - gboolean notify_message = prefs_get_boolean(PREF_NOTIFY_MESSAGE); - - gboolean notify_trigger = prefs_get_boolean(PREF_NOTIFY_MESSAGE_TRIGGER); - gboolean trigger_found = FALSE; - if (notify_trigger) { - char *message_lower = g_utf8_strdown(message, -1); - gsize len = 0; - gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "message.trigger.list", &len, NULL); - int i; - for (i = 0; i < len; i++) { - char *trigger_lower = g_utf8_strdown(triggers[i], -1); - if (g_strrstr(message_lower, trigger_lower)) { - trigger_found = TRUE; - g_free(trigger_lower); - break; - } - g_free(trigger_lower); - } - g_strfreev(triggers); - g_free(message_lower); - } - + gboolean notify_current = prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT); gboolean notify_window = FALSE; - if (!current_win || (current_win && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) { + if (!current_win || (current_win && notify_current) ) { notify_window = TRUE; } - if (!notify_window) { return FALSE; } + gboolean notify_message = prefs_get_boolean(PREF_NOTIFY_MESSAGE); if (notify_message) { return TRUE; } - if (notify_trigger && trigger_found) { + gboolean notify_trigger = prefs_get_boolean(PREF_NOTIFY_MESSAGE_TRIGGER); + if (!notify_trigger) { + return FALSE; + } + + gboolean trigger_found = FALSE; + char *message_lower = g_utf8_strdown(message, -1); + gsize len = 0; + gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "message.trigger.list", &len, NULL); + int i; + for (i = 0; i < len; i++) { + char *trigger_lower = g_utf8_strdown(triggers[i], -1); + if (g_strrstr(message_lower, trigger_lower)) { + trigger_found = TRUE; + g_free(trigger_lower); + break; + } + g_free(trigger_lower); + } + g_strfreev(triggers); + g_free(message_lower); + + if (trigger_found) { return TRUE; } @@ -252,29 +266,60 @@ prefs_get_notify_chat(gboolean current_win, const char *const message) gboolean prefs_get_notify_room(gboolean current_win, const char *const nick, const char *const message) { - gboolean notify_message = FALSE; + gboolean notify_current = prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT); gboolean notify_window = FALSE; + if (!current_win || (current_win && notify_current) ) { + notify_window = TRUE; + } + if (!notify_window) { + return FALSE; + } - char *room_setting = prefs_get_string(PREF_NOTIFY_ROOM); - if (g_strcmp0(room_setting, "on") == 0) { - notify_message = TRUE; + gboolean notify_room = prefs_get_boolean(PREF_NOTIFY_ROOM); + if (notify_room) { + return TRUE; } - if (g_strcmp0(room_setting, "mention") == 0) { + + gboolean notify_mention = prefs_get_boolean(PREF_NOTIFY_ROOM_MENTION); + if (notify_mention) { char *message_lower = g_utf8_strdown(message, -1); char *nick_lower = g_utf8_strdown(nick, -1); if (g_strrstr(message_lower, nick_lower)) { - notify_message = TRUE; + g_free(message_lower); + g_free(nick_lower); + return TRUE; } g_free(message_lower); g_free(nick_lower); } - prefs_free_string(room_setting); - if (!current_win || (current_win && prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT)) ) { - notify_window = TRUE; + gboolean notify_trigger = prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER); + if (!notify_trigger) { + return FALSE; + } + + gboolean trigger_found = FALSE; + char *message_lower = g_utf8_strdown(message, -1); + gsize len = 0; + gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL); + int i; + for (i = 0; i < len; i++) { + char *trigger_lower = g_utf8_strdown(triggers[i], -1); + if (g_strrstr(message_lower, trigger_lower)) { + trigger_found = TRUE; + g_free(trigger_lower); + break; + } + g_free(trigger_lower); } + g_strfreev(triggers); + g_free(message_lower); - return (notify_message && notify_window); + if (trigger_found) { + return TRUE; + } + + return FALSE; } gboolean @@ -989,13 +1034,14 @@ _get_group(preference_t pref) case PREF_NOTIFY_TYPING: case PREF_NOTIFY_TYPING_CURRENT: case PREF_NOTIFY_MESSAGE: + case PREF_NOTIFY_MESSAGE_TRIGGER: case PREF_NOTIFY_MESSAGE_CURRENT: case PREF_NOTIFY_MESSAGE_TEXT: - case PREF_NOTIFY_MESSAGE_TRIGGER: case PREF_NOTIFY_ROOM: + case PREF_NOTIFY_ROOM_MENTION: + case PREF_NOTIFY_ROOM_TRIGGER: case PREF_NOTIFY_ROOM_CURRENT: case PREF_NOTIFY_ROOM_TEXT: - case PREF_NOTIFY_ROOM_TRIGGER: case PREF_NOTIFY_INVITE: case PREF_NOTIFY_SUB: return PREF_GROUP_NOTIFICATIONS; @@ -1082,20 +1128,22 @@ _get_key(preference_t pref) return "typing.current"; case PREF_NOTIFY_MESSAGE: return "message"; + case PREF_NOTIFY_MESSAGE_TRIGGER: + return "message.trigger"; case PREF_NOTIFY_MESSAGE_CURRENT: return "message.current"; case PREF_NOTIFY_MESSAGE_TEXT: return "message.text"; - case PREF_NOTIFY_MESSAGE_TRIGGER: - return "message.trigger"; case PREF_NOTIFY_ROOM: return "room"; + case PREF_NOTIFY_ROOM_TRIGGER: + return "room.trigger"; + case PREF_NOTIFY_ROOM_MENTION: + return "room.mention"; case PREF_NOTIFY_ROOM_CURRENT: return "room.current"; case PREF_NOTIFY_ROOM_TEXT: return "room.text"; - case PREF_NOTIFY_ROOM_TRIGGER: - return "room.trigger"; case PREF_NOTIFY_INVITE: return "invite"; case PREF_NOTIFY_SUB: @@ -1204,6 +1252,7 @@ _get_default_boolean(preference_t pref) case PREF_LOG_SHARED: case PREF_NOTIFY_MESSAGE: case PREF_NOTIFY_MESSAGE_CURRENT: + case PREF_NOTIFY_ROOM: case PREF_NOTIFY_ROOM_CURRENT: case PREF_NOTIFY_TYPING: case PREF_NOTIFY_TYPING_CURRENT: @@ -1241,8 +1290,6 @@ _get_default_string(preference_t pref) { case PREF_AUTOAWAY_MODE: return "off"; - case PREF_NOTIFY_ROOM: - return "on"; case PREF_OTR_LOG: return "redact"; case PREF_OTR_POLICY: diff --git a/src/config/preferences.h b/src/config/preferences.h index 603ba30c..56c87d92 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -94,13 +94,14 @@ typedef enum { PREF_NOTIFY_TYPING, PREF_NOTIFY_TYPING_CURRENT, PREF_NOTIFY_MESSAGE, + PREF_NOTIFY_MESSAGE_TRIGGER, PREF_NOTIFY_MESSAGE_CURRENT, PREF_NOTIFY_MESSAGE_TEXT, - PREF_NOTIFY_MESSAGE_TRIGGER, PREF_NOTIFY_ROOM, + PREF_NOTIFY_ROOM_MENTION, + PREF_NOTIFY_ROOM_TRIGGER, PREF_NOTIFY_ROOM_CURRENT, PREF_NOTIFY_ROOM_TEXT, - PREF_NOTIFY_ROOM_TRIGGER, PREF_NOTIFY_INVITE, PREF_NOTIFY_SUB, PREF_CHLOG, -- cgit 1.4.1-2-gfad0 hor Andreas Rumpf <rumpf_a@web.de> 2017-10-29 19:46:17 +0100 committer Andreas Rumpf <rumpf_a@web.de> 2017-10-29 19:46:17 +0100 work in progress: new implementation for 'a[^1]'' href='/ahoang/Nim/commit/changelog.md?h=devel&id=d52a1061b35bbd2abfbd062b08023d986dbafb3c'>d52a1061b ^
d7a896f19 ^


90c1b94fb ^

560d87f5f ^
90c1b94fb ^
9565da11e ^
089506498 ^

4e4d466d0 ^

a9ba02e8c ^
4e4d466d0 ^



a9ba02e8c ^
4e4d466d0 ^
742f43e57 ^



a9ba02e8c ^
742f43e57 ^
a9ba02e8c ^
742f43e57 ^


a9ba02e8c ^
742f43e57 ^
a9ba02e8c ^
136dbd3c6 ^




a9ba02e8c ^
136dbd3c6 ^



a9ba02e8c ^
5e66a7ce5 ^



a4d40d137 ^


661ce8b8c ^

908a25a2c ^

55cdaaef6 ^
844e12306 ^

0594a3a70 ^


908a25a2c ^
0594a3a70 ^






8d1a5dc8e ^



5d2e86ea1 ^


ca9f3b47d ^
5d2e86ea1 ^



ca9f3b47d ^
b74a5148a ^

5196cc3a5 ^
caecd60e2 ^

45821ea2a ^


33814cf63 ^





255902f9a ^
17becb8d3 ^




6df6ec27e ^


196977f62 ^


ca9f3b47d ^

8db5b32ff ^

e0591d494 ^

26198e4ee ^


a9ba02e8c ^


2b3ec0a7c ^

a8b0a8a92 ^
2b3ec0a7c ^











a8b0a8a92 ^


2b3ec0a7c ^
a8b0a8a92 ^
2b3ec0a7c ^

a8b0a8a92 ^


















ce983383f ^


7ce38122e ^
2c9e56a78 ^


7ce38122e ^

















be2db6d67 ^
7ce38122e ^



be2db6d67 ^


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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222