Skip to content

Commit

Permalink
convert the notifications from compose to email
Browse files Browse the repository at this point in the history
Use NT_EMAIL rather than NT_COMPOSE. Then drop NT_COMPOSE.
  • Loading branch information
flatcap committed Feb 19, 2022
1 parent 36a29a4 commit 7e48d98
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 98 deletions.
17 changes: 10 additions & 7 deletions compose/attach.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
*
* | Event Type | Handler |
* | :-------------------- | :------------------------ |
* | #NT_COMPOSE | attach_compose_observer() |
* | #NT_CONFIG | attach_config_observer() |
* | #NT_EMAIL | attach_email_observer() |
* | #NT_WINDOW | attach_window_observer() |
* | MuttWindow::recalc() | attach_recalc() |
* | MuttWindow::repaint() | attach_repaint() |
Expand Down Expand Up @@ -173,14 +173,14 @@ int attach_repaint(struct MuttWindow *win)
}

/**
* attach_compose_observer - Notification that the Compose data has changed - Implements ::observer_t - @ingroup observer_api
* attach_email_observer - Notification that the Email has changed - Implements ::observer_t - @ingroup observer_api
*/
static int attach_compose_observer(struct NotifyCallback *nc)
static int attach_email_observer(struct NotifyCallback *nc)
{
if ((nc->event_type != NT_COMPOSE) || !nc->global_data)
if ((nc->event_type != NT_EMAIL) || !nc->global_data)
return -1;

if (nc->event_subtype != NT_COMPOSE_ATTACH)
if (nc->event_subtype != NT_EMAIL_CHANGE_ATTACH)
return 0;

struct MuttWindow *win_attach = nc->global_data;
Expand Down Expand Up @@ -230,7 +230,10 @@ static int attach_window_observer(struct NotifyCallback *nc)
}
else if (nc->event_subtype == NT_WINDOW_DELETE)
{
notify_observer_remove(win_attach->parent->notify, attach_compose_observer, win_attach);
struct Menu *menu = win_attach->wdata;
struct ComposeAttachData *adata = menu->mdata;
struct AttachCtx *actx = adata->actx;
notify_observer_remove(actx->email->notify, attach_email_observer, win_attach);
notify_observer_remove(NeoMutt->notify, attach_config_observer, win_attach);
notify_observer_remove(win_attach->notify, attach_window_observer, win_attach);
mutt_debug(LL_DEBUG5, "window delete done\n");
Expand Down Expand Up @@ -288,8 +291,8 @@ struct MuttWindow *attach_new(struct MuttWindow *parent, struct ComposeSharedDat
// win_attach->repaint = attach_repaint;

// NT_COLOR is handled by the Menu Window
notify_observer_add(parent->notify, NT_COMPOSE, attach_compose_observer, win_attach);
notify_observer_add(NeoMutt->notify, NT_CONFIG, attach_config_observer, win_attach);
notify_observer_add(shared->email->notify, NT_EMAIL, attach_email_observer, win_attach);
notify_observer_add(win_attach->notify, NT_WINDOW, attach_window_observer, win_attach);

struct Menu *menu = win_attach->wdata;
Expand Down
33 changes: 17 additions & 16 deletions compose/cbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
* | Event Type | Handler |
* | :-------------------- | :---------------------- |
* | #NT_COLOR | cbar_color_observer() |
* | #NT_COMPOSE | cbar_compose_observer() |
* | #NT_CONFIG | cbar_config_observer() |
* | #NT_EMAIL | cbar_email_observer() |
* | #NT_WINDOW | cbar_window_observer() |
* | MuttWindow::recalc() | cbar_recalc() |
* | MuttWindow::repaint() | cbar_repaint() |
Expand All @@ -65,6 +65,7 @@
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "color/lib.h"
Expand Down Expand Up @@ -222,35 +223,35 @@ int cbar_color_observer(struct NotifyCallback *nc)
}

/**
* cbar_compose_observer - Notification that the Compose data has changed - Implements ::observer_t - @ingroup observer_api
* cbar_config_observer - Notification that a Config Variable has changed - Implements ::observer_t - @ingroup observer_api
*/
int cbar_compose_observer(struct NotifyCallback *nc)
int cbar_config_observer(struct NotifyCallback *nc)
{
if ((nc->event_type != NT_COMPOSE) || !nc->global_data || !nc->event_data)
if ((nc->event_type != NT_CONFIG) || !nc->global_data || !nc->event_data)
return -1;

struct EventConfig *ev_c = nc->event_data;
if (!mutt_str_equal(ev_c->name, "compose_format"))
return 0;

struct MuttWindow *win_cbar = nc->global_data;
win_cbar->actions |= WA_REPAINT;
mutt_debug(LL_DEBUG5, "compose done, request WA_REPAINT\n");
win_cbar->actions |= WA_RECALC;
mutt_debug(LL_DEBUG5, "config done, request WA_RECALC\n");

return 0;
}

/**
* cbar_config_observer - Notification that a Config Variable has changed - Implements ::observer_t - @ingroup observer_api
* cbar_email_observer - Notification that the Email has changed - Implements ::observer_t - @ingroup observer_api
*/
int cbar_config_observer(struct NotifyCallback *nc)
int cbar_email_observer(struct NotifyCallback *nc)
{
if ((nc->event_type != NT_CONFIG) || !nc->global_data || !nc->event_data)
if ((nc->event_type != NT_EMAIL) || !nc->global_data || !nc->event_data)
return -1;

struct EventConfig *ev_c = nc->event_data;
if (!mutt_str_equal(ev_c->name, "compose_format"))
return 0;

struct MuttWindow *win_cbar = nc->global_data;
win_cbar->actions |= WA_RECALC;
mutt_debug(LL_DEBUG5, "config done, request WA_RECALC\n");
mutt_debug(LL_DEBUG5, "compose done, request WA_RECALC\n");

return 0;
}
Expand Down Expand Up @@ -279,8 +280,8 @@ int cbar_window_observer(struct NotifyCallback *nc)
struct ComposeSharedData *shared = dlg->wdata;

notify_observer_remove(NeoMutt->notify, cbar_color_observer, win_cbar);
notify_observer_remove(shared->notify, cbar_compose_observer, win_cbar);
notify_observer_remove(NeoMutt->notify, cbar_config_observer, win_cbar);
notify_observer_remove(shared->email->notify, cbar_email_observer, win_cbar);
notify_observer_remove(win_cbar->notify, cbar_window_observer, win_cbar);

mutt_debug(LL_DEBUG5, "window delete done\n");
Expand All @@ -305,8 +306,8 @@ struct MuttWindow *cbar_new(struct ComposeSharedData *shared)
win_cbar->repaint = cbar_repaint;

notify_observer_add(NeoMutt->notify, NT_COLOR, cbar_color_observer, win_cbar);
notify_observer_add(shared->notify, NT_COMPOSE, cbar_compose_observer, win_cbar);
notify_observer_add(NeoMutt->notify, NT_CONFIG, cbar_config_observer, win_cbar);
notify_observer_add(shared->email->notify, NT_EMAIL, cbar_email_observer, win_cbar);
notify_observer_add(win_cbar->notify, NT_WINDOW, cbar_window_observer, win_cbar);

return win_cbar;
Expand Down
58 changes: 28 additions & 30 deletions compose/envelope.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@
*
* Once constructed, it is controlled by the following events:
*
* | Event Type | Handler |
* | :-------------------- | :--------------------- |
* | #NT_COLOR | env_color_observer() |
* | #NT_COMPOSE | env_compose_observer() |
* | #NT_CONFIG | env_config_observer() |
* | #NT_HEADER | env_header_observer() |
* | #NT_WINDOW | env_window_observer() |
* | MuttWindow::recalc() | env_recalc() |
* | MuttWindow::repaint() | env_repaint() |
* | Event Type | Handler |
* | :----------------------- | :--------------------- |
* | #NT_COLOR | env_color_observer() |
* | #NT_CONFIG | env_config_observer() |
* | #NT_EMAIL (#NT_ENVELOPE) | env_email_observer() |
* | #NT_HEADER | env_header_observer() |
* | #NT_WINDOW | env_window_observer() |
* | MuttWindow::recalc() | env_recalc() |
* | MuttWindow::repaint() | env_repaint() |
*/

#include "config.h"
Expand Down Expand Up @@ -733,25 +733,6 @@ static int env_color_observer(struct NotifyCallback *nc)
return 0;
}

/**
* env_compose_observer - Notification that the Compose data has changed - Implements ::observer_t - @ingroup observer_api
*/
static int env_compose_observer(struct NotifyCallback *nc)
{
if ((nc->event_type != NT_COMPOSE) || !nc->global_data)
return -1;

if (nc->event_subtype != NT_COMPOSE_ENVELOPE)
return 0;

struct MuttWindow *win_env = nc->global_data;

win_env->actions |= WA_RECALC;
mutt_debug(LL_DEBUG5, "compose done, request WA_RECALC\n");

return 0;
}

/**
* env_config_observer - Notification that a Config Variable has changed - Implements ::observer_t - @ingroup observer_api
*/
Expand Down Expand Up @@ -797,6 +778,23 @@ static int env_config_observer(struct NotifyCallback *nc)
return 0;
}

/**
* env_email_observer - Notification that the Email has changed - Implements ::observer_t - @ingroup observer_api
*/
static int env_email_observer(struct NotifyCallback *nc)
{
if ((nc->event_type != NT_EMAIL) && (nc->event_type != NT_ENVELOPE))
return -1;
if (!nc->global_data)
return -1;

struct MuttWindow *win_env = nc->global_data;

win_env->actions |= WA_RECALC;
mutt_debug(LL_DEBUG5, "email done, request WA_RECALC\n");
return 0;
}

/**
* env_header_observer - Notification that a User Header has changed - Implements ::observer_t - @ingroup observer_api
*/
Expand Down Expand Up @@ -859,7 +857,7 @@ static int env_window_observer(struct NotifyCallback *nc)
struct ComposeSharedData *shared = win_env->parent->wdata;

notify_observer_remove(NeoMutt->notify, env_color_observer, win_env);
notify_observer_remove(shared->notify, env_compose_observer, win_env);
notify_observer_remove(shared->email->notify, env_email_observer, win_env);
notify_observer_remove(NeoMutt->notify, env_config_observer, win_env);
notify_observer_remove(NeoMutt->notify, env_header_observer, win_env);
notify_observer_remove(win_env->notify, env_window_observer, win_env);
Expand All @@ -882,7 +880,7 @@ struct MuttWindow *compose_env_new(struct ComposeSharedData *shared, struct Buff
MUTT_WIN_SIZE_UNLIMITED, HDR_ATTACH_TITLE - 1);

notify_observer_add(NeoMutt->notify, NT_COLOR, env_color_observer, win_env);
notify_observer_add(shared->notify, NT_COMPOSE, env_compose_observer, win_env);
notify_observer_add(shared->email->notify, NT_ALL, env_email_observer, win_env);
notify_observer_add(NeoMutt->notify, NT_CONFIG, env_config_observer, win_env);
notify_observer_add(NeoMutt->notify, NT_HEADER, env_header_observer, win_env);
notify_observer_add(win_env->notify, NT_WINDOW, env_window_observer, win_env);
Expand Down
Loading

0 comments on commit 7e48d98

Please sign in to comment.