parent
9689fff957
commit
bd809abc52
After Width: | Height: | Size: 399 B |
After Width: | Height: | Size: 760 B |
@ -0,0 +1,352 @@
|
||||
// Copyright (c) 2014-2019, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Controls 2.0
|
||||
import QtQuick.Controls.Styles 1.4
|
||||
import QtQuick.Layouts 1.1
|
||||
import QtQuick.Dialogs 1.2
|
||||
|
||||
import "../components" as MoneroComponents
|
||||
import moneroComponents.Clipboard 1.0
|
||||
import moneroComponents.Wallet 1.0
|
||||
import moneroComponents.WalletManager 1.0
|
||||
import moneroComponents.TransactionHistory 1.0
|
||||
import moneroComponents.TransactionHistoryModel 1.0
|
||||
import "../js/TxUtils.js" as TxUtils
|
||||
|
||||
Rectangle {
|
||||
id: pageAccount
|
||||
color: "transparent"
|
||||
property var model
|
||||
property alias accountHeight: mainLayout.height
|
||||
property bool selectAndSend: false
|
||||
|
||||
function renameSubaddressAccountLabel(_index){
|
||||
inputDialog.labelText = qsTr("Set the label of the selected account:") + translationManager.emptyString;
|
||||
inputDialog.inputText = appWindow.currentWallet.getSubaddressLabel(_index, 0);
|
||||
inputDialog.onAcceptedCallback = function() {
|
||||
appWindow.currentWallet.subaddressAccount.setLabel(_index, inputDialog.inputText)
|
||||
}
|
||||
inputDialog.onRejectedCallback = null;
|
||||
inputDialog.open()
|
||||
}
|
||||
|
||||
Clipboard { id: clipboard }
|
||||
|
||||
/* main layout */
|
||||
ColumnLayout {
|
||||
id: mainLayout
|
||||
anchors.margins: (isMobile)? 17 * scaleRatio : 20 * scaleRatio
|
||||
anchors.topMargin: 40 * scaleRatio
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
|
||||
spacing: 20 * scaleRatio
|
||||
|
||||
ColumnLayout {
|
||||
id: balanceRow
|
||||
visible: !selectAndSend
|
||||
spacing: 0
|
||||
|
||||
MoneroComponents.LabelSubheader {
|
||||
Layout.fillWidth: true
|
||||
textFormat: Text.RichText
|
||||
text: qsTr("Balance All")
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.topMargin: 22 * scaleRatio
|
||||
Text {
|
||||
text: qsTr("Total balance: ")
|
||||
Layout.fillWidth: true
|
||||
color: "#757575"
|
||||
font.pixelSize: 14
|
||||
font.family: MoneroComponents.Style.fontRegular.name
|
||||
}
|
||||
Text {
|
||||
id: balanceAll
|
||||
font.family: MoneroComponents.Style.fontRegular.name
|
||||
font.pixelSize: 14
|
||||
color: MoneroComponents.Style.white
|
||||
MouseArea {
|
||||
hoverEnabled: true
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onEntered: {
|
||||
parent.color = MoneroComponents.Style.orange
|
||||
}
|
||||
onExited: {
|
||||
parent.color = MoneroComponents.Style.white
|
||||
}
|
||||
onClicked: {
|
||||
console.log("Copied to clipboard");
|
||||
clipboard.setText(parent.text);
|
||||
appWindow.showStatusMessage(qsTr("Copied to clipboard"),3)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.topMargin: 10 * scaleRatio
|
||||
Text {
|
||||
text: qsTr("Total unlocked balance: ")
|
||||
Layout.fillWidth: true
|
||||
color: "#757575"
|
||||
font.pixelSize: 14
|
||||
font.family: MoneroComponents.Style.fontRegular.name
|
||||
}
|
||||
Text {
|
||||
id: unlockedBalanceAll
|
||||
font.family: MoneroComponents.Style.fontRegular.name
|
||||
font.pixelSize: 14
|
||||
color: MoneroComponents.Style.white
|
||||
MouseArea {
|
||||
hoverEnabled: true
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onEntered: {
|
||||
parent.color = MoneroComponents.Style.orange
|
||||
}
|
||||
onExited: {
|
||||
parent.color = MoneroComponents.Style.white
|
||||
}
|
||||
onClicked: {
|
||||
console.log("Copied to clipboard");
|
||||
clipboard.setText(parent.text);
|
||||
appWindow.showStatusMessage(qsTr("Copied to clipboard"),3)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: addressRow
|
||||
spacing: 0
|
||||
|
||||
MoneroComponents.LabelSubheader {
|
||||
Layout.fillWidth: true
|
||||
textFormat: Text.RichText
|
||||
text: qsTr("Accounts")
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: subaddressAccountListRow
|
||||
property int subaddressAccountListItemHeight: 50 * scaleRatio
|
||||
Layout.topMargin: 6 * scaleRatio
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumWidth: 240
|
||||
Layout.preferredHeight: subaddressAccountListItemHeight * subaddressAccountListView.count
|
||||
visible: subaddressAccountListView.count >= 1
|
||||
|
||||
ListView {
|
||||
id: subaddressAccountListView
|
||||
Layout.fillWidth: true
|
||||
anchors.fill: parent
|
||||
clip: true
|
||||
boundsBehavior: ListView.StopAtBounds
|
||||
delegate: Rectangle {
|
||||
id: tableItem2
|
||||
height: subaddressAccountListRow.subaddressAccountListItemHeight
|
||||
width: parent.width
|
||||
Layout.fillWidth: true
|
||||
color: "transparent"
|
||||
Rectangle {
|
||||
anchors.right: parent.right
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
height: 1
|
||||
color: "#404040"
|
||||
visible: index !== 0
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
anchors.topMargin: 5 * scaleRatio
|
||||
anchors.rightMargin: 80 * scaleRatio
|
||||
color: "transparent"
|
||||
|
||||
MoneroComponents.Label {
|
||||
id: idLabel
|
||||
color: index === appWindow.current_subaddress_account_table_index ? "white" : "#757575"
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 6 * scaleRatio
|
||||
fontSize: 14 * scaleRatio
|
||||
fontBold: true
|
||||
text: "#" + index
|
||||
}
|
||||
|
||||
MoneroComponents.Label {
|
||||
id: nameLabel
|
||||
color: "#a5a5a5"
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: idLabel.right
|
||||
anchors.leftMargin: 6 * scaleRatio
|
||||
fontSize: 14 * scaleRatio
|
||||
fontBold: true
|
||||
text: label
|
||||
elide: Text.ElideRight
|
||||
textWidth: addressLabel.x - nameLabel.x - 1
|
||||
}
|
||||
|
||||
MoneroComponents.Label {
|
||||
id: addressLabel
|
||||
color: "white"
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: balanceLabel.left
|
||||
anchors.leftMargin: (mainLayout.width < 510 ? -70 : -125) * scaleRatio
|
||||
fontSize: 14 * scaleRatio
|
||||
fontBold: true
|
||||
text: TxUtils.addressTruncate(address, mainLayout.width < 510 ? 3 : 6)
|
||||
}
|
||||
|
||||
MoneroComponents.Label {
|
||||
id: balanceLabel
|
||||
color: "white"
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: parent.right
|
||||
anchors.leftMargin: (mainLayout.width < 510 ? -120 : -180) * scaleRatio
|
||||
fontSize: 14 * scaleRatio
|
||||
fontBold: true
|
||||
text: qsTr("Balance: ") + balance
|
||||
elide: mainLayout.width < 510 ? Text.ElideRight : Text.ElideNone
|
||||
textWidth: 120
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
onEntered: {
|
||||
tableItem2.color = "#26FFFFFF"
|
||||
}
|
||||
onExited: {
|
||||
tableItem2.color = "transparent"
|
||||
}
|
||||
onClicked: {
|
||||
if (index == subaddressAccountListView.currentIndex && selectAndSend) {
|
||||
appWindow.showPageRequest("Transfer");
|
||||
}
|
||||
subaddressAccountListView.currentIndex = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MoneroComponents.IconButton {
|
||||
id: renameButton
|
||||
imageSource: "../images/editIcon.png"
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 30 * scaleRatio
|
||||
anchors.topMargin: 1 * scaleRatio
|
||||
|
||||
onClicked: {
|
||||
renameSubaddressAccountLabel(index);
|
||||
}
|
||||
}
|
||||
|
||||
MoneroComponents.IconButton {
|
||||
id: copyButton
|
||||
imageSource: "../images/dropdownCopy.png"
|
||||
anchors.right: parent.right
|
||||
|
||||
onClicked: {
|
||||
console.log("Address copied to clipboard");
|
||||
clipboard.setText(address);
|
||||
appWindow.showStatusMessage(qsTr("Address copied to clipboard"),3);
|
||||
}
|
||||
}
|
||||
}
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
color: "#404040"
|
||||
Layout.fillWidth: true
|
||||
height: 1
|
||||
}
|
||||
|
||||
MoneroComponents.CheckBox {
|
||||
id: addNewAccountCheckbox
|
||||
visible: !selectAndSend
|
||||
border: false
|
||||
checkedIcon: "qrc:///images/plus-in-circle-medium-white.png"
|
||||
uncheckedIcon: "qrc:///images/plus-in-circle-medium-white.png"
|
||||
fontSize: 14 * scaleRatio
|
||||
iconOnTheLeft: true
|
||||
Layout.fillWidth: true
|
||||
Layout.topMargin: 10 * scaleRatio
|
||||
text: qsTr("Create new account") + translationManager.emptyString;
|
||||
onClicked: {
|
||||
inputDialog.labelText = qsTr("Set the label of the new account:") + translationManager.emptyString
|
||||
inputDialog.inputText = qsTr("(Untitled)")
|
||||
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
|
||||
appWindow.onWalletUpdate();
|
||||
}
|
||||
inputDialog.onRejectedCallback = null;
|
||||
inputDialog.open()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onPageCompleted() {
|
||||
console.log("account");
|
||||
if (appWindow.currentWallet !== undefined) {
|
||||
appWindow.currentWallet.subaddressAccount.refresh();
|
||||
subaddressAccountListView.model = appWindow.currentWallet.subaddressAccountModel;
|
||||
appWindow.currentWallet.subaddress.refresh(appWindow.currentWallet.currentSubaddressAccount)
|
||||
|
||||
balanceAll.text = walletManager.displayAmount(appWindow.currentWallet.balanceAll())
|
||||
unlockedBalanceAll.text = walletManager.displayAmount(appWindow.currentWallet.unlockedBalanceAll())
|
||||
}
|
||||
}
|
||||
|
||||
function onPageClosed() {
|
||||
selectAndSend = false;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
#include "SubaddressAccount.h"
|
||||
#include <QDebug>
|
||||
|
||||
SubaddressAccount::SubaddressAccount(Monero::SubaddressAccount *subaddressAccountImpl, QObject *parent)
|
||||
: QObject(parent), m_subaddressAccountImpl(subaddressAccountImpl)
|
||||
{
|
||||
qDebug(__FUNCTION__);
|
||||
getAll();
|
||||
}
|
||||
|
||||
QList<Monero::SubaddressAccountRow*> SubaddressAccount::getAll(bool update) const
|
||||
{
|
||||
qDebug(__FUNCTION__);
|
||||
|
||||
emit refreshStarted();
|
||||
|
||||
if(update)
|
||||
m_rows.clear();
|
||||
|
||||
if (m_rows.empty()){
|
||||
for (auto &row: m_subaddressAccountImpl->getAll()) {
|
||||
m_rows.append(row);
|
||||
}
|
||||
}
|
||||
|
||||
emit refreshFinished();
|
||||
return m_rows;
|
||||
}
|
||||
|
||||
Monero::SubaddressAccountRow * SubaddressAccount::getRow(int index) const
|
||||
{
|
||||
return m_rows.at(index);
|
||||
}
|
||||
|
||||
void SubaddressAccount::addRow(const QString &label) const
|
||||
{
|
||||
m_subaddressAccountImpl->addRow(label.toStdString());
|
||||
getAll(true);
|
||||
}
|
||||
|
||||
void SubaddressAccount::setLabel(quint32 accountIndex, const QString &label) const
|
||||
{
|
||||
m_subaddressAccountImpl->setLabel(accountIndex, label.toStdString());
|
||||
getAll(true);
|
||||
}
|
||||
|
||||
void SubaddressAccount::refresh() const
|
||||
{
|
||||
m_subaddressAccountImpl->refresh();
|
||||
getAll(true);
|
||||
}
|
||||
|
||||
quint64 SubaddressAccount::count() const
|
||||
{
|
||||
return m_rows.size();
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
#ifndef SUBADDRESSACCOUNT_H
|
||||
#define SUBADDRESSACCOUNT_H
|
||||
|
||||
#include <wallet/api/wallet2_api.h>
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QDateTime>
|
||||
|
||||
class SubaddressAccount : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_INVOKABLE QList<Monero::SubaddressAccountRow*> getAll(bool update = false) const;
|
||||
Q_INVOKABLE Monero::SubaddressAccountRow * getRow(int index) const;
|
||||
Q_INVOKABLE void addRow(const QString &label) const;
|
||||
Q_INVOKABLE void setLabel(quint32 accountIndex, const QString &label) const;
|
||||
Q_INVOKABLE void refresh() const;
|
||||
quint64 count() const;
|
||||
|
||||
signals:
|
||||
void refreshStarted() const;
|
||||
void refreshFinished() const;
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
explicit SubaddressAccount(Monero::SubaddressAccount * subaddressAccountImpl, QObject *parent);
|
||||
friend class Wallet;
|
||||
Monero::SubaddressAccount * m_subaddressAccountImpl;
|
||||
mutable QList<Monero::SubaddressAccountRow*> m_rows;
|
||||
};
|
||||
|
||||
#endif // SUBADDRESSACCOUNT_H
|
@ -0,0 +1,66 @@
|
||||
#include "SubaddressAccountModel.h"
|
||||
#include "SubaddressAccount.h"
|
||||
#include <QDebug>
|
||||
#include <QHash>
|
||||
#include <wallet/api/wallet2_api.h>
|
||||
|
||||
SubaddressAccountModel::SubaddressAccountModel(QObject *parent, SubaddressAccount *subaddressAccount)
|
||||
: QAbstractListModel(parent), m_subaddressAccount(subaddressAccount)
|
||||
{
|
||||
qDebug(__FUNCTION__);
|
||||
connect(m_subaddressAccount,SIGNAL(refreshStarted()),this,SLOT(startReset()));
|
||||
connect(m_subaddressAccount,SIGNAL(refreshFinished()),this,SLOT(endReset()));
|
||||
}
|
||||
|
||||
void SubaddressAccountModel::startReset(){
|
||||
qDebug("SubaddressAccountModel::startReset");
|
||||
beginResetModel();
|
||||
}
|
||||
void SubaddressAccountModel::endReset(){
|
||||
qDebug("SubaddressAccountModel::endReset");
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
int SubaddressAccountModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return m_subaddressAccount->count();
|
||||
}
|
||||
|
||||
QVariant SubaddressAccountModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0 || (unsigned)index.row() >= m_subaddressAccount->count())
|
||||
return {};
|
||||
|
||||
Monero::SubaddressAccountRow * sr = m_subaddressAccount->getRow(index.row());
|
||||
|
||||
QVariant result = "";
|
||||
switch (role) {
|
||||
case SubaddressAccountAddressRole:
|
||||
result = QString::fromStdString(sr->getAddress());
|
||||
break;
|
||||
case SubaddressAccountLabelRole:
|
||||
result = QString::fromStdString(sr->getLabel());
|
||||
break;
|
||||
case SubaddressAccountBalanceRole:
|
||||
result = QString::fromStdString(sr->getBalance());
|
||||
break;
|
||||
case SubaddressAccountUnlockedBalanceRole:
|
||||
result = QString::fromStdString(sr->getUnlockedBalance());
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> SubaddressAccountModel::roleNames() const
|
||||
{
|
||||
static QHash<int, QByteArray> roleNames;
|
||||
if (roleNames.empty())
|
||||
{
|
||||
roleNames.insert(SubaddressAccountAddressRole, "address");
|
||||
roleNames.insert(SubaddressAccountLabelRole, "label");
|
||||
roleNames.insert(SubaddressAccountBalanceRole, "balance");
|
||||
roleNames.insert(SubaddressAccountUnlockedBalanceRole, "unlockedBalance");
|
||||
}
|
||||
return roleNames;
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
#ifndef SUBADDRESSACCOUNTMODEL_H
|
||||
#define SUBADDRESSACCOUNTMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
|
||||
class SubaddressAccount;
|
||||
|
||||
class SubaddressAccountModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum SubaddressAccountRowRole {
|
||||
SubaddressAccountRole = Qt::UserRole + 1, // for the SubaddressAccountRow object;
|
||||
SubaddressAccountAddressRole,
|
||||
SubaddressAccountLabelRole,
|
||||
SubaddressAccountBalanceRole,
|
||||
SubaddressAccountUnlockedBalanceRole,
|
||||
};
|
||||
Q_ENUM(SubaddressAccountRowRole)
|
||||
|
||||
SubaddressAccountModel(QObject *parent, SubaddressAccount *subaddressAccount);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
public slots:
|
||||
void startReset();
|
||||
void endReset();
|
||||
|
||||
private:
|
||||
SubaddressAccount *m_subaddressAccount;
|
||||
};
|
||||
|
||||
#endif // SUBADDRESSACCOUNTMODEL_H
|
Reference in new issue