#include "session_window.h" #include #include #include #include #include #include SessionWindow::SessionWindow(const Profile& profile, QWidget* parent) : QMainWindow(parent), m_tabs(new QTabWidget(this)) { 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); addSessionTab(profile); } void SessionWindow::addSessionTab(const Profile& profile) { auto* container = new QWidget(this); auto* layout = new QVBoxLayout(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("") : 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 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(220); surfaceLabel->setStyleSheet( QStringLiteral("border: 1px solid #8a8a8a; background-color: #f5f5f5;")); layout->addWidget(profileLabel); layout->addWidget(endpointLabel); layout->addWidget(authModeLabel); layout->addWidget(statusLabel); layout->addWidget(surfaceLabel, 1); 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)); }); }