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);
97 if (Context && Context->compressinfo && Context->realpath)
99 strfcpy (tmp, Context->realpath, sizeof (tmp));
100 mutt_pretty_mailbox (tmp);
104 if (Context && Context->path)
106 strfcpy (tmp, Context->path, sizeof (tmp));
107 mutt_pretty_mailbox (tmp);
110 strfcpy (tmp, _("(no mailbox)"), sizeof (tmp));
111 snprintf (buf, buflen, fmt, tmp);
117 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
118 snprintf (buf, buflen, fmt, Context ? Context->flagged : 0);
120 else if (!Context || !Context->flagged)
127 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
128 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->size : 0);
129 snprintf (buf, buflen, fmt, tmp);
131 else if (!Context || !Context->size)
138 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
139 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->vsize: 0);
140 snprintf (buf, buflen, fmt, tmp);
142 else if (!Context || !Context->pattern)
149 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
150 snprintf (buf, buflen, fmt, Context ? Context->msgcount : 0);
152 else if (!Context || !Context->msgcount)
159 snprintf (fmt, sizeof(fmt), "%%%sd", prefix);
160 snprintf (buf, buflen, fmt, Context ? Context->vcount : 0);
162 else if (!Context || !Context->pattern)
169 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
170 snprintf (buf, buflen, fmt, Context ? Context->new : 0);
172 else if (!Context || !Context->new)
179 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
180 snprintf (buf, buflen, fmt, Context ? Context->unread - Context->new : 0);
182 else if (!Context || !(Context->unread - Context->new))
187 count = mutt_num_postponed (0);
190 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
191 snprintf (buf, buflen, fmt, count);
198 if (menu->top + menu->pagelen >= menu->max)
199 cp = menu->top ? "end" : "all";
202 count = (100 * (menu->top + menu->pagelen)) / menu->max;
203 snprintf (tmp, sizeof (tmp), "%d%%", count);
206 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
207 snprintf (buf, buflen, fmt, cp);
216 i = option(OPTATTACHMSG) ? 3 : ((Context->readonly ||
217 Context->dontwrite) ? 2 : (Context->changed || (
219 /* deleted doesn't necessarily mean changed in IMAP */
220 Context->magic != M_IMAP &&
222 Context->deleted)) ? 1 : 0);
227 else if (i >= mutt_strlen(StChars))
237 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
238 snprintf (buf, buflen, fmt,
239 get_sort_str (tmp, sizeof (tmp), Sort));
243 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
244 snprintf (buf, buflen, fmt,
245 get_sort_str (tmp, sizeof (tmp), SortAux));
251 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
252 snprintf (buf, buflen, fmt, Context ? Context->tagged : 0);
254 else if (!Context || !Context->tagged)
261 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
262 snprintf (buf, buflen, fmt, Context ? Context->unread : 0);
264 else if (!Context || !Context->unread)
269 snprintf (fmt, sizeof (fmt), "Mutt %%s");
270 snprintf (buf, buflen, fmt, MUTT_VERSION);
276 snprintf (fmt, sizeof(fmt), "%%%ss", prefix);
277 snprintf (buf, buflen, fmt, Context ? Context->pattern : 0);
279 else if (!Context || !Context->pattern)
288 snprintf (buf, buflen, "%%%s%c", prefix, op);
293 menu_status_line (buf, buflen, menu, ifstring);
294 else if (flags & M_FORMAT_OPTIONAL)
295 menu_status_line (buf, buflen, menu, elsestring);
300 void menu_status_line (char *buf, size_t buflen, MUTTMENU *menu, const char *p)
302 mutt_FormatString (buf, buflen, p, status_format_str, (unsigned long) menu, 0);