1 ;;; gnus-picon.el --- displaying pretty icons in Gnus
2 ;; Copyright (C) 1996,97,98,99 Free Software Foundation, Inc.
4 ;; Author: Wes Hardaker <hardaker@ece.ucdavis.edu>
5 ;; Keywords: news xpm annotation glyph faces
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
30 (require 'annotations)
38 "Show pictures of people, domains, and newsgroups (XEmacs).
39 For this to work, you must switch on the `gnus-treat-display-picons'
43 (defcustom gnus-picons-display-where 'picons
44 "Where to display the group and article icons.
45 Valid values are `article' and `picons'."
46 :type '(choice symbol string)
49 (defcustom gnus-picons-has-modeline-p t
50 "*Whether the picons window should have a modeline.
51 This is only useful if `gnus-picons-display-where' is `picons'."
55 (defcustom gnus-picons-database "/usr/local/faces"
56 "*Defines the location of the faces database.
57 For information on obtaining this database of pretty pictures, please
58 see http://www.cs.indiana.edu/picons/ftp/index.html"
62 (defcustom gnus-picons-news-directories '("news")
63 "*List of directories to search for newsgroups faces."
64 :type '(repeat string)
66 (define-obsolete-variable-alias 'gnus-picons-news-directory
67 'gnus-picons-news-directories)
69 (defcustom gnus-picons-user-directories '("local" "users" "usenix" "misc")
70 "*List of directories to search for user faces."
71 :type '(repeat string)
74 (defcustom gnus-picons-domain-directories '("domains")
75 "*List of directories to search for domain faces.
76 Some people may want to add \"unknown\" to this list."
77 :type '(repeat string)
80 (defcustom gnus-picons-refresh-before-display nil
81 "*If non-nil, display the article buffer before computing the picons."
85 (defcustom gnus-picons-group-excluded-groups nil
86 "*If this regexp matches the group name, group picons will be disabled."
90 (defcustom gnus-picons-x-face-file-name
91 (format "/tmp/picon-xface.%s.xbm" (user-login-name))
92 "*The name of the file in which to store the converted X-face header."
96 (defcustom gnus-picons-convert-x-face (format "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | pbmtoxbm > %s" gnus-picons-x-face-file-name)
97 "*Command to convert the x-face header into a xbm file."
101 (defcustom gnus-picons-display-as-address t
102 "*If t display textual email addresses along with pictures."
106 (defcustom gnus-picons-file-suffixes
108 (let ((types (list "xbm")))
109 (when (featurep 'gif)
111 (when (featurep 'xpm)
114 "*List of suffixes on picon file names to try."
115 :type '(repeat string)
118 (defcustom gnus-picons-display-article-move-p nil
119 "*Whether to move point to first empty line when displaying picons.
120 This has only an effect if `gnus-picons-display-where' has value `article'."
124 (defcustom gnus-picons-clear-cache-on-shutdown t
125 "*Whether to clear the picons cache when exiting gnus.
126 Gnus caches every picons it finds while it is running. This saves
127 some time in the search process but eats some memory. If this
128 variable is set to nil, Gnus will never clear the cache itself; you
129 will have to manually call `gnus-picons-clear-cache' to clear it.
130 Otherwise the cache will be cleared every time you exit Gnus."
134 (defcustom gnus-picons-piconsearch-url nil
135 "*The url to query for picons. Setting this to nil will disable it.
136 The only publicly available address currently known is
137 http://www.cs.indiana.edu:800/piconsearch. If you know of any other,
138 please tell me so that we can list it."
139 :type '(choice (const :tag "Disable" :value nil)
140 (const :tag "www.cs.indiana.edu"
141 :value "http://www.cs.indiana.edu:800/piconsearch")
145 (defface gnus-picons-xbm-face '((t (:foreground "black" :background "white")))
146 "Face to show xbm picons in."
149 (defface gnus-picons-face '((t (:foreground "black" :background "white")))
150 "Face to show picons in."
153 (defcustom gnus-picons-setup-hook nil
154 "Hook run in Picons buffers."
158 ;;; Internal variables:
160 (defvar gnus-picons-setup-p nil)
161 (defvar gnus-picons-processes-alist nil
162 "Picons processes currently running and their environment.")
163 (defvar gnus-picons-glyph-alist nil
164 "Picons glyphs cache.
165 List of pairs (KEY . GLYPH) where KEY is either a filename or an URL.")
166 (defvar gnus-picons-url-alist nil
167 "Picons file names cache.
168 List of pairs (KEY . NAME) where KEY is (USER HOST DBS) and NAME is an URL.")
170 (defvar gnus-picons-jobs-alist nil
171 "List of jobs that still need be done.
172 This is a list of (SYM-ANN TAG ARGS...) where SYM-ANN three annotations list,
173 TAG is one of `picon' or `search' indicating that the job should query a
174 picon or do a search for picons file names, and ARGS is some additionnal
175 arguments necessary for the job.")
177 (defvar gnus-picons-job-already-running nil
178 "Lock to ensure only one stream of http requests is running.")
182 (defun gnus-picons-remove-all ()
183 "Removes all picons from the Gnus display(s)."
185 (map-extents (function (lambda (ext unused) (delete-annotation ext) nil))
186 nil nil nil nil nil 'gnus-picon)
187 (setq gnus-picons-jobs-alist '())
188 ;; notify running job that it may have been preempted
189 (if (and (listp gnus-picons-job-already-running)
190 gnus-picons-job-already-running)
191 (setq gnus-picons-job-already-running t)))
193 (defun gnus-get-buffer-name (variable)
194 "Returns the buffer name associated with the contents of a variable."
195 (let ((buf (gnus-get-buffer-create
196 (gnus-window-to-buffer-helper
197 (cdr (assq variable gnus-window-to-buffer))))))
201 (defun gnus-picons-buffer-name ()
202 (cond ((or (stringp gnus-picons-display-where)
203 (bufferp gnus-picons-display-where))
204 gnus-picons-display-where)
205 ((eq gnus-picons-display-where 'picons)
206 (if gnus-single-article-buffer
208 (concat "*Picons " gnus-newsgroup-name "*")))
210 (gnus-get-buffer-name gnus-picons-display-where))))
212 (defun gnus-picons-kill-buffer ()
213 (let ((buf (get-buffer (gnus-picons-buffer-name))))
214 (when (and (buffer-live-p buf)
215 (string-match "Picons" (buffer-name buf)))
218 (defun gnus-picons-setup-buffer ()
219 (let ((name (gnus-picons-buffer-name)))
221 (if (and (get-buffer name)
222 (with-current-buffer name
223 gnus-picons-setup-p))
225 (set-buffer (gnus-get-buffer-create name))
226 (buffer-disable-undo)
227 (setq buffer-read-only t)
228 (run-hooks 'gnus-picons-setup-hook)
229 (set (make-local-variable 'gnus-picons-setup-p) t)
230 (add-hook 'gnus-summary-prepare-exit-hook 'gnus-picons-kill-buffer))
233 (defun gnus-picons-set-buffer ()
234 (set-buffer (gnus-picons-setup-buffer))
235 (goto-char (point-min))
236 (if (and (eq gnus-picons-display-where 'article)
237 gnus-picons-display-article-move-p)
238 (if (search-forward "\n\n" nil t)
240 (goto-char (point-max)))
241 (setq buffer-read-only t)
242 (unless gnus-picons-has-modeline-p
243 (set-specifier has-modeline-p
244 (list (list (current-buffer)
245 (cons nil gnus-picons-has-modeline-p)))))))
247 (defun gnus-picons-prepare-for-annotations ()
248 "Prepare picons buffer for putting annotations."
249 ;; let drawing catch up
250 (when gnus-picons-refresh-before-display
252 (gnus-picons-set-buffer)
253 (gnus-picons-remove-all))
255 (defun gnus-picons-make-annotation (&rest args)
256 (let ((annot (apply 'make-annotation args)))
257 (set-extent-property annot 'gnus-picon t)
258 (set-extent-property annot 'duplicable t)
261 (defun gnus-picons-article-display-x-face ()
262 "Display the x-face header bitmap in the 'gnus-picons-display-where buffer."
263 (let ((gnus-article-x-face-command 'gnus-picons-display-x-face))
264 (gnus-article-display-x-face)))
266 (defun gnus-picons-x-face-sentinel (process event)
267 (when (memq process gnus-picons-processes-alist)
268 (setq gnus-picons-processes-alist
269 (delq process gnus-picons-processes-alist))
270 (gnus-picons-set-buffer)
271 (gnus-picons-make-annotation
272 (make-glyph gnus-picons-x-face-file-name) nil 'text)
273 (when (file-exists-p gnus-picons-x-face-file-name)
274 (delete-file gnus-picons-x-face-file-name))))
276 (defun gnus-picons-display-x-face (beg end)
277 "Function to display the x-face header in the picons window.
278 To use: (setq gnus-article-x-face-command 'gnus-picons-display-x-face)"
280 (if (featurep 'xface)
281 ;; Use builtin support
283 ;; Don't remove this binding, it is really needed: when
284 ;; `gnus-picons-set-buffer' changes buffer (like when it is
285 ;; set to display picons outside of the article buffer), BEG
286 ;; and END still refer the buffer current now !
287 (let ((buf (current-buffer)))
288 (gnus-picons-set-buffer)
289 (gnus-picons-make-annotation
291 :data (concat "X-Face: " (buffer-substring beg end buf)))
292 nil 'text nil nil nil t)))
293 ;; convert the x-face header to a .xbm file
294 (let* ((process-connection-type nil)
295 (process (start-process-shell-command
296 "gnus-x-face" nil gnus-picons-convert-x-face)))
297 (push process gnus-picons-processes-alist)
298 (process-kill-without-query process)
299 (set-process-sentinel process 'gnus-picons-x-face-sentinel)
300 (process-send-region process beg end)
301 (process-send-eof process))))
303 (defun gnus-article-display-picons ()
304 "Display faces for an author and her domain in gnus-picons-display-where."
307 (when (and (featurep 'xpm)
308 (or (not (fboundp 'device-type)) (equal (device-type) 'x))
309 (setq from (mail-fetch-field "from"))
310 (setq from (downcase (or (cadr
311 (funcall gnus-extract-address-components
314 (or (setq at-idx (string-match "@" from))
315 (setq at-idx (length from))))
317 (let ((username (downcase (substring from 0 at-idx)))
318 (addrs (if (eq at-idx (length from))
319 (if gnus-local-domain
320 (message-tokenize-header gnus-local-domain "."))
321 (message-tokenize-header (substring from (1+ at-idx))
323 (gnus-picons-prepare-for-annotations)
324 (gnus-group-display-picons)
325 (unless gnus-picons-display-article-move-p
326 (let ((buffer-read-only nil)
327 (case-fold-search t))
328 (when (re-search-forward "^From *: *" nil t)
329 (when (search-forward from (gnus-point-at-eol) t)
330 (gnus-put-text-property
331 (match-beginning 0) (match-end 0)
333 (if (null gnus-picons-piconsearch-url)
335 (gnus-picons-display-pairs (gnus-picons-lookup-pairs
337 gnus-picons-domain-directories)
338 gnus-picons-display-as-address
340 (if (and gnus-picons-display-as-address addrs)
341 (gnus-picons-make-annotation
342 [string :data "@"] nil 'text nil nil nil t))
343 (gnus-picons-display-picon-or-name
344 (gnus-picons-lookup-user username addrs)
346 (push (list 'gnus-article-annotations 'search username addrs
347 gnus-picons-domain-directories t (point-marker))
348 gnus-picons-jobs-alist)
349 (gnus-picons-next-job)))))))
351 (defun gnus-group-display-picons ()
352 "Display icons for the group in the `gnus-picons-display-where' buffer."
354 (when (and (featurep 'xpm)
355 (or (not (fboundp 'device-type)) (equal (device-type) 'x))
356 (or (null gnus-picons-group-excluded-groups)
357 (not (string-match gnus-picons-group-excluded-groups
358 gnus-newsgroup-name))))
359 (let* ((newsgroups (mail-fetch-field "newsgroups"))
361 (if (or gnus-picons-display-article-move-p
363 (list (gnus-group-real-name gnus-newsgroup-name))
364 (split-string newsgroups ",")))
367 (gnus-picons-prepare-for-annotations)
368 (while (setq group (pop groups))
369 (unless gnus-picons-display-article-move-p
370 (let ((buffer-read-only nil)
371 (case-fold-search t))
372 (goto-char (point-min))
373 (if (and (re-search-forward "^Newsgroups *: *" nil t)
374 (search-forward group (gnus-point-at-eol) t))
375 (gnus-put-text-property
376 (match-beginning 0) (match-end 0)
380 (backward-char 1)))))
381 (if (null gnus-picons-piconsearch-url)
382 (gnus-picons-display-pairs
383 (gnus-picons-lookup-pairs
384 (reverse (split-string group "\\."))
385 gnus-picons-news-directories)
387 (push (list 'gnus-group-annotations 'search nil
388 (split-string group "\\.")
389 (if (listp gnus-picons-news-directories)
390 gnus-picons-news-directories
391 (list gnus-picons-news-directories))
393 gnus-picons-jobs-alist)
394 (gnus-picons-next-job))
396 (add-hook 'gnus-summary-exit-hook 'gnus-picons-remove-all))))))
398 (defun gnus-picons-lookup-internal (addrs dir)
399 (setq dir (expand-file-name dir gnus-picons-database))
400 (gnus-picons-try-face (dolist (part (reverse addrs) dir)
401 (setq dir (expand-file-name part dir)))))
403 (defun gnus-picons-lookup (addrs dirs)
404 "Lookup the picon for ADDRS in databases DIRS.
405 Returns the picon filename or NIL if none found."
407 (while (and dirs (null result))
408 (setq result (gnus-picons-lookup-internal addrs (pop dirs))))
411 (defun gnus-picons-lookup-user-internal (user domains)
412 (let ((dirs gnus-picons-user-directories)
413 domains-tmp dir picon)
414 (while (and dirs (null picon))
415 (setq domains-tmp domains
417 (while (and domains-tmp
418 (null (setq picon (gnus-picons-lookup-internal
419 (cons user domains-tmp) dir))))
421 ;; Also make a try in MISC subdir
423 (setq picon (gnus-picons-lookup-internal (list user "MISC") dir))))
426 (defun gnus-picons-lookup-user (user domains)
427 "Lookup the picon for USER at DOMAINS.
428 USER is a string containing a name.
429 DOMAINS is a list of strings from the fully qualified domain name."
430 (or (gnus-picons-lookup-user-internal user domains)
431 (gnus-picons-lookup-user-internal "unknown" domains)))
433 (defun gnus-picons-lookup-pairs (domains directories)
434 "Lookup picons for DOMAINS and all its parents in DIRECTORIES.
435 Returns a list of PAIRS whose CAR is the picon filename or NIL if
436 none, and whose CDR is the corresponding element of DOMAINS."
438 (setq directories (if (listp directories)
442 (push (list (gnus-picons-lookup (cons "unknown" domains) directories)
447 (defun gnus-picons-display-picon-or-name (picon name &optional right-p)
448 (cond (picon (gnus-picons-display-glyph picon name right-p))
449 (gnus-picons-display-as-address (list (gnus-picons-make-annotation
450 (vector 'string :data name)
452 nil nil nil right-p)))))
454 (defun gnus-picons-display-pairs (pairs &optional bar-p dot-p right-p)
455 "Display picons in list PAIRS."
456 (let ((domain-p (and gnus-picons-display-as-address dot-p))
458 (when (and bar-p domain-p right-p
459 gnus-picons-display-article-move-p)
460 (setq picons (gnus-picons-display-glyph
461 (let ((gnus-picons-file-suffixes '("xbm")))
462 (gnus-picons-try-face
463 gnus-xmas-glyph-directory "bar."))
465 (while (setq pair (pop pairs))
466 (setq picons (nconc picons
467 (gnus-picons-display-picon-or-name
468 (car pair) (cadr pair) right-p)
469 (if (and domain-p pairs)
470 (list (gnus-picons-make-annotation
471 (vector 'string :data dot-p)
472 nil 'text nil nil nil right-p))))))
475 (defun gnus-picons-try-face (dir &optional filebase)
476 (let* ((dir (file-name-as-directory dir))
477 (filebase (or filebase "face."))
478 (key (concat dir filebase))
479 (glyph (cdr (assoc key gnus-picons-glyph-alist)))
480 (suffixes gnus-picons-file-suffixes)
482 (while (setq suf (pop suffixes))
483 (when (file-exists-p (setq f (expand-file-name
484 (concat filebase suf)
487 glyph (make-glyph f))
488 (if (equal suf "xbm")
489 (set-glyph-face glyph 'gnus-picons-xbm-face)
490 (set-glyph-face glyph 'gnus-picons-face))
491 (push (cons key glyph) gnus-picons-glyph-alist)))
494 (defun gnus-picons-display-glyph (glyph &optional part rightp)
495 (set-glyph-baseline glyph 70)
496 (let ((new (gnus-picons-make-annotation
497 glyph (point) 'text nil nil nil rightp)))
498 (when (and part gnus-picons-display-as-address)
500 new (cons new (make-glyph (vector 'string :data part))))
501 (set-annotation-action new 'gnus-picons-action-toggle))
504 (if (and (eq major-mode 'gnus-article-mode)
505 (not gnus-picons-display-as-address)
507 (list (gnus-picons-make-annotation [string :data " "] (point)
508 'text nil nil nil rightp))))))
510 (defun gnus-picons-action-toggle (data)
513 (let* ((annot (car data))
514 (glyph (annotation-glyph annot)))
515 (set-annotation-glyph annot (cdr data))
516 (set-annotation-data annot (cons annot glyph))))
518 (defun gnus-picons-clear-cache ()
519 "Clear the picons cache."
521 (setq gnus-picons-glyph-alist nil
522 gnus-picons-url-alist nil))
524 (gnus-add-shutdown 'gnus-picons-close 'gnus)
526 (defun gnus-picons-close ()
527 "Shut down the picons."
528 (if gnus-picons-clear-cache-on-shutdown
529 (gnus-picons-clear-cache)))
531 ;;; Query a remote DB. This requires some stuff from w3 !
536 (require 'w3-forms)))
538 (defun gnus-picons-url-retrieve (url fn arg)
539 (let ((old-asynch (default-value 'url-be-asynchronous))
540 (url-working-buffer (generate-new-buffer " *picons*"))
541 (url-package-name "Gnus")
542 (url-package-version gnus-version-number)
544 (setq-default url-be-asynchronous t)
546 (set-buffer url-working-buffer)
547 (setq url-be-asynchronous t
548 url-current-callback-data arg
549 url-current-callback-func fn)
550 (url-retrieve url t))
551 (setq-default url-be-asynchronous old-asynch)))
553 (defun gnus-picons-make-glyph (type)
554 "Make a TYPE glyph using current buffer as data. Handles xbm nicely."
555 (cond ((null type) nil)
556 ((eq type 'xbm) (let ((fname (make-temp-name "/tmp/picon")))
557 (write-region (point-min) (point-max) fname
559 (prog1 (make-glyph (vector 'xbm :file fname))
560 (delete-file fname))))
561 (t (make-glyph (vector type :data (buffer-string))))))
563 ;;; Parsing of piconsearch result page.
566 ;; 1 - each value field has the form: "<strong>key</strong> = <kbd>value</kbd>"
567 ;; 2 - a "<p>" separates the keywords from the results
568 ;; 3 - every results begins by the path within the database at the beginning
569 ;; of the line in raw text.
570 ;; 3b - and the href following it is the preferred image type.
572 ;; if 1 or 2 is not met, it will probably cause an error. The other
573 ;; will go undetected
575 (defun gnus-picons-parse-value (name)
576 (goto-char (point-min))
577 (if (re-search-forward (concat "<strong>"
579 "</strong> *= *<kbd> *\\([^ <][^<]*\\) *</kbd>")
581 (buffer-substring (match-beginning 1) (match-end 1))))
583 (defun gnus-picons-parse-filenames ()
584 ;; returns an alist of ((USER ADDRS DB) . URL)
585 (let ((case-fold-search t)
586 (user (gnus-picons-parse-value "user"))
587 (host (gnus-picons-parse-value "host"))
588 (dbs (message-tokenize-header (gnus-picons-parse-value "db") " "))
589 start-re cur-db cur-host cur-user types res)
590 ;; now point will be somewhere in the header. Find beginning of
592 (when (and user host dbs)
596 "^\\(" (mapconcat 'identity dbs "\\|") "\\)/"
598 "\\(\\(" (replace-in-string host "\\." "/\\|" t)
601 "\\(" (regexp-quote user) "\\|unknown\\)/"
603 (re-search-forward "<p>[ \t\n]*")
604 (while (re-search-forward start-re nil t)
605 (setq cur-db (buffer-substring (match-beginning 1) (match-end 1))
606 cur-host (buffer-substring (match-beginning 2) (match-end 2))
607 cur-user (buffer-substring (match-beginning 4) (match-end 4))
608 cur-host (nreverse (message-tokenize-header cur-host "/")))
609 ;; XXX - KLUDGE: there is a blank picon in news/MISC/unknown
610 (unless (and (string-equal cur-db "news")
611 (string-equal cur-user "unknown")
612 (equal cur-host '("MISC")))
613 ;; ok now we have found an entry (USER HOST DB), find the
614 ;; corresponding picon URL
616 ;; restrict region to this entry
617 (narrow-to-region (point) (search-forward "<br>"))
618 (goto-char (point-min))
619 (setq types gnus-picons-file-suffixes)
621 (not (re-search-forward
622 (concat "<a[ \t\n]+href=\"\\([^\"]*\\."
623 (regexp-quote (car types)) "\\)\"")
626 (push (cons (list cur-user cur-host cur-db)
627 (buffer-substring (match-beginning 1) (match-end 1)))
631 ;;; picon network display functions :
633 (defun gnus-picons-network-display-internal (sym-ann glyph part right-p marker)
634 (let ((buf (marker-buffer marker))
635 (pos (marker-position marker)))
640 (gnus-picons-display-picon-or-name glyph part right-p))))
641 (gnus-picons-next-job-internal))
643 (defun gnus-picons-network-display-callback (url part sym-ann right-p marker)
644 (let ((glyph (gnus-picons-make-glyph (cdr (assoc url-current-mime-type
645 w3-image-mappings)))))
646 (kill-buffer (current-buffer))
647 (push (cons url glyph) gnus-picons-glyph-alist)
648 ;; only do the job if it has not been preempted.
649 (if (equal gnus-picons-job-already-running
650 (list sym-ann 'picon url part right-p marker))
651 (gnus-picons-network-display-internal
652 sym-ann glyph part right-p marker)
653 (gnus-picons-next-job-internal))))
655 (defun gnus-picons-network-display (url part sym-ann right-p marker)
656 (let ((cache (assoc url gnus-picons-glyph-alist)))
657 (if (or cache (null url))
658 (gnus-picons-network-display-internal
659 sym-ann (cdr cache) part right-p marker)
660 (gnus-picons-url-retrieve url 'gnus-picons-network-display-callback
661 (list url part sym-ann right-p marker)))))
663 ;;; search job functions
665 (defun gnus-picons-display-bar-p ()
666 (and (not (eq gnus-picons-display-where 'article))
667 gnus-picons-display-as-address))
669 (defun gnus-picons-network-search-internal (user addrs dbs sym-ann right-p
670 marker &optional fnames)
671 (let (curkey dom pfx url dbs-tmp cache new-jobs)
672 ;; First do the domain search
673 (dolist (part (if right-p
676 (setq pfx (nconc (list part) pfx)
677 dom (cond ((and dom right-p) (concat part "." dom))
678 (dom (concat dom "." part))
680 curkey (list "unknown" dom dbs))
681 (when (null (setq cache (assoc curkey gnus-picons-url-alist)))
682 ;; This one is not yet in the cache, create a new entry
683 ;; Search for an entry
686 (while (and dbs-tmp (null url))
687 (setq url (or (cdr (assoc (list "unknown" pfx (car dbs-tmp)) fnames))
689 ;; This is the first component. Try the
690 ;; catch-all MISC component
691 (cdr (assoc (list "unknown"
696 (push (setq cache (cons curkey url)) gnus-picons-url-alist))
697 ;; Put this glyph in the job list
698 (if (and (not (eq dom part)) gnus-picons-display-as-address)
699 (push (list sym-ann "." right-p marker) new-jobs))
700 (push (list sym-ann 'picon (cdr cache) part right-p marker) new-jobs))
701 ;; next, the user search
703 (setq curkey (list user dom gnus-picons-user-directories))
704 (if (null (setq cache (assoc curkey gnus-picons-url-alist)))
705 (let ((users (list user "unknown"))
706 dirs usr domains-tmp dir picon)
707 (while (and users (null picon))
708 (setq dirs gnus-picons-user-directories
710 (while (and dirs (null picon))
711 (setq domains-tmp addrs
713 (while (and domains-tmp
714 (null (setq picon (assoc (list usr domains-tmp dir)
718 (setq picon (assoc (list usr '("MISC") dir) fnames)))))
719 (push (setq cache (cons curkey (cdr picon)))
720 gnus-picons-url-alist)))
721 (if (and gnus-picons-display-as-address new-jobs)
722 (push (list sym-ann "@" right-p marker) new-jobs))
723 (push (list sym-ann 'picon (cdr cache) user right-p marker) new-jobs))
724 (if (and (gnus-picons-display-bar-p) (not right-p))
725 (push (list sym-ann 'bar right-p marker) new-jobs))
726 ;; only put the jobs in the queue if this job has not been preempted.
727 (if (equal gnus-picons-job-already-running
728 (list sym-ann 'search user addrs dbs right-p marker))
729 (setq gnus-picons-jobs-alist
730 (nconc (if (and (gnus-picons-display-bar-p) right-p)
731 (list (list sym-ann 'bar right-p marker)))
733 gnus-picons-jobs-alist)))
734 (gnus-picons-next-job-internal)))
736 (defun gnus-picons-network-search-callback (user addrs dbs sym-ann right-p
738 (gnus-picons-network-search-internal
739 user addrs dbs sym-ann right-p marker
741 (gnus-picons-parse-filenames)
742 (kill-buffer (current-buffer)))))
744 ;; Initiate a query on the picon database
745 (defun gnus-picons-network-search (user addrs dbs sym-ann right-p marker)
746 (let* ((host (mapconcat 'identity addrs "."))
747 (key (list (or user "unknown") host (if user
748 gnus-picons-user-directories
750 (cache (assoc key gnus-picons-url-alist)))
752 (gnus-picons-url-retrieve
753 (concat gnus-picons-piconsearch-url
754 "?user=" (w3-form-encode-xwfu (or user "unknown"))
755 "&host=" (w3-form-encode-xwfu host)
756 "&db=" (mapconcat 'w3-form-encode-xwfu
759 gnus-picons-user-directories)
762 'gnus-picons-network-search-callback
763 (list user addrs dbs sym-ann right-p marker))
764 (gnus-picons-network-search-internal
765 user addrs dbs sym-ann right-p marker))))
767 ;;; Main jobs dispatcher function
769 (defun gnus-picons-next-job-internal ()
770 (when (setq gnus-picons-job-already-running (pop gnus-picons-jobs-alist))
771 (let* ((job gnus-picons-job-already-running)
776 ((stringp tag);; (SYM-ANN "..." RIGHT-P MARKER)
777 (gnus-picons-network-display-internal
778 sym-ann nil tag (pop job) (pop job)))
779 ((eq 'bar tag);; (SYM-ANN 'bar RIGHT-P MARKER)
780 (gnus-picons-network-display-internal
782 (let ((gnus-picons-file-suffixes '("xbm")))
783 (gnus-picons-try-face
784 gnus-xmas-glyph-directory "bar."))
785 nil (pop job) (pop job)))
786 ((eq 'search tag);; (SYM-ANN 'search USER ADDRS DBS RIGHT-P MARKER)
787 (gnus-picons-network-search
788 (pop job) (pop job) (pop job) sym-ann (pop job) (pop job)))
789 ((eq 'picon tag);; (SYM-ANN 'picon URL PART RIGHT-P MARKER)
790 (gnus-picons-network-display
791 (pop job) (pop job) sym-ann (pop job) (pop job)))
793 (setq gnus-picons-job-already-running nil)
794 (error "Unknown picon job tag %s" tag)))))))
796 (defun gnus-picons-next-job ()
797 "Start processing the job queue if it is not in progress."
798 (unless gnus-picons-job-already-running
799 (gnus-picons-next-job-internal)))
801 (provide 'gnus-picon)
803 ;;; gnus-picon.el ends here