forked from len0rd/rockbox
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
This commit is contained in:
parent
2995c2d265
commit
bfce7eea5c
3 changed files with 23 additions and 57 deletions
|
|
@ -333,9 +333,9 @@ bool Autodetection::detectUsb()
|
||||||
// usbids holds the mapping in the form
|
// usbids holds the mapping in the form
|
||||||
// ((VID<<16)|(PID)), targetname
|
// ((VID<<16)|(PID)), targetname
|
||||||
// the ini file needs to hold the IDs as hex values.
|
// the ini file needs to hold the IDs as hex values.
|
||||||
QMap<int, QString> usbids = settings->usbIdMap();
|
QMap<int, QString> usbids = settings->usbIdMap(RbSettings::MapDevice);
|
||||||
QMap<int, QString> usberror = settings->usbIdErrorMap();
|
QMap<int, QString> usberror = settings->usbIdMap(RbSettings::MapError);
|
||||||
QMap<int, QString> usbincompat = settings->usbIdIncompatMap();
|
QMap<int, QString> usbincompat = settings->usbIdMap(RbSettings::MapIncompatible);
|
||||||
|
|
||||||
// usb pid detection
|
// usb pid detection
|
||||||
QList<uint32_t> attached;
|
QList<uint32_t> attached;
|
||||||
|
|
|
||||||
|
|
@ -388,7 +388,7 @@ QString RbSettings::brand(QString plattform)
|
||||||
return brand;
|
return brand;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<int, QString> RbSettings::usbIdMap()
|
QMap<int, QString> RbSettings::usbIdMap(enum MapType type)
|
||||||
{
|
{
|
||||||
QMap<int, QString> map;
|
QMap<int, QString> map;
|
||||||
// get a list of ID -> target name
|
// get a list of ID -> target name
|
||||||
|
|
@ -397,31 +397,18 @@ QMap<int, QString> RbSettings::usbIdMap()
|
||||||
platforms = devices->childKeys();
|
platforms = devices->childKeys();
|
||||||
devices->endGroup();
|
devices->endGroup();
|
||||||
|
|
||||||
for(int i = 0; i < platforms.size(); i++)
|
QString t;
|
||||||
{
|
switch(type) {
|
||||||
devices->beginGroup("platforms");
|
case MapDevice:
|
||||||
QString target = devices->value(platforms.at(i)).toString();
|
t = "usbid";
|
||||||
devices->endGroup();
|
break;
|
||||||
devices->beginGroup(target);
|
case MapError:
|
||||||
QStringList ids = devices->value("usbid").toStringList();
|
t = "usberror";
|
||||||
int j = ids.size();
|
break;
|
||||||
while(j--)
|
case MapIncompatible:
|
||||||
map.insert(ids.at(j).toInt(0, 16), target);
|
t = "usbincompat";
|
||||||
|
break;
|
||||||
devices->endGroup();
|
|
||||||
}
|
}
|
||||||
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++)
|
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();
|
QString target = devices->value(platforms.at(i)).toString();
|
||||||
devices->endGroup();
|
devices->endGroup();
|
||||||
devices->beginGroup(target);
|
devices->beginGroup(target);
|
||||||
QStringList ids = devices->value("usberror").toStringList();
|
QStringList ids = devices->value(t).toStringList();
|
||||||
int j = ids.size();
|
int j = ids.size();
|
||||||
while(j--)
|
while(j--)
|
||||||
map.insert(ids.at(j).toInt(0, 16), target);
|
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();
|
devices->endGroup();
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,12 @@ class RbSettings : public QObject
|
||||||
// returns the filename of the usersettings file
|
// returns the filename of the usersettings file
|
||||||
QString userSettingFilename();
|
QString userSettingFilename();
|
||||||
|
|
||||||
|
enum MapType {
|
||||||
|
MapDevice,
|
||||||
|
MapError,
|
||||||
|
MapIncompatible,
|
||||||
|
};
|
||||||
|
|
||||||
//! access functions for the settings
|
//! access functions for the settings
|
||||||
QString curVersion();
|
QString curVersion();
|
||||||
bool cacheOffline();
|
bool cacheOffline();
|
||||||
|
|
@ -86,9 +92,7 @@ class RbSettings : public QObject
|
||||||
QString name(QString plattform);
|
QString name(QString plattform);
|
||||||
QString brand(QString plattform);
|
QString brand(QString plattform);
|
||||||
|
|
||||||
QMap<int, QString> usbIdMap();
|
QMap<int, QString> usbIdMap(enum MapType);
|
||||||
QMap<int, QString> usbIdErrorMap();
|
|
||||||
QMap<int, QString> usbIdIncompatMap();
|
|
||||||
|
|
||||||
QString curBrand();
|
QString curBrand();
|
||||||
QString curName();
|
QString curName();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue