NeoMutt  2025-12-11-800-ga0ee0f
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
notify.c
Go to the documentation of this file.
1
22
28
29#include "config.h"
30#include <stddef.h>
31#include "mutt/lib.h"
32#include "config/lib.h"
33#include "email/lib.h"
34#include "core/lib.h"
35#include "gui/lib.h"
36#include "lib.h"
37#include "color/lib.h"
38
39extern const struct Mapping ColorFields[];
40
45static void notify_dump_account(struct NotifyCallback *nc)
46{
47 struct EventAccount *ev_a = nc->event_data;
48 struct Account *a = ev_a->account;
49 if (!a)
50 return;
51
52 mutt_debug(LL_DEBUG1, " Account: %p (%s) %s\n", (void *) a,
54}
55
60static void notify_dump_color(struct NotifyCallback *nc)
61{
62 struct EventColor *ev_c = nc->event_data;
63
64 const char *color = NULL;
65
66 if (ev_c->cid == MT_COLOR_MAX)
67 color = "ALL";
68
69 if (!color)
70 color = mutt_map_get_name(ev_c->cid, ColorFields);
71
72 if (!color)
73 color = "UNKNOWN";
74
75 mutt_debug(LL_DEBUG1, " Color: %s %s (%d)\n",
76 (nc->event_subtype == NT_COLOR_SET) ? "set" : "reset", color, ev_c->cid);
77}
78
83static void notify_dump_command(struct NotifyCallback *nc)
84{
85 struct Command *cmd = nc->event_data;
86
87 mutt_debug(LL_DEBUG1, " Command: %s, (%s)\n", cmd->name, name_command_id(cmd->id));
88}
89
94static void notify_dump_config(struct NotifyCallback *nc)
95{
96 struct EventConfig *ev_c = nc->event_data;
97
98 struct Buffer *value = buf_pool_get();
99 cs_he_string_get(ev_c->sub->cs, ev_c->he, value);
100 mutt_debug(LL_DEBUG1, " Config: %s %s = %s\n",
101 name_notify_config(nc->event_subtype), ev_c->name, buf_string(value));
102 buf_pool_release(&value);
103}
104
109static void notify_dump_mview(struct NotifyCallback *nc)
110{
111 struct EventMview *ev_m = nc->event_data;
112
113 const char *path = "NONE";
114 if (ev_m->mv && ev_m->mv->mailbox)
115 path = mailbox_path(ev_m->mv->mailbox);
116
117 mutt_debug(LL_DEBUG1, " MailboxView: %s %s\n",
119}
120
125static void notify_dump_email(struct NotifyCallback *nc)
126{
127 struct EventEmail *ev_e = nc->event_data;
128
129 mutt_debug(LL_DEBUG1, " Email: %d\n", ev_e->num_emails);
130 for (size_t i = 0; i < ev_e->num_emails; i++)
131 {
132 mutt_debug(LL_DEBUG1, " : %p\n", (void *) ev_e->emails[i]);
133 }
134}
135
140static void notify_dump_global(struct NotifyCallback *nc)
141{
143}
144
149static void notify_dump_mailbox(struct NotifyCallback *nc)
150{
151 struct EventMailbox *ev_m = nc->event_data;
152
153 struct Mailbox *m = ev_m->mailbox;
154 const char *path = m ? mailbox_path(m) : "";
155 mutt_debug(LL_DEBUG1, " Mailbox: %s %s\n",
157}
158
164{
165 struct EventWindow *ev_w = nc->event_data;
166 const struct MuttWindow *win = ev_w->win;
167 WindowNotifyFlags flags = ev_w->flags;
168
169 struct Buffer *buf = buf_pool_get();
170
171 buf_add_printf(buf, "[%s] ", mutt_window_win_name(win));
172
173 if (flags & WN_VISIBLE)
174 buf_addstr(buf, "visible ");
175 if (flags & WN_HIDDEN)
176 buf_addstr(buf, "hidden ");
177
178 if (flags & WN_MOVED)
179 {
180 buf_add_printf(buf, "moved (C%d,R%d)->(C%d,R%d) ", win->old.col_offset,
181 win->old.row_offset, win->state.col_offset, win->state.row_offset);
182 }
183
184 if (flags & WN_TALLER)
185 buf_add_printf(buf, "taller [%d->%d] ", win->old.rows, win->state.rows);
186 if (flags & WN_SHORTER)
187 buf_add_printf(buf, "shorter [%d->%d] ", win->old.rows, win->state.rows);
188 if (flags & WN_WIDER)
189 buf_add_printf(buf, "wider [%d->%d] ", win->old.cols, win->state.cols);
190 if (flags & WN_NARROWER)
191 buf_add_printf(buf, "narrower [%d->%d] ", win->old.cols, win->state.cols);
192
193 mutt_debug(LL_DEBUG1, " Window: %s\n", buf_string(buf));
194
195 buf_pool_release(&buf);
196}
197
203{
204 struct EventWindow *ev_w = nc->event_data;
205 struct MuttWindow *win = ev_w->win;
206
207 struct Buffer *buf = buf_pool_get();
208
209 buf_addstr(buf, "Focus: ");
210
211 if (win)
212 {
213 struct MuttWindow *dlg = dialog_find(win);
214 if (dlg && (dlg != win))
215 buf_add_printf(buf, "%s:", mutt_window_win_name(dlg));
216
217 buf_add_printf(buf, "%s ", mutt_window_win_name(win));
218
219 buf_add_printf(buf, "(C%d,R%d) [%dx%d]", win->state.col_offset,
220 win->state.row_offset, win->state.cols, win->state.rows);
221 }
222 else
223 {
224 buf_addstr(buf, "NONE");
225 }
226
227 mutt_debug(LL_DEBUG1, " Window: %s\n", buf_string(buf));
228
229 buf_pool_release(&buf);
230}
231
238{
239 mutt_debug(LL_DEBUG1, "\033[1;31mNotification:\033[0m %s\n",
241
242 switch (nc->event_type)
243 {
244 case NT_ACCOUNT:
246 break;
247 case NT_COLOR:
249 break;
250 case NT_COMMAND:
252 break;
253 case NT_CONFIG:
255 break;
256 case NT_MVIEW:
258 break;
259 case NT_EMAIL:
261 break;
262 case NT_GLOBAL:
264 break;
265 case NT_MAILBOX:
267 break;
268 case NT_RESIZE:
269 case NT_TIMEOUT:
270 break; // no other data
271 case NT_WINDOW:
274 else if (nc->event_subtype == NT_WINDOW_FOCUS)
276 break;
277 default:
278 mutt_debug(LL_DEBUG1, " Event Type: %d\n", nc->event_type);
279 mutt_debug(LL_DEBUG1, " Event Sub-type: %d\n", nc->event_subtype);
280 mutt_debug(LL_DEBUG1, " Event Data: %p\n", nc->event_data);
281 break;
282 }
283
284 mutt_debug(LL_DEBUG1, " Global Data: %p\n", nc->global_data);
285
286 mutt_debug(LL_DEBUG5, "debug done\n");
287 return 0;
288}
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition buffer.c:204
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:226
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
Color and attribute parsing.
const struct Mapping ColorFields[]
Mapping of colour names to their IDs.
Definition commands.c:55
@ MT_COLOR_MAX
Definition color.h:97
Convenience wrapper for the config headers.
int cs_he_string_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
Get a config item as a string.
Definition set.c:692
Convenience wrapper for the core headers.
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition mailbox.h:213
Convenience wrapper for the debug headers.
const char * name_notify_global(int id)
Get the name of a global notification type.
Definition names.c:305
const char * name_mailbox_type(enum MailboxType type)
Get the name of a mailbox type.
Definition names.c:250
const char * name_command_id(enum CommandId id)
Get the name of a Command id.
Definition names.c:52
const char * name_notify_type(enum NotifyType type)
Get the name of a notification type.
Definition names.c:214
const char * name_notify_mview(int id)
Get the name of a mailbox view notification type.
Definition names.c:358
const char * name_notify_config(int id)
Get the name of a config notification type.
Definition names.c:321
const char * name_notify_mailbox(int id)
Get the name of a mailbox notification type.
Definition names.c:337
static void notify_dump_global(struct NotifyCallback *nc)
Dump global notification.
Definition notify.c:140
static void notify_dump_config(struct NotifyCallback *nc)
Dump config notification.
Definition notify.c:94
static void notify_dump_mview(struct NotifyCallback *nc)
Dump mailbox view notification.
Definition notify.c:109
static void notify_dump_command(struct NotifyCallback *nc)
Dump command notification.
Definition notify.c:83
static void notify_dump_color(struct NotifyCallback *nc)
Dump color notification.
Definition notify.c:60
int debug_all_observer(struct NotifyCallback *nc)
Debug observer for all notifications.
Definition notify.c:237
static void notify_dump_mailbox(struct NotifyCallback *nc)
Dump mailbox notification.
Definition notify.c:149
static void notify_dump_window_focus(struct NotifyCallback *nc)
Dump window focus notification.
Definition notify.c:202
static void notify_dump_account(struct NotifyCallback *nc)
Dump account notification.
Definition notify.c:45
static void notify_dump_email(struct NotifyCallback *nc)
Dump email notification.
Definition notify.c:125
static void notify_dump_window_state(struct NotifyCallback *nc)
Dump window state notification.
Definition notify.c:163
struct MuttWindow * dialog_find(struct MuttWindow *win)
Find the parent Dialog of a Window.
Definition dialog.c:89
Structs that make up an email.
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
Convenience wrapper for the gui headers.
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition mapping.c:42
Convenience wrapper for the library headers.
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
#define WN_MOVED
Window moved.
uint8_t WindowNotifyFlags
Flags for Changes to a MuttWindow, e.g. WN_TALLER.
#define WN_WIDER
Window became wider.
@ NT_WINDOW_STATE
Window state has changed, e.g. WN_VISIBLE.
@ NT_WINDOW_FOCUS
Window focus has changed.
#define WN_VISIBLE
Window became visible.
#define WN_HIDDEN
Window became hidden.
#define WN_TALLER
Window became taller.
#define WN_NARROWER
Window became narrower.
#define WN_SHORTER
Window became shorter.
@ NT_COLOR_SET
Color has been set.
Definition notify2.h:40
@ NT_TIMEOUT
Timeout has occurred.
Definition notify_type.h:57
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition notify_type.h:58
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition notify_type.h:43
@ NT_COLOR
Colour has changed, NotifyColor, EventColor.
Definition notify_type.h:41
@ NT_EMAIL
Email has changed, NotifyEmail, EventEmail.
Definition notify_type.h:44
@ NT_MAILBOX
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition notify_type.h:50
@ NT_COMMAND
A Command has been executed, Command.
Definition notify_type.h:42
@ NT_ACCOUNT
Account has changed, NotifyAccount, EventAccount.
Definition notify_type.h:36
@ NT_MVIEW
MailboxView has changed, NotifyMview, EventMview.
Definition notify_type.h:51
@ NT_GLOBAL
Not object-related, NotifyGlobal.
Definition notify_type.h:46
@ NT_RESIZE
Window has been resized.
Definition notify_type.h:53
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
#define NONULL(x)
Definition string2.h:44
A group of associated Mailboxes.
Definition account.h:36
enum MailboxType type
Type of Mailboxes this Account contains.
Definition account.h:37
char * name
Name of Account.
Definition account.h:38
String manipulation buffer.
Definition buffer.h:36
const char * name
Name of the Command.
Definition command.h:159
enum CommandId id
ID of the Command.
Definition command.h:160
struct ConfigSet * cs
Parent ConfigSet.
Definition subset.h:50
An Event that happened to an Account.
Definition account.h:77
struct Account * account
The Account this Event relates to.
Definition account.h:78
An Event that happened to a Colour.
Definition notify2.h:52
enum ColorId cid
Colour ID that has changed.
Definition notify2.h:53
A config-change event.
Definition subset.h:70
const struct ConfigSubset * sub
Config Subset.
Definition subset.h:71
const char * name
Name of config item that changed.
Definition subset.h:72
struct HashElem * he
Config item that changed.
Definition subset.h:73
An Event that happened to an Email.
Definition email.h:196
int num_emails
Number of Emails the event applies to.
Definition email.h:197
struct Email ** emails
Emails affected by the event.
Definition email.h:198
An Event that happened to a Mailbox.
Definition mailbox.h:189
struct Mailbox * mailbox
The Mailbox this Event relates to.
Definition mailbox.h:190
An Event that happened to an MailboxView.
Definition mview.h:71
struct MailboxView * mv
The MailboxView this Event relates to.
Definition mview.h:72
An Event that happened to a Window.
struct MuttWindow * win
Window that changed.
WindowNotifyFlags flags
Attributes of Window that changed.
struct Mailbox * mailbox
Current Mailbox.
Definition mview.h:51
A mailbox.
Definition mailbox.h:78
Mapping between user-readable string and a constant.
Definition mapping.h:33
struct WindowState old
Previous state of the Window.
struct WindowState state
Current state of the Window.
Data passed to a notification function.
Definition observer.h:34
void * event_data
Data from notify_send()
Definition observer.h:38
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition observer.h:36
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition observer.h:37
void * global_data
Data from notify_observer_add()
Definition observer.h:39
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition mutt_window.h:60
short row_offset
Absolute on-screen row.
Definition mutt_window.h:63
short col_offset
Absolute on-screen column.
Definition mutt_window.h:62
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition mutt_window.h:61