NeoMutt  2024-10-02-58-g7720cc
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 "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  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 SortType 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 88 of file sidebar.c.

89{
90 if (!m)
91 return;
92
93 struct SbEntry **sbep = NULL;
94 ARRAY_FOREACH(sbep, &wdata->entries)
95 {
96 if ((*sbep)->mailbox == m)
97 return;
98 }
99
100 /* Any new/deleted mailboxes will cause a refresh. As long as
101 * they're valid, our pointers will be updated in prepare_sidebar() */
102
103 struct IndexSharedData *shared = wdata->shared;
104 struct SbEntry *entry = mutt_mem_calloc(1, sizeof(struct SbEntry));
105 entry->mailbox = m;
106
107 if (wdata->top_index < 0)
108 wdata->top_index = ARRAY_SIZE(&wdata->entries);
109 if (wdata->bot_index < 0)
110 wdata->bot_index = ARRAY_SIZE(&wdata->entries);
111 if ((wdata->opn_index < 0) && shared->mailbox &&
113 {
114 wdata->opn_index = ARRAY_SIZE(&wdata->entries);
115 }
116
117 ARRAY_ADD(&wdata->entries, entry);
118}
#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:212
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:87
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
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 125 of file sidebar.c.

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

179{
180 wdata->opn_index = -1;
181
182 struct SbEntry **sbep = NULL;
183 ARRAY_FOREACH(sbep, &wdata->entries)
184 {
185 if (m && m->visible)
186 {
187 if (mutt_str_equal((*sbep)->mailbox->realpath, m->realpath))
188 {
189 wdata->opn_index = ARRAY_FOREACH_IDX;
190 wdata->hil_index = ARRAY_FOREACH_IDX;
191 break;
192 }
193 }
194 (*sbep)->is_hidden = !(*sbep)->mailbox->visible;
195 }
196}
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 63 of file sidebar.c.

64{
65 const bool c_sidebar_visible = cs_subset_bool(NeoMutt->sub, "sidebar_visible");
66 if (!c_sidebar_visible)
67 return NULL;
68
70 if (wdata->hil_index < 0)
71 return NULL;
72
73 struct SbEntry **sbep = ARRAY_GET(&wdata->entries, wdata->hil_index);
74 if (!sbep)
75 return NULL;
76
77 return (*sbep)->mailbox;
78}
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:144
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
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;
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:223
+ 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:259
#define ARRAY_FOREACH_TO(elem, head, to)
Iterate from the beginning to an index.
Definition: array.h:234
+ 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 427 of file observer.c.

428{
429 if (!win || !NeoMutt)
430 return;
431
432 struct MuttWindow *dlg = window_find_parent(win, WT_DLG_INDEX);
433
441}
void mutt_color_observer_add(observer_t callback, void *global_data)
Add an observer.
Definition: notify.c:59
static int sb_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: observer.c:398
static int sb_mailbox_observer(struct NotifyCallback *nc)
Notification that a Mailbox has changed - Implements observer_t -.
Definition: observer.c:369
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:239
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:345
static int sb_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: observer.c:260
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:557
@ WT_DLG_INDEX
Index Dialog, dlg_index()
Definition: mutt_window.h:86
@ 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:52
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:137
struct Notify * notify
Notifications handler.
Definition: neomutt.h:43
+ 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 171 of file sort.c.

172{
174
175 switch (sort & SORT_MASK)
176 {
177 case SORT_COUNT:
178 fn = sb_sort_count;
179 break;
180 case SORT_DESC:
181 fn = sb_sort_desc;
182 break;
183 case SORT_FLAGGED:
184 fn = sb_sort_flagged;
185 break;
186 case SORT_PATH:
187 fn = sb_sort_path;
188 break;
189 case SORT_UNREAD:
190 fn = sb_sort_unread;
191 break;
192 case SORT_ORDER:
193 fn = sb_sort_order;
195 default:
196 break;
197 }
198
199 bool sort_reverse = (sort & SORT_REVERSE);
200 ARRAY_SORT(&wdata->entries, fn, &sort_reverse);
201}
#define ARRAY_SORT(head, fn, sdata)
Sort an array.
Definition: array.h:279
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:62
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:116
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:77
static int sb_sort_unsorted(const void *a, const void *b, void *sdata)
Compare two Sidebar entries into their original order - Implements sort_t -.
Definition: sort.c:151
static int sb_sort_order(const void *a, const void *b, void *sdata)
Compare two Sidebar entries by order of creation - Implements sort_t -.
Definition: sort.c:136
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:97
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:42
#define FALLTHROUGH
Definition: lib.h:111
int(* sort_t)(const void *a, const void *b, void *sdata)
Definition: qsort_r.h:41
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:70
@ SORT_ORDER
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:40
@ SORT_PATH
Sort by the folder's path.
Definition: sort2.h:53
@ SORT_FLAGGED
Sort by the number of flagged emails.
Definition: sort2.h:52
@ SORT_DESC
Sort by the folder's description.
Definition: sort2.h:55
@ SORT_COUNT
Sort by number of emails in a folder.
Definition: sort2.h:50
@ SORT_UNREAD
Sort by the number of unread emails.
Definition: sort2.h:51
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:71
+ 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:100
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:143
+ 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{
46 struct SidebarWindowData *wdata = mutt_mem_calloc(1, sizeof(struct SidebarWindowData));
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 call graph for this function:
+ 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 43 of file sidebar.c.