From 646d3394d39bdd7c3ff5a5abddb54367a1980b6c Mon Sep 17 00:00:00 2001 From: xiphon Date: Tue, 3 Dec 2019 11:53:12 +0000 Subject: [PATCH] Wallet: persistent subaddress account selection --- LeftPanel.qml | 7 +++---- main.qml | 11 ++++++++--- pages/Account.qml | 20 ++++++-------------- src/libwalletqt/Wallet.cpp | 8 ++++++++ src/libwalletqt/Wallet.h | 3 ++- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/LeftPanel.qml b/LeftPanel.qml index 308e1954..959f5189 100644 --- a/LeftPanel.qml +++ b/LeftPanel.qml @@ -40,8 +40,8 @@ import "components/effects/" as MoneroEffects Rectangle { id: panel - property int currentAccountIndex: 0 - property string currentAccountLabel: "Primary account" + property int currentAccountIndex + property alias currentAccountLabel: accountLabel.text property string balanceString: "?.??" property string balanceUnlockedString: "?.??" property string balanceFiatString: "?.??" @@ -184,7 +184,7 @@ Rectangle { MoneroComponents.Label { fontSize: 12 id: accountIndex - text: qsTr("Account") + " #" + currentAccountIndex + text: qsTr("Account") + translationManager.emptyString + " #" + currentAccountIndex color: MoneroComponents.Style.blackTheme ? "white" : "black" anchors.left: parent.left anchors.leftMargin: 60 @@ -204,7 +204,6 @@ Rectangle { fontSize: 16 id: accountLabel textWidth: 170 - text: currentAccountLabel color: MoneroComponents.Style.blackTheme ? "white" : "black" anchors.left: parent.left anchors.leftMargin: 60 diff --git a/main.qml b/main.qml index 8522267a..7e28a4c6 100644 --- a/main.qml +++ b/main.qml @@ -112,7 +112,6 @@ ApplicationWindow { property var current_address property var current_address_label: "Primary" property int current_subaddress_table_index: 0 - property int current_subaddress_account_table_index: 0 function altKeyReleased() { ctrlPressed = false; } @@ -418,8 +417,6 @@ ApplicationWindow { } leftPanel.minutesToUnlock = (balance !== balanceU) ? currentWallet.history.minutesToUnlock : ""; - leftPanel.currentAccountIndex = currentWallet.currentSubaddressAccount; - leftPanel.currentAccountLabel = currentWallet.getSubaddressLabel(currentWallet.currentSubaddressAccount, 0); leftPanel.balanceString = balance leftPanel.balanceUnlockedString = balanceU } @@ -1616,6 +1613,13 @@ ApplicationWindow { anchors.left: parent.left anchors.bottom: parent.bottom visible: rootItem.state == "normal" && middlePanel.state != "Merchant" + currentAccountIndex: currentWallet ? currentWallet.currentSubaddressAccount : 0 + currentAccountLabel: { + if (currentWallet) { + return currentWallet.getSubaddressLabel(currentWallet.currentSubaddressAccount, 0); + } + return qsTr("Primary account") + translationManager.emptyString; + } onTransferClicked: { middlePanel.state = "Transfer"; @@ -1687,6 +1691,7 @@ ApplicationWindow { MiddlePanel { id: middlePanel + accountView.currentAccountIndex: currentWallet ? currentWallet.currentSubaddressAccount : 0 anchors.top: parent.top anchors.bottom: parent.bottom anchors.left: leftPanel.visible ? leftPanel.right : parent.left diff --git a/pages/Account.qml b/pages/Account.qml index 13c2b1cf..c34e6218 100644 --- a/pages/Account.qml +++ b/pages/Account.qml @@ -49,6 +49,7 @@ Rectangle { property var model property alias accountHeight: mainLayout.height property bool selectAndSend: false + property int currentAccountIndex function renameSubaddressAccountLabel(_index){ inputDialog.labelText = qsTr("Set the label of the selected account:") + translationManager.emptyString; @@ -180,6 +181,7 @@ Rectangle { clip: true boundsBehavior: ListView.StopAtBounds interactive: false + currentIndex: currentAccountIndex delegate: Rectangle { id: tableItem2 @@ -211,7 +213,7 @@ Rectangle { MoneroComponents.Label { id: idLabel - color: index === appWindow.current_subaddress_account_table_index ? MoneroComponents.Style.defaultFontColor : "#757575" + color: index === currentAccountIndex ? MoneroComponents.Style.defaultFontColor : "#757575" anchors.verticalCenter: parent.verticalCenter anchors.left: parent.left anchors.leftMargin: 6 @@ -278,9 +280,9 @@ Rectangle { onEntered: tableItem2.color = MoneroComponents.Style.titleBarButtonHoverColor onExited: tableItem2.color = "transparent" onClicked: { - if (index == subaddressAccountListView.currentIndex && selectAndSend) + appWindow.currentWallet.switchSubaddressAccount(index); + if (selectAndSend) appWindow.showPageRequest("Transfer"); - subaddressAccountListView.currentIndex = index; } } } @@ -319,17 +321,9 @@ Rectangle { } } } - onCurrentItemChanged: { - // reset global vars - appWindow.current_subaddress_account_table_index = subaddressAccountListView.currentIndex; - appWindow.currentWallet.switchSubaddressAccount(appWindow.current_subaddress_account_table_index); - appWindow.onWalletUpdate(); - } onCurrentIndexChanged: { - if (selectAndSend) { - appWindow.showPageRequest("Transfer"); - } + appWindow.onWalletUpdate(); } } } @@ -364,8 +358,6 @@ Rectangle { inputDialog.onAcceptedCallback = function() { appWindow.currentWallet.subaddressAccount.addRow(inputDialog.inputText) appWindow.currentWallet.switchSubaddressAccount(appWindow.currentWallet.numSubaddressAccounts() - 1) - current_subaddress_account_table_index = appWindow.currentWallet.numSubaddressAccounts() - 1 - subaddressAccountListView.currentIndex = current_subaddress_account_table_index appWindow.onWalletUpdate(); } inputDialog.onRejectedCallback = null; diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 5b0f0719..7b122481 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -55,6 +55,8 @@ namespace { static const int DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS = 5; static const int DAEMON_BLOCKCHAIN_TARGET_HEIGHT_CACHE_TTL_SECONDS = 30; static const int WALLET_CONNECTION_STATUS_CACHE_TTL_SECONDS = 5; + + static constexpr char ATTRIBUTE_SUBADDRESS_ACCOUNT[] ="gui.subaddress_account"; } class WalletListenerImpl : public Monero::WalletListener @@ -316,8 +318,13 @@ void Wallet::switchSubaddressAccount(quint32 accountIndex) if (accountIndex < numSubaddressAccounts()) { m_currentSubaddressAccount = accountIndex; + if (!setCacheAttribute(ATTRIBUTE_SUBADDRESS_ACCOUNT, QString::number(m_currentSubaddressAccount))) + { + qWarning() << "failed to set " << ATTRIBUTE_SUBADDRESS_ACCOUNT << " cache attribute"; + } m_subaddress->refresh(m_currentSubaddressAccount); m_history->refresh(m_currentSubaddressAccount); + emit currentSubaddressAccountChanged(); } } void Wallet::addSubaddressAccount(const QString& label) @@ -982,6 +989,7 @@ Wallet::Wallet(Monero::Wallet *w, QObject *parent) m_walletListener = new WalletListenerImpl(this); m_walletImpl->setListener(m_walletListener); m_connectionStatus = Wallet::ConnectionStatus_Disconnected; + m_currentSubaddressAccount = getCacheAttribute(ATTRIBUTE_SUBADDRESS_ACCOUNT).toUInt(); // start cache timers m_connectionStatusTime.restart(); m_daemonBlockChainHeightTime.restart(); diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index fb2dc3f8..30861c78 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -65,7 +65,7 @@ class Wallet : public QObject Q_PROPERTY(Status status READ status) Q_PROPERTY(NetworkType::Type nettype READ nettype) // Q_PROPERTY(ConnectionStatus connected READ connected) - Q_PROPERTY(quint32 currentSubaddressAccount READ currentSubaddressAccount) + Q_PROPERTY(quint32 currentSubaddressAccount READ currentSubaddressAccount NOTIFY currentSubaddressAccountChanged) Q_PROPERTY(bool synchronized READ synchronized) Q_PROPERTY(QString errorString READ errorString) Q_PROPERTY(TransactionHistory * history READ history) @@ -365,6 +365,7 @@ signals: void transactionCreated(PendingTransaction * transaction, QString address, QString paymentId, quint32 mixinCount); void connectionStatusChanged(int status) const; + void currentSubaddressAccountChanged() const; private: Wallet(QObject * parent = nullptr);