]> crepu.dev Git - config.git/blob - djavu-asus/elpa/jabber-20230715.456/jabber-libnotify.el
Actualizado el Readme
[config.git] / djavu-asus / elpa / jabber-20230715.456 / jabber-libnotify.el
1 ;; jabber-libnotify.el - emacs-jabber interface to libnotify -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2010 - Kirill A. Korinskiy - catap@catap.ru
4 ;; Copyright (C) 2007 - Rodrigo Lazo - rlazo.paz@gmail.com
5
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.
10
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.
15
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
19
20 (require 'dbus nil t)
21 (eval-when-compile (require 'jabber-alert))
22
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)
27
28
29 (defcustom jabber-libnotify-timeout 2500
30 "Specifies the timeout of the pop up window in millisecond"
31 :type 'integer
32 :group 'jabber-alerts)
33
34 (defcustom jabber-libnotify-message-header "Jabber message"
35 "Defines the header of the pop up."
36 :type 'string
37 :group 'jabber-alerts)
38
39 (defcustom jabber-libnotify-app "Emacs Jabber"
40 "Defines the app of the pop up."
41 :type 'string
42 :group 'jabber-alerts)
43
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)
50
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)
56
57 (defvar jabber-libnotify-id 0)
58
59 (defun jabber-libnotify-next-id ()
60 "Return the next notification id."
61 (setq jabber-libnotify-id (+ jabber-libnotify-id 1)))
62
63 (defun jabber-libnotify-message (text &optional title)
64 "Show MSG using libnotify"
65 (let
66 ((body (or (jabber-escape-xml text) " "))
67 (head (jabber-escape-xml
68 (or title
69 (or jabber-libnotify-message-header " ")
70 text))))
71 ;; Possible errors include not finding the notify-send binary.
72 (condition-case e
73 (cond
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
80 head body)))
81 ((eq jabber-libnotify-method 'dbus)
82 (dbus-call-method
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
87 jabber-libnotify-app
88 (jabber-libnotify-next-id)
89 jabber-libnotify-icon
90 ':string (encode-coding-string head 'utf-8)
91 ':string (encode-coding-string body 'utf-8)
92 '(:array)
93 '(:array :signature "{sv}")
94 ':int32 jabber-libnotify-timeout)))
95 (error nil))))
96
97 (define-jabber-alert libnotify "Show a message through the libnotify interface"
98 'jabber-libnotify-message)
99 (define-personal-jabber-alert jabber-muc-libnotify)
100
101 (provide 'jabber-libnotify)
102
103 ;; arch-tag: e9c4c210-8245-11dd-bddf-000a95c2fcd0