NeoMutt  2023-11-03-85-g512e01
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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 {
138 optional = false;
139 }
140 break;
141
142 case 'c':
143 if (optional)
144 break;
145
146 snprintf(fmt, sizeof(fmt), "%%%ss", prec);
147 snprintf(buf, buflen, fmt, mix_format_caps(remailer));
148 break;
149
150 case 'n':
151 if (optional)
152 break;
153
154 snprintf(fmt, sizeof(fmt), "%%%sd", prec);
155 snprintf(buf, buflen, fmt, remailer->num);
156 break;
157
158 case 's':
159 if (!optional)
160 {
161 snprintf(fmt, sizeof(fmt), "%%%ss", prec);
162 snprintf(buf, buflen, fmt, NONULL(remailer->shortname));
163 }
164 else if (!remailer->shortname)
165 {
166 optional = false;
167 }
168 break;
169
170 default:
171 *buf = '\0';
172 }
173
174 if (optional)
175 {
176 mutt_expando_format(buf, buflen, col, cols, if_str, mix_format_str, data,
178 }
179 else if (flags & MUTT_FORMAT_OPTIONAL)
180 {
181 mutt_expando_format(buf, buflen, col, cols, else_str, mix_format_str, data,
183 }
184
185 /* We return the format string, unchanged */
186 return src;
187}
188
194static void mix_make_entry(struct Menu *menu, char *buf, size_t buflen, int num)
195{
196 struct RemailerArray *ra = menu->mdata;
197 struct Remailer **r = ARRAY_GET(ra, num);
198 if (!r)
199 return;
200
201 const char *const c_mix_entry_format = cs_subset_string(NeoMutt->sub, "mix_entry_format");
202 mutt_expando_format(buf, buflen, 0, menu->win->state.cols, NONULL(c_mix_entry_format),
204}
205
211struct MuttWindow *win_hosts_new(struct RemailerArray *ra)
212{
213 struct MuttWindow *win_hosts = menu_window_new(MENU_MIXMASTER, NeoMutt->sub);
214 win_hosts->focus = win_hosts;
215
216 struct Menu *menu = win_hosts->wdata;
217
218 menu->max = ARRAY_SIZE(ra);
220 menu->tag = NULL;
221 menu->mdata = ra;
222 menu->mdata_free = NULL; // Menu doesn't own the data
223
224 return win_hosts;
225}
226
233{
234 if (!win || !win->wdata)
235 return NULL;
236
237 struct Menu *menu = win->wdata;
238 if (!menu->mdata)
239 return NULL;
240
241 struct RemailerArray *ra = menu->mdata;
242
243 const int sel = menu_get_index(menu);
244 if (sel < 0)
245 return NULL;
246
247 struct Remailer **r = ARRAY_GET(ra, sel);
248 if (!r)
249 return NULL;
250
251 return *r;
252}
#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:292
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:739
static void mix_make_entry(struct Menu *menu, char *buf, size_t buflen, int num)
Format a Remailer for the Menu - Implements Menu::make_entry() -.
Definition: win_hosts.c:194
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:156
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.
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:96
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:151
int(* tag)(struct Menu *menu, int sel, int act)
Definition: lib.h:121
void * mdata
Private data.
Definition: lib.h:137
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: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
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
@ 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:211
struct Remailer * win_hosts_get_selection(struct MuttWindow *win)
Get the current selection.
Definition: win_hosts.c:232
static const char * mix_format_caps(struct Remailer *r)
Turn flags into a MixMaster capability string.
Definition: win_hosts.c:67