Commit a266e638 authored by ck's avatar ck

Maemo: Add interface for ssh library (completely #ifdef'ed out for now).

This will replace the current ssh-via-QProcess approach, which
has severe drawbacks.
parent 1c1394c1
......@@ -68,7 +68,7 @@ class DevConfIdMatcher
{
public:
DevConfIdMatcher(quint64 id) : m_id(id) {}
bool operator()(const MaemoDeviceConfigurations::DeviceConfig &devConfig)
bool operator()(const MaemoDeviceConfig &devConfig)
{
return devConfig.internalId == m_id;
}
......@@ -76,7 +76,7 @@ private:
const quint64 m_id;
};
MaemoDeviceConfigurations::DeviceConfig::DeviceConfig(const QString &name)
MaemoDeviceConfig::MaemoDeviceConfig(const QString &name)
: name(name),
type(Physical),
port(22),
......@@ -87,8 +87,8 @@ MaemoDeviceConfigurations::DeviceConfig::DeviceConfig(const QString &name)
{
}
MaemoDeviceConfigurations::DeviceConfig::DeviceConfig(const QSettings &settings,
quint64 &nextId)
MaemoDeviceConfig::MaemoDeviceConfig(const QSettings &settings,
quint64 &nextId)
: name(settings.value(NameKey).toString()),
type(static_cast<DeviceType>(settings.value(TypeKey, Physical).toInt())),
host(settings.value(HostKey).toString()),
......@@ -104,17 +104,17 @@ MaemoDeviceConfigurations::DeviceConfig::DeviceConfig(const QSettings &settings,
++nextId;
}
MaemoDeviceConfigurations::DeviceConfig::DeviceConfig()
MaemoDeviceConfig::MaemoDeviceConfig()
: internalId(InvalidId)
{
}
bool MaemoDeviceConfigurations::DeviceConfig::isValid() const
bool MaemoDeviceConfig::isValid() const
{
return internalId != InvalidId;
}
void MaemoDeviceConfigurations::DeviceConfig::save(QSettings &settings) const
void MaemoDeviceConfig::save(QSettings &settings) const
{
settings.setValue(NameKey, name);
settings.setValue(TypeKey, type);
......@@ -128,7 +128,7 @@ void MaemoDeviceConfigurations::DeviceConfig::save(QSettings &settings) const
settings.setValue(InternalIdKey, internalId);
}
void MaemoDeviceConfigurations::setDevConfigs(const QList<DeviceConfig> &devConfigs)
void MaemoDeviceConfigurations::setDevConfigs(const QList<MaemoDeviceConfig> &devConfigs)
{
m_devConfigs = devConfigs;
save();
......@@ -162,7 +162,6 @@ MaemoDeviceConfigurations::MaemoDeviceConfigurations(QObject *parent)
load();
}
void MaemoDeviceConfigurations::load()
{
QSettings *settings = Core::ICore::instance()->settings();
......@@ -171,26 +170,26 @@ void MaemoDeviceConfigurations::load()
int count = settings->beginReadArray(ConfigListKey);
for (int i = 0; i < count; ++i) {
settings->setArrayIndex(i);
m_devConfigs.append(DeviceConfig(*settings, m_nextId));
m_devConfigs.append(MaemoDeviceConfig(*settings, m_nextId));
}
settings->endArray();
settings->endGroup();
}
MaemoDeviceConfigurations::DeviceConfig MaemoDeviceConfigurations::find(const QString &name) const
MaemoDeviceConfig MaemoDeviceConfigurations::find(const QString &name) const
{
QList<DeviceConfig>::ConstIterator resultIt =
QList<MaemoDeviceConfig>::ConstIterator resultIt =
std::find_if(m_devConfigs.constBegin(), m_devConfigs.constEnd(),
DevConfNameMatcher(name));
return resultIt == m_devConfigs.constEnd() ? DeviceConfig() : *resultIt;
return resultIt == m_devConfigs.constEnd() ? MaemoDeviceConfig() : *resultIt;
}
MaemoDeviceConfigurations::DeviceConfig MaemoDeviceConfigurations::find(int id) const
MaemoDeviceConfig MaemoDeviceConfigurations::find(int id) const
{
QList<DeviceConfig>::ConstIterator resultIt =
QList<MaemoDeviceConfig>::ConstIterator resultIt =
std::find_if(m_devConfigs.constBegin(), m_devConfigs.constEnd(),
DevConfIdMatcher(id));
return resultIt == m_devConfigs.constEnd() ? DeviceConfig() : *resultIt;
return resultIt == m_devConfigs.constEnd() ? MaemoDeviceConfig() : *resultIt;
}
MaemoDeviceConfigurations *MaemoDeviceConfigurations::m_instance = 0;
......
......@@ -47,53 +47,55 @@ QT_END_NAMESPACE
namespace Qt4ProjectManager {
namespace Internal {
class MaemoDeviceConfigurations : public QObject
class MaemoDeviceConfig
{
Q_OBJECT
Q_DISABLE_COPY(MaemoDeviceConfigurations)
public:
class DeviceConfig
{
public:
enum DeviceType { Physical, Simulator };
enum AuthType { Password, Key };
DeviceConfig();
DeviceConfig(const QString &name);
DeviceConfig(const QSettings &settings, quint64 &nextId);
void save(QSettings &settings) const;
bool isValid() const;
QString name;
DeviceType type;
QString host;
int port;
QString uname;
AuthType authentication;
QString pwd;
QString keyFile;
int timeout;
quint64 internalId;
enum DeviceType { Physical, Simulator };
enum AuthType { Password, Key };
MaemoDeviceConfig();
MaemoDeviceConfig(const QString &name);
MaemoDeviceConfig(const QSettings &settings, quint64 &nextId);
void save(QSettings &settings) const;
bool isValid() const;
QString name;
DeviceType type;
QString host;
int port;
QString uname;
AuthType authentication;
QString pwd;
QString keyFile;
int timeout;
quint64 internalId;
private:
static const quint64 InvalidId = 0;
};
private:
static const quint64 InvalidId = 0;
};
class DevConfNameMatcher
class DevConfNameMatcher
{
public:
DevConfNameMatcher(const QString &name) : m_name(name) {}
bool operator()(const MaemoDeviceConfig &devConfig)
{
public:
DevConfNameMatcher(const QString &name) : m_name(name) {}
bool operator()(const MaemoDeviceConfigurations::DeviceConfig &devConfig)
{
return devConfig.name == m_name;
}
private:
const QString m_name;
};
return devConfig.name == m_name;
}
private:
const QString m_name;
};
class MaemoDeviceConfigurations : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(MaemoDeviceConfigurations)
public:
static MaemoDeviceConfigurations &instance(QObject *parent = 0);
QList<DeviceConfig> devConfigs() const { return m_devConfigs; }
void setDevConfigs(const QList<DeviceConfig> &devConfigs);
DeviceConfig find(const QString &name) const;
DeviceConfig find(int id) const;
QList<MaemoDeviceConfig> devConfigs() const { return m_devConfigs; }
void setDevConfigs(const QList<MaemoDeviceConfig> &devConfigs);
MaemoDeviceConfig find(const QString &name) const;
MaemoDeviceConfig find(int id) const;
signals:
void updated();
......@@ -104,9 +106,9 @@ private:
void save();
static MaemoDeviceConfigurations *m_instance;
QList<DeviceConfig> m_devConfigs;
QList<MaemoDeviceConfig> m_devConfigs;
quint64 m_nextId;
friend class MaemoDeviceConfigurations::DeviceConfig;
friend class MaemoDeviceConfig;
};
} // namespace Internal
......
......@@ -88,7 +88,7 @@ private slots:
void updateTargetInformation();
private:
void setSimInfoVisible(const MaemoDeviceConfigurations::DeviceConfig &devConf);
void setSimInfoVisible(const MaemoDeviceConfig &devConf);
QLineEdit *m_configNameLineEdit;
QLineEdit *m_argsLineEdit;
......@@ -130,7 +130,7 @@ private slots:
protected:
ErrorDumper dumper;
MaemoRunConfiguration *runConfig; // TODO this pointer can be invalid
const MaemoDeviceConfigurations::DeviceConfig devConfig;
const MaemoDeviceConfig devConfig;
private:
virtual void handleDeploymentFinished(bool success)=0;
......@@ -399,13 +399,12 @@ bool MaemoRunConfiguration::fileNeedsDeployment(const QString &path,
|| QFileInfo(path).lastModified() > lastDeployed;
}
void MaemoRunConfiguration::setDeviceConfig(
const MaemoDeviceConfigurations::DeviceConfig &devConf)
void MaemoRunConfiguration::setDeviceConfig(const MaemoDeviceConfig &devConf)
{
m_devConfig = devConf;
}
MaemoDeviceConfigurations::DeviceConfig MaemoRunConfiguration::deviceConfig() const
MaemoDeviceConfig MaemoRunConfiguration::deviceConfig() const
{
return m_devConfig;
}
......@@ -774,17 +773,15 @@ void MaemoRunConfigurationWidget::updateSimulatorPath()
void MaemoRunConfigurationWidget::deviceConfigurationChanged(const QString &name)
{
const MaemoDeviceConfigurations::DeviceConfig &devConfig =
MaemoDeviceConfigurations::instance().find(name);
const MaemoDeviceConfig &devConfig
= MaemoDeviceConfigurations::instance().find(name);
setSimInfoVisible(devConfig);
m_runConfiguration->setDeviceConfig(devConfig);
}
void MaemoRunConfigurationWidget::setSimInfoVisible(
const MaemoDeviceConfigurations::DeviceConfig &devConf)
void MaemoRunConfigurationWidget::setSimInfoVisible(const MaemoDeviceConfig &devConf)
{
const bool isSimulator =
devConf.type == MaemoDeviceConfigurations::DeviceConfig::Simulator;
const bool isSimulator = devConf.type == MaemoDeviceConfig::Simulator;
m_simPathNameLabel->setVisible(isSimulator);
m_simPathValueLabel->setVisible(isSimulator);
}
......@@ -792,13 +789,12 @@ void MaemoRunConfigurationWidget::setSimInfoVisible(
void MaemoRunConfigurationWidget::resetDeviceConfigurations()
{
m_devConfBox->clear();
const QList<MaemoDeviceConfigurations::DeviceConfig> &devConfs =
const QList<MaemoDeviceConfig> &devConfs =
MaemoDeviceConfigurations::instance().devConfigs();
foreach (const MaemoDeviceConfigurations::DeviceConfig &devConf, devConfs)
foreach (const MaemoDeviceConfig &devConf, devConfs)
m_devConfBox->addItem(devConf.name);
m_devConfBox->addItem(MaemoDeviceConfigurations::DeviceConfig().name);
const MaemoDeviceConfigurations::DeviceConfig &devConf =
m_runConfiguration->deviceConfig();
m_devConfBox->addItem(MaemoDeviceConfig().name);
const MaemoDeviceConfig &devConf = m_runConfiguration->deviceConfig();
m_devConfBox->setCurrentIndex(m_devConfBox->findText(devConf.name));
setSimInfoVisible(devConf);
}
......@@ -992,8 +988,7 @@ QWidget* MaemoRunControlFactory::configurationWidget(RunConfiguration *config)
AbstractMaemoRunControl::AbstractMaemoRunControl(RunConfiguration *rc)
: RunControl(rc)
, runConfig(qobject_cast<MaemoRunConfiguration *>(rc))
, devConfig(runConfig ? runConfig->deviceConfig()
: MaemoDeviceConfigurations::DeviceConfig())
, devConfig(runConfig ? runConfig->deviceConfig() : MaemoDeviceConfig())
{
setProcessEnvironment(deployProcess);
......@@ -1117,8 +1112,8 @@ const QString AbstractMaemoRunControl::remoteDir() const
const QStringList AbstractMaemoRunControl::options() const
{
const bool usePassword =
devConfig.authentication == MaemoDeviceConfigurations::DeviceConfig::Password;
const bool usePassword
= devConfig.authentication == MaemoDeviceConfig::Password;
const QLatin1String opt("-o");
QStringList optionList;
if (!usePassword)
......
......@@ -91,8 +91,8 @@ public:
const QString sysRoot() const;
const QStringList arguments() const;
void setArguments(const QStringList &args);
void setDeviceConfig(const MaemoDeviceConfigurations::DeviceConfig &deviceConfig);
MaemoDeviceConfigurations::DeviceConfig deviceConfig() const;
void setDeviceConfig(const MaemoDeviceConfig &deviceConfig);
MaemoDeviceConfig deviceConfig() const;
QString simulator() const;
QString simulatorArgs() const;
......@@ -158,7 +158,7 @@ private:
QString m_gdbPath;
MaemoDeviceConfigurations::DeviceConfig m_devConfig;
MaemoDeviceConfig m_devConfig;
QStringList m_arguments;
QDateTime m_lastDeployed;
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>515</width>
<height>387</height>
<height>487</height>
</rect>
</property>
<property name="windowTitle">
......@@ -32,6 +32,9 @@
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
......@@ -175,6 +178,20 @@
</layout>
</widget>
</item>
<item>
<widget class="QTextEdit" name="testResultEdit">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;No current test results available.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
......@@ -197,6 +214,16 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="testConfigButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Test</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
......@@ -427,8 +454,8 @@
<slot>keyFileEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>268</x>
<y>337</y>
<x>150</x>
<y>357</y>
</hint>
<hint type="destinationlabel">
<x>257</x>
......@@ -443,8 +470,8 @@
<slot>keyFileEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>268</x>
<y>337</y>
<x>150</x>
<y>357</y>
</hint>
<hint type="destinationlabel">
<x>257</x>
......@@ -452,6 +479,22 @@
</hint>
</hints>
</connection>
<connection>
<sender>testConfigButton</sender>
<signal>clicked()</signal>
<receiver>maemoSettingsWidget</receiver>
<slot>testConfig()</slot>
<hints>
<hint type="sourcelabel">
<x>450</x>
<y>96</y>
</hint>
<hint type="destinationlabel">
<x>428</x>
<y>367</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>configNameEditingFinished()</slot>
......@@ -466,5 +509,6 @@
<slot>deleteConfig()</slot>
<slot>authenticationTypeChanged()</slot>
<slot>keyFileEditingFinished()</slot>
<slot>testConfig()</slot>
</slots>
</ui>
/****************************************************************************
**
** Copyright (C) 2009 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$
**
****************************************************************************/
#include "maemosshconnection.h"
#ifdef USE_SSH_LIB
#include "maemodeviceconfigurations.h"
#include "/opt/ne7ssh/include/ne7ssh.h"
#include <QtCore/QMutex>
#include <QtCore/QMutexLocker>
namespace Qt4ProjectManager {
namespace Internal {
namespace {
ne7ssh ssh;
}
MaemoSshConnection::Ptr MaemoSshConnection::connect(
const MaemoDeviceConfig &devConf, bool shell)
{
return MaemoSshConnection::Ptr(new MaemoSshConnection(devConf, shell));
}
MaemoSshConnection::MaemoSshConnection(const MaemoDeviceConfig &devConf,
bool shell)
: m_channel(-1), m_prompt(0), m_stopRequested(false)
{
const QString *authString;
int (ne7ssh::*connFunc)(const char *, int, const char *, const char *, bool, int);
if (devConf.authentication == MaemoDeviceConfig::Password) {
authString = &devConf.pwd;
connFunc = &ne7ssh::connectWithPassword;
} else {
authString = &devConf.keyFile;
connFunc = &ne7ssh::connectWithKey;
}
m_channel = (ssh.*connFunc)(devConf.host.toAscii(), devConf.port,
devConf.uname.toAscii(), authString->toAscii(), shell, devConf.timeout);
if (m_channel == -1)
throw MaemoSshException(tr("Could not connect to host"));
if (shell) {
m_prompt = devConf.uname == QLatin1String("root") ? "# " : "$ ";
if (!ssh.waitFor(m_channel, m_prompt, devConf.timeout)) {
const QString error = tr("Could not start remote shell: %1").
arg(ssh.errors()->pop(m_channel));
ssh.close(m_channel);
throw MaemoSshException(error);
}
}
}
MaemoSshConnection::~MaemoSshConnection()
{
qDebug("%s", Q_FUNC_INFO);
if (m_prompt) {
ssh.send("exit\n", m_channel);
ssh.waitFor(m_channel, m_prompt, 1);
}
ssh.close(m_channel);
}
void MaemoSshConnection::runCommand(const QString &command)
{
if (!ssh.send((command + QLatin1String("\n")).toLatin1().data(),
m_channel)) {
throw MaemoSshException(tr("Error running command: %1")
.arg(ssh.errors()->pop(m_channel)));
}
bool done;
do {
done = ssh.waitFor(m_channel, m_prompt, 3);
const char * const error = ssh.errors()->pop(m_channel);
if (error)
throw MaemoSshException(tr("SSH error: %1").arg(error));
const char * const output = ssh.read(m_channel);
if (output)
emit remoteOutput(QLatin1String(output));
} while (!done && !m_stopRequested);
}
void MaemoSshConnection::stopCommand()
{
m_stopRequested = true;
}
} // namespace Internal
} // namespace Qt4ProjectManager
#endif
/****************************************************************************
**
** Copyright (C) 2009 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$
**
****************************************************************************/
#ifndef MAEMOSSHCONNECTION_H
#define MAEMOSSHCONNECTION_H
#ifdef USE_SSH_LIB
#include <QtCore/QCoreApplication>
#include <QtCore/QScopedPointer>
#include <QtCore/QSharedPointer>
class ne7ssh;
namespace Qt4ProjectManager {
namespace Internal {
class MaemoDeviceConfig;
class MaemoSshException
{
public:
MaemoSshException(const QString &error) : m_error(error) {}
const QString &error() const { return m_error; }
private:
const QString m_error;
};
class MaemoSshConnection : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(MaemoSshConnection)
friend class MaemoSshFacility;
public:
typedef QSharedPointer<MaemoSshConnection> Ptr;
static Ptr connect(const MaemoDeviceConfig &devConf, bool shell);
void runCommand(const QString &command);
void stopCommand();
~MaemoSshConnection();
signals:
void remoteOutput(const QString &output);
private:
MaemoSshConnection(const MaemoDeviceConfig &devConf, bool shell);
int m_channel;
const char *m_prompt;
volatile bool m_stopRequested;
};
} // namespace Internal
} // namespace Qt4ProjectManager
#endif