diff --git a/CMakeLists.txt b/CMakeLists.txt index bcc2f9e..c0056bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index b38dd6c..38e862d 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -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(); } diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 8e694d7..99a28be 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -1,47 +1,95 @@ #include "settingsdialog.h" -#include "authmanager.h" -#include "store.h" -#include "ui_settingsdialog.h" +#include +#include +#include +#include +#include +#include +#include -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); } diff --git a/src/settingsdialog.h b/src/settingsdialog.h index ba678ad..cd06bda 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -3,30 +3,36 @@ #include -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 diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui deleted file mode 100644 index 5894b0a..0000000 --- a/src/settingsdialog.ui +++ /dev/null @@ -1,107 +0,0 @@ - - - SettingsDialog - - - - 0 - 0 - 785 - 700 - - - - Settings - - - - - - - 220 - 16777215 - - - - - - - - - - - - Qt::Orientation::Vertical - - - - - - - Hello, - - - Qt::AlignmentFlag::AlignCenter - - - - - - - Sign Out - - - - - - - Qt::Orientation::Vertical - - - - - - - - - - - Create a new network - - - - 16 - - - - - - - - Network name - - - - - - - Create - - - - - - - Qt::Orientation::Vertical - - - - - - - - - - - -