Commit 499c3c83 authored by ck's avatar ck
Browse files

Maemo: Deal sensibly with device type changes in settings page.

Task-number: QTCREATORBUG-1074
Reviewed-by: kh1
parent b949cafc
......@@ -71,8 +71,12 @@ namespace {
const QString DefaultKeyFile =
QDesktopServices::storageLocation(QDesktopServices::HomeLocation)
+ QLatin1String("/.ssh/id_rsa");
const int DefaultSshPort(22);
const int DefaultGdbServerPort(10000);
const int DefaultSshPortHW(22);
const int DefaultSshPortSim(6666);
const int DefaultGdbServerPortHW(10000);
const int DefaultGdbServerPortSim(13219);
const QString DefaultHostNameHW(QLatin1String("192.168.2.15"));
const QString DefaultHostNameSim(QLatin1String("localhost"));
const QString DefaultUserName(QLatin1String("developer"));
const MaemoDeviceConfig::AuthType DefaultAuthType(MaemoDeviceConfig::Key);
const int DefaultTimeout(30);
......@@ -91,11 +95,12 @@ private:
const quint64 m_id;
};
MaemoDeviceConfig::MaemoDeviceConfig(const QString &name)
MaemoDeviceConfig::MaemoDeviceConfig(const QString &name, MaemoDeviceConfig::DeviceType devType)
: name(name),
type(DefaultDeviceType),
sshPort(DefaultSshPort),
gdbServerPort(DefaultGdbServerPort),
type(devType),
host(defaultHost(type)),
sshPort(defaultSshPort(type)),
gdbServerPort(defaultGdbServerPort(type)),
uname(DefaultUserName),
authentication(DefaultAuthType),
keyFile(DefaultKeyFile),
......@@ -108,9 +113,9 @@ MaemoDeviceConfig::MaemoDeviceConfig(const QSettings &settings,
quint64 &nextId)
: name(settings.value(NameKey).toString()),
type(static_cast<DeviceType>(settings.value(TypeKey, DefaultDeviceType).toInt())),
host(settings.value(HostKey).toString()),
sshPort(settings.value(SshPortKey, DefaultSshPort).toInt()),
gdbServerPort(settings.value(GdbServerPortKey, DefaultGdbServerPort).toInt()),
host(settings.value(HostKey, defaultHost(type)).toString()),
sshPort(settings.value(SshPortKey, defaultSshPort(type)).toInt()),
gdbServerPort(settings.value(GdbServerPortKey, defaultGdbServerPort(type)).toInt()),
uname(settings.value(UserNameKey, DefaultUserName).toString()),
authentication(static_cast<AuthType>(settings.value(AuthKey, DefaultAuthType).toInt())),
pwd(settings.value(PasswordKey).toString()),
......@@ -127,6 +132,21 @@ MaemoDeviceConfig::MaemoDeviceConfig()
{
}
int MaemoDeviceConfig::defaultSshPort(DeviceType type) const
{
return type == Physical ? DefaultSshPortHW : DefaultSshPortSim;
}
int MaemoDeviceConfig::defaultGdbServerPort(DeviceType type) const
{
return type == Physical ? DefaultGdbServerPortHW : DefaultGdbServerPortSim;
}
QString MaemoDeviceConfig::defaultHost(DeviceType type) const
{
return type == Physical ? DefaultHostNameHW : DefaultHostNameSim;
}
bool MaemoDeviceConfig::isValid() const
{
return internalId != InvalidId;
......
......@@ -54,7 +54,7 @@ public:
enum DeviceType { Physical, Simulator };
enum AuthType { Password, Key };
MaemoDeviceConfig();
MaemoDeviceConfig(const QString &name);
MaemoDeviceConfig(const QString &name, DeviceType type);
MaemoDeviceConfig(const QSettings &settings, quint64 &nextId);
void save(QSettings &settings) const;
bool isValid() const;
......@@ -71,6 +71,10 @@ public:
quint64 internalId;
private:
int defaultSshPort(DeviceType type) const;
int defaultGdbServerPort(DeviceType type) const;
QString defaultHost(DeviceType type) const;
static const quint64 InvalidId = 0;
};
......
......@@ -152,7 +152,7 @@ void MaemoSettingsWidget::addConfig()
isUnique = !configNameExists(m_devConfs, newName);
} while (!isUnique);
m_devConfs.append(MaemoDeviceConfig(newName));
m_devConfs.append(MaemoDeviceConfig(newName, MaemoDeviceConfig::Physical));
m_ui->configListWidget->addItem(newName);
m_ui->configListWidget->setCurrentRow(m_ui->configListWidget->count() - 1);
m_ui->nameLineEdit->selectAll();
......@@ -180,10 +180,24 @@ void MaemoSettingsWidget::deleteConfig()
void MaemoSettingsWidget::display(const MaemoDeviceConfig &devConfig)
{
m_ui->nameLineEdit->setText(devConfig.name);
if (devConfig.type == MaemoDeviceConfig::Physical)
MaemoDeviceConfig *otherConfig;
if (devConfig.type == MaemoDeviceConfig::Physical) {
m_lastConfigHW = devConfig;
m_lastConfigSim
= MaemoDeviceConfig(devConfig.name, MaemoDeviceConfig::Simulator);
otherConfig = &m_lastConfigSim;
m_ui->deviceButton->setChecked(true);
else
} else {
m_lastConfigSim = devConfig;
m_lastConfigHW
= MaemoDeviceConfig(devConfig.name, MaemoDeviceConfig::Physical);
otherConfig = &m_lastConfigHW;
m_ui->simulatorButton->setChecked(true);
}
otherConfig->authentication = devConfig.authentication;
otherConfig->timeout = devConfig.timeout;
otherConfig->pwd = devConfig.pwd;
otherConfig->keyFile = devConfig.keyFile;
if (devConfig.authentication == MaemoDeviceConfig::Password)
m_ui->passwordButton->setChecked(true);
......@@ -194,6 +208,25 @@ void MaemoSettingsWidget::display(const MaemoDeviceConfig &devConfig)
m_sshPortValidator->setValue(devConfig.sshPort);
m_gdbServerPortValidator->setValue(devConfig.gdbServerPort);
m_timeoutValidator->setValue(devConfig.timeout);
fillInValues();
}
void MaemoSettingsWidget::fillInValues()
{
m_ui->hostLineEdit->setText(currentConfig().host);
m_ui->sshPortLineEdit->setText(QString::number(currentConfig().sshPort));
m_ui->gdbServerPortLineEdit
->setText(QString::number(currentConfig().gdbServerPort));
m_ui->timeoutLineEdit->setText(QString::number(currentConfig().timeout));
m_ui->userLineEdit->setText(currentConfig().uname);
m_ui->pwdLineEdit->setText(currentConfig().pwd);
m_ui->keyFileLineEdit->setPath(currentConfig().keyFile);
const bool isSimulator
= currentConfig().type == MaemoDeviceConfig::Simulator;
m_ui->hostLineEdit->setReadOnly(isSimulator);
m_ui->sshPortLineEdit->setReadOnly(isSimulator);
m_ui->gdbServerPortLineEdit->setReadOnly(isSimulator);
}
void MaemoSettingsWidget::saveSettings()
......@@ -222,34 +255,19 @@ void MaemoSettingsWidget::configNameEditingFinished()
void MaemoSettingsWidget::deviceTypeChanged()
{
currentConfig().type =
const MaemoDeviceConfig::DeviceType devType =
m_ui->deviceButton->isChecked()
? MaemoDeviceConfig::Physical
: MaemoDeviceConfig::Simulator;
// Port values for the simulator are specified by Qemu's
// "information" file, to which we have no access here,
// so we hard-code the last known values.
if (currentConfig().type == MaemoDeviceConfig::Simulator) {
currentConfig().host = QLatin1String("localhost");
currentConfig().sshPort = 6666;
currentConfig().gdbServerPort = 13219;
m_ui->hostLineEdit->setReadOnly(true);
m_ui->sshPortLineEdit->setReadOnly(true);
m_ui->gdbServerPortLineEdit->setReadOnly(true);
if (devType == MaemoDeviceConfig::Simulator) {
m_lastConfigHW = currentConfig();
currentConfig() = m_lastConfigSim;
} else {
m_ui->hostLineEdit->setReadOnly(false);
m_ui->sshPortLineEdit->setReadOnly(false);
m_ui->gdbServerPortLineEdit->setReadOnly(false);
m_lastConfigSim = currentConfig();
currentConfig() = m_lastConfigHW;
}
m_ui->hostLineEdit->setText(currentConfig().host);
m_ui->sshPortLineEdit->setText(QString::number(currentConfig().sshPort));
m_ui->gdbServerPortLineEdit
->setText(QString::number(currentConfig().gdbServerPort));
m_ui->timeoutLineEdit->setText(QString::number(currentConfig().timeout));
m_ui->userLineEdit->setText(currentConfig().uname);
m_ui->pwdLineEdit->setText(currentConfig().pwd);
m_ui->keyFileLineEdit->setPath(currentConfig().keyFile);
fillInValues();
}
void MaemoSettingsWidget::authenticationTypeChanged()
......
......@@ -92,9 +92,12 @@ private:
PortAndTimeoutValidator *validator);
void clearDetails();
QString parseTestOutput();
void fillInValues();
Ui_MaemoSettingsWidget *m_ui;
QList<MaemoDeviceConfig> m_devConfs;
MaemoDeviceConfig m_lastConfigHW;
MaemoDeviceConfig m_lastConfigSim;
NameValidator * const m_nameValidator;
PortAndTimeoutValidator * const m_sshPortValidator;
PortAndTimeoutValidator * const m_gdbServerPortValidator;
......
......@@ -279,13 +279,13 @@
</connection>
<connection>
<sender>deviceButton</sender>
<signal>toggled(bool)</signal>
<signal>clicked(bool)</signal>
<receiver>MaemoSettingsWidget</receiver>
<slot>deviceTypeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>267</x>
<y>169</y>
<x>287</x>
<y>192</y>
</hint>
<hint type="destinationlabel">
<x>511</x>
......@@ -300,8 +300,8 @@
<slot>hostNameEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>396</x>
<y>216</y>
<x>431</x>
<y>247</y>
</hint>
<hint type="destinationlabel">
<x>424</x>
......@@ -316,8 +316,8 @@
<slot>sshPortEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>396</x>
<y>240</y>
<x>431</x>
<y>275</y>
</hint>
<hint type="destinationlabel">
<x>514</x>
......@@ -332,8 +332,8 @@
<slot>timeoutEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>396</x>
<y>309</y>
<x>431</x>
<y>331</y>
</hint>
<hint type="destinationlabel">
<x>425</x>
......@@ -348,8 +348,8 @@
<slot>userNameEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>396</x>
<y>336</y>
<x>431</x>
<y>359</y>
</hint>
<hint type="destinationlabel">
<x>422</x>
......@@ -364,8 +364,8 @@
<slot>passwordEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>396</x>
<y>363</y>
<x>431</x>
<y>387</y>
</hint>
<hint type="destinationlabel">
<x>423</x>
......@@ -375,13 +375,13 @@
</connection>
<connection>
<sender>simulatorButton</sender>
<signal>toggled(bool)</signal>
<signal>clicked(bool)</signal>
<receiver>MaemoSettingsWidget</receiver>
<slot>deviceTypeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>387</x>
<y>169</y>
<x>414</x>
<y>192</y>
</hint>
<hint type="destinationlabel">
<x>426</x>
......@@ -428,8 +428,8 @@
<slot>deleteConfig()</slot>
<hints>
<hint type="sourcelabel">
<x>454</x>
<y>56</y>
<x>555</x>
<y>68</y>
</hint>
<hint type="destinationlabel">
<x>513</x>
......@@ -444,8 +444,8 @@
<slot>authenticationTypeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>196</x>
<y>187</y>
<x>254</x>
<y>219</y>
</hint>
<hint type="destinationlabel">
<x>513</x>
......@@ -460,8 +460,8 @@
<slot>keyFileEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>150</x>
<y>384</y>
<x>162</x>
<y>409</y>
</hint>
<hint type="destinationlabel">
<x>257</x>
......@@ -476,8 +476,8 @@
<slot>keyFileEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>150</x>
<y>384</y>
<x>162</x>
<y>409</y>
</hint>
<hint type="destinationlabel">
<x>257</x>
......@@ -492,8 +492,8 @@
<slot>testConfig()</slot>
<hints>
<hint type="sourcelabel">
<x>450</x>
<y>96</y>
<x>555</x>
<y>102</y>
</hint>
<hint type="destinationlabel">
<x>428</x>
......@@ -508,8 +508,8 @@
<slot>deployKey()</slot>
<hints>
<hint type="sourcelabel">
<x>438</x>
<y>119</y>
<x>555</x>
<y>136</y>
</hint>
<hint type="destinationlabel">
<x>510</x>
......@@ -524,8 +524,8 @@
<slot>gdbServerPortEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>369</x>
<y>282</y>
<x>431</x>
<y>303</y>
</hint>
<hint type="destinationlabel">
<x>427</x>
......@@ -540,8 +540,8 @@
<slot>authenticationTypeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>257</x>
<y>189</y>
<x>307</x>
<y>219</y>
</hint>
<hint type="destinationlabel">
<x>525</x>
......
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