Newer
Older
#ifndef DAPSERVICECONTROLLER_H
#define DAPSERVICECONTROLLER_H
#include <QObject>
#include <QQmlEngine>
#include <QJSEngine>
#include <QApplication>
#include <QTimer>
littletux89
committed
#include <QMap>
#include <QPair>
#include "DapCommandController.h"
#include "DapServiceClient.h"
littletux89@gmail.com
committed
#include "DapChainWalletsModel.h"
#include "DapChainNodeNetworkModel.h"
#include "DapConsoleModel.h"
class DapServiceController : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(DapServiceController)
/// Brand сompany.
QString m_sBrand {DAP_BRAND};
/// Application version.
QString m_sVersion {DAP_VERSION};
/// Settings file.
QString m_sSettingFile {DAP_SETTINGS_FILE};
/// Service connection management service.
DapServiceClient *m_pDapServiceClient {nullptr};
/// RPC protocol controller.
DapCommandController *m_pDapCommandController {nullptr};
explicit DapServiceController(QObject *apParent = nullptr);
public:
/// Get an instance of a class.
/// @return Instance of a class.
Q_INVOKABLE static DapServiceController &getInstance();
///********************************************
/// Property
/// *******************************************
/// Brand сompany.
Q_PROPERTY(QString Brand MEMBER m_sBrand READ getBrand NOTIFY brandChanged)
/// Application version.
Q_PROPERTY(QString Version MEMBER m_sVersion READ getVersion NOTIFY versionChanged)
/// Result execute command.
Q_PROPERTY(QString Result MEMBER m_sVersion READ getResult NOTIFY resultChanged)
///********************************************
/// Interface
/// *******************************************
void init(DapServiceClient *apDapServiceClient);
/// Get company brand.
/// @return Brand сompany.
QString getBrand() const;
/// Get app version.
/// @return Application version.
QString getVersion() const;
/// Get setting file name.
/// @return Setting file name
QString getSettingFile() const;
/// Get result command execute.
/// @return Result execute.
QString getResult();
littletux89@gmail.com
committed
/// Get node logs.
/// @param aiTimeStamp Timestamp start reading logging.
/// @param aiRowCount Number of lines displayed.
void getNodeLogs(int aiTimeStamp, int aiRowCount) const;
Q_INVOKABLE void getWallets() const;
DapLogModel getLogModel() const;
void setLogModel(const DapLogModel &dapLogModel);
littletux89
committed
Q_INVOKABLE void addWallet(const QString& asWalletName);
Q_INVOKABLE void removeWallet(int index, const QString& asWalletName);
Q_INVOKABLE void sendToken(const QString &asSendWallet, const QString& asAddressReceiver, const QString& asToken, const QString& aAmount);
void getWalletInfo(const QString& asWalletName);
signals:
/// 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 result execute property changes.
void resultChanged();
/// The signal is emitted when the main application window is activated.
void activateWindow();
/// The signal is emitted when checking the existence of an already running copy of the application.
void isExistenceClient(bool isExistenceClient);
void sendNodeNetwork(const QVariant& aData);
void userSettingsLoaded();
void userSettingsSaved();
littletux89@gmail.com
committed
private slots:
/// Handling service response for receiving node logs.
/// @param aNodeLogs List of node logs.
void processGetNodeLogs(const QStringList& aNodeLogs);
littletux89@gmail.com
committed
void processAddWallet(const QString& asWalletName, const QString& asWalletAddress);
littletux89
committed
littletux89@gmail.com
committed
void processSendToken(const QString& asAnswer);
littletux89
committed
void processGetWallets(const QMap<QString, QVariant>& aWallets);
littletux89@gmail.com
committed
void processGetWalletInfo(const QString& asWalletName, const QString& asWalletAddress, const QStringList &aBalance, const QStringList& aTokens);
void processExecuteCommandInfo(const QString& result);
void processGetNodeNetwork(const QVariant& aData);
void processGetHistory(const QVariant& aData);
/// Change status of node
/// @param it is true if a node is online
void setNodeStatus(const bool aIsOnline);
/// Get node logs.
Q_INVOKABLE void getNodeLogs() const;
void clearLogModel();
/// Show or hide GUI client by clicking on the tray icon.
/// @param aIsActivated Accepts true - when requesting to
/// display a client, falso - when requesting to hide a client.
void activateClient(bool aIsActivated);
/// Shut down client.
void closeClient();
/// Load user settings from settings file
void loadUserSettings();
/// Save user settings to file
void saveUserSettings();
/// 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 // DAPSERVICECONTROLLER_H