From 03ddc94d65c74c12636f2e2835b833633aa6a851 Mon Sep 17 00:00:00 2001 From: user <user@debian9.deb9> Date: Wed, 17 Jul 2019 16:36:55 -0400 Subject: [PATCH] Ayupov Roman(test task) --- KelvinDashboardGUI/DapCommandController.cpp | 23 +++++ KelvinDashboardGUI/DapCommandController.h | 4 + KelvinDashboardGUI/DapServiceController.cpp | 29 ++++++- KelvinDashboardGUI/DapServiceController.h | 18 +++- KelvinDashboardGUI/DapUiQmlWidgetConsole.qml | 27 ++++++ .../DapUiQmlWidgetConsoleForm.ui.qml | 83 +++++++++++++++++++ KelvinDashboardGUI/DapUiQmlWidgetModel.cpp | 1 + KelvinDashboardGUI/qml.qrc | 2 + 8 files changed, 180 insertions(+), 7 deletions(-) create mode 100644 KelvinDashboardGUI/DapUiQmlWidgetConsole.qml create mode 100644 KelvinDashboardGUI/DapUiQmlWidgetConsoleForm.ui.qml diff --git a/KelvinDashboardGUI/DapCommandController.cpp b/KelvinDashboardGUI/DapCommandController.cpp index f5c7cde2e..61d350242 100755 --- a/KelvinDashboardGUI/DapCommandController.cpp +++ b/KelvinDashboardGUI/DapCommandController.cpp @@ -124,6 +124,22 @@ void DapCommandController::processGetWalletInfo() emit sigWalletInfoChanged(name, address, balance, tokens); } +void DapCommandController::processExecuteCommand() +{ + qInfo() << "processGetWalletInfo()"; + DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); + if (!reply || reply->response().result().toVariant().toStringList().isEmpty()) { + + QString result = "Invalid response received"; + qWarning() << result; + emit executeCommandChanged(result); + return; + } + emit sigCommandResult(reply->response().result()); + QString result = reply->response().result().toVariant().toStringList().at(0); + emit executeCommandChanged(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. @@ -180,3 +196,10 @@ void DapCommandController::getWalletInfo(const QString& asWalletName) DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.getWalletInfo", asWalletName); connect(reply, SIGNAL(finished()), this, SLOT(processGetWalletInfo())); } + +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/KelvinDashboardGUI/DapCommandController.h b/KelvinDashboardGUI/DapCommandController.h index f602769c5..57a9d17d5 100755 --- a/KelvinDashboardGUI/DapCommandController.h +++ b/KelvinDashboardGUI/DapCommandController.h @@ -37,6 +37,7 @@ signals: void sigWalletInfoChanged(const QString& asWalletName, const QString& asWalletAddress, const QStringList& aBalance, const QStringList& aTokens); + void executeCommandChanged(const QString& result); public: /// Overloaded constructor. /// @param apIODevice Data transfer device. @@ -58,6 +59,7 @@ private slots: void processGetWalletInfo(); + void processExecuteCommand(); public slots: /// Show or hide GUI client by clicking on the tray icon. /// @param aIsActivated Accepts true - when requesting to @@ -77,6 +79,8 @@ public slots: void getWallets(); void getWalletInfo(const QString& asWalletName); + + void executeCommand(const QString& command); }; #endif // COMMANDCONTROLLER_H diff --git a/KelvinDashboardGUI/DapServiceController.cpp b/KelvinDashboardGUI/DapServiceController.cpp index 2dfa49881..cb5226b10 100755 --- a/KelvinDashboardGUI/DapServiceController.cpp +++ b/KelvinDashboardGUI/DapServiceController.cpp @@ -47,6 +47,9 @@ void DapServiceController::init(DapServiceClient *apDapServiceClient) 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))); + } QString DapServiceController::getBrand() const @@ -61,6 +64,11 @@ QString DapServiceController::getVersion() const return m_sVersion; } +QString DapServiceController::getResult() +{ + return m_sResult; +} + /// Get node logs. /// @param aiTimeStamp Timestamp start reading logging. /// @param aiRowCount Number of lines displayed. @@ -122,10 +130,9 @@ void DapServiceController::addWallet(const QString &asWalletName) void DapServiceController::removeWallet(int index, const QString &asWalletName) { - qInfo() << QString("removeWallet(%1)").arg(index); - qInfo() << QString("removeWallet(%1)").arg(asWalletName); - m_pDapCommandController->removeWallet(asWalletName.trimmed()); - DapChainWalletsModel::getInstance().remove(index); + 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) @@ -134,6 +141,13 @@ void DapServiceController::sendToken(const QString &asSendWallet, const QString 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); @@ -172,6 +186,13 @@ void DapServiceController::processGetWalletInfo(const QString &asWalletName, con } } +void DapServiceController::processExecuteCommandInfo(const QString &result) +{ + qInfo() << QString("processExecuteCommandInfo(%1)").arg(result); + m_sResult = result; + emit resultChanged(); +} + /// Get an instance of a class. /// @return Instance of a class. DapServiceController &DapServiceController::getInstance() diff --git a/KelvinDashboardGUI/DapServiceController.h b/KelvinDashboardGUI/DapServiceController.h index a213ac263..7fd427e91 100755 --- a/KelvinDashboardGUI/DapServiceController.h +++ b/KelvinDashboardGUI/DapServiceController.h @@ -22,7 +22,9 @@ class DapServiceController : public QObject QString m_sBrand {DAP_BRAND}; /// Application version. QString m_sVersion {DAP_VERSION}; - + /// Result execute. + QString m_sResult; + /// Service connection management service. DapServiceClient *m_pDapServiceClient {nullptr}; /// RPC protocol controller. @@ -45,7 +47,9 @@ 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 /// ******************************************* @@ -56,6 +60,9 @@ public: /// Get app version. /// @return Application version. QString getVersion() 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. @@ -69,6 +76,7 @@ public: 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); void getWalletInfo(const QString& asWalletName); @@ -77,11 +85,13 @@ signals: void brandChanged(const QString &brand); /// The signal is emitted when the Application version property changes. 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. void isExistenceClient(bool isExistenceClient); - + void sendToQML(QString); private slots: /// Handling service response for receiving node logs. /// @param aNodeLogs List of node logs. @@ -95,6 +105,8 @@ private slots: void processGetWalletInfo(const QString& asWalletName, const QString& asWalletAddress, const QStringList &aBalance, const QStringList& aTokens); + void processExecuteCommandInfo(const QString& result); + public slots: /// Show or hide GUI client by clicking on the tray icon. /// @param aIsActivated Accepts true - when requesting to diff --git a/KelvinDashboardGUI/DapUiQmlWidgetConsole.qml b/KelvinDashboardGUI/DapUiQmlWidgetConsole.qml new file mode 100644 index 000000000..ea079704e --- /dev/null +++ b/KelvinDashboardGUI/DapUiQmlWidgetConsole.qml @@ -0,0 +1,27 @@ +import QtQuick 2.9 +import QtQuick.Controls 1.4 +import QtQuick.Controls 2.2 +import QtQuick.Window 2.0 +import QtQuick.Controls.Styles 1.3 +import QtQuick.Controls.Styles 1.4 +import Qt.labs.platform 1.0 +import KelvinDashboard 1.0 + + +DapUiQmlWidgetConsoleForm { + id: dapQmlWidgetConsole + execute.onClicked: { + dapServiceController.executeCommand(command.text) + execute.enabled = false; + + } + Connections { + target: dapServiceController + onResultChanged: { + command.clear() + result.text = dapServiceController.Result + execute.enabled = true + } + } + +} diff --git a/KelvinDashboardGUI/DapUiQmlWidgetConsoleForm.ui.qml b/KelvinDashboardGUI/DapUiQmlWidgetConsoleForm.ui.qml new file mode 100644 index 000000000..0fe42cea0 --- /dev/null +++ b/KelvinDashboardGUI/DapUiQmlWidgetConsoleForm.ui.qml @@ -0,0 +1,83 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.1 + +Page { + id: dapUiQmlWidgetConsole + property alias result: result + property alias command: command + property alias execute: execute + + + Rectangle { + id: rectangle + y: 0 + width: 640 + height: 480 + color: "#ffffff" + anchors.left: parent.left + anchors.leftMargin: 0 + anchors.verticalCenter: parent.verticalCenter + border.width: 0 + + Button { + id: execute + x: 250 + y: 366 + text: qsTr("Execute") + anchors.horizontalCenterOffset: 0 + anchors.bottom: parent.bottom + anchors.bottomMargin: 74 + anchors.horizontalCenter: parent.horizontalCenter + } + + TextEdit { + id: command + x: 290 + y: 50 + width: 606 + height: 208 + anchors.horizontalCenterOffset: 4 + anchors.horizontalCenter: parent.horizontalCenter + font.pixelSize: 12 + } + + Label { + id: result + y: 422 + width: 606 + height: 50 + text: qsTr("") + anchors.left: parent.left + anchors.leftMargin: 21 + anchors.bottom: parent.bottom + anchors.bottomMargin: 8 + } + + Label { + id: commandText + x: 21 + y: 24 + width: 82 + height: 14 + text: qsTr("Command:") + anchors.left: parent.left + anchors.leftMargin: 21 + } + + Label { + id: resultText + x: 21 + y: 409 + text: qsTr("Result:") + } + } +} + + + + +/*##^## Designer { + D{i:0;autoSize:true;height:480;width:640} +} + ##^##*/ diff --git a/KelvinDashboardGUI/DapUiQmlWidgetModel.cpp b/KelvinDashboardGUI/DapUiQmlWidgetModel.cpp index 828d2d78e..0530c87a1 100755 --- a/KelvinDashboardGUI/DapUiQmlWidgetModel.cpp +++ b/KelvinDashboardGUI/DapUiQmlWidgetModel.cpp @@ -9,6 +9,7 @@ DapUiQmlWidgetModel::DapUiQmlWidgetModel(QObject *parent) : QAbstractListModel(p m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Settings", "DapUiQmlWidgetChainSettings.ui.qml", "qrc:/Resources/Icons/add.png")); m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Wallet", "DapUiQmlWidgetChainWallet.qml", "qrc:/Resources/Icons/add.png")); m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Logs", "DapUiQmlWidgetChainNodeLogsForm.ui.qml", "qrc:/Resources/Icons/add.png")); + m_dapUiQmlWidgets.append(new DapUiQmlWidget( "Console cli", "DapUiQmlWidgetConsole.qml", "qrc:/Resources/Icons/add.png")); } DapUiQmlWidgetModel &DapUiQmlWidgetModel::getInstance() diff --git a/KelvinDashboardGUI/qml.qrc b/KelvinDashboardGUI/qml.qrc index 4f4f7be70..f65258291 100755 --- a/KelvinDashboardGUI/qml.qrc +++ b/KelvinDashboardGUI/qml.qrc @@ -35,5 +35,7 @@ <file>DapUiQmlWidgetChainNodeLogsForm.ui.qml</file> <file>DapUiQmlScreenDialogSendToken.qml</file> <file>DapUiQmlScreenDialogRemoveWallet.qml</file> + <file>DapUiQmlWidgetConsoleForm.ui.qml</file> + <file>DapUiQmlWidgetConsole.qml</file> </qresource> </RCC> -- GitLab