NeoMutt  2021-10-29-43-g6b8931
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 "core/lib.h"
76 #include "gui/lib.h"
77 #include "mutt.h"
78 #include "menu/lib.h"
79 #include "pattern/lib.h"
80 #include "format_flags.h"
81 #include "hdrline.h"
82 #include "opcodes.h"
83 #include "protos.h"
84 
85 struct Email;
86 
88 static const struct Mapping PostponeHelp[] = {
89  // clang-format off
90  { N_("Exit"), OP_EXIT },
91  { N_("Del"), OP_DELETE },
92  { N_("Undel"), OP_UNDELETE },
93  { N_("Help"), OP_HELP },
94  { NULL, 0 },
95  // clang-format on
96 };
97 
101 static void post_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
102 {
103  struct Mailbox *m = menu->mdata;
104 
105  const char *const c_index_format =
106  cs_subset_string(NeoMutt->sub, "index_format");
107  mutt_make_string(buf, buflen, menu->win->state.cols, NONULL(c_index_format),
108  m, -1, m->emails[line], MUTT_FORMAT_ARROWCURSOR, NULL);
109 }
110 
117 {
118  if ((nc->event_type != NT_CONFIG) || !nc->global_data || !nc->event_data)
119  return -1;
120 
121  struct EventConfig *ev_c = nc->event_data;
122 
123  if (!mutt_str_equal(ev_c->name, "index_format") && !mutt_str_equal(ev_c->name, "sort"))
124  return 0;
125 
126  struct Menu *menu = nc->global_data;
128  mutt_debug(LL_DEBUG5, "config done, request WA_RECALC, MENU_REDRAW_FULL\n");
129 
130  return 0;
131 }
132 
141 {
142  if ((nc->event_type != NT_WINDOW) || !nc->global_data || !nc->event_data)
143  return -1;
144 
145  if (nc->event_subtype != NT_WINDOW_DELETE)
146  return 0;
147 
148  struct MuttWindow *win_menu = nc->global_data;
149  struct EventWindow *ev_w = nc->event_data;
150  if (ev_w->win != win_menu)
151  return 0;
152 
153  struct Menu *menu = win_menu->wdata;
154 
157 
158  mutt_debug(LL_DEBUG5, "window delete done\n");
159  return 0;
160 }
161 
168 {
169  int r = -1;
170  bool done = false;
171 
173 
174  struct Menu *menu = dlg->wdata;
175  menu->make_entry = post_make_entry;
176  menu->max = m->msg_count;
177  menu->mdata = m;
178  menu->custom_search = true;
179 
180  struct MuttWindow *win_menu = menu->win;
181 
182  // NT_COLOR is handled by the SimpleDialog
185 
186  struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
187  sbar_set_title(sbar, _("Postponed Messages"));
188 
189  /* The postponed mailbox is setup to have sorting disabled, but the global
190  * `$sort` variable may indicate something different. Sorting has to be
191  * disabled while the postpone menu is being displayed. */
192  const short c_sort = cs_subset_sort(NeoMutt->sub, "sort");
194 
195  while (!done)
196  {
197  const int op = menu_loop(menu);
198  switch (op)
199  {
200  case OP_DELETE:
201  case OP_UNDELETE:
202  {
203  const int index = menu_get_index(menu);
204  /* should deleted draft messages be saved in the trash folder? */
205  mutt_set_flag(m, m->emails[index], MUTT_DELETE, (op == OP_DELETE));
206  PostCount = m->msg_count - m->msg_deleted;
207  const bool c_resolve = cs_subset_bool(NeoMutt->sub, "resolve");
208  if (c_resolve && (index < (menu->max - 1)))
209  {
210  menu_set_index(menu, index + 1);
211  if (index >= (menu->top + menu->pagelen))
212  {
213  menu->top = index;
215  }
216  }
217  else
219  break;
220  }
221 
222  // All search operations must exist to show the menu
223  case OP_SEARCH_REVERSE:
224  case OP_SEARCH_NEXT:
225  case OP_SEARCH_OPPOSITE:
226  case OP_SEARCH:
227  {
228  int index = menu_get_index(menu);
229  index = mutt_search_command(m, menu, index, op);
230  if (index != -1)
231  menu_set_index(menu, index);
232  break;
233  }
234 
235  case OP_GENERIC_SELECT_ENTRY:
236  r = menu_get_index(menu);
237  done = true;
238  break;
239 
240  case OP_EXIT:
241  done = true;
242  break;
243  }
244  }
245 
246  cs_subset_str_native_set(NeoMutt->sub, "sort", c_sort, NULL);
247  simple_dialog_free(&dlg);
248 
249  return (r > -1) ? m->emails[r] : NULL;
250 }
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
static const struct Mapping PostponeHelp[]
Help Bar for the Postponed email selection dialog.
Definition: dlg_postpone.c:88
struct Email * dlg_select_postponed_email(struct Mailbox *m)
Create a Menu to select a postponed message.
Definition: dlg_postpone.c:167
Flags to control mutt_expando_format()
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition: format_flags.h:35
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
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:101
static int postponed_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: dlg_postpone.c:140
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.
struct MuttWindow * simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:126
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:163
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:1410
String processing routines to generate the mail index.
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:292
@ LL_DEBUG5
Log at debug level 5.
Definition: logging.h:44
GUI present the user with a selectable list.
#define MENU_REDRAW_FULL
Redraw everything.
Definition: lib.h:55
#define MENU_REDRAW_INDEX
Redraw the index.
Definition: lib.h:52
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:632
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:608
int menu_loop(struct Menu *menu)
Menu event loop.
Definition: menu.c:283
#define MENU_REDRAW_CURRENT
Redraw the current line of the menu.
Definition: lib.h:54
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:622
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, observer_t callback, 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:715
Many unsorted constants and some structs.
@ MUTT_DELETE
Messages to be deleted.
Definition: mutt.h:94
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:520
@ 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:206
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
All user-callable functions.
Match patterns to emails.
int mutt_search_command(struct Mailbox *m, struct Menu *menu, int cur, int op)
Perform a search.
Definition: pattern.c:497
short PostCount
Definition: postpone.c:57
Prototypes for many functions.
#define mutt_set_flag(m, e, flag, bf)
Definition: protos.h:66
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:219
@ SORT_ORDER
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:48
#define NONULL(x)
Definition: string2.h:37
The envelope/body of an email.
Definition: email.h:37
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:216
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
A mailbox.
Definition: mailbox.h:82
int msg_count
Total number of messages.
Definition: mailbox.h:91
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
int msg_deleted
Number of deleted messages.
Definition: mailbox.h:96
Mapping between user-readable string and a constant.
Definition: mapping.h:32
Definition: lib.h:67
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:74
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:103
int top
Entry that is the top of the current page.
Definition: lib.h:87
int pagelen
Number of entries per screen.
Definition: lib.h:72
void * mdata
Private data.
Definition: lib.h:153
int max
Number of entries in the menu.
Definition: lib.h:69
bool custom_search
The menu implements its own non-Menusearch()-compatible search, trickle OP_SEARCH*.
Definition: lib.h:91
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
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