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