Merge remote-tracking branch 'sourceforge/master'
[emacs-jabber.git] / jabber-menu.el
blob47957eed28ec0d9938a586fdf474729349471faf
1 ;; jabber-menu.el - menu definitions
3 ;; Copyright (C) 2003, 2004, 2008 - Magnus Henoch - mange@freemail.hu
4 ;; Copyright (C) 2002, 2003, 2004 - tom berger - object@intelectronica.net
6 ;; This file is a part of jabber.el.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program; if not, write to the Free Software
20 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 (require 'jabber-util)
23 (require 'jabber-autoloads)
24 (eval-when-compile (require 'cl))
26 ;;;###autoload
27 (defvar jabber-menu
28 (let ((map (make-sparse-keymap "jabber-menu")))
29 (define-key map
30 [jabber-menu-connect]
31 '("Connect" . jabber-connect-all))
33 (define-key map
34 [jabber-menu-nextmsg]
35 '("Next unread message" . jabber-activity-switch-to))
37 (define-key map
38 [jabber-menu-disconnect]
39 '("Disconnect" . jabber-disconnect))
41 (define-key map
42 [jabber-menu-roster]
43 '("Switch to roster" . jabber-switch-to-roster-buffer))
45 (define-key map
46 [jabber-menu-customize]
47 '("Customize" . jabber-customize))
49 (define-key map
50 [jabber-menu-info]
51 '("Help" . jabber-info))
53 (define-key map
54 [jabber-menu-status]
55 (cons "Set Status" (make-sparse-keymap "set-status")))
57 (define-key map
58 [jabber-menu-status jabber-menu-status-chat]
59 '("Chatty" .
60 (lambda ()
61 (interactive)
62 (jabber-send-presence "chat"
63 (jabber-read-with-input-method "status message: " *jabber-current-status* '*jabber-status-history*)
64 *jabber-current-priority*))))
65 (define-key map
66 [jabber-menu-status jabber-menu-status-dnd]
67 '("Do not Disturb" .
68 (lambda ()
69 (interactive)
70 (jabber-send-presence "dnd"
71 (jabber-read-with-input-method "status message: " *jabber-current-status* '*jabber-status-history*)
72 *jabber-current-priority*))))
73 (define-key map
74 [jabber-menu-status jabber-menu-status-xa]
75 '("Extended Away" . jabber-send-xa-presence))
76 (define-key map
77 [jabber-menu-status jabber-menu-status-away]
78 '("Away" . jabber-send-away-presence))
79 (define-key map
80 [jabber-menu-status jabber-menu-status-online]
81 '("Online" . jabber-send-default-presence))
83 map))
85 ;;;###autoload
86 (defcustom jabber-display-menu 'maybe
87 "Decide whether the \"Jabber\" menu is displayed in the menu bar.
88 If t, always display.
89 If nil, never display.
90 If maybe, display if any of `jabber-account-list' or `jabber-connections'
91 is non-nil."
92 :group 'jabber
93 :type '(choice (const :tag "Never" nil)
94 (const :tag "Always" t)
95 (const :tag "When any accounts have been configured or connected" maybe)))
97 (defun jabber-menu (&optional remove)
98 "Put \"Jabber\" menu on menubar.
99 With prefix argument, remove it."
100 (interactive "P")
101 (setq jabber-display-menu (if remove nil t))
102 (force-mode-line-update))
103 (make-obsolete 'jabber-menu "set the variable `jabber-display-menu' instead.")
105 ;; This used to be:
106 ;; (define-key-after global-map [menu-bar jabber-menu] ...)
107 ;; but that doesn't work in Emacs 21.
108 ;;;###autoload
109 (define-key-after (lookup-key global-map [menu-bar])
110 [jabber-menu]
111 (list 'menu-item "Jabber" jabber-menu
112 :visible '(or (eq jabber-display-menu t)
113 (and (eq jabber-display-menu 'maybe)
114 (or jabber-account-list
115 (bound-and-true-p jabber-connections))))))
117 (defvar jabber-jid-chat-menu nil
118 "Menu items for chat menu")
120 (defvar jabber-jid-info-menu nil
121 "Menu item for info menu")
123 (defvar jabber-jid-roster-menu nil
124 "Menu items for roster menu")
126 (defvar jabber-jid-muc-menu nil
127 "Menu items for MUC menu")
129 (defvar jabber-jid-service-menu nil
130 "Menu items for service menu")
132 (defun jabber-popup-menu (which-menu)
133 "Popup specified menu"
134 (let* ((mouse-event (and (listp last-input-event) last-input-event))
135 (choice (widget-choose "Actions" which-menu mouse-event)))
136 (if mouse-event
137 (mouse-set-point mouse-event))
138 (if choice
139 (call-interactively choice))))
141 (defun jabber-popup-chat-menu ()
142 "Popup chat menu"
143 (interactive)
144 (jabber-popup-menu jabber-jid-chat-menu))
146 (defun jabber-popup-info-menu ()
147 "Popup info menu"
148 (interactive)
149 (jabber-popup-menu jabber-jid-info-menu))
151 (defun jabber-popup-roster-menu ()
152 "Popup roster menu"
153 (interactive)
154 (jabber-popup-menu jabber-jid-roster-menu))
156 (defun jabber-popup-muc-menu ()
157 "Popup MUC menu"
158 (interactive)
159 (jabber-popup-menu jabber-jid-muc-menu))
161 (defun jabber-popup-service-menu ()
162 "Popup service menu"
163 (interactive)
164 (jabber-popup-menu jabber-jid-service-menu))
166 (defun jabber-popup-combined-menu ()
167 "Popup combined menu"
168 (interactive)
169 (jabber-popup-menu (append jabber-jid-chat-menu jabber-jid-info-menu jabber-jid-roster-menu jabber-jid-muc-menu)))
171 (provide 'jabber-menu)
173 ;;; arch-tag: 5147f52f-de47-4348-86ff-b799d7a75e3f