NeoMutt  2022-04-29-247-gc6aae8
Teaching an old dog new tricks
DOXYGEN
functions.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stddef.h>
31#include "mutt/lib.h"
32#include "core/lib.h"
33#include "gui/lib.h"
34#include "functions.h"
35#include "opcodes.h"
36#include "private_data.h"
37#include "win_chain.h"
38#include "win_hosts.h"
39
43static int op_exit(struct MixmasterPrivateData *priv, int op)
44{
45 return FR_NO_ACTION;
46}
47
51static int op_mix_append(struct MixmasterPrivateData *priv, int op)
52{
54 return FR_ERROR;
55
56 return FR_SUCCESS;
57}
58
62static int op_mix_chain_next(struct MixmasterPrivateData *priv, int op)
63{
64 if (win_chain_next(priv->win_chain))
65 return FR_SUCCESS;
66
67 return FR_ERROR;
68}
69
73static int op_mix_chain_prev(struct MixmasterPrivateData *priv, int op)
74{
75 if (win_chain_prev(priv->win_chain))
76 return FR_SUCCESS;
77
78 return FR_ERROR;
79}
80
84static int op_mix_delete(struct MixmasterPrivateData *priv, int op)
85{
86 if (!win_chain_delete(priv->win_chain))
87 return FR_ERROR;
88
89 return FR_SUCCESS;
90}
91
95static int op_mix_insert(struct MixmasterPrivateData *priv, int op)
96{
98 return FR_ERROR;
99
100 return FR_SUCCESS;
101}
102
106static int op_mix_use(struct MixmasterPrivateData *priv, int op)
107{
108 // If we don't have a chain yet, insert the current item
109 if (win_chain_get_length(priv->win_chain) == 0)
110 op_mix_insert(priv, op);
111
112 if (win_chain_validate(priv->win_chain))
113 return FR_DONE;
114
115 return FR_SUCCESS;
116}
117
118// -----------------------------------------------------------------------------
119
124 // clang-format off
125 { OP_EXIT, op_exit },
126 { OP_GENERIC_SELECT_ENTRY, op_mix_append },
127 { OP_MIX_APPEND, op_mix_append },
128 { OP_MIX_CHAIN_NEXT, op_mix_chain_next },
129 { OP_MIX_CHAIN_PREV, op_mix_chain_prev },
130 { OP_MIX_DELETE, op_mix_delete },
131 { OP_MIX_INSERT, op_mix_insert },
132 { OP_MIX_USE, op_mix_use },
133 { 0, NULL },
134 // clang-format on
135};
136
141{
142 if (!win || !win->wdata)
143 return FR_UNKNOWN;
144
145 struct MixmasterPrivateData *priv = win->wdata;
146 int rc = FR_UNKNOWN;
147 for (size_t i = 0; MixmasterFunctions[i].op != OP_NULL; i++)
148 {
149 const struct MixmasterFunction *fn = &MixmasterFunctions[i];
150 if (fn->op == op)
151 {
152 rc = fn->function(priv, op);
153 break;
154 }
155 }
156
157 if (rc == FR_UNKNOWN) // Not our function
158 return rc;
159
160 const char *result = dispacher_get_retval_name(rc);
161 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
162
163 return rc;
164}
Convenience wrapper for the core headers.
const char * dispacher_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
int mix_function_dispatcher(struct MuttWindow *win, int op)
Perform a Mixmaster function - Implements function_dispatcher_t -.
Definition: functions.c:140
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
static int op_mix_insert(struct MixmasterPrivateData *priv, int op)
insert a remailer into the chain - Implements mixmaster_function_t -
Definition: functions.c:95
static int op_mix_delete(struct MixmasterPrivateData *priv, int op)
delete a remailer from the chain - Implements mixmaster_function_t -
Definition: functions.c:84
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:73
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:62
static int op_exit(struct MixmasterPrivateData *priv, int op)
exit this menu - Implements mixmaster_function_t -
Definition: functions.c:43
static int op_mix_use(struct MixmasterPrivateData *priv, int op)
accept the chain constructed - Implements mixmaster_function_t -
Definition: functions.c:106
static int op_mix_append(struct MixmasterPrivateData *priv, int op)
append a remailer to the chain - Implements mixmaster_function_t -
Definition: functions.c:51
Convenience wrapper for the gui headers.
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
struct MixmasterFunction MixmasterFunctions[]
All the NeoMutt functions that the Mixmaster supports.
Definition: functions.c:123
Convenience wrapper for the library headers.
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:46
All user-callable functions.
Private state data for the Pager.
Sidebar functions.
#define NONULL(x)
Definition: string2.h:37
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:228
Mixmaster Hosts Window.