1 ;;; riece-xfaceb.el --- display X-Face/Colour Face in IRC buffers
2 ;; Copyright (C) 2005 Daiki Ueno
4 ;; Author: Steve Youngs <steve@sxemacs.org>
6 ;; Keywords: IRC, riece
8 ;; This file is part of Riece.
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; NOTE: This is an add-on module for Riece. It is adapted from
28 ;; `riece-xface' but gets the image data from BBDB instead of LSDB.
30 ;; This add-on displays either X-Face or colour Face images in the
31 ;; Riece "Users" buffers. The image data comes from entries in a BBDB
32 ;; db. Consequently it does require a little setting up in BBDB...
36 ;; You need a new field called "ircnick" for each IRC contact that is
37 ;; in your BBDB. Its value is the IRC nickname of the contact (what
38 ;; is listed in the Riece "Users" buffer).
40 ;; M-x bbdb-insert-new-field RET ircnick RET
41 ;; answer `yes' to the prompt about the field not being defined
42 ;; then give it a value which will be that record's IRC nickname
44 ;; Then you'll need to collect X-Face: and Face: headers from your mail.
45 ;; To do that see: <http://www.emacswiki.org/cgi-bin/wiki/BbdbFaces>
49 (require 'riece-identity)
50 (require 'riece-globals)
51 (require 'riece-display)
54 (autoload 'bbdb-records "bbdb")
55 (autoload 'bbdb-record-getprop "bbdb"))
57 (defconst riece-xfaceb-description
58 "Display X-Face & Colour Face images in IRC buffers \(BBDB\).")
60 (defcustom riece-xfaceb-prefer-cface-to-xface (featurep 'png)
61 "*When non-nil, display colour face images instead of X-Face."
65 (defun riece-xfaceb-face-to-png (face)
66 "Base64 decode a Face header into a PNG.
70 (base64-decode-region (point-min) (point-max))
73 (defun riece-xfaceb-update-user-list-buffer ()
74 "Add X-Face or Colour Face images to channel users' buffer."
75 (when (get 'riece-xfaceb 'riece-addon-enabled)
76 (let ((users (ignore-errors
77 (riece-with-server-buffer
78 (riece-identity-server riece-current-channel)
79 (riece-channel-get-users (riece-identity-prefix
80 riece-current-channel)))))
81 all-records cface xface nick name record)
83 (setq name (caar users))
84 (setq all-records (bbdb-records))
86 (setq record (car all-records)
87 nick (bbdb-record-getprop record 'ircnick)
88 xface (bbdb-record-getprop record 'face)
89 cface (bbdb-record-getprop record 'cface))
90 (when (and (equal nick name)
92 (with-current-buffer riece-user-list-buffer
93 (goto-char (point-min))
94 (re-search-forward (regexp-quote name) nil t)
97 (or (not riece-xfaceb-prefer-cface-to-xface)
99 (set-extent-begin-glyph
101 (make-glyph (list (vector 'xface
102 :data (concat "X-Face: " xface)
104 :background "white")))))
105 (when (and (featurep 'png)
106 riece-xfaceb-prefer-cface-to-xface
108 (set-extent-begin-glyph
110 (make-glyph (list (vector 'png
111 :data (riece-xfaceb-face-to-png cface)))))))
112 ;; We have a match, get out of the inner loop
113 (setq all-records nil))
114 (setq all-records (cdr all-records)))
115 (setq users (cdr users))))))
117 (defun riece-xfaceb-requires ()
120 (defun riece-xfaceb-user-list-mode-hook ()
121 (add-hook 'riece-update-buffer-functions
122 'riece-xfaceb-update-user-list-buffer t t))
124 (defun riece-xfaceb-insinuate ()
125 (if riece-user-list-buffer
126 (with-current-buffer riece-user-list-buffer
127 (riece-xfaceb-user-list-mode-hook)))
128 (add-hook 'riece-user-list-mode-hook
129 'riece-xfaceb-user-list-mode-hook))
131 (defun riece-xfaceb-uninstall ()
132 (if riece-user-list-buffer
133 (with-current-buffer riece-user-list-buffer
134 (remove-hook 'riece-update-buffer-functions
135 'riece-xfaceb-update-user-list-buffer t)))
136 (remove-hook 'riece-user-list-mode-hook
137 'riece-xfaceb-user-list-mode-hook))
139 (defun riece-xfaceb-enable ()
140 (if riece-current-channel
141 (riece-emit-signal 'user-list-changed riece-current-channel)))
143 (defun riece-xfaceb-disable ()
144 (if riece-current-channel
145 (riece-emit-signal 'user-list-changed riece-current-channel)))
147 (provide 'riece-xfaceb)
149 ;;; riece-xfaceb.el ends here