NeoMutt  2024-03-23-147-g885fbc
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
cbar.c
Go to the documentation of this file.
1
62#include "config.h"
63#include <stddef.h>
64#include "private.h"
65#include "mutt/lib.h"
66#include "config/lib.h"
67#include "email/lib.h"
68#include "core/lib.h"
69#include "gui/lib.h"
70#include "cbar.h"
71#include "color/lib.h"
72#include "expando/lib.h"
73#include "index/lib.h"
74#include "menu/lib.h"
75#include "attach_data.h"
76#include "cbar_data.h"
77#include "globals.h"
78#include "muttlib.h"
79#include "shared_data.h"
80
82
88static int num_attachments(const struct ComposeAttachData *adata)
89{
90 if (!adata || !adata->menu)
91 return 0;
92 return adata->menu->max;
93}
94
98long compose_a_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
99{
100 const struct ComposeSharedData *shared = data;
101
102 return num_attachments(shared->adata);
103}
104
108void compose_h(const struct ExpandoNode *node, void *data,
109 MuttFormatFlags flags, int max_cols, struct Buffer *buf)
110{
111 const char *s = ShortHostname;
112 buf_strcpy(buf, s);
113}
114
118long compose_l_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
119{
120 const struct ComposeSharedData *shared = data;
121 return cum_attachs_size(shared->sub, shared->adata);
122}
123
127void compose_l(const struct ExpandoNode *node, void *data,
128 MuttFormatFlags flags, int max_cols, struct Buffer *buf)
129{
130 const struct ComposeSharedData *shared = data;
131
132 char tmp[128] = { 0 };
133
134 mutt_str_pretty_size(tmp, sizeof(tmp), cum_attachs_size(shared->sub, shared->adata));
135 buf_strcpy(buf, tmp);
136}
137
141void compose_v(const struct ExpandoNode *node, void *data,
142 MuttFormatFlags flags, int max_cols, struct Buffer *buf)
143{
144 const char *s = mutt_make_version();
145 buf_strcpy(buf, s);
146}
147
153static int cbar_recalc(struct MuttWindow *win)
154{
155 struct Buffer *buf = buf_pool_get();
156 struct ComposeSharedData *shared = win->parent->wdata;
157
158 const struct Expando *c_compose_format = cs_subset_expando(shared->sub, "compose_format");
159 expando_render(c_compose_format, ComposeRenderData, shared,
160 MUTT_FORMAT_NO_FLAGS, win->state.cols, buf);
161
162 struct ComposeBarData *cbar_data = win->wdata;
163 if (!mutt_str_equal(buf_string(buf), cbar_data->compose_format))
164 {
165 mutt_str_replace(&cbar_data->compose_format, buf_string(buf));
166 win->actions |= WA_REPAINT;
167 mutt_debug(LL_DEBUG5, "recalc done, request WA_REPAINT\n");
168 }
169 buf_pool_release(&buf);
170
171 return 0;
172}
173
177static int cbar_repaint(struct MuttWindow *win)
178{
179 struct ComposeBarData *cbar_data = win->wdata;
180
181 mutt_window_move(win, 0, 0);
184
185 mutt_window_move(win, 0, 0);
186 mutt_draw_statusline(win, win->state.cols, cbar_data->compose_format,
187 mutt_str_len(cbar_data->compose_format));
189 mutt_debug(LL_DEBUG5, "repaint done\n");
190
191 return 0;
192}
193
198{
199 if (nc->event_type != NT_COLOR)
200 return 0;
201 if (!nc->global_data || !nc->event_data)
202 return -1;
203
204 struct EventColor *ev_c = nc->event_data;
205
206 // MT_COLOR_MAX is sent on `uncolor *`
207 if ((ev_c->cid != MT_COLOR_STATUS) && (ev_c->cid != MT_COLOR_NORMAL) &&
208 (ev_c->cid != MT_COLOR_MAX))
209 {
210 return 0;
211 }
212
213 struct MuttWindow *win_cbar = nc->global_data;
214 win_cbar->actions |= WA_REPAINT;
215 mutt_debug(LL_DEBUG5, "color done, request WA_REPAINT\n");
216
217 return 0;
218}
219
224{
225 if (nc->event_type != NT_CONFIG)
226 return 0;
227 if (!nc->global_data || !nc->event_data)
228 return -1;
229
230 struct EventConfig *ev_c = nc->event_data;
231 if (!mutt_str_equal(ev_c->name, "compose_format"))
232 return 0;
233
234 struct MuttWindow *win_cbar = nc->global_data;
235 win_cbar->actions |= WA_RECALC;
236 mutt_debug(LL_DEBUG5, "config done, request WA_RECALC\n");
237
238 return 0;
239}
240
245{
246 if (nc->event_type != NT_EMAIL)
247 return 0;
248 if (!nc->global_data || !nc->event_data)
249 return -1;
250
251 struct MuttWindow *win_cbar = nc->global_data;
252 win_cbar->actions |= WA_RECALC;
253 mutt_debug(LL_DEBUG5, "compose done, request WA_RECALC\n");
254
255 return 0;
256}
257
262{
263 if (nc->event_type != NT_WINDOW)
264 return 0;
265 if (!nc->global_data || !nc->event_data)
266 return -1;
267
268 struct MuttWindow *win_cbar = nc->global_data;
269 struct EventWindow *ev_w = nc->event_data;
270 if (ev_w->win != win_cbar)
271 return 0;
272
274 {
275 win_cbar->actions |= WA_RECALC;
276 mutt_debug(LL_DEBUG5, "window state done, request WA_RECALC\n");
277 }
278 else if (nc->event_subtype == NT_WINDOW_DELETE)
279 {
280 struct MuttWindow *dlg = win_cbar->parent;
281 struct ComposeSharedData *shared = dlg->wdata;
282
287
288 mutt_debug(LL_DEBUG5, "window delete done\n");
289 }
290
291 return 0;
292}
293
298struct MuttWindow *cbar_new(struct ComposeSharedData *shared)
299{
303
304 win_cbar->wdata = cbar_data_new();
305 win_cbar->wdata_free = cbar_data_free;
306 win_cbar->recalc = cbar_recalc;
307 win_cbar->repaint = cbar_repaint;
308
313
314 return win_cbar;
315}
316
322const struct ExpandoRenderData ComposeRenderData[] = {
323 // clang-format off
328 { -1, -1, NULL, NULL },
329 // clang-format on
330};
Compose Attach Data.
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:394
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
static int num_attachments(const struct ComposeAttachData *adata)
Count the number of attachments.
Definition: cbar.c:88
const struct ExpandoRenderData ComposeRenderData[]
Callbacks for Compose Expandos.
Definition: cbar.c:81
struct MuttWindow * cbar_new(struct ComposeSharedData *shared)
Create the Compose Bar (status)
Definition: cbar.c:298
Compose Bar.
struct ComposeBarData * cbar_data_new(void)
Create the private data for the Compose Bar.
Definition: cbar_data.c:52
Compose Bar Data.
Color and attribute parsing.
void mutt_color_observer_remove(observer_t callback, void *global_data)
Remove an observer.
Definition: notify.c:69
void mutt_color_observer_add(observer_t callback, void *global_data)
Add an observer.
Definition: notify.c:59
@ MT_COLOR_MAX
Definition: color.h:94
@ MT_COLOR_STATUS
Status bar (takes a pattern)
Definition: color.h:75
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:59
unsigned long cum_attachs_size(struct ConfigSubset *sub, struct ComposeAttachData *adata)
Cumulative Attachments Size.
Definition: attach.c:84
@ ED_COM_ATTACH_COUNT
ComposeAttachData, num_attachments()
Definition: shared_data.h:56
@ ED_COM_ATTACH_SIZE
ComposeAttachData, cum_attachs_size()
Definition: shared_data.h:57
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.
void mutt_draw_statusline(struct MuttWindow *win, int max_cols, const char *buf, size_t buflen)
Draw a highlighted status bar.
Definition: dlg_index.c:930
@ ED_COMPOSE
Compose ED_COM_ ExpandoDataCompose.
Definition: domain.h:39
@ ED_GLOBAL
Global ED_GLO_ ExpandoDataGlobal.
Definition: domain.h:44
Structs that make up an email.
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
char * ShortHostname
Short version of the hostname.
Definition: globals.c:39
long compose_a_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Compose: Number of attachments - Implements ExpandoRenderData::get_number() -.
Definition: cbar.c:98
long compose_l_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Compose: Size in bytes - Implements ExpandoRenderData::get_number() -.
Definition: cbar.c:118
void compose_h(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Compose: Hostname - Implements ExpandoRenderData::get_string() -.
Definition: cbar.c:108
void compose_v(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Compose: Version - Implements ExpandoRenderData::get_string() -.
Definition: cbar.c:141
void compose_l(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Compose: Size in bytes - Implements ExpandoRenderData::get_string() -.
Definition: cbar.c:127
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
int cbar_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t -.
Definition: cbar.c:197
int cbar_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: cbar.c:223
static int cbar_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: cbar.c:261
static int cbar_email_observer(struct NotifyCallback *nc)
Notification that the Email has changed - Implements observer_t -.
Definition: cbar.c:244
static int cbar_recalc(struct MuttWindow *win)
Recalculate the Window data - Implements MuttWindow::recalc() -.
Definition: cbar.c:153
static int cbar_repaint(struct MuttWindow *win)
Repaint the Window - Implements MuttWindow::repaint() -.
Definition: cbar.c:177
void cbar_data_free(struct MuttWindow *win, void **ptr)
Free the private Compose Bar data - Implements MuttWindow::wdata_free() -.
Definition: cbar_data.c:36
Convenience wrapper for the gui headers.
GUI manage the main index (list of emails)
Data shared between Index, Pager and Sidebar.
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
GUI present the user with a selectable list.
Convenience wrapper for the library headers.
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition: notify.c:230
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:191
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:709
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:545
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:329
const struct AttrColor * mutt_curses_set_normal_backed_color_by_id(enum ColorId cid)
Set the colour and attributes by the colour id.
Definition: mutt_curses.c:63
const struct AttrColor * mutt_curses_set_color_by_id(enum ColorId cid)
Set the colour and attributes by the colour id.
Definition: mutt_curses.c:79
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
Definition: mutt_window.c:182
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:297
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:244
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:38
@ NT_WINDOW_STATE
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:230
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:229
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:52
@ MUTT_WIN_SIZE_FIXED
Window has a fixed size.
Definition: mutt_window.h:47
const char * mutt_make_version(void)
Generate the NeoMutt version string.
Definition: muttlib.c:893
void mutt_str_pretty_size(char *buf, size_t buflen, size_t num)
Display an abbreviated size, like 3.4K.
Definition: muttlib.c:1101
Some miscellaneous functions.
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:57
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
@ NT_COLOR
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:41
@ NT_EMAIL
Email has changed, NotifyEmail, EventEmail.
Definition: notify_type.h:44
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: render.h:33
uint8_t MuttFormatFlags
Flags for expando_render(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: render.h:32
GUI display the mailboxes in a side panel.
String manipulation buffer.
Definition: buffer.h:36
Data to fill the Compose Attach Window.
Definition: attach_data.h:33
struct Menu * menu
Menu displaying the attachments.
Definition: attach_data.h:35
Data to fill the Compose Bar Window.
Definition: cbar_data.h:34
char * compose_format
Cached status string.
Definition: cbar_data.h:35
Shared Compose Data.
Definition: shared_data.h:35
struct ConfigSubset * sub
Config set to use.
Definition: shared_data.h:36
int flags
Flags, e.g. MUTT_COMPOSE_NOFREEHEADER.
Definition: shared_data.h:43
struct ComposeAttachData * adata
Attachments.
Definition: shared_data.h:39
struct Email * email
Email being composed.
Definition: shared_data.h:38
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition: subset.h:52
struct Notify * notify
Notifications: NotifyEmail, EventEmail.
Definition: email.h:73
An Event that happened to a Colour.
Definition: notify2.h:53
enum ColorId cid
Colour ID that has changed.
Definition: notify2.h:54
A config-change event.
Definition: subset.h:71
const char * name
Name of config item that changed.
Definition: subset.h:73
An Event that happened to a Window.
Definition: mutt_window.h:239
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:240
Basic Expando Node.
Definition: node.h:67
Parsed Expando trees.
Definition: expando.h:41
int max
Number of entries in the menu.
Definition: lib.h:81
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:187
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
void * wdata
Private data.
Definition: mutt_window.h:145
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:173
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:159
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
Data passed to a notification function.
Definition: observer.h:34
void * event_data
Data from notify_send()
Definition: observer.h:38
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:36
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:37
void * global_data
Data from notify_observer_add()
Definition: observer.h:39
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
@ ED_GLO_VERSION
NeoMutt version.
Definition: uid.h:43
@ ED_GLO_HOSTNAME
Local hostname.
Definition: uid.h:35