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

Created framework GUI client, and also began work on the service

parent 96c16cea
No related branches found
No related tags found
No related merge requests found
Showing
with 564 additions and 0 deletions
KelvinDashboardGUI/Resources/Icons/add.png

66.7 KiB

KelvinDashboardGUI/Resources/Icons/icon.ico

2.4 KiB

KelvinDashboardGUI/Resources/Icons/icon.png

2.61 KiB

KelvinDashboardGUI/Resources/Icons/iconErrorNetwork.png

2.49 KiB

KelvinDashboardGUI/Resources/Icons/iconNetwork.png

2.25 KiB

#include <QApplication>
#include <QGuiApplication>
#include <QtQml>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QIcon>
#include <QSystemSemaphore>
#include <QSharedMemory>
#include "DapHalper.h"
#include "DapClient.h"
#include "DapScreenLogin.h"
int main(int argc, char *argv[])
{
// Creating a semaphore for locking external resources, as well as initializing an external resource-memory
QSystemSemaphore systemSemaphore(QString("systemSemaphore for %1").arg("KelvinDashboardGUI"), 1);
#ifndef Q_OS_WIN
QSharedMemory memmoryAppBagFix(QString("memmory for %1").arg("KelvinDashboardGUI"));
#endif
QSharedMemory memmoryApp(QString("memmory for %1").arg("KelvinDashboardGUI"));
// Check for the existence of a running instance of the program
bool isRunning = DapHalper::getInstance().checkExistenceRunningInstanceApp(systemSemaphore, memmoryApp, memmoryAppBagFix);
if(isRunning)
{
return 1;
}
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
app.setOrganizationName("DEMLABS");
app.setOrganizationDomain("demlabs.com");
app.setApplicationName("Kelvin Client");
app.setWindowIcon(QIcon(":/Resources/Icons/icon.ico"));
// Set the name of the service connection
DapClient::getInstance().setNameSrvice(app.applicationName());
// We establish a connection with the service
DapClient::getInstance().connectToService("Kelvin Client");
qmlRegisterType<DapScreenLogin>("KelvinDashboard", 1, 0, "DapScreenLogin");
qmlRegisterSingletonType<DapClient>("KelvinDashboard", 1, 0, "DapClient", DapClient::singletonProvider);
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("dapClient", &DapClient::getInstance());
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
import QtQuick 2.9
import QtQuick.Controls 1.4
import QtQuick.Controls 2.4
import QtQuick.Window 2.0
import QtQuick.Controls.Styles 1.4
import Qt.labs.platform 1.0
ApplicationWindow {
id: window
visible: true
width: 640
height: 480
onClosing: {
window.hide()
}
Connections {
target: dapClient
onActivateWindow: {
if(window.visibility === Window.Hidden) {
window.show()
window.raise()
window.requestActivate()
} else {
window.hide()
}
}
onErrorConnect: {
imageNetwork.visible = false
if(imageErrorNetwork.visible)
imageErrorNetwork.visible = false
else
imageErrorNetwork.visible = true
}
onConnectedToService: {
imageNetwork.visible = true
imageErrorNetwork.visible = false
console.log("Connected")
}
}
header: ToolBar {
contentHeight: buttomMenu.implicitHeight
spacing: 20
ToolButton {
id: buttomMenu
text: stackView.depth > 1 ? "\u25C0" : "\u2630"
font.pixelSize: Qt.application.font.pixelSize * 1.6
onClicked: {
if (stackView.depth > 1) {
stackView.pop()
} else {
drawerMenu.open()
}
}
}
Label {
id: labelTitleWidget
text: stackView.currentItem.title
anchors.centerIn: parent
}
Image {
id: imageNetwork
source: "qrc:/Resources/Icons/iconNetwork.png"
scale: 0.7
visible: false
anchors.verticalCenter: parent.verticalCenter
anchors.right: labelBalance.left
}
Image {
id: imageErrorNetwork
source: "qrc:/Resources/Icons/iconErrorNetwork.png"
scale: 0.7
visible: true
anchors.verticalCenter: parent.verticalCenter
anchors.right: labelBalance.left
}
Text {
id: labelBalance
text: "$0"
font.pointSize: 16
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: 10
}
}
Drawer {
id: drawerMenu
width: window.width * 0.25
height: window.height
ListView {
id: listViewMenu
anchors.fill: parent
model: listModelMenu
DapUiQmlListModelWidgets {
id: listModelMenu
}
delegate:
Component {
id: listViewItemMenu
Item {
id: itemMenu
width: listViewMenu.width
height: textItemMenu.height + 10
Row {
anchors.margins: 5
anchors.fill: parent
Text
{
id: textItemMenu
text: qsTr(name)
}
}
MouseArea {
anchors.fill: parent
onClicked:
{
listViewMenu.currentIndex = index
stackView.push(Qt.resolvedUrl(page), StackView.Immediate)
drawerMenu.close()
}
}
}
}
highlight: Rectangle { color: "aliceblue"; radius: 5 }
focus: true
}
}
StackView {
id: stackView
initialItem: "DapUiQmlScreenDashboard.qml"
anchors.fill: parent
}
}
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>DapUiQmlScreenDashboard.qml</file>
<file>DapUiQmlScreenMainWindow.ui.qml</file>
<file>KelvinDashboardGUI.conf</file>
<file>DapUiQmlScreenLogin.ui.qml</file>
<file>DapUiQmlWidgetChainBlockExplorer.ui.qml</file>
<file>DapUiQmlWidgetChainExchanges.ui.qml</file>
<file>DapUiQmlWidgetChainServicesClient.ui.qml</file>
<file>DapUiQmlWidgetChainServicesShareControl.ui.qml</file>
<file>DapUiQmlWidgetChainSettings.ui.qml</file>
<file>DapUiQmlWidgetChainWallet.ui.qml</file>
<file>DapUiQmlScreenDialog.qml</file>
<file>Resources/Icons/icon.png</file>
<file>Resources/Icons/icon.ico</file>
<file>DapUiQmlListModelWidgets.qml</file>
<file>Resources/Icons/add.png</file>
<file>DapQmlScreenLogin.qml</file>
<file>DapUiQmlScreenAbout.ui.qml</file>
<file>DapQmlScreenAbout.qml</file>
<file>Resources/Icons/iconErrorNetwork.png</file>
<file>Resources/Icons/iconNetwork.png</file>
</qresource>
</RCC>
#include "DapChainDashboardAuth.h"
/// Standart constructor.
DapChainDashboardAuth::DapChainDashboardAuth(QObject *parent) : QObject(parent)
{
}
/// Get user password.
/// @return User password.
QString DapChainDashboardAuth::getPassword() const
{
return m_password;
}
/// Set user password.
/// @param password User password.
void DapChainDashboardAuth::setPassword(const QString &password)
{
m_password = password;
}
/// Execute the command.
/// @param command Executable command.
void DapChainDashboardAuth::runCommand(const DapCommand &command)
{
qDebug() << "Run command authorization";
DapCommand *answerCommand = new DapCommand(TypeDapCommand::Authorization);
answerCommand->setCountArguments(1);
if(getPassword() == command.getArgument(0).toString())
answerCommand->addArgument(true);
else
answerCommand->addArgument(false);
emit onCommandCompleted(*answerCommand);
}
/****************************************************************************
**
** This file is part of the KelvinDashboardService application.
**
** The class implements the authorization object. Stores the user password,
** provides a user authorization mechanism in the service.
**
****************************************************************************/
#ifndef DAPCHAINDASHBOARDAUTH_H
#define DAPCHAINDASHBOARDAUTH_H
#include <QObject>
#include "DapCommand.h"
class DapChainDashboardAuth : public QObject
{
Q_OBJECT
protected:
/// User password.
QString m_password = "123";
public:
/// Standart constructor.
explicit DapChainDashboardAuth(QObject *parent = nullptr);
///********************************************
/// Interface
/// *******************************************
/// Get user password.
/// @return User password.
QString getPassword() const;
/// Set user password.
/// @param password User password.
void setPassword(const QString &password);
/// Execute the command.
/// @param command Executable command.
void runCommand(const DapCommand& command);
signals:
/// The signal is emitted when the command is successful.
/// @param command The executed command.
void onCommandCompleted(const DapCommand& command);
};
#endif // DAPCHAINDASHBOARDAUTH_H
#include "DapChainDashboardService.h"
DapChainDashboardService::DapChainDashboardService(QObject *parent) : QObject(parent)
{
// Creating a local server to establish connection with the GUI client and then connect to it.
m_dapLocalServer = new DapLocalServer("Kelvin Client");
m_dapLocalServer->connectWithClient();
// Signal-slot connection that triggers the identification of a received command.
connect(m_dapLocalServer, &DapLocalServer::commandRecieved, this, &DapChainDashboardService::identificationCommand);
// Signal-slot connection, starts processing the user authorization command.
connect(&m_dapChainDashboardAuth, &DapChainDashboardAuth::onCommandCompleted, m_dapLocalServer, &DapLocalServer::sendCommand);
}
/// Identification of the command received.
/// @param command Command received
/// @return Returns true if the command is identified, otherwise - false.
bool DapChainDashboardService::identificationCommand(const DapCommand &command)
{
qDebug() << "Identification command: " << command.getTypeCommand();
switch (command.getTypeCommand())
{
// User authorization
case TypeDapCommand::Authorization:
m_dapChainDashboardAuth.runCommand(command);
return true;
default:
return false;
}
}
/// 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::clientActivated(const QSystemTrayIcon::ActivationReason& reason)
{
qDebug() << "Client activated";
switch (reason)
{
case QSystemTrayIcon::Trigger:
{
if(m_dapLocalServer->isClientExist())
{
qDebug() << "Send command activated";
DapCommand *command = new DapCommand(TypeDapCommand::ActivateWindowClient, {true});
m_dapLocalServer->sendCommand(*command);
}
}
break;
default:
break;
}
}
/// Shut down client.
void DapChainDashboardService::closeClient()
{
DapCommand *command = new DapCommand(TypeDapCommand::CloseClient, {true});
m_dapLocalServer->sendCommand(*command);
}
/// System tray initialization.
void DapChainDashboardService::initTray()
{
QSystemTrayIcon *trayIconKelvinDashboard = new QSystemTrayIcon();
trayIconKelvinDashboard->setIcon(QIcon(":/Resources/Icons/icon.ico"));
trayIconKelvinDashboard->setToolTip("KelvinDashboard");
QMenu * menuKelvinDashboardService = new QMenu();
QAction * quitAction = new QAction("Выход");
menuKelvinDashboardService->addAction(quitAction);
trayIconKelvinDashboard->setContextMenu(menuKelvinDashboardService);
trayIconKelvinDashboard->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();
qApp->quit();
});
// With a double click on the icon in the system tray,
// we send a command to the client to activate the main window
connect(trayIconKelvinDashboard, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(clientActivated(QSystemTrayIcon::ActivationReason)));
}
/****************************************************************************
**
** This file is part of the KelvinDashboardService application.
**
** The class implements the main application object CalvinDashboardService.
** It involves the implementation of the interaction of all the components
** of the service components. For example, identification of commands,
** control of the authorization mechanism, management of an GUI client, etc.
**
****************************************************************************/
#ifndef DAPCHAINDASHBOARDSERVICE_H
#define DAPCHAINDASHBOARDSERVICE_H
#include <QObject>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QAction>
#include <QApplication>
#include "DapLocalServer.h"
#include "DapChainDashboardAuth.h"
class DapChainDashboardService : public QObject
{
Q_OBJECT
/// The object responsible for authorization of the user in the application.
DapChainDashboardAuth m_dapChainDashboardAuth;
/// Local server for establishing connection with GUI client.
DapLocalServer *m_dapLocalServer;
public:
/// Standard сonstructor.
explicit DapChainDashboardService(QObject *parent = nullptr);
public slots:
/// Identification of the command received.
/// @param command Command received.
/// @return Returns true if the command is identified, otherwise - false.
bool identificationCommand(const DapCommand &command);
/// 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 clientActivated(const QSystemTrayIcon::ActivationReason& reason);
/// Shut down client.
void closeClient();
/// System tray initialization.
void initTray();
};
#endif // DAPCHAINDASHBOARDSERVICE_H
#include "DapChainNode.h"
DapChainNode::DapChainNode(QObject *parent) : QObject(parent)
{
}
#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
#include "DapChainNodeCache.h"
DapChainNodeCache::DapChainNodeCache(QObject *parent) : QObject(parent)
{
}
#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
QT += network widgets
QT += gui
CONFIG += c++11
CONFIG -= app_bundle
!defined(BRAND,var){
# Default brand
BRAND = KelvinDashboard
}
TARGET = $${BRAND}Service
VER_MAJ = 1
VER_MIN = 0
VER_PAT = 0
ICON = icon.ico
win32 {
VERSION = $${VER_MAJ}.$${VER_MIN}.$$VER_PAT
}
else {
VERSION = $$VER_MAJ\.$$VER_MIN\-$$VER_PAT
}
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
DapChainDashboardService.cpp \
DapChainDashboardAuth.cpp \
DapChainNode.cpp \
DapChainNodeCache.cpp
HEADERS += \
DapChainDashboardService.h \
DapChainDashboardAuth.h \
DapChainNode.h \
DapChainNodeCache.h
include (../libKelvinDashboardCommon/libKelvinDashboardCommon.pri)
INCLUDEPATH += $$_PRO_FILE_PWD_/../libKelvinDashboardCommon/
RESOURCES += \
KelvinDashboardService.qrc
DISTFILES +=
<RCC>
<qresource prefix="/">
<file>Resources/Icons/add.png</file>
<file>Resources/Icons/icon.ico</file>
<file>Resources/Icons/icon.png</file>
</qresource>
</RCC>
KelvinDashboardService/Resources/Icons/add.png

66.7 KiB

KelvinDashboardService/Resources/Icons/icon.ico

2.4 KiB

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