* riece-xface.el (riece-xface-user-list-mode-hook): New function.
[riece] / lisp / riece-keepalive.el
1 ;;; riece-keepalive.el --- keep an IRC connection
2 ;; Copyright (C) 1998-2004 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-options)
32
33 (defgroup riece-keepalive nil
34   "Keep an IRC connection."
35   :prefix "riece-"
36   :group 'riece)
37
38 (defcustom riece-keepalive-ping-repeat 120
39   "Interval for sending PING to server."
40   :type 'integer
41   :group 'riece-keepalive)
42
43 (defvar riece-keepalive-timer nil)
44
45 (defconst riece-keepalive-description
46   "Keep an IRC connection.")
47
48 (defun riece-keepalive-after-login-hook ()
49   (make-local-variable 'riece-keepalive-timer)
50   (unless riece-keepalive-timer
51     (setq riece-keepalive-timer
52           (riece-run-at-time
53            riece-keepalive-ping-repeat riece-keepalive-ping-repeat
54            (lambda (buffer)
55              (save-excursion
56                (set-buffer buffer)
57                (riece-send-string "PING riece-keepalive\r\n")))
58            (current-buffer)))))
59
60 (defun riece-keepalive-after-close-hook ()
61   (when riece-keepalive-timer
62     (riece-cancel-timer riece-keepalive-timer)
63     (setq riece-keepalive-timer nil)))
64
65 (defun riece-keepalive-insinuate ()
66   (add-hook 'riece-after-login-hook 'riece-keepalive-after-login-hook)
67   (add-hook 'riece-after-close-hook 'riece-keepalive-after-close-hook))
68
69 (defun riece-keepalive-uninstall ()
70   (remove-hook 'riece-after-login-hook 'riece-keepalive-after-login-hook)
71   (remove-hook 'riece-after-close-hook 'riece-keepalive-after-close-hook))
72
73 (provide 'riece-keepalive)
74
75 ;;; riece-ignore.el ends here