Skip to content
Snippets Groups Projects
Commit 2c65bba6 authored by inso's avatar inso
Browse files

A bit of refactoring

Configuring account : changing its name and the communities
parent cba7f95c
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@ RESOURCE_DIR = res/ui
COMPILED_DIR = src/cutecoin/gen_resources
#UI files to compile
UI_FILES = mainwindow.ui addAccountDialog.ui addCommunityDialog.ui communityTabWidget.ui issuanceDialog.ui transferDialog.ui addContactDialog.ui configureAccountDialog.ui communityParametersWidget.ui
UI_FILES = mainwindow.ui accountConfigurationDialog.ui addCommunityDialog.ui communityTabWidget.ui issuanceDialog.ui transferDialog.ui addContactDialog.ui communityParametersWidget.ui
#Qt resource files to compile
RESOURCES =
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddAccountDialog</class>
<widget class="QDialog" name="AddAccountDialog">
<class>AccountConfigurationDialog</class>
<widget class="QDialog" name="AccountConfigurationDialog">
<property name="geometry">
<rect>
<x>0</x>
......@@ -33,7 +33,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="accountName"/>
<widget class="QLineEdit" name="edit_accountName"/>
</item>
</layout>
</item>
......@@ -47,7 +47,7 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="pgpKeysList"/>
<widget class="QComboBox" name="combo_keysList"/>
</item>
</layout>
</item>
......@@ -61,19 +61,19 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QListView" name="communitiesList"/>
<widget class="QListView" name="list_communities"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="addCommunity">
<widget class="QPushButton" name="button_addCommunity">
<property name="text">
<string>Add a community</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeCommunity">
<widget class="QPushButton" name="button_removeCommunity">
<property name="text">
<string>Remove selected community</string>
</property>
......@@ -101,7 +101,7 @@
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>AddAccountDialog</receiver>
<receiver>AccountConfigurationDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
......@@ -117,7 +117,7 @@
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>AddAccountDialog</receiver>
<receiver>AccountConfigurationDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
......@@ -131,9 +131,9 @@
</hints>
</connection>
<connection>
<sender>addCommunity</sender>
<sender>button_addCommunity</sender>
<signal>clicked()</signal>
<receiver>AddAccountDialog</receiver>
<receiver>AccountConfigurationDialog</receiver>
<slot>openAddCommunityDialog()</slot>
<hints>
<hint type="sourcelabel">
......@@ -146,9 +146,43 @@
</hint>
</hints>
</connection>
<connection>
<sender>button_removeCommunity</sender>
<signal>clicked()</signal>
<receiver>AccountConfigurationDialog</receiver>
<slot>actionRemoveCommunity()</slot>
<hints>
<hint type="sourcelabel">
<x>290</x>
<y>237</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>149</y>
</hint>
</hints>
</connection>
<connection>
<sender>list_communities</sender>
<signal>clicked(QModelIndex)</signal>
<receiver>AccountConfigurationDialog</receiver>
<slot>actionEditCommunity()</slot>
<hints>
<hint type="sourcelabel">
<x>199</x>
<y>180</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>149</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>openAddCommunityDialog()</slot>
<slot>keyChanged(int)</slot>
<slot>actionRemoveCommunity()</slot>
<slot>actionEditCommunity()</slot>
</slots>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureAccountDialog</class>
<widget class="QDialog" name="ConfigureAccountDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Configure current account</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Global parameters</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Communities parameters</string>
</property>
</widget>
</item>
<item>
<widget class="QTabWidget" name="communitiesWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</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>accepted()</signal>
<receiver>ConfigureAccountDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ConfigureAccountDialog</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>
......@@ -35,8 +35,8 @@ class Core(object):
def addAccount(self, account):
for a in self.accounts:
if a.pgpKeyId == account.pgpKeyId:
raise KeyAlreadyUsed(account, account.pgpKeyId, a)
if a.keyId == account.keyId:
raise KeyAlreadyUsed(account, account.keyId, a)
self.accounts.append(account)
self.currentAccount = account
......
......@@ -3,7 +3,7 @@ Created on 2 févr. 2014
@author: inso
'''
from cutecoin.gen_resources.addAccountDialog_uic import Ui_AddAccountDialog
from cutecoin.gen_resources.accountConfigurationDialog_uic import Ui_AccountConfigurationDialog
from PyQt5.QtWidgets import QDialog
from cutecoin.gui.addCommunityDialog import AddCommunityDialog
from cutecoin.models.account import Account
......@@ -13,7 +13,7 @@ from cutecoin.models.account.communities.listModel import CommunitiesListModel
import gnupg
class AddAccountDialog(QDialog, Ui_AddAccountDialog):
class AddAccountDialog(QDialog, Ui_AccountConfigurationDialog):
'''
classdocs
'''
......@@ -34,27 +34,35 @@ class AddAccountDialog(QDialog, Ui_AddAccountDialog):
def setData(self):
gpg = gnupg.GPG()
self.pgpKeysList.clear()
self.combo_keysList.clear()
availableKeys = gpg.list_keys(True)
for key in availableKeys:
self.pgpKeysList.addItem(key['uids'][0])
self.combo_keysList.addItem(key['uids'][0])
self.account = Account.create(availableKeys[0]['keyid'], "", Communities())
self.pgpKeysList.setEnabled(True)
self.pgpKeysList.currentIndexChanged[int].connect(self.keyChanged)
self.communityDialog = AddCommunityDialog(self)
self.combo_keysList.setEnabled(True)
self.combo_keysList.currentIndexChanged[int].connect(self.keyChanged)
def openAddCommunityDialog(self):
self.communityDialog.setAccount(self.account)
self.communityDialog.exec_()
dialog = AddCommunityDialog(self)
dialog.setAccount(self.account)
dialog.exec_()
def actionAddCommunity(self):
self.pgpKeysList.setEnabled(False)
self.pgpKeysList.disconnect()
self.communitiesList.setModel(CommunitiesListModel(self.account))
self.combo_keysList.setEnabled(False)
self.combo_keysList.disconnect()
self.list_communities.setModel(CommunitiesListModel(self.account))
def actionRemoveCommunity(self):
#TODO:Remove selected community
pass
def actionEditCommunity(self):
#TODO: Edit selected community
pass
def keyChanged(self, keyIndex):
gpg = gnupg.GPG()
availableKeys = gpg.list_keys(True)
self.account.pgpKeyId = availableKeys[keyIndex]['keyid']
self.account.keyId = availableKeys[keyIndex]['keyid']
'''
Created on 6 mars 2014
@author: inso
'''
from cutecoin.gen_resources.accountConfigurationDialog_uic import Ui_AccountConfigurationDialog
from cutecoin.gui.addCommunityDialog import AddCommunityDialog
from cutecoin.models.account import Account
from cutecoin.models.account.communities import Communities
from cutecoin.models.account.communities.listModel import CommunitiesListModel
from PyQt5.QtWidgets import QDialog
import gnupg
class ConfigureAccountDialog(QDialog, Ui_AccountConfigurationDialog):
'''
classdocs
'''
def __init__(self, mainWindow):
'''
Constructor
'''
# Set up the user interface from Designer.
super(ConfigureAccountDialog, self).__init__()
self.setupUi(self)
self.account = mainWindow.core.currentAccount
self.setWindowTitle("Configure " + self.account.name)
self.setData()
def setData(self):
gpg = gnupg.GPG()
self.combo_keysList.clear()
availableKeys = gpg.list_keys(True)
for index, key in enumerate(availableKeys):
self.combo_keysList.addItem(key['uids'][0])
if (key['keyid']) == self.account.keyId:
self.combo_keysList.setCurrentIndex(index)
self.combo_keysList.setEnabled(False)
self.list_communities.setModel(CommunitiesListModel(self.account))
self.edit_accountName.setText(self.account.name)
def openAddCommunityDialog(self):
dialog = AddCommunityDialog(self)
dialog.setAccount(self.account)
dialog.exec_()
def actionAddCommunity(self):
self.list_communities.setModel(CommunitiesListModel(self.account))
def actionRemoveCommunity(self):
#TODO:Remove selected community
pass
def actionEditCommunity(self):
#TODO: Edit selected community
pass
......@@ -7,6 +7,7 @@ from cutecoin.gen_resources.mainwindow_uic import Ui_MainWindow
from PyQt5.QtWidgets import QMainWindow, QAction, QErrorMessage
from PyQt5.QtCore import QSignalMapper
from cutecoin.gui.addAccountDialog import AddAccountDialog
from cutecoin.gui.configureAccountDialog import ConfigureAccountDialog
from cutecoin.gui.transferMoneyDialog import TransferMoneyDialog
from cutecoin.gui.communityTabWidget import CommunityTabWidget
from cutecoin.gui.addContactDialog import AddContactDialog
......@@ -40,7 +41,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.addAccountDialog.exec_()
def actionAddAccount(self):
self.addAccountDialog.account.name = self.addAccountDialog.accountName.text()
self.addAccountDialog.account.name = self.addAccountDialog.edit_accountName.text()
try:
self.core.addAccount(self.addAccountDialog.account)
except KeyAlreadyUsed as e:
......@@ -55,13 +56,15 @@ class MainWindow(QMainWindow, Ui_MainWindow):
logging.info('Changing account to ' + self.core.currentAccount.name)
self.refreshMainWindow()
def openTransferMoneyDialog(self):
TransferMoneyDialog(self.core.currentAccount).exec_()
def openAddContactDialog(self):
AddContactDialog(self.core.currentAccount, self).exec_()
def openConfigureAccountDialog(self):
ConfigureAccountDialog(self).exec_()
'''
Refresh main window
When the selected account changes, all the widgets
......
......@@ -16,27 +16,27 @@ from cutecoin.models.person import Person
class Account(object):
'''
An account is specific to a pgpKey.
Each account has only one pgpKey, and a key can
An account is specific to a key.
Each account has only one key, and a key can
be locally referenced by only one account.
'''
def __init__(self, pgpKeyId, name, communities, wallets, contacts):
def __init__(self, keyId, name, communities, wallets, contacts):
'''
Constructor
'''
self.pgpKeyId = pgpKeyId
self.keyId = keyId
self.name = name
self.communities = communities
self.wallets = wallets
self.contacts = contacts
@classmethod
def create(cls, pgpKeyId, name, communities):
def create(cls, keyId, name, communities):
'''
Constructor
'''
wallets = Wallets()
account = cls(pgpKeyId, name, communities, wallets, [])
account = cls(keyId, name, communities, wallets, [])
for community in account.communities.communitiesList:
wallet = account.wallets.addWallet(community.currency)
wallet.refreshCoins(community, account.keyFingerprint())
......@@ -44,7 +44,7 @@ class Account(object):
@classmethod
def load(cls, jsonData):
pgpKeyId = jsonData['pgpKeyId']
keyId = jsonData['keyId']
name = jsonData['name']
communities = Communities()
wallets = Wallets()
......@@ -53,7 +53,7 @@ class Account(object):
for contactData in jsonData['contacts']:
contacts.append(Person.fromJson(contactData))
account = cls(pgpKeyId, name, communities, wallets, contacts)
account = cls(keyId, name, communities, wallets, contacts)
for communityData in jsonData['communities']:
account.communities.communitiesList.append(Community.load(communityData, account))
......@@ -69,10 +69,10 @@ class Account(object):
def keyFingerprint(self):
gpg = gnupg.GPG()
availableKeys = gpg.list_keys()
logging.debug(self.pgpKeyId)
logging.debug(self.keyId)
for k in availableKeys:
logging.debug(k)
if k['keyid'] == self.pgpKeyId:
if k['keyid'] == self.keyId:
return k['fingerprint']
return ""
......@@ -133,7 +133,7 @@ class Account(object):
def jsonify(self):
data = {'name' : self.name,
'pgpKeyId' : self.pgpKeyId,
'keyId' : self.keyId,
'communities' : self.communities.jsonify(self.wallets),
'contacts' : self.jsonifyContacts()}
return data
......
......@@ -20,8 +20,8 @@ class Communities(object):
def addCommunity(self, mainNode, keyFingerprint):
'''
Add a community with a mainNode and the pgpFingerprint of the account
Check if the pgpFingerprint is present in the community members list
Add a community with a mainNode and the fingerprint of the account
Check if the fingerprint is present in the community members list
If its not, the account isnt added and an error is raised.
'''
community = Community.create(mainNode)
......
......@@ -24,12 +24,12 @@ class Person(object):
@classmethod
def lookup(cls, pgpFingerprint, community):
def lookup(cls, fingerprint, community):
'''
Create a person from the pgpFingerprint found in a community
Create a person from the fngerprint found in a community
'''
keys = community.ucoinRequest(ucoin.pks.Lookup(),
get_args={'search':"0x"+pgpFingerprint, 'op':'index'})['keys']
get_args={'search':"0x"+fingerprint, 'op':'index'})['keys']
if len(keys) > 0:
json = keys[0]['key']
name = json['name']
......@@ -37,7 +37,7 @@ class Person(object):
email = json['email']
return cls(name, fingerprint, email)
else:
raise PersonNotFoundError(pgpFingerprint, "pgpFingerprint", community)
raise PersonNotFoundError(fingerprint, "fingerprint", community)
return None
@classmethod
......
......@@ -47,8 +47,8 @@ class Wallet(object):
return value
#TODO: Refresh coins when changing current account
def refreshCoins(self, pgpFingerprint):
dataList = self.community.ucoinRequest(ucoin.hdc.coins.List({'pgp_fingerprint':pgpFingerprint}))
def refreshCoins(self, fingerprint):
dataList = self.community.ucoinRequest(ucoin.hdc.coins.List({'pgp_fingerprint':fingerprint}))
for issaunces in dataList['coins']:
issuer = issaunces['issuer']
for coinsIds in issaunces['ids']:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment