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 791 additions and 9 deletions
CMakeCache.txt *.user*
CMakeFiles *~
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
TEMPLATE = subdirs
SUBDIRS = KelvinDashboardGUI KelvinDashboardService
KelvinDashboardGUI.subdir = KelvinDashboardGUI
KelvinDashboardService.subdir = KelvinDashboardService
KelvinDashboardGUI.depends = KelvinDashboardService
!defined(BRAND, var)
{
BRAND = KelvinDashboard
}
#include "DapClient.h"
/// Standard сonstructor.
DapClient::DapClient(QObject *parent) : QObject(parent)
{
connect(&m_localClient, &DapLocalClient::commandRecieved, this, &DapClient::identificationCommand);
connect(&m_localClient, static_cast<void(DapLocalClient::*)(DapLocalClient::LocalSocketError)>(&DapLocalClient::error), this, &DapClient::errorHandler);
connect(&m_localClient, &DapLocalClient::connected, this, [=]
{
QTimer::singleShot(1000, [&]
{
emit connectedToService();
});
});
}
/// Get an instance of a class.
/// @return Instance of a class.
DapClient &DapClient::getInstance()
{
static DapClient instance;
return instance;
}
/// Connect to the service.
/// @brief The name of the service connection is set from the NameSrvice property.
void DapClient::connectToService()
{
qDebug() << "Connect to service ()" << getNameSrvice();
m_localClient.connectToServer(getNameSrvice());
}
/// Connect to the service.
/// @param nameService Service connection name.
void DapClient::connectToService(const QString &nameService)
{
setNameSrvice(nameService);
qDebug() << "Connect to servoce (nameService)";
m_localClient.connectToServer(nameService);
}
/// Authorize user.
/// @param password User password.
void DapClient::authorization(const QString &password)
{
qDebug() << "Authorization " << password << endl;
DapCommand command(TypeDapCommand::Authorization, 1, { password });
m_localClient.sendCommand(command);
}
/// Handle connection error.
/// @param socketError Error local connection of the client with the service.
void DapClient::errorHandler(const DapLocalClient::LocalSocketError &socketError)
{
switch (socketError) {
case DapLocalClient::PeerClosedError:
case DapLocalClient::ConnectionRefusedError:
case DapLocalClient::ServerNotFoundError:
QTimer::singleShot(1000, [&]
{
connectToService();
emit errorConnect();
} );
break;
default:
break;
}
}
/// Get the name of the service connection.
/// @return The name of the service connection.
QString DapClient::getNameSrvice() const
{
return m_nameService;
}
/// Set the name of the service connection.
/// @param nameService Service connection name.
void DapClient::setNameSrvice(const QString &nameService)
{
m_nameService = nameService;
m_localClient.setNameConnect(nameService);
}
/// Get company brand.
/// @return Brand сompany.
QString DapClient::getBrand() const
{
return m_brand;
}
/// Get app version.
/// @return Application version.
QString DapClient::getVersion() const
{
return m_version;
}
/// Get user authorization flag.
/// @return Returns true if the user is authorized, otherwise - false.
bool DapClient::getIsAuthorization() const
{
return m_isAuthorization;
}
/// Set user authorization flag.
/// @param isAuthorization The value of the user authorization flag.
void DapClient::setIsAuthorization(bool isAuthorization)
{
m_isAuthorization = isAuthorization;
emit isAuthorizationChanged(m_isAuthorization);
}
/// /// Identification of the command received.
/// @param command Command received.
/// @return Returns true if the command is identified, otherwise - false.
bool DapClient::identificationCommand(const DapCommand &command)
{
qDebug() << "Identification command: " << command.getTypeCommand();
qDebug() << "Identification command: " << command.getArguments().count();
switch (command.getTypeCommand())
{
case TypeDapCommand::Authorization:
if(command.getArgument(0).toBool())
setIsAuthorization(true);
else
setIsAuthorization(false);
return true;
case TypeDapCommand::ActivateWindowClient:
emit activateWindow();
return true;
case TypeDapCommand::CheckExistenceClient:
if(command.getArgument(0).toBool())
emit isExistenceClient(true);
else
emit isExistenceClient(false);
return true;
case TypeDapCommand::CloseClient:
qApp->quit();
return true;
default:
return false;
}
}
/// Method that implements the singleton pattern for the qml layer.
/// @param engine QML application.
/// @param scriptEngine The QJSEngine class provides an environment for evaluating JavaScript code.
QObject *DapClient::singletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return &getInstance();
}
/****************************************************************************
**
** This file is part of the KelvinDashboardGUI application.
**
** The class implements the GUI interface of the application. Designed to
** broadcast user actions to the service. Manages the state of graphic
** elements of the GUI framework, connection with the service, identification
** of commands received from the service, etc.
**
** Class implements a singleton pattern.
**
****************************************************************************/
#ifndef DAPCLIENT_H
#define DAPCLIENT_H
#include <QObject>
#include <QLocalSocket>
#include <QQmlEngine>
#include <QJSEngine>
#include <QApplication>
#include <QTimer>
#include "DapCommand.h"
#include "DapLocalClient.h"
class DapClient : public QObject
{
Q_OBJECT
/// Local client.
DapLocalClient m_localClient;
/// Brand сompany.
QString m_brand {DAP_BRAND};
/// Application version.
QString m_version {DAP_VERSION};
/// Service connection name.
QString m_nameService;
/// User authorization flag.
bool m_isAuthorization {false};
/// Standard сonstructor.
explicit DapClient(QObject *parent = nullptr);
public:
DapClient(const DapClient&) = delete;
DapClient& operator= (const DapClient &) = delete;
/// Get an instance of a class.
/// @return Instance of a class.
Q_INVOKABLE static DapClient &getInstance();
///********************************************
/// Property
/// *******************************************
/// Service connection name.
Q_PROPERTY(QString NameSrvice MEMBER m_nameService READ getNameSrvice WRITE setNameSrvice NOTIFY nameSrviceChanged)
/// Brand сompany.
Q_PROPERTY(QString Brand MEMBER m_brand READ getBrand NOTIFY brandChanged)
/// Application version.
Q_PROPERTY(QString Version MEMBER m_version READ getVersion NOTIFY versionChanged)
/// User authorization flag.
Q_PROPERTY(bool IsAuthorization MEMBER m_isAuthorization READ getIsAuthorization WRITE setIsAuthorization NOTIFY isAuthorizationChanged)
///********************************************
/// Interface
/// *******************************************
/// Connect to the service.
/// @brief The name of the service connection is set from the NameSrvice property.
Q_INVOKABLE void connectToService();
/// Connect to the service.
/// @param nameService Service connection name.
Q_INVOKABLE void connectToService(const QString &nameService);
/// Authorize user.
/// @param password User password.
Q_INVOKABLE void authorization(const QString &password);
/// Handle connection error.
/// @param socketError Error local connection of the client with the service.
void errorHandler(const QLocalSocket::LocalSocketError& socketError);
/// Get the name of the service connection.
/// @return The name of the service connection.
QString getNameSrvice() const;
/// Set the name of the service connection.
/// @param nameService Service connection name.
void setNameSrvice(const QString &nameService);
/// Get company brand.
/// @return Brand сompany.
QString getBrand() const;
/// Get app version.
/// @return Application version.
QString getVersion() const;
/// Get user authorization flag.
/// @return Returns true if the user is authorized, otherwise - false.
bool getIsAuthorization() const;
/// Set user authorization flag.
/// @param isAuthorization The value of the user authorization flag.
void setIsAuthorization(bool isAuthorization);
signals:
/// The signal is emitted when a successful connection to the service is established.
void connectedToService();
/// The signal is emitted when the connection to the service is broken.
void disconnectedFromService();
/// The signal is emitted when the name of the client's connection with the service is changed.
void nameSrviceChanged(const QString &nameService);
/// The signal is emitted when the Brand company property changes.
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 User authorization flag property changes.
void isAuthorizationChanged(bool isAuthorization);
/// The signal is emitted when the main application window is activated.
void activateWindow();
/// The signal is emitted when an error occurs in the connection between the client and the service.
void errorConnect();
/// The signal is emitted when checking the existence of an already running copy of the application.
void isExistenceClient(bool isExistenceClient);
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);
/// Method that implements the singleton pattern for the qml layer.
/// @param engine QML application.
/// @param scriptEngine The QJSEngine class provides an environment for evaluating JavaScript code.
static QObject *singletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine);
};
#endif // DAPCLIENT_H
import QtQuick 2.9
import QtQml 2.11
import QtQuick.Controls 2.2
import KelvinDashboard 1.0
DapUiQmlScreenAbout {
id: dapQmlScreenAbout
textTitle.text: DapClient.Brand
textAbout.text: "KelvinDashboard"
textVersion.text: "Version " + DapClient.Version
textYear.text: new Date().toLocaleDateString(locale, "dd MMM yyyy")
}
import QtQuick 2.0
import KelvinDashboard 1.0
DapUiQmlScreenLogin {
id: dapQmlScreenLogin
function acceptPassword()
{
dapScreenLogin.Password = textFieldPassword.text
DapClient.authorization(textFieldPassword.text)
console.log(textFieldPassword.text)
}
Connections {
target: dapClient
onIsAuthorizationChanged: {
console.log("PARAM " + isAuthorization)
textStatus.visible = true
if(isAuthorization)
{
textStatus.text = "Password confirmed"
textStatus.color = "green"
textFieldPassword.color = "green"
}
else
{
textStatus.text = "Password not verified"
textStatus.color = "red"
textFieldPassword.color = "red"
}
}
}
buttonPassword.onClicked: acceptPassword()
}
#ifndef DAPUIQMLSCREENDIALOG_H
#define DAPUIQMLSCREENDIALOG_H
class DapUiQmlScreenDialog
{
public:
DapUiQmlScreenDialog();
};
#endif // DAPUIQMLSCREENDIALOG_H
#include "DapScreenLogin.h"
DapScreenLogin::DapScreenLogin(QObject *parent) : QObject(parent)
{
connect(this, &DapScreenLogin::passwordChanged, this, &DapScreenLogin::autorization);
}
QString DapScreenLogin::getPassword() const
{
return m_password;
}
void DapScreenLogin::setPassword(const QString &password)
{
qDebug() << "Set password: " << password << endl;
m_password = password;
}
bool DapScreenLogin::autorization(const QString &password)
{
}
#ifndef DAPSCREENLOGIN_H
#define DAPSCREENLOGIN_H
#include <QObject>
#include <QDebug>
class DapScreenLogin : public QObject
{
Q_OBJECT
QString m_password;
public:
explicit DapScreenLogin(QObject *parent = nullptr);
Q_PROPERTY(QString Password MEMBER m_password READ getPassword WRITE setPassword NOTIFY passwordChanged)
QString getPassword() const;
void setPassword(const QString &password);
Q_INVOKABLE bool autorization(const QString& password);
signals:
void passwordChanged(const QString& password);
public slots:
};
#endif // DAPSCREENLOGIN_H
import QtQuick 2.0
ListModel {
id: listModelMenu
ListElement {
name: qsTr("Blockchain explorer")
page: "DapUiQmlWidgetChainBlockExplorer.ui.qml"
}
ListElement {
name: qsTr("Exchanges")
page: "DapUiQmlWidgetChainExchanges.ui.qml"
}
ListElement {
name: qsTr("Services client")
page: "DapUiQmlWidgetChainServicesClient.ui.qml"
}
ListElement {
name: qsTr("Services share control")
page: "DapUiQmlWidgetChainServicesShareControl.ui.qml"
}
ListElement {
name: qsTr("Settings")
page: "DapUiQmlWidgetChainSettings.ui.qml"
}
ListElement {
name: qsTr("Wallet")
page: "DapUiQmlWidgetChainWallet.ui.qml"
}
}
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.1
Page {
id: dapUiQmlScreenAbout
property alias textTitle: textTitle
property alias textAbout: textAbout
property alias textVersion: textVersion
property alias textYear: textYear
title: qsTr("About")
ColumnLayout {
id: columnScreenLogin
width: parent.width
anchors.centerIn: parent
clip: true
RowLayout {
id: rowAboutInformation
spacing: 15
Layout.alignment: Qt.AlignHCenter
Layout.bottomMargin: 20
Image {
id: name
source: "qrc:/Resources/Icons/icon.png"
scale: 2
Layout.alignment: Qt.AlignHCenter
}
ColumnLayout {
id: columnText
Text {
id: textTitle
width: parent.width
font.pointSize: 14
font.bold: true
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
Layout.alignment: Qt.AlignHCenter
}
Text {
id: textAbout
width: parent.width
font.pointSize: 12
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
Layout.alignment: Qt.AlignHCenter
}
}
}
Text {
id: textVersion
width: parent.width
font.pointSize: 10
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
Layout.alignment: Qt.AlignHCenter
}
Text {
id: textYear
width: parent.width
font.pointSize: 10
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
Layout.alignment: Qt.AlignHCenter
}
}
}
#include "DapUiQmlScreenDashboard.h"
DapUiQmlScreenDashboard::DapUiQmlScreenDashboard()
{
}
#ifndef DAPUIQMLSCREENDASHBOARD_H
#define DAPUIQMLSCREENDASHBOARD_H
class DapUiQmlScreenDashboard
{
public:
DapUiQmlScreenDashboard();
};
#endif // DAPUIQMLSCREENDASHBOARD_H
\ No newline at end of file
import QtQuick 2.9
import QtQuick.Controls 1.4
import QtQuick.Controls 2.2
import QtQuick.Controls.Styles 1.4
Page {
id: dapUiQmlScreenDashboard
title: qsTr("General")
ListView {
id: listViewTabs
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: parent.left
width: dapUiQmlScreenDashboard.width/5
model: listModelTabs
ListModel {
id: listModelTabs
ListElement {
name: qsTr("Login")
page: "DapQmlScreenLogin.qml"
}
ListElement {
name: qsTr("Dashboard")
page: "DapUiQmlScreenDialog.qml"
}
ListElement {
name: qsTr("About")
page: "DapQmlScreenAbout.qml"
}
}
delegate:
Component {
id: componentTab
Item {
width: listViewTabs.width
height: textTab.height + 10
Rectangle {
id: canvas
border.color: "whitesmoke"
color: "Transparent"
anchors.fill: parent
Row {
anchors.margins: 5
anchors.fill: parent
Text
{
id: textTab
text: qsTr(name)
}
}
}
MouseArea {
anchors.fill: parent
onClicked:
{
listViewTabs.currentIndex = index
stackViewScreenDashboard.setSource(Qt.resolvedUrl(page))
}
}
}
}
highlight: Rectangle { color: "aliceblue"; radius: 1 }
focus: true
}
Rectangle {
anchors.left: listViewTabs.right
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.right: parent.right
border.color: "whitesmoke"
Loader {
id: stackViewScreenDashboard
anchors.fill: parent
anchors.margins: 1
source: "DapQmlScreenLogin.qml"
}
}
}
#include "DapScreenDialog.h"
DapUiQmlScreenDialog::DapUiQmlScreenDialog()
{
}
import QtQuick 2.9
import QtQuick.Controls 2.4
Page {
id: dapUiQmlScreenDialog
title: qsTr("Dashboard")
anchors.fill: parent
Rectangle {
color: "white"
anchors.fill: parent
GridView {
id: gridViewDashboard
anchors.fill: parent
cellWidth: width/3; cellHeight: height/2
focus: true
model: DapUiQmlListModelWidgets {}
highlight: Rectangle { width: gridViewDashboard.cellWidth; height: gridViewDashboard.cellHeight; radius: width/50; color: "aliceblue" }
delegate: Item {
width: gridViewDashboard.cellWidth
height: gridViewDashboard.cellHeight
Rectangle {
anchors.fill: parent
border.color: "grey"
color: "transparent"
radius: width/50
anchors.margins: 5
clip: true
Column {
width: parent.width
anchors.centerIn: parent
spacing: width / 10
anchors.margins: width / 10
Image {
id: iconWidget
source: "qrc:/Resources/Icons/add.png"
width: parent.width * 2/3
height: width
anchors.horizontalCenter: parent.horizontalCenter
}
Text {
text: name
color: "darkgrey"
anchors.horizontalCenter: parent.horizontalCenter
}
}
}
MouseArea {
anchors.fill: parent
onClicked:
{
parent.GridView.view.currentIndex = index;
stackView.push(Qt.resolvedUrl(page), StackView.Immediate);
}
}
}
}
}
}
#include "DapUiQmlScreenLogin.h"
DapUiQmlScreenLogin::DapUiQmlScreenLogin(QObject *parent) : QObject(parent)
{
}
QString DapUiQmlScreenLogin::getPassword() const
{
}
void DapUiQmlScreenLogin::setPassword(const QString &password)
{
}
#ifndef DAPUIQMLSCREENLOGIN_H
#define DAPUIQMLSCREENLOGIN_H
#include <QObject>
class DapUiQmlScreenLogin : public QObject
{
Q_OBJECT
QString m_password;
public:
explicit DapUiQmlScreenLogin(QObject *parent = nullptr);
Q_PROPERTY(QString Password MEMBER m_password READ Password WRITE setPassword NOTIFY passwordChanged)
QString getPassword() const;
void setPassword(const QString &password);
signals:
void passwordChanged(const QString& password);
public slots:
};
#endif // DAPUIQMLSCREENLOGIN_H
\ No newline at end of file
import QtQuick 2.9
import QtQuick.Controls 2.2
import KelvinDashboard 1.0
Page {
id: dapUiQmlScreenLogin
property alias dapScreenLogin: dapScreenLogin
property alias textFieldPassword: textFieldPassword
property alias buttonPassword: buttonPassword
property alias textStatus: textStatus
title: qsTr("Login")
DapScreenLogin
{
id: dapScreenLogin
}
Column {
id: columnScreenLogin
width: parent.width
anchors.centerIn: parent
spacing: 10
clip: true
TextField {
id: textFieldPassword
placeholderText: "Password"
echoMode: TextInput.Password
anchors.horizontalCenter: parent.horizontalCenter
}
Text {
id: textStatus
width: parent.width
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
anchors.horizontalCenter: parent.horizontalCenter
visible: false
}
Button {
id: buttonPassword
text: "Log in"
width: textFieldPassword.width
anchors.horizontalCenter: parent.horizontalCenter
focus: true
}
}
}
import QtQuick 2.9
import QtQuick.Controls 1.4
import QtQuick.Controls 2.4
Page {
title: qsTr("General")
}
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