diff --git a/Makefile b/Makefile index ad67e6e185217fec99d76ed84c74fbc7d32a0ad3..8f1d8d15dc26238a2e086f4b341ba1c370e41ec5 100644 --- a/Makefile +++ b/Makefile @@ -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 = diff --git a/res/ui/addAccountDialog.ui b/res/ui/accountConfigurationDialog.ui similarity index 69% rename from res/ui/addAccountDialog.ui rename to res/ui/accountConfigurationDialog.ui index 8cba07b0c43a4b5bf83c90614903a6e083c12533..f480b5762c3ace1d987e8cca24e0c06bf855b2f7 100644 --- a/res/ui/addAccountDialog.ui +++ b/res/ui/accountConfigurationDialog.ui @@ -1,7 +1,7 @@ <?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> diff --git a/res/ui/configureAccountDialog.ui b/res/ui/configureAccountDialog.ui deleted file mode 100644 index 0ec37d49219146d317b9a1f2640966ec33663eda..0000000000000000000000000000000000000000 --- a/res/ui/configureAccountDialog.ui +++ /dev/null @@ -1,88 +0,0 @@ -<?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> diff --git a/src/cutecoin/core/__init__.py b/src/cutecoin/core/__init__.py index 7aa15265c0918069ab911b6b2b116ef4c4fc0b60..e435781346c0fe46b721b78891d330217baa408a 100644 --- a/src/cutecoin/core/__init__.py +++ b/src/cutecoin/core/__init__.py @@ -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 diff --git a/src/cutecoin/gui/addAccountDialog.py b/src/cutecoin/gui/addAccountDialog.py index 3dcbca64d03f275c79d557388c8069ea67c1ca40..66cf421f777c5580417307fe3b966cdbad83675a 100644 --- a/src/cutecoin/gui/addAccountDialog.py +++ b/src/cutecoin/gui/addAccountDialog.py @@ -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'] diff --git a/src/cutecoin/gui/configureAccountDialog.py b/src/cutecoin/gui/configureAccountDialog.py new file mode 100644 index 0000000000000000000000000000000000000000..776c45ef5a5e71b47daac1cfbbd425d8bcd45a89 --- /dev/null +++ b/src/cutecoin/gui/configureAccountDialog.py @@ -0,0 +1,62 @@ +''' +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 + + diff --git a/src/cutecoin/gui/mainWindow.py b/src/cutecoin/gui/mainWindow.py index 8be75f1714c3da111f1c05a5c628e4c607307acc..090a9b056fa9790c035e7e8e0d3b652a15fd542c 100644 --- a/src/cutecoin/gui/mainWindow.py +++ b/src/cutecoin/gui/mainWindow.py @@ -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 diff --git a/src/cutecoin/models/account/__init__.py b/src/cutecoin/models/account/__init__.py index 0a55405f38f71dfcf9572f1adc56f260330c937d..9fcbc46428d20ab672483cc152d31f4f3994a564 100644 --- a/src/cutecoin/models/account/__init__.py +++ b/src/cutecoin/models/account/__init__.py @@ -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 diff --git a/src/cutecoin/models/account/communities/__init__.py b/src/cutecoin/models/account/communities/__init__.py index 0e04bb60ca47c43f1526fbd512d570bb78d350ff..180d560480b0c9d285a7fe737f151ed8a06bac1f 100644 --- a/src/cutecoin/models/account/communities/__init__.py +++ b/src/cutecoin/models/account/communities/__init__.py @@ -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) diff --git a/src/cutecoin/models/person/__init__.py b/src/cutecoin/models/person/__init__.py index 4c837608872d2266f3f4276eb176f22022958a7d..30e913129d9e1f579c621e5c46a52cbf8bab65bc 100644 --- a/src/cutecoin/models/person/__init__.py +++ b/src/cutecoin/models/person/__init__.py @@ -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 diff --git a/src/cutecoin/models/wallet/__init__.py b/src/cutecoin/models/wallet/__init__.py index 1de4d1a6a6ce80851a1f443c44f448b07282f7ab..1858a91912cbeaf2b4ea4354e81abb3a0a6a57c3 100644 --- a/src/cutecoin/models/wallet/__init__.py +++ b/src/cutecoin/models/wallet/__init__.py @@ -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']: