Skip to content
Snippets Groups Projects
Commit 6214fba0 authored by littletux89's avatar littletux89
Browse files

[+] Added model and commands for adding a wallet and getting a list of existing wallets.

parent 6dd78495
No related branches found
No related tags found
No related merge requests found
Showing
with 345 additions and 11 deletions
#include "DapChainWalletsModel.h"
DapChainWalletsModel::DapChainWalletsModel(QObject *parent)
{
}
DapChainWalletsModel &DapChainWalletsModel::getInstance()
{
static DapChainWalletsModel instance;
return instance;
}
int DapChainWalletsModel::rowCount(const QModelIndex &) const
{
return m_dapChainWallets.count();
}
QVariant DapChainWalletsModel::data(const QModelIndex &index, int role) const
{
if (index.row() < rowCount())
switch (role) {
case IconWalletRole: return m_dapChainWallets.at(index.row())->getIconPath();
case NameWalletRole: return m_dapChainWallets.at(index.row())->getName();
case AddressWalletRole: return m_dapChainWallets.at(index.row())->getAddress();
default:
return QVariant();
}
return QVariant();
}
QHash<int, QByteArray> DapChainWalletsModel::roleNames() const
{
static const QHash<int, QByteArray> roles {
{ IconWalletRole, "iconPath" },
{ NameWalletRole, "name" },
{ AddressWalletRole, "address" }
};
return roles;
}
QVariantMap DapChainWalletsModel::get(int row) const
{
const DapChainWallet *wallet = m_dapChainWallets.value(row);
return { {"iconPath", wallet->getIconPath()}, {"name", wallet->getName()}, {"address", wallet->getAddress()} };
}
void DapChainWalletsModel::append(const DapChainWallet &arWallet)
{
this->append(arWallet.getIconPath(), arWallet.getName(), arWallet.getAddress());
}
void DapChainWalletsModel::append(const QString& asIconPath, const QString &asName, const QString &asAddress)
{
int row = 0;
while (row < m_dapChainWallets.count())
++row;
beginInsertRows(QModelIndex(), row, row);
m_dapChainWallets.insert(row, new DapChainWallet(asIconPath, asName, asAddress));
endInsertRows();
}
void DapChainWalletsModel::set(int row, const QString& asIconPath, const QString &asName, const QString &asAddresss)
{
if (row < 0 || row >= m_dapChainWallets.count())
return;
DapChainWallet *wallet = m_dapChainWallets.value(row);
wallet->setIconPath(asIconPath);
wallet->setName(asName);
wallet->setAddress(asAddresss);
dataChanged(index(row, 0), index(row, 0), { IconWalletRole, NameWalletRole, AddressWalletRole });
}
void DapChainWalletsModel::remove(int row)
{
if (row < 0 || row >= m_dapChainWallets.count())
return;
beginRemoveRows(QModelIndex(), row, row);
m_dapChainWallets.removeAt(row);
endRemoveRows();
}
QObject *DapChainWalletsModel::singletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return &getInstance();
}
#ifndef DAPCHAINWALLETSMODEL_H
#define DAPCHAINWALLETSMODEL_H
#include <QObject>
#include <QAbstractListModel>
#include <QList>
#include <QQmlEngine>
#include <QJSEngine>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QXmlStreamAttribute>
#include <DapChainWallet.h>
enum DapChainWalletRole {
IconWalletRole = Qt::DisplayRole,
NameWalletRole = Qt::UserRole,
AddressWalletRole
};
class DapChainWalletsModel : public QAbstractListModel
{
Q_OBJECT
QList<DapChainWallet*> m_dapChainWallets;
DapChainWalletsModel(QObject* parent = nullptr);
public:
/// Get an instance of a class.
/// @return Instance of a class.
Q_INVOKABLE static DapChainWalletsModel &getInstance();
int rowCount(const QModelIndex & = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QHash<int, QByteArray> roleNames() const;
Q_INVOKABLE QVariantMap get(int row) const;
Q_INVOKABLE void append(const DapChainWallet &arWallet);
Q_INVOKABLE void append(const QString& asIconPath, const QString &asName, const QString &asAddress);
Q_INVOKABLE void set(int row, const QString& asIconPath, const QString &asName, const QString &asAddresss);
Q_INVOKABLE void remove(int row);
public slots:
/// Method that implements the singleton pattern for the qml layer.
/// @param engine QML application.
/// @param scriptEngine The QJSEngine class provides an environment for evaluating JavaScript code.
static QObject *singletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine);
};
#endif // DAPCHAINWALLETSMODEL_H
......@@ -52,6 +52,31 @@ void DapCommandController::processGetNodeLogs()
emit sigNodeLogsReceived(reply->response().result().toVariant().toStringList());
}
///
void DapCommandController::processAddWallet()
{
qInfo() << "processAddWallet()";
DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender());
if (!reply) {
qWarning() << "Invalid response received";
return;
}
emit sigCommandResult(reply->response().result());
emit sigWalletAdded(reply->response().result().toVariant().toString());
}
void DapCommandController::processGetWallets()
{
qInfo() << "processGetWallets()";
DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender());
if (!reply) {
qWarning() << "Invalid response received";
return;
}
emit sigCommandResult(reply->response().result());
emit sigWalletsReceived(reply->response().result().toVariant().toMap());
}
/// Show or hide GUI client by clicking on the tray icon.
/// @param aIsActivated Accepts true - when requesting to
/// display a client, falso - when requesting to hide a client.
......@@ -75,3 +100,16 @@ void DapCommandController::getNodeLogs(int aiTimeStamp, int aiRowCount)
DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.getNodeLogs", aiTimeStamp, aiRowCount);
connect(reply, SIGNAL(finished()), this, SLOT(processGetNodeLogs()));
}
void DapCommandController::addWallet(const QString &asWalletName)
{
qInfo() << QString("addWallet(%1)").arg(asWalletName);
DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.addWallet", asWalletName);
connect(reply, SIGNAL(finished()), this, SLOT(processAddWallet()));
}
void DapCommandController::getWallets()
{
DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.getWallets");
connect(reply, SIGNAL(finished()), this, SLOT(processGetWallets()));
}
......@@ -25,6 +25,10 @@ signals:
/// The signal is emitted when node logs are received from the service.
/// @param aNodeLogs List of node logs.
void sigNodeLogsReceived(const QStringList& aNodeLogs);
void sigWalletAdded(const QString& asWalletAddress);
void sigWalletsReceived(const QMap<QString, QVariant>& aWallets);
/// The signal is emitted when the main application window is activated.
void onClientActivate(bool aIsActivated);
......@@ -44,6 +48,10 @@ private slots:
void processCommandResult();
/// Handling service response for receiving node logs.
void processGetNodeLogs();
void processAddWallet();
void processGetWallets();
public slots:
/// Show or hide GUI client by clicking on the tray icon.
......@@ -56,6 +64,10 @@ public slots:
/// @param aiTimeStamp Timestamp start reading logging.
/// @param aiRowCount Number of lines displayed.
void getNodeLogs(int aiTimeStamp, int aiRowCount);
void addWallet(const QString& asWalletName);
void getWallets();
};
#endif // COMMANDCONTROLLER_H
......@@ -38,6 +38,10 @@ void DapServiceController::init(DapServiceClient *apDapServiceClient)
connect(m_pDapCommandController, SIGNAL(onClientClose()), SLOT(closeClient()));
// Signal-slot connection for receiving node logs from the service
connect(m_pDapCommandController, SIGNAL(sigNodeLogsReceived(QStringList)), SLOT(processGetNodeLogs(QStringList)));
connect(m_pDapCommandController, SIGNAL(sigWalletAdded(QString)), SLOT(processAddWallet(QString)));
connect(m_pDapCommandController, SIGNAL(sigWalletsReceived(QMap<QString,QVariant>)), SLOT(processGetWallets(QMap<QString,QVariant>)));
}
QString DapServiceController::getBrand() const
......@@ -61,9 +65,10 @@ void DapServiceController::getNodeLogs(int aiTimeStamp, int aiRowCount) const
m_pDapCommandController->getNodeLogs(aiTimeStamp, aiRowCount);
}
void DapServiceController::addWallet(const QString &asName)
void DapServiceController::getWallets() const
{
qDebug() << "NAME WALLET " << asName;
qInfo() << QString("getNodeLogs()");
m_pDapCommandController->getWallets();
}
/// Handling service response for receiving node logs.
......@@ -95,6 +100,25 @@ void DapServiceController::processGetNodeLogs(const QStringList &aNodeLogs)
}
}
void DapServiceController::addWallet(const QString &asWalletName)
{
qInfo() << QString("addWallet(%1)").arg(asWalletName);
m_pDapCommandController->addWallet(asWalletName);
}
void DapServiceController::processAddWallet(const QString &asWalletAddress)
{
qInfo() << QString("processAddWallet(%1)").arg(asWalletAddress);
qDebug() << "Wallet address() " << asWalletAddress;
}
void DapServiceController::processGetWallets(const QMap<QString, QVariant> &aWallets)
{
qInfo() << QString("processGetWallets()") << aWallets.size();
for(QString wallet : aWallets.keys())
qDebug() << "W" << wallet << " " << aWallets.value(wallet).toString();
}
/// Get an instance of a class.
/// @return Instance of a class.
DapServiceController &DapServiceController::getInstance()
......
......@@ -6,6 +6,8 @@
#include <QJSEngine>
#include <QApplication>
#include <QTimer>
#include <QMap>
#include <QPair>
#include "DapCommandController.h"
#include "DapServiceClient.h"
......@@ -57,11 +59,13 @@ public:
/// @param aiTimeStamp Timestamp start reading logging.
/// @param aiRowCount Number of lines displayed.
void getNodeLogs(int aiTimeStamp, int aiRowCount) const;
void getWallets() const;
DapLogModel getLogModel() const;
void setLogModel(const DapLogModel &dapLogModel);
Q_INVOKABLE void addWallet(const QString& asName);
Q_INVOKABLE void addWallet(const QString& asWalletName);
signals:
/// The signal is emitted when the Brand company property changes.
......@@ -78,6 +82,10 @@ private slots:
/// @param aNodeLogs List of node logs.
void processGetNodeLogs(const QStringList& aNodeLogs);
void processAddWallet(const QString& asWalletAddress);
void processGetWallets(const QMap<QString, QVariant>& aWallets);
public slots:
/// Show or hide GUI client by clicking on the tray icon.
/// @param aIsActivated Accepts true - when requesting to
......
......@@ -162,6 +162,7 @@ Page {
anchors.bottom: parent.bottom
anchors.right: parent.right
border.color: "whitesmoke"
Loader {
id: stackViewScreenDashboard
anchors.fill: parent
......
import QtQuick 2.9
import QtQuick 2.11
import QtQuick.Controls 2.4
import KelvinDashboard 1.0
......@@ -16,7 +16,7 @@ Page {
}
Rectangle {
color: "white"
anchors.fill: parent
GridView {
......
import QtQuick 2.11
import QtGraphicalEffects 1.0
import QtQuick.Controls 2.2
Page {
......
......@@ -52,7 +52,8 @@ SOURCES += \
DapServiceController.cpp \
DapCommandController.cpp \
DapServiceClientNativeAbstract.cpp \
DapServiceClientNativeLinux.cpp
DapServiceClientNativeLinux.cpp \
DapChainWalletsModel.cpp
RESOURCES += qml.qrc
......@@ -82,7 +83,8 @@ HEADERS += \
DapServiceController.h \
DapCommandController.h \
DapServiceClientNativeAbstract.h \
DapServiceClientNativeLinux.h
DapServiceClientNativeLinux.h \
DapChainWalletsModel.h
include (../libdap-qt/libdap-qt.pri)
include (../libKelvinDashboardCommon/libKelvinDashboardCommon.pri)
......
......@@ -18,6 +18,7 @@
#include "DapLogger.h"
#include "DapLogMessage.h"
#include "DapLogModel.h"
#include "DapChainWalletsModel.h"
int main(int argc, char *argv[])
{
......@@ -44,6 +45,7 @@ int main(int argc, char *argv[])
controller.init(&dapServiceClient);
dapServiceClient.init();
controller.getNodeLogs(0, 100);
controller.getWallets();
qmlRegisterType<DapScreenDialog>("KelvinDashboard", 1, 0, "DapScreenDialog");
qmlRegisterType<DapScreenDialogChangeWidget>("KelvinDashboard", 1, 0, "DapScreenDialogChangeWidget");
......@@ -55,6 +57,7 @@ int main(int argc, char *argv[])
engine.rootContext()->setContextProperty("dapServiceController", &DapServiceController::getInstance());
engine.rootContext()->setContextProperty("dapUiQmlWidgetModel", &DapUiQmlWidgetModel::getInstance());
engine.rootContext()->setContextProperty("dapLogModel", &DapLogModel::getInstance());
engine.rootContext()->setContextProperty("dapChainWalletsModel", &DapChainWalletsModel::getInstance());
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
// DapSettings &settings = DapSettings::getInstance("Settings.json");
......
......@@ -12,7 +12,7 @@ ApplicationWindow {
visible: true
width: 640
height: 480
onClosing: {
console.log("Close")
window.hide()
......@@ -172,7 +172,7 @@ ApplicationWindow {
focus: true
}
}
StackView {
id: stackView
initialItem: "DapUiQmlScreenDashboard.qml"
......
......@@ -39,6 +39,21 @@ QStringList DapChainDashboardService::getNodeLogs(int aiTimeStamp, int aiRowCoun
return m_pDapLogReader->request(aiTimeStamp, aiRowCount);
}
QString DapChainDashboardService::addWallet(const QString &asWalletName)
{
qInfo() << QString("addWallet(%1)").arg(asWalletName);
return "NULL";
}
QMap<QString, QVariant> DapChainDashboardService::getWallets()
{
qInfo() << QString("getWallets()");
QMap<QString, QVariant> map;
map.insert("My", "454asf6das4f6fd68df6877dsf");
return map;
}
/// Activate the main client window by double-clicking the application icon in the system tray.
/// @param reason Type of action on the icon in the system tray.
......
......@@ -64,6 +64,10 @@ public slots:
/// @param aiRowCount Number of lines displayed.
/// @return Logs node.
QStringList getNodeLogs(int aiTimeStamp, int aiRowCount);
QString addWallet(const QString &asWalletName);
QMap<QString, QVariant> getWallets();
};
......
#include "DapChainWallet.h"
DapChainWallet::DapChainWallet(const QString &asIconPath, const QString &asName, const QString &asAddresss, QObject *parent)
: QObject(parent), m_sIconPath(asIconPath), m_sName(asName), m_sAddress(asAddresss)
{
}
QString DapChainWallet::getIconPath() const
{
return m_sIconPath;
}
void DapChainWallet::setIconPath(const QString &asIconPath)
{
m_sIconPath = asIconPath;
emit iconPathChanged(m_sIconPath);
}
QString DapChainWallet::getName() const
{
return m_sName;
}
void DapChainWallet::setName(const QString &asName)
{
m_sName = asName;
emit nameChanged(m_sName);
}
QString DapChainWallet::getAddress() const
{
return m_sAddress;
}
void DapChainWallet::setAddress(const QString &asAddress)
{
m_sAddress = asAddress;
emit addressChanged(m_sAddress);
}
#ifndef DAPCHAINWALLET_H
#define DAPCHAINWALLET_H
#include <QObject>
#include <QString>
class DapChainWallet : public QObject
{
Q_OBJECT
QString m_sIconPath;
QString m_sName;
QString m_sAddress;
public:
DapChainWallet(QObject *parent = nullptr) {}
DapChainWallet(const QString& asIconPath, const QString &asName, const QString &asAddresss, QObject * parent = nullptr);
Q_PROPERTY(QString iconPath MEMBER m_sIconPath READ getIconPath WRITE setIconPath NOTIFY iconPathChanged)
Q_PROPERTY(QString name MEMBER m_sName READ getName WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString address MEMBER m_sAddress READ getAddress WRITE setAddress NOTIFY addressChanged)
QString getName() const;
void setName(const QString &asName);
QString getAddress() const;
void setAddress(const QString &asAddress);
QString getIconPath() const;
void setIconPath(const QString &asIconPath);
signals:
void iconPathChanged(const QString& asIconPath);
void nameChanged(const QString& asName);
void addressChanged(const QString& asAddress);
};
#endif // DAPCHAINWALLET_H
......@@ -16,11 +16,13 @@ SOURCES +=\
$$PWD/DapSettings.cpp \
$$PWD/DapSettingsCipher.cpp \
$$PWD/DapLogMessage.cpp \
$$PWD/DapLogModel.cpp
$$PWD/DapLogModel.cpp \
$$PWD/DapChainWallet.cpp
HEADERS +=\
$$PWD/DapHalper.h \
$$PWD/DapSettings.h \
$$PWD/DapSettingsCipher.h \
$$PWD/DapLogMessage.h \
$$PWD/DapLogModel.h
$$PWD/DapLogModel.h \
$$PWD/DapChainWallet.h
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment