quick_frontend, primitivus: handling of actionNew signal

This commit is contained in:
Goffi 2015-08-18 09:01:18 +02:00
commit 3312c3bf97

View file

@ -199,12 +199,14 @@ class QuickApp(object):
"""This class contain the main methods needed for the frontend"""
MB_HANDLE = True # Set to false if the frontend doesn't manage microblog
def __init__(self, create_bridge, check_options=None):
def __init__(self, create_bridge, xmlui, check_options=None):
"""Create a frontend application
@param create_bridge: method to use to create the Bridge
@param xmlui: xmlui module
@param check_options: method to call to check options (usually command line arguments)
"""
self.xmlui = xmlui
self.menus = quick_menus.QuickMenusManager(self)
ProfileManager.host = self
self.profiles = ProfilesManager()
@ -238,6 +240,7 @@ class QuickApp(object):
ProfileManager.bridge = self.bridge
self.registerSignal("connected")
self.registerSignal("disconnected")
self.registerSignal("actionNew")
self.registerSignal("newContact")
self.registerSignal("newMessage")
self.registerSignal("newAlert")
@ -463,6 +466,9 @@ class QuickApp(object):
self.contact_lists[profile].clearContacts()
self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=profile)
def actionNewHandler(self, action_data, id_, profile):
self._actionManager(action_data, profile=profile)
def newContactHandler(self, jid_s, attributes, groups, profile):
entity = jid.JID(jid_s)
_groups = list(groups)
@ -672,6 +678,9 @@ class QuickApp(object):
def showAlert(self, message):
pass #FIXME
def dialogFailure(self, failure):
log.warning(u"Failure: {}".format(failure))
def updateAlertsCounter(self):
"""Update the over whole alerts counter
@ -713,18 +722,43 @@ class QuickApp(object):
def actionResultHandler(self, type, id, data, profile):
raise NotImplementedError
def _actionManagerUnknownError(self):
raise NotImplementedError
def _actionManager(self, action_data, callback=None, profile=C.PROF_KEY_NONE):
if "xmlui" in action_data:
ui = self.xmlui.create(self, xml_data=action_data['xmlui'], callback=callback, profile=profile)
ui.show()
else:
self._actionManagerUnknownError()
def launchAction(self, callback_id, data=None, callback=None, profile=C.PROF_KEY_NONE):
"""Launch a dynamic action
""" Launch a dynamic action
@param callback_id: id of the action to launch
@param data: data needed only for certain actions
@param callback: if not None and 'validated' key is present, it will be called with the following parameters:
- callback_id
- data
- profile_key
@param profile_key: %(doc_profile)s
- profile
@param profile: %(doc_profile)s
"""
raise NotImplementedError
if data is None:
data = dict()
def action_cb(data):
if not data:
# action was a one shot, nothing to do
pass
elif 'validated' in data:
if callback:
callback(callback_id, data, profile)
else:
self._actionManager(data, profile=profile)
self.bridge.launchAction(callback_id, data, profile, callback=action_cb, errback=self.dialogFailure)
def disconnect(self, profile):
log.info("disconnecting")