comparison frontends/src/quick_frontend/quick_contact_list.py @ 1334:15e177584d82 frontends_multi_profiles

quick frontends(contact list): added a getFullJid method to add resource to a bare jid
author Goffi <goffi@goffi.org>
date Mon, 23 Feb 2015 18:04:25 +0100
parents 7c2289090b9b
children f29beedb33b0
comparison
equal deleted inserted replaced
1333:7c2289090b9b 1334:15e177584d82
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from sat.core.log import getLogger 21 from sat.core.log import getLogger
22 log = getLogger(__name__) 22 log = getLogger(__name__)
23 from sat_frontends.quick_frontend.quick_widgets import QuickWidget 23 from sat_frontends.quick_frontend.quick_widgets import QuickWidget
24 from sat_frontends.quick_frontend.constants import Const as C 24 from sat_frontends.quick_frontend.constants import Const as C
25 from sat_frontends.tools import jid
25 26
26 27
27 try: 28 try:
28 # FIXME: to be removed when an acceptable solution is here 29 # FIXME: to be removed when an acceptable solution is here
29 unicode('') # XXX: unicode doesn't exist in pyjamas 30 unicode('') # XXX: unicode doesn't exist in pyjamas
131 @param entity(entity.entity): entity of the contact from who we want data (resource is used if given) 132 @param entity(entity.entity): entity of the contact from who we want data (resource is used if given)
132 if a resource specific information is requested: 133 if a resource specific information is requested:
133 - if no resource is given (bare jid), the main resource is used, according to priority 134 - if no resource is given (bare jid), the main resource is used, according to priority
134 - if resource is given, it is used 135 - if resource is given, it is used
135 @param name(unicode): name the data to get, or None to get everything 136 @param name(unicode): name the data to get, or None to get everything
137 @return: full cache if no name is given, or value of "name", or None
136 """ 138 """
137 try: 139 try:
138 cache = self._cache[entity.bare] 140 cache = self._cache[entity.bare]
139 except KeyError: 141 except KeyError:
140 self.setContact(entity) 142 self.setContact(entity)
164 166
165 @param entity(JID): entity to update 167 @param entity(JID): entity to update
166 @param name(unicode): value to set or update 168 @param name(unicode): value to set or update
167 """ 169 """
168 self.setContact(entity, None, {name: value}) 170 self.setContact(entity, None, {name: value})
171
172 def getFullJid(self, entity):
173 """Get full jid from a bare jid
174
175 @param entity(jid.JID): must be a bare jid
176 @return (jid.JID): bare jid + main resource
177 @raise ValueError: the entity is not bare
178 """
179 if entity.resource:
180 raise ValueError("getFullJid must be used with a bare jid")
181 main_resource = self.getCache(entity, C.CONTACT_MAIN_RESOURCE)
182 return jid.JID(u"{}/{}".format(entity, main_resource))
183
169 184
170 def setGroupData(self, group, name, value): 185 def setGroupData(self, group, name, value):
171 """Register a data for a group 186 """Register a data for a group
172 187
173 @param group: a valid (existing) group name 188 @param group: a valid (existing) group name