NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
functions.c File Reference

Sidebar functions. More...

#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "opcodes.h"
+ Include dependency graph for functions.c:

Go to the source code of this file.

Functions

bool select_next (struct SidebarWindowData *wdata)
 Selects the next unhidden mailbox. More...
 
static struct SbEntry ** next_new (struct SidebarWindowData *wdata, size_t begin, size_t end)
 Return the next mailbox with new messages. More...
 
static bool select_next_new (struct SidebarWindowData *wdata, bool next_new_wrap)
 Selects the next new mailbox. More...
 
bool select_prev (struct SidebarWindowData *wdata)
 Selects the previous unhidden mailbox. More...
 
static struct SbEntry ** prev_new (struct SidebarWindowData *wdata, size_t begin, size_t end)
 Return the previous mailbox with new messages. More...
 
static bool select_prev_new (struct SidebarWindowData *wdata, bool next_new_wrap)
 Selects the previous new mailbox. More...
 
static bool select_page_down (struct SidebarWindowData *wdata)
 Selects the first entry in the next page of mailboxes. More...
 
static bool select_page_up (struct SidebarWindowData *wdata)
 Selects the last entry in the previous page of mailboxes. More...
 
static bool select_first (struct SidebarWindowData *wdata)
 Selects the first unhidden mailbox. More...
 
static bool select_last (struct SidebarWindowData *wdata)
 Selects the last unhidden mailbox. More...
 
void sb_change_mailbox (struct MuttWindow *win, int op)
 Perform a Sidebar function. More...
 

Detailed Description

Sidebar functions.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file functions.c.

Function Documentation

◆ select_next()

bool select_next ( struct SidebarWindowData wdata)

Selects the next unhidden mailbox.

Parameters
wdataSidebar data
Return values
trueThe selection changed

Definition at line 45 of file functions.c.

46 {
47  if (ARRAY_EMPTY(&wdata->entries) || (wdata->hil_index < 0))
48  return false;
49 
50  struct SbEntry **sbep = NULL;
51  ARRAY_FOREACH_FROM(sbep, &wdata->entries, wdata->hil_index + 1)
52  {
53  if (!(*sbep)->is_hidden)
54  {
55  wdata->hil_index = ARRAY_FOREACH_IDX;
56  return true;
57  }
58  }
59 
60  return false;
61 }
Info about folders in the sidebar.
Definition: private.h:39
int hil_index
Highlighted mailbox.
Definition: private.h:69
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:70
#define ARRAY_FOREACH_FROM(elem, head, from)
Iterate from an index to the end.
Definition: array.h:217
+ Here is the caller graph for this function:

◆ next_new()

static struct SbEntry** next_new ( struct SidebarWindowData wdata,
size_t  begin,
size_t  end 
)
static

Return the next mailbox with new messages.

Parameters
wdataSidebar data
beginStarting index for searching
endEnding index for searching
Return values
sbePointer to the first entry with new messages
NULLNone could be found

Definition at line 71 of file functions.c.

72 {
73  struct SbEntry **sbep = NULL;
74  ARRAY_FOREACH_FROM_TO(sbep, &wdata->entries, begin, end)
75  {
76  if ((*sbep)->mailbox->has_new || (*sbep)->mailbox->msg_unread != 0)
77  return sbep;
78  }
79  return NULL;
80 }
Info about folders in the sidebar.
Definition: private.h:39
#define ARRAY_FOREACH_FROM_TO(elem, head, from, to)
Iterate between two indexes.
Definition: array.h:241
+ Here is the caller graph for this function:

◆ select_next_new()

static bool select_next_new ( struct SidebarWindowData wdata,
bool  next_new_wrap 
)
static

Selects the next new mailbox.

Parameters
wdataSidebar data
next_new_wrapWrap around when searching for the next mailbox with new mail
Return values
trueThe selection changed

Search down the list of mail folders for one containing new mail.

Definition at line 90 of file functions.c.

91 {
92  const size_t max_entries = ARRAY_SIZE(&wdata->entries);
93 
94  if ((max_entries == 0) || (wdata->hil_index < 0))
95  return false;
96 
97  struct SbEntry **sbep = NULL;
98  if ((sbep = next_new(wdata, wdata->hil_index + 1, max_entries)) ||
99  (next_new_wrap && (sbep = next_new(wdata, 0, wdata->hil_index))))
100  {
101  wdata->hil_index = ARRAY_IDX(&wdata->entries, sbep);
102  return true;
103  }
104 
105  return false;
106 }
#define ARRAY_IDX(head, elem)
Return the index of an element of the array.
Definition: array.h:253
Info about folders in the sidebar.
Definition: private.h:39
int hil_index
Highlighted mailbox.
Definition: private.h:69
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:83
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ select_prev()

bool select_prev ( struct SidebarWindowData wdata)

Selects the previous unhidden mailbox.

Parameters
wdataSidebar data
Return values
trueThe selection changed

Definition at line 113 of file functions.c.

114 {
115  if (ARRAY_EMPTY(&wdata->entries) || (wdata->hil_index < 0))
116  return false;
117 
118  struct SbEntry **sbep = NULL, **prev = NULL;
119  ARRAY_FOREACH_TO(sbep, &wdata->entries, wdata->hil_index)
120  {
121  if (!(*sbep)->is_hidden)
122  prev = sbep;
123  }
124 
125  if (prev)
126  {
127  wdata->hil_index = ARRAY_IDX(&wdata->entries, prev);
128  return true;
129  }
130 
131  return false;
132 }
#define ARRAY_IDX(head, elem)
Return the index of an element of the array.
Definition: array.h:253
#define ARRAY_FOREACH_TO(elem, head, to)
Iterate from the beginning to an index.
Definition: array.h:228
Info about folders in the sidebar.
Definition: private.h:39
int hil_index
Highlighted mailbox.
Definition: private.h:69
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:70
+ Here is the caller graph for this function:

◆ prev_new()

static struct SbEntry** prev_new ( struct SidebarWindowData wdata,
size_t  begin,
size_t  end 
)
static

Return the previous mailbox with new messages.

Parameters
wdataSidebar data
beginStarting index for searching
endEnding index for searching
Return values
sbePointer to the first entry with new messages
NULLNone could be found

Definition at line 142 of file functions.c.

143 {
144  struct SbEntry **sbep = NULL, **prev = NULL;
145  ARRAY_FOREACH_FROM_TO(sbep, &wdata->entries, begin, end)
146  {
147  if ((*sbep)->mailbox->has_new || (*sbep)->mailbox->msg_unread != 0)
148  prev = sbep;
149  }
150 
151  return prev;
152 }
Info about folders in the sidebar.
Definition: private.h:39
#define ARRAY_FOREACH_FROM_TO(elem, head, from, to)
Iterate between two indexes.
Definition: array.h:241
+ Here is the caller graph for this function:

◆ select_prev_new()

static bool select_prev_new ( struct SidebarWindowData wdata,
bool  next_new_wrap 
)
static

Selects the previous new mailbox.

Parameters
wdataSidebar data
next_new_wrapWrap around when searching for the next mailbox with new mail
Return values
trueThe selection changed

Search up the list of mail folders for one containing new mail.

Definition at line 162 of file functions.c.

163 {
164  const size_t max_entries = ARRAY_SIZE(&wdata->entries);
165 
166  if ((max_entries == 0) || (wdata->hil_index < 0))
167  return false;
168 
169  struct SbEntry **sbep = NULL;
170  if ((sbep = prev_new(wdata, 0, wdata->hil_index)) ||
171  (next_new_wrap && (sbep = prev_new(wdata, wdata->hil_index + 1, max_entries))))
172  {
173  wdata->hil_index = ARRAY_IDX(&wdata->entries, sbep);
174  return true;
175  }
176 
177  return false;
178 }
#define ARRAY_IDX(head, elem)
Return the index of an element of the array.
Definition: array.h:253
Info about folders in the sidebar.
Definition: private.h:39
int hil_index
Highlighted mailbox.
Definition: private.h:69
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:83
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ select_page_down()

static bool select_page_down ( struct SidebarWindowData wdata)
static

Selects the first entry in the next page of mailboxes.

Parameters
wdataSidebar data
Return values
trueThe selection changed

Definition at line 185 of file functions.c.

186 {
187  if (ARRAY_EMPTY(&wdata->entries) || (wdata->bot_index < 0))
188  return false;
189 
190  int orig_hil_index = wdata->hil_index;
191 
192  wdata->hil_index = wdata->bot_index;
193  select_next(wdata);
194  /* If the rest of the entries are hidden, go up to the last unhidden one */
195  if ((*ARRAY_GET(&wdata->entries, wdata->hil_index))->is_hidden)
196  select_prev(wdata);
197 
198  return (orig_hil_index != wdata->hil_index);
199 }
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:105
int hil_index
Highlighted mailbox.
Definition: private.h:69
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:70
int bot_index
Last mailbox visible in sidebar.
Definition: private.h:70
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ select_page_up()

static bool select_page_up ( struct SidebarWindowData wdata)
static

Selects the last entry in the previous page of mailboxes.

Parameters
wdataSidebar data
Return values
trueThe selection changed

Definition at line 206 of file functions.c.

207 {
208  if (ARRAY_EMPTY(&wdata->entries) || (wdata->top_index < 0))
209  return false;
210 
211  int orig_hil_index = wdata->hil_index;
212 
213  wdata->hil_index = wdata->top_index;
214  select_prev(wdata);
215  /* If the rest of the entries are hidden, go down to the last unhidden one */
216  if ((*ARRAY_GET(&wdata->entries, wdata->hil_index))->is_hidden)
217  select_next(wdata);
218 
219  return (orig_hil_index != wdata->hil_index);
220 }
int top_index
First mailbox visible in sidebar.
Definition: private.h:67
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:105
int hil_index
Highlighted mailbox.
Definition: private.h:69
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:70
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ select_first()

static bool select_first ( struct SidebarWindowData wdata)
static

Selects the first unhidden mailbox.

Parameters
wdataSidebar data
Return values
trueThe selection changed

Definition at line 227 of file functions.c.

228 {
229  if (ARRAY_EMPTY(&wdata->entries) || (wdata->hil_index < 0))
230  return false;
231 
232  int orig_hil_index = wdata->hil_index;
233 
234  wdata->hil_index = 0;
235  if ((*ARRAY_GET(&wdata->entries, wdata->hil_index))->is_hidden)
236  if (!select_next(wdata))
237  wdata->hil_index = orig_hil_index;
238 
239  return (orig_hil_index != wdata->hil_index);
240 }
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:105
int hil_index
Highlighted mailbox.
Definition: private.h:69
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:70
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ select_last()

static bool select_last ( struct SidebarWindowData wdata)
static

Selects the last unhidden mailbox.

Parameters
wdataSidebar data
Return values
trueThe selection changed

Definition at line 247 of file functions.c.

248 {
249  if (ARRAY_EMPTY(&wdata->entries) || (wdata->hil_index < 0))
250  return false;
251 
252  int orig_hil_index = wdata->hil_index;
253 
254  wdata->hil_index = ARRAY_SIZE(&wdata->entries);
255  if (!select_prev(wdata))
256  wdata->hil_index = orig_hil_index;
257 
258  return (orig_hil_index != wdata->hil_index);
259 }
int hil_index
Highlighted mailbox.
Definition: private.h:69
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:70
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:83
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_change_mailbox()

void sb_change_mailbox ( struct MuttWindow win,
int  op 
)

Perform a Sidebar function.

Parameters
winSidebar Window
opOperation to perform, e.g. OP_SIDEBAR_NEXT_NEW

Definition at line 266 of file functions.c.

267 {
268  if (!mutt_window_is_visible(win))
269  return;
270 
271  struct SidebarWindowData *wdata = sb_wdata_get(win);
272  if (!wdata)
273  return;
274 
275  if (wdata->hil_index < 0) /* It'll get reset on the next draw */
276  return;
277 
278  bool changed = false;
279  const bool c_sidebar_next_new_wrap =
280  cs_subset_bool(NeoMutt->sub, "sidebar_next_new_wrap");
281  switch (op)
282  {
283  case OP_SIDEBAR_FIRST:
284  changed = select_first(wdata);
285  break;
286  case OP_SIDEBAR_LAST:
287  changed = select_last(wdata);
288  break;
289  case OP_SIDEBAR_NEXT:
290  changed = select_next(wdata);
291  break;
292  case OP_SIDEBAR_NEXT_NEW:
293  changed = select_next_new(wdata, c_sidebar_next_new_wrap);
294  break;
295  case OP_SIDEBAR_PAGE_DOWN:
296  changed = select_page_down(wdata);
297  break;
298  case OP_SIDEBAR_PAGE_UP:
299  changed = select_page_up(wdata);
300  break;
301  case OP_SIDEBAR_PREV:
302  changed = select_prev(wdata);
303  break;
304  case OP_SIDEBAR_PREV_NEW:
305  changed = select_prev_new(wdata, c_sidebar_next_new_wrap);
306  break;
307  default:
308  return;
309  }
310  if (changed)
311  win->actions |= WA_RECALC;
312 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
Sidebar private Window data -.
Definition: private.h:62
int hil_index
Highlighted mailbox.
Definition: private.h:69
Container for Accounts, Notifications.
Definition: neomutt.h:36
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
Definition: mutt_window.c:529
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
void * wdata
Private data.
Definition: mutt_window.h:145
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ Here is the call graph for this function:
+ Here is the caller graph for this function: