diff --git a/src/profile_dialog.cpp b/src/profile_dialog.cpp index b07015f..509c9d7 100644 --- a/src/profile_dialog.cpp +++ b/src/profile_dialog.cpp @@ -6,9 +6,23 @@ #include #include #include +#include #include #include +namespace { +int standardPortForProtocol(const QString& protocol) +{ + if (protocol == QStringLiteral("RDP")) { + return 3389; + } + if (protocol == QStringLiteral("VNC")) { + return 5900; + } + return 22; // SSH default +} +} + ProfileDialog::ProfileDialog(QWidget* parent) : QDialog(parent), m_nameInput(new QLineEdit(this)), @@ -32,6 +46,13 @@ ProfileDialog::ProfileDialog(QWidget* parent) m_protocolInput->addItems({QStringLiteral("SSH"), QStringLiteral("RDP"), QStringLiteral("VNC")}); m_authModeInput->addItems({QStringLiteral("Password"), QStringLiteral("Private Key")}); + connect(m_protocolInput, + &QComboBox::currentTextChanged, + this, + [this](const QString& protocol) { + m_portInput->setValue(standardPortForProtocol(protocol)); + }); + form->addRow(QStringLiteral("Name"), m_nameInput); form->addRow(QStringLiteral("Host"), m_hostInput); form->addRow(QStringLiteral("Port"), m_portInput); @@ -60,7 +81,11 @@ void ProfileDialog::setProfile(const Profile& profile) m_usernameInput->setText(profile.username); const int protocolIndex = m_protocolInput->findText(profile.protocol); - m_protocolInput->setCurrentIndex(protocolIndex >= 0 ? protocolIndex : 0); + { + // Keep stored custom port when loading an existing profile. + const QSignalBlocker blocker(m_protocolInput); + m_protocolInput->setCurrentIndex(protocolIndex >= 0 ? protocolIndex : 0); + } const int authModeIndex = m_authModeInput->findText(profile.authMode); m_authModeInput->setCurrentIndex(authModeIndex >= 0 ? authModeIndex : 0);