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

Task-number: QTCREATORBUG-1074
Reviewed-by: kh1
This commit is contained in:
ck
2010-04-08 17:31:55 +02:00
parent b949cafc78
commit 499c3c8362
5 changed files with 112 additions and 67 deletions

View File

@@ -71,8 +71,12 @@ namespace {
const QString DefaultKeyFile = const QString DefaultKeyFile =
QDesktopServices::storageLocation(QDesktopServices::HomeLocation) QDesktopServices::storageLocation(QDesktopServices::HomeLocation)
+ QLatin1String("/.ssh/id_rsa"); + QLatin1String("/.ssh/id_rsa");
const int DefaultSshPort(22); const int DefaultSshPortHW(22);
const int DefaultGdbServerPort(10000); 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 QString DefaultUserName(QLatin1String("developer"));
const MaemoDeviceConfig::AuthType DefaultAuthType(MaemoDeviceConfig::Key); const MaemoDeviceConfig::AuthType DefaultAuthType(MaemoDeviceConfig::Key);
const int DefaultTimeout(30); const int DefaultTimeout(30);
@@ -91,11 +95,12 @@ private:
const quint64 m_id; const quint64 m_id;
}; };
MaemoDeviceConfig::MaemoDeviceConfig(const QString &name) MaemoDeviceConfig::MaemoDeviceConfig(const QString &name, MaemoDeviceConfig::DeviceType devType)
: name(name), : name(name),
type(DefaultDeviceType), type(devType),
sshPort(DefaultSshPort), host(defaultHost(type)),
gdbServerPort(DefaultGdbServerPort), sshPort(defaultSshPort(type)),
gdbServerPort(defaultGdbServerPort(type)),
uname(DefaultUserName), uname(DefaultUserName),
authentication(DefaultAuthType), authentication(DefaultAuthType),
keyFile(DefaultKeyFile), keyFile(DefaultKeyFile),
@@ -108,9 +113,9 @@ MaemoDeviceConfig::MaemoDeviceConfig(const QSettings &settings,
quint64 &nextId) quint64 &nextId)
: name(settings.value(NameKey).toString()), : name(settings.value(NameKey).toString()),
type(static_cast<DeviceType>(settings.value(TypeKey, DefaultDeviceType).toInt())), type(static_cast<DeviceType>(settings.value(TypeKey, DefaultDeviceType).toInt())),
host(settings.value(HostKey).toString()), host(settings.value(HostKey, defaultHost(type)).toString()),
sshPort(settings.value(SshPortKey, DefaultSshPort).toInt()), sshPort(settings.value(SshPortKey, defaultSshPort(type)).toInt()),
gdbServerPort(settings.value(GdbServerPortKey, DefaultGdbServerPort).toInt()), gdbServerPort(settings.value(GdbServerPortKey, defaultGdbServerPort(type)).toInt()),
uname(settings.value(UserNameKey, DefaultUserName).toString()), uname(settings.value(UserNameKey, DefaultUserName).toString()),
authentication(static_cast<AuthType>(settings.value(AuthKey, DefaultAuthType).toInt())), authentication(static_cast<AuthType>(settings.value(AuthKey, DefaultAuthType).toInt())),
pwd(settings.value(PasswordKey).toString()), 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 bool MaemoDeviceConfig::isValid() const
{ {
return internalId != InvalidId; return internalId != InvalidId;

View File

@@ -54,7 +54,7 @@ public:
enum DeviceType { Physical, Simulator }; enum DeviceType { Physical, Simulator };
enum AuthType { Password, Key }; enum AuthType { Password, Key };
MaemoDeviceConfig(); MaemoDeviceConfig();
MaemoDeviceConfig(const QString &name); MaemoDeviceConfig(const QString &name, DeviceType type);
MaemoDeviceConfig(const QSettings &settings, quint64 &nextId); MaemoDeviceConfig(const QSettings &settings, quint64 &nextId);
void save(QSettings &settings) const; void save(QSettings &settings) const;
bool isValid() const; bool isValid() const;
@@ -71,6 +71,10 @@ public:
quint64 internalId; quint64 internalId;
private: private:
int defaultSshPort(DeviceType type) const;
int defaultGdbServerPort(DeviceType type) const;
QString defaultHost(DeviceType type) const;
static const quint64 InvalidId = 0; static const quint64 InvalidId = 0;
}; };

View File

@@ -152,7 +152,7 @@ void MaemoSettingsWidget::addConfig()
isUnique = !configNameExists(m_devConfs, newName); isUnique = !configNameExists(m_devConfs, newName);
} while (!isUnique); } while (!isUnique);
m_devConfs.append(MaemoDeviceConfig(newName)); m_devConfs.append(MaemoDeviceConfig(newName, MaemoDeviceConfig::Physical));
m_ui->configListWidget->addItem(newName); m_ui->configListWidget->addItem(newName);
m_ui->configListWidget->setCurrentRow(m_ui->configListWidget->count() - 1); m_ui->configListWidget->setCurrentRow(m_ui->configListWidget->count() - 1);
m_ui->nameLineEdit->selectAll(); m_ui->nameLineEdit->selectAll();
@@ -180,10 +180,24 @@ void MaemoSettingsWidget::deleteConfig()
void MaemoSettingsWidget::display(const MaemoDeviceConfig &devConfig) void MaemoSettingsWidget::display(const MaemoDeviceConfig &devConfig)
{ {
m_ui->nameLineEdit->setText(devConfig.name); 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); 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); 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) if (devConfig.authentication == MaemoDeviceConfig::Password)
m_ui->passwordButton->setChecked(true); m_ui->passwordButton->setChecked(true);
@@ -194,6 +208,25 @@ void MaemoSettingsWidget::display(const MaemoDeviceConfig &devConfig)
m_sshPortValidator->setValue(devConfig.sshPort); m_sshPortValidator->setValue(devConfig.sshPort);
m_gdbServerPortValidator->setValue(devConfig.gdbServerPort); m_gdbServerPortValidator->setValue(devConfig.gdbServerPort);
m_timeoutValidator->setValue(devConfig.timeout); 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() void MaemoSettingsWidget::saveSettings()
@@ -222,34 +255,19 @@ void MaemoSettingsWidget::configNameEditingFinished()
void MaemoSettingsWidget::deviceTypeChanged() void MaemoSettingsWidget::deviceTypeChanged()
{ {
currentConfig().type = const MaemoDeviceConfig::DeviceType devType =
m_ui->deviceButton->isChecked() m_ui->deviceButton->isChecked()
? MaemoDeviceConfig::Physical ? MaemoDeviceConfig::Physical
: MaemoDeviceConfig::Simulator; : MaemoDeviceConfig::Simulator;
// Port values for the simulator are specified by Qemu's if (devType == MaemoDeviceConfig::Simulator) {
// "information" file, to which we have no access here, m_lastConfigHW = currentConfig();
// so we hard-code the last known values. currentConfig() = m_lastConfigSim;
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);
} else { } else {
m_ui->hostLineEdit->setReadOnly(false); m_lastConfigSim = currentConfig();
m_ui->sshPortLineEdit->setReadOnly(false); currentConfig() = m_lastConfigHW;
m_ui->gdbServerPortLineEdit->setReadOnly(false);
} }
m_ui->hostLineEdit->setText(currentConfig().host); fillInValues();
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);
} }
void MaemoSettingsWidget::authenticationTypeChanged() void MaemoSettingsWidget::authenticationTypeChanged()

View File

@@ -92,9 +92,12 @@ private:
PortAndTimeoutValidator *validator); PortAndTimeoutValidator *validator);
void clearDetails(); void clearDetails();
QString parseTestOutput(); QString parseTestOutput();
void fillInValues();
Ui_MaemoSettingsWidget *m_ui; Ui_MaemoSettingsWidget *m_ui;
QList<MaemoDeviceConfig> m_devConfs; QList<MaemoDeviceConfig> m_devConfs;
MaemoDeviceConfig m_lastConfigHW;
MaemoDeviceConfig m_lastConfigSim;
NameValidator * const m_nameValidator; NameValidator * const m_nameValidator;
PortAndTimeoutValidator * const m_sshPortValidator; PortAndTimeoutValidator * const m_sshPortValidator;
PortAndTimeoutValidator * const m_gdbServerPortValidator; PortAndTimeoutValidator * const m_gdbServerPortValidator;

View File

@@ -279,13 +279,13 @@
</connection> </connection>
<connection> <connection>
<sender>deviceButton</sender> <sender>deviceButton</sender>
<signal>toggled(bool)</signal> <signal>clicked(bool)</signal>
<receiver>MaemoSettingsWidget</receiver> <receiver>MaemoSettingsWidget</receiver>
<slot>deviceTypeChanged()</slot> <slot>deviceTypeChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>267</x> <x>287</x>
<y>169</y> <y>192</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>511</x> <x>511</x>
@@ -300,8 +300,8 @@
<slot>hostNameEditingFinished()</slot> <slot>hostNameEditingFinished()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>396</x> <x>431</x>
<y>216</y> <y>247</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>424</x> <x>424</x>
@@ -316,8 +316,8 @@
<slot>sshPortEditingFinished()</slot> <slot>sshPortEditingFinished()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>396</x> <x>431</x>
<y>240</y> <y>275</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>514</x> <x>514</x>
@@ -332,8 +332,8 @@
<slot>timeoutEditingFinished()</slot> <slot>timeoutEditingFinished()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>396</x> <x>431</x>
<y>309</y> <y>331</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>425</x> <x>425</x>
@@ -348,8 +348,8 @@
<slot>userNameEditingFinished()</slot> <slot>userNameEditingFinished()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>396</x> <x>431</x>
<y>336</y> <y>359</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>422</x> <x>422</x>
@@ -364,8 +364,8 @@
<slot>passwordEditingFinished()</slot> <slot>passwordEditingFinished()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>396</x> <x>431</x>
<y>363</y> <y>387</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>423</x> <x>423</x>
@@ -375,13 +375,13 @@
</connection> </connection>
<connection> <connection>
<sender>simulatorButton</sender> <sender>simulatorButton</sender>
<signal>toggled(bool)</signal> <signal>clicked(bool)</signal>
<receiver>MaemoSettingsWidget</receiver> <receiver>MaemoSettingsWidget</receiver>
<slot>deviceTypeChanged()</slot> <slot>deviceTypeChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>387</x> <x>414</x>
<y>169</y> <y>192</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>426</x> <x>426</x>
@@ -428,8 +428,8 @@
<slot>deleteConfig()</slot> <slot>deleteConfig()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>454</x> <x>555</x>
<y>56</y> <y>68</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>513</x> <x>513</x>
@@ -444,8 +444,8 @@
<slot>authenticationTypeChanged()</slot> <slot>authenticationTypeChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>196</x> <x>254</x>
<y>187</y> <y>219</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>513</x> <x>513</x>
@@ -460,8 +460,8 @@
<slot>keyFileEditingFinished()</slot> <slot>keyFileEditingFinished()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>150</x> <x>162</x>
<y>384</y> <y>409</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>257</x> <x>257</x>
@@ -476,8 +476,8 @@
<slot>keyFileEditingFinished()</slot> <slot>keyFileEditingFinished()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>150</x> <x>162</x>
<y>384</y> <y>409</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>257</x> <x>257</x>
@@ -492,8 +492,8 @@
<slot>testConfig()</slot> <slot>testConfig()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>450</x> <x>555</x>
<y>96</y> <y>102</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>428</x> <x>428</x>
@@ -508,8 +508,8 @@
<slot>deployKey()</slot> <slot>deployKey()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>438</x> <x>555</x>
<y>119</y> <y>136</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>510</x> <x>510</x>
@@ -524,8 +524,8 @@
<slot>gdbServerPortEditingFinished()</slot> <slot>gdbServerPortEditingFinished()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>369</x> <x>431</x>
<y>282</y> <y>303</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>427</x> <x>427</x>
@@ -540,8 +540,8 @@
<slot>authenticationTypeChanged()</slot> <slot>authenticationTypeChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>257</x> <x>307</x>
<y>189</y> <y>219</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>525</x> <x>525</x>