Implement Milestone 2 profile schema, dialog, and connect lifecycle
This commit is contained in:
@@ -3,43 +3,93 @@
|
||||
#include <QFont>
|
||||
#include <QLabel>
|
||||
#include <QTabWidget>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
SessionWindow::SessionWindow(const QString& profileName, QWidget* parent)
|
||||
SessionWindow::SessionWindow(const Profile& profile, QWidget* parent)
|
||||
: QMainWindow(parent), m_tabs(new QTabWidget(this))
|
||||
{
|
||||
setWindowTitle(QStringLiteral("OrbitHub Session - %1").arg(profileName));
|
||||
resize(900, 600);
|
||||
setWindowTitle(QStringLiteral("OrbitHub Session - %1").arg(profile.name));
|
||||
resize(980, 680);
|
||||
|
||||
m_tabs->setTabsClosable(true);
|
||||
connect(m_tabs,
|
||||
&QTabWidget::tabCloseRequested,
|
||||
this,
|
||||
[this](int index) {
|
||||
QWidget* tab = m_tabs->widget(index);
|
||||
m_tabs->removeTab(index);
|
||||
delete tab;
|
||||
if (m_tabs->count() == 0) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
setCentralWidget(m_tabs);
|
||||
addPlaceholderTab(profileName);
|
||||
addSessionTab(profile);
|
||||
}
|
||||
|
||||
void SessionWindow::addPlaceholderTab(const QString& profileName)
|
||||
void SessionWindow::addSessionTab(const Profile& profile)
|
||||
{
|
||||
auto* container = new QWidget(this);
|
||||
auto* layout = new QVBoxLayout(container);
|
||||
|
||||
auto* titleLabel = new QLabel(QStringLiteral("Profile: %1").arg(profileName), container);
|
||||
auto* profileLabel = new QLabel(QStringLiteral("Profile: %1").arg(profile.name), container);
|
||||
auto* endpointLabel = new QLabel(
|
||||
QStringLiteral("Endpoint: %1://%2@%3:%4")
|
||||
.arg(profile.protocol,
|
||||
profile.username.isEmpty() ? QStringLiteral("<none>") : profile.username,
|
||||
profile.host,
|
||||
QString::number(profile.port)),
|
||||
container);
|
||||
auto* authModeLabel = new QLabel(QStringLiteral("Auth Mode: %1").arg(profile.authMode), container);
|
||||
auto* statusLabel = new QLabel(QStringLiteral("Connection State: Connecting"), container);
|
||||
auto* surfaceLabel = new QLabel(QStringLiteral("OrbitHub Native Surface"), container);
|
||||
|
||||
QFont titleFont = titleLabel->font();
|
||||
titleFont.setBold(true);
|
||||
titleLabel->setFont(titleFont);
|
||||
QFont profileFont = profileLabel->font();
|
||||
profileFont.setBold(true);
|
||||
profileLabel->setFont(profileFont);
|
||||
|
||||
QFont surfaceFont = surfaceLabel->font();
|
||||
surfaceFont.setPointSize(surfaceFont.pointSize() + 6);
|
||||
surfaceFont.setBold(true);
|
||||
surfaceLabel->setFont(surfaceFont);
|
||||
|
||||
statusLabel->setStyleSheet(
|
||||
QStringLiteral("border: 1px solid #a5a5a5; background-color: #fff3cd; padding: 6px;"));
|
||||
|
||||
surfaceLabel->setAlignment(Qt::AlignCenter);
|
||||
surfaceLabel->setMinimumHeight(200);
|
||||
surfaceLabel->setMinimumHeight(220);
|
||||
surfaceLabel->setStyleSheet(
|
||||
QStringLiteral("border: 1px solid #8a8a8a; background-color: #f5f5f5;"));
|
||||
|
||||
layout->addWidget(titleLabel);
|
||||
layout->addWidget(profileLabel);
|
||||
layout->addWidget(endpointLabel);
|
||||
layout->addWidget(authModeLabel);
|
||||
layout->addWidget(statusLabel);
|
||||
layout->addWidget(surfaceLabel, 1);
|
||||
|
||||
m_tabs->addTab(container, profileName);
|
||||
const int tabIndex = m_tabs->addTab(container, QStringLiteral("%1 (Connecting)").arg(profile.name));
|
||||
|
||||
QTimer::singleShot(900,
|
||||
this,
|
||||
[this, tabIndex, statusLabel, profile]() {
|
||||
const bool shouldFail = profile.host.contains(QStringLiteral("fail"),
|
||||
Qt::CaseInsensitive);
|
||||
if (shouldFail) {
|
||||
statusLabel->setText(QStringLiteral("Connection State: Failed"));
|
||||
statusLabel->setStyleSheet(QStringLiteral(
|
||||
"border: 1px solid #a94442; background-color: #f2dede; padding: 6px;"));
|
||||
m_tabs->setTabText(tabIndex,
|
||||
QStringLiteral("%1 (Failed)").arg(profile.name));
|
||||
return;
|
||||
}
|
||||
|
||||
statusLabel->setText(QStringLiteral("Connection State: Connected"));
|
||||
statusLabel->setStyleSheet(QStringLiteral(
|
||||
"border: 1px solid #3c763d; background-color: #dff0d8; padding: 6px;"));
|
||||
m_tabs->setTabText(tabIndex,
|
||||
QStringLiteral("%1 (Connected)").arg(profile.name));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user