Files
esa-remote-lite/WebSocketController.h

69 lines
1.9 KiB
C++

#pragma once
#include <QObject>
#include <QString>
#include <QStringList>
#include <QWebSocket>
class GamesPanel;
class LightsPanel;
class LogPanel;
class PanelsPanel;
class PowerPanel;
class QLabel;
class QLineEdit;
class QTextEdit;
class SettingsTree;
class VersionsPanel;
class WebSocketController : public QObject
{
Q_OBJECT
public:
explicit WebSocketController(QLineEdit *urlEdit, QLabel *statusLabel,
QObject *parent = nullptr);
QWebSocket *socket();
bool isConnected() const;
void addLogView(QTextEdit *log);
void setSettingsTree(SettingsTree *tree);
void setGamesPanel(GamesPanel *panel);
void setVersionsPanel(VersionsPanel *panel);
void setPowerPanel(PowerPanel *panel);
void setLogPanel(LogPanel *panel);
void setPanelsPanel(PanelsPanel *panel);
void setLightsPanel(LightsPanel *panel);
public slots:
void startConnection();
void closeConnection();
void sendCommand(const QString &cmd);
void onConnected();
void onDisconnected();
void onTextMessageReceived(const QString &message);
void onErrorOccurred(QAbstractSocket::SocketError error);
private slots:
void onValueEdited(const QString &key, const QString &newValue);
private:
void handleProtocol(const QString &msg);
void broadcast(const QString &line);
QWebSocket m_socket;
QLineEdit *m_urlEdit = nullptr;
QLabel *m_statusLabel = nullptr;
QList<QTextEdit*> m_logs;
SettingsTree *m_settingsTree = nullptr;
GamesPanel *m_gamesPanel = nullptr;
VersionsPanel *m_versionsPanel = nullptr;
PowerPanel *m_powerPanel = nullptr;
LogPanel *m_logPanel = nullptr;
PanelsPanel *m_panelsPanel = nullptr;
LightsPanel *m_lightsPanel = nullptr;
QStringList m_settingsKeys;
int m_rnpCount = -1;
};