2 * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
3 * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 #include "mutt_menu.h"
24 #include "mutt_curses.h"
31 /*BUFFY *CurBuffy = 0;*/
32 static BUFFY *TopBuffy = 0;
33 static BUFFY *BottomBuffy = 0;
34 static int known_lines = 0;
36 static int quick_log10(int n)
39 sprintf(string, "%d", n);
40 return strlen(string);
43 void calc_boundaries (int menu)
45 BUFFY *tmp = Incoming;
47 if ( known_lines != LINES ) {
48 TopBuffy = BottomBuffy = 0;
51 for ( ; tmp->next != 0; tmp = tmp->next )
52 tmp->next->prev = tmp;
54 if ( TopBuffy == 0 && BottomBuffy == 0 )
56 if ( BottomBuffy == 0 ) {
57 int count = LINES - 2 - (menu != MENU_PAGER);
58 BottomBuffy = TopBuffy;
59 while ( --count && BottomBuffy->next )
60 BottomBuffy = BottomBuffy->next;
62 else if ( TopBuffy == CurBuffy->next ) {
63 int count = LINES - 2 - (menu != MENU_PAGER);
64 BottomBuffy = CurBuffy;
66 while ( --count && tmp->prev)
70 else if ( BottomBuffy == CurBuffy->prev ) {
71 int count = LINES - 2 - (menu != MENU_PAGER);
74 while ( --count && tmp->next )
80 char *make_sidebar_entry(char *box, int size, int new)
82 static char *entry = 0;
86 c = realloc(entry, SidebarWidth + 1);
88 entry[SidebarWidth] = 0;
89 for (; i < SidebarWidth; entry[i++] = ' ' );
91 if (ImapHomeNamespace && strlen(ImapHomeNamespace)>0) {
92 if (strncmp(box,ImapHomeNamespace,strlen(ImapHomeNamespace))==0 && strcmp(box,ImapHomeNamespace)!=0) {
93 box+=strlen(ImapHomeNamespace)+1;
98 strncpy( entry, box, i < SidebarWidth ? i :SidebarWidth );
102 entry + SidebarWidth - 5 - quick_log10(size) - quick_log10(new),
103 "% d(%d)", size, new);
105 sprintf( entry + SidebarWidth - 3 - quick_log10(size), "% d", size);
109 void set_curbuffy(char buf[LONG_STRING])
111 BUFFY* tmp = CurBuffy = Incoming;
117 if(!strcmp(tmp->path, buf)) {
129 int draw_sidebar(int menu) {
131 int lines = option(OPTHELP) ? 1 : 0;
133 #ifndef USE_SLANG_CURSES
138 static bool initialized = false;
139 static int prev_show_value;
140 static short saveSidebarWidth;
142 /* initialize first time */
144 prev_show_value = option(OPTMBOXPANE);
145 saveSidebarWidth = SidebarWidth;
146 if(!option(OPTMBOXPANE)) SidebarWidth = 0;
150 /* save or restore the value SidebarWidth */
151 if(prev_show_value != option(OPTMBOXPANE)) {
152 if(prev_show_value && !option(OPTMBOXPANE)) {
153 saveSidebarWidth = SidebarWidth;
155 } else if(!prev_show_value && option(OPTMBOXPANE)) {
156 SidebarWidth = saveSidebarWidth;
158 prev_show_value = option(OPTMBOXPANE);
162 if ( SidebarWidth == 0 ) return 0;
164 /* get attributes for divider */
165 SETCOLOR(MT_COLOR_STATUS);
166 #ifndef USE_SLANG_CURSES
167 attr_get(&attrs, &color_pair, 0);
169 color_pair = attr_get();
171 SETCOLOR(MT_COLOR_NORMAL);
173 /* draw the divider */
175 for ( ; lines < LINES-1-(menu != MENU_PAGER); lines++ ) {
176 move(lines, SidebarWidth - 1);
178 #ifndef USE_SLANG_CURSES
179 mvchgat(lines, SidebarWidth - 1, 1, 0, color_pair, NULL);
182 if ( Incoming == 0 ) return 0;
183 lines = option(OPTHELP) ? 1 : 0; /* go back to the top */
185 if ( known_lines != LINES || TopBuffy == 0 || BottomBuffy == 0 )
186 calc_boundaries(menu);
187 if ( CurBuffy == 0 ) CurBuffy = Incoming;
191 SETCOLOR(MT_COLOR_NORMAL);
193 for ( ; tmp && lines < LINES-1 - (menu != MENU_PAGER); tmp = tmp->next ) {
194 if ( tmp == CurBuffy )
195 SETCOLOR(MT_COLOR_INDICATOR);
196 else if ( tmp->msg_unread > 0 )
197 SETCOLOR(MT_COLOR_NEW);
199 SETCOLOR(MT_COLOR_NORMAL);
202 if ( Context && !strcmp( tmp->path, Context->path ) ) {
203 printw( "%.*s", SidebarWidth,
204 make_sidebar_entry(basename(tmp->path), Context->msgcount,
206 tmp->msg_unread = Context->unread;
207 tmp->msgcount = Context->msgcount;
210 printw( "%.*s", SidebarWidth,
211 make_sidebar_entry(basename(tmp->path), tmp->msgcount,
215 SETCOLOR(MT_COLOR_NORMAL);
216 for ( ; lines < LINES - 1 - (menu != MENU_PAGER); lines++ ) {
219 for ( ; i < SidebarWidth - 1; i++ )
225 void scroll_sidebar(int op, int menu)
227 if(!SidebarWidth) return;
228 if(!CurBuffy) return;
231 case OP_SIDEBAR_NEXT:
232 if ( CurBuffy->next == NULL ) return;
233 CurBuffy = CurBuffy->next;
235 case OP_SIDEBAR_PREV:
236 if ( CurBuffy == Incoming ) return;
238 BUFFY *tmp = Incoming;
239 while ( tmp->next && strcmp(tmp->next->path, CurBuffy->path) ) tmp = tmp->next;
243 case OP_SIDEBAR_SCROLL_UP:
245 if ( CurBuffy != Incoming ) {
246 calc_boundaries(menu);
247 CurBuffy = CurBuffy->prev;
250 case OP_SIDEBAR_SCROLL_DOWN:
251 CurBuffy = BottomBuffy;
252 if ( CurBuffy->next ) {
253 calc_boundaries(menu);
254 CurBuffy = CurBuffy->next;
260 calc_boundaries(menu);