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., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, 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)
53 (autoload 'bbdb-records "bbdb")
54 (autoload 'bbdb-record-getprop "bbdb")
56 (defconst riece-xfaceb-description
57 "Display X-Face & Colour Face images in IRC buffers \(BBDB\).")
59 (defcustom riece-xfaceb-prefer-cface-to-xface (featurep 'png)
60 "*When non-nil, display colour face images instead of X-Face."
64 (defun riece-xfaceb-face-to-png (face)
65 "Base64 decode a Face header into a PNG.
69 (base64-decode-region (point-min) (point-max))
72 (defun riece-xfaceb-update-user-list-buffer ()
73 "Add X-Face or Colour Face images to channel users' buffer."
74 (when (get 'riece-xfaceb 'riece-addon-enabled)
75 (let ((users (ignore-errors
76 (riece-with-server-buffer
77 (riece-identity-server riece-current-channel)
78 (riece-channel-get-users (riece-identity-prefix
79 riece-current-channel)))))
80 all-records cface xface nick name record)
82 (setq name (caar users))
83 (setq all-records (bbdb-records))
85 (setq record (car all-records)
86 nick (bbdb-record-getprop record 'ircnick)
87 xface (bbdb-record-getprop record 'face)
88 cface (bbdb-record-getprop record 'cface))
89 (when (and (equal nick name)
91 (with-current-buffer riece-user-list-buffer
92 (goto-char (point-min))
93 (re-search-forward (regexp-quote name) nil t)
96 (or (not riece-xfaceb-prefer-cface-to-xface)
98 (set-extent-begin-glyph
100 (make-glyph (list (vector 'xface
101 :data (concat "X-Face: " xface)
103 :background "white")))))
104 (when (and (featurep 'png)
105 riece-xfaceb-prefer-cface-to-xface
107 (set-extent-begin-glyph
109 (make-glyph (list (vector 'png
110 :data (riece-xfaceb-face-to-png cface)))))))
111 ;; We have a match, get out of the inner loop
112 (setq all-records nil))
113 (setq all-records (cdr all-records)))
114 (setq users (cdr users))))))
116 (defun riece-xfaceb-requires ()
119 (defun riece-xfaceb-user-list-mode-hook ()
120 (add-hook 'riece-update-buffer-functions
121 'riece-xfaceb-update-user-list-buffer t t))
123 (defun riece-xfaceb-insinuate ()
124 (if riece-user-list-buffer
125 (with-current-buffer riece-user-list-buffer
126 (riece-xfaceb-user-list-mode-hook)))
127 (add-hook 'riece-user-list-mode-hook
128 'riece-xfaceb-user-list-mode-hook))
130 (defun riece-xfaceb-uninstall ()
131 (if riece-user-list-buffer
132 (with-current-buffer riece-user-list-buffer
133 (remove-hook 'riece-update-buffer-functions
134 'riece-xfaceb-update-user-list-buffer t)))
135 (remove-hook 'riece-user-list-mode-hook
136 'riece-xfaceb-user-list-mode-hook))
138 (defun riece-xfaceb-enable ()
139 (if riece-current-channel
140 (riece-emit-signal 'user-list-changed riece-current-channel)))
142 (defun riece-xfaceb-disable ()
143 (if riece-current-channel
144 (riece-emit-signal 'user-list-changed riece-current-channel)))
146 (provide 'riece-xfaceb)
148 ;;; riece-xfaceb.el ends here