Show appointment notifications as notifications

This commit is contained in:
Tom Willemse 2016-05-17 02:00:38 +02:00
parent 62a267f633
commit 2260dde68d

View file

@ -26,20 +26,52 @@
;;; Code:
(require 'appt)
(require 'notifications)
(autoload 'jabber-send-message "jabber-chat")
(defvar jabber-connections)
(defun oni:appt-display-single-notification (min-to-appt cur-time body)
"Show an appointment in a desktop notification.
(defun oni:appt-display-window-and-jabber (min-to-app new-time appt-msg)
"Send a message to my phone jabber account."
(let ((fmt "%s%s (in %s minutes)"))
(jabber-send-message
(car jabber-connections) "phone@ryuslash.org" nil
(format fmt new-time appt-msg min-to-app) nil))
(appt-disp-window min-to-app new-time appt-msg))
MIN-TO-APPT should be a string with the number of minutes until
the appointment. CUR-TIME is the current time. BODY is the text
of the appointment."
(ignore cur-time)
(let ((minutes (string-to-number min-to-appt)))
(notifications-notify
:title (cond
((= minutes 0) "Appointment right now")
((= minutes 1) "Appointment in 1 minute")
(t (format "Appointment in %s minute(s)" min-to-appt)))
:body body)))
(setq appt-display-diary nil)
(defun oni:appt-display-multiple-notifications
(mins-to-appts cur-time bodies)
"Show multiple appointments in desktop notifications.
MINS-TO-APPTS should be a list of strings with the numbers of
minutes until the appointments. CUR-TIME is the current time.
BODIES is the texts of the appointments."
(cl-mapc (lambda (min-to-appt body)
(oni:appt-display-single-notification
min-to-appt cur-time body))
mins-to-appts bodies))
(defun oni:appt-display-notification (mins-to-appts cur-time bodies)
"Show one or more appointments in desktop notifications.
MINS-TO-APPTS should be either a string with the number of
minutes until the appointment, or a list of strings with the
numbers of minutes until each appointment. CUR-TIME is the
current time. BODIES is either a string with the text of the
appointment or a list of strings with the text for each
appointment."
(let ((func (if (listp bodies)
'oni:appt-display-multiple-notifications
'oni:appt-display-single-notification)))
(funcall func mins-to-appts cur-time bodies)))
(setq appt-disp-window-function #'oni:appt-display-notification
appt-delete-window-function (lambda ())
appt-display-diary nil)
(provide 'appt-init)
;;; appt-init.el ends here