diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..1a3b7868b6f804de81e8da68dea33e4e80ae2d3b --- /dev/null +++ b/Makefile @@ -0,0 +1,36 @@ +###### EDIT ##################### +#Directory with ui and resource files +RESOURCE_DIR = res/ui + +#Directory for compiled resources +COMPILED_DIR = src/cutecoin/gen_resources + +#UI files to compile +UI_FILES = mainwindow.ui addAccountDialog.ui addCommunityDialog.ui +#Qt resource files to compile +RESOURCES = + +#pyuic4 and pyrcc4 binaries +PYUIC = pyuic5 +PYRCC = pyrcc5 + +################################# +# DO NOT EDIT FOLLOWING + +COMPILED_UI = $(UI_FILES:%.ui=$(COMPILED_DIR)/%_uic.py) +COMPILED_RESOURCES = $(RESOURCES:%.qrc=$(COMPILED_DIR)/%_rc.py) + +all : resources ui + +resources : $(COMPILED_RESOURCES) + +ui : $(COMPILED_UI) + +$(COMPILED_DIR)/%_uic.py : $(RESOURCE_DIR)/%.ui + $(PYUIC) $< -o $@ + +$(COMPILED_DIR)/%_rc.py : $(RESOURCE_DIR)/%.qrc + $(PYRCC) $< -o $@ + +clean : + $(RM) $(COMPILED_UI) $(COMPILED_RESOURCES) $(COMPILED_UI:.py=.pyc) $(COMPILED_RESOURCES:.py=.pyc) \ No newline at end of file diff --git a/doc/uml/models.png b/doc/uml/models.png new file mode 100644 index 0000000000000000000000000000000000000000..a4314ae24e7027f32e61959c854ac9f5ceb327ba Binary files /dev/null and b/doc/uml/models.png differ diff --git a/doc/uml/models.pu b/doc/uml/models.pu new file mode 100644 index 0000000000000000000000000000000000000000..672dc8979f57667d6ed1b4d5c94a189c03db3f97 --- /dev/null +++ b/doc/uml/models.pu @@ -0,0 +1,44 @@ +@startuml + +class Account { + pgpkey +} + +Account --> "0..*" Community : is a member of +Account --> "0..*" Node : trusts +Account --> "0..*" Node : send transactions with +Account --> "*" Transaction : send +Account --> "*" Transaction : receive +Account --> "0..*" Wallet : owns + +class Community { +} + +Community "1" -- "1" Currency : uses +Community "1" --> "1..*" Node : known nodes + +class Node { + address + port + auth +} + +Node --> "1" Community + +class Transaction { + value + currency + sender + receiver +} + +class Wallet { + currency + coins +} + + + +@enduml + + diff --git a/res/ui/addAccountDialog.ui b/res/ui/addAccountDialog.ui index a65a745a7a2233c15a527d7845532208bf533916..807ffccb5bb68c291718b916f5808c2e05a58c92 100644 --- a/res/ui/addAccountDialog.ui +++ b/res/ui/addAccountDialog.ui @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <class>Dialog</class> - <widget class="QDialog" name="Dialog"> + <class>AddAccountDialog</class> + <widget class="QDialog" name="AddAccountDialog"> <property name="geometry"> <rect> <x>0</x> @@ -11,7 +11,10 @@ </rect> </property> <property name="windowTitle"> - <string>Dialog</string> + <string>Add an account</string> + </property> + <property name="modal"> + <bool>true</bool> </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> @@ -56,10 +59,28 @@ <property name="title"> <string>Communities membership</string> </property> - <layout class="QHBoxLayout" name="horizontalLayout_3"> + <layout class="QVBoxLayout" name="verticalLayout_3"> <item> <widget class="QTableView" name="communitiesTable"/> </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QPushButton" name="addCommunity"> + <property name="text"> + <string>Add a community</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="removeCommunity"> + <property name="text"> + <string>Remove selected community</string> + </property> + </widget> + </item> + </layout> + </item> </layout> </widget> </item> @@ -80,7 +101,7 @@ <connection> <sender>buttonBox</sender> <signal>accepted()</signal> - <receiver>Dialog</receiver> + <receiver>AddAccountDialog</receiver> <slot>accept()</slot> <hints> <hint type="sourcelabel"> @@ -96,7 +117,7 @@ <connection> <sender>buttonBox</sender> <signal>rejected()</signal> - <receiver>Dialog</receiver> + <receiver>AddAccountDialog</receiver> <slot>reject()</slot> <hints> <hint type="sourcelabel"> @@ -109,5 +130,24 @@ </hint> </hints> </connection> + <connection> + <sender>addCommunity</sender> + <signal>clicked()</signal> + <receiver>AddAccountDialog</receiver> + <slot>openAddCommunityDialog()</slot> + <hints> + <hint type="sourcelabel"> + <x>109</x> + <y>237</y> + </hint> + <hint type="destinationlabel"> + <x>199</x> + <y>149</y> + </hint> + </hints> + </connection> </connections> + <slots> + <slot>openAddCommunityDialog()</slot> + </slots> </ui> diff --git a/res/ui/addCommunityDialog.ui b/res/ui/addCommunityDialog.ui new file mode 100644 index 0000000000000000000000000000000000000000..520b3d138069728e9662ac74a4bce5a04e8a2f30 --- /dev/null +++ b/res/ui/addCommunityDialog.ui @@ -0,0 +1,117 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>AddCommunityDialog</class> + <widget class="QDialog" name="AddCommunityDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Add a community</string> + </property> + <property name="modal"> + <bool>true</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QGroupBox" name="groupBox_2"> + <property name="title"> + <string>Communities nodes</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <widget class="QTableView" name="communitiesTable"/> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QLineEdit" name="lineEdit"> + <property name="text"> + <string/> + </property> + <property name="placeholderText"> + <string>Server</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lineEdit_2"> + <property name="text"> + <string/> + </property> + <property name="placeholderText"> + <string>Port</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox"> + <property name="text"> + <string>Auth</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="removeCommunity"> + <property name="text"> + <string>Add</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </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>AddCommunityDialog</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>AddCommunityDialog</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/res/ui/mainwindow.ui b/res/ui/mainwindow.ui index b2cda408026e35f696fa337e1a1fb3993d59255f..c9c3e646f3b9801066a7eccdd8172b2c4c7d8960 100644 --- a/res/ui/mainwindow.ui +++ b/res/ui/mainwindow.ui @@ -152,8 +152,7 @@ <string>Account</string> </property> <addaction name="actionChange_account"/> - <addaction name="actionManage_accounts"/> - <addaction name="actionConfigure_trustable_nodes"/> + <addaction name="actionAdd_account"/> </widget> <widget class="QMenu" name="menuEdit"> <property name="title"> @@ -216,7 +215,32 @@ <string>Remove contact</string> </property> </action> + <action name="actionAdd_account"> + <property name="text"> + <string>Add account</string> + </property> + </action> </widget> <resources/> - <connections/> + <connections> + <connection> + <sender>actionAdd_account</sender> + <signal>triggered()</signal> + <receiver>MainWindow</receiver> + <slot>openAddAccountDialog()</slot> + <hints> + <hint type="sourcelabel"> + <x>-1</x> + <y>-1</y> + </hint> + <hint type="destinationlabel"> + <x>225</x> + <y>199</y> + </hint> + </hints> + </connection> + </connections> + <slots> + <slot>openAddAccountDialog()</slot> + </slots> </ui> diff --git a/src/cutecoin/__init__.py b/src/cutecoin/__init__.py index e9a7bd2401ebf4db17c0a66bc79995fcac2f43a0..16edd0be597e42e43731472412ec411392332636 100644 --- a/src/cutecoin/__init__.py +++ b/src/cutecoin/__init__.py @@ -10,7 +10,6 @@ from cutecoin.models.account import Account if __name__ == '__main__': app = QApplication(sys.argv) - acc = Account() window = MainWindow() window.show() sys.exit(app.exec_()) diff --git a/src/cutecoin/gui/addAccountDialog.py b/src/cutecoin/gui/addAccountDialog.py new file mode 100644 index 0000000000000000000000000000000000000000..661cee2b77b33acc91afecf7c4f0a799958d9d8c --- /dev/null +++ b/src/cutecoin/gui/addAccountDialog.py @@ -0,0 +1,28 @@ +''' +Created on 2 févr. 2014 + +@author: inso +''' +from cutecoin.gen_resources.addAccountDialog_uic import Ui_AddAccountDialog +from PyQt5.QtWidgets import QDialog +from cutecoin.gui.addCommunityDialog import AddCommunityDialog + +class AddAccountDialog(QDialog, Ui_AddAccountDialog): + ''' + classdocs + ''' + + + def __init__(self): + ''' + Constructor + ''' + # Set up the user interface from Designer. + super(AddAccountDialog, self).__init__() + self.setupUi(self) + print("stiio") + + def openAddCommunityDialog(self): + dialog = AddCommunityDialog() + dialog.show() + diff --git a/src/cutecoin/gui/addCommunityDialog.py b/src/cutecoin/gui/addCommunityDialog.py new file mode 100644 index 0000000000000000000000000000000000000000..8598d3960dc7bef21fc40c1bd48d7dbb9fb19e0a --- /dev/null +++ b/src/cutecoin/gui/addCommunityDialog.py @@ -0,0 +1,21 @@ +''' +Created on 2 févr. 2014 + +@author: inso +''' +from cutecoin.gen_resources.addCommunityDialog_uic import Ui_AddCommunityDialog +from PyQt5.QtWidgets import QDialog + +class AddCommunityDialog(QDialog, Ui_AddCommunityDialog): + ''' + classdocs + ''' + + + def __init__(self): + ''' + Constructor + ''' + super(AddCommunityDialog, self).__init__() + self.setupUi(self) + diff --git a/src/cutecoin/gui/mainWindow.py b/src/cutecoin/gui/mainWindow.py index 973ec967e8dc660ca47a44a936d49b5b229e4631..9a5683118f004987b0f692e6f3dbb4172b055da5 100644 --- a/src/cutecoin/gui/mainWindow.py +++ b/src/cutecoin/gui/mainWindow.py @@ -5,7 +5,7 @@ Created on 1 févr. 2014 ''' from cutecoin.gen_resources.mainwindow_uic import Ui_MainWindow from PyQt5.QtWidgets import QMainWindow - +from cutecoin.gui.addAccountDialog import AddAccountDialog class MainWindow(QMainWindow, Ui_MainWindow): ''' @@ -20,3 +20,9 @@ class MainWindow(QMainWindow, Ui_MainWindow): # Set up the user interface from Designer. super(MainWindow, self).__init__() self.setupUi(self) + + def openAddAccountDialog(self): + dialog = AddAccountDialog() + print("shoow") + dialog.show() + print("shoow2") \ No newline at end of file diff --git a/src/cutecoin/models/account.py b/src/cutecoin/models/account.py index 936652d38965c739dd5ea267d22ab5808acb06ac..6d9a4a46a3cd2142d16edbdf76307b32238410e7 100644 --- a/src/cutecoin/models/account.py +++ b/src/cutecoin/models/account.py @@ -11,12 +11,18 @@ class Account(object): classdocs ''' - def __init__(self): + def __init__(self, pgpKey, name, communities): ''' Constructor ''' + self.pgpKey = pgpKey + self.name = name + self.communities = communities self.transactionNodes = [] self.trustableNodes = [] + self.wallets = [] + self.receivedTransactions = [] + self.sentTransactions = [] def addTransactionNode(self, node): self.transactionNodes.append(node) diff --git a/src/cutecoin/models/coin.py b/src/cutecoin/models/coin.py new file mode 100644 index 0000000000000000000000000000000000000000..5188e01055f068659320528c4b998ba41eaa4e40 --- /dev/null +++ b/src/cutecoin/models/coin.py @@ -0,0 +1,17 @@ +''' +Created on 2 févr. 2014 + +@author: inso +''' + +class Coin(object): + ''' + classdocs + ''' + + + def __init__(self, number): + ''' + Constructor + ''' + self.number = number diff --git a/src/cutecoin/models/community.py b/src/cutecoin/models/community.py index 73dd4d5937befac765711ebcd05ab31378c196c1..1e085d070f82fd47fc2513cd7be512b567b3056e 100644 --- a/src/cutecoin/models/community.py +++ b/src/cutecoin/models/community.py @@ -4,13 +4,56 @@ Created on 1 févr. 2014 @author: inso ''' -class communityModel(object): +import ucoinpy as ucoin + +class Community(object): ''' classdocs ''' - def __init__(self, params): + def __init__(self, mainNode, currency): + ''' + Constructor + ''' + self.knowNodes = [] + self.knowNodes.append(mainNode) + + def members(self): + ''' + Listing members of a community + ''' + + # TODO : Try connecting with nodes of the list + # if the first fails + # Maybe create a method + ucoin.settings['server'] = self.knowNodes[0].address + ucoin.settings['port'] = self.knowNodes[0].port + ucoin.settings['auth'] = self.knowNodes[0].auth + + members = ucoin.hdc.amendments.view.Members( ucoin.hdc.amendments.Current ) + return members + +class CommunitiesManager(object): + ''' + classdocs + ''' + def __init__(self): ''' Constructor ''' + self.communities = [] + + def getCommunity(self, currency): + for com in self.communities: + if com.currency == currency: + return com + + def addCommunity(self, node): + ucoin.settings['server'] = node.address + ucoin.settings['port'] = node.port + ucoin.settings['auth'] = node.auth + + currentAmendment = ucoin.hdc.amendments.Current.get(self) + currency = currentAmendment['currency'] + self.communities.append(Community(node), currency) diff --git a/src/cutecoin/models/transaction.py b/src/cutecoin/models/transaction.py index 766a906a9c258044586264334c8e682f31a9c6f9..7b9496a1eb90baf8eb7f7955352812b83fbca68c 100644 --- a/src/cutecoin/models/transaction.py +++ b/src/cutecoin/models/transaction.py @@ -4,13 +4,17 @@ Created on 1 févr. 2014 @author: inso ''' -class TransactionModel(object): +class Transaction(object): ''' classdocs ''' - def __init__(self, params): + def __init__(self, value, sender, receiver, currency): ''' Constructor ''' + self.value = value + self.sender = sender + self.receiver = receiver + self.currency = currency diff --git a/src/cutecoin/models/wallet.py b/src/cutecoin/models/wallet.py index 9d6e49295d72a6a016331c39ae5b8d6e4eb2bd53..fb9c9aa12d5e49bd433ee460dab78624b78012cc 100644 --- a/src/cutecoin/models/wallet.py +++ b/src/cutecoin/models/wallet.py @@ -4,13 +4,16 @@ Created on 1 févr. 2014 @author: inso ''' -class WalletModel(object): +class Wallet(object): ''' classdocs ''' - def __init__(self, params): + def __init__(self, currency): ''' Constructor ''' + self.initialValue = 0 + self.coins = [] + self.currency = currency