summaryrefslogtreecommitdiff
path: root/rbutil
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2009-04-16 20:49:43 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2009-04-16 20:49:43 +0000
commitbfce7eea5c0d43c9f2cd84cd325bbcc1949102e3 (patch)
treeac926f8a844d2706cb01323d80fb42b2a8f24898 /rbutil
parent2995c2d265e4e6b2c07a88023bbd7635ae7cb9e9 (diff)
Refactor USB ID map retrieval from device settings file and minimize duplicated code.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20716 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil')
-rw-r--r--rbutil/rbutilqt/base/autodetection.cpp6
-rw-r--r--rbutil/rbutilqt/rbsettings.cpp64
-rw-r--r--rbutil/rbutilqt/rbsettings.h10
3 files changed, 23 insertions, 57 deletions
diff --git a/rbutil/rbutilqt/base/autodetection.cpp b/rbutil/rbutilqt/base/autodetection.cpp
index aa74419ce0..ee42a8c09e 100644
--- a/rbutil/rbutilqt/base/autodetection.cpp
+++ b/rbutil/rbutilqt/base/autodetection.cpp
@@ -333,9 +333,9 @@ bool Autodetection::detectUsb()
// usbids holds the mapping in the form
// ((VID<<16)|(PID)), targetname
// the ini file needs to hold the IDs as hex values.
- QMap<int, QString> usbids = settings->usbIdMap();
- QMap<int, QString> usberror = settings->usbIdErrorMap();
- QMap<int, QString> usbincompat = settings->usbIdIncompatMap();
+ QMap<int, QString> usbids = settings->usbIdMap(RbSettings::MapDevice);
+ QMap<int, QString> usberror = settings->usbIdMap(RbSettings::MapError);
+ QMap<int, QString> usbincompat = settings->usbIdMap(RbSettings::MapIncompatible);
// usb pid detection
QList<uint32_t> attached;
diff --git a/rbutil/rbutilqt/rbsettings.cpp b/rbutil/rbutilqt/rbsettings.cpp
index 909dba4951..560b9ab5fc 100644
--- a/rbutil/rbutilqt/rbsettings.cpp
+++ b/rbutil/rbutilqt/rbsettings.cpp
@@ -388,7 +388,7 @@ QString RbSettings::brand(QString plattform)
return brand;
}
-QMap<int, QString> RbSettings::usbIdMap()
+QMap<int, QString> RbSettings::usbIdMap(enum MapType type)
{
QMap<int, QString> map;
// get a list of ID -> target name
@@ -397,31 +397,18 @@ QMap<int, QString> RbSettings::usbIdMap()
platforms = devices->childKeys();
devices->endGroup();
- for(int i = 0; i < platforms.size(); i++)
- {
- devices->beginGroup("platforms");
- QString target = devices->value(platforms.at(i)).toString();
- devices->endGroup();
- devices->beginGroup(target);
- QStringList ids = devices->value("usbid").toStringList();
- int j = ids.size();
- while(j--)
- map.insert(ids.at(j).toInt(0, 16), target);
-
- devices->endGroup();
+ QString t;
+ switch(type) {
+ case MapDevice:
+ t = "usbid";
+ break;
+ case MapError:
+ t = "usberror";
+ break;
+ case MapIncompatible:
+ t = "usbincompat";
+ break;
}
- return map;
-}
-
-QMap<int, QString> RbSettings::usbIdErrorMap()
-{
-
- QMap<int, QString> map;
- // get a list of ID -> target name
- QStringList platforms;
- devices->beginGroup("platforms");
- platforms = devices->childKeys();
- devices->endGroup();
for(int i = 0; i < platforms.size(); i++)
{
@@ -429,36 +416,11 @@ QMap<int, QString> RbSettings::usbIdErrorMap()
QString target = devices->value(platforms.at(i)).toString();
devices->endGroup();
devices->beginGroup(target);
- QStringList ids = devices->value("usberror").toStringList();
+ QStringList ids = devices->value(t).toStringList();
int j = ids.size();
while(j--)
map.insert(ids.at(j).toInt(0, 16), target);
- devices->endGroup();
- }
- return map;
-}
-
-
-QMap<int, QString> RbSettings::usbIdIncompatMap()
-{
-
- QMap<int, QString> map;
- // get a list of ID -> target name
- QStringList platforms;
- devices->beginGroup("platforms");
- platforms = devices->childKeys();
- devices->endGroup();
- for(int i = 0; i < platforms.size(); i++)
- {
- devices->beginGroup("platforms");
- QString target = devices->value(platforms.at(i)).toString();
- devices->endGroup();
- devices->beginGroup(target);
- QStringList ids = devices->value("usbincompat").toStringList();
- int j = ids.size();
- while(j--)
- map.insert(ids.at(j).toInt(0, 16), target);
devices->endGroup();
}
return map;
diff --git a/rbutil/rbutilqt/rbsettings.h b/rbutil/rbutilqt/rbsettings.h
index c785061ee8..339c835d4a 100644
--- a/rbutil/rbutilqt/rbsettings.h
+++ b/rbutil/rbutilqt/rbsettings.h
@@ -41,6 +41,12 @@ class RbSettings : public QObject
// returns the filename of the usersettings file
QString userSettingFilename();
+ enum MapType {
+ MapDevice,
+ MapError,
+ MapIncompatible,
+ };
+
//! access functions for the settings
QString curVersion();
bool cacheOffline();
@@ -86,9 +92,7 @@ class RbSettings : public QObject
QString name(QString plattform);
QString brand(QString plattform);
- QMap<int, QString> usbIdMap();
- QMap<int, QString> usbIdErrorMap();
- QMap<int, QString> usbIdIncompatMap();
+ QMap<int, QString> usbIdMap(enum MapType);
QString curBrand();
QString curName();