NeoMutt  2023-05-17-33-gce4425
Teaching an old dog new tricks
DOXYGEN
shared_data.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stdbool.h>
31#include "mutt/lib.h"
32#include "email/lib.h"
33#include "core/lib.h"
34#include "shared_data.h"
35#include "lib.h"
36#include "mview.h"
37
44{
45 if (!shared)
46 return;
47
49
50 if (shared->mailbox_view != mv)
51 {
52 shared->mailbox_view = mv;
53 subtype |= NT_INDEX_MVIEW;
54 }
55
56 struct Mailbox *m = mview_mailbox(mv);
57 if (shared->mailbox != m)
58 {
59 shared->mailbox = m;
60 shared->email = NULL;
61 shared->email_seq = 0;
63 }
64
65 struct Account *a = m ? m->account : NULL;
66 if (shared->account != a)
67 {
68 shared->account = a;
69 subtype |= NT_INDEX_ACCOUNT;
70 }
71
72 struct ConfigSubset *sub = NeoMutt->sub;
73#if 0
74 if (m)
75 sub = m->sub;
76 else if (a)
77 sub = a->sub;
78#endif
79 if (shared->sub != sub)
80 {
81 shared->sub = sub;
82 subtype |= NT_INDEX_SUBSET;
83 }
84
85 if (subtype != NT_INDEX_NO_FLAGS)
86 {
87 mutt_debug(LL_NOTIFY, "NT_INDEX: %p\n", shared);
88 notify_send(shared->notify, NT_INDEX, subtype, shared);
89 }
90}
91
97void index_shared_data_set_email(struct IndexSharedData *shared, struct Email *e)
98{
99 if (!shared)
100 return;
101
102 size_t seq = e ? e->sequence : 0;
103 if ((shared->email != e) || (shared->email_seq != seq))
104 {
105 shared->email = e;
106 shared->email_seq = seq;
107
108 mutt_debug(LL_NOTIFY, "NT_INDEX_EMAIL: %p\n", shared->email);
109 notify_send(shared->notify, NT_INDEX, NT_INDEX_EMAIL, shared);
110 }
111}
112
121 const struct Email *e)
122{
123 if (!shared)
124 return false;
125
126 return shared->email_seq == e->sequence;
127}
128
134void index_shared_data_free(struct MuttWindow *win, void **ptr)
135{
136 if (!ptr || !*ptr)
137 return;
138
139 struct IndexSharedData *shared = *ptr;
140
141 mutt_debug(LL_NOTIFY, "NT_INDEX_DELETE: %p\n", shared);
142 notify_send(shared->notify, NT_INDEX, NT_INDEX_DELETE, shared);
143 notify_free(&shared->notify);
144
145 FREE(ptr);
146}
147
153{
154 struct IndexSharedData *shared = mutt_mem_calloc(1, sizeof(struct IndexSharedData));
155
156 shared->notify = notify_new();
157 shared->sub = NeoMutt->sub;
158
159 mutt_debug(LL_NOTIFY, "NT_INDEX_ADD: %p\n", shared);
160 notify_send(shared->notify, NT_INDEX, NT_INDEX_ADD, shared);
161
162 return shared;
163}
Convenience wrapper for the core headers.
Structs that make up an email.
#define mutt_debug(LEVEL,...)
Definition: logging2.h:84
void index_shared_data_free(struct MuttWindow *win, void **ptr)
Free Shared Index Data - Implements MuttWindow::wdata_free() -.
Definition: shared_data.c:134
#define NT_INDEX_DELETE
Index Shared Data is about to be freed.
Definition: lib.h:61
#define NT_INDEX_MAILBOX
Mailbox has changed.
Definition: lib.h:65
uint8_t NotifyIndex
Flags, e.g. NT_INDEX_ACCOUNT.
Definition: lib.h:58
#define NT_INDEX_SUBSET
Config Subset has changed.
Definition: lib.h:62
#define NT_INDEX_MVIEW
MailboxView has changed.
Definition: lib.h:64
#define NT_INDEX_ADD
New Index Shared Data has been created.
Definition: lib.h:60
#define NT_INDEX_ACCOUNT
Account has changed.
Definition: lib.h:63
#define NT_INDEX_EMAIL
Email has changed.
Definition: lib.h:66
#define NT_INDEX_NO_FLAGS
No flags are set.
Definition: lib.h:59
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:97
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:120
struct IndexSharedData * index_shared_data_new(void)
Create new Index Data.
Definition: shared_data.c:152
void index_shared_data_set_mview(struct IndexSharedData *shared, struct MailboxView *mv)
Set the MailboxView for the Index and friends.
Definition: shared_data.c:43
Data shared between Index, Pager and Sidebar.
@ LL_NOTIFY
Log of notifications.
Definition: logging2.h:45
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define FREE(x)
Definition: memory.h:43
Convenience wrapper for the library headers.
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:60
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:171
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:73
struct Mailbox * mview_mailbox(struct MailboxView *mv)
Wrapper to get the mailbox in a MailboxView, or NULL.
Definition: mview.c:439
View of a Mailbox.
@ NT_INDEX
Index data has changed, NotifyIndex, IndexSharedData.
Definition: notify_type.h:48
Key value store.
A group of associated Mailboxes.
Definition: account.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: account.h:40
A set of inherited config items.
Definition: subset.h:47
The envelope/body of an email.
Definition: email.h:37
size_t sequence
Sequence number assigned on creation.
Definition: email.h:65
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 Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition: shared_data.h:44
View of a Mailbox.
Definition: mview.h:39
A mailbox.
Definition: mailbox.h:79
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:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39