From: Richard Russon Date: Wed, 3 Jul 2019 10:01:13 +0000 (+0100) Subject: notify: add Account Events X-Git-Tag: 2019-10-25~139^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=80c96a23a3db379ab0adadcd26b1ce4fea0abcae;p=neomutt notify: add Account Events --- diff --git a/account.c b/account.c index b145d65f1..252f7e082 100644 --- a/account.c +++ b/account.c @@ -39,6 +39,7 @@ struct Account *account_new(void) { struct Account *a = mutt_mem_calloc(1, sizeof(struct Account)); STAILQ_INIT(&a->mailboxes); + a->notify = notify_new(a, NT_ACCOUNT); return a; } @@ -167,6 +168,7 @@ void account_free(struct Account **ptr) if (a->free_adata) a->free_adata(&a->adata); + notify_free(&a->notify); account_free_config(a); FREE(ptr); diff --git a/account.h b/account.h index e19a22fc8..bb230ec51 100644 --- a/account.h +++ b/account.h @@ -52,6 +52,23 @@ struct Account }; TAILQ_HEAD(AccountList, Account); +/** + * struct EventAccount - An Event that happened to an Account + */ +struct EventAccount +{ + struct Account *account; ///< The Account this Event relates to +}; + +/** + * enum NotifyAccount - Types of Account Event + */ +enum NotifyAccount +{ + NT_ACCOUNT_ADD = 1, ///< A new Account has been created + NT_ACCOUNT_REMOVE, ///< An Account is about to be destroyed +}; + bool account_add_config(struct Account *a, const struct ConfigSet *cs, const char *name, const char *var_names[]); void account_free(struct Account **ptr); void account_free_config(struct Account *a); diff --git a/neomutt.c b/neomutt.c index 52f402365..28fcc2b88 100644 --- a/neomutt.c +++ b/neomutt.c @@ -78,6 +78,8 @@ bool neomutt_account_add(struct NeoMutt *n, struct Account *a) TAILQ_INSERT_TAIL(&n->accounts, a, entries); notify_set_parent(a->notify, n->notify); + struct EventAccount ev_a = { a }; + notify_send(n->notify, NT_ACCOUNT, NT_ACCOUNT_ADD, IP & ev_a); return true; } @@ -101,6 +103,8 @@ bool neomutt_account_remove(struct NeoMutt *n, struct Account *a) { if (!a || (np == a)) { + struct EventAccount ev_a = { np }; + notify_send(n->notify, NT_ACCOUNT, NT_ACCOUNT_REMOVE, IP & ev_a); TAILQ_REMOVE(&n->accounts, np, entries); account_free(&np); result = true;