diff --git a/KelvinDashboardGUI/DapChainWalletsModel.cpp b/KelvinDashboardGUI/DapChainWalletsModel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..76187491b082c091bac272b2ba35b65dcb443f7b --- /dev/null +++ b/KelvinDashboardGUI/DapChainWalletsModel.cpp @@ -0,0 +1,92 @@ +#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(); +} diff --git a/KelvinDashboardGUI/DapChainWalletsModel.h b/KelvinDashboardGUI/DapChainWalletsModel.h new file mode 100644 index 0000000000000000000000000000000000000000..4b318c7ede9210a36b5ceb1de6fd1b4dd8e855b8 --- /dev/null +++ b/KelvinDashboardGUI/DapChainWalletsModel.h @@ -0,0 +1,51 @@ +#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 diff --git a/KelvinDashboardGUI/DapCommandController.cpp b/KelvinDashboardGUI/DapCommandController.cpp index ceab1158e4b30f74bc0b0861238a22ac2b9af776..3c10bd0d066b49c2166ea8a44ccd7c60c70494cc 100644 --- a/KelvinDashboardGUI/DapCommandController.cpp +++ b/KelvinDashboardGUI/DapCommandController.cpp @@ -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())); +} diff --git a/KelvinDashboardGUI/DapCommandController.h b/KelvinDashboardGUI/DapCommandController.h index 568a7b6d5764e42e1eaf71a7b23fafc6f3288455..eb9283aa08468df6114d84ecaf8a59808e6377e2 100644 --- a/KelvinDashboardGUI/DapCommandController.h +++ b/KelvinDashboardGUI/DapCommandController.h @@ -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 diff --git a/KelvinDashboardGUI/DapServiceController.cpp b/KelvinDashboardGUI/DapServiceController.cpp index 5a07927aa56a40309a57346710f9cc18c93cac70..4149cc8993c23f825a2229ae7f5cf8b5ed261c91 100644 --- a/KelvinDashboardGUI/DapServiceController.cpp +++ b/KelvinDashboardGUI/DapServiceController.cpp @@ -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() diff --git a/KelvinDashboardGUI/DapServiceController.h b/KelvinDashboardGUI/DapServiceController.h index e13547f91a3502a025aadfc90f1867351cc07f7e..08fdc132aa99ac52ae3054f64f6e56d5517d2690 100644 --- a/KelvinDashboardGUI/DapServiceController.h +++ b/KelvinDashboardGUI/DapServiceController.h @@ -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 diff --git a/KelvinDashboardGUI/DapUiQmlScreenDashboard.qml b/KelvinDashboardGUI/DapUiQmlScreenDashboard.qml index ecee0b113a12a77d776f558c26f83d3bf0f0b6c1..881e48384fda01a110a05fb70c259aa4ceb2a638 100755 --- a/KelvinDashboardGUI/DapUiQmlScreenDashboard.qml +++ b/KelvinDashboardGUI/DapUiQmlScreenDashboard.qml @@ -162,6 +162,7 @@ Page { anchors.bottom: parent.bottom anchors.right: parent.right border.color: "whitesmoke" + Loader { id: stackViewScreenDashboard anchors.fill: parent diff --git a/KelvinDashboardGUI/DapUiQmlScreenDialog.qml b/KelvinDashboardGUI/DapUiQmlScreenDialog.qml index b463f1a93ea903d32fd8a23c017475e0147d1d16..15b1490d1116cac6050aee79bb10e8df4c541bfa 100644 --- a/KelvinDashboardGUI/DapUiQmlScreenDialog.qml +++ b/KelvinDashboardGUI/DapUiQmlScreenDialog.qml @@ -1,4 +1,4 @@ -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 { diff --git a/KelvinDashboardGUI/DapUiQmlWidgetChainWalletForm.ui.qml b/KelvinDashboardGUI/DapUiQmlWidgetChainWalletForm.ui.qml index 386d3a68b6e8bd6b9aa0246bc889bbe8c4e88fcc..0532651266b50f9ef6d198dbc780f73fd5908421 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetChainWalletForm.ui.qml +++ b/KelvinDashboardGUI/DapUiQmlWidgetChainWalletForm.ui.qml @@ -1,4 +1,5 @@ import QtQuick 2.11 +import QtGraphicalEffects 1.0 import QtQuick.Controls 2.2 Page { diff --git a/KelvinDashboardGUI/KelvinDashboardGUI.pro b/KelvinDashboardGUI/KelvinDashboardGUI.pro index 3eea6c63c7ad886ddefd733ddd7b3bebc816cc88..0b144a22127613eb176012c74ebc499ea9668480 100755 --- a/KelvinDashboardGUI/KelvinDashboardGUI.pro +++ b/KelvinDashboardGUI/KelvinDashboardGUI.pro @@ -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) diff --git a/KelvinDashboardGUI/main.cpp b/KelvinDashboardGUI/main.cpp index f2d8ca3f4a36747138b639dd9ca96a6904718d81..8db0315d38f1d6ff7c47d5e32888184da257a122 100755 --- a/KelvinDashboardGUI/main.cpp +++ b/KelvinDashboardGUI/main.cpp @@ -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"); diff --git a/KelvinDashboardGUI/main.qml b/KelvinDashboardGUI/main.qml index ae64980d6fc3b1ef5cf2362b3395a6ea98345d88..46dc72f93fdea8c6f85a082a9a4d365e55cb302c 100755 --- a/KelvinDashboardGUI/main.qml +++ b/KelvinDashboardGUI/main.qml @@ -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" diff --git a/KelvinDashboardService/DapChainDashboardService.cpp b/KelvinDashboardService/DapChainDashboardService.cpp index fa6c7d28c7e982ccd04f05517edc41c57190e49b..10eefd8f7d6bdeb33c93c40bb577131dbcf71ba9 100755 --- a/KelvinDashboardService/DapChainDashboardService.cpp +++ b/KelvinDashboardService/DapChainDashboardService.cpp @@ -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. diff --git a/KelvinDashboardService/DapChainDashboardService.h b/KelvinDashboardService/DapChainDashboardService.h index 5527ef925f1b166f7fd6bbb37188e4ff6ff6b7c0..f6a609d6285f6104c8467f6fef959ec41e2eb53e 100755 --- a/KelvinDashboardService/DapChainDashboardService.h +++ b/KelvinDashboardService/DapChainDashboardService.h @@ -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(); }; diff --git a/libKelvinDashboardCommon/DapChainWallet.cpp b/libKelvinDashboardCommon/DapChainWallet.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7a311014f60135f946427f27528a96e35801a8c6 --- /dev/null +++ b/libKelvinDashboardCommon/DapChainWallet.cpp @@ -0,0 +1,43 @@ +#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); +} diff --git a/libKelvinDashboardCommon/DapChainWallet.h b/libKelvinDashboardCommon/DapChainWallet.h new file mode 100644 index 0000000000000000000000000000000000000000..11f0d0cb2800dc2266d92723104437cd166a4eab --- /dev/null +++ b/libKelvinDashboardCommon/DapChainWallet.h @@ -0,0 +1,38 @@ +#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 diff --git a/libKelvinDashboardCommon/libKelvinDashboardCommon.pri b/libKelvinDashboardCommon/libKelvinDashboardCommon.pri index ee6bc4c894696ea960690aa0efeb2f04dd0ff66c..0db2e7e162777bc41f088930dcea8f687b78fa77 100755 --- a/libKelvinDashboardCommon/libKelvinDashboardCommon.pri +++ b/libKelvinDashboardCommon/libKelvinDashboardCommon.pri @@ -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