changeset 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 2c6c93438f74
files frontends/src/quick_frontend/quick_contact_list.py
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_contact_list.py	Mon Feb 23 18:04:16 2015 +0100
+++ b/frontends/src/quick_frontend/quick_contact_list.py	Mon Feb 23 18:04:25 2015 +0100
@@ -22,6 +22,7 @@
 log = getLogger(__name__)
 from sat_frontends.quick_frontend.quick_widgets import QuickWidget
 from sat_frontends.quick_frontend.constants import Const as C
+from sat_frontends.tools import jid
 
 
 try:
@@ -133,6 +134,7 @@
                 - if no resource is given (bare jid), the main resource is used, according to priority
                 - if resource is given, it is used
         @param name(unicode): name the data to get, or None to get everything
+        @return: full cache if no name is given, or value of "name", or None
         """
         try:
             cache = self._cache[entity.bare]
@@ -167,6 +169,19 @@
         """
         self.setContact(entity, None, {name: value})
 
+    def getFullJid(self, entity):
+        """Get full jid from a bare jid
+
+        @param entity(jid.JID): must be a bare jid
+        @return (jid.JID): bare jid + main resource
+        @raise ValueError: the entity is not bare
+        """
+        if entity.resource:
+            raise ValueError("getFullJid must be used with a bare jid")
+        main_resource = self.getCache(entity, C.CONTACT_MAIN_RESOURCE)
+        return jid.JID(u"{}/{}".format(entity, main_resource))
+
+
     def setGroupData(self, group, name, value):
         """Register a data for a group