feat: integrate ui with data api
Much of this was ai generated.
This commit is contained in:
+49
-31
@@ -19,7 +19,7 @@
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent), m_trayIcon(nullptr), m_authManager(new AuthManager(this)), m_settingsDialog(nullptr),
|
||||
m_authDialog(nullptr), m_data(nullptr), m_networkStreamModel(nullptr), m_particleListModel(nullptr),
|
||||
m_authDialog(nullptr), m_store(nullptr), m_networkStreamModel(nullptr), m_particleListModel(nullptr),
|
||||
m_selectedParticleRow(-1), m_isDragging(false)
|
||||
{
|
||||
m_authDialog = new AuthDialog(this);
|
||||
@@ -95,6 +95,12 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
connect(m_authManager, &AuthManager::signedIn, m_authDialog, &AuthDialog::reset);
|
||||
connect(m_authManager, &AuthManager::signedOut, m_authDialog, &AuthDialog::reset);
|
||||
connect(m_authManager, &AuthManager::signedOut, m_authDialog, &AuthDialog::show);
|
||||
connect(m_authManager, &AuthManager::signedIn, this, [this]() {
|
||||
m_store->loadStartupData();
|
||||
});
|
||||
connect(m_store, &Store::startupDataLoaded, this, [this]() {
|
||||
ui->topLevelParticlesView->expandAll();
|
||||
});
|
||||
|
||||
m_authManager->tryRestoreSession();
|
||||
|
||||
@@ -143,11 +149,11 @@ void MainWindow::on_settingsButton_clicked()
|
||||
|
||||
void MainWindow::setupModels()
|
||||
{
|
||||
// Create data with fake data
|
||||
m_data = new Data(this);
|
||||
// Create store (data loaded after sign-in via loadStartupData)
|
||||
m_store = new Store(this);
|
||||
|
||||
// Create and set tree model
|
||||
m_networkStreamModel = new NetworkStreamModel(m_data, this);
|
||||
m_networkStreamModel = new NetworkStreamModel(m_store, this);
|
||||
ui->topLevelParticlesView->setModel(m_networkStreamModel);
|
||||
ui->topLevelParticlesView->setIndentation(5);
|
||||
ui->topLevelParticlesView->setHeaderHidden(true);
|
||||
@@ -160,7 +166,7 @@ void MainWindow::setupModels()
|
||||
ui->topLevelParticlesView->setColumnWidth(1, 40);
|
||||
|
||||
// Create and set list model
|
||||
m_particleListModel = new ParticleListModel(m_data, this);
|
||||
m_particleListModel = new ParticleListModel(m_store, this);
|
||||
ui->particlesView->setModel(m_particleListModel);
|
||||
|
||||
// Configure particle list view to use ellipses for long text
|
||||
@@ -175,8 +181,6 @@ void MainWindow::setupModels()
|
||||
connect(ui->particlesView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
||||
&MainWindow::onParticleSelectionChanged);
|
||||
|
||||
// setup human presence list
|
||||
ui->presenceList->addItems(QStringList{"agnes", "katie", "stephen", "viet", "anthony"});
|
||||
}
|
||||
|
||||
void MainWindow::onTreeSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
||||
@@ -186,6 +190,7 @@ void MainWindow::onTreeSelectionChanged(const QItemSelection &selected, const QI
|
||||
if (selected.indexes().isEmpty())
|
||||
{
|
||||
m_particleListModel->setStreamId(QString());
|
||||
ui->membersList->clear();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -202,6 +207,17 @@ void MainWindow::onTreeSelectionChanged(const QItemSelection &selected, const QI
|
||||
QString networkId = m_networkStreamModel->networkIdFromIndex(parentIndex);
|
||||
m_selectedNetworkName = networkId;
|
||||
|
||||
// Show stream members
|
||||
ui->membersList->clear();
|
||||
const Stream *stream = m_store->streamById(streamId);
|
||||
if (stream)
|
||||
{
|
||||
for (const QString &email : stream->memberEmails)
|
||||
{
|
||||
ui->membersList->addItem(email.split("@")[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-select first unseen particle (or first particle if all seen)
|
||||
int unseenRow = m_particleListModel->firstUnseenRow();
|
||||
if (unseenRow >= 0)
|
||||
@@ -220,6 +236,7 @@ void MainWindow::onTreeSelectionChanged(const QItemSelection &selected, const QI
|
||||
m_particleListModel->setStreamId(QString());
|
||||
m_selectedStreamId.clear();
|
||||
m_selectedParticleRow = -1;
|
||||
ui->membersList->clear();
|
||||
|
||||
QString networkId = m_networkStreamModel->networkIdFromIndex(index);
|
||||
m_selectedNetworkName = networkId;
|
||||
@@ -247,9 +264,17 @@ void MainWindow::onParticleSelectionChanged(const QItemSelection &selected, cons
|
||||
const Particle *particle = m_particleListModel->particleAtRow(index.row());
|
||||
if (particle)
|
||||
{
|
||||
// ui->label->setText(particle->summary);
|
||||
ui->label_2->setText(particle->createdBy);
|
||||
ui->label_2->setText(particle->createdByEmail);
|
||||
m_selectedParticleId = particle->id;
|
||||
|
||||
if (particle->type == "text")
|
||||
{
|
||||
ui->label->setText(particle->data.value("content").toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->label->setText("");
|
||||
}
|
||||
}
|
||||
|
||||
updateStatusBar();
|
||||
@@ -262,41 +287,30 @@ void MainWindow::updateStatusBar()
|
||||
// Add network if selected
|
||||
if (!m_selectedNetworkName.isEmpty())
|
||||
{
|
||||
for (const auto &network : m_data->networks())
|
||||
const Network *network = m_store->networkById(m_selectedNetworkName);
|
||||
if (network)
|
||||
{
|
||||
if (network.id == m_selectedNetworkName)
|
||||
{
|
||||
pathComponents << network.name;
|
||||
break;
|
||||
}
|
||||
pathComponents << network->name;
|
||||
}
|
||||
}
|
||||
|
||||
// Add stream if selected
|
||||
if (!m_selectedStreamId.isEmpty() && !m_selectedNetworkName.isEmpty())
|
||||
if (!m_selectedStreamId.isEmpty())
|
||||
{
|
||||
const QList<Stream> &streams = m_data->streamsForNetwork(m_selectedNetworkName);
|
||||
for (const auto &stream : streams)
|
||||
const Stream *stream = m_store->streamById(m_selectedStreamId);
|
||||
if (stream)
|
||||
{
|
||||
if (stream.id == m_selectedStreamId)
|
||||
{
|
||||
pathComponents << stream.name;
|
||||
break;
|
||||
}
|
||||
pathComponents << stream->name;
|
||||
}
|
||||
}
|
||||
|
||||
// Add particle if selected
|
||||
if (!m_selectedParticleId.isEmpty() && !m_selectedStreamId.isEmpty())
|
||||
if (!m_selectedParticleId.isEmpty())
|
||||
{
|
||||
const QList<Particle> &particles = m_data->particlesForStream(m_selectedStreamId);
|
||||
for (const auto &particle : particles)
|
||||
const Particle *particle = m_store->particleById(m_selectedParticleId);
|
||||
if (particle)
|
||||
{
|
||||
if (particle.id == m_selectedParticleId)
|
||||
{
|
||||
pathComponents << particle.id;
|
||||
break;
|
||||
}
|
||||
pathComponents << particle->id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,9 +365,13 @@ void MainWindow::updatePingIndicator()
|
||||
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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user