NeoMutt  2024-04-16-36-g75b6fb
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[];
41extern const struct Mapping ComposeColorFields[];
42
43static void notify_dump_account(struct NotifyCallback *nc)
44{
45 struct EventAccount *ev_a = nc->event_data;
46 struct Account *a = ev_a->account;
47 if (!a)
48 return;
49
50 mutt_debug(LL_DEBUG1, " Account: %p (%s) %s\n", (void *) a,
52}
53
54static void notify_dump_color(struct NotifyCallback *nc)
55{
56 struct EventColor *ev_c = nc->event_data;
57
58 const char *color = NULL;
59 const char *scope = "";
60
61 if (ev_c->cid == MT_COLOR_MAX)
62 color = "ALL";
63
64 if (!color)
65 color = mutt_map_get_name(ev_c->cid, ColorFields);
66
67 if (!color)
68 {
70 scope = "compose ";
71 }
72
73 if (!color)
74 color = "UNKNOWN";
75
76 mutt_debug(LL_DEBUG1, " Color: %s %s%s (%d)\n",
77 (nc->event_subtype == NT_COLOR_SET) ? "set" : "reset", scope,
78 color, ev_c->cid);
79}
80
81static void notify_dump_command(struct NotifyCallback *nc)
82{
83 struct Command *cmd = nc->event_data;
84
85 if (cmd->data < 4096)
86 mutt_debug(LL_DEBUG1, " Command: %s, data: %ld\n", cmd->name, cmd->data);
87 else
88 mutt_debug(LL_DEBUG1, " Command: %s, data: %p\n", cmd->name, (void *) cmd->data);
89}
90
91static void notify_dump_config(struct NotifyCallback *nc)
92{
93 struct EventConfig *ev_c = nc->event_data;
94
95 struct Buffer *value = buf_pool_get();
96 cs_he_string_get(ev_c->sub->cs, ev_c->he, value);
97 mutt_debug(LL_DEBUG1, " Config: %s %s = %s\n",
99 buf_pool_release(&value);
100}
101
102static void notify_dump_mview(struct NotifyCallback *nc)
103{
104 struct EventMview *ev_m = nc->event_data;
105
106 const char *path = "NONE";
107 if (ev_m->mv && ev_m->mv->mailbox)
108 path = mailbox_path(ev_m->mv->mailbox);
109
110 mutt_debug(LL_DEBUG1, " MailboxView: %s %s\n",
112}
113
114static void notify_dump_email(struct NotifyCallback *nc)
115{
116 struct EventEmail *ev_e = nc->event_data;
117
118 mutt_debug(LL_DEBUG1, " Email: %d\n", ev_e->num_emails);
119 for (size_t i = 0; i < ev_e->num_emails; i++)
120 {
121 mutt_debug(LL_DEBUG1, " : %p\n", (void *) ev_e->emails[i]);
122 }
123}
124
125static void notify_dump_global(struct NotifyCallback *nc)
126{
128}
129
130static void notify_dump_mailbox(struct NotifyCallback *nc)
131{
132 struct EventMailbox *ev_m = nc->event_data;
133
134 struct Mailbox *m = ev_m->mailbox;
135 const char *path = m ? mailbox_path(m) : "";
136 mutt_debug(LL_DEBUG1, " Mailbox: %s %s\n",
138}
139
141{
142 struct EventWindow *ev_w = nc->event_data;
143 const struct MuttWindow *win = ev_w->win;
144 WindowNotifyFlags flags = ev_w->flags;
145
146 struct Buffer *buf = buf_pool_get();
147
148 buf_add_printf(buf, "[%s] ", mutt_window_win_name(win));
149
150 if (flags & WN_VISIBLE)
151 buf_addstr(buf, "visible ");
152 if (flags & WN_HIDDEN)
153 buf_addstr(buf, "hidden ");
154
155 if (flags & WN_MOVED)
156 {
157 buf_add_printf(buf, "moved (C%d,R%d)->(C%d,R%d) ", win->old.col_offset,
158 win->old.row_offset, win->state.col_offset, win->state.row_offset);
159 }
160
161 if (flags & WN_TALLER)
162 buf_add_printf(buf, "taller [%d->%d] ", win->old.rows, win->state.rows);
163 if (flags & WN_SHORTER)
164 buf_add_printf(buf, "shorter [%d->%d] ", win->old.rows, win->state.rows);
165 if (flags & WN_WIDER)
166 buf_add_printf(buf, "wider [%d->%d] ", win->old.cols, win->state.cols);
167 if (flags & WN_NARROWER)
168 buf_add_printf(buf, "narrower [%d->%d] ", win->old.cols, win->state.cols);
169
170 mutt_debug(LL_DEBUG1, " Window: %s\n", buf_string(buf));
171
172 buf_pool_release(&buf);
173}
174
176{
177 struct EventWindow *ev_w = nc->event_data;
178 struct MuttWindow *win = ev_w->win;
179
180 struct Buffer *buf = buf_pool_get();
181
182 buf_addstr(buf, "Focus: ");
183
184 if (win)
185 {
186 struct MuttWindow *dlg = dialog_find(win);
187 if (dlg && (dlg != win))
188 buf_add_printf(buf, "%s:", mutt_window_win_name(dlg));
189
190 buf_add_printf(buf, "%s ", mutt_window_win_name(win));
191
192 buf_add_printf(buf, "(C%d,R%d) [%dx%d]", win->state.col_offset,
193 win->state.row_offset, win->state.cols, win->state.rows);
194 }
195 else
196 {
197 buf_addstr(buf, "NONE");
198 }
199
200 mutt_debug(LL_DEBUG1, " Window: %s\n", buf_string(buf));
201
202 buf_pool_release(&buf);
203}
204
206{
207 mutt_debug(LL_DEBUG1, "\033[1;31mNotification:\033[0m %s\n",
209
210 switch (nc->event_type)
211 {
212 case NT_ACCOUNT:
214 break;
215 case NT_COLOR:
217 break;
218 case NT_COMMAND:
220 break;
221 case NT_CONFIG:
223 break;
224 case NT_MVIEW:
226 break;
227 case NT_EMAIL:
229 break;
230 case NT_GLOBAL:
232 break;
233 case NT_MAILBOX:
235 break;
236 case NT_RESIZE:
237 case NT_TIMEOUT:
238 break; // no other data
239 case NT_WINDOW:
242 else if (nc->event_subtype == NT_WINDOW_FOCUS)
244 break;
245 default:
246 mutt_debug(LL_DEBUG1, " Event Type: %d\n", nc->event_type);
247 mutt_debug(LL_DEBUG1, " Event Sub-type: %d\n", nc->event_subtype);
248 mutt_debug(LL_DEBUG1, " Event Data: %p\n", nc->event_data);
249 break;
250 }
251
252 mutt_debug(LL_DEBUG1, " Global Data: %p\n", nc->global_data);
253
254 mutt_debug(LL_DEBUG5, "debug done\n");
255 return 0;
256}
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:203
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
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:94
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:663
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:174
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:212
const char * name_notify_config(int id)
Definition: names.c:185
const char * name_notify_mailbox(int id)
Definition: names.c:196
static void notify_dump_global(struct NotifyCallback *nc)
Definition: notify.c:125
const struct Mapping ComposeColorFields[]
Mapping of compose colour names to their IDs.
Definition: command.c:111
const struct Mapping ColorFields[]
Mapping of colour names to their IDs.
Definition: command.c:56
static void notify_dump_config(struct NotifyCallback *nc)
Definition: notify.c:91
static void notify_dump_mview(struct NotifyCallback *nc)
Definition: notify.c:102
static void notify_dump_command(struct NotifyCallback *nc)
Definition: notify.c:81
static void notify_dump_color(struct NotifyCallback *nc)
Definition: notify.c:54
int debug_all_observer(struct NotifyCallback *nc)
Definition: notify.c:205
static void notify_dump_mailbox(struct NotifyCallback *nc)
Definition: notify.c:130
static void notify_dump_window_focus(struct NotifyCallback *nc)
Definition: notify.c:175
static void notify_dump_account(struct NotifyCallback *nc)
Definition: notify.c:43
static void notify_dump_email(struct NotifyCallback *nc)
Definition: notify.c:114
static void notify_dump_window_state(struct NotifyCallback *nc)
Definition: notify.c:140
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:735
#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:41
@ 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:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
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:51
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:53
enum ColorId cid
Colour ID that has changed.
Definition: notify2.h:54
A config-change event.
Definition: subset.h:71
const struct ConfigSubset * sub
Config Subset.
Definition: subset.h:72
const char * name
Name of config item that changed.
Definition: subset.h:73
struct HashElem * he
Config item that changed.
Definition: subset.h:74
An Event that happened to an Email.
Definition: email.h:199
int num_emails
Number of Emails the event applies to.
Definition: email.h:200
struct Email ** emails
Emails affected by the event.
Definition: email.h:201
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: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