summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@nokia.com>2011-02-03 09:59:50 +0100
committerChristian Kandeler <christian.kandeler@nokia.com>2011-02-03 10:00:36 +0100
commita84106dfd470e66f75a4b9d161ca72d51b5740e4 (patch)
tree6da88b9c607796508eb1917c3a433348584b4c19
parent011f2f9858193df5cd88d36eb82417c412d633fb (diff)
downloadqt-creator-a84106dfd470e66f75a4b9d161ca72d51b5740e4.tar.gz
Maemo: Introduce dedicated class for key deploying.
We want to re-use that functionality in our wizard.
-rw-r--r--src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurationssettingswidget.cpp76
-rw-r--r--src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurationssettingswidget.h10
-rw-r--r--src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigwizard.cpp33
-rw-r--r--src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigwizard.h33
-rw-r--r--src/plugins/qt4projectmanager/qt-maemo/maemokeydeployer.cpp123
-rw-r--r--src/plugins/qt4projectmanager/qt-maemo/maemokeydeployer.h76
-rw-r--r--src/plugins/qt4projectmanager/qt-maemo/qt-maemo.pri6
7 files changed, 292 insertions, 65 deletions
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurationssettingswidget.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurationssettingswidget.cpp
index 912726090d..927013c3c9 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurationssettingswidget.cpp
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurationssettingswidget.cpp
@@ -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);
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurationssettingswidget.h b/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurationssettingswidget.h
index e073c3df72..cc13caab45 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurationssettingswidget.h
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurationssettingswidget.h
@@ -37,7 +37,6 @@
#include <QtCore/QList>
#include <QtCore/QScopedPointer>
-#include <QtCore/QSharedPointer>
#include <QtCore/QString>
#include <QtGui/QWidget>
@@ -57,6 +56,7 @@ namespace Internal {
class NameValidator;
class MaemoDeviceConfig;
class MaemoDeviceConfigurations;
+class MaemoKeyDeployer;
class MaemoDeviceConfigurationsSettingsWidget : public QWidget
{
@@ -95,9 +95,9 @@ private slots:
// For key deploying.
void deployKey();
- void stopDeploying();
- void handleConnectionFailure();
- void handleKeyUploadFinished(int exitStatus);
+ void finishDeployment();
+ void handleDeploymentError(const QString &errorMsg);
+ void handleDeploymentSuccess();
private:
void initGui();
@@ -110,9 +110,9 @@ private:
void updatePortsWarningLabel();
Ui_MaemoDeviceConfigurationsSettingsWidget *m_ui;
- QSharedPointer<Core::SshRemoteProcessRunner> m_keyDeployer;
const QScopedPointer<MaemoDeviceConfigurations> m_devConfigs;
NameValidator * const m_nameValidator;
+ MaemoKeyDeployer *const m_keyDeployer;
bool m_saveSettingsRequested;
};
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigwizard.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigwizard.cpp
index dc2437377a..ed73dc9a62 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigwizard.cpp
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigwizard.cpp
@@ -1,3 +1,36 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of Qt Creator.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
#include "maemodeviceconfigwizard.h"
#include "ui_maemodeviceconfigwizardkeycreationpage.h"
#include "ui_maemodeviceconfigwizardpreviouskeysetupcheckpage.h"
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigwizard.h b/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigwizard.h
index dd08b3fcfe..0b933a9520 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigwizard.h
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigwizard.h
@@ -1,3 +1,36 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of Qt Creator.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
#ifndef MAEMODEVICECONFIGWIZARD_H
#define MAEMODEVICECONFIGWIZARD_H
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemokeydeployer.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemokeydeployer.cpp
new file mode 100644
index 0000000000..ff25305401
--- /dev/null
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemokeydeployer.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of Qt Creator.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "maemokeydeployer.h"
+
+#include <coreplugin/ssh/sshremoteprocessrunner.h>
+
+#include <QtCore/QFile>
+
+using namespace Core;
+
+namespace Qt4ProjectManager {
+namespace Internal {
+
+MaemoKeyDeployer::MaemoKeyDeployer(QObject *parent)
+ : QObject(parent)
+{
+}
+
+MaemoKeyDeployer::~MaemoKeyDeployer()
+{
+ cleanup();
+}
+
+void MaemoKeyDeployer::deployPublicKey(const SshConnectionParameters &sshParams,
+ const QString &keyFilePath)
+{
+ cleanup();
+ m_deployProcess = SshRemoteProcessRunner::create(sshParams);
+
+ QFile keyFile(keyFilePath);
+ QByteArray key;
+ const bool keyFileAccessible = keyFile.open(QIODevice::ReadOnly);
+ if (keyFileAccessible)
+ key = keyFile.readAll();
+ if (!keyFileAccessible || keyFile.error() != QFile::NoError) {
+ emit error(tr("Could not read public key file '%1'.").arg(keyFilePath));
+ return;
+ }
+
+ connect(m_deployProcess.data(), SIGNAL(connectionError(Core::SshError)), this,
+ SLOT(handleConnectionFailure()));
+ connect(m_deployProcess.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_deployProcess->run(command);
+}
+
+void MaemoKeyDeployer::handleConnectionFailure()
+{
+ if (!m_deployProcess)
+ return;
+ const QString errorMsg = m_deployProcess->connection()->errorString();
+ cleanup();
+ emit error(tr("Connection failed: %1").arg(errorMsg));
+}
+
+void MaemoKeyDeployer::handleKeyUploadFinished(int exitStatus)
+{
+ Q_ASSERT(exitStatus == SshRemoteProcess::FailedToStart
+ || exitStatus == SshRemoteProcess::KilledBySignal
+ || exitStatus == SshRemoteProcess::ExitedNormally);
+
+ if (!m_deployProcess)
+ return;
+
+ const int exitCode = m_deployProcess->process()->exitCode();
+ const QString errorMsg = m_deployProcess->process()->errorString();
+ cleanup();
+ if (exitStatus == SshRemoteProcess::ExitedNormally && exitCode == 0)
+ emit finishedSuccessfully();
+ else
+ emit error(tr("Key deployment failed: %1.").arg(errorMsg));
+}
+
+void MaemoKeyDeployer::stopDeployment()
+{
+ cleanup();
+}
+
+void MaemoKeyDeployer::cleanup()
+{
+ if (m_deployProcess) {
+ disconnect(m_deployProcess.data(), 0, this, 0);
+ m_deployProcess.clear();
+ }
+}
+
+
+} // namespace Internal
+} // namespace Qt4ProjectManager
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemokeydeployer.h b/src/plugins/qt4projectmanager/qt-maemo/maemokeydeployer.h
new file mode 100644
index 0000000000..1766ee8d02
--- /dev/null
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemokeydeployer.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of Qt Creator.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef MAEMOKEYDEPLOYER_H
+#define MAEMOKEYDEPLOYER_H
+
+#include <QtCore/QObject>
+#include <QtCore/QSharedPointer>
+
+namespace Core {
+class SshConnectionParameters;
+class SshRemoteProcessRunner;
+}
+
+namespace Qt4ProjectManager {
+namespace Internal {
+
+class MaemoKeyDeployer : public QObject
+{
+ Q_OBJECT
+public:
+ explicit MaemoKeyDeployer(QObject *parent = 0);
+ ~MaemoKeyDeployer();
+
+ void deployPublicKey(const Core::SshConnectionParameters &sshParams,
+ const QString &keyFilePath);
+ void stopDeployment();
+
+signals:
+ void error(const QString &errorMsg);
+ void finishedSuccessfully();
+
+private slots:
+ void handleConnectionFailure();
+ void handleKeyUploadFinished(int exitStatus);
+
+private:
+ void cleanup();
+
+ QSharedPointer<Core::SshRemoteProcessRunner> m_deployProcess;
+};
+
+} // namespace Internal
+} // namespace Qt4ProjectManager
+
+#endif // MAEMOKEYDEPLOYER_H
diff --git a/src/plugins/qt4projectmanager/qt-maemo/qt-maemo.pri b/src/plugins/qt4projectmanager/qt-maemo/qt-maemo.pri
index 5f38c7cf34..1577399f48 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/qt-maemo.pri
+++ b/src/plugins/qt4projectmanager/qt-maemo/qt-maemo.pri
@@ -47,7 +47,8 @@ HEADERS += \
$$PWD/qt4maemotargetfactory.h \
$$PWD/qt4maemotarget.h \
$$PWD/qt4maemodeployconfiguration.h \
- $$PWD/maemodeviceconfigwizard.h
+ $$PWD/maemodeviceconfigwizard.h \
+ $$PWD/maemokeydeployer.h
SOURCES += \
$$PWD/maemoconfigtestdialog.cpp \
@@ -95,7 +96,8 @@ SOURCES += \
$$PWD/qt4maemotargetfactory.cpp \
$$PWD/qt4maemotarget.cpp \
$$PWD/qt4maemodeployconfiguration.cpp \
- $$PWD/maemodeviceconfigwizard.cpp
+ $$PWD/maemodeviceconfigwizard.cpp \
+ $$PWD/maemokeydeployer.cpp
FORMS += \
$$PWD/maemoconfigtestdialog.ui \