2010-07-27 17:56:07 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
** All rights reserved.
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** This file is part of the 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$
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
#include "maemodeviceenvreader.h"
|
|
|
|
|
|
2010-09-13 16:50:30 +02:00
|
|
|
#include "maemoglobal.h"
|
2010-07-27 17:56:07 +02:00
|
|
|
#include "maemorunconfiguration.h"
|
|
|
|
|
|
2010-10-22 13:52:50 +02:00
|
|
|
#include <coreplugin/ssh/sshremoteprocessrunner.h>
|
2010-07-27 17:56:07 +02:00
|
|
|
|
|
|
|
|
namespace Qt4ProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
MaemoDeviceEnvReader::MaemoDeviceEnvReader(QObject *parent, MaemoRunConfiguration *config)
|
2010-07-27 17:56:07 +02:00
|
|
|
: QObject(parent)
|
|
|
|
|
, m_stop(false)
|
|
|
|
|
, m_devConfig(config->deviceConfig())
|
2010-10-06 15:11:46 +02:00
|
|
|
, m_runConfig(config)
|
2010-07-27 17:56:07 +02:00
|
|
|
{
|
2010-10-06 15:11:46 +02:00
|
|
|
connect(config, SIGNAL(deviceConfigurationChanged(ProjectExplorer::Target*)),
|
|
|
|
|
this, SLOT(handleCurrentDeviceConfigChanged()));
|
2010-07-27 17:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
MaemoDeviceEnvReader::~MaemoDeviceEnvReader()
|
2010-07-27 17:56:07 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoDeviceEnvReader::start()
|
2010-07-27 17:56:07 +02:00
|
|
|
{
|
|
|
|
|
m_stop = false;
|
2010-10-22 13:52:50 +02:00
|
|
|
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,
|
2010-07-27 17:56:07 +02:00
|
|
|
SLOT(handleConnectionFailure()));
|
2010-10-22 13:52:50 +02:00
|
|
|
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);
|
2010-07-27 17:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoDeviceEnvReader::stop()
|
2010-07-27 17:56:07 +02:00
|
|
|
{
|
|
|
|
|
m_stop = true;
|
2010-10-22 13:52:50 +02:00
|
|
|
if (m_remoteProcessRunner)
|
|
|
|
|
disconnect(m_remoteProcessRunner.data(), 0, this, 0);
|
2010-07-27 17:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
2010-10-22 13:52:50 +02:00
|
|
|
void MaemoDeviceEnvReader::handleConnectionFailure()
|
2010-07-27 17:56:07 +02:00
|
|
|
{
|
|
|
|
|
if (m_stop)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-10-22 13:52:50 +02:00
|
|
|
disconnect(m_remoteProcessRunner.data(), 0, this, 0);
|
|
|
|
|
emit error(tr("Connection error: %1")
|
|
|
|
|
.arg(m_remoteProcessRunner->connection()->errorString()));
|
|
|
|
|
emit finished();
|
2010-07-27 17:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
2010-10-06 15:11:46 +02:00
|
|
|
void MaemoDeviceEnvReader::handleCurrentDeviceConfigChanged()
|
|
|
|
|
{
|
|
|
|
|
m_devConfig = m_runConfig->deviceConfig();
|
|
|
|
|
|
2010-10-22 13:52:50 +02:00
|
|
|
disconnect(m_remoteProcessRunner.data(), 0, this, 0);
|
2010-10-06 15:11:46 +02:00
|
|
|
m_env.clear();
|
2010-10-13 11:04:24 +02:00
|
|
|
setFinished();
|
2010-10-06 15:11:46 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoDeviceEnvReader::remoteProcessFinished(int exitCode)
|
2010-07-27 17:56:07 +02:00
|
|
|
{
|
|
|
|
|
Q_ASSERT(exitCode == Core::SshRemoteProcess::FailedToStart
|
|
|
|
|
|| exitCode == Core::SshRemoteProcess::KilledBySignal
|
|
|
|
|
|| exitCode == Core::SshRemoteProcess::ExitedNormally);
|
|
|
|
|
|
|
|
|
|
if (m_stop)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-10-22 13:52:50 +02:00
|
|
|
disconnect(m_remoteProcessRunner.data(), 0, this, 0);
|
2010-10-06 15:11:46 +02:00
|
|
|
m_env.clear();
|
2010-07-27 17:56:07 +02:00
|
|
|
if (exitCode == Core::SshRemoteProcess::ExitedNormally) {
|
2010-10-06 15:11:46 +02:00
|
|
|
if (!m_remoteOutput.isEmpty()) {
|
|
|
|
|
m_env = Utils::Environment(m_remoteOutput.split(QLatin1Char('\n'),
|
|
|
|
|
QString::SkipEmptyParts));
|
|
|
|
|
}
|
2010-07-27 17:56:07 +02:00
|
|
|
} else {
|
2010-10-13 11:04:24 +02:00
|
|
|
QString errorMsg = tr("Error running remote process: %1")
|
2010-10-22 13:52:50 +02:00
|
|
|
.arg(m_remoteProcessRunner->process()->errorString());
|
2010-10-13 11:04:24 +02:00
|
|
|
if (!m_remoteErrorOutput.isEmpty()) {
|
|
|
|
|
errorMsg += tr("\nRemote stderr was: '%1'")
|
|
|
|
|
.arg(QString::fromUtf8(m_remoteErrorOutput));
|
|
|
|
|
}
|
|
|
|
|
emit error(errorMsg);
|
2010-07-27 17:56:07 +02:00
|
|
|
}
|
2010-10-13 11:04:24 +02:00
|
|
|
setFinished();
|
2010-07-27 17:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoDeviceEnvReader::remoteOutput(const QByteArray &data)
|
2010-07-27 17:56:07 +02:00
|
|
|
{
|
|
|
|
|
m_remoteOutput.append(QString::fromUtf8(data));
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoDeviceEnvReader::remoteErrorOutput(const QByteArray &data)
|
2010-07-27 17:56:07 +02:00
|
|
|
{
|
2010-10-13 11:04:24 +02:00
|
|
|
m_remoteErrorOutput += data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDeviceEnvReader::setFinished()
|
|
|
|
|
{
|
|
|
|
|
stop();
|
|
|
|
|
emit finished();
|
2010-07-27 17:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
2010-10-13 11:04:24 +02:00
|
|
|
} // Internal
|
2010-07-27 17:56:07 +02:00
|
|
|
} // Qt4ProjectManager
|