annotate lisp/net/notifications.el @ 108925:515ffffc30e6

* net/notifications.el (notifications-notify): Fix docstring.
author Michael Albinus <albinus@detlef>
date Wed, 09 Jun 2010 19:54:28 +0200
parents 838873812c0a
children da553d450193
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
108916
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
1 ;;; notifications.el --- Client interface to desktop notifications.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
2
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
3 ;; Copyright (C) 2010 Free Software Foundation, Inc.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
4
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
5 ;; Author: Julien Danjou <julien@danjou.info>
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
6 ;; Keywords: comm desktop notifications
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
7
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
9
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
13 ;; (at your option) any later version.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
14
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
18 ;; GNU General Public License for more details.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
19
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
22
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
23 ;;; Commentary:
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
24
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
25 ;; This package provides an implementation of the Desktop Notifications
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
26 ;; <http://www.galago-project.org/specs/notification/>.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
27
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
28 ;; In order to activate this package, you must add the following code
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
29 ;; into your .emacs:
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
30 ;;
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
31 ;; (require 'notifications)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
32
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
33 ;;; Code:
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
34 (eval-when-compile
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
35 (require 'cl))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
36
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
37 ;; Pacify byte-compiler. D-Bus support in the Emacs core can be
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
38 ;; disabled with configuration option "--without-dbus". Declare used
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
39 ;; subroutines and variables of `dbus' therefore.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
40 (declare-function dbus-call-method "dbusbind.c")
108920
838873812c0a * net/notifications.el (dbus-register-signal): Declare function.
Juanma Barranquero <lekktu@gmail.com>
parents: 108918
diff changeset
41 (declare-function dbus-register-signal "dbusbind.c")
108916
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
42
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
43 (require 'dbus)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
44
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
45 (defconst notifications-application-name "Emacs"
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
46 "Default application name.")
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
47
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
48 (defconst notifications-application-icon
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
49 (expand-file-name
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
50 "images/icons/hicolor/scalable/apps/emacs.svg"
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
51 data-directory)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
52 "Default application icon.")
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
53
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
54 (defconst notifications-service "org.freedesktop.Notifications"
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
55 "D-Bus notifications service name.")
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
56
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
57 (defconst notifications-path "/org/freedesktop/Notifications"
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
58 "D-Bus notifications service path.")
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
59
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
60 (defconst notifications-interface "org.freedesktop.Notifications"
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
61 "D-Bus notifications service path.")
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
62
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
63 (defconst notifications-notify-method "Notify"
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
64 "D-Bus notifications service path.")
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
65
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
66 (defconst notifications-close-notification-method "CloseNotification"
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
67 "D-Bus notifications service path.")
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
68
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
69 (defconst notifications-action-signal "ActionInvoked"
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
70 "D-Bus notifications action signal.")
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
71
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
72 (defconst notifications-closed-signal "NotificationClosed"
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
73 "D-Bus notifications closed signal.")
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
74
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
75 (defconst notifications-closed-reason
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
76 '((1 expired)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
77 (2 dismissed)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
78 (3 close-notification)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
79 (4 undefined))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
80 "List of reasons why a notification has been closed.")
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
81
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
82 (defvar notifications-on-action-map nil
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
83 "Mapping between notification and action callback functions.")
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
84
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
85 (defvar notifications-on-close-map nil
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
86 "Mapping between notification and close callback functions.")
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
87
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
88 (defun notifications-on-action-signal (id action)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
89 (let ((entry (assoc id notifications-on-action-map)))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
90 (when entry
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
91 (funcall (cadr entry) action)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
92 (remove entry 'notifications-on-action-map))))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
93
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
94 (dbus-register-signal
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
95 :session
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
96 notifications-service
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
97 notifications-path
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
98 notifications-interface
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
99 notifications-action-signal
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
100 'notifications-on-action-signal)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
101
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
102 (defun notifications-on-closed-signal (id reason)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
103 (let ((entry (assoc id notifications-on-close-map)))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
104 (when entry
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
105 (funcall (cadr entry) (cadr (assoc reason notifications-closed-reason)))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
106 (remove entry 'notifications-on-close-map))))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
107
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
108 (dbus-register-signal
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
109 :session
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
110 notifications-service
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
111 notifications-path
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
112 notifications-interface
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
113 notifications-closed-signal
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
114 'notifications-on-closed-signal)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
115
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
116 (defun notifications-notify (&rest params)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
117 "Send notification via D-Bus using the Freedesktop notification protocol.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
118 Various PARAMS can be set:
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
119
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
120 :title The notification title.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
121 :body The notification body text.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
122 :app-name The name of the application sending the notification.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
123 Default to `notifications-application-name'.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
124 :replaces-id The notification ID that this notification replaces.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
125 :app-icon The notification icon.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
126 Default is `notifications-application-icon'.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
127 Set to nil if you do not want any icon displayed.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
128 :actions A list of actions in the form:
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
129 (KEY TITLE KEY TITLE ...)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
130 where KEY and TITLE are both strings.
108920
838873812c0a * net/notifications.el (dbus-register-signal): Declare function.
Juanma Barranquero <lekktu@gmail.com>
parents: 108918
diff changeset
131 The default action (usually invoked by clicking the
838873812c0a * net/notifications.el (dbus-register-signal): Declare function.
Juanma Barranquero <lekktu@gmail.com>
parents: 108918
diff changeset
132 notification) should have a key named \"default\".
108925
515ffffc30e6 * net/notifications.el (notifications-notify): Fix docstring.
Michael Albinus <albinus@detlef>
parents: 108920
diff changeset
133 The title can be anything, though implementations are free
108920
838873812c0a * net/notifications.el (dbus-register-signal): Declare function.
Juanma Barranquero <lekktu@gmail.com>
parents: 108918
diff changeset
134 not to display it.
108916
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
135 :timeout The timeout time in milliseconds since the display
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
136 of the notification at which the notification should
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
137 automatically close.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
138 If -1, the notification's expiration time is dependent
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
139 on the notification server's settings, and may vary for
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
140 the type of notification.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
141 If 0, the notification never expires.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
142 Default value is -1.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
143 :urgency The urgency level.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
144 Either `low', `normal' or `critical'.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
145 :category The type of notification this is.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
146 :desktop-entry This specifies the name of the desktop filename representing
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
147 the calling program.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
148 :image-data This is a raw data image format which describes the width,
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
149 height, rowstride, has alpha, bits per sample, channels and
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
150 image data respectively.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
151 :sound-file The path to a sound file to play when the notification pops up.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
152 :suppress-sound Causes the server to suppress playing any sounds, if it has
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
153 that ability.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
154 :x Specifies the X location on the screen that the notification
108920
838873812c0a * net/notifications.el (dbus-register-signal): Declare function.
Juanma Barranquero <lekktu@gmail.com>
parents: 108918
diff changeset
155 should point to. The \"y\" hint must also be specified.
108916
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
156 :y Specifies the Y location on the screen that the notification
108920
838873812c0a * net/notifications.el (dbus-register-signal): Declare function.
Juanma Barranquero <lekktu@gmail.com>
parents: 108918
diff changeset
157 should point to. The \"x\" hint must also be specified.
838873812c0a * net/notifications.el (dbus-register-signal): Declare function.
Juanma Barranquero <lekktu@gmail.com>
parents: 108918
diff changeset
158 :on-action Function to call when an action is invoked. The key of the
108916
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
159 action is passed as argument to the function.
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
160 :on-close Function to call when the notification has been closed
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
161 by timeout or by the user.
108920
838873812c0a * net/notifications.el (dbus-register-signal): Declare function.
Juanma Barranquero <lekktu@gmail.com>
parents: 108918
diff changeset
162 The function receives the closing reason as argument:
108916
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
163 - `expired' if the notification has expired
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
164 - `dismissed' if the notification was dismissed by the user
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
165 - `close-notification' if the notification was closed
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
166 by a call to CloseNotification
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
167
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
168 This function returns a notification id, an integer, which can be
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
169 used to manipulate the notification item with
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
170 `notifications-close'."
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
171 (let ((title (plist-get params :title))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
172 (body (plist-get params :body))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
173 (app-name (plist-get params :app-name))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
174 (replaces-id (plist-get params :replaces-id))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
175 (app-icon (plist-get params :app-icon))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
176 (actions (plist-get params :actions))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
177 (timeout (plist-get params :timeout))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
178 ;; Hints
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
179 (hints '())
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
180 (urgency (plist-get params :urgency))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
181 (category (plist-get params :category))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
182 (desktop-entry (plist-get params :desktop-entry))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
183 (image-data (plist-get params :image-data))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
184 (sound-file (plist-get params :sound-file))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
185 (suppress-sound (plist-get params :suppress-sound))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
186 (x (plist-get params :x))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
187 (y (plist-get params :y))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
188 id)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
189 ;; Build hints array
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
190 (when urgency
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
191 (add-to-list 'hints `(:dict-entry
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
192 "urgency"
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
193 (:variant :byte ,(case urgency
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
194 ('low 0)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
195 ('critical 2)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
196 (t 1)))) t))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
197 (when category
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
198 (add-to-list 'hints `(:dict-entry
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
199 "category"
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
200 (:variant :string ,category)) t))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
201 (when desktop-entry
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
202 (add-to-list 'hints `(:dict-entry
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
203 "desktop-entry"
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
204 (:variant :string ,desktop-entry)) t))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
205 (when image-data
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
206 (add-to-list 'hints `(:dict-entry
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
207 "image_data"
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
208 (:variant :struct ,image-data)) t))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
209 (when sound-file
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
210 (add-to-list 'hints `(:dict-entry
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
211 "sound-file"
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
212 (:variant :string ,sound-file)) t))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
213 (when suppress-sound
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
214 (add-to-list 'hints `(:dict-entry
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
215 "suppress-sound"
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
216 (:variant :boolean ,suppress-sound)) t))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
217 (when x
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
218 (add-to-list 'hints `(:dict-entry "x" (:variant :int32 ,x)) t))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
219 (when y
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
220 (add-to-list 'hints `(:dict-entry "y" (:variant :int32 ,y)) t))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
221
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
222 ;; Call Notify method
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
223 (setq id
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
224 (dbus-call-method :session
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
225 notifications-service
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
226 notifications-path
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
227 notifications-interface
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
228 notifications-notify-method
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
229 :string (or app-name
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
230 notifications-application-name)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
231 :uint32 (or replaces-id 0)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
232 :string (if app-icon
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
233 (expand-file-name app-icon)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
234 ;; If app-icon is nil because user
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
235 ;; requested it to be so, send the
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
236 ;; empty string
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
237 (if (plist-member params :app-icon)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
238 ""
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
239 ;; Otherwise send the default icon path
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
240 notifications-application-icon))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
241 :string (or title "")
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
242 :string (or body "")
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
243 `(:array ,@actions)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
244 (or hints '(:array :signature "{sv}"))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
245 :int32 (or timeout -1)))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
246
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
247 ;; Register close/action callback function
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
248 (let ((on-action (plist-get params :on-action))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
249 (on-close (plist-get params :on-close)))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
250 (when on-action
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
251 (add-to-list 'notifications-on-action-map (list id on-action)))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
252 (when on-close
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
253 (add-to-list 'notifications-on-close-map (list id on-close))))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
254
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
255 ;; Return notification id
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
256 id))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
257
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
258 (defun notifications-close-notification (id)
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
259 "Close a notification with identifier ID."
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
260 (dbus-call-method :session
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
261 notifications-service
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
262 notifications-path
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
263 notifications-interface
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
264 notifications-close-notification-method
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
265 :int32 id))
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
266
f0e5fbe77b7c * notifications.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
267 (provide 'notifications)