* riece-addon.el (riece-uninstall-addon): Don't check the add-on
[riece] / lisp / riece-xface.el
1 ;;; riece-xface.el --- display X-Face in IRC buffers
2 ;; Copyright (C) 1998-2003 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Keywords: IRC, riece
7
8 ;; This file is part of Riece.
9
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)
13 ;; any later version.
14
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.
19
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.
24
25 ;;; Commentary:
26
27 ;; NOTE: This is an add-on module for Riece.
28
29 ;;; Code:
30
31 (require 'riece-identity)
32 (require 'riece-globals)
33 (require 'riece-display)
34 (require 'riece-lsdb)
35
36 (defconst riece-xface-description
37   "Display X-Face in IRC buffers.")
38
39 (defvar lsdb-insert-x-face-function)
40
41 (defun riece-xface-update-user-list-buffer ()
42   (if (get 'riece-xface 'riece-addon-enabled)
43       (riece-scan-property-region
44        'riece-identity (point-min)(point-max)
45        (lambda (start end)
46          (let ((records (riece-lsdb-lookup-records (get-text-property
47                                                     start 'riece-identity)))
48                xface)
49            (while (and records
50                        (null xface))
51              (setq xface (nth 1 (assq 'x-face (car records)))
52                    records (cdr records)))
53            (if (and xface
54                     (not (eq (char-after end) ? )))
55                (let ((inhibit-read-only t)
56                      buffer-read-only)
57                  (goto-char end)
58                  (insert " ")
59                  (funcall lsdb-insert-x-face-function xface))))))))
60
61 (defun riece-xface-requires ()
62   '(riece-lsdb))
63
64 (defun riece-xface-user-list-mode-hook ()
65   (add-hook 'riece-update-buffer-functions
66             'riece-xface-update-user-list-buffer t t))
67
68 (defun riece-xface-insinuate ()
69   (if riece-user-list-buffer
70       (with-current-buffer riece-user-list-buffer
71         (riece-xface-user-list-mode-hook)))
72   (add-hook 'riece-user-list-mode-hook
73             'riece-xface-user-list-mode-hook))
74
75 (defun riece-xface-uninstall ()
76   (if riece-user-list-buffer
77       (with-current-buffer riece-user-list-buffer
78         (remove-hook 'riece-update-buffer-functions
79                      'riece-xface-update-user-list-buffer t)))
80   (remove-hook 'riece-user-list-mode-hook
81                'riece-xface-user-list-mode-hook))
82
83 (defun riece-xface-enable ()
84   (if riece-current-channel
85       (riece-emit-signal 'user-list-changed riece-current-channel)))
86
87 (defun riece-xface-disable ()
88   (if riece-current-channel
89       (riece-emit-signal 'user-list-changed riece-current-channel)))
90
91 (provide 'riece-xface)
92
93 ;;; riece-xface.el ends here