Commit 5c4c3fd4 authored by Rocco Rutte's avatar Rocco Rutte

Add percentages to progress bar optionally supplied by caller.

This is necessary to let the mbox driver print useful percentages. If there's no
percentage given and we have a size, calculate on it on our own. Closes #2929.
parent 841be702
2007-11-06 17:22 +0100 Rocco Rutte <pdmef@gmx.net> (eae335942190)
* mh.c: (Re-)Add total msg count to progress for parsing maildirs
2007-11-05 14:24 -0800 Vincent Lefevre <vincent@vinc17.org> (ecb694b6176b)
* po/fr.po: Updated French translation
2007-11-05 17:47 +0100 Rocco Rutte <pdmef@gmx.net> (6b9e91edba54)
* ChangeLog, curs_lib.c: Save value of errno across mutt_endwin()
calls. Mutt_endwin() is sometimes called after noticing an error but
before printing the message via perror(). Closes #2965.
2007-11-05 15:53 +0100 Emanuele Giaquinta <e.giaquinta@glauco.it> (b8dc6926ddf4)
* doc/manual.xml.head: Manual: Fix typo
......
......@@ -350,10 +350,10 @@ void mutt_progress_init (progress_t* progress, const char *msg,
progress->flags = flags;
progress->msg = msg;
progress->size = size;
mutt_progress_update (progress, 0);
mutt_progress_update (progress, 0, 0);
}
void mutt_progress_update (progress_t* progress, long pos)
void mutt_progress_update (progress_t* progress, long pos, int percent)
{
char posstr[SHORT_STRING];
short update = 0;
......@@ -396,11 +396,19 @@ void mutt_progress_update (progress_t* progress, long pos)
if (update)
{
progress->pos = pos;
if (progress->size)
mutt_message ("%s %s/%s", progress->msg, posstr, progress->sizestr);
if (progress->size > 0)
{
mutt_message ("%s %s/%s (%d%%)", progress->msg, posstr, progress->sizestr,
percent > 0 ? percent : progress->pos * 100 / progress->size);
}
else
{
if (percent > 0)
mutt_message ("%s %s (%d%%)", progress->msg, posstr, percent);
else
mutt_message ("%s %s", progress->msg, posstr);
}
}
if (pos >= progress->size)
mutt_clear_error ();
......
......@@ -230,7 +230,7 @@ int imap_read_literal (FILE* fp, IMAP_DATA* idata, long bytes, progress_t* pbar)
fputc (c, fp);
if (pbar && !(pos % 1024))
mutt_progress_update (pbar, pos);
mutt_progress_update (pbar, pos, -1);
#ifdef DEBUG
if (debuglevel >= IMAP_LOG_LTRL)
fputc (c, debugfile);
......
......@@ -145,7 +145,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
for (msgno = msgbegin; msgno <= msgend ; msgno++)
{
mutt_progress_update (&progress, msgno + 1);
mutt_progress_update (&progress, msgno + 1, -1);
memset (&h, 0, sizeof (h));
h.data = safe_calloc (1, sizeof (IMAP_HEADER_DATA));
......@@ -223,7 +223,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
for (msgno = msgbegin; msgno <= msgend ; msgno++)
{
mutt_progress_update (&progress, msgno + 1);
mutt_progress_update (&progress, msgno + 1, -1);
/* we may get notification of new mail while fetching headers */
if (msgno + 1 > fetchlast)
......@@ -641,7 +641,7 @@ int imap_append_message (CONTEXT *ctx, MESSAGE *msg)
{
sent += len;
flush_buffer(buf, &len, idata->conn);
mutt_progress_update (&progressbar, sent);
mutt_progress_update (&progressbar, sent, -1);
}
}
......
......@@ -132,7 +132,8 @@ int mmdf_parse_mailbox (CONTEXT *ctx)
count++;
if (!ctx->quiet)
mutt_progress_update (&progress, count);
mutt_progress_update (&progress, count,
(int)loc / (ctx->size / 100 + 1));
if (ctx->msgcount == ctx->hdrmax)
mx_alloc_memory (ctx);
......@@ -294,7 +295,8 @@ int mbox_parse_mailbox (CONTEXT *ctx)
count++;
if (!ctx->quiet)
mutt_progress_update (&progress, count);
mutt_progress_update (&progress, count,
(int)(ftell (ctx->fp) / (ctx->size / 100 + 1)));
if (ctx->msgcount == ctx->hdrmax)
mx_alloc_memory (ctx);
......@@ -788,7 +790,7 @@ int mbox_sync_mailbox (CONTEXT *ctx, int *index_hint)
for (i = first, j = 0; i < ctx->msgcount; i++)
{
if (!ctx->quiet)
mutt_progress_update (&progress, i);
mutt_progress_update (&progress, i, (int)(ftell (ctx->fp) / (ctx->size / 100 + 1)));
/*
* back up some information which is needed to restore offsets when
* something fails.
......
......@@ -727,7 +727,7 @@ static int maildir_parse_entry (CONTEXT * ctx, struct maildir ***last,
{
(*count)++;
if (!ctx->quiet && progress)
mutt_progress_update (progress, *count);
mutt_progress_update (progress, *count, -1);
}
if (subdir)
......@@ -1007,7 +1007,7 @@ void maildir_delayed_parsing (CONTEXT * ctx, struct maildir *md,
continue;
if (!ctx->quiet && progress)
mutt_progress_update (progress, count);
mutt_progress_update (progress, count, -1);
#if USE_HCACHE
data = mutt_hcache_fetch (hc, p->h->path + 3, &maildir_hcache_keylen);
......@@ -1602,7 +1602,7 @@ int mh_sync_mailbox (CONTEXT * ctx, int *index_hint)
for (i = 0; i < ctx->msgcount; i++)
{
if (!ctx->quiet)
mutt_progress_update (&progress, i);
mutt_progress_update (&progress, i, -1);
if (ctx->hdrs[i]->deleted
&& (ctx->magic != M_MAILDIR || !option (OPTMAILDIRTRASH)))
......
......@@ -157,7 +157,10 @@ typedef struct
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);
/* If percent is positive, it is displayed as percentage, otherwise
* percentage is calculated from progress->size and pos if progress
* was initialized with positive size, otherwise no percentage is shown */
void mutt_progress_update (progress_t* progress, long pos, int percent);
static inline int mutt_term_width(short wrap)
{
......
......@@ -1318,7 +1318,7 @@ int mutt_pattern_func (int op, char *prompt)
for (i = 0; i < Context->msgcount; i++)
{
mutt_progress_update (&progress, i);
mutt_progress_update (&progress, i, -1);
/* new limit pattern implicitly uncollapses all threads */
Context->hdrs[i]->virtual = -1;
Context->hdrs[i]->limited = 0;
......@@ -1339,7 +1339,7 @@ int mutt_pattern_func (int op, char *prompt)
{
for (i = 0; i < Context->vcount; i++)
{
mutt_progress_update (&progress, i);
mutt_progress_update (&progress, i, -1);
if (mutt_pattern_exec (pat, M_MATCH_FULL_ADDRESS, Context, Context->hdrs[Context->v2r[i]]))
{
switch (op)
......@@ -1458,7 +1458,7 @@ int mutt_search_command (int cur, int op)
for (i = cur + incr, j = 0 ; j != Context->vcount; j++)
{
mutt_progress_update (&progress, j);
mutt_progress_update (&progress, j, -1);
if (i > Context->vcount - 1)
{
i = 0;
......
......@@ -248,7 +248,7 @@ static int pop_fetch_headers (CONTEXT *ctx)
for (i = old_count; i < new_count; i++)
{
if (!ctx->quiet)
mutt_progress_update (&progress, i + 1 - old_count);
mutt_progress_update (&progress, i + 1 - old_count, -1);
#if USE_HCACHE
if ((data = mutt_hcache_fetch (hc, ctx->hdrs[i]->data, strlen)))
{
......@@ -622,7 +622,7 @@ int pop_sync_mailbox (CONTEXT *ctx, int *index_hint)
{
j++;
if (!ctx->quiet)
mutt_progress_update (&progress, j);
mutt_progress_update (&progress, j, -1);
snprintf (buf, sizeof (buf), "DELE %d\r\n", ctx->hdrs[i]->refno);
if ((ret = pop_query (pop_data, buf, sizeof (buf))) == 0)
{
......
......@@ -496,7 +496,7 @@ int pop_fetch_data (POP_DATA *pop_data, char *query, progress_t *progressbar,
else
{
if (progressbar)
mutt_progress_update (progressbar, pos);
mutt_progress_update (progressbar, pos, -1);
if (ret == 0 && funct (inbuf, data) < 0)
ret = -3;
lenbuf = 0;
......
......@@ -190,7 +190,7 @@ smtp_data (CONNECTION * conn, const char *msgfile)
return smtp_err_write;
}
mutt_progress_update (&progress, ftell (fp));
mutt_progress_update (&progress, ftell (fp), -1);
}
fclose (fp);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment