Dont show Fetch button if cannot connect to Namecoin

This commit is contained in:
Jonathan Warren 2013-08-14 18:59:50 -04:00
parent 27f10f6ac1
commit 077177b742
4 changed files with 36 additions and 23 deletions

View File

@ -432,10 +432,21 @@ class MyForm(QtGui.QMainWindow):
"removeInboxRowByMsgid(PyQt_PyObject)"), self.removeInboxRowByMsgid)
self.UISignalThread.start()
# Below this point, it would be good if all of the necessary global data
# structures were initialized.
# Below this point, it would be good if all of the necessary global data
# structures were initialized.
self.rerenderComboBoxSendFrom()
# Check to see whether we can connect to namecoin. Hide the 'Fetch Namecoin ID' button if we can't.
options = {}
options["type"] = shared.config.get('bitmessagesettings', 'namecoinrpctype')
options["host"] = shared.config.get('bitmessagesettings', 'namecoinrpchost')
options["port"] = shared.config.get('bitmessagesettings', 'namecoinrpcport')
options["user"] = shared.config.get('bitmessagesettings', 'namecoinrpcuser')
options["password"] = shared.config.get('bitmessagesettings', 'namecoinrpcpassword')
nc = namecoinConnection(options)
if nc.test()[0] == 'failed':
self.ui.pushButtonFetchNamecoinID.hide()
# Show or hide the application window after clicking an item within the
@ -3180,6 +3191,8 @@ class settingsDialog(QtGui.QDialog):
# Test the namecoin settings specified in the settings dialog.
def click_pushButtonNamecoinTest(self):
self.ui.labelNamecoinTestResult.setText(_translate(
"MainWindow", "Testing..."))
options = {}
options["type"] = self.getNamecoinType()
options["host"] = self.ui.lineEditNamecoinHost.text()
@ -3187,8 +3200,10 @@ class settingsDialog(QtGui.QDialog):
options["user"] = self.ui.lineEditNamecoinUser.text()
options["password"] = self.ui.lineEditNamecoinPassword.text()
nc = namecoinConnection(options)
res = nc.test()
self.ui.labelNamecoinTestResult.setText(res)
responseStatus = nc.test()[1]
self.ui.labelNamecoinTestResult.setText(responseStatus)
if nc.test()[0]== 'success':
self.parent.ui.pushButtonFetchNamecoinID.show()
class SpecialAddressBehaviorDialog(QtGui.QDialog):

View File

@ -2,8 +2,8 @@
# Form implementation generated from reading ui file 'settings.ui'
#
# Created: Sun Aug 11 22:12:58 2013
# by: PyQt4 UI code generator 4.10.2
# Created: Wed Aug 14 18:31:34 2013
# by: PyQt4 UI code generator 4.10
#
# WARNING! All changes made in this file will be lost!
@ -26,7 +26,7 @@ except AttributeError:
class Ui_settingsDialog(object):
def setupUi(self, settingsDialog):
settingsDialog.setObjectName(_fromUtf8("settingsDialog"))
settingsDialog.resize(462, 343)
settingsDialog.resize(567, 343)
self.gridLayout = QtGui.QGridLayout(settingsDialog)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.buttonBox = QtGui.QDialogButtonBox(settingsDialog)
@ -356,7 +356,7 @@ class Ui_settingsDialog(object):
self.label_13.setText(_translate("settingsDialog", "Maximum acceptable total difficulty:", None))
self.label_14.setText(_translate("settingsDialog", "Maximum acceptable small message difficulty:", None))
self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tab_2), _translate("settingsDialog", "Max acceptable difficulty", None))
self.label_16.setText(_translate("settingsDialog", "Bitmessage addresses can be fetched automatically from Namecoin identities. You can use either namecoind directly or a running nmcontrol instance.", None))
self.label_16.setText(_translate("settingsDialog", "<html><head/><body><p>Bitmessage can utilize a different Bitcoin-based program called Namecoin to make addresses human-friendly. For example, instead of having to tell your friend your long Bitmessage address, you can simply tell him to send a message to <span style=\" font-style:italic;\">test. </span></p><p>(Getting your own Bitmessage address into Namecoin is still rather difficult).</p><p>Bitmessage can use either namecoind directly or a running nmcontrol instance.</p></body></html>", None))
self.label_17.setText(_translate("settingsDialog", "Host:", None))
self.label_18.setText(_translate("settingsDialog", "Port:", None))
self.labelNamecoinUser.setText(_translate("settingsDialog", "Username:", None))

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>462</width>
<width>567</width>
<height>343</height>
</rect>
</property>
@ -526,7 +526,7 @@
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="label_16">
<property name="text">
<string>Bitmessage addresses can be fetched automatically from Namecoin identities. You can use either namecoind directly or a running nmcontrol instance.</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Bitmessage can utilize a different Bitcoin-based program called Namecoin to make addresses human-friendly. For example, instead of having to tell your friend your long Bitmessage address, you can simply tell him to send a message to &lt;span style=&quot; font-style:italic;&quot;&gt;test. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;(Getting your own Bitmessage address into Namecoin is still rather difficult).&lt;/p&gt;&lt;p&gt;Bitmessage can use either namecoind directly or a running nmcontrol instance.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>

View File

@ -25,6 +25,7 @@ import socket
import sys
import shared
import tr # translate
configSection = "bitmessagesettings"
@ -89,24 +90,21 @@ class namecoinConnection (object):
assert False
except RPCError as exc:
if exc.error["code"] == -4:
return ("The name '%s' was not found." % string, None)
return (tr.translateText("MainWindow",'The name %1 was not found.').arg(unicode(string)), None)
else:
return ("The namecoin query failed (%s)" % exc.error["message"],
None)
return (tr.translateText("MainWindow",'The namecoin query failed (%1)').arg(unicode(exc.error["message"])), None)
except Exception as exc:
print "Namecoin query exception: %s" % str (exc)
return ("The namecoin query failed.", None)
return (tr.translateText("MainWindow",'The namecoin query failed.'), None)
try:
val = json.loads (res)
except:
return ("The name '%s' has no valid JSON data." % string, None)
return (tr.translateText("MainWindow",'The name %1 has no valid JSON data.').arg(unicode(string)), None)
if "bitmessage" in val:
return (None, val["bitmessage"])
return ("The name '%s' has no associated Bitmessage address." % string,
None)
return (tr.translateText("MainWindow",'The name %1 has no associated Bitmessage address.').arg(unicode(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
@ -126,24 +124,23 @@ class namecoinConnection (object):
versStr = "0.%d.%d" % (v1, v2)
else:
versStr = "0.%d.%d.%d" % (v1, v2, v3)
return "Success! Namecoind version %s running." % versStr
return ('success', tr.translateText("MainWindow",'Success! Namecoind version %1 running.').arg(unicode(versStr)) )
elif self.nmctype == "nmcontrol":
res = self.callRPC ("data", ["status"])
prefix = "Plugin data running"
if ("reply" in res) and res["reply"][:len(prefix)] == prefix:
return "Success! NMControll is up and running."
return ('success', tr.translateText("MainWindow",'Success! NMControll is up and running.'))
print "Unexpected nmcontrol reply: %s" % res
return "Couldn't understand NMControl."
return ('failed', tr.translateText("MainWindow",'Couldn\'t understand NMControl.'))
else:
assert False
except Exception as exc:
print "Exception testing the namecoin connection:\n%s" % str (exc)
return "The connection to namecoin failed."
return ('failed', "The connection to namecoin failed.")
# Helper routine that actually performs an JSON RPC call.
def callRPC (self, method, params):
@ -195,6 +192,7 @@ class namecoinConnection (object):
try:
s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt (socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.settimeout(3)
s.connect ((self.host, int (self.port)))
s.sendall (data)
result = ""