1 ;;; emchat-wharf.el --- DockApp/status window for EMchat
3 ;; Copyright (C) 2001 - 2011 Steve Youngs, Erik Arneson
5 ;; Author: Erik Arneson <erik@emchat.org>
6 ;; Maintainer: Erik Arneson <erik@emchat.org>
7 ;; Created: Aug 10, 2001
8 ;; Homepage: http://www.emchat.org/
11 ;; This file is part of EMchat.
13 ;; Redistribution and use in source and binary forms, with or without
14 ;; modification, are permitted provided that the following conditions
17 ;; 1. Redistributions of source code must retain the above copyright
18 ;; notice, this list of conditions and the following disclaimer.
20 ;; 2. Redistributions in binary form must reproduce the above copyright
21 ;; notice, this list of conditions and the following disclaimer in the
22 ;; documentation and/or other materials provided with the distribution.
24 ;; 3. Neither the name of the author nor the names of any contributors
25 ;; may be used to endorse or promote products derived from this
26 ;; software without specific prior written permission.
28 ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
29 ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 ;; DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
37 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
38 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 (defvar emchat-wharf-frame nil
41 "Frame in which EMchatWharf is running.")
43 (defvar emchat-wharf-frame-props
44 '((name . "EMchatWharf")
49 (menubar-visible-p . nil)
50 (has-modeline-p . nil)
51 (default-gutter-visible-p . nil)
52 (default-toolbar-visible-p . nil)
53 (scrollbar-height . 0)
55 (text-cursor-visible-p . nil))
56 "Frame properties for EMchatWharf.")
58 (defvar emchat-wharf-buf nil
59 "Buffer in which EMchatWharf is running.")
61 (defgroup emchat-wharf nil
62 "Miniature EMchat status window."
63 :prefix "emchat-wharf-"
66 (defface emchat-wharf-default-face
68 (:foreground "Green" :family "fixed" :size "9pt"))
70 (:family "fixed" :size "9pt")))
71 "Face used in EMchatWharf window.
73 If you want this to be dockable, make sure you use a small but readable
77 (defcustom emchat-wharf-notice-riece-flag nil
78 "When non-nil, indicate Riece activity in EMchatWharf.
80 This requires riece-biff to be set up and active."
84 ;; Riece activity indicator face
85 (make-face 'emchat-wharf-riece-active-face
86 "Face used in EMchat Wharf when there is activity from Riece.")
87 (set-face-parent 'emchat-wharf-riece-active-face
88 'emchat-wharf-default-face)
89 (set-face-foreground 'emchat-wharf-riece-active-face "Red")
91 (make-face 'emchat-wharf-riece-inactive-face
92 "Face used in EMchat Wharf when there is no activity from Riece.")
93 (set-face-parent 'emchat-wharf-riece-inactive-face
94 'emchat-wharf-default-face)
95 (set-face-foreground 'emchat-wharf-riece-inactive-face "Black")
99 (defcustom emchat-wharf-frame-use-p nil
100 "If non-NIL, start up the EMchatWharf mini-frame."
103 :tag "EMchatWharf mini-frame")
105 ;;; Internal variables
107 ;;; Riece integration
108 (defvar emchat-riece-activity nil
109 "This is non-nil when riece-biff has been triggered.")
111 ;; Advise a couple of Riece functions to run some hooks for us.
112 (defadvice riece-biff-after-display-message-function (after biffon (&rest args) activate)
113 "Update the EMchatWharf Riece indicator."
114 (when (eq riece-biff-mode-string 'riece-biff-biff-mode-string)
115 (run-hooks 'riece-biff-activity-hook)))
117 (defadvice riece-biff-clear (after biffoff (&rest args) activate)
118 "Update the EMchatWharf Riece indicator."
119 (when (eq riece-biff-mode-string 'riece-biff-default-mode-string)
120 (run-hooks 'riece-biff-clear-hook)))
122 (defun emchat-wharf-riece-active ()
123 "Make the EMchatWharf Riece indicator active."
124 (let ((emchat-riece-activity t))
125 (emchat-wharf-update-riece)))
127 (defun emchat-wharf-riece-inactive ()
128 "Make the EMchatWharf Riece indicator inactive."
129 (let ((emchat-riece-activity nil))
130 (emchat-wharf-update-riece)))
132 (defun emchat-wharf-update-riece ()
133 "Update the status line in EMchatWharf."
134 (when emchat-wharf-buf
136 (set-buffer emchat-wharf-buf)
138 (delete-region (point-at-bol) (point-at-eol))
139 (insert-face "Riece" (if emchat-riece-activity
140 'emchat-wharf-riece-active-face
141 'emchat-wharf-riece-inactive-face)))))
144 (defun emchat-wharf-new-frame ()
145 "Create new EMchatWharf frame."
146 (unless (frame-live-p emchat-wharf-frame)
147 (setq emchat-wharf-frame (new-frame emchat-wharf-frame-props))
148 (select-frame emchat-wharf-frame)
149 (unless (buffer-live-p emchat-wharf-buf)
150 (setq emchat-wharf-buf (get-buffer-create "*EMchatWharf*"))
151 (set-buffer-dedicated-frame emchat-wharf-buf emchat-wharf-frame)
153 (set-buffer emchat-wharf-buf)
154 (insert "New 000\nSys 000\n")
155 (set-extent-face (make-extent (point-min) (point-max) emchat-wharf-buf)
156 'emchat-wharf-default-face)
157 (insert-face emchat-user-status (emchat-status-face emchat-user-status))
158 (when emchat-wharf-notice-riece-flag
160 (insert-face "Riece" (if emchat-riece-activity
161 'emchat-wharf-riece-active-face
162 'emchat-wharf-riece-inactive-face)))
164 (if (fboundp 'set-specifier)
166 (set-specifier horizontal-scrollbar-visible-p nil
167 (cons emchat-wharf-frame nil))
168 (set-specifier vertical-scrollbar-visible-p nil
169 (cons emchat-wharf-frame nil))))
170 (set-face-font 'default
171 (face-font-name 'emchat-wharf-default-face)
173 (set-window-buffer nil emchat-wharf-buf)))
175 (defun emchat-wharf-change-messages (type num)
179 (set-buffer emchat-wharf-buf)
180 (goto-char (point-min))
181 (if (re-search-forward (concat "^\\("
183 " *\\([0-9]+\\)\\)$")
186 (setq oldnum (string-to-int (match-string 2))
187 newnum (+ oldnum num))
190 (replace-match (format "%-3s %03d" type newnum))))))))
192 (defun emchat-wharf-inc-messages ()
193 "Increment number of new messages in EMchatWharf."
194 (emchat-wharf-change-messages "New" 1))
196 (defun emchat-wharf-dec-messages ()
197 "Decrement number of new messages in EMchatWharf."
198 (emchat-wharf-change-messages "New" -1))
200 (defun emchat-wharf-inc-system ()
201 "Increment number of system messages in EMchatWharf."
202 (emchat-wharf-change-messages "Sys" 1))
204 (defun emchat-wharf-dec-system ()
205 "Decrement number of system messages in EMchatWharf."
206 (emchat-wharf-change-messages "Sys" -1))
208 (defun emchat-wharf-update-status ()
209 "Update the status line in EMchatWharf."
210 (when emchat-wharf-buf
212 (set-buffer emchat-wharf-buf)
214 (delete-region (point-at-bol) (point-at-eol))
215 (insert-face emchat-user-status (emchat-status-face emchat-user-status)))))
217 (provide 'emchat-wharf)
218 ;;; emchat-wharf.el ends here