1 ;;; riece-icon.el --- display icons in IRC buffers
2 ;; Copyright (C) 1998-2003 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.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.
31 (require 'riece-globals)
32 (require 'riece-signal)
34 (defvar riece-channel-list-icons
36 static char * blank_xpm[] = {
52 static char * balloon_xpm[] = {
70 static char * check_xpm[] = {
88 static char * active_xpm[] = {
106 (defvar riece-user-list-icons
108 static char * blank_xpm[] = {
124 static char * spiral_xpm[] = {
142 static char * cross_xpm[] = {
160 (defvar riece-pointer-icon
162 static char * a_xpm[] = {
184 (defconst riece-icon-description
185 "Display icons in IRC buffers.")
187 (defun riece-icon-available-p ()
188 (if (featurep 'xemacs)
190 (if (fboundp 'image-type-available-p)
191 (image-type-available-p 'xpm))))
194 (if (featurep 'xemacs)
195 (defun riece-icon-make-image (data string)
196 (make-glyph (list (vector 'xpm :data data)
197 (vector 'string :data string))))
198 (defun riece-icon-make-image (data string)
199 (create-image data 'xpm t :ascent 'center))))
201 (defun riece-icon-make-images (alist)
202 (let ((pointer (setq alist (copy-alist alist))))
204 (setcdr (car pointer)
205 (riece-icon-make-image (cdr (car pointer)) (car (car pointer))))
206 (setq pointer (cdr pointer)))
210 (if (featurep 'xemacs)
211 (defun riece-icon-add-image-region (image start end)
213 (lambda (extent ignore)
214 (if (or (extent-property extent 'riece-icon-user-list-extent)
215 (extent-property extent 'riece-icon-user-list-annotation))
216 (delete-extent extent)))
217 (current-buffer) start end)
218 (let ((extent (make-extent start end))
219 (annotation (make-annotation image end 'text)))
220 (set-extent-property extent 'end-open t)
221 (set-extent-property extent 'start-open t)
222 (set-extent-property extent 'invisible t)
223 (set-extent-property extent 'intangible t)
224 (set-extent-property annotation
225 'riece-icon-user-list-extent extent)
226 (set-extent-property extent
227 'riece-icon-user-list-annotation annotation)))
228 (defun riece-icon-add-image-region (image start end)
229 (let ((inhibit-read-only t)
231 (add-text-properties start end
234 'rear-nonsticky (list 'display)))))))
236 (defun riece-icon-update-user-list-buffer ()
237 (if (get 'riece-icon 'riece-addon-enabled)
238 (let ((images (riece-icon-make-images riece-user-list-icons)))
240 (goto-char (point-min))
241 (while (re-search-forward "^[ @+]" nil t)
242 (riece-icon-add-image-region
243 (cdr (assoc (match-string 0) images))
244 (1- (point)) (point)))))))
246 (defun riece-icon-update-channel-list-buffer ()
247 (if (get 'riece-icon 'riece-addon-enabled)
248 (let ((images (riece-icon-make-images riece-channel-list-icons)))
250 (goto-char (point-min))
251 (while (re-search-forward "^ ?[0-9]+:\\([ !+*]\\)" nil t)
252 (riece-icon-add-image-region
253 (cdr (assoc (match-string 1) images))
254 (match-beginning 1) (match-end 1)))))))
257 (if (featurep 'xemacs)
259 (defvar riece-icon-xemacs-modeline-left-extent
260 (copy-extent modeline-buffer-id-left-extent))
262 (defvar riece-icon-xemacs-modeline-right-extent
263 (copy-extent modeline-buffer-id-right-extent))
265 (defun riece-icon-modeline-buffer-identification (line)
266 "Decorate 1st element of `mode-line-buffer-identification' LINE.
267 Modify whole identification by side effect."
268 (let ((id (car line)) chopped)
269 (if (and (stringp id) (string-match "^Riece:" id))
271 (setq chopped (substring id 0 (match-end 0))
272 id (substring id (match-end 0)))
279 (list (vector 'xpm :data
280 riece-pointer-icon)))
281 (list (vector 'string :data chopped))))))
282 (set-glyph-face glyph 'modeline-buffer-id)
283 (cons riece-icon-xemacs-modeline-left-extent glyph))
284 (cons riece-icon-xemacs-modeline-right-extent id))
290 (defun riece-icon-modeline-buffer-identification (line)
291 "Decorate 1st element of `mode-line-buffer-identification' LINE.
292 Modify whole identification by side effect."
293 (let ((id (copy-sequence (car line)))
295 (if (image-type-available-p 'xpm)
296 (create-image riece-pointer-icon 'xpm t
299 (stringp id) (string-match "^Riece:" id))
300 (add-text-properties 0 (length id)
302 'rear-nonsticky (list 'display))
307 (defalias 'riece-icon-modeline-buffer-identification 'identity)))))
309 (defun riece-icon-user-list-mode-hook ()
310 (if (riece-icon-available-p)
311 (add-hook 'riece-update-buffer-functions
312 'riece-icon-update-user-list-buffer t t)))
314 (defun riece-icon-channel-list-mode-hook ()
315 (if (riece-icon-available-p)
316 (add-hook 'riece-update-buffer-functions
317 'riece-icon-update-channel-list-buffer t t)))
319 (defun riece-icon-insinuate ()
321 (when riece-user-list-buffer
322 (set-buffer riece-user-list-buffer)
323 (riece-icon-user-list-mode-hook))
324 (when riece-channel-list-buffer
325 (set-buffer riece-channel-list-buffer)
326 (riece-icon-channel-list-mode-hook)))
327 (add-hook 'riece-user-list-mode-hook
328 'riece-icon-user-list-mode-hook)
329 (add-hook 'riece-channel-list-mode-hook
330 'riece-icon-channel-list-mode-hook))
332 (defun riece-icon-uninstall ()
334 (when riece-user-list-buffer
335 (set-buffer riece-user-list-buffer)
336 (remove-hook 'riece-update-buffer-functions
337 'riece-icon-update-user-list-buffer t))
338 (when riece-channel-list-buffer
339 (set-buffer riece-channel-list-buffer)
340 (remove-hook 'riece-update-buffer-functions
341 'riece-icon-update-channel-list-buffer t)))
342 (remove-hook 'riece-user-list-mode-hook
343 'riece-icon-user-list-mode-hook)
344 (remove-hook 'riece-channel-list-mode-hook
345 'riece-icon-channel-list-mode-hook))
347 (defvar riece-icon-original-mode-line-buffer-identification nil)
349 (defun riece-icon-update-mode-line-buffer-identification ()
350 (let ((buffers riece-buffer-list))
353 (set-buffer (car buffers))
354 (if (local-variable-p 'riece-mode-line-buffer-identification
356 (setq mode-line-buffer-identification
357 (riece-mode-line-buffer-identification
358 riece-mode-line-buffer-identification)))
359 (setq buffers (cdr buffers))))))
361 (defun riece-icon-enable ()
362 (setq riece-icon-original-mode-line-buffer-identification
363 (symbol-function 'riece-mode-line-buffer-identification))
364 (defalias 'riece-mode-line-buffer-identification
365 'riece-icon-modeline-buffer-identification)
366 (riece-icon-update-mode-line-buffer-identification)
367 (if riece-current-channel
368 (riece-emit-signal 'user-list-changed riece-current-channel))
369 (riece-emit-signal 'channel-list-changed))
371 (defun riece-icon-disable ()
372 (fset 'riece-mode-line-buffer-identification
373 riece-icon-original-mode-line-buffer-identification)
374 (riece-icon-update-mode-line-buffer-identification)
375 (if riece-current-channel
376 (riece-emit-signal 'user-list-changed riece-current-channel))
377 (riece-emit-signal 'channel-list-changed))
379 (provide 'riece-icon)
381 ;;; riece-icon.el ends here