Andreas Krennmair:
authorak1 <ak1@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Wed, 23 Feb 2005 20:15:40 +0000 (20:15 +0000)
committerak1 <ak1@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Wed, 23 Feb 2005 20:15:40 +0000 (20:15 +0000)
integrated Rocco Rutte's sidebar fixes

git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@84 e385b8ad-14ed-0310-8656-cc95a2468c6d

ChangeLog.mutt-ng
buffy.c
globals.h
init.h
pager.c
sidebar.c

index 4116dc7..ea52d03 100644 (file)
@@ -4,6 +4,7 @@ Changes specific to mutt-ng:
   * Integrated assume_charset patch from http://www.emaillab.org/mutt/download15.html.en
   * Integrated patch by Rocco Rutte to correct minor bugs
   * Fixed huge multibyte handling fuckup (was I drunk?!)
+  * Integrated sidebar fixed by Rocco Rutte
 
 2005-02-22:
   * Merged mutt changes
diff --git a/buffy.c b/buffy.c
index 7f5b4b7..208eaac 100644 (file)
--- a/buffy.c
+++ b/buffy.c
@@ -421,7 +421,7 @@ int mutt_buffy_check (int force)
          }
        }
        closedir (dirp);
-#if 0
+#if 1
   /* I commented this out because it led to an infite "New mail in ..." loop,
    * and when looking at the code, the check seems to be overly eager.
    *   -- ak
@@ -440,8 +440,13 @@ int mutt_buffy_check (int force)
          {
            /* one new and undeleted message is enough */
            BuffyCount++;
+#if 0
+            /* we're checking for read and not new mail; 
+             * seems like copy'n'paste error
+             */
            tmp->has_new = tmp->new = 1;
-        tmp->msgcount++;
+#endif
+            tmp->msgcount++;
          }
        }
        closedir (dirp);
index 24fc694..c04e5a3 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -121,6 +121,7 @@ WHERE char *Realname;
 WHERE char *SendCharset;
 WHERE char *Sendmail;
 WHERE char *Shell;
+WHERE char *SidebarDelim;
 WHERE char *Signature;
 WHERE char *SignOffString;
 WHERE char *SimpleSearch;
diff --git a/init.h b/init.h
index a569719..2ccd08e 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1211,6 +1211,12 @@ struct option_t MuttVars[] = {
   ** this is unset, it will be set to the operating system name that uname(2)
   ** returns. If uname(2) fails, "UNIX" will be used.
   */
+  { "sidebar_delim", DT_STR, R_BOTH, UL &SidebarDelim, UL "|" },
+  /*
+  ** .pp
+  ** This specifies the delimiter between the sidebar (if visible) and 
+  ** other screens.
+  */
   { "sidebar_visible", DT_BOOL, R_BOTH, OPTMBOXPANE, 0 },
   /*
   ** .pp
diff --git a/pager.c b/pager.c
index b735abf..4b1c48a 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -1773,11 +1773,10 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
       /* redraw the pager_index indicator, because the
        * flags for this message might have changed. */
       menu_redraw_current (index);
-         draw_sidebar(MENU_PAGER);
+      draw_sidebar(MENU_PAGER);
       /* print out the index status bar */
       menu_status_line (buffer, sizeof (buffer), index, NONULL(Status));
-      move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)),
-                 SidebarWidth);
+      move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)),SidebarWidth);
       SETCOLOR (MT_COLOR_STATUS);
       mutt_paddstr (COLS-SidebarWidth, buffer);
       SETCOLOR (MT_COLOR_NORMAL);
index e1bec5d..85605bd 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
 static BUFFY *TopBuffy = 0;
 static BUFFY *BottomBuffy = 0;
 static int known_lines = 0;
+static bool initialized = false;
+static int prev_show_value;
+static short saveSidebarWidth;
+static char *entry = 0;
 
 static int quick_log10(int n)
 {
-        char string[32];
-        sprintf(string, "%d", n);
-        return strlen(string);
+  int len = 0;
+  for (; n > 9; len++, n /= 10)
+    ;
+  return (++len);
 }
 
 void calc_boundaries (int menu)
 {
-       BUFFY *tmp = Incoming;
-
-       if ( known_lines != LINES ) {
-               TopBuffy = BottomBuffy = 0;
-               known_lines = LINES;
-       }
-       for ( ; tmp->next != 0; tmp = tmp->next )
-               tmp->next->prev = tmp;
-
-       if ( TopBuffy == 0 && BottomBuffy == 0 )
-               TopBuffy = Incoming;
-       if ( BottomBuffy == 0 ) {
-               int count = LINES - 2 - (menu != MENU_PAGER);
-               BottomBuffy = TopBuffy;
-               while ( --count && BottomBuffy->next )
-                       BottomBuffy = BottomBuffy->next;
-       }
-       else if ( TopBuffy == CurBuffy->next ) {
-               int count = LINES - 2 - (menu != MENU_PAGER);
-               BottomBuffy = CurBuffy;
-               tmp = BottomBuffy;
-               while ( --count && tmp->prev)
-                       tmp = tmp->prev;
-               TopBuffy = tmp;
-       }
-       else if ( BottomBuffy == CurBuffy->prev ) {
-               int count = LINES - 2 - (menu != MENU_PAGER);
-               TopBuffy = CurBuffy;
-               tmp = TopBuffy;
-               while ( --count && tmp->next )
-                       tmp = tmp->next;
-               BottomBuffy = tmp;
-       }
+  BUFFY *tmp = Incoming;
+
+  if ( known_lines != LINES ) {
+    TopBuffy = BottomBuffy = 0;
+    known_lines = LINES;
+  }
+  for ( ; tmp->next != 0; tmp = tmp->next )
+    tmp->next->prev = tmp;
+
+  if ( TopBuffy == 0 && BottomBuffy == 0 )
+    TopBuffy = Incoming;
+  if ( BottomBuffy == 0 ) {
+    int count = LINES - 2 - (menu != MENU_PAGER);
+    BottomBuffy = TopBuffy;
+    while ( --count && BottomBuffy->next )
+      BottomBuffy = BottomBuffy->next;
+  }
+  else if ( TopBuffy == CurBuffy->next ) {
+    int count = LINES - 2 - (menu != MENU_PAGER);
+    BottomBuffy = CurBuffy;
+    tmp = BottomBuffy;
+    while ( --count && tmp->prev)
+      tmp = tmp->prev;
+    TopBuffy = tmp;
+  }
+  else if ( BottomBuffy == CurBuffy->prev ) {
+    int count = LINES - 2 - (menu != MENU_PAGER);
+    TopBuffy = CurBuffy;
+    tmp = TopBuffy;
+    while ( --count && tmp->next )
+      tmp = tmp->next;
+    BottomBuffy = tmp;
+  }
 }
 
 static char * shortened_hierarchy(char * box) {
@@ -109,16 +114,15 @@ static char * shortened_hierarchy(char * box) {
 
 char *make_sidebar_entry(char *box, int size, int new)
 {
-       static char *entry = 0;
-       char *c;
-       int i = 0;
-
-       c = realloc(entry, SidebarWidth + 1);
-       if ( c ) entry = c;
-       entry[SidebarWidth] = 0;
-       for (; i < SidebarWidth; entry[i++] = ' ' );
+  char *c;
+  int i = 0, dlen = mutt_strlen (SidebarDelim);
+
+  c = realloc(entry, SidebarWidth + 1);
+  if ( c ) entry = c;
+  entry[SidebarWidth] = 0;
+  for (; i < SidebarWidth; entry[i++] = ' ' );
 #if USE_IMAP
-       if (ImapHomeNamespace && strlen(ImapHomeNamespace)>0) {
+  if (ImapHomeNamespace && strlen(ImapHomeNamespace)>0) {
     if (strncmp(box,ImapHomeNamespace,strlen(ImapHomeNamespace))==0 && strcmp(box,ImapHomeNamespace)!=0) {
       box+=strlen(ImapHomeNamespace)+1;
     }
@@ -127,19 +131,18 @@ char *make_sidebar_entry(char *box, int size, int new)
   if (option(OPTSHORTENHIERARCHY)) {
     box = shortened_hierarchy(box);
   }
-       i = strlen(box);
-       strncpy( entry, box, i < SidebarWidth ? i :SidebarWidth );
-
-       if ( new ) 
-               sprintf(
-                       entry + SidebarWidth - 5 - quick_log10(size) - quick_log10(new),
-                       "% d(%d)", size, new);
-       else
-               sprintf( entry + SidebarWidth - 3 - quick_log10(size), "% d", size);
+  i = strlen(box);
+  strncpy( entry, box, i < SidebarWidth - dlen ? i :SidebarWidth - dlen);
+
+  if ( new ) 
+    sprintf(entry + SidebarWidth - 3 - quick_log10(size) - dlen - quick_log10(new),
+            "% d(%d)", size, new);
+  else
+    sprintf( entry + SidebarWidth - 1 - quick_log10(size) - dlen, "% d", size);
   if (option(OPTSHORTENHIERARCHY)) {
     free(box);
   }
-       return entry;
+  return entry;
 }
 
 void set_curbuffy(char buf[LONG_STRING])
@@ -164,98 +167,95 @@ void set_curbuffy(char buf[LONG_STRING])
 
 int draw_sidebar(int menu) {
 
-       int lines = option(OPTHELP) ? 1 : 0;
-       BUFFY *tmp;
+  int lines = option(OPTHELP) ? 1 : 0;
+  BUFFY *tmp;
 #ifndef USE_SLANG_CURSES
-        attr_t attrs;
+  attr_t attrs;
 #endif
-        short color_pair;
-
-        static bool initialized = false;
-        static int prev_show_value;
-        static short saveSidebarWidth;
-
-        /* initialize first time */
-        if(!initialized) {
-                prev_show_value = option(OPTMBOXPANE);
-                saveSidebarWidth = SidebarWidth;
-                if(!option(OPTMBOXPANE)) SidebarWidth = 0;
-                initialized = true;
-        }
+  short color_pair;
+  short delim_len = mutt_strlen (SidebarDelim);
+
+  /* initialize first time */
+  if(!initialized) {
+    prev_show_value = option(OPTMBOXPANE);
+    saveSidebarWidth = SidebarWidth;
+    if(!option(OPTMBOXPANE)) SidebarWidth = 0;
+    initialized = true;
+  }
 
-        /* save or restore the value SidebarWidth */
-        if(prev_show_value != option(OPTMBOXPANE)) {
-                if(prev_show_value && !option(OPTMBOXPANE)) {
-                        saveSidebarWidth = SidebarWidth;
-                        SidebarWidth = 0;
-                } else if(!prev_show_value && option(OPTMBOXPANE)) {
-                        SidebarWidth = saveSidebarWidth;
-                }
-                prev_show_value = option(OPTMBOXPANE);
-        }
+  /* save or restore the value SidebarWidth */
+  if(prev_show_value != option(OPTMBOXPANE)) {
+    if(prev_show_value && !option(OPTMBOXPANE)) {
+      saveSidebarWidth = SidebarWidth;
+      SidebarWidth = 0;
+    } else if(!prev_show_value && option(OPTMBOXPANE)) {
+      SidebarWidth = saveSidebarWidth;
+    }
+    prev_show_value = option(OPTMBOXPANE);
+  }
 
 
-       if ( SidebarWidth == 0 ) return 0;
+  if ( SidebarWidth == 0 ) return 0;
 
-        /* get attributes for divider */
-       SETCOLOR(MT_COLOR_STATUS);
+  /* get attributes for divider */
+  SETCOLOR(MT_COLOR_STATUS);
 #ifndef USE_SLANG_CURSES
-        attr_get(&attrs, &color_pair, 0);
+  attr_get(&attrs, &color_pair, 0);
 #else
-        color_pair = attr_get();
+  color_pair = attr_get();
 #endif
-        SETCOLOR(MT_COLOR_NORMAL);
+  SETCOLOR(MT_COLOR_NORMAL);
 
-       /* draw the divider */
+  /* draw the divider */
 
-       for ( ; lines < LINES-1-(menu != MENU_PAGER); lines++ ) {
-               move(lines, SidebarWidth - 1);
-               addch('|');
+  for ( ; lines < LINES-1-(menu != MENU_PAGER); lines++ ) {
+    move(lines, SidebarWidth - delim_len);
+    addstr (NONULL (SidebarDelim));
  #ifndef USE_SLANG_CURSES
-                mvchgat(lines, SidebarWidth - 1, 1, 0, color_pair, NULL);
+    mvchgat(lines, SidebarWidth - delim_len, delim_len, 0, color_pair, NULL);
  #endif
-       }
-       if ( Incoming == 0 ) return 0;
-       lines = option(OPTHELP) ? 1 : 0; /* go back to the top */
-
-       if ( known_lines != LINES || TopBuffy == 0 || BottomBuffy == 0 ) 
-               calc_boundaries(menu);
-       if ( CurBuffy == 0 ) CurBuffy = Incoming;
-
-       tmp = TopBuffy;
-
-       SETCOLOR(MT_COLOR_NORMAL);
-
-       for ( ; tmp && lines < LINES-1 - (menu != MENU_PAGER); tmp = tmp->next ) {
-               if ( tmp == CurBuffy )
-                       SETCOLOR(MT_COLOR_INDICATOR);
-               else if ( tmp->msg_unread > 0 )
-                       SETCOLOR(MT_COLOR_NEW);
-               else
-                       SETCOLOR(MT_COLOR_NORMAL);
-
-               move( lines, 0 );
-               if ( Context && !strcmp( tmp->path, Context->path ) ) {
-                       printw( "%.*s", SidebarWidth,
-                               make_sidebar_entry(basename(tmp->path), Context->msgcount,
-                               Context->unread));
-                       tmp->msg_unread = Context->unread;
-                       tmp->msgcount = Context->msgcount;
-               }
-               else
-                       printw( "%.*s", SidebarWidth,
-                               make_sidebar_entry(basename(tmp->path), tmp->msgcount,
-                               tmp->msg_unread));
-               lines++;
-       }
-       SETCOLOR(MT_COLOR_NORMAL);
-       for ( ; lines < LINES - 1 - (menu != MENU_PAGER); lines++ ) {
-               int i = 0;
-               move( lines, 0 );
-               for ( ; i < SidebarWidth - 1; i++ )
-                       addch(' ');
-       }
-       return 0;
+  }
+  if ( Incoming == 0 ) return 0;
+  lines = option(OPTHELP) ? 1 : 0; /* go back to the top */
+
+  if ( known_lines != LINES || TopBuffy == 0 || BottomBuffy == 0 ) 
+    calc_boundaries(menu);
+  if ( CurBuffy == 0 ) CurBuffy = Incoming;
+
+  tmp = TopBuffy;
+
+  SETCOLOR(MT_COLOR_NORMAL);
+
+  for ( ; tmp && lines < LINES-1 - (menu != MENU_PAGER); tmp = tmp->next ) {
+    if ( tmp == CurBuffy )
+      SETCOLOR(MT_COLOR_INDICATOR);
+    else if ( tmp->msg_unread > 0 )
+      SETCOLOR(MT_COLOR_NEW);
+    else
+      SETCOLOR(MT_COLOR_NORMAL);
+
+    move( lines, 0 );
+    if ( Context && !strcmp( tmp->path, Context->path ) ) {
+      printw( "%.*s", SidebarWidth - delim_len,
+              make_sidebar_entry(basename(tmp->path),
+                                 Context->msgcount, Context->unread));
+      tmp->msg_unread = Context->unread;
+      tmp->msgcount = Context->msgcount;
+    }
+    else
+      printw( "%.*s", SidebarWidth - delim_len,
+              make_sidebar_entry(basename(tmp->path),
+                                 tmp->msgcount,tmp->msg_unread));
+    lines++;
+  }
+  SETCOLOR(MT_COLOR_NORMAL);
+  for ( ; lines < LINES - 1 - (menu != MENU_PAGER); lines++ ) {
+    int i = 0;
+    move( lines, 0 );
+    for ( ; i < SidebarWidth - delim_len; i++ )
+      addch(' ');
+  }
+  return 0;
 }
 
 void scroll_sidebar(int op, int menu)
@@ -263,36 +263,36 @@ void scroll_sidebar(int op, int menu)
         if(!SidebarWidth) return;
         if(!CurBuffy) return;
 
-       switch (op) {
-               case OP_SIDEBAR_NEXT:
-                       if ( CurBuffy->next == NULL ) return;
-                       CurBuffy = CurBuffy->next;
-                       break;
-               case OP_SIDEBAR_PREV:
-                       if ( CurBuffy == Incoming ) return;
-                       {
-                               BUFFY *tmp = Incoming;
-                               while ( tmp->next && strcmp(tmp->next->path, CurBuffy->path) ) tmp = tmp->next;
-                               CurBuffy = tmp;
-                       }
-                       break;
-               case OP_SIDEBAR_SCROLL_UP:
-                       CurBuffy = TopBuffy;
-                       if ( CurBuffy != Incoming ) {
-                               calc_boundaries(menu);
-                               CurBuffy = CurBuffy->prev;
-                       }
-                       break;
-               case OP_SIDEBAR_SCROLL_DOWN:
-                       CurBuffy = BottomBuffy;
-                       if ( CurBuffy->next ) {
-                               calc_boundaries(menu);
-                               CurBuffy = CurBuffy->next;
-                       }
-                       break;
-               default:
-                       return;
-       }
-       calc_boundaries(menu);
-       draw_sidebar(menu);
+  switch (op) {
+    case OP_SIDEBAR_NEXT:
+      if ( CurBuffy->next == NULL ) return;
+      CurBuffy = CurBuffy->next;
+      break;
+    case OP_SIDEBAR_PREV:
+      if ( CurBuffy == Incoming ) return;
+      {
+        BUFFY *tmp = Incoming;
+        while ( tmp->next && strcmp(tmp->next->path, CurBuffy->path) ) tmp = tmp->next;
+        CurBuffy = tmp;
+      }
+      break;
+    case OP_SIDEBAR_SCROLL_UP:
+      CurBuffy = TopBuffy;
+      if ( CurBuffy != Incoming ) {
+        calc_boundaries(menu);
+        CurBuffy = CurBuffy->prev;
+      }
+      break;
+    case OP_SIDEBAR_SCROLL_DOWN:
+      CurBuffy = BottomBuffy;
+      if ( CurBuffy->next ) {
+        calc_boundaries(menu);
+        CurBuffy = CurBuffy->next;
+      }
+      break;
+    default:
+      return;
+  }
+  calc_boundaries(menu);
+  draw_sidebar(menu);
 }