NeoMutt  2025-01-09-81-g753ae0
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
notify.c
Go to the documentation of this file.
1
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#include "mview.h"
39
40extern const struct Mapping ColorFields[];
41
42static void notify_dump_account(struct NotifyCallback *nc)
43{
44 struct EventAccount *ev_a = nc->event_data;
45 struct Account *a = ev_a->account;
46 if (!a)
47 return;
48
49 mutt_debug(LL_DEBUG1, " Account: %p (%s) %s\n", (void *) a,
51}
52
53static void notify_dump_color(struct NotifyCallback *nc)
54{
55 struct EventColor *ev_c = nc->event_data;
56
57 const char *color = NULL;
58
59 if (ev_c->cid == MT_COLOR_MAX)
60 color = "ALL";
61
62 if (!color)
63 color = mutt_map_get_name(ev_c->cid, ColorFields);
64
65 if (!color)
66 color = "UNKNOWN";
67
68 mutt_debug(LL_DEBUG1, " Color: %s %s (%d)\n",
69 (nc->event_subtype == NT_COLOR_SET) ? "set" : "reset", color, ev_c->cid);
70}
71
72static void notify_dump_command(struct NotifyCallback *nc)
73{
74 struct Command *cmd = nc->event_data;
75
76 if (cmd->data < 4096)
77 mutt_debug(LL_DEBUG1, " Command: %s, data: %ld\n", cmd->name, cmd->data);
78 else
79 mutt_debug(LL_DEBUG1, " Command: %s, data: %p\n", cmd->name, (void *) cmd->data);
80}
81
82static void notify_dump_config(struct NotifyCallback *nc)
83{
84 struct EventConfig *ev_c = nc->event_data;
85
86 struct Buffer *value = buf_pool_get();
87 cs_he_string_get(ev_c->sub->cs, ev_c->he, value);
88 mutt_debug(LL_DEBUG1, " Config: %s %s = %s\n",
90 buf_pool_release(&value);
91}
92
93static void notify_dump_mview(struct NotifyCallback *nc)
94{
95 struct EventMview *ev_m = nc->event_data;
96
97 const char *path = "NONE";
98 if (ev_m->mv && ev_m->mv->mailbox)
99 path = mailbox_path(ev_m->mv->mailbox);
100
101 mutt_debug(LL_DEBUG1, " MailboxView: %s %s\n",
103}
104
105static void notify_dump_email(struct NotifyCallback *nc)
106{
107 struct EventEmail *ev_e = nc->event_data;
108
109 mutt_debug(LL_DEBUG1, " Email: %d\n", ev_e->num_emails);
110 for (size_t i = 0; i < ev_e->num_emails; i++)
111 {
112 mutt_debug(LL_DEBUG1, " : %p\n", (void *) ev_e->emails[i]);
113 }
114}
115
116static void notify_dump_global(struct NotifyCallback *nc)
117{
119}
120
121static void notify_dump_mailbox(struct NotifyCallback *nc)
122{
123 struct EventMailbox *ev_m = nc->event_data;
124
125 struct Mailbox *m = ev_m->mailbox;
126 const char *path = m ? mailbox_path(m) : "";
127 mutt_debug(LL_DEBUG1, " Mailbox: %s %s\n",
129}
130
132{
133 struct EventWindow *ev_w = nc->event_data;
134 const struct MuttWindow *win = ev_w->win;
135 WindowNotifyFlags flags = ev_w->flags;
136
137 struct Buffer *buf = buf_pool_get();
138
139 buf_add_printf(buf, "[%s] ", mutt_window_win_name(win));
140
141 if (flags & WN_VISIBLE)
142 buf_addstr(buf, "visible ");
143 if (flags & WN_HIDDEN)
144 buf_addstr(buf, "hidden ");
145
146 if (flags & WN_MOVED)
147 {
148 buf_add_printf(buf, "moved (C%d,R%d)->(C%d,R%d) ", win->old.col_offset,
149 win->old.row_offset, win->state.col_offset, win->state.row_offset);
150 }
151
152 if (flags & WN_TALLER)
153 buf_add_printf(buf, "taller [%d->%d] ", win->old.rows, win->state.rows);
154 if (flags & WN_SHORTER)
155 buf_add_printf(buf, "shorter [%d->%d] ", win->old.rows, win->state.rows);
156 if (flags & WN_WIDER)
157 buf_add_printf(buf, "wider [%d->%d] ", win->old.cols, win->state.cols);
158 if (flags & WN_NARROWER)
159 buf_add_printf(buf, "narrower [%d->%d] ", win->old.cols, win->state.cols);
160
161 mutt_debug(LL_DEBUG1, " Window: %s\n", buf_string(buf));
162
163 buf_pool_release(&buf);
164}
165
167{
168 struct EventWindow *ev_w = nc->event_data;
169 struct MuttWindow *win = ev_w->win;
170
171 struct Buffer *buf = buf_pool_get();
172
173 buf_addstr(buf, "Focus: ");
174
175 if (win)
176 {
177 struct MuttWindow *dlg = dialog_find(win);
178 if (dlg && (dlg != win))
179 buf_add_printf(buf, "%s:", mutt_window_win_name(dlg));
180
181 buf_add_printf(buf, "%s ", mutt_window_win_name(win));
182
183 buf_add_printf(buf, "(C%d,R%d) [%dx%d]", win->state.col_offset,
184 win->state.row_offset, win->state.cols, win->state.rows);
185 }
186 else
187 {
188 buf_addstr(buf, "NONE");
189 }
190
191 mutt_debug(LL_DEBUG1, " Window: %s\n", buf_string(buf));
192
193 buf_pool_release(&buf);
194}
195
197{
198 mutt_debug(LL_DEBUG1, "\033[1;31mNotification:\033[0m %s\n",
200
201 switch (nc->event_type)
202 {
203 case NT_ACCOUNT:
205 break;
206 case NT_COLOR:
208 break;
209 case NT_COMMAND:
211 break;
212 case NT_CONFIG:
214 break;
215 case NT_MVIEW:
217 break;
218 case NT_EMAIL:
220 break;
221 case NT_GLOBAL:
223 break;
224 case NT_MAILBOX:
226 break;
227 case NT_RESIZE:
228 case NT_TIMEOUT:
229 break; // no other data
230 case NT_WINDOW:
233 else if (nc->event_subtype == NT_WINDOW_FOCUS)
235 break;
236 default:
237 mutt_debug(LL_DEBUG1, " Event Type: %d\n", nc->event_type);
238 mutt_debug(LL_DEBUG1, " Event Sub-type: %d\n", nc->event_subtype);
239 mutt_debug(LL_DEBUG1, " Event Data: %p\n", nc->event_data);
240 break;
241 }
242
243 mutt_debug(LL_DEBUG1, " Global Data: %p\n", nc->global_data);
244
245 mutt_debug(LL_DEBUG5, "debug done\n");
246 return 0;
247}
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.
@ MT_COLOR_MAX
Definition: color.h:99
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:715
Convenience wrapper for the core headers.
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:223
const char * name_notify_global(int id)
Definition: names.c:171
const char * name_mailbox_type(enum MailboxType type)
Definition: names.c:123
const char * name_notify_type(enum NotifyType type)
Definition: names.c:92
const char * name_notify_mview(int id)
Definition: names.c:209
const char * name_notify_config(int id)
Definition: names.c:182
const char * name_notify_mailbox(int id)
Definition: names.c:193
static void notify_dump_global(struct NotifyCallback *nc)
Definition: notify.c:116
const struct Mapping ColorFields[]
Mapping of colour names to their IDs.
Definition: command.c:55
static void notify_dump_config(struct NotifyCallback *nc)
Definition: notify.c:82
static void notify_dump_mview(struct NotifyCallback *nc)
Definition: notify.c:93
static void notify_dump_command(struct NotifyCallback *nc)
Definition: notify.c:72
static void notify_dump_color(struct NotifyCallback *nc)
Definition: notify.c:53
int debug_all_observer(struct NotifyCallback *nc)
Definition: notify.c:196
static void notify_dump_mailbox(struct NotifyCallback *nc)
Definition: notify.c:121
static void notify_dump_window_focus(struct NotifyCallback *nc)
Definition: notify.c:166
static void notify_dump_account(struct NotifyCallback *nc)
Definition: notify.c:42
static void notify_dump_email(struct NotifyCallback *nc)
Definition: notify.c:105
static void notify_dump_window_state(struct NotifyCallback *nc)
Definition: notify.c:131
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:89
Convenience wrapper for the gui headers.
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
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.
Definition: mutt_window.c:700
#define WN_MOVED
Window moved.
Definition: mutt_window.h:214
uint8_t WindowNotifyFlags
Flags for Changes to a MuttWindow, e.g. WN_TALLER.
Definition: mutt_window.h:208
#define WN_WIDER
Window became wider.
Definition: mutt_window.h:212
@ NT_WINDOW_STATE
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:230
@ NT_WINDOW_FOCUS
Window focus has changed.
Definition: mutt_window.h:232
#define WN_VISIBLE
Window became visible.
Definition: mutt_window.h:215
#define WN_HIDDEN
Window became hidden.
Definition: mutt_window.h:216
#define WN_TALLER
Window became taller.
Definition: mutt_window.h:210
#define WN_NARROWER
Window became narrower.
Definition: mutt_window.h:213
#define WN_SHORTER
Window became shorter.
Definition: mutt_window.h:211
View of a Mailbox.
@ NT_COLOR_SET
Color has been set.
Definition: notify2.h:43
@ NT_TIMEOUT
Timeout has occurred.
Definition: notify_type.h:56
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:57
@ 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:49
@ 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:50
@ NT_GLOBAL
Not object-related, NotifyGlobal.
Definition: notify_type.h:46
@ NT_RESIZE
Window has been resized.
Definition: notify_type.h:52
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
Key value store.
#define NONULL(x)
Definition: string2.h:37
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
intptr_t data
Data or flags to pass to the command.
Definition: command.h:67
const char * name
Name of the command.
Definition: command.h:52
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:50
An Event that happened to an Account.
Definition: account.h:79
struct Account * account
The Account this Event relates to.
Definition: account.h:80
An Event that happened to a Colour.
Definition: notify2.h:55
enum ColorId cid
Colour ID that has changed.
Definition: notify2.h:56
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:199
struct Mailbox * mailbox
The Mailbox this Event relates to.
Definition: mailbox.h:200
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.
Definition: mutt_window.h:239
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:240
WindowNotifyFlags flags
Attributes of Window that changed.
Definition: mutt_window.h:241
struct Mailbox * mailbox
Current Mailbox.
Definition: mview.h:51
A mailbox.
Definition: mailbox.h:79
Mapping between user-readable string and a constant.
Definition: mapping.h:33
struct WindowState old
Previous state of the Window.
Definition: mutt_window.h:128
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
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:61
short row_offset
Absolute on-screen row.
Definition: mutt_window.h:64
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:63
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:62