refactor: use private slots instead of lambdas
This commit is contained in:
+120
-94
@@ -121,32 +121,9 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
connect(m_authManager, &AuthManager::signedIn, m_authDialog, &AuthDialog::reset);
|
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::reset);
|
||||||
connect(m_authManager, &AuthManager::signedOut, m_authDialog, &AuthDialog::show);
|
connect(m_authManager, &AuthManager::signedOut, m_authDialog, &AuthDialog::show);
|
||||||
connect(m_authManager, &AuthManager::signedIn, this, [this]() {
|
connect(m_authManager, &AuthManager::signedIn, this, &MainWindow::onSignedIn);
|
||||||
m_store->setCurrentUserEmail(m_authManager->sessionData()->email);
|
connect(m_store, &Store::startupDataLoaded, m_treeView, &QTreeView::expandAll);
|
||||||
m_store->loadStartupData();
|
connect(m_store, &Store::particleUpdated, this, &MainWindow::onParticleUpdated);
|
||||||
});
|
|
||||||
connect(m_store, &Store::startupDataLoaded, this, [this]() {
|
|
||||||
m_treeView->expandAll();
|
|
||||||
});
|
|
||||||
connect(m_store, &Store::particleUpdated, this, [this](const QString &, const QString &particleId) {
|
|
||||||
if (particleId == m_selectedParticleId)
|
|
||||||
{
|
|
||||||
const Particle *particle = m_store->particleById(particleId);
|
|
||||||
if (particle && !particle->ackedByEmails.empty())
|
|
||||||
{
|
|
||||||
QStringList acked;
|
|
||||||
for (const auto &email : particle->ackedByEmails)
|
|
||||||
{
|
|
||||||
acked.append(email);
|
|
||||||
}
|
|
||||||
m_ackLabel->setText("Acked by: " + acked.join(", "));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_ackLabel->setText("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// DocumentSend toolbar button opens text input dialog
|
// DocumentSend toolbar button opens text input dialog
|
||||||
connect(m_sendTextButton, &QToolButton::clicked, this, &MainWindow::showTextInputDialog);
|
connect(m_sendTextButton, &QToolButton::clicked, this, &MainWindow::showTextInputDialog);
|
||||||
@@ -157,56 +134,11 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
|
|
||||||
// "New stream" button
|
// "New stream" button
|
||||||
m_createStreamDialog = new CreateStreamDialog(this);
|
m_createStreamDialog = new CreateStreamDialog(this);
|
||||||
connect(m_newStreamButton, &QPushButton::clicked, this, [this]() {
|
connect(m_newStreamButton, &QPushButton::clicked, this, &MainWindow::onNewStreamClicked);
|
||||||
if (m_selectedNetworkId.isEmpty())
|
connect(m_createStreamDialog, &CreateStreamDialog::streamRequested, this, &MainWindow::onCreateStreamRequested);
|
||||||
return;
|
|
||||||
const Network *network = m_store->networkById(m_selectedNetworkId);
|
|
||||||
if (network)
|
|
||||||
m_createStreamDialog->setNetworkMembers(network->members);
|
|
||||||
m_createStreamDialog->show();
|
|
||||||
m_createStreamDialog->raise();
|
|
||||||
m_createStreamDialog->activateWindow();
|
|
||||||
});
|
|
||||||
connect(m_createStreamDialog, &CreateStreamDialog::streamRequested, this,
|
|
||||||
[this](const QString &name, const QString &visibility, const QStringList &members) {
|
|
||||||
m_store->createStream(m_selectedNetworkId, name, "", visibility, members);
|
|
||||||
});
|
|
||||||
|
|
||||||
// "Add members" toolbar button (ListAdd icon in right sidebar)
|
// "Add members" toolbar button (ListAdd icon in right sidebar)
|
||||||
connect(m_addMembersButton, &QToolButton::clicked, this, [this]() {
|
connect(m_addMembersButton, &QToolButton::clicked, this, &MainWindow::onAddMembersClicked);
|
||||||
if (m_selectedStreamId.isEmpty() || m_selectedNetworkId.isEmpty())
|
|
||||||
return;
|
|
||||||
const Network *network = m_store->networkById(m_selectedNetworkId);
|
|
||||||
const Stream *stream = m_store->streamById(m_selectedStreamId);
|
|
||||||
if (!network || !stream)
|
|
||||||
return;
|
|
||||||
|
|
||||||
MemberPickerDialog picker("Add Members", this);
|
|
||||||
picker.setMembers(network->members, stream->memberEmails);
|
|
||||||
|
|
||||||
if (picker.exec() == QDialog::Accepted)
|
|
||||||
{
|
|
||||||
QStringList emails = picker.selectedEmails();
|
|
||||||
if (!emails.isEmpty())
|
|
||||||
{
|
|
||||||
auto *op = m_store->addStreamMembers(m_selectedStreamId, emails);
|
|
||||||
connect(op, &Operation::success, this, [this](const QJsonDocument &) {
|
|
||||||
auto *fetchOp = m_store->fetchStream(m_selectedStreamId);
|
|
||||||
connect(fetchOp, &Operation::success, this, [this](const QJsonDocument &) {
|
|
||||||
m_membersList->clear();
|
|
||||||
const Stream *s = m_store->streamById(m_selectedStreamId);
|
|
||||||
if (s)
|
|
||||||
{
|
|
||||||
for (const QString &email : s->memberEmails)
|
|
||||||
{
|
|
||||||
m_membersList->addItem(email.split("@")[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
m_authManager->tryRestoreSession();
|
m_authManager->tryRestoreSession();
|
||||||
|
|
||||||
@@ -468,26 +400,8 @@ void MainWindow::setupModels()
|
|||||||
m_splitter->setStretchFactor(3, 4);
|
m_splitter->setStretchFactor(3, 4);
|
||||||
m_networkDetailWidget->hide();
|
m_networkDetailWidget->hide();
|
||||||
|
|
||||||
// Push fresh data when networks change
|
connect(m_store, &Store::networksChanged, this, &MainWindow::onNetworksChanged);
|
||||||
connect(m_store, &Store::networksChanged, this, [this]() {
|
connect(m_networkDetailWidget, &NetworkDetailWidget::addMemberRequested, this, &MainWindow::onAddNetworkMemberRequested);
|
||||||
if (!m_selectedNetworkId.isEmpty() && m_networkDetailWidget->isVisible())
|
|
||||||
{
|
|
||||||
const Network *network = m_store->networkById(m_selectedNetworkId);
|
|
||||||
if (network)
|
|
||||||
m_networkDetailWidget->setNetwork(*network, m_authManager->sessionData() ? m_authManager->sessionData()->email : QString());
|
|
||||||
else
|
|
||||||
m_networkDetailWidget->clear();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle add-member requests from the widget
|
|
||||||
connect(m_networkDetailWidget, &NetworkDetailWidget::addMemberRequested, this,
|
|
||||||
[this](const QString &networkId, const QString &email) {
|
|
||||||
auto *op = m_store->addNetworkMembers(networkId, {email});
|
|
||||||
connect(op, &Operation::success, this, [this, networkId](const QJsonDocument &) {
|
|
||||||
m_store->fetchNetwork(networkId);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create and set tree model
|
// Create and set tree model
|
||||||
m_networkStreamModel = new NetworkStreamModel(m_store, this);
|
m_networkStreamModel = new NetworkStreamModel(m_store, this);
|
||||||
@@ -523,6 +437,118 @@ void MainWindow::setupModels()
|
|||||||
m_particlesView->installEventFilter(this);
|
m_particlesView->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::onSignedIn()
|
||||||
|
{
|
||||||
|
m_store->setCurrentUserEmail(m_authManager->sessionData()->email);
|
||||||
|
m_store->loadStartupData();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onParticleUpdated(const QString &streamId, const QString &particleId)
|
||||||
|
{
|
||||||
|
Q_UNUSED(streamId);
|
||||||
|
|
||||||
|
if (particleId != m_selectedParticleId)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const Particle *particle = m_store->particleById(particleId);
|
||||||
|
if (particle && !particle->ackedByEmails.empty())
|
||||||
|
{
|
||||||
|
QStringList acked;
|
||||||
|
for (const auto &email : particle->ackedByEmails)
|
||||||
|
acked.append(email);
|
||||||
|
m_ackLabel->setText("Acked by: " + acked.join(", "));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_ackLabel->setText("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onNewStreamClicked()
|
||||||
|
{
|
||||||
|
if (m_selectedNetworkId.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const Network *network = m_store->networkById(m_selectedNetworkId);
|
||||||
|
if (network)
|
||||||
|
{
|
||||||
|
m_createStreamDialog->setNetworkMembers(network->members);
|
||||||
|
}
|
||||||
|
m_createStreamDialog->show();
|
||||||
|
m_createStreamDialog->raise();
|
||||||
|
m_createStreamDialog->activateWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onCreateStreamRequested(const QString &name, const QString &visibility, const QStringList &members)
|
||||||
|
{
|
||||||
|
m_store->createStream(m_selectedNetworkId, name, "", visibility, members);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onAddMembersClicked()
|
||||||
|
{
|
||||||
|
if (m_selectedStreamId.isEmpty() || m_selectedNetworkId.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const Network *network = m_store->networkById(m_selectedNetworkId);
|
||||||
|
const Stream *stream = m_store->streamById(m_selectedStreamId);
|
||||||
|
if (!network || !stream)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MemberPickerDialog picker("Add Members", this);
|
||||||
|
picker.setMembers(network->members, stream->memberEmails);
|
||||||
|
|
||||||
|
if (picker.exec() == QDialog::Accepted)
|
||||||
|
{
|
||||||
|
QStringList emails = picker.selectedEmails();
|
||||||
|
if (!emails.isEmpty())
|
||||||
|
{
|
||||||
|
auto *op = m_store->addStreamMembers(m_selectedStreamId, emails);
|
||||||
|
connect(op, &Operation::success, this, [this](const QJsonDocument &) {
|
||||||
|
auto *fetchOp = m_store->fetchStream(m_selectedStreamId);
|
||||||
|
connect(fetchOp, &Operation::success, this, [this](const QJsonDocument &) {
|
||||||
|
m_membersList->clear();
|
||||||
|
const Stream *s = m_store->streamById(m_selectedStreamId);
|
||||||
|
if (s)
|
||||||
|
{
|
||||||
|
for (const QString &email : s->memberEmails)
|
||||||
|
{
|
||||||
|
m_membersList->addItem(email.split("@")[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onNetworksChanged()
|
||||||
|
{
|
||||||
|
if (!m_selectedNetworkId.isEmpty() && m_networkDetailWidget->isVisible())
|
||||||
|
{
|
||||||
|
const Network *network = m_store->networkById(m_selectedNetworkId);
|
||||||
|
if (network)
|
||||||
|
{
|
||||||
|
m_networkDetailWidget->setNetwork(*network, m_authManager->sessionData() ? m_authManager->sessionData()->email : QString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_networkDetailWidget->clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onAddNetworkMemberRequested(const QString &networkId, const QString &email)
|
||||||
|
{
|
||||||
|
auto *op = m_store->addNetworkMembers(networkId, {email});
|
||||||
|
connect(op, &Operation::success, this, [this, networkId](const QJsonDocument &) {
|
||||||
|
m_store->fetchNetwork(networkId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::onTreeSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
void MainWindow::onTreeSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
||||||
{
|
{
|
||||||
Q_UNUSED(deselected);
|
Q_UNUSED(deselected);
|
||||||
|
|||||||
+8
-1
@@ -42,9 +42,16 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_exitButton_clicked();
|
void on_exitButton_clicked();
|
||||||
|
|
||||||
void on_settingsButton_clicked();
|
void on_settingsButton_clicked();
|
||||||
|
|
||||||
|
void onSignedIn();
|
||||||
|
void onParticleUpdated(const QString &streamId, const QString &particleId);
|
||||||
|
void onNewStreamClicked();
|
||||||
|
void onCreateStreamRequested(const QString &name, const QString &visibility, const QStringList &members);
|
||||||
|
void onAddMembersClicked();
|
||||||
|
void onNetworksChanged();
|
||||||
|
void onAddNetworkMemberRequested(const QString &networkId, const QString &email);
|
||||||
|
|
||||||
void onTreeSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
void onTreeSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||||
void onParticleSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
void onParticleSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||||
void onTextMessageSubmitted(const QString &text);
|
void onTextMessageSubmitted(const QString &text);
|
||||||
|
|||||||
Reference in New Issue
Block a user