Browse Source

Resolve address when lost focus.

master
Bartosz Dabkowski 11 years ago
parent
commit
090816998e
  1. 52
      plugins/openalias.py

52
plugins/openalias.py

@ -99,34 +99,56 @@ class Plugin(BasePlugin):
return EnterButton(_('Settings'), self.settings_dialog) return EnterButton(_('Settings'), self.settings_dialog)
@hook @hook
def before_send(self): def timer_actions(self):
''' if self.win.payto_e.hasFocus():
Change URL to address before making a send. return
IMPORTANT:
return False to continue execution of the send
return True to stop execution of the send
'''
if self.win.payto_e.is_multiline(): # only supports single line entries atm if self.win.payto_e.is_multiline(): # only supports single line entries atm
return False return
url = str(self.win.payto_e.toPlainText()) 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 url = url.replace('@', '.') # support email-style addresses, per the OA standard
if ('.' in url) and (not '<' in url) and (not ' ' in url): if ('.' in url) and (not '<' in url) and (not ' ' in url):
if not OA_READY: # handle a failed DNSPython load 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')) 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 return
else: else:
return False return
data = self.resolve(url) data = self.resolve(url)
if not data: if not data:
self.win.previous_payto_e = url
return True return True
(address, name) = data (address, name) = data
self.win.payto_e.setText(url + ' <' + address + '>') new_url = url + ' <' + address + '>'
self.win.payto_e.setText(new_url)
self.win.previous_payto_e = new_url
@hook
def before_send(self):
'''
Change URL to address before making a send.
IMPORTANT:
return False to continue execution of the send
return True to stop execution of the send
'''
if self.win.payto_e.is_multiline(): # only supports single line entries atm
return False
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
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
if not self.validate_dnssec(url): if not self.validate_dnssec(url):
msgBox = QMessageBox() msgBox = QMessageBox()
@ -274,7 +296,7 @@ class Plugin(BasePlugin):
except DNSException: except DNSException:
err = _('Unhandled exception.') err = _('Unhandled exception.')
continue continue
except Exception,e: except Exception, e:
err = _('Unexpected error: ' + str(e)) err = _('Unexpected error: ' + str(e))
continue continue
break break
@ -337,6 +359,6 @@ class Plugin(BasePlugin):
dns.dnssec.validate(answer[0], answer[1], {name: answer[0]}) dns.dnssec.validate(answer[0], answer[1], {name: answer[0]})
except dns.dnssec.ValidationFailure: except dns.dnssec.ValidationFailure:
return 0 return 0
except Exception,e: except Exception, e:
return 0 return 0
return 1 return 1
Loading…
Cancel
Save