moved ICapDating.get_status() and ICapMessagesPost.get_status() into ICapAccount.get_account_status()

This commit is contained in:
Romain Bignon 2010-11-20 20:42:50 +01:00
commit c83c923e3d
8 changed files with 72 additions and 64 deletions

View file

@ -16,9 +16,9 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from PyQt4.QtGui import QWidget, QHBoxLayout, QVBoxLayout, QFrame, QLabel, QImage, QPixmap from PyQt4.QtGui import QScrollArea, QWidget, QHBoxLayout, QVBoxLayout, QFrame, QLabel, QImage, QPixmap
from weboob.capabilities.dating import StatusField from weboob.capabilities.account import ICapAccount, StatusField
from weboob.tools.application.qt import QtDo from weboob.tools.application.qt import QtDo
class Account(QFrame): class Account(QFrame):
@ -31,12 +31,14 @@ class Account(QFrame):
self.weboob = weboob self.weboob = weboob
self.backend = backend self.backend = backend
self.setLayout(QVBoxLayout()) self.setLayout(QVBoxLayout())
self.timer = None
head = QHBoxLayout() head = QHBoxLayout()
headw = QWidget() headw = QWidget()
headw.setLayout(head) headw.setLayout(head)
self.title = QLabel(u'<h1>%s%s</h1>' % (backend.name, backend.DESCRIPTION)) self.title = QLabel(u'<h1>%s%s</h1>' % (backend.name, backend.DESCRIPTION))
self.body = QLabel()
if backend.ICON: if backend.ICON:
self.icon = QLabel() self.icon = QLabel()
@ -47,18 +49,23 @@ class Account(QFrame):
head.addWidget(self.title) head.addWidget(self.title)
head.addStretch() head.addStretch()
self.body = QLabel(u'<i>Waiting...</i>')
self.layout().addWidget(headw) self.layout().addWidget(headw)
self.layout().addWidget(self.body)
self.weboob.repeat(60, self.updateStats) if backend.has_caps(ICapAccount):
self.body.setText(u'<i>Waiting...</i>')
self.layout().addWidget(self.body)
self.timer = self.weboob.repeat(60, self.updateStats)
def deinit(self):
if self.timer is not None:
self.weboob.stop(self.timer)
def updateStats(self): def updateStats(self):
self.process = QtDo(self.weboob, self.updateStats_cb, self.updateStats_eb) self.process = QtDo(self.weboob, self.updateStats_cb, self.updateStats_eb)
self.process.body = u'' self.process.body = u''
self.process.in_p = False self.process.in_p = False
self.process.do('get_status', backends=self.backend) self.process.do('get_account_status', backends=self.backend)
def updateStats_cb(self, backend, field): def updateStats_cb(self, backend, field):
if not field: if not field:
@ -93,23 +100,30 @@ class Account(QFrame):
self.body.setText(u'<b>Unable to connect:</b> %s' % unicode(err)) self.body.setText(u'<b>Unable to connect:</b> %s' % unicode(err))
self.title.setText(u'<font color=#ff0000>%s</font>' % unicode(self.title.text())) self.title.setText(u'<font color=#ff0000>%s</font>' % unicode(self.title.text()))
class AccountsStatus(QWidget): class AccountsStatus(QScrollArea):
def __init__(self, weboob, parent=None): def __init__(self, weboob, parent=None):
QWidget.__init__(self, parent) QScrollArea.__init__(self, parent)
self.weboob = weboob self.weboob = weboob
self.setLayout(QVBoxLayout()) self.setFrameShadow(self.Plain)
self.setFrameShape(self.NoFrame)
self.setWidgetResizable(True)
widget = QWidget(self)
widget.setLayout(QVBoxLayout())
widget.show()
self.setWidget(widget)
def load(self): def load(self):
while self.layout().count() > 0: while self.widget().layout().count() > 0:
item = self.layout().takeAt(0) item = self.widget().layout().takeAt(0)
if item.widget(): if item.widget():
item.widget().hide() item.widget().hide()
item.widget().deleteLater() item.widget().deleteLater()
for backend in self.weboob.iter_backends(): for backend in self.weboob.iter_backends():
account = Account(self.weboob, backend) account = Account(self.weboob, backend)
self.layout().addWidget(account) self.widget().layout().addWidget(account)
self.layout().addStretch() self.widget().layout().addStretch()

View file

@ -25,9 +25,9 @@ from dateutil import tz
from weboob.capabilities.base import NotLoaded from weboob.capabilities.base import NotLoaded
from weboob.capabilities.chat import ICapChat from weboob.capabilities.chat import ICapChat
from weboob.capabilities.messages import ICapMessages, ICapMessagesPost, Message, Thread from weboob.capabilities.messages import ICapMessages, ICapMessagesPost, Message, Thread
from weboob.capabilities.dating import ICapDating, StatusField, OptimizationNotFound from weboob.capabilities.dating import ICapDating, OptimizationNotFound
from weboob.capabilities.contact import ICapContact, Contact, ContactPhoto, ProfileNode, Query, QueryError from weboob.capabilities.contact import ICapContact, Contact, ContactPhoto, ProfileNode, Query, QueryError
from weboob.capabilities.account import ICapAccount from weboob.capabilities.account import ICapAccount, StatusField
from weboob.tools.backend import BaseBackend from weboob.tools.backend import BaseBackend
from weboob.tools.browser import BrowserUnavailable from weboob.tools.browser import BrowserUnavailable
from weboob.tools.value import Value, ValuesDict, ValueBool from weboob.tools.value import Value, ValuesDict, ValueBool
@ -90,17 +90,6 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapDating, ICapCh
self.add_optimization('PRIORITY_CONNECTION', PriorityConnection(self.weboob.scheduler, self.storage, self.browser)) self.add_optimization('PRIORITY_CONNECTION', PriorityConnection(self.weboob.scheduler, self.storage, self.browser))
self.add_optimization('QUERIES_QUEUE', QueriesQueue(self.weboob.scheduler, self.storage, self.browser)) self.add_optimization('QUERIES_QUEUE', QueriesQueue(self.weboob.scheduler, self.storage, self.browser))
def get_status(self):
with self.browser:
try:
return (
StatusField('myname', 'My name', self.browser.get_my_name()),
StatusField('score', 'Score', self.browser.score()),
StatusField('avcharms', 'Available charms', self.browser.nb_available_charms()),
)
except AdopteWait:
return (StatusField('notice', '', u'<h3>You are currently waiting 1am to be able to connect with this account</h3>', StatusField.FIELD_HTML|StatusField.FIELD_TEXT))
# ---- ICapMessages methods --------------------- # ---- ICapMessages methods ---------------------
def fill_thread(self, thread, fields): def fill_thread(self, thread, fields):
@ -495,6 +484,18 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapDating, ICapCh
""" """
raise NotImplementedError() raise NotImplementedError()
def get_account_status(self):
with self.browser:
try:
return (
StatusField('myname', 'My name', self.browser.get_my_name()),
StatusField('score', 'Score', self.browser.score()),
StatusField('avcharms', 'Available charms', self.browser.nb_available_charms()),
StatusField('godchilds', 'Number of godchilds', self.browser.nb_godchilds()),
)
except AdopteWait:
return (StatusField('notice', '', u'<h3>You are currently waiting 1am to be able to connect with this account</h3>', StatusField.FIELD_HTML|StatusField.FIELD_TEXT))
OBJECTS = {Thread: fill_thread, OBJECTS = {Thread: fill_thread,
Contact: fill_contact, Contact: fill_contact,
ContactPhoto: fill_photo ContactPhoto: fill_photo

View file

@ -18,7 +18,8 @@
from __future__ import with_statement from __future__ import with_statement
from weboob.capabilities.messages import CantSendMessage, ICapMessagesPost, StatusField from weboob.capabilities.messages import CantSendMessage, ICapMessages, ICapMessagesPost
from weboob.capabilities.account import ICapAccount, StatusField
from weboob.tools.backend import BaseBackend from weboob.tools.backend import BaseBackend
from weboob.tools.value import ValuesDict, Value from weboob.tools.value import ValuesDict, Value
@ -28,7 +29,7 @@ from .browser import SfrBrowser
__all__ = ['SfrBackend'] __all__ = ['SfrBackend']
class SfrBackend(BaseBackend, ICapMessagesPost): class SfrBackend(BaseBackend, ICapAccount, ICapMessages, ICapMessagesPost):
NAME = 'sfr' NAME = 'sfr'
MAINTAINER = 'Christophe Benz' MAINTAINER = 'Christophe Benz'
EMAIL = 'christophe.benz@gmail.com' EMAIL = 'christophe.benz@gmail.com'
@ -38,13 +39,14 @@ class SfrBackend(BaseBackend, ICapMessagesPost):
CONFIG = ValuesDict(Value('login', label='Login'), CONFIG = ValuesDict(Value('login', label='Login'),
Value('password', label='Password', masked=True)) Value('password', label='Password', masked=True))
BROWSER = SfrBrowser BROWSER = SfrBrowser
ACCOUNT_REGISTER_PROPERTIES = None
def create_default_browser(self): def create_default_browser(self):
return self.create_browser(self.config['login'], self.config['password']) return self.create_browser(self.config['login'], self.config['password'])
# ICapMessagesPost methods # ICapMessagesPost methods
def get_status(self): def get_account_status(self):
with self.browser: with self.browser:
return (StatusField('nb_remaining_free_sms', 'Number of remaining free SMS', return (StatusField('nb_remaining_free_sms', 'Number of remaining free SMS',
self.browser.get_nb_remaining_free_sms()),) self.browser.get_nb_remaining_free_sms()),)
@ -53,4 +55,4 @@ class SfrBackend(BaseBackend, ICapMessagesPost):
if not message.content.strip(): if not message.content.strip():
raise CantSendMessage(u'Message content is empty.') raise CantSendMessage(u'Message content is empty.')
with self.browser: with self.browser:
self.browser.post_message(message) self.browser.post_message(message)

View file

@ -32,8 +32,21 @@ class Account(CapBaseObject):
self.add_field('password', basestring) self.add_field('password', basestring)
self.add_field('properties', dict) self.add_field('properties', dict)
class StatusField(object):
FIELD_TEXT = 0x001 # the value is a long text
FIELD_HTML = 0x002 # the value is HTML formated
def __init__(self, key, label, value, flags=0):
self.key = key
self.label = label
self.value = value
self.flags = flags
class ICapAccount(IBaseCap): class ICapAccount(IBaseCap):
ACCOUNT_REGISTER_PROPERTIES = [] # This class constant may be a list of Value* objects. If the value remains
# None, weboob considers that register_account() isn't supported.
ACCOUNT_REGISTER_PROPERTIES = None
@staticmethod @staticmethod
def register_account(account): def register_account(account):
@ -64,3 +77,11 @@ class ICapAccount(IBaseCap):
Update the current account. Update the current account.
""" """
raise NotImplementedError() raise NotImplementedError()
def get_account_status(self):
"""
Get status of the current account.
@return a list of fields
"""
raise NotImplementedError()

View file

@ -45,24 +45,7 @@ class Optimization(object):
def set_config(self, params): def set_config(self, params):
raise NotImplementedError() raise NotImplementedError()
class StatusField(object):
FIELD_TEXT = 0x001 # the value is a long text
FIELD_HTML = 0x002 # the value is HTML formated
def __init__(self, key, label, value, flags=0):
self.key = key
self.label = label
self.value = value
self.flags = flags
class ICapDating(IBaseCap): class ICapDating(IBaseCap):
def get_status(self):
"""
Get a list of fields
"""
raise NotImplementedError()
def init_optimizations(self): def init_optimizations(self):
raise NotImplementedError() raise NotImplementedError()

View file

@ -117,13 +117,6 @@ class Thread(CapBaseObject):
yield m yield m
class StatusField(object):
def __init__(self, key, label, value):
self.key = key
self.label = label
self.value = value
class ICapMessages(IBaseCap): class ICapMessages(IBaseCap):
def iter_threads(self): def iter_threads(self):
""" """
@ -162,12 +155,6 @@ class CantSendMessage(Exception):
pass pass
class ICapMessagesPost(IBaseCap): class ICapMessagesPost(IBaseCap):
def get_status(self):
"""
Get a list of fields
"""
raise NotImplementedError()
def post_message(self, message): def post_message(self, message):
""" """
Post a message. Post a message.

View file

@ -287,7 +287,7 @@ class BackendCfg(QDialog):
backend.description, backend.description,
', '.join([cap.__name__ for cap in backend.iter_caps()]))) ', '.join([cap.__name__ for cap in backend.iter_caps()])))
if backend.has_caps(ICapAccount) and self.ui.nameEdit.isEnabled(): if backend.has_caps(ICapAccount) and self.ui.nameEdit.isEnabled() and backend.klass.ACCOUNT_REGISTER_PROPERTIES is not None:
self.ui.registerButton.show() self.ui.registerButton.show()
else: else:
self.ui.registerButton.hide() self.ui.registerButton.hide()

View file

@ -151,7 +151,7 @@ class ReplApplication(Cmd, BaseApplication):
print 'Backend "%s" does not exist.' % name print 'Backend "%s" does not exist.' % name
return None return None
if not backend.has_caps(ICapAccount): if not backend.has_caps(ICapAccount) or backend.klass.ACCOUNT_REGISTER_PROPERTIES is None:
print 'You can\'t register a new account with %s' % name print 'You can\'t register a new account with %s' % name
return None return None