NeoMutt  2022-04-29-81-g9c5a59
Teaching an old dog new tricks
DOXYGEN
private.h File Reference

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

#include <stdbool.h>
#include <stdint.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/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

 ARRAY_HEAD (SbEntryArray, struct SbEntry *)
 
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...
 
struct Mailboxsb_get_highlight (struct MuttWindow *win)
 Get the Mailbox that's highlighted in the sidebar. More...
 
enum CommandResult sb_parse_unwhitelist (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unsidebar_whitelist' command - Implements Command::parse() -. More...
 
enum CommandResult sb_parse_whitelist (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'sidebar_whitelist' command - Implements Command::parse() -. More...
 
bool sb_next (struct SidebarWindowData *wdata)
 Find the next unhidden Mailbox. More...
 
bool sb_prev (struct SidebarWindowData *wdata)
 Find 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 MuttWindow *win, 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 54 of file private.h.

55 {
56  SB_DIV_USER,
57  SB_DIV_ASCII,
58  SB_DIV_UTF8,
59 };
@ SB_DIV_ASCII
An ASCII vertical bar (pipe)
Definition: private.h:57
@ SB_DIV_USER
User configured using $sidebar_divider_char.
Definition: private.h:56
@ SB_DIV_UTF8
A unicode line-drawing character.
Definition: private.h:58

Function Documentation

◆ ARRAY_HEAD()

ARRAY_HEAD ( SbEntryArray  ,
struct SbEntry  
)

◆ 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 83 of file sidebar.c.

84 {
85  if (!m)
86  return;
87 
88  struct SbEntry **sbep = NULL;
89  ARRAY_FOREACH(sbep, &wdata->entries)
90  {
91  if ((*sbep)->mailbox == m)
92  return;
93  }
94 
95  /* Any new/deleted mailboxes will cause a refresh. As long as
96  * they're valid, our pointers will be updated in prepare_sidebar() */
97 
98  struct IndexSharedData *shared = wdata->shared;
99  struct SbEntry *entry = mutt_mem_calloc(1, sizeof(struct SbEntry));
100  entry->mailbox = m;
101 
102  if (wdata->top_index < 0)
103  wdata->top_index = ARRAY_SIZE(&wdata->entries);
104  if (wdata->bot_index < 0)
105  wdata->bot_index = ARRAY_SIZE(&wdata->entries);
106  if ((wdata->opn_index < 0) && shared->mailbox &&
107  mutt_str_equal(m->realpath, shared->mailbox->realpath))
108  {
109  wdata->opn_index = ARRAY_SIZE(&wdata->entries);
110  }
111 
112  ARRAY_ADD(&wdata->entries, entry);
113 }
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:155
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:211
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:86
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:784
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:37
struct Mailbox * mailbox
Current Mailbox.
Definition: shared_data.h:41
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
Info about folders in the sidebar.
Definition: private.h:41
struct Mailbox * mailbox
Mailbox this represents.
Definition: private.h:45
int top_index
First mailbox visible in sidebar.
Definition: private.h:70
int bot_index
Last mailbox visible in sidebar.
Definition: private.h:73
struct IndexSharedData * shared
Shared Index Data.
Definition: private.h:67
int opn_index
Current (open) mailbox.
Definition: private.h:71
struct SbEntryArray entries
Items to display in the sidebar.
Definition: private.h:68
+ 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 120 of file sidebar.c.

121 {
122  struct SbEntry **sbep = NULL;
123  ARRAY_FOREACH(sbep, &wdata->entries)
124  {
125  if ((*sbep)->mailbox != m)
126  continue;
127 
128  struct SbEntry *sbe_remove = *sbep;
129  ARRAY_REMOVE(&wdata->entries, sbep);
130  FREE(&sbe_remove);
131 
132  if (wdata->opn_index == ARRAY_FOREACH_IDX)
133  {
134  // Open item was deleted
135  wdata->opn_index = -1;
136  }
137  else if ((wdata->opn_index > 0) && (wdata->opn_index > ARRAY_FOREACH_IDX))
138  {
139  // Open item is still visible, so adjust the index
140  wdata->opn_index--;
141  }
142 
143  if (wdata->hil_index == ARRAY_FOREACH_IDX)
144  {
145  // If possible, keep the highlight where it is
146  struct SbEntry **sbep_cur = ARRAY_GET(&wdata->entries, ARRAY_FOREACH_IDX);
147  if (!sbep_cur)
148  {
149  // The last entry was deleted, so backtrack
150  sb_prev(wdata);
151  }
152  else if ((*sbep)->is_hidden)
153  {
154  // Find the next unhidden entry, or the previous
155  if (!sb_next(wdata) && !sb_prev(wdata))
156  wdata->hil_index = -1;
157  }
158  }
159  else if ((wdata->hil_index > 0) && (wdata->hil_index > ARRAY_FOREACH_IDX))
160  {
161  // Highlighted item is still visible, so adjust the index
162  wdata->hil_index--;
163  }
164  break;
165  }
166 }
#define ARRAY_REMOVE(head, elem)
Remove an entry from the array, shifting down the subsequent entries.
Definition: array.h:266
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:108
#define FREE(x)
Definition: memory.h:40
bool sb_prev(struct SidebarWindowData *wdata)
Find the previous unhidden Mailbox.
Definition: functions.c:86
bool sb_next(struct SidebarWindowData *wdata)
Find the next unhidden Mailbox.
Definition: functions.c:47
int hil_index
Highlighted mailbox.
Definition: private.h:72
+ 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 173 of file sidebar.c.

174 {
175  wdata->opn_index = -1;
176 
177  struct SbEntry **sbep = NULL;
178  ARRAY_FOREACH(sbep, &wdata->entries)
179  {
180  if (m && m->visible)
181  {
182  if (mutt_str_equal((*sbep)->mailbox->realpath, m->realpath))
183  {
184  wdata->opn_index = ARRAY_FOREACH_IDX;
185  wdata->hil_index = ARRAY_FOREACH_IDX;
186  break;
187  }
188  }
189  (*sbep)->is_hidden = !(*sbep)->mailbox->visible;
190  }
191 }
bool visible
True if a result of "mailboxes".
Definition: mailbox.h:131
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_get_highlight()

struct Mailbox* sb_get_highlight ( struct MuttWindow win)

Get the Mailbox that's highlighted in the sidebar.

Parameters
winSidebar Window
Return values
ptrMailbox

Definition at line 58 of file sidebar.c.

59 {
60  const bool c_sidebar_visible = cs_subset_bool(NeoMutt->sub, "sidebar_visible");
61  if (!c_sidebar_visible)
62  return NULL;
63 
65  if (wdata->hil_index < 0)
66  return NULL;
67 
68  struct SbEntry **sbep = ARRAY_GET(&wdata->entries, wdata->hil_index);
69  if (!sbep)
70  return NULL;
71 
72  return (*sbep)->mailbox;
73 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
struct SidebarWindowData * sb_wdata_get(struct MuttWindow *win)
Get the Sidebar data for this window.
Definition: wdata.c:73
void * wdata
Private data.
Definition: mutt_window.h:145
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
Sidebar private Window data -.
Definition: private.h:65
struct MuttWindow * win
Sidebar Window.
Definition: private.h:66
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_next()

bool sb_next ( struct SidebarWindowData wdata)

Find the next unhidden Mailbox.

Parameters
wdataSidebar data
Return values
booltrue if found

Definition at line 47 of file functions.c.

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 }
#define ARRAY_FOREACH_FROM(elem, head, from)
Iterate from an index to the end.
Definition: array.h:222
+ Here is the caller graph for this function:

◆ sb_prev()

bool sb_prev ( struct SidebarWindowData wdata)

Find the previous unhidden Mailbox.

Parameters
wdataSidebar data
Return values
booltrue if found

Definition at line 86 of file functions.c.

87 {
88  struct SbEntry **sbep = NULL, **prev = NULL;
89  ARRAY_FOREACH_TO(sbep, &wdata->entries, wdata->hil_index)
90  {
91  if (!(*sbep)->is_hidden)
92  prev = sbep;
93  }
94 
95  if (prev)
96  {
97  wdata->hil_index = ARRAY_IDX(&wdata->entries, prev);
98  return true;
99  }
100 
101  return false;
102 }
#define ARRAY_IDX(head, elem)
Return the index of an element of the array.
Definition: array.h:258
#define ARRAY_FOREACH_TO(elem, head, to)
Iterate from the beginning to an index.
Definition: array.h:233
+ 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 421 of file observer.c.

422 {
423  if (!win || !NeoMutt)
424  return;
425 
426  struct MuttWindow *dlg = window_find_parent(win, WT_DLG_INDEX);
427 
435 }
static int sb_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: observer.c:394
static int sb_mailbox_observer(struct NotifyCallback *nc)
Notification that a Mailbox has changed - Implements observer_t -.
Definition: observer.c:367
static int sb_account_observer(struct NotifyCallback *nc)
Notification that an Account has changed - Implements observer_t -.
Definition: observer.c:179
static int sb_command_observer(struct NotifyCallback *nc)
Notification that a Command has occurred - Implements observer_t -.
Definition: observer.c:240
static int sb_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t -.
Definition: observer.c:204
static int sb_index_observer(struct NotifyCallback *nc)
Notification that the Index has changed - Implements observer_t -.
Definition: observer.c:344
static int sb_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: observer.c:259
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
struct MuttWindow * window_find_parent(struct MuttWindow *win, enum WindowType type)
Find a (grand-)parent of a Window by type.
Definition: mutt_window.c:547
@ WT_DLG_INDEX
Index Dialog, index_pager_init()
Definition: mutt_window.h:86
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:55
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
@ NT_COLOR
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:41
@ NT_MAILBOX
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition: notify_type.h:49
@ NT_COMMAND
A Command has been executed, Command.
Definition: notify_type.h:42
@ NT_ACCOUNT
Account has changed, NotifyAccount, EventAccount.
Definition: notify_type.h:36
@ NT_ALL
Register for all notifications.
Definition: notify_type.h:35
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
+ 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 }
#define ARRAY_SORT(head, fn)
Sort an array.
Definition: array.h:277
static int sb_sort_unread(const void *a, const void *b)
Sort Sidebar entries by unread - Implements sort_t -.
Definition: sort.c:123
static int sb_sort_order(const void *a, const void *b)
Sort Sidebar entries by order of creation - Implements sort_t -.
Definition: sort.c:144
static int sb_sort_desc(const void *a, const void *b)
Sort Sidebar entries by description - Implements sort_t -.
Definition: sort.c:65
static int sb_sort_unsorted(const void *a, const void *b)
Sort Sidebar entries into their original order - Implements sort_t -.
Definition: sort.c:157
static int sb_sort_count(const void *a, const void *b)
Sort Sidebar entries by count - Implements sort_t -.
Definition: sort.c:44
static int sb_sort_path(const void *a, const void *b)
Sort Sidebar entries by path - Implements sort_t -.
Definition: sort.c:103
static int sb_sort_flagged(const void *a, const void *b)
Sort Sidebar entries by flagged - Implements sort_t -.
Definition: sort.c:82
static bool sb_sort_reverse
An extra parameter to control sort order.
Definition: sort.c:39
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:78
@ SORT_ORDER
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:48
@ SORT_PATH
Sort by the folder's path.
Definition: sort2.h:61
@ SORT_FLAGGED
Sort by the number of flagged emails.
Definition: sort2.h:60
@ SORT_DESC
Sort by the folder's description.
Definition: sort2.h:63
@ SORT_COUNT
Sort by number of emails in a folder.
Definition: sort2.h:58
@ SORT_UNREAD
Sort by the number of unread emails.
Definition: sort2.h:59
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:79
int(* sort_t)(const void *a, const void *b)
Definition: sort.h:49
+ 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 73 of file wdata.c.

74 {
75  if (!win || (win->type != WT_SIDEBAR))
76  return NULL;
77 
78  return win->wdata;
79 }
@ WT_SIDEBAR
Side panel containing Accounts or groups of data.
Definition: mutt_window.h:101
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 MuttWindow win,
struct IndexSharedData shared 
)

Create new Window data for the Sidebar.

Parameters
winSidebar Window
sharedIndex shared data
Return values
ptrNew Window data

Definition at line 43 of file wdata.c.

44 {
45  struct SidebarWindowData *wdata = mutt_mem_calloc(1, sizeof(struct SidebarWindowData));
46  wdata->win = win;
47  wdata->shared = shared;
48  ARRAY_INIT(&wdata->entries);
49  return wdata;
50 }
#define ARRAY_INIT(head)
Initialize an array.
Definition: array.h:64
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ SidebarWhitelist

struct ListHead SidebarWhitelist
extern

List of mailboxes to always display in the sidebar.

Definition at line 1 of file sidebar.c.