diff --git a/CellFrameDashboard.pro b/CellFrameDashboard.pro index 3b7a918fd91885072b3717e11915558c15ea6f75..14df6c1fe475dab4f0977db5ac850d7320b55bc3 100755 --- a/CellFrameDashboard.pro +++ b/CellFrameDashboard.pro @@ -15,8 +15,3 @@ unix: !mac : !android { share_target.path = /opt/cellframe-dashboard/share/ INSTALLS += share_target } - -BUILD_DASHBOARD_TESTS { - message(BUILD_DASHBOARD_TESTS enabled) - SUBDIRS += CellFrameDashboardTests -} diff --git a/CellFrameDashboardGUI/CellFrameDashboardGUI.pro b/CellFrameDashboardGUI/CellFrameDashboardGUI.pro index a9e5b0301c0c18756e46c439522960f8a4b6e8e2..4b492e3030f23eee69e14104ab38c1e20579bf9a 100755 --- a/CellFrameDashboardGUI/CellFrameDashboardGUI.pro +++ b/CellFrameDashboardGUI/CellFrameDashboardGUI.pro @@ -63,18 +63,7 @@ INCLUDEPATH += $$_PRO_FILE_PWD_/../libCellFrameDashboardCommon/ \ OTHER_FILES += libdap-qt-ui-qml SOURCES += \ - $$PWD/DapChainNodeNetworkExplorer.cpp \ - $$PWD/DapChainNodeNetworkModel.cpp \ - $$PWD/DapChainWalletModel.cpp \ - $$PWD/DapClipboard.cpp \ - $$PWD/DapConsoleModel.cpp \ - $$PWD/DapScreenHistoryFilterModel.cpp \ - $$PWD/DapScreenHistoryModel.cpp \ - $$PWD/DapSettingsNetworkModel.cpp \ - $$PWD/DapWalletFilterModel.cpp \ $$PWD/main.cpp \ - $$PWD/DapScreenDialog.cpp \ - $$PWD/DapScreenDialogChangeWidget.cpp \ $$PWD/DapServiceClient.cpp \ $$PWD/DapServiceController.cpp \ $$PWD/DapCommandController.cpp \ @@ -82,7 +71,6 @@ SOURCES += \ $$PWD/DapServiceClientNativeLinux.cpp \ $$PWD/DapServiceClientNativeWin.cpp \ $$PWD/DapServiceClientNativeMacOS.cpp \ - $$PWD/DapChainWalletsModel.cpp RESOURCES += $$PWD/qml.qrc @@ -92,24 +80,12 @@ else: unix:!android: target.path = /opt/cellframe-dashboard/bin !isEmpty(target.path): INSTALLS += target HEADERS += \ - $$PWD/DapChainNodeNetworkExplorer.h \ - $$PWD/DapChainNodeNetworkModel.h \ - $$PWD/DapChainWalletModel.h \ - $$PWD/DapClipboard.h \ - $$PWD/DapConsoleModel.h \ - $$PWD/DapScreenHistoryFilterModel.h \ - $$PWD/DapScreenHistoryModel.h \ - $$PWD/DapSettingsNetworkModel.h \ - $$PWD/DapScreenDialog.h \ - $$PWD/DapScreenDialogChangeWidget.h \ $$PWD/DapServiceClient.h \ $$PWD/DapServiceController.h \ $$PWD/DapCommandController.h \ $$PWD/DapServiceClientNativeAbstract.h \ $$PWD/DapServiceClientNativeLinux.h \ $$PWD/DapServiceClientNativeWin.h \ - $$PWD/DapChainWalletsModel.h \ - $$PWD/DapWalletFilterModel.h include (../libdap/libdap.pri) include (../libdap-crypto/libdap-crypto.pri) diff --git a/CellFrameDashboardGUI/DapChainNodeNetworkExplorer.cpp b/CellFrameDashboardGUI/DapChainNodeNetworkExplorer.cpp deleted file mode 100644 index 53a988b055634675f1a6529f4dcfc9051ef27507..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapChainNodeNetworkExplorer.cpp +++ /dev/null @@ -1,325 +0,0 @@ -#include "DapChainNodeNetworkExplorer.h" - -#define DEFAULT_NODE_COLOR_HOVER QColor("#FF0000") -#define DEFAULT_NODE_COLOR QColor("#000000") -#define DEFAULT_NODE_COLOR_OFFLINE QColor("#FF0000") -#define DEFAULT_NODE_COLOR_ONLINE QColor("#00FF00") -#define DEFAULT_NODE_COLOR_SELECTED QColor("#0000FF") -#define DEFAULT_NODE_SIZE 50 -#define DEFAULT_WIDTH_LINE 3 - -DapChainNodeNetworkExplorer::DapChainNodeNetworkExplorer(QQuickItem *parent) : - QQuickPaintedItem(parent), - m_model(nullptr), - m_colorOnline(DEFAULT_NODE_COLOR_ONLINE), - m_colorOffline(DEFAULT_NODE_COLOR_OFFLINE), - m_colorSelect(DEFAULT_NODE_COLOR_SELECTED), - m_colorNormal(DEFAULT_NODE_COLOR), - m_colorFocused(DEFAULT_NODE_COLOR_HOVER), - m_widthLine(DEFAULT_WIDTH_LINE), - m_sizeNode(DEFAULT_NODE_SIZE) -{ - setAcceptedMouseButtons(Qt::RightButton); - setAcceptHoverEvents(true); -} - -void DapChainNodeNetworkExplorer::mousePressEvent(QMouseEvent* event) -{ - QQuickPaintedItem::mousePressEvent(event); - - emit selectNodeChanged(); - - if(m_currentSelectedNode.second != nullptr) - { - m_currentSelectedNode.second->State = Normal; - m_currentSelectedNode.second = nullptr; - } - - for(auto node = m_nodeMap.begin(); node != m_nodeMap.end(); node++) - { - if(node.value().State == DapNodeState::Focused) - { - DapNodeGui* nodeData = &node.value(); - nodeData->State = DapNodeState::Selected; - m_currentSelectedNode = QPair<QString, DapNodeGui*>(node.key(), nodeData); - - const DapNodeData* currentData = m_model->getNodeData(node.key()); - emit selectNode(currentData->isCurrentNode); - update(); - return; - } - } -} - -void DapChainNodeNetworkExplorer::wheelEvent(QWheelEvent* event) -{ - if(event->delta() > 1) - { - if(scale() < 1.8) setScale(scale() + 0.1); - } - else - { - if(scale() > 0.5) setScale(scale() - 0.1); - } -} - -void DapChainNodeNetworkExplorer::hoverMoveEvent(QHoverEvent* event) -{ - QQuickPaintedItem::hoverMoveEvent(event); - - for(auto node = m_nodeMap.begin(); node != m_nodeMap.end(); node++) - { - DapNodeGui* nodeDataGui = &node.value(); - if(nodeDataGui->Rect.contains(event->pos()) && nodeDataGui->State != Selected) - { - nodeDataGui->State = DapNodeState::Focused; - break; - } - else if(nodeDataGui->State == DapNodeState::Focused) - { - nodeDataGui->State = DapNodeState::Normal; - break; - } - } - - update(); -} - -void DapChainNodeNetworkExplorer::paint(QPainter* painter) -{ - if(m_model == nullptr) return; - QString focusedNode = QString(); - QPen penNormal(QBrush(m_colorNormal), m_widthLine); - QPen penOnline(QBrush(m_colorOnline), m_widthLine); - QPen penOffline(QBrush(m_colorOffline), m_widthLine); - QPen penFocused(QBrush(m_colorFocused), m_widthLine); - QPen penSelected(QBrush(m_colorSelect), m_widthLine); - - painter->setBrush(QBrush("#FFFFFF")); - for(auto node = m_nodeMap.constBegin(); node != m_nodeMap.constEnd(); node++) - { - const DapNodeGui* nodeDataGui = &node.value(); - const DapNodeData* nodeData = m_model->getNodeData(node.key()); - if(nodeData == nullptr) continue; - for(int i = 0; i < nodeData->Link.count(); i++) - { - painter->setPen(penNormal); - if(nodeData->isCurrentNode) - { - if(nodeData->Status) painter->setPen(penOnline); - else painter->setPen(penOffline); - } - - painter->drawLine(nodeDataGui->Rect.center(), m_nodeMap[nodeData->Link.at(i)].Rect.center()); - } - - if(nodeDataGui->State == Focused) - { - painter->setPen(penFocused); - focusedNode = node.key(); - } - else if(nodeDataGui->State == Selected) painter->setPen(penSelected); - else painter->setPen(penNormal); - - painter->drawEllipse(nodeDataGui->Rect); - } - - if(!focusedNode.isEmpty()) - { - QPen penWhite(QBrush("#FFFFFF"), m_widthLine); - QRect rect(m_nodeMap[focusedNode].Rect.center(), QSize(200, 15)); - const DapNodeData* nodeData = m_model->getNodeData(focusedNode); - - painter->setPen(penWhite); - painter->drawRect(rect); - painter->setPen(penNormal); - painter->drawText(rect, nodeData->Alias); - } -} - -QColor DapChainNodeNetworkExplorer::getColorNormal() const -{ - return m_colorNormal; -} - -QColor DapChainNodeNetworkExplorer::getColorFocused() const -{ - return m_colorFocused; -} - -int DapChainNodeNetworkExplorer::getWidthLine() const -{ - return m_widthLine; -} - -int DapChainNodeNetworkExplorer::getSizeNode() const -{ - return m_sizeNode; -} - -DapChainNodeNetworkModel* DapChainNodeNetworkExplorer::getModel() const -{ - return m_model; -} - -int DapChainNodeNetworkExplorer::getSelectedNodePosX() const -{ - if(m_currentSelectedNode.second != nullptr) - return m_currentSelectedNode.second->Rect.center().x(); - return -1; -} - -int DapChainNodeNetworkExplorer::getSelectedNodePosY() const -{ - if(m_currentSelectedNode.second != nullptr) - return m_currentSelectedNode.second->Rect.center().y(); - return -1; -} - -QString DapChainNodeNetworkExplorer::getSelectedNodeAddress() const -{ - if(m_currentSelectedNode.second != nullptr) - return m_currentSelectedNode.first; - return QString(); -} - -QString DapChainNodeNetworkExplorer::getSelectedNodeAlias() const -{ - if(m_currentSelectedNode.second != nullptr) - { - const DapNodeData* nodeData = m_model->getNodeData(m_currentSelectedNode.first); - if(nodeData != nullptr) - return nodeData->Alias; - } - - return QString(); -} - -QString DapChainNodeNetworkExplorer::getSelectedNodeIpv4() const -{ - if(m_currentSelectedNode.second != nullptr) - { - const DapNodeData* nodeData = m_model->getNodeData(m_currentSelectedNode.first); - if(nodeData != nullptr) - return nodeData->Ipv4; - } - - return QString(); -} - -QColor DapChainNodeNetworkExplorer::getColorOnline() const -{ - return m_colorOnline; -} - -QColor DapChainNodeNetworkExplorer::getColorOffline() const -{ - return m_colorOffline; -} - -QColor DapChainNodeNetworkExplorer::getColorSelect() const -{ - return m_colorSelect; -} - -void DapChainNodeNetworkExplorer::setColorNormal(const QColor& aColorNormal) -{ - if (m_colorNormal == aColorNormal) - return; - - m_colorNormal = aColorNormal; - emit colorNormalChanged(m_colorNormal); -} - -void DapChainNodeNetworkExplorer::setColorFocused(const QColor& aColorActivated) -{ - if (m_colorFocused == aColorActivated) return; - m_colorFocused = aColorActivated; - emit colorFocusedChanged(m_colorFocused); -} - -void DapChainNodeNetworkExplorer::setWidthLine(const int widthLine) -{ - if (m_widthLine == widthLine) return; - m_widthLine = widthLine; - emit widthLineChanged(m_widthLine); -} - -void DapChainNodeNetworkExplorer::setSizeNode(const int sizeNode) -{ - if (m_sizeNode == sizeNode) return; - m_sizeNode = sizeNode; - emit sizeNodeChanged(m_sizeNode); -} - -void DapChainNodeNetworkExplorer::setModel(DapChainNodeNetworkModel* aModel) -{ - if (m_model == aModel) return; - m_model = aModel; - QObject::connect(m_model, SIGNAL(changeNodeNetwork()), this, SLOT(proccessCreateGraph())); - QObject::connect(m_model, SIGNAL(changeStatusNode(QString, bool)), this, SLOT(update())); - proccessCreateGraph(); - emit modelChanged(m_model); -} - -QString DapChainNodeNetworkExplorer::getAddressByPos(const int aX, const int aY) -{ - for(auto node = m_nodeMap.constBegin(); node != m_nodeMap.constEnd(); node++) - { - if(node->Rect.contains(aX, aY)) - return node.key(); - } - - return QString(); -} - -void DapChainNodeNetworkExplorer::setColorOnline(const QColor& aColorOnline) -{ - if (m_colorOnline == aColorOnline) - return; - - m_colorOnline = aColorOnline; - emit colorOnlineChanged(m_colorOnline); -} - -void DapChainNodeNetworkExplorer::setColorOffline(const QColor& aColorOffline) -{ - if (m_colorOffline == aColorOffline) - return; - - m_colorOffline = aColorOffline; - emit colorOfflineChanged(m_colorOffline); -} - -void DapChainNodeNetworkExplorer::setColorSelect(const QColor& aColorSelect) -{ - if (m_colorSelect == aColorSelect) - return; - - m_colorSelect = aColorSelect; - emit colorSelectChanged(m_colorSelect); -} - -void DapChainNodeNetworkExplorer::proccessCreateGraph() -{ - if(m_model == nullptr) return; - - const DapNodeMap* const nodeMap = m_model->getDataMap(); - int pointX = m_sizeNode; - int heightConten = nodeMap->count() * m_sizeNode; - - qsrand(150); - for (auto node = nodeMap->constBegin(); node != nodeMap->constEnd(); node++) - { - DapNodeGui nodeData; - - int posY = (qrand() % ((heightConten + 1) - m_sizeNode) + m_sizeNode); - nodeData.Rect = QRect(pointX, posY, m_sizeNode, m_sizeNode); - pointX += m_sizeNode * 2; - - m_nodeMap[node.key()] = nodeData; - } - - setSize(QSize(pointX + m_sizeNode * 2, heightConten + m_sizeNode * 2)); - update(); -} diff --git a/CellFrameDashboardGUI/DapChainNodeNetworkExplorer.h b/CellFrameDashboardGUI/DapChainNodeNetworkExplorer.h deleted file mode 100644 index 6e90980240c60664441121919e8d92cb6c5cbab5..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapChainNodeNetworkExplorer.h +++ /dev/null @@ -1,204 +0,0 @@ -#ifndef DAPCHAINNODENETWORKEXPLORER_H -#define DAPCHAINNODENETWORKEXPLORER_H - -#include <QQuickPaintedItem> -#include <QPainter> -#include <QVariant> -#include <QToolTip> - -#include "DapChainNodeNetworkModel.h" -#include "DapNodeType.h" - -/// The DapChainNodeNetworkExplorer class -/// details Class painting DapCellFrame map -/// @warning To use this class it requers to send DapChainNodeNetworkModel model to slot setModel() -class DapChainNodeNetworkExplorer : public QQuickPaintedItem -{ - Q_OBJECT - Q_PROPERTY(QColor colorSelect READ getColorSelect WRITE setColorSelect NOTIFY colorSelectChanged) - Q_PROPERTY(QColor colorNormal READ getColorNormal WRITE setColorNormal NOTIFY colorNormalChanged) - Q_PROPERTY(QColor colorFocused READ getColorFocused WRITE setColorFocused NOTIFY colorFocusedChanged) - Q_PROPERTY(QColor colorOnline READ getColorOnline WRITE setColorOnline NOTIFY colorOnlineChanged) - Q_PROPERTY(QColor colorOffline READ getColorOffline WRITE setColorOffline NOTIFY colorOfflineChanged) - Q_PROPERTY(int widthLine READ getWidthLine WRITE setWidthLine NOTIFY widthLineChanged) - Q_PROPERTY(int sizeNode READ getSizeNode WRITE setSizeNode NOTIFY sizeNodeChanged) - Q_PROPERTY(DapChainNodeNetworkModel* model READ getModel WRITE setModel NOTIFY modelChanged) - -public: - /** - * @brief The DapNodeState enum - * The values are used to display state of nodes - */ - enum DapNodeState { - /// Normal - Normal, - /// Focused - Focused, - /// Selected - Selected - }; - - /** - * @brief The DapNodeGui struct - * Structure which has state of node and size of area node - */ - struct DapNodeGui { - /// State of node - DapNodeState State; - /// Graphic area node - QRect Rect; - }; - -private: - /// Model for Network Explorer - DapChainNodeNetworkModel* m_model; - /// node map for gui - QMap<QString /*Address*/, DapNodeGui /*NodeDataGui*/> m_nodeMap; - /// selected node - QPair<QString /*Address*/, DapNodeGui* /*NodeDataGui*/> m_currentSelectedNode; - - /// Color online state - QColor m_colorOnline; - /// Color offline state - QColor m_colorOffline; - /// Color selected state - QColor m_colorSelect; - /// Color normal state - QColor m_colorNormal; - /// Color focused state - QColor m_colorFocused; - /// Width of line - int m_widthLine; - /// Size of node - int m_sizeNode; - -protected: - /// Event occurs when moused pressed - /// @param event Mouse event - void mousePressEvent(QMouseEvent* event); - /// Event occurs when wheel moves - /// @param event Wheel event - void wheelEvent(QWheelEvent* event); - /// Event occurs when mouse hover under item - /// @param event Hover move - void hoverMoveEvent(QHoverEvent* event); - -public: - /// Standard constructor - explicit DapChainNodeNetworkExplorer(QQuickItem *parent = nullptr); - /// Overload method for paiting - void paint(QPainter* painter); - - /// Get color for online nodes - /// @return color of online nodes - QColor getColorOnline() const; - /// Get color for offline nodes - /// @return color of offline nodes - QColor getColorOffline() const; - /// Get color for selected node - /// @return color of seletected node - QColor getColorSelect() const; - /// Get color for normal state for node - /// @return color of normal state - QColor getColorNormal() const; - /// Get color for focused node - /// @return color of focused node - QColor getColorFocused() const; - /// Get line width for borders - /// @return width of line - int getWidthLine() const; - /// Get lenght of square's side - /// @return diameter of node element - int getSizeNode() const; - - /// Get model - /// @return model for network explorer - DapChainNodeNetworkModel* getModel() const; - - /// Get X position for selected node - /// @return X position of selected node - Q_INVOKABLE int getSelectedNodePosX() const; - /// Get Y position for selected node - /// @return Y position of selected node - Q_INVOKABLE int getSelectedNodePosY() const; - /// Get address for selected node - /// @return address of selected node - Q_INVOKABLE QString getSelectedNodeAddress() const; - /// Get alias for selected node - /// @return alias of selected node - Q_INVOKABLE QString getSelectedNodeAlias() const; - /// Get Ipv4 address for selected node - /// @return Ipv4 address of selected node - Q_INVOKABLE QString getSelectedNodeIpv4() const; - /// Find node address by coordinate - /// @param X position - /// @param Y position - /// @return address of node - Q_INVOKABLE QString getAddressByPos(const int aX, const int aY); - -public slots: - /// Set color for selected node - /// @param color for selected node - void setColorSelect(const QColor& aColorSelect); - /// Set color for normal state for node - /// @param color for normal state of node - void setColorNormal(const QColor& aColorNormal); - /// Set color for focused node - /// @param color for focused node - void setColorFocused(const QColor& aColorActivated); - /// Set color for online nodes - /// @param color for online nodes - void setColorOnline(const QColor& aColorOnline); - /// Set color for offline nodes - /// @param color offline nodes - void setColorOffline(const QColor& aColorOffline); - /// Set line width for borders - /// @param width of line - void setWidthLine(const int widthLine); - /// Set lenght of square's side - /// @param diameter of node element - void setSizeNode(const int sizeNode); - - /// Set model - /// @param model for explorer - void setModel(DapChainNodeNetworkModel* aModel); - -private slots: - /// Create graph - void proccessCreateGraph(); - -signals: - /// Signals emitted when select color was changed - /// @param colorSelect Color for select state - void colorSelectChanged(QColor colorSelect); - /// Signals emitted when normal state color was changed - /// @param colorNormal Color for normal state - void colorNormalChanged(QColor colorNormal); - /// Signals emitted when focused state color was changed - /// @param colorActivated Color for focused state - void colorFocusedChanged(QColor colorActivated); - /// Signals emitted when online state color was changed - /// @param colorOnline Color for online state - void colorOnlineChanged(QColor colorOnline); - /// Signals emitted when offline state color was changed - /// @param colorOffline Color for offline state - void colorOfflineChanged(QColor colorOffline); - /// Signals emitted when width line was changed - /// @param widthLine Width of line - void widthLineChanged(int widthLine); - /// Signals emitted when size node was changed - /// @param sizeNode Size of node - void sizeNodeChanged(int sizeNode); - /// Signals emitted when model was changed - /// @param model New model for Network Explorer - void modelChanged(DapChainNodeNetworkModel* model); - - /// Signal selected node - /// @param status current selected node. It is true - /// if current node was selected - void selectNode(bool isCurrentNode); - /// Signal skip selected node to normal state - void selectNodeChanged(); -}; - -#endif // DAPCHAINNODENETWORKEXPLORER_H diff --git a/CellFrameDashboardGUI/DapChainNodeNetworkModel.cpp b/CellFrameDashboardGUI/DapChainNodeNetworkModel.cpp deleted file mode 100644 index 7dfd5a7156781b31e5a75e0e5658a36a64c0c376..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapChainNodeNetworkModel.cpp +++ /dev/null @@ -1,141 +0,0 @@ -#include "DapChainNodeNetworkModel.h" -#include <QDataStream> -#include <QDebug> - -#define DEFAULT_TIMER_MS 1000 - -DapChainNodeNetworkModel::DapChainNodeNetworkModel(QObject *parent) : QObject(parent) -{ - m_timerRequest = new QTimer(this); - QObject::connect(m_timerRequest, SIGNAL(timeout()), this, SIGNAL(requestNodeNetwork())); - m_timerRequest->start(DEFAULT_TIMER_MS); -} - -DapChainNodeNetworkModel& DapChainNodeNetworkModel::getInstance() -{ - static DapChainNodeNetworkModel instance; - return instance; -} - -const DapNodeMap* DapChainNodeNetworkModel::getDataMap() const -{ - return &m_nodeMap; -} - -const DapNodeData* DapChainNodeNetworkModel::getNodeData(const QString& aAddress) const -{ - const DapNodeData* nodeData = nullptr; - if(m_nodeMap.contains(aAddress)) - nodeData = const_cast<const DapNodeData*>(&m_nodeMap.find(aAddress).value()); - - return nodeData; -} - -QString DapChainNodeNetworkModel::getCurrentAddress() const -{ - for (auto node = m_nodeMap.constBegin(); node != m_nodeMap.constBegin(); node++) { - if(node.value().isCurrentNode) return node.key(); - } - - return QString(); -} - -bool DapChainNodeNetworkModel::isNodeOnline(const QString& aAddress) const -{ - if(m_nodeMap.contains(aAddress)) - return m_nodeMap[aAddress].Status; - - return false; -} - -void DapChainNodeNetworkModel::sendRequestNodeStatus(const bool aIsOnline) -{ - QString address = getCurrentAddress(); - qDebug() << "New STatus" << address << aIsOnline; - if(m_nodeMap[address].Status != aIsOnline) - emit requestNodeStatus(aIsOnline); -} - -void DapChainNodeNetworkModel::startRequest() -{ - if(m_timerRequest->isActive()) m_timerRequest->stop(); - m_timerRequest->start(); -} - -void DapChainNodeNetworkModel::startRequest(const int aTimeout) -{ - if(m_timerRequest->isActive()) m_timerRequest->stop(); - m_timerRequest->start(aTimeout); -} - -void DapChainNodeNetworkModel::stopRequest() -{ - m_timerRequest->stop(); -} - -void DapChainNodeNetworkModel::receiveNewNetwork(const QVariant& aData) -{ - if (m_data == aData) return; - m_data = aData; - m_nodeMap.clear(); - - QMap<QString, QVariant> dataMap = m_data.toMap(); - - QList<QString> addressList = dataMap.keys(); - QString currentNode; - bool currentNodeStatus = false; - foreach(auto address, addressList) - { - if(address == "current") - { - QStringList args = dataMap["current"].toStringList(); - currentNode = args.at(0); - currentNodeStatus = (args.at(1) == "NET_STATE_OFFLINE" ? false : true); - - continue; - } - m_nodeMap[address] = DapNodeData(); - } - - if(m_nodeMap.contains(currentNode)) - { - m_nodeMap[currentNode].Status = currentNodeStatus; - m_nodeMap[currentNode].isCurrentNode = true; - } - - for(auto node = m_nodeMap.begin(); node != m_nodeMap.end(); node++) - { - DapNodeData* nodeData = &node.value(); - QStringList nodeDataList = dataMap[node.key()].toStringList(); - nodeData->Cell = nodeDataList.at(0).toUInt(); - nodeData->Ipv4 = nodeDataList.at(1); - nodeData->Alias = nodeDataList.at(2); - - if(nodeDataList.at(3).toUInt() > 0) - { - for(int i = 4; i < nodeDataList.count(); i++) - nodeData->Link.append(nodeDataList.at(i)); - } - } - - emit changeNodeNetwork(); -} - -void DapChainNodeNetworkModel::receiveNodeStatus(const QVariant& aData) -{ - QByteArray data = aData.toByteArray(); - QDataStream out(&data, QIODevice::ReadOnly); - - QString address; - bool status; - - out >> address >> status; - - if(m_nodeMap.contains(address)) - { - DapNodeData* nodeData = &m_nodeMap[address]; - nodeData->Status = status; - nodeData->isCurrentNode = true; - emit changeStatusNode(address, status); - } -} diff --git a/CellFrameDashboardGUI/DapChainNodeNetworkModel.h b/CellFrameDashboardGUI/DapChainNodeNetworkModel.h deleted file mode 100644 index 236041ce00d6b9b862f1f25705004538743f464d..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapChainNodeNetworkModel.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef DAPCHAINNODENETWORKMODEL_H -#define DAPCHAINNODENETWORKMODEL_H - -#include <QObject> -#include <QTimer> -#include <QHostAddress> -#include <QVariant> - -#include "DapNodeType.h" - -/// Class model for Network Explorer -class DapChainNodeNetworkModel : public QObject -{ - Q_OBJECT - -private: - /// Data about network with nodes - QVariant m_data; - /// Timer for request - QTimer* m_timerRequest; - -protected: - /// Data about whole network with nodes - DapNodeMap m_nodeMap; - -public: - /// Standard constructor - explicit DapChainNodeNetworkModel(QObject *parent = nullptr); - - /// Get an instance of a class. - /// @return Instance of a class. - Q_INVOKABLE static DapChainNodeNetworkModel &getInstance(); - /// Get data about whole network with nodes - /// @return QMap where key is address and value is structure about one node - const DapNodeMap* getDataMap() const; - /// Get data about node by address - /// @param aAddress Address of node - /// @return data's node structure - const DapNodeData* getNodeData(const QString& aAddress) const; - - /// Get current address of node - /// @return address of current node - QString getCurrentAddress() const; - /// Get status of node - /// @param aAddress Address of node - /// @return It is true if node is online - Q_INVOKABLE bool isNodeOnline(const QString& aAddress) const; - -public slots: - /// Receive new network data and repaint the screen - /// @param aData data of node network - void receiveNewNetwork(const QVariant& aData); - /// Receive changes status for nodes - /// @param aData data of node network - void receiveNodeStatus(const QVariant& aData); - /// Send request to service about changing status of node - /// @param aIsOnline set new status to node - Q_INVOKABLE void sendRequestNodeStatus(const bool aIsOnline); - /// Start timer for request new data of network - Q_INVOKABLE void startRequest(); - /// @param aTimeout in milliseconds for delay - Q_INVOKABLE void startRequest(const int aTimeout); - /// Stop timer for request data of network - Q_INVOKABLE void stopRequest(); - -signals: - /// Signal for changing network - void changeNodeNetwork(); - /// Signal for request network - void requestNodeNetwork(); - /// Signal for request status of node - /// @param status status of node - void requestNodeStatus(bool status); - /// SIgnal about changing status node - /// @param node Address of node - /// @param aIsOnline new status to node - void changeStatusNode(QString asNode, bool aIsOnline); -}; - - -#endif // DAPCHAINNODENETWORKMODEL_H diff --git a/CellFrameDashboardGUI/DapChainWalletModel.cpp b/CellFrameDashboardGUI/DapChainWalletModel.cpp deleted file mode 100644 index 1a5d6fd2ed5028a8fc5d81d9cb1603c53fb58403..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapChainWalletModel.cpp +++ /dev/null @@ -1,188 +0,0 @@ -#include "DapChainWalletModel.h" - -DapChainWalletModel::DapChainWalletModel(QObject *parent) - : QAbstractListModel(parent) -{ - -} - -DapChainWalletModel& DapChainWalletModel::instance() -{ - static DapChainWalletModel instance; - return instance; -} - -int DapChainWalletModel::rowCount(const QModelIndex &parent) const -{ - // For list models only the root node (an invalid parent) should return the list's size. For all - // other (valid) parents, rowCount() should return 0 so that it does not become a tree model. - if (parent.isValid()) return 0; - return m_walletList.count(); -} - -QVariant DapChainWalletModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) return QVariant(); - switch (role) { - case WalletListDisplayRole: return walletList(); - case WalletNameDisplayRole: return m_walletList[index.row()].first.Name; - case WalletAddressDisplayRole: return m_walletList[index.row()].first.Address; - case WalletIconDisplayRole: return m_walletList[index.row()].first.IconPath; - case NetworkDisplayRole: return m_walletList[index.row()].first.Network; - case WalletTokenListDisplayRole: - return QVariant::fromValue<QList<QObject*>>(tokeListByIndex(index.row())); - default: break; - } - - return QVariant(); -} - -QHash<int, QByteArray> DapChainWalletModel::roleNames() const -{ - QHash<int, QByteArray> roles; - roles[WalletNameDisplayRole] = "walletNameDisplayRole"; - roles[WalletAddressDisplayRole] = "walletAddressDisplayRole"; - roles[WalletIconDisplayRole] = "walletIconDisplayRole"; - roles[WalletTokenListDisplayRole] = "walletTokenListDisplayRole"; - roles[NetworkDisplayRole] = "networkDisplayRole"; - roles[WalletListDisplayRole] = "walletListDisplayRole"; - return roles; -} - -QStringList DapChainWalletModel::walletList() const -{ - return m_wallets; -} - -double DapChainWalletModel::walletBalance(const QString& aName) const -{ - double balance = 0.0; - - for(int i = 0; i < m_walletList.count(); i++) - { - if(m_walletList[i].first.Name == aName || aName == TITLE_ALL_WALLETS) - { - DapChainWalletTokenItemList tokenList = m_walletList[i].second; - for(int m = 0; m < tokenList.count(); m++) - { - balance += tokenList[m]->balance(); - } - } - } - - return balance; -} - -double DapChainWalletModel::walletBalance(const int aWalletIndex) const -{ - QString address = m_walletList[aWalletIndex].first.Address; - return walletBalance(address); -} - -QList<QObject*> DapChainWalletModel::tokeListByWallet(const QString& aWalletAddress, const QString& aNetwork) const -{ - QList<QObject*> tokenList; - for(int i = 0; i < m_walletList.count(); i++) - { - if(m_walletList[i].first.Address == aWalletAddress) - { - if(aNetwork.isEmpty() || aNetwork == m_walletList[i].first.Network) - { - DapChainWalletTokenItemList mTokenList = m_walletList[i].second; - for(int m = 0; m < mTokenList.count(); m++) - { - tokenList.append(mTokenList[m]); - } - - return tokenList; - } - - } - } - - return tokenList; -} - -QList<QObject*> DapChainWalletModel::tokeListByIndex(const int aIndex) const -{ - QList<QObject*> tokenList; - DapChainWalletTokenItemList tokenDataList = m_walletList[aIndex].second; - for(int i = 0; i < tokenDataList.count(); i++) - tokenList.append(tokenDataList[i]); - - return tokenList; -} - -void DapChainWalletModel::setWalletData(const QByteArray& aData) -{ - beginResetModel(); - m_walletList.clear(); - m_wallets.clear(); - m_wallets << TITLE_ALL_WALLETS; - QList<QPair<DapChainWalletData, QList<DapChainWalletTokenData>>> walletData; - QDataStream in(aData); - in >> walletData; - - for(int i = 0; i < walletData.count(); i++) - { - DapChainWalletPair walletPair(walletData[i].first, DapChainWalletTokenItemList()); - QList<DapChainWalletTokenData> tokeData = walletData[i].second; - if(!m_wallets.contains(walletData[i].first.Name)) - m_wallets.append(walletData[i].first.Name); - - for(int m = 0; m < tokeData.count(); m++) - { - walletPair.second.append(new DapChainWalletTokenItem(walletData[i].first.Address, tokeData[m], this)); - } - - m_walletList.append(walletPair); - } - - emit walletListChanged(m_wallets); - endResetModel(); -} - -void DapChainWalletModel::appendWallet(const DapChainWalletData& aWallet) -{ - m_walletList.append(DapChainWalletPair(aWallet, DapChainWalletTokenItemList())); - int lastIndex = m_walletList.count() - 1; - beginInsertRows(QModelIndex(), lastIndex, lastIndex); - endInsertRows(); -} - -void DapChainWalletModel::appendToken(const QString& aWalletAddress, const DapChainWalletTokenData& aTokenData) -{ - for(int i = 0; i < m_walletList.count(); i++) - { - if(m_walletList[i].first.Address == aWalletAddress) - { - m_walletList[i].second.append(new DapChainWalletTokenItem(aWalletAddress, aTokenData, this)); - } - } -} - -void DapChainWalletModel::removeWallet(const QString& aWalletAddress) -{ - int removeIndex = -1; - for(int i = 0; i < m_walletList.count(); i++) - { - if(m_walletList[i].first.Address == aWalletAddress) - { - m_walletList.removeAt(i); - removeIndex = i; - break; - } - } - - if(removeIndex == -1) return; - beginRemoveRows(QModelIndex(), removeIndex, removeIndex); - endRemoveRows(); -} - -void DapChainWalletModel::removeWallet(const int aWalletIndex) -{ - if(aWalletIndex > m_walletList.count() || m_walletList.count() < aWalletIndex) return; - beginRemoveRows(QModelIndex(), aWalletIndex, aWalletIndex); - m_walletList.removeAt(aWalletIndex); - endRemoveRows(); -} diff --git a/CellFrameDashboardGUI/DapChainWalletModel.h b/CellFrameDashboardGUI/DapChainWalletModel.h deleted file mode 100644 index 3a7c9c7c421507f2abce6511d9f6d51fc7af893c..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapChainWalletModel.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef DAPCHAINWALLETMODEL_H -#define DAPCHAINWALLETMODEL_H - -#include <QAbstractListModel> -#include <QDebug> -#include "DapChainWallet.h" - -#define TITLE_ALL_WALLETS tr("all wallets") - -class DapChainWalletModel : public QAbstractListModel -{ - Q_OBJECT - Q_PROPERTY(QStringList wallets READ walletList NOTIFY walletListChanged) - -public: - enum { - WalletNameDisplayRole = Qt::UserRole, - WalletAddressDisplayRole, - WalletIconDisplayRole, - WalletTokenListDisplayRole, - WalletListDisplayRole, - NetworkDisplayRole, - }; - -private: - QStringList m_wallets; - QList<DapChainWalletPair> m_walletList; - - -public: - explicit DapChainWalletModel(QObject *parent = nullptr); - - static DapChainWalletModel& instance(); - - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - - QHash<int, QByteArray> roleNames() const override; - - Q_INVOKABLE QStringList walletList() const; - - Q_INVOKABLE double walletBalance(const QString& aName) const; - - Q_INVOKABLE double walletBalance(const int aWalletIndex) const; - - Q_INVOKABLE QList<QObject*> tokeListByWallet(const QString& aWalletAddress, const QString& aNetwork = QString()) const; - - QList<QObject*> tokeListByIndex(const int aIndex) const; - -public slots: - - void setWalletData(const QByteArray& aData); - - void appendWallet(const DapChainWalletData& aWallet); - - void appendToken(const QString& aWalletAddress, const DapChainWalletTokenData& aTokenData); - - void removeWallet(const QString& aWalletAddress); - - void removeWallet(const int aWalletIndex); - -signals: - void sigAppendWallet(QString name); - void sigRemoveWallet(QString address); - void walletListChanged(QStringList walletList); -}; - -#endif // DAPCHAINWALLETMODEL_H diff --git a/CellFrameDashboardGUI/DapChainWalletsModel.cpp b/CellFrameDashboardGUI/DapChainWalletsModel.cpp deleted file mode 100644 index 86d4815bf87c97a026390d0487193dac5c7b69f8..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapChainWalletsModel.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include "DapChainWalletsModel.h" - - -DapChainWalletsModel::DapChainWalletsModel(QObject *parent) : QAbstractListModel(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(); - case BalanceWalletRole: return m_dapChainWallets.at(index.row())->getBalance(); - case TokensWalletRole: return m_dapChainWallets.at(index.row())->getTokens(); - case CountWalletRole: return m_dapChainWallets.at(index.row())->getCount(); - default: - return QVariant(); - } - return QVariant(); -} - -QHash<int, QByteArray> DapChainWalletsModel::roleNames() const -{ - static const QHash<int, QByteArray> roles { - { IconWalletRole, "iconPath" }, - { NameWalletRole, "name" }, - { AddressWalletRole, "address" }, - { BalanceWalletRole, "balance" }, - { TokensWalletRole, "tokens" }, - { CountWalletRole, "count" } - }; - - return roles; -} - -QVariantMap DapChainWalletsModel::get(int row) const -{ - if (m_dapChainWallets.count() == 0 || m_dapChainWallets.count() == row) { - return { {"iconPath", ""}, {"name", ""}, {"address", ""}, {"balance", ""}, {"tokens", QStringList()}, {"count", 0} }; - } - const DapChainWallet *wallet = m_dapChainWallets.value(row); - return { {"iconPath", wallet->getIconPath()}, {"name", wallet->getName()}, {"address", wallet->getAddress()}, {"balance", wallet->getBalance()}, {"tokens", wallet->getTokens()}, {"count", wallet->getCount()} }; -} - -void DapChainWalletsModel::append(const DapChainWallet &arWallet) -{ - this->append(arWallet.getIconPath(), arWallet.getName(), arWallet.getAddress(), arWallet.getBalance(), arWallet.getTokens()); -} - -void DapChainWalletsModel::append(const QString& asIconPath, const QString &asName, const QString &asAddress, const QStringList& aBalance, const QStringList& aTokens) -{ - int row = 0; - while (row < m_dapChainWallets.count()) - ++row; - beginInsertRows(QModelIndex(), row, row); - m_dapChainWallets.insert(row, new DapChainWallet(asIconPath, asName, asAddress, aBalance, aTokens)); - endInsertRows(); -} - -void DapChainWalletsModel::set(int row, const QString& asIconPath, const QString &asName, const QString &asAddresss, const QStringList& aBalance, const QStringList& aTokens) -{ - if (row < 0 || row >= m_dapChainWallets.count()) - return; - - DapChainWallet *wallet = m_dapChainWallets.value(row); - wallet->setIconPath(asIconPath); - wallet->setName(asName); - wallet->setAddress(asAddresss); - wallet->setBalance(aBalance); - wallet->setTokens(aTokens); - dataChanged(index(row, 0), index(row, 0), { IconWalletRole, NameWalletRole, AddressWalletRole, BalanceWalletRole, CountWalletRole }); -} - -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() -{ - beginResetModel(); - if(m_dapChainWallets.count() > 0) { - qDeleteAll(m_dapChainWallets); - m_dapChainWallets.clear(); - } - endResetModel(); -} - -QObject *DapChainWalletsModel::singletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine) -{ - Q_UNUSED(engine) - Q_UNUSED(scriptEngine) - - return &getInstance(); -} diff --git a/CellFrameDashboardGUI/DapChainWalletsModel.h b/CellFrameDashboardGUI/DapChainWalletsModel.h deleted file mode 100644 index c622c5a0d78bfd177b897318b940900d15ee0b5f..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapChainWalletsModel.h +++ /dev/null @@ -1,98 +0,0 @@ -#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> -/** - * @brief The DapChainWalletRole enum - * - * These values are used in arguments to methods data and roleNames. - * Main goal is return data from selected information about wallet - */ -enum DapChainWalletRole { - /// Icon wallet - IconWalletRole = Qt::DisplayRole, - /// Name of wallet - NameWalletRole = Qt::UserRole, - /// Address of wallet - AddressWalletRole, - /// Balance - BalanceWalletRole, - /// Tokens name - TokensWalletRole, - /// Number of wallets - CountWalletRole - }; - -/// Class model for wallets screen -class DapChainWalletsModel : public QAbstractListModel -{ - Q_OBJECT - /// Set of wallets - QList<DapChainWallet*> m_dapChainWallets; - - /// standard constructor - DapChainWalletsModel(QObject* parent = nullptr); -public: - /// Get an instance of a class. - /// @return Instance of a class. - Q_INVOKABLE static DapChainWalletsModel &getInstance(); - - /// Overraid model's methods - /// Get number of wallets - /// @return Number of wallets - int rowCount(const QModelIndex & = QModelIndex()) const; - /// Information about selected wallet by index and which field needs - /// @return Information about wallet - /// @param index Index of wallet - /// @param role Concrete fields about wallet - /// @return Data about concrete field of wallet - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - /// Information about fields of wallet - /// @return Set of fields wallet - QHash<int, QByteArray> roleNames() const; - - /// Get data in a row - /// @param row Row of wallet - /// @return Information about wallet selected by row - Q_INVOKABLE QVariantMap get(int row) const; - /// Add new wallet - /// @param arWallet new wallet - Q_INVOKABLE void append(const DapChainWallet &arWallet); - /// Add new wallet - /// @param asIconPath Path icon - /// @param asName Name of wallet - /// @param asAddress Address of wallet - /// @param aBalance Balance - /// @param aTokens Tokens name - Q_INVOKABLE void append(const QString& asIconPath, const QString &asName, const QString &asAddress, const QStringList &aBalance, const QStringList &aTokens); - /// Change data for wallet in a row - /// @param row Row of wallet - /// @param asName Name of wallet - /// @param asAddress Address of wallet - /// @param aBalance Balance - /// @param aTokens Tokens name - Q_INVOKABLE void set(int row, const QString& asIconPath, const QString &asName, const QString &asAddresss, const QStringList &aBalance, const QStringList &aTokens); - /// Remove row with wallet - /// @param row Row of wallet - Q_INVOKABLE void remove(int row); - /// Clear screen - 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/CellFrameDashboardGUI/DapClipboard.cpp b/CellFrameDashboardGUI/DapClipboard.cpp deleted file mode 100644 index eb618ac2a95c5bc56b6236cc962345dd0e99edf4..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapClipboard.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "DapClipboard.h" - -DapClipboard::DapClipboard(QObject *parent) : QObject(parent) -{ - m_clipboard = QApplication::clipboard(); -} - -DapClipboard& DapClipboard::instance() -{ - static DapClipboard instance; - return instance; -} - -void DapClipboard::setText(const QString& aText) -{ - m_clipboard->setText(aText); -} diff --git a/CellFrameDashboardGUI/DapClipboard.h b/CellFrameDashboardGUI/DapClipboard.h deleted file mode 100644 index 1e95afebc3317ca5c7530e271b7347ab582ecdde..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapClipboard.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef DAPCLIPBOARD_H -#define DAPCLIPBOARD_H - -#include <QObject> -#include <QClipboard> -#include <QApplication> - -class DapClipboard : public QObject -{ - Q_OBJECT - -private: - QClipboard* m_clipboard; - -public: - explicit DapClipboard(QObject *parent = nullptr); - static DapClipboard& instance(); - -public slots: - Q_INVOKABLE void setText(const QString& aText); -}; - -#endif // DAPCLIPBOARD_H diff --git a/CellFrameDashboardGUI/DapCommandController.cpp b/CellFrameDashboardGUI/DapCommandController.cpp index 88d41c62c99f4ca921366fe4d705dede0f5fa745..99f49ea9af2fea763cf66c95ccd6dc37de295446 100644 --- a/CellFrameDashboardGUI/DapCommandController.cpp +++ b/CellFrameDashboardGUI/DapCommandController.cpp @@ -1,7 +1,5 @@ #include "DapCommandController.h" -#include <DapNodeType.h> -#include <QDataStream> /// Overloaded constructor. /// @param apIODevice Data transfer device. @@ -29,290 +27,3 @@ void DapCommandController::messageProcessing(const DapRpcMessage &asMessage) processMessage(socket, asMessage); } - -/// Process the result of the command execution. -void DapCommandController::processCommandResult() -{ - qInfo() << "processCommandResult()"; - DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); - if (!reply) { - qWarning() << "Invalid response received"; - return; - } - emit sigCommandResult(reply->response().toJsonValue()); -} - -/// Get node logs. -void DapCommandController::getNodeLogs() -{ - qInfo() << QString("getNodeLogs()"); - DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.getNodeLogs"); - connect(reply, SIGNAL(finished()), this, SLOT(processGetNodeLogs())); -} - -void DapCommandController::getHistory() -{ - DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.getHistory"); - connect(reply, SIGNAL(finished()), this, SLOT(processGetHistory())); - -} - -void DapCommandController::setNewHistory(const QVariant& aData) -{ - emit sendHistory(aData); -} - -void DapCommandController::requestConsole(const QString& aQueue) -{ - DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.getQueryResult", aQueue); - connect(reply, SIGNAL(finished()), this, SLOT(processResponseConsole())); -} - -void DapCommandController::getCmdHistory() -{ - DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.getCmdHistory"); - connect(reply, SIGNAL(finished()), this, SLOT(processGetCmdHistory())); -} - -void DapCommandController::changeCurrentNetwork(const QString& aNetwork) -{ - m_DAPRpcSocket->invokeRemoteMethod("RPCServer.changeCurrentNetwork", aNetwork); -} - -void DapCommandController::sendMempool(const QString& aFromWallet, const QString& aToAddress, const QString& aToken, const QString& aNetwork, const quint64 aValue) -{ - DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.createTransaction", aFromWallet, aToAddress, aToken, aNetwork, aValue); - connect(reply, SIGNAL(finished()), this, SLOT(processGetResultTransaction())); -} - -void DapCommandController::takeFromMempool(const QString& aNetwork) -{ - m_DAPRpcSocket->invokeRemoteMethod("RPCServer.takeFromMempool", aNetwork); -} - -void DapCommandController::setNewWalletData(const QVariant& aData) -{ - emit sigWalletData(QByteArray::fromHex(aData.toByteArray())); -} - -void DapCommandController::requestWalletData() -{ - DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.walletData"); - connect(reply, SIGNAL(finished()), this, SLOT(processGetWalletData())); -} - -void DapCommandController::processChangedLog() -{ - emit onChangeLogModel(); -} - -/// Handling service response for receiving node logs. -void DapCommandController::processGetNodeLogs() -{ - qInfo() << "processGetNodeLogs()"; - DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); - if (!reply) { - qWarning() << "Invalid response received"; - return; - } - emit sigCommandResult(reply->response().toJsonValue()); - emit sigNodeLogsReceived(reply->response().toJsonValue().toVariant().toStringList()); -} - -/// -void DapCommandController::processAddWallet() -{ - qInfo() << "processAddWallet()"; - DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); - if (!reply) { - qWarning() << "Invalid response received"; - return; - } - emit sigCommandResult(reply->response().toJsonValue()); - auto name = reply->response().toJsonValue().toVariant().toStringList().at(0); - auto address = reply->response().toJsonValue().toVariant().toStringList().at(1); - emit sigWalletAdded(name, address); -} - -void DapCommandController::processSendToken() -{ - qInfo() << "processSendToken()"; - DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); - if (!reply) { - qWarning() << "Invalid response received"; - return; - } - qInfo() << reply->response(); - emit sigCommandResult(reply->response().toJsonValue()); - auto answer = reply->response().toJsonValue().toVariant().toString(); - emit onTokenSended(answer); -} - -void DapCommandController::processGetWallets() -{ - qInfo() << "processGetWallets()"; - DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); - if (!reply) { - qWarning() << "Invalid response received"; - return; - } - emit sigCommandResult(reply->response().toJsonValue()); - emit sigWalletsReceived(reply->response().toJsonValue().toVariant().toMap()); -} - -void DapCommandController::processGetWalletInfo() -{ - qInfo() << "processGetWalletInfo()"; - DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); - if (!reply || reply->response().toJsonValue().toVariant().toStringList().count() <= 0) { - qWarning() << "Invalid response received"; - return; - } - emit sigCommandResult(reply->response().toJsonValue()); - QString name = reply->response().toJsonValue().toVariant().toStringList().at(0); - QString address = reply->response().toJsonValue().toVariant().toStringList().at(1); - QStringList temp = reply->response().toJsonValue().toVariant().toStringList(); - QStringList tokens = temp.mid(3, temp.count()); - - emit sigWalletInfoChanged(name, address, QStringList(), tokens); -} - -void DapCommandController::processGetNodeNetwork() -{ - DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); - emit sendNodeNetwork(reply->response().toJsonValue().toVariant()); -} - -void DapCommandController::processGetNodeStatus() -{ - DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); - emit sendNodeStatus(reply->response().toJsonValue().toVariant()); -} - -void DapCommandController::processExecuteCommand() -{ - qInfo() << "processGetWalletInfo()"; - DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); - if (!reply || reply->response().toJsonValue().toVariant().toStringList().isEmpty()) { - - QString result = "Invalid response received"; - qWarning() << result; - emit executeCommandChanged(result); - return; - } - emit sigCommandResult(reply->response().toJsonValue()); - QString result = reply->response().toJsonValue().toVariant().toStringList().at(0); - emit executeCommandChanged(result); -} - -void DapCommandController::processGetHistory() -{ - DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); - QVariant result = reply->response().toJsonValue().toArray().toVariantList(); - emit sendHistory(result); -} - -void DapCommandController::processResponseConsole() -{ - DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); - QString result = reply->response().toJsonValue().toVariant().toString(); - emit responseConsole(result); -} - -void DapCommandController::processGetCmdHistory() -{ - DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); - QString result = reply->response().toJsonValue().toVariant().toString(); - emit sigCmdHistory(result); -} - -void DapCommandController::processGetWalletData() -{ - DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); - QByteArray result = reply->response().toJsonValue().toVariant().toByteArray(); - emit sigWalletData(QByteArray::fromHex(result)); -} - -void DapCommandController::processGetResultTransaction() -{ - DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); - emit sendResponseTransaction(reply->response().toJsonValue().toBool()); -} - -void DapCommandController::processGetNetworkList() -{ - DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); - QStringList result = reply->response().toJsonValue().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. -void DapCommandController::activateClient(bool aIsActivated) -{ - emit onClientActivate(aIsActivated); -} - -/// Shut down client. -void DapCommandController::closeClient() -{ - emit onClientClose(); -} - -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::removeWallet(const QString &asWalletName) -{ - qInfo() << QString("removeWallet(%1)").arg(asWalletName); - m_DAPRpcSocket->invokeRemoteMethod("RPCServer.removeWallet", asWalletName); -} - -void DapCommandController::sendToken(const QString &asSendWallet, const QString &asAddressReceiver, const QString &asToken, const QString &aAmount) -{ - qInfo() << QString("sendToken(%1, %2, %3, %4)").arg(asSendWallet).arg(asAddressReceiver).arg(asToken).arg(aAmount); - DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.sendToken", asSendWallet, asAddressReceiver, asToken, aAmount); - connect(reply, SIGNAL(finished()), this, SLOT(processSendToken())); -} - -void DapCommandController::getWallets() -{ - DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.getWallets"); - connect(reply, SIGNAL(finished()), this, SLOT(processGetWallets())); -} - -void DapCommandController::getWalletInfo(const QString& asWalletName) -{ - qInfo() << QString("getWalletInfo(%1)").arg(asWalletName); - DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.getWalletInfo", asWalletName); - connect(reply, SIGNAL(finished()), this, SLOT(processGetWalletInfo())); -} - -void DapCommandController::getNodeNetwork() -{ - DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.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) -{ - m_DAPRpcSocket->invokeRemoteMethod("RPCServer.setNodeStatus", aIsOnline); -} - -void DapCommandController::executeCommand(const QString &command) -{ - qInfo() << QString("rpc executeCommand(%1)").arg(command); - DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.executeCommand", command); - connect(reply, SIGNAL(finished()), this, SLOT(processExecuteCommand())); -} diff --git a/CellFrameDashboardGUI/DapCommandController.h b/CellFrameDashboardGUI/DapCommandController.h index e9bb6d3aff1ff882db05ebb1d44605f3a6bbb883..960fdde1128ac270719f68909286e54da5d8dde4 100644 --- a/CellFrameDashboardGUI/DapCommandController.h +++ b/CellFrameDashboardGUI/DapCommandController.h @@ -20,63 +20,6 @@ class DapCommandController : public DapRpcService, public DapRpcServiceProvider /// RPC socket. DapRpcSocket * m_DAPRpcSocket {nullptr}; - -signals: - /// The signal is emitted after receiving a response from the service about the command execution. - void sigCommandResult(QJsonValue ); - /// The signal is emitted when node logs are received from the service. - /// @param aNodeLogs List of node logs. - void sigNodeLogsReceived(const QStringList& aNodeLogs); - - /// The signal is emitted when new wallet was added - /// @param asWalletName Wallet's name - /// @param asWalletAddress Wallet's address - void sigWalletAdded(const QString& asWalletName, const QString& asWalletAddress); - /// The signal is emitted when token was sent - /// @param asAnswer Answer from service - void onTokenSended(const QString& asAnswer); - - /// The signal is emitted when receive current wallets - /// @param aWallets current wallets - void sigWalletsReceived(const QMap<QString, QVariant>& aWallets); - /// The signal is emitted when the main application window is activated. - /// @param aIsActivated Accepts true - when requesting to - /// display a client, falso - when requesting to hide a client. - void onClientActivate(bool aIsActivated); - /// The signal is emitted when the main application window closed - void onClientClose(); - /// Signal for changing information of wallet - /// @param asWalletName Wallet's name - /// @param asWalletAddress Wallet's address - void sigWalletInfoChanged(const QString& asWalletName, const QString& asWalletAddress, const QStringList& aBalance, const QStringList& aTokens); - /// Signal for data network - /// @param Data network - void sendNodeNetwork(const QVariant& aData); - /// Signal for sending status of node - /// @param Status of node - void sendNodeStatus(const QVariant& aData); - /// The signal is emitted when execute command result was changed - /// @param result Result of command - void executeCommandChanged(const QString& result); - /// The signal for changing logs - void onChangeLogModel(); - /// Ths signal for sending new transaction history - /// @param aData New transaction history - void sendHistory(const QVariant& aData); - /// The signal for response from service about command request - /// @param Responce from service - void responseConsole(const QString& aResponse); - /// The signal about changing history of commands - /// @param aHistory Changed history of commands - void sigCmdHistory(const QString& aHistory); - /// The signal for send network list - /// @param List of networks - void sendNetworkList(const QStringList& aList); - -// --------------------------------------------- - void sigWalletData(QByteArray data); - - void sendResponseTransaction(bool result); public: /// Overloaded constructor. @@ -88,111 +31,6 @@ private slots: /// Process incoming message. /// @param asMessage Incoming message. void messageProcessing(const DapRpcMessage &asMessage); - /// Process the result of the command execution. - void processCommandResult(); - /// Handling service response for receiving node logs. - void processGetNodeLogs(); - /// Handling service response for add new wallet - void processAddWallet(); - /// Handling service response for send token - void processSendToken(); - /// Handling service response for get wallets - void processGetWallets(); - /// Handling service response for get information about wallet - void processGetWalletInfo(); - /// Handling service response for get node network - void processGetNodeNetwork(); - /// Handling service response for get node status - void processGetNodeStatus(); - /// Handling service response for execute command from service - void processExecuteCommand(); - /// Handling service response for get history - void processGetHistory(); - /// Handling service response for get list network and send to network model - void processGetNetworkList(); - /// Handling service response for send new history operation to console model - void processResponseConsole(); - /// Handling service response for changing history of commands - void processGetCmdHistory(); - - // --------------------------------------------- - /// Handling service response for get wallet data - void processGetWalletData(); - /// Handling service response for get result of putting transaction to mempool - void processGetResultTransaction(); - -public slots: - /// 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. - void activateClient(bool aIsActivated); - /// Shut down client. - void closeClient(); - /// Send signal for changing log model - void processChangedLog(); - /// Add new wallet - /// @param asWalletName Name of new wallet - void addWallet(const QString& asWalletName); - /// Remove wallet - /// @param asWalletName Name of removing wallet - void removeWallet(const QString& asWalletName); - /// Send new token - /// @param asSendWallet Sent wallet - /// @param asAddressReceiver Address of receiver - /// @param asToken Name of token - /// @param aAmount sum for transaction - void sendToken(const QString &asSendWallet, const QString& asAddressReceiver, const QString& asToken, const QString& aAmount); - /// Get wallets - void getWallets(); - /// Get information about wallet - /// @param asWalletName Name of wallet - void getWalletInfo(const QString& asWalletName); - /// Get node network for explorer - void getNodeNetwork(); - /// Request about new network list - void getNetworkList(); - /// Set new status for node - /// @param aIsOnline New status for node - void setNodeStatus(const bool aIsOnline); - /// Execute command - /// @param command Command for executing - void executeCommand(const QString& command); - - /// Get node logs. - void getNodeLogs(); - - /// Get transaction history - void getHistory(); - /// Send to model new history - /// @param aData New history transaction - void setNewHistory(const QVariant& aData); - /// Commands request - /// @param aQueue Result for command - void requestConsole(const QString& aQueue); - /// Get command history - void getCmdHistory(); - /// Change current network - /// @param name of network which was selected - void changeCurrentNetwork(const QString& aNetwork); - - -// --------------------------------------------- - /// Response wallet data - /// @param data - void setNewWalletData(const QVariant& aData); - /// Request wallet data - void requestWalletData(); - /// Request for creation new transaction - /// @param name of wallet - /// @param address of a receiver - /// @param name of token - /// @param name of network - /// @param sum for transaction - /// @return result of trying to do transaction - void sendMempool(const QString& aFromWallet, const QString& aToAddress, const QString& aToken, const QString& aNetwork, const quint64 aValue); - /// Taking everything from mempool - /// @param network - void takeFromMempool(const QString& aNetwork); }; #endif // COMMANDCONTROLLER_H diff --git a/CellFrameDashboardGUI/DapConsoleModel.cpp b/CellFrameDashboardGUI/DapConsoleModel.cpp deleted file mode 100644 index 01d0ad78a6a60f5ca25964bc7d4342da5b9ce6dc..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapConsoleModel.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include "DapConsoleModel.h" - -DapConsoleModel::DapConsoleModel(QObject *parent) : - QAbstractListModel(parent) -{ - -} - -DapConsoleModel& DapConsoleModel::getInstance() -{ - static DapConsoleModel instance; - return instance; -} - -void DapConsoleModel::receiveResponse(const QString& aResponse) -{ - m_History.append(aResponse); - emit sendResponse(aResponse); -} - -int DapConsoleModel::rowCount(const QModelIndex& parent) const -{ - Q_UNUSED(parent) - - return m_CommandList.count(); -} - -QVariant DapConsoleModel::data(const QModelIndex& index, int role) const -{ - if (!index.isValid()) return QVariant(); - - if(role == LastCommand) - return m_CommandList.at(index.row()); - - return QVariant(); -} - -QHash<int, QByteArray> DapConsoleModel::roleNames() const -{ - QHash<int, QByteArray> roles; - roles[LastCommand] = "lastCommand"; - return roles; -} - -QString DapConsoleModel::getCommandUp() -{ - if(m_CommandList.isEmpty()) return QString(); - if(m_CommandIndex > m_CommandList.begin()) m_CommandIndex--; - return *m_CommandIndex; -} - -QString DapConsoleModel::getCommandDown() -{ - if(m_CommandList.isEmpty()) return QString(); - if(m_CommandIndex < m_CommandList.end() -1) m_CommandIndex++; - else return QString(); - return *m_CommandIndex; -} - -void DapConsoleModel::receiveRequest(const QString& aCommand) -{ - beginResetModel(); - if(!m_CommandList.contains(aCommand)) - m_CommandList.append(aCommand); - endResetModel(); - m_CommandIndex = m_CommandList.end(); - - QString returnSymbol = "\n"; - -#ifdef Q_OS_WIN - returnSymbol.prepend("\r"); -#endif - - m_History.append(returnSymbol + "> " + aCommand + returnSymbol); - emit sendRequest(aCommand); -} - -QString DapConsoleModel::getCmdHistory() -{ - return m_History; -} - -void DapConsoleModel::receiveCmdHistory(const QString& aHistory) -{ - m_History = aHistory; - QRegularExpression rx("^> (.+)$"); - rx.setPatternOptions(QRegularExpression::MultilineOption); - - QRegularExpressionMatchIterator i = rx.globalMatch(m_History); - - while (i.hasNext()) { - QRegularExpressionMatch match = i.next(); - QString cmd = match.captured(1).remove(QChar('\r'), Qt::CaseInsensitive); - if(!m_CommandList.contains(cmd)) - m_CommandList.append(cmd); - } - - if(!m_CommandList.isEmpty()) - m_CommandIndex = m_CommandList.end(); - emit cmdHistoryChanged(m_History); -} diff --git a/CellFrameDashboardGUI/DapConsoleModel.h b/CellFrameDashboardGUI/DapConsoleModel.h deleted file mode 100644 index 00bd228e4d905260b56eb8f6eb988f9fe8dc905d..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapConsoleModel.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef DAPUIQMLSCREENCONSOLEFORM_H -#define DAPUIQMLSCREENCONSOLEFORM_H - -#include <QDebug> -#include <QAbstractListModel> -#include <QStringList> -#include <QRegularExpression> - -/// Model for DAP console -class DapConsoleModel : public QAbstractListModel -{ - Q_OBJECT - -public: - /// Enumeration for model roles - enum ConsoleRole { - LastCommand = Qt::DisplayRole - }; - -private: - QString m_History; - QStringList m_CommandList; - QStringList::iterator m_CommandIndex; - -public: - explicit DapConsoleModel(QObject *parent = nullptr); - -public slots: - /// Receive response from service about command - /// @param result - void receiveResponse(const QString& aResponse); - /// Override methods of abstract model - int rowCount(const QModelIndex& parent) const override; - QVariant data(const QModelIndex& index, int role) const override; - QHash<int, QByteArray> roleNames() const override; - - /// Getting instanse of this class - /// @return instanse of this class - Q_INVOKABLE static DapConsoleModel& getInstance(); - /// Get the latest commands - /// @return the latest commands - Q_INVOKABLE QString getCommandUp(); - /// Get the earliest commands - /// @return the earliest commands. If it is last command in the list - /// it returns QString() - Q_INVOKABLE QString getCommandDown(); - /// Receive command requst for service - /// @param command request - Q_INVOKABLE void receiveRequest(const QString& aCommand); - /// Get current history - /// @return history of commands - Q_INVOKABLE QString getCmdHistory(); - /// Receive new history of commands - /// @param last 50 commands - void receiveCmdHistory(const QString& aHistory); - -signals: - /// Signal to send request to the service - /// @param command - void sendRequest(QString command); - /// Signal for getting response from service - /// @param result of command - void sendResponse(QString response); - /// Signal for view about changing history - /// @param last 50 commands - void cmdHistoryChanged(QString history); -}; - -#endif // DAPUIQMLSCREENCONSOLEFORM_H diff --git a/CellFrameDashboardGUI/DapScreenDialog.cpp b/CellFrameDashboardGUI/DapScreenDialog.cpp deleted file mode 100644 index 0814c9e09ea8a6841d53f3ad31d2d432c3d2acf2..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapScreenDialog.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "DapScreenDialog.h" - -DapScreenDialog::DapScreenDialog(QObject *parent) : QObject(parent) -{ - m_proxyModel = new QSortFilterProxyModel; - m_proxyModel->setFilterRegExp(QRegExp("true")); -} - -QSortFilterProxyModel *DapScreenDialog::proxyModel() const -{ - return m_proxyModel; -} - -void DapScreenDialog::setProxyModel(QSortFilterProxyModel *proxyModel) -{ - m_proxyModel = proxyModel; -} diff --git a/CellFrameDashboardGUI/DapScreenDialog.h b/CellFrameDashboardGUI/DapScreenDialog.h deleted file mode 100644 index a0347f393163917f40c80ede2bdad686865d845a..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapScreenDialog.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef DAPSCREENDIALOG_H -#define DAPSCREENDIALOG_H - -#include <QObject> -#include <QSortFilterProxyModel> - -/// Class of screen dialog. Can filtered different models -class DapScreenDialog : public QObject -{ - Q_OBJECT - - /// Pointer to current filter proxy model - QSortFilterProxyModel *m_proxyModel; -public: - /// Standard constructor - explicit DapScreenDialog(QObject *parent = nullptr); - - Q_PROPERTY(QSortFilterProxyModel* ProxyModel MEMBER m_proxyModel READ proxyModel WRITE setProxyModel NOTIFY proxyModelChanged) - /// Get current filter of proxy model - /// @return Pointer to current filter of proxy model - QSortFilterProxyModel *proxyModel() const; - /// Setn new proxy model - /// @param proxyModel New current filter of proxy model - void setProxyModel(QSortFilterProxyModel *proxyModel); - -signals: - /// The signal is emitted when filter of proxy model was changed - /// @param proxyModel New current filter of proxy model - void proxyModelChanged(QSortFilterProxyModel *proxyModel); -public slots: -}; - -#endif // DAPSCREENDIALOG_H diff --git a/CellFrameDashboardGUI/DapScreenDialogChangeWidget.cpp b/CellFrameDashboardGUI/DapScreenDialogChangeWidget.cpp deleted file mode 100644 index fa396332d6ea156db0b70505bef53ef2701f1dcb..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapScreenDialogChangeWidget.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "DapScreenDialogChangeWidget.h" - -DapScreenDialogChangeWidget::DapScreenDialogChangeWidget(QObject *parent) : QObject(parent) -{ - m_proxyModel = new QSortFilterProxyModel(this); - m_proxyModel->setFilterRegExp(QRegExp("false")); -} - -QSortFilterProxyModel *DapScreenDialogChangeWidget::proxyModel() const -{ - return m_proxyModel; -} - -void DapScreenDialogChangeWidget::setProxyModel(QSortFilterProxyModel *proxyModel) -{ - m_proxyModel = proxyModel; -} diff --git a/CellFrameDashboardGUI/DapScreenDialogChangeWidget.h b/CellFrameDashboardGUI/DapScreenDialogChangeWidget.h deleted file mode 100644 index 20dab74440ed7978adfcc662b929494c3ebd49ed..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapScreenDialogChangeWidget.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef DAPSCREENDIALOGCHANGEWIDGET_H -#define DAPSCREENDIALOGCHANGEWIDGET_H - -#include <QObject> -#include <QSortFilterProxyModel> - -/// Class of dialog change widget -class DapScreenDialogChangeWidget : public QObject -{ - Q_OBJECT - /// Pointer to current filter proxy model - QSortFilterProxyModel *m_proxyModel; -public: - /// Standard constructor - explicit DapScreenDialogChangeWidget(QObject *parent = nullptr); - - Q_PROPERTY(QSortFilterProxyModel* ProxyModel MEMBER m_proxyModel READ proxyModel WRITE setProxyModel NOTIFY proxyModelChanged) - /// Get current filter of proxy model - /// @return Pointer to current filter of proxy model - QSortFilterProxyModel *proxyModel() const; - /// Setn new proxy model - /// @param proxyModel New current filter of proxy model - void setProxyModel(QSortFilterProxyModel *proxyModel); -signals: - /// The signal is emitted when filter of proxy model was changed - /// @param proxyModel New current filter of proxy model - void proxyModelChanged(QSortFilterProxyModel *proxyModel); -public slots: -}; - -#endif // DAPSCREENDIALOGCHANGEWIDGET_H diff --git a/CellFrameDashboardGUI/DapScreenHistoryFilterModel.cpp b/CellFrameDashboardGUI/DapScreenHistoryFilterModel.cpp deleted file mode 100644 index 8f6d334e8d283170e2c0ea76267b17956b64ad6e..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapScreenHistoryFilterModel.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "DapScreenHistoryFilterModel.h" - -DapScreenHistoryFilterModel::DapScreenHistoryFilterModel(QObject *parent) : - QSortFilterProxyModel(parent), - m_status(-1) -{ - sort(0, Qt::DescendingOrder); -} - -DapScreenHistoryFilterModel& DapScreenHistoryFilterModel::getInstance() -{ - static DapScreenHistoryFilterModel instance; - return instance; -} - -void DapScreenHistoryFilterModel::setFilterWallet(const QString& aWalletNumber) -{ - if(m_walletNumber == aWalletNumber) return; - m_walletNumber = aWalletNumber; - setFilterKeyColumn(0); -} - -void DapScreenHistoryFilterModel::setFilterDate(const QDate& aDateLeft, const QDate& aDateRight) -{ - if(m_dateLeft == aDateLeft || m_dateRight == aDateRight) return; - m_dateLeft = aDateLeft; - m_dateRight = aDateRight; - setFilterKeyColumn(0); -} - -void DapScreenHistoryFilterModel::setFilterStatus(const DapTransactionStatus aStatus) -{ - if(m_status == aStatus) return; - m_status = aStatus; - setFilterKeyColumn(0); -} - -bool DapScreenHistoryFilterModel::lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const -{ - QDateTime first = source_left.data(DapScreenHistoryModel::DateRole).toDateTime(); - QDateTime second = source_right.data(DapScreenHistoryModel::DateRole).toDateTime(); - return first < second; -} - -bool DapScreenHistoryFilterModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const -{ - QModelIndex index = sourceModel()->index(source_row, 0, source_parent); - QDateTime time = index.data(DapScreenHistoryModel::DateRole).toDateTime(); - - bool result = true; - bool filterByWalletNumber = !m_walletNumber.isEmpty(); - bool filterByDate = m_dateLeft.isValid() && m_dateRight.isValid(); - bool filterByStatus = m_status > -1; - - if(filterByDate) result &= (time.date() >= m_dateLeft && time.date() <= m_dateRight); - if(filterByStatus) result &= (index.data(DapScreenHistoryModel::StatusRole).toInt() == m_status); - if(filterByWalletNumber) result &= (index.data(DapScreenHistoryModel::DisplayNumberWalletRole).toString() == m_walletNumber); - - return result; -} diff --git a/CellFrameDashboardGUI/DapScreenHistoryFilterModel.h b/CellFrameDashboardGUI/DapScreenHistoryFilterModel.h deleted file mode 100644 index 85bddba4fa383ba27fd2172fae2e94094826a1af..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapScreenHistoryFilterModel.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef DAPSCREENHISTORYFILTERMODEL_H -#define DAPSCREENHISTORYFILTERMODEL_H - -#include <QSortFilterProxyModel> - -#include "DapScreenHistoryModel.h" - -/// Class screen of history transaction -class DapScreenHistoryFilterModel : public QSortFilterProxyModel -{ - Q_OBJECT - -private: - /// Number of wallet - QString m_walletNumber; - /// Minimum date - QDate m_dateLeft; - /// Maximum date - QDate m_dateRight; - /// Filter status - int m_status; - -protected: - /// Overides methods - bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const; - bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const; - -public: - explicit DapScreenHistoryFilterModel(QObject *parent = nullptr); - /// Get instance of this class - /// @return instance of this class - static DapScreenHistoryFilterModel &getInstance(); - -public slots: - /// Filter model with wallet - /// @param number of wallet - void setFilterWallet(const QString& aWalletNumber); - /// Filter model with dates - /// @param Min date - /// @param Max date - void setFilterDate(const QDate& aDateLeft, const QDate& aDateRight); - /// Filter with status of transaction - /// @param status of transaction - void setFilterStatus(const DapTransactionStatus aStatus); -}; - -#endif // DAPSCREENHISTORYFILTERMODEL_H diff --git a/CellFrameDashboardGUI/DapScreenHistoryModel.cpp b/CellFrameDashboardGUI/DapScreenHistoryModel.cpp deleted file mode 100644 index 428b272bc68e8c4d53c13910d48149a3387ace60..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapScreenHistoryModel.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include "DapScreenHistoryModel.h" - -DapScreenHistoryModel::DapScreenHistoryModel(QObject *parent) - : QAbstractListModel(parent) -{ - -} - -DapScreenHistoryModel& DapScreenHistoryModel::getInstance() -{ - static DapScreenHistoryModel instance; - return instance; -} - -QHash<int, QByteArray> DapScreenHistoryModel::roleNames() const -{ - QHash<int, QByteArray> names; - names[DisplayDateRole] = "date"; - names[DisplayNameTokenRole] = "tokenName"; - names[DisplayNumberWalletRole] = "numberWallet"; - names[DisplayStatusRole] = "txStatus"; - names[DisplayCryptocurrency] = "cryptocurrency"; - names[DisplayCurrency] = "currency"; - names[DateRole] = "dateRole"; - names[StatusColorRole] = "statusColor"; - return names; -} - -void DapScreenHistoryModel::receiveNewData(const QVariant& aData) -{ - if(!aData.isValid()) - { - qWarning() << "New history data is not valid"; - return; - } - - beginResetModel(); - QList<QVariant> dataList = aData.toList(); - m_elementList.clear(); - - for(int i = 0; i < dataList.count(); i++) - { - // Description QStringList - // ------------------------ - // 0: date - // 1: status - // 2: currency - // 3: token - // 4: wallet_to - // 5: wallet_from - - QStringList dataItem = dataList.at(i).toStringList(); - DapTransactionItem item; - item.Date = QDateTime::fromString(dataItem.at(0), Qt::RFC2822Date); - item.Status = static_cast<DapTransactionStatus>(dataItem.at(1).toInt()); - item.Cryptocurrency = dataItem.at(2); - item.TokenName = dataItem.at(3); - item.WalletNumber = dataItem.at(5); - // TODO: Later we should convert currency - item.Currency = QString::number(dataItem.at(2).toDouble() * 0.98); - - switch (item.Status) { - case DapTransactionStatus::stSent: - item.Cryptocurrency.prepend("- "); - item.Currency.prepend("- $ "); - break; - case DapTransactionStatus::stReceived: - item.Cryptocurrency.prepend("+ "); - item.Currency.prepend("+ $ "); - break; - default: break; - } - - item.Cryptocurrency = DapChainConvertor::getInstance().toConvertCurrency(item.Cryptocurrency); - item.Cryptocurrency += " " + item.TokenName; - item.Currency.append(" USD"); - - m_elementList.append(item); - } - - - endResetModel(); -} - -int DapScreenHistoryModel::rowCount(const QModelIndex &parent) const -{ - if (parent.isValid()) return 0; - return m_elementList.count(); -} - -QVariant DapScreenHistoryModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) return QVariant(); - - switch (role) - { - case DisplayDateRole: - { - QDateTime currentTime = QDateTime::currentDateTime(); - QDateTime itemDate = m_elementList.at(index.row()).Date; - if(currentTime.date() == itemDate.date()) return QString("Today"); - else if(currentTime.daysTo(itemDate) == -1) return QString("Yesterday"); - else if(currentTime.date().year() < itemDate.date().year()) return itemDate.toString(MASK_FOR_MODEL_WITH_YEAR); - return itemDate.toString(MASK_FOR_MODEL); - } - case DisplayNameTokenRole: return m_elementList.at(index.row()).TokenName; - case DisplayNumberWalletRole: return m_elementList.at(index.row()).WalletNumber; - case DisplayStatusRole: return DapTransactionStatusConvertor::getLongStatus(m_elementList.at(index.row()).Status); - case DisplayCryptocurrency: return m_elementList.at(index.row()).Cryptocurrency; - case DisplayCurrency: return m_elementList.at(index.row()).Currency; - case DateRole: return m_elementList.at(index.row()).Date; - case StatusColorRole: return DapTransactionStatusConvertor::getStatusColor(m_elementList.at(index.row()).Status); - case StatusRole: return m_elementList.at(index.row()).Status; - default: return QVariant(); - } -} diff --git a/CellFrameDashboardGUI/DapScreenHistoryModel.h b/CellFrameDashboardGUI/DapScreenHistoryModel.h deleted file mode 100644 index cb1b833a58fb06aa47d0e8923ae0e5b839f614fe..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapScreenHistoryModel.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef DAPSCREENHISTORYMODEL_H -#define DAPSCREENHISTORYMODEL_H - -#include <QtGlobal> -#include <QDebug> -#include <QImage> -#include <QAbstractListModel> -#include <QDateTime> -#include <QTimer> -#include "DapHistoryType.h" -#include "DapChainConvertor.h" - -#define MASK_FOR_MODEL QString("MMMM, d") -#define MASK_FOR_MODEL_WITH_YEAR QString("MMMM, d, yyyy") - -class DapScreenHistoryModel : public QAbstractListModel -{ - Q_OBJECT - -public: - /// Role enumeration - enum { - DisplayDateRole = Qt::UserRole, - DateRole, - DisplayNameTokenRole, - DisplayNumberWalletRole, - DisplayStatusRole, - StatusRole, - StatusColorRole, - DisplayCryptocurrency, - DisplayCurrency - }; - -private: - QList<DapTransactionItem> m_elementList; - -public: - explicit DapScreenHistoryModel(QObject *parent = nullptr); - /// Get instance of this class - /// @param instance of this class - static DapScreenHistoryModel &getInstance(); - - /// Override model's methods - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - QHash<int, QByteArray> roleNames() const override; - -public slots: - /// Receive new tx history - /// @param QList<QStringList> data - void receiveNewData(const QVariant& aData); - -signals: - /// Signal for requset current state of tx history - /// By defalt this signal emits when the client has just started while - /// the tx model will not get at least one tx history. - /// The signal stop emitting after getting the request result - void sendRequestHistory(); -}; - -#endif // DAPSCREENHISTORYMODEL_H diff --git a/CellFrameDashboardGUI/DapServiceController.cpp b/CellFrameDashboardGUI/DapServiceController.cpp index d5cfc6d76e92547ac12e6e481bd3d17763a3ab0b..75a4b022b1d6eacc16e473944a41e3b3682d6f3b 100644 --- a/CellFrameDashboardGUI/DapServiceController.cpp +++ b/CellFrameDashboardGUI/DapServiceController.cpp @@ -1,8 +1,4 @@ #include "DapServiceController.h" -#include "DapLogMessage.h" -#include "DapChainWallet.h" -#include "DapSettings.h" -#include <QRegularExpression> DapServiceController::DapServiceController(QObject *apParent) : QObject(apParent) @@ -10,70 +6,15 @@ DapServiceController::DapServiceController(QObject *apParent) } -/// 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. -void DapServiceController::activateClient(bool aIsActivated) -{ - if(aIsActivated) - emit activateWindow(); -} - -/// Shut down client. -void DapServiceController::closeClient() -{ - qApp->quit(); -} - /// Get company brand. /// @return Brand Ñompany. void DapServiceController::init(DapServiceClient *apDapServiceClient) { m_pDapServiceClient = apDapServiceClient; - - connect(m_pDapServiceClient, SIGNAL(sigDisconnected()), SLOT(clearLogModel())); - connect(m_pDapServiceClient, SIGNAL(sigConnected()), SLOT(loadUserSettings())); // Creating rpc controller m_pDapCommandController = new DapCommandController(apDapServiceClient->getClientSocket(), this); - // Signal-slot connection that implements the client display control when you click on the tray icon - connect(m_pDapCommandController, SIGNAL(onClientActivate(bool)), SLOT(activateClient(bool))); - // Signal-slot connection that implements the client display control when you click on the tray icon - 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>))); - - connect(m_pDapCommandController, SIGNAL(sigWalletInfoChanged(QString,QString, QStringList, QStringList)), SLOT(processGetWalletInfo(QString,QString, QStringList, QStringList))); - - connect(m_pDapCommandController, SIGNAL(onTokenSended(QString)), SLOT(processSendToken(QString))); - - connect(m_pDapCommandController, SIGNAL(executeCommandChanged(QString)), SLOT(processExecuteCommandInfo(QString))); - - connect(m_pDapCommandController, SIGNAL(sendNodeNetwork(QVariant)), this, SLOT(processGetNodeNetwork(QVariant))); - connect(m_pDapCommandController, SIGNAL(onChangeLogModel()), SLOT(getNodeLogs())); - - connect(&DapChainNodeNetworkModel::getInstance(), SIGNAL(requestNodeNetwork()), this, SLOT(getNodeNetwork())); - connect(&DapChainNodeNetworkModel::getInstance(), SIGNAL(requestNodeStatus(bool)), this, SLOT(setNodeStatus(bool))); - - connect(m_pDapCommandController, SIGNAL(sendHistory(QVariant)), this, SLOT(processGetHistory(QVariant))); - - connect(m_pDapCommandController, &DapCommandController::sendHistory, &DapScreenHistoryModel::getInstance(), &DapScreenHistoryModel::receiveNewData); - - 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); - - connect(m_pDapCommandController, &DapCommandController::sigWalletData, &DapChainWalletModel::instance(), &DapChainWalletModel::setWalletData); - - connect(m_pDapCommandController, &DapCommandController::sendResponseTransaction, this, &DapServiceController::resultMempool); } QString DapServiceController::getBrand() const @@ -88,181 +29,6 @@ QString DapServiceController::getVersion() const return m_sVersion; } -QString DapServiceController::getSettingFile() const -{ - return m_sSettingFile; -} - -QString DapServiceController::getResult() -{ - return m_sResult; -} - -void DapServiceController::getWallets() const -{ - qInfo() << QString("getWallets()"); - m_pDapCommandController->getWallets(); -} - -/// Handling service response for receiving node logs. -/// @param aNodeLogs List of node logs. -void DapServiceController::processGetNodeLogs(const QStringList &aNodeLogs) -{ - if(aNodeLogs.isEmpty()) - return; - - QRegularExpression re("(?<=])\\s"); - for (auto const & log : aNodeLogs) - { - const QStringList list = log.split(re); - DapLogMessage logMessage; - logMessage.setTimeStamp(list.at(0)); - logMessage.setType(list.at(1)); - logMessage.setFile(list.at(2)); - logMessage.setMessage(list.at(3)); - DapLogModel::getInstance().append(logMessage); - } - - emit logCompleted(); -} - -/// Get node logs. -void DapServiceController::getNodeLogs() const -{ - qInfo() << QString("getNodeLogs()"); - m_pDapCommandController->getNodeLogs(); -} - -void DapServiceController::clearLogModel() -{ - DapLogModel::getInstance().clear(); - emit logCompleted(); -} - -void DapServiceController::addWallet(const QString &asWalletName) -{ - qInfo() << QString("addWallet(%1)").arg(asWalletName); - m_pDapCommandController->addWallet(asWalletName); -} - -void DapServiceController::removeWallet(int index, const QString &asWalletName) -{ - qInfo() << QString("removeWallet(%1)").arg(asWalletName); - m_pDapCommandController->removeWallet(asWalletName.trimmed()); - DapChainWalletsModel::getInstance().remove(index); -} - -void DapServiceController::sendToken(const QString &asSendWallet, const QString &asAddressReceiver, const QString &asToken, const QString &aAmount) -{ - qInfo() << QString("sendToken(%1, %2, %3, %4)").arg(asSendWallet).arg(asAddressReceiver).arg(asToken).arg(aAmount); - m_pDapCommandController->sendToken(asSendWallet.trimmed(), asAddressReceiver.trimmed(), asToken.trimmed(), aAmount); -} - -void DapServiceController::executeCommand(const QString& command) -{ - qInfo() << QString("executeCommand (%1)").arg(command); - m_pDapCommandController->executeCommand(command); -} - - -void DapServiceController::getWalletInfo(const QString &asWalletName) -{ - qInfo() << QString("getWalletInfo(%1)").arg(asWalletName); - m_pDapCommandController->getWalletInfo(asWalletName); -} - -void DapServiceController::getCmdHistory() -{ - m_pDapCommandController->getCmdHistory(); -} - -void DapServiceController::getHistory() -{ - m_pDapCommandController->getHistory(); -} - -void DapServiceController::getNodeNetwork() -{ - m_pDapCommandController->getNodeNetwork(); -} - -void DapServiceController::setNodeStatus(const bool aIsOnline) -{ - m_pDapCommandController->setNodeStatus(aIsOnline); -} - -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::processSendToken(const QString &asAnswer) -{ - qInfo() << QString("processSendToken(%1)").arg(asAnswer); -} - -void DapServiceController::processGetWallets(const QMap<QString, QVariant> &aWallets) -{ - qInfo() << QString("processGetWallets()") << aWallets.size(); - for(QString w : aWallets.keys()) - { - getWalletInfo(w); - } -} - -void DapServiceController::processGetWalletInfo(const QString &asWalletName, const QString &asWalletAddress, const QStringList& aBalance, const QStringList &aTokens) -{ - qInfo() << QString("processGetWalletInfo(%1, %2)").arg(asWalletName).arg(asWalletAddress); - DapChainWallet wallet("", asWalletName, asWalletAddress, aBalance, aTokens); - DapChainWalletsModel::getInstance().append(wallet); -} - -void DapServiceController::processExecuteCommandInfo(const QString &result) -{ - qInfo() << QString("processExecuteCommandInfo(%1)").arg(result); - m_sResult = result; - emit resultChanged(); -} - -void DapServiceController::processGetNodeNetwork(const QVariant& aData) -{ - DapChainNodeNetworkModel::getInstance().receiveNewNetwork(aData); -} - -void DapServiceController::processGetHistory(const QVariant& aData) -{ - DapScreenHistoryModel::getInstance().receiveNewData(aData); -} - -void DapServiceController::getNetworkList() -{ - m_pDapCommandController->getNetworkList(); -} - -void DapServiceController::loadUserSettings() -{ - const QString networkName = DapSettings::getInstance(m_sSettingFile) - .getKeyValue("network").toString(); - qInfo() << "get settings name: " << networkName; - int currentIndex = DapSettingsNetworkModel::getInstance().getCurrentIndex(); - qInfo() << "current index is " << currentIndex; - DapSettingsNetworkModel::getInstance().setCurrentNetwork(networkName, ++currentIndex); - qInfo() << "change Current Network: " << DapSettingsNetworkModel::getInstance().getCurrentNetwork(); - emit userSettingsLoaded(); -} - -void DapServiceController::saveUserSettings() -{ - DapSettings::getInstance().setFileName(m_sSettingFile); - QJsonObject networkObject; - networkObject["network"] = DapSettingsNetworkModel::getInstance().getCurrentNetwork(); - qInfo() << "Save to file: " << networkObject; - DapSettings::getInstance().writeFile(QJsonDocument(networkObject)); - emit userSettingsSaved(); -} - /// Get an instance of a class. /// @return Instance of a class. DapServiceController &DapServiceController::getInstance() @@ -281,18 +47,3 @@ QObject *DapServiceController::singletonProvider(QQmlEngine *engine, QJSEngine * return &getInstance(); } - -void DapServiceController::createTransaction(const QString& aFromWallet, const QString& aToAddress, const QString& aToken, const QString& aNetwork, const quint64 aValue) -{ - m_pDapCommandController->sendMempool(aFromWallet, aToAddress, aToken, aNetwork, aValue); -} - -void DapServiceController::sendToken(const QString& aNetwork) -{ - m_pDapCommandController->takeFromMempool(aNetwork); -} - -void DapServiceController::requestWalletData() -{ - m_pDapCommandController->requestWalletData(); -} diff --git a/CellFrameDashboardGUI/DapServiceController.h b/CellFrameDashboardGUI/DapServiceController.h index fd767d9f13cf162279d035fdd4ea17435a220871..1872df162cdddc7c969e16b022892f863710d674 100644 --- a/CellFrameDashboardGUI/DapServiceController.h +++ b/CellFrameDashboardGUI/DapServiceController.h @@ -4,21 +4,9 @@ #include <QObject> #include <QQmlEngine> #include <QJSEngine> -#include <QApplication> -#include <QTimer> -#include <QMap> -#include <QPair> #include "DapCommandController.h" #include "DapServiceClient.h" -#include "DapLogModel.h" -#include "DapChainWalletsModel.h" -#include "DapChainNodeNetworkModel.h" -#include "DapScreenHistoryModel.h" -#include "DapSettingsNetworkModel.h" -#include "DapConsoleModel.h" - -#include "DapChainWalletModel.h" class DapServiceController : public QObject { @@ -28,10 +16,6 @@ class DapServiceController : public QObject QString m_sBrand {DAP_BRAND}; /// Application version. QString m_sVersion {DAP_VERSION}; - /// Settings file. - QString m_sSettingFile {DAP_SETTINGS_FILE}; - /// Result execute. - QString m_sResult; /// Service connection management service. DapServiceClient *m_pDapServiceClient {nullptr}; @@ -53,8 +37,6 @@ public: Q_PROPERTY(QString Brand MEMBER m_sBrand READ getBrand NOTIFY brandChanged) /// Application version. Q_PROPERTY(QString Version MEMBER m_sVersion READ getVersion NOTIFY versionChanged) - /// Result execute command. - Q_PROPERTY(QString Result MEMBER m_sVersion READ getResult NOTIFY resultChanged) ///******************************************** /// Interface @@ -66,32 +48,6 @@ public: /// Get app version. /// @return Application version. QString getVersion() const; - /// Get setting file name. - /// @return Setting file name - QString getSettingFile() const; - /// Get result command execute. - /// @return Result execute. - QString getResult(); - /// Get node logs. - /// @param aiTimeStamp Timestamp start reading logging. - /// @param aiRowCount Number of lines displayed. - void getNodeLogs(int aiTimeStamp, int aiRowCount) const; - /// Get wallets - Q_INVOKABLE void getWallets() const; - /// Add new wallet - /// @param wallet - Q_INVOKABLE void addWallet(const QString& asWalletName); - Q_INVOKABLE void removeWallet(int index, const QString& asWalletName); - Q_INVOKABLE void sendToken(const QString &asSendWallet, const QString& asAddressReceiver, const QString& asToken, const QString& aAmount); - Q_INVOKABLE void executeCommand(const QString& command); - - /// Get information about wallet - /// @param name of wallet - void getWalletInfo(const QString& asWalletName); - /// Request about new netowrk list - void getNetworkList(); - /// Get history of commands - void getCmdHistory(); signals: /// The signal is emitted when the Brand company property changes. @@ -100,89 +56,12 @@ signals: /// The signal is emitted when the Application version property changes. /// @param version Version void versionChanged(const QString &version); - /// The signal is emitted when the result execute property changes. - void resultChanged(); - /// The signal is emitted when the main application window is activated. - void activateWindow(); - /// The signal is emitted when checking the existence of an already running copy of the application. - /// @param isExistenceClient True if after checking client is exist. False when not - void isExistenceClient(bool isExistenceClient); - /// The signal is emitted when sending to QML - void sendToQML(QString); - /// The signal is emitted when log message append to log model or logs was cleared - void logCompleted(); - /// Signal for data network - /// @param aData Data network - void sendNodeNetwork(const QVariant& aData); - void userSettingsLoaded(); - void userSettingsSaved(); - -private slots: - /// Handling service response for receiving node logs. - /// @param aNodeLogs List of node logs. - void processGetNodeLogs(const QStringList& aNodeLogs); - /// Handling service response for add new wallet - /// @param asWalletName Name of wallet - /// @param asWalletAddress Address of wallet - void processAddWallet(const QString& asWalletName, const QString& asWalletAddress); - // TODO: Implement logic to proccess. - /// Handling service response for send new token - /// @param asAnswer Answer - void processSendToken(const QString& asAnswer); - /// Handling service response for get wallets - /// @param aWallets Wallets - void processGetWallets(const QMap<QString, QVariant>& aWallets); - /// Handling service response for get information about selected wallet - /// @param asWalletName Name of wallet - /// @param asWalletAddress Address of wallet - void processGetWalletInfo(const QString& asWalletName, const QString& asWalletAddress, const QStringList &aBalance, const QStringList& aTokens); - /// Handling service response for write information of result executing command - /// @param result Result executing information - void processExecuteCommandInfo(const QString& result); - /// Handling service response for get node network - /// @param aData Data of node network - void processGetNodeNetwork(const QVariant& aData); - /// Handling service response for get transaction history - /// @param Data of history - void processGetHistory(const QVariant& aData); public slots: - /// Get history of transaction - void getHistory(); - /// Get node network for explorer - void getNodeNetwork(); - /// Change status of node - /// @param it is true if a node is online - void setNodeStatus(const bool aIsOnline); - - /// Get node logs. - Q_INVOKABLE void getNodeLogs() const; - - void clearLogModel(); - /// 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. - void activateClient(bool aIsActivated); - /// Shut down client. - void closeClient(); - /// Load user settings from settings file - void loadUserSettings(); - /// Save user settings to file - void saveUserSettings(); /// 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); - - void createTransaction(const QString& aFromWallet, const QString& aToAddress, const QString& aToken, const QString& aNetwork, const quint64 aValue); - void sendToken(const QString& aNetwork); - -public slots: - /// Request wallet data - void requestWalletData(); - -signals: - void resultMempool(bool result); }; #endif // DAPSERVICECONTROLLER_H diff --git a/CellFrameDashboardGUI/DapSettingsNetworkModel.cpp b/CellFrameDashboardGUI/DapSettingsNetworkModel.cpp deleted file mode 100644 index e6567a038718a95644e9f8c72238c9c2bf725fa7..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapSettingsNetworkModel.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#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 deleted file mode 100644 index 216d012900777673f5863c34a6653d170e9c4036..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapSettingsNetworkModel.h +++ /dev/null @@ -1,56 +0,0 @@ -#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/DapWalletFilterModel.cpp b/CellFrameDashboardGUI/DapWalletFilterModel.cpp deleted file mode 100644 index 3228100fb3b02a3ef68a0ad597c11aae1cc8885f..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapWalletFilterModel.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "DapWalletFilterModel.h" - -DapWalletFilterModel::DapWalletFilterModel(QObject *parent) : - QSortFilterProxyModel(parent), - m_filterWalletName(TITLE_ALL_WALLETS) -{ - sort(0, Qt::DescendingOrder); -} - -DapWalletFilterModel& DapWalletFilterModel::instance() -{ - static DapWalletFilterModel instance; - return instance; -} - -void DapWalletFilterModel::setWalletFilter(const QString& aName) -{ - if(m_filterWalletName == aName) return; - m_filterWalletName = aName; - setFilterKeyColumn(0); -} - -bool DapWalletFilterModel::lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const -{ - QString first = source_left.data(DapChainWalletModel::NetworkDisplayRole).toString(); - QString second = source_right.data(DapChainWalletModel::NetworkDisplayRole).toString(); - return first < second; -} - -bool DapWalletFilterModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const -{ - if(m_filterWalletName == TITLE_ALL_WALLETS) return true; - - QModelIndex index = sourceModel()->index(source_row, 0, source_parent); - QString wallet = index.data(DapChainWalletModel::WalletNameDisplayRole).toString(); - - return wallet == m_filterWalletName; -} diff --git a/CellFrameDashboardGUI/DapWalletFilterModel.h b/CellFrameDashboardGUI/DapWalletFilterModel.h deleted file mode 100644 index fe8927d30761f9bae1776779f1030f1ed8ef0c42..0000000000000000000000000000000000000000 --- a/CellFrameDashboardGUI/DapWalletFilterModel.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef DAPWALLETFILTERMODEL_H -#define DAPWALLETFILTERMODEL_H - -#include <QSortFilterProxyModel> -#include "DapChainWalletModel.h" - -class DapWalletFilterModel : public QSortFilterProxyModel -{ - Q_OBJECT - -private: - QString m_filterWalletName; - -protected: - bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const; - bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const; - -public: - explicit DapWalletFilterModel(QObject *parent = nullptr); - static DapWalletFilterModel& instance(); - -public slots: - Q_INVOKABLE void setWalletFilter(const QString& aName); -}; - -#endif // DAPWALLETFILTERMODEL_H diff --git a/CellFrameDashboardGUI/main.cpp b/CellFrameDashboardGUI/main.cpp index a3dfcb3b425cdf9183e342359a9b98a5e60575ac..4677a6f397ba9e68f2295261a13ffebb16fb2589 100644 --- a/CellFrameDashboardGUI/main.cpp +++ b/CellFrameDashboardGUI/main.cpp @@ -9,27 +9,10 @@ #include <QScreen> #include "DapHalper.h" -#include "DapScreenDialog.h" -#include "DapScreenDialogChangeWidget.h" -#include "DapSettings.h" #include "DapServiceClient.h" #include "DapServiceController.h" #include "DapLogger.h" #include "DapLogMessage.h" -#include "DapLogModel.h" -#include "DapChainWalletsModel.h" -#include "DapChainNodeNetworkModel.h" -#include "DapChainNodeNetworkExplorer.h" -#include "DapScreenHistoryFilterModel.h" -#include "DapSettingsNetworkModel.h" -#include "DapConsoleModel.h" -#include "DapChainConvertor.h" -#include "DapClipboard.h" - -#include "DapChainWalletModel.h" -#include "DapWalletFilterModel.h" - -#include <QRegExp> #include <sys/stat.h> @@ -63,38 +46,10 @@ int main(int argc, char *argv[]) DapServiceController &controller = DapServiceController::getInstance(); controller.init(&dapServiceClient); dapServiceClient.init(); - controller.getWallets(); - controller.requestWalletData(); - controller.getHistory(); - controller.getCmdHistory(); - controller.getNetworkList(); - - DapScreenHistoryFilterModel::getInstance() - .setSourceModel(&DapScreenHistoryModel::getInstance()); - - DapWalletFilterModel::instance() - .setSourceModel(&DapChainWalletModel::instance()); - - qmlRegisterType<DapScreenDialog>("CellFrameDashboard", 1, 0, "DapScreenDialog"); - qmlRegisterType<DapScreenDialogChangeWidget>("CellFrameDashboard", 1, 0, "DapScreenDialogChangeWidget"); qmlRegisterType<DapLogMessage>("LogMessage", 1, 0, "DapLogMessage"); - qmlRegisterType<DapChainNodeNetworkExplorer>("NodeNetworkExplorer", 1, 0, "DapUiQmlWidgetNodeNetwork"); - qmlRegisterType<DapScreenHistoryModel>("DapTransactionHistory", 1, 0, "DapTransactionModel"); QQmlApplicationEngine engine; - /// TODO: this method for getting DPI screen can be useful in the future -// qreal dpi = QGuiApplication::primaryScreen()->physicalDotsPerInch(); engine.rootContext()->setContextProperty("dapServiceController", &DapServiceController::getInstance()); - engine.rootContext()->setContextProperty("dapLogModel", &DapLogModel::getInstance()); - engine.rootContext()->setContextProperty("dapChainWalletsModel", &DapChainWalletsModel::getInstance()); - 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("dapChainConvertor", &DapChainConvertor::getInstance()); - engine.rootContext()->setContextProperty("dapWalletFilterModel", &DapWalletFilterModel::instance()); - engine.rootContext()->setContextProperty("dapWalletModel", &DapChainWalletModel::instance()); - engine.rootContext()->setContextProperty("clipboard", &DapClipboard::instance()); engine.rootContext()->setContextProperty("pt", 1.0); engine.load(QUrl("qrc:/main.qml")); diff --git a/CellFrameDashboardGUI/main.qml b/CellFrameDashboardGUI/main.qml index 2e1c03185f026addf8d53fc6d1891e4ff39fc3f3..ae336dc30f0f00133c56d3afcb9d6c63eac29057 100755 --- a/CellFrameDashboardGUI/main.qml +++ b/CellFrameDashboardGUI/main.qml @@ -2,43 +2,22 @@ import QtQuick 2.0 import QtQuick.Controls 2.0 import "screen" -ApplicationWindow { +ApplicationWindow +{ id: window visible: true width: 1280 height: 800 - -// property string device: "desktop" - onClosing: { - console.log("Close") - window.hide() - } - - Connections { - target: dapServiceController - - onActivateWindow: { - if(window.visibility === Window.Hidden) { - window.show() - window.raise() - window.requestActivate() - } else { - window.hide() - } - } - } - - - DapMainApplicationWindow { - property alias device: dapDevice.device - Device { - id: dapDevice - - } + property alias device: dapDevice.device + anchors.fill: parent - } + Device + { + id: dapDevice + } + } } diff --git a/CellFrameDashboardService/CellFrameDashboardService.pro b/CellFrameDashboardService/CellFrameDashboardService.pro index e03e0a07991dd1f50cae6f3ed8def0abd796c4ff..69a9c8fc8d6d119bd703d0d9a54a8a9189fb3350 100755 --- a/CellFrameDashboardService/CellFrameDashboardService.pro +++ b/CellFrameDashboardService/CellFrameDashboardService.pro @@ -45,29 +45,13 @@ DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ - $$PWD/DapChainHistoryHandler.cpp \ - $$PWD/DapChainNodeNetworkHandler.cpp \ - $$PWD/main.cpp \ $$PWD/DapChainDashboardService.cpp \ - $$PWD/DapChainNode.cpp \ - $$PWD/DapChainNodeCache.cpp \ - $$PWD/DapChainWalletHandler.cpp \ - $$PWD/DapChainLogHandler.cpp \ - $$PWD/DapChainNetworkHandler.cpp \ - $$PWD/DapChainConsoleHandler.cpp \ - $$PWD/DapChainTransaction.cpp + $$PWD/main.cpp \ + HEADERS += \ $$PWD/DapChainDashboardService.h \ - $$PWD/DapChainHistoryHandler.h \ - $$PWD/DapChainNode.h \ - $$PWD/DapChainNodeCache.h \ - $$PWD/DapChainNodeNetworkHandler.h \ - $$PWD/DapChainWalletHandler.h \ - $$PWD/DapChainLogHandler.h \ - $$PWD/DapChainNetworkHandler.h \ - $$PWD/DapChainConsoleHandler.h \ - $$PWD/DapChainTransaction.h + include (../libdap/libdap.pri) include (../libdap-crypto/libdap-crypto.pri) @@ -78,7 +62,7 @@ include (../DapRPCProtocol/DapRPCProtocol.pri) INCLUDEPATH += $$_PRO_FILE_PWD_/../libCellFrameDashboardCommon/ $$_PRO_FILE_PWD_/../DapRPCProtocol/ - $$_PRO_FILE_PWD_/../cellframe-node/ + $$_PRO_FILE_PWD_/../cellframe-node/ unix: !mac : !android { service_target.files = $${BRAND}Service diff --git a/CellFrameDashboardService/CellFrameDashboardService.qrc b/CellFrameDashboardService/CellFrameDashboardService.qrc index e1b0195c21621b97fa3efbdcbd394dc84c164ac1..4d8ed6621d1502f356d84a5458adf1dead82f0c0 100644 --- a/CellFrameDashboardService/CellFrameDashboardService.qrc +++ b/CellFrameDashboardService/CellFrameDashboardService.qrc @@ -1,7 +1,3 @@ <RCC> - <qresource prefix="/"> - <file>Resources/Icons/add.png</file> - <file>Resources/Icons/icon.ico</file> - <file>Resources/Icons/icon.png</file> - </qresource> + <qresource prefix="/"/> </RCC> diff --git a/CellFrameDashboardService/DapChainConsoleHandler.cpp b/CellFrameDashboardService/DapChainConsoleHandler.cpp deleted file mode 100644 index c65b2aa344b19fcab50f070a6f912d79ba3228e2..0000000000000000000000000000000000000000 --- a/CellFrameDashboardService/DapChainConsoleHandler.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "DapChainConsoleHandler.h" - -#define MAX_COUNT_CMD 50 - -DapChainConsoleHandler::DapChainConsoleHandler(QObject *parent) : QObject(parent) -{ - QDir().mkpath(QFileInfo(CMD_LOG).path()); - m_File = new QFile(CMD_LOG, this); - m_File->open(QIODevice::Append | QIODevice::ReadWrite); -} - -QString DapChainConsoleHandler::getHistory() const -{ - if(!m_File->isOpen()) return QString(); - - quint8 countCmd = 0; - while (m_File->pos() > 0) - { - QByteArray symbol = m_File->read(1); - if(symbol == ">") ++countCmd; - m_File->seek(m_File->pos() - 2); - if(countCmd == MAX_COUNT_CMD) break; - } - - QByteArray lastCmd = m_File->read(m_File->size() - m_File->pos()); - - return QString::fromStdString(lastCmd.toStdString()); -} - -QString DapChainConsoleHandler::getResult(const QString& aQuery) const -{ - QProcess process; - process.start(QString(CLI_PATH) + " " + aQuery); - process.waitForFinished(-1); - - QByteArray returnSymbol = "\n"; - -#ifdef Q_OS_WIN - returnSymbol.prepend("\r"); -#endif - - QByteArray result = process.readAll(); - m_File->write("> " + aQuery.toUtf8() + returnSymbol); - m_File->write(result + returnSymbol); - m_File->flush(); - - return QString::fromStdString(result.toStdString()); -} diff --git a/CellFrameDashboardService/DapChainConsoleHandler.h b/CellFrameDashboardService/DapChainConsoleHandler.h deleted file mode 100644 index 0ba265ecba65ee7337e98839a13b2b8e2071052f..0000000000000000000000000000000000000000 --- a/CellFrameDashboardService/DapChainConsoleHandler.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef DAPCHAINCONSOLEHANDLER_H -#define DAPCHAINCONSOLEHANDLER_H - -#include <QObject> -#include <QProcess> -#include <QDebug> -#include <QFile> -#include <QDir> - -/// Class of recipient history commands -class DapChainConsoleHandler : public QObject -{ - Q_OBJECT - -private: - /// System file - QFile * m_File; - -public: - /// Standard constructor - explicit DapChainConsoleHandler(QObject *parent = nullptr); - - /// Get history of commands - /// @return history - QString getHistory() const; - /// Get result of command - /// @param command - /// @return command result - QString getResult(const QString& aQuery) const; -}; - -#endif // DAPCHAINCONSOLEHANDLER_H diff --git a/CellFrameDashboardService/DapChainDashboardService.cpp b/CellFrameDashboardService/DapChainDashboardService.cpp index d33f84b96effb9a08199c5e960ba5fcac1ec3de6..26195151364d7a79ba5c8811592fb33007f39d30 100755 --- a/CellFrameDashboardService/DapChainDashboardService.cpp +++ b/CellFrameDashboardService/DapChainDashboardService.cpp @@ -1,33 +1,10 @@ #include "DapChainDashboardService.h" -#include "DapSettings.h" - DapChainDashboardService::DapChainDashboardService() : DapRpcService(nullptr) { - // Log reader - m_pDapChainLogHandler = new DapChainLogHandler(this); - connect(m_pDapChainLogHandler, SIGNAL(onChangedLog()), SLOT(changedLogModel())); connect(this, &DapChainDashboardService::onNewClientConnected, [=] { qDebug() << "Frontend connected"; }); - - - m_pDapChainNodeHandler = new DapChainNodeNetworkHandler(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); - - m_pDapChainWalletHandler = new DapChainWalletHandler(this); - QObject::connect(m_pDapChainWalletHandler, &DapChainWalletHandler::walletDataChanged, this, &DapChainDashboardService::doSendNewWalletData); - m_pDapChainWalletHandler->setNetworkList(m_pDapChainNetworkHandler->getNetworkList()); - - m_pDapChainTransaction = new DapChainTransaction(this); - } bool DapChainDashboardService::start() @@ -49,188 +26,3 @@ bool DapChainDashboardService::start() } return true; } - -/// Get node logs. -/// @param aiTimeStamp Timestamp start reading logging. -/// @param aiRowCount Number of lines displayed. -/// @return Logs node. -QStringList DapChainDashboardService::getNodeLogs(int aiTimeStamp, int aiRowCount) -{ - qInfo() << QString("getNodeLogs(%1, %2)").arg(aiTimeStamp).arg(aiRowCount); - return m_pDapChainLogHandler->request(); -} - -QStringList DapChainDashboardService::addWallet(const QString &asWalletName) -{ - qInfo() << QString("addWallet(%1)").arg(asWalletName); - return m_pDapChainWalletHandler->createWallet(asWalletName); -} - -void DapChainDashboardService::removeWallet(const QString &asWalletName) -{ - qInfo() << QString("removeWallet(%1)").arg(asWalletName); - return m_pDapChainWalletHandler->removeWallet(asWalletName); -} - -QMap<QString, QVariant> DapChainDashboardService::getWallets() -{ - qInfo() << QString("getWallets()"); - - return m_pDapChainWalletHandler->getWallets(); -} - -QStringList DapChainDashboardService::getWalletInfo(const QString &asWalletName) -{ - qInfo() << QString("getWalletInfo(%1)").arg(asWalletName); - return m_pDapChainWalletHandler->getWalletInfo(asWalletName); -} - -QVariant DapChainDashboardService::getNodeNetwork() const -{ - return m_pDapChainNodeHandler->getNodeNetwork(); -} - -void DapChainDashboardService::setNodeStatus(const bool aIsOnline) -{ - m_pDapChainNodeHandler->setNodeStatus(aIsOnline); -} - -QVariant DapChainDashboardService::getHistory() const -{ - return m_pDapChainHistoryHandler->getHistory(); -} - -QString DapChainDashboardService::getQueryResult(const QString& aQuery) const -{ - return m_pDapChainConsoleHandler->getResult(aQuery); -} - -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() -{ - QMap<QString, QVariant> wallets = m_pDapChainWalletHandler->getWallets(); - m_pDapChainHistoryHandler->onRequestNewHistory(wallets); - /// TODO: for future -// QVariantList params = QVariantList() << wallets; -// DapRpcMessage request = DapRpcMessage::createRequest("RPCClient.setNewWallets", QJsonArray::fromVariantList(params)); -// m_pServer->notifyConnectedClients(request); -} - -void DapChainDashboardService::doSendNewHistory(const QVariant& aData) -{ - if(!aData.isValid()) return; - QVariantList params = QVariantList() << aData; - DapRpcMessage request = DapRpcMessage::createRequest("RPCClient.setNewHistory", QJsonArray::fromVariantList(params)); - m_pServer->notifyConnectedClients(request); -} - -void DapChainDashboardService::doSendNewWalletData(const QByteArray& aData) -{ - if(aData.isEmpty()) return; - QVariantList params = QVariantList() << aData.toHex(); - DapRpcMessage request = DapRpcMessage::createRequest("RPCClient.setNewWalletData", QJsonArray::fromVariantList(params)); - m_pServer->notifyConnectedClients(request); -} - -QString DapChainDashboardService::sendToken(const QString &asWalletName, const QString &asReceiverAddr, const QString &asToken, const QString &asAmount) -{ - qInfo() << QString("sendToken(%1;%2;%3;%4)").arg(asWalletName).arg(asReceiverAddr).arg(asToken).arg(asAmount); - return m_pDapChainWalletHandler->sendToken(asWalletName, asReceiverAddr, asToken, asAmount); -} - -void DapChainDashboardService::changedLogModel() -{ - qDebug() << "changedLogModel()"; - QJsonArray arguments; - m_pServer->notifyConnectedClients("RPCClient.processChangedLog", arguments); -} - -/// 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. -//void DapChainDashboardService::activateClient(const QSystemTrayIcon::ActivationReason& reason) -//{ -// qInfo() << "DapChainDashboardService::activateClient()"; -// switch (reason) -// { -// case QSystemTrayIcon::Trigger: -// { -// QJsonArray arguments; -// arguments.append(true); -// m_pServer->notifyConnectedClients("RPCClient.activateClient", arguments); -// } -// break; -// default: -// break; -// } -//} - -/// Shut down client. -void DapChainDashboardService::closeClient() -{ - qDebug() << "Close client"; - QJsonArray arguments; - m_pServer->notifyConnectedClients("RPCClient.closeClient", arguments); - // Signal-slot connection shutting down the service after closing the client - connect(m_pServer, SIGNAL(onClientDisconnected()), qApp, SLOT(quit())); -} - -/// System tray initialization. -//void DapChainDashboardService::initTray() -//{ -// QSystemTrayIcon *trayIconCellFrameDashboard = new QSystemTrayIcon(); -// trayIconCellFrameDashboard->setIcon(QIcon(":/Resources/Icons/icon.ico")); -// trayIconCellFrameDashboard->setToolTip("CellFrameDashboard"); -// QMenu * menuCellFrameDashboardService = new QMenu(); -// QAction * quitAction = new QAction("Выход"); -// menuCellFrameDashboardService->addAction(quitAction); -// trayIconCellFrameDashboard->setContextMenu(menuCellFrameDashboardService); -// trayIconCellFrameDashboard->show(); - -// // If the "Exit" menu item is selected, then we shut down the service, -// // and also send a command to shut down the client. -// connect(quitAction, &QAction::triggered, this, [=] -// { -// closeClient(); -// }); - -// // With a double click on the icon in the system tray, -// // we send a command to the client to activate the main window -// connect(trayIconCellFrameDashboard, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), -// this, SLOT(activateClient(QSystemTrayIcon::ActivationReason))); -//} - -bool DapChainDashboardService::appendWallet(const QString& aWalletName) const -{ - return m_pDapChainWalletHandler->appendWallet(aWalletName); -} - -QByteArray DapChainDashboardService::walletData() const -{ - return m_pDapChainWalletHandler->walletData(); -} - -bool DapChainDashboardService::createTransaction(const QString& aFromWallet, const QString& aToAddress, const QString& aTokenName, const QString& aNetwork, const quint64 aValue) -{ - return m_pDapChainTransaction->createTransaction(aFromWallet, aToAddress, aTokenName, aNetwork, aValue); -} - -void DapChainDashboardService::takeFromMempool(const QString& aNetwork) -{ - m_pDapChainTransaction->takeFromMempool(aNetwork); -} diff --git a/CellFrameDashboardService/DapChainDashboardService.h b/CellFrameDashboardService/DapChainDashboardService.h index 808cfbc896ce5d78604c4ef09a0eab8696612b7a..b299b65a9f9a5a4b8a7d0498cb0dd6ee66b6b128 100755 --- a/CellFrameDashboardService/DapChainDashboardService.h +++ b/CellFrameDashboardService/DapChainDashboardService.h @@ -13,9 +13,6 @@ #define DAPCHAINDASHBOARDSERVICE_H #include <QObject> -//#include <QSystemTrayIcon> -//#include <QMenu> -//#include <QAction> #include <QCoreApplication> #include "DapRpcAbstractServer.h" @@ -23,14 +20,6 @@ #include "DapRpcTCPServer.h" #include "DapRpcService.h" -#include "DapChainLogHandler.h" -#include "DapChainWalletHandler.h" -#include "DapChainNodeNetworkHandler.h" -#include "DapChainHistoryHandler.h" -#include "DapChainNetworkHandler.h" -#include "DapChainConsoleHandler.h" -#include "DapChainTransaction.h" - #include <QLocalServer> typedef class DapRpcLocalServer DapUiService; @@ -41,11 +30,6 @@ typedef class DapRpcLocalServer DapUiService; * Work with serves start from public methos start(). * Class consist of follow handlers: * @see DapChainLogHandler - * @see DapChainWalletHandler - * @see DapChainNodeNetworkHandler - * @see DapChainHistoryHandler - * @see DapChainConsoleHandler - * @see DapChainNetworkHandler */ class DapChainDashboardService : public DapRpcService { @@ -53,20 +37,6 @@ class DapChainDashboardService : public DapRpcService Q_CLASSINFO("serviceName", "RPCServer") /// Service core. DapUiService * m_pServer {nullptr}; - /// Recipient logs information - DapChainLogHandler * m_pDapChainLogHandler {nullptr}; - /// Recipient wallet information - DapChainWalletHandler * m_pDapChainWalletHandler {nullptr}; - /// Recipient node network - DapChainNodeNetworkHandler * m_pDapChainNodeHandler {nullptr}; - /// Recipient history of transactions - DapChainHistoryHandler* m_pDapChainHistoryHandler {nullptr}; - /// Recipient history of commands - DapChainConsoleHandler* m_pDapChainConsoleHandler {nullptr}; - /// Recipient network's name - DapChainNetworkHandler* m_pDapChainNetworkHandler {nullptr}; - - DapChainTransaction* m_pDapChainTransaction {nullptr}; public: /// Standard Ñonstructor. @@ -77,94 +47,6 @@ public: signals: /// The signal is emitted in case of successful connection of a new client. void onNewClientConnected(); - // TODO get structure Settings which has method fill from jsonDocument - /// The signal is emitted in case of need to save setting - void onSaveSetting(); - -public slots: - /// Change log model - void changedLogModel(); - /// 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. -// void activateClient(const QSystemTrayIcon::ActivationReason& reason); - /// Shut down client. - void closeClient(); - /// System tray initialization. - //void initTray(); - /// Get node logs. - /// @param aiTimeStamp Timestamp start reading logging. - /// @param aiRowCount Number of lines displayed. - /// @return Logs node. - QStringList getNodeLogs(int aiTimeStamp, int aiRowCount); - /// Add new wallet - QStringList addWallet(const QString &asWalletName); - /// Remove wallet - void removeWallet(const QString &asWalletName); - /// Get wallet - /// @return data for wallets - QMap<QString, QVariant> getWallets(); - /// Get information of wallet such as balance, currencies - /// @param number of wallet - /// @return data for the wallet - QStringList getWalletInfo(const QString &asWalletName); - /// Create new transactio - /// @param name of wallet - /// @param address of a receiver - /// @param name of token - /// @param sum for transaction - /// @return result of trasaction - QString sendToken(const QString &asWalletName, const QString &asReceiverAddr, const QString &asToken, const QString &asAmount); - /// Get node network - /// @return QMap node network - QVariant getNodeNetwork() const; - /// Receive new status for node - /// @param true if online - void setNodeStatus(const bool aIsOnline); - /// 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 - QString getQueryResult(const QString& aQuery) const; - /// Get history of commands - /// @return history of last 50 commands - QString getCmdHistory() const; - - /// Add new wallet - /// @param wallet name - /// @return sucessful or not - bool appendWallet(const QString& aWalletName) const; - /// Wallets data - /// @return data - QByteArray walletData() const; - /// Putting new transaction in mempool - /// @param name of wallet - /// @param address of a receiver - /// @param name of token - /// @param name of network - /// @param sum for transaction - /// @return sucessful or not - bool createTransaction(const QString& aFromWallet, const QString& aToAddress, const QString& aTokenName, const QString& aNetwork, const quint64 aValue); - /// Taking everything from mempool - /// @param network - void takeFromMempool(const QString& aNetwork); - -private slots: - /// Request new history request by handle wallet's name - void doRequestWallets(); - /// Send new history transaction to client - /// @param New history transaction - void doSendNewHistory(const QVariant& aData); - /// Taking everything from mempool - /// @param network - void doSendNewWalletData(const QByteArray& aData); }; #endif // DAPCHAINDASHBOARDSERVICE_H diff --git a/CellFrameDashboardService/DapChainHistoryHandler.cpp b/CellFrameDashboardService/DapChainHistoryHandler.cpp deleted file mode 100644 index 71c10a7faeb09681ecbd3bde6c78a496e78c036c..0000000000000000000000000000000000000000 --- a/CellFrameDashboardService/DapChainHistoryHandler.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "DapChainHistoryHandler.h" - -DapChainHistoryHandler::DapChainHistoryHandler(QObject *parent) : - QObject(parent) -{ - m_timoutRequestHistory = new QTimer(this); - QObject::connect(m_timoutRequestHistory, &QTimer::timeout, this, &DapChainHistoryHandler::requsetWallets, Qt::QueuedConnection); - m_timoutRequestHistory->start(3000); -} - -QVariant DapChainHistoryHandler::getHistory() const -{ - return m_history; -} - -void DapChainHistoryHandler::onRequestNewHistory(const QMap<QString, QVariant>& aWallets) -{ - QList<QVariant> wallets = aWallets.values(); - if(wallets.isEmpty()) return; - - QList<QVariant> data; - for(int i = 0; i < wallets.count(); i++) - { - QProcess process; - 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(); - - if(!result.isEmpty()) - { - QRegularExpression regular("((\\w{3}\\s+){2}\\d{1,2}\\s+(\\d{1,2}:*){3}\\s+\\d{4})\\s+(\\w+)\\s+(\\d+)\\s(\\w+)\\s+\\w+\\s+([\\w\\d]+)", QRegularExpression::MultilineOption); - QRegularExpressionMatchIterator matchItr = regular.globalMatch(result); - while (matchItr.hasNext()) - { - QRegularExpressionMatch match = matchItr.next(); - QStringList dataItem = QStringList() - << match.captured(1) - << QString::number(DapTransactionStatusConvertor::getStatusByShort(match.captured(4))) - << match.captured(5) - << match.captured(6) - << match.captured(7) - << wallets.at(i).toString(); - data << dataItem; - - } - } - } - - - if(m_history != data) - { - m_history = data; - 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 deleted file mode 100644 index 61b45dfb4f1b9ee5b6b6dfebcc84df9ce3709d87..0000000000000000000000000000000000000000 --- a/CellFrameDashboardService/DapChainHistoryHandler.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef DAPCHAINHISTORYHANDLER_H -#define DAPCHAINHISTORYHANDLER_H - -#include <QtGlobal> -#include <QObject> -#include <QVariantList> -#include <QTimer> -#include <QProcess> -#include <QDebug> -#include <QList> -#include <QRegularExpression> - -#include "DapHistoryType.h" - -class DapChainHistoryHandler : public QObject -{ - Q_OBJECT - -private: - QString m_CurrentNetwork; - QVariant m_history; - QTimer* m_timoutRequestHistory; - -public: - explicit DapChainHistoryHandler(QObject *parent = nullptr); - - /// Get current state of history - /// @return data - QVariant getHistory() const; - -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 - void requsetWallets(); - /// Signal about getting new transatcion history - /// @param data of history QList<QVariant>. - /// QVariant is QStringList. QStringList consists - /// 0: date - /// 1: status - /// 2: currency - /// 3: token - /// 4: wallet_to - /// 5: wallet_from - void changeHistory(QVariant); -}; - -#endif // DAPCHAINHISTORYHANDLER_H diff --git a/CellFrameDashboardService/DapChainLogHandler.cpp b/CellFrameDashboardService/DapChainLogHandler.cpp deleted file mode 100755 index 6f5cbaae7c0d79df63c7f92030e3386124052fde..0000000000000000000000000000000000000000 --- a/CellFrameDashboardService/DapChainLogHandler.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "DapChainLogHandler.h" - -#include <QRegularExpression> - -DapChainLogHandler::DapChainLogHandler(QObject *parent) : QObject(parent) -{ - m_fileSystemWatcher.addPath(LOG_FILE); - - connect(&m_fileSystemWatcher, &QFileSystemWatcher::fileChanged, this, [=] (const QString& asFile) { - Q_UNUSED(asFile) - m_fileSystemWatcher.addPath(LOG_FILE); - emit onChangedLog(); - }); -} - -QStringList DapChainLogHandler::request() -{ - QFile file(LOG_FILE); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) - { - qWarning() << "Failed to open file " << file.fileName(); - return QStringList(); - } - else - { - QTextStream in(&file); - in.seek(m_currentCaretPosition); - const QRegularExpression re("(\\[\\d\\d\\/\\d\\d\\/\\d\\d\\-\\d\\d\\:\\d\\d\\:\\d\\d])\\s(\\[\\w+\\])\\s(\\[\\w+\\])(.+)"); - - QStringList listLogs; - while (!in.atEnd()) { - const QString line = in.readLine(); - const auto match = re.match(line); - if(!match.hasMatch()) - continue; - - const QString matchedLog = match.captured(); - listLogs.append(matchedLog); - m_currentCaretPosition += matchedLog.length(); - } - - return listLogs; - - } -} diff --git a/CellFrameDashboardService/DapChainLogHandler.h b/CellFrameDashboardService/DapChainLogHandler.h deleted file mode 100644 index 78d67fd7376969513a8422bc6106d39d214a5363..0000000000000000000000000000000000000000 --- a/CellFrameDashboardService/DapChainLogHandler.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef DAPCHAINLOGHANDLER_H -#define DAPCHAINLOGHANDLER_H - -#include <QObject> -#include <QString> -#include <QProcess> -#include <algorithm> -#include <QFile> -#include <QFileSystemWatcher> -#include <QDebug> - -#include "DapLogMessage.h" - -/// Class read logs from system file when it's changed -class DapChainLogHandler : public QObject -{ - Q_OBJECT - - /// Log file change watcher. - QFileSystemWatcher m_fileSystemWatcher; - /// Current caret position in log file - qint64 m_currentCaretPosition{0}; -public: - /// Standard constructor - /// Add path to system logs file - explicit DapChainLogHandler(QObject *parent = nullptr); - -signals: - /// The signal is emitted when system logs file was changed - void onChangedLog(); - -public slots: - /// Request new logs from system logs file - /// @return list of new logs - QStringList request(); -}; - -#endif // DAPCHAINLOGHANDLER_H diff --git a/CellFrameDashboardService/DapChainNetworkHandler.cpp b/CellFrameDashboardService/DapChainNetworkHandler.cpp deleted file mode 100644 index 7abc34e13603c39405f72d73964dbcd848ab0675..0000000000000000000000000000000000000000 --- a/CellFrameDashboardService/DapChainNetworkHandler.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#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 deleted file mode 100644 index c3e84c727fe6c14d04c51658552a53836382c054..0000000000000000000000000000000000000000 --- a/CellFrameDashboardService/DapChainNetworkHandler.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef DAPCHAINNETWORKHANDLER_H -#define DAPCHAINNETWORKHANDLER_H - -#include <QObject> -#include <QString> -#include <QProcess> - -#include <QFile> - -/// Class provides to get network's name list -class DapChainNetworkHandler : public QObject -{ - Q_OBJECT - -private: - /// List of network's name - QStringList m_NetworkList; - -public: - /// Standard constructor - explicit DapChainNetworkHandler(QObject *parent = nullptr); - - /// Get network list - /// @return Network list - QStringList getNetworkList(); -}; - -#endif // DAPCHAINNETWORKHANDLER_H diff --git a/CellFrameDashboardService/DapChainNode.cpp b/CellFrameDashboardService/DapChainNode.cpp deleted file mode 100644 index a401f9bdf38fe191dd9780aa28a4b4c3a10ce878..0000000000000000000000000000000000000000 --- a/CellFrameDashboardService/DapChainNode.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "DapChainNode.h" - -DapChainNode::DapChainNode(QObject *parent) : QObject(parent) -{ - -} diff --git a/CellFrameDashboardService/DapChainNode.h b/CellFrameDashboardService/DapChainNode.h deleted file mode 100644 index 17fd7a59ee7a569c9dda5453072d40c75b76df06..0000000000000000000000000000000000000000 --- a/CellFrameDashboardService/DapChainNode.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef DAPCHAINNODE_H -#define DAPCHAINNODE_H - -#include <QObject> - -class DapChainNode : public QObject -{ - Q_OBJECT -public: - explicit DapChainNode(QObject *parent = nullptr); - -signals: - -public slots: -}; - -#endif // DAPCHAINNODE_H \ No newline at end of file diff --git a/CellFrameDashboardService/DapChainNodeCache.cpp b/CellFrameDashboardService/DapChainNodeCache.cpp deleted file mode 100644 index b7874dff69638ce53ee5a381a87ddf0f3b3ea26f..0000000000000000000000000000000000000000 --- a/CellFrameDashboardService/DapChainNodeCache.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "DapChainNodeCache.h" - -DapChainNodeCache::DapChainNodeCache(QObject *parent) : QObject(parent) -{ - -} diff --git a/CellFrameDashboardService/DapChainNodeCache.h b/CellFrameDashboardService/DapChainNodeCache.h deleted file mode 100644 index 2404694b73175474ec2febf18b884db91f59b7ff..0000000000000000000000000000000000000000 --- a/CellFrameDashboardService/DapChainNodeCache.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef DAPCHAINNODECACHE_H -#define DAPCHAINNODECACHE_H - -#include <QObject> - -class DapChainNodeCache : public QObject -{ - Q_OBJECT -public: - explicit DapChainNodeCache(QObject *parent = nullptr); - -signals: - -public slots: -}; - -#endif // DAPCHAINNODECACHE_H \ No newline at end of file diff --git a/CellFrameDashboardService/DapChainNodeNetworkHandler.cpp b/CellFrameDashboardService/DapChainNodeNetworkHandler.cpp deleted file mode 100644 index 88edcd25f6c19cbd8db31fa1e38386c4cb416860..0000000000000000000000000000000000000000 --- a/CellFrameDashboardService/DapChainNodeNetworkHandler.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include "DapChainNodeNetworkHandler.h" - - -DapChainNodeNetworkHandler::DapChainNodeNetworkHandler(QObject *parent) : QObject(parent) -{ - -} - -const QString &DapChainNodeNetworkHandler::getCurrentNetwork() const -{ - return m_CurrentNetwork; -} - -QVariant DapChainNodeNetworkHandler::getNodeNetwork() const -{ - QProcess process; - process.start(QString("%1 node dump -net %2 -full").arg(CLI_PATH).arg(m_CurrentNetwork)); - process.waitForFinished(-1); - - QByteArray result = process.readAll(); - - QMap<QString, QVariant> nodeMap; - - if(!result.isEmpty()) - { - QStringList nodes = QString::fromStdString(result.toStdString()).split("node "); - for(int m = 1; m < nodes.count(); m++) - { - QString node = nodes.at(m); - QStringList nodeData; - QRegExp rx_node("address ((?:[0-9A-F]{4}::){3}[0-9A-F]{4}).+" - "cell (0[xX][0-9A-F]{16}).+" - "ipv4 ((?:[0-9]{1,3}\\.){3}[0-9]{1,3}).+" - "ipv6 ::.+" - "alias (\\S+).+" - "links (\\d+).+"); - - rx_node.indexIn(node, 0); - for(int i = 2; i < 6; i++) nodeData << rx_node.cap(i); - - if(nodeData.last().toUInt() > 0) - { - QRegExp rx_links("link\\d+ address : ((?:[0-9A-F]{4}::){3}[0-9A-F]{4})"); - int pos = 0; - while ((pos = rx_links.indexIn(node, pos)) != -1) - { - nodeData << rx_links.cap(1); - pos += rx_links.matchedLength(); - } - } - - nodeMap[rx_node.cap(1)] = nodeData; - } - } - - - QProcess process_status; - process_status.start(QString(CLI_PATH) + " net -net " + m_CurrentNetwork + " get status"); - - process_status.waitForFinished(-1); - QByteArray result_status = process_status.readAll(); - - if(!result_status.isEmpty()) - { - QRegExp reg_exp("Network \"([\\w\\W]+)\" has state (\\w+).+, " - "active links \\d+ from \\d+, cur node address ((?:[0-9A-F]{4}::){3}[0-9A-F]{4})"); - - reg_exp.indexIn(result_status, 0); - nodeMap["current"] = QStringList() << reg_exp.cap(3) << reg_exp.cap(2); - } - - 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 %1 go %2").arg(m_CurrentNetwork).arg(aIsOnline ? "online" : "offline")); - process.waitForFinished(-1); -} diff --git a/CellFrameDashboardService/DapChainNodeNetworkHandler.h b/CellFrameDashboardService/DapChainNodeNetworkHandler.h deleted file mode 100644 index 6a38ab1cd88e857356e51b48fc6a898a44f7f970..0000000000000000000000000000000000000000 --- a/CellFrameDashboardService/DapChainNodeNetworkHandler.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef DAPCHAINNODENETWORKHANDLER_H -#define DAPCHAINNODENETWORKHANDLER_H - -#include <QObject> -#include <QProcess> -#include <QRegExp> -#include <QDebug> -#include <QDataStream> - -#include "DapNodeType.h" - -/// Class provides to operations with nodes of network -class DapChainNodeNetworkHandler : public QObject -{ - Q_OBJECT - -private: - /// Current network's name - QString m_CurrentNetwork; - -public: - /// Standard constructor - explicit DapChainNodeNetworkHandler(QObject *parent = nullptr); - -public: - /// Get current network name - /// @return name of current network - const QString& getCurrentNetwork() const; - -public slots: - /// Change status of a node - /// @param it is true if a node is online - void setNodeStatus(const bool aIsOnline); - /// 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/DapChainTransaction.cpp b/CellFrameDashboardService/DapChainTransaction.cpp deleted file mode 100644 index 62f0ef9638aec207d30134d2e390f31de732ff15..0000000000000000000000000000000000000000 --- a/CellFrameDashboardService/DapChainTransaction.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "DapChainTransaction.h" - -DapChainTransaction::DapChainTransaction(QObject *parent) : QObject(parent) -{ - -} - -bool DapChainTransaction::createTransaction(const QString& aFromWallet, const QString& aToAddress, const QString& aTokenName, const QString& aNetwork, const quint64 aValue) const -{ - QProcess processCreate; - processCreate.start(QString("%1 tx_create -net %2 -chain gdb -from_wallet %3 -to_addr %4 -token %5 -value %6") - .arg(CLI_PATH) - .arg(aNetwork) - .arg(aFromWallet) - .arg(aToAddress) - .arg(aTokenName) - .arg(QString::number(aValue))); - processCreate.waitForFinished(-1); - QByteArray result = processCreate.readAll(); - - QRegExp rx("transfer=(\\w+)"); - rx.indexIn(result, 0); - - if(rx.cap(1) == "Ok") - { - return true; - } - - return false; -} - -void DapChainTransaction::takeFromMempool(const QString& aNetwork) -{ - QProcess processMempool; - processMempool.start(QString("%1 mempool_proc -net " + aNetwork +" -chain gdb").arg(CLI_PATH)); - processMempool.waitForFinished(-1); - processMempool.readAll(); -} diff --git a/CellFrameDashboardService/DapChainTransaction.h b/CellFrameDashboardService/DapChainTransaction.h deleted file mode 100644 index e7a3a3a5e4418fccd02acf59208a65fd733e21fd..0000000000000000000000000000000000000000 --- a/CellFrameDashboardService/DapChainTransaction.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef DAPCHAINTRANSACTION_H -#define DAPCHAINTRANSACTION_H - -#include <QObject> -#include <QProcess> -#include <QDebug> - -class DapChainTransaction : public QObject -{ - Q_OBJECT - -public: - explicit DapChainTransaction(QObject *parent = nullptr); - - /// Request for creation new transaction - /// @param name of wallet - /// @param address of a receiver - /// @param name of token - /// @param name of network - /// @param sum for transaction - /// @return result of trying to do transaction - bool createTransaction(const QString& aFromWallet, const QString& aToAddress, const QString& aTokenName, const QString& aNetwork, const quint64 aValue) const; - - /// Taking everything from mempool - /// @param network - void takeFromMempool(const QString& aNetwork); -}; - -#endif // DAPCHAINTRANSACTION_H diff --git a/CellFrameDashboardService/DapChainWalletHandler.cpp b/CellFrameDashboardService/DapChainWalletHandler.cpp deleted file mode 100755 index fd61172fe0e2c4b658922572d765ad74ddb94baa..0000000000000000000000000000000000000000 --- a/CellFrameDashboardService/DapChainWalletHandler.cpp +++ /dev/null @@ -1,211 +0,0 @@ -#include "DapChainWalletHandler.h" -#include <QDebug> -#include <QRegularExpression> - -DapChainWalletHandler::DapChainWalletHandler(QObject *parent) : QObject(parent) -{ - m_timeout = new QTimer(this); - QObject::connect(m_timeout, &QTimer::timeout, this, &DapChainWalletHandler::onReadWallet); - m_timeout->setInterval(5000); - m_timeout->start(); -} - -bool DapChainWalletHandler::appendWallet(const QString& aWalletName) -{ - QProcess process; - process.start(QString("%1 wallet new -w %2").arg(CLI_PATH).arg(aWalletName)); - process.waitForFinished(-1); - QByteArray result = process.readAll(); - - QRegExp rx("new address\\s(\\w+)"); - return rx.indexIn(result, 0); -} - -QByteArray DapChainWalletHandler::walletData() const -{ - QByteArray data; - QDataStream out(&data, QIODevice::WriteOnly); - out << m_walletList; - - return data; -} - -void DapChainWalletHandler::onReadWallet() -{ - QList<QPair<DapChainWalletData, QList<DapChainWalletTokenData>>> walletList; - - QProcess process; - process.start(QString("%1 wallet list").arg(CLI_PATH)); - process.waitForFinished(-1); - QByteArray result = process.readAll(); - QRegularExpression rx("wallet:\\s(.+)\\s+addr:\\s(.+)", QRegularExpression::MultilineOption); - QRegularExpressionMatchIterator itr = rx.globalMatch(result); - while (itr.hasNext()) - { - QRegularExpressionMatch match = itr.next(); - QString walletName = match.captured(1); - - for(int i = 0; i < m_networkList.count(); i++) - { - DapChainWalletData wallet; - wallet.Name = walletName; - wallet.Network = m_networkList.at(i); - QPair<DapChainWalletData, QList<DapChainWalletTokenData>> walletPair(wallet, QList<DapChainWalletTokenData>()); - - QProcess process_token; - process_token.start(QString("%1 wallet info -w %2 -net %3") - .arg(CLI_PATH) - .arg(walletName) - .arg(m_networkList.at(i))); - - process_token.waitForFinished(-1); - QByteArray result_tokens = process_token.readAll(); - QRegExp regex("wallet: (.+)\\s+addr:\\s+(.+)\\s+(balance)|(\\d+.\\d+)\\s\\((\\d+)\\)\\s(\\w+)"); - - int pos = 0; - while((pos = regex.indexIn(result_tokens, pos)) != -1) - { - DapChainWalletTokenData token; - if(!regex.cap(2).isEmpty()) - { - walletPair.first.Address = regex.cap(2); - } - else - { - token.Balance = regex.cap(4).toDouble(); - token.Emission = regex.cap(5).toUInt(); - token.Name = regex.cap(6); - walletPair.second.append(token); - } - - pos += regex.matchedLength(); - } - - walletList.append(walletPair); - } - - } - - if(m_walletList != walletList) - { - m_walletList = walletList; - emit walletDataChanged(walletData()); - } -} - -void DapChainWalletHandler::setNetworkList(const QStringList& aNetworkList) -{ - if(m_networkList == aNetworkList) return; - m_networkList = aNetworkList; -} - - - - - - - - - - -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(CLI_PATH).arg(asNameWallet)); - process.waitForFinished(-1); - result = process.readAll(); - QStringList list; - list.append(asNameWallet); - list.append(parse(result)); - return result.isEmpty() ? QStringList() : list; -} - -void DapChainWalletHandler::removeWallet(const QString &asNameWallet) -{ - QByteArray result; - QProcess process; - process.start(QString("rm %1%2.dwallet").arg("/opt/cellframe-node/var/lib/wallet/").arg(asNameWallet)); - qDebug() << (QString("rm %1%2.dwallet").arg("/opt/cellframe-node/var/lib/wallet/").arg(asNameWallet)); - process.waitForFinished(-1); - result = process.readAll(); -} - -QMap<QString, QVariant> DapChainWalletHandler::getWallets() -{ - QMap<QString, QVariant> map; - QProcess process; - process.start(QString("%1 wallet list").arg(CLI_PATH)); - process.waitForFinished(-1); - QByteArray result = process.readAll(); - QRegularExpression rx("wallet:\\s(.+)\\s+addr:\\s(.+)", QRegularExpression::MultilineOption); - QRegularExpressionMatchIterator itr = rx.globalMatch(result); - while (itr.hasNext()) { - QRegularExpressionMatch match = itr.next(); - map[match.captured(1)] = match.captured(2); - } - - return map; -} - -QStringList DapChainWalletHandler::getWalletInfo(const QString &asNameWallet) -{ - QProcess process; - process.start(QString("%1 wallet info -w %2 -net private").arg(CLI_PATH).arg(asNameWallet)); - process.waitForFinished(-1); - QByteArray result = process.readAll(); - QRegExp rx("wallet: (.+)\\s+addr:\\s+(\\w+)\\s+(balance)|(\\d+.\\d+)\\s(\\(\\d+\\))\\s(\\w+)"); - QStringList list; - - int pos = 0; - while((pos = rx.indexIn(result, pos)) != -1) - { - if(rx.cap(1).isEmpty()) - list << rx.cap(4) << rx.cap(5) << rx.cap(6); - else - list << rx.cap(1) << rx.cap(2) << rx.cap(3); - - pos += rx.matchedLength(); - } - - return list; -} - -QString DapChainWalletHandler::sendToken(const QString &asSendWallet, const QString &asAddressReceiver, const QString &asToken, const QString &aAmount) -{ - 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 %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) ); - 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 " + 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 deleted file mode 100755 index 5b3d3cd46be657ce045f1870d50c0eda761f2f68..0000000000000000000000000000000000000000 --- a/CellFrameDashboardService/DapChainWalletHandler.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef DAPCHAINWALLETHANDLER_H -#define DAPCHAINWALLETHANDLER_H - -#include <QObject> -#include <QProcess> -#include <QRegExp> -#include <QDebug> -#include <QTimer> -#include "DapChainWallet.h" - -/// Class provides operations at wallets -class DapChainWalletHandler : public QObject -{ - Q_OBJECT - -private: - QStringList m_networkList; - QList<QPair<DapChainWalletData, QList<DapChainWalletTokenData>>> m_walletList; - QTimer* m_timeout; - -public: - /// Standard constructor - explicit DapChainWalletHandler(QObject *parent = nullptr); - - bool appendWallet(const QString& aWalletName); - - QByteArray walletData() const; - -private slots: - - void onReadWallet(); - -public slots: - - void setNetworkList(const QStringList& aNetworkList); - -signals: - - void walletDataChanged(QByteArray data); - - - - - - -private: - /// Current network's name - QString m_CurrentNetwork; - -protected: - /// Parse address of wallet from console command - /// @param aWalletAddress Console command to create new wallet's address - /// @return Address of wallet - virtual QString parse(const QByteArray& aWalletAddress); - -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 diff --git a/CellFrameDashboardService/Resources/Icons/add.png b/CellFrameDashboardService/Resources/Icons/add.png deleted file mode 100644 index f3c75ff7cc06fe9833492a80f6bd7ddcfefe3072..0000000000000000000000000000000000000000 Binary files a/CellFrameDashboardService/Resources/Icons/add.png and /dev/null differ diff --git a/CellFrameDashboardService/Resources/Icons/icon.ico b/CellFrameDashboardService/Resources/Icons/icon.ico deleted file mode 100644 index 41230db92cb8101b8f24cf6f861082c6dfb827e1..0000000000000000000000000000000000000000 Binary files a/CellFrameDashboardService/Resources/Icons/icon.ico and /dev/null differ diff --git a/CellFrameDashboardService/Resources/Icons/icon.png b/CellFrameDashboardService/Resources/Icons/icon.png deleted file mode 100644 index 52525ef9e99b9d42242dcddc0f5f5a25eaeee901..0000000000000000000000000000000000000000 Binary files a/CellFrameDashboardService/Resources/Icons/icon.png and /dev/null differ diff --git a/CellFrameDashboardService/main.cpp b/CellFrameDashboardService/main.cpp index 057ae38933aaad6c0c7cd8b0f5e96088e6d25d5d..06b2451e963fa778fb9b424aff32c32e30157d53 100755 --- a/CellFrameDashboardService/main.cpp +++ b/CellFrameDashboardService/main.cpp @@ -2,14 +2,13 @@ #include <QSystemSemaphore> #include <QSharedMemory> #include <QCommandLineParser> +#include <QProcess> #include <unistd.h> #include "DapHalper.h" #include "DapChainDashboardService.h" #include "DapLogger.h" -#include "DapChainLogHandler.h" -#include "DapSettings.h" #include <sys/stat.h> diff --git a/CellFrameDashboardTests/.gitignore b/CellFrameDashboardTests/.gitignore deleted file mode 100644 index fab7372d796ea95c80d02df6caa7eb2b411a7ac1..0000000000000000000000000000000000000000 --- a/CellFrameDashboardTests/.gitignore +++ /dev/null @@ -1,73 +0,0 @@ -# This file is used to ignore files which are generated -# ---------------------------------------------------------------------------- - -*~ -*.autosave -*.a -*.core -*.moc -*.o -*.obj -*.orig -*.rej -*.so -*.so.* -*_pch.h.cpp -*_resource.rc -*.qm -.#* -*.*# -core -!core/ -tags -.DS_Store -.directory -*.debug -Makefile* -*.prl -*.app -moc_*.cpp -ui_*.h -qrc_*.cpp -Thumbs.db -*.res -*.rc -/.qmake.cache -/.qmake.stash - -# qtcreator generated files -*.pro.user* - -# xemacs temporary files -*.flc - -# Vim temporary files -.*.swp - -# Visual Studio generated files -*.ib_pdb_index -*.idb -*.ilk -*.pdb -*.sln -*.suo -*.vcproj -*vcproj.*.*.user -*.ncb -*.sdf -*.opensdf -*.vcxproj -*vcxproj.* - -# MinGW generated files -*.Debug -*.Release - -# Python byte code -*.pyc - -# Binaries -# -------- -*.dll -*.exe - diff --git a/CellFrameDashboardTests/CellFrameDashboardTests.pro b/CellFrameDashboardTests/CellFrameDashboardTests.pro deleted file mode 100644 index 42b3c415152a2087195cc7bd5cff0fbe05ba0a42..0000000000000000000000000000000000000000 --- a/CellFrameDashboardTests/CellFrameDashboardTests.pro +++ /dev/null @@ -1,18 +0,0 @@ -include(gtest_dependency.pri) -include (../libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri) - -QT += core network -QT -= gui -QT += qml - -TEMPLATE = app -CONFIG += console c++11 -CONFIG -= app_bundle -CONFIG += thread -CONFIG += qt - -SOURCES += \ - DapSettingsTests.cpp \ - main.cpp - -INCLUDEPATH += $$_PRO_FILE_PWD_/../libCellFrameDashboardCommon/ diff --git a/CellFrameDashboardTests/DapSettingsTests.cpp b/CellFrameDashboardTests/DapSettingsTests.cpp deleted file mode 100644 index a21c88c37a31ddec5db8fe4730694bc5756ec851..0000000000000000000000000000000000000000 --- a/CellFrameDashboardTests/DapSettingsTests.cpp +++ /dev/null @@ -1,158 +0,0 @@ -#include "gtest/gtest.h" - -#include "DapSettings.h" - -#include <QJsonDocument> -#include <QJsonObject> - -TEST(DapSettingsTest, settingFileName) -{ - // set filename to setting file - // 1. set filename to settings - // 2. check what filename in DapSettings equal - - // 1. set filename to settings - const QString filename = "settings.json"; - DapSettings::getInstance().setFileName(filename); - - // 2. check what filename in DapSettings equal - EXPECT_EQ(DapSettings::getInstance().getFileName(), filename); -} - -TEST(DapSettingsTest, writeFile) -{ - // test for check write and read data in file - // 1. Write to file data - // 2. Read from file data - // 3. Compare data - - // 1. Write to file data - QJsonObject object; - const QString networkName = "test"; - object["network"] = networkName; - const QString filename = "settings.json"; - DapSettings::getInstance(filename).writeFile(QJsonDocument(object)); - - // 2. Read from file data - const QJsonDocument dataFromFile = DapSettings::getInstance(filename).readFile(); - - // 3. Compare data - EXPECT_EQ(dataFromFile.object(), object); - -} - -TEST(DapSettingsTest, FailedReadFromNotExistingFile) -{ - // test for check failed reading when file doesn't exist - // 1. Read from empty file. Example: "notexist.json" - // 2. Check what readed jsonDocument is null - - // 1. Read from empty file. Example: "notexist.json" - const QString filename = "notexist.json"; - DapSettings::getInstance(filename).setFileName(filename); - const QJsonDocument notExistingDocument = DapSettings::getInstance(filename).readFile(); - - // 2. Check what readed jsonDocument is empty - EXPECT_TRUE(notExistingDocument.isNull()); -} - -TEST(DapSettingsTest, FailedReadFromEmptyFile) -{ - // test for check failed reading when file is empty - // 1. Creating empty file - // 2. Read from empty file. Example: "empty.json". Create this file - // 3. Check what readed jsonDocument is empty - - // 1. Creating empty file - const QString filename = "empty.json"; - DapSettings::getInstance(filename).writeFile(QJsonDocument()); - - // 2. Read from empty file. Example: "empty.json" - QJsonDocument emptyDocument = DapSettings::getInstance(filename).readFile(); - - // 3. Check what readed jsonDocument is empty - EXPECT_TRUE(emptyDocument.isEmpty()); -} - -TEST(DapSettingsTest, FailedWriteEmptyData) -{ - // test for check failed write empty data - // 1. Check what Failed write empty data to file. Example: "emptyData.json" - - // 1. Check what Failed write empty data to file. Example: "emptyData.json" - EXPECT_FALSE(DapSettings::getInstance("emptyData.json").writeFile(QJsonDocument())); -} - -TEST(DapSettingsTest, SetKeyValue) -{ - // test for check set key value to file - // 1. Set key value to file. Example: "keys.json" - // 2. Get value from file - // 3. Comparing values are equal - - // 1. Set key value to file. Example: "keys.json" - const QString filename = "keys.json"; - DapSettings::getInstance(filename).setFileName(filename); - const QString key = "key"; - const QString value = "value"; - DapSettings::getInstance(filename).setKeyValue(key, value); - - // 2. Get value from file - const QVariant gettingValue = DapSettings::getInstance(filename).getKeyValue(key); - - // 3. Comparing values are equal - EXPECT_EQ(value, gettingValue.toString()); -} - -TEST(DapSettingsTest, FailedSetKeyValueByEmptyKey) -{ - // test for check failed set key value by empty key - // 1. Check what value doesn't write to file by empty key. Example: "keys.json" - - // 1. Check what value doesn't write to file by empty key. Example: "keys.json" - EXPECT_FALSE(DapSettings::getInstance("keys.json").setKeyValue("", "value")); -} - -TEST(DapSettingsTest, FailedSetEmptyKeyValue) -{ - // test for check failed set empty key value - // 1. Check what empty value doesn't write to file. Example: "keys.json" - - // 1. Check what empty value doesn't write to file. Example: "keys.json" - EXPECT_FALSE(DapSettings::getInstance("keys.json").setKeyValue("key", QVariant())); -} - -TEST(DapSettingsTest, SetGroupValue) -{ - // test check for setting group value in file - // 1. Set group value in file. Example: "group.json" - // 2. Get group value from file - // 3. Compare two values - - // 1. Set group value in file. Example: "group.json" - const QVariantMap map { {"1", "A"}, {"2", "B"} }; - QList<QVariantMap> list; - list.append(map); - const QString filename = "group.json"; - const QString key = "group"; - DapSettings::getInstance(filename).setGroupValue(key, list); - - // 2. Get group value from file - auto gettingList = DapSettings::getInstance(filename).getGroupValue(key); - - // 3. Compare two values - EXPECT_EQ(list, gettingList); -} - -TEST(DapSettingsTest, FailedSetGroupValueByEmptyGroupName) -{ - // test check for failed set group value because group name is empty - // 1. Check failed set group value by empty group name - - // 1. Check failed set group value by empty group name - const QVariantMap map { {"1", "A"}, {"2", "B"} }; - QList<QVariantMap> list; - list.append(map); - const QString filename = "group.json"; - EXPECT_FALSE(DapSettings::getInstance("group.json").setGroupValue(QString(), list)); -} diff --git a/CellFrameDashboardTests/gtest_dependency.pri b/CellFrameDashboardTests/gtest_dependency.pri deleted file mode 100644 index de65828b6029eebb50225c399e86ada77ff484f1..0000000000000000000000000000000000000000 --- a/CellFrameDashboardTests/gtest_dependency.pri +++ /dev/null @@ -1,29 +0,0 @@ -isEmpty(GOOGLETEST_DIR):GOOGLETEST_DIR=$$(GOOGLETEST_DIR) - -isEmpty(GOOGLETEST_DIR) { - warning("Using googletest src dir specified at Qt Creator wizard") - message("set GOOGLETEST_DIR as environment variable or qmake variable to get rid of this message") - GOOGLETEST_DIR = $$_PRO_FILE_PWD_/../../3dparty/googletest -} - -!isEmpty(GOOGLETEST_DIR): { - GTEST_SRCDIR = $$GOOGLETEST_DIR/googletest - GMOCK_SRCDIR = $$GOOGLETEST_DIR/googlemock -} - -requires(exists($$GTEST_SRCDIR):exists($$GMOCK_SRCDIR)) - -!exists($$GOOGLETEST_DIR):message("No googletest src dir found - set GOOGLETEST_DIR to enable.") - -DEFINES += \ - GTEST_LANG_CXX11 - -INCLUDEPATH *= \ - $$GTEST_SRCDIR \ - $$GTEST_SRCDIR/include \ - $$GMOCK_SRCDIR \ - $$GMOCK_SRCDIR/include - -SOURCES += \ - $$GTEST_SRCDIR/src/gtest-all.cc \ - $$GMOCK_SRCDIR/src/gmock-all.cc diff --git a/CellFrameDashboardTests/main.cpp b/CellFrameDashboardTests/main.cpp deleted file mode 100644 index 899ed9fab3fdba8cbae9f8ebe37a7ff31282a1bc..0000000000000000000000000000000000000000 --- a/CellFrameDashboardTests/main.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include <gtest/gtest.h> - -int main(int argc, char *argv[]) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -}