NeoMutt  2024-03-23-147-g885fbc
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
win_hosts.c
Go to the documentation of this file.
1
47#include "config.h"
48#include <stddef.h>
49#include <stdbool.h>
50#include "mutt/lib.h"
51#include "config/lib.h"
52#include "core/lib.h"
53#include "gui/lib.h"
54#include "expando/lib.h"
55#include "menu/lib.h"
56#include "remailer.h"
57
59
67static const char *mix_format_caps(const struct Remailer *r)
68{
69 // NOTE(g0mb4): use $to_chars?
70 static char capbuf[10];
71 char *t = capbuf;
72
73 if (r->caps & MIX_CAP_COMPRESS)
74 *t++ = 'C';
75 else
76 *t++ = ' ';
77
78 if (r->caps & MIX_CAP_MIDDLEMAN)
79 *t++ = 'M';
80 else
81 *t++ = ' ';
82
83 if (r->caps & MIX_CAP_NEWSPOST)
84 {
85 *t++ = 'N';
86 *t++ = 'p';
87 }
88 else
89 {
90 *t++ = ' ';
91 *t++ = ' ';
92 }
93
94 if (r->caps & MIX_CAP_NEWSMAIL)
95 {
96 *t++ = 'N';
97 *t++ = 'm';
98 }
99 else
100 {
101 *t++ = ' ';
102 *t++ = ' ';
103 }
104
105 *t = '\0';
106
107 return capbuf;
108}
109
113void mix_a(const struct ExpandoNode *node, void *data, MuttFormatFlags flags,
114 int max_cols, struct Buffer *buf)
115{
116 const struct Remailer *remailer = data;
117
118 const char *s = remailer->addr;
119 buf_strcpy(buf, s);
120}
121
125void mix_c(const struct ExpandoNode *node, void *data, MuttFormatFlags flags,
126 int max_cols, struct Buffer *buf)
127{
128 const struct Remailer *remailer = data;
129
130 const char *s = mix_format_caps(remailer);
131 buf_strcpy(buf, s);
132}
133
137long mix_n_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
138{
139 const struct Remailer *remailer = data;
140
141 return remailer->num;
142}
143
147void mix_s(const struct ExpandoNode *node, void *data, MuttFormatFlags flags,
148 int max_cols, struct Buffer *buf)
149{
150 const struct Remailer *remailer = data;
151
152 const char *s = remailer->shortname;
153 buf_strcpy(buf, s);
154}
155
161static int mix_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
162{
163 struct RemailerArray *ra = menu->mdata;
164 struct Remailer **r = ARRAY_GET(ra, line);
165 if (!r)
166 return 0;
167
168 const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
169 if (c_arrow_cursor)
170 {
171 const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
172 max_cols -= (mutt_strwidth(c_arrow_string) + 1);
173 }
174
175 const struct Expando *c_mix_entry_format = cs_subset_expando(NeoMutt->sub, "mix_entry_format");
176 return expando_render(c_mix_entry_format, MixRenderData, *r,
177 MUTT_FORMAT_ARROWCURSOR, max_cols, buf);
178}
179
185struct MuttWindow *win_hosts_new(struct RemailerArray *ra)
186{
187 struct MuttWindow *win_hosts = menu_window_new(MENU_MIXMASTER, NeoMutt->sub);
188 win_hosts->focus = win_hosts;
189
190 struct Menu *menu = win_hosts->wdata;
191
192 menu->max = ARRAY_SIZE(ra);
194 menu->tag = NULL;
195 menu->mdata = ra;
196 menu->mdata_free = NULL; // Menu doesn't own the data
197
198 return win_hosts;
199}
200
207{
208 if (!win || !win->wdata)
209 return NULL;
210
211 struct Menu *menu = win->wdata;
212 if (!menu->mdata)
213 return NULL;
214
215 struct RemailerArray *ra = menu->mdata;
216
217 const int sel = menu_get_index(menu);
218 if (sel < 0)
219 return NULL;
220
221 struct Remailer **r = ARRAY_GET(ra, sel);
222 if (!r)
223 return NULL;
224
225 return *r;
226}
227
233const struct ExpandoRenderData MixRenderData[] = {
234 // clang-format off
239 { -1, -1, NULL, NULL },
240 // clang-format on
241};
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:87
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:109
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:394
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando config item by name.
Definition: config_type.c:358
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
Definition: curs_lib.c:443
@ ED_MIXMASTER
Mixmaster ED_MIX_ ExpandoDataMixmaster.
Definition: domain.h:49
Parse Expando string.
int expando_render(const struct Expando *exp, const struct ExpandoRenderData *rdata, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Render an Expando + data into a string.
Definition: expando.c:110
long mix_n_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Mixmaster: Index number - Implements ExpandoRenderData::get_number() -.
Definition: win_hosts.c:137
void mix_s(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Mixmaster: Short name - Implements ExpandoRenderData::get_string() -.
Definition: win_hosts.c:147
void mix_c(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Mixmaster: Capabilities - Implements ExpandoRenderData::get_string() -.
Definition: win_hosts.c:125
void mix_a(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Mixmaster: Email address - Implements ExpandoRenderData::get_string() -.
Definition: win_hosts.c:113
static int mix_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Format a Remailer for the Menu - Implements Menu::make_entry() -.
Definition: win_hosts.c:161
Convenience wrapper for the gui headers.
GUI present the user with a selectable list.
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:160
struct MuttWindow * menu_window_new(enum MenuType type, struct ConfigSubset *sub)
Create a new Menu Window.
Definition: window.c:140
Convenience wrapper for the library headers.
Mixmaster Remailer.
#define MIX_CAP_MIDDLEMAN
Must be a middle-man (not at the end of a chain)
Definition: remailer.h:32
#define MIX_CAP_NEWSMAIL
Supports posting to Usenet through a mail-to-news gateway.
Definition: remailer.h:34
@ ED_MIX_ADDRESS
Remailer.addr.
Definition: remailer.h:56
@ ED_MIX_CAPABILITIES
Remailer, mix_format_caps()
Definition: remailer.h:57
@ ED_MIX_SHORT_NAME
Remailer.shortname.
Definition: remailer.h:59
@ ED_MIX_NUMBER
Remailer.num.
Definition: remailer.h:58
#define MIX_CAP_COMPRESS
Accepts compressed messages.
Definition: remailer.h:31
#define MIX_CAP_NEWSPOST
Supports direct posting to Usenet.
Definition: remailer.h:33
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition: render.h:37
uint8_t MuttFormatFlags
Flags for expando_render(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: render.h:32
String manipulation buffer.
Definition: buffer.h:36
Basic Expando Node.
Definition: node.h:67
Parsed Expando trees.
Definition: expando.h:41
Definition: lib.h:79
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:86
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:161
int(* tag)(struct Menu *menu, int sel, int act)
Definition: lib.h:131
int(* make_entry)(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Definition: lib.h:106
struct ConfigSubset * sub
Inherited config items.
Definition: lib.h:87
void * mdata
Private data.
Definition: lib.h:147
int max
Number of entries in the menu.
Definition: lib.h:81
struct MuttWindow * focus
Focused Window.
Definition: mutt_window.h:140
void * wdata
Private data.
Definition: mutt_window.h:145
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
A Mixmaster remailer.
Definition: remailer.h:40
int num
Index number.
Definition: remailer.h:41
char * addr
Address of host.
Definition: remailer.h:43
char * shortname
Short name of remailer host.
Definition: remailer.h:42
MixCapFlags caps
Capabilities of host.
Definition: remailer.h:45
@ MENU_MIXMASTER
Create/edit a Mixmaster chain.
Definition: type.h:53
struct MuttWindow * win_hosts_new(struct RemailerArray *ra)
Create a new Hosts Window.
Definition: win_hosts.c:185
struct Remailer * win_hosts_get_selection(struct MuttWindow *win)
Get the current selection.
Definition: win_hosts.c:206
static const char * mix_format_caps(const struct Remailer *r)
Turn flags into a MixMaster capability string.
Definition: win_hosts.c:67
const struct ExpandoRenderData MixRenderData[]
Callbacks for Mixmaster Expandos.
Definition: win_hosts.c:58