Merge remote-tracking branch 'sourceforge/master'
[emacs-jabber.git] / jabber-modeline.el
blobe322819c351b9bf9f127771bec37f67ceba4be14
1 ;; jabber-modeline.el - display jabber status in modeline
3 ;; Copyright (C) 2004 - Magnus Henoch - mange@freemail.hu
5 ;; This file is a part of jabber.el.
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2 of the License, or
10 ;; (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program; if not, write to the Free Software
19 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 (require 'jabber-presence)
22 (require 'jabber-alert)
23 (eval-when-compile (require 'cl))
25 (defgroup jabber-mode-line nil
26 "Display Jabber status in mode line"
27 :group 'jabber)
29 (defcustom jabber-mode-line-compact t
30 "Count contacts in fewer categories for compact view"
31 :group 'jabber-mode-line
32 :type 'boolean)
34 (defvar jabber-mode-line-string nil)
35 (defvar jabber-mode-line-presence nil)
36 (defvar jabber-mode-line-contacts nil)
38 (defadvice jabber-send-presence (after jsp-update-mode-line
39 (show status priority))
40 (jabber-mode-line-presence-update))
42 (defun jabber-mode-line-presence-update ()
43 (setq jabber-mode-line-presence (if (and jabber-connections (not *jabber-disconnecting*))
44 (cdr (assoc *jabber-current-show* jabber-presence-strings))
45 "Offline")))
47 (defun jabber-mode-line-count-contacts (&rest ignore)
48 (let ((count (list (cons "chat" 0)
49 (cons "" 0)
50 (cons "away" 0)
51 (cons "xa" 0)
52 (cons "dnd" 0)
53 (cons nil 0))))
54 (dolist (jc jabber-connections)
55 (dolist (buddy (plist-get (fsm-get-state-data jc) :roster))
56 (when (assoc (get buddy 'show) count)
57 (incf (cdr (assoc (get buddy 'show) count))))))
58 (setq jabber-mode-line-contacts
59 (if jabber-mode-line-compact
60 (format "(%d/%d/%d)"
61 (+ (cdr (assoc "chat" count))
62 (cdr (assoc "" count)))
63 (+ (cdr (assoc "away" count))
64 (cdr (assoc "xa" count))
65 (cdr (assoc "dnd" count)))
66 (cdr (assoc nil count)))
67 (apply 'format "(%d/%d/%d/%d/%d/%d)"
68 (mapcar 'cdr count))))))
70 (define-minor-mode jabber-mode-line-mode
71 "Toggle display of Jabber status in mode lines.
72 Display consists of your own status, and six numbers
73 meaning the number of chatty, online, away, xa, dnd
74 and offline contacts, respectively."
75 :global t :group 'jabber-mode-line
76 (setq jabber-mode-line-string "")
77 (or global-mode-string (setq global-mode-string '("")))
78 (if jabber-mode-line-mode
79 (progn
80 (add-to-list 'global-mode-string 'jabber-mode-line-string t)
82 (setq jabber-mode-line-string (list " "
83 'jabber-mode-line-presence
84 " "
85 'jabber-mode-line-contacts))
86 (put 'jabber-mode-line-string 'risky-local-variable t)
87 (put 'jabber-mode-line-presence 'risky-local-variable t)
88 (jabber-mode-line-presence-update)
89 (jabber-mode-line-count-contacts)
90 (ad-activate 'jabber-send-presence)
91 (add-hook 'jabber-post-disconnect-hook
92 'jabber-mode-line-presence-update)
93 (add-hook 'jabber-presence-hooks
94 'jabber-mode-line-count-contacts))))
96 (provide 'jabber-modeline)
98 ;;; arch-tag: c03a7d3b-8811-49d4-b0e0-7ffd661d7925