]> granicus.if.org Git - neomutt/commitdiff
feature: refresh
authorDavid Sterba <dsterba@suse.cz>
Fri, 27 Nov 2015 21:56:00 +0000 (21:56 +0000)
committerRichard Russon <rich@flatcap.org>
Mon, 4 Apr 2016 02:37:42 +0000 (03:37 +0100)
Add new config: "sidebar_refresh"
Configure the minimum time between sidebar refreshes to reduce
network traffic.

buffy.c
globals.h
init.h
sidebar.c
sidebar.h

diff --git a/buffy.c b/buffy.c
index d34e6f5cbd9b73a1ed7dcc44496ee03229b6218c..cb4d80962e02b04b98932070985fc7c20a0c66ad 100644 (file)
--- 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++;
index 28f95198839b735feee6a44e1d9f178bc23a55ab..6bbb28c5b447f01b7c61c25591ad3ab2026988b8 100644 (file)
--- 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 d46cde2980b7c52bf072c7d04ae3beef47b3bdf5..cfc67add94fa78b497483bf833c11b9ca072ad5b 100644 (file)
--- 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
index a56dded65a2ae80f4c006326c94d8eff44ea91df..e62b9460efd32d6e6911a0caa4e9112640902666 100644 (file)
--- 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);
+}
index 8c2b441edc8366ad37ad76ca8558b913d6bf7e4a..7371a14ea9b5f50a7d776c63d8731d6c7104332a 100644 (file)
--- 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 */