Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0050.py @ 773:eac23b1aad90
core: dynamics menus refactoring:
- menu now use generic callback system, with extra data
- asyncMenuCall is removed in favor of launchAction
- menu_id (== callback_id) is used to identify menu instead of category/name/type tuple
- i18n is managed throught deferred translation, and returned with _i18n suffix
e.g.: menu (D_('File'), D_('Open')): (u'File', u'Open') is menu_path, (u'Fichier', u'Ouvrir') is french menu_path_i18n.
- type actually can have the following values:
- NORMAL: classical menu
- JID_CONTEXT: contextual menu, used with any jid
- ROSTER_JID_CONTEXT: like JID_CONTEXT, but restricted to jids in roster.
- ROSTER_GROUP_CONTEXT: contextual menu, use with groups
- security_limit is used, in the same way as for parameters
- when using importMenu, callback can be an actual callback, or one already registered with registerCallback
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 29 Dec 2013 17:10:14 +0100 |
parents | bfabeedbf32e |
children | 8f5479f8709a |
comparison
equal
deleted
inserted
replaced
772:dd07fc737d6c | 773:eac23b1aad90 |
---|---|
15 # GNU Affero General Public License for more details. | 15 # GNU Affero General Public License for more details. |
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _, D_ |
21 from logging import debug, info, warning, error | 21 from logging import debug, info, warning, error |
22 from twisted.words.protocols.jabber import jid | 22 from twisted.words.protocols.jabber import jid |
23 from twisted.words.protocols.jabber import error as xmpp_error | 23 from twisted.words.protocols.jabber import error as xmpp_error |
24 from twisted.words.xish import domish | 24 from twisted.words.xish import domish |
25 from twisted.internet import defer, reactor | 25 from twisted.internet import defer, reactor |
210 self.answering = {} | 210 self.answering = {} |
211 host.bridge.addMethod("requestCommand", ".plugin", in_sign='ss', out_sign='s', | 211 host.bridge.addMethod("requestCommand", ".plugin", in_sign='ss', out_sign='s', |
212 method=self._requestCommandsList, | 212 method=self._requestCommandsList, |
213 async=True) | 213 async=True) |
214 self.__requesting_id = host.registerCallback(self._requestingEntity, with_data=True) | 214 self.__requesting_id = host.registerCallback(self._requestingEntity, with_data=True) |
215 host.importMenu("Service", "commands", self._commandsMenu, help_string=_("Execute ad-hoc commands")) | 215 host.importMenu((D_("Service"), D_("commands")), self._commandsMenu, help_string=D_("Execute ad-hoc commands")) |
216 | 216 |
217 def getHandler(self, profile): | 217 def getHandler(self, profile): |
218 return XEP_0050_handler(self) | 218 return XEP_0050_handler(self) |
219 | 219 |
220 def profileConnected(self, profile): | 220 def profileConnected(self, profile): |
320 d.addCallback(self._commandsAnswer2XMLUI, session_id, session_data) | 320 d.addCallback(self._commandsAnswer2XMLUI, session_id, session_data) |
321 d.addCallback(lambda xmlui: {'xmlui': xmlui.toXml()} if xmlui is not None else {}) | 321 d.addCallback(lambda xmlui: {'xmlui': xmlui.toXml()} if xmlui is not None else {}) |
322 | 322 |
323 return d | 323 return d |
324 | 324 |
325 def _commandsMenu(self, profile): | 325 def _commandsMenu(self, menu_data, profile): |
326 """ First XMLUI activated by menu: ask for target jid | 326 """ First XMLUI activated by menu: ask for target jid |
327 @param profile: %(doc_profile)s | 327 @param profile: %(doc_profile)s |
328 | 328 |
329 """ | 329 """ |
330 form_ui = xml_tools.XMLUI("form", submit_id=self.__requesting_id) | 330 form_ui = xml_tools.XMLUI("form", submit_id=self.__requesting_id) |
331 form_ui.addText(_("Please enter target jid"), 'instructions') | 331 form_ui.addText(_("Please enter target jid"), 'instructions') |
332 form_ui.changeLayout("pairs") | 332 form_ui.changeLayout("pairs") |
333 form_ui.addLabel("jid") | 333 form_ui.addLabel("jid") |
334 form_ui.addString("jid") | 334 form_ui.addString("jid") |
335 return form_ui.toXml() | 335 return {'xmlui': form_ui.toXml()} |
336 | 336 |
337 def _statusCallback(self, command_elt, session_data, action, node, profile): | 337 def _statusCallback(self, command_elt, session_data, action, node, profile): |
338 """ Ad-hoc command used to change the "show" part of status """ | 338 """ Ad-hoc command used to change the "show" part of status """ |
339 actions = session_data.setdefault('actions',[]) | 339 actions = session_data.setdefault('actions',[]) |
340 actions.append(action) | 340 actions.append(action) |