Improve queue-related actions of the main view

- The queue-related actions of `mu4e~main-view-real` have been extracted
  to their own `mu4e~main-view-queue` method.
- The queue toggling action now has the word "currently" to easily.
  distinguish between the current state and the toggle (e.g., "currently
  queued" instead of just "queued").
- The "[f]lush queued emails" is only visible if there is at least 1
  email in the queue.
- The number of emails in the queue is visible in the flushing
  action (e.g., "[f]lush 10 queued emails").
This commit is contained in:
Damien Cassou 2015-01-19 10:36:55 +01:00
parent ce5905ffca
commit 8a2c40a4b7
1 changed files with 31 additions and 9 deletions

View File

@ -138,15 +138,9 @@ clicked."
'mu4e-update-mail-and-index)
;; show the queue functions if `smtpmail-queue-dir' is defined
(if (file-directory-p smtpmail-queue-dir)
(concat
(mu4e~main-action-str "\t* toggle [m]ail sending mode "
'mu4e~main-toggle-mail-sending-mode)
"(" (propertize (if smtpmail-queue-mail "queued" "direct")
'face 'mu4e-header-key-face) ")\n"
(mu4e~main-action-str "\t* [f]lush queued mail\n"
'smtpmail-send-queued-mail))
"")
(if (file-directory-p smtpmail-queue-dir)
(mu4e~main-view-queue)
"")
"\n"
(mu4e~main-action-str "\t* [A]bout mu4e\n" 'mu4e-about)
(mu4e~main-action-str "\t* [H]elp\n" 'mu4e-display-manual)
@ -154,6 +148,34 @@ clicked."
(mu4e-main-mode)
)))
(defun mu4e~main-view-queue ()
"Display queue-related actions in the main view."
(concat
(mu4e~main-action-str "\t* toggle [m]ail sending mode "
'mu4e~main-toggle-mail-sending-mode)
"(currently "
(propertize (if smtpmail-queue-mail "queued" "direct")
'face 'mu4e-header-key-face)
")\n"
(let ((queue-size (mu4e~main-queue-size)))
(if (zerop queue-size)
""
(mu4e~main-action-str
(format "\t* [f]lush %s queued %s\n"
(propertize (int-to-string queue-size)
'face 'mu4e-header-key-face)
(if (> queue-size 1) "mails" "mail"))
'smtpmail-send-queued-mail)))))
(defun mu4e~main-queue-size ()
"Return, as an int, the number of emails in the queue."
(condition-case nil
(with-temp-buffer
(insert-file-contents (expand-file-name smtpmail-queue-index-file
smtpmail-queue-dir))
(count-lines (point-min) (point-max)))
(error 0)))
(defun mu4e~main-view ()
"Create the mu4e main-view, and switch to it."
(mu4e~main-view-real nil nil)