NeoMutt  2024-04-16-36-g75b6fb
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_mixmaster.c
Go to the documentation of this file.
1
62#include "config.h"
63#include <stdbool.h>
64#include <stdio.h>
65#include "mutt/lib.h"
66#include "config/lib.h"
67#include "core/lib.h"
68#include "gui/lib.h"
69#include "key/lib.h"
70#include "menu/lib.h"
71#include "functions.h"
72#include "mutt_logging.h"
73#include "private_data.h"
74#include "remailer.h"
75#include "win_chain.h"
76#include "win_hosts.h"
77
79static const struct Mapping RemailerHelp[] = {
80 // clang-format off
81 { N_("Append"), OP_MIX_APPEND },
82 { N_("Insert"), OP_MIX_INSERT },
83 { N_("Delete"), OP_MIX_DELETE },
84 { N_("Abort"), OP_EXIT },
85 { N_("OK"), OP_MIX_USE },
86 { NULL, 0 },
87 // clang-format on
88};
89
94{
95 if (nc->event_type != NT_CONFIG)
96 return 0;
97 if (!nc->global_data || !nc->event_data)
98 return -1;
99
100 struct EventConfig *ev_c = nc->event_data;
101 if (!mutt_str_equal(ev_c->name, "status_on_top"))
102 return 0;
103
104 struct MuttWindow *dlg = nc->global_data;
106 mutt_debug(LL_DEBUG5, "config done\n");
107 return 0;
108}
109
114{
115 if (nc->event_type != NT_WINDOW)
116 return 0;
117 if (!nc->global_data || !nc->event_data)
118 return -1;
120 return 0;
121
122 struct MuttWindow *dlg = nc->global_data;
123 struct EventWindow *ev_w = nc->event_data;
124 if (ev_w->win != dlg)
125 return 0;
126
129 mutt_debug(LL_DEBUG5, "window delete done\n");
130
131 return 0;
132}
133
140static struct MuttWindow *mix_dlg_new(struct MixmasterPrivateData *priv,
141 struct RemailerArray *ra)
142{
147 dlg->help_data = RemailerHelp;
148 dlg->wdata = priv;
149
150 priv->win_hosts = win_hosts_new(ra);
151 struct MuttWindow *win_cbar = sbar_new();
152 priv->win_chain = win_chain_new(win_cbar);
153
154 struct MuttWindow *win_rbar = sbar_new();
155 sbar_set_title(win_rbar, _("Select a remailer chain"));
156
157 const bool c_status_on_top = cs_subset_bool(NeoMutt->sub, "status_on_top");
158 if (c_status_on_top)
159 {
160 mutt_window_add_child(dlg, win_rbar);
162 mutt_window_add_child(dlg, win_cbar);
164 }
165 else
166 {
168 mutt_window_add_child(dlg, win_cbar);
170 mutt_window_add_child(dlg, win_rbar);
171 }
172
175
176 return dlg;
177}
178
186void dlg_mixmaster(struct ListHead *chainhead)
187{
188 struct MixmasterPrivateData priv = { 0 };
189
190 struct RemailerArray ra = remailer_get_hosts();
191 if (ARRAY_EMPTY(&ra))
192 {
193 mutt_error(_("Can't get mixmaster's type2.list"));
194 return;
195 }
196
197 struct MuttWindow *dlg = mix_dlg_new(&priv, &ra);
198
199 win_chain_init(priv.win_chain, chainhead, &ra);
200 mutt_list_free(chainhead);
201
202 dialog_push(dlg);
203 struct MuttWindow *old_focus = window_set_focus(priv.win_hosts);
204
205 // ---------------------------------------------------------------------------
206 // Event Loop
207 int op = OP_NULL;
208 int rc = FR_UNKNOWN;
209 do
210 {
212 window_redraw(NULL);
213
215 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
216 if (op < 0)
217 continue;
218 if (op == OP_NULL)
219 {
221 continue;
222 }
224
225 rc = mix_function_dispatcher(dlg, op);
226
227 if (rc == FR_UNKNOWN)
228 rc = menu_function_dispatcher(priv.win_hosts, op);
229 if (rc == FR_UNKNOWN)
230 rc = global_function_dispatcher(NULL, op);
231 } while ((rc != FR_DONE) && (rc != FR_NO_ACTION));
232 // ---------------------------------------------------------------------------
233
234 /* construct the remailer list */
235 if (rc == FR_DONE)
236 win_chain_extract(priv.win_chain, chainhead);
237
238 window_set_focus(old_focus);
239 dialog_pop();
240 mutt_window_free(&dlg);
241
243}
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:74
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
void dialog_push(struct MuttWindow *dlg)
Display a Window to the user.
Definition: dialog.c:109
void dialog_pop(void)
Hide a Window from the user.
Definition: dialog.c:142
@ FR_DONE
Exit the Dialog.
Definition: dispatcher.h:35
@ FR_UNKNOWN
Unknown function.
Definition: dispatcher.h:33
@ FR_NO_ACTION
Valid function - no action performed.
Definition: dispatcher.h:37
static struct MuttWindow * mix_dlg_new(struct MixmasterPrivateData *priv, struct RemailerArray *ra)
Create a new Mixmaster Remailer Dialog.
static const struct Mapping RemailerHelp[]
Help Bar for the Mixmaster dialog.
Definition: dlg_mixmaster.c:79
int km_dokey(enum MenuType mtype, GetChFlags flags)
Determine what a keypress should do.
Definition: get.c:463
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: get.c:293
int menu_tagging_dispatcher(struct MuttWindow *win, int op)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition: tagging.c:230
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:172
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:318
int mix_function_dispatcher(struct MuttWindow *win, int op)
Perform a Mixmaster function - Implements function_dispatcher_t -.
Definition: functions.c:183
void dlg_mixmaster(struct ListHead *chainhead)
Create a Mixmaster chain -.
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
static int remailer_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: dlg_mixmaster.c:93
static int remailer_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Convenience wrapper for the gui headers.
Manage keymappings.
#define GETCH_NO_FLAGS
No flags are set.
Definition: lib.h:51
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
GUI present the user with a selectable list.
Convenience wrapper for the library headers.
#define N_(a)
Definition: message.h:32
#define _(a)
Definition: message.h:28
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition: notify.c:230
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:191
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:654
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
NeoMutt Logging.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:634
bool window_status_on_top(struct MuttWindow *panel, struct ConfigSubset *sub)
Organise windows according to config variable.
Definition: mutt_window.c:784
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:202
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:446
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
Definition: mutt_window.c:182
struct MuttWindow * window_set_focus(struct MuttWindow *win)
Set the Window focus.
Definition: mutt_window.c:684
@ WT_DLG_MIXMASTER
Mixmaster Dialog, dlg_mixmaster()
Definition: mutt_window.h:91
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:38
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:229
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:52
@ MUTT_WIN_SIZE_MAXIMISE
Window wants as much space as possible.
Definition: mutt_window.h:48
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:57
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:48
Private state data for the Pager.
struct RemailerArray remailer_get_hosts(void)
Parse the type2.list as given by mixmaster -T.
Definition: remailer.c:114
void remailer_clear_hosts(struct RemailerArray *ra)
Clear a Remailer List.
Definition: remailer.c:205
Mixmaster Remailer.
struct MuttWindow * sbar_new(void)
Add the Simple Bar (status)
Definition: sbar.c:203
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:227
Sidebar functions.
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition: subset.h:52
A config-change event.
Definition: subset.h:71
const char * name
Name of config item that changed.
Definition: subset.h:73
An Event that happened to a Window.
Definition: mutt_window.h:239
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:240
Mapping between user-readable string and a constant.
Definition: mapping.h:33
Private state data for the Mixmaster.
Definition: private_data.h:30
struct MuttWindow * win_chain
Chain Window.
Definition: private_data.h:32
struct MuttWindow * win_hosts
Hosts Window.
Definition: private_data.h:31
const struct Mapping * help_data
Data for the Help Bar.
Definition: mutt_window.h:142
void * wdata
Private data.
Definition: mutt_window.h:145
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
int help_menu
Menu for key bindings, e.g. MENU_PAGER.
Definition: mutt_window.h:141
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
Data passed to a notification function.
Definition: observer.h:34
void * event_data
Data from notify_send()
Definition: observer.h:38
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:36
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:37
void * global_data
Data from notify_observer_add()
Definition: observer.h:39
@ MENU_MIXMASTER
Create/edit a Mixmaster chain.
Definition: type.h:53
int win_chain_extract(struct MuttWindow *win, struct ListHead *chain)
Extract the Chain list data.
Definition: win_chain.c:233
struct MuttWindow * win_chain_new(struct MuttWindow *win_cbar)
Create a new Chain list Window.
Definition: win_chain.c:184
void win_chain_init(struct MuttWindow *win, struct ListHead *chain, struct RemailerArray *ra)
Initialise the Chain list Window.
Definition: win_chain.c:207
Mixmaster Chain Window.
struct MuttWindow * win_hosts_new(struct RemailerArray *ra)
Create a new Hosts Window.
Definition: win_hosts.c:185
Mixmaster Hosts Window.