NeoMutt  2023-03-22-27-g3cb248
Teaching an old dog new tricks
DOXYGEN
dlg_postpone.c
Go to the documentation of this file.
1
70#include "config.h"
71#include <stdbool.h>
72#include <stdio.h>
73#include "mutt/lib.h"
74#include "config/lib.h"
75#include "email/lib.h"
76#include "core/lib.h"
77#include "gui/lib.h"
78#include "index/lib.h"
79#include "menu/lib.h"
80#include "format_flags.h"
81#include "functions.h"
82#include "hdrline.h"
83#include "keymap.h"
84#include "mutt_logging.h"
85#include "mview.h"
86#include "opcodes.h"
87
89static const struct Mapping PostponeHelp[] = {
90 // clang-format off
91 { N_("Exit"), OP_EXIT },
92 { N_("Del"), OP_DELETE },
93 { N_("Undel"), OP_UNDELETE },
94 { N_("Help"), OP_HELP },
95 { NULL, 0 },
96 // clang-format on
97};
98
102static void post_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
103{
104 struct Mailbox *m = menu->mdata;
105
106 const char *const c_index_format = cs_subset_string(NeoMutt->sub, "index_format");
107 mutt_make_string(buf, buflen, menu->win->state.cols, NONULL(c_index_format), m, -1,
109}
110
117{
118 if (nc->event_type != NT_CONFIG)
119 return 0;
120 if (!nc->global_data || !nc->event_data)
121 return -1;
122
123 struct EventConfig *ev_c = nc->event_data;
124
125 if (!mutt_str_equal(ev_c->name, "index_format") && !mutt_str_equal(ev_c->name, "sort"))
126 return 0;
127
128 struct Menu *menu = nc->global_data;
130 mutt_debug(LL_DEBUG5, "config done, request WA_RECALC, MENU_REDRAW_FULL\n");
131
132 return 0;
133}
134
143{
144 if (nc->event_type != NT_WINDOW)
145 return 0;
146 if (!nc->global_data || !nc->event_data)
147 return -1;
149 return 0;
150
151 struct MuttWindow *win_menu = nc->global_data;
152 struct EventWindow *ev_w = nc->event_data;
153 if (ev_w->win != win_menu)
154 return 0;
155
156 struct Menu *menu = win_menu->wdata;
157
160
161 mutt_debug(LL_DEBUG5, "window delete done\n");
162 return 0;
163}
164
168static struct AttrColor *post_color(struct Menu *menu, int line)
169{
170 struct Mailbox *m = menu->mdata;
171 if (!m || (line < 0))
172 return NULL;
173
174 struct Email *e = mutt_get_virt_email(m, line);
175 if (!e)
176 return NULL;
177
178 if (e->attr_color)
179 return e->attr_color;
180
182 return e->attr_color;
183}
184
191{
193
194 struct Menu *menu = dlg->wdata;
196 menu->color = post_color;
197 menu->max = m->msg_count;
198 menu->mdata = m;
199 menu->mdata_free = NULL; // Menu doesn't own the data
200 menu->custom_search = true;
201
202 struct PostponeData pd = { false, m, menu, NULL };
203 dlg->wdata = &pd;
204
205 // NT_COLOR is handled by the SimpleDialog
208
209 struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
210 sbar_set_title(sbar, _("Postponed Messages"));
211
212 /* The postponed mailbox is setup to have sorting disabled, but the global
213 * `$sort` variable may indicate something different. Sorting has to be
214 * disabled while the postpone menu is being displayed. */
215 const short c_sort = cs_subset_sort(NeoMutt->sub, "sort");
217
218 // ---------------------------------------------------------------------------
219 // Event Loop
220 int op = OP_NULL;
221 do
222 {
223 menu_tagging_dispatcher(menu->win, op);
224 window_redraw(NULL);
225
227 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
228 if (op < 0)
229 continue;
230 if (op == OP_NULL)
231 {
233 continue;
234 }
236
237 int rc = postpone_function_dispatcher(dlg, op);
238
239 if (rc == FR_UNKNOWN)
240 rc = menu_function_dispatcher(menu->win, op);
241 if (rc == FR_UNKNOWN)
242 rc = global_function_dispatcher(NULL, op);
243 } while (!pd.done);
244 // ---------------------------------------------------------------------------
245
246 cs_subset_str_native_set(NeoMutt->sub, "sort", c_sort, NULL);
247 simple_dialog_free(&dlg);
248
249 return pd.email;
250}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:292
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
@ FR_UNKNOWN
Unknown function.
Definition: dispatcher.h:33
void mutt_set_header_color(struct Mailbox *m, struct Email *e)
Select a colour for a message.
Definition: dlg_index.c:1382
struct Email * dlg_select_postponed_email(struct Mailbox *m)
Create a Menu to select a postponed message.
Definition: dlg_postpone.c:190
static const struct Mapping PostponeHelp[]
Help Bar for the Postponed email selection dialog.
Definition: dlg_postpone.c:89
Structs that make up an email.
Flags to control mutt_expando_format()
#define MUTT_FORMAT_INDEX
This is a main index entry.
Definition: format_flags.h:36
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition: format_flags.h:35
int menu_tagging_dispatcher(struct MuttWindow *win, int op)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition: tagging.c:223
int postpone_function_dispatcher(struct MuttWindow *win, int op)
Perform a Postpone function - Implements function_dispatcher_t -.
Definition: functions.c:129
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:164
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:320
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
static struct AttrColor * post_color(struct Menu *menu, int line)
Calculate the colour for a line of the postpone index - Implements Menu::color() -.
Definition: dlg_postpone.c:168
static void post_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
Format a menu item for the email list - Implements Menu::make_entry() -.
Definition: dlg_postpone.c:102
static int postponed_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: dlg_postpone.c:142
static int postponed_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: dlg_postpone.c:116
Convenience wrapper for the gui headers.
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:166
struct MuttWindow * simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:129
void mutt_make_string(char *buf, size_t buflen, int cols, const char *s, struct Mailbox *m, int inpgr, struct Email *e, MuttFormatFlags flags, const char *progress)
Create formatted strings using mailbox expandos.
Definition: hdrline.c:1443
String processing routines to generate the mail index.
GUI manage the main index (list of emails)
int km_dokey(enum MenuType mtype)
Determine what a keypress should do.
Definition: keymap.c:797
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: keymap.c:1065
Manage keymappings.
@ LL_DEBUG5
Log at debug level 5.
Definition: logging.h:44
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
GUI present the user with a selectable list.
#define MENU_REDRAW_FULL
Redraw everything.
Definition: lib.h:60
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:178
Convenience wrapper for the library headers.
#define N_(a)
Definition: message.h:32
#define _(a)
Definition: message.h:28
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition: notify.c:228
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:189
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:807
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:73
NeoMutt Logging.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:605
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:523
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
@ WT_DLG_POSTPONE
Postpone Dialog, dlg_select_postponed_email()
Definition: mutt_window.h:89
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:205
struct Email * mutt_get_virt_email(struct Mailbox *m, int vnum)
Get a virtual Email.
Definition: mview.c:414
The "currently-open" mailbox.
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:55
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:46
All user-callable functions.
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:224
Sidebar functions.
@ SORT_ORDER
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:44
#define NONULL(x)
Definition: string2.h:37
A curses colour and its attributes.
Definition: attr.h:35
The envelope/body of an email.
Definition: email.h:37
struct AttrColor * attr_color
Color-pair to use when displaying in the index.
Definition: email.h:111
A config-change event.
Definition: subset.h:70
const char * name
Name of config item that changed.
Definition: subset.h:72
An Event that happened to a Window.
Definition: mutt_window.h:215
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:216
A mailbox.
Definition: mailbox.h:79
int msg_count
Total number of messages.
Definition: mailbox.h:88
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
Mapping between user-readable string and a constant.
Definition: mapping.h:32
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
struct AttrColor *(* color)(struct Menu *menu, int line)
Definition: lib.h:134
void * mdata
Private data.
Definition: lib.h:138
int max
Number of entries in the menu.
Definition: lib.h:72
bool custom_search
The menu implements its own non-Menusearch()-compatible search, trickle OP_SEARCH*.
Definition: lib.h:85
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
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
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
Data to pass to the Postpone Functions.
Definition: functions.h:34
struct Email * email
Selected Email.
Definition: functions.h:38
bool done
Should we close the Dialog?
Definition: functions.h:35
struct Menu * menu
Postponed Menu.
Definition: functions.h:37
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
int cs_subset_str_native_set(const struct ConfigSubset *sub, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.
Definition: subset.c:305
@ MENU_POSTPONE
Select a postponed email.
Definition: type.h:56