NeoMutt  2024-12-12-19-ge4b57e
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
shared_data.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <stdbool.h>
32#include "mutt/lib.h"
33#include "email/lib.h"
34#include "core/lib.h"
35#include "shared_data.h"
36#include "lib.h"
37#include "pattern/lib.h"
38#include "mview.h"
39
44{
45 if (nc->event_type != NT_MVIEW)
46 return 0;
47 if (!nc->global_data || !nc->event_data)
48 return -1;
49 if (nc->event_subtype == NT_MVIEW_ADD)
50 return 0;
51
52 struct EventMview *ev_m = nc->event_data;
53 struct IndexSharedData *shared = nc->global_data;
54 if (ev_m->mv != shared->mailbox_view)
55 return 0;
56
58 shared->mailbox_view = NULL;
59
60 mutt_debug(LL_NOTIFY, "relay NT_MVIEW to shared data observers\n");
62 return 0;
63}
64
69{
70 if (nc->event_type != NT_ACCOUNT)
71 return 0;
72 if (!nc->global_data || !nc->event_data)
73 return -1;
75 return 0;
76
77 struct EventAccount *ev_a = nc->event_data;
78 struct IndexSharedData *shared = nc->global_data;
79 if (ev_a->account != shared->account)
80 return 0;
81
83 shared->account = NULL;
84
85 mutt_debug(LL_NOTIFY, "relay NT_ACCOUNT to shared data observers\n");
87 return 0;
88}
89
94{
95 if (nc->event_type != NT_MAILBOX)
96 return 0;
97 if (!nc->global_data || !nc->event_data)
98 return -1;
100 return 0;
101
102 struct EventMailbox *ev_m = nc->event_data;
103 struct IndexSharedData *shared = nc->global_data;
104 if (ev_m->mailbox != shared->mailbox)
105 return 0;
106
108 shared->mailbox = NULL;
109
110 mutt_debug(LL_NOTIFY, "relay NT_MAILBOX to shared data observers\n");
111 notify_send(shared->notify, nc->event_type, nc->event_subtype, nc->event_data);
112 return 0;
113}
114
119{
120 if (nc->event_type != NT_EMAIL)
121 return 0;
122 if (!nc->global_data || !nc->event_data)
123 return -1;
124 if (nc->event_subtype == NT_EMAIL_ADD)
125 return 0;
126
127 struct EventEmail *ev_e = nc->event_data;
128 struct IndexSharedData *shared = nc->global_data;
129 bool match = false;
130 for (int i = 0; i < ev_e->num_emails; i++)
131 {
132 if (ev_e->emails[i] == shared->email)
133 {
134 match = true;
135 break;
136 }
137 }
138
139 if (!match)
140 return 0;
141
143 {
144 shared->email = NULL;
145 mutt_debug(LL_NOTIFY, "NT_INDEX_EMAIL: %p\n", (void *) shared->email);
146 notify_send(shared->notify, NT_INDEX, NT_INDEX_EMAIL, shared);
147 }
148
149 mutt_debug(LL_NOTIFY, "relay NT_EMAIL %p to shared data observers\n",
150 (void *) shared->email);
151 notify_send(shared->notify, nc->event_type, nc->event_subtype, nc->event_data);
152 return 0;
153}
154
161{
162 if (!shared)
163 return;
164
166
167 if (shared->mailbox_view != mv)
168 {
169 if (shared->mailbox_view)
170 {
173 }
174
175 shared->mailbox_view = mv;
176 subtype |= NT_INDEX_MVIEW;
177
178 if (mv)
180 }
181
182 struct Mailbox *m = mview_mailbox(mv);
183 if (shared->mailbox != m)
184 {
185 if (shared->mailbox)
187
188 shared->mailbox = m;
189 shared->email = NULL;
190 shared->email_seq = 0;
191 subtype |= NT_INDEX_MAILBOX | NT_INDEX_EMAIL;
192
193 if (m)
195 }
196
197 struct Account *a = m ? m->account : NULL;
198 if (shared->account != a)
199 {
200 if (shared->account)
202
203 shared->account = a;
204 subtype |= NT_INDEX_ACCOUNT;
205
206 if (a)
208 }
209
210 struct ConfigSubset *sub = NeoMutt->sub;
211#if 0
212 if (m)
213 sub = m->sub;
214 else if (a)
215 sub = a->sub;
216#endif
217 if (shared->sub != sub)
218 {
219 shared->sub = sub;
220 subtype |= NT_INDEX_SUBSET;
221 }
222
223 if (subtype != NT_INDEX_NO_FLAGS)
224 {
225 mutt_debug(LL_NOTIFY, "NT_INDEX: %p\n", (void *) shared);
226 notify_send(shared->notify, NT_INDEX, subtype, shared);
227 }
228}
229
235void index_shared_data_set_email(struct IndexSharedData *shared, struct Email *e)
236{
237 if (!shared)
238 return;
239
240 size_t seq = e ? e->sequence : 0;
241 if ((shared->email != e) || (shared->email_seq != seq))
242 {
243 if (shared->email)
245
246 shared->email = e;
247 shared->email_seq = seq;
248
249 if (e)
251
252 mutt_debug(LL_NOTIFY, "NT_INDEX_EMAIL: %p\n", (void *) shared->email);
253 notify_send(shared->notify, NT_INDEX, NT_INDEX_EMAIL, shared);
254 }
255}
256
265 const struct Email *e)
266{
267 if (!shared)
268 return false;
269
270 return shared->email_seq == e->sequence;
271}
272
278void index_shared_data_free(struct MuttWindow *win, void **ptr)
279{
280 if (!ptr || !*ptr)
281 return;
282
283 struct IndexSharedData *shared = *ptr;
284
285 mutt_debug(LL_NOTIFY, "NT_INDEX_DELETE: %p\n", (void *) shared);
286 notify_send(shared->notify, NT_INDEX, NT_INDEX_DELETE, shared);
287 notify_free(&shared->notify);
288
289 if (shared->account)
291 if (shared->mailbox_view)
293 if (shared->mailbox)
295 if (shared->email)
297
299
300 FREE(ptr);
301}
302
308{
309 struct IndexSharedData *shared = MUTT_MEM_CALLOC(1, struct IndexSharedData);
310
311 shared->notify = notify_new();
312 shared->sub = NeoMutt->sub;
313 shared->search_state = search_state_new();
314
315 mutt_debug(LL_NOTIFY, "NT_INDEX_ADD: %p\n", (void *) shared);
316 notify_send(shared->notify, NT_INDEX, NT_INDEX_ADD, shared);
317
318 return shared;
319}
@ NT_ACCOUNT_ADD
Account has been added.
Definition: account.h:69
@ NT_ACCOUNT_DELETE
Account is about to be deleted.
Definition: account.h:70
Convenience wrapper for the core headers.
@ NT_MAILBOX_DELETE
Mailbox is about to be deleted.
Definition: mailbox.h:183
@ NT_MAILBOX_ADD
Mailbox has been added.
Definition: mailbox.h:182
Structs that make up an email.
@ NT_EMAIL_ADD
Email has been added.
Definition: email.h:183
@ NT_EMAIL_DELETE
Email is about to be deleted.
Definition: email.h:184
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
static int index_shared_mview_observer(struct NotifyCallback *nc)
Notification that the MailboxView has changed - Implements observer_t -.
Definition: shared_data.c:43
static int index_shared_account_observer(struct NotifyCallback *nc)
Notification that an Account has changed - Implements observer_t -.
Definition: shared_data.c:68
static int index_shared_email_observer(struct NotifyCallback *nc)
Notification that an Email has changed - Implements observer_t -.
Definition: shared_data.c:118
static int index_shared_mailbox_observer(struct NotifyCallback *nc)
Notification that a Mailbox has changed - Implements observer_t -.
Definition: shared_data.c:93
void index_shared_data_free(struct MuttWindow *win, void **ptr)
Free Shared Index Data - Implements MuttWindow::wdata_free() -.
Definition: shared_data.c:278
#define NT_INDEX_DELETE
Index Shared Data is about to be freed.
Definition: lib.h:66
#define NT_INDEX_MAILBOX
Mailbox has changed.
Definition: lib.h:70
uint8_t NotifyIndex
Flags, e.g. NT_INDEX_ACCOUNT.
Definition: lib.h:63
#define NT_INDEX_SUBSET
Config Subset has changed.
Definition: lib.h:67
#define NT_INDEX_MVIEW
MailboxView has changed.
Definition: lib.h:69
#define NT_INDEX_ADD
New Index Shared Data has been created.
Definition: lib.h:65
#define NT_INDEX_ACCOUNT
Account has changed.
Definition: lib.h:68
#define NT_INDEX_EMAIL
Email has changed.
Definition: lib.h:71
#define NT_INDEX_NO_FLAGS
No flags are set.
Definition: lib.h:64
void index_shared_data_set_email(struct IndexSharedData *shared, struct Email *e)
Set the current Email for the Index and friends.
Definition: shared_data.c:235
bool index_shared_data_is_cur_email(const struct IndexSharedData *shared, const struct Email *e)
Check whether an email is the currently selected Email.
Definition: shared_data.c:264
struct IndexSharedData * index_shared_data_new(void)
Create new Index Data.
Definition: shared_data.c:307
void index_shared_data_set_mview(struct IndexSharedData *shared, struct MailboxView *mv)
Set the MailboxView for the Index and friends.
Definition: shared_data.c:160
Data shared between Index, Pager and Sidebar.
@ LL_NOTIFY
Log of notifications.
Definition: logging2.h:48
#define FREE(x)
Definition: memory.h:55
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
Convenience wrapper for the library headers.
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition: notify.c:230
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:191
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:62
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:173
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:75
struct Mailbox * mview_mailbox(struct MailboxView *mv)
Wrapper to get the mailbox in a MailboxView, or NULL.
Definition: mview.c:449
View of a Mailbox.
@ NT_MVIEW_DELETE
The Mview is about to be destroyed.
Definition: mview.h:63
@ NT_MVIEW_ADD
The Mview has been opened.
Definition: mview.h:62
@ 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_ACCOUNT
Account has changed, NotifyAccount, EventAccount.
Definition: notify_type.h:36
@ NT_INDEX
Index data has changed, NotifyIndex, IndexSharedData.
Definition: notify_type.h:48
@ NT_MVIEW
MailboxView has changed, NotifyMview, EventMview.
Definition: notify_type.h:50
Match patterns to emails.
void search_state_free(struct SearchState **ptr)
Free a SearchState.
Definition: search_state.c:51
struct SearchState * search_state_new(void)
Create a new SearchState.
Definition: search_state.c:39
Key value store.
A group of associated Mailboxes.
Definition: account.h:36
struct Notify * notify
Notifications: NotifyAccount, EventAccount.
Definition: account.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: account.h:39
A set of inherited config items.
Definition: subset.h:47
The envelope/body of an email.
Definition: email.h:39
struct Notify * notify
Notifications: NotifyEmail, EventEmail.
Definition: email.h:73
size_t sequence
Sequence number assigned on creation.
Definition: email.h:67
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 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
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:37
size_t email_seq
Sequence number of the current email.
Definition: shared_data.h:43
struct Account * account
Current Account.
Definition: shared_data.h:39
struct Email * email
Currently selected Email.
Definition: shared_data.h:42
struct Mailbox * mailbox
Current Mailbox.
Definition: shared_data.h:41
struct ConfigSubset * sub
Config set to use.
Definition: shared_data.h:38
struct MailboxView * mailbox_view
Current Mailbox view.
Definition: shared_data.h:40
struct SearchState * search_state
State of the current search.
Definition: shared_data.h:45
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition: shared_data.h:44
View of a Mailbox.
Definition: mview.h:40
struct Notify * notify
Notifications: NotifyMview, EventMview.
Definition: mview.h:52
A mailbox.
Definition: mailbox.h:79
struct Notify * notify
Notifications: NotifyMailbox, EventMailbox.
Definition: mailbox.h:145
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:127
struct ConfigSubset * sub
Inherited config items.
Definition: mailbox.h:83
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
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