Merge from emacs-23; up to 2010-06-12T10:58:54Z!romain@orebokech.com.
[bpt/emacs.git] / lisp / notifications.el
index beb63a6..adb9fdd 100644 (file)
@@ -1,6 +1,6 @@
 ;;; notifications.el --- Client interface to desktop notifications.
 
-;; Copyright (C) 2010 Free Software Foundation, Inc.
+;; Copyright (C) 2010-2011 Free Software Foundation, Inc.
 
 ;; Author: Julien Danjou <julien@danjou.info>
 ;; Keywords: comm desktop notifications
@@ -42,6 +42,9 @@
 
 (require 'dbus)
 
+(defconst notifications-specification-version "1.1"
+  "The version of the Desktop Notifications Specification implemented.")
+
 (defconst notifications-application-name "Emacs"
   "Default application name.")
 
       (funcall (cadr entry) id action)
       (remove entry 'notifications-on-action-map))))
 
-(dbus-register-signal
- :session
- notifications-service
- notifications-path
- notifications-interface
- notifications-action-signal
- 'notifications-on-action-signal)
+(when (fboundp 'dbus-register-signal)
+  (dbus-register-signal
+   :session
+   notifications-service
+   notifications-path
+   notifications-interface
+   notifications-action-signal
+   'notifications-on-action-signal))
 
 (defun notifications-on-closed-signal (id reason)
   "Dispatch signals to callback functions from `notifications-on-closed-map'."
               id (cadr (assoc reason notifications-closed-reason)))
       (remove entry 'notifications-on-close-map))))
 
-(dbus-register-signal
- :session
- notifications-service
- notifications-path
- notifications-interface
- notifications-closed-signal
- 'notifications-on-closed-signal)
+(when (fboundp 'dbus-register-signal)
+  (dbus-register-signal
+   :session
+   notifications-service
+   notifications-path
+   notifications-interface
+   notifications-closed-signal
+   'notifications-on-closed-signal))
 
 (defun notifications-notify (&rest params)
   "Send notification via D-Bus using the Freedesktop notification protocol.
@@ -151,7 +156,14 @@ Various PARAMS can be set:
  :image-data     This is a raw data image format which describes the width,
                  height, rowstride, has alpha, bits per sample, channels and
                  image data respectively.
+ :image-path     This is represented either as a URI (file:// is the
+                 only URI schema supported right now) or a name
+                 in a freedesktop.org-compliant icon theme.
  :sound-file     The path to a sound file to play when the notification pops up.
+ :sound-name     A themeable named sound from the freedesktop.org sound naming
+                 specification to play when the notification pops up.
+                 Similar to icon-name,only for sounds. An example would
+                 be \"message-new-instant\".
  :suppress-sound Causes the server to suppress playing any sounds, if it has
                  that ability.
  :x              Specifies the X location on the screen that the notification
@@ -186,7 +198,9 @@ used to manipulate the notification item with
         (category (plist-get params :category))
         (desktop-entry (plist-get params :desktop-entry))
         (image-data (plist-get params :image-data))
+        (image-path (plist-get params :image-path))
         (sound-file (plist-get params :sound-file))
+        (sound-name (plist-get params :sound-name))
         (suppress-sound (plist-get params :suppress-sound))
         (x (plist-get params :x))
         (y (plist-get params :y))
@@ -196,8 +210,8 @@ used to manipulate the notification item with
       (add-to-list 'hints `(:dict-entry
                             "urgency"
                             (:variant :byte ,(case urgency
-                                               ('low 0)
-                                               ('critical 2)
+                                               (low 0)
+                                               (critical 2)
                                                (t 1)))) t))
     (when category
       (add-to-list 'hints `(:dict-entry
@@ -211,10 +225,18 @@ used to manipulate the notification item with
       (add-to-list 'hints `(:dict-entry
                             "image_data"
                             (:variant :struct ,image-data)) t))
+    (when image-path
+      (add-to-list 'hints `(:dict-entry
+                            "image_path"
+                            (:variant :string ,image-path)) t))
     (when sound-file
       (add-to-list 'hints `(:dict-entry
                             "sound-file"
                             (:variant :string ,sound-file)) t))
+    (when sound-name
+      (add-to-list 'hints `(:dict-entry
+                            "sound-name"
+                            (:variant :string ,sound-name)) t))
     (when suppress-sound
       (add-to-list 'hints `(:dict-entry
                             "suppress-sound"