X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-ui%2Fsidebar.c;h=238a5dd1b34e12532b1af5b8db0fd650a960b060;hp=a83505c3c8c18b3ac23d990aed9cb56140116ff9;hb=f435868132e200bfa71ac155f037cf64bf5414ba;hpb=98cf5779d8184a74541be1bc61d15c5f35efd310;ds=sidebyside diff --git a/lib-ui/sidebar.c b/lib-ui/sidebar.c index a83505c..238a5dd 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 @@ -32,18 +31,18 @@ static short prev_show_value; /* computes first entry to be shown */ static void calc_boundaries (void) { - if (list_empty(Incoming)) + if (!Incoming.len) return; - if (CurBuffy < 0 || CurBuffy >= Incoming->length) + if (CurBuffy < 0 || CurBuffy >= Incoming.len) CurBuffy = 0; - if (TopBuffy < 0 || TopBuffy >= Incoming->length) + if (TopBuffy < 0 || TopBuffy >= Incoming.len) TopBuffy = 0; if (option (OPTSIDEBARNEWMAILONLY)) { int i = CurBuffy; TopBuffy = CurBuffy - 1; while (i >= 0) { - if (((BUFFY*) Incoming->data[i])->new > 0) + if (Incoming.arr[i]->new > 0) TopBuffy = i; i--; } @@ -82,7 +81,7 @@ static char *shortened_hierarchy (char *hbox, int maxlen) new_box[j++] = hbox[i + 1]; new_box[j] = 0; } else { - strcat (&new_box[j], last_dot); + m_strcat(&new_box[j], maxlen + 1, last_dot); break; } } @@ -92,12 +91,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) { - char tmp[SHORT_STRING]; - BUFFY* b = (BUFFY*) Incoming->data[data]; +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.i]; int opt = flags & M_FORMAT_OPTIONAL; int c = Context && !m_strcmp(Context->path, b->path); @@ -162,13 +163,10 @@ static const char* sidebar_number_format (char* dest, ssize_t destlen, char op, break; } - if (opt) - mutt_FormatString (dest, destlen, ifstr, sidebar_number_format, - data, M_FORMAT_OPTIONAL); - else if (flags & M_FORMAT_OPTIONAL) - mutt_FormatString (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) { @@ -186,29 +184,22 @@ int sidebar_need_count (void) { static int make_sidebar_entry (char* sbox, int idx, ssize_t len) { int shortened = 0, lencnt = 0; - char no[SHORT_STRING], entry[SHORT_STRING]; - int l = m_strlen(ImapHomeNamespace); + char no[STRING], entry[STRING]; int l_m = m_strlen(Maildir); if (SidebarWidth > COLS) SidebarWidth = COLS; if (option (OPTSIDEBARNEWMAILONLY) && sbox && Context && Context->path && - m_strcmp(Context->path, sbox) && ((BUFFY*) Incoming->data[idx])->new == 0) + 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); + return 0; - mutt_FormatString (no, len, NONULL (SidebarNumberFormat), - sidebar_number_format, idx, M_FORMAT_OPTIONAL); + m_strformat(no, len, SidebarWidth, SidebarNumberFormat, sidebar_number_format, idx, 0); 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; @@ -218,30 +209,28 @@ static int make_sidebar_entry (char* sbox, int idx, ssize_t len) } else sbox = basename (sbox); - if (option (OPTSHORTENHIERARCHY) && m_strlen(sbox) > len-lencnt-1) { + 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); - - addnstr (entry, len); + snprintf(entry, sizeof(entry), "%*s", (int)len, no); + memcpy(entry, sbox, MIN(len - 1, m_strlen(sbox))); + waddnstr(stdscr, entry, len); if (shortened) p_delete(&sbox); - return (1); + return 1; } /* returns folder name of currently * selected folder for */ const char* sidebar_get_current (void) { - if (list_empty(Incoming)) + if (!Incoming.len) return (NULL); - return ((char*) ((BUFFY*) Incoming->data[CurBuffy])->path); + return Incoming.arr[CurBuffy]->path; } /* internally sets item to buf */ @@ -259,9 +248,9 @@ void sidebar_set_current (const char* buf) { void sidebar_set_buffystats (CONTEXT* curContext) { int i = 0; BUFFY* tmp = NULL; - if (!curContext || list_empty(Incoming) || (i = buffy_lookup (curContext->path)) < 0) + if (!curContext || !Incoming.len || (i = buffy_lookup (curContext->path)) < 0) return; - tmp = Incoming->data[i]; + tmp = Incoming.arr[i]; tmp->new = curContext->new; tmp->msg_unread = curContext->unread; tmp->msgcount = curContext->msgcount; @@ -279,15 +268,11 @@ void sidebar_draw_frames (void) { /* 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"); + wmove (stdscr, i, SidebarWidth - delim_len); + if (!m_strcmp(SidebarDelim, "|")) + waddch (stdscr, ACS_VLINE); else - addstr (NONULL (SidebarDelim)); + waddstr (stdscr, NONULL (SidebarDelim)); } /* fill "gaps" at top+bottom */ @@ -298,16 +283,16 @@ void sidebar_draw_frames (void) { * gap with spaces to get bg color */ if (option(OPTSTATUSONTOP) || option(OPTHELP)) { - move(0,i); - addch(' '); + wmove(stdscr, 0,i); + waddch(stdscr, ' '); } /* * if we don't have $status_on_top or we have $help, fill bottom * gap with spaces to get bg color */ if (!option(OPTSTATUSONTOP) || option(OPTHELP)) { - move(LINES-2,i); - addch(' '); + wmove(stdscr, LINES-2,i); + waddch(stdscr, ' '); } } SETCOLOR (MT_COLOR_NORMAL); @@ -322,7 +307,7 @@ int sidebar_draw (void) { i = 0,line; BUFFY *tmp; ssize_t delim_len = m_strlen(SidebarDelim); - char blank[SHORT_STRING]; + char blank[STRING]; known_lines=last_line-first_line; @@ -357,12 +342,12 @@ int sidebar_draw (void) { sidebar_draw_frames(); - if (list_empty(Incoming)) + if (!Incoming.len) return 0; /* actually print items */ - for (i = TopBuffy, line=first_line; i < Incoming->length && line < last_line; i++) { - tmp = (BUFFY*) Incoming->data[i]; + for (i = TopBuffy, line=first_line; i < Incoming.len && line < last_line; i++) { + tmp = Incoming.arr[i]; if (i == CurBuffy) SETCOLOR (MT_COLOR_INDICATOR); @@ -373,7 +358,7 @@ int sidebar_draw (void) { else SETCOLOR (MT_COLOR_NORMAL); - move (line, 0); + wmove (stdscr, line, 0); line += make_sidebar_entry (tmp->path, i, SidebarWidth-delim_len); } @@ -382,8 +367,8 @@ int sidebar_draw (void) { /* fill with blanks to bottom */ memset(&blank, ' ', sizeof(blank)); for (; line < last_line; line++) { - move (line, 0); - addnstr (blank, SidebarWidth-delim_len); + wmove (stdscr, line, 0); + waddnstr (stdscr, blank, SidebarWidth-delim_len); } return 0; } @@ -391,11 +376,11 @@ int sidebar_draw (void) { /* returns index of new item with new mail or -1 */ static int exist_next_new () { int i = 0; - if (list_empty(Incoming)) + if (!Incoming.len) return (-1); i = CurBuffy + 1; - while (i < Incoming->length) - if (((BUFFY*) Incoming->data[i++])->new > 0) + while (i < Incoming.len) + if (Incoming.arr[i++]->new > 0) return (i-1); return (-1); } @@ -403,11 +388,11 @@ static int exist_next_new () { /* returns index of prev item with new mail or -1 */ static int exist_prev_new () { int i = 0; - if (list_empty(Incoming)) + if (!Incoming.len) return (-1); i = CurBuffy - 1; while (i >= 0) - if (((BUFFY*) Incoming->data[i--])->new > 0) + if (Incoming.arr[i--]->new > 0) return (i+1); return (-1); } @@ -415,13 +400,13 @@ static int exist_prev_new () { void sidebar_scroll (int op) { int i = 0; - if (!SidebarWidth || list_empty(Incoming)) + if (!SidebarWidth || !Incoming.len) return; switch (op) { case OP_SIDEBAR_NEXT: if (!option (OPTSIDEBARNEWMAILONLY)) { - if (CurBuffy + 1 == Incoming->length) { + if (CurBuffy + 1 == Incoming.len) { mutt_error (_("You are on the last mailbox.")); return; } @@ -464,13 +449,13 @@ void sidebar_scroll (int op) { CurBuffy = 0; break; case OP_SIDEBAR_SCROLL_DOWN: - if (CurBuffy + 1 == Incoming->length) { + if (CurBuffy + 1 == Incoming.len) { mutt_error (_("You are on the last mailbox.")); return; } CurBuffy += known_lines; - if (CurBuffy >= Incoming->length) - CurBuffy = Incoming->length - 1; + if (CurBuffy >= Incoming.len) + CurBuffy = Incoming.len - 1; break; default: return;