2 * Copyright (C) 1996-2000,2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "mutt_menu.h"
25 #include "mutt_curses.h"
34 static char *get_sort_str (char *buf, size_t buflen, int method)
36 snprintf (buf, buflen, "%s%s%s",
37 (method & SORT_REVERSE) ? "reverse-" : "",
38 (method & SORT_LAST) ? "last-" : "",
39 mutt_getnamebyvalue (method & SORT_MASK, SortMethods));
43 static void _menu_status_line (char *buf, size_t buflen, size_t col, MUTTMENU *menu, const char *p);
45 /* %b = number of incoming folders with unread messages [option]
46 * %d = number of deleted messages [option]
47 * %f = full mailbox path
48 * %F = number of flagged messages [option]
50 * %l = length of mailbox (in bytes) [option]
51 * %m = total number of messages [option]
52 * %M = number of messages shown (virtual message count when limiting) [option]
53 * %n = number of new messages [option]
54 * %o = number of old unread messages [option]
55 * %p = number of postponed messages [option]
56 * %P = percent of way through index
57 * %r = readonly/wontwrite/changed flag
58 * %s = current sorting method ($sort)
59 * %S = current aux sorting method ($sort_aux)
60 * %t = # of tagged messages [option]
61 * %u = number of unread messages [option]
63 * %V = currently active limit pattern [option] */
65 status_format_str (char *buf, size_t buflen, size_t col, char op, const char *src,
66 const char *prefix, const char *ifstring,
67 const char *elsestring,
68 unsigned long data, format_flag flags)
70 char fmt[SHORT_STRING], tmp[SHORT_STRING], *cp;
71 int count, optional = (flags & M_FORMAT_OPTIONAL);
72 MUTTMENU *menu = (MUTTMENU *) data;
80 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
81 snprintf (buf, buflen, fmt, mutt_buffy_check (0));
83 else if (!mutt_buffy_check (0))
90 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
91 snprintf (buf, buflen, fmt, Context ? Context->deleted : 0);
93 else if (!Context || !Context->deleted)
98 snprintf (fmt, sizeof(fmt), "%%%ss", prefix);
99 if (Context && Context->path)
101 strfcpy (tmp, Context->path, sizeof (tmp));
102 mutt_pretty_mailbox (tmp, sizeof (tmp));
105 strfcpy (tmp, _("(no mailbox)"), sizeof (tmp));
106 snprintf (buf, buflen, fmt, tmp);
112 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
113 snprintf (buf, buflen, fmt, Context ? Context->flagged : 0);
115 else if (!Context || !Context->flagged)
120 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
121 snprintf (buf, buflen, fmt, NONULL(Hostname));
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) ? Context->pattern : "");
279 else if (!Context || !Context->pattern)
288 snprintf (buf, buflen, "%%%s%c", prefix, op);
293 _menu_status_line (buf, buflen, col, menu, ifstring);
294 else if (flags & M_FORMAT_OPTIONAL)
295 _menu_status_line (buf, buflen, col, menu, elsestring);
300 static void _menu_status_line (char *buf, size_t buflen, size_t col, MUTTMENU *menu, const char *p)
302 mutt_FormatString (buf, buflen, col, p, status_format_str, (unsigned long) menu, 0);
305 void menu_status_line (char *buf, size_t buflen, MUTTMENU *menu, const char *p)
307 mutt_FormatString (buf, buflen, 0, p, status_format_str, (unsigned long) menu, 0);