]> granicus.if.org Git - mutt/commitdiff
Display progress meter when uploading/fetching IMAP data. Closes: #1772.
authorBrendan Cully <brendan@kublai.com>
Wed, 7 Sep 2005 07:44:05 +0000 (07:44 +0000)
committerBrendan Cully <brendan@kublai.com>
Wed, 7 Sep 2005 07:44:05 +0000 (07:44 +0000)
curs_lib.c
globals.h
imap/imap.c
imap/imap_private.h
imap/message.c
init.h
mutt_curses.h

index eb4be076213129caf406b2ee6709121afc2b9d90..f9481797f121f2604d4c230bfcb7e905872e077d 100644 (file)
@@ -340,6 +340,31 @@ void mutt_curses_message (const char *fmt, ...)
   unset_option (OPTMSGERR);
 }
 
+void mutt_progress_bar (progress_t* progress, long pos)
+{
+  char posstr[SHORT_STRING];
+
+  if (!pos)
+  {
+    if (!NetInc)
+      mutt_message (progress->msg);
+    else {
+      mutt_pretty_size (progress->sizestr, sizeof (progress->sizestr), progress->size);
+      progress->pos = 0;
+    }
+  }
+
+  if (!NetInc)
+    return;
+
+  if (pos > progress->pos + (NetInc << 10))
+  {
+    mutt_pretty_size (posstr, sizeof (posstr), pos);
+    mutt_message ("%s %s/%s", progress->msg, posstr, progress->sizestr);
+    progress->pos = pos;
+  }
+}
+
 void mutt_show_error (void)
 {
   if (option (OPTKEEPQUIET))
index 7cdfe8bc9345798677445385f94e98d978d11289..942288dbfc196ec1dd76bac325aa2eef300c05ad 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -78,6 +78,7 @@ WHERE char *MsgFmt;
 #ifdef USE_SOCKET
 WHERE char *Preconnect INITVAL (NULL);
 WHERE char *Tunnel INITVAL (NULL);
+WHERE short NetInc;
 #endif /* USE_SOCKET */
 
 #ifdef MIXMASTER
index c2d0d3f1f9e5c3c4cf91926c24043b5161d6fc73..14485d27b6d23ab0d31f826c800a0b22fa0441cc 100644 (file)
@@ -25,7 +25,6 @@
 #endif
 
 #include "mutt.h"
-#include "mutt_curses.h"
 #include "mx.h"
 #include "mailbox.h"
 #include "globals.h"
@@ -189,7 +188,7 @@ void imap_logout_all (void)
 /* imap_read_literal: read bytes bytes from server into file. Not explicitly
  *   buffered, relies on FILE buffering. NOTE: strips \r from \r\n.
  *   Apparently even literals use \r\n-terminated strings ?! */
-int imap_read_literal (FILE* fp, IMAP_DATA* idata, long bytes)
+int imap_read_literal (FILE* fp, IMAP_DATA* idata, long bytes, progress_t* pbar)
 {
   long pos;
   char c;
@@ -221,6 +220,9 @@ int imap_read_literal (FILE* fp, IMAP_DATA* idata, long bytes)
       r = 0;
 #endif
     fputc (c, fp);
+    
+    if (pbar && pos % 1024)
+      mutt_progress_bar (pbar, pos);
 #ifdef DEBUG
     if (debuglevel >= IMAP_LOG_LTRL)
       fputc (c, debugfile);
index 831a9c8094bc6c7c0e2c90a99ae47994431e5d80..ba536deffd85531ad7e388c38cf8abe066135913 100644 (file)
@@ -21,6 +21,7 @@
 #define _IMAP_PRIVATE_H 1
 
 #include "imap.h"
+#include "mutt_curses.h"
 #include "mutt_socket.h"
 
 /* -- symbols -- */
@@ -199,7 +200,7 @@ int imap_open_connection (IMAP_DATA* idata);
 IMAP_DATA* imap_conn_find (const ACCOUNT* account, int flags);
 int imap_parse_list_response(IMAP_DATA* idata, char** name, int* noselect,
   int* noinferiors, char* delim);
-int imap_read_literal (FILE* fp, IMAP_DATA* idata, long bytes);
+int imap_read_literal (FILE* fp, IMAP_DATA* idata, long bytes, progress_t*);
 void imap_expunge_mailbox (IMAP_DATA* idata);
 void imap_logout (IMAP_DATA* idata);
 int imap_sync_message (IMAP_DATA *idata, HEADER *hdr, BUFFER *cmd,
index d7ce21d7d3a7a166779e35105f2cab5d93606c67..59cd9e11d14eff9d3051edba32bf8eba24764038 100644 (file)
@@ -29,7 +29,6 @@
 #include <ctype.h>
 
 #include "mutt.h"
-#include "mutt_curses.h"
 #include "imap_private.h"
 #include "message.h"
 #include "mx.h"
@@ -325,6 +324,7 @@ int imap_fetch_message (MESSAGE *msg, CONTEXT *ctx, int msgno)
   char path[_POSIX_PATH_MAX];
   char *pc;
   long bytes;
+  progress_t progressbar;
   int uid;
   int cacheno;
   IMAP_CACHE *cache;
@@ -409,7 +409,10 @@ int imap_fetch_message (MESSAGE *msg, CONTEXT *ctx, int msgno)
            imap_error ("imap_fetch_message()", buf);
            goto bail;
          }
-         if (imap_read_literal (msg->fp, idata, bytes) < 0)
+          progressbar.size = bytes;
+          progressbar.msg = _("Fetching message...");
+          mutt_progress_bar (&progressbar, 0);
+         if (imap_read_literal (msg->fp, idata, bytes, &progressbar) < 0)
            goto bail;
          /* pick up trailing line */
          if ((rc = imap_cmd_step (idata)) != IMAP_CMD_CONTINUE)
@@ -508,6 +511,8 @@ int imap_append_message (CONTEXT *ctx, MESSAGE *msg)
   char mbox[LONG_STRING];
   char mailbox[LONG_STRING]; 
   size_t len;
+  progress_t progressbar;
+  size_t sent;
   int c, last;
   IMAP_MBOX mx;
   int rc;
@@ -539,6 +544,10 @@ int imap_append_message (CONTEXT *ctx, MESSAGE *msg)
     len++;
   }
   rewind (fp);
+
+  progressbar.msg = _("Uploading message...");
+  progressbar.size = len;
+  mutt_progress_bar (&progressbar, 0);
   
   imap_munge_mbox_name (mbox, sizeof (mbox), mailbox);
   snprintf (buf, sizeof (buf), "APPEND %s (%s%s%s%s%s) {%lu}", mbox,
@@ -571,9 +580,7 @@ int imap_append_message (CONTEXT *ctx, MESSAGE *msg)
     goto fail;
   }
 
-  mutt_message _("Uploading message ...");
-
-  for (last = EOF, len = 0; (c = fgetc(fp)) != EOF; last = c)
+  for (last = EOF, sent = len = 0; (c = fgetc(fp)) != EOF; last = c)
   {
     if (c == '\n' && last != '\r')
       buf[len++] = '\r';
@@ -581,7 +588,11 @@ int imap_append_message (CONTEXT *ctx, MESSAGE *msg)
     buf[len++] = c;
 
     if (len > sizeof(buf) - 3)
+    {
+      sent += len;
       flush_buffer(buf, &len, idata->conn);
+      mutt_progress_bar (&progressbar, sent);
+    }
   }
   
   if (len)
@@ -898,7 +909,7 @@ static int msg_fetch_header (CONTEXT* ctx, IMAP_HEADER* h, char* buf, FILE* fp)
   
   if (imap_get_literal_count (buf, &bytes) == 0)
   {
-    imap_read_literal (fp, idata, bytes);
+    imap_read_literal (fp, idata, bytes, NULL);
 
     /* we may have other fields of the FETCH _after_ the literal
      * (eg Domino puts FLAGS here). Nothing wrong with that, either.
diff --git a/init.h b/init.h
index 99c2a1a76ee13f5d5841a0b45f04dcf529292948..8d1176c271696d13637e02c51ae1e6cb5675b5f8 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1266,6 +1266,17 @@ struct option_t MuttVars[] = {
   ** This variable, when set, makes the thread tree narrower, allowing
   ** deeper threads to fit on the screen.
   */
+#ifdef USE_SOCKET
+  { "net_inc", DT_NUM,  R_NONE, UL &NetInc, 10 },
+  /*
+   ** .pp
+   ** Operations that expect to transfer a large amount of data over the
+   ** network will update their progress every \fInet_inc\fP kilobytes.
+   ** If set to 0, no progress messages will be displayed.
+   ** .pp
+   ** See also ``$$read_inc'' and ``$$write_inc''.
+   */
+#endif  
   { "pager",           DT_PATH, R_NONE, UL &Pager, UL "builtin" },
   /*
   ** .pp
index 0b354ca5b1d4ac58b33d17c4f90096b6dd0e470b..5f2a84aeb4a54a1040d728aec1f793743ed0b0e1 100644 (file)
@@ -17,6 +17,9 @@
  *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  */ 
 
+#ifndef _MUTT_CURSES_H_
+#define _MUTT_CURSES_H_ 1
+
 #ifdef USE_SLANG_CURSES
 
 #ifndef unix /* this symbol is not defined by the hp-ux compiler (sigh) */
@@ -136,6 +139,16 @@ typedef struct color_line
   struct color_line *next;
 } COLOR_LINE;
 
+typedef struct
+{
+  const char* msg;
+  long pos;
+  long size;
+  char sizestr[SHORT_STRING];
+} progress_t;
+
+void mutt_progress_bar (progress_t* progress, long pos);
+
 extern int *ColorQuote;
 extern int ColorQuoteUsed;
 extern int ColorDefs[];
@@ -174,3 +187,5 @@ extern int wclear();
 extern int waddstr();
 extern int wclrtoeol();
 #endif
+
+#endif /* _MUTT_CURSES_H_ */