unset_option (OPTMSGERR);
}
-#ifdef USE_SOCKET
-void mutt_progress_bar (progress_t* progress, long pos)
+void mutt_progress_init (progress_t* progress, const char *msg,
+ unsigned short flags, unsigned short inc,
+ long size)
+{
+ if (!progress)
+ return;
+ memset (progress, 0, sizeof (progress_t));
+ progress->inc = inc;
+ progress->flags = flags;
+ progress->msg = msg;
+ progress->size = size;
+ mutt_progress_update (progress, 0);
+}
+
+void mutt_progress_update (progress_t* progress, long pos)
{
char posstr[SHORT_STRING];
+ short update = 0;
if (!pos)
{
- if (!NetInc)
+ if (!progress->inc)
mutt_message (progress->msg);
- else {
+ else
+ {
if (progress->size)
- mutt_pretty_size (progress->sizestr, sizeof (progress->sizestr), progress->size);
+ {
+ if (progress->flags & PROG_SIZE)
+ mutt_pretty_size (progress->sizestr, sizeof (progress->sizestr), progress->size);
+ else
+ snprintf (progress->sizestr, sizeof (progress->sizestr), "%ld", progress->size);
+ }
progress->pos = 0;
}
}
- if (!NetInc)
+ if (!progress->inc)
return;
- if (pos >= progress->pos + (NetInc << 10))
+ if (progress->flags & PROG_SIZE)
+ {
+ if (pos >= progress->pos + (progress->inc << 10))
+ {
+ pos = pos / (progress->inc << 10) * (progress->inc << 10);
+ mutt_pretty_size (posstr, sizeof (posstr), pos);
+ update = 1;
+ }
+ }
+ else if (pos >= progress->pos + progress->inc)
+ {
+ snprintf (posstr, sizeof (posstr), "%ld", pos);
+ update = 1;
+ }
+
+ if (update)
{
progress->pos = pos;
- pos = pos / (NetInc << 10) * (NetInc << 10);
- mutt_pretty_size (posstr, sizeof (posstr), pos);
if (progress->size)
mutt_message ("%s %s/%s", progress->msg, posstr, progress->sizestr);
else
if (pos >= progress->size)
mutt_clear_error ();
}
-#endif
void mutt_show_error (void)
{
fputc (c, fp);
if (pbar && !(pos % 1024))
- mutt_progress_bar (pbar, pos);
+ mutt_progress_update (pbar, pos);
#ifdef DEBUG
if (debuglevel >= IMAP_LOG_LTRL)
fputc (c, debugfile);
int fetchlast = 0;
int maxuid = 0;
const char *want_headers = "DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL";
+ progress_t progress;
#if USE_HCACHE
header_cache_t *hc = NULL;
}
if (evalhc)
{
+ mutt_progress_init (&progress, _("Evaluating cache..."),
+ PROG_MSG, ReadInc, msgend + 1);
+
snprintf (buf, sizeof (buf),
"UID FETCH 1:%u (UID FLAGS)", *uidnext - 1);
FREE (&uidnext);
for (msgno = msgbegin; msgno <= msgend ; msgno++)
{
- if (ReadInc && (!msgno || ((msgno+1) % ReadInc == 0)))
- mutt_message (_("Evaluating cache... [%d/%d]"), msgno + 1,
- msgend + 1);
+ mutt_progress_update (&progress, msgno + 1);
memset (&h, 0, sizeof (h));
h.data = safe_calloc (1, sizeof (IMAP_HEADER_DATA));
}
#endif /* USE_HCACHE */
+ mutt_progress_init (&progress, _("Fetching message headers..."),
+ PROG_MSG, ReadInc, msgend + 1);
+
for (msgno = msgbegin; msgno <= msgend ; msgno++)
{
- if (ReadInc && (msgno == msgbegin || ((msgno+1) % ReadInc == 0)))
- mutt_message (_("Fetching message headers... [%d/%d]"), msgno + 1,
- msgend + 1);
+ mutt_progress_update (&progress, msgno + 1);
if (msgno + 1 > fetchlast)
{
imap_error ("imap_fetch_message()", buf);
goto bail;
}
- progressbar.size = bytes;
- progressbar.msg = _("Fetching message...");
- mutt_progress_bar (&progressbar, 0);
+ mutt_progress_init (&progressbar, _("Fetching message..."),
+ PROG_SIZE, NetInc, bytes);
if (imap_read_literal (msg->fp, idata, bytes, &progressbar) < 0)
goto bail;
/* pick up trailing line */
}
rewind (fp);
- progressbar.msg = _("Uploading message...");
- progressbar.size = len;
- mutt_progress_bar (&progressbar, 0);
-
+ mutt_progress_init (&progressbar, _("Uploading message..."),
+ PROG_SIZE, NetInc, len);
+
imap_munge_mbox_name (mbox, sizeof (mbox), mailbox);
snprintf (buf, sizeof (buf), "APPEND %s (%s%s%s%s%s) {%lu}", mbox,
msg->flags.read ? "\\Seen" : "",
{
sent += len;
flush_buffer(buf, &len, idata->conn);
- mutt_progress_bar (&progressbar, sent);
+ mutt_progress_update (&progressbar, sent);
}
}
struct color_line *next;
} COLOR_LINE;
+#define PROG_SIZE (1<<0) /* traffic-based progress */
+#define PROG_MSG (1<<1) /* message-based progress */
+
typedef struct
{
+ unsigned short inc;
+ unsigned short flags;
const char* msg;
long pos;
long size;
char sizestr[SHORT_STRING];
} progress_t;
-void mutt_progress_bar (progress_t* progress, long pos);
+void mutt_progress_init (progress_t* progress, const char *msg,
+ unsigned short flags, unsigned short inc,
+ long size);
+void mutt_progress_update (progress_t* progress, long pos);
extern int *ColorQuote;
extern int ColorQuoteUsed;
int i, ret, old_count, new_count;
unsigned short hcached = 0, bcached;
POP_DATA *pop_data = (POP_DATA *)ctx->data;
+ progress_t progress;
#ifdef USE_HCACHE
header_cache_t *hc = NULL;
}
}
- mutt_message _("Fetching message headers...");
+ mutt_progress_init (&progress, _("Fetching message headers..."),
+ PROG_MSG, ReadInc, 0);
if (ret == 0)
{
for (i = old_count; i < new_count; i++)
{
- if (!ctx->quiet && ReadInc && (((i - old_count) % ReadInc) == 0 || (i - old_count) == 1))
- mutt_message (_("Fetching message headers... [%d/%d]"),
- i + 1 - old_count, new_count - old_count);
-
+ if (!ctx->quiet)
+ mutt_progress_update (&progress, i + 1 - old_count);
#if USE_HCACHE
if ((data = mutt_hcache_fetch (hc, ctx->hdrs[i]->data, strlen)))
{
return -1;
}
- progressbar.size = h->content->length + h->content->offset - 1;
- progressbar.msg = _("Fetching message...");
- mutt_progress_bar (&progressbar, 0);
+ mutt_progress_init (&progressbar, _("Fetching message..."),
+ PROG_SIZE, NetInc, h->content->length + h->content->offset - 1);
/* see if we can put in body cache; use our cache as fallback */
if (!(msg->fp = mutt_bcache_put (pop_data->bcache, h->data)))
int i, j, ret = 0;
char buf[LONG_STRING];
POP_DATA *pop_data = (POP_DATA *)ctx->data;
+ progress_t progress;
#ifdef USE_HCACHE
header_cache_t *hc = NULL;
#endif
if (pop_reconnect (ctx) < 0)
return -1;
- mutt_message (_("Marking %d messages deleted..."), ctx->deleted);
+ mutt_progress_init (&progress, _("Marking messages deleted..."),
+ PROG_MSG, WriteInc, ctx->deleted);
#if USE_HCACHE
hc = mutt_hcache_open (HeaderCache, ctx->path);
if (ctx->hdrs[i]->deleted)
{
j++;
- if (!ctx->quiet && WriteInc && ((j % WriteInc) == 0 || j == 1))
- mutt_message (_("Deleting messages [%d/%d]..."), j, ctx->deleted);
+ if (!ctx->quiet)
+ mutt_progress_update (&progress, j);
snprintf (buf, sizeof (buf), "DELE %d\r\n", ctx->hdrs[i]->refno);
if ((ret = pop_query (pop_data, buf, sizeof (buf))) == 0)
{
else
{
if (progressbar)
- mutt_progress_bar (progressbar, pos);
+ mutt_progress_update (progressbar, pos);
if (ret == 0 && funct (inbuf, data) < 0)
ret = -3;
lenbuf = 0;
{
int i;
- progressbar.msg = _("Verifying message indexes...");
- progressbar.size = 0;
- mutt_progress_bar (&progressbar, 0);
+ mutt_progress_init (&progressbar, _("Verifying message indexes..."),
+ PROG_SIZE, NetInc, 0);
for (i = 0; i < ctx->msgcount; i++)
ctx->hdrs[i]->refno = -1;