]> granicus.if.org Git - mutt/commitdiff
Teach pop driver about mutt_progress_bar. Allow progress bar to omit total
authorBrendan Cully <brendan@kublai.com>
Mon, 12 Sep 2005 06:22:21 +0000 (06:22 +0000)
committerBrendan Cully <brendan@kublai.com>
Mon, 12 Sep 2005 06:22:21 +0000 (06:22 +0000)
size if zero (=unknown).

curs_lib.c
pop.c
pop.h
pop_lib.c

index 2305d959ada86bb908d86b7aa25e30cfdbf8112d..44ecbee8dc897ae24bafe0582a50c3a5e070276f 100644 (file)
@@ -350,7 +350,8 @@ void mutt_progress_bar (progress_t* progress, long pos)
     if (!NetInc)
       mutt_message (progress->msg);
     else {
-      mutt_pretty_size (progress->sizestr, sizeof (progress->sizestr), progress->size);
+      if (progress->size)
+       mutt_pretty_size (progress->sizestr, sizeof (progress->sizestr), progress->size);
       progress->pos = 0;
     }
   }
@@ -363,7 +364,10 @@ void mutt_progress_bar (progress_t* progress, long pos)
     progress->pos = pos;
     pos = pos / (NetInc << 10) * (NetInc << 10);
     mutt_pretty_size (posstr, sizeof (posstr), pos);
-    mutt_message ("%s %s/%s", progress->msg, posstr, progress->sizestr);
+    if (progress->size)
+      mutt_message ("%s %s/%s", progress->msg, posstr, progress->sizestr);
+    else
+      mutt_message ("%s %s", progress->msg, posstr);
   }
 }
 #endif
diff --git a/pop.c b/pop.c
index 7136ab0efa111a7911b900b2a97dd76514495645..d08f3382c9a598b7328e85111017e0f48ba7fc51 100644 (file)
--- a/pop.c
+++ b/pop.c
@@ -21,6 +21,7 @@
 #endif
 
 #include "mutt.h"
+#include "mutt_curses.h"
 #include "mx.h"
 #include "pop.h"
 #include "mutt_crypt.h"
@@ -341,7 +342,7 @@ int pop_fetch_message (MESSAGE* msg, CONTEXT* ctx, int msgno)
   void *uidl;
   char buf[LONG_STRING];
   char path[_POSIX_PATH_MAX];
-  char *m = _("Fetching message...");
+  progress_t progressbar;
   POP_DATA *pop_data = (POP_DATA *)ctx->data;
   POP_CACHE *cache;
   HEADER *h = ctx->hdrs[msgno];
@@ -383,7 +384,9 @@ int pop_fetch_message (MESSAGE* msg, CONTEXT* ctx, int msgno)
       return -1;
     }
 
-    mutt_message (m);
+    progressbar.size = h->content->length + h->content->offset - 1;
+    progressbar.msg = _("Fetching message...");
+    mutt_progress_bar (&progressbar, 0);
 
     mutt_mktemp (path);
     msg->fp = safe_fopen (path, "w+");
@@ -396,7 +399,7 @@ int pop_fetch_message (MESSAGE* msg, CONTEXT* ctx, int msgno)
 
     snprintf (buf, sizeof (buf), "RETR %d\r\n", h->refno);
 
-    ret = pop_fetch_data (pop_data, buf, m, fetch_message, msg->fp);
+    ret = pop_fetch_data (pop_data, buf, &progressbar, fetch_message, msg->fp);
     if (ret == 0)
       break;
 
diff --git a/pop.h b/pop.h
index 027c20ddb5f3fba223f5b3160c7481bf5176e3d6..00d49f94c44bc7b95c12c411328dbf1e404681d1 100644 (file)
--- a/pop.h
+++ b/pop.h
@@ -21,6 +21,7 @@
 
 #include "mailbox.h"
 #include "mutt_socket.h"
+#include "mutt_curses.h"
 
 #define POP_PORT 110
 #define POP_SSL_PORT 995
@@ -96,7 +97,7 @@ int pop_parse_path (const char *, ACCOUNT *);
 int pop_connect (POP_DATA *);
 int pop_open_connection (POP_DATA *);
 int pop_query_d (POP_DATA *, char *, size_t, char *);
-int pop_fetch_data (POP_DATA *, char *, char *, int (*funct) (char *, void *), void *);
+int pop_fetch_data (POP_DATA *, char *, progress_t *, int (*funct) (char *, void *), void *);
 int pop_reconnect (CONTEXT *);
 void pop_logout (CONTEXT *);
 void pop_error (POP_DATA *, char *);
index a4d5c3a8798b1a5857b1310668fe80bac328d968..5a13b85fd766b014240d0e9a6d65a74de7e95072 100644 (file)
--- a/pop_lib.c
+++ b/pop_lib.c
@@ -455,13 +455,14 @@ int pop_query_d (POP_DATA *pop_data, char *buf, size_t buflen, char *msg)
  * -2 - invalid command or execution error,
  * -3 - error in funct(*line, *data)
  */
-int pop_fetch_data (POP_DATA *pop_data, char *query, char *msg,
+int pop_fetch_data (POP_DATA *pop_data, char *query, progress_t *progressbar,
                    int (*funct) (char *, void *), void *data)
 {
   char buf[LONG_STRING];
   char *inbuf;
   char *p;
-  int ret, chunk, line = 0;
+  int ret, chunk = 0;
+  long pos = 0;
   size_t lenbuf = 0;
 
   strfcpy (buf, query, sizeof (buf));
@@ -490,6 +491,7 @@ int pop_fetch_data (POP_DATA *pop_data, char *query, char *msg,
     }
 
     strfcpy (inbuf + lenbuf, p, sizeof (buf));
+    pos += chunk;
 
     if (chunk >= sizeof (buf))
     {
@@ -497,9 +499,8 @@ int pop_fetch_data (POP_DATA *pop_data, char *query, char *msg,
     }
     else
     {
-      line++;
-      if (msg && ReadInc && (line % ReadInc == 0))
-       mutt_message ("%s %d", msg, line);
+      if (progressbar)
+       mutt_progress_bar (progressbar, pos);
       if (ret == 0 && funct (inbuf, data) < 0)
        ret = -3;
       lenbuf = 0;
@@ -537,6 +538,7 @@ int pop_reconnect (CONTEXT *ctx)
 {
   int ret;
   POP_DATA *pop_data = (POP_DATA *)ctx->data;
+  progress_t progressbar;
 
   if (pop_data->status == POP_CONNECTED)
     return 0;
@@ -550,15 +552,16 @@ int pop_reconnect (CONTEXT *ctx)
     ret = pop_open_connection (pop_data);
     if (ret == 0)
     {
-      char *msg = _("Verifying message indexes...");
       int i;
 
+      progressbar.msg = _("Verifying message indexes...");
+      progressbar.size = 0;
+      mutt_progress_bar (&progressbar, 0);
+
       for (i = 0; i < ctx->msgcount; i++)
        ctx->hdrs[i]->refno = -1;
 
-      mutt_message (msg);
-
-      ret = pop_fetch_data (pop_data, "UIDL\r\n", msg, check_uidl, ctx);
+      ret = pop_fetch_data (pop_data, "UIDL\r\n", &progressbar, check_uidl, ctx);
       if (ret == -2)
       {
         mutt_error ("%s", pop_data->err_msg);