diff options
| author | Julien Danjou | 2012-08-30 22:14:27 +0000 |
|---|---|---|
| committer | Katsumi Yamaoka | 2012-08-30 22:14:27 +0000 |
| commit | ba7ac1f6e5f675614953c51dafff677b7ddafa2b (patch) | |
| tree | 7bca576779a5d51f2fa4c58138973d0a400a24a3 | |
| parent | b118352941c84d26d38be3ab77d4939bfd70de2f (diff) | |
| download | emacs-ba7ac1f6e5f675614953c51dafff677b7ddafa2b.tar.gz emacs-ba7ac1f6e5f675614953c51dafff677b7ddafa2b.zip | |
gnus-notifications.el: Add defcustom for timeout and actions support
| -rw-r--r-- | lisp/gnus/ChangeLog | 12 | ||||
| -rw-r--r-- | lisp/gnus/gnus-notifications.el | 58 |
2 files changed, 53 insertions, 17 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog index 9de24402f90..c449f53d420 100644 --- a/lisp/gnus/ChangeLog +++ b/lisp/gnus/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2012-08-30 Julien Danjou <julien@danjou.info> | ||
| 2 | |||
| 3 | * gnus-notifications.el (gnus-notifications-notify): Use timeout from | ||
| 4 | `gnus-notifications-timeout'. | ||
| 5 | (gnus-notifications-timeout): Add. | ||
| 6 | (gnus-notifications-action): New function. | ||
| 7 | (gnus-notifications-notify): Add :action using | ||
| 8 | `gnus-notifications-action'. | ||
| 9 | (gnus-notifications-id-to-msg): New variable. | ||
| 10 | (gnus-notifications): Use `gnus-notifications-id-to-msg' to map | ||
| 11 | notifications id to messages. | ||
| 12 | |||
| 1 | 2012-08-30 Kenichi Handa <handa@gnu.org> | 13 | 2012-08-30 Kenichi Handa <handa@gnu.org> |
| 2 | 14 | ||
| 3 | * qp.el (quoted-printable-decode-region): Decode multiple bytes at | 15 | * qp.el (quoted-printable-decode-region): Decode multiple bytes at |
diff --git a/lisp/gnus/gnus-notifications.el b/lisp/gnus/gnus-notifications.el index 8811b47ba42..811a90895ae 100644 --- a/lisp/gnus/gnus-notifications.el +++ b/lisp/gnus/gnus-notifications.el | |||
| @@ -58,20 +58,42 @@ not get notifications." | |||
| 58 | :type 'integer | 58 | :type 'integer |
| 59 | :group 'gnus-notifications) | 59 | :group 'gnus-notifications) |
| 60 | 60 | ||
| 61 | (defcustom gnus-notifications-timeout nil | ||
| 62 | "Timeout used for notifications sent via `notifications-notify'." | ||
| 63 | :type 'integer | ||
| 64 | :group 'gnus-notifications) | ||
| 65 | |||
| 61 | (defvar gnus-notifications-sent nil | 66 | (defvar gnus-notifications-sent nil |
| 62 | "Notifications already sent.") | 67 | "Notifications already sent.") |
| 63 | 68 | ||
| 69 | (defvar gnus-notifications-id-to-msg nil | ||
| 70 | "Map notifications ids to messages.") | ||
| 71 | |||
| 72 | (defun gnus-notifications-action (id key) | ||
| 73 | (when (string= key "read") | ||
| 74 | (let ((group-article (assoc id gnus-notifications-id-to-msg))) | ||
| 75 | (when group-article | ||
| 76 | (let ((group (cadr group-article)) | ||
| 77 | (article (caddr group-article))) | ||
| 78 | (gnus-fetch-group group (list article))))))) | ||
| 79 | |||
| 64 | (defun gnus-notifications-notify (from subject photo-file) | 80 | (defun gnus-notifications-notify (from subject photo-file) |
| 65 | "Send a notification about a new mail." | 81 | "Send a notification about a new mail. |
| 82 | Return a notification id if any, or t on success." | ||
| 66 | (if (fboundp 'notifications-notify) | 83 | (if (fboundp 'notifications-notify) |
| 67 | (notifications-notify | 84 | (notifications-notify |
| 68 | :title from | 85 | :title from |
| 69 | :body subject | 86 | :body subject |
| 87 | :actions '("read" "Read") | ||
| 88 | :on-action 'gnus-notifications-action | ||
| 70 | :app-icon (image-search-load-path "gnus/gnus.png") | 89 | :app-icon (image-search-load-path "gnus/gnus.png") |
| 71 | :app-name "Gnus" | 90 | :app-name "Gnus" |
| 72 | :category "email.arrived" | 91 | :category "email.arrived" |
| 92 | :timeout gnus-notifications-timeout | ||
| 73 | :image-path photo-file) | 93 | :image-path photo-file) |
| 74 | (message "New message from %s: %s" from subject))) | 94 | (message "New message from %s: %s" from subject) |
| 95 | ;; Don't return an id | ||
| 96 | t)) | ||
| 75 | 97 | ||
| 76 | (defun gnus-notifications-get-photo (mail-address) | 98 | (defun gnus-notifications-get-photo (mail-address) |
| 77 | "Get photo for mail address." | 99 | "Get photo for mail address." |
| @@ -136,21 +158,23 @@ This is typically a function to add in | |||
| 136 | (article-decode-encoded-words) ; to decode mail addresses, subjects, etc | 158 | (article-decode-encoded-words) ; to decode mail addresses, subjects, etc |
| 137 | (let* ((address-components (mail-extract-address-components | 159 | (let* ((address-components (mail-extract-address-components |
| 138 | (or (mail-fetch-field "From") ""))) | 160 | (or (mail-fetch-field "From") ""))) |
| 139 | (address (cadr address-components)) | 161 | (address (cadr address-components))) |
| 140 | (photo-file (gnus-notifications-get-photo-file | 162 | ;; Ignore mails from ourselves |
| 141 | address))) | 163 | (unless (gnus-string-match-p gnus-ignored-from-addresses |
| 142 | (when (or | 164 | address) |
| 143 | ;; Ignore mails from ourselves | 165 | (let* ((photo-file (gnus-notifications-get-photo-file address)) |
| 144 | (gnus-string-match-p gnus-ignored-from-addresses | 166 | (notification-id (gnus-notifications-notify |
| 145 | address) | 167 | (or (car address-components) address) |
| 146 | (gnus-notifications-notify | 168 | (mail-fetch-field "Subject") |
| 147 | (or (car address-components) address) | 169 | photo-file))) |
| 148 | (mail-fetch-field "Subject") | 170 | (when notification-id |
| 149 | photo-file)) | 171 | ;; Register that we did notify this message |
| 150 | ;; Register that we did notify this message | 172 | (setcdr group-notifications (cons article (cdr group-notifications))) |
| 151 | (setcdr group-notifications (cons article (cdr group-notifications)))) | 173 | (unless (eq notification-id t) |
| 152 | (when photo-file | 174 | ;; Register the notification id for later actions |
| 153 | (delete-file photo-file))))))))))) | 175 | (add-to-list 'gnus-notifications-id-to-msg (list notification-id group article)))) |
| 176 | (when photo-file | ||
| 177 | (delete-file photo-file))))))))))))) | ||
| 154 | 178 | ||
| 155 | (provide 'gnus-notifications) | 179 | (provide 'gnus-notifications) |
| 156 | 180 | ||