SshTunnelTab::SshTunnelTab(ConnectionSettings *settings) : _settings(settings) { SshSettings *info = settings->sshSettings(); _sshSupport = new QCheckBox("Use SSH tunnel"); _sshSupport->setStyleSheet("margin-bottom: 7px"); _sshSupport->setChecked(info->enabled()); _askForPassword = new QCheckBox(askPasswordText); _askForPassword->setChecked(info->askPassword()); VERIFY(connect(_askForPassword, SIGNAL(stateChanged(int)), this, SLOT(askForPasswordStateChanged(int)))); _sshHostName = new QLineEdit(QtUtils::toQString(info->host())); _userName = new QLineEdit(QtUtils::toQString(info->userName())); _sshPort = new QLineEdit(QString::number(info->port())); _sshPort->setFixedWidth(40); QRegExp rx("\\d+"); //(0-65554) _sshPort->setValidator(new QRegExpValidator(rx, this)); _security = new QComboBox(); _security->addItems(QStringList() << "Password" << "Private Key"); VERIFY(connect(_security, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(securityChange(const QString&)))); _passwordBox = new QLineEdit(QtUtils::toQString(info->userPassword())); _passwordBox->setEchoMode(QLineEdit::Password); _passwordEchoModeButton = new QPushButton; VERIFY(connect(_passwordEchoModeButton, SIGNAL(clicked()), this, SLOT(togglePasswordEchoMode()))); togglePasswordEchoMode(); _privateKeyBox = new QLineEdit(QtUtils::toQString(info->privateKeyFile())); _passphraseBox = new QLineEdit(QtUtils::toQString(info->passphrase())); _passphraseBox->setEchoMode(QLineEdit::Password); _passphraseEchoModeButton = new QPushButton; VERIFY(connect(_passphraseEchoModeButton, SIGNAL(clicked()), this, SLOT(togglePassphraseEchoMode()))); togglePassphraseEchoMode(); _passwordLabel = new QLabel("User Password:"******"Private key:"); _sshPassphraseLabel = new QLabel("Passphrase:"); _sshAddressLabel = new QLabel("SSH Address:"); _sshUserNameLabel = new QLabel("SSH User Name:"); _sshAuthMethodLabel = new QLabel("SSH Auth Method:"); /* // Commented because of this: // https://github.com/paralect/robomongo/issues/391 #ifdef Q_OS_WIN QRegExp pathx("([a-zA-Z]:)?([\\\\/][a-zA-Z0-9_.-]+)+[\\\\/]?"); #else QRegExp pathx("^\\/?([\\d\\w\\.]+)(/([\\d\\w\\.]+))*\\/?$"); #endif // Q_OS_WIN _publicKeyBox->setValidator(new QRegExpValidator(pathx, this)); _privateKeyBox->setValidator(new QRegExpValidator(pathx, this)); */ QHBoxLayout *hostAndPasswordLayout = new QHBoxLayout; hostAndPasswordLayout->addWidget(_sshHostName); hostAndPasswordLayout->addWidget(new QLabel(":")); hostAndPasswordLayout->addWidget(_sshPort); QGridLayout *connectionLayout = new QGridLayout; connectionLayout->setAlignment(Qt::AlignTop); connectionLayout->setColumnStretch(1, 1); connectionLayout->setColumnMinimumWidth(0, _passwordLabel->sizeHint().width() + 5); connectionLayout->addWidget(_sshAddressLabel , 1, 0); connectionLayout->addLayout(hostAndPasswordLayout, 1, 1, 1, 2); connectionLayout->addWidget(_sshUserNameLabel, 2, 0); connectionLayout->addWidget(_userName, 2, 1, 1, 2); connectionLayout->addWidget(_sshAuthMethodLabel, 4, 0); connectionLayout->addWidget(_security, 4, 1, 1, 2); connectionLayout->addWidget(_passwordLabel, 5, 0); connectionLayout->addWidget(_passwordBox, 5, 1); connectionLayout->addWidget(_passwordEchoModeButton, 5, 2); _selectPrivateFileButton = new QPushButton("..."); _selectPrivateFileButton->setMaximumWidth(50); connectionLayout->addWidget(_sshPrivateKeyLabel, 7, 0); connectionLayout->addWidget(_privateKeyBox, 7, 1); connectionLayout->addWidget(_selectPrivateFileButton, 7, 2); connectionLayout->addWidget(_sshPassphraseLabel, 8, 0); connectionLayout->addWidget(_passphraseBox, 8, 1); connectionLayout->addWidget(_passphraseEchoModeButton, 8, 2); connectionLayout->addWidget(_askForPassword, 9, 1, 1, 2); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(_sshSupport); mainLayout->addLayout(connectionLayout); setLayout(mainLayout); if (info->authMethod() == "publickey") { utils::setCurrentText(_security, "Private Key"); } else { utils::setCurrentText(_security, "Password"); } securityChange(_security->currentText()); VERIFY(connect(_selectPrivateFileButton, SIGNAL(clicked()), this, SLOT(setPrivateFile()))); sshSupportStateChange(_sshSupport->checkState()); VERIFY(connect(_sshSupport, SIGNAL(stateChanged(int)), this, SLOT(sshSupportStateChange(int)))); _sshHostName->setFocus(); #ifdef Q_OS_MAC _passwordEchoModeButton->setMaximumWidth(_selectPrivateFileButton->width()); _passphraseEchoModeButton->setMaximumWidth(_selectPrivateFileButton->width()); #else _passwordEchoModeButton->setMinimumWidth(_selectPrivateFileButton->width()); _passphraseEchoModeButton->setMinimumWidth(_selectPrivateFileButton->width()); #endif // Attempt to fix the issue for Windows High DPI button height is slightly taller than other widgets #ifdef Q_OS_WIN _passwordEchoModeButton->setMaximumHeight(HighDpiContants::WIN_HIGH_DPI_BUTTON_HEIGHT); _passphraseEchoModeButton->setMaximumHeight(HighDpiContants::WIN_HIGH_DPI_BUTTON_HEIGHT); _selectPrivateFileButton->setMaximumHeight(HighDpiContants::WIN_HIGH_DPI_BUTTON_HEIGHT); #endif }
SshTunelTab::SshTunelTab(ConnectionSettings *settings) : _settings(settings) { SSHInfo info = _settings->sshInfo(); _sshSupport = new QCheckBox("SSH support"); _sshSupport->setChecked(info.isValid()); _sshHostName = new QLineEdit(QtUtils::toQString(info._hostName)); _userName = new QLineEdit(QtUtils::toQString(info._userName)); _sshPort = new QLineEdit(QString::number(info._port)); _sshPort->setFixedWidth(80); QRegExp rx("\\d+");//(0-65554) _sshPort->setValidator(new QRegExpValidator(rx, this)); _security = new QComboBox(); _security->addItems(QStringList() << "Password" << "PublicKey"); VERIFY(connect(_security,SIGNAL(currentIndexChanged(const QString&)),this,SLOT(securityChange(const QString&)))); _passwordBox = new QLineEdit(QtUtils::toQString(info._password)); _publicKeyBox = new QLineEdit(QtUtils::toQString(info._publicKey._publicKey)); _privateKeyBox = new QLineEdit(QtUtils::toQString(info._publicKey._privateKey)); _passphraseBox = new QLineEdit(QtUtils::toQString(info._publicKey._passphrase)); #ifdef Q_OS_WIN QRegExp pathx("([a-zA-Z]:)?([\\\\/][a-zA-Z0-9_.-]+)+[\\\\/]?"); #else QRegExp pathx("^\\/?([\\d\\w\\.]+)(/([\\d\\w\\.]+))*\\/?$"); #endif // Q_OS_WIN _publicKeyBox->setValidator(new QRegExpValidator(pathx, this)); _privateKeyBox->setValidator(new QRegExpValidator(pathx, this)); QGridLayout *connectionLayout = new QGridLayout; connectionLayout->addWidget(new QLabel("SSH Host:"), 1, 0); connectionLayout->addWidget(_sshHostName, 1, 1); connectionLayout->addWidget(new QLabel("Username:"******"Port:"), 3, 0); connectionLayout->addWidget(_sshPort, 3, 1); connectionLayout->addWidget(new QLabel("Security:"), 4, 0); connectionLayout->addWidget(_security, 4, 1); _pivateKeyFrame = new QFrame; QVBoxLayout *pivL = new QVBoxLayout; pivL->setContentsMargins(0,0,0,0); QHBoxLayout *pivL1 = new QHBoxLayout; pivL1->addWidget(new QLabel("Public key:")); pivL1->addWidget(_publicKeyBox); QPushButton *selectPublicFile = new QPushButton("..."); selectPublicFile->setFixedSize(20,20); pivL1->addWidget(selectPublicFile); QHBoxLayout *pivL2 = new QHBoxLayout; pivL2->addWidget(new QLabel("Private key:")); pivL2->addWidget(_privateKeyBox); QPushButton *selectPrivateFile = new QPushButton("..."); selectPrivateFile->setFixedSize(20,20); pivL2->addWidget(selectPrivateFile); QHBoxLayout *pivL3 = new QHBoxLayout; pivL3->addWidget(new QLabel("Passphrase:")); pivL3->addWidget(_passphraseBox); pivL->addLayout(pivL1); pivL->addLayout(pivL2); pivL->addLayout(pivL3); _pivateKeyFrame->setLayout(pivL); _passwordFrame = new QFrame; QHBoxLayout *pasL = new QHBoxLayout; pasL->setContentsMargins(0,0,0,0); pasL->addWidget(new QLabel("Password:"******"PublicKey"); } else{ _security->setCurrentText("Password"); } securityChange(_security->currentText()); VERIFY(connect(selectPrivateFile, SIGNAL(clicked()), this, SLOT(setPrivateFile()))); VERIFY(connect(selectPublicFile, SIGNAL(clicked()), this, SLOT(setPublicFile()))); sshSupportStateChange(_sshSupport->checkState()); VERIFY(connect(_sshSupport,SIGNAL(stateChanged(int)),this,SLOT(sshSupportStateChange(int)))); _sshHostName->setFocus(); }