From 00aa23162c3300dfce19fc995e0eed0296e73a62 Mon Sep 17 00:00:00 2001 From: Jaquee Date: Sat, 25 Feb 2017 22:16:58 +0100 Subject: [PATCH] Daemon rpc login support requires #1803 --- components/LineEdit.qml | 1 + main.qml | 6 ++++++ pages/Settings.qml | 39 +++++++++++++++++++++++++++++++++++--- src/libwalletqt/Wallet.cpp | 11 ++++++++++- src/libwalletqt/Wallet.h | 5 +++++ 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/components/LineEdit.qml b/components/LineEdit.qml index 1d83e617..3760fd2a 100644 --- a/components/LineEdit.qml +++ b/components/LineEdit.qml @@ -35,6 +35,7 @@ Item { property alias validator: input.validator property alias readOnly : input.readOnly property alias cursorPosition: input.cursorPosition + property alias echoMode: input.echoMode property int fontSize: 18 property bool error: false signal editingFinished() diff --git a/main.qml b/main.qml index 843c43b4..49851b20 100644 --- a/main.qml +++ b/main.qml @@ -257,6 +257,10 @@ ApplicationWindow { console.log("initializing with daemon address: ", persistentSettings.daemon_address) console.log("Recovering from seed: ", persistentSettings.is_recovering) console.log("restore Height", persistentSettings.restore_height) + + // Use saved daemon rpc login settings + currentWallet.setDaemonLogin(persistentSettings.daemonUsername, persistentSettings.daemonPassword); + currentWallet.initAsync(persistentSettings.daemon_address, 0, persistentSettings.is_recovering, persistentSettings.restore_height); } @@ -800,6 +804,8 @@ ApplicationWindow { property string daemonFlags property int logLevel: 0 property string logCategories: "" + property string daemonUsername: "" + property string daemonPassword: "" } // Information dialog diff --git a/pages/Settings.qml b/pages/Settings.qml index 651357cb..5286548b 100644 --- a/pages/Settings.qml +++ b/pages/Settings.qml @@ -236,7 +236,35 @@ Rectangle { text: (daemonAddress !== undefined) ? daemonAddress[1] : "18081" placeholderText: qsTr("Port") } + } + RowLayout { + + Label { + id: daemonLoginLabel + Layout.fillWidth: true + color: "#4A4949" + text: qsTr("Login (optional)") + translationManager.emptyString + fontSize: 16 + } + + LineEdit { + id: daemonUsername + Layout.preferredWidth: 100 + Layout.fillWidth: true + text: persistentSettings.daemonUsername + placeholderText: qsTr("Username") + } + + + LineEdit { + id: daemonPassword + Layout.preferredWidth: 100 + Layout.fillWidth: true + text: persistentSettings.daemonPassword + placeholderText: qsTr("Password") + echoMode: TextInput.Password + } StandardButton { id: daemonAddrSave @@ -253,12 +281,17 @@ Rectangle { var newDaemon = daemonAddr.text + ":" + daemonPort.text if(persistentSettings.daemon_address != newDaemon) { persistentSettings.daemon_address = newDaemon - //Reinit wallet - currentWallet.initAsync(newDaemon) } + + // Update daemon login + persistentSettings.daemonUsername = daemonUsername.text; + persistentSettings.daemonPassword = daemonPassword.text; + currentWallet.setDaemonLogin(persistentSettings.daemonUsername, persistentSettings.daemonPassword); + + //Reinit wallet + currentWallet.initAsync(newDaemon); } } - } RowLayout { diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 8913d4c3..2957618a 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -178,10 +178,17 @@ bool Wallet::init(const QString &daemonAddress, quint64 upperTransactionLimit, b m_walletImpl->setRecoveringFromSeed(true); m_walletImpl->setRefreshFromBlockHeight(restoreHeight); } - m_walletImpl->init(daemonAddress.toStdString(), upperTransactionLimit); + m_walletImpl->init(daemonAddress.toStdString(), upperTransactionLimit, m_daemonUsername.toStdString(), m_daemonPassword.toStdString()); return true; } +void Wallet::setDaemonLogin(const QString &daemonUsername, const QString &daemonPassword) +{ + // store daemon login + m_daemonUsername = daemonUsername; + m_daemonPassword = daemonPassword; +} + void Wallet::initAsync(const QString &daemonAddress, quint64 upperTransactionLimit, bool isRecovering, quint64 restoreHeight) { qDebug() << "initAsync: " + daemonAddress; @@ -593,6 +600,8 @@ Wallet::Wallet(Monero::Wallet *w, QObject *parent) m_daemonBlockChainTargetHeightTime.restart(); m_initialized = false; m_connectionStatusRunning = false; + m_daemonUsername = ""; + m_daemonPassword = ""; } Wallet::~Wallet() diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index a11cabe9..a01d5c37 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -106,6 +106,9 @@ public: //! initializes wallet asynchronously Q_INVOKABLE void initAsync(const QString &daemonAddress, quint64 upperTransactionLimit = 0, bool isRecovering = false, quint64 restoreHeight = 0); + // Set daemon rpc user/pass + Q_INVOKABLE void setDaemonLogin(const QString &daemonUsername = "", const QString &daemonPassword = ""); + //! create a view only wallet Q_INVOKABLE bool createViewOnly(const QString &path, const QString &password) const; @@ -271,6 +274,8 @@ private: mutable AddressBookModel * m_addressBookModel; QMutex m_connectionStatusMutex; bool m_connectionStatusRunning; + QString m_daemonUsername; + QString m_daemonPassword; };