return;
struct Context *ctx = *ptr;
+
+ struct EventContext ev_ctx = { ctx };
+ notify_send(ctx->notify, NT_CONTEXT, NT_CONTEXT_CLOSE, IP & ev_ctx);
+
if (ctx->mailbox)
notify_observer_remove(ctx->mailbox->notify, ctx_mailbox_observer);
+ notify_free(&ctx->notify);
+
FREE(ptr);
}
+/**
+ * ctx_new - Create a new Context
+ * @retval ptr New Context
+ */
+struct Context *ctx_new(void)
+{
+ struct Context *ctx = mutt_mem_calloc(1, sizeof(struct Context));
+
+ ctx->notify = notify_new(ctx, NT_CONTEXT);
+ notify_set_parent(ctx->notify, NeoMutt->notify);
+
+ return ctx;
+}
+
/**
* ctx_cleanup - Release memory and initialize a Context object
* @param ctx Context to cleanup
mutt_pattern_free(&ctx->limit_pattern);
if (ctx->mailbox)
notify_observer_remove(ctx->mailbox->notify, ctx_mailbox_observer);
+
+ struct Notify *notify = ctx->notify;
memset(ctx, 0, sizeof(struct Context));
+ ctx->notify = notify;
}
/**
bool collapsed : 1; ///< Are all threads collapsed?
struct Mailbox *mailbox;
+ struct Notify *notify; ///< Notifications handler
+};
+
+/**
+ * struct EventContext - An Event that happened to an Context
+ */
+struct EventContext
+{
+ struct Context *context; ///< The Context this Event relates to
+};
+
+/**
+ * enum NotifyContext - Types of Context Event
+ */
+enum NotifyContext
+{
+ NT_CONTEXT_OPEN = 1, ///< The Context has been opened
+ NT_CONTEXT_CLOSE, ///< The Context is about to be destroyed
};
void ctx_free (struct Context **ptr);
int ctx_mailbox_observer(struct NotifyCallback *nc);
+struct Context *ctx_new (void);
void ctx_update (struct Context *ctx);
void ctx_update_tables (struct Context *ctx, bool committing);
if (!m)
return NULL;
- struct Context *ctx = mutt_mem_calloc(1, sizeof(*ctx));
+ struct Context *ctx = ctx_new();
ctx->mailbox = m;
+
+ struct EventContext ev_ctx = { ctx };
+ notify_send(ctx->notify, NT_CONTEXT, NT_CONTEXT_OPEN, IP & ev_ctx);
+
+ // If the Mailbox is closed, Context->mailbox must be set to NULL
notify_observer_add(m->notify, NT_MAILBOX, 0, ctx_mailbox_observer, IP ctx);
if ((m->magic == MUTT_UNKNOWN) && (flags & (MUTT_NEWFOLDER | MUTT_APPEND)))