Add work with libnotify by dbus
This commit is contained in:
parent
c31d8a0918
commit
7c5dfede4d
|
@ -1,5 +1,6 @@
|
||||||
;; jabber-libnotify.el - emacs-jabber interface to libnotify
|
;; 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
|
;; Copyright (C) 2007 - Rodrigo Lazo - rlazo.paz@gmail.com
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or modify
|
;; 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
|
;; along with this program; if not, write to the Free Software
|
||||||
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
(require 'dbus nil t)
|
||||||
(eval-when-compile (require 'jabber-alert))
|
(eval-when-compile (require 'jabber-alert))
|
||||||
|
|
||||||
(defcustom jabber-libnotify-icon ""
|
(defcustom jabber-libnotify-icon ""
|
||||||
|
@ -34,6 +36,11 @@
|
||||||
:type 'string
|
:type 'string
|
||||||
:group 'jabber-alerts)
|
: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"
|
(defcustom jabber-libnotify-urgency "low"
|
||||||
"Urgency of libnotify message"
|
"Urgency of libnotify message"
|
||||||
:type '(choice (const :tag "Low" "low")
|
:type '(choice (const :tag "Low" "low")
|
||||||
|
@ -41,18 +48,50 @@
|
||||||
(const :tag "Critical" "critical"))
|
(const :tag "Critical" "critical"))
|
||||||
:group 'jabber-alerts)
|
: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)
|
(defun jabber-libnotify-message (msg)
|
||||||
"Show MSG using libnotify"
|
"Show MSG using libnotify"
|
||||||
;; Possible errors include not finding the notify-send binary.
|
(cond
|
||||||
(condition-case e
|
((eq jabber-libnotify-method 'shell)
|
||||||
(let ((process-connection-type nil))
|
;; Possible errors include not finding the notify-send binary.
|
||||||
(start-process "notification" nil "notify-send"
|
(condition-case e
|
||||||
"-t" (format "%s" jabber-libnotify-timeout)
|
(let ((process-connection-type nil))
|
||||||
"-i" (or jabber-libnotify-icon "\"\"")
|
(start-process "notification" nil "notify-send"
|
||||||
"-u" jabber-libnotify-urgency
|
"-t" (format "%s" jabber-libnotify-timeout)
|
||||||
(or jabber-libnotify-message-header " ") msg))
|
"-i" (or jabber-libnotify-icon "\"\"")
|
||||||
(error nil)))
|
"-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"
|
(define-jabber-alert libnotify "Show a message through the libnotify interface"
|
||||||
'jabber-libnotify-message)
|
'jabber-libnotify-message)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user