diff --git a/KelvinDashboardGUI/DapChainWalletsModel.cpp b/KelvinDashboardGUI/DapChainWalletsModel.cpp index 76187491b082c091bac272b2ba35b65dcb443f7b..0c5a322212f8127df1be6e315ea0c95d70e26a88 100644 --- a/KelvinDashboardGUI/DapChainWalletsModel.cpp +++ b/KelvinDashboardGUI/DapChainWalletsModel.cpp @@ -83,6 +83,12 @@ void DapChainWalletsModel::remove(int row) endRemoveRows(); } +void DapChainWalletsModel::clear() +{ + if(m_dapChainWallets.count() > 0) + m_dapChainWallets.clear(); +} + QObject *DapChainWalletsModel::singletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine) { Q_UNUSED(engine) diff --git a/KelvinDashboardGUI/DapChainWalletsModel.h b/KelvinDashboardGUI/DapChainWalletsModel.h index 4b318c7ede9210a36b5ceb1de6fd1b4dd8e855b8..2013196b8258b64109c6efe9a9e65eda6fb05169 100644 --- a/KelvinDashboardGUI/DapChainWalletsModel.h +++ b/KelvinDashboardGUI/DapChainWalletsModel.h @@ -39,6 +39,7 @@ public: 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. diff --git a/KelvinDashboardGUI/DapCommandController.cpp b/KelvinDashboardGUI/DapCommandController.cpp index 3c10bd0d066b49c2166ea8a44ccd7c60c70494cc..5e63b1e13bc3c00965cc2b9d3142646137bac4c2 100644 --- a/KelvinDashboardGUI/DapCommandController.cpp +++ b/KelvinDashboardGUI/DapCommandController.cpp @@ -62,7 +62,9 @@ void DapCommandController::processAddWallet() return; } emit sigCommandResult(reply->response().result()); - emit sigWalletAdded(reply->response().result().toVariant().toString()); + 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() diff --git a/KelvinDashboardGUI/DapCommandController.h b/KelvinDashboardGUI/DapCommandController.h index eb9283aa08468df6114d84ecaf8a59808e6377e2..6b4abdfbc38abd5725120abf306be3274c64d64a 100644 --- a/KelvinDashboardGUI/DapCommandController.h +++ b/KelvinDashboardGUI/DapCommandController.h @@ -26,7 +26,7 @@ signals: /// @param aNodeLogs List of node logs. void sigNodeLogsReceived(const QStringList& aNodeLogs); - void sigWalletAdded(const QString& asWalletAddress); + 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. diff --git a/KelvinDashboardGUI/DapServiceController.cpp b/KelvinDashboardGUI/DapServiceController.cpp index 4149cc8993c23f825a2229ae7f5cf8b5ed261c91..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) @@ -39,7 +40,7 @@ void DapServiceController::init(DapServiceClient *apDapServiceClient) // 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(sigWalletAdded(QString, QString)), SLOT(processAddWallet(QString, QString))); connect(m_pDapCommandController, SIGNAL(sigWalletsReceived(QMap<QString,QVariant>)), SLOT(processGetWallets(QMap<QString,QVariant>))); } @@ -106,17 +107,21 @@ void DapServiceController::addWallet(const QString &asWalletName) m_pDapCommandController->addWallet(asWalletName); } -void DapServiceController::processAddWallet(const QString &asWalletAddress) +void DapServiceController::processAddWallet(const QString& asWalletName, const QString& asWalletAddress) { - qInfo() << QString("processAddWallet(%1)").arg(asWalletAddress); - qDebug() << "Wallet address() " << 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 wallet : aWallets.keys()) - qDebug() << "W" << wallet << " " << aWallets.value(wallet).toString(); + for(QString w : aWallets.keys()) + { + DapChainWallet wallet("", w, aWallets.value(w).toString()); + DapChainWalletsModel::getInstance().append(wallet); + } } /// Get an instance of a class. diff --git a/KelvinDashboardGUI/DapServiceController.h b/KelvinDashboardGUI/DapServiceController.h index 08fdc132aa99ac52ae3054f64f6e56d5517d2690..fe9a03f65589160e3f9f5b14f9859262728f81ae 100644 --- a/KelvinDashboardGUI/DapServiceController.h +++ b/KelvinDashboardGUI/DapServiceController.h @@ -12,6 +12,7 @@ #include "DapCommandController.h" #include "DapServiceClient.h" #include "DapLogModel.h" +#include "DapChainWalletsModel.h" class DapServiceController : public QObject { @@ -82,7 +83,7 @@ private slots: /// @param aNodeLogs List of node logs. void processGetNodeLogs(const QStringList& aNodeLogs); - void processAddWallet(const QString& asWalletAddress); + void processAddWallet(const QString& asWalletName, const QString& asWalletAddress); void processGetWallets(const QMap<QString, QVariant>& aWallets); diff --git a/KelvinDashboardGUI/DapUiQmlScreenDialogAddWallet.qml b/KelvinDashboardGUI/DapUiQmlScreenDialogAddWallet.qml index e40c42e6e8c8acb1be3de9e88a703bcb0c23347f..54517ffacb6d17132da87496daab3046486e2af4 100644 --- a/KelvinDashboardGUI/DapUiQmlScreenDialogAddWallet.qml +++ b/KelvinDashboardGUI/DapUiQmlScreenDialogAddWallet.qml @@ -48,14 +48,31 @@ Dialog { Button { - id: buttonCancle - text: "Cancel" - width: 100 - height: 30 + 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() @@ -67,12 +84,28 @@ Dialog { { id: buttonOk text: "OK" - width: 100 - height: 30 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) diff --git a/KelvinDashboardGUI/DapUiQmlWidgetChainWalletForm.ui.qml b/KelvinDashboardGUI/DapUiQmlWidgetChainWalletForm.ui.qml index 0532651266b50f9ef6d198dbc780f73fd5908421..1bdc39b1d976947f4022633c9dbccc06acef6c92 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetChainWalletForm.ui.qml +++ b/KelvinDashboardGUI/DapUiQmlWidgetChainWalletForm.ui.qml @@ -7,6 +7,7 @@ Page { title: qsTr("Wallet") + property alias listViewWallet: listViewWallet property alias save: save property alias dialogAddWallet: dialogAddWallet @@ -15,6 +16,7 @@ Page { anchors.fill: parent anchors.margins: 10 spacing: 10 + model: dapChainWalletsModel delegate: Item { width: parent.width @@ -85,27 +87,7 @@ Page { } } - model: ListModel { - ListElement { - name: "mywallet" - address: "RpiDC8c1SxrTNbxwSTVP6mAHhXvUAgCthoCfpVmUSm889M3zt5JfBxo6iRoAPmJkCPihSWNxhRtdTxnd7LXwcj1nbVd5NQyW1kCgXyM6" - } - - ListElement { - name: "mywallet" - address: "RpiDC8c1SxrTNbxwSTVP6mAHhXvUAgCthoCfpVmUSm889M3zt5JfBxo6iRoAPmJkCPihSWNxhRtdTxnd7LXwcj1nbVd5NQyW1kCgXyM6" - } - ListElement { - name: "mywallet" - address: "RpiDC8c1SxrTNbxwSTVP6mAHhXvUAgCthoCfpVmUSm889M3zt5JfBxo6iRoAPmJkCPihSWNxhRtdTxnd7LXwcj1nbVd5NQyW1kCgXyM6" - } - - ListElement { - name: "mywallet" - address: "RpiDC8c1SxrTNbxwSTVP6mAHhXvUAgCthoCfpVmUSm889M3zt5JfBxo6iRoAPmJkCPihSWNxhRtdTxnd7LXwcj1nbVd5NQyW1kCgXyM6" - } - } } DapUiQmlScreenDialogAddWallet { id: dialogAddWallet diff --git a/KelvinDashboardGUI/main.cpp b/KelvinDashboardGUI/main.cpp index 8db0315d38f1d6ff7c47d5e32888184da257a122..dce86218eaacb0a55bcf82f3a92e7a1a7b5426de 100755 --- a/KelvinDashboardGUI/main.cpp +++ b/KelvinDashboardGUI/main.cpp @@ -20,6 +20,8 @@ #include "DapLogModel.h" #include "DapChainWalletsModel.h" +#include <QRegExp> + int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); @@ -37,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 diff --git a/KelvinDashboardService/DapChainDashboardService.cpp b/KelvinDashboardService/DapChainDashboardService.cpp index 10eefd8f7d6bdeb33c93c40bb577131dbcf71ba9..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,19 +41,17 @@ QStringList DapChainDashboardService::getNodeLogs(int aiTimeStamp, int aiRowCoun return m_pDapLogReader->request(aiTimeStamp, aiRowCount); } -QString DapChainDashboardService::addWallet(const QString &asWalletName) +QStringList DapChainDashboardService::addWallet(const QString &asWalletName) { qInfo() << QString("addWallet(%1)").arg(asWalletName); - return "NULL"; + return m_pDapChainWalletHandler->createWallet(asWalletName); } QMap<QString, QVariant> DapChainDashboardService::getWallets() { qInfo() << QString("getWallets()"); - QMap<QString, QVariant> map; - map.insert("My", "454asf6das4f6fd68df6877dsf"); - return map; + return m_pDapChainWalletHandler->getWallets(); } diff --git a/KelvinDashboardService/DapChainDashboardService.h b/KelvinDashboardService/DapChainDashboardService.h index f6a609d6285f6104c8467f6fef959ec41e2eb53e..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(); @@ -65,7 +68,7 @@ public slots: /// @return Logs node. QStringList getNodeLogs(int aiTimeStamp, int aiRowCount); - QString addWallet(const QString &asWalletName); + 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)