From b56616f7dd0eecbd96c65ea7f680dc02616b2d46 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Sat, 24 Jul 2010 12:10:01 +0200 Subject: [PATCH] asynchroneous fetches of photos and profile --- weboob/applications/qhavesex/contacts.py | 42 +++++++++++++++++++--- weboob/applications/qhavesex/ui/profile.ui | 2 +- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/weboob/applications/qhavesex/contacts.py b/weboob/applications/qhavesex/contacts.py index 5c61bb0c..6ddb2976 100644 --- a/weboob/applications/qhavesex/contacts.py +++ b/weboob/applications/qhavesex/contacts.py @@ -127,9 +127,29 @@ class ContactProfile(QWidget): self.weboob = weboob 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('

%s

' % contact.name) self.ui.statusLabel.setText('%s' % contact.status_msg) - self.ui.descriptionEdit.setText('

Description

%s

' % contact.summary) + self.ui.descriptionEdit.setText('

Description

%s

' % (contact.summary.replace('\n', '
') or 'Receiving...')) class IGroup(object): def __init__(self, weboob, id, name): @@ -190,12 +210,22 @@ class ContactsWidget(QWidget): group = self.ui.groupBox.itemData(i).toPyObject() group.iter_contacts(self.addContact) - def addContact(self, contact): + def setPhoto(self, contact, item): if not contact: return - data = urllib2.urlopen(contact.thumbnail_url).read() - img = QImage.fromData(data) + img = None + 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 = '' if contact.status == Contact.STATUS_ONLINE: @@ -216,9 +246,11 @@ class ContactsWidget(QWidget): item = QListWidgetItem() item.setText('

%s

%s
%s' % (contact.name, status_color, status, contact.backend.name)) - item.setIcon(QIcon(QPixmap.fromImage(img))) 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()): if self.ui.contactList.item(i).data(Qt.UserRole).toPyObject().status > contact.status: self.ui.contactList.insertItem(i, item) diff --git a/weboob/applications/qhavesex/ui/profile.ui b/weboob/applications/qhavesex/ui/profile.ui index 327cb02b..64b8da85 100644 --- a/weboob/applications/qhavesex/ui/profile.ui +++ b/weboob/applications/qhavesex/ui/profile.ui @@ -35,7 +35,7 @@ - photo + Receiving...