File: jabber-notifications.el

package info (click to toggle)
emacs-jabber 0.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,224 kB
  • sloc: lisp: 12,524; xml: 362; makefile: 46; sh: 1
file content (99 lines) | stat: -rw-r--r-- 3,813 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
;;; jabber-notifications.el --- emacs-jabber interface to notifications.el  -*- lexical-binding: t; -*-

;; Copyright (C) 2014 - Adam Sjøgren - asjo@koldfront.dk
;; 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
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

;; Built on jabber-libnotify.el.

(eval-when-compile (require 'jabber-alert))

(require 'notifications)

(defcustom jabber-notifications-icon ""
  "Icon to be used on the notification pop-up. Default is empty"
  :type '(file :must-match t)
  :group 'jabber-alerts)

(defcustom jabber-notifications-timeout nil
  "Specifies the timeout of the pop up window in millisecond"
  :type 'integer
  :group 'jabber-alerts)

(defcustom jabber-notifications-message-header "Jabber message"
  "Defines the header of the pop up."
  :type 'string
  :group 'jabber-alerts)

(defcustom jabber-notifications-app "Emacs Jabber"
  "Defines the app of the pop up."
  :type 'string
  :group 'jabber-alerts)

(defcustom jabber-notifications-urgency "low"
  "Urgency of message"
  :type '(choice (const :tag "Low" "low")
                 (const :tag "Normal" "normal")
                 (const :tag "Critical" "critical"))
  :group 'jabber-alerts)

;; Global reference declarations

(declare-function jabber-muc-looks-like-personal-p "jabber-muc-nick-completion.el"
                  (message &optional group))
(declare-function jabber-avatar-find-cached "jabber-avatar.el" (sha1-sum))
(declare-function jabber-jid-symbol "jabber-util.el" (jid))
(declare-function jabber-escape-xml "jabber-xml.el" (string))

;;

(defun jabber-message-notifications (from _buffer text title)
  "Show a message through the notifications.el interface"
  (let
      ((body (or (jabber-escape-xml text) " "))
       (avatar-hash (get (jabber-jid-symbol from) 'avatar-hash)))
    (notifications-notify
     :title title
     :body body
     :app-icon (or (and avatar-hash (jabber-avatar-find-cached avatar-hash))
                   jabber-notifications-icon)
     :app-name jabber-notifications-app
     :category "jabber.message"
     :timeout jabber-notifications-timeout)))

(defun jabber-muc-notifications (nick group buffer text title)
  "Show MUC message through the notifications.el interface"
  (jabber-message-notifications group buffer (if nick (format "%s: %s" nick text) text) title)
  )

(defun jabber-muc-notifications-personal (nick group buffer text title)
  "Show personal MUC message through the notifications.el interface"
  (if (jabber-muc-looks-like-personal-p text group)
      (jabber-muc-notifications nick group buffer text title))
  )

  ;; jabber-*-notifications* requires "from" argument, so we cant use
  ;; define-jabber-alert/define-personal-jabber-alert here and do the
  ;; work by hand:

(cl-pushnew 'jabber-message-notifications (get 'jabber-alert-message-hooks 'custom-options))
(cl-pushnew 'jabber-muc-notifications (get 'jabber-alert-muc-hooks 'custom-options))
(cl-pushnew 'jabber-muc-notifications-personal (get 'jabber-alert-muc-hooks 'custom-options))

(provide 'jabber-notifications)

;;; jabber-notifications.el ends here