Rocco Rutte:
[apps/madmutt.git] / sidebar.c
index 8adea8f..c71090e 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -133,10 +133,11 @@ static char * shortened_hierarchy(char * box) {
   return safe_strdup(box);
 }
 
-char *make_sidebar_entry(char *box, int size, int new)
+char *make_sidebar_entry(char *box, int size, int new, int flagged)
 {
   char *c;
-  int i = 0, dlen = mutt_strlen (SidebarDelim);
+  int i = 0, dlen = mutt_strlen (SidebarDelim), max = SidebarWidth-dlen-1,
+      shortened = 0;
 
   c = realloc(entry, SidebarWidth + 1);
   if ( c ) entry = c;
@@ -149,18 +150,35 @@ char *make_sidebar_entry(char *box, int size, int new)
     }
   }
 #endif
-  if (option(OPTSHORTENHIERARCHY)) {
+  max -= quick_log10(size);
+  if (new)
+    max -= quick_log10(new) + 2;
+  if (flagged > 0)
+    max -= quick_log10(flagged) + 2;
+  if (option(OPTSHORTENHIERARCHY) && mutt_strlen(box) > max) {
     box = shortened_hierarchy(box);
+    shortened = 1;
   }
   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)) {
+  if ( new ) {
+    if (flagged>0) {
+      sprintf(entry + SidebarWidth - 5 - quick_log10(size) - dlen - quick_log10(new) - quick_log10(flagged),
+              "% d(%d)[%d]", size, new, flagged);
+    } else {
+      sprintf(entry + SidebarWidth - 3 - quick_log10(size) - dlen - quick_log10(new),
+              "% d(%d)", size, new);
+    }
+  } else {
+    if (flagged>0) {
+      sprintf( entry + SidebarWidth - 3 - quick_log10(size) - dlen - quick_log10(flagged), "% d[%d]", size,flagged);
+    } else {
+      sprintf( entry + SidebarWidth - 1 - quick_log10(size) - dlen, "% d", size);
+    }
+
+  }
+  if (option(OPTSHORTENHIERARCHY) && shortened) {
     free(box);
   }
   return entry;
@@ -195,6 +213,7 @@ void set_buffystats (CONTEXT* Context)
     {
       tmp->msg_unread = Context->unread;
       tmp->msgcount = Context->msgcount;
+      tmp->msg_flagged = Context->flagged;
       break;
     }
     tmp = tmp->next;
@@ -252,6 +271,8 @@ int draw_sidebar(int menu) {
   for ( ; tmp && lines < LINES-1 - (menu != MENU_PAGER || option (OPTSTATUSONTOP)); tmp = tmp->next ) {
     if ( tmp == CurBuffy )
       SETCOLOR(MT_COLOR_INDICATOR);
+    else if ( tmp->msg_flagged > 0 )
+      SETCOLOR(MT_COLOR_FLAGGED);
     else if ( tmp->msg_unread > 0 )
       SETCOLOR(MT_COLOR_NEW);
     else
@@ -261,14 +282,15 @@ int draw_sidebar(int menu) {
     if ( Context && !strcmp( tmp->path, Context->path ) ) {
       printw( "%.*s", SidebarWidth - delim_len,
               make_sidebar_entry(basename(tmp->path),
-                                 Context->msgcount, Context->unread));
+                                 Context->msgcount, Context->unread, Context->flagged));
       tmp->msg_unread = Context->unread;
       tmp->msgcount = Context->msgcount;
+      tmp->msg_flagged = Context->flagged;
     }
     else
       printw( "%.*s", SidebarWidth - delim_len,
               make_sidebar_entry(basename(tmp->path),
-                                 tmp->msgcount,tmp->msg_unread));
+                                 tmp->msgcount,tmp->msg_unread, tmp->msg_flagged));
     lines++;
   }
   SETCOLOR(MT_COLOR_NORMAL);