diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurations.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurations.cpp index 0d786c8140c..1afc132ae21 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurations.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurations.cpp @@ -57,6 +57,7 @@ namespace { const QLatin1String HostKey("Host"); const QLatin1String SshPortKey("SshPort"); const QLatin1String DebuggingPortKey("GdbServerPort"); + const QLatin1String PortsSpecKey("FreePortsSpec"); const QLatin1String UserNameKey("Uname"); const QLatin1String AuthKey("Authentication"); const QLatin1String KeyFileKey("KeyFile"); @@ -107,7 +108,7 @@ public: * ElemList -> Elem [ ',' ElemList ] * Elem -> Port [ '-' Port ] */ - QList parse() + MaemoPortList parse() { try { if (!atEnd()) @@ -115,7 +116,7 @@ public: } catch (ParseException &e) { qWarning("Malformed ports specification: %s", e.error); } - return m_ports; + return m_portList; } private: @@ -138,15 +139,14 @@ private: { const int startPort = parsePort(); if (atEnd() || nextChar() != '-') { - m_ports << startPort; + m_portList.addRange(MaemoPortList::Range(startPort, startPort)); return; } ++m_pos; const int endPort = parsePort(); if (endPort < startPort) throw ParseException("Invalid range (end < start)."); - for (int port = startPort; port <= endPort; ++port) - m_ports << port; + m_portList.addRange(MaemoPortList::Range(startPort, endPort)); } int parsePort() @@ -154,12 +154,13 @@ private: if (atEnd()) throw ParseException("Empty port string."); int port = 0; - char next = nextChar(); - while (!atEnd() && std::isdigit(next)) { + do { + const char next = nextChar(); + if (!std::isdigit(next)) + break; port = 10*port + next - '0'; ++m_pos; - next = nextChar(); - } + } while (!atEnd()); if (port == 0 || port >= 2 << 16) throw ParseException("Invalid port value."); return port; @@ -168,7 +169,7 @@ private: bool atEnd() const { return m_pos == m_portsSpec.length(); } char nextChar() const { return m_portsSpec.at(m_pos).toAscii(); } - QList m_ports; + MaemoPortList m_portList; int m_pos; const QString &m_portsSpec; }; @@ -177,6 +178,7 @@ MaemoDeviceConfig::MaemoDeviceConfig(const QString &name, MaemoDeviceConfig::Dev : name(name), type(devType), debuggingPort(defaultDebuggingPort(type)), + portsSpec(defaultPortsSpec(type)), internalId(MaemoDeviceConfigurations::instance().m_nextId++) { server.host = defaultHost(type); @@ -192,6 +194,7 @@ MaemoDeviceConfig::MaemoDeviceConfig(const QSettings &settings, : name(settings.value(NameKey).toString()), type(static_cast(settings.value(TypeKey, DefaultDeviceType).toInt())), debuggingPort(settings.value(DebuggingPortKey, defaultDebuggingPort(type)).toInt()), + portsSpec(settings.value(PortsSpecKey, defaultPortsSpec(type)).toString()), internalId(settings.value(InternalIdKey, nextId).toULongLong()) { if (internalId == nextId) @@ -230,6 +233,11 @@ int MaemoDeviceConfig::defaultDebuggingPort(DeviceType type) const return type == Physical ? DefaultGdbServerPortHW : DefaultGdbServerPortSim; } +QString MaemoDeviceConfig::defaultPortsSpec(DeviceType type) const +{ + return QLatin1String(type == Physical ? "10000-10100" : "13219,14168"); +} + QString MaemoDeviceConfig::defaultHost(DeviceType type) const { return type == Physical ? DefaultHostNameHW : DefaultHostNameSim; @@ -240,7 +248,7 @@ bool MaemoDeviceConfig::isValid() const return internalId != InvalidId; } -QList MaemoDeviceConfig::freePorts() const +MaemoPortList MaemoDeviceConfig::freePorts() const { return PortsSpecParser(portsSpec).parse(); } @@ -252,6 +260,7 @@ void MaemoDeviceConfig::save(QSettings &settings) const settings.setValue(HostKey, server.host); settings.setValue(SshPortKey, server.port); settings.setValue(DebuggingPortKey, debuggingPort); + settings.setValue(PortsSpecKey, portsSpec); settings.setValue(UserNameKey, server.uname); settings.setValue(AuthKey, server.authType); settings.setValue(PasswordKey, server.pwd); diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurations.h b/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurations.h index 051cb356e69..6839893677c 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurations.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurations.h @@ -39,6 +39,7 @@ #include #include +#include #include QT_BEGIN_NAMESPACE @@ -48,6 +49,31 @@ QT_END_NAMESPACE namespace Qt4ProjectManager { namespace Internal { +class MaemoPortList +{ +public: + typedef QPair Range; + void addRange(const Range &range) { m_ranges << range; } + bool hasMore() const { return !m_ranges.isEmpty(); } + int count() const { + int n = 0; + foreach (const Range &r, m_ranges) + n += r.second - r.first + 1; + return n; + } + int getNext() { + Q_ASSERT(!m_ranges.isEmpty()); + Range &firstRange = m_ranges.first(); + const int next = firstRange.first++; + if (firstRange.first > firstRange.second) + m_ranges.removeFirst(); + return next; + } + +private: + QList m_ranges; +}; + class MaemoDeviceConfig { public: @@ -57,7 +83,7 @@ public: MaemoDeviceConfig(const QSettings &settings, quint64 &nextId); void save(QSettings &settings) const; bool isValid() const; - QList freePorts() const; + MaemoPortList freePorts() const; static QString portsRegExpr(); static const quint64 InvalidId = 0; @@ -72,6 +98,7 @@ public: private: int defaultSshPort(DeviceType type) const; int defaultDebuggingPort(DeviceType type) const; + QString defaultPortsSpec(DeviceType type) const; QString defaultHost(DeviceType type) const; }; diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.cpp index 544d43fa024..85e78d1cacf 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.cpp @@ -145,6 +145,13 @@ void MaemoSettingsWidget::initGui() m_ui->setupUi(this); m_ui->nameLineEdit->setValidator(m_nameValidator); m_ui->keyFileLineEdit->setExpectedKind(Utils::PathChooser::File); + QRegExpValidator * const portsValidator + = new QRegExpValidator(QRegExp(MaemoDeviceConfig::portsRegExpr()), this); + m_ui->portsLineEdit->setValidator(portsValidator); +#if 1 + m_ui->freePortsLabel->hide(); + m_ui->portsLineEdit->hide(); +#endif foreach (const MaemoDeviceConfig &devConf, m_devConfs) m_ui->configurationComboBox->addItem(devConf.name); @@ -217,6 +224,7 @@ void MaemoSettingsWidget::fillInValues() m_ui->hostLineEdit->setText(currentConfig().server.host); m_ui->sshPortSpinBox->setValue(currentConfig().server.port); m_ui->gdbServerPortSpinBox->setValue(currentConfig().debuggingPort); + m_ui->portsLineEdit->setText(currentConfig().portsSpec); m_ui->timeoutSpinBox->setValue(currentConfig().server.timeout); m_ui->userLineEdit->setText(currentConfig().server.uname); m_ui->pwdLineEdit->setText(currentConfig().server.pwd); @@ -302,6 +310,11 @@ void MaemoSettingsWidget::gdbServerPortEditingFinished() currentConfig().debuggingPort = m_ui->gdbServerPortSpinBox->value(); } +void MaemoSettingsWidget::handleFreePortsChanged() +{ + currentConfig().portsSpec = m_ui->portsLineEdit->text(); +} + void MaemoSettingsWidget::timeoutEditingFinished() { currentConfig().server.timeout = m_ui->timeoutSpinBox->value(); diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.h b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.h index 7a1a51e7a35..d6f9f8aad08 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.h @@ -84,6 +84,7 @@ private slots: void passwordEditingFinished(); void keyFileEditingFinished(); void showPassword(bool showClearText); + void handleFreePortsChanged(); // For configuration testing. void testConfig(); diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.ui b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.ui index 3b6ab984da1..a1c6ca7bd51 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.ui +++ b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.ui @@ -6,8 +6,8 @@ 0 0 - 596 - 354 + 602 + 421 @@ -209,13 +209,44 @@ + + + Free ports: + + + + + + + + + You can enter lists and ranges like this: 1024,1026-1028,1030 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + Connection timeout: - + @@ -248,24 +279,24 @@ - + Username: - + - + Password: - + @@ -283,14 +314,14 @@ - + Private key file: - + @@ -420,8 +451,8 @@ userNameEditingFinished() - 419 - 268 + 425 + 302 422 @@ -436,8 +467,8 @@ passwordEditingFinished() - 291 - 299 + 297 + 334 423 @@ -516,8 +547,8 @@ keyFileEditingFinished() - 419 - 321 + 425 + 356 257 @@ -532,8 +563,8 @@ keyFileEditingFinished() - 419 - 321 + 425 + 356 257 @@ -628,8 +659,8 @@ timeoutEditingFinished() - 199 - 227 + 237 + 270 6 @@ -644,8 +675,8 @@ timeoutEditingFinished() - 178 - 224 + 237 + 270 0 @@ -724,8 +755,8 @@ showPassword(bool) - 316 - 290 + 424 + 332 3 @@ -733,6 +764,22 @@ + + portsLineEdit + editingFinished() + MaemoSettingsWidget + handleFreePortsChanged() + + + 184 + 225 + + + 0 + 393 + + + configNameEditingFinished() @@ -753,5 +800,6 @@ currentConfigChanged(int) showGenerateSshKeyDialog() showPassword(bool) + handleFreePortsChanged()