From 077177b742c8622043228bccb3544e6dba375eef Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Wed, 14 Aug 2013 18:59:50 -0400 Subject: [PATCH] Dont show Fetch button if cannot connect to Namecoin --- src/bitmessageqt/__init__.py | 23 +++++++++++++++++++---- src/bitmessageqt/settings.py | 8 ++++---- src/bitmessageqt/settings.ui | 4 ++-- src/namecoin.py | 24 +++++++++++------------- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index f6eb762e..b426e6e5 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -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): diff --git a/src/bitmessageqt/settings.py b/src/bitmessageqt/settings.py index a899ecbe..87e8ba7b 100644 --- a/src/bitmessageqt/settings.py +++ b/src/bitmessageqt/settings.py @@ -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", "

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 test.

(Getting your own Bitmessage address into Namecoin is still rather difficult).

Bitmessage can use either namecoind directly or a running nmcontrol instance.

", None)) self.label_17.setText(_translate("settingsDialog", "Host:", None)) self.label_18.setText(_translate("settingsDialog", "Port:", None)) self.labelNamecoinUser.setText(_translate("settingsDialog", "Username:", None)) diff --git a/src/bitmessageqt/settings.ui b/src/bitmessageqt/settings.ui index 90487305..0ca22088 100644 --- a/src/bitmessageqt/settings.ui +++ b/src/bitmessageqt/settings.ui @@ -6,7 +6,7 @@ 0 0 - 462 + 567 343 @@ -526,7 +526,7 @@ - Bitmessage addresses can be fetched automatically from Namecoin identities. You can use either namecoind directly or a running nmcontrol instance. + <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> true diff --git a/src/namecoin.py b/src/namecoin.py index 57059a1c..3f6c584c 100644 --- a/src/namecoin.py +++ b/src/namecoin.py @@ -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 = ""