2 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
20 #include "mutt_menu.h"
21 #include "mutt_curses.h"
30 static char *get_sort_str (char *buf, size_t buflen, int method)
32 snprintf (buf, buflen, "%s%s%s",
33 (method & SORT_REVERSE) ? "reverse-" : "",
34 (method & SORT_LAST) ? "last-" : "",
35 mutt_getnamebyvalue (method & SORT_MASK, SortMethods));
39 /* %b = number of incoming folders with unread messages [option]
40 * %d = number of deleted messages [option]
41 * %f = full mailbox path
42 * %F = number of flagged messages [option]
44 * %l = length of mailbox (in bytes) [option]
45 * %m = total number of messages [option]
46 * %M = number of messages shown (virutal message count when limiting) [option]
47 * %n = number of new messages [option]
48 * %p = number of postponed messages [option]
49 * %P = percent of way through index
50 * %r = readonly/wontwrite/changed flag
51 * %s = current sorting method ($sort)
52 * %S = current aux sorting method ($sort_aux)
53 * %t = # of tagged messages [option]
55 * %V = currently active limit pattern [option] */
57 status_format_str (char *buf, size_t buflen, char op, const char *src,
58 const char *prefix, const char *ifstring,
59 const char *elsestring,
60 unsigned long data, format_flag flags)
62 char fmt[SHORT_STRING], tmp[SHORT_STRING], *cp;
63 int count, optional = (flags & M_FORMAT_OPTIONAL);
64 MUTTMENU *menu = (MUTTMENU *) data;
72 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
73 snprintf (buf, buflen, fmt, mutt_buffy_check (0));
75 else if (!mutt_buffy_check (0))
82 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
83 snprintf (buf, buflen, fmt, Context ? Context->deleted : 0);
85 else if (!Context || !Context->deleted)
90 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
91 snprintf (buf, buflen, fmt, NONULL(Hostname));
95 snprintf (fmt, sizeof(fmt), "%%%ss", prefix);
96 if (Context && Context->path)
98 strfcpy (tmp, Context->path, sizeof (tmp));
99 mutt_pretty_mailbox (tmp);
102 strfcpy (tmp, _("(no mailbox)"), sizeof (tmp));
103 snprintf (buf, buflen, fmt, tmp);
109 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
110 snprintf (buf, buflen, fmt, Context ? Context->flagged : 0);
112 else if (!Context || !Context->flagged)
119 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
120 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->size : 0);
121 snprintf (buf, buflen, fmt, tmp);
123 else if (!Context || !Context->size)
130 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
131 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->vsize: 0);
132 snprintf (buf, buflen, fmt, tmp);
134 else if (!Context || !Context->pattern)
141 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
142 snprintf (buf, buflen, fmt, Context ? Context->msgcount : 0);
144 else if (!Context || !Context->msgcount)
151 snprintf (fmt, sizeof(fmt), "%%%sd", prefix);
152 snprintf (buf, buflen, fmt, Context ? Context->vcount : 0);
154 else if (!Context || !Context->pattern)
161 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
162 snprintf (buf, buflen, fmt, Context ? Context->new : 0);
164 else if (!Context || !Context->new)
171 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
172 snprintf (buf, buflen, fmt, Context ? Context->unread - Context->new : 0);
174 else if (!Context || !(Context->unread - Context->new))
179 count = mutt_num_postponed (0);
182 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
183 snprintf (buf, buflen, fmt, count);
190 if (menu->top + menu->pagelen >= menu->max)
191 cp = menu->top ? "end" : "all";
194 count = (100 * (menu->top + menu->pagelen)) / menu->max;
195 snprintf (tmp, sizeof (tmp), "%d%%", count);
198 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
199 snprintf (buf, buflen, fmt, cp);
208 i = option(OPTATTACHMSG) ? 3 : ((Context->readonly ||
209 Context->dontwrite) ? 2 : (Context->changed || (
211 /* deleted doesn't necessarily mean changed in IMAP */
212 Context->magic != M_IMAP &&
214 Context->deleted)) ? 1 : 0);
219 else if (i >= mutt_strlen(StChars))
229 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
230 snprintf (buf, buflen, fmt,
231 get_sort_str (tmp, sizeof (tmp), Sort));
235 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
236 snprintf (buf, buflen, fmt,
237 get_sort_str (tmp, sizeof (tmp), SortAux));
243 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
244 snprintf (buf, buflen, fmt, Context ? Context->tagged : 0);
246 else if (!Context || !Context->tagged)
253 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
254 snprintf (buf, buflen, fmt, Context ? Context->unread : 0);
256 else if (!Context || !Context->unread)
261 snprintf (fmt, sizeof (fmt), "Mutt %%s");
262 snprintf (buf, buflen, fmt, MUTT_VERSION);
268 snprintf (fmt, sizeof(fmt), "%%%ss", prefix);
269 snprintf (buf, buflen, fmt, Context ? Context->pattern : 0);
271 else if (!Context || !Context->pattern)
280 snprintf (buf, buflen, "%%%s%c", prefix, op);
285 menu_status_line (buf, buflen, menu, ifstring);
286 else if (flags & M_FORMAT_OPTIONAL)
287 menu_status_line (buf, buflen, menu, elsestring);
292 void menu_status_line (char *buf, size_t buflen, MUTTMENU *menu, const char *p)
294 mutt_FormatString (buf, buflen, p, status_format_str, (unsigned long) menu, 0);