Commit 4b687618 authored by Christian Kandeler's avatar Christian Kandeler
Browse files

Maemo: Start to make use of new SshRemoteProcessRunner class.

This removes some tedious keeping track of connection state.

Reviewed-by: kh1
parent 552a2d02
......@@ -38,8 +38,7 @@
#include "maemodeviceconfigurations.h"
#include "maemoglobal.h"
#include <coreplugin/ssh/sshconnection.h>
#include <coreplugin/ssh/sshremoteprocess.h>
#include <coreplugin/ssh/sshremoteprocessrunner.h>
#include <QtGui/QPalette>
#include <QtGui/QPushButton>
......@@ -71,63 +70,60 @@ MaemoConfigTestDialog::~MaemoConfigTestDialog()
void MaemoConfigTestDialog::startConfigTest()
{
if (m_infoProcess)
if (m_testProcessRunner)
return;
m_currentTest = GeneralTest;
m_ui->testResultEdit->setPlainText(tr("Testing configuration..."));
m_closeButton->setText(tr("Stop Test"));
m_connection = SshConnection::create();
connect(m_connection.data(), SIGNAL(connected()), this,
SLOT(handleConnected()));
connect(m_connection.data(), SIGNAL(error(Core::SshError)), this,
SLOT(handleConnectionError()));
m_connection->connectToHost(m_config.server);
}
void MaemoConfigTestDialog::handleConnected()
{
if (!m_connection)
return;
m_testProcessRunner = SshRemoteProcessRunner::create(m_config.server);
connect(m_testProcessRunner.data(), SIGNAL(connectionError(Core::SshError)),
this, SLOT(handleConnectionError()));
connect(m_testProcessRunner.data(), SIGNAL(processClosed(int)), this,
SLOT(handleTestProcessFinished(int)));
connect(m_testProcessRunner.data(),
SIGNAL(processOutputAvailable(QByteArray)), this,
SLOT(processSshOutput(QByteArray)));
QLatin1String sysInfoCmd("uname -rsm");
QLatin1String qtInfoCmd("dpkg-query -W -f '${Package} ${Version} ${Status}\n' 'libqt*' "
"|grep ' installed$'");
QString command(sysInfoCmd + " && " + qtInfoCmd);
m_infoProcess = m_connection->createRemoteProcess(command.toUtf8());
connect(m_infoProcess.data(), SIGNAL(closed(int)), this,
SLOT(handleInfoProcessFinished(int)));
connect(m_infoProcess.data(), SIGNAL(outputAvailable(QByteArray)), this,
SLOT(processSshOutput(QByteArray)));
m_infoProcess->start();
m_testProcessRunner->run(command.toUtf8());
}
void MaemoConfigTestDialog::handleConnectionError()
{
if (!m_connection)
if (!m_testProcessRunner)
return;
QString output = tr("Could not connect to host: %1")
.arg(m_connection->errorString());
.arg(m_testProcessRunner->connection()->errorString());
if (m_config.type == MaemoDeviceConfig::Simulator)
output += tr("\nDid you start Qemu?");
m_ui->testResultEdit->setPlainText(output);
stopConfigTest();
}
void MaemoConfigTestDialog::handleInfoProcessFinished(int exitStatus)
void MaemoConfigTestDialog::handleTestProcessFinished(int exitStatus)
{
if (!m_connection)
if (!m_testProcessRunner)
return;
Q_ASSERT(exitStatus == SshRemoteProcess::FailedToStart
|| exitStatus == SshRemoteProcess::KilledBySignal
|| exitStatus == SshRemoteProcess::ExitedNormally);
if (!m_infoProcess)
return;
if (m_currentTest == GeneralTest)
handleGeneralTestResult(exitStatus);
else
handleMadDeveloperTestResult(exitStatus);
}
void MaemoConfigTestDialog::handleGeneralTestResult(int exitStatus)
{
if (exitStatus != SshRemoteProcess::ExitedNormally
|| m_infoProcess->exitCode() != 0) {
|| m_testProcessRunner->process()->exitCode() != 0) {
m_ui->testResultEdit->setPlainText(tr("Remote process failed: %1")
.arg(m_infoProcess->errorString()));
.arg(m_testProcessRunner->process()->errorString()));
} else {
const QString &output = parseTestOutput();
if (!m_qtVersionOk) {
......@@ -137,26 +133,20 @@ void MaemoConfigTestDialog::handleInfoProcessFinished(int exitStatus)
m_ui->testResultEdit->setPlainText(output);
}
m_currentTest = MadDeveloperTest;
disconnect(m_testProcessRunner.data(),
SIGNAL(processOutputAvailable(QByteArray)), this,
SLOT(processSshOutput(QByteArray)));
const QByteArray command = "test -x " + MaemoGlobal::remoteSudo().toUtf8();
m_madDeveloperTestProcess = m_connection->createRemoteProcess(command);
connect(m_madDeveloperTestProcess.data(), SIGNAL(closed(int)), this,
SLOT(handleMadDeveloperTestProcessFinished(int)));
m_madDeveloperTestProcess->start();
m_testProcessRunner->run(command);
}
void MaemoConfigTestDialog::handleMadDeveloperTestProcessFinished(int exitStatus)
void MaemoConfigTestDialog::handleMadDeveloperTestResult(int exitStatus)
{
if (!m_connection)
return;
Q_ASSERT(exitStatus == SshRemoteProcess::FailedToStart
|| exitStatus == SshRemoteProcess::KilledBySignal
|| exitStatus == SshRemoteProcess::ExitedNormally);
if (exitStatus != SshRemoteProcess::ExitedNormally) {
m_ui->testResultEdit->setPlainText(tr("Remote process failed: %1")
.arg(m_madDeveloperTestProcess->errorString()));
} else if (m_madDeveloperTestProcess->exitCode() != 0) {
.arg(m_testProcessRunner->process()->errorString()));
} else if (m_testProcessRunner->process()->exitCode() != 0) {
m_ui->errorLabel->setText(m_ui->errorLabel->text()
+ QLatin1String("<br>") + tr("Mad Developer is not installed.<br>"
"You will not be able to deploy to this device."));
......@@ -173,13 +163,10 @@ void MaemoConfigTestDialog::handleMadDeveloperTestProcessFinished(int exitStatus
void MaemoConfigTestDialog::stopConfigTest()
{
if (m_infoProcess)
disconnect(m_infoProcess.data(), 0, this, 0);
if (m_madDeveloperTestProcess)
disconnect(m_madDeveloperTestProcess.data(), 0, this, 0);
if (m_connection)
disconnect(m_connection.data(), 0, this, 0);
if (m_testProcessRunner) {
disconnect(m_testProcessRunner.data(), 0, this, 0);
m_testProcessRunner = SshRemoteProcessRunner::Ptr();
}
m_deviceTestOutput.clear();
m_closeButton->setText(tr("Close"));
}
......
......@@ -44,8 +44,7 @@ class Ui_MaemoConfigTestDialog;
QT_END_NAMESPACE
namespace Core {
class SshConnection;
class SshRemoteProcess;
class SshRemoteProcessRunner;
} // namespace Core
namespace Qt4ProjectManager {
......@@ -66,24 +65,25 @@ public:
private slots:
void stopConfigTest();
void processSshOutput(const QByteArray &output);
void handleConnected();
void handleConnectionError();
void handleInfoProcessFinished(int exitStatus);
void handleMadDeveloperTestProcessFinished(int exitStatus);
void handleTestProcessFinished(int exitStatus);
private:
void startConfigTest();
QString parseTestOutput();
void handleGeneralTestResult(int exitStatus);
void handleMadDeveloperTestResult(int exitStatus);
Ui_MaemoConfigTestDialog *m_ui;
QPushButton *m_closeButton;
const MaemoDeviceConfig &m_config;
QSharedPointer<Core::SshConnection> m_connection;
QSharedPointer<Core::SshRemoteProcess> m_infoProcess;
QSharedPointer<Core::SshRemoteProcess> m_madDeveloperTestProcess;
QSharedPointer<Core::SshRemoteProcessRunner> m_testProcessRunner;
QString m_deviceTestOutput;
bool m_qtVersionOk;
enum DeviceTest { GeneralTest, MadDeveloperTest };
DeviceTest m_currentTest;
};
} // namespace Internal
......
......@@ -40,8 +40,7 @@
#include "maemodeviceconfigurations.h"
#include "maemosshconfigdialog.h"
#include <coreplugin/ssh/sshconnection.h>
#include <coreplugin/ssh/sshremoteprocess.h>
#include <coreplugin/ssh/sshremoteprocessrunner.h>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
......@@ -354,32 +353,13 @@ void MaemoSettingsWidget::deployKey()
if (m_keyDeployer)
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_connection = SshConnection::create();
connect(m_connection.data(), SIGNAL(connected()), this,
SLOT(handleConnected()));
connect(m_connection.data(), SIGNAL(error(Core::SshError)), this,
SLOT(handleConnectionFailure()));
m_connection->connectToHost(currentConfig().server);
}
void MaemoSettingsWidget::handleConnected()
{
if (!m_connection)
return;
const QString &dir
= QFileInfo(currentConfig().server.privateKeyFile).path();
QString publicKeyFileName = QFileDialog::getOpenFileName(this,
tr("Choose Public Key File"), dir,
tr("Public Key Files(*.pub);;All Files (*)"));
if (publicKeyFileName.isEmpty()) {
stopDeploying();
if (publicKeyFileName.isEmpty())
return;
}
QFile keyFile(publicKeyFileName);
QByteArray key;
......@@ -389,26 +369,33 @@ void MaemoSettingsWidget::handleConnected()
if (!keyFileAccessible || keyFile.error() != QFile::NoError) {
QMessageBox::critical(this, tr("Deployment Failed"),
tr("Could not read public key file '%1'.").arg(publicKeyFileName));
stopDeploying();
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(currentConfig().server);
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";
m_keyDeployer = m_connection->createRemoteProcess(command);
connect(m_keyDeployer.data(), SIGNAL(closed(int)), this,
SLOT(handleKeyUploadFinished(int)));
m_keyDeployer->start();
m_keyDeployer->run(command);
}
void MaemoSettingsWidget::handleConnectionFailure()
{
if (!m_connection)
if (!m_keyDeployer)
return;
QMessageBox::critical(this, tr("Deployment Failed"),
tr("Could not connect to host: %1").arg(m_connection->errorString()));
tr("Could not connect to host: %1")
.arg(m_keyDeployer->connection()->errorString()));
stopDeploying();
}
......@@ -418,16 +405,17 @@ void MaemoSettingsWidget::handleKeyUploadFinished(int exitStatus)
|| exitStatus == SshRemoteProcess::KilledBySignal
|| exitStatus == SshRemoteProcess::ExitedNormally);
if (!m_connection)
if (!m_keyDeployer)
return;
if (exitStatus == SshRemoteProcess::ExitedNormally
&& m_keyDeployer->exitCode() == 0) {
&& 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->errorString()));
tr("Key deployment failed: %1.")
.arg(m_keyDeployer->process()->errorString()));
}
stopDeploying();
}
......@@ -436,10 +424,8 @@ void MaemoSettingsWidget::stopDeploying()
{
if (m_keyDeployer) {
disconnect(m_keyDeployer.data(), 0, this, 0);
m_keyDeployer = SshRemoteProcess::Ptr();
m_keyDeployer = SshRemoteProcessRunner::Ptr();
}
if (m_connection)
disconnect(m_connection.data(), 0, this, 0);
m_ui->deployKeyButton->disconnect();
m_ui->deployKeyButton->setText(tr("Deploy Public Key ..."));
connect(m_ui->deployKeyButton, SIGNAL(clicked()), this, SLOT(deployKey()));
......
......@@ -49,14 +49,12 @@ class Ui_MaemoSettingsWidget;
QT_END_NAMESPACE
namespace Core {
class SshConnection;
class SshRemoteProcess;
class SshRemoteProcessRunner;
}
namespace Qt4ProjectManager {
namespace Internal {
class MaemoSshRunner;
class NameValidator;
class MaemoSettingsWidget : public QWidget
......@@ -94,7 +92,6 @@ private slots:
// For key deploying.
void deployKey();
void stopDeploying();
void handleConnected();
void handleConnectionFailure();
void handleKeyUploadFinished(int exitStatus);
......@@ -112,8 +109,7 @@ private:
MaemoDeviceConfig m_lastConfigHW;
MaemoDeviceConfig m_lastConfigSim;
NameValidator * const m_nameValidator;
QSharedPointer<Core::SshConnection> m_connection;
QSharedPointer<Core::SshRemoteProcess> m_keyDeployer;
QSharedPointer<Core::SshRemoteProcessRunner> m_keyDeployer;
bool m_saveSettingsRequested;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment