NeoMutt  2025-12-11-177-g48e272
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
private.h File Reference

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

#include <stdbool.h>
#include "mutt/lib.h"
#include "email/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  ExpandoDataSidebar {
  ED_SID_DELETED_COUNT = 1 , ED_SID_DESCRIPTION , ED_SID_FLAGGED , ED_SID_FLAGGED_COUNT ,
  ED_SID_LIMITED_COUNT , ED_SID_MESSAGE_COUNT , ED_SID_NAME , ED_SID_NEW_MAIL ,
  ED_SID_NOTIFY , ED_SID_OLD_COUNT , ED_SID_POLL , ED_SID_READ_COUNT ,
  ED_SID_TAGGED_COUNT , ED_SID_UNREAD_COUNT , ED_SID_UNSEEN_COUNT
}
 Expando UIDs for the Sidebar. More...
 
enum  DivType { SB_DIV_USER , SB_DIV_ASCII }
 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.
 
void sb_remove_mailbox (struct SidebarWindowData *wdata, const struct Mailbox *m)
 Remove a Mailbox from the Sidebar.
 
void sb_set_current_mailbox (struct SidebarWindowData *wdata, struct Mailbox *m)
 Set the current Mailbox.
 
struct Mailboxsb_get_highlight (struct MuttWindow *win)
 Get the Mailbox that's highlighted in the sidebar.
 
enum CommandResult parse_sidebar_unpin (const struct Command *cmd, struct Buffer *line, struct Buffer *err)
 Parse the 'sidebar-unpin' command - Implements Command::parse() -.
 
enum CommandResult parse_sidebar_pin (const struct Command *cmd, struct Buffer *line, struct Buffer *err)
 Parse the 'sidebar-pin' command - Implements Command::parse() -.
 
bool sb_next (struct SidebarWindowData *wdata)
 Find the next unhidden Mailbox.
 
bool sb_prev (struct SidebarWindowData *wdata)
 Find the previous unhidden Mailbox.
 
int sb_insertion_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t -.
 
void sb_win_add_observers (struct MuttWindow *win)
 Add Observers to the Sidebar Window.
 
void sb_sort_entries (struct SidebarWindowData *wdata, enum EmailSortType sort)
 Sort the Sidebar entries.
 
void sb_wdata_free (struct MuttWindow *win, void **ptr)
 Free Sidebar Window data - Implements MuttWindow::wdata_free() -.
 
struct SidebarWindowDatasb_wdata_get (struct MuttWindow *win)
 Get the Sidebar data for this window.
 
struct SidebarWindowDatasb_wdata_new (struct MuttWindow *win, struct IndexSharedData *shared)
 Create new Window data for the Sidebar.
 
int sb_recalc (struct MuttWindow *win)
 Recalculate the Sidebar display - Implements MuttWindow::recalc() -.
 
int sb_repaint (struct MuttWindow *win)
 Repaint the Sidebar display - Implements MuttWindow::repaint() -.
 

Variables

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

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

◆ ExpandoDataSidebar

Expando UIDs for the Sidebar.

See also
ED_SIDEBAR, ExpandoDomain
Enumerator
ED_SID_DELETED_COUNT 

Mailbox.msg_deleted.

ED_SID_DESCRIPTION 

Mailbox.name.

ED_SID_FLAGGED 

Mailbox.msg_flagged.

ED_SID_FLAGGED_COUNT 

Mailbox.msg_flagged.

ED_SID_LIMITED_COUNT 

Mailbox.vcount.

ED_SID_MESSAGE_COUNT 

Mailbox.msg_count.

ED_SID_NAME 

SbEntry.box.

ED_SID_NEW_MAIL 

Mailbox.has_new.

ED_SID_NOTIFY 

Mailbox.notify_user.

ED_SID_OLD_COUNT 

Mailbox.msg_unread, Mailbox.msg_new.

ED_SID_POLL 

Mailbox.poll_new_mail.

ED_SID_READ_COUNT 

Mailbox.msg_count, Mailbox.msg_unread.

ED_SID_TAGGED_COUNT 

Mailbox.msg_tagged.

ED_SID_UNREAD_COUNT 

Mailbox.msg_unread.

ED_SID_UNSEEN_COUNT 

Mailbox.msg_new.

Definition at line 55 of file private.h.

56{
72};
@ ED_SID_FLAGGED_COUNT
Mailbox.msg_flagged.
Definition private.h:60
@ ED_SID_READ_COUNT
Mailbox.msg_count, Mailbox.msg_unread.
Definition private.h:68
@ ED_SID_DESCRIPTION
Mailbox.name.
Definition private.h:58
@ ED_SID_NEW_MAIL
Mailbox.has_new.
Definition private.h:64
@ ED_SID_UNSEEN_COUNT
Mailbox.msg_new.
Definition private.h:71
@ ED_SID_POLL
Mailbox.poll_new_mail.
Definition private.h:67
@ ED_SID_OLD_COUNT
Mailbox.msg_unread, Mailbox.msg_new.
Definition private.h:66
@ ED_SID_MESSAGE_COUNT
Mailbox.msg_count.
Definition private.h:62
@ ED_SID_LIMITED_COUNT
Mailbox.vcount.
Definition private.h:61
@ ED_SID_UNREAD_COUNT
Mailbox.msg_unread.
Definition private.h:70
@ ED_SID_TAGGED_COUNT
Mailbox.msg_tagged.
Definition private.h:69
@ ED_SID_NOTIFY
Mailbox.notify_user.
Definition private.h:65
@ ED_SID_NAME
SbEntry.box.
Definition private.h:63
@ ED_SID_DELETED_COUNT
Mailbox.msg_deleted.
Definition private.h:57
@ ED_SID_FLAGGED
Mailbox.msg_flagged.
Definition private.h:59

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

Definition at line 77 of file private.h.

78{
81};
@ SB_DIV_ASCII
An ASCII vertical bar (pipe)
Definition private.h:80
@ SB_DIV_USER
User configured using $sidebar_divider_char.
Definition private.h:79

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

101{
102 if (!m)
103 return;
104
105 struct SbEntry **sbep = NULL;
106 ARRAY_FOREACH(sbep, &wdata->entries)
107 {
108 if ((*sbep)->mailbox == m)
109 return;
110 }
111
112 /* Any new/deleted mailboxes will cause a refresh. As long as
113 * they're valid, our pointers will be updated in prepare_sidebar() */
114
115 struct IndexSharedData *shared = wdata->shared;
116 struct SbEntry *entry = MUTT_MEM_CALLOC(1, struct SbEntry);
117 entry->mailbox = m;
118
119 if (wdata->top_index < 0)
120 wdata->top_index = ARRAY_SIZE(&wdata->entries);
121 if (wdata->bot_index < 0)
122 wdata->bot_index = ARRAY_SIZE(&wdata->entries);
123 if ((wdata->opn_index < 0) && shared->mailbox &&
125 {
126 wdata->opn_index = ARRAY_SIZE(&wdata->entries);
127 }
128
129 ARRAY_ADD(&wdata->entries, entry);
130}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:48
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:662
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:40
struct Mailbox * mailbox
Mailbox this represents.
Definition private.h:44
int top_index
First mailbox visible in sidebar.
Definition private.h:92
int bot_index
Last mailbox visible in sidebar.
Definition private.h:95
struct IndexSharedData * shared
Shared Index Data.
Definition private.h:89
int opn_index
Current (open) mailbox.
Definition private.h:93
struct SbEntryArray entries
Items to display in the sidebar.
Definition private.h:90
+ 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,
const struct Mailbox * m )

Remove a Mailbox from the Sidebar.

Parameters
wdataSidebar data
mMailbox to remove

Definition at line 137 of file sidebar.c.

138{
139 struct SbEntry **sbep = NULL;
140 ARRAY_FOREACH(sbep, &wdata->entries)
141 {
142 if ((*sbep)->mailbox != m)
143 continue;
144
145 struct SbEntry *sbe_remove = *sbep;
146 ARRAY_REMOVE(&wdata->entries, sbep);
147 FREE(&sbe_remove);
148
149 if (wdata->opn_index == ARRAY_FOREACH_IDX_sbep)
150 {
151 // Open item was deleted
152 wdata->opn_index = -1;
153 }
154 else if ((wdata->opn_index > 0) && (wdata->opn_index > ARRAY_FOREACH_IDX_sbep))
155 {
156 // Open item is still visible, so adjust the index
157 wdata->opn_index--;
158 }
159
160 if (wdata->hil_index == ARRAY_FOREACH_IDX_sbep)
161 {
162 // If possible, keep the highlight where it is
163 struct SbEntry **sbep_cur = ARRAY_GET(&wdata->entries, ARRAY_FOREACH_IDX_sbep);
164 if (!sbep_cur)
165 {
166 // The last entry was deleted, so backtrack
167 sb_prev(wdata);
168 }
169 else if ((*sbep)->is_hidden)
170 {
171 // Find the next unhidden entry, or the previous
172 if (!sb_next(wdata) && !sb_prev(wdata))
173 wdata->hil_index = -1;
174 }
175 }
176 else if ((wdata->hil_index > 0) && (wdata->hil_index > ARRAY_FOREACH_IDX_sbep))
177 {
178 // Highlighted item is still visible, so adjust the index
179 wdata->hil_index--;
180 }
181 break;
182 }
183}
#define ARRAY_REMOVE(head, elem)
Remove an entry from the array, shifting down the subsequent entries.
Definition array.h:332
#define ARRAY_GET(head, idx)
Return the element at index.
Definition array.h:109
#define FREE(x)
Definition memory.h:63
bool sb_prev(struct SidebarWindowData *wdata)
Find the previous unhidden Mailbox.
Definition functions.c:131
bool sb_next(struct SidebarWindowData *wdata)
Find the next unhidden Mailbox.
Definition functions.c:92
int hil_index
Highlighted mailbox.
Definition private.h:94
+ 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 190 of file sidebar.c.

191{
192 wdata->opn_index = -1;
193
194 struct SbEntry **sbep = NULL;
195 ARRAY_FOREACH(sbep, &wdata->entries)
196 {
197 if (m && m->visible)
198 {
199 if (mutt_str_equal((*sbep)->mailbox->realpath, m->realpath))
200 {
201 wdata->opn_index = ARRAY_FOREACH_IDX_sbep;
202 wdata->hil_index = ARRAY_FOREACH_IDX_sbep;
203 break;
204 }
205 }
206 (*sbep)->is_hidden = !(*sbep)->mailbox->visible;
207 }
208}
bool visible
True if a result of "mailboxes".
Definition mailbox.h:130
bool is_hidden
Don't show, e.g. $sidebar_new_mail_only.
Definition private.h:45
+ 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 75 of file sidebar.c.

76{
77 const bool c_sidebar_visible = cs_subset_bool(NeoMutt->sub, "sidebar_visible");
78 if (!c_sidebar_visible)
79 return NULL;
80
82 if (wdata->hil_index < 0)
83 return NULL;
84
85 struct SbEntry **sbep = ARRAY_GET(&wdata->entries, wdata->hil_index);
86 if (!sbep)
87 return NULL;
88
89 return (*sbep)->mailbox;
90}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
struct SidebarWindowData * sb_wdata_get(struct MuttWindow *win)
Get the Sidebar data for this window.
Definition wdata.c:77
void * wdata
Private data.
Container for Accounts, Notifications.
Definition neomutt.h:128
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:134
Sidebar private Window data -.
Definition private.h:87
struct MuttWindow * win
Sidebar Window.
Definition private.h:88
+ 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
trueMailbox found

Definition at line 92 of file functions.c.

93{
94 struct SbEntry **sbep = NULL;
95 ARRAY_FOREACH_FROM(sbep, &wdata->entries, wdata->hil_index + 1)
96 {
97 if (!(*sbep)->is_hidden)
98 {
99 wdata->hil_index = ARRAY_FOREACH_IDX_sbep;
100 return true;
101 }
102 }
103
104 return false;
105}
#define ARRAY_FOREACH_FROM(elem, head, from)
Iterate from an index to the end.
Definition array.h:235
+ 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
trueMailbox found

Definition at line 131 of file functions.c.

132{
133 struct SbEntry **sbep = NULL, **prev = NULL;
134 ARRAY_FOREACH_TO(sbep, &wdata->entries, wdata->hil_index)
135 {
136 if (!(*sbep)->is_hidden)
137 prev = sbep;
138 }
139
140 if (prev)
141 {
142 wdata->hil_index = ARRAY_IDX(&wdata->entries, prev);
143 return true;
144 }
145
146 return false;
147}
#define ARRAY_IDX(head, elem)
Return the index of an element of the array.
Definition array.h:324
#define ARRAY_FOREACH_TO(elem, head, to)
Iterate from the beginning to an index.
Definition array.h:247
+ 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 436 of file observer.c.

437{
438 if (!win || !NeoMutt)
439 return;
440
441 struct MuttWindow *dlg = window_find_parent(win, WT_DLG_INDEX);
442
450}
void mutt_color_observer_add(observer_t callback, void *global_data)
Add an observer.
Definition notify.c:61
static int sb_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition observer.c:407
static int sb_mailbox_observer(struct NotifyCallback *nc)
Notification that a Mailbox has changed - Implements observer_t -.
Definition observer.c:378
static int sb_account_observer(struct NotifyCallback *nc)
Notification that an Account has changed - Implements observer_t -.
Definition observer.c:175
static int sb_command_observer(struct NotifyCallback *nc)
Notification that a Command has occurred - Implements observer_t -.
Definition observer.c:248
static int sb_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t -.
Definition observer.c:202
static int sb_index_observer(struct NotifyCallback *nc)
Notification that the Index has changed - Implements observer_t -.
Definition observer.c:354
static int sb_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition observer.c:269
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:191
struct MuttWindow * window_find_parent(struct MuttWindow *win, enum WindowType type)
Find a (grand-)parent of a Window by type.
@ WT_DLG_INDEX
Index Dialog, dlg_index()
Definition mutt_window.h:87
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition notify_type.h:57
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition notify_type.h:43
@ 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_INDEX
Index data has changed, NotifyIndex, IndexSharedData.
Definition notify_type.h:48
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition subset.h:51
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
struct Notify * notify
Notifications handler.
Definition neomutt.h:130
+ 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 EmailSortType sort )

Sort the Sidebar entries.

Parameters
wdataSidebar data
sortSort order, e.g. SB_SORT_PATH

Sort the wdata->entries array according to the current sort config option $sidebar_sort. 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 161 of file sort.c.

162{
163 sort_t fn = NULL;
164
165 switch (sort & SORT_MASK)
166 {
167 case SB_SORT_COUNT:
168 fn = sb_sort_count;
169 break;
170 case SB_SORT_DESC:
171 fn = sb_sort_desc;
172 break;
173 case SB_SORT_FLAGGED:
174 fn = sb_sort_flagged;
175 break;
176 case SB_SORT_PATH:
177 fn = sb_sort_path;
178 break;
179 case SB_SORT_UNREAD:
180 fn = sb_sort_unread;
181 break;
182 case SB_SORT_UNSORTED:
183 default:
184 fn = sb_sort_unsorted;
185 break;
186 }
187
188 bool sort_reverse = (sort & SORT_REVERSE);
189 ARRAY_SORT(&wdata->entries, fn, &sort_reverse);
190}
#define ARRAY_SORT(head, fn, sdata)
Sort an array.
Definition array.h:350
#define SORT_MASK
Mask for the sort id.
Definition sort.h:38
#define SORT_REVERSE
Reverse the order of the sort.
Definition sort.h:39
static int sb_sort_desc(const void *a, const void *b, void *sdata)
Compare two Sidebar entries by description - Implements sort_t -.
Definition sort.c:64
static int sb_sort_unread(const void *a, const void *b, void *sdata)
Compare two Sidebar entries by unread - Implements sort_t -.
Definition sort.c:118
static int sb_sort_flagged(const void *a, const void *b, void *sdata)
Compare two Sidebar entries by flagged - Implements sort_t -.
Definition sort.c:79
static int sb_sort_unsorted(const void *a, const void *b, void *sdata)
Compare two Sidebar entries by order of creation - Implements sort_t -.
Definition sort.c:138
static int sb_sort_path(const void *a, const void *b, void *sdata)
Compare two Sidebar entries by path - Implements sort_t -.
Definition sort.c:99
static int sb_sort_count(const void *a, const void *b, void *sdata)
Compare two Sidebar entries by count - Implements sort_t -.
Definition sort.c:44
int(* sort_t)(const void *a, const void *b, void *sdata)
Definition qsort_r.h:41
@ SB_SORT_FLAGGED
Sort by count of flagged messages.
Definition sort.h:33
@ SB_SORT_COUNT
Sort by total message count.
Definition sort.h:31
@ SB_SORT_DESC
Sort by mailbox description.
Definition sort.h:32
@ SB_SORT_PATH
Sort by mailbox path (alphabetically)
Definition sort.h:34
@ SB_SORT_UNREAD
Sort by count of unread messages.
Definition sort.h:35
@ SB_SORT_UNSORTED
Sort into the order the mailboxes were configured.
Definition sort.h:36
+ 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 77 of file wdata.c.

78{
79 if (!win || (win->type != WT_SIDEBAR))
80 return NULL;
81
82 return win->wdata;
83}
@ WT_SIDEBAR
Side panel containing Accounts or groups of data.
enum WindowType type
Window type, e.g. WT_SIDEBAR.
+ 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 44 of file wdata.c.

45{
47 wdata->win = win;
48 wdata->shared = shared;
49 ARRAY_INIT(&wdata->entries);
50 return wdata;
51}
#define ARRAY_INIT(head)
Initialize an array.
Definition array.h:65
+ Here is the caller graph for this function:

Variable Documentation

◆ SidebarPinned

struct ListHead SidebarPinned
extern

List of mailboxes to always display in the sidebar.

Definition at line 44 of file sidebar.c.