Add UI to test namecoin connection.

Add a test button to namecoin UI settings, which tries
out the connection and reports its result back.  Also use
namecoin.conf as config file to load default RPC user/pass
combination from.
This commit is contained in:
Daniel Kraft 2013-07-07 18:41:13 +02:00
parent 68fbc4b344
commit 213d92b88a
4 changed files with 79 additions and 10 deletions

View File

@ -2759,6 +2759,8 @@ class settingsDialog(QtGui.QDialog):
shared.config.get('bitmessagesettings', 'namecoinrpcuser')))
self.ui.lineEditNamecoinPassword.setText(str(
shared.config.get('bitmessagesettings', 'namecoinrpcpassword')))
QtCore.QObject.connect(self.ui.pushButtonNamecoinTest, QtCore.SIGNAL(
"clicked()"), self.click_pushButtonNamecoinTest)
#'System' tab removed for now.
"""try:
@ -2797,6 +2799,17 @@ class settingsDialog(QtGui.QDialog):
self.ui.lineEditSocksPassword.setEnabled(True)
self.ui.lineEditTCPPort.setEnabled(False)
# Test the namecoin settings specified in the settings dialog.
def click_pushButtonNamecoinTest(self):
options = {}
options["host"] = self.ui.lineEditNamecoinHost.text()
options["port"] = self.ui.lineEditNamecoinPort.text()
options["user"] = self.ui.lineEditNamecoinUser.text()
options["password"] = self.ui.lineEditNamecoinPassword.text()
nc = namecoinConnection(options)
res = nc.test()
self.ui.labelNamecoinTestResult.setText(res)
class SpecialAddressBehaviorDialog(QtGui.QDialog):

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'settings.ui'
#
# Created: Sun Jul 7 17:25:43 2013
# Created: Sun Jul 7 18:40:01 2013
# by: PyQt4 UI code generator 4.9.3
#
# WARNING! All changes made in this file will be lost!
@ -242,7 +242,7 @@ class Ui_settingsDialog(object):
self.lineEditNamecoinPort.setObjectName(_fromUtf8("lineEditNamecoinPort"))
self.gridLayout_8.addWidget(self.lineEditNamecoinPort, 2, 2, 1, 1)
spacerItem10 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.gridLayout_8.addItem(spacerItem10, 5, 1, 1, 1)
self.gridLayout_8.addItem(spacerItem10, 7, 1, 1, 1)
spacerItem11 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_8.addItem(spacerItem11, 3, 0, 1, 1)
self.label_19 = QtGui.QLabel(self.tabNamecoin)
@ -263,6 +263,13 @@ class Ui_settingsDialog(object):
self.lineEditNamecoinPassword.setEchoMode(QtGui.QLineEdit.Password)
self.lineEditNamecoinPassword.setObjectName(_fromUtf8("lineEditNamecoinPassword"))
self.gridLayout_8.addWidget(self.lineEditNamecoinPassword, 4, 2, 1, 1)
self.labelNamecoinTestResult = QtGui.QLabel(self.tabNamecoin)
self.labelNamecoinTestResult.setText(_fromUtf8(""))
self.labelNamecoinTestResult.setObjectName(_fromUtf8("labelNamecoinTestResult"))
self.gridLayout_8.addWidget(self.labelNamecoinTestResult, 6, 0, 1, 2)
self.pushButtonNamecoinTest = QtGui.QPushButton(self.tabNamecoin)
self.pushButtonNamecoinTest.setObjectName(_fromUtf8("pushButtonNamecoinTest"))
self.gridLayout_8.addWidget(self.pushButtonNamecoinTest, 6, 2, 1, 1)
self.tabWidgetSettings.addTab(self.tabNamecoin, _fromUtf8(""))
self.gridLayout.addWidget(self.tabWidgetSettings, 0, 0, 1, 1)
@ -323,5 +330,6 @@ class Ui_settingsDialog(object):
self.label_18.setText(QtGui.QApplication.translate("settingsDialog", "Port:", None, QtGui.QApplication.UnicodeUTF8))
self.label_19.setText(QtGui.QApplication.translate("settingsDialog", "Username:", None, QtGui.QApplication.UnicodeUTF8))
self.label_20.setText(QtGui.QApplication.translate("settingsDialog", "Password:", None, QtGui.QApplication.UnicodeUTF8))
self.pushButtonNamecoinTest.setText(QtGui.QApplication.translate("settingsDialog", "Test", None, QtGui.QApplication.UnicodeUTF8))
self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tabNamecoin), QtGui.QApplication.translate("settingsDialog", "Namecoin integration", None, QtGui.QApplication.UnicodeUTF8))

View File

@ -558,7 +558,7 @@
<item row="2" column="2">
<widget class="QLineEdit" name="lineEditNamecoinPort"/>
</item>
<item row="5" column="1">
<item row="7" column="1">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -630,6 +630,20 @@
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QLabel" name="labelNamecoinTestResult">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="6" column="2">
<widget class="QPushButton" name="pushButtonNamecoinTest">
<property name="text">
<string>Test</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>

View File

@ -44,12 +44,23 @@ class namecoinConnection (object):
bufsize = 4096
queryid = 1
def __init__ (self):
ensureNamecoinOptions ()
self.user = shared.config.get (configSection, "namecoinrpcuser")
self.password = shared.config.get (configSection, "namecoinrpcpassword")
self.host = shared.config.get (configSection, "namecoinrpchost")
self.port = shared.config.get (configSection, "namecoinrpcport")
# Initialise. If options are given, take the connection settings from
# them instead of loading from the configs. This can be used to test
# currently entered connection settings in the config dialog without
# actually changing the values (yet).
def __init__ (self, options = None):
if options is None:
ensureNamecoinOptions ()
self.host = shared.config.get (configSection, "namecoinrpchost")
self.port = shared.config.get (configSection, "namecoinrpcport")
self.user = shared.config.get (configSection, "namecoinrpcuser")
self.password = shared.config.get (configSection,
"namecoinrpcpassword")
else:
self.host = options["host"]
self.port = options["port"]
self.user = options["user"]
self.password = options["password"]
# Query for the bitmessage address corresponding to the given identity
# string. If it doesn't contain a slash, id/ is prepended. We return
@ -83,6 +94,29 @@ class namecoinConnection (object):
return ("The name '%s' has no associated Bitmessage address." % string,
None)
# Test the connection settings. This routine tries to query a "getinfo"
# command, and builds either an error message or a success message with
# some info from it.
def test (self):
try:
res = self.callRPC ("getinfo", [])
vers = res["version"]
v3 = vers % 100
vers = vers / 100
v2 = vers % 100
vers = vers / 100
v1 = vers
if v3 == 0:
versStr = "0.%d.%d" % (v1, v2)
else:
versStr = "0.%d.%d.%d" % (v1, v2, v3)
return "Success! Namecoind version %s running." % versStr
except:
return "The connection to namecoind failed."
# Helper routine that actually performs an JSON RPC call.
def callRPC (self, method, params):
data = {"method": method, "params": params, "id": self.queryid}
@ -181,7 +215,7 @@ def ensureNamecoinOptions ():
if (not hasUser) or (not hasPass):
try:
nmcFolder = lookupNamecoinFolder ()
nmcConfig = nmcFolder + "bitcoin.conf"
nmcConfig = nmcFolder + "namecoin.conf"
nmc = open (nmcConfig, "r")
while True: