]> granicus.if.org Git - neomutt/commitdiff
notify: add Account Events
authorRichard Russon <rich@flatcap.org>
Wed, 3 Jul 2019 10:01:13 +0000 (11:01 +0100)
committerRichard Russon <rich@flatcap.org>
Sat, 13 Jul 2019 23:25:45 +0000 (00:25 +0100)
account.c
account.h
neomutt.c

index b145d65f14589c2fcfe2964830ef68962a793824..252f7e0823dd88674dcf16da5e475f9d294a891c 100644 (file)
--- 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);
index e19a22fc8c34b9ce5361e2bdac8272d3b5b135cb..bb230ec51c22dcf469c58bc1c532f58d5ae3d4dc 100644 (file)
--- 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);
index 52f402365f3600d090956471383d8f92099ec059..28fcc2b881392302f0548a9634d8688cd62d38f6 100644 (file)
--- 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;