NeoMutt  2025-01-09-117-gace867
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 <stdint.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 sb_parse_sidebar_unpin (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'sidebar_unpin' command - Implements Command::parse() -.
 
enum CommandResult sb_parse_sidebar_pin (struct Buffer *buf, struct Buffer *s, intptr_t data, 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 56 of file private.h.

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

◆ 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 78 of file private.h.

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

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

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

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

182{
183 wdata->opn_index = -1;
184
185 struct SbEntry **sbep = NULL;
186 ARRAY_FOREACH(sbep, &wdata->entries)
187 {
188 if (m && m->visible)
189 {
190 if (mutt_str_equal((*sbep)->mailbox->realpath, m->realpath))
191 {
192 wdata->opn_index = ARRAY_FOREACH_IDX_sbep;
193 wdata->hil_index = ARRAY_FOREACH_IDX_sbep;
194 break;
195 }
196 }
197 (*sbep)->is_hidden = !(*sbep)->mailbox->visible;
198 }
199}
bool visible
True if a result of "mailboxes".
Definition: mailbox.h:130
+ 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 66 of file sidebar.c.

67{
68 const bool c_sidebar_visible = cs_subset_bool(NeoMutt->sub, "sidebar_visible");
69 if (!c_sidebar_visible)
70 return NULL;
71
73 if (wdata->hil_index < 0)
74 return NULL;
75
76 struct SbEntry **sbep = ARRAY_GET(&wdata->entries, wdata->hil_index);
77 if (!sbep)
78 return NULL;
79
80 return (*sbep)->mailbox;
81}
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.
Definition: mutt_window.h:145
Container for Accounts, Notifications.
Definition: neomutt.h:43
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:47
Sidebar private Window data -.
Definition: private.h:88
struct MuttWindow * win
Sidebar Window.
Definition: private.h:89
+ 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 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_sbep;
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:226
+ 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 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:315
#define ARRAY_FOREACH_TO(elem, head, to)
Iterate from the beginning to an index.
Definition: array.h:238
+ 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 434 of file observer.c.

435{
436 if (!win || !NeoMutt)
437 return;
438
439 struct MuttWindow *dlg = window_find_parent(win, WT_DLG_INDEX);
440
448}
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:405
static int sb_mailbox_observer(struct NotifyCallback *nc)
Notification that a Mailbox has changed - Implements observer_t -.
Definition: observer.c:376
static int sb_account_observer(struct NotifyCallback *nc)
Notification that an Account has changed - Implements observer_t -.
Definition: observer.c:173
static int sb_command_observer(struct NotifyCallback *nc)
Notification that a Command has occurred - Implements observer_t -.
Definition: observer.c:246
static int sb_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t -.
Definition: observer.c:200
static int sb_index_observer(struct NotifyCallback *nc)
Notification that the Index has changed - Implements observer_t -.
Definition: observer.c:352
static int sb_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: observer.c:267
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.
Definition: mutt_window.c:523
@ 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_ALL
Register for all notifications.
Definition: notify_type.h:35
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition: subset.h:51
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
struct Notify * notify
Notifications handler.
Definition: neomutt.h:44
+ 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:335
#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.
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 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.