* elmo-util.el (elmo-progress-start): Accept nil for `total'. Set
authorhmurata <hmurata>
Tue, 7 Nov 2006 14:18:53 +0000 (14:18 +0000)
committerhmurata <hmurata>
Tue, 7 Nov 2006 14:18:53 +0000 (14:18 +0000)
`elmo-progress-counter' as t when a query callback returns nil.
(elmo-progress-clear): New function.
(elmo-progress-done): Split into `elmo-progress-clear'.
(elmo-progress-notify): Update a total slot when it is nil.
(elmo-with-progress-display): Call `elmo-progress-clear' in
unwind-protect and move calling `elmo-progress-done' to outside.

* elmo-imap4.el (elmo-imap4-find-next-line): Call
`elmo-progress-notify' with :total parameter instead of
`elmo-progress-counter-set-total'.

elmo/ChangeLog
elmo/elmo-imap4.el
elmo/elmo-util.el

index a612605..e52bb40 100644 (file)
@@ -1,3 +1,17 @@
+2006-11-07  Hiroya Murata  <lapis-lazuli@pop06.odn.ne.jp>
+
+       * elmo-util.el (elmo-progress-start): Accept nil for `total'.  Set
+       `elmo-progress-counter' as t when a query callback returns nil.
+       (elmo-progress-clear): New function.
+       (elmo-progress-done): Split into `elmo-progress-clear'.
+       (elmo-progress-notify): Update a total slot when it is nil.
+       (elmo-with-progress-display): Call `elmo-progress-clear' in
+       unwind-protect and move calling `elmo-progress-done' to outside.
+
+       * elmo-imap4.el (elmo-imap4-find-next-line): Call
+       `elmo-progress-notify' with :total parameter instead of
+       `elmo-progress-counter-set-total'.
+
 2006-11-07  Tetsurou Okazaki  <okazaki@be.to>
 
        * elmo-util.el (elmo-cache-expire-by-age): Add docstring.
index 5f1d5e2..d22da97 100644 (file)
@@ -1246,13 +1246,11 @@ Return nil if no complete line has arrived."
     (if (match-string 1)
        (if (< (point-max) (+ (point) (string-to-number (match-string 1))))
            (progn
-             (when (elmo-progress-counter-label
-                    elmo-imap4-literal-progress-reporter)
-               (elmo-progress-counter-set-total
-                elmo-imap4-literal-progress-reporter
-                (string-to-number (match-string 1)))
-               (elmo-progress-notify 'elmo-retrieve-message
-                                     :set (- (point-max) (point))))
+             (when elmo-imap4-literal-progress-reporter
+               (elmo-progress-notify
+                'elmo-retrieve-message
+                :set (- (point-max) (point))
+                :total (string-to-number (match-string 1))))
              nil)
          (goto-char (+ (point) (string-to-number (match-string 1))))
          (elmo-imap4-find-next-line))
@@ -2694,8 +2692,7 @@ If optional argument REMOVE is non-nil, remove FLAG."
       (setq elmo-imap4-fetch-callback nil)
       (setq elmo-imap4-fetch-callback-data nil))
     (elmo-with-progress-display (elmo-retrieve-message
-                                (or (elmo-message-field folder number :size)
-                                    0)
+                                (elmo-message-field folder number :size)
                                 elmo-imap4-literal-progress-reporter)
        "Retrieving"
       (setq response
index 9f4910b..c744ff3 100644 (file)
@@ -1189,40 +1189,53 @@ If optional DELETE-FUNCTION is speficied, it is used as delete procedure."
             (elmo-progress-counter-total counter))))
 
 (defun elmo-progress-start (label total action)
-  (when (and (> total 0)
-            (null elmo-progress-counter))
+  (when (and (null elmo-progress-counter)
+            (or (null total)
+                (> total 0)))
     (let ((counter (cons label (vector 0 total action))))
       (elmo-progress-call-callback counter 'start)
-      (when (elmo-progress-call-callback counter 'query)
-       (elmo-progress-call-callback counter)
-       (setq elmo-progress-counter counter))
+      (setq elmo-progress-counter
+           (cond ((null total)
+                  counter)
+                 ((elmo-progress-call-callback counter 'query)
+                  (elmo-progress-call-callback counter)
+                  counter)
+                 (t
+                  t)))
       counter)))
 
-(defun elmo-progress-done (counter)
+(defun elmo-progress-clear (counter)
   (when counter
-    (when (elmo-progress-counter-label counter)
-      (when (< (elmo-progress-counter-value counter)
-              (elmo-progress-counter-total counter))
-       (elmo-progress-call-callback counter 100))
-      (elmo-progress-call-callback counter 'done))
-    (when (eq counter elmo-progress-counter)
-      (setq elmo-progress-counter nil))))
+    (when (and (elmo-progress-counter-label elmo-progress-counter)
+              (elmo-progress-counter-total elmo-progress-counter))
+      (elmo-progress-call-callback elmo-progress-counter 100))
+    (setq elmo-progress-counter nil)))
+
+(defun elmo-progress-done (counter)
+  (when (elmo-progress-counter-label counter)
+    (elmo-progress-call-callback counter 'done)))
 
 (defun elmo-progress-notify (label &rest params)
-  (when (and elmo-progress-counter
-            (eq (elmo-progress-counter-label elmo-progress-counter) label))
+  (when (eq label (elmo-progress-counter-label elmo-progress-counter))
     (let ((counter elmo-progress-counter))
-      (elmo-progress-counter-set-value
-       counter
-       (or (plist-get params :set)
-          (+ (elmo-progress-counter-value counter)
-             (or (plist-get params :inc)
-                 (car params)
-                 1))))
-      (elmo-progress-call-callback counter))))
+      (if (or (elmo-progress-counter-total counter)
+             (and (elmo-progress-counter-set-total
+                   counter
+                   (plist-get params :total))
+                  (elmo-progress-call-callback counter 'query)))
+         (progn
+           (elmo-progress-counter-set-value
+            counter
+            (or (plist-get params :set)
+                (+ (elmo-progress-counter-value counter)
+                   (or (plist-get params :inc)
+                       (car params)
+                       1))))
+           (elmo-progress-call-callback counter))
+       (setq elmo-progress-counter t)))))
 
 (defmacro elmo-with-progress-display (spec message &rest body)
-  "Evaluate BODY with progress gauge if CONDITION is non-nil.
+  "Evaluate BODY with progress message.
 SPEC is a list as followed (LABEL TOTAL [VAR])."
   (let ((label (nth 0 spec))
        (total (nth 1 spec))
@@ -1231,7 +1244,8 @@ SPEC is a list as followed (LABEL TOTAL [VAR])."
        (unwind-protect
           (progn
             ,@body)
-        (elmo-progress-done ,var)))))
+        (elmo-progress-clear ,var))
+       (elmo-progress-done ,var))))
 
 (put 'elmo-with-progress-display 'lisp-indent-function '2)
 (def-edebug-spec elmo-with-progress-display