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

Maemo: Move some device configurations code around.

parent ca3b9e00
......@@ -176,6 +176,49 @@ private:
const QString &m_portsSpec;
};
void MaemoPortList::addPort(int port) { addRange(port, port); }
void MaemoPortList::addRange(int startPort, int endPort)
{
m_ranges << Range(startPort, endPort);
}
bool MaemoPortList::hasMore() const { return !m_ranges.isEmpty(); }
int MaemoPortList::count() const
{
int n = 0;
foreach (const Range &r, m_ranges)
n += r.second - r.first + 1;
return n;
}
int MaemoPortList::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;
}
QString MaemoPortList::toString() const
{
QString stringRep;
foreach (const Range &range, m_ranges) {
stringRep += QString::number(range.first);
if (range.second != range.first)
stringRep += QLatin1Char('-') + QString::number(range.second);
stringRep += QLatin1Char(',');
}
if (!stringRep.isEmpty())
stringRep.remove(stringRep.length() - 1, 1); // Trailing comma.
return stringRep;
}
MaemoDeviceConfig::Ptr MaemoDeviceConfig::create(const QString &name,
DeviceType type, Id &nextId)
{
......@@ -286,6 +329,9 @@ void MaemoDeviceConfig::save(QSettings &settings) const
settings.setValue(InternalIdKey, m_internalId);
}
const MaemoDeviceConfig::Id MaemoDeviceConfig::InvalidId = 0;
MaemoDeviceConfigurations *MaemoDeviceConfigurations::instance(QObject *parent)
{
if (m_instance == 0) {
......@@ -514,7 +560,7 @@ MaemoDeviceConfig::ConstPtr MaemoDeviceConfigurations::defaultDeviceConfig() con
int MaemoDeviceConfigurations::indexForInternalId(MaemoDeviceConfig::Id internalId) const
{
for (int i = 0; i < m_devConfigs.count(); ++i) {
if (deviceAt(i)->internalId() == internalId)
if (deviceAt(i)->m_internalId == internalId)
return i;
}
return -1;
......@@ -522,7 +568,7 @@ int MaemoDeviceConfigurations::indexForInternalId(MaemoDeviceConfig::Id internal
MaemoDeviceConfig::Id MaemoDeviceConfigurations::internalId(MaemoDeviceConfig::ConstPtr devConf) const
{
return devConf ? devConf->internalId() : MaemoDeviceConfig::InvalidId;
return devConf ? devConf->m_internalId : MaemoDeviceConfig::InvalidId;
}
int MaemoDeviceConfigurations::rowCount(const QModelIndex &parent) const
......
......@@ -52,45 +52,20 @@ namespace Internal {
class MaemoPortList
{
typedef QPair<int, int> Range;
public:
void addPort(int port) { addRange(port, port); }
void addRange(int startPort, int endPort) {
m_ranges << Range(startPort, endPort);
}
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;
}
QString toString() const
{
QString stringRep;
foreach (const Range &range, m_ranges) {
stringRep += QString::number(range.first);
if (range.second != range.first)
stringRep += QLatin1Char('-') + QString::number(range.second);
stringRep += QLatin1Char(',');
}
if (!stringRep.isEmpty())
stringRep.remove(stringRep.length() - 1, 1); // Trailing comma.
return stringRep;
}
void addPort(int port);
void addRange(int startPort, int endPort);
bool hasMore() const;
int count() const;
int getNext();
QString toString() const;
private:
typedef QPair<int, int> Range;
QList<Range> m_ranges;
};
class MaemoDeviceConfig
{
friend class MaemoDeviceConfigurations;
......@@ -105,10 +80,9 @@ public:
DeviceType type() const { return m_type; }
QString portsSpec() const { return m_portsSpec; }
bool isDefault() const { return m_isDefault; }
Id internalId() const { return m_internalId; }
static QString portsRegExpr();
static const Id InvalidId = 0;
static const Id InvalidId;
private:
typedef QSharedPointer<MaemoDeviceConfig> Ptr;
......
Supports Markdown
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