NeoMutt  2024-03-23-23-gec7045
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
functions.c
Go to the documentation of this file.
1
29#include "config.h"
30#ifdef _MAKEDOC
31#include "docs/makedoc_defs.h"
32#else
33#include <stddef.h>
34#include "mutt/lib.h"
35#include "core/lib.h"
36#include "gui/lib.h"
37#include "key/lib.h"
38#include "functions.h"
39#include "private_data.h"
40#include "win_chain.h"
41#include "win_hosts.h"
42#endif
43
44// clang-format off
45#ifdef MIXMASTER
49const struct MenuFuncOp OpMixmaster[] = { /* map: mixmaster */
50 { "accept", OP_MIX_USE },
51 { "append", OP_MIX_APPEND },
52 { "chain-next", OP_MIX_CHAIN_NEXT },
53 { "chain-prev", OP_MIX_CHAIN_PREV },
54 { "delete", OP_MIX_DELETE },
55 { "exit", OP_EXIT },
56 { "insert", OP_MIX_INSERT },
57 { NULL, 0 },
58};
59#endif /* MIXMASTER */
60
61#ifdef MIXMASTER
65const struct MenuOpSeq MixmasterDefaultBindings[] = { /* map: mixmaster */
66 { OP_EXIT, "q" },
67 { OP_GENERIC_SELECT_ENTRY, "<space>" },
68 { OP_MIX_APPEND, "a" },
69 { OP_MIX_CHAIN_NEXT, "<right>" },
70 { OP_MIX_CHAIN_NEXT, "l" },
71 { OP_MIX_CHAIN_PREV, "<left>" },
72 { OP_MIX_CHAIN_PREV, "h" },
73 { OP_MIX_DELETE, "d" },
74 { OP_MIX_INSERT, "i" },
75 { OP_MIX_USE, "<keypadenter>" },
76 { OP_MIX_USE, "\n" }, // <Enter>
77 { OP_MIX_USE, "\r" }, // <Return>
78 { 0, NULL },
79};
80#endif /* MIXMASTER */
81// clang-format on
82
86static int op_exit(struct MixmasterPrivateData *priv, int op)
87{
88 return FR_NO_ACTION;
89}
90
94static int op_mix_append(struct MixmasterPrivateData *priv, int op)
95{
97 return FR_ERROR;
98
99 return FR_SUCCESS;
100}
101
105static int op_mix_chain_next(struct MixmasterPrivateData *priv, int op)
106{
107 if (win_chain_next(priv->win_chain))
108 return FR_SUCCESS;
109
110 return FR_ERROR;
111}
112
116static int op_mix_chain_prev(struct MixmasterPrivateData *priv, int op)
117{
118 if (win_chain_prev(priv->win_chain))
119 return FR_SUCCESS;
120
121 return FR_ERROR;
122}
123
127static int op_mix_delete(struct MixmasterPrivateData *priv, int op)
128{
129 if (!win_chain_delete(priv->win_chain))
130 return FR_ERROR;
131
132 return FR_SUCCESS;
133}
134
138static int op_mix_insert(struct MixmasterPrivateData *priv, int op)
139{
141 return FR_ERROR;
142
143 return FR_SUCCESS;
144}
145
149static int op_mix_use(struct MixmasterPrivateData *priv, int op)
150{
151 // If we don't have a chain yet, insert the current item
152 if (win_chain_get_length(priv->win_chain) == 0)
153 op_mix_insert(priv, op);
154
155 if (win_chain_validate(priv->win_chain))
156 return FR_DONE;
157
158 return FR_SUCCESS;
159}
160
161// -----------------------------------------------------------------------------
162
166static const struct MixmasterFunction MixmasterFunctions[] = {
167 // clang-format off
168 { OP_EXIT, op_exit },
169 { OP_GENERIC_SELECT_ENTRY, op_mix_append },
170 { OP_MIX_APPEND, op_mix_append },
171 { OP_MIX_CHAIN_NEXT, op_mix_chain_next },
172 { OP_MIX_CHAIN_PREV, op_mix_chain_prev },
173 { OP_MIX_DELETE, op_mix_delete },
174 { OP_MIX_INSERT, op_mix_insert },
175 { OP_MIX_USE, op_mix_use },
176 { 0, NULL },
177 // clang-format on
178};
179
184{
185 if (!win || !win->wdata)
186 return FR_UNKNOWN;
187
188 struct MixmasterPrivateData *priv = win->wdata;
189 int rc = FR_UNKNOWN;
190 for (size_t i = 0; MixmasterFunctions[i].op != OP_NULL; i++)
191 {
192 const struct MixmasterFunction *fn = &MixmasterFunctions[i];
193 if (fn->op == op)
194 {
195 rc = fn->function(priv, op);
196 break;
197 }
198 }
199
200 if (rc == FR_UNKNOWN) // Not our function
201 return rc;
202
203 const char *result = dispatcher_get_retval_name(rc);
204 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
205
206 return rc;
207}
Convenience wrapper for the core headers.
const char * dispatcher_get_retval_name(int rv)
Get the name of a return value.
Definition: dispatcher.c:54
@ FR_SUCCESS
Valid function - successfully performed.
Definition: dispatcher.h:39
@ FR_DONE
Exit the Dialog.
Definition: dispatcher.h:35
@ FR_UNKNOWN
Unknown function.
Definition: dispatcher.h:33
@ FR_ERROR
Valid function - error occurred.
Definition: dispatcher.h:38
@ FR_NO_ACTION
Valid function - no action performed.
Definition: dispatcher.h:37
static int op_exit(struct AliasMenuData *mdata, int op)
exit this menu - Implements alias_function_t -
Definition: functions.c:191
int mix_function_dispatcher(struct MuttWindow *win, int op)
Perform a Mixmaster function - Implements function_dispatcher_t -.
Definition: functions.c:183
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
static int op_mix_insert(struct MixmasterPrivateData *priv, int op)
insert a remailer into the chain - Implements mixmaster_function_t -
Definition: functions.c:138
static int op_mix_delete(struct MixmasterPrivateData *priv, int op)
delete a remailer from the chain - Implements mixmaster_function_t -
Definition: functions.c:127
static int op_mix_chain_prev(struct MixmasterPrivateData *priv, int op)
select the previous element of the chain - Implements mixmaster_function_t -
Definition: functions.c:116
static int op_mix_chain_next(struct MixmasterPrivateData *priv, int op)
select the next element of the chain - Implements mixmaster_function_t -
Definition: functions.c:105
static int op_mix_use(struct MixmasterPrivateData *priv, int op)
accept the chain constructed - Implements mixmaster_function_t -
Definition: functions.c:149
static int op_mix_append(struct MixmasterPrivateData *priv, int op)
append a remailer to the chain - Implements mixmaster_function_t -
Definition: functions.c:94
Convenience wrapper for the gui headers.
Manage keymappings.
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
const struct MenuFuncOp OpMixmaster[]
Functions for the Mixmaster Menu.
Definition: functions.c:49
const struct MenuOpSeq MixmasterDefaultBindings[]
Key bindings for the Mixmaster Menu.
Definition: functions.c:65
static const struct MixmasterFunction MixmasterFunctions[]
All the NeoMutt functions that the Mixmaster supports.
Definition: functions.c:166
Convenience wrapper for the library headers.
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:48
Private state data for the Pager.
Sidebar functions.
#define NONULL(x)
Definition: string2.h:37
Mapping between a function and an operation.
Definition: lib.h:101
Mapping between an operation and a key sequence.
Definition: lib.h:110
int op
Operation, e.g. OP_DELETE.
Definition: lib.h:111
A NeoMutt function.
Definition: functions.h:45
mixmaster_function_t function
Function to call.
Definition: functions.h:47
int op
Op code, e.g. OP_MIX_USE.
Definition: functions.h:46
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
void * wdata
Private data.
Definition: mutt_window.h:145
bool win_chain_prev(struct MuttWindow *win)
Select the previous entry in the Chain list.
Definition: win_chain.c:308
bool win_chain_insert(struct MuttWindow *win, struct Remailer *r)
Add an item to the Chain, before the current item.
Definition: win_chain.c:354
bool win_chain_delete(struct MuttWindow *win)
Delete the current item from the Chain.
Definition: win_chain.c:385
bool win_chain_next(struct MuttWindow *win)
Select the next entry in the Chain list.
Definition: win_chain.c:282
bool win_chain_validate(struct MuttWindow *win)
Validate the Chain.
Definition: win_chain.c:417
bool win_chain_append(struct MuttWindow *win, struct Remailer *r)
Add an item to the Chain, after the current item.
Definition: win_chain.c:335
int win_chain_get_length(struct MuttWindow *win)
Get the number of Remailers in the Chain.
Definition: win_chain.c:267
Mixmaster Chain Window.
struct Remailer * win_hosts_get_selection(struct MuttWindow *win)
Get the current selection.
Definition: win_hosts.c:206
Mixmaster Hosts Window.