1
mirror of https://github.com/monero-project/monero-gui synced 2024-12-18 05:15:54 +01:00

added TransactionHistoryModel; renamings

This commit is contained in:
Ilya Kitaev 2016-10-02 21:40:40 +03:00
parent bd8646dd19
commit 0ff3fd3212
22 changed files with 256 additions and 46 deletions

View File

@ -252,17 +252,17 @@ Rectangle {
panel.receiveClicked()
}
}
/*
Rectangle {
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: 16
color: transferButton.checked || historyButton.checked ? "#1C1C1C" : "#505050"
height: 1
}*/
}
// ------------- History tab ---------------
/*
MenuButton {
id: historyButton
anchors.left: parent.left
@ -276,7 +276,7 @@ Rectangle {
panel.historyClicked()
}
}
/*
Rectangle {
anchors.left: parent.left
anchors.right: parent.right

View File

@ -27,6 +27,8 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import QtQuick 2.2
import QtQml 2.0
import QtQuick.Controls 2.0
import QtGraphicalEffects 1.0
Rectangle {
@ -73,6 +75,18 @@ Rectangle {
Rectangle { height: 4; width: parent.width / 5; color: "#FF4F41" }
}
// TODO: replace loader with StackView
// StackView {
// id: stackView
// anchors.left: parent.left
// anchors.right: parent.right
// anchors.top: styledRow.bottom
// anchors.bottom: parent.bottom
// }
Loader {
id: loader
anchors.left: parent.left

View File

@ -27,7 +27,7 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import QtQuick 2.0
import moneroComponents 1.0
import moneroComponents.Clipboard 1.0
ListView {
id: listView

View File

@ -27,7 +27,7 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import QtQuick 2.0
import moneroComponents 1.0
import moneroComponents.Clipboard 1.0
ListView {
id: listView

View File

@ -27,7 +27,7 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import QtQuick 2.0
import moneroComponents 1.0
import moneroComponents.Clipboard 1.0
ListView {
id: listView

View File

@ -1,10 +1,10 @@
#!/bin/bash
MONERO_URL=https://github.com/monero-project/monero.git
MONERO_BRANCH=master
# MONERO_URL=https://github.com/mbg033/monero.git
# MONERO_BRANCH=develop
# MONERO_URL=https://github.com/monero-project/monero.git
# MONERO_BRANCH=master
MONERO_URL=https://github.com/mbg033/monero.git
MONERO_BRANCH=develop
# thanks to SO: http://stackoverflow.com/a/20283965/4118915
CPU_CORE_COUNT=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)
pushd $(pwd)

View File

@ -39,7 +39,7 @@
#include "Wallet.h"
#include "PendingTransaction.h"
#include "TranslationManager.h"
#include "model/TransactionHistoryModel.h"
@ -56,14 +56,15 @@ int main(int argc, char *argv[])
filter *eventFilter = new filter;
app.installEventFilter(eventFilter);
qmlRegisterType<clipboardAdapter>("moneroComponents", 1, 0, "Clipboard");
qmlRegisterType<clipboardAdapter>("moneroComponents.Clipboard", 1, 0, "Clipboard");
qmlRegisterUncreatableType<Wallet>("Bitmonero.Wallet", 1, 0, "Wallet", "Wallet can't be instantiated directly");
qmlRegisterUncreatableType<Wallet>("moneroComponents.Wallet", 1, 0, "Wallet", "Wallet can't be instantiated directly");
qmlRegisterUncreatableType<PendingTransaction>("Bitmonero.PendingTransaction", 1, 0, "PendingTransaction",
qmlRegisterUncreatableType<PendingTransaction>("moneroComponents.PendingTransaction", 1, 0, "PendingTransaction",
"PendingTransaction can't be instantiated directly");
qmlRegisterUncreatableType<WalletManager>("Bitmonero.WalletManager", 1, 0, "WalletManager",
qmlRegisterUncreatableType<WalletManager>("moneroComponents.WalletManager", 1, 0, "WalletManager",
"WalletManager can't be instantiated directly");
qmlRegisterUncreatableType<TranslationManager>("moneroComponents", 1, 0, "TranslationManager",
@ -72,6 +73,8 @@ int main(int argc, char *argv[])
qRegisterMetaType<PendingTransaction::Priority>();
qmlRegisterUncreatableType<TransactionHistoryModel>("moneroComponents", 1, 0, "TransactionHistoryModel",
"TranslationManager can't be instantiated directly");
QQmlApplicationEngine engine;

View File

@ -32,8 +32,9 @@ import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
import QtQuick.Dialogs 1.2
import Qt.labs.settings 1.0
import Bitmonero.Wallet 1.0
import Bitmonero.PendingTransaction 1.0
import moneroComponents.Wallet 1.0
import moneroComponents.PendingTransaction 1.0
import "components"
@ -146,7 +147,7 @@ ApplicationWindow {
} else {
var wallet_path = walletPath();
// console.log("opening wallet at: ", wallet_path, "with password: ", appWindow.password);
console.log("opening wallet at: ", wallet_path);
console.log("opening wallet at: ", wallet_path, ", testnet: ", persistentSettings.testnet);
walletManager.openWalletAsync(wallet_path, appWindow.password,
persistentSettings.testnet);
}

View File

@ -10,7 +10,8 @@ CONFIG += c++11
QMAKE_DISTCLEAN += -r $$WALLET_ROOT
INCLUDEPATH += $$WALLET_ROOT/include \
$$PWD/src/libwalletqt
$$PWD/src/libwalletqt \
$$PWD/src
HEADERS += \
filter.h \
@ -22,7 +23,8 @@ HEADERS += \
src/libwalletqt/TransactionHistory.h \
src/libwalletqt/TransactionInfo.h \
oshelper.h \
TranslationManager.h
TranslationManager.h \
src/model/TransactionHistoryModel.h
SOURCES += main.cpp \
@ -35,7 +37,8 @@ SOURCES += main.cpp \
src/libwalletqt/TransactionHistory.cpp \
src/libwalletqt/TransactionInfo.cpp \
oshelper.cpp \
TranslationManager.cpp
TranslationManager.cpp \
src/model/TransactionHistoryModel.cpp
lupdate_only {
SOURCES = *.qml \

View File

@ -28,6 +28,8 @@
import QtQuick 2.0
import "../components"
import moneroComponents.Wallet 1.0
import moneroComponents.WalletManager 1.0
Rectangle {
color: "#F0EEEE"

View File

@ -32,7 +32,7 @@ import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.1
import "../components"
import moneroComponents 1.0
import moneroComponents.Clipboard 1.0
Rectangle {

View File

@ -27,7 +27,7 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import QtQuick 2.0
import Bitmonero.PendingTransaction 1.0
import moneroComponents.PendingTransaction 1.0
import "../components"

View File

@ -3,11 +3,6 @@
#include <wallet/wallet2_api.h>
int TransactionHistory::count() const
{
return m_pimpl->count();
}
TransactionInfo *TransactionHistory::transaction(int index)
{
// box up Bitmonero::TransactionInfo
@ -39,10 +34,17 @@ QList<TransactionInfo *> TransactionHistory::getAll() const
void TransactionHistory::refresh()
{
// XXX this invalidates previously saved history that might be used by clients
emit refreshStarted();
m_pimpl->refresh();
emit invalidated();
emit refreshFinished();
}
quint64 TransactionHistory::count() const
{
return m_pimpl->count();
}
TransactionHistory::TransactionHistory(Bitmonero::TransactionHistory *pimpl, QObject *parent)
: QObject(parent), m_pimpl(pimpl)
{

View File

@ -16,14 +16,15 @@ class TransactionHistory : public QObject
Q_PROPERTY(int count READ count)
public:
int count() const;
Q_INVOKABLE TransactionInfo *transaction(int index);
Q_INVOKABLE TransactionInfo * transaction(const QString &id);
Q_INVOKABLE QList<TransactionInfo*> getAll() const;
Q_INVOKABLE void refresh();
quint64 count() const;
signals:
void invalidated();
void refreshStarted();
void refreshFinished();
public slots:

View File

@ -1,4 +1,6 @@
#include "TransactionInfo.h"
#include "WalletManager.h"
#include <QDateTime>
TransactionInfo::Direction TransactionInfo::direction() const
@ -16,15 +18,15 @@ bool TransactionInfo::isFailed() const
return m_pimpl->isFailed();
}
quint64 TransactionInfo::amount() const
QString TransactionInfo::amount() const
{
return m_pimpl->amount();
return WalletManager::instance()->displayAmount(m_pimpl->amount());
}
quint64 TransactionInfo::fee() const
QString TransactionInfo::fee() const
{
return m_pimpl->fee();
return WalletManager::instance()->displayAmount(m_pimpl->fee());
}
quint64 TransactionInfo::blockHeight() const

View File

@ -10,8 +10,8 @@ class TransactionInfo : public QObject
Q_PROPERTY(Direction direction READ direction)
Q_PROPERTY(bool isPending READ isPending)
Q_PROPERTY(bool isFailed READ isFailed)
Q_PROPERTY(quint64 amount READ amount)
Q_PROPERTY(quint64 fee READ fee)
Q_PROPERTY(QString amount READ amount)
Q_PROPERTY(QString fee READ fee)
Q_PROPERTY(quint64 blockHeight READ blockHeight)
Q_PROPERTY(QString hash READ hash)
Q_PROPERTY(QString timestamp READ timestamp)
@ -23,6 +23,8 @@ public:
Direction_Out = Bitmonero::TransactionInfo::Direction_Out
};
Q_ENUM(Direction)
// TODO: implement as separate class;
// struct Transfer {
@ -30,11 +32,12 @@ public:
// const uint64_t amount;
// const std::string address;
// };
Direction direction() const;
bool isPending() const;
bool isFailed() const;
quint64 amount() const;
quint64 fee() const;
QString amount() const;
QString fee() const;
quint64 blockHeight() const;
//! transaction_id
QString hash() const;
@ -51,4 +54,7 @@ private:
Bitmonero::TransactionInfo * m_pimpl;
};
// in order to wrap it to QVariant
Q_DECLARE_METATYPE(TransactionInfo*)
#endif // TRANSACTIONINFO_H

View File

@ -1,6 +1,7 @@
#include "Wallet.h"
#include "PendingTransaction.h"
#include "TransactionHistory.h"
#include "model/TransactionHistoryModel.h"
#include "wallet/wallet2_api.h"
#include <QFile>
@ -59,7 +60,10 @@ private:
Wallet * m_wallet;
};
Wallet::Wallet(QObject * parent)
: Wallet(nullptr, parent)
{
}
QString Wallet::getSeed() const
{
@ -202,6 +206,16 @@ TransactionHistory *Wallet::history()
return m_history;
}
TransactionHistoryModel *Wallet::historyModel()
{
if (!m_historyModel) {
m_historyModel = new TransactionHistoryModel(this);
m_historyModel->setTransactionHistory(this->history());
}
return m_historyModel;
}
QString Wallet::generatePaymentId() const
{
@ -228,6 +242,7 @@ Wallet::Wallet(Bitmonero::Wallet *w, QObject *parent)
: QObject(parent)
, m_walletImpl(w)
, m_history(nullptr)
, m_historyModel(nullptr)
, m_daemonBlockChainHeight(0)
, m_daemonBlockChainHeightTtl(DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS)
{
@ -236,5 +251,6 @@ Wallet::Wallet(Bitmonero::Wallet *w, QObject *parent)
Wallet::~Wallet()
{
Bitmonero::WalletManagerFactory::getWalletManager()->closeWallet(m_walletImpl);
}

View File

@ -13,6 +13,7 @@ namespace Bitmonero {
class TransactionHistory;
class TransactionHistoryModel;
class Wallet : public QObject
{
@ -27,8 +28,11 @@ class Wallet : public QObject
Q_PROPERTY(quint64 unlockedBalance READ unlockedBalance)
Q_PROPERTY(TransactionHistory * history READ history)
Q_PROPERTY(QString paymentId READ paymentId WRITE setPaymentId)
Q_PROPERTY(TransactionHistoryModel * historyModel READ historyModel)
public:
enum Status {
Status_Ok = Bitmonero::Wallet::Status_Ok,
Status_Error = Bitmonero::Wallet::Status_Error
@ -111,6 +115,9 @@ public:
//! returns transaction history
TransactionHistory * history();
//! returns transaction history model
TransactionHistoryModel * historyModel();
//! generate payment id
Q_INVOKABLE QString generatePaymentId() const;
@ -139,9 +146,9 @@ signals:
private:
Wallet(QObject * parent = nullptr);
Wallet(Bitmonero::Wallet *w, QObject * parent = 0);
~Wallet();
private:
friend class WalletManager;
friend class WalletListenerImpl;
@ -149,6 +156,8 @@ private:
Bitmonero::Wallet * m_walletImpl;
// history lifetime managed by wallet;
TransactionHistory * m_history;
// Used for UI history view
TransactionHistoryModel * m_historyModel;
QString m_paymentId;
mutable QTime m_daemonBlockChainHeightTime;
mutable quint64 m_daemonBlockChainHeight;
@ -156,4 +165,6 @@ private:
};
#endif // WALLET_H

View File

@ -0,0 +1,102 @@
#include "TransactionHistoryModel.h"
#include "TransactionHistory.h"
#include "TransactionInfo.h"
TransactionHistoryModel::TransactionHistoryModel(QObject *parent)
: QAbstractListModel(parent), m_transactionHistory(nullptr)
{
}
void TransactionHistoryModel::setTransactionHistory(TransactionHistory *th)
{
beginResetModel();
m_transactionHistory = th;
endResetModel();
emit transactionHistoryChanged();
}
TransactionHistory *TransactionHistoryModel::transactionHistory() const
{
return m_transactionHistory;
}
QVariant TransactionHistoryModel::data(const QModelIndex &index, int role) const
{
if (!m_transactionHistory) {
return QVariant();
}
if (index.row() < 0 || (unsigned)index.row() >= m_transactionHistory->count()) {
return QVariant();
}
TransactionInfo * tInfo = m_transactionHistory->transaction(index.row());
Q_ASSERT(tInfo);
if (!tInfo) {
qCritical("%s: internal error: no transaction info for index %d", __FUNCTION__, index.row());
return QVariant();
}
QVariant result;
switch (role) {
case TransactionRole:
result = QVariant::fromValue(tInfo);
break;
case TransactionDirectionRole:
result = QVariant::fromValue(tInfo->direction());
break;
case TransactionPendingRole:
result = tInfo->isPending();
break;
case TransactionFailedRole:
result = tInfo->isFailed();
break;
case TransactionAmountRole:
result = tInfo->amount();
break;
case TransactionFeeRole:
result = tInfo->fee();
break;
case TransactionBlockHeightRole:
result = tInfo->blockHeight();
break;
case TransactionHashRole:
result = tInfo->hash();
break;
case TransactionTimeStampRole:
result = tInfo->timestamp();
break;
case TransactionPaymentIdRole:
result = tInfo->paymentId();
break;
}
return result;
}
int TransactionHistoryModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return m_transactionHistory ? m_transactionHistory->count() : 0;
}
QHash<int, QByteArray> TransactionHistoryModel::roleNames() const
{
QHash<int, QByteArray> roleNames = QAbstractListModel::roleNames();
roleNames.insert(TransactionRole, "transaction");
roleNames.insert(TransactionDirectionRole, "direction");
roleNames.insert(TransactionPendingRole, "isPending");
roleNames.insert(TransactionFailedRole, "isFailed");
roleNames.insert(TransactionAmountRole, "amount");
roleNames.insert(TransactionFeeRole, "fee");
roleNames.insert(TransactionBlockHeightRole, "blockHeight");
roleNames.insert(TransactionHashRole, "hash");
roleNames.insert(TransactionTimeStampRole, "timeStamp");
roleNames.insert(TransactionPaymentIdRole, "paymentId");
return roleNames;
}

View File

@ -0,0 +1,48 @@
#ifndef TRANSACTIONHISTORYMODEL_H
#define TRANSACTIONHISTORYMODEL_H
#include <QAbstractListModel>
class TransactionHistory;
class TransactionInfo;
/**
* @brief The TransactionHistoryModel class - read-only list model for Transaction History
*/
class TransactionHistoryModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(TransactionHistory * transactionHistory READ transactionHistory WRITE setTransactionHistory NOTIFY transactionHistoryChanged)
public:
enum TransactionInfoRole {
TransactionRole = Qt::UserRole + 1, // for the TransactionInfo object;
TransactionDirectionRole,
TransactionPendingRole,
TransactionFailedRole,
TransactionAmountRole,
TransactionFeeRole,
TransactionBlockHeightRole,
TransactionHashRole,
TransactionTimeStampRole,
TransactionPaymentIdRole
};
TransactionHistoryModel(QObject * parent = 0);
void setTransactionHistory(TransactionHistory * th);
TransactionHistory * transactionHistory() const;
/// QAbstractListModel
virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
virtual int rowCount(const QModelIndex & parent = QModelIndex()) const override;
virtual QHash<int, QByteArray> roleNames() const override;
signals:
void transactionHistoryChanged();
private:
TransactionHistory * m_transactionHistory;
};
#endif // TRANSACTIONHISTORYMODEL_H

View File

@ -1,5 +1,5 @@
import QtQuick 2.0
import moneroComponents 1.0
import moneroComponents.Clipboard 1.0
Column {

View File

@ -27,9 +27,8 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import QtQuick 2.2
import moneroComponents 1.0
import QtQuick.Dialogs 1.2
import Bitmonero.Wallet 1.0
import moneroComponents.Wallet 1.0
import 'utils.js' as Utils
Item {