core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
- added profile argument to askConfirmation, actionResult, actionResultExt, entityDataUpdated, confirmationAnswer, getProgress
- core, frontends: fixed calls/signals according to new bridge API
- user of proper profile namespace for progression indicators and dialogs
- memory: getParam* now return bool when param type is bool
- memory: added getStringParam* to return string instead of typed value
- core, memory, storage, quick_frontend: getHistory now manage properly multi-profiles
- plugins XEP-0047, XEP-0054, XEP-0065, XEP-0077, XEP-0096; multi-profiles proper handling
This commit is contained in:
parent
49437fd9c3
commit
fa38394401
1 changed files with 570 additions and 400 deletions
|
|
@ -227,6 +227,28 @@ class Params():
|
|||
d.addCallback(self.__default_ok, name, category)
|
||||
d.addErrback(errback or self.__default_ko, name, category)
|
||||
|
||||
def __getAttr(self, node, attr, value):
|
||||
""" get attribute value
|
||||
@param node: XML param node
|
||||
@param attr: name of the attribute to get (e.g.: 'value' or 'type')
|
||||
@param value: user defined value"""
|
||||
if attr == 'value':
|
||||
value_to_use = value if value!=None else node.getAttribute(attr) #we use value (user defined) if it exist, else we use node's default value
|
||||
if node.getAttribute('type') == 'bool':
|
||||
return value_to_use.lower() not in ('false','0')
|
||||
return value_to_use
|
||||
return node.getAttribute(attr)
|
||||
|
||||
def __type_to_string(self, result):
|
||||
""" convert result to string, according to its type """
|
||||
if isinstance(result,bool):
|
||||
return "true" if result else "false"
|
||||
return result
|
||||
|
||||
def getStringParamA(self, name, category, attr="value", profile_key="@DEFAULT@"):
|
||||
""" Same as getParamA but for bridge: convert non string value to string """
|
||||
return self.__type_to_string(self.getParamA(name, category, attr, profile_key))
|
||||
|
||||
def getParamA(self, name, category, attr="value", profile_key="@DEFAULT@"):
|
||||
"""Helper method to get a specific attribute
|
||||
@param name: name of the parameter
|
||||
|
|
@ -235,31 +257,35 @@ class Params():
|
|||
@param profile: owner of the param (@ALL@ for everyone)
|
||||
|
||||
@return: attribute"""
|
||||
#FIXME: looks really dirty and buggy, need to be reviewed/refactored
|
||||
node = self.__getParamNode(name, category)
|
||||
if not node:
|
||||
error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name':name, 'category':category})
|
||||
return ""
|
||||
raise exceptions.NotFound
|
||||
|
||||
if node[0] == 'general':
|
||||
value = self.__getParam(None, category, name, 'general')
|
||||
return value if value!=None else node[1].getAttribute(attr)
|
||||
return self.__getAttr(node[1], attr, value)
|
||||
|
||||
assert(node[0] == 'individual')
|
||||
|
||||
profile = self.getProfileName(profile_key)
|
||||
if not profile:
|
||||
error(_('Requesting a param for an non-existant profile'))
|
||||
return ""
|
||||
raise exceptions.ProfileUnknownError
|
||||
|
||||
if profile not in self.params:
|
||||
error(_('Requesting synchronous param for not connected profile'))
|
||||
return ""
|
||||
raise exceptions.ConnectedProfileError
|
||||
|
||||
if attr == "value":
|
||||
value = self.__getParam(profile, category, name)
|
||||
return value if value!=None else node[1].getAttribute(attr)
|
||||
else:
|
||||
return node[1].getAttribute(attr)
|
||||
return self.__getAttr(node[1], attr, value)
|
||||
|
||||
def asyncGetStringParamA(self, name, category, attr="value", profile_key="@DEFAULT@"):
|
||||
d = self.asyncGetParamA(name, category, attr, profile_key)
|
||||
d.addCallback(self.__type_to_string)
|
||||
return d
|
||||
|
||||
def asyncGetParamA(self, name, category, attr="value", profile_key="@DEFAULT@"):
|
||||
"""Helper method to get a specific attribute
|
||||
|
|
@ -274,7 +300,7 @@ class Params():
|
|||
|
||||
if node[0] == 'general':
|
||||
value = self.__getParam(None, category, name, 'general')
|
||||
return defer.succeed(value if value!=None else node[1].getAttribute(attr))
|
||||
return defer.succeed(self.__getAttr(node[1], attr, value))
|
||||
|
||||
assert(node[0] == 'individual')
|
||||
|
||||
|
|
@ -285,21 +311,20 @@ class Params():
|
|||
|
||||
if attr != "value":
|
||||
return defer.succeed(node[1].getAttribute(attr))
|
||||
default = node[1].getAttribute(attr)
|
||||
try:
|
||||
value = self.__getParam(profile, category, name)
|
||||
return defer.succeed(value if value!=None else default)
|
||||
return defer.succeed(self.__getAttr(node[1], attr, value))
|
||||
except exceptions.ProfileNotInCacheError:
|
||||
#We have to ask data to the storage manager
|
||||
d = self.storage.getIndParam(category, name, profile)
|
||||
return d.addCallback(lambda value: value if value!=None else default)
|
||||
return d.addCallback(lambda value: self.__getAttr(node[1], attr, value))
|
||||
|
||||
def __getParam(self, profile, category, name, _type='individual', cache=None):
|
||||
"""Return the param, or None if it doesn't exist
|
||||
@param profile: the profile name (not profile key, i.e. name and not something like @DEFAULT@)
|
||||
@param category: param category
|
||||
@param name: param name
|
||||
@param type: "general" or "individual"
|
||||
@param _type: "general" or "individual"
|
||||
@param cache: temporary cache, to use when profile is not logged
|
||||
@return: param value or None if it doesn't exist
|
||||
"""
|
||||
|
|
@ -614,8 +639,9 @@ class Memory:
|
|||
assert(profile!="@NONE@")
|
||||
return self.storage.addToHistory(from_jid, to_jid, message, _type, timestamp, profile)
|
||||
|
||||
def getHistory(self, from_jid, to_jid, limit=0, between=True):
|
||||
return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between)
|
||||
def getHistory(self, from_jid, to_jid, limit=0, between=True, profile="@NONE@"):
|
||||
assert(profile != "@NONE@")
|
||||
return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, profile)
|
||||
|
||||
def addServerFeature(self, feature, profile):
|
||||
"""Add a feature discovered from server
|
||||
|
|
@ -788,11 +814,14 @@ class Memory:
|
|||
|
||||
return self.subscriptions[profile]
|
||||
|
||||
def getStringParamA(self, name, category, attr="value", profile_key='@DEFAULT@'):
|
||||
return self.params.getStringParamA(name, category, attr, profile_key)
|
||||
|
||||
def getParamA(self, name, category, attr="value", profile_key='@DEFAULT@'):
|
||||
return self.params.getParamA(name, category, attr, profile_key)
|
||||
|
||||
def asyncGetParamA(self, name, category, attr="value", profile_key='@DEFAULT@'):
|
||||
return self.params.asyncGetParamA(name, category, attr, profile_key)
|
||||
def asyncGetStringParamA(self, name, category, attr="value", profile_key='@DEFAULT@'):
|
||||
return self.params.asyncGetStringParamA(name, category, attr, profile_key)
|
||||
|
||||
def getParamsUI(self, profile_key):
|
||||
return self.params.getParamsUI(profile_key)
|
||||
|
|
|
|||
Loading…
Reference in a new issue