Skip to content
Snippets Groups Projects
Commit 5bd84754 authored by andrey.daragan's avatar andrey.daragan
Browse files

[+] The functionality of the RPC-protocol has been improved. Added tray icon....

[+] The functionality of the RPC-protocol has been improved. Added tray icon. The activation function of the GUI client has been implemented. Implemented dynamic tooltip.
parent 03d917e9
No related branches found
No related tags found
No related merge requests found
Showing
with 208 additions and 49 deletions
......@@ -35,10 +35,10 @@ DEFINES += DAP_SERVICE_NAME=\\\"CellFrameDashboardService\\\"
DEFINES += DAP_VERSION=\\\"$$VERSION\\\"
DEFINES += DAP_SETTINGS_FILE=\\\"settings.json\\\"
macx {
ICON = res/icons/dashboard.icns
ICON = res/icons/dashboard.icns
}
else {
ICON =
ICON = qrc:/res/icons/icon.ico
}
# You can also make your code fail to compile if you use deprecated APIs.
......
......@@ -41,23 +41,37 @@ DapServiceController &DapServiceController::getInstance()
/// Send request to service.
/// @param arg1...arg10 Parametrs.
void DapServiceController::requestToService(const QString &asServicename, const QVariant &arg1,
void DapServiceController::requestToService(const QString &asServiceName, 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)
{
DapAbstractCommand * transceiver = m_transceivers.find(asServicename).value().first;
DapAbstractCommand * transceiver = dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->findService(asServiceName));
Q_ASSERT(transceiver);
connect(transceiver, SIGNAL(serviceResponded(QVariant)), SLOT(findEmittedSignal(QVariant)));
transceiver->requestToService(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
}
void DapServiceController::notifyService(const QString &asServiceName, 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)
{
DapAbstractCommand * transceiver = dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->findService(asServiceName));
Q_ASSERT(transceiver);
transceiver->notifyToService(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
}
/// Register command.
void DapServiceController::registerCommand()
{
m_transceivers.insert("ADD", qMakePair(new DapAddWalletCommand("ADD", m_DAPRpcSocket, this), QString("addWalletResponded")));
m_transceivers.insert("GET_LOG", qMakePair(new DapUpdateLogsCommand("GET_LOG", m_DAPRpcSocket, this),QString("historyLogResponded")));
m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapQuitApplicationCommand("DapQuitApplicationCommand", m_DAPRpcSocket))), QString()));
m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapActivateClientCommand("DapActivateClientCommand", m_DAPRpcSocket))), QString("clientActivated")));
m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapUpdateLogsCommand("DapUpdateLogsCommand", m_DAPRpcSocket))), QString("logUpdated")));
registerEmmitedSignal();
}
/// Find the emitted signal.
......@@ -68,20 +82,28 @@ void DapServiceController::findEmittedSignal(const QVariant &aValue)
Q_ASSERT(transceiver);
auto service = std::find_if(m_transceivers.begin(), m_transceivers.end(), [=] (const QPair<DapAbstractCommand*, QString>& it)
{
QString s = it.first->getName();
QString t = transceiver->getName();
{
return it.first->getName() == transceiver->getName() ? true : false;
});
for (int idx = 0; idx < metaObject()->methodCount(); ++idx)
{
const QMetaMethod method = metaObject()->method(idx);
if (method.methodType() == QMetaMethod::Signal && method.name() == service.value().second)
if (method.methodType() == QMetaMethod::Signal && method.name() == service->second)
{
metaObject()->method(idx).invoke(this, Q_ARG(QVariant, aValue));
}
}
}
void DapServiceController::registerEmmitedSignal()
{
foreach (auto command, m_transceivers)
{
connect(command.first, SIGNAL(clientNotifed(QVariant)), SLOT(findEmittedSignal(QVariant)));
}
}
......@@ -2,16 +2,16 @@
#define DAPSERVICECONTROLLER_H
#include <QObject>
#include <QGenericArgument>
#include <QQmlEngine>
#include <QJSEngine>
#include <QPair>
#include <QVector>
#include <algorithm>
#include "DapServiceClient.h"
#include "Handlers/DapAbstractCommand.h"
#include "Handlers/DapAddWalletCommand.h"
#include "Handlers/DapQuitApplicationCommand.h"
#include "Handlers/DapActivateClientCommand.h"
#include "Handlers/DapUpdateLogsCommand.h"
class DapServiceController : public QObject
......@@ -25,7 +25,7 @@ class DapServiceController : public QObject
/// Service connection management service.
DapServiceClient *m_pDapServiceClient {nullptr};
/// Command manager.
QMap<QString, QPair<DapAbstractCommand*, QString>> m_transceivers;
QVector<QPair<DapAbstractCommand*, QString>> m_transceivers;
/// RPC socket.
DapRpcSocket * m_DAPRpcSocket {nullptr};
/// Standard constructor
......@@ -43,6 +43,12 @@ public:
const QVariant &arg6 = QVariant(), const QVariant &arg7 = QVariant(),
const QVariant &arg8 = QVariant(), const QVariant &arg9 = QVariant(),
const QVariant &arg10 = QVariant());
Q_INVOKABLE void notifyService(const QString& asServiceName, 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());
///********************************************
/// Property
......@@ -74,11 +80,13 @@ signals:
/// The signal is emitted when the Application version property changes.
/// @param version Version
void versionChanged(const QString &version);
void clientActivated();
void addWalletResponded(const QVariant& wallet);
///A signal that is used to transmit data to the log model.
/// @param historyString QStringList
void historyLogResponded(const QVariant& historyString);
void logUpdated(const QVariant& logs);
private slots:
/// Register command.
......@@ -86,6 +94,8 @@ private slots:
/// Find the emitted signal.
/// @param aValue Transmitted parameter.
void findEmittedSignal(const QVariant& aValue);
void registerEmmitedSignal();
};
#endif // DAPSERVICECONTROLLER_H
import QtQuick 2.0
import QtQuick.Controls 2.0
import QtGraphicalEffects 1.0
import QtQuick.Window 2.0
import "screen"
ApplicationWindow
......@@ -41,4 +42,27 @@ ApplicationWindow
visible: false
}
onClosing:
{
window.hide()
}
Connections
{
target: dapServiceController
onClientActivated:
{
if(window.visibility === Window.Hidden)
{
window.show()
window.raise()
window.requestActivate()
}
else
{
window.hide()
}
}
}
}
......@@ -118,5 +118,6 @@
<file>screen/desktop/Console/DapConsoleScreenForm.ui.qml</file>
<file>screen/desktop/Console/DapConsoleTopPanel.qml</file>
<file>screen/desktop/Console/DapConsoleTopPanelForm.ui.qml</file>
<file>res/icons/icon.ico</file>
</qresource>
</RCC>
CellFrameDashboardGUI/res/icons/icon.ico

83.3 KiB

......@@ -40,17 +40,9 @@ DapLogsScreenForm
Connections
{
target: dapServiceController
onHistoryLogResponded:fillModel(historyString);
onLogUpdated:fillModel(logs);
}
//Timer for updating data in the model
Timer
{
id:loadContentLogTimer
interval: 60000
repeat: true
onTriggered: dapServiceController.requestToService("GET_LOG",200);
}
//Creates a list model for the example
Component.onCompleted:
......@@ -63,9 +55,7 @@ DapLogsScreenForm
var timeString = new Date();
var day = new Date(86400);
dapServiceController.requestToService("GET_LOG",200);
loadContentLogTimer.start();
dapServiceController.requestToService("DapUpdateLogsCommand",200);
}
ListModel
......
QT += core network
QT -= gui
QT += core network gui
CONFIG += c++11 console
CONFIG -= app_bundle
......@@ -16,8 +15,6 @@ VER_MAJ = 1
VER_MIN = 6
VER_PAT = 4
ICON = icon.ico
win32 {
CONFIG -= console
VERSION = $${VER_MAJ}.$${VER_MIN}.$$VER_PAT
......@@ -46,11 +43,15 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
$$PWD/DapServiceController.cpp \
$$PWD/DapToolTipWidget.cpp \
$$PWD/main.cpp \
HEADERS += \
$$PWD/DapServiceController.h \
$$PWD/DapToolTipWidget.h
include (../libdap/libdap.pri)
......
<RCC>
<qresource prefix="/"/>
<qresource prefix="/">
<file>res/icons/icon.ico</file>
</qresource>
</RCC>
......@@ -9,19 +9,26 @@ DapServiceController::DapServiceController(QObject *parent) : QObject(parent)
});
}
DapServiceController::~DapServiceController()
{
delete m_pToolTipWidget;
delete menuSystemTrayIcon;
}
/// Start service: creating server and socket.
/// @return Returns true if the service starts successfully, otherwise false.
bool DapServiceController::start()
{
qInfo() << "DapChainDashboardService::start()";
m_pServer = new DapUiService();
m_pServer = new DapUiService(this);
m_pServer->setSocketOptions(QLocalServer::WorldAccessOption);
if(m_pServer->listen(DAP_BRAND))
{
connect(m_pServer, SIGNAL(onClientConnected()), SIGNAL(onNewClientConnected()));
// Register command to cellframenode
registerCommand();
initSystemTrayIcon();
}
else
{
......@@ -35,6 +42,39 @@ bool DapServiceController::start()
/// Register command.
void DapServiceController::registerCommand()
{
m_pServer->addService(new DapAddWalletCommand("ADD", nullptr, this));
m_pServer->addService(new DapUpdateLogsCommand("GET_LOG", nullptr, this));
m_pServer->addService(new DapQuitApplicationCommand("DapQuitApplicationCommand", m_pServer));
m_pServer->addService(new DapActivateClientCommand("DapActivateClientCommand", m_pServer));
m_pServer->addService(new DapUpdateLogsCommand("DapUpdateLogsCommand", m_pServer, LOG_FILE));
}
void DapServiceController::initSystemTrayIcon()
{
m_pToolTipWidget = new DapToolTipWidget();
m_pSystemTrayIcon = new DapSystemTrayIcon(this);
m_pSystemTrayIcon->setToolTipWidget(m_pToolTipWidget);
m_pSystemTrayIcon->setIcon(QIcon(":/res/icons/icon.ico"));
menuSystemTrayIcon = new QMenu();
QAction * quitAction = new QAction("Quit", this);
menuSystemTrayIcon->addAction(quitAction);
m_pSystemTrayIcon->setContextMenu(menuSystemTrayIcon);
m_pSystemTrayIcon->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, [=]
{
DapQuitApplicationCommand * command = dynamic_cast<DapQuitApplicationCommand*>(m_pServer->findService("DapQuitApplicationCommand"));
Q_ASSERT(command);
command->notifyToClient();
});
// With a double click on the icon in the system tray,
// we send a command to the client to activate the main window
connect(m_pSystemTrayIcon, &DapSystemTrayIcon::activated, this, [=] (const QSystemTrayIcon::ActivationReason& reason)
{
Q_UNUSED(reason);
DapActivateClientCommand * command = dynamic_cast<DapActivateClientCommand*>(m_pServer->findService("DapActivateClientCommand"));
Q_ASSERT(command);
command->notifyToClient();
});
}
......@@ -14,6 +14,8 @@
#include <QObject>
#include <QCoreApplication>
#include <QAction>
#include <QMenu>
#include "DapRpcLocalServer.h"
......@@ -22,8 +24,12 @@ typedef class DapRpcLocalServer DapUiService;
#include "Handlers/DapAbstractCommand.h"
#include "Handlers/DapAddWalletCommand.h"
#include "Handlers/DapQuitApplicationCommand.h"
#include "Handlers/DapActivateClientCommand.h"
#include "Handlers/DapUpdateLogsCommand.h"
#include "DapSystemTrayIcon.h"
#include "DapToolTipWidget.h"
/**
* @brief The DapServiceController class
......@@ -36,12 +42,19 @@ class DapServiceController : public QObject
Q_OBJECT
/// Service core.
DapUiService * m_pServer {nullptr};
DapUiService * m_pServer {nullptr};
DapSystemTrayIcon * m_pSystemTrayIcon {nullptr};
DapToolTipWidget * m_pToolTipWidget {nullptr};
QMenu * menuSystemTrayIcon {nullptr};
public:
/// Standard constructor.
/// @param parent Parent.
explicit DapServiceController(QObject * parent = nullptr);
~DapServiceController();
/// Start service: creating server and socket.
/// @return Returns true if the service starts successfully, otherwise false.
bool start();
......@@ -53,6 +66,8 @@ signals:
private slots:
/// Register command.
void registerCommand();
void initSystemTrayIcon();
};
#endif // DAPSERVICECONTROLLER_H
#include "DapToolTipWidget.h"
DapToolTipWidget::DapToolTipWidget(QWidget *parent) : QWidget(parent)
{
setWindowFlags(Qt::FramelessWindowHint);
setFixedSize(140, 45);
m_pLabel = new QLabel(this);
QFont font("Times", 28, QFont::Bold);
m_pLabel->setFont(font);
m_pLabel->setText(QTime::currentTime().toString("hh:mm:ss"));
m_pTimer = new QTimer(this);
connect(m_pTimer, SIGNAL(timeout()), this, SLOT(slotTimerAlarm()));
m_pTimer->start(1000);
}
void DapToolTipWidget::slotTimerAlarm()
{
m_pLabel->setText(QTime::currentTime().toString("hh:mm:ss"));
}
#ifndef DAPTOOLTIPWIDGET_H
#define DAPTOOLTIPWIDGET_H
#include <QWidget>
#include <QTimer>
#include <QTime>
#include <QLabel>
class DapToolTipWidget : public QWidget
{
Q_OBJECT
QTimer * m_pTimer {nullptr};
QLabel * m_pLabel {nullptr};
public:
explicit DapToolTipWidget(QWidget *parent = nullptr);
signals:
private slots:
void slotTimerAlarm();
};
#endif // DAPTOOLTIPWIDGET_H
CellFrameDashboardService/Resources/Icons/iconErrorNetwork.png

2.49 KiB

CellFrameDashboardService/Resources/Icons/iconNetwork.png

2.25 KiB

#include <QCoreApplication>
#include <QApplication>
#include <QSystemSemaphore>
#include <QSharedMemory>
#include <QCommandLineParser>
......@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
return 1;
}
QCoreApplication a(argc, argv);
QApplication a(argc, argv);
a.setOrganizationName("DEMLABS");
a.setOrganizationDomain("demlabs.net");
a.setApplicationName("CellFrameDashboardService");
......
CellFrameDashboardService/res/icons/icon.ico

83.3 KiB

......@@ -15,10 +15,12 @@ int DapRpcAbstractServer::connectedClientCount() const
return m_clients.size();
}
void DapRpcAbstractServer::notifyConnectedClients(const DapRpcMessage &message)
DapRpcServiceReply* DapRpcAbstractServer::notifyConnectedClients(const DapRpcMessage &message)
{
DapRpcServiceReply * reply {nullptr};
for (int i = 0; i < m_clients.size(); ++i)
m_clients[i]->sendMessage(message);
reply = m_clients[i]->sendMessage(message);
return reply;
}
void DapRpcAbstractServer::notifyConnectedClients(const QString &method, const QJsonArray &params)
......
......@@ -22,7 +22,6 @@ protected:
public:
/// Standard constructor
DapRpcAbstractServer();
/// Virtual destructor
virtual ~DapRpcAbstractServer();
/// Connected clients count
......@@ -43,11 +42,13 @@ public:
// public slots:
/// Notify connected clients. Send all message
/// @param message Message to client
virtual void notifyConnectedClients(const DapRpcMessage &message);
virtual DapRpcServiceReply *notifyConnectedClients(const DapRpcMessage &message);
/// Notify connected clients. Send all message
/// @param method Method which clients were notified
/// @param params Parameters of message in JSON format
virtual void notifyConnectedClients(const QString &method, const QJsonArray &params);
};
#endif // DapRPCABSTRACTSERVER_H
......@@ -26,16 +26,16 @@ bool DapRpcLocalServer::listen(const QString &asAddress, quint16 aPort)
return QLocalServer::listen(asAddress);
}
bool DapRpcLocalServer::addService(DapRpcService *apService)
DapRpcService *DapRpcLocalServer::addService(DapRpcService *apService)
{
if (!DapRpcServiceProvider::addService(apService))
return false;
return nullptr;
connect(apService, SIGNAL(notifyConnectedClients(DapRpcMessage)),
this, SLOT(notifyConnectedClients(DapRpcMessage)));
connect(apService, SIGNAL(notifyConnectedClients(QString,QJsonArray)),
this, SLOT(notifyConnectedClients(QString,QJsonArray)));
return true;
return apService;
}
bool DapRpcLocalServer::removeService(DapRpcService *apService)
......@@ -50,6 +50,11 @@ bool DapRpcLocalServer::removeService(DapRpcService *apService)
return true;
}
DapRpcService *DapRpcLocalServer::findService(const QString &asServiceName)
{
return DapRpcServiceProvider::findService(asServiceName);
}
void DapRpcLocalServer::clientDisconnected()
{
QLocalSocket *localSocket = static_cast<QLocalSocket*>(sender());
......@@ -78,9 +83,9 @@ void DapRpcLocalServer::messageProcessing(const DapRpcMessage &asMessage)
processMessage(socket, asMessage);
}
void DapRpcLocalServer::notifyConnectedClients(const DapRpcMessage &message)
DapRpcServiceReply *DapRpcLocalServer::notifyConnectedClients(const DapRpcMessage &message)
{
DapRpcAbstractServer::notifyConnectedClients(message);
return DapRpcAbstractServer::notifyConnectedClients(message);
}
void DapRpcLocalServer::notifyConnectedClients(const QString &method, const QJsonArray &params)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment