feat: implement ping and particle data size in statusbar
This commit is contained in:
+40
-26
@@ -7,6 +7,7 @@
|
||||
#include "authmanager.h"
|
||||
#include "createstreamdialog.h"
|
||||
#include "memberpickerdialog.h"
|
||||
#include "networkmanager.h"
|
||||
#include "settingsdialog.h"
|
||||
#include "textinputdialog.h"
|
||||
#include "ui_mainwindow.h"
|
||||
@@ -18,7 +19,7 @@
|
||||
#include <QMenu>
|
||||
#include <QKeyEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QRandomGenerator>
|
||||
#include <QJsonObject>
|
||||
#include <QToolButton>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QTimer>
|
||||
@@ -81,11 +82,21 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
m_storageLabel->setStyleSheet(statusBarLabelStyle);
|
||||
ui->statusbar->addPermanentWidget(m_storageLabel);
|
||||
|
||||
// Setup ping timer to oscillate every 500ms
|
||||
// Setup ping timer for periodic server connectivity check
|
||||
m_pingTimer = new QTimer(this);
|
||||
connect(m_pingTimer, &QTimer::timeout, this, &MainWindow::updatePingIndicator);
|
||||
m_pingTimer->start(500);
|
||||
updatePingIndicator();
|
||||
connect(m_pingTimer, &QTimer::timeout, this, []() {
|
||||
NetworkManager::instance().ping();
|
||||
});
|
||||
connect(&NetworkManager::instance(), &NetworkManager::pingResult, this, [this](int ms) {
|
||||
m_pingLabel->setText("connected " + QString::number(ms) + "ms");
|
||||
m_pingLabel->setStyleSheet("QLabel { color: #00AA00; }");
|
||||
});
|
||||
connect(&NetworkManager::instance(), &NetworkManager::pingFailed, this, [this]() {
|
||||
m_pingLabel->setText("disconnected");
|
||||
m_pingLabel->setStyleSheet("QLabel { color: #AA0000; }");
|
||||
});
|
||||
m_pingTimer->start(10000);
|
||||
NetworkManager::instance().ping();
|
||||
|
||||
ui->splitter->setStretchFactor(0, 1);
|
||||
ui->splitter->setStretchFactor(1, 4);
|
||||
@@ -417,10 +428,30 @@ void MainWindow::updateStatusBar()
|
||||
m_positionLabel->setText("");
|
||||
}
|
||||
|
||||
// Update storage indicator with pseudo-random size based on stream ID
|
||||
uint hash = qHash(m_selectedStreamId);
|
||||
int sizeKB = 50 + (hash % 950); // Random size between 50-1000 kB
|
||||
m_storageLabel->setText(QString::number(sizeKB) + " kB");
|
||||
// Update data size indicator for selected particle
|
||||
if (!m_selectedParticleId.isEmpty())
|
||||
{
|
||||
const Particle *particle = m_store->particleById(m_selectedParticleId);
|
||||
if (particle)
|
||||
{
|
||||
QJsonObject dataObj;
|
||||
for (auto it = particle->data.constBegin(); it != particle->data.constEnd(); ++it)
|
||||
dataObj.insert(it.key(), QJsonValue::fromVariant(it.value()));
|
||||
int bytes = QJsonDocument(dataObj).toJson(QJsonDocument::Compact).size();
|
||||
if (bytes < 1024)
|
||||
m_storageLabel->setText(QString::number(bytes) + " B");
|
||||
else
|
||||
m_storageLabel->setText(QString::number(bytes / 1024) + " kB");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_storageLabel->setText("");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_storageLabel->setText("");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -429,23 +460,6 @@ void MainWindow::updateStatusBar()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::updatePingIndicator()
|
||||
{
|
||||
// Oscillate ping between 15-35ms
|
||||
static int basePing = 23;
|
||||
int variation = (QRandomGenerator::global()->bounded(21)) - 10; // -10 to +10
|
||||
int currentPing = basePing + variation;
|
||||
if (currentPing < 15)
|
||||
{
|
||||
currentPing = 15;
|
||||
}
|
||||
if (currentPing > 35)
|
||||
{
|
||||
currentPing = 35;
|
||||
}
|
||||
|
||||
m_pingLabel->setText("connected " + QString::number(currentPing) + "ms");
|
||||
}
|
||||
|
||||
void MainWindow::showTextInputDialog()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user