comparison frontends/src/quick_frontend/quick_app.py @ 1318:6c7d89843f1b frontends_multi_profiles

frontends (quick frontend): use of new getEntitiesData to get cached values for avatars on profile connection.
author Goffi <goffi@goffi.org>
date Mon, 09 Feb 2015 21:39:51 +0100
parents faa1129559b8
children 781ee3539252
comparison
equal deleted inserted replaced
1317:bd69d341d969 1318:6c7d89843f1b
31 31
32 class ProfileManager(object): 32 class ProfileManager(object):
33 """Class managing all data relative to one profile, and plugging in mechanism""" 33 """Class managing all data relative to one profile, and plugging in mechanism"""
34 host = None 34 host = None
35 bridge = None 35 bridge = None
36 cache_keys_to_get = ['avatar']
36 37
37 def __init__(self, profile): 38 def __init__(self, profile):
38 self.profile = profile 39 self.profile = profile
39 self.whoami = None 40 self.whoami = None
40 self.data = {} 41 self.data = {}
63 else: 64 else:
64 self._plug_profile_afterconnect() 65 self._plug_profile_afterconnect()
65 66
66 def _plug_profile_afterconnect(self): 67 def _plug_profile_afterconnect(self):
67 # Profile can be connected or not 68 # Profile can be connected or not
69 # we get cached data
70 self.host.bridge.getEntitiesData([], ProfileManager.cache_keys_to_get, profile=self.profile, callback=self._plug_profile_gotCachedValues, errback=self._plug_profile_failedCachedValues)
71
72 def _plug_profile_failedCachedValues(self, failure):
73 log.error("Couldn't get cached values: {}".format(failure))
74 self._plug_profile_gotCachedValues({})
75
76 def _plug_profile_gotCachedValues(self, cached_values):
68 # TODO: watched plugin 77 # TODO: watched plugin
69 contact_list = self.host.addContactList(self.profile) 78 contact_list = self.host.addContactList(self.profile)
79
80 for entity, data in cached_values.iteritems():
81 for key, value in data.iteritems():
82 self.host.contact_lists[self.profile].setCache(jid.JID(entity), key, value)
70 83
71 if not self.bridge.isConnected(self.profile): 84 if not self.bridge.isConnected(self.profile):
72 self.host.setStatusOnline(False, profile=self.profile) 85 self.host.setStatusOnline(False, profile=self.profile)
73 else: 86 else:
74 self.host.setStatusOnline(True, profile=self.profile) 87 self.host.setStatusOnline(True, profile=self.profile)