Fixing namecoin button again (broken in c7d3784
):
* separate method MyForm.resetNamecoinConnection() - sets MyForm.namecoin to fresh instance of namecoin.namecoinConnection, tests it and shows or hides "Fetch Namecoin ID" button; * that method is called when MyForm initializes and when settingsDialog instance is accepted; * namecoin.namecoinConnection.query() checks found address and always prepends it with display name, if query result doesn't contain "name" field it will be the query string.
This commit is contained in:
parent
8ad064dcac
commit
ea38e91839
|
@ -798,19 +798,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
"valueChanged(int)"), self.updateTTL)
|
"valueChanged(int)"), self.updateTTL)
|
||||||
|
|
||||||
self.initSettings()
|
self.initSettings()
|
||||||
|
self.resetNamecoinConnection()
|
||||||
namecoin.ensureNamecoinOptions()
|
|
||||||
self.namecoin = namecoin.namecoinConnection()
|
|
||||||
|
|
||||||
# Check to see whether we can connect to namecoin.
|
|
||||||
# Hide the 'Fetch Namecoin ID' button if we can't.
|
|
||||||
if BMConfigParser().safeGetBoolean(
|
|
||||||
'bitmessagesettings', 'dontconnect'
|
|
||||||
) or self.namecoin.test()[0] == 'failed':
|
|
||||||
logger.warning(
|
|
||||||
'There was a problem testing for a Namecoin daemon. Hiding the'
|
|
||||||
' Fetch Namecoin ID button')
|
|
||||||
self.ui.pushButtonFetchNamecoinID.hide()
|
|
||||||
|
|
||||||
def updateTTL(self, sliderPosition):
|
def updateTTL(self, sliderPosition):
|
||||||
TTL = int(sliderPosition ** 3.199 + 3600)
|
TTL = int(sliderPosition ** 3.199 + 3600)
|
||||||
|
@ -2160,9 +2148,8 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
))
|
))
|
||||||
|
|
||||||
def click_pushButtonFetchNamecoinID(self):
|
def click_pushButtonFetchNamecoinID(self):
|
||||||
nc = namecoinConnection()
|
|
||||||
identities = str(self.ui.lineEditTo.text().toUtf8()).split(";")
|
identities = str(self.ui.lineEditTo.text().toUtf8()).split(";")
|
||||||
err, addr = nc.query(identities[-1].strip())
|
err, addr = self.namecoin.query(identities[-1].strip())
|
||||||
if err is not None:
|
if err is not None:
|
||||||
self.updateStatusBar(
|
self.updateStatusBar(
|
||||||
_translate("MainWindow", "Error: %1").arg(err))
|
_translate("MainWindow", "Error: %1").arg(err))
|
||||||
|
@ -2481,6 +2468,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
self.settingsDialogInstance.ui.lineEditNamecoinUser.text()))
|
self.settingsDialogInstance.ui.lineEditNamecoinUser.text()))
|
||||||
BMConfigParser().set('bitmessagesettings', 'namecoinrpcpassword', str(
|
BMConfigParser().set('bitmessagesettings', 'namecoinrpcpassword', str(
|
||||||
self.settingsDialogInstance.ui.lineEditNamecoinPassword.text()))
|
self.settingsDialogInstance.ui.lineEditNamecoinPassword.text()))
|
||||||
|
self.resetNamecoinConnection()
|
||||||
|
|
||||||
# Demanded difficulty tab
|
# Demanded difficulty tab
|
||||||
if float(self.settingsDialogInstance.ui.lineEditTotalDifficulty.text()) >= 1:
|
if float(self.settingsDialogInstance.ui.lineEditTotalDifficulty.text()) >= 1:
|
||||||
|
@ -4129,6 +4117,22 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
else:
|
else:
|
||||||
self.statusbar.showMessage(message, 10000)
|
self.statusbar.showMessage(message, 10000)
|
||||||
|
|
||||||
|
def resetNamecoinConnection(self):
|
||||||
|
namecoin.ensureNamecoinOptions()
|
||||||
|
self.namecoin = namecoin.namecoinConnection()
|
||||||
|
|
||||||
|
# Check to see whether we can connect to namecoin.
|
||||||
|
# Hide the 'Fetch Namecoin ID' button if we can't.
|
||||||
|
if BMConfigParser().safeGetBoolean(
|
||||||
|
'bitmessagesettings', 'dontconnect'
|
||||||
|
) or self.namecoin.test()[0] == 'failed':
|
||||||
|
logger.warning(
|
||||||
|
'There was a problem testing for a Namecoin daemon. Hiding the'
|
||||||
|
' Fetch Namecoin ID button')
|
||||||
|
self.ui.pushButtonFetchNamecoinID.hide()
|
||||||
|
else:
|
||||||
|
self.ui.pushButtonFetchNamecoinID.show()
|
||||||
|
|
||||||
def initSettings(self):
|
def initSettings(self):
|
||||||
QtCore.QCoreApplication.setOrganizationName("PyBitmessage")
|
QtCore.QCoreApplication.setOrganizationName("PyBitmessage")
|
||||||
QtCore.QCoreApplication.setOrganizationDomain("bitmessage.org")
|
QtCore.QCoreApplication.setOrganizationDomain("bitmessage.org")
|
||||||
|
@ -4356,8 +4360,8 @@ class settingsDialog(QtGui.QDialog):
|
||||||
else:
|
else:
|
||||||
self.ui.lineEditNamecoinPort.setText("9000")
|
self.ui.lineEditNamecoinPort.setText("9000")
|
||||||
|
|
||||||
# Test the namecoin settings specified in the settings dialog.
|
|
||||||
def click_pushButtonNamecoinTest(self):
|
def click_pushButtonNamecoinTest(self):
|
||||||
|
"""Test the namecoin settings specified in the settings dialog."""
|
||||||
self.ui.labelNamecoinTestResult.setText(_translate(
|
self.ui.labelNamecoinTestResult.setText(_translate(
|
||||||
"MainWindow", "Testing..."))
|
"MainWindow", "Testing..."))
|
||||||
options = {}
|
options = {}
|
||||||
|
@ -4366,13 +4370,11 @@ class settingsDialog(QtGui.QDialog):
|
||||||
options["port"] = str(self.ui.lineEditNamecoinPort.text().toUtf8())
|
options["port"] = str(self.ui.lineEditNamecoinPort.text().toUtf8())
|
||||||
options["user"] = str(self.ui.lineEditNamecoinUser.text().toUtf8())
|
options["user"] = str(self.ui.lineEditNamecoinUser.text().toUtf8())
|
||||||
options["password"] = str(self.ui.lineEditNamecoinPassword.text().toUtf8())
|
options["password"] = str(self.ui.lineEditNamecoinPassword.text().toUtf8())
|
||||||
nc = namecoinConnection(options)
|
nc = namecoin.namecoinConnection(options)
|
||||||
response = nc.test()
|
status, text = nc.test()
|
||||||
responseStatus = response[0]
|
self.ui.labelNamecoinTestResult.setText(text)
|
||||||
responseText = response[1]
|
if status == 'success':
|
||||||
self.ui.labelNamecoinTestResult.setText(responseText)
|
self.parent.namecoin = nc
|
||||||
if responseStatus== 'success':
|
|
||||||
self.parent.ui.pushButtonFetchNamecoinID.show()
|
|
||||||
|
|
||||||
|
|
||||||
# In order for the time columns on the Inbox and Sent tabs to be sorted
|
# In order for the time columns on the Inbox and Sent tabs to be sorted
|
||||||
|
|
|
@ -34,6 +34,7 @@ import os
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from addresses import decodeAddress
|
||||||
from debug import logger
|
from debug import logger
|
||||||
import defaults
|
import defaults
|
||||||
import tr # translate
|
import tr # translate
|
||||||
|
@ -102,7 +103,10 @@ class namecoinConnection(object):
|
||||||
"""
|
"""
|
||||||
slashPos = string.find("/")
|
slashPos = string.find("/")
|
||||||
if slashPos < 0:
|
if slashPos < 0:
|
||||||
|
display_name = string
|
||||||
string = "id/" + string
|
string = "id/" + string
|
||||||
|
else:
|
||||||
|
display_name = string.split("/")[1]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if self.nmctype == "namecoind":
|
if self.nmctype == "namecoind":
|
||||||
|
@ -112,7 +116,9 @@ class namecoinConnection(object):
|
||||||
res = self.callRPC("data", ["getValue", string])
|
res = self.callRPC("data", ["getValue", string])
|
||||||
res = res["reply"]
|
res = res["reply"]
|
||||||
if not res:
|
if not res:
|
||||||
return (tr._translate("MainWindow", 'The name %1 was not found.').arg(unicode(string)), None)
|
return (tr._translate(
|
||||||
|
"MainWindow", 'The name %1 was not found.'
|
||||||
|
).arg(unicode(string)), None)
|
||||||
else:
|
else:
|
||||||
assert False
|
assert False
|
||||||
except RPCError as exc:
|
except RPCError as exc:
|
||||||
|
@ -121,29 +127,37 @@ class namecoinConnection(object):
|
||||||
errmsg = exc.error["message"]
|
errmsg = exc.error["message"]
|
||||||
else:
|
else:
|
||||||
errmsg = exc.error
|
errmsg = exc.error
|
||||||
return (tr._translate("MainWindow", 'The namecoin query failed (%1)').arg(unicode(errmsg)), None)
|
return (tr._translate(
|
||||||
|
"MainWindow", 'The namecoin query failed (%1)'
|
||||||
|
).arg(unicode(errmsg)), None)
|
||||||
|
except AssertionError:
|
||||||
|
return (tr._translate(
|
||||||
|
"MainWindow", 'Unknown namecoin interface type: %1'
|
||||||
|
).arg(unicode(self.nmctype)), None)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("Namecoin query exception")
|
logger.exception("Namecoin query exception")
|
||||||
return (tr._translate("MainWindow", 'The namecoin query failed.'), None)
|
return (tr._translate(
|
||||||
|
"MainWindow", 'The namecoin query failed.'), None)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
val = json.loads(res)
|
res = json.loads(res)
|
||||||
except:
|
except ValueError:
|
||||||
logger.exception("Namecoin query json exception")
|
pass
|
||||||
return (tr._translate("MainWindow", 'The name %1 has no valid JSON data.').arg(unicode(string)), None)
|
|
||||||
|
|
||||||
if "bitmessage" in val:
|
|
||||||
if "name" in val:
|
|
||||||
ret = "%s <%s>" % (val["name"], val["bitmessage"])
|
|
||||||
else:
|
else:
|
||||||
ret = val["bitmessage"]
|
try:
|
||||||
return (None, ret)
|
display_name = res["name"]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
res = res.get("bitmessage")
|
||||||
|
|
||||||
|
valid = decodeAddress(res)[0] == 'success'
|
||||||
return (
|
return (
|
||||||
|
None, "%s <%s>" % (display_name, res)
|
||||||
|
) if valid else (
|
||||||
tr._translate(
|
tr._translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
'The name %1 has no associated Bitmessage address.').arg(
|
'The name %1 has no associated Bitmessage address.'
|
||||||
unicode(string)),
|
).arg(unicode(string)), None)
|
||||||
None)
|
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
"""
|
"""
|
||||||
|
|
Reference in New Issue
Block a user