Mercurial > libervia-backend
changeset 2050:046449cc2bff
core, bridge, frontends: removed deprecated bridge method askConfirmation, confirmationAnswer, actionResult, actionResultExt and getWaitingConf
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 28 Aug 2016 19:23:58 +0200 |
parents | b67aece4a667 |
children | 1dc3c7680ea0 |
files | frontends/src/bridge/DBus.py frontends/src/primitivus/primitivus frontends/src/quick_frontend/quick_app.py src/bridge/DBus.py src/bridge/bridge_constructor/bridge_constructor.py src/bridge/bridge_constructor/bridge_template.ini src/core/sat_main.py src/core/xmpp.py |
diffstat | 8 files changed, 6 insertions(+), 309 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/bridge/DBus.py Sun Aug 28 18:24:45 2016 +0200 +++ b/frontends/src/bridge/DBus.py Sun Aug 28 19:23:58 2016 +0200 @@ -207,20 +207,6 @@ error_handler = lambda err:errback(dbus_to_bridge_exception(err)) return self.db_core_iface.asyncGetParamsValuesFromCategory(category, security_limit, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) - def confirmationAnswer(self, id, accepted, data, profile, callback=None, errback=None): - if callback is None: - error_handler = None - else: - if errback is None: - errback = log.error - error_handler = lambda err:errback(dbus_to_bridge_exception(err)) - kwargs={} - if callback is not None: - kwargs['timeout'] = const_TIMEOUT - kwargs['reply_handler'] = callback - kwargs['error_handler'] = error_handler - return self.db_core_iface.confirmationAnswer(id, accepted, data, profile, **kwargs) - def delContact(self, entity_jid, profile_key="@DEFAULT@", callback=None, errback=None): if callback is None: error_handler = None @@ -480,20 +466,6 @@ kwargs['error_handler'] = error_handler return unicode(self.db_core_iface.getVersion(**kwargs)) - def getWaitingConf(self, profile_key, callback=None, errback=None): - if callback is None: - error_handler = None - else: - if errback is None: - errback = log.error - error_handler = lambda err:errback(dbus_to_bridge_exception(err)) - kwargs={} - if callback is not None: - kwargs['timeout'] = const_TIMEOUT - kwargs['reply_handler'] = callback - kwargs['error_handler'] = error_handler - return self.db_core_iface.getWaitingConf(profile_key, **kwargs) - def getWaitingSub(self, profile_key="@DEFAULT@", callback=None, errback=None): if callback is None: error_handler = None
--- a/frontends/src/primitivus/primitivus Sun Aug 28 18:24:45 2016 +0200 +++ b/frontends/src/primitivus/primitivus Sun Aug 28 19:23:58 2016 +0200 @@ -28,7 +28,6 @@ import urwid from urwid.util import is_wide_char from urwid_satext import sat_widgets -from urwid_satext.files_management import FileDialog from sat_frontends.bridge.DBus import DBusBridgeFrontend from sat_frontends.quick_frontend.quick_app import QuickApp from sat_frontends.quick_frontend import quick_utils @@ -43,7 +42,6 @@ from sat_frontends.primitivus import config from sat_frontends.tools.misc import InputHistory from sat_frontends.tools import jid -from os.path import join import signal import sys @@ -744,78 +742,6 @@ def _actionManagerUnknownError(self): self.alert(_("Error"), _(u"Unmanaged action")) - def askConfirmationHandler(self, confirmation_id, confirmation_type, data, profile): - answer_data = {} - - def dir_selected_cb(path): - dest_path = join(path, data['filename']) - answer_data["dest_path"] = quick_utils.getNewPath(dest_path) - self.addProgress(confirmation_id, dest_path) - accept_cb(None) - - def accept_file_transfer_cb(widget): - self.removePopUp() - pop_up_widget = FileDialog(dir_selected_cb, refuse_cb, title=_(u"Where do you want to save the file ?"), style=['dir']) - self.showPopUp(pop_up_widget) - - def accept_cb(widget): - self.removePopUp() - self.bridge.confirmationAnswer(confirmation_id, True, answer_data, profile) - - def refuse_cb(widget): - self.removePopUp() - self.bridge.confirmationAnswer(confirmation_id, False, answer_data, profile) - - if confirmation_type == "FILE_TRANSFER": - pop_up_widget = sat_widgets.ConfirmDialog(_("The contact %(jid)s wants to send you the file %(filename)s\nDo you accept ?") % {'jid':data["from"], 'filename':data["filename"]}, no_cb=refuse_cb, yes_cb=accept_file_transfer_cb) - self.showPopUp(pop_up_widget) - - elif confirmation_type == "YES/NO": - pop_up_widget = sat_widgets.ConfirmDialog(data["message"], no_cb=refuse_cb, yes_cb=accept_cb) - self.showPopUp(pop_up_widget) - - def actionResultHandler(self, type_, id, data, profile): - # FIXME: to be removed - - if not id in self.current_action_ids: - log.debug (_('unknown id, ignoring')) - return - if type_ == "SUPPRESS": - self.current_action_ids.remove(id) - elif type_ == "XMLUI": - self.current_action_ids.remove(id) - log.debug (_("XML user interface received")) - misc = {} - #FIXME FIXME FIXME: must clean all this crap ! - title = _('Form') - if data['type'] == 'registration': - title = _('Registration') - misc['target'] = data['target'] - misc['action_back'] = self.bridge.gatewayRegister - ui = xmlui.create(self, title=title, xml_data=data['xml'], misc=misc, profile=profile) - if data['type'] == 'registration': - ui.show('popup') - else: - ui.show('window') - elif type_ == "ERROR": - self.current_action_ids.remove(id) - self.alert(_("Error"), unicode(data["message"])) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore - elif type_ == "RESULT": - self.current_action_ids.remove(id) - if self.current_action_ids_cb.has_key(id): - callback = self.current_action_ids_cb[id] - del self.current_action_ids_cb[id] - callback(data) - elif type_ == "DICT_DICT": - self.current_action_ids.remove(id) - if self.current_action_ids_cb.has_key(id): - callback = self.current_action_ids_cb[id] - del self.current_action_ids_cb[id] - callback(data) - else: - log.error (_("FIXME FIXME FIXME: type [%s] not implemented") % type_) - raise NotImplementedError - def roomJoinedHandler(self, room_jid_s, room_nicks, user_nick, subject, profile): super(PrimitivusApp, self).roomJoinedHandler(room_jid_s, room_nicks, user_nick, subject, profile) # if self.selected_widget is None:
--- a/frontends/src/quick_frontend/quick_app.py Sun Aug 28 18:24:45 2016 +0200 +++ b/frontends/src/quick_frontend/quick_app.py Sun Aug 28 19:23:58 2016 +0200 @@ -46,6 +46,8 @@ class ProfileManager(object): """Class managing all data relative to one profile, and plugging in mechanism""" + # TODO: handle waiting XMLUI requests: getWaitingConf doesn't exist anymore + # and a way to keep some XMLUI request between sessions is expected in backend host = None bridge = None cache_keys_to_get = ['avatar'] @@ -136,13 +138,6 @@ self.host.presenceUpdateHandler(jabber_id, show, priority, statuses, self.profile) self.host.bridge.getEntityData(contact, ['avatar', 'nick'], self.profile, callback=lambda data, contact=contact: gotEntityData(data, contact), errback=lambda failure, contact=contact: log.debug(u"No cache data for {}".format(contact))) - #Finaly, we get the waiting confirmation requests - self.bridge.getWaitingConf(self.profile, callback=self._plug_profile_gotWaitingConf) - - def _plug_profile_gotWaitingConf(self, waiting_confs): - for confirm_id, confirm_type, data in waiting_confs: - self.host.askConfirmationHandler(confirm_id, confirm_type, data, self.profile) - # At this point, profile should be fully plugged # and we launch frontend specific method self.host.profilePlugged(self.profile) @@ -238,18 +233,14 @@ self.registerSignal("actionNew") self.registerSignal("newContact") self.registerSignal("messageNew") - self.registerSignal("newAlert") self.registerSignal("presenceUpdate") self.registerSignal("subscribe") self.registerSignal("paramUpdate") self.registerSignal("contactDeleted") self.registerSignal("entityDataUpdated") - self.registerSignal("askConfirmation") - self.registerSignal("actionResult") self.registerSignal("progressStarted") self.registerSignal("progressFinished") self.registerSignal("progressError") - self.registerSignal("actionResultExt", self.actionResultHandler) self.registerSignal("mucRoomJoined", iface="plugin") self.registerSignal("mucRoomLeft", iface="plugin") self.registerSignal("mucRoomUserChangedNick", iface="plugin") @@ -263,8 +254,6 @@ quick_games.Quiz.registerSignals(self) quick_games.Radiocol.registerSignals(self) - self.current_action_ids = set() # FIXME: to be removed - self.current_action_ids_cb = {} # FIXME: to be removed self._notif_id = 0 self._notifications = OrderedDict() self.media_dir = self.bridge.getConfig('', 'media_dir') @@ -485,9 +474,6 @@ # we want to be sure to have at least one QuickChat instance self.widgets.getOrCreateWidget(quick_chat.QuickChat, target, type_=C.CHAT_ONE2ONE, on_new_widget=None, profile=profile) - self.current_action_ids = set() # FIXME: to be removed - self.current_action_ids_cb = {} # FIXME: to be removed - if not from_jid in contact_list and from_jid.bare != self.profiles[profile].whoami.bare: #XXX: needed to show entities which haven't sent any # presence information and which are not in roster @@ -516,10 +502,6 @@ self.bridge.messageSend(unicode(to_jid), message, subject, mess_type, extra, profile_key, callback=callback, errback=errback) - def newAlertHandler(self, msg, title, alert_type, profile): - assert alert_type in ['INFO', 'ERROR'] - self.showDialog(unicode(msg), unicode(title), alert_type.lower()) - def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE): raise NotImplementedError @@ -788,12 +770,6 @@ self.callListeners('avatar', entity, filename, profile=profile) self.bridge.getAvatarFile(value, callback=gotFilename) - def askConfirmationHandler(self, confirm_id, confirm_type, data, profile): - raise NotImplementedError - - def actionResultHandler(self, type, id, data, profile): - raise NotImplementedError - def actionManager(self, action_data, callback=None, ui_show_cb=None, user_action=True, profile=C.PROF_KEY_NONE): """Handle backend action
--- a/src/bridge/DBus.py Sun Aug 28 18:24:45 2016 +0200 +++ b/src/bridge/DBus.py Sun Aug 28 19:23:58 2016 +0200 @@ -131,21 +131,6 @@ pass @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, - signature='ssa{ss}s') - def actionResult(self, answer_type, id, data, profile): - pass - - @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, - signature='ssa{sa{ss}}s') - def actionResultExt(self, answer_type, id, data, profile): - pass - - @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, - signature='ssa{ss}s') - def askConfirmation(self, id, conf_type, data, profile): - pass - - @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, signature='ss') def connected(self, profile, jid_s): pass @@ -171,11 +156,6 @@ pass @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, - signature='ssss') - def newAlert(self, message, title, alert_type, profile): - pass - - @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, signature='sa{ss}ass') def newContact(self, contact_jid, attributes, groups, profile): pass @@ -255,12 +235,6 @@ return self._callback("asyncGetParamsValuesFromCategory", unicode(category), security_limit, unicode(profile_key), callback=callback, errback=errback) @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, - in_signature='sba{ss}s', out_signature='', - async_callbacks=None) - def confirmationAnswer(self, id, accepted, data, profile): - return self._callback("confirmationAnswer", unicode(id), accepted, data, unicode(profile)) - - @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, in_signature='ss', out_signature='', async_callbacks=('callback', 'errback')) def delContact(self, entity_jid, profile_key="@DEFAULT@", callback=None, errback=None): @@ -387,12 +361,6 @@ return self._callback("getVersion", ) @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, - in_signature='s', out_signature='a(ssa{ss})', - async_callbacks=None) - def getWaitingConf(self, profile_key): - return self._callback("getWaitingConf", unicode(profile_key)) - - @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, in_signature='s', out_signature='a{ss}', async_callbacks=None) def getWaitingSub(self, profile_key="@DEFAULT@"): @@ -605,15 +573,6 @@ def actionNew(self, action_data, id, security_limit, profile): self.dbus_bridge.actionNew(action_data, id, security_limit, profile) - def actionResult(self, answer_type, id, data, profile): - self.dbus_bridge.actionResult(answer_type, id, data, profile) - - def actionResultExt(self, answer_type, id, data, profile): - self.dbus_bridge.actionResultExt(answer_type, id, data, profile) - - def askConfirmation(self, id, conf_type, data, profile): - self.dbus_bridge.askConfirmation(id, conf_type, data, profile) - def connected(self, profile, jid_s): self.dbus_bridge.connected(profile, jid_s) @@ -629,9 +588,6 @@ def messageNew(self, uid, timestamp, from_jid, to_jid, message, subject, mess_type, extra, profile): self.dbus_bridge.messageNew(uid, timestamp, from_jid, to_jid, message, subject, mess_type, extra, profile) - def newAlert(self, message, title, alert_type, profile): - self.dbus_bridge.newAlert(message, title, alert_type, profile) - def newContact(self, contact_jid, attributes, groups, profile): self.dbus_bridge.newContact(contact_jid, attributes, groups, profile)
--- a/src/bridge/bridge_constructor/bridge_constructor.py Sun Aug 28 18:24:45 2016 +0200 +++ b/src/bridge/bridge_constructor/bridge_constructor.py Sun Aug 28 19:23:58 2016 +0200 @@ -167,11 +167,13 @@ def getArguments(self, signature, name=None, default=None, unicode_protect=False): """Return arguments to user given a signature + @param signature: signature in the short form (using s,a,i,b etc) @param name: dictionary of arguments name like given by getArguments @param default: dictionary of default values, like given by getDefault @param unicode_protect: activate unicode protection on strings (return strings as unicode(str)) - @return: list of arguments that correspond to a signature (e.g.: "sss" return "arg1, arg2, arg3")""" + @return: list of arguments that correspond to a signature (e.g.: "sss" return "arg1, arg2, arg3") + """ idx = 0 attr_string = [] @@ -276,7 +278,6 @@ for section in sections: function = self.getValues(section) print ("Adding %s %s" % (section, function["type"])) - default = self.getDefault(section) async_msg = """<br />'''This method is asynchronous'''""" deprecated_msg = """<br />'''<font color="#FF0000">/!\ WARNING /!\ : This method is deprecated, please don't use it !</font>'''""" signature_signal = \ @@ -516,7 +517,7 @@ 'a{i(ss)}': 'HistoryT', 'a(sss)': 'QList<MenuT>', 'a{sa{s(sia{ss})}}': 'PresenceStatusT', - 'a{sa{ss}}': 'ActionResultExtDataT'} + } def generateCoreSide(self): try: @@ -536,7 +537,6 @@ print ("Adding %s %s" % (section, function["type"])) new_elt = doc.createElement('method' if function["type"] == 'method' else 'signal') new_elt.setAttribute('name', section) - args_in_str = self.getArguments(function['sig_in']) idx = 0 args_doc = self.getArgumentsDoc(section)
--- a/src/bridge/bridge_constructor/bridge_template.ini Sun Aug 28 18:24:45 2016 +0200 +++ b/src/bridge/bridge_constructor/bridge_template.ini Sun Aug 28 19:23:58 2016 +0200 @@ -54,19 +54,6 @@ - info_type: subtype for info messages doc_param_8=%(doc_profile)s -[newAlert] -deprecated= -type=signal -category=core -sig_in=ssss -doc=A new alert happened -doc_param_0=message: Body of the alert -doc_param_1=title: Title of the alert -doc_param_2=alert_type: Type of the alert, can be: - - INFO: Informative message - - ERROR: something went wrong -doc_param_3=%(doc_profile)s - [presenceUpdate] type=signal category=core @@ -105,19 +92,6 @@ doc_param_0=entity_jid: JID of the contact removed from roster doc_param_1=%(doc_profile)s -[askConfirmation] -deprecated= -type=signal -category=core -sig_in=ssa{ss}s -doc=A confirmation is needed for an action -doc_param_0=id: Id of the confirmation query -doc_param_1=conf_type: Type of the confirmation, can be: - - YES/NO: A question which need a yes or no answer - - FILE_TRANSFER: A confirmation is needed before transfering a file -doc_param_2=data: conf_type dependent data -doc_param_3=%(doc_profile)s - [actionNew] type=signal category=core @@ -138,33 +112,6 @@ doc_param_2=%(doc_security_limit)s doc_param_3=%(doc_profile)s -[actionResult] -deprecated= -type=signal -category=core -sig_in=ssa{ss}s -doc=Requested result of an action -doc_param_0=answer_type: Type of the answer, can be: - - SUPPRESS: The action is managed, the id MUST be removed from queue - - XMLUI: A SàT XMLUI interface is sent - - ERROR: Something went wrong when doing the action - - RESULT: General result, interpretation depend of the action -doc_param_1=id: Id of the action -doc_param_2=data: answer_type specific data -doc_param_3=%(doc_profile)s - -[actionResultExt] -deprecated= -type=signal -category=core -sig_in=ssa{sa{ss}}s -doc=Requested result of an action (Extended) -doc_param_0=answer_type: Same as for [actionResult] but with the following additional one: - - DICT_DICT: As RESULT, but returned as a dictionary of dictionary -doc_param_1=id: Id of the action -doc_param_2=data: answer_type specific data -doc_param_3=%(doc_profile)s - [entityDataUpdated] type=signal category=core @@ -432,16 +379,6 @@ doc_param_0=%(doc_profile_key)s doc_return=Dict where contact JID is the key, and value is the subscription type -[getWaitingConf] -type=method -category=core -sig_in=s -sig_out=a(ssa{ss}) -doc=Get confirmations requests in queue -doc_param_0=%(doc_profile_key)s -doc_return=List of confirmation request data, same as for [askConfirmation] - - [messageSend] async= type=method @@ -667,18 +604,6 @@ doc_param_0=%(doc_profile_key)s doc_return=list of data as for [actionNew] (without the profile) -[confirmationAnswer] -deprecated= -type=method -category=core -sig_in=sba{ss}s -sig_out= -doc=Give answer to a confirmation request -doc_param_0=id: id of the confirmation request -doc_param_1=accepted: True if the action is confirmed -doc_param_2=data: action specific data -doc_param_3=%(doc_profile)s - [progressGet] type=method category=core
--- a/src/core/sat_main.py Sun Aug 28 18:24:45 2016 +0200 +++ b/src/core/sat_main.py Sun Aug 28 19:23:58 2016 +0200 @@ -53,7 +53,6 @@ def __init__(self): self._cb_map = {} # map from callback_id to callbacks self._menus = OrderedDict() # dynamic menus. key: callback_id, value: menu data (dictionnary) - self.__private_data = {} # used for internal callbacks (key = id) FIXME: to be removed self.initialised = defer.Deferred() self.profiles = {} self.plugins = {} @@ -85,7 +84,6 @@ self.bridge.register("getMainResource", self.memory._getMainResource) self.bridge.register("getPresenceStatuses", self.memory._getPresenceStatuses) self.bridge.register("getWaitingSub", self.memory.getWaitingSub) - self.bridge.register("getWaitingConf", self.getWaitingConf) self.bridge.register("messageSend", self._messageSend) self.bridge.register("getConfig", self._getConfig) self.bridge.register("setParam", self.setParam) @@ -104,7 +102,6 @@ self.bridge.register("isConnected", self.isConnected) self.bridge.register("launchAction", self.launchCallback) self.bridge.register("actionsGet", self.actionsGet) - self.bridge.register("confirmationAnswer", self.confirmationAnswer) self.bridge.register("progressGet", self._progressGet) self.bridge.register("progressGetAll", self._progressGetAll) self.bridge.register("getMenus", self.getMenus) @@ -519,15 +516,6 @@ ## XMPP methods ## - def getWaitingConf(self, profile_key=None): - assert profile_key - client = self.getClient(profile_key) - ret = [] - for conf_id in client._waiting_conf: - conf_type, data = client._waiting_conf[conf_id][:2] - ret.append((conf_id, conf_type, data)) - return ret - def generateMessageXML(self, data): """Generate <message/> stanza from message data @@ -796,51 +784,6 @@ ## Generic HMI ## - def actionResult(self, action_id, action_type, data, profile): - """Send the result of an action - @param action_id: same action_id used with action - @param action_type: result action_type ("PARAM", "SUCCESS", "ERROR", "XMLUI") - @param data: dictionary - """ - self.bridge.actionResult(action_type, action_id, data, profile) - - def actionResultExt(self, action_id, action_type, data, profile): - """Send the result of an action, extended version - @param action_id: same action_id used with action - @param action_type: result action_type /!\ only "DICT_DICT" for this method - @param data: dictionary of dictionaries - """ - if action_type != "DICT_DICT": - log.error(_("action_type for actionResultExt must be DICT_DICT, fixing it")) - action_type = "DICT_DICT" - self.bridge.actionResultExt(action_type, action_id, data, profile) - - def askConfirmation(self, conf_id, conf_type, data, cb, profile): - """Add a confirmation callback - @param conf_id: conf_id used to get answer - @param conf_type: confirmation conf_type ("YES/NO", "FILE_TRANSFER") - @param data: data (depend of confirmation conf_type) - @param cb: callback called with the answer - """ - # FIXME: use XMLUI and *callback methods for dialog - client = self.getClient(profile) - if conf_id in client._waiting_conf: - log.error(_("Attempt to register two callbacks for the same confirmation")) - else: - client._waiting_conf[conf_id] = (conf_type, data, cb) - self.bridge.askConfirmation(conf_id, conf_type, data, profile) - - def confirmationAnswer(self, conf_id, accepted, data, profile): - """Called by frontends to answer confirmation requests""" - client = self.getClient(profile) - log.debug(_(u"Received confirmation answer for conf_id [%(conf_id)s]: %(success)s") % {'conf_id': conf_id, 'success': _("accepted") if accepted else _("refused")}) - if conf_id not in client._waiting_conf: - log.error(_(u"Received an unknown confirmation (%(id)s for %(profile)s)") % {'id': conf_id, 'profile': profile}) - else: - cb = client._waiting_conf[conf_id][-1] - del client._waiting_conf[conf_id] - cb(conf_id, accepted, data, profile) - def _killAction(self, keep_id, client): log.debug(u"Killing action {} for timeout".format(keep_id)) client.actions[keep_id]
--- a/src/core/xmpp.py Sun Aug 28 18:24:45 2016 +0200 +++ b/src/core/xmpp.py Sun Aug 28 19:23:58 2016 +0200 @@ -50,7 +50,6 @@ self.host_app = host_app self._mess_id_uid = {} # map from message id to uid use in history. Key: (full_jid,message_id) Value: uid self.conn_deferred = defer.Deferred() - self._waiting_conf = {} # callback called when a confirmation is received self._progress_cb = {} # callback called when a progress is requested (key = progress id) self.actions = {} # used to keep track of actions for retrieval (key = action_id)