diff --git a/electrum/gui/qml/components/WalletDetails.qml b/electrum/gui/qml/components/WalletDetails.qml index 18df38413..f3a69358c 100644 --- a/electrum/gui/qml/components/WalletDetails.qml +++ b/electrum/gui/qml/components/WalletDetails.qml @@ -26,14 +26,14 @@ Pane { var dialog = app.messageDialog.createObject(rootItem, {'text': qsTr('Really delete this wallet?'), 'yesno': true}) dialog.yesClicked.connect(function() { - Daemon.check_then_delete_wallet(Daemon.currentWallet) + Daemon.checkThenDeleteWallet(Daemon.currentWallet) }) dialog.open() } function changePassword() { // trigger dialog via wallet (auth then signal) - Daemon.start_change_password() + Daemon.startChangePassword() } function importAddressesKeys() { @@ -343,7 +343,7 @@ Pane { restore from seed. Please make sure you have your seed stored safely') } ) dialog.accepted.connect(function() { - Daemon.set_password(dialog.password) + Daemon.setPassword(dialog.password) }) dialog.open() } @@ -351,13 +351,13 @@ Pane { if (code == 'unpaid_requests') { var dialog = app.messageDialog.createObject(app, {text: message, yesno: true }) dialog.yesClicked.connect(function() { - Daemon.check_then_delete_wallet(Daemon.currentWallet, true) + Daemon.checkThenDeleteWallet(Daemon.currentWallet, true) }) dialog.open() } else if (code == 'balance') { var dialog = app.messageDialog.createObject(app, {text: message, yesno: true }) dialog.yesClicked.connect(function() { - Daemon.check_then_delete_wallet(Daemon.currentWallet, true, true) + Daemon.checkThenDeleteWallet(Daemon.currentWallet, true, true) }) dialog.open() } else { diff --git a/electrum/gui/qml/components/Wallets.qml b/electrum/gui/qml/components/Wallets.qml index a80c5d346..9e925aa10 100644 --- a/electrum/gui/qml/components/Wallets.qml +++ b/electrum/gui/qml/components/Wallets.qml @@ -13,8 +13,6 @@ Pane { padding: 0 - // property string title: qsTr('Wallets') - function createWallet() { var dialog = app.newWalletWizard.createObject(rootItem) dialog.open() diff --git a/electrum/gui/qml/qeapp.py b/electrum/gui/qml/qeapp.py index 730a5ded6..4c28b096b 100644 --- a/electrum/gui/qml/qeapp.py +++ b/electrum/gui/qml/qeapp.py @@ -12,7 +12,7 @@ from electrum.logging import Logger, get_logger from electrum.util import BITCOIN_BIP21_URI_SCHEME, LIGHTNING_URI_SCHEME from .qeconfig import QEConfig -from .qedaemon import QEDaemon, QEWalletListModel +from .qedaemon import QEDaemon from .qenetwork import QENetwork from .qewallet import QEWallet from .qeqr import QEQRParser, QEQRImageProvider, QEQRImageProviderHelper diff --git a/electrum/gui/qml/qedaemon.py b/electrum/gui/qml/qedaemon.py index 489667b36..752c78a1c 100644 --- a/electrum/gui/qml/qedaemon.py +++ b/electrum/gui/qml/qedaemon.py @@ -20,15 +20,18 @@ from .qewizard import QENewWalletWizard, QEServerConnectWizard # and whole Wallet instances (loaded wallets) class QEWalletListModel(QAbstractListModel): _logger = get_logger(__name__) - def __init__(self, parent=None): - QAbstractListModel.__init__(self, parent) - self.wallets = [] # define listmodel rolemap _ROLE_NAMES= ('name','path','active') _ROLE_KEYS = range(Qt.UserRole, Qt.UserRole + len(_ROLE_NAMES)) _ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES])) + def __init__(self, daemon, parent=None): + QAbstractListModel.__init__(self, parent) + self.daemon = daemon + self.wallets = [] + self.reload() + def rowCount(self, index): return len(self.wallets) @@ -36,7 +39,7 @@ class QEWalletListModel(QAbstractListModel): return self._ROLE_MAP def data(self, index, role): - (wallet_name, wallet_path, wallet) = self.wallets[index.row()] + (wallet_name, wallet_path) = self.wallets[index.row()] role_index = role - Qt.UserRole role_name = self._ROLE_NAMES[role_index] if role_name == 'name': @@ -44,23 +47,31 @@ class QEWalletListModel(QAbstractListModel): if role_name == 'path': return wallet_path if role_name == 'active': - return wallet is not None + return self.daemon.get_wallet(wallet_path) is not None - def add_wallet(self, wallet_path = None, wallet: Abstract_Wallet = None): - if wallet_path is None and wallet is None: - return - # only add wallet instance if instance not yet in model - if wallet: - for name,path,w in self.wallets: - if w == wallet: - return + @pyqtSlot() + def reload(self): + self._logger.debug('enumerating available wallets') + if len(self.wallets) > 0: + self.beginRemoveRows(QModelIndex(), 0, len(self.wallets) - 1) + self.wallets = [] + self.endRemoveRows() + + available = [] + wallet_folder = os.path.dirname(self.daemon.config.get_wallet_path()) + with os.scandir(wallet_folder) as it: + for i in it: + if i.is_file() and not i.name.startswith('.'): + available.append(i.path) + for path in sorted(available): + wallet = self.daemon.get_wallet(path) + self.add_wallet(wallet_path = path) + + def add_wallet(self, wallet_path): self.beginInsertRows(QModelIndex(), len(self.wallets), len(self.wallets)) - if wallet is None: - wallet_name = os.path.basename(wallet_path) - else: - wallet_name = wallet.basename() + wallet_name = os.path.basename(wallet_path) wallet_path = standardize_path(wallet_path) - item = (wallet_name, wallet_path, wallet) + item = (wallet_name, wallet_path) self.wallets.append(item) self.endInsertRows() @@ -68,12 +79,12 @@ class QEWalletListModel(QAbstractListModel): i = 0 wallets = [] remove = -1 - for wallet_name, wallet_path, wallet in self.wallets: + for wallet_name, wallet_path in self.wallets: if wallet_path == path: remove = i else: self._logger.debug('HM, %s is not %s', wallet_path, path) - wallets.append((wallet_name, wallet_path, wallet)) + wallets.append((wallet_name, wallet_path)) i += 1 if remove >= 0: @@ -81,31 +92,8 @@ class QEWalletListModel(QAbstractListModel): self.wallets = wallets self.endRemoveRows() -class QEAvailableWalletListModel(QEWalletListModel): - def __init__(self, daemon, parent=None): - QEWalletListModel.__init__(self, parent) - self.daemon = daemon - self.reload() - - @pyqtSlot() - def reload(self): - if len(self.wallets) > 0: - self.beginRemoveRows(QModelIndex(), 0, len(self.wallets) - 1) - self.wallets = [] - self.endRemoveRows() - - available = [] - wallet_folder = os.path.dirname(self.daemon.config.get_wallet_path()) - with os.scandir(wallet_folder) as it: - for i in it: - if i.is_file() and not i.name.startswith('.'): - available.append(i.path) - for path in sorted(available): - wallet = self.daemon.get_wallet(path) - self.add_wallet(wallet_path = path, wallet = wallet) - def wallet_name_exists(self, name): - for wallet_name, wallet_path, wallet in self.wallets: + for wallet_name, wallet_path in self.wallets: if name == wallet_name: return True return False @@ -119,7 +107,6 @@ class QEDaemon(AuthMixin, QObject): self._walletdb.validPasswordChanged.connect(self.passwordValidityCheck) _logger = get_logger(__name__) - _loaded_wallets = QEWalletListModel() _available_wallets = None _current_wallet = None _new_wallet_wizard = None @@ -128,7 +115,6 @@ class QEDaemon(AuthMixin, QObject): _use_single_password = False _password = None - activeWalletsChanged = pyqtSignal() availableWalletsChanged = pyqtSignal() fxChanged = pyqtSignal() newWalletWizardChanged = pyqtSignal() @@ -178,7 +164,6 @@ class QEDaemon(AuthMixin, QObject): if wallet is not None: self._current_wallet = QEWallet.getInstanceFor(wallet) if not wallet_already_open: - self._loaded_wallets.add_wallet(wallet_path=self._path, wallet=wallet) self._current_wallet.password = password self.walletLoaded.emit() @@ -202,7 +187,7 @@ class QEDaemon(AuthMixin, QObject): @pyqtSlot(QEWallet) @pyqtSlot(QEWallet, bool) @pyqtSlot(QEWallet, bool, bool) - def check_then_delete_wallet(self, wallet, confirm_requests=False, confirm_balance=False): + def checkThenDeleteWallet(self, wallet, confirm_requests=False, confirm_balance=False): if wallet.wallet.lnworker: lnchannels = wallet.wallet.lnworker.get_channel_objects() if any([channel.get_state() != ChannelState.REDEEMED for channel in lnchannels.values()]): @@ -221,7 +206,6 @@ class QEDaemon(AuthMixin, QObject): self.delete_wallet(wallet) - @pyqtSlot(QEWallet) @auth_protect def delete_wallet(self, wallet): path = standardize_path(wallet.wallet.storage.path) @@ -234,7 +218,6 @@ class QEDaemon(AuthMixin, QObject): self.walletDeleteError.emit('error', _('Problem deleting wallet')) return - self.activeWallets.remove_wallet(path) self.availableWallets.remove_wallet(path) @pyqtProperty('QString') @@ -245,14 +228,10 @@ class QEDaemon(AuthMixin, QObject): def currentWallet(self): return self._current_wallet - @pyqtProperty(QEWalletListModel, notify=activeWalletsChanged) - def activeWallets(self): - return self._loaded_wallets - - @pyqtProperty(QEAvailableWalletListModel, notify=availableWalletsChanged) + @pyqtProperty(QEWalletListModel, notify=availableWalletsChanged) def availableWallets(self): if not self._available_wallets: - self._available_wallets = QEAvailableWalletListModel(self.daemon) + self._available_wallets = QEWalletListModel(self.daemon) return self._available_wallets @@ -279,14 +258,14 @@ class QEDaemon(AuthMixin, QObject): requestNewPassword = pyqtSignal() @pyqtSlot() @auth_protect - def start_change_password(self): + def startChangePassword(self): if self._use_single_password: self.requestNewPassword.emit() else: self.currentWallet.requestNewPassword.emit() @pyqtSlot(str) - def set_password(self, password): + def setPassword(self, password): assert self._use_single_password self._logger.debug('about to set password for ALL wallets') self.daemon.update_password_for_directory(old_password=self._password, new_password=password) diff --git a/electrum/gui/qml/qewalletdb.py b/electrum/gui/qml/qewalletdb.py index 52ff68c01..62807c7d6 100644 --- a/electrum/gui/qml/qewalletdb.py +++ b/electrum/gui/qml/qewalletdb.py @@ -50,10 +50,7 @@ class QEWalletDB(QObject): @path.setter def path(self, wallet_path): - if wallet_path == self._path: - return - - self._logger.info('setting path: ' + wallet_path) + self._logger.debug('setting path: ' + wallet_path) self.reset() self._path = wallet_path