Commit a266e638 authored by ck's avatar ck
Browse files

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;
......
......@@ -42,10 +42,12 @@
#include <qt4projectmanager/qt4projectmanagerconstants.h>
#include "maemodeviceconfigurations.h"
#include "maemosshrunner.h"
#include "ui_maemosettingswidget.h"
#include "maemosettingspage.h"
#include <QtCore/QRegExp>
#include <QtGui/QIntValidator>
#include <algorithm>
......@@ -56,11 +58,11 @@ namespace Internal {
#define PAGE_ID "ZZ.Maemo Device Configurations"
#define PAGE_ID_TR "Maemo Device Configurations"
bool configNameExists(const QList<MaemoDeviceConfigurations::DeviceConfig> &devConfs,
bool configNameExists(const QList<MaemoDeviceConfig> &devConfs,
const QString &name)
{
return std::find_if(devConfs.constBegin(), devConfs.constEnd(),
MaemoDeviceConfigurations::DevConfNameMatcher(name)) != devConfs.constEnd();
DevConfNameMatcher(name)) != devConfs.constEnd();
}
class PortAndTimeoutValidator : public QIntValidator
......@@ -86,7 +88,7 @@ private:
class NameValidator : public QValidator
{
public:
NameValidator(const QList<MaemoDeviceConfigurations::DeviceConfig> &devConfs)
NameValidator(const QList<MaemoDeviceConfig> &devConfs)
: m_devConfs(devConfs)
{
}
......@@ -110,7 +112,7 @@ public:
private:
QString m_oldName;
const QList<MaemoDeviceConfigurations::DeviceConfig> &m_devConfs;
const QList<MaemoDeviceConfig> &m_devConfs;
};
......@@ -134,20 +136,31 @@ private slots:
void userNameEditingFinished();
void passwordEditingFinished();
void keyFileEditingFinished();
void testConfig();
void enableTestStop();
void processSshOutput(const QString &data);
void handleSshFinished();
void stopConfigTest();
private:
void initGui();
void display(const MaemoDeviceConfigurations::DeviceConfig &devConfig);
MaemoDeviceConfigurations::DeviceConfig &currentConfig();
void display(const MaemoDeviceConfig &devConfig);
MaemoDeviceConfig &currentConfig();
void setPortOrTimeout(const QLineEdit *lineEdit, int &confVal,
PortAndTimeoutValidator &validator);
void clearDetails();
QString parseTestOutput();
Ui_maemoSettingsWidget *m_ui;
QList<MaemoDeviceConfigurations::DeviceConfig> m_devConfs;
QList<MaemoDeviceConfig> m_devConfs;
PortAndTimeoutValidator m_portValidator;
PortAndTimeoutValidator m_timeoutValidator;
NameValidator m_nameValidator;
#ifdef USE_SSH_LIBS
MaemoSshRunner *m_deviceTester;
#endif
QString m_deviceTestOutput;
QString m_defaultTestOutput;
};
MaemoSettingsPage::MaemoSettingsPage(QObject *parent)
......@@ -200,6 +213,9 @@ MaemoSettingsWidget::MaemoSettingsWidget(QWidget *parent)
m_ui(new Ui_maemoSettingsWidget),
m_devConfs(MaemoDeviceConfigurations::instance().devConfigs()),
m_nameValidator(m_devConfs)
#ifdef USE_SSH_LIBS
, m_deviceTester(0)
#endif
{
initGui();
......@@ -216,11 +232,13 @@ void MaemoSettingsWidget::initGui()
m_ui->portLineEdit->setValidator(&m_portValidator);
m_ui->timeoutLineEdit->setValidator(&m_timeoutValidator);
m_ui->keyFileLineEdit->setExpectedKind(Utils::PathChooser::File);
foreach(const MaemoDeviceConfigurations::DeviceConfig &devConf, m_devConfs)
foreach(const MaemoDeviceConfig &devConf, m_devConfs)
m_ui->configListWidget->addItem(devConf.name);
m_defaultTestOutput = m_ui->testResultEdit->toPlainText();
#if 1 // Password authentication does not currently work due to ssh/scp issues.
#ifndef USE_SSH_LIB // Password authentication does not currently work due to ssh/scp issues.
m_ui->testConfigButton->hide();
m_ui->testResultEdit->hide();
m_ui->authTypeLabel->hide();
m_ui->authTypeButtonsWidget->hide();
m_ui->passwordLabel->hide();
......@@ -239,7 +257,7 @@ void MaemoSettingsWidget::addConfig()
isUnique = !configNameExists(m_devConfs, newName);
} while (!isUnique);
m_devConfs.append(MaemoDeviceConfigurations::DeviceConfig(newName));
m_devConfs.append(MaemoDeviceConfig(newName));
m_ui->configListWidget->addItem(newName);
m_ui->configListWidget->setCurrentRow(m_ui->configListWidget->count() - 1);
m_ui->nameLineEdit->selectAll();
......@@ -264,14 +282,14 @@ void MaemoSettingsWidget::deleteConfig()
selectionChanged();
}
void MaemoSettingsWidget::display(const MaemoDeviceConfigurations::DeviceConfig &devConfig)
void MaemoSettingsWidget::display(const MaemoDeviceConfig &devConfig)
{
m_ui->nameLineEdit->setText(devConfig.name);
if (devConfig.type == MaemoDeviceConfigurations::DeviceConfig::Physical)
if (devConfig.type == MaemoDeviceConfig::Physical)
m_ui->deviceButton->setChecked(true);
else
m_ui->simulatorButton->setChecked(true);
if (devConfig.authentication == MaemoDeviceConfigurations::DeviceConfig::Password)
if (devConfig.authentication == MaemoDeviceConfig::Password)
m_ui->passwordButton->setChecked(true);
else
m_ui->keyButton->setChecked(true);
......@@ -293,7 +311,7 @@ void MaemoSettingsWidget::saveSettings()
MaemoDeviceConfigurations::instance().setDevConfigs(m_devConfs);
}
MaemoDeviceConfigurations::DeviceConfig &MaemoSettingsWidget::currentConfig()
MaemoDeviceConfig &MaemoSettingsWidget::currentConfig()
{
Q_ASSERT(m_ui->configListWidget->count() == m_devConfs.count());
const QList<QListWidgetItem *> &selectedItems =
......@@ -316,16 +334,16 @@ void MaemoSettingsWidget::deviceTypeChanged()
{
currentConfig().type =
m_ui->deviceButton->isChecked()
? MaemoDeviceConfigurations::DeviceConfig::Physical
: MaemoDeviceConfigurations::DeviceConfig::Simulator;
? MaemoDeviceConfig::Physical
: MaemoDeviceConfig::Simulator;
}
void MaemoSettingsWidget::authenticationTypeChanged()
{
const bool usePassword = m_ui->passwordButton->isChecked();
currentConfig().authentication = usePassword
? MaemoDeviceConfigurations::DeviceConfig::Password
: MaemoDeviceConfigurations::DeviceConfig::Key;
? MaemoDeviceConfig::Password
: MaemoDeviceConfig::Key;
m_ui->pwdLineEdit->setEnabled(usePassword);
m_ui->passwordLabel->setEnabled(usePassword);
m_ui->keyFileLineEdit->setEnabled(!usePassword);
......@@ -372,17 +390,129 @@ void MaemoSettingsWidget::keyFileEditingFinished()
currentConfig().keyFile = m_ui->keyFileLineEdit->path();
}
void MaemoSettingsWidget::testConfig()
{
#ifdef USE_SSH_LIBS
qDebug("Oh yes, this config will be tested!");
if (m_deviceTester)
return;
m_ui->testResultEdit->setPlainText(m_defaultTestOutput);
QLatin1String sysInfoCmd("uname -rsm");
QLatin1String qtInfoCmd("dpkg -l |grep libqt "
"|sed 's/[[:space:]][[:space:]]*/ /g' "
"|cut -d ' ' -f 2,3 |sed 's/~.*//g'");
QString command(sysInfoCmd + " && " + qtInfoCmd);
m_deviceTester = new MaemoSshRunner(currentConfig(), command);
connect(m_deviceTester, SIGNAL(connectionEstablished()),
this, SLOT(enableTestStop()));
connect(m_deviceTester, SIGNAL(remoteOutput(QString)),
this, SLOT(processSshOutput(QString)));
connect(m_deviceTester, SIGNAL(finished()),
this, SLOT(handleSshFinished()));
m_deviceTester->start();
#endif
}
void MaemoSettingsWidget::enableTestStop()
{
m_ui->testConfigButton->disconnect();
m_ui->testConfigButton->setText(tr("Stop test"));
connect(m_ui->testConfigButton, SIGNAL(clicked()),
this, SLOT(stopConfigTest()));
}
void MaemoSettingsWidget::processSshOutput(const QString &data)
{
qDebug("%s", qPrintable(data));
m_deviceTestOutput.append(data);
}
void MaemoSettingsWidget::handleSshFinished()
{
#ifdef USE_SSH_LIBS
qDebug("================> %s", Q_FUNC_INFO);
if (!m_deviceTester)
return;
QString output;
if (m_deviceTester->hasError()) {
output = tr("Device configuration test failed:\n");
output.append(m_deviceTester->error());
} else {
output = parseTestOutput();
}
m_ui->testResultEdit->setPlainText(output);
stopConfigTest();
#endif
}
void MaemoSettingsWidget::stopConfigTest()
{
#ifdef USE_SSH_LIBS
qDebug("================> %s", Q_FUNC_INFO);
if (m_deviceTester) {
qDebug("Actually doing something");
m_deviceTester->disconnect();
const bool buttonWasEnabled = m_ui->testConfigButton->isEnabled();
m_ui->testConfigButton->setEnabled(false);
m_deviceTester->stop();
delete m_deviceTester;
m_deviceTester = 0;
m_deviceTestOutput.clear();
m_ui->testConfigButton->setText(tr("Test"));
m_ui->testConfigButton->disconnect();
connect(m_ui->testConfigButton, SIGNAL(clicked()),
this, SLOT(testConfig()));
m_ui->testConfigButton->setEnabled(buttonWasEnabled);
}
#endif
}
QString MaemoSettingsWidget::parseTestOutput()
{
QString output;
const QRegExp unamePattern(QLatin1String("Linux (\\S+)\\s(\\S+)"));
int index = unamePattern.indexIn(m_deviceTestOutput);
if (index == -1) {
output = tr("Device configuration test failed: Unexpected output:\n");
output.append(m_deviceTestOutput);
return output;
}
output = tr("Hardware architecture: %1\n").arg(unamePattern.cap(2));
output.append(tr("Kernel version: %1\n").arg(unamePattern.cap(1)));
output.prepend(tr("Device configuration successful.\n"));
const QRegExp dkpgPattern(QLatin1String("libqt\\S+ \\d\\.\\d\\.\\d"));
index = dkpgPattern.indexIn(m_deviceTestOutput);
if (index == -1) {
output.append("No Qt packages installed.");
return output;
}
output.append("List of installed Qt packages:\n");
do {
output.append(QLatin1String("\t") + dkpgPattern.cap(0)
+ QLatin1String("\n"));