diff --git a/CellFrameDashboardGUI/DapServiceController.cpp b/CellFrameDashboardGUI/DapServiceController.cpp index f5ef4b132ac8bcbd6139a62448fe82c032c44245..ba6cba5bf8d740a81598f20f29ada23fd40e247a 100644 --- a/CellFrameDashboardGUI/DapServiceController.cpp +++ b/CellFrameDashboardGUI/DapServiceController.cpp @@ -81,6 +81,8 @@ void DapServiceController::registerCommand() m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapActivateClientCommand("DapActivateClientCommand", m_DAPRpcSocket))), QString("clientActivated"))); // Log update command on the Logs tab m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapUpdateLogsCommand("DapUpdateLogsCommand", m_DAPRpcSocket))), QString("logUpdated"))); + // Command to save data from the Logs tab + m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapExportLogCommand("DapExportLogCommand",m_DAPRpcSocket))), QString("exportLogs"))); registerEmmitedSignal(); } diff --git a/CellFrameDashboardGUI/DapServiceController.h b/CellFrameDashboardGUI/DapServiceController.h index 080fa9778ea1c5e5d3b6c3a46e1da0565a065892..4fa6b1545d6939fe5ed04e14538e8475a95b4421 100644 --- a/CellFrameDashboardGUI/DapServiceController.h +++ b/CellFrameDashboardGUI/DapServiceController.h @@ -13,6 +13,7 @@ #include "Handlers/DapQuitApplicationCommand.h" #include "Handlers/DapActivateClientCommand.h" #include "Handlers/DapUpdateLogsCommand.h" +#include "Handlers/DapExportLogCommand.h" class DapServiceController : public QObject { @@ -81,9 +82,13 @@ signals: void versionChanged(const QString &version); /// The signal is emitted when a command to activate a client is received. void clientActivated(); - /// A signal that is used to transmit data to the log model. - /// @param historyString QStringList + ///This signal sends data about saving a file from the Logs tab + /// @param saveLogRezult + void saveLogRezult(const QVariant& message); + ///A signal that is used to transmit data to the log model. + /// @param logUpdated QStringList void logUpdated(const QVariant& logs); + private slots: /// Register command. diff --git a/CellFrameDashboardGUI/screen/desktop/Logs/DapLogsScreen.qml b/CellFrameDashboardGUI/screen/desktop/Logs/DapLogsScreen.qml index 2b81e7daef78d0344fdf223499dcfefa68fd8e8e..b17c7a54223cb527222b4dd9d5b27bf8dd46ec55 100644 --- a/CellFrameDashboardGUI/screen/desktop/Logs/DapLogsScreen.qml +++ b/CellFrameDashboardGUI/screen/desktop/Logs/DapLogsScreen.qml @@ -1,11 +1,14 @@ import QtQuick.Window 2.2 -import QtQuick.Controls 2.1 -import QtQuick 2.0 import QtGraphicalEffects 1.0 import QtQml 2.0 +import QtQuick 2.4 +import QtQuick.Controls 2.0 +import "../../" DapLogsScreenForm { + id:dapLogsScreenForm + ///@detalis firstMarginList First indent in the delegate to the first word. property int firstMarginList: 16 * pt ///@detalis secondMarginList Second indent between the first and second word. @@ -23,6 +26,13 @@ DapLogsScreenForm ///@detalis Font color. property string fontColor: "#070023" + //Slot for updating data in the model. The signal comes from C++. + Connections + { + target: dapServiceController + onLogUpdated:fillModel(logs); + } + ///In this block, the properties are only auxiliary for internal use. QtObject { @@ -36,13 +46,6 @@ DapLogsScreenForm property var todayYear property var stringTime } - //Slot for updating data in the model. The signal comes from C++. - Connections - { - target: dapServiceController - onLogUpdated:fillModel(logs); - - } //Creates a list model for the example Component.onCompleted: @@ -58,10 +61,6 @@ DapLogsScreenForm dapServiceController.requestToService("DapUpdateLogsCommand",200); } - ListModel - { - id:dapLogsModel - } //The Component Header Component { @@ -239,6 +238,7 @@ DapLogsScreenForm } } + //Splits a string from the log. function parceStringFromLog(string) { @@ -257,7 +257,7 @@ DapLogsScreenForm var stringTime = parceTime(arrLogString[1]); dapLogsModel.append({"type":arrLogString[2], "info":arrLogString[4], "file":arrLogString[3], "time":getTime(stringTime), - "date":getDay(stringTime)}); + "date":getDay(stringTime), "momentTime":stringTime}); } } diff --git a/CellFrameDashboardGUI/screen/desktop/Logs/DapLogsTab.qml b/CellFrameDashboardGUI/screen/desktop/Logs/DapLogsTab.qml index 8996c3b440e744a9fad1926386decf431d983ae3..7d46b5dccc3734a8634fa7d5fb3279d74f301245 100644 --- a/CellFrameDashboardGUI/screen/desktop/Logs/DapLogsTab.qml +++ b/CellFrameDashboardGUI/screen/desktop/Logs/DapLogsTab.qml @@ -2,5 +2,9 @@ import QtQuick 2.4 DapLogsTabForm { - + ///Log window model. + ListModel + { + id:dapLogsModel + } } diff --git a/CellFrameDashboardGUI/screen/desktop/Logs/DapLogsTabForm.ui.qml b/CellFrameDashboardGUI/screen/desktop/Logs/DapLogsTabForm.ui.qml index c9167d8121110203ea1ac39d109d789ebb8830e4..5fc3f38b08ebb783c1426de63fb06676ce4b8e32 100644 --- a/CellFrameDashboardGUI/screen/desktop/Logs/DapLogsTabForm.ui.qml +++ b/CellFrameDashboardGUI/screen/desktop/Logs/DapLogsTabForm.ui.qml @@ -11,4 +11,5 @@ DapAbstractTab dapScreen: DapLogsScreen { } dapRightPanel: DapLogsRightPanel { } + } diff --git a/CellFrameDashboardGUI/screen/desktop/Logs/DapLogsTopPanel.qml b/CellFrameDashboardGUI/screen/desktop/Logs/DapLogsTopPanel.qml index 684fa7762bb5bafde4b236c627caeb7d7aa650af..a3ac598d7cdee31b69dba9ba08abb3360fbcba89 100644 --- a/CellFrameDashboardGUI/screen/desktop/Logs/DapLogsTopPanel.qml +++ b/CellFrameDashboardGUI/screen/desktop/Logs/DapLogsTopPanel.qml @@ -1,17 +1,18 @@ import QtQuick 2.4 import QtQuick.Dialogs 1.2 import Qt.labs.platform 1.0 -import QtGraphicalEffects 1.0 import "../../" DapLogsTopPanelForm { + ///@detalis filterFileArray Array with filters for the file saving window. + property var filterFileArray:["Text files (*.txt)", "Log files (*.log)"] + ///Loader for the Save window. Loader { id:saveWindow } - ///Component for the Save dialog box. Component { @@ -21,12 +22,20 @@ DapLogsTopPanelForm id: saveDialog title: "Save the file" fileMode: FileDialog.SaveFile + nameFilters: filterFileArray + selectedNameFilter.index: 0 + modality: Qt.WindowModal onFileChanged: { setPropertyDefaultWindow(); - } + var resultAddres = String(currentFile).replace(/file:\/\//,""); + resultAddres = resultAddres.replace(/\.([$A-Za-z0-9]{2,4})/,""); + resultAddres += "." + selectedNameFilter.extensions[0]; + dapServiceController.requestToService("DapExportLogCommand",resultAddres,sendLogToFile()); + + } onRejected: { setPropertyDefaultWindow(); @@ -34,6 +43,31 @@ DapLogsTopPanelForm Component.onCompleted: visible = true; } } + ///Creates a string from the model to save to a file. + function sendLogToFile() + { + var logArray = ""; + var tmpDate = new Date(); + for(var ind = 0; ind<dapLogsModel.count;ind++) + { + tmpDate.setTime(dapLogsModel.get(ind).momentTime); + var dd = tmpDate.getDate(); + if (dd < 10) dd = '0' + dd; + + var mm = tmpDate.getMonth() + 1; + if (mm < 10) mm = '0' + mm; + + var yy = tmpDate.getFullYear() % 100; + if (yy < 10) yy = '0' + yy; + + logArray+="[" + mm + "/" + dd + "/" + yy + "-" + dapLogsModel.get(ind).time +"] "; + logArray+="["+dapLogsModel.get(ind).type+"] "; + logArray+="["+dapLogsModel.get(ind).file+"] "; + logArray+=dapLogsModel.get(ind).info +"\n"; + } + return logArray; + + } ///Creating a screenshot of a window function grub() diff --git a/CellFrameDashboardService/CellFrameDashboardService.pro b/CellFrameDashboardService/CellFrameDashboardService.pro index 8b47e620143982179fbec0b20cf3df5bb9d2f7eb..b5d91d91cc90900144d82e1afc3bb8a56d98494f 100755 --- a/CellFrameDashboardService/CellFrameDashboardService.pro +++ b/CellFrameDashboardService/CellFrameDashboardService.pro @@ -19,14 +19,14 @@ win32 { CONFIG -= console VERSION = $${VER_MAJ}.$${VER_MIN}.$$VER_PAT DEFINES += CLI_PATH=\\\"./cellframe-node-cli.exe\\\" - DEFINES += LOG_FILE=\\\"./opt/cellframe-node/var/log/cellframe-node_logs.txt\\\" + DEFINES += LOG_FILE=\\\"./opt/cellframe-node/var/log/cellframe-node.log\\\" DEFINES += CMD_LOG=\\\"./opt/cellframe-dashboard/data/cellframe-cmd_log.txt\\\" DEFINES += HAVE_STRNDUP } else { VERSION = $$VER_MAJ\.$$VER_MIN\-$$VER_PAT DEFINES += CLI_PATH=\\\"/opt/cellframe-node/bin/cellframe-node-cli\\\" - DEFINES += LOG_FILE=\\\"/opt/cellframe-node/var/log/cellframe-node_logs.txt\\\" + DEFINES += LOG_FILE=\\\"/opt/cellframe-node/var/log/cellframe-node.log\\\" DEFINES += CMD_LOG=\\\"/opt/cellframe-dashboard/data/cellframe-cmd_log.txt\\\" } diff --git a/CellFrameDashboardService/DapServiceController.cpp b/CellFrameDashboardService/DapServiceController.cpp index 2ce411568fb8473f5685a9ee95d01587661106e9..4bc4019c80483b0e153f6b73d0db639c4955c0af 100755 --- a/CellFrameDashboardService/DapServiceController.cpp +++ b/CellFrameDashboardService/DapServiceController.cpp @@ -50,6 +50,8 @@ void DapServiceController::registerCommand() m_pServer->addService(new DapActivateClientCommand("DapActivateClientCommand", m_pServer)); // Log update command on the Logs tab m_pServer->addService(new DapUpdateLogsCommand("DapUpdateLogsCommand", m_pServer, LOG_FILE)); + // Saving the file with the logs + m_pServer->addService(new DapExportLogCommand("DapExportLogCommand", m_pServer)); } /// Initialize system tray. @@ -83,4 +85,5 @@ void DapServiceController::initSystemTrayIcon() Q_ASSERT(command); command->notifyToClient(); }); + } diff --git a/CellFrameDashboardService/DapServiceController.h b/CellFrameDashboardService/DapServiceController.h index 8a3c98961fc02aa593ef4bcd29550dd9ffcedb27..ceb76d1e826030a97144ac5f9a8f7c1aeeaf2ff5 100755 --- a/CellFrameDashboardService/DapServiceController.h +++ b/CellFrameDashboardService/DapServiceController.h @@ -27,10 +27,12 @@ typedef class DapRpcLocalServer DapUiService; #include "Handlers/DapQuitApplicationCommand.h" #include "Handlers/DapActivateClientCommand.h" #include "Handlers/DapUpdateLogsCommand.h" +#include "Handlers/DapExportLogCommand.h" #include "DapSystemTrayIcon.h" #include "DapToolTipWidget.h" + /** * @brief The DapServiceController class * Service class which provide handle operations with dashboard. diff --git a/libCellFrameDashboardCommon/Handlers/DapExportLogCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapExportLogCommand.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9f26d85d8d9a34494fab73e499bfd38253844423 --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapExportLogCommand.cpp @@ -0,0 +1,42 @@ +#include "DapExportLogCommand.h" + +/// Overloaded constructor. +/// @param asServiceName Service name. +/// @param apSocket Client connection socket with service. +/// @param parent Parent. +DapExportLogCommand::DapExportLogCommand(const QString &asServicename, QObject *parent) + : DapAbstractCommand(asServicename, parent) +{ + +} + +/// Send a response to the client. +/// A log file is saved from the GUI window. +/// @param arg1...arg10 Parameters. +/// @return Reply to client. +QVariant DapExportLogCommand::respondToClient(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, + const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, + const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, + const QVariant &arg10) +{ + Q_UNUSED(arg3) + Q_UNUSED(arg4) + Q_UNUSED(arg5) + Q_UNUSED(arg6) + Q_UNUSED(arg7) + Q_UNUSED(arg8) + Q_UNUSED(arg9) + Q_UNUSED(arg10) + + QFile saveDapLog(arg1.toString()); + if (!saveDapLog.open(QIODevice::WriteOnly | QIODevice::Text)) + { + qCritical("The file does not write."); + return false; + } + QTextStream saveLog(&saveDapLog); + saveLog << arg2.toString(); + + saveDapLog.close(); + return QVariant(); +} diff --git a/libCellFrameDashboardCommon/Handlers/DapExportLogCommand.h b/libCellFrameDashboardCommon/Handlers/DapExportLogCommand.h new file mode 100644 index 0000000000000000000000000000000000000000..79d21af12cbdeb94dd3c6e20848c21577cd7b789 --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapExportLogCommand.h @@ -0,0 +1,30 @@ +#ifndef DAPSAVELOGCOMMAND_H +#define DAPSAVELOGCOMMAND_H + +#include <QFile> + +#include "DapAbstractCommand.h" + +class DapExportLogCommand : public DapAbstractCommand +{ + +public: + /// Overloaded constructor. + /// @param asServiceName Service name. + /// @param apSocket Client connection socket with service. + /// @param parent Parent. + explicit DapExportLogCommand(const QString &asServicename, QObject *parent = nullptr); + +public slots: + /// Send a response to the client. + /// /// A log file is saved from the GUI window. + /// @param arg1...arg10 Parameters. + /// @return Reply to client. + QVariant respondToClient(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), + const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), + const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), + const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(), + const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()) override; +}; + +#endif // DAPSAVELOGCOMMAND_H diff --git a/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri b/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri index 17f6e7687e54061ef15e35df8141de1c1ad8b4da..542f21ed0c7387094d1dba0575fd8afc9b8562ab 100755 --- a/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri +++ b/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri @@ -22,6 +22,7 @@ SOURCES +=\ $$PWD/DapSystemTrayIcon.cpp \ $$PWD/Handlers/DapAbstractCommand.cpp \ $$PWD/Handlers/DapActivateClientCommand.cpp \ + $$PWD/Handlers/DapExportLogCommand.cpp \ $$PWD/Handlers/DapQuitApplicationCommand.cpp \ $$PWD/Handlers/DapAddWalletCommand.cpp \ $$PWD/Handlers/DapUpdateLogsCommand.cpp @@ -37,6 +38,7 @@ HEADERS +=\ $$PWD/DapSystemTrayIcon.h \ $$PWD/Handlers/DapAbstractCommand.h \ $$PWD/Handlers/DapActivateClientCommand.h \ + $$PWD/Handlers/DapExportLogCommand.h \ $$PWD/Handlers/DapQuitApplicationCommand.h \ $$PWD/Handlers/DapAddWalletCommand.h \ $$PWD/Handlers/DapUpdateLogsCommand.h