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 <QToolButton>
28#include <QLabel>
29#include <QCheckBox>
30#include <QComboBox>
31#include <QSpinBox>
32#include <QMenu>
33#include <QVBoxLayout>
34#include "ores.qt/ClientManager.hpp"
35#include "ores.logging/make_logger.hpp"
36
37namespace ores::qt {
38
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:
58 explicit LoginDialog(QWidget* parent = nullptr);
59 ~LoginDialog() override;
60
61 QSize sizeHint() const override;
62
66 void setSavedConnections(const QStringList& connectionNames);
67
71 void setServer(const QString& server);
72
76 void setPort(int port);
77
81 void setUsername(const QString& username);
82
86 void setPassword(const QString& password);
87
91 void setClientManager(ClientManager* clientManager);
92
96 QString getUsername() const;
97
101 QString getServer() const;
102
106 int getPort() const;
107
108protected:
109 void keyPressEvent(QKeyEvent* event) override;
110
111signals:
115 void loginSucceeded(const QString& username);
116
120 void loginFailed(const QString& errorMessage);
121
122 void signUpRequested();
123 void closeRequested();
124
128 void savedConnectionSelected(const QString& connectionName);
129
138 void bootstrapModeDetected(const std::vector<BootstrapBundleInfo>& bundles);
139
140private slots:
141 void onLoginClicked();
142 void onSignUpClicked();
143 void onGetStartedClicked();
144 void onShowPasswordToggled(bool checked);
145 void onLoginResult(const LoginResult& result);
146
147private:
148 void setupUI();
149 void setupLeftPanel(QWidget* parent);
150 void setupRightPanel(QWidget* parent);
151 void setupHeader(QVBoxLayout* layout, QWidget* parent);
152 void setupAuthFields(QVBoxLayout* layout, QWidget* parent);
153 void setupServerFields(QVBoxLayout* layout, QWidget* parent);
154 void setupActions(QVBoxLayout* layout, QWidget* parent);
155 void setupFooter(QVBoxLayout* layout, QWidget* parent);
156 void enableForm(bool enabled);
157
158 // UI elements
159 QLabel* loginTitleLabel_;
160 QLineEdit* usernameEdit_;
161 QLineEdit* passwordEdit_;
162 QCheckBox* showPasswordCheck_;
163 QCheckBox* rememberMeCheck_;
164 QPushButton* loginButton_;
165 QPushButton* signUpButton_;
166 QLabel* signUpLabel_;
167 QLabel* statusLabel_;
168
169 // Server fields
170 QLineEdit* hostEdit_;
171 QSpinBox* portSpinBox_;
172
173 // Saved connections
174 QToolButton* savedConnectionsButton_;
175 QMenu* savedConnectionsMenu_;
176
177 // Dependencies
178 ClientManager* clientManager_{nullptr};
179};
180
181}
182
183#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
Result of a login attempt.
Definition ClientManager.hpp:58
Manages the lifecycle of the network client and IO context.
Definition ClientManager.hpp:90
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 bootstrapModeDetected(const std::vector< BootstrapBundleInfo > &bundles)
Emitted when the server is in bootstrap mode.
QString getServer() const
Get the current server/host field value.
Definition LoginDialog.cpp:114
void setClientManager(ClientManager *clientManager)
Set the client manager for performing login.
Definition LoginDialog.cpp:106
int getPort() const
Get the current port field value.
Definition LoginDialog.cpp:118
void setSavedConnections(const QStringList &connectionNames)
Set the list of saved connection names for the dropdown.
Definition LoginDialog.cpp:72
void setUsername(const QString &username)
Set the username field value.
Definition LoginDialog.cpp:98
void setPassword(const QString &password)
Set the password field value.
Definition LoginDialog.cpp:102
void savedConnectionSelected(const QString &connectionName)
Emitted when user selects a saved connection from the dropdown.
QString getUsername() const
Get the username that was used for login.
Definition LoginDialog.cpp:110
void setPort(int port)
Set the port field value.
Definition LoginDialog.cpp:94
void setServer(const QString &server)
Set the server/host field value.
Definition LoginDialog.cpp:90