comparison frontends/src/quick_frontend/quick_app.py @ 1468:731fbed0b9cf

quick_frontend, primitivus: handling of actionNew signal
author Goffi <goffi@goffi.org>
date Tue, 18 Aug 2015 09:01:18 +0200
parents 9fce331ba0fd
children 621b045cd284
comparison
equal deleted inserted replaced
1467:ceba6fd77739 1468:731fbed0b9cf
197 197
198 class QuickApp(object): 198 class QuickApp(object):
199 """This class contain the main methods needed for the frontend""" 199 """This class contain the main methods needed for the frontend"""
200 MB_HANDLE = True # Set to false if the frontend doesn't manage microblog 200 MB_HANDLE = True # Set to false if the frontend doesn't manage microblog
201 201
202 def __init__(self, create_bridge, check_options=None): 202 def __init__(self, create_bridge, xmlui, check_options=None):
203 """Create a frontend application 203 """Create a frontend application
204 204
205 @param create_bridge: method to use to create the Bridge 205 @param create_bridge: method to use to create the Bridge
206 @param xmlui: xmlui module
206 @param check_options: method to call to check options (usually command line arguments) 207 @param check_options: method to call to check options (usually command line arguments)
207 """ 208 """
209 self.xmlui = xmlui
208 self.menus = quick_menus.QuickMenusManager(self) 210 self.menus = quick_menus.QuickMenusManager(self)
209 ProfileManager.host = self 211 ProfileManager.host = self
210 self.profiles = ProfilesManager() 212 self.profiles = ProfilesManager()
211 self.ready_profiles = set() # profiles which are connected and ready 213 self.ready_profiles = set() # profiles which are connected and ready
212 self.signals_cache = {} # used to keep signal received between start of plug_profile and when the profile is actualy ready 214 self.signals_cache = {} # used to keep signal received between start of plug_profile and when the profile is actualy ready
236 print(_(u"Can't init bridge")) 238 print(_(u"Can't init bridge"))
237 sys.exit(1) 239 sys.exit(1)
238 ProfileManager.bridge = self.bridge 240 ProfileManager.bridge = self.bridge
239 self.registerSignal("connected") 241 self.registerSignal("connected")
240 self.registerSignal("disconnected") 242 self.registerSignal("disconnected")
243 self.registerSignal("actionNew")
241 self.registerSignal("newContact") 244 self.registerSignal("newContact")
242 self.registerSignal("newMessage") 245 self.registerSignal("newMessage")
243 self.registerSignal("newAlert") 246 self.registerSignal("newAlert")
244 self.registerSignal("presenceUpdate") 247 self.registerSignal("presenceUpdate")
245 self.registerSignal("subscribe") 248 self.registerSignal("subscribe")
461 """called when the connection is closed""" 464 """called when the connection is closed"""
462 log.debug(_("Disconnected")) 465 log.debug(_("Disconnected"))
463 self.contact_lists[profile].clearContacts() 466 self.contact_lists[profile].clearContacts()
464 self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=profile) 467 self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=profile)
465 468
469 def actionNewHandler(self, action_data, id_, profile):
470 self._actionManager(action_data, profile=profile)
471
466 def newContactHandler(self, jid_s, attributes, groups, profile): 472 def newContactHandler(self, jid_s, attributes, groups, profile):
467 entity = jid.JID(jid_s) 473 entity = jid.JID(jid_s)
468 _groups = list(groups) 474 _groups = list(groups)
469 self.contact_lists[profile].setContact(entity, _groups, attributes, in_roster=True) 475 self.contact_lists[profile].setContact(entity, _groups, attributes, in_roster=True)
470 476
670 raise NotImplementedError 676 raise NotImplementedError
671 677
672 def showAlert(self, message): 678 def showAlert(self, message):
673 pass #FIXME 679 pass #FIXME
674 680
681 def dialogFailure(self, failure):
682 log.warning(u"Failure: {}".format(failure))
683
675 def updateAlertsCounter(self): 684 def updateAlertsCounter(self):
676 """Update the over whole alerts counter 685 """Update the over whole alerts counter
677 686
678 """ 687 """
679 pass 688 pass
711 raise NotImplementedError 720 raise NotImplementedError
712 721
713 def actionResultHandler(self, type, id, data, profile): 722 def actionResultHandler(self, type, id, data, profile):
714 raise NotImplementedError 723 raise NotImplementedError
715 724
725 def _actionManagerUnknownError(self):
726 raise NotImplementedError
727
728
729 def _actionManager(self, action_data, callback=None, profile=C.PROF_KEY_NONE):
730 if "xmlui" in action_data:
731 ui = self.xmlui.create(self, xml_data=action_data['xmlui'], callback=callback, profile=profile)
732 ui.show()
733 else:
734 self._actionManagerUnknownError()
735
716 def launchAction(self, callback_id, data=None, callback=None, profile=C.PROF_KEY_NONE): 736 def launchAction(self, callback_id, data=None, callback=None, profile=C.PROF_KEY_NONE):
717 """Launch a dynamic action 737 """ Launch a dynamic action
738
718 @param callback_id: id of the action to launch 739 @param callback_id: id of the action to launch
719 @param data: data needed only for certain actions 740 @param data: data needed only for certain actions
720 @param callback: if not None and 'validated' key is present, it will be called with the following parameters: 741 @param callback: if not None and 'validated' key is present, it will be called with the following parameters:
721 - callback_id 742 - callback_id
722 - data 743 - data
723 - profile_key 744 - profile
724 @param profile_key: %(doc_profile)s 745 @param profile: %(doc_profile)s
725 746
726 """ 747 """
727 raise NotImplementedError 748 if data is None:
749 data = dict()
750
751 def action_cb(data):
752 if not data:
753 # action was a one shot, nothing to do
754 pass
755 elif 'validated' in data:
756 if callback:
757 callback(callback_id, data, profile)
758 else:
759 self._actionManager(data, profile=profile)
760
761 self.bridge.launchAction(callback_id, data, profile, callback=action_cb, errback=self.dialogFailure)
728 762
729 def disconnect(self, profile): 763 def disconnect(self, profile):
730 log.info("disconnecting") 764 log.info("disconnecting")
731 self.callListeners('disconnect', profile=profile) 765 self.callListeners('disconnect', profile=profile)
732 self.bridge.disconnect(profile) 766 self.bridge.disconnect(profile)