diff --git a/KelvinDashboardGUI/DapUiQmlScreenConsoleForm.qml b/KelvinDashboardGUI/DapUiQmlScreenConsoleForm.qml new file mode 100644 index 0000000000000000000000000000000000000000..17d0965d51f79d8a7b76186c4a0b5df96d78d412 --- /dev/null +++ b/KelvinDashboardGUI/DapUiQmlScreenConsoleForm.qml @@ -0,0 +1,49 @@ +import QtQuick 2.9 +import QtQml 2.12 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.12 + +Page { + TextEdit { + id: txtCommands + property int positionLine: 2 + anchors.fill: parent + + text: "> " + wrapMode: TextEdit.WordWrap + + onTextChanged: { + if(txtCommands.cursorPosition === txtCommands.positionLine) + { + txtCommands.text += " "; + txtCommands.cursorPosition = txtCommands.text.length + } + } + + function acceptedResopose(responce) + { + txtCommands.readOnly = false; + txtCommands.append(responce); + txtCommands.append("> "); + console.debug(txtCommands.positionLine); + console.debug(txtCommands.cursorPosition); + txtCommands.positionLine = txtCommands.cursorPosition + 1; + } + + Keys.onPressed: { + + switch(event.key) + { + case Qt.Key_Up: console.debug("UP"); break; + case Qt.Key_Down: console.debug("Down"); break; + default: break; + } + } + + Keys.onReturnPressed: { + console.debug("ENTER"); + txtCommands.readOnly = true; + acceptedResopose("New resp"); + } + } +} diff --git a/KelvinDashboardGUI/DapUiQmlScreenDashboard.qml b/KelvinDashboardGUI/DapUiQmlScreenDashboard.qml index ad42c4374c14bb08a9bc2920d007cd5d9a110925..9b79c70f1f71f66a496fa103bc1ae92758dcf7c9 100755 --- a/KelvinDashboardGUI/DapUiQmlScreenDashboard.qml +++ b/KelvinDashboardGUI/DapUiQmlScreenDashboard.qml @@ -51,6 +51,13 @@ Page { page: "DapUiQmlScreenHistory.qml" source: "qrc:/Resources/Icons/defaul_icon.png" } + + ListElement { + name: qsTr("Console") + page: "DapUiQmlScreenConsoleForm.qml" + source: "qrc:/Resources/Icons/defaul_icon.png" + } + ListElement { name: qsTr("About") page: "DapQmlScreenAbout.qml" diff --git a/KelvinDashboardGUI/DapUiQmlWidgetConsole.cpp b/KelvinDashboardGUI/DapUiQmlWidgetConsole.cpp new file mode 100644 index 0000000000000000000000000000000000000000..373b4b90f5f9c897ae5ea7fb75ee89b4b11e1160 --- /dev/null +++ b/KelvinDashboardGUI/DapUiQmlWidgetConsole.cpp @@ -0,0 +1,6 @@ +#include "DapUiQmlWidgetConsole.h" + +DapUiQmlWidgetConsole::DapUiQmlWidgetConsole(QObject *parent) : QObject(parent) +{ + +} diff --git a/KelvinDashboardGUI/DapUiQmlWidgetConsole.h b/KelvinDashboardGUI/DapUiQmlWidgetConsole.h new file mode 100644 index 0000000000000000000000000000000000000000..bbd8f157630b9463da9ebf21e17a1642e857fa27 --- /dev/null +++ b/KelvinDashboardGUI/DapUiQmlWidgetConsole.h @@ -0,0 +1,19 @@ +#ifndef DAPUIQMLSCREENCONSOLEFORM_H +#define DAPUIQMLSCREENCONSOLEFORM_H + +#include <QObject> +#include <QPlainTextEdit> + +class DapUiQmlWidgetConsole : public QObject +{ + Q_OBJECT + +public: + explicit DapUiQmlWidgetConsole(QObject *parent = nullptr); + +public slots: + +signals: +}; + +#endif // DAPUIQMLSCREENCONSOLEFORM_H diff --git a/KelvinDashboardGUI/DapUiQmlWidgetConsole.qml b/KelvinDashboardGUI/DapUiQmlWidgetConsole.qml deleted file mode 100644 index ea079704eedebbeae9b3b3593a8598d362e07b67..0000000000000000000000000000000000000000 --- a/KelvinDashboardGUI/DapUiQmlWidgetConsole.qml +++ /dev/null @@ -1,27 +0,0 @@ -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 deleted file mode 100644 index 0fe42cea054435147c8235c83eb33e54944609e0..0000000000000000000000000000000000000000 --- a/KelvinDashboardGUI/DapUiQmlWidgetConsoleForm.ui.qml +++ /dev/null @@ -1,83 +0,0 @@ -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/KelvinDashboardGUI.pro b/KelvinDashboardGUI/KelvinDashboardGUI.pro index 37c5639d60074f10ab012ef2a3847cad5d97a40b..bf431dd61b01d9e1bff236419e3832a6ddf73ecd 100755 --- a/KelvinDashboardGUI/KelvinDashboardGUI.pro +++ b/KelvinDashboardGUI/KelvinDashboardGUI.pro @@ -45,6 +45,7 @@ SOURCES += \ DapScreenHistoryFilterModel.cpp \ DapScreenHistoryModel.cpp \ DapUiQmlWidgetChainTransactions.cpp \ + DapUiQmlWidgetConsole.cpp \ main.cpp \ DapUiQmlWidgetChainBallance.cpp \ DapUiQmlWidgetChainBlockExplorer.cpp \ @@ -86,6 +87,7 @@ HEADERS += \ DapUiQmlScreenDashboard.h \ DapUiQmlWidgetChainOperations.h \ DapUiQmlWidgetChainTransactions.h \ + DapUiQmlWidgetConsole.h \ DapUiQmlWidgetModel.h \ DapUiQmlWidget.h \ DapScreenDialog.h \ diff --git a/KelvinDashboardGUI/main.cpp b/KelvinDashboardGUI/main.cpp index 0239d20a45384a95f552ef5eb871661320e579c9..e413577b34d9880b00595159cd6c02675e482891 100755 --- a/KelvinDashboardGUI/main.cpp +++ b/KelvinDashboardGUI/main.cpp @@ -23,7 +23,7 @@ #include "DapChainNodeNetworkModel.h" #include "DapChainNodeNetworkExplorer.h" #include "DapScreenHistoryFilterModel.h" - +#include "DapUiQmlWidgetConsole.h" #include <QRegExp> @@ -66,6 +66,7 @@ int main(int argc, char *argv[]) // qmlRegisterType<DapScreenHistoryModel>("") qmlRegisterSingletonType<DapUiQmlWidgetModel>("KelvinDashboard", 1, 0, "DapUiQmlWidgetModel", DapUiQmlWidgetModel::singletonProvider); qmlRegisterType<DapScreenHistoryModel>("DapTransactionHistory", 1, 0, "DapTransactionModel"); + qmlRegisterType<DapUiQmlWidgetConsole>("QmlWidgetConsole", 1, 0, "DapUiQmlWidgetConsole"); QQmlApplicationEngine engine; // qreal dpi = QGuiApplication::primaryScreen()->physicalDotsPerInch(); diff --git a/KelvinDashboardGUI/qml.qrc b/KelvinDashboardGUI/qml.qrc index a3f93cb2cf1d28dc7316663de2b99bcbd4394936..4c6ab326cce99e3d573f373d41f8ede21195da29 100755 --- a/KelvinDashboardGUI/qml.qrc +++ b/KelvinDashboardGUI/qml.qrc @@ -24,10 +24,9 @@ <file>DapUiQmlWidgetChainNodeLogsForm.ui.qml</file> <file>DapUiQmlScreenDialogSendToken.qml</file> <file>DapUiQmlScreenDialogRemoveWallet.qml</file> - <file>DapUiQmlWidgetConsoleForm.ui.qml</file> - <file>DapUiQmlWidgetConsole.qml</file> <file>DapUiQmlWidgetNodeNetworkExplorer.qml</file> <file>DapUiQmlScreenHistory.qml</file> -<file>Resources/Icons/defaul_icon.png</file> + <file>Resources/Icons/defaul_icon.png</file> + <file>DapUiQmlScreenConsoleForm.qml</file> </qresource> </RCC> diff --git a/KelvinDashboardService/DapChainConsoleHandler.cpp b/KelvinDashboardService/DapChainConsoleHandler.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8b3403e7cba3dbd51b376959824cdd2d9afc67c0 --- /dev/null +++ b/KelvinDashboardService/DapChainConsoleHandler.cpp @@ -0,0 +1,15 @@ +#include "DapChainConsoleHandler.h" + +DapChainConsoleHandler::DapChainConsoleHandler(QObject *parent) : QObject(parent) +{ + +} + +QString DapChainConsoleHandler::getResult(const QString& aQuery) const +{ + QProcess process; + process.start(QString(CLI_PATH) + " " + aQuery); + process.waitForFinished(-1); + + return QString::fromStdString(process.readAll().toStdString()); +} diff --git a/KelvinDashboardService/DapChainConsoleHandler.h b/KelvinDashboardService/DapChainConsoleHandler.h new file mode 100644 index 0000000000000000000000000000000000000000..6864a5d903e64b12fb853d85786a4bf3b2b75d3a --- /dev/null +++ b/KelvinDashboardService/DapChainConsoleHandler.h @@ -0,0 +1,17 @@ +#ifndef DAPCHAINCONSOLEHANDLER_H +#define DAPCHAINCONSOLEHANDLER_H + +#include <QObject> +#include <QProcess> + +class DapChainConsoleHandler : public QObject +{ + Q_OBJECT + +public: + explicit DapChainConsoleHandler(QObject *parent = nullptr); + + QString getResult(const QString& aQuery) const; +}; + +#endif // DAPCHAINCONSOLEHANDLER_H diff --git a/KelvinDashboardService/DapChainDashboardService.cpp b/KelvinDashboardService/DapChainDashboardService.cpp index 6f01f3b2e9e5a45d23fbdc4495e1c067a3455fb7..4120c1bc7121a3f2b6c2af9195836b60afc74ae5 100755 --- a/KelvinDashboardService/DapChainDashboardService.cpp +++ b/KelvinDashboardService/DapChainDashboardService.cpp @@ -16,6 +16,9 @@ DapChainDashboardService::DapChainDashboardService() : DapRpcService(nullptr) m_pDapChainHistoryHandler = new DapChainHistoryHandler {this}; QObject::connect(m_pDapChainHistoryHandler, &DapChainHistoryHandler::requsetWallets, this, &DapChainDashboardService::doRequestWallets); QObject::connect(m_pDapChainHistoryHandler, &DapChainHistoryHandler::changeHistory, this, &DapChainDashboardService::doSendNewHistory); + + m_pDapChainConsoleHandler = new DapChainConsoleHandler(this); + } bool DapChainDashboardService::start() @@ -89,6 +92,11 @@ QVariant DapChainDashboardService::getHistory() const return m_pDapChainHistoryHandler->getHistory(); } +QString DapChainDashboardService::getQueryResult(const QString& aQuery) const +{ + return m_pDapChainConsoleHandler->getResult(aQuery); +} + void DapChainDashboardService::doRequestWallets() { m_pDapChainHistoryHandler->onRequestNewHistory(m_pDapChainWalletHandler->getWallets()); diff --git a/KelvinDashboardService/DapChainDashboardService.h b/KelvinDashboardService/DapChainDashboardService.h index 22ce4d49653dc2a093c103058e6ee8a26a2f97eb..573826f8b1cdd07428b74458edd5e1e636c2e71b 100755 --- a/KelvinDashboardService/DapChainDashboardService.h +++ b/KelvinDashboardService/DapChainDashboardService.h @@ -27,6 +27,7 @@ #include "DapChainWalletHandler.h" #include "DapChainNodeNetworkHandler.h" #include "DapChainHistoryHandler.h" +#include "DapChainConsoleHandler.h" #include <QLocalServer> typedef class DapRpcLocalServer DapUiService; @@ -49,6 +50,8 @@ class DapChainDashboardService : public DapRpcService DapChainHistoryHandler* m_pDapChainHistoryHandler {nullptr}; + DapChainConsoleHandler* m_pDapChainConsoleHandler {nullptr}; + public: /// Standard Ñonstructor. explicit DapChainDashboardService(); @@ -92,6 +95,8 @@ public slots: QVariant getHistory() const; + QString getQueryResult(const QString& aQuery) const; + private slots: void doRequestWallets(); void doSendNewHistory(const QVariant& aData); diff --git a/KelvinDashboardService/KelvinDashboardService.pro b/KelvinDashboardService/KelvinDashboardService.pro index bce4996d1cb0c4318565821c810a200806d86666..e021179c1eef25c4120a952d9695e04550bb95d0 100755 --- a/KelvinDashboardService/KelvinDashboardService.pro +++ b/KelvinDashboardService/KelvinDashboardService.pro @@ -48,7 +48,8 @@ SOURCES += \ $$PWD/DapChainNode.cpp \ $$PWD/DapChainNodeCache.cpp \ $$PWD/DapChainWalletHandler.cpp \ - $$PWD/DapChainLogHandler.cpp + $$PWD/DapChainLogHandler.cpp \ + DapChainConsoleHandler.cpp HEADERS += \ $$PWD/DapChainDashboardService.h \ @@ -57,7 +58,8 @@ HEADERS += \ $$PWD/DapChainNodeCache.h \ $$PWD/DapChainNodeNetworkHandler.h \ $$PWD/DapChainWalletHandler.h \ - $$PWD/DapChainLogHandler.h + $$PWD/DapChainLogHandler.h \ + DapChainConsoleHandler.h include (../libdap/libdap.pri) include (../libdap-crypto/libdap-crypto.pri)