From: Rocco Rutte Date: Wed, 15 Nov 2006 18:53:15 +0000 (+0000) Subject: Unify size and count progress display. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=360c8bf14a083a062eaf7c394313e5631b6d688c;p=neomutt Unify size and count progress display. --- diff --git a/curs_lib.c b/curs_lib.c index bc68335c7..96c5b9b70 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -326,30 +326,63 @@ void mutt_curses_message (const char *fmt, ...) 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 @@ -359,7 +392,6 @@ void mutt_progress_bar (progress_t* progress, long pos) if (pos >= progress->size) mutt_clear_error (); } -#endif void mutt_show_error (void) { diff --git a/imap/imap.c b/imap/imap.c index 6a723516c..03ca21149 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -223,7 +223,7 @@ int imap_read_literal (FILE* fp, IMAP_DATA* idata, long bytes, progress_t* pbar) 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); diff --git a/imap/message.c b/imap/message.c index e973f6434..11bfcaf0b 100644 --- a/imap/message.c +++ b/imap/message.c @@ -71,6 +71,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) 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; @@ -133,6 +134,9 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) } 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); @@ -141,9 +145,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) 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)); @@ -211,11 +213,12 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) } #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) { @@ -454,9 +457,8 @@ int imap_fetch_message (MESSAGE *msg, CONTEXT *ctx, int msgno) 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 */ @@ -593,10 +595,9 @@ int imap_append_message (CONTEXT *ctx, MESSAGE *msg) } 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" : "", @@ -639,7 +640,7 @@ int imap_append_message (CONTEXT *ctx, MESSAGE *msg) { sent += len; flush_buffer(buf, &len, idata->conn); - mutt_progress_bar (&progressbar, sent); + mutt_progress_update (&progressbar, sent); } } diff --git a/mutt_curses.h b/mutt_curses.h index 8ee3d45a2..ac7915e4b 100644 --- a/mutt_curses.h +++ b/mutt_curses.h @@ -141,15 +141,23 @@ typedef struct color_line 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; diff --git a/pop.c b/pop.c index 98cd8a85c..acc9181be 100644 --- a/pop.c +++ b/pop.c @@ -197,6 +197,7 @@ static int pop_fetch_headers (CONTEXT *ctx) 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; @@ -235,7 +236,8 @@ static int pop_fetch_headers (CONTEXT *ctx) } } - mutt_message _("Fetching message headers..."); + mutt_progress_init (&progress, _("Fetching message headers..."), + PROG_MSG, ReadInc, 0); if (ret == 0) { @@ -245,10 +247,8 @@ static int pop_fetch_headers (CONTEXT *ctx) 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))) { @@ -509,9 +509,8 @@ int pop_fetch_message (MESSAGE* msg, CONTEXT* ctx, int msgno) 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))) @@ -597,6 +596,7 @@ int pop_sync_mailbox (CONTEXT *ctx, int *index_hint) 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 @@ -608,7 +608,8 @@ int pop_sync_mailbox (CONTEXT *ctx, int *index_hint) 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); @@ -619,8 +620,8 @@ int pop_sync_mailbox (CONTEXT *ctx, int *index_hint) 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) { diff --git a/pop_lib.c b/pop_lib.c index fdd5256b7..7956f16bf 100644 --- a/pop_lib.c +++ b/pop_lib.c @@ -496,7 +496,7 @@ int pop_fetch_data (POP_DATA *pop_data, char *query, progress_t *progressbar, else { if (progressbar) - mutt_progress_bar (progressbar, pos); + mutt_progress_update (progressbar, pos); if (ret == 0 && funct (inbuf, data) < 0) ret = -3; lenbuf = 0; @@ -550,9 +550,8 @@ int pop_reconnect (CONTEXT *ctx) { 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;