@@ -1043,31 +1043,7 @@ class ElectrumWindow(QMainWindow):
|
|||||||
self.completions.setStringList(l)
|
self.completions.setStringList(l)
|
||||||
|
|
||||||
def protected(func):
|
def protected(func):
|
||||||
'''Password request wrapper. The password is passed to the function
|
return lambda s, *args: s.do_protect(func, args)
|
||||||
as the 'password' named argument. Return value is a 2-element
|
|
||||||
tuple: (Cancelled, Result) where Cancelled is True if the user
|
|
||||||
cancels the password request, otherwise False. Result is the
|
|
||||||
return value of the wrapped function, or None if cancelled.
|
|
||||||
'''
|
|
||||||
def request_password(self, *args, **kwargs):
|
|
||||||
parent = kwargs.get('parent', self)
|
|
||||||
if self.wallet.use_encryption:
|
|
||||||
while True:
|
|
||||||
password = self.password_dialog(parent=parent)
|
|
||||||
if not password:
|
|
||||||
return True, None
|
|
||||||
try:
|
|
||||||
self.wallet.check_password(password)
|
|
||||||
break
|
|
||||||
except Exception as e:
|
|
||||||
QMessageBox.warning(parent, _('Error'), str(e), _('OK'))
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
password = None
|
|
||||||
|
|
||||||
kwargs['password'] = password
|
|
||||||
return False, func(self, *args, **kwargs)
|
|
||||||
return request_password
|
|
||||||
|
|
||||||
def read_send_tab(self):
|
def read_send_tab(self):
|
||||||
if self.payment_request and self.payment_request.has_expired():
|
if self.payment_request and self.payment_request.has_expired():
|
||||||
@@ -1886,6 +1862,29 @@ class ElectrumWindow(QMainWindow):
|
|||||||
d = QRDialog(data, self, title)
|
d = QRDialog(data, self, title)
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
|
||||||
|
|
||||||
|
def do_protect(self, func, args):
|
||||||
|
if self.wallet.use_encryption:
|
||||||
|
while True:
|
||||||
|
password = self.password_dialog()
|
||||||
|
if not password:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
self.wallet.check_password(password)
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
QMessageBox.warning(self, _('Error'), str(e), _('OK'))
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
password = None
|
||||||
|
|
||||||
|
if args != (False,):
|
||||||
|
args = (self,) + args + (password,)
|
||||||
|
else:
|
||||||
|
args = (self, password)
|
||||||
|
apply(func, args)
|
||||||
|
|
||||||
|
|
||||||
def show_public_keys(self, address):
|
def show_public_keys(self, address):
|
||||||
if not address: return
|
if not address: return
|
||||||
try:
|
try:
|
||||||
@@ -2065,10 +2064,8 @@ class ElectrumWindow(QMainWindow):
|
|||||||
def show_warning(self, msg):
|
def show_warning(self, msg):
|
||||||
QMessageBox.warning(self, _('Warning'), msg, _('OK'))
|
QMessageBox.warning(self, _('Warning'), msg, _('OK'))
|
||||||
|
|
||||||
def password_dialog(self, msg=None, parent=None):
|
def password_dialog(self, msg=None):
|
||||||
if parent == None:
|
d = QDialog(self)
|
||||||
parent = self
|
|
||||||
d = QDialog(parent)
|
|
||||||
d.setModal(1)
|
d.setModal(1)
|
||||||
d.setWindowTitle(_("Enter Password"))
|
d.setWindowTitle(_("Enter Password"))
|
||||||
pw = QLineEdit()
|
pw = QLineEdit()
|
||||||
|
|||||||
Reference in New Issue
Block a user