]> granicus.if.org Git - mutt/commitdiff
Add percentages to progress bar optionally supplied by caller.
authorRocco Rutte <pdmef@gmx.net>
Tue, 6 Nov 2007 17:23:06 +0000 (18:23 +0100)
committerRocco Rutte <pdmef@gmx.net>
Tue, 6 Nov 2007 17:23:06 +0000 (18:23 +0100)
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.

ChangeLog
curs_lib.c
imap/imap.c
imap/message.c
mbox.c
mh.c
mutt_curses.h
pattern.c
pop.c
pop_lib.c
smtp.c

index 279dd7845c21a43db0feb1ed6a8b64e6618f4bde..b2f5e2387c9b6af1eeb42898005211d84307084a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+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
index 0e4139cf601a866e9a50c2222fb0d19ccc30e3b2..bafb802b79a451a635acc9402d01ae5ddd48e4a7 100644 (file)
@@ -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,10 +396,18 @@ 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
-      mutt_message ("%s %s", progress->msg, posstr);
+    {
+      if (percent > 0)
+       mutt_message ("%s %s (%d%%)", progress->msg, posstr, percent);
+      else
+       mutt_message ("%s %s", progress->msg, posstr);
+    }
   }
 
   if (pos >= progress->size)
index 8ac9cef710002c80ef3c00eb93e487f8eea851b3..1a278dc10f92d2819065777cf84a34142c6bc0ae 100644 (file)
@@ -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);
index 77cef6ea654d50bd215840aeb5e7505884cef59c..a610f7896580d57b7df15eb5ca716733722d2b02 100644 (file)
@@ -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);
     }
   }
   
diff --git a/mbox.c b/mbox.c
index af3c7fb74a74f23a719f3262f976ccc3c84737b7..80843ea55d1f42bc18792b1485b97b85757a2a63 100644 (file)
--- a/mbox.c
+++ b/mbox.c
@@ -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.
diff --git a/mh.c b/mh.c
index af5f90afa5f261840e2e3cd5587f0aaaf2a17950..2994b9c60458c7ef56abc9a5dc23bfdbdf3a6a40 100644 (file)
--- a/mh.c
+++ b/mh.c
@@ -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)))
index 536f8a356a2c4da1818673cc0f10be3a5955fe9a..901c1df28f8294d591eaa2883760a23fc65e83eb 100644 (file)
@@ -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)
 {
index da2540c16340b1d666578b4b9eb2058e67f28baf..ee167cc867cf6aa823e985d097795db6c20f90e1 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -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;
diff --git a/pop.c b/pop.c
index cafeebf59143e602e7acd0491c2097cbd4c7632d..adb0c8de684f28ef48a42c77b69bbb31af0dc1f0 100644 (file)
--- a/pop.c
+++ b/pop.c
@@ -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)
        {
index 2c133d23c5b5dcc44b1626c9782d8bba6635f678..4b06ab0af5a754236554a4857e605854590446e9 100644 (file)
--- 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_update (progressbar, pos);
+       mutt_progress_update (progressbar, pos, -1);
       if (ret == 0 && funct (inbuf, data) < 0)
        ret = -3;
       lenbuf = 0;
diff --git a/smtp.c b/smtp.c
index 89397096dc2b665e1344489f70172f4959dbc05b..654f4aa9834a38e7ec986237a8001a5ae2c779e9 100644 (file)
--- a/smtp.c
+++ b/smtp.c
@@ -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);