al-appt.el 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. ;;; al-appt.el --- Additional functionality for appointments
  2. ;; Copyright © 2014-2016 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;;
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;;
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (require 'notifications)
  17. (require 'al-sound)
  18. (require 'al-file)
  19. (defvar al/appt-actions
  20. '((5 . al/appt-notify-normal)
  21. (0 . al/appt-notify-urgent))
  22. "Alist of minutes left for an appointment and action functions.
  23. Each function is called with an appointment string when the
  24. according number of minutes is left.")
  25. (defvar al/appt-notify-normal-sound
  26. (al/file-if-exists
  27. "/usr/share/sounds/freedesktop/stereo/bell.oga")
  28. "Audio file used by `al/appt-notify-normal'.")
  29. (defvar al/appt-notify-urgent-sound
  30. (al/file-if-exists
  31. "/usr/share/sounds/freedesktop/stereo/complete.oga")
  32. "Audio file used by `al/appt-notify-urgent'.")
  33. (defun al/appt-notify-sound (sound)
  34. "Notify about an appointment by playing SOUND."
  35. (al/play-sound sound))
  36. (defun al/appt-notify-sound-message (sound string)
  37. "Notify about an appointment by playing SOUND and displaying STRING."
  38. (al/play-sound sound)
  39. (notifications-notify :title "Appointment"
  40. :body string))
  41. (defun al/appt-notify-normal (&optional _)
  42. "Notify about an appointment in a normal way.
  43. Use `al/appt-notify-normal-sound'."
  44. (al/appt-notify-sound al/appt-notify-normal-sound))
  45. (defun al/appt-notify-urgent (string)
  46. "Notify about an appointment in an urgent way.
  47. Use `al/appt-notify-urgent-sound'."
  48. (al/appt-notify-sound-message al/appt-notify-urgent-sound
  49. string))
  50. (defun al/appt-display-message (strings mins)
  51. "Notify about an appointment if needed.
  52. This function is a substitution for `appt-display-message',
  53. because I know better what to do."
  54. (let* ((string (car strings))
  55. (min (car mins))
  56. (fun (cdr (assq min al/appt-actions))))
  57. (and fun (funcall fun string))))
  58. (provide 'al-appt)
  59. ;;; al-appt.el ends here