comparison libervia.py @ 251:24335e82fef0

plugin XEP-249: added parameter Misc / Auto-join MUC on invitation: - also cleaned getOrCreateLiberviaWidget and _chatStateReceivedCb from unused arguments
author souliane <souliane@mailoo.org>
date Tue, 05 Nov 2013 21:12:14 +0100
parents 38e6211d36ca
children cc778206b7ae
comparison
equal deleted inserted replaced
250:38e6211d36ca 251:24335e82fef0
117 "getHistory", "getPresenceStatus", "joinMUC", "mucLeave", "getRoomsJoined", 117 "getHistory", "getPresenceStatus", "joinMUC", "mucLeave", "getRoomsJoined",
118 "launchTarotGame", "getTarotCardsPaths", "tarotGameReady", 118 "launchTarotGame", "getTarotCardsPaths", "tarotGameReady",
119 "tarotGameContratChoosed", "tarotGamePlayCards", "launchRadioCollective", 119 "tarotGameContratChoosed", "tarotGamePlayCards", "launchRadioCollective",
120 "getWaitingSub", "subscription", "delContact", "updateContact", "getCard", 120 "getWaitingSub", "subscription", "delContact", "updateContact", "getCard",
121 "getEntityData", "getParamsUI", "asyncGetParamA", "setParam", "launchAction", 121 "getEntityData", "getParamsUI", "asyncGetParamA", "setParam", "launchAction",
122 "disconnect", "chatStateComposing", "getNewAccountDomain" 122 "disconnect", "chatStateComposing", "getNewAccountDomain", "confirmationAnswer"
123 ]) 123 ])
124 124
125 125
126 class BridgeSignals(LiberviaJsonProxy): 126 class BridgeSignals(LiberviaJsonProxy):
127 RETRY_BASE_DELAY = 1000 127 RETRY_BASE_DELAY = 1000
352 self._roomJoinedCb(*args) 352 self._roomJoinedCb(*args)
353 elif name == 'roomUserJoined': 353 elif name == 'roomUserJoined':
354 self._roomUserJoinedCb(*args) 354 self._roomUserJoinedCb(*args)
355 elif name == 'roomUserLeft': 355 elif name == 'roomUserLeft':
356 self._roomUserLeftCb(*args) 356 self._roomUserLeftCb(*args)
357 elif name == 'askConfirmation':
358 self._askConfirmation(*args)
359 elif name == 'newAlert':
360 self._newAlert(*args)
357 elif name == 'tarotGameStarted': 361 elif name == 'tarotGameStarted':
358 self._tarotGameStartedCb(*args) 362 self._tarotGameStartedCb(*args)
359 elif name == 'tarotGameNew' or \ 363 elif name == 'tarotGameNew' or \
360 name == 'tarotGameChooseContrat' or \ 364 name == 'tarotGameChooseContrat' or \
361 name == 'tarotGameShowCards' or \ 365 name == 'tarotGameShowCards' or \
507 except AttributeError as e: 511 except AttributeError as e:
508 e.stack_list() 512 e.stack_list()
509 return None 513 return None
510 return None 514 return None
511 515
512 def getOrCreateLiberviaWidget(self, class_, entity, add=True, refresh=True, add=True): 516 def getOrCreateLiberviaWidget(self, class_, entity, select=True):
513 """Get the matching LiberviaWidget if it exists, or create a new one. 517 """Get the matching LiberviaWidget if it exists, or create a new one.
514 @param class_: class of the panel (ChatPanel, MicroblogPanel...) 518 @param class_: class of the panel (ChatPanel, MicroblogPanel...)
515 @param entity: polymorphic parameter, see class_.matchEntity. 519 @param entity: polymorphic parameter, see class_.matchEntity.
516 @param refresh: if True, refresh the display of a widget that is found 520 @param select: if True, select the widget that has been found or created
517 (ignored if no widget is found and a new one is created)
518 @param add: if True, add a widget that is created to the selected tab
519 (ignored if a widget is found and no new one is created)
520 @return: the newly created wigdet if REUSE_EXISTING_LIBERVIA_WIDGETS 521 @return: the newly created wigdet if REUSE_EXISTING_LIBERVIA_WIDGETS
521 is set to False or if the widget has not been found, the existing 522 is set to False or if the widget has not been found, the existing
522 widget that has been found otherwise.""" 523 widget that has been found otherwise."""
523 lib_wid = None 524 lib_wid = None
524 if REUSE_EXISTING_LIBERVIA_WIDGETS: 525 if REUSE_EXISTING_LIBERVIA_WIDGETS:
525 lib_wid = self.getLiberviaWidget(class_, entity) 526 lib_wid = self.getLiberviaWidget(class_, entity)
526 if lib_wid is None: 527 if lib_wid is None:
527 lib_wid = class_.createPanel(self, entity) 528 lib_wid = class_.createPanel(self, entity)
528 elif refresh: 529 else:
529 # remove the widget from its previous panel 530 # remove the widget from its previous panel
530 panel = lib_wid.getWidgetsPanel(verbose=False) 531 panel = lib_wid.getWidgetsPanel(verbose=False)
531 if panel is not None: 532 if panel is not None:
532 panel.removeWidget(lib_wid) 533 panel.removeWidget(lib_wid)
533 if add or refresh: 534 self.addWidget(lib_wid)
534 self.addWidget(lib_wid) 535 if select:
535 if refresh:
536 # must be done after the widget is added, 536 # must be done after the widget is added,
537 # for example to scroll to the bottom 537 # for example to scroll to the bottom
538 self.setSelected(lib_wid) 538 self.setSelected(lib_wid)
539 lib_wid.refresh() 539 lib_wid.refresh()
540 return lib_wid 540 return lib_wid
655 for lib_wid in self.libervia_widgets: 655 for lib_wid in self.libervia_widgets:
656 if isinstance(lib_wid, panels.MicroblogPanel): 656 if isinstance(lib_wid, panels.MicroblogPanel):
657 if lib_wid.isJidAccepted(entity_jid_s) or (self.whoami and entity_jid_s == self.whoami.bare): 657 if lib_wid.isJidAccepted(entity_jid_s) or (self.whoami and entity_jid_s == self.whoami.bare):
658 lib_wid.updateValue('avatar', entity_jid_s, avatar) 658 lib_wid.updateValue('avatar', entity_jid_s, avatar)
659 659
660 def _chatStateReceivedCb(self, from_jid_s, state, profile): 660 def _chatStateReceivedCb(self, from_jid_s, state):
661 """Callback when a new chat state is received. 661 """Callback when a new chat state is received.
662 @param from_jid_s: JID from the contact who sent his state 662 @param from_jid_s: JID from the contact who sent his state
663 @param state: new state 663 @param state: new state
664 @profile: current profile
665 """ 664 """
666 _from = JID(from_jid_s).bare if from_jid_s != "@ALL@" else from_jid_s 665 _from = JID(from_jid_s).bare if from_jid_s != "@ALL@" else from_jid_s
667 for lib_wid in self.libervia_widgets: 666 for lib_wid in self.libervia_widgets:
668 if isinstance(lib_wid, panels.ChatPanel): 667 if isinstance(lib_wid, panels.ChatPanel):
669 win_from = lib_wid.target.bare 668 win_from = lib_wid.target.bare
677 lib_wid.state_machine.started = True 676 lib_wid.state_machine.started = True
678 elif (lib_wid.type == 'group'): 677 elif (lib_wid.type == 'group'):
679 # TODO: chat state notification for groupchat 678 # TODO: chat state notification for groupchat
680 pass 679 pass
681 680
681 def _askConfirmation(self, confirmation_id, confirmation_type, data):
682 answer_data = {}
683
684 def confirm_cb(result):
685 self.bridge.call('confirmationAnswer', None, confirmation_id, result, answer_data)
686
687 if confirmation_type == "YES/NO":
688 dialog.ConfirmDialog(confirm_cb, text=data["message"], title=data["title"]).show()
689
690 def _newAlert(self, message, title, alert_type):
691 dialog.InfoDialog(title, message).show()
682 692
683 if __name__ == '__main__': 693 if __name__ == '__main__':
684 pyjd.setup("http://localhost:8080/libervia.html") 694 pyjd.setup("http://localhost:8080/libervia.html")
685 app = SatWebFrontend() 695 app = SatWebFrontend()
686 app.onModuleLoad() 696 app.onModuleLoad()