Resolve address when lost focus.

This commit is contained in:
Bartosz Dabkowski 2015-02-04 14:44:50 +01:00
parent 540adeb22c
commit 090816998e
1 changed files with 61 additions and 39 deletions

View File

@ -98,6 +98,36 @@ class Plugin(BasePlugin):
def settings_widget(self, window):
return EnterButton(_('Settings'), self.settings_dialog)
@hook
def timer_actions(self):
if self.win.payto_e.hasFocus():
return
if self.win.payto_e.is_multiline(): # only supports single line entries atm
return
url = str(self.win.payto_e.toPlainText())
if url == self.win.previous_payto_e:
return
self.win.previous_payto_e = url
url = url.replace('@', '.') # support email-style addresses, per the OA standard
if ('.' in url) and (not '<' in url) and (not ' ' in url):
if not OA_READY: # handle a failed DNSPython load
QMessageBox.warning(self.win, _('Error'), 'Could not load DNSPython libraries, please ensure they are available and/or Electrum has been built correctly', _('OK'))
return
else:
return
data = self.resolve(url)
if not data:
self.win.previous_payto_e = url
return True
(address, name) = data
new_url = url + ' <' + address + '>'
self.win.payto_e.setText(new_url)
self.win.previous_payto_e = new_url
@hook
def before_send(self):
'''
@ -109,28 +139,20 @@ class Plugin(BasePlugin):
if self.win.payto_e.is_multiline(): # only supports single line entries atm
return False
url = str(self.win.payto_e.toPlainText())
url = url.replace('@', '.') # support email-style addresses, per the OA standard
if ('.' in url) and (not '<' in url) and (not ' ' in url):
if not OA_READY: # handle a failed DNSPython load
QMessageBox.warning(self.win, _('Error'), 'Could not load DNSPython libraries, please ensure they are available and/or Electrum has been built correctly', _('OK'))
return False
else:
payto_e = str(self.win.payto_e.toPlainText())
regex = re.compile(r'^([^\s]+) <([A-Za-z0-9]+)>') # only do that for converted addresses
try:
(url, address) = regex.search(payto_e).groups()
except AttributeError:
return False
data = self.resolve(url)
if not data:
if not OA_READY: # handle a failed DNSPython load
QMessageBox.warning(self.win, _('Error'), 'Could not load DNSPython libraries, please ensure they are available and/or Electrum has been built correctly', _('OK'))
return True
(address, name) = data
self.win.payto_e.setText(url + ' <' + address + '>')
if not self.validate_dnssec(url):
msgBox = QMessageBox()
msgBox.setText(_('WARNING: the address ' + address + ' could not be validated via an additional security check, DNSSEC, and thus may not be correct.'))
msgBox.setText(_('WARNING: the address ' + address + ' could not be validated via an additional security check, DNSSEC, and thus may not be correct.'))
msgBox.setInformativeText(_('Do you wish to continue?'))
msgBox.setStandardButtons(QMessageBox.Cancel | QMessageBox.Ok)
msgBox.setDefaultButton(QMessageBox.Cancel)
@ -200,7 +222,7 @@ class Plugin(BasePlugin):
if not self.validate_dnssec(url):
msgBox = QMessageBox()
msgBox.setText(_('WARNING: the address ' + address + ' could not be validated via an additional security check, DNSSEC, and thus may not be correct.'))
msgBox.setText(_('WARNING: the address ' + address + ' could not be validated via an additional security check, DNSSEC, and thus may not be correct.'))
msgBox.setInformativeText("Do you wish to continue?")
msgBox.setStandardButtons(QMessageBox.Cancel | QMessageBox.Ok)
msgBox.setDefaultButton(QMessageBox.Cancel)
@ -274,7 +296,7 @@ class Plugin(BasePlugin):
except DNSException:
err = _('Unhandled exception.')
continue
except Exception,e:
except Exception, e:
err = _('Unexpected error: ' + str(e))
continue
break
@ -337,6 +359,6 @@ class Plugin(BasePlugin):
dns.dnssec.validate(answer[0], answer[1], {name: answer[0]})
except dns.dnssec.ValidationFailure:
return 0
except Exception,e:
except Exception, e:
return 0
return 1