1 ;; jabber-watch.el - get notified when certain persons go online
3 ;; Copyright (C) 2004 - Mathias Dahl
4 ;; Copyright (C) 2004 - Magnus Henoch - mange@freemail.hu
6 ;; This file is a part of jabber.el.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program; if not, write to the Free Software
20 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 (require 'jabber-util
)
24 (defcustom jabber-watch-alist nil
25 "Alist of buddies for which an extra notification should be sent
26 when they come online, with comment strings as values."
27 ;; XXX: change symbol to jid-symbol or something, and update
29 :type
'(alist :key-type symbol
:value-type string
)
32 (defun jabber-presence-watch (who oldstatus newstatus
33 statustext proposed-alert
)
34 "Checks if one of your extra-important buddies comes online and
35 sends a message if that happens. The buddies are stored in
36 `jabber-watch-alist' and are added and removed by calling
37 `jabber-watch-add' and `jabber-watch-remove.'"
38 ;; check that buddy was previously offline and now online
39 (if (and (null oldstatus
)
40 (not (null newstatus
)))
41 (let ((entry (assq who jabber-watch-alist
)))
43 ;; Give an intrusive message. With a window system,
46 (message-box "%s%s" proposed-alert
47 (if (cdr entry
) (format ": %s" (cdr entry
)) ""))
48 ;; Without a window system, yes-or-no-p should be
51 (yes-or-no-p (format "%s%s Got that? " proposed-alert
52 (if (cdr entry
) (format ": %s" (cdr entry
)) ""))))))))))
54 (defun jabber-watch-add (buddy &optional comment
)
55 (interactive (list (jabber-read-jid-completing "Add buddy to watch list: ")
56 (read-string "Comment: ")))
57 (unless (memq 'jabber-presence-watch jabber-presence-hooks
)
58 (error "jabber-presence-watch is not in jabber-presence-hooks"))
59 (add-to-list 'jabber-watch-alist
(cons
60 (jabber-jid-symbol buddy
)
61 (and (not (zerop (length comment
)))
64 (defun jabber-watch-remove (buddy)
66 (list (jabber-read-jid-completing "Remove buddy from watch list: "
67 (or (mapcar 'car jabber-watch-alist
)
68 (error "Watch list is empty"))
70 (setq jabber-watch-alist
71 (delq (assq (jabber-jid-symbol buddy
) jabber-watch-alist
)
74 (provide 'jabber-watch
)
76 ;; arch-tag: c27299d8-019e-44b5-9529-d67b8682be23