Skip to content
Snippets Groups Projects
Commit 4e7668d4 authored by inso's avatar inso
Browse files

Continuing refactoring...

parent 0834a1cc
No related branches found
No related tags found
No related merge requests found
...@@ -126,6 +126,9 @@ ...@@ -126,6 +126,9 @@
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="placeholderText"> <property name="placeholderText">
<string>Please repeat your password</string> <string>Please repeat your password</string>
</property> </property>
...@@ -333,18 +336,50 @@ ...@@ -333,18 +336,50 @@
</hints> </hints>
</connection> </connection>
<connection> <connection>
<sender>button_generate</sender> <sender>edit_email</sender>
<signal>clicked()</signal> <signal>textChanged(QString)</signal>
<receiver>AccountConfigurationDialog</receiver> <receiver>AccountConfigurationDialog</receiver>
<slot>open_generate_account_key()</slot> <slot>action_edit_account_key()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>224</x> <x>199</x>
<y>221</y> <y>69</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>199</x> <x>199</x>
<y>149</y> <y>118</y>
</hint>
</hints>
</connection>
<connection>
<sender>edit_password</sender>
<signal>textChanged(QString)</signal>
<receiver>AccountConfigurationDialog</receiver>
<slot>action_edit_account_key()</slot>
<hints>
<hint type="sourcelabel">
<x>199</x>
<y>98</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>118</y>
</hint>
</hints>
</connection>
<connection>
<sender>edit_password_repeat</sender>
<signal>textChanged(QString)</signal>
<receiver>AccountConfigurationDialog</receiver>
<slot>action_edit_account_key()</slot>
<hints>
<hint type="sourcelabel">
<x>199</x>
<y>127</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>118</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
...@@ -358,5 +393,6 @@ ...@@ -358,5 +393,6 @@
<slot>previous()</slot> <slot>previous()</slot>
<slot>open_import_key()</slot> <slot>open_import_key()</slot>
<slot>open_generate_account_key()</slot> <slot>open_generate_account_key()</slot>
<slot>action_edit_account_key()</slot>
</slots> </slots>
</ui> </ui>
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<item> <item>
<widget class="QStackedWidget" name="stacked_pages"> <widget class="QStackedWidget" name="stacked_pages">
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="page_init"> <widget class="QWidget" name="page_init">
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
......
'''
Created on 22 mai 2014
@author: inso
'''
from ucoinpy.key import SigningKey
import re
import logging
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QMessageBox, QProgressDialog
from PyQt5.QtCore import QThread, pyqtSignal
from cutecoin.gen_resources.generateKeyDialog_uic import Ui_GenerateKeyDialog
class TaskGenKey(QThread):
taskFinished = pyqtSignal()
def run(self):
self.key = self.account.gpg.gen_key(self.input_data)
self.taskFinished.emit()
class GenerateAccountKeyDialog(QDialog, Ui_GenerateKeyDialog):
'''
classdocs
'''
def __init__(self, account, parent=None):
'''
Constructor
'''
super(GenerateAccountKeyDialog, self).__init__()
self.setupUi(self)
self.account = account
self.main_window = parent
self.button_box.button(QDialogButtonBox.Ok).setEnabled(False)
def accept(self):
name = self.edit_name.text()
password = self.edit_password.text()
password_repeat = self.edit_password_repeat.text()
salt = self.edit_email.text()
def gen_finished(self):
self.progress_dialog.close()
self.account.key = SigningKey(self.salt, self.password)
logging.debug("Key generated : " + self.account.keyid)
QMessageBox.information(self, "Key generation", "Key " +
self.account.key.pubkey + " has been generated",
QMessageBox.Ok)
self.main_window.label_pubkey.setText("Key : " + self.account.key.public_key)
self.main_window.button_next.setEnabled(True)
self.close()
def check(self):
if len(self.edit_password.text()) < 8:
self.label_errors.setText("Please enter a password with more than 8 characters")
self.button_box.button(QDialogButtonBox.Ok).setEnabled(False)
return
elif self.edit_password.text() != self.edit_password_repeat.text():
self.label_errors.setText("Passwords do not match")
self.button_box.button(QDialogButtonBox.Ok).setEnabled(False)
return
else:
pattern = re.compile("([A-Za-z-.]+ )([A-Za-z-.]+( )*)+")
if not pattern.match(self.edit_name.text()):
self.label_errors.setText("Please enter your name and family name.")
self.button_box.button(QDialogButtonBox.Ok).setEnabled(False)
return
self.label_errors.setText("")
self.button_box.button(QDialogButtonBox.Ok).setEnabled(True)
...@@ -117,12 +117,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -117,12 +117,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.refresh_wallet_content(QModelIndex()) self.refresh_wallet_content(QModelIndex())
def refresh_wallet_content(self, index): def refresh_wallet_content(self, index):
if index.isValid(): pass
current_wallet = self.core.current_account.wallets[index.row()]
self.list_wallet_content.setModel(CoinsListModel(current_wallet,
current_wallet.coins))
else:
self.list_wallet_content.setModel(CoinsListModel(None, []))
def import_account(self): def import_account(self):
dialog = ImportAccountDialog(self.core, self) dialog = ImportAccountDialog(self.core, self)
......
...@@ -3,8 +3,9 @@ Created on 6 mars 2014 ...@@ -3,8 +3,9 @@ Created on 6 mars 2014
@author: inso @author: inso
''' '''
import logging
from ucoinpy.key import SigningKey
from cutecoin.gen_resources.accountConfigurationDialog_uic import Ui_AccountConfigurationDialog from cutecoin.gen_resources.accountConfigurationDialog_uic import Ui_AccountConfigurationDialog
from cutecoin.gui.generateAccountKeyDialog import GenerateAccountKeyDialog
from cutecoin.gui.processConfigureCommunity import ProcessConfigureCommunity from cutecoin.gui.processConfigureCommunity import ProcessConfigureCommunity
from cutecoin.models.account.communities.listModel import CommunitiesListModel from cutecoin.models.account.communities.listModel import CommunitiesListModel
from cutecoin.tools.exceptions import KeyAlreadyUsed, Error from cutecoin.tools.exceptions import KeyAlreadyUsed, Error
...@@ -45,9 +46,10 @@ class StepPageInit(Step): ...@@ -45,9 +46,10 @@ class StepPageInit(Step):
self.config_dialog.list_communities.setModel(model) self.config_dialog.list_communities.setModel(model)
self.config_dialog.button_previous.setEnabled(False) self.config_dialog.button_previous.setEnabled(False)
self.config_dialog.button_next.setEnabled(False)
class StepPageGPG(Step): class StepPageKey(Step):
''' '''
First step when adding a community First step when adding a community
''' '''
...@@ -55,9 +57,22 @@ class StepPageGPG(Step): ...@@ -55,9 +57,22 @@ class StepPageGPG(Step):
super().__init__(config_dialog) super().__init__(config_dialog)
def is_valid(self): def is_valid(self):
return self.config_dialog.account.keyid != '' if len(self.config_dialog.edit_password.text()) < 8:
return False
if len(self.config_dialog.edit_email.text()) < 2:
return False
if self.config_dialog.edit_password.text() != \
self.config_dialog.edit_password_repeat.text():
return False
return True
def process_next(self): def process_next(self):
salt = self.config_dialog.edit_email.text()
password = self.config_dialog.edit_password.text()
self.config_dialog.account.key = SigningKey(salt, password)
model = CommunitiesListModel(self.config_dialog.account) model = CommunitiesListModel(self.config_dialog.account)
self.config_dialog.list_communities.setModel(model) self.config_dialog.list_communities.setModel(model)
...@@ -82,11 +97,11 @@ class StepPageCommunities(Step): ...@@ -82,11 +97,11 @@ class StepPageCommunities(Step):
''' '''
server = self.config_dialog.lineedit_server.text() server = self.config_dialog.lineedit_server.text()
port = self.config_dialog.spinbox_port.value() port = self.config_dialog.spinbox_port.value()
default_node = Node.create(server, port, trust=True, hoster=True) default_node = Node.create(server, port)
account = self.config_dialog.account account = self.config_dialog.account
self.config_dialog.community = account.communities.add_community( self.config_dialog.community = account.communities.add_community(
default_node) default_node)
account.wallets.add_wallet(account.keyid, account.wallets.add_wallet(account.key,
self.config_dialog.community) self.config_dialog.community)
self.config_dialog.refresh() self.config_dialog.refresh()
...@@ -112,10 +127,10 @@ class ProcessConfigureAccount(QDialog, Ui_AccountConfigurationDialog): ...@@ -112,10 +127,10 @@ class ProcessConfigureAccount(QDialog, Ui_AccountConfigurationDialog):
self.account = account self.account = account
self.core = core self.core = core
step_init = StepPageInit(self) step_init = StepPageInit(self)
step_gpg = StepPageGPG(self) step_key = StepPageKey(self)
step_communities = StepPageCommunities(self) step_communities = StepPageCommunities(self)
step_init.next_step = step_gpg step_init.next_step = step_key
step_gpg.next_step = step_communities step_key.next_step = step_communities
self.step = step_init self.step = step_init
self.step.display_page() self.step.display_page()
if self.account is None: if self.account is None:
...@@ -126,6 +141,7 @@ class ProcessConfigureAccount(QDialog, Ui_AccountConfigurationDialog): ...@@ -126,6 +141,7 @@ class ProcessConfigureAccount(QDialog, Ui_AccountConfigurationDialog):
self.setWindowTitle("Configure " + self.account.name) self.setWindowTitle("Configure " + self.account.name)
def open_process_add_community(self): def open_process_add_community(self):
logging.debug("Opening configure community dialog")
dialog = ProcessConfigureCommunity(self.account, None) dialog = ProcessConfigureCommunity(self.account, None)
dialog.accepted.connect(self.action_add_community) dialog.accepted.connect(self.action_add_community)
dialog.exec_() dialog.exec_()
...@@ -144,42 +160,18 @@ class ProcessConfigureAccount(QDialog, Ui_AccountConfigurationDialog): ...@@ -144,42 +160,18 @@ class ProcessConfigureAccount(QDialog, Ui_AccountConfigurationDialog):
def action_edit_community(self): def action_edit_community(self):
self.list_communities.setModel(CommunitiesListModel(self.account)) self.list_communities.setModel(CommunitiesListModel(self.account))
def action_edit_account_key(self):
if self.step.is_valid():
self.button_next.setEnabled(True)
else:
self.button_next.setEnabled(False)
def open_process_edit_community(self, index): def open_process_edit_community(self, index):
community = self.account.communities[index.row()] community = self.account.communities[index.row()]
dialog = ProcessConfigureCommunity(self.account, community) dialog = ProcessConfigureCommunity(self.account, community)
dialog.accepted.connect(self.action_edit_community) dialog.accepted.connect(self.action_edit_community)
dialog.exec_() dialog.exec_()
def open_generate_account_key(self):
dialog = GenerateAccountKeyDialog(self.account, self)
dialog.exec_()
def open_import_key(self):
keyfile = QFileDialog.getOpenFileName(self,
"Choose a secret key",
"",
"All key files (*.asc);; Any file (*)")
keyfile = keyfile[0]
key = open(keyfile).read()
result = self.account.gpg.import_keys(key)
if result.count == 0:
QErrorMessage(self).showMessage("Bad key file")
else:
QMessageBox.information(self, "Key import", "Key " +
result.fingerprints[0] + " has been imported",
QMessageBox.Ok)
if self.account.keyid is not '':
self.account.gpg.delete_keys(self.account.keyid)
secret_keys = self.account.gpg.list_keys(True)
for k in secret_keys:
if k['fingerprint'] == result.fingerprints[0]:
self.account.keyid = k['keyid']
self.label_fingerprint.setText("Key : " + result.fingerprints[0])
self.edit_secretkey_path.setText(keyfile)
self.button_next.setEnabled(True)
def next(self): def next(self):
if self.step.next_step is not None: if self.step.next_step is not None:
if self.step.is_valid(): if self.step.is_valid():
...@@ -191,7 +183,6 @@ class ProcessConfigureAccount(QDialog, Ui_AccountConfigurationDialog): ...@@ -191,7 +183,6 @@ class ProcessConfigureAccount(QDialog, Ui_AccountConfigurationDialog):
self.step.display_page() self.step.display_page()
except Error as e: except Error as e:
QErrorMessage(self).showMessage(e.message) QErrorMessage(self).showMessage(e.message)
else: else:
self.accept() self.accept()
......
...@@ -4,6 +4,7 @@ Created on 8 mars 2014 ...@@ -4,6 +4,7 @@ Created on 8 mars 2014
@author: inso @author: inso
''' '''
import logging
from ucoinpy.api import bma from ucoinpy.api import bma
from cutecoin.gen_resources.communityConfigurationDialog_uic import Ui_CommunityConfigurationDialog from cutecoin.gen_resources.communityConfigurationDialog_uic import Ui_CommunityConfigurationDialog
from PyQt5.QtWidgets import QDialog, QMenu, QMessageBox, QWidget, QAction from PyQt5.QtWidgets import QDialog, QMenu, QMessageBox, QWidget, QAction
...@@ -26,10 +27,12 @@ class StepPageInit(Step): ...@@ -26,10 +27,12 @@ class StepPageInit(Step):
''' '''
def __init__(self, config_dialog): def __init__(self, config_dialog):
super().__init__(config_dialog) super().__init__(config_dialog)
logging.debug("Init")
def is_valid(self): def is_valid(self):
server = self.config_dialog.lineedit_server.text() server = self.config_dialog.lineedit_server.text()
port = self.config_dialog.spinbox_port.value() port = self.config_dialog.spinbox_port.value()
logging.debug("Is valid ? ")
try: try:
bma.network.Peering(server, port) bma.network.Peering(server, port)
except: except:
...@@ -46,6 +49,7 @@ class StepPageInit(Step): ...@@ -46,6 +49,7 @@ class StepPageInit(Step):
port = self.config_dialog.spinbox_port.value() port = self.config_dialog.spinbox_port.value()
default_node = Node.create(server, port) default_node = Node.create(server, port)
account = self.config_dialog.account account = self.config_dialog.account
logging.debug("Account : {0}".format(account))
self.config_dialog.community = account.add_community(default_node) self.config_dialog.community = account.add_community(default_node)
def display_page(self): def display_page(self):
...@@ -165,8 +169,9 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog): ...@@ -165,8 +169,9 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog):
''' '''
server = self.lineedit_server.text() server = self.lineedit_server.text()
port = self.spinbox_port.value() port = self.spinbox_port.value()
logging.debug("Add node : {0}".format(self.community))
if self.community is not None: if self.community is not None:
self.nodes.append(Node.create(server, port, trust=True)) self.nodes.append(Node.create(server, port))
self.tree_nodes.setModel(NodesTreeModel(self.community, self.tree_nodes.setModel(NodesTreeModel(self.community,
self.nodes)) self.nodes))
......
...@@ -68,9 +68,11 @@ class Account(object): ...@@ -68,9 +68,11 @@ class Account(object):
self.contacts.append(person) self.contacts.append(person)
def add_community(self, default_node): def add_community(self, default_node):
logging.debug("Adding a community")
current = bma.blockchain.Current(default_node.connection_handler()) current = bma.blockchain.Current(default_node.connection_handler())
amendment_data = current.get() block_data = current.get()
currency = amendment_data['currency'] currency = block_data['currency']
logging.debug("Currency : {0}".format(currency))
community = self.communities.add_community(currency, default_node) community = self.communities.add_community(currency, default_node)
self.wallets.add_wallet(currency) self.wallets.add_wallet(currency)
return community return community
......
...@@ -14,7 +14,7 @@ class Node(object): ...@@ -14,7 +14,7 @@ class Node(object):
A ucoin node using BMA protocol A ucoin node using BMA protocol
''' '''
def __init__(self, server, port, trust, hoster): def __init__(self, server, port):
''' '''
Constructor Constructor
''' '''
......
...@@ -43,8 +43,6 @@ class NodeItem(object): ...@@ -43,8 +43,6 @@ class NodeItem(object):
def __init__(self, main_node, root_item): def __init__(self, main_node, root_item):
self.main_node_text = main_node.get_text() self.main_node_text = main_node.get_text()
self.root_item = root_item self.root_item = root_item
self.trust = main_node.trust
self.hoster = main_node.hoster
self.node_items = [] self.node_items = []
def appendChild(self, node_item): def appendChild(self, node_item):
......
...@@ -102,7 +102,7 @@ class NodesTreeModel(QAbstractItemModel): ...@@ -102,7 +102,7 @@ class NodesTreeModel(QAbstractItemModel):
" / " + " / " +
node_item.data(0)) node_item.data(0))
self.root_item.appendChild(node_item) self.root_item.appendChild(node_item)
for node in node.downstream_peers(): for node in node.peers():
child_node_item = NodeItem(node, node_item) child_node_item = NodeItem(node, node_item)
logging.debug( logging.debug(
"\t node : " + "\t node : " +
......
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