diff --git a/KelvinDashboardGUI/DapChainWalletsModel.cpp b/KelvinDashboardGUI/DapChainWalletsModel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0c5a322212f8127df1be6e315ea0c95d70e26a88 --- /dev/null +++ b/KelvinDashboardGUI/DapChainWalletsModel.cpp @@ -0,0 +1,98 @@ +#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(); +} + +void DapChainWalletsModel::clear() +{ + if(m_dapChainWallets.count() > 0) + m_dapChainWallets.clear(); +} + +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..2013196b8258b64109c6efe9a9e65eda6fb05169 --- /dev/null +++ b/KelvinDashboardGUI/DapChainWalletsModel.h @@ -0,0 +1,52 @@ +#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); + Q_INVOKABLE void clear(); + +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..5e63b1e13bc3c00965cc2b9d3142646137bac4c2 100644 --- a/KelvinDashboardGUI/DapCommandController.cpp +++ b/KelvinDashboardGUI/DapCommandController.cpp @@ -52,6 +52,33 @@ 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()); + auto name = reply->response().result().toVariant().toStringList().at(0); + auto address = reply->response().result().toVariant().toStringList().at(1); + emit sigWalletAdded(name, address); +} + +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 +102,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..6b4abdfbc38abd5725120abf306be3274c64d64a 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& asWalletName, 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 e43d06d15b4c689645ae7ee7bf99723622efc99b..8543ef039b3ed34f5992bb6b921999ef803fe351 100644 --- a/KelvinDashboardGUI/DapServiceController.cpp +++ b/KelvinDashboardGUI/DapServiceController.cpp @@ -1,6 +1,7 @@ #include "DapServiceController.h" #include "DapUiQmlWidgetModel.h" #include "DapLogMessage.h" +#include "DapChainWallet.h" DapServiceController::DapServiceController(QObject *apParent) : QObject(apParent) @@ -38,6 +39,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, QString)), SLOT(processAddWallet(QString, QString))); + + connect(m_pDapCommandController, SIGNAL(sigWalletsReceived(QMap<QString,QVariant>)), SLOT(processGetWallets(QMap<QString,QVariant>))); } QString DapServiceController::getBrand() const @@ -61,6 +66,12 @@ void DapServiceController::getNodeLogs(int aiTimeStamp, int aiRowCount) const m_pDapCommandController->getNodeLogs(aiTimeStamp, aiRowCount); } +void DapServiceController::getWallets() const +{ + qInfo() << QString("getNodeLogs()"); + m_pDapCommandController->getWallets(); +} + /// Handling service response for receiving node logs. /// @param aNodeLogs List of node logs. void DapServiceController::processGetNodeLogs(const QStringList &aNodeLogs) @@ -90,6 +101,29 @@ 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& asWalletName, const QString& asWalletAddress) +{ + qInfo() << QString("processAddWallet(%1, %2)").arg(asWalletName).arg(asWalletAddress);; + DapChainWallet wallet("", asWalletName, asWalletAddress); + DapChainWalletsModel::getInstance().append(wallet); +} + +void DapServiceController::processGetWallets(const QMap<QString, QVariant> &aWallets) +{ + qInfo() << QString("processGetWallets()") << aWallets.size(); + for(QString w : aWallets.keys()) + { + DapChainWallet wallet("", w, aWallets.value(w).toString()); + DapChainWalletsModel::getInstance().append(wallet); + } +} + /// 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 cc18d73129fa5d01e71ab90db37b05c47438eec6..fe9a03f65589160e3f9f5b14f9859262728f81ae 100644 --- a/KelvinDashboardGUI/DapServiceController.h +++ b/KelvinDashboardGUI/DapServiceController.h @@ -6,10 +6,13 @@ #include <QJSEngine> #include <QApplication> #include <QTimer> +#include <QMap> +#include <QPair> #include "DapCommandController.h" #include "DapServiceClient.h" #include "DapLogModel.h" +#include "DapChainWalletsModel.h" class DapServiceController : public QObject { @@ -57,10 +60,14 @@ 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& asWalletName); + signals: /// The signal is emitted when the Brand company property changes. void brandChanged(const QString &brand); @@ -76,6 +83,10 @@ private slots: /// @param aNodeLogs List of node logs. void processGetNodeLogs(const QStringList& aNodeLogs); + void processAddWallet(const QString& asWalletName, 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 e6909d573c90276af8780a51c2524a5470ed419f..881e48384fda01a110a05fb70c259aa4ceb2a638 100755 --- a/KelvinDashboardGUI/DapUiQmlScreenDashboard.qml +++ b/KelvinDashboardGUI/DapUiQmlScreenDashboard.qml @@ -127,9 +127,9 @@ Page { Image { id: imageMenu - source: "qrc:/Resources/Icons/home.png" - height: 36 - width: 36 + source: "qrc:/Resources/Icons/exit.png" + height: 32 + width: 32 anchors.horizontalCenter: parent.horizontalCenter } Text @@ -139,12 +139,19 @@ Page { anchors.horizontalCenter: parent.horizontalCenter } } + MouseArea { anchors.fill: parent - onClicked: + onHoveredChanged: { rectangleBorder.color = "#EE5321" } + + onClicked: + { + + Qt.quit() + } } } } @@ -155,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/DapUiQmlScreenDialogAddWallet.qml b/KelvinDashboardGUI/DapUiQmlScreenDialogAddWallet.qml new file mode 100644 index 0000000000000000000000000000000000000000..54517ffacb6d17132da87496daab3046486e2af4 --- /dev/null +++ b/KelvinDashboardGUI/DapUiQmlScreenDialogAddWallet.qml @@ -0,0 +1,118 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.4 +import KelvinDashboard 1.0 + +Dialog { + id: dialogAddWallet + focus: true + modal: true + title: qsTr("Add wallet...") + + width: parent.width/1.5 + height: 150 + + x: parent.width / 2 - width / 2 + y: parent.height / 2 - height / 2 + + function show() { + dialogAddWallet.open(); + } + contentItem: + + Rectangle + { + anchors.fill: parent + + TextField + { + background: Rectangle { + radius: 2 + border.color: "gray" + border.width: 1 + } + + id: textFieldNameWallet + selectByMouse: true + height: 35 + anchors.bottom: buttonOk.top + anchors.bottomMargin: 20 + anchors.right: parent.right + anchors.rightMargin: 10 + anchors.left: parent.left + anchors.leftMargin: 10 + font.pixelSize: 20 + clip: true + + + } + + Button + { + id: buttonCancel + text: qsTr("Cancel") + anchors.right: buttonOk.left + anchors.rightMargin: 10 + anchors.bottom: parent.bottom + anchors.bottomMargin: 10 + + contentItem: Text { + text: buttonCancel.text + font: buttonCancel.font + opacity: enabled ? 1.0 : 0.3 + color: buttonCancel.down ? "#353841" : "white" + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + } + + background: Rectangle { + implicitWidth: 100 + implicitHeight: 30 + opacity: enabled ? 1 : 0.3 + color: buttonCancel.down ? "white" : "#353841" + radius: 4 + } + + onClicked: + { + textFieldNameWallet.clear() + close() + } + } + + Button + { + id: buttonOk + text: "OK" + anchors.right: parent.right + anchors.rightMargin: 10 + anchors.bottom: parent.bottom + anchors.bottomMargin: 10 + contentItem: Text { + text: buttonOk.text + font: buttonOk.font + opacity: enabled ? 1.0 : 0.3 + color: buttonOk.down ? "#353841" : "white" + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + } + + background: Rectangle { + implicitWidth: 100 + implicitHeight: 30 + opacity: enabled ? 1 : 0.3 + color: buttonOk.down ? "white" : "#353841" + radius: 4 + } + + onClicked: + { + dapServiceController.addWallet(textFieldNameWallet.text) + textFieldNameWallet.clear() + close() + } + } + } + +} diff --git a/KelvinDashboardGUI/DapUiQmlWidgetChainWallet.qml b/KelvinDashboardGUI/DapUiQmlWidgetChainWallet.qml new file mode 100644 index 0000000000000000000000000000000000000000..9767571a913c9d4378cbbfa7d617a6a08e00903d --- /dev/null +++ b/KelvinDashboardGUI/DapUiQmlWidgetChainWallet.qml @@ -0,0 +1,13 @@ +import QtQuick 2.4 + +DapUiQmlWidgetChainWalletForm { + id: dapQmlWidgetChainWallet + + + + save.onClicked: { + dialogAddWallet.show() +} + + +} diff --git a/KelvinDashboardGUI/DapUiQmlWidgetChainWallet.ui.qml b/KelvinDashboardGUI/DapUiQmlWidgetChainWallet.ui.qml deleted file mode 100644 index 465499b497235b5b058c80b1d46e28a589f29662..0000000000000000000000000000000000000000 --- a/KelvinDashboardGUI/DapUiQmlWidgetChainWallet.ui.qml +++ /dev/null @@ -1,14 +0,0 @@ -import QtQuick 2.9 -import QtQuick.Controls 2.2 - -Page { - id: dapUiQmlWidgetChainWallet - - title: qsTr("Wallet") - - Text { - id: name - anchors.centerIn: parent - text: qsTr("Wallet") - } -} diff --git a/KelvinDashboardGUI/DapUiQmlWidgetChainWalletForm.ui.qml b/KelvinDashboardGUI/DapUiQmlWidgetChainWalletForm.ui.qml new file mode 100644 index 0000000000000000000000000000000000000000..1bdc39b1d976947f4022633c9dbccc06acef6c92 --- /dev/null +++ b/KelvinDashboardGUI/DapUiQmlWidgetChainWalletForm.ui.qml @@ -0,0 +1,105 @@ +import QtQuick 2.11 +import QtGraphicalEffects 1.0 +import QtQuick.Controls 2.2 + +Page { + id: dapUiQmlWidgetChainWallet + + title: qsTr("Wallet") + + property alias listViewWallet: listViewWallet + property alias save: save + property alias dialogAddWallet: dialogAddWallet + + ListView { + id: listViewWallet + anchors.fill: parent + anchors.margins: 10 + spacing: 10 + model: dapChainWalletsModel + + delegate: Item { + width: parent.width + height: 150 + + Rectangle { + id: rectangleWallet + anchors.fill: parent + color: "lightgray" + opacity: 0.5 + radius: 5 + border.color: "gray" + clip: true + + Rectangle + { + id: iconWallet + height: 140 + width: 140 + border.color: "gray" + anchors.left: parent.left + anchors.leftMargin: 5 + anchors.verticalCenter: parent.verticalCenter + radius: 3.5 + + Image + { + anchors.fill: parent + source: "qrc:/Resources/Icons/add.png" + } + } + + Column + { + anchors.verticalCenter: parent.verticalCenter + anchors.left: iconWallet.right + anchors.leftMargin: 10 + anchors.right: parent.right + anchors.rightMargin: 10 + spacing: 5 + + Text { + id: nameWallet + text: name + bottomPadding: 15 + font.bold: true + font.pixelSize: 20 + } + + Text { + id: lableAddress + text: "Address:" + font.pixelSize: 18 + color: "gray" + } + + TextEdit { + id: addressWallet + text: address + width: parent.width + font.pixelSize: 16 + wrapMode: Text.Wrap + selectByMouse: true + // clip: true + // elide: Text.ElideRight + } + } + } + } + + + } + DapUiQmlScreenDialogAddWallet { + id: dialogAddWallet + } + + RoundButton { + id: save + text: qsTr("+") + highlighted: true + anchors.margins: 10 + anchors.right: parent.right + anchors.bottom: parent.bottom + } +} + diff --git a/KelvinDashboardGUI/DapUiQmlWidgetModel.cpp b/KelvinDashboardGUI/DapUiQmlWidgetModel.cpp index 41c2b477eeb7d90cffe14421eef5328a1ebadfce..11ff0ae6fbe7f8152e01cc742eb28b9a97ac2a3c 100755 --- a/KelvinDashboardGUI/DapUiQmlWidgetModel.cpp +++ b/KelvinDashboardGUI/DapUiQmlWidgetModel.cpp @@ -7,7 +7,7 @@ DapUiQmlWidgetModel::DapUiQmlWidgetModel(QObject *parent) : QAbstractListModel(p m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Services client", "DapUiQmlWidgetChainServicesClient.ui.qml", "qrc:/Resources/Icons/add.png")); m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Services share control", "DapUiQmlWidgetChainServicesShareControl.ui.qml", "qrc:/Resources/Icons/add.png")); m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Settings", "DapUiQmlWidgetChainSettings.ui.qml", "qrc:/Resources/Icons/add.png")); - m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Wallet", "DapUiQmlWidgetChainWallet.ui.qml", "qrc:/Resources/Icons/add.png")); + m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Wallet", "DapUiQmlWidgetChainWallet.qml", "qrc:/Resources/Icons/add.png")); m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Logs", "DapUiQmlWidgetChainNodeLogs.ui.qml", "qrc:/Resources/Icons/add.png")); } 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/Resources/Icons/exit.png b/KelvinDashboardGUI/Resources/Icons/exit.png new file mode 100644 index 0000000000000000000000000000000000000000..04e3ded47f074d892077759f5697546cef36ae98 Binary files /dev/null and b/KelvinDashboardGUI/Resources/Icons/exit.png differ diff --git a/KelvinDashboardGUI/main.cpp b/KelvinDashboardGUI/main.cpp index f2d8ca3f4a36747138b639dd9ca96a6904718d81..dce86218eaacb0a55bcf82f3a92e7a1a7b5426de 100755 --- a/KelvinDashboardGUI/main.cpp +++ b/KelvinDashboardGUI/main.cpp @@ -18,6 +18,9 @@ #include "DapLogger.h" #include "DapLogMessage.h" #include "DapLogModel.h" +#include "DapChainWalletsModel.h" + +#include <QRegExp> int main(int argc, char *argv[]) { @@ -36,7 +39,7 @@ int main(int argc, char *argv[]) dapLogger.setLogFile(QString("/opt/%1/log/%2Gui.log").arg(QString(DAP_BRAND)).arg(DAP_BRAND)); #endif //#endif - + /// Local client. DapServiceClient dapServiceClient; // Creating a service controller @@ -44,6 +47,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 +59,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 f5786572477962fff2e9ce3b3c17727fb8eba97d..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() @@ -106,7 +106,7 @@ ApplicationWindow { scale: 0.7 visible: false anchors.verticalCenter: parent.verticalCenter - anchors.right: imageDollars.left + anchors.right: parent.left } Image { @@ -115,27 +115,7 @@ ApplicationWindow { scale: 0.7 visible: true anchors.verticalCenter: parent.verticalCenter - anchors.right: imageDollars.left - } - - Image { - id: imageDollars - source: "qrc:/Resources/Icons/dollar.png" - scale: 0.7 - visible: true - anchors.verticalCenter: parent.verticalCenter - anchors.right: labelBalance.right - anchors.leftMargin: 5 - anchors.rightMargin: 5 - } - - Text { - id: labelBalance - text: "0" - font.pointSize: 16 - anchors.verticalCenter: parent.verticalCenter anchors.right: parent.right - anchors.rightMargin: 10 } } Rectangle @@ -192,7 +172,7 @@ ApplicationWindow { focus: true } } - + StackView { id: stackView initialItem: "DapUiQmlScreenDashboard.qml" diff --git a/KelvinDashboardGUI/qml.qrc b/KelvinDashboardGUI/qml.qrc index abfd1123f0a4d78c65066cbfa59c68cddd01a158..4d465d5ce350680b684637f53e46c55395c2875c 100755 --- a/KelvinDashboardGUI/qml.qrc +++ b/KelvinDashboardGUI/qml.qrc @@ -9,7 +9,6 @@ <file>DapUiQmlWidgetChainServicesClient.ui.qml</file> <file>DapUiQmlWidgetChainServicesShareControl.ui.qml</file> <file>DapUiQmlWidgetChainSettings.ui.qml</file> - <file>DapUiQmlWidgetChainWallet.ui.qml</file> <file>DapUiQmlScreenDialog.qml</file> <file>Resources/Icons/icon.png</file> <file>DapUiQmlScreenAbout.ui.qml</file> @@ -26,5 +25,9 @@ <file>Resources/Icons/home.png</file> <file>Resources/Icons/settings.png</file> <file>Resources/Icons/dialog.png</file> + <file>Resources/Icons/exit.png</file> + <file>DapUiQmlScreenDialogAddWallet.qml</file> + <file>DapUiQmlWidgetChainWallet.qml</file> + <file>DapUiQmlWidgetChainWalletForm.ui.qml</file> </qresource> </RCC> diff --git a/KelvinDashboardService/DapChainDashboardService.cpp b/KelvinDashboardService/DapChainDashboardService.cpp index fa6c7d28c7e982ccd04f05517edc41c57190e49b..b5530fcc0d07887f65829a66dde5fd0021d1dfb8 100755 --- a/KelvinDashboardService/DapChainDashboardService.cpp +++ b/KelvinDashboardService/DapChainDashboardService.cpp @@ -5,6 +5,8 @@ DapChainDashboardService::DapChainDashboardService() : DapRpcService(nullptr) // Log reader m_pDapLogReader = new DapLogReader(this); + m_pDapChainWalletHandler = new DapChainWalletHandler(this); + connect(this, &DapChainDashboardService::onNewClientConnected, [=] { qDebug() << "New client"; }); @@ -39,6 +41,19 @@ QStringList DapChainDashboardService::getNodeLogs(int aiTimeStamp, int aiRowCoun return m_pDapLogReader->request(aiTimeStamp, aiRowCount); } +QStringList DapChainDashboardService::addWallet(const QString &asWalletName) +{ + qInfo() << QString("addWallet(%1)").arg(asWalletName); + return m_pDapChainWalletHandler->createWallet(asWalletName); +} + +QMap<QString, QVariant> DapChainDashboardService::getWallets() +{ + qInfo() << QString("getWallets()"); + + return m_pDapChainWalletHandler->getWallets(); +} + /// 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..6c0f7399e78a189b06835c81ac697484d77117de 100755 --- a/KelvinDashboardService/DapChainDashboardService.h +++ b/KelvinDashboardService/DapChainDashboardService.h @@ -24,6 +24,7 @@ #include "DapRpcService.h" #include "DapLogReader.h" +#include "DapChainWalletHandler.h" #include <QLocalServer> typedef class DapRpcLocalServer DapUiService; @@ -39,6 +40,8 @@ class DapChainDashboardService : public DapRpcService DapUiSocketServer * m_pSocketService {nullptr}; /// Log reader. DapLogReader * m_pDapLogReader {nullptr}; + + DapChainWalletHandler * m_pDapChainWalletHandler {nullptr}; public: /// Standard Ñonstructor. explicit DapChainDashboardService(); @@ -64,6 +67,10 @@ public slots: /// @param aiRowCount Number of lines displayed. /// @return Logs node. QStringList getNodeLogs(int aiTimeStamp, int aiRowCount); + + QStringList addWallet(const QString &asWalletName); + + QMap<QString, QVariant> getWallets(); }; diff --git a/KelvinDashboardService/DapChainWalletHandler.cpp b/KelvinDashboardService/DapChainWalletHandler.cpp new file mode 100644 index 0000000000000000000000000000000000000000..50f3669bd3805475b8037ff5fb9761dfeb7a12e7 --- /dev/null +++ b/KelvinDashboardService/DapChainWalletHandler.cpp @@ -0,0 +1,55 @@ +#include "DapChainWalletHandler.h" + +DapChainWalletHandler::DapChainWalletHandler(QObject *parent) : QObject(parent) +{ + +} + +QString DapChainWalletHandler::parse(const QByteArray &aWalletAddress) +{ + qDebug() << aWalletAddress; + QStringList result = QString::fromLatin1(aWalletAddress).split(" "); + return result.at(result.size()-1).trimmed(); +} + +QStringList DapChainWalletHandler::createWallet(const QString &asNameWallet) +{ + QByteArray result; + QProcess process; + process.start(QString("%1 wallet new -w %2").arg("/home/andrey/Demlabs/build-kelvin-node/kelvin-node-cli").arg(asNameWallet)); + process.waitForFinished(-1); + result = process.readAll(); + QStringList list; + list.append(asNameWallet); + list.append(parse(result)); + return result.isEmpty() ? QStringList() : list; +} + +QMap<QString, QVariant> DapChainWalletHandler::getWallets() +{ + QMap<QString, QVariant> map; + QProcess process; + process.start(QString("%1 wallet list").arg("/home/andrey/Demlabs/build-kelvin-node/kelvin-node-cli")); + process.waitForFinished(-1); + QString str = QString::fromLatin1(process.readAll()).remove(" "); + QRegExp rx( ":\\b([a-zA-Z0-9]+)\\n" ); + int pos = 0; + int x {0}; + QString tempName; + while ((pos = rx.indexIn(str, pos)) != -1) + { + if(x == 0) + { + tempName = rx.cap(1); + ++x; + } + else + { + map.insert(tempName, rx.cap(1)); + x = 0; + } + pos += rx.matchedLength(); + } + + return map; +} diff --git a/KelvinDashboardService/DapChainWalletHandler.h b/KelvinDashboardService/DapChainWalletHandler.h new file mode 100644 index 0000000000000000000000000000000000000000..652890f26a04bc9e22fa42636aeaaa97c477b2bc --- /dev/null +++ b/KelvinDashboardService/DapChainWalletHandler.h @@ -0,0 +1,26 @@ +#ifndef DAPCHAINWALLETHANDLER_H +#define DAPCHAINWALLETHANDLER_H + +#include <QObject> +#include <QProcess> +#include <QRegExp> +#include <QDebug> + +class DapChainWalletHandler : public QObject +{ + Q_OBJECT + +protected: + virtual QString parse(const QByteArray& aWalletAddress); + +public: + explicit DapChainWalletHandler(QObject *parent = nullptr); + +signals: + +public slots: + QStringList createWallet(const QString& asNameWallet); + QMap<QString, QVariant> getWallets(); +}; + +#endif // DAPCHAINWALLETHANDLER_H diff --git a/KelvinDashboardService/KelvinDashboardService.pro b/KelvinDashboardService/KelvinDashboardService.pro index 6f8faa37276801799f612ea58d8d4bd3f0e434d5..3ef532f066313a26c413e0b90081c48f9fb9abb4 100755 --- a/KelvinDashboardService/KelvinDashboardService.pro +++ b/KelvinDashboardService/KelvinDashboardService.pro @@ -41,13 +41,15 @@ SOURCES += \ DapChainDashboardService.cpp \ DapChainNode.cpp \ DapChainNodeCache.cpp \ - DapLogReader.cpp + DapLogReader.cpp \ + DapChainWalletHandler.cpp HEADERS += \ DapChainDashboardService.h \ DapChainNode.h \ DapChainNodeCache.h \ - DapLogReader.h + DapLogReader.h \ + DapChainWalletHandler.h include (../libdap-qt/libdap-qt.pri) include (../libKelvinDashboardCommon/libKelvinDashboardCommon.pri) 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