From 0a9087eecac7538c2f9cf788e56d0498b83197ee Mon Sep 17 00:00:00 2001 From: ck <qt-info@nokia.com> Date: Fri, 16 Apr 2010 12:46:08 +0200 Subject: [PATCH] Maemo: Allow more than one SSH key on the device. Reviewed-by: kh1 --- .../qt-maemo/maemosettingswidget.cpp | 35 ++++++++++++------- .../qt-maemo/maemosettingswidget.h | 6 ++-- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.cpp index 903f8a7aa2e..28a81620a9d 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.cpp @@ -41,10 +41,11 @@ #include "maemosshconfigdialog.h" #include "maemosshthread.h" +#include <QtCore/QFile> +#include <QtCore/QFileInfo> #include <QtCore/QRegExp> #include <QtCore/QTextStream> -#include <QtCore/QFileInfo> #include <QtGui/QFileDialog> #include <QtGui/QMessageBox> #include <QtGui/QIntValidator> @@ -297,7 +298,6 @@ void MaemoSettingsWidget::authenticationTypeChanged() m_ui->passwordLabel->setEnabled(usePassword); m_ui->keyFileLineEdit->setEnabled(!usePassword); m_ui->keyLabel->setEnabled(!usePassword); - m_ui->deployKeyButton->setEnabled(usePassword); } void MaemoSettingsWidget::hostNameEditingFinished() @@ -363,7 +363,7 @@ void MaemoSettingsWidget::showGenerateSshKeyDialog() void MaemoSettingsWidget::setPublicKey(const QString &path) { - m_publicKey = path; + m_publicKeyFileName = path; } void MaemoSettingsWidget::setPrivateKey(const QString &path) @@ -377,21 +377,32 @@ void MaemoSettingsWidget::deployKey() if (m_keyDeployer) return; - if (!QFileInfo(m_publicKey).exists()) { + if (!QFileInfo(m_publicKeyFileName).exists()) { const QString &dir = QFileInfo(currentConfig().keyFile).path(); - m_publicKey = QFileDialog::getOpenFileName(this, + m_publicKeyFileName = QFileDialog::getOpenFileName(this, tr("Choose public key file"), dir, tr("Public Key Files(*.pub);;All Files (*)")); } - if (m_publicKey.isEmpty()) + if (m_publicKeyFileName.isEmpty()) return; + QFile keyFile(m_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(m_publicKeyFileName)); + return; + } m_ui->deployKeyButton->disconnect(); - SshDeploySpec deploySpec(m_publicKey, homeDirOnDevice(currentConfig().uname) - + QLatin1String("/.ssh/authorized_keys"), true); - m_keyDeployer = new MaemoSshDeployer(currentConfig(), QList<SshDeploySpec>() << deploySpec); - connect(m_keyDeployer, SIGNAL(finished()), this, SLOT(handleDeployThreadFinished())); + const QString command = QLatin1String("test -d .ssh || mkdir .ssh && echo '") + + key + QLatin1String("' >> .ssh/authorized_keys"); + m_keyDeployer = new MaemoSshRunner(currentConfig(), command); + connect(m_keyDeployer, SIGNAL(finished()), + this, SLOT(handleDeployThreadFinished())); m_ui->deployKeyButton->setText(tr("Stop deploying")); connect(m_ui->deployKeyButton, SIGNAL(clicked()), this, SLOT(stopDeploying())); m_keyDeployer->start(); @@ -416,14 +427,12 @@ void MaemoSettingsWidget::stopDeploying() { if (m_keyDeployer) { m_ui->deployKeyButton->disconnect(); - const bool buttonWasEnabled = m_ui->deployKeyButton->isEnabled(); m_keyDeployer->disconnect(); m_keyDeployer->stop(); delete m_keyDeployer; m_keyDeployer = 0; m_ui->deployKeyButton->setText(tr("Deploy Key ...")); connect(m_ui->deployKeyButton, SIGNAL(clicked()), this, SLOT(deployKey())); - m_ui->deployKeyButton->setEnabled(buttonWasEnabled); } } @@ -434,12 +443,14 @@ void MaemoSettingsWidget::currentConfigChanged(int index) m_ui->removeConfigButton->setEnabled(false); m_ui->testConfigButton->setEnabled(false); m_ui->generateKeyButton->setEnabled(false); + m_ui->deployKeyButton->setEnabled(false); clearDetails(); m_ui->detailsWidget->setEnabled(false); } else { m_ui->removeConfigButton->setEnabled(true); m_ui->testConfigButton->setEnabled(true); m_ui->generateKeyButton->setEnabled(true); + m_ui->deployKeyButton->setEnabled(true); m_ui->configurationComboBox->setCurrentIndex(index); display(currentConfig()); } diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.h b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.h index af56ed9b387..cad3f32e38c 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.h @@ -50,7 +50,7 @@ QT_END_NAMESPACE namespace Qt4ProjectManager { namespace Internal { -class MaemoSshDeployer; +class MaemoSshRunner; class NameValidator; class TimeoutValidator; @@ -107,8 +107,8 @@ private: MaemoDeviceConfig m_lastConfigSim; NameValidator * const m_nameValidator; TimeoutValidator * const m_timeoutValidator; - MaemoSshDeployer *m_keyDeployer; - QString m_publicKey; + MaemoSshRunner *m_keyDeployer; + QString m_publicKeyFileName; }; } // namespace Internal -- GitLab