From: Richard Russon Date: Tue, 9 Jul 2019 14:23:50 +0000 (+0100) Subject: notify: add Mailbox Events X-Git-Tag: 2019-10-25~139^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c1af2595f9af846ee37b35ee756b4050c9f33fa5;p=neomutt notify: add Mailbox Events --- diff --git a/account.c b/account.c index 9ababa009..2d7df2d6d 100644 --- a/account.c +++ b/account.c @@ -133,7 +133,10 @@ bool account_mailbox_add(struct Account *a, struct Mailbox *m) struct MailboxNode *np = mutt_mem_calloc(1, sizeof(*np)); np->mailbox = m; STAILQ_INSERT_TAIL(&a->mailboxes, np, entries); + notify_set_parent(m->notify, a->notify); + struct EventMailbox ev_m = { m }; + notify_send(a->notify, NT_MAILBOX, NT_MAILBOX_ADD, IP & ev_m); return true; } @@ -156,6 +159,8 @@ bool account_mailbox_remove(struct Account *a, struct Mailbox *m) { if (!m || (np->mailbox == m)) { + struct EventMailbox ev_m = { m }; + notify_send(a->notify, NT_MAILBOX, NT_MAILBOX_REMOVE, IP & ev_m); STAILQ_REMOVE(&a->mailboxes, np, MailboxNode, entries); mailbox_free(&np->mailbox); FREE(&np); diff --git a/mailbox.h b/mailbox.h index f45665fc6..234f47653 100644 --- a/mailbox.h +++ b/mailbox.h @@ -146,6 +146,7 @@ struct Mailbox void *mdata; /**< driver specific data */ void (*free_mdata)(void **); /**< driver-specific data free function */ + struct Notify *notify; ///< Notifications handler void (*notify2)(struct Mailbox *m, enum MailboxNotification action); ///< Notification callback void *ndata; ///< Notification callback private data }; @@ -160,6 +161,23 @@ struct MailboxNode }; STAILQ_HEAD(MailboxList, MailboxNode); +/** + * struct EventMailbox - An Event that happened to a Mailbox + */ +struct EventMailbox +{ + struct Mailbox *mailbox; ///< The Mailbox this Event relates to +}; + +/** + * enum NotifyMailbox - Types of Mailbox Event + */ +enum NotifyMailbox +{ + NT_MAILBOX_ADD = 1, ///< A new Mailbox has been created + NT_MAILBOX_REMOVE, ///< A Mailbox is about to be destroyed +}; + void mailbox_free (struct Mailbox **ptr); struct Mailbox *mailbox_new (void); void mutt_mailbox_changed (struct Mailbox *m, enum MailboxNotification action);