asynchroneous fetches of photos and profile
This commit is contained in:
parent
d0bc9abc7d
commit
b56616f7dd
2 changed files with 38 additions and 6 deletions
|
|
@ -127,9 +127,29 @@ class ContactProfile(QWidget):
|
||||||
self.weboob = weboob
|
self.weboob = weboob
|
||||||
self.contact = contact
|
self.contact = contact
|
||||||
|
|
||||||
|
self.gotProfile(contact.backend, contact)
|
||||||
|
|
||||||
|
self.process_contact = QtDo(self.weboob, self.gotProfile)
|
||||||
|
self.process_contact.do('fillobj', self.contact, ['photos', 'profile'], backends=self.contact.backend)
|
||||||
|
|
||||||
|
def gotProfile(self, backend, contact):
|
||||||
|
if not backend:
|
||||||
|
return
|
||||||
|
|
||||||
|
first = True
|
||||||
|
for photo in contact.photos.itervalues():
|
||||||
|
photo = contact.photos.values()[0]
|
||||||
|
if first:
|
||||||
|
img = QImage.fromData(photo.data)
|
||||||
|
self.ui.photoLabel.setPixmap(QPixmap.fromImage(img))
|
||||||
|
else:
|
||||||
|
# TODO display thumbnails
|
||||||
|
pass
|
||||||
|
first = False
|
||||||
|
|
||||||
self.ui.nicknameLabel.setText('<h1>%s</h1>' % contact.name)
|
self.ui.nicknameLabel.setText('<h1>%s</h1>' % contact.name)
|
||||||
self.ui.statusLabel.setText('%s' % contact.status_msg)
|
self.ui.statusLabel.setText('%s' % contact.status_msg)
|
||||||
self.ui.descriptionEdit.setText('<h1>Description</h1><p>%s</p>' % contact.summary)
|
self.ui.descriptionEdit.setText('<h1>Description</h1><p>%s</p>' % (contact.summary.replace('\n', '<br />') or '<i>Receiving...</i>'))
|
||||||
|
|
||||||
class IGroup(object):
|
class IGroup(object):
|
||||||
def __init__(self, weboob, id, name):
|
def __init__(self, weboob, id, name):
|
||||||
|
|
@ -190,12 +210,22 @@ class ContactsWidget(QWidget):
|
||||||
group = self.ui.groupBox.itemData(i).toPyObject()
|
group = self.ui.groupBox.itemData(i).toPyObject()
|
||||||
group.iter_contacts(self.addContact)
|
group.iter_contacts(self.addContact)
|
||||||
|
|
||||||
def addContact(self, contact):
|
def setPhoto(self, contact, item):
|
||||||
if not contact:
|
if not contact:
|
||||||
return
|
return
|
||||||
|
|
||||||
data = urllib2.urlopen(contact.thumbnail_url).read()
|
img = None
|
||||||
img = QImage.fromData(data)
|
for photo in contact.photos.itervalues():
|
||||||
|
if photo.thumbnail_data:
|
||||||
|
img = QImage.fromData(photo.thumbnail_data)
|
||||||
|
break
|
||||||
|
|
||||||
|
if img:
|
||||||
|
item.setIcon(QIcon(QPixmap.fromImage(img)))
|
||||||
|
|
||||||
|
def addContact(self, contact):
|
||||||
|
if not contact:
|
||||||
|
return
|
||||||
|
|
||||||
status = ''
|
status = ''
|
||||||
if contact.status == Contact.STATUS_ONLINE:
|
if contact.status == Contact.STATUS_ONLINE:
|
||||||
|
|
@ -216,9 +246,11 @@ class ContactsWidget(QWidget):
|
||||||
|
|
||||||
item = QListWidgetItem()
|
item = QListWidgetItem()
|
||||||
item.setText('<h2>%s</h2><font color="#%06X">%s</font><br /><i>%s</i>' % (contact.name, status_color, status, contact.backend.name))
|
item.setText('<h2>%s</h2><font color="#%06X">%s</font><br /><i>%s</i>' % (contact.name, status_color, status, contact.backend.name))
|
||||||
item.setIcon(QIcon(QPixmap.fromImage(img)))
|
|
||||||
item.setData(Qt.UserRole, contact)
|
item.setData(Qt.UserRole, contact)
|
||||||
|
|
||||||
|
process = QtDo(self.weboob, lambda b, c: self.setPhoto(c, item))
|
||||||
|
process.do('fillobj', contact, ['photos'], backends=contact.backend)
|
||||||
|
|
||||||
for i in xrange(self.ui.contactList.count()):
|
for i in xrange(self.ui.contactList.count()):
|
||||||
if self.ui.contactList.item(i).data(Qt.UserRole).toPyObject().status > contact.status:
|
if self.ui.contactList.item(i).data(Qt.UserRole).toPyObject().status > contact.status:
|
||||||
self.ui.contactList.insertItem(i, item)
|
self.ui.contactList.insertItem(i, item)
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="photoLabel">
|
<widget class="QLabel" name="photoLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>photo</string>
|
<string><i>Receiving...</i></string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue