* Makefile.am (EXTRA_DIST): Remove INSTALL-CVS.
[elisp/riece.git] / lisp / riece-notify.el
1 ;;; riece-notify.el --- display notification on status area
2 ;; Copyright (C) 1998-2008 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Keywords: IRC, riece
7
8 ;; This file is part of Riece.
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24
25 ;;; Commentary:
26
27 ;; NOTE: This is an add-on module for Riece.
28
29 ;;; Code:
30
31 (require 'riece-message)
32 (eval-when-compile (require 'riece-keyword))
33 (require 'dbus)
34
35 (defconst riece-notify-description "Display notification on status area.")
36
37 (defun riece-notify-keyword-notify-function (keyword message)
38   (riece--notify (format "%s: %s"
39                          (riece-format-identity (riece-message-speaker message))
40                          (riece-message-text message))))
41
42 (defun riece--notify (string)
43   (dbus-call-method
44    :session "org.freedesktop.Notifications"
45    "/org/freedesktop/Notifications"
46    "org.freedesktop.Notifications" "Notify"
47    "GNU Emacs"                 ;; Application name.
48    0                           ;; No replacement of other notifications.
49    ""                          ;; No icon.
50    "Notification summary"      ;; Summary.
51    (encode-coding-string string 'utf-8) ;; Body.
52    '(:array)                   ;; No actions (empty array of strings).
53    '(:array :signature "{sv}") ;; No hints
54    ;; (empty array of dictionary entries).
55    ':int32 -1)                 ;; Default timeout.
56   )
57
58 (defun riece-notify-requires ()
59   '(riece-keyword))
60
61 (defun riece-notify-insinuate ()
62   (add-hook 'riece-keyword-notify-functions
63             'riece-notify-keyword-notify-function))
64
65 (defun riece-notify-uninstall ()
66   (remove-hook 'riece-keyword-notify-functions
67                'riece-notify-keyword-notify-function))
68
69 (provide 'riece-notify)
70
71 ;;; riece-notify.el ends here