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

GUI display the mailboxes in a side panel. More...

#include <stdbool.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "gui/lib.h"
+ Include dependency graph for private.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SbEntry
 Info about folders in the sidebar. More...
 
struct  SidebarWindowData
 Sidebar private Window data -. More...
 

Enumerations

enum  DivType { SB_DIV_USER, SB_DIV_ASCII, SB_DIV_UTF8 }
 Source of the sidebar divider character. More...
 

Functions

void sb_add_mailbox (struct SidebarWindowData *wdata, struct Mailbox *m)
 Add a Mailbox to the Sidebar. More...
 
void sb_remove_mailbox (struct SidebarWindowData *wdata, struct Mailbox *m)
 Remove a Mailbox from the Sidebar. More...
 
void sb_set_current_mailbox (struct SidebarWindowData *wdata, struct Mailbox *m)
 Set the current Mailbox. More...
 
bool select_next (struct SidebarWindowData *wdata)
 Selects the next unhidden mailbox. More...
 
bool select_prev (struct SidebarWindowData *wdata)
 Selects the previous unhidden mailbox. More...
 
int sb_insertion_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t. More...
 
void sb_win_add_observers (struct MuttWindow *win)
 Add Observers to the Sidebar Window. More...
 
void sb_sort_entries (struct SidebarWindowData *wdata, enum SortType sort)
 Sort the Sidebar entries. More...
 
void sb_wdata_free (struct MuttWindow *win, void **ptr)
 Free Sidebar Window data - Implements MuttWindow::wdata_free() -. More...
 
struct SidebarWindowDatasb_wdata_get (struct MuttWindow *win)
 Get the Sidebar data for this window. More...
 
struct SidebarWindowDatasb_wdata_new (struct IndexSharedData *shared)
 Create new Window data for the Sidebar. More...
 
int sb_recalc (struct MuttWindow *win)
 Recalculate the Sidebar display - Implements MuttWindow::recalc() -. More...
 
int sb_repaint (struct MuttWindow *win)
 Repaint the Sidebar display - Implements MuttWindow::repaint() -. More...
 

Variables

struct ListHead SidebarWhitelist
 List of mailboxes to always display in the sidebar. More...
 

Detailed Description

GUI display the mailboxes in a side panel.

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 private.h.

Enumeration Type Documentation

◆ DivType

enum DivType

Source of the sidebar divider character.

Enumerator
SB_DIV_USER 

User configured using $sidebar_divider_char.

SB_DIV_ASCII 

An ASCII vertical bar (pipe)

SB_DIV_UTF8 

A unicode line-drawing character.

Definition at line 52 of file private.h.

53 {
54  SB_DIV_USER,
55  SB_DIV_ASCII,
56  SB_DIV_UTF8,
57 };

Function Documentation

◆ sb_add_mailbox()

void sb_add_mailbox ( struct SidebarWindowData wdata,
struct Mailbox m 
)

Add a Mailbox to the Sidebar.

Parameters
wdataSidebar data
mMailbox to add

The Sidebar will be re-sorted, and the indices updated, when sb_recalc() is called.

Definition at line 84 of file sidebar.c.

85 {
86  if (!m)
87  return;
88 
89  /* Any new/deleted mailboxes will cause a refresh. As long as
90  * they're valid, our pointers will be updated in prepare_sidebar() */
91 
92  struct IndexSharedData *shared = wdata->shared;
93  struct SbEntry *entry = mutt_mem_calloc(1, sizeof(struct SbEntry));
94  entry->mailbox = m;
95 
96  if (wdata->top_index < 0)
97  wdata->top_index = ARRAY_SIZE(&wdata->entries);
98  if (wdata->bot_index < 0)
99  wdata->bot_index = ARRAY_SIZE(&wdata->entries);
100  if ((wdata->opn_index < 0) && shared->mailbox &&
101  mutt_str_equal(m->realpath, shared->mailbox->realpath))
102  {
103  wdata->opn_index = ARRAY_SIZE(&wdata->entries);
104  }
105 
106  ARRAY_ADD(&wdata->entries, entry);
107 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
int opn_index
Current (open) mailbox.
Definition: private.h:68
int top_index
First mailbox visible in sidebar.
Definition: private.h:67
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:36
Info about folders in the sidebar.
Definition: private.h:39
struct Mailbox * mailbox
Mailbox this represents.
Definition: private.h:44
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:152
struct Mailbox * mailbox
Current Mailbox.
Definition: shared_data.h:41
int bot_index
Last mailbox visible in sidebar.
Definition: private.h:70
struct IndexSharedData * shared
Definition: private.h:64
#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_remove_mailbox()

void sb_remove_mailbox ( struct SidebarWindowData wdata,
struct Mailbox m 
)

Remove a Mailbox from the Sidebar.

Parameters
wdataSidebar data
mMailbox to remove

Definition at line 114 of file sidebar.c.

115 {
116  struct SbEntry **sbep = NULL;
117  ARRAY_FOREACH(sbep, &wdata->entries)
118  {
119  if (mutt_str_equal((*sbep)->mailbox->realpath, m->realpath))
120  {
121  struct SbEntry *sbe_remove = *sbep;
122  ARRAY_REMOVE(&wdata->entries, sbep);
123  FREE(&sbe_remove);
124 
125  if (wdata->opn_index == ARRAY_FOREACH_IDX)
126  {
127  // Open item was deleted
128  wdata->opn_index = -1;
129  }
130  else if ((wdata->opn_index > 0) && (wdata->opn_index > ARRAY_FOREACH_IDX))
131  {
132  // Open item is still visible, so adjust the index
133  wdata->opn_index--;
134  }
135 
136  if (wdata->hil_index == ARRAY_FOREACH_IDX)
137  {
138  // If possible, keep the highlight where it is
139  struct SbEntry **sbep_cur = ARRAY_GET(&wdata->entries, ARRAY_FOREACH_IDX);
140  if (!sbep_cur)
141  {
142  // The last entry was deleted, so backtrack
143  select_prev(wdata);
144  }
145  else if ((*sbep)->is_hidden)
146  {
147  // Find the next unhidden entry, or the previous
148  if (!select_next(wdata))
149  if (!select_prev(wdata))
150  wdata->hil_index = -1;
151  }
152  }
153  else if ((wdata->hil_index > 0) && (wdata->hil_index > ARRAY_FOREACH_IDX))
154  {
155  // Highlighted item is still visible, so adjust the index
156  wdata->hil_index--;
157  }
158  break;
159  }
160  }
161 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
int opn_index
Current (open) mailbox.
Definition: private.h:68
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:206
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:105
Info about folders in the sidebar.
Definition: private.h:39
int hil_index
Highlighted mailbox.
Definition: private.h:69
#define ARRAY_REMOVE(head, elem)
Remove an entry from the array, shifting down the subsequent entries.
Definition: array.h:261
#define FREE(x)
Definition: memory.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_set_current_mailbox()

void sb_set_current_mailbox ( struct SidebarWindowData wdata,
struct Mailbox m 
)

Set the current Mailbox.

Parameters
wdataSidebar data
mMailbox

Definition at line 168 of file sidebar.c.

169 {
170  wdata->opn_index = -1;
171 
172  struct SbEntry **sbep = NULL;
173  ARRAY_FOREACH(sbep, &wdata->entries)
174  {
175  if (m)
176  {
177  if (mutt_str_equal((*sbep)->mailbox->realpath, m->realpath))
178  {
179  wdata->opn_index = ARRAY_FOREACH_IDX;
180  wdata->hil_index = ARRAY_FOREACH_IDX;
181  break;
182  }
183  }
184  (*sbep)->is_hidden = ((*sbep)->mailbox->flags & MB_HIDDEN);
185  }
186 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
int opn_index
Current (open) mailbox.
Definition: private.h:68
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:206
Info about folders in the sidebar.
Definition: private.h:39
int hil_index
Highlighted mailbox.
Definition: private.h:69
#define MB_HIDDEN
Definition: mailbox.h:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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:

◆ 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:

◆ sb_insertion_window_observer()

int sb_insertion_window_observer ( struct NotifyCallback nc)

Notification that a Window has changed - Implements observer_t.

Definition at line 470 of file observer.c.

471 {
472  if ((nc->event_type != NT_WINDOW) || !nc->event_data)
473  return -1;
474 
475  if (nc->event_subtype != NT_WINDOW_DIALOG)
476  return 0;
477 
478  struct EventWindow *ev_w = nc->event_data;
479  if (ev_w->win->type != WT_DLG_INDEX)
480  return 0;
481 
482  if (ev_w->flags & WN_VISIBLE)
483  {
484  mutt_debug(LL_DEBUG5, "insertion: visible\n");
485  struct MuttWindow *win_sidebar = sb_win_init(ev_w->win);
486  sb_init_data(win_sidebar);
487  }
488  else if (ev_w->flags & WN_HIDDEN)
489  {
490  mutt_debug(LL_DEBUG5, "insertion: hidden\n");
492  }
493 
494  return 0;
495 }
A new Dialog Window has been created, e.g. WT_DLG_INDEX.
Definition: mutt_window.h:208
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
An Event that happened to a Window.
Definition: mutt_window.h:215
#define WN_HIDDEN
Window became hidden.
Definition: mutt_window.h:193
WindowNotifyFlags flags
Attributes of Window that changed.
Definition: mutt_window.h:218
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:43
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
#define WN_VISIBLE
Window became visible.
Definition: mutt_window.h:192
Index Dialog, index_pager_init()
Definition: mutt_window.h:86
Log at debug level 5.
Definition: logging.h:44
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_win_add_observers()

void sb_win_add_observers ( struct MuttWindow win)

Add Observers to the Sidebar Window.

Parameters
winSidebar Window

Definition at line 435 of file observer.c.

436 {
437  if (!win || !NeoMutt)
438  return;
439 
447 }
A Command has been executed, Command.
Definition: notify_type.h:40
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
Index data has changed, NotifyIndex, IndexSharedData.
Definition: notify_type.h:47
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
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
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:39
Account has changed, NotifyAccount, EventAccount.
Definition: notify_type.h:34
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition: notify_type.h:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_sort_entries()

void sb_sort_entries ( struct SidebarWindowData wdata,
enum SortType  sort 
)

Sort the Sidebar entries.

Parameters
wdataSidebar data
sortSort order, e.g. SORT_PATH

Sort the wdata->entries array according to the current sort config option $sidebar_sort_method. This calls qsort to do the work which calls our callback function "cb_qsort_sbe".

Once sorted, the prev/next links will be reconstructed.

Definition at line 177 of file sort.c.

178 {
180 
181  switch (sort & SORT_MASK)
182  {
183  case SORT_COUNT:
184  fn = sb_sort_count;
185  break;
186  case SORT_DESC:
187  fn = sb_sort_desc;
188  break;
189  case SORT_FLAGGED:
190  fn = sb_sort_flagged;
191  break;
192  case SORT_PATH:
193  fn = sb_sort_path;
194  break;
195  case SORT_UNREAD:
196  fn = sb_sort_unread;
197  break;
198  case SORT_ORDER:
199  fn = sb_sort_order;
200  default:
201  break;
202  }
203 
204  sb_sort_reverse = (sort & SORT_REVERSE);
205  ARRAY_SORT(&wdata->entries, fn);
206 }
Sort by the number of flagged emails.
Definition: sort2.h:60
Sort by the folder&#39;s path.
Definition: sort2.h:61
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:48
int(* sort_t)(const void *a, const void *b)
Prototype for generic comparison function, compatible with qsort.
Definition: sort.h:44
Sort by the number of unread emails.
Definition: sort2.h:59
Sort by the folder&#39;s description.
Definition: sort2.h:63
#define ARRAY_SORT(head, fn)
Sort an array.
Definition: array.h:271
Sort by number of emails in a folder.
Definition: sort2.h:58
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:79
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_wdata_get()

struct SidebarWindowData* sb_wdata_get ( struct MuttWindow win)

Get the Sidebar data for this window.

Parameters
winWindow

Definition at line 70 of file wdata.c.

71 {
72  if (!win || (win->type != WT_SIDEBAR))
73  return NULL;
74 
75  return win->wdata;
76 }
Side panel containing Accounts or groups of data.
Definition: mutt_window.h:101
void * wdata
Private data.
Definition: mutt_window.h:145
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
+ Here is the caller graph for this function:

◆ sb_wdata_new()

struct SidebarWindowData* sb_wdata_new ( struct IndexSharedData shared)

Create new Window data for the Sidebar.

Return values
ptrNew Window data

Definition at line 41 of file wdata.c.

42 {
43  struct SidebarWindowData *wdata = mutt_mem_calloc(1, sizeof(struct SidebarWindowData));
44  wdata->shared = shared;
45  ARRAY_INIT(&wdata->entries);
46  return wdata;
47 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
Sidebar private Window data -.
Definition: private.h:62
struct IndexSharedData * shared
Definition: private.h:64
void * wdata
Private data.
Definition: mutt_window.h:145
#define ARRAY_INIT(head)
Initialize an array.
Definition: array.h:61
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ SidebarWhitelist

struct ListHead SidebarWhitelist

List of mailboxes to always display in the sidebar.

Definition at line 44 of file sidebar.c.