From: Karel Zak Date: Wed, 14 Mar 2012 14:19:43 +0000 (+0100) Subject: add support for virtual folders, add sidebar-toggle command X-Git-Tag: neomutt-20160404~13^2~80 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=438217ab53e22fd4995412234e0f3ac6701fb302;p=neomutt add support for virtual folders, add sidebar-toggle command * add support for virtual folders * add sidebar-toggle function to toggle between virtual and normal folders in sudebar * virtual folders are used by default if 'virtual_spoolfile' is 'yes' Signed-off-by: Karel Zak --- diff --git a/OPS.SIDEBAR b/OPS.SIDEBAR index d09ec1f1d..9bcc31929 100644 --- a/OPS.SIDEBAR +++ b/OPS.SIDEBAR @@ -5,4 +5,5 @@ OP_SIDEBAR_PAGE_DOWN "Scroll the Sidebar down 1 page" OP_SIDEBAR_PAGE_UP "Scroll the Sidebar up 1 page" OP_SIDEBAR_PREV "Move the highlight to previous mailbox" OP_SIDEBAR_PREV_NEW "Move the highlight to previous mailbox with new mail" +OP_SIDEBAR_TOGGLE "toggle between mailboxes and virtual mailboxes" OP_SIDEBAR_TOGGLE_VISIBLE "Make the Sidebar (in)visible" diff --git a/browser.c b/browser.c index 12e6cf983..11f1bc9c9 100644 --- a/browser.c +++ b/browser.c @@ -522,9 +522,9 @@ static int examine_vfolders (MUTTMENU *menu, struct browser_state *state) { 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); + nm_get_count(tmp->path, &tmp->msg_count, &tmp->msg_unread); + add_folder (menu, state, tmp->path, tmp->desc, NULL, + tmp->msg_unread, tmp->msg_count); continue; } } diff --git a/buffy.c b/buffy.c index 03a20fc6d..f2d33eb61 100644 --- a/buffy.c +++ b/buffy.c @@ -35,6 +35,10 @@ #include "imap.h" #endif +#ifdef USE_NOTMUCH +#include "mutt_notmuch.h" +#endif + #include #include #include @@ -590,51 +594,13 @@ buffy_mbox_update (BUFFY *mailbox, struct stat *sb) } #endif -int mutt_buffy_check (int force) -{ - BUFFY *tmp; - struct stat sb; - struct stat contex_sb; - time_t t; - - sb.st_size=0; - contex_sb.st_dev=0; - contex_sb.st_ino=0; -#ifdef USE_IMAP - /* update postponed count as well, on force */ - if (force) - mutt_update_num_postponed (); -#endif - - /* fastest return if there are no mailboxes */ - if (!Incoming) - return 0; - t = time (NULL); - if (!force && (t - BuffyTime < BuffyTimeout)) - return BuffyCount; - - BuffyTime = t; - BuffyCount = 0; - BuffyNotify = 0; +static void buffy_check(BUFFY *tmp, struct stat *contex_sb) +{ + struct stat sb; -#ifdef USE_IMAP - BuffyCount += imap_buffy_check (force); -#endif + sb.st_size=0; - /* check device ID and serial number instead of comparing paths */ - if (!Context || Context->magic == M_IMAP || Context->magic == M_POP - || stat (Context->path, &contex_sb) != 0) - { - contex_sb.st_dev=0; - contex_sb.st_ino=0; - } - -#ifdef USE_SIDEBAR - int should_refresh = sb_should_refresh(); -#endif - for (tmp = Incoming; tmp; tmp = tmp->next) - { if (tmp->magic != M_IMAP) { tmp->new = 0; @@ -642,6 +608,11 @@ int mutt_buffy_check (int force) if (mx_is_pop (tmp->path)) tmp->magic = M_POP; else +#endif +#ifdef USE_NOTMUCH + if (mx_is_notmuch (tmp->path)) + tmp->magic = M_NOTMUCH; + else #endif if (stat (tmp->path, &sb) != 0 || (S_ISREG(sb.st_mode) && sb.st_size == 0) || (!tmp->magic && (tmp->magic = mx_get_magic (tmp->path)) <= 0)) @@ -651,23 +622,23 @@ int mutt_buffy_check (int force) tmp->newly_created = 1; tmp->magic = 0; tmp->size = 0; - continue; + return; } } /* check to see if the folder is the currently selected folder * before polling */ if (!Context || !Context->path || - (( tmp->magic == M_IMAP || tmp->magic == M_POP ) + (( tmp->magic == M_IMAP || tmp->magic == M_POP || tmp->magic == M_NOTMUCH) ? mutt_strcmp (tmp->path, Context->path) : - (sb.st_dev != contex_sb.st_dev || sb.st_ino != contex_sb.st_ino))) + (sb.st_dev != contex_sb->st_dev || sb.st_ino != contex_sb->st_ino))) { switch (tmp->magic) { case M_MBOX: case M_MMDF: #ifdef USE_SIDEBAR - if (should_refresh) + if (option(OPTSIDEBAR)) buffy_mbox_update (tmp, &sb); #endif if (buffy_mbox_hasnew (tmp, &sb) > 0) @@ -676,7 +647,7 @@ int mutt_buffy_check (int force) case M_MAILDIR: #ifdef USE_SIDEBAR - if (should_refresh) + if (option(OPTSIDEBAR)) buffy_maildir_update (tmp); #endif if (buffy_maildir_hasnew (tmp) > 0) @@ -685,15 +656,23 @@ int mutt_buffy_check (int force) case M_MH: #ifdef USE_SIDEBAR - if (sb_should_refresh()) { + if (option(OPTSIDEBAR)) mh_buffy_update (tmp); - sb_set_update_time(); - } #endif mh_buffy(tmp); if (tmp->new) BuffyCount++; break; +#ifdef USE_NOTMUCH + case M_NOTMUCH: + tmp->msg_count = 0; + tmp->msg_unread = 0; + tmp->msg_flagged = 0; + nm_get_count(tmp->path, &tmp->msg_count, &tmp->msg_unread); + if (tmp->msg_unread > 0) + BuffyCount++; + break; +#endif } } else if (option(OPTCHECKMBOXSIZE) && Context && Context->path) @@ -703,12 +682,60 @@ int mutt_buffy_check (int force) tmp->notified = 0; else if (!tmp->notified) BuffyNotify++; +} + +int mutt_buffy_check (int force) +{ + BUFFY *tmp; + struct stat contex_sb; + time_t t; + + contex_sb.st_dev=0; + contex_sb.st_ino=0; + +#ifdef USE_IMAP + /* update postponed count as well, on force */ + if (force) + mutt_update_num_postponed (); +#endif + + /* fastest return if there are no mailboxes */ + if (!Incoming && !VirtIncoming) + return 0; + t = time (NULL); + if (!force && (t - BuffyTime < BuffyTimeout)) + return BuffyCount; + + BuffyTime = t; + BuffyCount = 0; + BuffyNotify = 0; + +#ifdef USE_IMAP + BuffyCount += imap_buffy_check (force); +#endif + + /* check device ID and serial number instead of comparing paths */ + if (!Context || Context->magic == M_IMAP || Context->magic == M_POP + || stat (Context->path, &contex_sb) != 0) + { + contex_sb.st_dev=0; + contex_sb.st_ino=0; } + #ifdef USE_SIDEBAR - if (should_refresh) - sb_set_update_time(); + if (sb_should_refresh()) { + for (tmp = Incoming; tmp; tmp = tmp->next) + buffy_check(tmp, &contex_sb); + sb_set_update_time(); + } +#else + for (tmp = Incoming; tmp; tmp = tmp->next) + buffy_check(tmp, &contex_sb); #endif + for (tmp = VirtIncoming; tmp; tmp = tmp->next) + buffy_check(tmp, &contex_sb); + BuffyDoneTime = BuffyTime; return (BuffyCount); } diff --git a/curs_main.c b/curs_main.c index d0db61f25..0af13b54d 100644 --- a/curs_main.c +++ b/curs_main.c @@ -600,7 +600,7 @@ static int main_change_folder(MUTTMENU *menu, int op, char *buf, size_t bufsz, mutt_expand_path (buf, bufsz); #ifdef USE_SIDEBAR if (sb_set_open_buffy (buf) == NULL) - break; + return -1; #endif if (mx_get_magic (buf) <= 0) { @@ -2606,6 +2606,10 @@ int mutt_index_menu (void) toggle_option (OPTSIDEBAR); menu->redraw = REDRAW_FULL; break; + + case OP_SIDEBAR_TOGGLE: + toggle_sidebar(menu->menu); + break; #endif default: if (menu->menu == MENU_MAIN) diff --git a/functions.h b/functions.h index ef64deb5c..8f4f90145 100644 --- a/functions.h +++ b/functions.h @@ -177,6 +177,7 @@ const struct binding_t OpMain[] = { /* map: index */ { "sidebar-page-up", OP_SIDEBAR_PAGE_UP, NULL }, { "sidebar-prev", OP_SIDEBAR_PREV, NULL }, { "sidebar-prev-new", OP_SIDEBAR_PREV_NEW, NULL }, + { "sidebar-toggle", OP_SIDEBAR_TOGGLE, NULL }, { "sidebar-toggle-visible", OP_SIDEBAR_TOGGLE_VISIBLE, NULL }, #endif @@ -298,6 +299,7 @@ const struct binding_t OpPager[] = { /* map: pager */ { "sidebar-page-up", OP_SIDEBAR_PAGE_UP, NULL }, { "sidebar-prev", OP_SIDEBAR_PREV, NULL }, { "sidebar-prev-new", OP_SIDEBAR_PREV_NEW, NULL }, + { "sidebar-toggle", OP_SIDEBAR_TOGGLE, NULL }, { "sidebar-toggle-visible", OP_SIDEBAR_TOGGLE_VISIBLE, NULL }, #endif diff --git a/mutt_notmuch.c b/mutt_notmuch.c index e77f54704..96cc48eb8 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -837,7 +837,7 @@ static unsigned count_query(notmuch_database_t *db, const char *qstr) return res; } -int nm_get_count(char *path, unsigned *all, unsigned *new) +int nm_get_count(char *path, int *all, int *new) { struct uri_tag *query_items = NULL, *item; char *db_filename = NULL, *db_query = NULL; diff --git a/mutt_notmuch.h b/mutt_notmuch.h index 82e8fdad6..b52d4bf51 100644 --- a/mutt_notmuch.h +++ b/mutt_notmuch.h @@ -11,7 +11,7 @@ char *nm_header_get_folder(HEADER *h); int nm_header_get_magic(HEADER *h); char *nm_header_get_fullpath(HEADER *h, char *buf, size_t bufsz); char *nm_header_get_tags(HEADER *h); -int nm_get_count(char *path, unsigned *all, unsigned *new); +int nm_get_count(char *path, int *all, int *new); int nm_update_filename(CONTEXT *ctx, const char *old, const char *new); char *nm_uri_from_query(CONTEXT *ctx, char *buf, size_t bufsz); int nm_modify_message_tags(CONTEXT *ctx, HEADER *hdr, char *tags); diff --git a/sidebar.c b/sidebar.c index 5a9cfcbf9..ce4debe14 100644 --- a/sidebar.c +++ b/sidebar.c @@ -26,6 +26,7 @@ #include "keymap.h" #include "mutt_curses.h" #include "mutt_menu.h" +#include "mx.h" #include "sort.h" /* Previous values for some sidebar config */ @@ -51,6 +52,36 @@ struct sidebar_entry { BUFFY *buffy; }; +enum { + SB_SRC_NONE = 0, + SB_SRC_VIRT, + SB_SRC_INCOMING +}; +static int sidebar_source = SB_SRC_NONE; + +static BUFFY * +get_incoming (void) +{ + switch (sidebar_source) { + case SB_SRC_NONE: + sidebar_source = SB_SRC_INCOMING; + + if (option (OPTVIRTSPOOLFILE) && VirtIncoming) { + sidebar_source = SB_SRC_VIRT; + return VirtIncoming; + } + break; + case SB_SRC_VIRT: + if (VirtIncoming) { + return VirtIncoming; + } + break; + case SB_SRC_INCOMING: + break; + } + + return Incoming; /* default */ +} /** * find_next_new - Find the next folder that contains new mail @@ -73,7 +104,7 @@ find_next_new (int wrap) do { b = b->next; if (!b && wrap) { - b = Incoming; + b = get_incoming(); } if (!b || (b == HilBuffy)) { break; @@ -472,7 +503,7 @@ sort_buffy_array (BUFFY **arr, int arr_len) static int prepare_sidebar (int page_size) { - BUFFY *b = Incoming; + BUFFY *b = get_incoming(); if (!b) return 0; @@ -488,14 +519,15 @@ prepare_sidebar (int page_size) return 0; int i = 0; - for (b = Incoming; b; b = b->next, i++) { + for (b = get_incoming(); b; b = b->next, i++) { arr[i] = b; } update_buffy_visibility (arr, count); sort_buffy_array (arr, count); - Incoming = arr[0]; + if (sidebar_source == SB_SRC_INCOMING) + Incoming = arr[0]; int top_index = 0; int opn_index = -1; @@ -778,6 +810,10 @@ draw_sidebar (int first_row, int num_rows, int div_width) strncat (sidebar_folder_name, tmp_folder_name, strlen (tmp_folder_name)); } } +#ifdef USE_NOTMUCH + else if (b->magic == M_NOTMUCH) + sidebar_folder_name = b->desc; +#endif char str[SHORT_STRING]; make_sidebar_entry (str, sizeof (str), w, sidebar_folder_name, b); printw ("%s", str); @@ -836,7 +872,7 @@ sb_draw (void) if (div_width < 0) return; - if (!Incoming) { + if (!get_incoming()) { int w = MIN(COLS, (SidebarWidth - div_width)); fill_empty_space (first_row, num_rows, w); return; @@ -921,7 +957,7 @@ sb_change_mailbox (int op) break; case OP_SIDEBAR_PAGE_UP: HilBuffy = TopBuffy; - if (HilBuffy != Incoming) { + if (HilBuffy != get_incoming()) { HilBuffy = HilBuffy->prev; } break; @@ -958,7 +994,7 @@ sb_set_buffystats (const CONTEXT *ctx) { /* Even if the sidebar's hidden, * we should take note of the new data. */ - BUFFY *b = Incoming; + BUFFY *b = get_incoming(); if (!ctx || !b) return; @@ -1005,7 +1041,7 @@ sb_set_open_buffy (const char *path) { /* Even if the sidebar is hidden */ - BUFFY *b = Incoming; + BUFFY *b = get_incoming(); if (!path || !b) return NULL; @@ -1078,3 +1114,26 @@ sb_notify_mailbox (BUFFY *b, int created) Outgoing = buffy_going (Outgoing); } } + +/* switch between regualar and virtual folders */ +void toggle_sidebar(int menu) +{ + if (sidebar_source == -1) + get_incoming(); + +#ifdef USE_NOTMUCH + if (sidebar_source == SB_SRC_INCOMING && VirtIncoming) + sidebar_source = SB_SRC_VIRT; + else +#endif + sidebar_source = SB_SRC_INCOMING; + + TopBuffy = NULL; + OpnBuffy = NULL; + HilBuffy = NULL; + BotBuffy = NULL; + Outgoing = NULL; + + sb_draw(); +} + diff --git a/sidebar.h b/sidebar.h index b203464f1..b61f90322 100644 --- a/sidebar.h +++ b/sidebar.h @@ -32,5 +32,6 @@ void sb_set_buffystats (const CONTEXT *ctx); BUFFY * sb_set_open_buffy (const char *path); void sb_set_update_time (void); int sb_should_refresh (void); +void toggle_sidebar(int menu); #endif /* SIDEBAR_H */