]> granicus.if.org Git - neomutt/commitdiff
Sidebar clean up: building and drawing logic.
authorKevin McCarthy <kevin@8t8.us>
Sat, 4 Jun 2016 18:32:03 +0000 (11:32 -0700)
committerKevin McCarthy <kevin@8t8.us>
Sat, 4 Jun 2016 18:32:03 +0000 (11:32 -0700)
Fix the autoconf/makefile.am changes to be consistent.

Create a global SidebarNeedsRedraw to indicate a redraw is needed,
instead of putting sb_draw() everywhere in the code.

Create a menu_redraw_sidebar() function and use the REDRAW_SIDEBAR
flag instead of piggy-backing it inside the index loop.

Fix curs_main.c and pager.c to be a bit cleaner by using the global and
REDRAW_SIDEBAR.

Start to clean up some of the buffy code, but this needs to refactored
and fixed.

Makefile.am
buffy.c
configure.ac
curs_main.c
flags.c
globals.h
keymap.c
menu.c
mutt_menu.h
pager.c
sidebar.c

index f2f67cf445f65e6899648eccebcbd23d854fd98b..b874d943b9009ce64366031ac1d365f47f154d64 100644 (file)
@@ -56,7 +56,7 @@ EXTRA_mutt_SOURCES = account.c bcache.c crypt-gpgme.c crypt-mod-pgp-classic.c \
        mutt_idna.c mutt_sasl.c mutt_socket.c mutt_ssl.c mutt_ssl_gnutls.c \
        mutt_tunnel.c pgp.c pgpinvoke.c pgpkey.c pgplib.c pgpmicalg.c \
        pgppacket.c pop.c pop_auth.c pop_lib.c remailer.c resize.c sha1.c \
-       smime.c smtp.c utf8.c wcwidth.c \
+       sidebar.c smime.c smtp.c utf8.c wcwidth.c \
        bcache.h browser.h hcache.h mbyte.h mutt_idna.h remailer.h url.h
 
 EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP OPS.CRYPT OPS.SMIME TODO UPDATING \
@@ -71,18 +71,12 @@ EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP OPS.CRYPT OPS.SMIME TODO UPDATING \
        mbyte.h lib.h extlib.c pgpewrap.c smime_keys.pl pgplib.h \
        README.SSL smime.h group.h \
        muttbug pgppacket.h depcomp ascii.h BEWARE PATCHES patchlist.sh \
-       ChangeLog mkchangelog.sh mutt_idna.h \
+       ChangeLog mkchangelog.sh mutt_idna.h sidebar.h OPS.sidebar \
        snprintf.c regex.c crypt-gpgme.h hcachever.sh.in \
        txt2c.c txt2c.sh version.sh check_sec.sh
 
 EXTRA_SCRIPTS = smime_keys
 
-if BUILD_SIDEBAR
-mutt_SOURCES += sidebar.c sidebar.h
-endif
-
-EXTRA_DIST += OPS.SIDEBAR
-
 mutt_dotlock_SOURCES = mutt_dotlock.c
 mutt_dotlock_LDADD = $(LIBOBJS)
 mutt_dotlock_DEPENDENCIES = $(LIBOBJS)
@@ -137,8 +131,8 @@ keymap_defs.h: $(OPS) $(srcdir)/gen_defs
 
 keymap_alldefs.h: $(srcdir)/OPS $(srcdir)/OPS.SIDEBAR $(srcdir)/OPS.PGP $(srcdir)/OPS.MIX $(srcdir)/OPS.CRYPT $(srcdir)/OPS.SMIME $(srcdir)/gen_defs
        rm -f $@
-       $(srcdir)/gen_defs $(srcdir)/OPS $(srcdir)/OPS.PGP \
-               $(srcdir)/OPS.SIDEBAR $(srcdir)/OPS.MIX $(srcdir)/OPS.CRYPT $(srcdir)/OPS.SMIME \
+       $(srcdir)/gen_defs $(srcdir)/OPS $(srcdir)/OPS.SIDEBAR $(srcdir)/OPS.PGP \
+               $(srcdir)/OPS.MIX $(srcdir)/OPS.CRYPT $(srcdir)/OPS.SMIME \
                        > keymap_alldefs.h
 
 reldate.h: $(srcdir)/ChangeLog
diff --git a/buffy.c b/buffy.c
index 325a2d7438e3764bfe2c7b85a9dfc2fc62da44d9..02e338b2f34287a7d8d24bf59becc4cd08468512 100644 (file)
--- a/buffy.c
+++ b/buffy.c
@@ -409,41 +409,41 @@ static int buffy_maildir_hasnew (BUFFY* mailbox)
 static void
 buffy_maildir_update_dir (BUFFY *mailbox, const char *dir)
 {
-       char path[_POSIX_PATH_MAX] = "";
-       DIR *dirp = NULL;
-       struct dirent *de = NULL;
-       char *p = NULL;
-       int read;
+  char path[_POSIX_PATH_MAX] = "";
+  DIR *dirp = NULL;
+  struct dirent *de = NULL;
+  char *p = NULL;
 
-       snprintf (path, sizeof (path), "%s/%s", mailbox->path, dir);
+  snprintf (path, sizeof (path), "%s/%s", mailbox->path, dir);
 
-       dirp = opendir (path);
-       if (!dirp) {
-               mailbox->magic = 0;
-               return;
-       }
+  dirp = opendir (path);
+  if (!dirp)
+  {
+    mailbox->magic = 0;
+    return;
+  }
 
-       while ((de = readdir (dirp)) != NULL) {
-               if (*de->d_name == '.')
-                       continue;
-
-               /* Matches maildir_parse_flags logic */
-               read = 0;
-               mailbox->msg_count++;
-               p = strstr (de->d_name, ":2,");
-               if (p) {
-                       p += 3;
-                       if (strchr (p, 'S'))
-                               read = 1;
-                       if (strchr (p, 'F'))
-                               mailbox->msg_flagged++;
-               }
-               if (!read) {
-                       mailbox->msg_unread++;
-               }
-       }
+  while ((de = readdir (dirp)) != NULL)
+  {
+    if (*de->d_name == '.')
+      continue;
 
-       closedir (dirp);
+    /* Matches maildir_parse_flags logic */
+    mailbox->msg_count++;
+    p = strstr (de->d_name, ":2,");
+    if (p)
+    {
+      p += 3;
+      if (strchr (p, 'T'))
+        continue;
+      if (!strchr (p, 'S'))
+        mailbox->msg_unread++;
+      if (strchr (p, 'F'))
+        mailbox->msg_flagged++;
+    }
+  }
+
+  closedir (dirp);
 }
 
 /**
@@ -470,9 +470,6 @@ buffy_maildir_update (BUFFY *mailbox)
        buffy_maildir_update_dir (mailbox, "cur");
 
        mailbox->sb_last_checked = time (NULL);
-
-       /* make sure the updates are actually put on screen */
-       sb_draw();
 }
 
 #endif
@@ -525,24 +522,22 @@ static int buffy_mbox_hasnew (BUFFY* mailbox, struct stat *sb)
 void
 buffy_mbox_update (BUFFY *mailbox, struct stat *sb)
 {
-       CONTEXT *ctx = NULL;
+  CONTEXT *ctx = NULL;
 
-       if (!option (OPTSIDEBAR))
-               return;
-       if ((mailbox->sb_last_checked > sb->st_mtime) && (mailbox->msg_count != 0))
-               return; /* no check necessary */
-
-       ctx = mx_open_mailbox (mailbox->path, MUTT_READONLY | MUTT_QUIET | MUTT_NOSORT | MUTT_PEEK, NULL);
-       if (ctx) {
-               mailbox->msg_count       = ctx->msgcount;
-               mailbox->msg_unread      = ctx->unread;
-               mailbox->msg_flagged     = ctx->flagged;
-               mailbox->sb_last_checked = time (NULL);
-               mx_close_mailbox (ctx, 0);
-       }
+  if (!option (OPTSIDEBAR))
+    return;
+  if ((mailbox->sb_last_checked > sb->st_mtime) && (mailbox->msg_count != 0))
+    return; /* no check necessary */
 
-       /* make sure the updates are actually put on screen */
-       sb_draw();
+  ctx = mx_open_mailbox (mailbox->path, MUTT_READONLY | MUTT_QUIET | MUTT_NOSORT | MUTT_PEEK, NULL);
+  if (ctx)
+  {
+    mailbox->msg_count       = ctx->msgcount;
+    mailbox->msg_unread      = ctx->unread;
+    mailbox->msg_flagged     = ctx->flagged;
+    mailbox->sb_last_checked = time (NULL);
+    mx_close_mailbox (ctx, 0);
+  }
 }
 #endif
 
@@ -641,10 +636,8 @@ int mutt_buffy_check (int force)
 
       case MUTT_MH:
 #ifdef USE_SIDEBAR
-       if (sb_should_refresh()) {
+       if (should_refresh)
          mh_buffy_update (tmp);
-         sb_set_update_time();
-       }
 #endif
        mh_buffy(tmp);
        if (tmp->new)
@@ -662,7 +655,10 @@ int mutt_buffy_check (int force)
   }
 #ifdef USE_SIDEBAR
   if (should_refresh)
-         sb_set_update_time();
+  {
+    SidebarNeedsRedraw = 1;
+    sb_set_update_time();
+  }
 #endif
 
   BuffyDoneTime = BuffyTime;
index f8d71a199a693ac8cc4942140a93f2e96323e697..df29887d430c75cca3a6827156fc4aeb218145f0 100644 (file)
@@ -177,12 +177,11 @@ fi
 
 AC_ARG_ENABLE(sidebar, AC_HELP_STRING([--enable-sidebar], [Enable Sidebar support]),
 [       if test x$enableval = xyes ; then
-               AC_DEFINE(USE_SIDEBAR,1,[ Define if you want support for the sidebar. ])
+               AC_DEFINE(USE_SIDEBAR, 1, [Define if you want support for the sidebar.])
                OPS="$OPS \$(srcdir)/OPS.SIDEBAR"
-               need_sidebar="yes"
+                MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS sidebar.o"
         fi
 ])
-AM_CONDITIONAL(BUILD_SIDEBAR, test x$need_sidebar = xyes)
 
 AC_ARG_WITH(mixmaster, AS_HELP_STRING([--with-mixmaster@<:@=PATH@:>@],[Include Mixmaster support]),
   [if test "$withval" != no
index e138906c76248f5bac53c30c26ff74975e8d154b..f18debbd525ce6820ab02a550ec7a4da9f36ba22 100644 (file)
@@ -609,31 +609,24 @@ int mutt_index_menu (void)
        do_buffy_notify = 1;
     }
 
-#ifdef USE_SIDEBAR
-    if (option (OPTSIDEBAR))
-        menu->redraw |= REDRAW_SIDEBAR;
-#endif
-
     if (op != -1)
       mutt_curs_set (0);
 
     if (menu->redraw & REDRAW_FULL)
     {
       menu_redraw_full (menu);
-#ifdef USE_SIDEBAR
-      sb_draw();
-#endif
       mutt_show_error ();
     }
-#ifdef USE_SIDEBAR
-    else if (menu->redraw & REDRAW_SIDEBAR) {
-      sb_draw();
-      menu->redraw &= ~REDRAW_SIDEBAR;
-    }
-#endif
 
     if (menu->menu == MENU_MAIN)
     {
+#ifdef USE_SIDEBAR
+      if (menu->redraw & REDRAW_SIDEBAR || SidebarNeedsRedraw)
+      {
+        sb_set_buffystats (Context);
+        menu_redraw_sidebar (menu);
+      }
+#endif
       if (Context && Context->hdrs && !(menu->current >= Context->vcount))
       {
        menu_check_recenter (menu);
@@ -654,9 +647,6 @@ int mutt_index_menu (void)
        menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
         mutt_window_move (MuttStatusWindow, 0, 0);
        SETCOLOR (MT_COLOR_STATUS);
-#ifdef USE_SIDEBAR
-       sb_set_buffystats (Context);
-#endif
        mutt_paddstr (MuttStatusWindow->cols, buf);
        NORMAL_COLOR;
        menu->redraw &= ~REDRAW_STATUS;
@@ -1116,9 +1106,6 @@ int mutt_index_menu (void)
          break;
 
        CHECK_MSGCOUNT;
-#ifdef USE_SIDEBAR
-       CHECK_VISIBLE;
-#endif
        CHECK_READONLY;
        {
          int oldvcount = Context->vcount;
@@ -1208,28 +1195,29 @@ int mutt_index_menu (void)
            break;
          }
        }
+#ifdef USE_SIDEBAR
+        else if (op == OP_SIDEBAR_OPEN)
+        {
+          const char *path = sb_get_highlight();
+          if (!path || !*path)
+            break;
+          strncpy (buf, path, sizeof (buf));
+        }
+#endif
        else
        {
          mutt_buffy (buf, sizeof (buf));
 
-#ifdef USE_SIDEBAR
-         if (op == OP_SIDEBAR_OPEN) {
-           const char *path = sb_get_highlight();
-           if (!path)
-             break;
-           strncpy (buf, path, sizeof (buf));
-         } else
-#endif
-         if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
-         {
-           if (menu->menu == MENU_PAGER)
-           {
-             op = OP_DISPLAY_MESSAGE;
-             continue;
-           }
-           else
-             break;
-         }
+          if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
+          {
+            if (menu->menu == MENU_PAGER)
+            {
+              op = OP_DISPLAY_MESSAGE;
+              continue;
+            }
+            else
+              break;
+          }
          if (!buf[0])
          {
             mutt_window_clearline (MuttMessageWindow, 0);
diff --git a/flags.c b/flags.c
index 2d404f60f3c736755cba9f95d88378acfdef8207..82e48647131767d88cb96a63b07877f0255d8cef 100644 (file)
--- a/flags.c
+++ b/flags.c
 #include "sort.h"
 #include "mx.h"
 
-#ifdef USE_SIDEBAR
-#include "sidebar.h"
-#endif
-
 void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
 {
   int changed = h->changed;
@@ -259,7 +255,12 @@ void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
   }
 
   if (update)
+  {
     mutt_set_header_color(ctx, h);
+#ifdef USE_SIDEBAR
+    SidebarNeedsRedraw = 1;
+#endif
+  }
 
   /* if the message status has changed, we need to invalidate the cached
    * search results so that any future search will match the current status
@@ -267,9 +268,6 @@ void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
    */
   if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged || flagged != ctx->flagged))
     h->searched = 0;
-#ifdef USE_SIDEBAR
-  sb_draw();
-#endif
 }
 
 void mutt_tag_set_flag (int flag, int bf)
index cf8c5f0cc713d6c01c39f2b18ae61dc2067b72f4..05a3e11f770fd7f9c309a91c2fa2f374bc01f2a6 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -220,12 +220,11 @@ WHERE short ScoreThresholdDelete;
 WHERE short ScoreThresholdRead;
 WHERE short ScoreThresholdFlag;
 
-/* This isn't excluded from the build because it's too entwined in the code.
- * For now. */
-WHERE short SidebarWidth;
 #ifdef USE_SIDEBAR
+WHERE short SidebarWidth;
 WHERE short SidebarRefreshTime;
 WHERE LIST *SidebarWhitelist INITVAL(0);
+WHERE int SidebarNeedsRedraw INITVAL (0);
 #endif
 
 #ifdef USE_IMAP
index 301ef653783d5b8fc0d9f24c3d9bc43da5658ecb..8b8b972b5bd7f1707a8ff21707c5d2e133d73496 100644 (file)
--- a/keymap.c
+++ b/keymap.c
@@ -457,9 +457,6 @@ int km_dokey (int menu)
     }
 #endif
 
-    /* update sidebar stats */
-    mutt_buffy_check(0);
-
     timeout (i * 1000);
     tmp = mutt_getch();
     timeout (-1);
diff --git a/menu.c b/menu.c
index a8be371dc3471864673a92f470a2f00631366dc3..86bbed4377a84670fe5f3d24a1eb1042b7785140 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -217,6 +217,9 @@ void menu_redraw_full (MUTTMENU *menu)
   mutt_show_error ();
 
   menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
+#ifdef USE_SIDEBAR
+  menu->redraw |= REDRAW_SIDEBAR;
+#endif
 }
 
 void menu_redraw_status (MUTTMENU *menu)
@@ -231,6 +234,14 @@ void menu_redraw_status (MUTTMENU *menu)
   menu->redraw &= ~REDRAW_STATUS;
 }
 
+#ifdef USE_SIDEBAR
+void menu_redraw_sidebar (MUTTMENU *menu)
+{
+  SidebarNeedsRedraw = 0;
+  sb_draw ();
+}
+#endif
+
 void menu_redraw_index (MUTTMENU *menu)
 {
   char buf[LONG_STRING];
@@ -238,9 +249,6 @@ void menu_redraw_index (MUTTMENU *menu)
   int do_color;
   int attr;
 
-#ifdef USE_SIDEBAR
-  sb_draw();
-#endif
   for (i = menu->top; i < menu->top + menu->pagelen; i++)
   {
     if (i < menu->max)
@@ -843,6 +851,10 @@ int menu_redraw (MUTTMENU *menu)
   
   if (menu->redraw & REDRAW_STATUS)
     menu_redraw_status (menu);
+#ifdef USE_SIDEBAR
+  if (menu->redraw & REDRAW_SIDEBAR || SidebarNeedsRedraw)
+    menu_redraw_sidebar (menu);
+#endif
   if (menu->redraw & REDRAW_INDEX)
     menu_redraw_index (menu);
   else if (menu->redraw & (REDRAW_MOTION | REDRAW_MOTION_RESYNCH))
index bf5522c07ce843e195d57eed715800914dfaa0b7..b229fd45e49775572c46627383bbb26425f909f4 100644 (file)
@@ -90,6 +90,9 @@ typedef struct menu_t
 void mutt_menu_init (void);
 void menu_jump (MUTTMENU *);
 void menu_redraw_full (MUTTMENU *);
+#ifdef USE_SIDEBAR
+void menu_redraw_sidebar (MUTTMENU *);
+#endif
 void menu_redraw_index (MUTTMENU *);
 void menu_redraw_status (MUTTMENU *);
 void menu_redraw_motion (MUTTMENU *);
diff --git a/pager.c b/pager.c
index 06bed3abf82e9cce24ba4b93788f68ad923149d7..d9907527575070dccad5b0e752695fee3fc9e433 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -1671,9 +1671,6 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
       /* clear() doesn't optimize screen redraws */
       move (0, 0);
       clrtobot ();
-#ifdef USE_SIDEBAR
-      sb_draw();
-#endif
 
       if (IsHeader (extra) && Context->vcount + 1 < PagerIndexLines)
        indexlen = Context->vcount + 1;
@@ -1767,6 +1764,9 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
       }
 
       redraw |= REDRAW_BODY | REDRAW_INDEX | REDRAW_STATUS;
+#ifdef USE_SIDEBAR
+      redraw |= REDRAW_SIDEBAR;
+#endif
       mutt_show_error ();
     }
 
@@ -1785,6 +1785,14 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
        }
     }
 
+#ifdef USE_SIDEBAR
+    if ((redraw & REDRAW_SIDEBAR) || SidebarNeedsRedraw)
+    {
+      SidebarNeedsRedraw = 0;
+      sb_draw ();
+    }
+#endif
+
     if ((redraw & REDRAW_BODY) || topline != oldtopline)
     {
       do {
@@ -2543,12 +2551,8 @@ search_next:
          ch = 0;
        }
 
-       if (option (OPTFORCEREDRAWPAGER)) {
+       if (option (OPTFORCEREDRAWPAGER))
          redraw = REDRAW_FULL;
-#ifdef USE_SIDEBAR
-         sb_draw();
-#endif
-       }
        unset_option (OPTFORCEREDRAWINDEX);
        unset_option (OPTFORCEREDRAWPAGER);
        break;
index 6f8093d437c3b22dffa2d3cffed6edef0ecd4ef3..26f5460c55dc276d0ad96aceb26a700fb5a21f73 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -843,7 +843,7 @@ sb_change_mailbox (int op)
                default:
                        return;
        }
-       sb_draw();
+       SidebarNeedsRedraw = 1;
 }
 
 /**