[PATCH] sidebar: add optional refresh interval

David Sterba dsterba at suse.cz
Tue May 15 17:38:33 UTC 2012


New option sidebar_refresh: do not refresh sidebar in less
than $sidebar_refresh seconds (0 disables refreshing).

This helps when there are 'mbox' mailboxes and scanning for new
mails blocks UI and consumes CPU, although it might not be desired
to refresh. This de-syncs message counts listed in sidebar, can be
updated by entering the mailbox.

Signed-off-by: David Sterba <dsterba at suse.cz>
---

I'm concerned about CPU consumption mainly because I read mail on
a shared host and I usually know what mboxes I want to read and do
not want to wait when toggling sidebar to easily pick mbox.


 buffy.c   |   13 ++++++++++---
 globals.h |    2 ++
 init.h    |    6 ++++++
 sidebar.c |   15 +++++++++++++++
 sidebar.h |    2 ++
 5 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/buffy.c b/buffy.c
index 989ea10..fc8efa6 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"
@@ -543,22 +544,28 @@ static void buffy_check(BUFFY *tmp, struct stat *contex_sb)
       {
       case M_MBOX:
       case M_MMDF:
-	if (option(OPTSIDEBAR))
+	if (sidebar_should_refresh()) {
 	  buffy_mbox_update (tmp);
+	  sidebar_updated();
+	}
 	if (buffy_mbox_hasnew (tmp, &sb) > 0)
 	  BuffyCount++;
 	break;
 
       case M_MAILDIR:
-	if (option(OPTSIDEBAR))
+	if (sidebar_should_refresh()) {
 	  buffy_maildir_update (tmp);
+	  sidebar_updated();
+	}
 	if (buffy_maildir_hasnew (tmp) > 0)
 	  BuffyCount++;
 	break;
 
       case M_MH:
-	if (option(OPTSIDEBAR))
+	if (sidebar_should_refresh()) {
 	  mh_buffy_update (tmp->path, &tmp->msgcount, &tmp->msg_unread, &tmp->msg_flagged);
+	  sidebar_updated();
+	}
 	if ((tmp->new = mh_buffy (tmp->path)) > 0)
 	  BuffyCount++;
 	break;
diff --git a/globals.h b/globals.h
--- a/globals.h
+++ b/globals.h
@@ -212,6 +212,8 @@ WHERE short ScoreThresholdFlag;
 WHERE struct buffy_t *CurBuffy INITVAL(0);
 WHERE short DrawFullLine INITVAL(0);
 WHERE short SidebarWidth;
+WHERE short SidebarRefresh;
+WHERE short SidebarLastRefresh;
 #ifdef USE_IMAP
 WHERE short ImapKeepalive;
 WHERE short ImapPipelineDepth;
diff --git a/init.h b/init.h
--- a/init.h
+++ b/init.h
@@ -1995,6 +1995,12 @@ struct option_t MuttVars[] = {
   { "sidebar_width", DT_NUM, R_BOTH, UL &SidebarWidth, 0 },
   /*
   ** .pp
+  ** Do not refresh sidebar in less than $sidebar_refresh seconds,
+  ** (0 disables refreshing).
+  */
+  { "sidebar_refresh", DT_NUM, R_BOTH, UL &SidebarRefresh, 60 },
+  /*
+  ** .pp
   ** The width of the sidebar.
   */
   { "pgp_use_gpg_agent", DT_BOOL, R_NONE, OPTUSEGPGAGENT, 0},
diff --git a/sidebar.c b/sidebar.c
--- a/sidebar.c
+++ b/sidebar.c
@@ -199,6 +199,7 @@ int draw_sidebar(int menu) {
                 saveSidebarWidth = SidebarWidth;
                 if(!option(OPTSIDEBAR)) SidebarWidth = 0;
                 initialized = true;
+		SidebarLastRefresh = time(NULL);
         }
 
         /* save or restore the value SidebarWidth */
@@ -434,3 +435,16 @@ void toggle_sidebar(int menu)
 	set_curbuffy("");	/* default is the first mailbox */
 	draw_sidebar(menu);
 }
+
+int sidebar_should_refresh()
+{
+	if (option(OPTSIDEBAR) && SidebarRefresh > 0) {
+		if (time(NULL) - SidebarLastRefresh >= SidebarRefresh)
+			return 1;
+	}
+	return 0;
+}
+void sidebar_updated()
+{
+	SidebarLastRefresh = time(NULL);
+}
diff --git a/sidebar.h b/sidebar.h
index 066b33b..94e08be 100644
--- a/sidebar.h
+++ b/sidebar.h
@@ -33,5 +33,7 @@ void scroll_sidebar(int, int);
 void set_curbuffy(char*);
 void set_buffystats(CONTEXT*);
 void toggle_sidebar(int menu);
+int sidebar_should_refresh();
+void sidebar_updated();
 
 #endif /* SIDEBAR_H */
-- 
1.7.6.233.gd79bc



More information about the mutt-kz mailing list