From: Karel Zak Date: Wed, 14 Dec 2011 15:43:07 +0000 (+0100) Subject: add support to browser X-Git-Tag: neomutt-20160404~13^2~100 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cca796da8e8e1cb365390b1a17624db2e8216803;p=neomutt add support to browser Signed-off-by: Karel Zak --- diff --git a/browser.c b/browser.c index 3d21ab19b..12e6cf983 100644 --- a/browser.c +++ b/browser.c @@ -33,6 +33,9 @@ #ifdef USE_IMAP #include "imap.h" #endif +#ifdef USE_NOTMUCH +#include "mutt_notmuch.h" +#endif #include #include @@ -232,6 +235,12 @@ folder_format_str (char *dest, size_t destlen, size_t col, char op, const char * case 'f': { char *s; + +#ifdef USE_NOTMUCH + if (mx_is_notmuch(folder->ff->name)) + s = NONULL (folder->ff->desc); + else +#endif #ifdef USE_IMAP if (folder->ff->imap) s = NONULL (folder->ff->desc); @@ -323,6 +332,14 @@ folder_format_str (char *dest, size_t destlen, size_t col, char op, const char * optional = 0; break; } +#endif +#ifdef USE_NOTMUCH + if (mx_is_notmuch (folder->ff->name)) + { + snprintf (tmp, sizeof (tmp), "%%%sd", fmt); + snprintf (dest, destlen, tmp, folder->ff->new); + break; + } #endif snprintf (tmp, sizeof (tmp), "%%%sc", fmt); snprintf (dest, destlen, tmp, folder->ff->new ? 'N' : ' '); @@ -490,6 +507,33 @@ static int examine_directory (MUTTMENU *menu, struct browser_state *state, return 0; } +#ifdef USE_NOTMUCH +static int examine_vfolders (MUTTMENU *menu, struct browser_state *state) +{ + BUFFY *tmp = VirtIncoming; + + if (!VirtIncoming) + return (-1); + mutt_buffy_check (0); + + init_state (state, menu); + + do + { + if (mx_is_notmuch (tmp->path)) + { + unsigned new = 0, all = 0; + nm_get_count(tmp->path, &all, &new); + add_folder (menu, state, tmp->path, tmp->desc, NULL, new, all); + continue; + } + } + while ((tmp = tmp->next)); + browser_sort (state); + return 0; +} +#endif + static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state) { struct stat s; @@ -570,6 +614,19 @@ static void folder_entry (char *s, size_t slen, MUTTMENU *menu, int num) (unsigned long) &folder, M_FORMAT_ARROWCURSOR); } +#ifdef USE_NOTMUCH +static void vfolder_entry (char *s, size_t slen, MUTTMENU *menu, int num) +{ + FOLDER folder; + + folder.ff = &((struct folder_file *) menu->data)[num]; + folder.num = num; + + mutt_FormatString (s, slen, 0, NONULL(VirtFolderFormat), folder_format_str, + (unsigned long) &folder, M_FORMAT_ARROWCURSOR); +} +#endif + static void init_menu (struct browser_state *state, MUTTMENU *menu, char *title, size_t titlelen, int buffy) { @@ -635,7 +692,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num int buffy = (flags & M_SEL_BUFFY) ? 1 : 0; buffy = buffy && folder; - + memset (&state, 0, sizeof (struct browser_state)); if (!folder) @@ -688,13 +745,17 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num } #endif } - else +#ifdef USE_NOTMUCH + else if (!(flags & M_SEL_VFOLDER)) +#else + else +#endif { if (!folder) getcwd (LastDir, sizeof (LastDir)); else if (!LastDir[0]) strfcpy (LastDir, NONULL(Maildir), sizeof (LastDir)); - + #ifdef USE_IMAP if (!buffy && mx_is_imap (LastDir)) { @@ -716,6 +777,12 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num *f = 0; +#ifdef USE_NOTMUCH + if (flags & M_SEL_VFOLDER) { + if (examine_vfolders (NULL, &state) == -1) + goto bail; + } else +#endif if (buffy) { if (examine_mailboxes (NULL, &state) == -1) @@ -725,11 +792,18 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num #ifdef USE_IMAP if (!state.imap_browse) #endif + { if (examine_directory (NULL, &state, LastDir, prefix) == -1) goto bail; - + } menu = mutt_new_menu (MENU_FOLDER); - menu->make_entry = folder_entry; +#ifdef USE_NOTMUCH + if (flags & M_SEL_VFOLDER) + menu->make_entry = vfolder_entry; + else +#endif + menu->make_entry = folder_entry; + menu->search = select_file_search; menu->title = title; menu->data = state.entry; @@ -883,6 +957,10 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num #ifdef USE_IMAP else if (state.imap_browse) strfcpy (f, state.entry[menu->current].name, flen); +#endif +#ifdef USE_NOTMUCH + else if (mx_is_notmuch(state.entry[menu->current].name)) + strfcpy (f, state.entry[menu->current].name, flen); #endif else mutt_concat_path (f, LastDir, state.entry[menu->current].name, flen); @@ -1038,7 +1116,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num } break; #endif - + case OP_CHANGE_DIRECTORY: strfcpy (buf, LastDir, sizeof (buf)); diff --git a/mutt.h b/mutt.h index 7a49a047b..953b6210c 100644 --- a/mutt.h +++ b/mutt.h @@ -321,6 +321,7 @@ enum #define M_SEL_BUFFY (1<<0) #define M_SEL_MULTI (1<<1) #define M_SEL_FOLDER (1<<2) +#define M_SEL_VFOLDER (1<<3) /* flags for parse_spam_list */ #define M_SPAM 1