Mercurial > libervia-backend
changeset 1468:731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 18 Aug 2015 09:01:18 +0200 |
parents | ceba6fd77739 |
children | b233274e9a0f |
files | frontends/src/primitivus/primitivus frontends/src/quick_frontend/quick_app.py src/plugins/plugin_misc_static_blog.py |
diffstat | 3 files changed, 52 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/primitivus/primitivus Tue Aug 18 09:01:18 2015 +0200 +++ b/frontends/src/primitivus/primitivus Tue Aug 18 09:01:18 2015 +0200 @@ -280,7 +280,7 @@ class PrimitivusApp(QuickApp, InputHistory): def __init__(self): - QuickApp.__init__(self, create_bridge=DBusBridgeFrontend, check_options=quick_utils.check_options) + QuickApp.__init__(self, create_bridge=DBusBridgeFrontend, xmlui=xmlui, check_options=quick_utils.check_options) ## main loop setup ## self.main_widget = ProfileManager(self) @@ -583,6 +583,13 @@ log.error(_('unmanaged dialog type: %s'), type_) self.showPopUp(popup) + def dialogFailure(self, failure): + """Show a failure that has been returned by an asynchronous bridge method. + + @param failure (defer.Failure): Failure instance + """ + self.showPopUp(sat_widgets.Alert(failure.classname, failure.message, ok_cb=self.removePopUp)) + def onNotification(self, notif_bar): """Called when a new notification has been received""" if not isinstance(self.main_widget, PrimitivusTopWidget): @@ -594,43 +601,8 @@ else: self.main_widget.show('notif_bar') - def launchAction(self, callback_id, data=None, callback=None, profile=C.PROF_KEY_NONE): - """ 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 - @param profile: %(doc_profile)s - - """ - if data is None: - data = dict() - - def action_cb(data): - if not data: - # action was a one shot, nothing to do - pass - elif "xmlui" in data: - ui = xmlui.create(self, xml_data=data['xmlui'], callback=callback, profile=profile) - ui.show() - elif 'validated' in data: - pass # this key is managed below - else: - self.showPopUp(sat_widgets.Alert(_("Error"), _(u"Unmanaged action result"), ok_cb=self.removePopUp)) - - if callback and 'validated' in data: - callback(callback_id, data, profile) - - self.bridge.launchAction(callback_id, data, profile, callback=action_cb, errback=self.showFailure) - - def showFailure(self, failure): - """Show a failure that has been returned by an asynchronous bridge method. - - @param failure (defer.Failure): Failure instance - """ - self.showPopUp(sat_widgets.Alert(failure.classname, failure.message, ok_cb=self.removePopUp)) + def _actionManagerUnknownError(self): + self.showPopUp(sat_widgets.Alert(_("Error"), _(u"Unmanaged action"), ok_cb=self.removePopUp)) def askConfirmationHandler(self, confirmation_id, confirmation_type, data, profile): answer_data = {} @@ -715,7 +687,7 @@ def onJoinRoom(self, button, edit): self.removePopUp() room_jid = jid.JID(edit.get_edit_text()) - self.bridge.joinMUC(room_jid, self.profiles[self.current_profile].whoami.node, {}, self.current_profile, callback=lambda dummy: None, errback=self.showFailure) + self.bridge.joinMUC(room_jid, self.profiles[self.current_profile].whoami.node, {}, self.current_profile, callback=lambda dummy: None, errback=self._notifyFailure) #MENU EVENTS# def onConnectRequest(self, menu):
--- a/frontends/src/quick_frontend/quick_app.py Tue Aug 18 09:01:18 2015 +0200 +++ b/frontends/src/quick_frontend/quick_app.py Tue Aug 18 09:01:18 2015 +0200 @@ -199,12 +199,14 @@ """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 @@ 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 @@ 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 @@ 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 @@ 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")
--- a/src/plugins/plugin_misc_static_blog.py Tue Aug 18 09:01:18 2015 +0200 +++ b/src/plugins/plugin_misc_static_blog.py Tue Aug 18 09:01:18 2015 +0200 @@ -83,6 +83,8 @@ @param profile: %(doc_profile)s @return: dict """ + # FIXME: "public_blog" key has been removed + # TODO: replace this with a more generic widget call with URIs try: user_jid = jid.JID(menu_data['jid']) except KeyError: