Commit 086a5b80 authored by Kevin J. McCarthy's avatar Kevin J. McCarthy

Sidebar clean up: building and drawing logic.

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.
parent 389c74bb
......@@ -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
......
......@@ -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;
......
......@@ -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
......
......@@ -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);
......
......@@ -25,10 +25,6 @@
#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)
......
......@@ -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
......
......@@ -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);
......
......@@ -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))
......
......@@ -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 *);
......
......@@ -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;
......
......@@ -843,7 +843,7 @@ sb_change_mailbox (int op)
default:
return;
}
sb_draw();
SidebarNeedsRedraw = 1;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment