NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
shared_data.h File Reference

Data shared between Index, Pager and Sidebar. More...

#include <stdbool.h>
#include <stdio.h>
+ Include dependency graph for shared_data.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  IndexSharedData
 Data shared between Index, Pager and Sidebar. More...
 

Functions

void index_shared_data_free (struct MuttWindow *win, void **ptr)
 Free Index Data. More...
 
struct IndexSharedDataindex_shared_data_new (void)
 Create new Index Data. More...
 
bool index_shared_data_is_cur_email (const struct IndexSharedData *shared, const struct Email *e)
 Check whether an email is the currently selected Email. More...
 
void index_shared_data_set_context (struct IndexSharedData *shared, struct Context *ctx)
 Set the Context for the Index and friends. More...
 
void index_shared_data_set_email (struct IndexSharedData *shared, struct Email *e)
 Set the current Email for the Index and friends. More...
 

Detailed Description

Data shared between Index, Pager and Sidebar.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file shared_data.h.

Function Documentation

◆ index_shared_data_free()

void index_shared_data_free ( struct MuttWindow win,
void **  ptr 
)

Free Index Data.

Parameters
winWindow
ptrIndex Data to free

Only notify is owned by IndexSharedData and should be freed.

Definition at line 273 of file shared_data.c.

274 {
275  if (!ptr || !*ptr)
276  return;
277 
278  struct IndexSharedData *shared = *ptr;
279 
280  mutt_debug(LL_NOTIFY, "NT_INDEX_DELETE: %p\n", shared);
281  notify_send(shared->notify, NT_INDEX, NT_INDEX_DELETE, shared);
282  notify_free(&shared->notify);
283 
284  if (shared->account)
286  if (shared->ctx)
288  if (shared->mailbox)
290  if (shared->email)
292 
293  FREE(ptr);
294 }
static int index_shared_mailbox_observer(struct NotifyCallback *nc)
Notification that a Mailbox has changed - Implements observer_t.
Definition: shared_data.c:92
Log of notifications.
Definition: logging.h:45
struct Email * email
Currently selected Email.
Definition: shared_data.h:42
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:73
static int index_shared_email_observer(struct NotifyCallback *nc)
Notification that an Email has changed - Implements observer_t.
Definition: shared_data.c:117
struct Notify * notify
Notifications: NotifyAccount, EventAccount.
Definition: account.h:42
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:36
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition: shared_data.h:44
Index data has changed, NotifyIndex, IndexSharedData.
Definition: notify_type.h:47
struct Notify * notify
Notifications: NotifyContext, EventContext.
Definition: context.h:50
#define NT_INDEX_DELETE
Index Shared Data is about to be freed.
Definition: lib.h:60
struct Context * ctx
Current Mailbox view.
Definition: shared_data.h:39
static int index_shared_context_observer(struct NotifyCallback *nc)
Notification that the Context has changed - Implements observer_t.
Definition: shared_data.c:42
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
static int index_shared_account_observer(struct NotifyCallback *nc)
Notification that an Account has changed - Implements observer_t.
Definition: shared_data.c:67
struct Notify * notify
Notifications: NotifyEmail, EventEmail.
Definition: email.h:123
#define FREE(x)
Definition: memory.h:40
struct Account * account
Current Account.
Definition: shared_data.h:40
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:228
struct Notify * notify
Notifications: NotifyMailbox, EventMailbox.
Definition: mailbox.h:148
struct Mailbox * mailbox
Current Mailbox.
Definition: shared_data.h:41
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ index_shared_data_new()

struct IndexSharedData* index_shared_data_new ( void  )

Create new Index Data.

Return values
ptrNew IndexSharedData

Definition at line 300 of file shared_data.c.

301 {
302  struct IndexSharedData *shared = mutt_mem_calloc(1, sizeof(struct IndexSharedData));
303 
304  shared->notify = notify_new();
305  shared->sub = NeoMutt->sub;
306 
307  mutt_debug(LL_NOTIFY, "NT_INDEX_ADD: %p\n", shared);
308  notify_send(shared->notify, NT_INDEX, NT_INDEX_ADD, shared);
309 
310  return shared;
311 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
Log of notifications.
Definition: logging.h:45
struct ConfigSubset * sub
Config set to use.
Definition: shared_data.h:38
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:36
Container for Accounts, Notifications.
Definition: neomutt.h:36
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition: shared_data.h:44
Index data has changed, NotifyIndex, IndexSharedData.
Definition: notify_type.h:47
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:60
#define NT_INDEX_ADD
New Index Shared Data has been created.
Definition: lib.h:59
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ index_shared_data_is_cur_email()

bool index_shared_data_is_cur_email ( const struct IndexSharedData shared,
const struct Email e 
)

Check whether an email is the currently selected Email.

Parameters
sharedShared Index data
eEmail to check
Return values
truee is current
falsee is not current

Definition at line 257 of file shared_data.c.

259 {
260  if (!shared)
261  return false;
262 
263  return shared->email_seq == e->sequence;
264 }
size_t email_seq
Sequence number of the current email.
Definition: shared_data.h:43
size_t sequence
Sequence number assigned on creation.
Definition: email.h:99
+ Here is the caller graph for this function:

◆ index_shared_data_set_context()

void index_shared_data_set_context ( struct IndexSharedData shared,
struct Context ctx 
)

Set the Context for the Index and friends.

Parameters
sharedShared Index data
ctxNew Context, may be NULL

Definition at line 154 of file shared_data.c.

155 {
156  if (!shared)
157  return;
158 
159  NotifyIndex subtype = NT_INDEX_NO_FLAGS;
160 
161  if (shared->ctx != ctx)
162  {
163  if (shared->ctx)
165 
166  shared->ctx = ctx;
167  subtype |= NT_INDEX_CONTEXT;
168 
169  if (ctx)
171 
172  Context = ctx;
173  }
174 
175  struct Mailbox *m = ctx_mailbox(ctx);
176  if (shared->mailbox != m)
177  {
178  if (shared->mailbox)
180 
181  shared->mailbox = m;
182  shared->email = NULL;
183  shared->email_seq = 0;
184  subtype |= NT_INDEX_MAILBOX | NT_INDEX_EMAIL;
185 
186  if (m)
188  }
189 
190  struct Account *a = m ? m->account : NULL;
191  if (shared->account != a)
192  {
193  if (shared->account)
195 
196  shared->account = a;
197  subtype |= NT_INDEX_ACCOUNT;
198 
199  if (a)
201  }
202 
203  struct ConfigSubset *sub = NeoMutt->sub;
204 #if 0
205  if (m)
206  sub = m->sub;
207  else if (a)
208  sub = a->sub;
209 #endif
210  if (shared->sub != sub)
211  {
212  shared->sub = sub;
213  subtype |= NT_INDEX_SUBSET;
214  }
215 
216  if (subtype != NT_INDEX_NO_FLAGS)
217  {
218  mutt_debug(LL_NOTIFY, "NT_INDEX: %p\n", shared);
219  notify_send(shared->notify, NT_INDEX, subtype, shared);
220  }
221 }
The "current" mailbox.
Definition: context.h:37
#define NT_INDEX_SUBSET
Config Subset has changed.
Definition: lib.h:61
#define NT_INDEX_CONTEXT
Context has changed.
Definition: lib.h:63
size_t email_seq
Sequence number of the current email.
Definition: shared_data.h:43
static int index_shared_mailbox_observer(struct NotifyCallback *nc)
Notification that a Mailbox has changed - Implements observer_t.
Definition: shared_data.c:92
struct Mailbox * ctx_mailbox(struct Context *ctx)
wrapper to get the mailbox in a Context, or NULL
Definition: context.c:444
Log of notifications.
Definition: logging.h:45
struct Email * email
Currently selected Email.
Definition: shared_data.h:42
#define NT_INDEX_EMAIL
Email has changed.
Definition: lib.h:65
struct ConfigSubset * sub
Config set to use.
Definition: shared_data.h:38
struct Notify * notify
Notifications: NotifyAccount, EventAccount.
Definition: account.h:42
uint8_t NotifyIndex
Flags, e.g. NT_INDEX_ACCOUNT.
Definition: lib.h:55
A group of associated Mailboxes.
Definition: account.h:36
#define NT_INDEX_ACCOUNT
Account has changed.
Definition: lib.h:62
#define NT_INDEX_MAILBOX
Mailbox has changed.
Definition: lib.h:64
Container for Accounts, Notifications.
Definition: neomutt.h:36
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition: shared_data.h:44
Index data has changed, NotifyIndex, IndexSharedData.
Definition: notify_type.h:47
struct Notify * notify
Notifications: NotifyContext, EventContext.
Definition: context.h:50
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:189
struct Context * ctx
Current Mailbox view.
Definition: shared_data.h:39
A set of inherited config items.
Definition: subset.h:46
A mailbox.
Definition: mailbox.h:81
struct ConfigSubset * sub
Inherited config items.
Definition: mailbox.h:86
static int index_shared_context_observer(struct NotifyCallback *nc)
Notification that the Context has changed - Implements observer_t.
Definition: shared_data.c:42
Account has changed, NotifyAccount, EventAccount.
Definition: notify_type.h:34
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
static int index_shared_account_observer(struct NotifyCallback *nc)
Notification that an Account has changed - Implements observer_t.
Definition: shared_data.c:67
#define NT_INDEX_NO_FLAGS
No flags are set.
Definition: lib.h:58
Context has changed, NotifyContext, EventContext.
Definition: notify_type.h:43
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:131
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition: notify_type.h:48
struct ConfigSubset * sub
Inherited config items.
Definition: account.h:40
struct Account * account
Current Account.
Definition: shared_data.h:40
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:228
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
struct Notify * notify
Notifications: NotifyMailbox, EventMailbox.
Definition: mailbox.h:148
struct Mailbox * mailbox
Current Mailbox.
Definition: shared_data.h:41
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ index_shared_data_set_email()

void index_shared_data_set_email ( struct IndexSharedData shared,
struct Email e 
)

Set the current Email for the Index and friends.

Parameters
sharedShared Index data
eCurrent Email, may be NULL

Definition at line 228 of file shared_data.c.

229 {
230  if (!shared)
231  return;
232 
233  size_t seq = e ? e->sequence : 0;
234  if ((shared->email != e) || (shared->email_seq != seq))
235  {
236  if (shared->email)
238 
239  shared->email = e;
240  shared->email_seq = seq;
241 
242  if (e)
244 
245  mutt_debug(LL_NOTIFY, "NT_INDEX_EMAIL: %p\n", shared->email);
246  notify_send(shared->notify, NT_INDEX, NT_INDEX_EMAIL, shared);
247  }
248 }
size_t email_seq
Sequence number of the current email.
Definition: shared_data.h:43
Log of notifications.
Definition: logging.h:45
struct Email * email
Currently selected Email.
Definition: shared_data.h:42
#define NT_INDEX_EMAIL
Email has changed.
Definition: lib.h:65
static int index_shared_email_observer(struct NotifyCallback *nc)
Notification that an Email has changed - Implements observer_t.
Definition: shared_data.c:117
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition: shared_data.h:44
Index data has changed, NotifyIndex, IndexSharedData.
Definition: notify_type.h:47
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:189
size_t sequence
Sequence number assigned on creation.
Definition: email.h:99
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
struct Notify * notify
Notifications: NotifyEmail, EventEmail.
Definition: email.h:123
Email has changed, NotifyEmail, EventEmail.
Definition: notify_type.h:44
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:228
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function: