Auto-fill standard port when protocol changes
This commit is contained in:
@@ -6,9 +6,23 @@
|
|||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QSignalBlocker>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
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)
|
ProfileDialog::ProfileDialog(QWidget* parent)
|
||||||
: QDialog(parent),
|
: QDialog(parent),
|
||||||
m_nameInput(new QLineEdit(this)),
|
m_nameInput(new QLineEdit(this)),
|
||||||
@@ -32,6 +46,13 @@ ProfileDialog::ProfileDialog(QWidget* parent)
|
|||||||
m_protocolInput->addItems({QStringLiteral("SSH"), QStringLiteral("RDP"), QStringLiteral("VNC")});
|
m_protocolInput->addItems({QStringLiteral("SSH"), QStringLiteral("RDP"), QStringLiteral("VNC")});
|
||||||
m_authModeInput->addItems({QStringLiteral("Password"), QStringLiteral("Private Key")});
|
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("Name"), m_nameInput);
|
||||||
form->addRow(QStringLiteral("Host"), m_hostInput);
|
form->addRow(QStringLiteral("Host"), m_hostInput);
|
||||||
form->addRow(QStringLiteral("Port"), m_portInput);
|
form->addRow(QStringLiteral("Port"), m_portInput);
|
||||||
@@ -60,7 +81,11 @@ void ProfileDialog::setProfile(const Profile& profile)
|
|||||||
m_usernameInput->setText(profile.username);
|
m_usernameInput->setText(profile.username);
|
||||||
|
|
||||||
const int protocolIndex = m_protocolInput->findText(profile.protocol);
|
const int protocolIndex = m_protocolInput->findText(profile.protocol);
|
||||||
|
{
|
||||||
|
// Keep stored custom port when loading an existing profile.
|
||||||
|
const QSignalBlocker blocker(m_protocolInput);
|
||||||
m_protocolInput->setCurrentIndex(protocolIndex >= 0 ? protocolIndex : 0);
|
m_protocolInput->setCurrentIndex(protocolIndex >= 0 ? protocolIndex : 0);
|
||||||
|
}
|
||||||
|
|
||||||
const int authModeIndex = m_authModeInput->findText(profile.authMode);
|
const int authModeIndex = m_authModeInput->findText(profile.authMode);
|
||||||
m_authModeInput->setCurrentIndex(authModeIndex >= 0 ? authModeIndex : 0);
|
m_authModeInput->setCurrentIndex(authModeIndex >= 0 ? authModeIndex : 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user