diff options
Diffstat (limited to 'src/sshagent/AgentSettingsWidget.cpp')
-rw-r--r-- | src/sshagent/AgentSettingsWidget.cpp | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/src/sshagent/AgentSettingsWidget.cpp b/src/sshagent/AgentSettingsWidget.cpp index be23c6906..3db5431fc 100644 --- a/src/sshagent/AgentSettingsWidget.cpp +++ b/src/sshagent/AgentSettingsWidget.cpp @@ -17,9 +17,11 @@ */ #include "AgentSettingsWidget.h" +#include "SSHAgent.h" #include "ui_AgentSettingsWidget.h" #include "core/Config.h" +#include <QProcessEnvironment> AgentSettingsWidget::AgentSettingsWidget(QWidget* parent) : QWidget(parent) @@ -28,7 +30,13 @@ AgentSettingsWidget::AgentSettingsWidget(QWidget* parent) m_ui->setupUi(this); #ifndef Q_OS_WIN m_ui->useOpenSSHCheckBox->setVisible(false); +#else + m_ui->sshAuthSockWidget->setVisible(false); #endif + m_ui->sshAuthSockMessageWidget->setVisible(sshAgent()->isEnabled()); + m_ui->sshAuthSockMessageWidget->setCloseButtonVisible(false); + m_ui->sshAuthSockMessageWidget->setAutoHideTimeout(-1); + connect(m_ui->enableSSHAgentCheckBox, SIGNAL(stateChanged(int)), SLOT(toggleSettingsEnabled())); } AgentSettingsWidget::~AgentSettingsWidget() @@ -37,16 +45,53 @@ AgentSettingsWidget::~AgentSettingsWidget() void AgentSettingsWidget::loadSettings() { - m_ui->enableSSHAgentCheckBox->setChecked(config()->get("SSHAgent", false).toBool()); + auto sshAgentEnabled = sshAgent()->isEnabled(); + + m_ui->enableSSHAgentCheckBox->setChecked(sshAgentEnabled); #ifdef Q_OS_WIN - m_ui->useOpenSSHCheckBox->setChecked(config()->get("SSHAgentOpenSSH", false).toBool()); + m_ui->useOpenSSHCheckBox->setChecked(sshAgent()->useOpenSSH()); +#else + auto sshAuthSock = sshAgent()->socketPath(false); + auto sshAuthSockOverride = sshAgent()->authSockOverride(); + m_ui->sshAuthSockLabel->setText(sshAuthSock.isEmpty() ? tr("(empty)") : sshAuthSock); + m_ui->sshAuthSockOverrideEdit->setText(sshAuthSockOverride); +#endif + + m_ui->sshAuthSockMessageWidget->setVisible(sshAgentEnabled); + + if (sshAgentEnabled) { +#ifndef Q_OS_WIN + if (sshAuthSock.isEmpty() && sshAuthSockOverride.isEmpty()) { + m_ui->sshAuthSockMessageWidget->showMessage( + tr("No SSH Agent socket available. Either make sure SSH_AUTH_SOCK environment variable exists or set " + "an override."), + MessageWidget::Warning); + return; + } #endif + QList<QSharedPointer<OpenSSHKey>> keys; + if (sshAgent()->listIdentities(keys)) { + m_ui->sshAuthSockMessageWidget->showMessage(tr("SSH Agent connection is working!"), + MessageWidget::Positive); + } else { + m_ui->sshAuthSockMessageWidget->showMessage(sshAgent()->errorString(), MessageWidget::Error); + } + } + + toggleSettingsEnabled(); } void AgentSettingsWidget::saveSettings() { - config()->set("SSHAgent", m_ui->enableSSHAgentCheckBox->isChecked()); + auto sshAuthSockOverride = m_ui->sshAuthSockOverrideEdit->text(); + sshAgent()->setAuthSockOverride(sshAuthSockOverride); #ifdef Q_OS_WIN - config()->set("SSHAgentOpenSSH", m_ui->useOpenSSHCheckBox->isChecked()); + sshAgent()->setUseOpenSSH(m_ui->useOpenSSHCheckBox->isChecked()); #endif + sshAgent()->setEnabled(m_ui->enableSSHAgentCheckBox->isChecked()); +} + +void AgentSettingsWidget::toggleSettingsEnabled() +{ + m_ui->agentConfigPageBody->setEnabled(m_ui->enableSSHAgentCheckBox->isChecked()); } |