Commit 83255c08 authored by Christian Kandeler's avatar Christian Kandeler
Browse files

Maemo: Use new SSH convenience class for fetching device environment.

parent ee53546d
......@@ -37,8 +37,7 @@
#include "maemoglobal.h"
#include "maemorunconfiguration.h"
#include <coreplugin/ssh/sshconnection.h>
#include <coreplugin/ssh/sshremoteprocess.h>
#include <coreplugin/ssh/sshremoteprocessrunner.h>
namespace Qt4ProjectManager {
namespace Internal {
......@@ -60,71 +59,52 @@ MaemoDeviceEnvReader::~MaemoDeviceEnvReader()
void MaemoDeviceEnvReader::start()
{
m_stop = false;
if (m_connection)
disconnect(m_connection.data(), 0, this, 0);
const bool reuse = m_connection
&& m_connection->state() == Core::SshConnection::Connected
&& m_connection->connectionParameters() == m_devConfig.server;
if (!reuse)
m_connection = Core::SshConnection::create();
connect(m_connection.data(), SIGNAL(connected()), this,
SLOT(executeRemoteCall()));
connect(m_connection.data(), SIGNAL(error(Core::SshError)), this,
if (!m_remoteProcessRunner
|| m_remoteProcessRunner->connection()->state() != Core::SshConnection::Connected
|| m_remoteProcessRunner->connection()->connectionParameters() != m_devConfig.server) {
m_remoteProcessRunner
= Core::SshRemoteProcessRunner::create(m_devConfig.server);
}
connect(m_remoteProcessRunner.data(),
SIGNAL(connectionError(Core::SshError)), this,
SLOT(handleConnectionFailure()));
if (reuse)
executeRemoteCall();
else
m_connection->connectToHost(m_devConfig.server);
connect(m_remoteProcessRunner.data(), SIGNAL(processClosed(int)), this,
SLOT(remoteProcessFinished(int)));
connect(m_remoteProcessRunner.data(),
SIGNAL(processOutputAvailable(QByteArray)), this,
SLOT(remoteOutput(QByteArray)));
connect(m_remoteProcessRunner.data(),
SIGNAL(processErrorOutputAvailable(QByteArray)), this,
SLOT(remoteErrorOutput(QByteArray)));
const QByteArray remoteCall = MaemoGlobal::remoteSourceProfilesCommand()
.toUtf8() + "; env";
m_remoteOutput.clear();
m_remoteProcessRunner->run(remoteCall);
}
void MaemoDeviceEnvReader::stop()
{
m_stop = true;
if (m_connection)
disconnect(m_connection.data(), 0, this, 0);
if (m_remoteProcess) {
disconnect(m_remoteProcess.data());
m_remoteProcess->closeChannel();
}
if (m_remoteProcessRunner)
disconnect(m_remoteProcessRunner.data(), 0, this, 0);
}
void MaemoDeviceEnvReader::executeRemoteCall()
void MaemoDeviceEnvReader::handleConnectionFailure()
{
if (m_stop)
return;
const QByteArray remoteCall = MaemoGlobal::remoteSourceProfilesCommand()
.toUtf8() + "; env";
m_remoteProcess = m_connection->createRemoteProcess(remoteCall);
connect(m_remoteProcess.data(), SIGNAL(closed(int)), this,
SLOT(remoteProcessFinished(int)));
connect(m_remoteProcess.data(), SIGNAL(outputAvailable(QByteArray)), this,
SLOT(remoteOutput(QByteArray)));
connect(m_remoteProcess.data(), SIGNAL(errorOutputAvailable(QByteArray)), this,
SLOT(remoteErrorOutput(QByteArray)));
m_remoteOutput.clear();
m_remoteErrorOutput.clear();
m_remoteProcess->start();
}
void MaemoDeviceEnvReader::handleConnectionFailure()
{
emit error(tr("Could not connect to host: %1")
.arg(m_connection->errorString()));
setFinished();
disconnect(m_remoteProcessRunner.data(), 0, this, 0);
emit error(tr("Connection error: %1")
.arg(m_remoteProcessRunner->connection()->errorString()));
emit finished();
}
void MaemoDeviceEnvReader::handleCurrentDeviceConfigChanged()
{
m_devConfig = m_runConfig->deviceConfig();
disconnect(m_remoteProcessRunner.data(), 0, this, 0);
m_env.clear();
setFinished();
}
......@@ -138,6 +118,7 @@ void MaemoDeviceEnvReader::remoteProcessFinished(int exitCode)
if (m_stop)
return;
disconnect(m_remoteProcessRunner.data(), 0, this, 0);
m_env.clear();
if (exitCode == Core::SshRemoteProcess::ExitedNormally) {
if (!m_remoteOutput.isEmpty()) {
......@@ -146,7 +127,7 @@ void MaemoDeviceEnvReader::remoteProcessFinished(int exitCode)
}
} else {
QString errorMsg = tr("Error running remote process: %1")
.arg(m_remoteProcess->errorString());
.arg(m_remoteProcessRunner->process()->errorString());
if (!m_remoteErrorOutput.isEmpty()) {
errorMsg += tr("\nRemote stderr was: '%1'")
.arg(QString::fromUtf8(m_remoteErrorOutput));
......
......@@ -42,8 +42,7 @@
#include <QtCore/QObject>
namespace Core {
class SshConnection;
class SshRemoteProcess;
class SshRemoteProcessRunner;
}
namespace Qt4ProjectManager {
......@@ -68,7 +67,6 @@ signals:
void error(const QString &error);
private slots:
void executeRemoteCall();
void handleConnectionFailure();
void handleCurrentDeviceConfigChanged();
......@@ -85,8 +83,7 @@ private:
Utils::Environment m_env;
MaemoDeviceConfig m_devConfig;
MaemoRunConfiguration *m_runConfig;
QSharedPointer<Core::SshConnection> m_connection;
QSharedPointer<Core::SshRemoteProcess> m_remoteProcess;
QSharedPointer<Core::SshRemoteProcessRunner> m_remoteProcessRunner;
};
} // Internal
......
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