From: David Sterba Date: Fri, 27 Nov 2015 21:56:00 +0000 (+0000) Subject: feature: refresh X-Git-Tag: neomutt-20160404~14^2~34 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=063033c9e5290bef80e6221ddc5f0827b67574d7;p=neomutt feature: refresh Add new config: "sidebar_refresh" Configure the minimum time between sidebar refreshes to reduce network traffic. --- diff --git a/buffy.c b/buffy.c index d34e6f5cb..cb4d80962 100644 --- a/buffy.c +++ b/buffy.c @@ -26,6 +26,7 @@ #include "mx.h" #include "mutt_curses.h" +#include "sidebar.h" #ifdef USE_IMAP #include "imap.h" @@ -602,19 +603,28 @@ int mutt_buffy_check (int force) { case M_MBOX: case M_MMDF: - buffy_mbox_update (tmp, &sb); + if (sidebar_should_refresh()) { + buffy_mbox_update (tmp, &sb); + sidebar_updated(); + } if (buffy_mbox_hasnew (tmp, &sb) > 0) BuffyCount++; break; case M_MAILDIR: - buffy_maildir_update (tmp); + if (sidebar_should_refresh()) { + buffy_maildir_update (tmp); + sidebar_updated(); + } if (buffy_maildir_hasnew (tmp) > 0) BuffyCount++; break; case M_MH: - mh_buffy_update (tmp->path, &tmp->msgcount, &tmp->msg_unread, &tmp->msg_flagged, &tmp->sb_last_checked); + if (sidebar_should_refresh()) { + mh_buffy_update (tmp->path, &tmp->msgcount, &tmp->msg_unread, &tmp->msg_flagged, &tmp->sb_last_checked); + sidebar_updated(); + } mh_buffy(tmp); if (tmp->new) BuffyCount++; diff --git a/globals.h b/globals.h index 28f951988..6bbb28c5b 100644 --- a/globals.h +++ b/globals.h @@ -220,6 +220,8 @@ WHERE short ScoreThresholdFlag; WHERE struct buffy_t *CurBuffy INITVAL(0); WHERE short DrawFullLine INITVAL(0); +WHERE short SidebarLastRefresh; +WHERE short SidebarRefresh; WHERE LIST *SidebarWhitelist INITVAL(0); WHERE short SidebarWidth; diff --git a/init.h b/init.h index d46cde298..cfc67add9 100644 --- a/init.h +++ b/init.h @@ -2712,6 +2712,12 @@ struct option_t MuttVars[] = { ** Setting sidebar_next_new_wrap=yes causes mutt to wrap around the list ** of mailboxes when using Next/Previous New Mailbox commands. */ + { "sidebar_refresh", DT_NUM, R_BOTH, UL &SidebarRefresh, 60 }, + /* + ** .pp + ** Do not refresh sidebar in less than $sidebar_refresh seconds, + ** (0 disables refreshing). + */ { "sidebar_shortpath", DT_BOOL, R_BOTH, OPTSIDEBARSHORTPATH, 0 }, /* ** .pp diff --git a/sidebar.c b/sidebar.c index a56dded65..e62b9460e 100644 --- a/sidebar.c +++ b/sidebar.c @@ -245,6 +245,7 @@ int draw_sidebar(int menu) { prev_show_value = option(OPTSIDEBAR); saveSidebarWidth = SidebarWidth; if(!option(OPTSIDEBAR)) SidebarWidth = 0; + SidebarLastRefresh = time(NULL); initialized = true; } @@ -428,6 +429,15 @@ int draw_sidebar(int menu) { return 0; } +int sidebar_should_refresh() +{ + if (option(OPTSIDEBAR) && SidebarRefresh > 0) { + if (time(NULL) - SidebarLastRefresh >= SidebarRefresh) + return 1; + } + return 0; +} + void scroll_sidebar(int op, int menu) { BUFFY *tmp; @@ -513,3 +523,7 @@ void set_curbuffy(char buf[LONG_STRING]) } } +void sidebar_updated() +{ + SidebarLastRefresh = time(NULL); +} diff --git a/sidebar.h b/sidebar.h index 8c2b441ed..7371a14ea 100644 --- a/sidebar.h +++ b/sidebar.h @@ -31,6 +31,7 @@ struct MBOX_LIST { int draw_sidebar(int); void scroll_sidebar(int, int); void set_buffystats(CONTEXT*); -void set_curbuffy(char*); +int sidebar_should_refresh(); +void sidebar_updated(); #endif /* SIDEBAR_H */