ORE Studio 0.0.4
Loading...
Searching...
No Matches
LoginDialog.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_QT_LOGIN_DIALOG_HPP
21#define ORES_QT_LOGIN_DIALOG_HPP
22
23#include <QWidget>
24#include <QKeyEvent>
25#include <QLineEdit>
26#include <QPushButton>
27#include <QLabel>
28#include <QCheckBox>
29#include <QComboBox>
30#include <QSpinBox>
31#include <QList>
32#include <QVBoxLayout>
33#include "ores.qt/ClientManager.hpp"
34#include "ores.logging/make_logger.hpp"
35
36namespace ores::qt {
37
45class LoginDialog : public QWidget {
46 Q_OBJECT
47
48private:
49 inline static std::string_view logger_name = "ores.qt.login_dialog";
50
51 [[nodiscard]] static auto& lg() {
52 using namespace ores::logging;
53 static auto instance = make_logger(logger_name);
54 return instance;
55 }
56
57public:
64 enum class Type { Environment, Connection };
65 Type type;
66 QString name;
67 QString subtitle; // "host:port" for environments, username for connections
68 };
69
70public:
71 explicit LoginDialog(QWidget* parent = nullptr);
72 ~LoginDialog() override;
73
74 QSize sizeHint() const override;
75
83 void setQuickConnectItems(const QList<QuickConnectItem>& items);
84
88 void setServer(const QString& server);
89
93 void setPort(int port);
94
98 void setUsername(const QString& username);
99
103 void setPassword(const QString& password);
104
108 void setSubjectPrefix(const QString& prefix);
109
113 void setClientManager(ClientManager* clientManager);
114
118 QString getUsername() const;
119
123 QString getPassword() const;
124
128 QString getServer() const;
129
133 int getPort() const;
134
138 QString getSubjectPrefix() const;
139
140protected:
141 void keyPressEvent(QKeyEvent* event) override;
142
143signals:
147 void loginSucceeded(const QString& username);
148
154 void httpBaseUrlDiscovered(const QString& baseUrl);
155
159 void loginFailed(const QString& errorMessage);
160
161 void signUpRequested();
162 void closeRequested();
163
168 void environmentSelected(const QString& environmentName);
169
174 void connectionSelected(const QString& connectionName);
175
180
185
186private slots:
187 void onLoginClicked();
188 void onSignUpClicked();
189 void onGetStartedClicked();
190 void onShowPasswordToggled(bool checked);
191 void onLoginResult(const LoginResult& result);
192 void onQuickConnectChanged(int idx);
193
194private:
195 void setupUI();
196 void setupLeftPanel(QWidget* parent);
197 void setupRightPanel(QWidget* parent);
198 void setupHeader(QVBoxLayout* layout, QWidget* parent);
199 void setupAuthFields(QVBoxLayout* layout, QWidget* parent);
200 void setupServerFields(QVBoxLayout* layout, QWidget* parent);
201 void setupActions(QVBoxLayout* layout, QWidget* parent);
202 void setupFooter(QVBoxLayout* layout, QWidget* parent);
203 void enableForm(bool enabled);
204 void lockServerFields(bool locked);
205 void lockCredentialFields(bool locked);
206
207 // UI elements
208 QLabel* loginTitleLabel_;
209 QLineEdit* usernameEdit_;
210 QLineEdit* passwordEdit_;
211 QCheckBox* showPasswordCheck_;
212 QCheckBox* rememberMeCheck_;
213 QPushButton* loginButton_;
214 QPushButton* signUpButton_;
215 QLabel* signUpLabel_;
216 QLabel* statusLabel_;
217
218 // Server fields
219 QLineEdit* hostEdit_;
220 QSpinBox* portSpinBox_;
221 QLineEdit* subjectPrefixEdit_;
222
223 // Quick-connect combo (environments + connections, hidden when empty)
224 QLabel* quickConnectLabel_{nullptr};
225 QComboBox* quickConnectCombo_{nullptr};
226
227 // Lock state (set when a saved item is selected)
228 bool serverFieldsLocked_{false};
229 bool credentialFieldsLocked_{false};
230
231 // Dependencies
232 ClientManager* clientManager_{nullptr};
233};
234
235}
236
237#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
Result of a login attempt.
Definition ClientManager.hpp:70
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Login dialog with dark theme.
Definition LoginDialog.hpp:45
void loginSucceeded(const QString &username)
Emitted when login succeeds.
void loginFailed(const QString &errorMessage)
Emitted when login fails.
void httpBaseUrlDiscovered(const QString &baseUrl)
Emitted when the HTTP base URL is discovered via NATS service discovery during login....
void connectionSelected(const QString &connectionName)
Emitted when a full connection is selected from the quick-connect combo. MainWindow handles this by f...
QString getServer() const
Get the current server/host field value.
Definition LoginDialog.cpp:184
void environmentSelected(const QString &environmentName)
Emitted when an environment is selected from the quick-connect combo. MainWindow handles this by fill...
QString getSubjectPrefix() const
Get the current subject prefix field value.
Definition LoginDialog.cpp:192
void setClientManager(ClientManager *clientManager)
Set the client manager for performing login.
Definition LoginDialog.cpp:172
QString getPassword() const
Get the password that was entered for login.
Definition LoginDialog.cpp:180
void setSubjectPrefix(const QString &prefix)
Set the NATS subject prefix field value.
Definition LoginDialog.cpp:168
int getPort() const
Get the current port field value.
Definition LoginDialog.cpp:188
void setQuickConnectItems(const QList< QuickConnectItem > &items)
Populate the quick-connect combo with environments and connections.
Definition LoginDialog.cpp:82
void bootstrapModeDetected()
Emitted when the server is in bootstrap mode.
void setUsername(const QString &username)
Set the username field value.
Definition LoginDialog.cpp:160
void setPassword(const QString &password)
Set the password field value.
Definition LoginDialog.cpp:164
QString getUsername() const
Get the username that was used for login.
Definition LoginDialog.cpp:176
void setPort(int port)
Set the port field value.
Definition LoginDialog.cpp:156
void tenantBootstrapDetected()
Emitted when the tenant is in bootstrap mode.
void setServer(const QString &server)
Set the server/host field value.
Definition LoginDialog.cpp:152
An item for the unified quick-connect combo.
Definition LoginDialog.hpp:63