forked from qt-creator/qt-creator
Maemo: Introduce dedicated class for key deploying.
We want to re-use that functionality in our wizard.
This commit is contained in:
@@ -38,13 +38,13 @@
|
||||
|
||||
#include "maemoconfigtestdialog.h"
|
||||
#include "maemodeviceconfigurations.h"
|
||||
#include "maemokeydeployer.h"
|
||||
#include "maemoremoteprocessesdialog.h"
|
||||
#include "maemosshconfigdialog.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/ssh/sshremoteprocessrunner.h>
|
||||
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QRegExp>
|
||||
#include <QtCore/QSettings>
|
||||
@@ -102,9 +102,14 @@ MaemoDeviceConfigurationsSettingsWidget::MaemoDeviceConfigurationsSettingsWidget
|
||||
m_ui(new Ui_MaemoDeviceConfigurationsSettingsWidget),
|
||||
m_devConfigs(MaemoDeviceConfigurations::cloneInstance()),
|
||||
m_nameValidator(new NameValidator(m_devConfigs.data(), this)),
|
||||
m_keyDeployer(new MaemoKeyDeployer(this)),
|
||||
m_saveSettingsRequested(false)
|
||||
{
|
||||
initGui();
|
||||
connect(m_keyDeployer, SIGNAL(error(QString)), this,
|
||||
SLOT(handleDeploymentError(QString)), Qt::QueuedConnection);
|
||||
connect(m_keyDeployer, SIGNAL(finishedSuccessfully()),
|
||||
SLOT(handleDeploymentSuccess()));
|
||||
}
|
||||
|
||||
MaemoDeviceConfigurationsSettingsWidget::~MaemoDeviceConfigurationsSettingsWidget()
|
||||
@@ -374,9 +379,6 @@ void MaemoDeviceConfigurationsSettingsWidget::setPrivateKey(const QString &path)
|
||||
|
||||
void MaemoDeviceConfigurationsSettingsWidget::deployKey()
|
||||
{
|
||||
if (m_keyDeployer)
|
||||
return;
|
||||
|
||||
const SshConnectionParameters sshParams = currentConfig()->sshParameters();
|
||||
const QString &dir = QFileInfo(sshParams.privateKeyFile).path();
|
||||
QString publicKeyFileName = QFileDialog::getOpenFileName(this,
|
||||
@@ -385,71 +387,29 @@ void MaemoDeviceConfigurationsSettingsWidget::deployKey()
|
||||
if (publicKeyFileName.isEmpty())
|
||||
return;
|
||||
|
||||
QFile keyFile(publicKeyFileName);
|
||||
QByteArray key;
|
||||
const bool keyFileAccessible = keyFile.open(QIODevice::ReadOnly);
|
||||
if (keyFileAccessible)
|
||||
key = keyFile.readAll();
|
||||
if (!keyFileAccessible || keyFile.error() != QFile::NoError) {
|
||||
QMessageBox::critical(this, tr("Deployment Failed"),
|
||||
tr("Could not read public key file '%1'.").arg(publicKeyFileName));
|
||||
return;
|
||||
}
|
||||
|
||||
disconnect(m_ui->deployKeyButton, 0, this, 0);
|
||||
m_ui->deployKeyButton->setText(tr("Stop Deploying"));
|
||||
connect(m_ui->deployKeyButton, SIGNAL(clicked()), this,
|
||||
SLOT(stopDeploying()));
|
||||
|
||||
m_keyDeployer = SshRemoteProcessRunner::create(sshParams);
|
||||
connect(m_keyDeployer.data(), SIGNAL(connectionError(Core::SshError)), this,
|
||||
SLOT(handleConnectionFailure()));
|
||||
connect(m_keyDeployer.data(), SIGNAL(processClosed(int)), this,
|
||||
SLOT(handleKeyUploadFinished(int)));
|
||||
const QByteArray command = "test -d .ssh "
|
||||
"|| mkdir .ssh && chmod 0700 .ssh && echo '"
|
||||
+ key + "' >> .ssh/authorized_keys && chmod 0700 .ssh/authorized_keys";
|
||||
m_keyDeployer->run(command);
|
||||
SLOT(finishDeployment()));
|
||||
m_keyDeployer->deployPublicKey(sshParams, publicKeyFileName);
|
||||
}
|
||||
|
||||
void MaemoDeviceConfigurationsSettingsWidget::handleConnectionFailure()
|
||||
void MaemoDeviceConfigurationsSettingsWidget::handleDeploymentError(const QString &errorMsg)
|
||||
{
|
||||
if (!m_keyDeployer)
|
||||
return;
|
||||
|
||||
QMessageBox::critical(this, tr("Deployment Failed"),
|
||||
tr("Could not connect to host: %1")
|
||||
.arg(m_keyDeployer->connection()->errorString()));
|
||||
stopDeploying();
|
||||
QMessageBox::critical(this, tr("Deployment Failed"), errorMsg);
|
||||
finishDeployment();
|
||||
}
|
||||
|
||||
void MaemoDeviceConfigurationsSettingsWidget::handleKeyUploadFinished(int exitStatus)
|
||||
void MaemoDeviceConfigurationsSettingsWidget::handleDeploymentSuccess()
|
||||
{
|
||||
Q_ASSERT(exitStatus == SshRemoteProcess::FailedToStart
|
||||
|| exitStatus == SshRemoteProcess::KilledBySignal
|
||||
|| exitStatus == SshRemoteProcess::ExitedNormally);
|
||||
|
||||
if (!m_keyDeployer)
|
||||
return;
|
||||
|
||||
if (exitStatus == SshRemoteProcess::ExitedNormally
|
||||
&& m_keyDeployer->process()->exitCode() == 0) {
|
||||
QMessageBox::information(this, tr("Deployment Succeeded"),
|
||||
tr("Key was successfully deployed."));
|
||||
} else {
|
||||
QMessageBox::critical(this, tr("Deployment Failed"),
|
||||
tr("Key deployment failed: %1.")
|
||||
.arg(m_keyDeployer->process()->errorString()));
|
||||
}
|
||||
stopDeploying();
|
||||
QMessageBox::information(this, tr("Deployment Succeeded"),
|
||||
tr("Key was successfully deployed."));
|
||||
finishDeployment();
|
||||
}
|
||||
|
||||
void MaemoDeviceConfigurationsSettingsWidget::stopDeploying()
|
||||
void MaemoDeviceConfigurationsSettingsWidget::finishDeployment()
|
||||
{
|
||||
if (m_keyDeployer) {
|
||||
disconnect(m_keyDeployer.data(), 0, this, 0);
|
||||
m_keyDeployer = SshRemoteProcessRunner::Ptr();
|
||||
}
|
||||
m_keyDeployer->stopDeployment();
|
||||
m_ui->deployKeyButton->disconnect();
|
||||
m_ui->deployKeyButton->setText(tr("Deploy Public Key ..."));
|
||||
connect(m_ui->deployKeyButton, SIGNAL(clicked()), this, SLOT(deployKey()));
|
||||
@@ -457,7 +417,7 @@ void MaemoDeviceConfigurationsSettingsWidget::stopDeploying()
|
||||
|
||||
void MaemoDeviceConfigurationsSettingsWidget::currentConfigChanged(int index)
|
||||
{
|
||||
stopDeploying();
|
||||
finishDeployment();
|
||||
if (index == -1) {
|
||||
m_ui->removeConfigButton->setEnabled(false);
|
||||
m_ui->testConfigButton->setEnabled(false);
|
||||
|
||||
Reference in New Issue
Block a user