NeoMutt  2023-11-03-85-g512e01
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_browser.c File Reference

File/Mailbox Browser Dialog. More...

#include "config.h"
#include <dirent.h>
#include <errno.h>
#include <grp.h>
#include <limits.h>
#include <locale.h>
#include <pwd.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "conn/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "imap/lib.h"
#include "key/lib.h"
#include "menu/lib.h"
#include "nntp/lib.h"
#include "format_flags.h"
#include "functions.h"
#include "globals.h"
#include "mutt_logging.h"
#include "mutt_mailbox.h"
#include "muttlib.h"
#include "mx.h"
#include "nntp/adata.h"
#include "nntp/mdata.h"
#include "private_data.h"
+ Include dependency graph for dlg_browser.c:

Go to the source code of this file.

Functions

static void init_lastdir (void)
 Initialise the browser directories.
 
void mutt_browser_cleanup (void)
 Clean up working Buffers.
 
bool link_is_dir (const char *folder, const char *path)
 Does this symlink point to a directory?
 
static const char * folder_format_str (char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
 Format a string for the folder browser - Implements format_t -.
 
void browser_add_folder (const struct Menu *menu, struct BrowserState *state, const char *name, const char *desc, const struct stat *st, struct Mailbox *m, void *data)
 Add a folder to the browser list.
 
void init_state (struct BrowserState *state, struct Menu *menu)
 Initialise a browser state.
 
int examine_directory (struct Mailbox *m, struct Menu *menu, struct BrowserState *state, const char *dirname, const char *prefix)
 Get list of all files/newsgroups with mask.
 
int examine_mailboxes (struct Mailbox *m, struct Menu *menu, struct BrowserState *state)
 Get list of mailboxes/subscribed newsgroups.
 
static int select_file_search (struct Menu *menu, regex_t *rx, int line)
 Menu search callback for matching files - Implements Menu::search() -.
 
static void folder_make_entry (struct Menu *menu, char *buf, size_t buflen, int line)
 Format a Folder for the Menu - Implements Menu::make_entry() -.
 
void browser_highlight_default (struct BrowserState *state, struct Menu *menu)
 Decide which browser item should be highlighted.
 
void init_menu (struct BrowserState *state, struct Menu *menu, struct Mailbox *m, struct MuttWindow *sbar)
 Set up a new menu.
 
static int file_tag (struct Menu *menu, int sel, int act)
 Tag an entry in the menu - Implements Menu::tag() -.
 
static int browser_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t -.
 
static int browser_mailbox_observer (struct NotifyCallback *nc)
 Notification that a Mailbox has changed - Implements observer_t -.
 
static int browser_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t -.
 
void mutt_browser_select_dir (const char *f)
 Remember the last directory selected.
 
void dlg_browser (struct Buffer *file, SelectFileFlags flags, struct Mailbox *m, char ***files, int *numfiles)
 Let the user select a file -.
 

Variables

static const struct Mapping FolderHelp []
 Help Bar for the File/Dir/Mailbox browser dialog.
 
static const struct Mapping FolderNewsHelp []
 Help Bar for the NNTP Mailbox browser dialog.
 
struct Buffer LastDir = { 0 }
 Browser: previous selected directory.
 
struct Buffer LastDirBackup = { 0 }
 Browser: backup copy of the current directory.
 

Detailed Description

File/Mailbox Browser Dialog.

Authors
  • Michael R. Elkins
  • R Primus

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 dlg_browser.c.

Function Documentation

◆ init_lastdir()

static void init_lastdir ( void  )
static

Initialise the browser directories.

These keep track of where the browser used to be looking.

Definition at line 139 of file dlg_browser.c.

140{
141 static bool done = false;
142 if (!done)
143 {
146 done = true;
147 }
148}
void buf_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
Definition: buffer.c:349
struct Buffer LastDir
Browser: previous selected directory.
Definition: dlg_browser.c:130
struct Buffer LastDirBackup
Browser: backup copy of the current directory.
Definition: dlg_browser.c:132
#define PATH_MAX
Definition: mutt.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_browser_cleanup()

void mutt_browser_cleanup ( void  )

Clean up working Buffers.

Definition at line 153 of file dlg_browser.c.

154{
157}
void buf_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:389
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ link_is_dir()

bool link_is_dir ( const char *  folder,
const char *  path 
)

Does this symlink point to a directory?

Parameters
folderFolder
pathLink name
Return values
trueLinks to a directory
falseOtherwise

Definition at line 166 of file dlg_browser.c.

167{
168 struct stat st = { 0 };
169 bool rc = false;
170
171 struct Buffer *fullpath = buf_pool_get();
172 buf_concat_path(fullpath, folder, path);
173
174 if (stat(buf_string(fullpath), &st) == 0)
175 rc = S_ISDIR(st.st_mode);
176
177 buf_pool_release(&fullpath);
178
179 return rc;
180}
size_t buf_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
Definition: buffer.c:484
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:93
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
String manipulation buffer.
Definition: buffer.h:34
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ browser_add_folder()

void browser_add_folder ( const struct Menu menu,
struct BrowserState state,
const char *  name,
const char *  desc,
const struct stat *  st,
struct Mailbox m,
void *  data 
)

Add a folder to the browser list.

Parameters
menuMenu to use
stateBrowser state
nameName of folder
descDescription of folder
ststat info for the folder
mMailbox
dataData to associate with the folder

Definition at line 572 of file dlg_browser.c.

575{
576 if ((!menu || state->is_mailbox_list) && m && !m->visible)
577 {
578 return;
579 }
580
581 struct FolderFile ff = { 0 };
582
583 if (st)
584 {
585 ff.mode = st->st_mode;
586 ff.mtime = st->st_mtime;
587 ff.size = st->st_size;
588 ff.gid = st->st_gid;
589 ff.uid = st->st_uid;
590 ff.nlink = st->st_nlink;
591 ff.local = true;
592 }
593 else
594 {
595 ff.local = false;
596 }
597
598 if (m)
599 {
600 ff.has_mailbox = true;
601 ff.gen = m->gen;
602 ff.has_new_mail = m->has_new;
603 ff.msg_count = m->msg_count;
604 ff.msg_unread = m->msg_unread;
605 ff.notify_user = m->notify_user;
607 }
608
609 ff.name = mutt_str_dup(name);
610 ff.desc = mutt_str_dup(desc ? desc : name);
611 ff.imap = false;
612 if (OptNews)
613 ff.nd = data;
614
615 ARRAY_ADD(&state->entry, ff);
616}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:155
bool OptNews
(pseudo) used to change reader mode
Definition: globals.c:75
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
bool is_mailbox_list
Viewing mailboxes.
Definition: lib.h:118
struct BrowserEntryArray entry
Array of files / dirs / mailboxes.
Definition: lib.h:115
Browser entry representing a folder/dir.
Definition: lib.h:78
bool imap
This is an IMAP folder.
Definition: lib.h:95
bool has_mailbox
This is a mailbox.
Definition: lib.h:98
char * name
Name of file/dir/mailbox.
Definition: lib.h:86
uid_t uid
File's User ID.
Definition: lib.h:82
gid_t gid
File's Group ID.
Definition: lib.h:83
bool has_new_mail
true if mailbox has "new mail"
Definition: lib.h:89
bool poll_new_mail
Check mailbox for new mail.
Definition: lib.h:101
bool notify_user
User will be notified of new mail.
Definition: lib.h:100
nlink_t nlink
Number of hard links.
Definition: lib.h:84
char * desc
Description of mailbox.
Definition: lib.h:87
struct NntpMboxData * nd
Extra NNTP data.
Definition: lib.h:103
off_t size
File size.
Definition: lib.h:80
int gen
Unique id, used for (un)sorting.
Definition: lib.h:105
time_t mtime
Modification time.
Definition: lib.h:81
int msg_count
total number of messages
Definition: lib.h:90
mode_t mode
File permissions.
Definition: lib.h:79
int msg_unread
number of unread messages
Definition: lib.h:91
bool has_new
Mailbox has new mail.
Definition: mailbox.h:85
int msg_count
Total number of messages.
Definition: mailbox.h:88
bool poll_new_mail
Check for new mail.
Definition: mailbox.h:114
bool notify_user
Notify the user of new mail.
Definition: mailbox.h:112
bool visible
True if a result of "mailboxes".
Definition: mailbox.h:129
int msg_unread
Number of unread messages.
Definition: mailbox.h:89
int gen
Generation number, for sorting.
Definition: mailbox.h:146
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_state()

void init_state ( struct BrowserState state,
struct Menu menu 
)

Initialise a browser state.

Parameters
stateBrowserState to initialise
menuCurrent menu

Definition at line 623 of file dlg_browser.c.

624{
625 ARRAY_INIT(&state->entry);
626 ARRAY_RESERVE(&state->entry, 256);
627 state->imap_browse = false;
628
629 if (menu)
630 {
631 menu->mdata = &state->entry;
632 menu->mdata_free = NULL; // Menu doesn't own the data
633 }
634}
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
Definition: array.h:188
#define ARRAY_INIT(head)
Initialize an array.
Definition: array.h:64
bool imap_browse
IMAP folder.
Definition: lib.h:116
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:151
void * mdata
Private data.
Definition: lib.h:137
+ Here is the caller graph for this function:

◆ examine_directory()

int examine_directory ( struct Mailbox m,
struct Menu menu,
struct BrowserState state,
const char *  dirname,
const char *  prefix 
)

Get list of all files/newsgroups with mask.

Parameters
mMailbox
menuCurrent Menu
stateState of browser
dirnameDirectory
prefixFiles/newsgroups must match this prefix
Return values
0Success
-1Error

Definition at line 646 of file dlg_browser.c.

648{
649 int rc = -1;
650 struct Buffer *buf = buf_pool_get();
651 if (OptNews)
652 {
654
655 init_state(state, menu);
656
657 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
658 for (unsigned int i = 0; i < adata->groups_num; i++)
659 {
660 struct NntpMboxData *mdata = adata->groups_list[i];
661 if (!mdata)
662 continue;
663 if (prefix && *prefix && !mutt_str_startswith(mdata->group, prefix))
664 continue;
665 if (!mutt_regex_match(c_mask, mdata->group))
666 {
667 continue;
668 }
669 browser_add_folder(menu, state, mdata->group, NULL, NULL, NULL, mdata);
670 }
671 }
672 else
673 {
674 struct stat st = { 0 };
675 DIR *dir = NULL;
676 struct dirent *de = NULL;
677
678 while (stat(dirname, &st) == -1)
679 {
680 if (errno == ENOENT)
681 {
682 /* The last used directory is deleted, try to use the parent dir. */
683 char *c = strrchr(dirname, '/');
684
685 if (c && (c > dirname))
686 {
687 *c = '\0';
688 continue;
689 }
690 }
691 mutt_perror("%s", dirname);
692 goto ed_out;
693 }
694
695 if (!S_ISDIR(st.st_mode))
696 {
697 mutt_error(_("%s is not a directory"), dirname);
698 goto ed_out;
699 }
700
701 if (m)
703
704 dir = mutt_file_opendir(dirname, MUTT_OPENDIR_NONE);
705 if (!dir)
706 {
707 mutt_perror("%s", dirname);
708 goto ed_out;
709 }
710
711 init_state(state, menu);
712
713 struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
715
716 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
717 while ((de = readdir(dir)))
718 {
719 if (mutt_str_equal(de->d_name, "."))
720 continue; /* we don't need . */
721
722 if (prefix && *prefix && !mutt_str_startswith(de->d_name, prefix))
723 {
724 continue;
725 }
726 if (!mutt_regex_match(c_mask, de->d_name))
727 {
728 continue;
729 }
730
731 buf_concat_path(buf, dirname, de->d_name);
732 if (lstat(buf_string(buf), &st) == -1)
733 continue;
734
735 /* No size for directories or symlinks */
736 if (S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode))
737 st.st_size = 0;
738 else if (!S_ISREG(st.st_mode))
739 continue;
740
741 struct MailboxNode *np = NULL;
742 STAILQ_FOREACH(np, &ml, entries)
743 {
745 break;
746 }
747
748 if (np && m && m->poll_new_mail && mutt_str_equal(np->mailbox->realpath, m->realpath))
749 {
750 np->mailbox->msg_count = m->msg_count;
751 np->mailbox->msg_unread = m->msg_unread;
752 }
753 browser_add_folder(menu, state, de->d_name, NULL, &st, np ? np->mailbox : NULL, NULL);
754 }
756 closedir(dir);
757 }
758 browser_sort(state);
759 rc = 0;
760ed_out:
761 buf_pool_release(&buf);
762 return rc;
763}
void browser_sort(struct BrowserState *state)
Sort the entries in the browser.
Definition: sort.c:185
const struct Regex * cs_subset_regex(const struct ConfigSubset *sub, const char *name)
Get a regex config item by name.
Definition: helpers.c:218
void init_state(struct BrowserState *state, struct Menu *menu)
Initialise a browser state.
Definition: dlg_browser.c:623
void browser_add_folder(const struct Menu *menu, struct BrowserState *state, const char *name, const char *desc, const struct stat *st, struct Mailbox *m, void *data)
Add a folder to the browser list.
Definition: dlg_browser.c:572
DIR * mutt_file_opendir(const char *path, enum MuttOpenDirMode mode)
Open a directory.
Definition: file.c:616
@ MUTT_OPENDIR_NONE
Plain opendir()
Definition: file.h:73
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_perror(...)
Definition: logging2.h:93
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:210
@ MUTT_MAILBOX_ANY
Match any Mailbox type.
Definition: mailbox.h:42
#define _(a)
Definition: message.h:28
bool mutt_regex_match(const struct Regex *regex, const char *str)
Shorthand to mutt_regex_capture()
Definition: regex.c:636
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:798
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:228
int mutt_mailbox_check(struct Mailbox *m_cur, CheckStatsFlags flags)
Check all all Mailboxes for new mail.
Definition: mutt_mailbox.c:166
#define MUTT_MAILBOX_CHECK_NO_FLAGS
No flags are set.
Definition: mxapi.h:53
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:162
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition: neomutt.c:185
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition: nntp.c:77
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
List of Mailboxes.
Definition: mailbox.h:153
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:154
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
void * mdata
Driver specific data.
Definition: mailbox.h:131
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
NNTP-specific Account data -.
Definition: adata.h:36
unsigned int groups_num
Definition: adata.h:58
void ** groups_list
Definition: adata.h:60
NNTP-specific Mailbox data -.
Definition: mdata.h:34
struct NntpAccountData * adata
Definition: mdata.h:48
Cached regular expression.
Definition: regex3.h:89
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ examine_mailboxes()

int examine_mailboxes ( struct Mailbox m,
struct Menu menu,
struct BrowserState state 
)

Get list of mailboxes/subscribed newsgroups.

Parameters
mMailbox
menuCurrent menu
stateState of browser
Return values
0Success
-1Error

Definition at line 773 of file dlg_browser.c.

774{
775 struct stat st = { 0 };
776 struct Buffer *md = NULL;
777 struct Buffer *mailbox = NULL;
778
779 if (OptNews)
780 {
782
783 init_state(state, menu);
784
785 const bool c_show_only_unread = cs_subset_bool(NeoMutt->sub, "show_only_unread");
786 for (unsigned int i = 0; i < adata->groups_num; i++)
787 {
788 struct NntpMboxData *mdata = adata->groups_list[i];
789 if (mdata && (mdata->has_new_mail ||
790 (mdata->subscribed && (mdata->unread || !c_show_only_unread))))
791 {
792 browser_add_folder(menu, state, mdata->group, NULL, NULL, NULL, mdata);
793 }
794 }
795 }
796 else
797 {
798 init_state(state, menu);
799
801 return -1;
802 mailbox = buf_pool_get();
803 md = buf_pool_get();
804
806
807 struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
809 struct MailboxNode *np = NULL;
810 const bool c_browser_abbreviate_mailboxes = cs_subset_bool(NeoMutt->sub, "browser_abbreviate_mailboxes");
811
812 STAILQ_FOREACH(np, &ml, entries)
813 {
814 if (!np->mailbox)
815 continue;
816
817 if (m && m->poll_new_mail && mutt_str_equal(np->mailbox->realpath, m->realpath))
818 {
819 np->mailbox->msg_count = m->msg_count;
820 np->mailbox->msg_unread = m->msg_unread;
821 }
822
824 if (c_browser_abbreviate_mailboxes)
826
827 switch (np->mailbox->type)
828 {
829 case MUTT_IMAP:
830 case MUTT_POP:
832 np->mailbox->name, NULL, np->mailbox, NULL);
833 continue;
834 case MUTT_NOTMUCH:
835 case MUTT_NNTP:
836 browser_add_folder(menu, state, mailbox_path(np->mailbox),
837 np->mailbox->name, NULL, np->mailbox, NULL);
838 continue;
839 default: /* Continue */
840 break;
841 }
842
843 if (lstat(mailbox_path(np->mailbox), &st) == -1)
844 continue;
845
846 if ((!S_ISREG(st.st_mode)) && (!S_ISDIR(st.st_mode)) && (!S_ISLNK(st.st_mode)))
847 continue;
848
849 if (np->mailbox->type == MUTT_MAILDIR)
850 {
851 struct stat st2 = { 0 };
852
853 buf_printf(md, "%s/new", mailbox_path(np->mailbox));
854 if (stat(buf_string(md), &st) < 0)
855 st.st_mtime = 0;
856 buf_printf(md, "%s/cur", mailbox_path(np->mailbox));
857 if (stat(buf_string(md), &st2) < 0)
858 st2.st_mtime = 0;
859 if (st2.st_mtime > st.st_mtime)
860 st.st_mtime = st2.st_mtime;
861 }
862
863 browser_add_folder(menu, state, buf_string(mailbox), np->mailbox->name,
864 &st, np->mailbox, NULL);
865 }
867 }
868 browser_sort(state);
869
870 buf_pool_release(&mailbox);
871 buf_pool_release(&md);
872 return 0;
873}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:173
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:407
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
Definition: mailbox.h:51
@ MUTT_POP
'POP3' Mailbox type
Definition: mailbox.h:52
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
Definition: mailbox.h:49
@ MUTT_IMAP
'IMAP' Mailbox type
Definition: mailbox.h:50
@ MUTT_MAILDIR
'Maildir' Mailbox type
Definition: mailbox.h:48
void buf_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
Definition: muttlib.c:556
#define TAILQ_EMPTY(head)
Definition: queue.h:721
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
char * name
A short name for the Mailbox.
Definition: mailbox.h:82
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ browser_highlight_default()

void browser_highlight_default ( struct BrowserState state,
struct Menu menu 
)

Decide which browser item should be highlighted.

Parameters
stateBrowser state
menuCurrent Menu

This function takes a menu and a state and defines the current entry that should be highlighted.

Definition at line 933 of file dlg_browser.c.

934{
935 menu->top = 0;
936 /* Reset menu position to 1.
937 * We do not risk overflow as the init_menu function changes
938 * current if it is bigger than state->entrylen. */
939 if (!ARRAY_EMPTY(&state->entry) &&
940 (mutt_str_equal(ARRAY_FIRST(&state->entry)->desc, "..") ||
941 mutt_str_equal(ARRAY_FIRST(&state->entry)->desc, "../")))
942 {
943 /* Skip the first entry, unless there's only one entry. */
944 menu_set_index(menu, (menu->max > 1));
945 }
946 else
947 {
948 menu_set_index(menu, 0);
949 }
950}
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition: array.h:134
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:73
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:170
int top
Entry that is the top of the current page.
Definition: lib.h:81
int max
Number of entries in the menu.
Definition: lib.h:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_menu()

void init_menu ( struct BrowserState state,
struct Menu menu,
struct Mailbox m,
struct MuttWindow sbar 
)

Set up a new menu.

Parameters
stateBrowser state
menuCurrent menu
mMailbox
sbarStatus bar

Definition at line 959 of file dlg_browser.c.

961{
962 char title[256] = { 0 };
963 menu->max = ARRAY_SIZE(&state->entry);
964
965 int index = menu_get_index(menu);
966 if (index >= menu->max)
967 menu_set_index(menu, menu->max - 1);
968 if (index < 0)
969 menu_set_index(menu, 0);
970 if (menu->top > index)
971 menu->top = 0;
972
973 menu->num_tagged = 0;
974
975 if (OptNews)
976 {
977 if (state->is_mailbox_list)
978 {
979 snprintf(title, sizeof(title), _("Subscribed newsgroups"));
980 }
981 else
982 {
983 snprintf(title, sizeof(title), _("Newsgroups on server [%s]"),
985 }
986 }
987 else
988 {
989 if (state->is_mailbox_list)
990 {
991 snprintf(title, sizeof(title), _("Mailboxes [%d]"),
993 }
994 else
995 {
996 struct Buffer *path = buf_pool_get();
997 buf_copy(path, &LastDir);
998 buf_pretty_mailbox(path);
999 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
1000 const bool c_imap_list_subscribed = cs_subset_bool(NeoMutt->sub, "imap_list_subscribed");
1001 if (state->imap_browse && c_imap_list_subscribed)
1002 {
1003 snprintf(title, sizeof(title), _("Subscribed [%s], File mask: %s"),
1004 buf_string(path), NONULL(c_mask ? c_mask->pattern : NULL));
1005 }
1006 else
1007 {
1008 snprintf(title, sizeof(title), _("Directory [%s], File mask: %s"),
1009 buf_string(path), NONULL(c_mask ? c_mask->pattern : NULL));
1010 }
1011 buf_pool_release(&path);
1012 }
1013 }
1014 sbar_set_title(sbar, title);
1015
1016 /* Browser tracking feature.
1017 * The goal is to highlight the good directory if LastDir is the parent dir
1018 * of LastDirBackup (this occurs mostly when one hit "../"). It should also work
1019 * properly when the user is in examine_mailboxes-mode. */
1021 {
1022 char target_dir[PATH_MAX] = { 0 };
1023
1024 /* Check what kind of dir LastDirBackup is. */
1026 {
1027 mutt_str_copy(target_dir, buf_string(&LastDirBackup), sizeof(target_dir));
1028 imap_clean_path(target_dir, sizeof(target_dir));
1029 }
1030 else
1031 {
1032 mutt_str_copy(target_dir, strrchr(buf_string(&LastDirBackup), '/') + 1,
1033 sizeof(target_dir));
1034 }
1035
1036 /* If we get here, it means that LastDir is the parent directory of
1037 * LastDirBackup. I.e., we're returning from a subdirectory, and we want
1038 * to position the cursor on the directory we're returning from. */
1039 bool matched = false;
1040 struct FolderFile *ff = NULL;
1041 ARRAY_FOREACH(ff, &state->entry)
1042 {
1043 if (mutt_str_equal(ff->name, target_dir))
1044 {
1045 menu_set_index(menu, ARRAY_FOREACH_IDX);
1046 matched = true;
1047 break;
1048 }
1049 }
1050 if (!matched)
1051 browser_highlight_default(state, menu);
1052 }
1053 else
1054 {
1055 browser_highlight_default(state, menu);
1056 }
1057
1059}
#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
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition: buffer.c:572
void browser_highlight_default(struct BrowserState *state, struct Menu *menu)
Decide which browser item should be highlighted.
Definition: dlg_browser.c:933
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox? - Implements MxOps::path_probe() -.
Definition: imap.c:2327
void imap_clean_path(char *path, size_t plen)
Cleans an IMAP path using imap_fix_path.
Definition: util.c:187
#define MENU_REDRAW_FULL
Redraw everything.
Definition: lib.h:60
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:180
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:156
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:653
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:227
#define NONULL(x)
Definition: string2.h:37
char host[128]
Server to login to.
Definition: connaccount.h:54
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:50
int num_tagged
Number of tagged entries.
Definition: lib.h:84
struct Connection * conn
Connection to NNTP Server.
Definition: adata.h:62
char * pattern
printable version
Definition: regex3.h:90
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_browser_select_dir()

void mutt_browser_select_dir ( const char *  f)

Remember the last directory selected.

Parameters
fDirectory name to save

This function helps the browser to know which directory has been selected. It should be called anywhere a confirm hit is done to open a new directory/file which is a maildir/mbox.

We could check if the sort method is appropriate with this feature.

Definition at line 1203 of file dlg_browser.c.

1204{
1205 init_lastdir();
1206
1208
1209 /* Method that will fetch the parent path depending on the type of the path. */
1210 char buf[PATH_MAX] = { 0 };
1211 mutt_get_parent_path(buf_string(&LastDirBackup), buf, sizeof(buf));
1212 buf_strcpy(&LastDir, buf);
1213}
static void init_lastdir(void)
Initialise the browser directories.
Definition: dlg_browser.c:139
void mutt_get_parent_path(const char *path, char *buf, size_t buflen)
Find the parent of a path (or mailbox)
Definition: muttlib.c:1511
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ FolderHelp

const struct Mapping FolderHelp[]
static
Initial value:
= {
{ N_("Exit"), OP_EXIT },
{ N_("Chdir"), OP_CHANGE_DIRECTORY },
{ N_("Goto"), OP_BROWSER_GOTO_FOLDER },
{ N_("Mask"), OP_ENTER_MASK },
{ N_("Help"), OP_HELP },
{ NULL, 0 },
}
#define N_(a)
Definition: message.h:32

Help Bar for the File/Dir/Mailbox browser dialog.

Definition at line 104 of file dlg_browser.c.

◆ FolderNewsHelp

const struct Mapping FolderNewsHelp[]
static
Initial value:
= {
{ N_("Exit"), OP_EXIT },
{ N_("List"), OP_TOGGLE_MAILBOXES },
{ N_("Subscribe"), OP_BROWSER_SUBSCRIBE },
{ N_("Unsubscribe"), OP_BROWSER_UNSUBSCRIBE },
{ N_("Catchup"), OP_CATCHUP },
{ N_("Mask"), OP_ENTER_MASK },
{ N_("Help"), OP_HELP },
{ NULL, 0 },
}

Help Bar for the NNTP Mailbox browser dialog.

Definition at line 116 of file dlg_browser.c.

◆ LastDir

struct Buffer LastDir = { 0 }

Browser: previous selected directory.

Definition at line 130 of file dlg_browser.c.

◆ LastDirBackup

struct Buffer LastDirBackup = { 0 }

Browser: backup copy of the current directory.

Definition at line 132 of file dlg_browser.c.