NeoMutt  2023-11-03-85-g512e01
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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 "key/lib.h"
80#include "menu/lib.h"
81#include "pattern/lib.h"
82#include "format_flags.h"
83#include "functions.h"
84#include "hdrline.h"
85#include "mutt_logging.h"
86#include "mview.h"
87
89static const struct Mapping PostponedHelp[] = {
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
104static void post_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
105{
106 struct MailboxView *mv = menu->mdata;
107 struct Mailbox *m = mv->mailbox;
108
109 const char *const c_index_format = cs_subset_string(NeoMutt->sub, "index_format");
110 mutt_make_string(buf, buflen, menu->win->state.cols, NONULL(c_index_format), m, -1,
112}
113
120{
121 if (nc->event_type != NT_CONFIG)
122 return 0;
123 if (!nc->global_data || !nc->event_data)
124 return -1;
125
126 struct EventConfig *ev_c = nc->event_data;
127
128 if (!mutt_str_equal(ev_c->name, "index_format") && !mutt_str_equal(ev_c->name, "sort"))
129 return 0;
130
131 struct Menu *menu = nc->global_data;
133 mutt_debug(LL_DEBUG5, "config done, request WA_RECALC, MENU_REDRAW_FULL\n");
134
135 return 0;
136}
137
146{
147 if (nc->event_type != NT_WINDOW)
148 return 0;
149 if (!nc->global_data || !nc->event_data)
150 return -1;
152 return 0;
153
154 struct MuttWindow *win_menu = nc->global_data;
155 struct EventWindow *ev_w = nc->event_data;
156 if (ev_w->win != win_menu)
157 return 0;
158
159 struct Menu *menu = win_menu->wdata;
160
163
164 mutt_debug(LL_DEBUG5, "window delete done\n");
165 return 0;
166}
167
171static const struct AttrColor *post_color(struct Menu *menu, int line)
172{
173 struct MailboxView *mv = menu->mdata;
174 if (!mv || (line < 0))
175 return NULL;
176
177 struct Mailbox *m = mv->mailbox;
178 if (!m)
179 return NULL;
180
181 struct Email *e = mutt_get_virt_email(m, line);
182 if (!e)
183 return NULL;
184
185 if (e->attr_color)
186 return e->attr_color;
187
189 return e->attr_color;
190}
191
202struct Email *dlg_postponed(struct Mailbox *m)
203{
205 // Required to number the emails
206 struct MailboxView *mv = mview_new(m, NeoMutt->notify);
207
208 struct Menu *menu = dlg->wdata;
210 menu->color = post_color;
211 menu->max = m->msg_count;
212 menu->mdata = mv;
213 menu->mdata_free = NULL; // Menu doesn't own the data
214
215 struct PostponeData pd = { mv, menu, NULL, false, search_state_new() };
216 dlg->wdata = &pd;
217
218 // NT_COLOR is handled by the SimpleDialog
221
222 struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
223 sbar_set_title(sbar, _("Postponed Messages"));
224
225 /* The postponed mailbox is setup to have sorting disabled, but the global
226 * `$sort` variable may indicate something different. Sorting has to be
227 * disabled while the postpone menu is being displayed. */
228 const enum SortType c_sort = cs_subset_sort(NeoMutt->sub, "sort");
230
231 struct MuttWindow *old_focus = window_set_focus(menu->win);
232 // ---------------------------------------------------------------------------
233 // Event Loop
234 int op = OP_NULL;
235 do
236 {
237 menu_tagging_dispatcher(menu->win, op);
238 window_redraw(NULL);
239
241 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
242 if (op < 0)
243 continue;
244 if (op == OP_NULL)
245 {
247 continue;
248 }
250
251 int rc = postpone_function_dispatcher(dlg, op);
252
253 if (rc == FR_UNKNOWN)
254 rc = menu_function_dispatcher(menu->win, op);
255 if (rc == FR_UNKNOWN)
256 rc = global_function_dispatcher(NULL, op);
257 } while (!pd.done);
258 // ---------------------------------------------------------------------------
259
260 mview_free(&mv);
261 cs_subset_str_native_set(NeoMutt->sub, "sort", c_sort, NULL);
263 window_set_focus(old_focus);
264 simple_dialog_free(&dlg);
265
266 return pd.email;
267}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:267
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:1360
static const struct Mapping PostponedHelp[]
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 km_dokey(enum MenuType mtype, GetChFlags flags)
Determine what a keypress should do.
Definition: get.c:475
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: get.c:305
int menu_tagging_dispatcher(struct MuttWindow *win, int op)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition: tagging.c:230
int postpone_function_dispatcher(struct MuttWindow *win, int op)
Perform a Postpone function - Implements function_dispatcher_t -.
Definition: functions.c:176
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:169
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:317
struct Email * dlg_postponed(struct Mailbox *m)
Create a Menu to select a postponed message -.
Definition: dlg_postpone.c:202
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
static const 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:171
static void post_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
Format an Email for the Menu - Implements Menu::make_entry() -.
Definition: dlg_postpone.c:104
static int postponed_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: dlg_postpone.c:145
static int postponed_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: dlg_postpone.c:119
Convenience wrapper for the gui headers.
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:168
struct MuttWindow * simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:132
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:1422
String processing routines to generate the mail index.
GUI manage the main index (list of emails)
Manage keymappings.
#define GETCH_NO_FLAGS
No flags are set.
Definition: lib.h:52
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
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:180
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: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:798
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:634
struct MuttWindow * window_set_focus(struct MuttWindow *win)
Set the Window focus.
Definition: mutt_window.c:684
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:533
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
@ WT_DLG_POSTPONED
Postponed Dialog, dlg_postponed()
Definition: mutt_window.h:89
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:229
struct Email * mutt_get_virt_email(struct Mailbox *m, int vnum)
Get a virtual Email.
Definition: mview.c:417
void mview_free(struct MailboxView **ptr)
Free a MailboxView.
Definition: mview.c:49
struct MailboxView * mview_new(struct Mailbox *m, struct Notify *parent)
Create a new MailboxView.
Definition: mview.c:90
View of a Mailbox.
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:57
@ 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:48
Match patterns to emails.
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:227
void search_state_free(struct SearchState **ptr)
Free a SearchState.
Definition: search_state.c:50
struct SearchState * search_state_new(void)
Create a new SearchState.
Definition: search_state.c:38
Sidebar functions.
SortType
Methods for sorting.
Definition: sort2.h:38
@ 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:66
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition: subset.h:52
The envelope/body of an email.
Definition: email.h:37
const struct AttrColor * attr_color
Color-pair to use when displaying in the index.
Definition: email.h:113
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
View of a Mailbox.
Definition: mview.h:39
struct Menu * menu
Needed for pattern compilation.
Definition: mview.h:46
struct Mailbox * mailbox
Current Mailbox.
Definition: mview.h:50
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:96
const struct AttrColor *(* color)(struct Menu *menu, int line)
Definition: lib.h:133
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:151
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
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:41
struct Notify * notify
Notifications handler.
Definition: neomutt.h:42
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
Data to pass to the Postpone Functions.
Definition: functions.h:34
struct Email * email
Selected Email.
Definition: functions.h:37
struct SearchState * search_state
State of the current search.
Definition: functions.h:39
bool done
Should we close the Dialog?
Definition: functions.h:38
struct Menu * menu
Postponed Menu.
Definition: functions.h:36
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:304
@ MENU_POSTPONED
Select a postponed email.
Definition: type.h:57