From 2921a17a3eb45a4e40d1eec9a29416deaa7d058c Mon Sep 17 00:00:00 2001 From: Christophe Benz Date: Fri, 19 Nov 2010 04:38:28 +0100 Subject: [PATCH] implement photo caroussel --- weboob/applications/qhavesex/contacts.py | 55 +++++++---- weboob/applications/qhavesex/ui/profile.ui | 103 ++++++++++++++------- 2 files changed, 104 insertions(+), 54 deletions(-) diff --git a/weboob/applications/qhavesex/contacts.py b/weboob/applications/qhavesex/contacts.py index eb91bed4..510b5520 100644 --- a/weboob/applications/qhavesex/contacts.py +++ b/weboob/applications/qhavesex/contacts.py @@ -26,7 +26,7 @@ from weboob.tools.application.qt import QtDo, HTMLDelegate from weboob.capabilities.contact import ICapContact, Contact from weboob.capabilities.chat import ICapChat from weboob.capabilities.messages import ICapMessages, ICapMessagesPost, Message -from weboob.capabilities.base import NotLoaded +from weboob.capabilities.base import NotLoaded, NotLoadedMeta from .ui.contacts_ui import Ui_Contacts from .ui.contact_thread_ui import Ui_ContactThread @@ -190,11 +190,17 @@ class ContactThread(QWidget): self.process_reply = None class ContactProfile(QWidget): + + displayed_photo_idx = 0 + def __init__(self, weboob, contact, parent=None): QWidget.__init__(self, parent) self.ui = Ui_Profile() self.ui.setupUi(self) + self.connect(self.ui.previousButton, SIGNAL('clicked()'), self.previousClicked) + self.connect(self.ui.nextButton, SIGNAL('clicked()'), self.nextClicked) + self.weboob = weboob self.contact = contact self.loaded_profile = False @@ -214,26 +220,19 @@ class ContactProfile(QWidget): return [] missing_fields = set(['photos']) - first = True - for photo in contact.photos.itervalues(): - photo = contact.photos.values()[0] - if photo.data: - data = photo.data - try: - missing_fields.remove('photos') - except KeyError: - pass - elif photo.thumbnail_data: - data = photo.thumbnail_data - else: - continue - if first: - img = QImage.fromData(data) - self.ui.photoLabel.setPixmap(QPixmap.fromImage(img)) - first = False - else: - # TODO display thumbnails + photo = contact.photos.values()[0] + data = None + if photo.data: + self.displayed_photo_idx = 0 + data = photo.data + try: + missing_fields.remove('photos') + except KeyError: pass + elif photo.thumbnail_data: + data = photo.thumbnail_data + if data: + self.display_photo(photo, data) self.ui.nicknameLabel.setText('

%s

' % contact.name) self.ui.statusLabel.setText('%s' % contact.status_msg) @@ -289,6 +288,22 @@ class ContactProfile(QWidget): else: logging.warning('Not supported widget: %r' % widget) + def previousClicked(self): + self.displayed_photo_idx = (self.displayed_photo_idx - 1) % len(self.contact.photos) + self.display_photo(self.contact.photos.values()[self.displayed_photo_idx]) + + def nextClicked(self): + self.displayed_photo_idx = (self.displayed_photo_idx + 1) % len(self.contact.photos) + self.display_photo(self.contact.photos.values()[self.displayed_photo_idx]) + + def display_photo(self, photo, data=None): + img = QImage.fromData(data if data else photo.data) + self.ui.photoLabel.setPixmap(QPixmap.fromImage(img)) + if not isinstance(photo.url, NotLoadedMeta): + self.ui.photoURLEdit.setText(photo.url) + self.ui.shownLabel.setText('' if photo.shown else 'Hidden photo') + + class IGroup(object): def __init__(self, weboob, id, name): self.id = id diff --git a/weboob/applications/qhavesex/ui/profile.ui b/weboob/applications/qhavesex/ui/profile.ui index be12d2a1..78b24b16 100644 --- a/weboob/applications/qhavesex/ui/profile.ui +++ b/weboob/applications/qhavesex/ui/profile.ui @@ -6,7 +6,7 @@ 0 0 - 576 + 755 647 @@ -33,7 +33,7 @@ 0 0 - 576 + 755 647 @@ -53,38 +53,6 @@ QFrame::Raised - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - <i>Receiving...</i> - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - - - @@ -133,6 +101,73 @@ + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + Previous + + + + + + + Next + + + + + + + + + + + + + + color: rgb(255, 0, 0); + + + + + + + + + + + + <i>Receiving...</i> + + + + + + + Qt::Vertical + + + + 13 + 13 + + + + + + +