refactor: settings dialog decoupled from bus logic

This commit is contained in:
talksik
2026-02-07 09:43:48 -08:00
parent af5cd32010
commit 814f4e471e
5 changed files with 108 additions and 154 deletions
-1
View File
@@ -27,7 +27,6 @@ qt_add_executable(llink
src/networkmanager.cpp
src/authdialog.ui
src/authdialog.cpp
src/settingsdialog.ui
src/settingsdialog.h
src/settingsdialog.cpp
src/models.h
+9 -1
View File
@@ -438,7 +438,15 @@ void MainWindow::on_settingsButton_clicked()
{
if (!m_settingsDialog)
{
m_settingsDialog = new SettingsDialog(m_authManager, m_store, this);
m_settingsDialog = new SettingsDialog(this);
connect(m_settingsDialog, &SettingsDialog::signOutRequested, m_authManager, &AuthManager::signOut);
connect(m_settingsDialog, &SettingsDialog::createNetworkRequested, this, [this](const QString &name) {
m_store->createNetwork(name);
});
}
if (m_authManager->sessionData())
{
m_settingsDialog->setAuthLabel("Hello, " + m_authManager->sessionData()->emailPrefix);
}
m_settingsDialog->show();
}
+78 -30
View File
@@ -1,47 +1,95 @@
#include "settingsdialog.h"
#include "authmanager.h"
#include "store.h"
#include "ui_settingsdialog.h"
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QPushButton>
#include <QStackedWidget>
#include <QVBoxLayout>
SettingsDialog::SettingsDialog(AuthManager *authManager, Store *store, QWidget *parent)
: QDialog(parent), m_authManager(authManager), m_store(store), ui(new Ui::SettingsDialog)
SettingsDialog::SettingsDialog(QWidget *parent)
: QDialog(parent)
{
ui->setupUi(this);
buildUi();
this->setModal(true);
setModal(true);
// Populate list widget with tab items
ui->listWidget->addItem("Account");
ui->listWidget->addItem("Create Network");
m_listWidget->addItem("Account");
m_listWidget->addItem("Create Network");
// Wire list navigation to stacked widget
connect(ui->listWidget, &QListWidget::currentRowChanged,
ui->stackedWidget, &QStackedWidget::setCurrentIndex);
connect(m_listWidget, &QListWidget::currentRowChanged,
m_stackedWidget, &QStackedWidget::setCurrentIndex);
// Select first item by default
ui->listWidget->setCurrentRow(0);
m_listWidget->setCurrentRow(0);
connect(ui->signOutButton, &QPushButton::clicked, this, &SettingsDialog::on_signOutButton_clicked);
connect(ui->createNetworkButton, &QPushButton::clicked, this, &SettingsDialog::onCreateNetworkClicked);
connect(m_signOutButton, &QPushButton::clicked, this, [this]() {
emit signOutRequested();
close();
});
connect(m_createNetworkButton, &QPushButton::clicked, this, [this]() {
QString name = m_networkNameEdit->text().trimmed();
if (name.isEmpty())
return;
emit createNetworkRequested(name);
m_networkNameEdit->clear();
});
}
SettingsDialog::~SettingsDialog()
void SettingsDialog::setAuthLabel(const QString &text)
{
delete ui;
m_authLabel->setText(text);
}
void SettingsDialog::on_signOutButton_clicked()
void SettingsDialog::buildUi()
{
m_authManager->signOut();
close();
}
resize(785, 700);
setWindowTitle("Settings");
void SettingsDialog::onCreateNetworkClicked()
{
QString name = ui->networkNameEdit->text().trimmed();
if (name.isEmpty())
return;
auto *mainLayout = new QHBoxLayout(this);
m_store->createNetwork(name);
ui->networkNameEdit->clear();
m_listWidget = new QListWidget();
m_listWidget->setMaximumWidth(220);
mainLayout->addWidget(m_listWidget);
m_stackedWidget = new QStackedWidget();
mainLayout->addWidget(m_stackedWidget);
// ── Account page ──
auto *accountPage = new QWidget();
auto *accountLayout = new QVBoxLayout(accountPage);
accountLayout->addStretch();
m_authLabel = new QLabel("Hello, ");
m_authLabel->setAlignment(Qt::AlignCenter);
accountLayout->addWidget(m_authLabel);
m_signOutButton = new QPushButton("Sign Out");
accountLayout->addWidget(m_signOutButton);
accountLayout->addStretch();
m_stackedWidget->addWidget(accountPage);
// ── Create Network page ──
auto *createNetworkPage = new QWidget();
auto *createNetworkLayout = new QVBoxLayout(createNetworkPage);
auto *createNetworkLabel = new QLabel("Create a new network");
QFont labelFont;
labelFont.setPointSize(16);
createNetworkLabel->setFont(labelFont);
createNetworkLayout->addWidget(createNetworkLabel);
m_networkNameEdit = new QLineEdit();
m_networkNameEdit->setPlaceholderText("Network name");
createNetworkLayout->addWidget(m_networkNameEdit);
m_createNetworkButton = new QPushButton("Create");
createNetworkLayout->addWidget(m_createNetworkButton);
createNetworkLayout->addStretch();
m_stackedWidget->addWidget(createNetworkPage);
}
+21 -15
View File
@@ -3,30 +3,36 @@
#include <QDialog>
class AuthManager;
class Store;
namespace Ui
{
class SettingsDialog;
}
QT_BEGIN_NAMESPACE
class QLabel;
class QLineEdit;
class QListWidget;
class QPushButton;
class QStackedWidget;
QT_END_NAMESPACE
class SettingsDialog : public QDialog
{
Q_OBJECT
public:
explicit SettingsDialog(AuthManager *, Store *, QWidget *parent = nullptr);
~SettingsDialog();
explicit SettingsDialog(QWidget *parent = nullptr);
private slots:
void on_signOutButton_clicked();
void onCreateNetworkClicked();
void setAuthLabel(const QString &text);
signals:
void signOutRequested();
void createNetworkRequested(const QString &name);
private:
Ui::SettingsDialog *ui;
AuthManager *m_authManager;
Store *m_store;
void buildUi();
QListWidget *m_listWidget;
QStackedWidget *m_stackedWidget;
QLabel *m_authLabel;
QPushButton *m_signOutButton;
QLineEdit *m_networkNameEdit;
QPushButton *m_createNetworkButton;
};
#endif // SETTINGSDIALOG_H
-107
View File
@@ -1,107 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SettingsDialog</class>
<widget class="QDialog" name="SettingsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>785</width>
<height>700</height>
</rect>
</property>
<property name="windowTitle">
<string>Settings</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListWidget" name="listWidget">
<property name="maximumSize">
<size>
<width>220</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="accountLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="authLabel">
<property name="text">
<string>Hello, </string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="signOutButton">
<property name="text">
<string>Sign Out</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="createNetworkLayout">
<item>
<widget class="QLabel" name="createNetworkLabel">
<property name="text">
<string>Create a new network</string>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="networkNameEdit">
<property name="placeholderText">
<string>Network name</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="createNetworkButton">
<property name="text">
<string>Create</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>