X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=sidebar.c;h=ebc1a64d63309b9c280de575501fc6ea151f35b7;hp=4f5d17c05646296caac92f350abae1969620c188;hb=643be053e447a35cccc37550ac0087bb5bb5c5ad;hpb=fd204cba10834057df23ba10458d4095b424e964;ds=sidebyside diff --git a/sidebar.c b/sidebar.c index 4f5d17c..ebc1a64 100644 --- 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, int tagged) +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,29 +150,35 @@ char *make_sidebar_entry(char *box, int size, int new, int tagged) } } #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 ) { - if (tagged>0) { - sprintf(entry + SidebarWidth - 5 - quick_log10(size) - dlen - quick_log10(new) - quick_log10(tagged), - "% d(%d)[%d]", size, new, tagged); + 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 (tagged>0) { - sprintf( entry + SidebarWidth - 3 - quick_log10(size) - dlen - quick_log10(tagged), "% d[%d]", size,tagged); + 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)) { + if (option(OPTSHORTENHIERARCHY) && shortened) { free(box); } return entry; @@ -200,13 +207,15 @@ void set_curbuffy(char buf[LONG_STRING]) void set_buffystats (CONTEXT* Context) { BUFFY* tmp = Incoming; + if (!Context) + return; while (tmp) { if (strcmp (tmp->path, Context->path) == 0) { tmp->msg_unread = Context->unread; tmp->msgcount = Context->msgcount; - tmp->msg_tagged = Context->flagged; + tmp->msg_flagged = Context->flagged; break; } tmp = tmp->next; @@ -264,6 +273,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 @@ -273,15 +284,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->tagged)); + Context->msgcount, Context->unread, Context->flagged)); tmp->msg_unread = Context->unread; tmp->msgcount = Context->msgcount; - tmp->msg_tagged = Context->tagged; + tmp->msg_flagged = Context->flagged; } else printw( "%.*s", SidebarWidth - delim_len, make_sidebar_entry(basename(tmp->path), - tmp->msgcount,tmp->msg_unread, tmp->msg_tagged)); + tmp->msgcount,tmp->msg_unread, tmp->msg_flagged)); lines++; } SETCOLOR(MT_COLOR_NORMAL); @@ -294,24 +305,58 @@ int draw_sidebar(int menu) { return 0; } +BUFFY * exist_next_new() +{ + BUFFY *tmp = CurBuffy; + if(tmp == NULL) return NULL; + while (tmp->next != NULL) + { + tmp = tmp->next; + if(tmp->msg_unread) return tmp; + } + return NULL; +} + +BUFFY * exist_prev_new() +{ + BUFFY *tmp = CurBuffy; + if(tmp == NULL) return NULL; + while (tmp->prev != NULL) + { + tmp = tmp->prev; + if(tmp->msg_unread) return tmp; + } + return NULL; +} + + void scroll_sidebar(int op, int menu) { - if(!SidebarWidth) return; - if(!CurBuffy) return; + BUFFY *tmp; + + if(!SidebarWidth) return; + if(!CurBuffy) return; switch (op) { case OP_SIDEBAR_NEXT: if ( CurBuffy->next == NULL ) return; CurBuffy = CurBuffy->next; break; + case OP_SIDEBAR_NEXT_NEW: + if ( (tmp = exist_next_new()) == NULL) + return; + else CurBuffy = tmp; + 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; - } + if ( CurBuffy->prev == NULL ) return; + CurBuffy = CurBuffy->prev; + break; + case OP_SIDEBAR_PREV_NEW: + if ( (tmp = exist_prev_new()) == NULL) + return; + else CurBuffy = tmp; break; + case OP_SIDEBAR_SCROLL_UP: CurBuffy = TopBuffy; if ( CurBuffy != Incoming ) {