NeoMutt  2023-03-22-27-g3cb248
Teaching an old dog new tricks
DOXYGEN
win_hosts.c
Go to the documentation of this file.
1
46#include "config.h"
47#include <stddef.h>
48#include <stdbool.h>
49#include <stdint.h>
50#include <stdio.h>
51#include "mutt/lib.h"
52#include "config/lib.h"
53#include "core/lib.h"
54#include "gui/lib.h"
55#include "menu/lib.h"
56#include "format_flags.h"
57#include "muttlib.h"
58#include "remailer.h"
59
67static const char *mix_format_caps(struct Remailer *r)
68{
69 static char capbuf[10];
70 char *t = capbuf;
71
72 if (r->caps & MIX_CAP_COMPRESS)
73 *t++ = 'C';
74 else
75 *t++ = ' ';
76
77 if (r->caps & MIX_CAP_MIDDLEMAN)
78 *t++ = 'M';
79 else
80 *t++ = ' ';
81
82 if (r->caps & MIX_CAP_NEWSPOST)
83 {
84 *t++ = 'N';
85 *t++ = 'p';
86 }
87 else
88 {
89 *t++ = ' ';
90 *t++ = ' ';
91 }
92
93 if (r->caps & MIX_CAP_NEWSMAIL)
94 {
95 *t++ = 'N';
96 *t++ = 'm';
97 }
98 else
99 {
100 *t++ = ' ';
101 *t++ = ' ';
102 }
103
104 *t = '\0';
105
106 return capbuf;
107}
108
119static const char *mix_format_str(char *buf, size_t buflen, size_t col, int cols,
120 char op, const char *src, const char *prec,
121 const char *if_str, const char *else_str,
122 intptr_t data, MuttFormatFlags flags)
123{
124 char fmt[128] = { 0 };
125 struct Remailer *remailer = (struct Remailer *) data;
126 bool optional = (flags & MUTT_FORMAT_OPTIONAL);
127
128 switch (op)
129 {
130 case 'a':
131 if (!optional)
132 {
133 snprintf(fmt, sizeof(fmt), "%%%ss", prec);
134 snprintf(buf, buflen, fmt, NONULL(remailer->addr));
135 }
136 else if (!remailer->addr)
137 optional = false;
138 break;
139
140 case 'c':
141 if (optional)
142 break;
143
144 snprintf(fmt, sizeof(fmt), "%%%ss", prec);
145 snprintf(buf, buflen, fmt, mix_format_caps(remailer));
146 break;
147
148 case 'n':
149 if (optional)
150 break;
151
152 snprintf(fmt, sizeof(fmt), "%%%sd", prec);
153 snprintf(buf, buflen, fmt, remailer->num);
154 break;
155
156 case 's':
157 if (!optional)
158 {
159 snprintf(fmt, sizeof(fmt), "%%%ss", prec);
160 snprintf(buf, buflen, fmt, NONULL(remailer->shortname));
161 }
162 else if (!remailer->shortname)
163 optional = false;
164 break;
165
166 default:
167 *buf = '\0';
168 }
169
170 if (optional)
171 {
172 mutt_expando_format(buf, buflen, col, cols, if_str, mix_format_str, data,
174 }
175 else if (flags & MUTT_FORMAT_OPTIONAL)
176 {
177 mutt_expando_format(buf, buflen, col, cols, else_str, mix_format_str, data,
179 }
180
181 /* We return the format string, unchanged */
182 return src;
183}
184
190static void mix_make_entry(struct Menu *menu, char *buf, size_t buflen, int num)
191{
192 struct RemailerArray *ra = menu->mdata;
193 struct Remailer **r = ARRAY_GET(ra, num);
194 if (!r)
195 return;
196
197 const char *const c_mix_entry_format = cs_subset_string(NeoMutt->sub, "mix_entry_format");
198 mutt_expando_format(buf, buflen, 0, menu->win->state.cols, NONULL(c_mix_entry_format),
200}
201
207struct MuttWindow *win_hosts_new(struct RemailerArray *ra)
208{
209 struct MuttWindow *win_hosts = menu_window_new(MENU_MIX, NeoMutt->sub);
210 win_hosts->focus = win_hosts;
211
212 struct Menu *menu = win_hosts->wdata;
213
214 menu->max = ARRAY_SIZE(ra);
216 menu->tag = NULL;
217 menu->mdata = ra;
218 menu->mdata_free = NULL; // Menu doesn't own the data
219
220 return win_hosts;
221}
222
229{
230 if (!win || !win->wdata)
231 return NULL;
232
233 struct Menu *menu = win->wdata;
234 if (!menu->mdata)
235 return NULL;
236
237 struct RemailerArray *ra = menu->mdata;
238
239 const int sel = menu_get_index(menu);
240 if (sel < 0)
241 return NULL;
242
243 struct Remailer **r = ARRAY_GET(ra, sel);
244 if (!r)
245 return NULL;
246
247 return *r;
248}
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:86
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:108
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
Flags to control mutt_expando_format()
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: format_flags.h:30
#define MUTT_FORMAT_OPTIONAL
Allow optional field processing.
Definition: format_flags.h:33
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition: format_flags.h:35
uint8_t MuttFormatFlags
Flags for mutt_expando_format(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: format_flags.h:29
static const char * mix_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
Format a string for the remailer menu - Implements format_t -.
Definition: win_hosts.c:119
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t callback, intptr_t data, MuttFormatFlags flags)
Expand expandos (x) in a string -.
Definition: muttlib.c:726
static void mix_make_entry(struct Menu *menu, char *buf, size_t buflen, int num)
Format a menu item for the mixmaster chain list - Implements Menu::make_entry() -.
Definition: win_hosts.c:190
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:154
struct MuttWindow * menu_window_new(enum MenuType type, struct ConfigSubset *sub)
Create a new Menu Window.
Definition: window.c:136
Convenience wrapper for the library headers.
Some miscellaneous functions.
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
#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 NONULL(x)
Definition: string2.h:37
Definition: lib.h:70
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:77
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:97
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:152
int(* tag)(struct Menu *menu, int sel, int act)
Definition: lib.h:122
void * mdata
Private data.
Definition: lib.h:138
int max
Number of entries in the menu.
Definition: lib.h:72
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
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:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
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
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
@ MENU_MIX
Create/edit a Mixmaster chain.
Definition: type.h:52
struct MuttWindow * win_hosts_new(struct RemailerArray *ra)
Create a new Hosts Window.
Definition: win_hosts.c:207
struct Remailer * win_hosts_get_selection(struct MuttWindow *win)
Get the current selection.
Definition: win_hosts.c:228
static const char * mix_format_caps(struct Remailer *r)
Turn flags into a MixMaster capability string.
Definition: win_hosts.c:67