~ubuntu-branches/ubuntu/lucid/mutt/lucid-updates

1.1.2 by Martin Pitt
Import upstream version 1.5.11+cvs20060403
1
/*
2
 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
3
 * 
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.
8
 * 
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.
13
 * 
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.
17
 */ 
18
19
#if HAVE_CONFIG_H
20
# include "config.h"
21
#endif
22
23
#include "mutt.h"
24
#include "mutt_menu.h"
25
#include "mutt_curses.h"
26
#include "sort.h"
27
#include "mapping.h"
28
#include "mx.h"
29
30
#include <string.h>
31
#include <ctype.h>
32
#include <unistd.h>
33
34
static char *get_sort_str (char *buf, size_t buflen, int method)
35
{
36
  snprintf (buf, buflen, "%s%s%s",
37
	    (method & SORT_REVERSE) ? "reverse-" : "",
38
	    (method & SORT_LAST) ? "last-" : "",
39
	    mutt_getnamebyvalue (method & SORT_MASK, SortMethods));
40
  return buf;
41
}
42
1.1.6 by Adeodato Simó
Import upstream version 1.5.16
43
static void _menu_status_line (char *buf, size_t buflen, size_t col, MUTTMENU *menu, const char *p);
44
1.1.2 by Martin Pitt
Import upstream version 1.5.11+cvs20060403
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]
49
 * %h = hostname
50
 * %l = length of mailbox (in bytes) [option]
51
 * %m = total number of messages [option]
52
 * %M = number of messages shown (virutal message count when limiting) [option]
53
 * %n = number of new messages [option]
54
 * %p = number of postponed messages [option]
55
 * %P = percent of way through index
56
 * %r = readonly/wontwrite/changed flag
57
 * %s = current sorting method ($sort)
58
 * %S = current aux sorting method ($sort_aux)
59
 * %t = # of tagged messages [option]
60
 * %v = Mutt version 
61
 * %V = currently active limit pattern [option] */
62
static const char *
1.1.6 by Adeodato Simó
Import upstream version 1.5.16
63
status_format_str (char *buf, size_t buflen, size_t col, char op, const char *src,
1.1.2 by Martin Pitt
Import upstream version 1.5.11+cvs20060403
64
		   const char *prefix, const char *ifstring,
65
		   const char *elsestring,
66
		   unsigned long data, format_flag flags)
67
{
68
  char fmt[SHORT_STRING], tmp[SHORT_STRING], *cp;
69
  int count, optional = (flags & M_FORMAT_OPTIONAL);
70
  MUTTMENU *menu = (MUTTMENU *) data;
71
72
  *buf = 0;
73
  switch (op)
74
  {
75
    case 'b':
76
      if (!optional)
77
      {
78
	snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
79
	snprintf (buf, buflen, fmt, mutt_buffy_check (0));
80
      }
81
      else if (!mutt_buffy_check (0))
82
	optional = 0;
83
      break;
84
85
    case 'd':
86
      if (!optional)
87
      {
88
	snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
89
	snprintf (buf, buflen, fmt, Context ? Context->deleted : 0);
90
      }
91
      else if (!Context || !Context->deleted)
92
	optional = 0;
93
      break;
94
95
    case 'h':
96
      snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
97
      snprintf (buf, buflen, fmt, NONULL(Hostname));
98
      break;
99
100
    case 'f':
101
      snprintf (fmt, sizeof(fmt), "%%%ss", prefix);
102
      if (Context && Context->path)
103
      {
104
	strfcpy (tmp, Context->path, sizeof (tmp));
105
	mutt_pretty_mailbox (tmp);
106
      }
107
      else
108
	strfcpy (tmp, _("(no mailbox)"), sizeof (tmp));
109
      snprintf (buf, buflen, fmt, tmp);
110
      break;
111
112
    case 'F':
113
      if (!optional)
114
      {
115
	snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
116
	snprintf (buf, buflen, fmt, Context ? Context->flagged : 0);
117
      }
118
      else if (!Context || !Context->flagged)
119
	optional = 0;
120
      break;
121
122
    case 'l':
123
      if (!optional)
124
      {
125
	snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
126
	mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->size : 0);
127
	snprintf (buf, buflen, fmt, tmp);
128
      }
129
      else if (!Context || !Context->size)
130
	optional = 0;
131
      break;
132
133
    case 'L':
134
      if (!optional)
135
      {
136
	snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
137
	mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->vsize: 0);
138
	snprintf (buf, buflen, fmt, tmp);
139
      }
140
      else if (!Context || !Context->pattern)
141
	optional = 0;
142
      break;
143
144
    case 'm':
145
      if (!optional)
146
      {
147
	snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
148
	snprintf (buf, buflen, fmt, Context ? Context->msgcount : 0);
149
      }
150
      else if (!Context || !Context->msgcount)
151
	optional = 0;
152
      break;
153
154
    case 'M':
155
      if (!optional)
156
      {
157
	snprintf (fmt, sizeof(fmt), "%%%sd", prefix);
158
	snprintf (buf, buflen, fmt, Context ? Context->vcount : 0);
159
      }
160
      else if (!Context || !Context->pattern)
161
	optional = 0;
162
      break;
163
164
    case 'n':
165
      if (!optional)
166
      {
167
	snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
168
	snprintf (buf, buflen, fmt, Context ? Context->new : 0);
169
      }
170
      else if (!Context || !Context->new)
171
	optional = 0;
172
      break;
173
174
    case 'o':
175
      if (!optional)
176
      {
177
	snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
178
	snprintf (buf, buflen, fmt, Context ? Context->unread - Context->new : 0);
179
      }
180
      else if (!Context || !(Context->unread - Context->new))
181
	optional = 0;
182
      break;
183
184
    case 'p':
185
      count = mutt_num_postponed (0);
186
      if (!optional)
187
      {
188
	snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
189
	snprintf (buf, buflen, fmt, count);
190
      }
191
      else if (!count)
192
	optional = 0;
193
      break;
194
195
    case 'P':
196
      if (menu->top + menu->pagelen >= menu->max)
197
	cp = menu->top ? "end" : "all";
198
      else
199
      {
200
	count = (100 * (menu->top + menu->pagelen)) / menu->max;
201
	snprintf (tmp, sizeof (tmp), "%d%%", count);
202
	cp = tmp;
203
      }
204
      snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
205
      snprintf (buf, buflen, fmt, cp);
206
      break;
207
208
    case 'r':
209
    {
210
      int i = 0;
211
212
      if (Context)
213
      {
214
	i = option(OPTATTACHMSG) ? 3 : ((Context->readonly ||
215
          Context->dontwrite) ? 2 : (Context->changed || (
216
#ifdef USE_IMAP
217
        /* deleted doesn't necessarily mean changed in IMAP */
218
          Context->magic != M_IMAP &&
219
#endif
220
          Context->deleted)) ? 1 : 0);
221
      }
222
      
223
      if (!StChars)
224
	buf[0] = 0;
225
      else if (i >= mutt_strlen(StChars))
226
	buf[0] = StChars[0];
227
      else
228
	buf[0] = StChars[i];
229
230
      buf[1] = 0;
231
      break;
232
    }
233
      
234
    case 's':
235
      snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
236
      snprintf (buf, buflen, fmt,
237
		get_sort_str (tmp, sizeof (tmp), Sort));
238
      break;
239
240
    case 'S':
241
      snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
242
      snprintf (buf, buflen, fmt,
243
		get_sort_str (tmp, sizeof (tmp), SortAux));
244
      break;
245
246
    case 't':
247
      if (!optional)
248
      {
249
	snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
250
	snprintf (buf, buflen, fmt, Context ? Context->tagged : 0);
251
      }
252
      else if (!Context || !Context->tagged)
253
	optional = 0;
254
      break;
255
256
    case 'u':
257
      if (!optional)
258
      {
259
	snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
260
	snprintf (buf, buflen, fmt, Context ? Context->unread : 0);
261
      }
262
      else if (!Context || !Context->unread)
263
	optional = 0;
264
      break;
265
266
    case 'v':
267
      snprintf (fmt, sizeof (fmt), "Mutt %%s");
268
      snprintf (buf, buflen, fmt, MUTT_VERSION);
269
      break;
270
271
    case 'V':
272
      if (!optional)
273
      {
274
	snprintf (fmt, sizeof(fmt), "%%%ss", prefix);
275
	snprintf (buf, buflen, fmt, (Context && Context->pattern) ? Context->pattern : "");
276
      }
277
      else if (!Context || !Context->pattern)
278
	optional = 0;
279
      break;
280
281
    case 0:
282
      *buf = 0;
283
      return (src);
284
285
    default:
286
      snprintf (buf, buflen, "%%%s%c", prefix, op);
287
      break;
288
  }
289
290
  if (optional)
1.1.6 by Adeodato Simó
Import upstream version 1.5.16
291
    _menu_status_line (buf, buflen, col, menu, ifstring);
1.1.2 by Martin Pitt
Import upstream version 1.5.11+cvs20060403
292
  else if (flags & M_FORMAT_OPTIONAL)
1.1.6 by Adeodato Simó
Import upstream version 1.5.16
293
    _menu_status_line (buf, buflen, col, menu, elsestring);
1.1.2 by Martin Pitt
Import upstream version 1.5.11+cvs20060403
294
295
  return (src);
296
}
297
1.1.6 by Adeodato Simó
Import upstream version 1.5.16
298
static void _menu_status_line (char *buf, size_t buflen, size_t col, MUTTMENU *menu, const char *p)
299
{
300
  mutt_FormatString (buf, buflen, col, p, status_format_str, (unsigned long) menu, 0);
301
}
302
1.1.2 by Martin Pitt
Import upstream version 1.5.11+cvs20060403
303
void menu_status_line (char *buf, size_t buflen, MUTTMENU *menu, const char *p)
304
{
1.1.6 by Adeodato Simó
Import upstream version 1.5.16
305
  mutt_FormatString (buf, buflen, 0, p, status_format_str, (unsigned long) menu, 0);
1.1.2 by Martin Pitt
Import upstream version 1.5.11+cvs20060403
306
}