Added lazy loading
This commit is contained in:
@@ -15,7 +15,6 @@ WebSocketController::WebSocketController(QLineEdit *urlEdit,
|
||||
{}
|
||||
|
||||
QWebSocket *WebSocketController::socket() { return &m_socket; }
|
||||
|
||||
void WebSocketController::addLogView(QTextEdit *log) { m_logs.append(log); }
|
||||
|
||||
void WebSocketController::setSettingsTree(SettingsTree *tree)
|
||||
@@ -25,7 +24,7 @@ void WebSocketController::setSettingsTree(SettingsTree *tree)
|
||||
this, &WebSocketController::onValueEdited);
|
||||
}
|
||||
|
||||
void WebSocketController::setGamesPanel(GamesPanel *panel) { m_gamesPanel = panel; }
|
||||
void WebSocketController::setGamesPanel(GamesPanel *panel) { m_gamesPanel = panel; }
|
||||
void WebSocketController::setVersionsPanel(VersionsPanel *panel) { m_versionsPanel = panel; }
|
||||
|
||||
bool WebSocketController::isConnected() const
|
||||
@@ -33,6 +32,43 @@ bool WebSocketController::isConnected() const
|
||||
return m_socket.state() == QAbstractSocket::ConnectedState;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Lazy loaders — called ONLY when user clicks a tab for first time
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
void WebSocketController::requestGamesData()
|
||||
{
|
||||
if (!isConnected() || m_gamesRequested) return;
|
||||
m_gamesRequested = true;
|
||||
broadcast("-- Loading games tab --");
|
||||
sendCommand(QStringLiteral("GAM list"));
|
||||
}
|
||||
|
||||
void WebSocketController::requestVersionsData()
|
||||
{
|
||||
if (!isConnected() || m_versionsRequested) return;
|
||||
m_versionsRequested = true;
|
||||
broadcast("-- Loading versions tab --");
|
||||
sendCommand(QStringLiteral("NAM"));
|
||||
sendCommand(QStringLiteral("VER"));
|
||||
sendCommand(QStringLiteral("UID"));
|
||||
sendCommand(QStringLiteral("RNP"));
|
||||
// Slave VER/UID loop fires in handleProtocol when RNP reply arrives
|
||||
}
|
||||
|
||||
void WebSocketController::requestSettingsData()
|
||||
{
|
||||
if (!isConnected() || m_settingsRequested) return;
|
||||
m_settingsRequested = true;
|
||||
broadcast("-- Loading settings tab --");
|
||||
sendCommand(QStringLiteral("GBL List"));
|
||||
// Individual GBL <key> loop fires in handleProtocol when List reply arrives
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Connection
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
void WebSocketController::startConnection()
|
||||
{
|
||||
const QUrl url(m_urlEdit->text().trimmed());
|
||||
@@ -46,7 +82,10 @@ void WebSocketController::closeConnection()
|
||||
{
|
||||
broadcast("Closing connection");
|
||||
m_settingsKeys.clear();
|
||||
m_rnpCount = -1;
|
||||
m_rnpCount = -1;
|
||||
m_gamesRequested = false;
|
||||
m_versionsRequested = false;
|
||||
m_settingsRequested = false;
|
||||
if (m_versionsPanel) m_versionsPanel->reset();
|
||||
m_socket.close();
|
||||
}
|
||||
@@ -60,16 +99,13 @@ void WebSocketController::sendCommand(const QString &cmd)
|
||||
|
||||
void WebSocketController::onConnected()
|
||||
{
|
||||
// Send NOTHING here — all data is lazy-loaded on tab click
|
||||
broadcast("Connected");
|
||||
m_statusLabel->setText("Connected");
|
||||
m_rnpCount = -1;
|
||||
|
||||
sendCommand(QStringLiteral("GBL List"));
|
||||
sendCommand(QStringLiteral("GAM list"));
|
||||
sendCommand(QStringLiteral("NAM"));
|
||||
sendCommand(QStringLiteral("VER"));
|
||||
sendCommand(QStringLiteral("UID"));
|
||||
sendCommand(QStringLiteral("RNP"));
|
||||
m_rnpCount = -1;
|
||||
m_gamesRequested = false;
|
||||
m_versionsRequested = false;
|
||||
m_settingsRequested = false;
|
||||
}
|
||||
|
||||
void WebSocketController::onDisconnected()
|
||||
@@ -77,7 +113,10 @@ void WebSocketController::onDisconnected()
|
||||
broadcast("Disconnected");
|
||||
m_statusLabel->setText("Disconnected");
|
||||
m_settingsKeys.clear();
|
||||
m_rnpCount = -1;
|
||||
m_rnpCount = -1;
|
||||
m_gamesRequested = false;
|
||||
m_versionsRequested = false;
|
||||
m_settingsRequested = false;
|
||||
}
|
||||
|
||||
void WebSocketController::onTextMessageReceived(const QString &msg)
|
||||
@@ -98,6 +137,10 @@ void WebSocketController::onValueEdited(const QString &key, const QString &newVa
|
||||
sendCommand(QString("GBL %1").arg(key));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Protocol handler
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
void WebSocketController::handleProtocol(const QString &msg)
|
||||
{
|
||||
const QStringList tokens = msg.split(' ', Qt::SkipEmptyParts);
|
||||
@@ -124,7 +167,7 @@ void WebSocketController::handleProtocol(const QString &msg)
|
||||
return;
|
||||
}
|
||||
|
||||
// RNP <count>
|
||||
// RNP <count> — triggers the slave loop
|
||||
if (cmd == "RNP" && tokens.size() >= 2) {
|
||||
bool ok = false;
|
||||
const int count = tokens[1].toInt(&ok);
|
||||
|
||||
Reference in New Issue
Block a user