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/networkmanager.cpp
src/authdialog.ui src/authdialog.ui
src/authdialog.cpp src/authdialog.cpp
src/settingsdialog.ui
src/settingsdialog.h src/settingsdialog.h
src/settingsdialog.cpp src/settingsdialog.cpp
src/models.h src/models.h
+9 -1
View File
@@ -438,7 +438,15 @@ void MainWindow::on_settingsButton_clicked()
{ {
if (!m_settingsDialog) 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(); m_settingsDialog->show();
} }
+78 -30
View File
@@ -1,47 +1,95 @@
#include "settingsdialog.h" #include "settingsdialog.h"
#include "authmanager.h" #include <QHBoxLayout>
#include "store.h" #include <QLabel>
#include "ui_settingsdialog.h" #include <QLineEdit>
#include <QListWidget>
#include <QPushButton>
#include <QStackedWidget>
#include <QVBoxLayout>
SettingsDialog::SettingsDialog(AuthManager *authManager, Store *store, QWidget *parent) SettingsDialog::SettingsDialog(QWidget *parent)
: QDialog(parent), m_authManager(authManager), m_store(store), ui(new Ui::SettingsDialog) : QDialog(parent)
{ {
ui->setupUi(this); buildUi();
this->setModal(true); setModal(true);
// Populate list widget with tab items m_listWidget->addItem("Account");
ui->listWidget->addItem("Account"); m_listWidget->addItem("Create Network");
ui->listWidget->addItem("Create Network");
// Wire list navigation to stacked widget connect(m_listWidget, &QListWidget::currentRowChanged,
connect(ui->listWidget, &QListWidget::currentRowChanged, m_stackedWidget, &QStackedWidget::setCurrentIndex);
ui->stackedWidget, &QStackedWidget::setCurrentIndex);
// Select first item by default m_listWidget->setCurrentRow(0);
ui->listWidget->setCurrentRow(0);
connect(ui->signOutButton, &QPushButton::clicked, this, &SettingsDialog::on_signOutButton_clicked); connect(m_signOutButton, &QPushButton::clicked, this, [this]() {
connect(ui->createNetworkButton, &QPushButton::clicked, this, &SettingsDialog::onCreateNetworkClicked); 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(); resize(785, 700);
close(); setWindowTitle("Settings");
}
void SettingsDialog::onCreateNetworkClicked() auto *mainLayout = new QHBoxLayout(this);
{
QString name = ui->networkNameEdit->text().trimmed();
if (name.isEmpty())
return;
m_store->createNetwork(name); m_listWidget = new QListWidget();
ui->networkNameEdit->clear(); 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> #include <QDialog>
class AuthManager; QT_BEGIN_NAMESPACE
class Store; class QLabel;
class QLineEdit;
namespace Ui class QListWidget;
{ class QPushButton;
class SettingsDialog; class QStackedWidget;
} QT_END_NAMESPACE
class SettingsDialog : public QDialog class SettingsDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SettingsDialog(AuthManager *, Store *, QWidget *parent = nullptr); explicit SettingsDialog(QWidget *parent = nullptr);
~SettingsDialog();
private slots: void setAuthLabel(const QString &text);
void on_signOutButton_clicked();
void onCreateNetworkClicked(); signals:
void signOutRequested();
void createNetworkRequested(const QString &name);
private: private:
Ui::SettingsDialog *ui; void buildUi();
AuthManager *m_authManager;
Store *m_store; QListWidget *m_listWidget;
QStackedWidget *m_stackedWidget;
QLabel *m_authLabel;
QPushButton *m_signOutButton;
QLineEdit *m_networkNameEdit;
QPushButton *m_createNetworkButton;
}; };
#endif // SETTINGSDIALOG_H #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>