Commit 10215d1e authored by Romain Bignon's avatar Romain Bignon

add a repositories editor in weboob-config-qt

parent 59b4e78f
......@@ -33,11 +33,29 @@ from weboob.core.repositories import IProgress, ModuleInstallError
from weboob.core.backendscfg import BackendAlreadyExists
from weboob.capabilities.account import ICapAccount, Account, AccountRegisterError
from weboob.tools.application.qt.backendcfg_ui import Ui_BackendCfg
from weboob.tools.application.qt.reposdlg_ui import Ui_RepositoriesDlg
from weboob.tools.ordereddict import OrderedDict
from weboob.tools.misc import to_unicode
from .qt import QtValue
class RepositoriesDialog(QDialog):
def __init__(self, filename, parent=None):
QDialog.__init__(self, parent)
self.filename = filename
self.ui = Ui_RepositoriesDlg()
self.ui.setupUi(self)
self.connect(self.ui.buttonBox, SIGNAL('accepted()'), self.save)
with open(self.filename, 'r') as fp:
self.ui.reposEdit.setPlainText(fp.read())
def save(self):
with open(self.filename, 'w') as fp:
fp.write(self.ui.reposEdit.toPlainText())
self.accept()
class IconFetcher(QThread):
def __init__(self, weboob, item, minfo):
QThread.__init__(self)
......@@ -49,6 +67,17 @@ class IconFetcher(QThread):
self.weboob.repositories.retrieve_icon(self.minfo)
self.emit(SIGNAL('retrieved'), self)
class ProgressDialog(IProgress, QProgressDialog):
def __init__(self, *args, **kwargs):
QProgressDialog.__init__(self, *args, **kwargs)
def progress(self, percent, message):
self.setValue(int(percent*100))
self.setLabelText(message)
def error(self, message):
QMessageBox.critical(self, self.tr('Error'), '%s' % message, QMessageBox.Ok)
class BackendCfg(QDialog):
def __init__(self, weboob, caps=None, parent=None):
QDialog.__init__(self, parent)
......@@ -77,13 +106,11 @@ class BackendCfg(QDialog):
self.icon_cache = {}
self.icon_threads = {}
for name, module in sorted(self.weboob.repositories.get_all_modules_info(self.caps).iteritems()):
item = QListWidgetItem(name.capitalize())
self.set_icon(item, module)
self.ui.modulesList.addItem(item)
self.loadModules()
self.loadBackendsList()
self.connect(self.ui.updateButton, SIGNAL('clicked()'), self.updateModules)
self.connect(self.ui.repositoriesButton, SIGNAL('clicked()'), self.editRepositories)
self.connect(self.ui.backendsList, SIGNAL('itemClicked(QTreeWidgetItem *, int)'),
self.backendClicked)
self.connect(self.ui.backendsList, SIGNAL('itemChanged(QTreeWidgetItem *, int)'),
......@@ -133,6 +160,32 @@ class BackendCfg(QDialog):
self.icon_threads.pop(minfo.name, None)
def updateModules(self):
self.ui.configFrame.hide()
pd = ProgressDialog('Update of modules', "Cancel", 0, 100, self)
pd.setWindowModality(Qt.WindowModal)
try:
self.weboob.repositories.update(pd)
except ModuleInstallError, err:
QMessageBox.critical(self, self.tr('Update error'),
unicode(self.tr('Unable to update modules: %s' % (err))),
QMessageBox.Ok)
pd.setValue(100)
self.loadModules()
QMessageBox.information(self, self.tr('Update of modules'),
self.tr('Modules updated!'), QMessageBox.Ok)
def editRepositories(self):
if RepositoriesDialog(self.weboob.repositories.sources_list).exec_():
self.updateModules()
def loadModules(self):
self.ui.modulesList.clear()
for name, module in sorted(self.weboob.repositories.get_all_modules_info(self.caps).iteritems()):
item = QListWidgetItem(name.capitalize())
self.set_icon(item, module)
self.ui.modulesList.addItem(item)
def askInstallModule(self, minfo):
reply = QMessageBox.question(self, self.tr('Install a module'),
unicode(self.tr("Module %s is not installed. Do you want to install it?")) % minfo.name,
......@@ -144,18 +197,14 @@ class BackendCfg(QDialog):
return self.installModule(minfo)
def installModule(self, minfo):
pd = QProgressDialog('Installation of %s' % minfo.name, "Cancel", 0, 100, self)
pd = ProgressDialog('Installation of %s' % minfo.name, "Cancel", 0, 100, self)
pd.setWindowModality(Qt.WindowModal)
class Progress(IProgress):
def progress(self, percent, message):
pd.setValue(int(percent*100))
pd.setLabelText(message)
try:
self.weboob.repositories.install(minfo, Progress())
self.weboob.repositories.install(minfo, pd)
except ModuleInstallError, err:
QMessageBox.critical(self, self.tr('Install error'),
unicode(self.tr('Unable to install mode %s: %s' % (minfo.name, err))),
unicode(self.tr('Unable to install module %s: %s' % (minfo.name, err))),
QMessageBox.Ok)
pd.setValue(100)
return True
......
......@@ -7,13 +7,61 @@
<x>0</x>
<y>0</y>
<width>622</width>
<height>484</height>
<height>516</height>
</rect>
</property>
<property name="windowTitle">
<string>Backends configuration</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>4</number>
</property>
<item>
<widget class="QFrame" name="frame_3">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="margin">
<number>4</number>
</property>
<item>
<widget class="QPushButton" name="updateButton">
<property name="text">
<string>Update modules</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="repositoriesButton">
<property name="text">
<string>Repositories</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QSplitter" name="splitter_2">
<property name="orientation">
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RepositoriesDlg</class>
<widget class="QDialog" name="RepositoriesDlg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Repositories</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextEdit" name="reposEdit"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>RepositoriesDlg</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment