* sb-airs.el (toplevel): Require 'sb-mhonarc.
[elisp/wanderlust.git] / elmo / sb-lump.el
1 ;;; sb-lump.el --- shimbun backend class to check all groups at once
2
3 ;; Author: TSUCHIYA Masatoshi <tsuchiya@pine.kuee.kyoto-u.ac.jp>
4 ;;         Akihiro Arisawa    <ari@atesoft.advantest.co.jp>
5 ;;         Yuuichi Teranishi <teranisi@gohome.org>
6
7 ;; Keywords: news
8
9 ;;; Copyright:
10
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program; if not, you can either send email to this
23 ;; program's maintainer or write to: The Free Software Foundation,
24 ;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; Original code was nnshimbun.el written by
29 ;; TSUCHIYA Masatoshi <tsuchiya@pine.kuee.kyoto-u.ac.jp>.
30
31 ;;; Code:
32
33 (require 'shimbun)
34 (defvar shimbun-lump-check-interval 300)
35
36 (eval-and-compile
37   (luna-define-class shimbun-lump (shimbun) (group-header-alist last-check))
38   (luna-define-internal-accessors 'shimbun-lump))
39
40 (defun shimbun-lump-lapse-seconds (time)
41   (let ((now (current-time)))
42     (+ (* (- (car now) (car time)) 65536)
43        (- (nth 1 now) (nth 1 time)))))
44
45 (defun shimbun-lump-check-p (shimbun)
46   (or (null (shimbun-lump-last-check-internal shimbun))
47       (and (shimbun-lump-last-check-internal shimbun)
48            (< (shimbun-lump-lapse-seconds
49                (shimbun-lump-last-check-internal shimbun))
50               shimbun-lump-check-interval))))
51
52 (defun shimbun-lump-checked (shimbun)
53   (shimbun-lump-set-last-check-internal shimbun (current-time)))
54
55 (luna-define-generic shimbun-get-group-header-alist (shimbun)
56   "Return an alist of group and header list.")
57
58 (luna-define-method shimbun-get-headers ((shimbun shimbun-lump))
59   (when (shimbun-lump-check-p shimbun)
60     (shimbun-lump-set-group-header-alist-internal
61      shimbun (shimbun-get-group-header-alist shimbun))
62     (shimbun-lump-checked shimbun))
63   (cdr (assoc (shimbun-current-group-internal shimbun)
64               (shimbun-lump-group-header-alist-internal shimbun))))
65
66 (luna-define-method shimbun-close :after ((shimbun shimbun-lump))
67   (shimbun-lump-set-group-header-alist-internal shimbun nil)
68   (shimbun-lump-set-last-check-internal shimbun nil))
69
70 (provide 'sb-lump)
71
72 ;;; sb-lump.el ends here