1 ;;; notify.el --- notification frontend
3 ;; Copyright (C) 2008 Mark A. Hershberger
5 ;; Original Author: Mark A. Hershberger <mhersberger@intrahealth.org>
6 ;; Keywords: extensions, convenience, lisp
8 ;; This file is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; This file is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
20 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
25 ;; This provides a single function, notify, that will produce a notify
30 (defvar notify-last '(0 0 0))
32 (defvar notify-defaults
33 (list :app "GNU Emacs"
34 :icon "/usr/share/icons/emacs22/emacs_48.png"
37 :category "emacs.message"))
41 (defvar notify-delay '(0 5 0))
43 (defvar notify-last-notification '(0 5 0))
45 ;; We could set up other notification methods like notify-via-shell or
47 (defvar notify-method 'notify-via-dbus)
49 (defun notify-next-id ()
50 "Return the next notification id."
51 (setq notify-id (+ notify-id 1)))
53 (defun notify-via-dbus (title body params)
54 "Send notification via DBus."
55 (when (and (fboundp 'dbus-ping)
56 (dbus-ping :session "org.freedesktop.Notifications"))
57 (dbus-call-method :session "org.freedesktop.Notifications"
58 "/org/freedesktop/Notifications"
59 "org.freedesktop.Notifications" "Notify"
66 '(:array :signature "{sv}")
67 ':int32 (get 'params :timeout))))
69 (defun notify (title body &rest args)
70 "Use pop-up notifications for events."
72 (time-less-p notify-delay
73 (time-since notify-last-notification))
75 (keywords-to-properties 'params args notify-defaults)
76 (setq notify-last-notification (current-time))
77 (funcall notify-method title body params)))))
79 (defun keywords-to-properties (symbol args &optional defaults)
80 "Convert a list in the form (:keywordA valueA
82 to a list of propertys with the given values"
83 (when (car-safe defaults) ; probably need to avoid recursion
84 (keywords-to-properties symbol defaults))
86 (let ((arg (car args)))
87 (setq args (cdr args))
89 (error "Junk in args %S" args))
93 (error "Keyword %s is missing an argument" keyword))
94 (setq args (cdr args))
95 (put symbol keyword value)))))
99 ;;; notify.el ends here