Skip to content
Snippets Groups Projects
Commit c10f6110 authored by Vincent Texier's avatar Vincent Texier
Browse files

Add new wallet in wallets context menu

parent 9655c216
Branches
Tags
No related merge requests found
...@@ -239,17 +239,17 @@ class Application(QObject): ...@@ -239,17 +239,17 @@ class Application(QObject):
data['version'] = __version__ data['version'] = __version__
json.dump(data, outfile, indent=4, sort_keys=True) json.dump(data, outfile, indent=4, sort_keys=True)
def save_cache(self, account): def save_wallet(self, account, wallet):
''' """
Save the cache of an account Save wallet of account in cache
:param account: The account object to save the cache :param cutecoin.core.account.Account account: Account instance
''' :param cutecoin.core.wallet.Wallet wallet: Wallet instance
"""
if not os.path.exists(os.path.join(config.parameters['home'], if not os.path.exists(os.path.join(config.parameters['home'],
account.name, '__cache__')): account.name, '__cache__')):
os.makedirs(os.path.join(config.parameters['home'], os.makedirs(os.path.join(config.parameters['home'],
account.name, '__cache__')) account.name, '__cache__'))
for wallet in account.wallets:
wallet_path = os.path.join(config.parameters['home'], wallet_path = os.path.join(config.parameters['home'],
account.name, '__cache__', wallet.pubkey) account.name, '__cache__', wallet.pubkey)
with open(wallet_path, 'w') as outfile: with open(wallet_path, 'w') as outfile:
...@@ -257,6 +257,19 @@ class Application(QObject): ...@@ -257,6 +257,19 @@ class Application(QObject):
data['version'] = __version__ data['version'] = __version__
json.dump(data, outfile, indent=4, sort_keys=True) json.dump(data, outfile, indent=4, sort_keys=True)
def save_cache(self, account):
'''
Save the cache of an account
:param account: The account object to save the cache
'''
if not os.path.exists(os.path.join(config.parameters['home'],
account.name, '__cache__')):
os.makedirs(os.path.join(config.parameters['home'],
account.name, '__cache__'))
for wallet in account.wallets:
self.save_wallet(account, wallet)
for community in account.communities: for community in account.communities:
community_path = os.path.join(config.parameters['home'], community_path = os.path.join(config.parameters['home'],
account.name, '__cache__', account.name, '__cache__',
...@@ -267,6 +280,7 @@ class Application(QObject): ...@@ -267,6 +280,7 @@ class Application(QObject):
community.currency + '_network') community.currency + '_network')
with open(network_path, 'w') as outfile: with open(network_path, 'w') as outfile:
data = dict()
data['network'] = community.jsonify_network() data['network'] = community.jsonify_network()
data['version'] = __version__ data['version'] = __version__
json.dump(data, outfile, indent=4, sort_keys=True) json.dump(data, outfile, indent=4, sort_keys=True)
......
...@@ -57,7 +57,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -57,7 +57,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, app): def __init__(self, app):
""" """
Init Init
:param ..core.app.Application app: :param cutecoin.core.app.Application app: application
""" """
# Set up the user interface from Designer. # Set up the user interface from Designer.
super().__init__() super().__init__()
......
...@@ -10,6 +10,7 @@ from PyQt5.QtCore import QDateTime, QModelIndex, Qt, QLocale ...@@ -10,6 +10,7 @@ from PyQt5.QtCore import QDateTime, QModelIndex, Qt, QLocale
from PyQt5.QtGui import QCursor from PyQt5.QtGui import QCursor
from ..core.person import Person from ..core.person import Person
from ..core.wallet import Wallet from ..core.wallet import Wallet
from ..gui.password_asker import PasswordAskerDialog
from ..models.wallets import WalletsTableModel, WalletsFilterProxyModel from ..models.wallets import WalletsTableModel, WalletsFilterProxyModel
from .transfer import TransferMoneyDialog from .transfer import TransferMoneyDialog
from ..tools.exceptions import MembershipNotFoundError from ..tools.exceptions import MembershipNotFoundError
...@@ -22,9 +23,13 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab): ...@@ -22,9 +23,13 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab):
''' '''
def __init__(self, app, account, community, password_asker): def __init__(self, app, account, community, password_asker):
''' """
Constructor Init
''' :param cutecoin.core.app.Application app: Application instance
:param cutecoin.core.account.Account account: Account instance
:param cutecoin.core.community.Community community: Community instance
:param cutecoin.gui.password_asker.PasswordAskerDialog password_asker: PasswordAskerDialog instance
"""
super().__init__() super().__init__()
self.setupUi(self) self.setupUi(self)
self.app = app self.app = app
...@@ -156,6 +161,9 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab): ...@@ -156,6 +161,9 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab):
pubkey = model.sourceModel().data(pubkey_index, Qt.DisplayRole) pubkey = model.sourceModel().data(pubkey_index, Qt.DisplayRole)
menu = QMenu(model.data(index, Qt.DisplayRole), self) menu = QMenu(model.data(index, Qt.DisplayRole), self)
new_wallet = QAction(self.tr("New Wallet"), self)
new_wallet.triggered.connect(self.new_wallet)
rename = QAction(self.tr("Rename"), self) rename = QAction(self.tr("Rename"), self)
rename.triggered.connect(self.rename_wallet) rename.triggered.connect(self.rename_wallet)
rename.setData(name_index) rename.setData(name_index)
...@@ -175,12 +183,34 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab): ...@@ -175,12 +183,34 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab):
transfer_action.setData(wallets) transfer_action.setData(wallets)
transfer_to.addAction(transfer_action) transfer_to.addAction(transfer_action)
menu.addAction(new_wallet)
menu.addAction(rename) menu.addAction(rename)
menu.addAction(copy_pubkey) menu.addAction(copy_pubkey)
menu.addMenu(transfer_to) menu.addMenu(transfer_to)
# Show the context menu. # Show the context menu.
menu.exec_(QCursor.pos()) menu.exec_(QCursor.pos())
def new_wallet(self):
"""
Create a new wallet
"""
password_asker = PasswordAskerDialog(self.app.current_account)
password = password_asker.exec_()
if password_asker.result() == QDialog.Rejected:
return None
# create new wallet by increasing wallet pool size
self.account.set_walletpool_size(len(self.account.wallets) + 1, password)
# capture new wallet
wallet = self.account.wallets[len(self.account.wallets)-1]
# feed cache data of the wallet
wallet.refresh_cache(self.community, list())
# save wallet cache on disk
self.app.save_wallet(self.account, self.account.wallets[len(self.account.wallets)-1])
# save account cache on disk (update number of wallets)
self.app.save(self.account)
# refresh wallet list in gui
self.refresh()
def rename_wallet(self): def rename_wallet(self):
index = self.sender().data() index = self.sender().data()
self.table_wallets.edit(index) self.table_wallets.edit(index)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment