forked from neomutt/neomutt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.c
389 lines (339 loc) · 9.38 KB
/
notify.c
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
/**
* @file
* Dump all notifications
*
* @authors
* Copyright (C) 2019-2020 Richard Russon <[email protected]>
*
* @copyright
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @page debug_notify Dump all notifications
*
* Dump all notifications
*/
#include "config.h"
#include <stddef.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "color/lib.h"
#include "mview.h"
extern const struct Mapping ColorFields[];
extern const struct Mapping ComposeColorFields[];
static const char *get_event_type(enum NotifyType type)
{
switch (type)
{
case NT_ACCOUNT:
return "account";
case NT_ALIAS:
return "alias";
case NT_ALTERN:
return "altern";
case NT_ATTACH:
return "attach";
case NT_BINDING:
return "binding";
case NT_COLOR:
return "color";
case NT_COMMAND:
return "command";
case NT_CONFIG:
return "config";
case NT_MVIEW:
return "mailboxview";
case NT_EMAIL:
return "email";
case NT_ENVELOPE:
return "envelope";
case NT_GLOBAL:
return "global";
case NT_HEADER:
return "header";
case NT_INDEX:
return "index";
case NT_MAILBOX:
return "mailbox";
case NT_MENU:
return "menu";
case NT_PAGER:
return "pager";
case NT_SCORE:
return "score";
case NT_SUBJRX:
return "subjrx";
case NT_WINDOW:
return "window";
default:
return "UNKNOWN";
}
}
const char *get_mailbox_type(enum MailboxType type)
{
switch (type)
{
case MUTT_COMPRESSED:
return "compressed";
case MUTT_IMAP:
return "imap";
case MUTT_MAILDIR:
return "maildir";
case MUTT_MBOX:
return "mbox";
case MUTT_MH:
return "mh";
case MUTT_MMDF:
return "mmdf";
case MUTT_NNTP:
return "nntp";
case MUTT_NOTMUCH:
return "notmuch";
case MUTT_POP:
return "pop";
default:
return "UNKNOWN";
}
}
static const char *get_global_event(int id)
{
switch (id)
{
case NT_GLOBAL_SHUTDOWN:
return "shutdown";
case NT_GLOBAL_STARTUP:
return "startup";
case NT_GLOBAL_TIMEOUT:
return "timeout";
default:
return "UNKNOWN";
}
}
static const char *get_config_type(int id)
{
switch (id)
{
case NT_CONFIG_SET:
return "set";
case NT_CONFIG_RESET:
return "reset";
default:
return "UNKNOWN";
}
}
static const char *get_mailbox_event(int id)
{
switch (id)
{
case NT_MAILBOX_ADD:
return "add";
case NT_MAILBOX_DELETE:
return "delete";
case NT_MAILBOX_INVALID:
return "invalid";
case NT_MAILBOX_RESORT:
return "resort";
case NT_MAILBOX_UPDATE:
return "update";
case NT_MAILBOX_UNTAG:
return "untag";
default:
return "UNKNOWN";
}
}
static const char *get_mview(int id)
{
switch (id)
{
case NT_MVIEW_DELETE:
return "delete";
case NT_MVIEW_ADD:
return "add";
default:
return "UNKNOWN";
}
}
static void notify_dump_account(struct NotifyCallback *nc)
{
struct EventAccount *ev_a = nc->event_data;
struct Account *a = ev_a->account;
if (!a)
return;
mutt_debug(LL_DEBUG1, " Account: %p (%s) %s\n", a,
get_mailbox_type(a->type), NONULL(a->name));
}
static void notify_dump_color(struct NotifyCallback *nc)
{
struct EventColor *ev_c = nc->event_data;
const char *color = NULL;
const char *scope = "";
if (ev_c->cid == MT_COLOR_MAX)
color = "ALL";
if (!color)
color = mutt_map_get_name(ev_c->cid, ColorFields);
if (!color)
{
color = mutt_map_get_name(ev_c->cid, ComposeColorFields);
scope = "compose ";
}
if (!color)
color = "UNKNOWN";
mutt_debug(LL_DEBUG1, " Color: %s %s%s (%d)\n",
(nc->event_subtype == NT_COLOR_SET) ? "set" : "reset", scope,
color, ev_c->cid);
}
static void notify_dump_command(struct NotifyCallback *nc)
{
struct Command *cmd = nc->event_data;
if (cmd->data < 4096)
mutt_debug(LL_DEBUG1, " Command: %s, data: %ld\n", cmd->name, cmd->data);
else
mutt_debug(LL_DEBUG1, " Command: %s, data: %p\n", cmd->name, (void *) cmd->data);
}
static void notify_dump_config(struct NotifyCallback *nc)
{
struct EventConfig *ev_c = nc->event_data;
struct Buffer value = mutt_buffer_make(128);
cs_he_string_get(ev_c->sub->cs, ev_c->he, &value);
mutt_debug(LL_DEBUG1, " Config: %s %s = %s\n", get_config_type(nc->event_subtype),
ev_c->name, mutt_buffer_string(&value));
mutt_buffer_dealloc(&value);
}
static void notify_dump_mview(struct NotifyCallback *nc)
{
struct EventMview *ev_m = nc->event_data;
const char *path = "NONE";
if (ev_m->mv && ev_m->mv->mailbox)
path = mailbox_path(ev_m->mv->mailbox);
mutt_debug(LL_DEBUG1, " MailboxView: %s %s\n", get_mview(nc->event_subtype), path);
}
static void notify_dump_email(struct NotifyCallback *nc)
{
struct EventEmail *ev_e = nc->event_data;
mutt_debug(LL_DEBUG1, " Email: %d\n", ev_e->num_emails);
for (size_t i = 0; i < ev_e->num_emails; i++)
{
mutt_debug(LL_DEBUG1, " : %p\n", ev_e->emails[i]);
}
}
static void notify_dump_global(struct NotifyCallback *nc)
{
mutt_debug(LL_DEBUG1, " Global: %s\n", get_global_event(nc->event_subtype));
}
static void notify_dump_mailbox(struct NotifyCallback *nc)
{
struct EventMailbox *ev_m = nc->event_data;
struct Mailbox *m = ev_m->mailbox;
const char *path = m ? mailbox_path(m) : "";
mutt_debug(LL_DEBUG1, " Mailbox: %s %s\n", get_mailbox_event(nc->event_subtype), path);
}
static void notify_dump_window_state(struct NotifyCallback *nc)
{
struct EventWindow *ev_w = nc->event_data;
const struct MuttWindow *win = ev_w->win;
WindowNotifyFlags flags = ev_w->flags;
struct Buffer buf = mutt_buffer_make(128);
mutt_buffer_add_printf(&buf, "[%s] ", mutt_window_win_name(win));
if (flags & WN_VISIBLE)
mutt_buffer_addstr(&buf, "visible ");
if (flags & WN_HIDDEN)
mutt_buffer_addstr(&buf, "hidden ");
if (flags & WN_MOVED)
{
mutt_buffer_add_printf(&buf, "moved (C%d,R%d)->(C%d,R%d) ",
win->old.col_offset, win->old.row_offset,
win->state.col_offset, win->state.row_offset);
}
if (flags & WN_TALLER)
mutt_buffer_add_printf(&buf, "taller [%d->%d] ", win->old.rows, win->state.rows);
if (flags & WN_SHORTER)
mutt_buffer_add_printf(&buf, "shorter [%d->%d] ", win->old.rows, win->state.rows);
if (flags & WN_WIDER)
mutt_buffer_add_printf(&buf, "wider [%d->%d] ", win->old.cols, win->state.cols);
if (flags & WN_NARROWER)
mutt_buffer_add_printf(&buf, "narrower [%d->%d] ", win->old.cols, win->state.cols);
mutt_debug(LL_DEBUG1, " Window: %s\n", mutt_buffer_string(&buf));
mutt_buffer_dealloc(&buf);
}
static void notify_dump_window_focus(struct NotifyCallback *nc)
{
struct EventWindow *ev_w = nc->event_data;
struct MuttWindow *win = ev_w->win;
struct Buffer buf = mutt_buffer_make(128);
mutt_buffer_addstr(&buf, "Focus: ");
if (win)
{
struct MuttWindow *dlg = dialog_find(win);
if (dlg && (dlg != win))
mutt_buffer_add_printf(&buf, "%s:", mutt_window_win_name(dlg));
mutt_buffer_add_printf(&buf, "%s ", mutt_window_win_name(win));
mutt_buffer_add_printf(&buf, "(C%d,R%d) [%dx%d]", win->state.col_offset,
win->state.row_offset, win->state.cols, win->state.rows);
}
else
{
mutt_buffer_addstr(&buf, "NONE");
}
mutt_debug(LL_DEBUG1, " Window: %s\n", mutt_buffer_string(&buf));
mutt_buffer_dealloc(&buf);
}
int debug_all_observer(struct NotifyCallback *nc)
{
mutt_debug(LL_DEBUG1, "\033[1;31mNotification:\033[0m %s\n", get_event_type(nc->event_type));
switch (nc->event_type)
{
case NT_ACCOUNT:
notify_dump_account(nc);
break;
case NT_COLOR:
notify_dump_color(nc);
break;
case NT_COMMAND:
notify_dump_command(nc);
break;
case NT_CONFIG:
notify_dump_config(nc);
break;
case NT_MVIEW:
notify_dump_mview(nc);
break;
case NT_EMAIL:
notify_dump_email(nc);
break;
case NT_GLOBAL:
notify_dump_global(nc);
break;
case NT_MAILBOX:
notify_dump_mailbox(nc);
break;
case NT_WINDOW:
if (nc->event_subtype == NT_WINDOW_STATE)
notify_dump_window_state(nc);
else if (nc->event_subtype == NT_WINDOW_FOCUS)
notify_dump_window_focus(nc);
break;
default:
mutt_debug(LL_DEBUG1, " Event Type: %d\n", nc->event_type);
mutt_debug(LL_DEBUG1, " Event Sub-type: %d\n", nc->event_subtype);
mutt_debug(LL_DEBUG1, " Event Data: %p\n", nc->event_data);
break;
}
mutt_debug(LL_DEBUG1, " Global Data: %p\n", nc->global_data);
mutt_debug(LL_DEBUG5, "debug done\n");
return 0;
}