diff --git a/jabber-libnotify.el b/jabber-libnotify.el index 73db5ff..60f29fe 100644 --- a/jabber-libnotify.el +++ b/jabber-libnotify.el @@ -1,5 +1,6 @@ ;; jabber-libnotify.el - emacs-jabber interface to libnotify +;; Copyright (C) 2010 - Kirill A. Korinskiy - catap@catap.ru ;; Copyright (C) 2007 - Rodrigo Lazo - rlazo.paz@gmail.com ;; This program is free software; you can redistribute it and/or modify @@ -16,6 +17,7 @@ ;; along with this program; if not, write to the Free Software ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +(require 'dbus nil t) (eval-when-compile (require 'jabber-alert)) (defcustom jabber-libnotify-icon "" @@ -34,6 +36,11 @@ :type 'string :group 'jabber-alerts) +(defcustom jabber-libnotify-app "Emacs Jabber" + "Defines the app of the pop up." + :type 'string + :group 'jabber-alerts) + (defcustom jabber-libnotify-urgency "low" "Urgency of libnotify message" :type '(choice (const :tag "Low" "low") @@ -41,18 +48,50 @@ (const :tag "Critical" "critical")) :group 'jabber-alerts) +(defcustom jabber-libnotify-method (if (featurep 'dbus) 'dbus 'shell) + "Specifies the method for libnotify call. Dbus is more faster but require emacs23+" + :type '(choice (const :tag "Shell" shell) + (const :tag "D-Bus" dbus)) + :group 'jabber-alerts) + +(defvar jabber-libnotify-id 0) + +(defun jabber-libnotify-next-id () + "Return the next notification id." + (setq jabber-libnotify-id (+ jabber-libnotify-id 1))) + (defun jabber-libnotify-message (msg) "Show MSG using libnotify" - ;; Possible errors include not finding the notify-send binary. - (condition-case e - (let ((process-connection-type nil)) - (start-process "notification" nil "notify-send" - "-t" (format "%s" jabber-libnotify-timeout) - "-i" (or jabber-libnotify-icon "\"\"") - "-u" jabber-libnotify-urgency - (or jabber-libnotify-message-header " ") msg)) - (error nil))) - + (cond + ((eq jabber-libnotify-method 'shell) + ;; Possible errors include not finding the notify-send binary. + (condition-case e + (let ((process-connection-type nil)) + (start-process "notification" nil "notify-send" + "-t" (format "%s" jabber-libnotify-timeout) + "-i" (or jabber-libnotify-icon "\"\"") + "-u" jabber-libnotify-urgency + (or jabber-libnotify-message-header " ") msg)) + (error nil))) + ((eq jabber-libnotify-method 'dbus) + (condition-case e + (when (and (fboundp 'dbus-ping) + (dbus-ping :session "org.freedesktop.Notifications")) + (dbus-call-method + :session ; use the session (not system) bus + "org.freedesktop.Notifications" ; service name + "/org/freedesktop/Notifications" ; path name + "org.freedesktop.Notifications" "Notify" ; Method + jabber-libnotify-app + (jabber-libnotify-next-id) + jabber-libnotify-icon + ':string (encode-coding-string + jabber-libnotify-message-header 'utf-8) + ':string (encode-coding-string msg 'utf-8) + '(:array) + '(:array :signature "{sv}") + ':int32 jabber-libnotify-timeout)) + (error nil))))) (define-jabber-alert libnotify "Show a message through the libnotify interface" 'jabber-libnotify-message)