From f95aab909692a3ba73e4438cc9ee24d3fac95d86 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Thu, 29 Jul 2010 13:08:16 +0200 Subject: [PATCH] display all of the profile --- weboob/applications/qhavesex/contacts.py | 63 +++++- weboob/applications/qhavesex/ui/profile.ui | 222 +++++++++++++-------- weboob/backends/aum/backend.py | 1 + weboob/capabilities/contact.py | 2 +- 4 files changed, 200 insertions(+), 88 deletions(-) diff --git a/weboob/applications/qhavesex/contacts.py b/weboob/applications/qhavesex/contacts.py index 6ddb2976..581edddb 100644 --- a/weboob/applications/qhavesex/contacts.py +++ b/weboob/applications/qhavesex/contacts.py @@ -15,10 +15,11 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -import urllib2 import time import logging -from PyQt4.QtGui import QWidget, QListWidgetItem, QImage, QIcon, QPixmap, QFrame, QMessageBox +from PyQt4.QtGui import QWidget, QListWidgetItem, QImage, QIcon, QPixmap, \ + QFrame, QMessageBox, QTabWidget, QVBoxLayout, \ + QFormLayout, QLabel from PyQt4.QtCore import SIGNAL, Qt from weboob.tools.application.qt import QtDo, HTMLDelegate @@ -127,10 +128,9 @@ 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) + if 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: @@ -139,18 +139,65 @@ class ContactProfile(QWidget): first = True for photo in contact.photos.itervalues(): photo = contact.photos.values()[0] - if first: + if first and photo.data: img = QImage.fromData(photo.data) self.ui.photoLabel.setPixmap(QPixmap.fromImage(img)) + first = False 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.replace('\n', '
') or 'Receiving...')) + if not contact.profile: + return True + + for head in contact.profile: + if head.flags & head.HEAD: + widget = self.ui.headFrame + else: + widget = self.ui.profileTab + self.process_node(head, widget) + + return False + + def process_node(self, node, widget): + # Set the value widget + value = None + if node.flags & node.SECTION: + value = QWidget() + value.setLayout(QFormLayout()) + for sub in node.value: + self.process_node(sub, value) + elif isinstance(node.value, list): + value = QLabel('
'.join([unicode(s) for s in node.value])) + value.setWordWrap(True) + elif isinstance(node.value, tuple): + value = QLabel(', '.join([unicode(s) for s in node.value])) + value.setWordWrap(True) + elif isinstance(node.value, (str,unicode,int)): + print '[%s]' % node.value + value = QLabel(unicode(node.value)) + + if not value: + print 'no value :(' + return + + # Insert the value widget into the parent widget, depending + # of its type. + if isinstance(widget, QTabWidget): + widget.addTab(value, node.label) + elif isinstance(widget.layout(), QFormLayout): + label = QLabel(u'%s: ' % node.label) + widget.layout().addRow(label, value) + elif isinstance(widget.layout(), QVBoxLayout): + widget.layout().addWidget(value) + else: + print 'TODO' + return + 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 64b8da85..950d3a5e 100644 --- a/weboob/applications/qhavesex/ui/profile.ui +++ b/weboob/applications/qhavesex/ui/profile.ui @@ -13,87 +13,151 @@ Form - + + + 0 + - - - QFrame::StyledPanel + + + true - - QFrame::Raised - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - Receiving... - - - - - - - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - <h1>Nickname</h1> - - - - - - - status - - - - - - - - - - - - - QFrame::NoFrame - - - QFrame::Plain - - - - - - true - - - - + + + + 0 + 0 + 456 + 316 + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + <i>Receiving...</i> + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + <h1>Nickname</h1> + + + + + + + status + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + + + + + + + + + Qt::Horizontal + + + + + 0 + 0 + + + + true + + + + + + 2 + 0 + + + + -1 + + + + + + diff --git a/weboob/backends/aum/backend.py b/weboob/backends/aum/backend.py index a974f45c..05a3a37f 100644 --- a/weboob/backends/aum/backend.py +++ b/weboob/backends/aum/backend.py @@ -214,6 +214,7 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesReply, ICapDating, ICapC s = ProfileNode(section, section.capitalize(), [], flags=ProfileNode.SECTION) for key, value in d.iteritems(): s.value.append(ProfileNode(key, key.capitalize(), value)) + contact.profile.append(s) return contact except BrowserUnavailable: diff --git a/weboob/capabilities/contact.py b/weboob/capabilities/contact.py index 3db053a6..92231fda 100644 --- a/weboob/capabilities/contact.py +++ b/weboob/capabilities/contact.py @@ -26,7 +26,7 @@ class ProfileNode(object): HEAD = 0x01 SECTION = 0x02 - def __init__(self, name, label, value, sufix=None, flags=None): + def __init__(self, name, label, value, sufix=None, flags=0): self.name = name self.label = label self.value = value