code clean, split too long lines

This commit is contained in:
Christophe Benz 2010-12-08 16:58:14 +01:00 committed by Romain Bignon
commit 851b2d34ca
10 changed files with 132 additions and 108 deletions

View file

@ -15,11 +15,13 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# 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 weboob.capabilities.bank import ICapBank, AccountNotFound from weboob.capabilities.bank import ICapBank, AccountNotFound
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
from .browser import BPbrowser from .browser import BPBrowser
class BPBackend(BaseBackend, ICapBank): class BPBackend(BaseBackend, ICapBank):
NAME = 'bp' NAME = 'bp'
@ -30,7 +32,7 @@ class BPBackend(BaseBackend, ICapBank):
DESCRIPTION = u'La banque postale, French bank' DESCRIPTION = u'La banque postale, French bank'
CONFIG = ValuesDict(Value('login', label='Account ID'), CONFIG = ValuesDict(Value('login', label='Account ID'),
Value('password', label='Password', masked=True)) Value('password', label='Password', masked=True))
BROWSER = BPbrowser BROWSER = BPBrowser
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'])
@ -57,4 +59,3 @@ class BPBackend(BaseBackend, ICapBank):
#TODO: retourner le numero du virement #TODO: retourner le numero du virement
#TODO: support the 'reason' parameter #TODO: support the 'reason' parameter
return self.browser.make_transfer(from_account, to_account, amount) return self.browser.make_transfer(from_account, to_account, amount)

View file

@ -20,69 +20,74 @@ from datetime import datetime
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword, BrowserBanned from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword, BrowserBanned
from .pages import LoginPage, LoggedPage, CookiePage, AccountList, AccountHistory, BadLoginPage, AccountDesactivate, TransferChooseAccounts, CompleteTransfer, TransferConfirm, TransferSummary from .pages import LoginPage, LoggedPage, CookiePage, AccountList, AccountHistory, BadLoginPage, AccountDesactivate, \
TransferChooseAccounts, CompleteTransfer, TransferConfirm, TransferSummary
from weboob.capabilities.bank import Transfer from weboob.capabilities.bank import Transfer
__all__ = ['BPbrowser']
__all__ = ['BPBrowser']
class BPbrowser(BaseBrowser): class BPBrowser(BaseBrowser):
DOMAIN = 'voscomptesenligne.labanquepostale.fr' DOMAIN = 'voscomptesenligne.labanquepostale.fr'
PROTOCOL = 'https' PROTOCOL = 'https'
ENCODING = None # refer to the HTML encoding ENCODING = None # refer to the HTML encoding
PAGES = { r'.*wsost/OstBrokerWeb/loginform.*': LoginPage, PAGES = {r'.*wsost/OstBrokerWeb/loginform.*': LoginPage,
r'.*voscomptes/canalXHTML/identif\.ea.*': LoggedPage, r'.*voscomptes/canalXHTML/identif\.ea.*': LoggedPage,
r'.*voscomptes/canalXHTML/releve/syntheseAssurancesEtComptes\.ea': CookiePage, r'.*voscomptes/canalXHTML/releve/syntheseAssurancesEtComptes\.ea': CookiePage,
r'.*voscomptes/canalXHTML/releve/liste_comptes\.jsp': AccountList, r'.*voscomptes/canalXHTML/releve/liste_comptes\.jsp': AccountList,
r'.*canalXHTML/relevesCCP/.*': AccountHistory, r'.*canalXHTML/relevesCCP/.*': AccountHistory,
r'.*canalXHTML/relevesEpargnes/.*': AccountHistory, r'.*canalXHTML/relevesEpargnes/.*': AccountHistory,
r'.*ost/messages\.CVS\.html\?param=0x132120c8.*' : BadLoginPage, r'.*ost/messages\.CVS\.html\?param=0x132120c8.*' : BadLoginPage,
r'.*ost/messages\.CVS\.html\?param=0x132120cb.*' : AccountDesactivate, r'.*ost/messages\.CVS\.html\?param=0x132120cb.*' : AccountDesactivate,
r'.*/virementsafran/aiguillage/saisieComptes\.ea.*': TransferChooseAccounts, r'.*/virementsafran/aiguillage/saisieComptes\.ea.*': TransferChooseAccounts,
r'.*/virementsafran/aiguillage/2-saisieComptes\.ea.*' : CompleteTransfer, r'.*/virementsafran/aiguillage/2-saisieComptes\.ea.*' : CompleteTransfer,
r'.*/virementsafran/virementnational/2-virementNational\.ea.*' : TransferConfirm, r'.*/virementsafran/virementnational/2-virementNational\.ea.*' : TransferConfirm,
r'.*/virementsafran/virementnational/4-virementNational\.ea.*' : TransferSummary, r'.*/virementsafran/virementnational/4-virementNational\.ea.*' : TransferSummary,
} }
def home(self): def home(self):
self.location("https://voscomptesenligne.labanquepostale.fr/wsost/OstBrokerWeb/loginform?TAM_OP=login&ERROR_CODE=0x00000000&URL=%2Fvoscomptes%2FcanalXHTML%2Fidentif.ea%3Forigin%3Dparticuliers") self.location('https://voscomptesenligne.labanquepostale.fr/wsost/OstBrokerWeb/loginform?TAM_OP=login&'
'ERROR_CODE=0x00000000&URL=%2Fvoscomptes%2FcanalXHTML%2Fidentif.ea%3Forigin%3Dparticuliers')
def is_logged(self): def is_logged(self):
return not self.is_on_page(LoginPage) return not self.is_on_page(LoginPage)
def login(self): def login(self):
if not self.is_on_page(LoginPage): if not self.is_on_page(LoginPage):
self.location('https://voscomptesenligne.labanquepostale.fr/wsost/OstBrokerWeb/loginform?TAM_OP=login&ERROR_CODE=0x00000000&URL=%2Fvoscomptes%2FcanalXHTML%2Fidentif.ea%3Forigin%3Dparticuliers', no_login=True) self.location('https://voscomptesenligne.labanquepostale.fr/wsost/OstBrokerWeb/loginform?TAM_OP=login&'
'ERROR_CODE=0x00000000&URL=%2Fvoscomptes%2FcanalXHTML%2Fidentif.ea%3Forigin%3Dparticuliers',
no_login=True)
self.page.login(self.username, self.password) self.page.login(self.username, self.password)
if self.is_on_page(BadLoginPage): if self.is_on_page(BadLoginPage):
raise BrowserIncorrectPassword() raise BrowserIncorrectPassword()
if self.is_on_page(AccountDesactivate): if self.is_on_page(AccountDesactivate):
raise BrowserBanned() raise BrowserBanned()
def get_accounts_list(self): def get_accounts_list(self):
self.location("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/authentification/liste_contrat_atos.ea") self.location('https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/authentification/'
self.location("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/releve/liste_comptes.jsp") 'liste_contrat_atos.ea')
self.location('https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/releve/liste_comptes.jsp')
return self.page.get_accounts_list() return self.page.get_accounts_list()
def get_account(self, id): def get_account(self, id):
if not self.is_on_page(AccountList): if not self.is_on_page(AccountList):
self.location("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/authentification/liste_contrat_atos.ea") self.location('https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/authentification/'
self.location("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/releve/liste_comptes.jsp") 'liste_contrat_atos.ea')
self.location('https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/releve/liste_comptes.jsp')
return self.page.get_account(id) return self.page.get_account(id)
def get_history(self, Account): def get_history(self, Account):
self.location(Account.link_id) self.location(Account.link_id)
return self.page.get_history() return self.page.get_history()
def make_transfer(self, from_account, to_account, amount): def make_transfer(self, from_account, to_account, amount):
self.location("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/virementsafran/aiguillage/saisieComptes.ea") self.location('https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/virementsafran/aiguillage/'
'saisieComptes.ea')
self.page.set_accouts(from_account, to_account) self.page.set_accouts(from_account, to_account)
#TODO: Check #TODO: Check

View file

@ -15,11 +15,13 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# 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 .login import LoginPage, LoggedPage, BadLoginPage, AccountDesactivate from .login import LoginPage, LoggedPage, BadLoginPage, AccountDesactivate
from .cookie import CookiePage from .cookie import CookiePage
from .accountlist import AccountList from .accountlist import AccountList
from .accounthistory import AccountHistory from .accounthistory import AccountHistory
from .transfer import TransferChooseAccounts, CompleteTransfer, TransferConfirm, TransferSummary from .transfer import TransferChooseAccounts, CompleteTransfer, TransferConfirm, TransferSummary
__all__ = ['LoginPage', 'LoggedPage', 'CookiePage', "AccountList", 'AccountHistory', 'BadLoginPage', 'AccountDesactivate', 'TransferChooseAccounts', 'CompleteTransfer', 'TransferConfirm', 'TransferSummary']
__all__ = ['LoginPage', 'LoggedPage', 'CookiePage', "AccountList", 'AccountHistory', 'BadLoginPage',
'AccountDesactivate', 'TransferChooseAccounts', 'CompleteTransfer', 'TransferConfirm', 'TransferSummary']

View file

@ -15,18 +15,22 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import re import re
from weboob.capabilities.bank import Operation from weboob.capabilities.bank import Operation
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
__all__ = ['AccountHistory'] __all__ = ['AccountHistory']
def remove_html_tags(data): def remove_html_tags(data):
p = re.compile(r'<.*?>') p = re.compile(r'<.*?>')
return p.sub(' ', data) return p.sub(' ', data)
def remove_extra_spaces(data): def remove_extra_spaces(data):
p = re.compile(r'\s+') p = re.compile(r'\s+')
return p.sub(' ', data) return p.sub(' ', data)
@ -34,7 +38,8 @@ def remove_extra_spaces(data):
class AccountHistory(BasePage): class AccountHistory(BasePage):
def on_loaded(self): def on_loaded(self):
if self.document.docinfo.doctype == '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">': if self.document.docinfo.doctype == '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" '
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">':
self.browser.follow_link(url_regex="releve", tag="a") self.browser.follow_link(url_regex="releve", tag="a")
def get_history(self): def get_history(self):
@ -49,7 +54,6 @@ class AccountHistory(BasePage):
tp = mvt.xpath("./td")[1] tp = mvt.xpath("./td")[1]
operation.label = remove_extra_spaces(remove_html_tags(self.browser.parser.tostring(tp))) operation.label = remove_extra_spaces(remove_html_tags(self.browser.parser.tostring(tp)))
r = re.compile(r'\d+') r = re.compile(r'\d+')
tp = mvt.xpath("./td/span") tp = mvt.xpath("./td/span")
amount = None amount = None

View file

@ -20,14 +20,15 @@ from weboob.capabilities.bank import Account, AccountNotFound
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
__all__ = ['AccountList'] __all__ = ['AccountList']
class AccountList(BasePage): class AccountList(BasePage):
def on_loaded(self): def on_loaded(self):
self.Account_List = [] self.account_list = []
def get_accounts_list(self): def get_accounts_list(self):
#Parse CCP #Parse CCP
compte_table = self.document.xpath("//table[@id='comptes']", smart_strings=False)[0] compte_table = self.document.xpath("//table[@id='comptes']", smart_strings=False)[0]
compte_ligne = compte_table.xpath("./tbody/tr") compte_ligne = compte_table.xpath("./tbody/tr")
@ -38,8 +39,8 @@ class AccountList(BasePage):
account.label = tp.text account.label = tp.text
account.link_id = tp.get("href") account.link_id = tp.get("href")
account.id = compte.xpath("./td")[1].text account.id = compte.xpath("./td")[1].text
account.balance = float(''.join( compte.xpath("./td/span")[0].text.replace('.','').replace(',','.').split() )) account.balance = float(''.join(compte.xpath("./td/span")[0].text.replace('.','').replace(',','.').split()))
self.Account_List.append(account) self.account_list.append(account)
#Parse epargne #Parse epargne
epargne_table = self.document.xpath("//table[@id='comptesEpargne']", smart_strings=False)[0] epargne_table = self.document.xpath("//table[@id='comptesEpargne']", smart_strings=False)[0]
@ -51,16 +52,16 @@ class AccountList(BasePage):
account.label = tp.text account.label = tp.text
account.link_id = tp.get("href") account.link_id = tp.get("href")
account.id = epargne.xpath("./td")[1].text account.id = epargne.xpath("./td")[1].text
account.balance = float(''.join( epargne.xpath("./td/span")[0].text.replace('.','').replace(',','.').split() ) ) account.balance = float(''.join(epargne.xpath("./td/span")[0].text.replace('.','').replace(',','.').split()))
self.Account_List.append(account) self.account_list.append(account)
return self.Account_List return self.account_list
def get_account(self, id): def get_account(self, id):
if not self.Account_List: if not self.account_list:
self.get_accounts_list() self.get_accounts_list()
for account in self.Account_List: for account in self.account_list:
if account.id == id: if account.id == id:
return account return account
raise AccountNotFound('Unable to find account: %s' % id) raise AccountNotFound('Unable to find account: %s' % id)

View file

@ -16,11 +16,11 @@
# 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 weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
__all__ = ['CookiePage'] __all__ = ['CookiePage']
class CookiePage(BasePage): class CookiePage(BasePage):
def on_loaded(self): pass
pass

View file

@ -15,6 +15,7 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import hashlib import hashlib
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
@ -35,26 +36,32 @@ class LoginPage(BasePage):
pass pass
def login(self, login, pwd): def login(self, login, pwd):
LOCAL_HASH = ['a02574d7bf67677d2a86b7bfc5e864fe', 'eb85e1cc45dd6bdb3cab65c002d7ac8a', '596e6fbd54d5b111fe5df8a4948e80a4', '9cdc989a4310554e7f5484d0d27a86ce', '0183943de6c0e331f3b9fc49c704ac6d', '291b9987225193ab1347301b241e2187', '163279f1a46082408613d12394e4042a', 'b0a9c740c4cada01eb691b4acda4daea', '3c4307ee92a1f3b571a3c542eafcb330', 'dbccecfa2206bfdb4ca891476404cc68'] LOCAL_HASH = ['a02574d7bf67677d2a86b7bfc5e864fe', 'eb85e1cc45dd6bdb3cab65c002d7ac8a',
process = lambda i: md5(self.browser.retrieve(("https://voscomptesenligne.labanquepostale.fr/wsost/OstBrokerWeb/loginform?imgid=%d&0.25122230781963073" % i ))[0]) '596e6fbd54d5b111fe5df8a4948e80a4', '9cdc989a4310554e7f5484d0d27a86ce',
Keypad = [ process(i) for i in range(10)] '0183943de6c0e331f3b9fc49c704ac6d', '291b9987225193ab1347301b241e2187',
'163279f1a46082408613d12394e4042a', 'b0a9c740c4cada01eb691b4acda4daea',
'3c4307ee92a1f3b571a3c542eafcb330', 'dbccecfa2206bfdb4ca891476404cc68',
]
process = lambda i: md5(self.browser.retrieve(('https://voscomptesenligne.labanquepostale.fr/wsost/OstBrokerWeb'
'/loginform?imgid=%d&0.25122230781963073' % i))[0])
keypad = [process(i) for i in range(10)]
correspondance = [keypad.index(i) for i in LOCAL_HASH]
newpassword = ''.join(str(correspondance[int(c)]) for c in pwd)
self.browser.select_form(name='formAccesCompte')
correspondance = [ Keypad.index(i) for i in LOCAL_HASH]
Newpassword = "".join([str(correspondance[int(c)]) for c in pwd])
self.browser.select_form(name="formAccesCompte")
self.browser.set_all_readonly(False) self.browser.set_all_readonly(False)
self.browser["password"] = Newpassword self.browser['password'] = newpassword
self.browser["username"] = login self.browser['username'] = login
self.browser.submit() self.browser.submit()
class LoggedPage(BasePage): class LoggedPage(BasePage):
pass pass
class BadLoginPage(BasePage): class BadLoginPage(BasePage):
pass pass
class AccountDesactivate(BasePage): class AccountDesactivate(BasePage):
pass pass

View file

@ -16,17 +16,17 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import re
from weboob.capabilities.bank import TransferError from weboob.capabilities.bank import TransferError
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
from weboob.tools.misc import to_unicode from weboob.tools.misc import to_unicode
import re
__all__ = ['TransferChooseAccounts', 'CompleteTransfer', 'TransferConfirm', 'TransferSummary'] __all__ = ['TransferChooseAccounts', 'CompleteTransfer', 'TransferConfirm', 'TransferSummary']
class TransferChooseAccounts(BasePage): class TransferChooseAccounts(BasePage):
def set_accouts(self, from_account, to_account): def set_accouts(self, from_account, to_account):
self.browser.select_form(name="AiguillageForm") self.browser.select_form(name="AiguillageForm")
self.browser["idxCompteEmetteur"] = [from_account.id] self.browser["idxCompteEmetteur"] = [from_account.id]
@ -35,16 +35,17 @@ class TransferChooseAccounts(BasePage):
class CompleteTransfer(BasePage): class CompleteTransfer(BasePage):
def complete_transfer(self, amount): def complete_transfer(self, amount):
self.browser.select_form(name="VirementNationalForm") self.browser.select_form(name="VirementNationalForm")
self.browser["montant"] = str(amount) self.browser["montant"] = str(amount)
self.browser.submit() self.browser.submit()
class TransferConfirm(BasePage):
class TransferConfirm(BasePage):
def confirm(self): def confirm(self):
self.browser.location("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/virementsafran/virementnational/4-virementNational.ea") self.browser.location('https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/virementsafran/'
'virementnational/4-virementNational.ea')
class TransferSummary(BasePage): class TransferSummary(BasePage):
def get_transfer_id(self): def get_transfer_id(self):
@ -56,7 +57,6 @@ class TransferSummary(BasePage):
except UnicodeDecodeError, error: except UnicodeDecodeError, error:
text = error.object.strip() text = error.object.strip()
match = re.search("Votre virement N.+ ([0-9]+) ", text) match = re.search("Votre virement N.+ ([0-9]+) ", text)
if match: if match:
id_transfer = match.groups()[0] id_transfer = match.groups()[0]

View file

@ -15,6 +15,7 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# 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 __future__ import with_statement from __future__ import with_statement
from weboob.tools.backend import BaseBackend from weboob.tools.backend import BaseBackend
@ -144,7 +145,8 @@ class DLFPBackend(BaseBackend, ICapMessages, ICapMessagesPost):
yield m yield m
def set_message_read(self, message): def set_message_read(self, message):
self.storage.set('seen', message.thread.id, 'comments', self.storage.get('seen', message.thread.id, 'comments', default=[]) + [message.id]) self.storage.set('seen', message.thread.id, 'comments',
self.storage.get('seen', message.thread.id, 'comments', default=[]) + [message.id])
self.storage.save() self.storage.save()
def post_message(self, message): def post_message(self, message):

View file

@ -15,6 +15,7 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# 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 QDialog, QTreeWidgetItem, QLabel, QFormLayout, \ from PyQt4.QtGui import QDialog, QTreeWidgetItem, QLabel, QFormLayout, \
QMessageBox, QPixmap, QImage, QIcon, QHeaderView, \ QMessageBox, QPixmap, QImage, QIcon, QHeaderView, \
QListWidgetItem, QTextDocument, QVBoxLayout, \ QListWidgetItem, QTextDocument, QVBoxLayout, \
@ -30,6 +31,7 @@ from weboob.tools.application.qt.backendcfg_ui import Ui_BackendCfg
from weboob.tools.ordereddict import OrderedDict from weboob.tools.ordereddict import OrderedDict
from .qt import QtValue from .qt import QtValue
class BackendCfg(QDialog): class BackendCfg(QDialog):
def __init__(self, weboob, caps=None, parent=None): def __init__(self, weboob, caps=None, parent=None):
QDialog.__init__(self, parent) QDialog.__init__(self, parent)
@ -69,8 +71,10 @@ class BackendCfg(QDialog):
self.loadConfiguredBackendsList() self.loadConfiguredBackendsList()
self.connect(self.ui.configuredBackendsList, SIGNAL('itemClicked(QTreeWidgetItem *, int)'), self.configuredBackendClicked) self.connect(self.ui.configuredBackendsList, SIGNAL('itemClicked(QTreeWidgetItem *, int)'),
self.connect(self.ui.configuredBackendsList, SIGNAL('itemChanged(QTreeWidgetItem *, int)'), self.configuredBackendEnabled) self.configuredBackendClicked)
self.connect(self.ui.configuredBackendsList, SIGNAL('itemChanged(QTreeWidgetItem *, int)'),
self.configuredBackendEnabled)
self.connect(self.ui.backendsList, SIGNAL('itemSelectionChanged()'), self.backendSelectionChanged) self.connect(self.ui.backendsList, SIGNAL('itemSelectionChanged()'), self.backendSelectionChanged)
self.connect(self.ui.proxyBox, SIGNAL('toggled(bool)'), self.proxyEditEnabled) self.connect(self.ui.proxyBox, SIGNAL('toggled(bool)'), self.proxyEditEnabled)
self.connect(self.ui.addButton, SIGNAL('clicked()'), self.addEvent) self.connect(self.ui.addButton, SIGNAL('clicked()'), self.addEvent)
@ -91,7 +95,8 @@ class BackendCfg(QDialog):
continue continue
item = QTreeWidgetItem(None, [instance_name, name]) item = QTreeWidgetItem(None, [instance_name, name])
item.setCheckState(0, Qt.Checked if params.get('_enabled', '1').lower() in ('1', 'y', 'true') else Qt.Unchecked) item.setCheckState(0, Qt.Checked if params.get('_enabled', '1').lower() in ('1', 'y', 'true') \
else Qt.Unchecked)
if backend.icon_path: if backend.icon_path:
img = QImage(backend.icon_path) img = QImage(backend.icon_path)
@ -136,8 +141,8 @@ class BackendCfg(QDialog):
bname = unicode(item.text(0)) bname = unicode(item.text(0))
reply = QMessageBox.question(self, self.tr('Remove a backend'), reply = QMessageBox.question(self, self.tr('Remove a backend'),
unicode(self.tr("Are you sure you want to remove the backend '%s'?")) % bname, unicode(self.tr("Are you sure you want to remove the backend '%s'?")) % bname,
QMessageBox.Yes|QMessageBox.No) QMessageBox.Yes|QMessageBox.No)
if reply != QMessageBox.Yes: if reply != QMessageBox.Yes:
return return
@ -197,7 +202,7 @@ class BackendCfg(QDialog):
if not selection: if not selection:
QMessageBox.critical(self, self.tr('Unable to add a configured backend'), QMessageBox.critical(self, self.tr('Unable to add a configured backend'),
self.tr('Please select a backend')) self.tr('Please select a backend'))
return return
try: try:
@ -207,26 +212,24 @@ class BackendCfg(QDialog):
if not backend: if not backend:
QMessageBox.critical(self, self.tr('Unable to add a configured backend'), QMessageBox.critical(self, self.tr('Unable to add a configured backend'),
self.tr('The selected backend does not exist.')) self.tr('The selected backend does not exist.'))
return return
params = {} params = {}
if not bname: if not bname:
QMessageBox.critical(self, self.tr('Missing field'), QMessageBox.critical(self, self.tr('Missing field'), self.tr('Please specify a backend name'))
self.tr('Please specify a backend name'))
return return
if self.ui.nameEdit.isEnabled() and not re.match(r'^[\w\-_]+$', bname): if self.ui.nameEdit.isEnabled() and not re.match(r'^[\w\-_]+$', bname):
QMessageBox.critical(self, self.tr('Invalid value'), QMessageBox.critical(self, self.tr('Invalid value'),
self.tr('The backend name can only contain letters and digits')) self.tr('The backend name can only contain letters and digits'))
return return
if self.ui.proxyBox.isChecked(): if self.ui.proxyBox.isChecked():
params['_proxy'] = unicode(self.ui.proxyEdit.text()) params['_proxy'] = unicode(self.ui.proxyEdit.text())
if not params['_proxy']: if not params['_proxy']:
QMessageBox.critical(self, self.tr('Missing field'), QMessageBox.critical(self, self.tr('Missing field'), self.tr('Please specify a proxy URL'))
self.tr('Please specify a proxy URL'))
return return
for key, field in backend.config.iteritems(): for key, field in backend.config.iteritems():
@ -235,9 +238,8 @@ class BackendCfg(QDialog):
try: try:
value = qtvalue.get_value() value = qtvalue.get_value()
except ValueError, e: except ValueError, e:
QMessageBox.critical(self, QMessageBox.critical(self, self.tr('Invalid value'),
self.tr('Invalid value'), unicode(self.tr('Invalid value for field "%s":<br /><br />%s')) % (field.label, e))
unicode(self.tr('Invalid value for field "%s":<br /><br />%s')) % (field.label, e))
return return
params[key] = value.value params[key] = value.value
@ -270,26 +272,28 @@ class BackendCfg(QDialog):
if backend.icon_path: if backend.icon_path:
img = QImage(backend.icon_path) img = QImage(backend.icon_path)
self.ui.backendInfo.document().addResource(QTextDocument.ImageResource, QUrl('mydata://logo.png'), QVariant(img)) self.ui.backendInfo.document().addResource(QTextDocument.ImageResource, QUrl('mydata://logo.png'),
QVariant(img))
self.ui.backendInfo.setText(unicode(self.tr( self.ui.backendInfo.setText(unicode(self.tr(
'<h1>%s Backend %s</h1>' '<h1>%s Backend %s</h1>'
'<b>Version</b>: %s<br />' '<b>Version</b>: %s<br />'
'<b>Maintainer</b>: %s<br />' '<b>Maintainer</b>: %s<br />'
'<b>License</b>: %s<br />' '<b>License</b>: %s<br />'
'%s' '%s'
'<b>Description</b>: %s<br />' '<b>Description</b>: %s<br />'
'<b>Capabilities</b>: %s<br />')) '<b>Capabilities</b>: %s<br />'))
% ('<img src="mydata://logo.png" />' if backend.icon_path else '', % ('<img src="mydata://logo.png" />' if backend.icon_path else '',
backend.name.capitalize(), backend.name.capitalize(),
backend.version, backend.version,
backend.maintainer.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;'), backend.maintainer.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;'),
backend.license, backend.license,
(unicode(self.tr('<b>Website</b>: %s<br />')) % backend.website) if backend.website else '', (unicode(self.tr('<b>Website</b>: %s<br />')) % backend.website) if backend.website else '',
backend.description, backend.description,
', '.join(sorted(cap.__name__.replace('ICap', '') for cap in backend.iter_caps())))) ', '.join(sorted(cap.__name__.replace('ICap', '') for cap in backend.iter_caps()))))
if backend.has_caps(ICapAccount) and self.ui.nameEdit.isEnabled() and backend.klass.ACCOUNT_REGISTER_PROPERTIES is not None: 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()
@ -347,9 +351,8 @@ class BackendCfg(QDialog):
try: try:
v = widget.get_value() v = widget.get_value()
except ValueError, e: except ValueError, e:
QMessageBox.critical(self, QMessageBox.critical(self, self.tr('Invalid value'),
self.tr('Invalid value'), unicode(self.tr('Invalid value for field "%s":<br /><br />%s')) % (key, e))
unicode(self.tr('Invalid value for field "%s":<br /><br />%s')) % (key, e))
end = False end = False
break break
else: else:
@ -358,9 +361,8 @@ class BackendCfg(QDialog):
try: try:
backend.klass.register_account(account) backend.klass.register_account(account)
except AccountRegisterError, e: except AccountRegisterError, e:
QMessageBox.critical(self, QMessageBox.critical(self, self.tr('Error during register'),
self.tr('Error during register'), unicode(self.tr('Unable to register account %s:<br /><br />%s')) % (website, e))
unicode(self.tr('Unable to register account %s:<br /><br />%s')) % (website, e))
end = False end = False
else: else:
for key, value in account.properties.iteritems(): for key, value in account.properties.iteritems():