From 9b840c4fcedf86d8e908ee35e4f7ea3124155633 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Wed, 23 Apr 2025 11:44:53 +0200 Subject: [PATCH] ProjectExplorer: Change authenticationType to BoolAspect Using a BoolAspect allows us to set it as an enabler on the PrivateKeyFile aspect. Change-Id: Ief61526d65d3c2c2bdfe8e2773404ccb701dc525 Reviewed-by: hjk --- .../projectexplorer/devicesupport/idevice.cpp | 9 +++--- .../devicesupport/sshparameters.cpp | 28 ++++++++----------- .../devicesupport/sshparameters.h | 2 +- .../genericlinuxdeviceconfigurationwidget.cpp | 2 +- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/plugins/projectexplorer/devicesupport/idevice.cpp b/src/plugins/projectexplorer/devicesupport/idevice.cpp index 89599a071fa..672f5ee800a 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.cpp +++ b/src/plugins/projectexplorer/devicesupport/idevice.cpp @@ -717,8 +717,7 @@ SshParameters IDevice::sshParameters() const void IDevice::setDefaultSshParameters(const SshParameters &sshParameters) { - QTC_ASSERT(QThread::currentThread() == qApp->thread(), - return); // This is not thread-safe. + QTC_ASSERT(QThread::currentThread() == qApp->thread(), return); sshParametersAspectContainer().host.setDefaultValue(sshParameters.host()); sshParametersAspectContainer().port.setDefaultValue(sshParameters.port()); @@ -726,8 +725,8 @@ void IDevice::setDefaultSshParameters(const SshParameters &sshParameters) sshParametersAspectContainer().privateKeyFile.setDefaultPathValue( sshParameters.privateKeyFile()); sshParametersAspectContainer().timeout.setDefaultValue(sshParameters.timeout()); - sshParametersAspectContainer().authenticationType.setDefaultValue( - sshParameters.authenticationType()); + sshParametersAspectContainer().useKeyFile.setDefaultValue( + sshParameters.authenticationType() == SshParameters::AuthenticationTypeSpecificKey); sshParametersAspectContainer().hostKeyCheckingMode.setDefaultValue( sshParameters.hostKeyCheckingMode()); @@ -939,7 +938,7 @@ void DeviceRef::setSshParameters(const SshParameters ¶ms) { const IDevice::Ptr device = m_mutableDevice.lock(); QTC_ASSERT(device, return); - device->setDefaultSshParameters(params); + device->sshParametersAspectContainer().setSshParameters(params); } SshParametersAspectContainer &IDevice::sshParametersAspectContainer() const diff --git a/src/plugins/projectexplorer/devicesupport/sshparameters.cpp b/src/plugins/projectexplorer/devicesupport/sshparameters.cpp index 226d4f73af7..14818113815 100644 --- a/src/plugins/projectexplorer/devicesupport/sshparameters.cpp +++ b/src/plugins/projectexplorer/devicesupport/sshparameters.cpp @@ -226,7 +226,7 @@ void SshParametersAspectContainer::setSshParameters(const SshParameters ¶ms) userName.setVolatileValue(params.userName()); privateKeyFile.setVolatileValue(params.privateKeyFile().toUserOutput()); timeout.setVolatileValue(params.timeout()); - authenticationType.setVolatileValue(params.authenticationType()); + useKeyFile.setVolatileValue(params.authenticationType() == SshParameters::AuthenticationTypeSpecificKey); hostKeyCheckingMode.setVolatileValue(params.hostKeyCheckingMode()); privateKeyFile.setEnabled( @@ -246,21 +246,21 @@ SshParameters SshParametersAspectContainer::sshParameters() const params.setUserName(userName.expandedValue()); params.setPrivateKeyFile(privateKeyFile.expandedValue()); params.setTimeout(timeout.value()); - params.setAuthenticationType(authenticationType.value()); + params.setAuthenticationType( + useKeyFile() ? SshParameters::AuthenticationTypeSpecificKey + : SshParameters::AuthenticationTypeAll); params.setHostKeyCheckingMode(hostKeyCheckingMode.value()); return params; } SshParametersAspectContainer::SshParametersAspectContainer() { - authenticationType.setDefaultValue(SshParameters::AuthenticationTypeAll); - authenticationType.setDisplayStyle(SelectionAspect::DisplayStyle::RadioButtons); - authenticationType - .addOption(Tr::tr("Default"), Tr::tr("Use all available authentication methods")); - authenticationType - .addOption(Tr::tr("Specific &key"), Tr::tr("Use only the specified private key")); - authenticationType.setToolTip(Tr::tr("Select the authentication method to use")); - authenticationType.setLabelText(Tr::tr("Authentication type:")); + useKeyFile.setDefaultValue(SshParameters::AuthenticationTypeAll); + useKeyFile.setToolTip( + Tr::tr("Enable to specify a private key file to use for authentication, " + "otherwise the default mechanism is used for authentication " + "(password, .sshconfig and the default private key)")); + useKeyFile.setLabelText(Tr::tr("Use specific key:")); hostKeyCheckingMode.setToolTip(Tr::tr("The device's SSH host key checking mode")); hostKeyCheckingMode.setLabelText(Tr::tr("Host key check:")); @@ -290,13 +290,7 @@ SshParametersAspectContainer::SshParametersAspectContainer() privateKeyFile.setToolTip(Tr::tr("The device's private key file")); privateKeyFile.setLabelText(Tr::tr("Private key file:")); privateKeyFile.setHistoryCompleter("KeyFile"); - privateKeyFile.setEnabled( - authenticationType.volatileValue() == SshParameters::AuthenticationTypeSpecificKey); - - connect(&authenticationType, &SelectionAspect::volatileValueChanged, this, [this]() { - privateKeyFile.setEnabled( - authenticationType.volatileValue() == SshParameters::AuthenticationTypeSpecificKey); - }); + privateKeyFile.setEnabler(&useKeyFile); timeout.setDefaultValue(10); timeout.setLabelText(Tr::tr("Timeout:")); diff --git a/src/plugins/projectexplorer/devicesupport/sshparameters.h b/src/plugins/projectexplorer/devicesupport/sshparameters.h index 50fd2184464..89e55fd61ed 100644 --- a/src/plugins/projectexplorer/devicesupport/sshparameters.h +++ b/src/plugins/projectexplorer/devicesupport/sshparameters.h @@ -82,9 +82,9 @@ public: void setSshParameters(const SshParameters ¶ms); public: + Utils::BoolAspect useKeyFile{this}; Utils::FilePathAspect privateKeyFile{this}; Utils::IntegerAspect timeout{this}; - Utils::TypedSelectionAspect authenticationType{this}; Utils::TypedSelectionAspect hostKeyCheckingMode{this}; Utils::StringAspect host{this}; diff --git a/src/plugins/remotelinux/genericlinuxdeviceconfigurationwidget.cpp b/src/plugins/remotelinux/genericlinuxdeviceconfigurationwidget.cpp index 801a7bc7dc8..b17b3631cc9 100644 --- a/src/plugins/remotelinux/genericlinuxdeviceconfigurationwidget.cpp +++ b/src/plugins/remotelinux/genericlinuxdeviceconfigurationwidget.cpp @@ -61,10 +61,10 @@ GenericLinuxDeviceConfigurationWidget::GenericLinuxDeviceConfigurationWidget( Form { Tr::tr("Machine type:"), machineType, st, br, - device->sshParametersAspectContainer().authenticationType.labelText(), device->sshParametersAspectContainer().authenticationType, st, br, device->sshParametersAspectContainer().host, device->sshParametersAspectContainer().port, device->sshParametersAspectContainer().hostKeyCheckingMode, st, br, device->freePortsAspect, portWarningLabel, device->sshParametersAspectContainer().timeout, st, br, device->sshParametersAspectContainer().userName, st, br, + device->sshParametersAspectContainer().useKeyFile, st, br, device->sshParametersAspectContainer().privateKeyFile, createKeyButton, br, device->debugServerPathAspect, br, device->qmlRunCommandAspect, br,