NeoMutt  2021-02-05
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 "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
booltrue if the selection changed

Definition at line 44 of file functions.c.

45 {
46  if (ARRAY_EMPTY(&wdata->entries) || (wdata->hil_index < 0))
47  return false;
48 
49  struct SbEntry **sbep = NULL;
50  ARRAY_FOREACH_FROM(sbep, &wdata->entries, wdata->hil_index + 1)
51  {
52  if (!(*sbep)->is_hidden)
53  {
54  wdata->hil_index = ARRAY_FOREACH_IDX;
55  return true;
56  }
57  }
58 
59  return false;
60 }
Info about folders in the sidebar.
Definition: private.h:38
int hil_index
Highlighted mailbox.
Definition: private.h:67
#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 70 of file functions.c.

71 {
72  struct SbEntry **sbep = NULL;
73  ARRAY_FOREACH_FROM_TO(sbep, &wdata->entries, begin, end)
74  {
75  if ((*sbep)->mailbox->has_new || (*sbep)->mailbox->msg_unread != 0)
76  return sbep;
77  }
78  return NULL;
79 }
Info about folders in the sidebar.
Definition: private.h:38
#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
booltrue if the selection changed

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

Definition at line 89 of file functions.c.

90 {
91  const size_t max_entries = ARRAY_SIZE(&wdata->entries);
92 
93  if ((max_entries == 0) || (wdata->hil_index < 0))
94  return false;
95 
96  struct SbEntry **sbep = NULL;
97  if ((sbep = next_new(wdata, wdata->hil_index + 1, max_entries)) ||
98  (next_new_wrap && (sbep = next_new(wdata, 0, wdata->hil_index))))
99  {
100  wdata->hil_index = ARRAY_IDX(&wdata->entries, sbep);
101  return true;
102  }
103 
104  return false;
105 }
#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:38
int hil_index
Highlighted mailbox.
Definition: private.h:67
#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
booltrue if the selection changed

Definition at line 112 of file functions.c.

113 {
114  if (ARRAY_EMPTY(&wdata->entries) || (wdata->hil_index < 0))
115  return false;
116 
117  struct SbEntry **sbep = NULL, **prev = NULL;
118  ARRAY_FOREACH_TO(sbep, &wdata->entries, wdata->hil_index)
119  {
120  if (!(*sbep)->is_hidden)
121  prev = sbep;
122  }
123 
124  if (prev)
125  {
126  wdata->hil_index = ARRAY_IDX(&wdata->entries, prev);
127  return true;
128  }
129 
130  return false;
131 }
#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:38
int hil_index
Highlighted mailbox.
Definition: private.h:67
#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 141 of file functions.c.

142 {
143  struct SbEntry **sbep = NULL, **prev = NULL;
144  ARRAY_FOREACH_FROM_TO(sbep, &wdata->entries, begin, end)
145  {
146  if ((*sbep)->mailbox->has_new || (*sbep)->mailbox->msg_unread != 0)
147  prev = sbep;
148  }
149 
150  return prev;
151 }
Info about folders in the sidebar.
Definition: private.h:38
#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
booltrue if the selection changed

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

Definition at line 161 of file functions.c.

162 {
163  const size_t max_entries = ARRAY_SIZE(&wdata->entries);
164 
165  if ((max_entries == 0) || (wdata->hil_index < 0))
166  return false;
167 
168  struct SbEntry **sbep = NULL;
169  if ((sbep = prev_new(wdata, 0, wdata->hil_index)) ||
170  (next_new_wrap && (sbep = prev_new(wdata, wdata->hil_index + 1, max_entries))))
171  {
172  wdata->hil_index = ARRAY_IDX(&wdata->entries, sbep);
173  return true;
174  }
175 
176  return false;
177 }
#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:38
int hil_index
Highlighted mailbox.
Definition: private.h:67
#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
booltrue if the selection changed

Definition at line 184 of file functions.c.

185 {
186  if (ARRAY_EMPTY(&wdata->entries) || (wdata->bot_index < 0))
187  return false;
188 
189  int orig_hil_index = wdata->hil_index;
190 
191  wdata->hil_index = wdata->bot_index;
192  select_next(wdata);
193  /* If the rest of the entries are hidden, go up to the last unhidden one */
194  if ((*ARRAY_GET(&wdata->entries, wdata->hil_index))->is_hidden)
195  select_prev(wdata);
196 
197  return (orig_hil_index != wdata->hil_index);
198 }
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:105
int hil_index
Highlighted mailbox.
Definition: private.h:67
#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:68
+ 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
booltrue if the selection changed

Definition at line 205 of file functions.c.

206 {
207  if (ARRAY_EMPTY(&wdata->entries) || (wdata->top_index < 0))
208  return false;
209 
210  int orig_hil_index = wdata->hil_index;
211 
212  wdata->hil_index = wdata->top_index;
213  select_prev(wdata);
214  /* If the rest of the entries are hidden, go down to the last unhidden one */
215  if ((*ARRAY_GET(&wdata->entries, wdata->hil_index))->is_hidden)
216  select_next(wdata);
217 
218  return (orig_hil_index != wdata->hil_index);
219 }
int top_index
First mailbox visible in sidebar.
Definition: private.h:65
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:105
int hil_index
Highlighted mailbox.
Definition: private.h:67
#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
booltrue if the selection changed

Definition at line 226 of file functions.c.

227 {
228  if (ARRAY_EMPTY(&wdata->entries) || (wdata->hil_index < 0))
229  return false;
230 
231  int orig_hil_index = wdata->hil_index;
232 
233  wdata->hil_index = 0;
234  if ((*ARRAY_GET(&wdata->entries, wdata->hil_index))->is_hidden)
235  if (!select_next(wdata))
236  wdata->hil_index = orig_hil_index;
237 
238  return (orig_hil_index != wdata->hil_index);
239 }
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:105
int hil_index
Highlighted mailbox.
Definition: private.h:67
#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
booltrue if the selection changed

Definition at line 246 of file functions.c.

247 {
248  if (ARRAY_EMPTY(&wdata->entries) || (wdata->hil_index < 0))
249  return false;
250 
251  int orig_hil_index = wdata->hil_index;
252 
253  wdata->hil_index = ARRAY_SIZE(&wdata->entries);
254  if (!select_prev(wdata))
255  wdata->hil_index = orig_hil_index;
256 
257  return (orig_hil_index != wdata->hil_index);
258 }
int hil_index
Highlighted mailbox.
Definition: private.h:67
#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 265 of file functions.c.

266 {
267  if (!mutt_window_is_visible(win))
268  return;
269 
270  struct SidebarWindowData *wdata = sb_wdata_get(win);
271  if (!wdata)
272  return;
273 
274  if (wdata->hil_index < 0) /* It'll get reset on the next draw */
275  return;
276 
277  bool changed = false;
278  switch (op)
279  {
280  case OP_SIDEBAR_FIRST:
281  changed = select_first(wdata);
282  break;
283  case OP_SIDEBAR_LAST:
284  changed = select_last(wdata);
285  break;
286  case OP_SIDEBAR_NEXT:
287  changed = select_next(wdata);
288  break;
289  case OP_SIDEBAR_NEXT_NEW:
290  changed = select_next_new(wdata, C_SidebarNextNewWrap);
291  break;
292  case OP_SIDEBAR_PAGE_DOWN:
293  changed = select_page_down(wdata);
294  break;
295  case OP_SIDEBAR_PAGE_UP:
296  changed = select_page_up(wdata);
297  break;
298  case OP_SIDEBAR_PREV:
299  changed = select_prev(wdata);
300  break;
301  case OP_SIDEBAR_PREV_NEW:
302  changed = select_prev_new(wdata, C_SidebarNextNewWrap);
303  break;
304  default:
305  return;
306  }
307  if (changed)
308  win->actions |= WA_RECALC;
309 }
Sidebar private Window data -.
Definition: private.h:61
int hil_index
Highlighted mailbox.
Definition: private.h:67
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:125
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
Definition: mutt_window.c:657
void * wdata
Private data.
Definition: mutt_window.h:138
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:107
+ Here is the call graph for this function:
+ Here is the caller graph for this function: