Use a nicer, cleaner syntax calling #'make-glyph
[emchat] / emchat-toolbar.el
1 ;;; emchat-toolbar.el --- A toolbar for EMchat   -*-Emacs-Lisp-*-
2
3 ;; Copyright (C) 2000 - 2011 Steve Youngs
4
5 ;; Author:        Steve Youngs <steve@emchat.org>
6 ;; Maintainer:    Steve Youngs <steve@emchat.org>
7 ;; Keywords:      emchat, toolbar, comm
8
9 ;; This file is part of EMchat.
10
11 ;; Redistribution and use in source and binary forms, with or without
12 ;; modification, are permitted provided that the following conditions
13 ;; are met:
14 ;;
15 ;; 1. Redistributions of source code must retain the above copyright
16 ;;    notice, this list of conditions and the following disclaimer.
17 ;;
18 ;; 2. Redistributions in binary form must reproduce the above copyright
19 ;;    notice, this list of conditions and the following disclaimer in the
20 ;;    documentation and/or other materials provided with the distribution.
21 ;;
22 ;; 3. Neither the name of the author nor the names of any contributors
23 ;;    may be used to endorse or promote products derived from this
24 ;;    software without specific prior written permission.
25 ;;
26 ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
27 ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 ;; DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
33 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
34 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
35 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
36 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
38 ;;; Commentary:
39 ;;
40 ;;            A toolbar for emchat.
41 ;;
42
43 (eval-and-compile
44   (require 'emchat-meta)
45   (require 'emchat-log))
46
47 (autoload 'emchat-change-password "emchat" nil t)
48 (autoload 'emchat-send-message-alias-here "emchat" nil t)
49 (autoload 'emchat-send-message "emchat" nil t)
50 (autoload 'emchat-send-url-alias-here "emchat" nil t)
51 (autoload 'emchat-send-url "emchat" nil t)
52 (autoload 'emchat-query-info-alias-around "emchat" nil t)
53 (autoload 'emchat-query-info "emchat" nil t)
54 (autoload 'emchat-search "emchat" nil t)
55 (autoload 'emchat-authorize-alias-here "emchat" nil t)
56 (autoload 'emchat-login "emchat" nil t)
57 (autoload 'emchat-logout "emchat" nil t)
58 (autoload 'emchat-exit "emchat" nil t)
59
60 ;;; Code:
61
62 (defcustom emchat-use-toolbar (if (and (featurep 'toolbar)
63                                      (featurep 'xpm))
64                                 'default-toolbar
65                               nil)
66   "*If nil, do not use a toolbar.
67 If it is non-nil, it must be a toolbar.  The five valid values are
68 `default-toolbar', `top-toolbar', `bottom-toolbar',
69 `right-toolbar', and `left-toolbar'."
70   :type '(choice (const default-toolbar)
71                  (const top-toolbar) (const bottom-toolbar)
72                  (const left-toolbar) (const right-toolbar)
73                  (const :tag "no toolbar" nil))
74   :group 'emchat-interface)
75
76 (defvar emchat-password-icon
77   (toolbar-make-button-list
78    (expand-file-name "password.xpm" emchat-glyph-dir))
79   "A password toolbar icon.")
80
81 (defvar emchat-send-message-here-icon
82   (toolbar-make-button-list
83    (expand-file-name "msg-here.xpm" emchat-glyph-dir))
84   "A send message toolbar icon.")
85
86 (defvar emchat-send-message-around-icon
87   (toolbar-make-button-list
88    (expand-file-name "msg-around.xpm" emchat-glyph-dir))
89   "A send message toolbar icon.")
90
91 (defvar emchat-send-url-here-icon
92   (toolbar-make-button-list
93    (expand-file-name "url-here.xpm" emchat-glyph-dir))
94   "A send URL toolbar icon.")
95
96 (defvar emchat-send-url-around-icon
97   (toolbar-make-button-list
98    (expand-file-name "url-around.xpm" emchat-glyph-dir))
99   "A send URL toolbar icon.")
100
101 (defvar emchat-query-info-here-icon
102   (toolbar-make-button-list
103    (expand-file-name "info-here.xpm" emchat-glyph-dir))
104   "A query info here toolbar icon.")
105
106 (defvar emchat-query-info-around-icon
107   (toolbar-make-button-list
108    (expand-file-name "info-around.xpm" emchat-glyph-dir))
109   "A query info here toolbar icon.")
110
111 (defvar emchat-update-info-icon
112   (toolbar-make-button-list
113    (expand-file-name "upd-info.xpm" emchat-glyph-dir))
114   "A update info toolbar icon.")
115
116 (defvar emchat-search-icon
117   (toolbar-make-button-list
118    (expand-file-name "search.xpm" emchat-glyph-dir))
119   "A search toolbar icon.")
120
121 (defvar emchat-authorize-here-icon
122   (toolbar-make-button-list
123    (expand-file-name "auth-here.xpm" emchat-glyph-dir))
124   "A authorize toolbar icon.")
125
126 (defvar emchat-login-icon
127   (toolbar-make-button-list
128    (expand-file-name "login.xpm" emchat-glyph-dir))
129   "A login toolbar icon.")
130
131 (defvar emchat-logout-icon
132   (toolbar-make-button-list
133    (expand-file-name "logout.xpm" emchat-glyph-dir))
134   "A logout toolbar icon.")
135
136 (defvar emchat-exit-icon
137   (toolbar-make-button-list
138    (expand-file-name "exit.xpm" emchat-glyph-dir))
139   "A exit toolbar icon.")
140
141 (defvar emchat-new-log-icon
142   (toolbar-make-button-list
143    (expand-file-name "new-log.xpm" emchat-glyph-dir))
144   "New log file toolbar icon.")
145
146 (defvar emchat-help-icon
147   (toolbar-make-button-list
148    (expand-file-name "help.xpm" emchat-glyph-dir))
149   "A help toolbar icon.")
150
151 ;; Define the functions for the toolbar
152
153 (defun emchat-toolbar-change-password (password)
154   "Change PASSWORD from the toolbar."
155   (interactive (list (read-passwd "Password: " 'confirm)))
156   (emchat-change-password password))
157
158 (defun emchat-toolbar-send-message-here ()
159   "Send message from toolbar."
160   (interactive)
161   (emchat-send-message-alias-here))
162
163 (defun emchat-toolbar-send-message-around ()
164   "Send message from toolbar."
165   (interactive)
166   (emchat-send-message))
167
168 (defun emchat-toolbar-send-url-here ()
169   "Send URL from the toolbar."
170   (interactive)
171   (emchat-send-url-alias-here))
172
173 (defun emchat-toolbar-send-url-around ()
174   "Send URL from the toolbar."
175   (interactive)
176   (emchat-send-url))
177
178 (defun emchat-toolbar-query-info-here ()
179   "Query info from the toolbar."
180   (interactive)
181   (emchat-query-info-alias-around))
182
183 (defun emchat-toolbar-query-info-around ()
184   "Query info from the toolbar."
185   (interactive)
186   (emchat-query-info))
187
188 (defun emchat-toolbar-update-info ()
189   "Update meta info from the toolbar."
190   (interactive)
191   ;(emchat-update-meta-info))
192   (message-or-box "Sorry, this feature is not yet implemented"))
193
194 (defun emchat-toolbar-search ()
195   "Search from the toolbar.
196
197 Prompts for the search terms."
198   (interactive)
199   (let ((first (read-string "First Name [RET for null]: "))
200         (last (read-string "Last Name [RET for null]: "))
201         (nick (read-string "Nick Name [RET for null]: "))
202         (email (read-string "Email Address [RET for null]: ")))
203     (emchat-search nil first last nick email)))
204
205 (defun emchat-toolbar-authorize-here ()
206   "Authorize from the toolbar."
207   (interactive)
208   (emchat-authorize-alias-here))
209
210 (defun emchat-toolbar-login ()
211   "Login from the toolbar."
212   (interactive)
213   (emchat-login))
214
215 (defun emchat-toolbar-logout ()
216   "Logout from the toolbar."
217   (interactive)
218   (emchat-logout))
219
220 (defun emchat-toolbar-exit ()
221   "Exit from the toolbar."
222   (interactive)
223   (emchat-exit))
224
225 (defun emchat-toolbar-new-log ()
226   "New log file from the toolbar."
227   (interactive)
228   (emchat-log-new-file))
229
230 (defun emchat-toolbar-help ()
231   "Display the EMchat info documentation."
232   (interactive)
233   (Info-goto-node "(emchat.info)Top"))
234
235 ;; Now define the toolbar
236 (defvar emchat-log-toolbar
237   '([emchat-password-icon
238      emchat-toolbar-change-password t "Change password"]
239     [emchat-send-message-here-icon
240      emchat-toolbar-send-message-here t "Send message here"]
241     [emchat-send-message-around-icon
242      emchat-toolbar-send-message-around t "Send message..."]
243     [emchat-send-url-here-icon
244      emchat-toolbar-send-url-here t "Send URL here"]
245     [emchat-send-url-around-icon
246      emchat-toolbar-send-url-around t "Send URL..."]
247     [emchat-query-info-here-icon
248      emchat-toolbar-query-info-here t "Query info here"]
249     [emchat-query-info-around-icon
250      emchat-toolbar-query-info-around t "Query info..."]
251     [emchat-search-icon
252      emchat-toolbar-search t "Search"]
253     [emchat-authorize-here-icon
254      emchat-toolbar-authorize-here t "Authorize here"]
255     [emchat-new-log-icon
256      emchat-toolbar-new-log t "New log file"]
257     [emchat-login-icon
258      emchat-toolbar-login t "Login"]
259     [emchat-logout-icon
260      emchat-toolbar-logout t "Logout"]
261     [emchat-exit-icon
262      emchat-toolbar-exit t "Exit"]
263     nil
264     [emchat-help-icon
265      emchat-toolbar-help t "Help"])
266   "A clickety click EMchat log buffer toolbar.")
267
268 ;;;###autoload
269 (defun emchat-install-buddy-toolbar ()
270   "Install the toolbar for `emchat-buddy-mode' in EMchat."
271   (and emchat-use-toolbar
272        (set-specifier (symbol-value emchat-use-toolbar)
273                       (cons
274                        (current-buffer) emchat-log-toolbar))))
275
276 ;;;###autoload
277 (defalias 'emchat-install-log-toolbar 'emchat-install-buddy-toolbar)
278
279 (provide 'emchat-toolbar)
280
281 ;;; emchat-toolbar.el ends here