1 ;; jabber-libnotify.el - emacs-jabber interface to libnotify -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2010 - Kirill A. Korinskiy - catap@catap.ru
4 ;; Copyright (C) 2007 - Rodrigo Lazo - rlazo.paz@gmail.com
6 ;; This program is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 2 of the License, or
9 ;; (at your option) any later version.
11 ;; This program is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;; GNU General Public License for more details.
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with this program; if not, write to the Free Software
18 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 (eval-when-compile (require 'jabber-alert))
23 (defcustom jabber-libnotify-icon ""
24 "Icon to be used on the notification pop-up. Default is empty"
25 :type '(file :must-match t)
26 :group 'jabber-alerts)
29 (defcustom jabber-libnotify-timeout 2500
30 "Specifies the timeout of the pop up window in millisecond"
32 :group 'jabber-alerts)
34 (defcustom jabber-libnotify-message-header "Jabber message"
35 "Defines the header of the pop up."
37 :group 'jabber-alerts)
39 (defcustom jabber-libnotify-app "Emacs Jabber"
40 "Defines the app of the pop up."
42 :group 'jabber-alerts)
44 (defcustom jabber-libnotify-urgency "low"
45 "Urgency of libnotify message"
46 :type '(choice (const :tag "Low" "low")
47 (const :tag "Normal" "normal")
48 (const :tag "Critical" "critical"))
49 :group 'jabber-alerts)
51 (defcustom jabber-libnotify-method (if (featurep 'dbus) 'dbus 'shell)
52 "Specifies the method for libnotify call. Dbus is more faster but require emacs23+"
53 :type '(choice (const :tag "Shell" shell)
54 (const :tag "D-Bus" dbus))
55 :group 'jabber-alerts)
57 (defvar jabber-libnotify-id 0)
59 (defun jabber-libnotify-next-id ()
60 "Return the next notification id."
61 (setq jabber-libnotify-id (+ jabber-libnotify-id 1)))
63 (defun jabber-libnotify-message (text &optional title)
64 "Show MSG using libnotify"
66 ((body (or (jabber-escape-xml text) " "))
67 (head (jabber-escape-xml
69 (or jabber-libnotify-message-header " ")
71 ;; Possible errors include not finding the notify-send binary.
74 ((eq jabber-libnotify-method 'shell)
75 (let ((process-connection-type nil))
76 (start-process "notification" nil "notify-send"
77 "-t" (format "%s" jabber-libnotify-timeout)
78 "-i" (or jabber-libnotify-icon "\"\"")
79 "-u" jabber-libnotify-urgency
81 ((eq jabber-libnotify-method 'dbus)
83 :session ; use the session (not system) bus
84 "org.freedesktop.Notifications" ; service name
85 "/org/freedesktop/Notifications" ; path name
86 "org.freedesktop.Notifications" "Notify" ; Method
88 (jabber-libnotify-next-id)
90 ':string (encode-coding-string head 'utf-8)
91 ':string (encode-coding-string body 'utf-8)
93 '(:array :signature "{sv}")
94 ':int32 jabber-libnotify-timeout)))
97 (define-jabber-alert libnotify "Show a message through the libnotify interface"
98 'jabber-libnotify-message)
99 (define-personal-jabber-alert jabber-muc-libnotify)
101 (provide 'jabber-libnotify)
103 ;; arch-tag: e9c4c210-8245-11dd-bddf-000a95c2fcd0