X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-ui%2Fsidebar.c;h=6ba8471ad66bcb2954a2c23fff5aa45d82d6d742;hp=48e4360e594d786ec5ab18edfb066da2e7f21aae;hb=5dcac54e5db074dc4572f843666c7f7acaf2d109;hpb=1eeaaac6bdcad962c41bf975a32078cc4a0e578c diff --git a/lib-ui/sidebar.c b/lib-ui/sidebar.c index 48e4360..6ba8471 100644 --- a/lib-ui/sidebar.c +++ b/lib-ui/sidebar.c @@ -12,10 +12,9 @@ * please see the file GPL in the top level source directory. */ -#include +#include #include -#include #include #include @@ -26,31 +25,32 @@ static int TopBuffy = 0; static int CurBuffy = 0; -static int known_lines = 0; static short initialized = 0; static short prev_show_value; /* computes first entry to be shown */ -static void calc_boundaries (void) { - if (!Incoming.len) - return; - if (CurBuffy < 0 || CurBuffy >= Incoming.len) - CurBuffy = 0; - if (TopBuffy < 0 || TopBuffy >= Incoming.len) - TopBuffy = 0; - - if (option (OPTSIDEBARNEWMAILONLY)) { - int i = CurBuffy; - TopBuffy = CurBuffy - 1; - while (i >= 0) { - if (Incoming.arr[i]->new > 0) - TopBuffy = i; - i--; +static void calc_boundaries(void) +{ + if (!Incoming.len) + return; + if (CurBuffy < 0 || CurBuffy >= Incoming.len) + CurBuffy = 0; + if (TopBuffy < 0 || TopBuffy >= Incoming.len) + TopBuffy = 0; + + if (option (OPTSIDEBARNEWMAILONLY)) { + int i = CurBuffy; + TopBuffy = CurBuffy - 1; + while (i >= 0) { + if (Incoming.arr[i]->new > 0) + TopBuffy = i; + i--; + } + } else { + TopBuffy = CurBuffy - (CurBuffy % (LINES - 3)); } - } else if (known_lines>0) - TopBuffy = CurBuffy - (CurBuffy % known_lines); - if (TopBuffy < 0) - TopBuffy = 0; + if (TopBuffy < 0) + TopBuffy = 0; } static char *shortened_hierarchy (char *hbox, int maxlen) @@ -92,12 +92,14 @@ static char *shortened_hierarchy (char *hbox, int maxlen) return m_strdup(hbox); } -static const char* sidebar_number_format (char* dest, ssize_t destlen, char op, - const char* src, const char* fmt, - const char* ifstr, const char* elstr, - unsigned long data, format_flag flags) { +static const char * +sidebar_number_format(char* dest, ssize_t destlen, + char op, const char* src, const char* fmt, + const char* ifstr, const char* elstr, + anytype data, format_flag flags) +{ char tmp[STRING]; - BUFFY* b = Incoming.arr[data]; + BUFFY* b = Incoming.arr[data.i]; int opt = flags & M_FORMAT_OPTIONAL; int c = Context && !m_strcmp(Context->path, b->path); @@ -162,20 +164,16 @@ static const char* sidebar_number_format (char* dest, ssize_t destlen, char op, break; } - if (opt) - m_strformat (dest, destlen, ifstr, sidebar_number_format, - data, M_FORMAT_OPTIONAL); - else if (flags & M_FORMAT_OPTIONAL) - m_strformat (dest, destlen, elstr, sidebar_number_format, - data, M_FORMAT_OPTIONAL); - return (src); + if (flags & M_FORMAT_OPTIONAL) + m_strformat(dest, destlen, 0, opt ? ifstr : elstr, + sidebar_number_format, data, flags); + return src; } -int sidebar_need_count (void) { - if (!option (OPTMBOXPANE) || SidebarWidth == 0 || - !SidebarNumberFormat || !*SidebarNumberFormat) - return (0); - return (1); +int sidebar_need_count(void) +{ + return ui_layout_sidebar_w() + && !m_strisempty(SidebarNumberFormat); } /* print single item @@ -183,56 +181,46 @@ int sidebar_need_count (void) { * 0 item was not printed ('cause of $sidebar_newmail_only) * 1 item was printed */ -static int make_sidebar_entry (char* sbox, int idx, ssize_t len) +static int make_sidebar_entry(WINDOW *sw, char *sbox, int idx, ssize_t len) { - int shortened = 0, lencnt = 0; - char no[STRING], entry[STRING]; - int l = m_strlen(ImapHomeNamespace); - int l_m = m_strlen(Maildir); - - if (SidebarWidth > COLS) - SidebarWidth = COLS; - - if (option (OPTSIDEBARNEWMAILONLY) && sbox && Context && Context->path && - m_strcmp(Context->path, sbox) && Incoming.arr[idx]->new == 0) - /* if $sidebar_newmail_only is set, don't display the - * box only if it's not the currently opened - * (i.e. always display the currently opened) */ - return (0); - - m_strformat (no, len, NONULL (SidebarNumberFormat), - sidebar_number_format, idx, M_FORMAT_OPTIONAL); - lencnt = m_strlen(no); - memset(&entry, ' ', sizeof(entry)); - - if (l > 0 && m_strncmp(sbox, ImapHomeNamespace, l) == 0 && - m_strlen(sbox) > l) - sbox += l + 1; /* we're trimming the ImapHomeNamespace, the "+ 1" is for the separator */ - else - if (l_m > 0 && m_strncmp(sbox, Maildir, l_m) == 0 && - m_strlen(sbox) > l_m) { - sbox += l_m; - if (Maildir[strlen(Maildir)-1]!='/') { - sbox += 1; + int shortened = 0, lencnt = 0; + char no[STRING], entry[STRING]; + int l_m = m_strlen(Maildir); + + if (option(OPTSIDEBARNEWMAILONLY) && sbox && Context && Context->path && + m_strcmp(Context->path, sbox) && Incoming.arr[idx]->new == 0) + /* if $sidebar_newmail_only is set, don't display the + * box only if it's not the currently opened + * (i.e. always display the currently opened) */ + return 0; + + m_strformat(no, sizeof(no), len, SidebarNumberFormat, + sidebar_number_format, idx, 0); + lencnt = m_strlen(no); + + if (l_m > 0 && m_strncmp(sbox, Maildir, l_m) == 0 && + m_strlen(sbox) > l_m) { + sbox += l_m; + if (Maildir[strlen(Maildir)-1]!='/') { + sbox += 1; + } + } else { + sbox = basename(sbox); } - } else - sbox = basename (sbox); - if (option (OPTSHORTENHIERARCHY) && m_strlen(sbox) > len-lencnt-1) { - sbox = shortened_hierarchy (sbox, len-lencnt-1); - shortened = 1; - } - - m_strcpy(entry, len - lencnt, sbox); - entry[m_strlen(entry)] = ' '; - memcpy(entry + (len - lencnt), no, lencnt); + if (option(OPTSHORTENHIERARCHY) && m_strlen(sbox) > len - lencnt) { + sbox = shortened_hierarchy(sbox, len - lencnt); + shortened = 1; + } - addnstr (entry, len); + snprintf(entry, sizeof(entry), "%*s", (int)len, no); + memcpy(entry, sbox, MIN(len, m_strlen(sbox))); + waddnstr(sw, entry, len); - if (shortened) - p_delete(&sbox); + if (shortened) + p_delete(&sbox); - return (1); + return 1; } /* returns folder name of currently @@ -268,128 +256,80 @@ void sidebar_set_buffystats (CONTEXT* curContext) { tmp->msg_flagged = curContext->flagged; } -void sidebar_draw_frames (void) { - ssize_t i,delim_len; - - if (!option(OPTMBOXPANE) || SidebarWidth==0) - return; - - delim_len=m_strlen(NONULL(SidebarDelim)); - - /* draw vertical delimiter */ - SETCOLOR (MT_COLOR_SIDEBAR); - for (i = 0; i < LINES-1; i++) { - move (i, SidebarWidth - delim_len); - if (option (OPTASCIICHARS)) - addstr (NONULL (SidebarDelim)); - else if (!option (OPTASCIICHARS) && !m_strcmp(SidebarDelim, "|")) - addch (ACS_VLINE); - else if ((Charset_is_utf8) && !m_strcmp(SidebarDelim, "|")) - addstr ("\342\224\202"); - else - addstr (NONULL (SidebarDelim)); - } - - /* fill "gaps" at top+bottom */ - SETCOLOR(MT_COLOR_STATUS); - for (i=0; i 0 && option (OPTMBOXPANE) - && m_strlen(SidebarDelim) >= SidebarWidth) { - mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar.")); - sleep (2); - unset_option (OPTMBOXPANE); - return (0); - } + sw = ui_layout_sidebar_w(); + if (!sw) + return 0; + getmaxyx(sw, y, x); + + memset(&blank, ' ', sizeof(blank)); + + wmove(sw, 0, 0); + WSETCOLOR(sw, MT_COLOR_STATUS); + waddnstr(sw, blank, x); + + for (i = TopBuffy, line = 1; i < Incoming.len && line < y; i++) { + BUFFY *tmp = Incoming.arr[i]; + + if (i == CurBuffy) + WSETCOLOR(sw, MT_COLOR_INDICATOR); + else if (tmp->new > 0) + WSETCOLOR(sw, MT_COLOR_NEW); + else if (tmp->msg_flagged > 0) + WSETCOLOR(sw, MT_COLOR_FLAGGED); + else + WSETCOLOR(sw, MT_COLOR_NORMAL); + + if (make_sidebar_entry(sw, tmp->path, i, x - 1)) { + WSETCOLOR(sw, MT_COLOR_SIDEBAR); + waddch(sw, ACS_VLINE); + line++; + } + } - if (SidebarWidth == 0 || !option (OPTMBOXPANE)) - return 0; + while (line < y - 1) { + WSETCOLOR(sw, MT_COLOR_NORMAL); + waddnstr(sw, blank, x - 1); + WSETCOLOR(sw, MT_COLOR_SIDEBAR); + waddch(sw, ACS_VLINE); + line++; + } - sidebar_draw_frames(); + WSETCOLOR(sw, MT_COLOR_STATUS); + waddnstr(sw, blank, x); + WSETCOLOR(sw, MT_COLOR_NORMAL); - if (!Incoming.len) return 0; - - /* actually print items */ - for (i = TopBuffy, line=first_line; i < Incoming.len && line < last_line; i++) { - tmp = Incoming.arr[i]; - - if (i == CurBuffy) - SETCOLOR (MT_COLOR_INDICATOR); - else if (tmp->new > 0) - SETCOLOR (MT_COLOR_NEW); - else if (tmp->msg_flagged > 0) - SETCOLOR (MT_COLOR_FLAGGED); - else - SETCOLOR (MT_COLOR_NORMAL); - - move (line, 0); - line += make_sidebar_entry (tmp->path, i, SidebarWidth-delim_len); - } - - SETCOLOR (MT_COLOR_NORMAL); - - /* fill with blanks to bottom */ - memset(&blank, ' ', sizeof(blank)); - for (; line < last_line; line++) { - move (line, 0); - addnstr (blank, SidebarWidth-delim_len); - } - return 0; } /* returns index of new item with new mail or -1 */ -static int exist_next_new () { +static int exist_next_new (void) { int i = 0; if (!Incoming.len) return (-1); @@ -401,7 +341,7 @@ static int exist_next_new () { } /* returns index of prev item with new mail or -1 */ -static int exist_prev_new () { +static int exist_prev_new (void) { int i = 0; if (!Incoming.len) return (-1); @@ -459,7 +399,7 @@ void sidebar_scroll (int op) { mutt_error (_("You are on the first mailbox.")); return; } - CurBuffy -= known_lines; + CurBuffy -= LINES - 3; if (CurBuffy < 0) CurBuffy = 0; break; @@ -468,7 +408,7 @@ void sidebar_scroll (int op) { mutt_error (_("You are on the last mailbox.")); return; } - CurBuffy += known_lines; + CurBuffy += LINES - 3; if (CurBuffy >= Incoming.len) CurBuffy = Incoming.len - 1; break;