Commit c5e00691 authored by Christian Kandeler's avatar Christian Kandeler
Browse files

Maemo: Use device configuration wizard.

Needs patch choosers instead of line edits.
parent c6431bb2
......@@ -216,12 +216,6 @@ QString MaemoPortList::toString() const
}
MaemoDeviceConfig::Ptr MaemoDeviceConfig::create(const QString &name,
MaemoGlobal::MaemoVersion osVersion, DeviceType type, Id &nextId)
{
return Ptr(new MaemoDeviceConfig(name, osVersion, type, nextId));
}
MaemoDeviceConfig::Ptr MaemoDeviceConfig::create(const QSettings &settings,
Id &nextId)
{
......@@ -233,9 +227,31 @@ MaemoDeviceConfig::Ptr MaemoDeviceConfig::create(const ConstPtr &other)
return Ptr(new MaemoDeviceConfig(other));
}
MaemoDeviceConfig::Ptr MaemoDeviceConfig::createHardwareConfig(const QString &name,
MaemoGlobal::MaemoVersion osVersion, const QString &hostName,
const QString privateKeyFilePath, Id &nextId)
{
Core::SshConnectionParameters sshParams(Core::SshConnectionParameters::NoProxy);
sshParams.authType = Core::SshConnectionParameters::AuthByKey;
sshParams.host = hostName;
sshParams.privateKeyFile = privateKeyFilePath;
return Ptr(new MaemoDeviceConfig(name, osVersion, Physical, sshParams, nextId));
}
MaemoDeviceConfig::Ptr MaemoDeviceConfig::createEmulatorConfig(const QString &name,
MaemoGlobal::MaemoVersion osVersion, Id &nextId)
{
Core::SshConnectionParameters sshParams(Core::SshConnectionParameters::NoProxy);
sshParams.authType = Core::SshConnectionParameters::AuthByPwd;
sshParams.host = defaultHost(Simulator);
sshParams.pwd = defaultQemuPassword(osVersion);
return Ptr(new MaemoDeviceConfig(name, osVersion, Simulator, sshParams, nextId));
}
MaemoDeviceConfig::MaemoDeviceConfig(const QString &name,
MaemoGlobal::MaemoVersion osVersion, DeviceType devType, Id &nextId)
: m_sshParameters(Core::SshConnectionParameters::NoProxy),
MaemoGlobal::MaemoVersion osVersion, DeviceType devType,
const Core::SshConnectionParameters &sshParams, Id &nextId)
: m_sshParameters(sshParams),
m_name(name),
m_osVersion(osVersion),
m_type(devType),
......@@ -243,12 +259,8 @@ MaemoDeviceConfig::MaemoDeviceConfig(const QString &name,
m_isDefault(false),
m_internalId(nextId++)
{
m_sshParameters.host = defaultHost(m_type);
m_sshParameters.port = defaultSshPort(m_type);
m_sshParameters.uname = defaultUser(m_osVersion);
m_sshParameters.authType = DefaultAuthType;
m_sshParameters.privateKeyFile
= MaemoDeviceConfigurations::instance()->defaultSshKeyFilePath();
m_sshParameters.timeout = DefaultTimeout;
}
......@@ -328,6 +340,20 @@ QString MaemoDeviceConfig::defaultUser(MaemoGlobal::MaemoVersion osVersion)
}
}
QString MaemoDeviceConfig::defaultQemuPassword(MaemoGlobal::MaemoVersion osVersion)
{
switch (osVersion) {
case MaemoGlobal::Maemo5:
case MaemoGlobal::Maemo6:
return QString();
case MaemoGlobal::Meego:
return QLatin1String("meego");
default:
Q_ASSERT(false);
return QString();
}
}
MaemoPortList MaemoDeviceConfig::freePorts() const
{
return PortsSpecParser(m_portsSpec).parse();
......@@ -390,7 +416,6 @@ void MaemoDeviceConfigurations::copy(const MaemoDeviceConfigurations *source,
}
target->m_defaultSshKeyFilePath = source->m_defaultSshKeyFilePath;
target->m_nextId = source->m_nextId;
target->initShadowDevConfs();
}
void MaemoDeviceConfigurations::save()
......@@ -408,45 +433,29 @@ void MaemoDeviceConfigurations::save()
settings->endGroup();
}
void MaemoDeviceConfigurations::initShadowDevConfs()
void MaemoDeviceConfigurations::addHardwareDeviceConfiguration(const QString &name,
MaemoGlobal::MaemoVersion osVersion, const QString &hostName,
const QString privateKeyFilePath)
{
m_shadowDevConfigs.clear();
for (int i = 0; i < m_devConfigs.count(); ++i)
m_shadowDevConfigs.push_back(MaemoDeviceConfig::Ptr());
const MaemoDeviceConfig::Ptr &devConf = MaemoDeviceConfig::createHardwareConfig(name,
osVersion, hostName, privateKeyFilePath, m_nextId);
addConfiguration(devConf);
}
void MaemoDeviceConfigurations::setupShadowDevConf(int idx)
void MaemoDeviceConfigurations::addEmulatorDeviceConfiguration(const QString &name,
MaemoGlobal::MaemoVersion osVersion)
{
MaemoDeviceConfig::Ptr shadowConf = m_shadowDevConfigs.at(idx);
if (shadowConf)
return;
const MaemoDeviceConfig::Ptr &devConf
= MaemoDeviceConfig::createEmulatorConfig(name, osVersion, m_nextId);
addConfiguration(devConf);
}
const MaemoDeviceConfig::Ptr devConf = m_devConfigs.at(idx);
const MaemoDeviceConfig::DeviceType shadowType
= devConf->type() == MaemoDeviceConfig::Physical
? MaemoDeviceConfig::Simulator : MaemoDeviceConfig::Physical;
shadowConf = MaemoDeviceConfig::create(devConf->name(),
devConf->osVersion(), shadowType, m_nextId);
shadowConf->m_sshParameters.authType = devConf->m_sshParameters.authType;
shadowConf->m_sshParameters.timeout = devConf->m_sshParameters.timeout;
shadowConf->m_sshParameters.pwd = devConf->m_sshParameters.pwd;
shadowConf->m_sshParameters.privateKeyFile
= devConf->m_sshParameters.privateKeyFile;
shadowConf->m_isDefault = devConf->m_isDefault;
shadowConf->m_internalId = devConf->m_internalId;
m_shadowDevConfigs[idx] = shadowConf;
}
void MaemoDeviceConfigurations::addConfiguration(const QString &name,
MaemoGlobal::MaemoVersion osVersion, MaemoDeviceConfig::DeviceType type)
void MaemoDeviceConfigurations::addConfiguration(const MaemoDeviceConfig::Ptr &devConfig)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
const MaemoDeviceConfig::Ptr devConf
= MaemoDeviceConfig::create(name, osVersion, type, m_nextId);
if (m_devConfigs.isEmpty())
devConf->m_isDefault = true;
m_devConfigs << devConf;
m_shadowDevConfigs << MaemoDeviceConfig::Ptr();
devConfig->m_isDefault = true;
m_devConfigs << devConfig;
endInsertRows();
}
......@@ -456,7 +465,6 @@ void MaemoDeviceConfigurations::removeConfiguration(int idx)
beginRemoveRows(QModelIndex(), idx, idx);
const bool wasDefault = deviceAt(idx)->m_isDefault;
m_devConfigs.removeAt(idx);
m_shadowDevConfigs.removeAt(idx);
endRemoveRows();
if (wasDefault && !m_devConfigs.isEmpty()) {
m_devConfigs.first()->m_isDefault = true;
......@@ -469,24 +477,10 @@ void MaemoDeviceConfigurations::setConfigurationName(int i, const QString &name)
{
Q_ASSERT(i >= 0 && i < rowCount());
m_devConfigs.at(i)->m_name = name;
const MaemoDeviceConfig::Ptr shadowConfig = m_shadowDevConfigs.at(i);
if (shadowConfig)
shadowConfig->m_name = name;
const QModelIndex changedIndex = index(i, 0);
emit dataChanged(changedIndex, changedIndex);
}
void MaemoDeviceConfigurations::setDeviceType(int i,
const MaemoDeviceConfig::DeviceType type)
{
Q_ASSERT(i >= 0 && i < rowCount());
MaemoDeviceConfig::Ptr &current = m_devConfigs[i];
if (current->type() == type)
return;
setupShadowDevConf(i);
std::swap(current, m_shadowDevConfigs[i]);
}
void MaemoDeviceConfigurations::setSshParameters(int i,
const Core::SshConnectionParameters &params)
{
......@@ -544,7 +538,6 @@ void MaemoDeviceConfigurations::load()
}
settings->endArray();
settings->endGroup();
initShadowDevConfs();
if (!hasDefault && !m_devConfigs.isEmpty())
m_devConfigs.first()->m_isDefault = true;
}
......
......@@ -88,6 +88,7 @@ public:
static QString defaultPrivateKeyFilePath();
static QString defaultUser(MaemoGlobal::MaemoVersion osVersion);
static int defaultSshPort(DeviceType type);
static QString defaultQemuPassword(MaemoGlobal::MaemoVersion osVersion);
static const Id InvalidId;
......@@ -95,15 +96,19 @@ private:
typedef QSharedPointer<MaemoDeviceConfig> Ptr;
MaemoDeviceConfig(const QString &name, MaemoGlobal::MaemoVersion osVersion,
DeviceType type, Id &nextId);
DeviceType type, const Core::SshConnectionParameters &sshParams,
Id &nextId);
MaemoDeviceConfig(const QSettings &settings, Id &nextId);
MaemoDeviceConfig(const ConstPtr &other);
MaemoDeviceConfig(const MaemoDeviceConfig &);
MaemoDeviceConfig &operator=(const MaemoDeviceConfig &);
static Ptr create(const QString &name, MaemoGlobal::MaemoVersion osVersion,
DeviceType type, Id &nextId);
static Ptr createHardwareConfig(const QString &name,
MaemoGlobal::MaemoVersion osVersion, const QString &hostName,
const QString privateKeyFilePath, Id &nextId);
static Ptr createEmulatorConfig(const QString &name,
MaemoGlobal::MaemoVersion osVersion, Id &nextId);
static Ptr create(const QSettings &settings, Id &nextId);
static Ptr create(const ConstPtr &other);
......@@ -140,12 +145,13 @@ public:
void setDefaultSshKeyFilePath(const QString &path) { m_defaultSshKeyFilePath = path; }
QString defaultSshKeyFilePath() const { return m_defaultSshKeyFilePath; }
void addConfiguration(const QString &name,
MaemoGlobal::MaemoVersion osVersion,
MaemoDeviceConfig::DeviceType type);
void addHardwareDeviceConfiguration(const QString &name,
MaemoGlobal::MaemoVersion osVersion, const QString &hostName,
const QString privateKeyFilePath);
void addEmulatorDeviceConfiguration(const QString &name,
MaemoGlobal::MaemoVersion osVersion);
void removeConfiguration(int index);
void setConfigurationName(int i, const QString &name);
void setDeviceType(int i, const MaemoDeviceConfig::DeviceType type);
void setSshParameters(int i, const Core::SshConnectionParameters &params);
void setPortsSpec(int i, const QString &portsSpec);
void setDefaultDevice(int index);
......@@ -161,15 +167,13 @@ private:
MaemoDeviceConfigurations(QObject *parent);
void load();
void save();
void initShadowDevConfs();
static void copy(const MaemoDeviceConfigurations *source,
MaemoDeviceConfigurations *target, bool deep);
void setupShadowDevConf(int index);
void addConfiguration(const MaemoDeviceConfig::Ptr &devConfig);
static MaemoDeviceConfigurations *m_instance;
MaemoDeviceConfig::Id m_nextId;
QList<MaemoDeviceConfig::Ptr> m_devConfigs;
QList<MaemoDeviceConfig::Ptr> m_shadowDevConfigs;
QString m_defaultSshKeyFilePath;
};
......
......@@ -37,6 +37,7 @@
#include "ui_maemodeviceconfigurationssettingswidget.h"
#include "maemoconfigtestdialog.h"
#include "maemodeviceconfigwizard.h"
#include "maemodeviceconfigurations.h"
#include "maemokeydeployer.h"
#include "maemoremoteprocessesdialog.h"
......@@ -175,21 +176,13 @@ void MaemoDeviceConfigurationsSettingsWidget::initGui()
void MaemoDeviceConfigurationsSettingsWidget::addConfig()
{
const QString prefix = tr("New Device Configuration %1", "Standard "
"Configuration name with number");
int suffix = 1;
QString newName;
bool isUnique = false;
do {
newName = prefix.arg(QString::number(suffix++));
isUnique = !m_devConfigs->hasConfig(newName);
} while (!isUnique);
m_devConfigs->addConfiguration(newName, MaemoGlobal::Maemo5,
MaemoDeviceConfig::Physical);
m_ui->removeConfigButton->setEnabled(true);
m_ui->configurationComboBox->setCurrentIndex(m_ui->configurationComboBox->count()-1);
m_ui->configurationComboBox->setFocus();
MaemoDeviceConfigWizard wizard(m_devConfigs.data(), this);
if (wizard.exec() == QDialog::Accepted) {
wizard.createDeviceConfig();
m_ui->removeConfigButton->setEnabled(true);
m_ui->configurationComboBox->setCurrentIndex(m_ui->configurationComboBox->count()-1);
testConfig();
}
}
void MaemoDeviceConfigurationsSettingsWidget::deleteConfig()
......@@ -269,7 +262,7 @@ void MaemoDeviceConfigurationsSettingsWidget::deviceTypeChanged()
const MaemoDeviceConfig::DeviceType devType
= m_ui->deviceButton->isChecked()
? MaemoDeviceConfig::Physical : MaemoDeviceConfig::Simulator;
m_devConfigs->setDeviceType(currentIndex(), devType);
//m_devConfigs->setDeviceType(currentIndex(), devType);
fillInValues();
}
......
......@@ -469,8 +469,10 @@ public:
struct MaemoDeviceConfigWizardPrivate
{
MaemoDeviceConfigWizardPrivate(QWidget *parent)
: startPage(parent),
MaemoDeviceConfigWizardPrivate(MaemoDeviceConfigurations *devConfigs,
QWidget *parent)
: devConfigs(devConfigs),
startPage(parent),
previousKeySetupPage(parent),
reuseKeysCheckPage(parent),
keyCreationPage(parent),
......@@ -480,6 +482,7 @@ struct MaemoDeviceConfigWizardPrivate
}
WizardData wizardData;
MaemoDeviceConfigurations * const devConfigs;
MaemoDeviceConfigWizardStartPage startPage;
MaemoDeviceConfigWizardPreviousKeySetupCheckPage previousKeySetupPage;
MaemoDeviceConfigWizardReuseKeysCheckPage reuseKeysCheckPage;
......@@ -489,8 +492,10 @@ struct MaemoDeviceConfigWizardPrivate
};
MaemoDeviceConfigWizard::MaemoDeviceConfigWizard(QWidget *parent) :
QWizard(parent), d(new MaemoDeviceConfigWizardPrivate(this))
MaemoDeviceConfigWizard::MaemoDeviceConfigWizard(MaemoDeviceConfigurations *devConfigs,
QWidget *parent)
: QWizard(parent),
d(new MaemoDeviceConfigWizardPrivate(devConfigs, this))
{
setWindowTitle(tr("New Device Configuration Setup"));
setPage(StartPageId, &d->startPage);
......@@ -504,6 +509,27 @@ MaemoDeviceConfigWizard::MaemoDeviceConfigWizard(QWidget *parent) :
MaemoDeviceConfigWizard::~MaemoDeviceConfigWizard() {}
void MaemoDeviceConfigWizard::createDeviceConfig()
{
QString name = d->wizardData.configName;
if (d->devConfigs->hasConfig(name)) {
const QString nameTemplate = name + QLatin1String(" (%1)");
int suffix = 2;
do
name = nameTemplate.arg(QString::number(suffix++));
while (d->devConfigs->hasConfig(name));
}
if (d->wizardData.deviceType == MaemoDeviceConfig::Physical) {
d->devConfigs->addHardwareDeviceConfiguration(name,
d->wizardData.maemoVersion, d->wizardData.hostName,
d->wizardData.privateKeyFilePath);
} else {
d->devConfigs->addEmulatorDeviceConfiguration(name,
d->wizardData.maemoVersion);
}
}
int MaemoDeviceConfigWizard::nextId() const
{
switch (currentId()) {
......@@ -516,7 +542,6 @@ int MaemoDeviceConfigWizard::nextId() const
d->wizardData.hostName = d->startPage.hostName();
if (d->wizardData.deviceType == MaemoDeviceConfig::Simulator) {
// TODO: insert default MADDE key file paths
return FinalPageId;
} else {
return PreviousKeySetupCheckPageId;
......@@ -545,7 +570,9 @@ int MaemoDeviceConfigWizard::nextId() const
d->wizardData.publicKeyFilePath
= d->keyCreationPage.publicKeyFilePath();
return KeyDeploymentPageId;
case KeyDeploymentPageId: return FinalPageId;
case KeyDeploymentPageId:
d->wizardData.hostName = d->keyDeploymentPage.hostAddress();
return FinalPageId;
case FinalPageId: return -1;
default:
Q_ASSERT(false);
......
......@@ -35,21 +35,22 @@
#define MAEMODEVICECONFIGWIZARD_H
#include <QtCore/QScopedPointer>
#include <QtCore/QSharedPointer>
#include <QtGui/QWizard>
namespace Qt4ProjectManager {
namespace Internal {
class MaemoDeviceConfig;
class MaemoDeviceConfigurations;
struct MaemoDeviceConfigWizardPrivate;
class MaemoDeviceConfigWizard : public QWizard
{
Q_OBJECT
public:
explicit MaemoDeviceConfigWizard(QWidget *parent = 0);
explicit MaemoDeviceConfigWizard(MaemoDeviceConfigurations *devConfigs,
QWidget *parent = 0);
~MaemoDeviceConfigWizard();
QSharedPointer<MaemoDeviceConfig> deviceConfig() const;
void createDeviceConfig();
virtual int nextId() const;
private:
......
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