diff --git a/CellFrameDashboardGUI/CellFrameDashboardGUI.pro b/CellFrameDashboardGUI/CellFrameDashboardGUI.pro index b20767a8ad3da1a8a21d82bc9c6754ba7d3d7394..b9b8631a41905b1b7a8607763560e991d61d841e 100755 --- a/CellFrameDashboardGUI/CellFrameDashboardGUI.pro +++ b/CellFrameDashboardGUI/CellFrameDashboardGUI.pro @@ -45,6 +45,7 @@ SOURCES += \ DapConsoleModel.cpp \ DapScreenHistoryFilterModel.cpp \ DapScreenHistoryModel.cpp \ + DapSettingsNetworkModel.cpp \ DapUiQmlWidgetChainTransactions.cpp \ main.cpp \ DapUiQmlWidgetChainBallance.cpp \ @@ -82,6 +83,7 @@ HEADERS += \ DapConsoleModel.h \ DapScreenHistoryFilterModel.h \ DapScreenHistoryModel.h \ + DapSettingsNetworkModel.h \ DapUiQmlWidgetChainBallance.h \ DapUiQmlWidgetChainBlockExplorer.h \ DapUiQmlWidgetChainNodeLogs.h \ @@ -117,4 +119,6 @@ unix: !mac : !android { INSTALLS += gui_target } -DISTFILES += +#DISTFILES += \ +# DapUiQmlScreenSettings.qml \ +# DapUiQmlScreenSettingsForm.ui.qml diff --git a/CellFrameDashboardGUI/DapCommandController.cpp b/CellFrameDashboardGUI/DapCommandController.cpp index 2942f0c90fcd3d8b6e4931a929b0475b36a77004..47562227a6d7cb21cf7422882613cefa457157d7 100755 --- a/CellFrameDashboardGUI/DapCommandController.cpp +++ b/CellFrameDashboardGUI/DapCommandController.cpp @@ -70,6 +70,11 @@ void DapCommandController::getCmdHistory() connect(reply, SIGNAL(finished()), this, SLOT(processGetCmdHistory())); } +void DapCommandController::changeCurrentNetwork(const QString& aNetwork) +{ + m_DAPRpcSocket->invokeRemoteMethod("RPCServer.changeCurrentNetwork", aNetwork); +} + void DapCommandController::processChangedLog() { // QStringList tempLogModel; @@ -193,7 +198,6 @@ void DapCommandController::processExecuteCommand() void DapCommandController::processGetHistory() { - qDebug() << "processGetHistory()"; DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); QVariant result = reply->response().result().toArray().toVariantList(); emit sendHistory(result); @@ -213,6 +217,13 @@ void DapCommandController::processGetCmdHistory() emit sigCmdHistory(result); } +void DapCommandController::processGetNetworkList() +{ + DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); + QStringList result = reply->response().result().toVariant().toStringList(); + emit sendNetworkList(result); +} + /// 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. @@ -266,6 +277,12 @@ void DapCommandController::getNodeNetwork() connect(reply, SIGNAL(finished()), this, SLOT(processGetNodeNetwork())); } +void DapCommandController::getNetworkList() +{ + DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.getNetworkList"); + connect(reply, SIGNAL(finished()), this, SLOT(processGetNetworkList())); +} + void DapCommandController::setNodeStatus(const bool aIsOnline) { /*DapRpcServiceReply *reply =*/ m_DAPRpcSocket->invokeRemoteMethod("RPCServer.setNodeStatus", aIsOnline); diff --git a/CellFrameDashboardGUI/DapCommandController.h b/CellFrameDashboardGUI/DapCommandController.h index 845f95cc6dcfa40ff641855cf38a691e9d2dbc14..a8dd9ffdbee2728879168f809cae0981fe1dc4e0 100755 --- a/CellFrameDashboardGUI/DapCommandController.h +++ b/CellFrameDashboardGUI/DapCommandController.h @@ -51,6 +51,8 @@ signals: /// Signal about changing history of commands void sigCmdHistory(const QString& aHistory); + void sendNetworkList(const QStringList& aList); + public: /// Overloaded constructor. /// @param apIODevice Data transfer device. @@ -80,6 +82,8 @@ private slots: void processGetHistory(); + void processGetNetworkList(); + void processResponseConsole(); void processGetCmdHistory(); @@ -104,6 +108,8 @@ public slots: void getNodeNetwork(); + void getNetworkList(); + void setNodeStatus(const bool aIsOnline); void executeCommand(const QString& command); @@ -119,6 +125,8 @@ public slots: void requestConsole(const QString& aQueue); /// Get command history void getCmdHistory(); + + void changeCurrentNetwork(const QString& aNetwork); }; #endif // COMMANDCONTROLLER_H diff --git a/CellFrameDashboardGUI/DapScreenHistoryModel.cpp b/CellFrameDashboardGUI/DapScreenHistoryModel.cpp index ac5b71693c474e239c347945181a39be5a4402ea..91754fae220b5828e8b552efadac766768a0db9c 100644 --- a/CellFrameDashboardGUI/DapScreenHistoryModel.cpp +++ b/CellFrameDashboardGUI/DapScreenHistoryModel.cpp @@ -50,7 +50,6 @@ void DapScreenHistoryModel::receiveNewData(const QVariant& aData) return; } - qDebug() << aData; beginResetModel(); QList<QVariant> dataList = aData.toList(); m_elementList.clear(); diff --git a/CellFrameDashboardGUI/DapServiceController.cpp b/CellFrameDashboardGUI/DapServiceController.cpp index ab03e89ae61c42ca727520166187f9c7334bdf46..3792b8135fa1c5cff5551a232bdee20989713bd2 100755 --- a/CellFrameDashboardGUI/DapServiceController.cpp +++ b/CellFrameDashboardGUI/DapServiceController.cpp @@ -67,6 +67,9 @@ void DapServiceController::init(DapServiceClient *apDapServiceClient) connect(&DapConsoleModel::getInstance(), &DapConsoleModel::sendRequest, m_pDapCommandController, &DapCommandController::requestConsole); connect(m_pDapCommandController, &DapCommandController::responseConsole, &DapConsoleModel::getInstance(), &DapConsoleModel::receiveResponse); connect(m_pDapCommandController, &DapCommandController::sigCmdHistory, &DapConsoleModel::getInstance(), &DapConsoleModel::receiveCmdHistory); + + connect(m_pDapCommandController, &DapCommandController::sendNetworkList, &DapSettingsNetworkModel::getInstance(), &DapSettingsNetworkModel::setNetworkList); + connect(&DapSettingsNetworkModel::getInstance(), &DapSettingsNetworkModel::currentNetworkChanged, m_pDapCommandController, &DapCommandController::changeCurrentNetwork); } QString DapServiceController::getBrand() const @@ -230,6 +233,11 @@ void DapServiceController::processGetHistory(const QVariant& aData) DapScreenHistoryModel::getInstance().receiveNewData(aData); } +void DapServiceController::getNetworkList() +{ + m_pDapCommandController->getNetworkList(); +} + /// Get an instance of a class. /// @return Instance of a class. diff --git a/CellFrameDashboardGUI/DapServiceController.h b/CellFrameDashboardGUI/DapServiceController.h index bcc569b14d4b0fde7a4829ed9f543b778f6a5070..e93daea8921b1a98705968e27bf6dd3a5e30ec9e 100755 --- a/CellFrameDashboardGUI/DapServiceController.h +++ b/CellFrameDashboardGUI/DapServiceController.h @@ -15,6 +15,7 @@ #include "DapChainWalletsModel.h" #include "DapChainNodeNetworkModel.h" #include "DapScreenHistoryModel.h" +#include "DapSettingsNetworkModel.h" #include "DapConsoleModel.h" class DapServiceController : public QObject @@ -81,6 +82,8 @@ public: Q_INVOKABLE void executeCommand(const QString& command); void getWalletInfo(const QString& asWalletName); + /// Request about new netowrk list + void getNetworkList(); /// Get history of commands void getCmdHistory(); diff --git a/CellFrameDashboardGUI/DapSettingsNetworkModel.cpp b/CellFrameDashboardGUI/DapSettingsNetworkModel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e6567a038718a95644e9f8c72238c9c2bf725fa7 --- /dev/null +++ b/CellFrameDashboardGUI/DapSettingsNetworkModel.cpp @@ -0,0 +1,65 @@ +#include "DapSettingsNetworkModel.h" + +DapSettingsNetworkModel::DapSettingsNetworkModel(QObject *parent) : QAbstractListModel(parent), + m_CurrentIndex(-1) +{ + +} + +DapSettingsNetworkModel& DapSettingsNetworkModel::getInstance() +{ + static DapSettingsNetworkModel instance; + return instance; +} + +int DapSettingsNetworkModel::rowCount(const QModelIndex& parent) const +{ + Q_UNUSED(parent) + + return m_NetworkList.count(); +} + +QVariant DapSettingsNetworkModel::data(const QModelIndex& index, int role) const +{ + if(!index.isValid()) return QVariant(); + if(role == DisplayName) + return m_NetworkList.at(index.row()); + + return QVariant(); +} + +QHash<int, QByteArray> DapSettingsNetworkModel::roleNames() const +{ + QHash<int, QByteArray> roles; + roles[DisplayName] = "network"; + + return roles; +} + +QString DapSettingsNetworkModel::getCurrentNetwork() const +{ + return m_CurrentNetwork; +} + +int DapSettingsNetworkModel::getCurrentIndex() const +{ + return m_CurrentIndex; +} + +void DapSettingsNetworkModel::setNetworkList(const QStringList& aNetworkList) +{ + if(m_NetworkList == aNetworkList) return; + beginResetModel(); + m_NetworkList = aNetworkList; + endResetModel(); +} + +void DapSettingsNetworkModel::setCurrentNetwork(QString CurrentNetwork, int CurrentIndex) +{ + if (m_CurrentNetwork == CurrentNetwork) + return; + + m_CurrentNetwork = CurrentNetwork; + m_CurrentIndex = CurrentIndex; + emit currentNetworkChanged(m_CurrentNetwork); +} diff --git a/CellFrameDashboardGUI/DapSettingsNetworkModel.h b/CellFrameDashboardGUI/DapSettingsNetworkModel.h new file mode 100644 index 0000000000000000000000000000000000000000..216d012900777673f5863c34a6653d170e9c4036 --- /dev/null +++ b/CellFrameDashboardGUI/DapSettingsNetworkModel.h @@ -0,0 +1,56 @@ +#ifndef DAPSETTINGSNETWORKMODEL_H +#define DAPSETTINGSNETWORKMODEL_H + +#include <QAbstractListModel> +#include <QStringList> +#include <QDebug> + +class DapSettingsNetworkModel : public QAbstractListModel +{ + Q_OBJECT + +public: + /// Enumeration display role + enum DisplayRole { + DisplayName = Qt::UserRole + }; + +private: + QStringList m_NetworkList; + QString m_CurrentNetwork; + int m_CurrentIndex; + +public: + explicit DapSettingsNetworkModel(QObject *parent = nullptr); + /// Get instance of this object + /// @return instance + static DapSettingsNetworkModel &getInstance(); + + /// Overload methods + int rowCount(const QModelIndex& parent) const; + QVariant data(const QModelIndex& index, int role) const; + QHash<int, QByteArray> roleNames() const; + + /// Get current network which was selected + /// @return name of current network + Q_INVOKABLE QString getCurrentNetwork() const; + /// Get current index which was selected + /// @return index of current network + Q_INVOKABLE int getCurrentIndex() const; + +public slots: + /// Set new network list + /// @param List of network + void setNetworkList(const QStringList& aNetworkList); + /// Set current network which was selected in combobox + /// @param name of network + /// @param index of network + void setCurrentNetwork(QString CurrentNetwork, int CurrentIndex); + +signals: + /// Signal about changing current network + /// @param name of network which was selected + void currentNetworkChanged(QString currentNetwork); +}; + +#endif // DAPSETTINGSNETWORKMODEL_H diff --git a/CellFrameDashboardGUI/DapUiQmlScreenMainWindowForm.ui.qml b/CellFrameDashboardGUI/DapUiQmlScreenMainWindowForm.ui.qml index a4c12e54736b2e654db5a6e8017a0ddda46c515a..20e633e36faec0231a30bd5cd848b90c815813ad 100644 --- a/CellFrameDashboardGUI/DapUiQmlScreenMainWindowForm.ui.qml +++ b/CellFrameDashboardGUI/DapUiQmlScreenMainWindowForm.ui.qml @@ -49,7 +49,9 @@ Page { } ListElement { name: qsTr("Settings") - page: "DapQmlScreenAbout.qml" +// page: "DapQmlScreenAbout.qml" + page: "DapUiQmlScreenSettings.qml" +// page: "DapUiQmlWidgetSettingsNetwork.qml" source: "qrc:/Resources/Icons/defaul_icon.png" } ListElement { diff --git a/CellFrameDashboardGUI/DapUiQmlScreenSettings.qml b/CellFrameDashboardGUI/DapUiQmlScreenSettings.qml new file mode 100644 index 0000000000000000000000000000000000000000..f7897fe4e805a44e761276f288f82fb2f4cf7e2e --- /dev/null +++ b/CellFrameDashboardGUI/DapUiQmlScreenSettings.qml @@ -0,0 +1,36 @@ +import QtQuick 2.4 +import QtQuick.Controls 2.12 + +DapUiQmlScreenSettingsForm { + anchors.fill: parent + + ListModel { + id: dapListModelSettings + ListElement { + name: qsTr("Network") + element: "DapUiQmlWidgetSettingsNetwork.qml" + } + } + + ListView { + id: dapListViewSettings + anchors.fill: parent + model: dapListModelSettings + delegate: Component { + + Item { + width: parent.width + height: loaderSettings.height + + Loader { + id: loaderSettings + source: element + } + } + } + + section.property: "name" + section.criteria: ViewSection.FullString + section.delegate: DapUiQmlScreenSettingsSection {} + } +} diff --git a/CellFrameDashboardGUI/DapUiQmlScreenSettingsForm.ui.qml b/CellFrameDashboardGUI/DapUiQmlScreenSettingsForm.ui.qml new file mode 100644 index 0000000000000000000000000000000000000000..9faa0c04d692a727610d3084348cf081ae43d72a --- /dev/null +++ b/CellFrameDashboardGUI/DapUiQmlScreenSettingsForm.ui.qml @@ -0,0 +1,5 @@ +import QtQuick 2.4 + +Item { + anchors.fill: parent +} diff --git a/CellFrameDashboardGUI/DapUiQmlScreenSettingsSection.qml b/CellFrameDashboardGUI/DapUiQmlScreenSettingsSection.qml new file mode 100644 index 0000000000000000000000000000000000000000..51d10f3f663f3837b9c9e5ffba1b2df6651d98cb --- /dev/null +++ b/CellFrameDashboardGUI/DapUiQmlScreenSettingsSection.qml @@ -0,0 +1,21 @@ +import QtQuick 2.0 + +Component { + + Rectangle { + width: parent.width + height: 30 * pt + color: "#DFE1E6" + + Text { + anchors.fill: parent + anchors.leftMargin: 18 * pt + verticalAlignment: Qt.AlignVCenter + text: section + font.family: "Roboto" + font.pixelSize: 12 * pt + color: "#5F5F63" + } + } + +} diff --git a/CellFrameDashboardGUI/DapUiQmlWidgetSettingsNetwork.qml b/CellFrameDashboardGUI/DapUiQmlWidgetSettingsNetwork.qml new file mode 100644 index 0000000000000000000000000000000000000000..30286e2c369761260bcb845cba90c05cf553666f --- /dev/null +++ b/CellFrameDashboardGUI/DapUiQmlWidgetSettingsNetwork.qml @@ -0,0 +1,25 @@ +import QtQuick 2.4 +import QtQuick.Controls 2.12 + +DapUiQmlWidgetSettingsNetworkForm { + width: parent.width + height: childrenRect.height + + ComboBox { + width: 150 + height: 50 + anchors.left: parent.left + anchors.top: parent.top + anchors.leftMargin: 18 * pt + anchors.topMargin: 13 * pt + model: dapSettingsNetworkModel + textRole: "network" + currentIndex: dapSettingsNetworkModel.getCurrentIndex() + + onCurrentTextChanged: { + if(dapSettingsNetworkModel.getCurrentIndex() !== currentIndex) { + dapSettingsNetworkModel.setCurrentNetwork(currentText, currentIndex); + } + } + } +} diff --git a/CellFrameDashboardGUI/DapUiQmlWidgetSettingsNetworkForm.ui.qml b/CellFrameDashboardGUI/DapUiQmlWidgetSettingsNetworkForm.ui.qml new file mode 100644 index 0000000000000000000000000000000000000000..96a8ae4f5771e1ed409dbaa2ffc4afbcc2382791 --- /dev/null +++ b/CellFrameDashboardGUI/DapUiQmlWidgetSettingsNetworkForm.ui.qml @@ -0,0 +1,6 @@ +import QtQuick 2.4 + +Item { + width: 400 + height: 400 +} diff --git a/CellFrameDashboardGUI/main.cpp b/CellFrameDashboardGUI/main.cpp index ff2ee42c7a064ba77e8b90d68cd85082918b15c0..741860dc262f5f38270c7c020b51e4f00c0a3951 100755 --- a/CellFrameDashboardGUI/main.cpp +++ b/CellFrameDashboardGUI/main.cpp @@ -23,6 +23,7 @@ #include "DapChainNodeNetworkModel.h" #include "DapChainNodeNetworkExplorer.h" #include "DapScreenHistoryFilterModel.h" +#include "DapSettingsNetworkModel.h" #include "DapConsoleModel.h" #include <QRegExp> @@ -54,6 +55,7 @@ int main(int argc, char *argv[]) controller.getWallets(); controller.getHistory(); controller.getCmdHistory(); + controller.getNetworkList(); DapScreenHistoryFilterModel::getInstance() .setSourceModel(&DapScreenHistoryModel::getInstance()); @@ -75,9 +77,10 @@ int main(int argc, char *argv[]) engine.rootContext()->setContextProperty("dapNodeNetworkModel", &DapChainNodeNetworkModel::getInstance()); engine.rootContext()->setContextProperty("dapConsoleModel", &DapConsoleModel::getInstance()); engine.rootContext()->setContextProperty("dapHistoryModel", &DapScreenHistoryFilterModel::getInstance()); + engine.rootContext()->setContextProperty("dapSettingsNetworkModel", &DapSettingsNetworkModel::getInstance()); engine.rootContext()->setContextProperty("pt", 1.3); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); - + if (engine.rootObjects().isEmpty()) return -1; diff --git a/CellFrameDashboardGUI/qml.qrc b/CellFrameDashboardGUI/qml.qrc index 16c736a9c50a1a30c4e8b6cdc92c7bf2c6f006f5..b642898dbc665a63e3795f9f784ad16916824bf6 100755 --- a/CellFrameDashboardGUI/qml.qrc +++ b/CellFrameDashboardGUI/qml.qrc @@ -61,5 +61,10 @@ <file>DapUiQmlWidgetConsoleLastActionsDelegateForm.qml</file> <file>DapUiQmlWidgetConsole.qml</file> <file>DapUiQmlWidgetConsoleForm.ui.qml</file> + <file>DapUiQmlWidgetSettingsNetwork.qml</file> + <file>DapUiQmlWidgetSettingsNetworkForm.ui.qml</file> + <file>DapUiQmlScreenSettings.qml</file> + <file>DapUiQmlScreenSettingsForm.ui.qml</file> + <file>DapUiQmlScreenSettingsSection.qml</file> </qresource> </RCC> diff --git a/CellFrameDashboardService/CellFrameDashboardService.pro b/CellFrameDashboardService/CellFrameDashboardService.pro index 918b1de4a58ef1ba6271c19fc3b14e2f0b7b6091..64bcd5e54e9a3f599d365192faf0eeff8c3a93c5 100755 --- a/CellFrameDashboardService/CellFrameDashboardService.pro +++ b/CellFrameDashboardService/CellFrameDashboardService.pro @@ -51,6 +51,7 @@ SOURCES += \ $$PWD/DapChainNodeCache.cpp \ $$PWD/DapChainWalletHandler.cpp \ $$PWD/DapChainLogHandler.cpp \ + $$PWD/DapChainNetworkHandler.cpp \ $$PWD/DapChainConsoleHandler.cpp HEADERS += \ @@ -61,6 +62,7 @@ HEADERS += \ $$PWD/DapChainNodeNetworkHandler.h \ $$PWD/DapChainWalletHandler.h \ $$PWD/DapChainLogHandler.h \ + $$PWD/DapChainNetworkHandler.h \ $$PWD/DapChainConsoleHandler.h include (../libdap/libdap.pri) diff --git a/CellFrameDashboardService/DapChainDashboardService.cpp b/CellFrameDashboardService/DapChainDashboardService.cpp index fa588c86d31fdea955cfc147158a416fe31ef956..d12ef4577ce76de2d464f73a737a45dc5889cee7 100755 --- a/CellFrameDashboardService/DapChainDashboardService.cpp +++ b/CellFrameDashboardService/DapChainDashboardService.cpp @@ -12,10 +12,12 @@ DapChainDashboardService::DapChainDashboardService() : DapRpcService(nullptr) m_pDapChainNodeHandler = new DapChainNodeNetworkHandler(this); - m_pDapChainHistoryHandler = new DapChainHistoryHandler {this}; + m_pDapChainHistoryHandler = new DapChainHistoryHandler(this); QObject::connect(m_pDapChainHistoryHandler, &DapChainHistoryHandler::requsetWallets, this, &DapChainDashboardService::doRequestWallets); QObject::connect(m_pDapChainHistoryHandler, &DapChainHistoryHandler::changeHistory, this, &DapChainDashboardService::doSendNewHistory); + m_pDapChainNetworkHandler = new DapChainNetworkHandler(this); + m_pDapChainConsoleHandler = new DapChainConsoleHandler(this); } @@ -100,6 +102,18 @@ QString DapChainDashboardService::getCmdHistory() const return m_pDapChainConsoleHandler->getHistory(); } +QStringList DapChainDashboardService::getNetworkList() const +{ + return m_pDapChainNetworkHandler->getNetworkList(); +} + +void DapChainDashboardService::changeCurrentNetwork(const QString& aNetwork) +{ + m_pDapChainHistoryHandler->setCurrentNetwork(aNetwork); + m_pDapChainNodeHandler->setCurrentNetwork(aNetwork); + m_pDapChainWalletHandler->setCurrentNetwork(aNetwork); +} + void DapChainDashboardService::doRequestWallets() { m_pDapChainHistoryHandler->onRequestNewHistory(m_pDapChainWalletHandler->getWallets()); diff --git a/CellFrameDashboardService/DapChainDashboardService.h b/CellFrameDashboardService/DapChainDashboardService.h index 6f1fe70bd889d4961539e7aa20bc625bab2718b6..85144bd63138023d52fd08dda1284ff8c46ae51e 100755 --- a/CellFrameDashboardService/DapChainDashboardService.h +++ b/CellFrameDashboardService/DapChainDashboardService.h @@ -27,6 +27,7 @@ #include "DapChainWalletHandler.h" #include "DapChainNodeNetworkHandler.h" #include "DapChainHistoryHandler.h" +#include "DapChainNetworkHandler.h" #include "DapChainConsoleHandler.h" #include <QLocalServer> @@ -52,6 +53,8 @@ class DapChainDashboardService : public DapRpcService /// Recipient history of commands DapChainConsoleHandler* m_pDapChainConsoleHandler {nullptr}; + DapChainNetworkHandler* m_pDapChainNetworkHandler {nullptr}; + public: /// Standard Ñonstructor. explicit DapChainDashboardService(); @@ -103,6 +106,12 @@ public slots: /// Get history /// @return QList data history QVariant getHistory() const; + /// Get network list + /// @return Network list + QStringList getNetworkList() const; + /// Change current network + /// @param name of network whcih was selected + void changeCurrentNetwork(const QString& aNetwork); /// Get result for command /// @param command /// @return result diff --git a/CellFrameDashboardService/DapChainHistoryHandler.cpp b/CellFrameDashboardService/DapChainHistoryHandler.cpp index 2bb2dd5fa738fa85d28175000dce01d695fe562e..136e34841e8ccff176082c7511a2ddf149e8c854 100644 --- a/CellFrameDashboardService/DapChainHistoryHandler.cpp +++ b/CellFrameDashboardService/DapChainHistoryHandler.cpp @@ -22,7 +22,7 @@ void DapChainHistoryHandler::onRequestNewHistory(const QMap<QString, QVariant>& for(int i = 0; i < wallets.count(); i++) { QProcess process; - process.start(QString(CLI_PATH) + " tx_history -net private -chain gdb -addr " + wallets.at(i).toString()); + process.start(QString("%1 tx_history -net %2 -chain gdb -addr %3").arg(CLI_PATH).arg(m_CurrentNetwork).arg(wallets.at(i).toString())); process.waitForFinished(-1); QByteArray result = process.readAll(); @@ -48,3 +48,10 @@ void DapChainHistoryHandler::onRequestNewHistory(const QMap<QString, QVariant>& emit changeHistory(m_history); } } + +void DapChainHistoryHandler::setCurrentNetwork(const QString& aNetwork) +{ + if(aNetwork == m_CurrentNetwork) + return; + m_CurrentNetwork = aNetwork; +} diff --git a/CellFrameDashboardService/DapChainHistoryHandler.h b/CellFrameDashboardService/DapChainHistoryHandler.h index 1d204c46ac0e6a7a0a3102784a2e2c107738711e..6b56f6e35801057ea3d67c547cc0e64d7b904feb 100644 --- a/CellFrameDashboardService/DapChainHistoryHandler.h +++ b/CellFrameDashboardService/DapChainHistoryHandler.h @@ -16,6 +16,7 @@ class DapChainHistoryHandler : public QObject Q_OBJECT private: + QString m_CurrentNetwork; QVariant m_history; QTimer* m_timoutRequestHistory; @@ -30,6 +31,9 @@ public slots: /// Request new tx history /// @param wallet list void onRequestNewHistory(const QMap<QString, QVariant>& aWallets); + /// Set current network + /// @param name of network + void setCurrentNetwork(const QString& aNetwork); signals: /// Signal for request wallets list diff --git a/CellFrameDashboardService/DapChainNetworkHandler.cpp b/CellFrameDashboardService/DapChainNetworkHandler.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7abc34e13603c39405f72d73964dbcd848ab0675 --- /dev/null +++ b/CellFrameDashboardService/DapChainNetworkHandler.cpp @@ -0,0 +1,29 @@ +#include "DapChainNetworkHandler.h" +#include <QDebug> + +DapChainNetworkHandler::DapChainNetworkHandler(QObject *parent) : QObject(parent) +{ + +} + +QStringList DapChainNetworkHandler::getNetworkList() +{ + QStringList network; + QProcess process; + process.start(QString(CLI_PATH) + " net list"); + process.waitForFinished(-1); + QByteArray result = process.readAll(); + + if(!result.isEmpty()) + { + QString data = QString::fromStdString(result.toStdString()); + data = data.remove("\n"); + QStringList list = data.split(": "); + if(list.count() > 1) + { + network = list.at(1).split(", "); + } + } + + return network; +} diff --git a/CellFrameDashboardService/DapChainNetworkHandler.h b/CellFrameDashboardService/DapChainNetworkHandler.h new file mode 100644 index 0000000000000000000000000000000000000000..515cd2298f0789ad760cb122870ab6aa67a6b9cc --- /dev/null +++ b/CellFrameDashboardService/DapChainNetworkHandler.h @@ -0,0 +1,25 @@ +#ifndef DAPCHAINNETWORKHANDLER_H +#define DAPCHAINNETWORKHANDLER_H + +#include <QObject> +#include <QString> +#include <QProcess> + +#include <QFile> + +class DapChainNetworkHandler : public QObject +{ + Q_OBJECT + +private: + QStringList m_NetworkList; + +public: + explicit DapChainNetworkHandler(QObject *parent = nullptr); + + /// Get network list + /// @return Network list + QStringList getNetworkList(); +}; + +#endif // DAPCHAINNETWORKHANDLER_H diff --git a/CellFrameDashboardService/DapChainNodeNetworkHandler.cpp b/CellFrameDashboardService/DapChainNodeNetworkHandler.cpp index fa829cefec1b741f507d928316e3c6e34731ce3e..52fda1159009e3ef01df630316192ec216ec02ee 100644 --- a/CellFrameDashboardService/DapChainNodeNetworkHandler.cpp +++ b/CellFrameDashboardService/DapChainNodeNetworkHandler.cpp @@ -9,7 +9,7 @@ DapChainNodeNetworkHandler::DapChainNodeNetworkHandler(QObject *parent) : QObjec QVariant DapChainNodeNetworkHandler::getNodeNetwork() const { QProcess process; - process.start(QString(CLI_PATH) + " node dump -net kelvin-testnet -full"); + process.start(QString("%1 node dump -net %2 -full").arg(CLI_PATH).arg(m_CurrentNetwork)); process.waitForFinished(-1); QByteArray result = process.readAll(); @@ -50,7 +50,7 @@ QVariant DapChainNodeNetworkHandler::getNodeNetwork() const QProcess process_status; - process_status.start(QString(CLI_PATH) + QString(" net -net kelvin-testnet get status")); + process_status.start(QString(CLI_PATH) + " net -net " + m_CurrentNetwork + " get status"); process_status.waitForFinished(-1); QByteArray result_status = process_status.readAll(); @@ -67,9 +67,16 @@ QVariant DapChainNodeNetworkHandler::getNodeNetwork() const return nodeMap; } +void DapChainNodeNetworkHandler::setCurrentNetwork(const QString& aNetwork) +{ + if(m_CurrentNetwork == aNetwork) + return; + m_CurrentNetwork = aNetwork; +} + void DapChainNodeNetworkHandler::setNodeStatus(const bool aIsOnline) { QProcess process; - process.start(QString(CLI_PATH) + QString(" net -net kelvin-testnet go %1").arg(aIsOnline ? "online" : "offline")); + process.start(QString(CLI_PATH) + QString(" net -net %1 go %2").arg(m_CurrentNetwork).arg(aIsOnline ? "online" : "offline")); process.waitForFinished(-1); } diff --git a/CellFrameDashboardService/DapChainNodeNetworkHandler.h b/CellFrameDashboardService/DapChainNodeNetworkHandler.h index e8cc121bed7349e55fc4faeecb6f5788f12567f3..ab57a373debb8cb82ee3a880f4b1326f2723823e 100644 --- a/CellFrameDashboardService/DapChainNodeNetworkHandler.h +++ b/CellFrameDashboardService/DapChainNodeNetworkHandler.h @@ -13,6 +13,9 @@ class DapChainNodeNetworkHandler : public QObject { Q_OBJECT +private: + QString m_CurrentNetwork; + public: explicit DapChainNodeNetworkHandler(QObject *parent = nullptr); @@ -23,6 +26,9 @@ public slots: /// Get new node network /// @return data of node network QVariant getNodeNetwork() const; + /// Set current network + /// @param name of network + void setCurrentNetwork(const QString& aNetwork); }; #endif // DAPCHAINNODENETWORKHANDLER_H diff --git a/CellFrameDashboardService/DapChainWalletHandler.cpp b/CellFrameDashboardService/DapChainWalletHandler.cpp index 32361ca17e9c51eef8cdc4d96e7527ca0b04ee9e..4da008ac980a5c0b0b36a7d7f7c5ae45b89b76c1 100755 --- a/CellFrameDashboardService/DapChainWalletHandler.cpp +++ b/CellFrameDashboardService/DapChainWalletHandler.cpp @@ -94,22 +94,29 @@ QString DapChainWalletHandler::sendToken(const QString &asSendWallet, const QStr QString answer; qInfo() << QString("sendTokenTest(%1, %2, %3, %4)").arg(asSendWallet).arg(asAddressReceiver).arg(asToken).arg(aAmount); QProcess processCreate; - processCreate.start(QString("%1 tx_create -net cellframe-testnet -chain gdb -from_wallet %2 -to_addr %3 -token %4 -value %5") + processCreate.start(QString("%1 tx_create -net %2 -chain gdb -from_wallet %3 -to_addr %4 -token %5 -value %6") .arg(CLI_PATH) + .arg(m_CurrentNetwork) .arg(asSendWallet) .arg(asAddressReceiver) .arg(asToken) - .arg(aAmount)); + .arg(aAmount) ); processCreate.waitForFinished(-1); QString resultCreate = QString::fromLatin1(processCreate.readAll()); qDebug() << resultCreate; if(!(resultCreate.isEmpty() || resultCreate.isNull())) { QProcess processMempool; - processMempool.start(QString("%1 mempool_proc -net kelvin-testnet -chain gdb").arg(CLI_PATH)); + processMempool.start(QString("%1 mempool_proc -net " + m_CurrentNetwork +" -chain gdb").arg(CLI_PATH)); processMempool.waitForFinished(-1); answer = QString::fromLatin1(processMempool.readAll()); qDebug() << answer; } return answer; } + +void DapChainWalletHandler::setCurrentNetwork(const QString& aNetwork) +{ + if(m_CurrentNetwork != aNetwork) return; + m_CurrentNetwork = aNetwork; +} diff --git a/CellFrameDashboardService/DapChainWalletHandler.h b/CellFrameDashboardService/DapChainWalletHandler.h index 9f0bd5aa057aa873149d604274147161a65c10c2..3f8f4a5df1a17c0f5fe06d5e30c2a5ba8214479d 100755 --- a/CellFrameDashboardService/DapChainWalletHandler.h +++ b/CellFrameDashboardService/DapChainWalletHandler.h @@ -10,6 +10,9 @@ class DapChainWalletHandler : public QObject { Q_OBJECT +private: + QString m_CurrentNetwork; + protected: virtual QString parse(const QByteArray& aWalletAddress); @@ -19,11 +22,31 @@ public: signals: public slots: + /// Create new wallet + /// @param name of wallet + /// @return result QStringList createWallet(const QString& asNameWallet); + /// Remove wallet + /// @param name of wallet void removeWallet(const QString& asNameWallet); + /// Get list of wallets + /// @return QMap of available wallets, where the key is name of wallet + /// and the value is number of wallet QMap<QString, QVariant> getWallets(); + /// Get details about wallet + /// @param name of wallet + /// @return list with balances and tokens QStringList getWalletInfo(const QString& asNameWallet); + /// Create new token + /// @param name of wallet where is needed to send + /// @param andress of wallet which will receive + /// @param token name + /// @param sum for sending + /// @return result QString sendToken(const QString &asSendWallet, const QString& asAddressReceiver, const QString& asToken, const QString& aAmount); + /// Set current network + /// @param name of network + void setCurrentNetwork(const QString& aNetwork); }; #endif // DAPCHAINWALLETHANDLER_H