-(defun emchat-buddy-show-xface (alias)
- "Display an XFace image in the buddy buffer."
- (unless (featurep '(and xface bbdb-autoloads))
- (error 'unimplemented "X-Face and/or BBDB"))
- (save-excursion
- (when (buffer-live-p emchat-buddy-buffer)
- (set-buffer emchat-buddy-buffer)
- (goto-char (point-min))
- (when (search-forward-regexp (concat "^" (regexp-quote alias) "$") nil t)
- (let ((ext (extent-at (point)))
- (all-records (bbdb-records))
- face cface nick record)
- (while all-records
- (setq record (car all-records)
- nick (bbdb-record-getprop record 'icqnick)
- face (bbdb-record-getprop record 'face)
- cface (bbdb-record-getprop record 'cface))
- (if (stringp nick)
- (setq nick (split-string nick ",\\| " 'omitnulls)))
- (when (and (member alias nick)
- (or face cface))
- ;; put some whitespace between the image and the name
- (set-extent-begin-glyph
- (make-extent (point-at-bol) (point-at-eol))
- (make-glyph " "))
- ;; Insert the X-Face
- (when (and face
- (or (not emchat-buddy-prefer-cface-to-xface)
- (not cface)))
- (set-extent-begin-glyph
- ext
- (make-glyph (list (vector 'xface
- :data (concat "X-Face: " face)
- :foreground "black"
- :background "white")))))
- ;; Insert the cface
- (when (and (featurep 'png)
- cface
- emchat-buddy-prefer-cface-to-xface)
- (set-extent-begin-glyph
- ext
- (make-glyph (list (vector 'png
- :data (emchat-face-to-png cface)))))))
- (setq all-records (cdr all-records))))))))
+(defun emchat-buddy-make-avatar (type extent data)
+ "Returns an avatar glyph.
+
+TYPE is a symbol, either `cface', or `xface'.
+EXTENT is the extent to add the glyph to.
+DATA is the image data from BBDB."
+ (cond
+ ((eq type 'cface)
+ (set-extent-begin-glyph
+ extent
+ (make-glyph (list (vector 'png
+ :data (emchat-face-to-png data))))))
+ ((eq type 'xface)
+ (set-extent-begin-glyph
+ extent
+ (make-glyph
+ (list (vector 'xface
+ :data (concat "X-Face: " data)
+ :foreground emchat-buddy-xface-foreground
+ :background emchat-buddy-xface-background)))))
+ (t nil)))
+
+;;;###autoload
+(defun emchat-buddy-show-avatar (alias)
+ "Display an avatar image in the buddy buffer."
+ ;; We might already have what we need in emchat-world
+ (let ((cface (emchat-world-getf alias 'cface))
+ (xface (emchat-world-getf alias 'xface)))
+ (unless (or cface xface)
+ ;; Nope, we don't. Search bbdb.
+ (unless (featurep 'bbdb-autoloads)
+ (error 'unimplemented "BBDB"))
+ (let* ((str (cons 'icqnick (regexp-quote alias)))
+ (records (bbdb-search (bbdb-records) nil nil nil str nil)))
+ (mapcar
+ #'(lambda (record)
+ (when (or (bbdb-record-getprop record 'face)
+ (bbdb-record-getprop record 'cface))
+ (setq xface (bbdb-record-getprop record 'face))
+ (setq cface (bbdb-record-getprop record 'cface))
+ (emchat-world-putf alias 'xface xface)
+ (emchat-world-putf alias 'cface cface)))
+ records)))
+ ;; Now we have what we need.
+ (save-excursion
+ (when (buffer-live-p emchat-buddy-buffer)
+ (set-buffer emchat-buddy-buffer)
+ (goto-char (point-min))
+ (when (search-forward-regexp (concat "^" (regexp-quote alias) "$") nil t)
+ (let ((ext (extent-at (point))))
+ ;; put some whitespace between the image and the name
+ (set-extent-begin-glyph
+ (make-extent (point-at-bol) (point-at-eol))
+ (make-glyph " "))
+ (cond
+ ((and cface
+ (or emchat-buddy-prefer-cface-to-xface
+ (not xface)))
+ (emchat-buddy-make-avatar 'cface ext cface))
+ (xface (emchat-buddy-make-avatar 'xface ext xface))
+ (t nil))))))))