mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-09 13:15:18 -05:00
Refactor device tree setup a bit.
- reorder value retrieval (display names etc) to cut down the number of necessary accesses. While this is not critical it cuts down the noise generated in the trace noticably. - match the old target by its internal name instead of the display name. - remove two access functions in SystemInfo that are not really needed anymore. Accessing the values via platformValue() is much more logical and in line with the rest of the value accesses. - try to scroll to the selected item in the device list after setup and detection. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24988 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
f67e3559c6
commit
8c8703038b
3 changed files with 20 additions and 36 deletions
|
|
@ -156,18 +156,6 @@ QStringList SystemInfo::languages()
|
|||
}
|
||||
|
||||
|
||||
QString SystemInfo::name(QString platform)
|
||||
{
|
||||
ensureSystemInfoExists();
|
||||
return systemInfos->value(platform + "/name").toString();
|
||||
}
|
||||
|
||||
QString SystemInfo::brand(QString platform)
|
||||
{
|
||||
ensureSystemInfoExists();
|
||||
return systemInfos->value(platform + "/brand").toString();
|
||||
}
|
||||
|
||||
QMap<int, QString> SystemInfo::usbIdMap(enum MapType type)
|
||||
{
|
||||
ensureSystemInfoExists();
|
||||
|
|
|
|||
|
|
@ -77,10 +77,6 @@ class SystemInfo : public QObject
|
|||
QString variant="");
|
||||
//! returns a list of all languages
|
||||
static QStringList languages(void);
|
||||
//! maps a platform to its name
|
||||
static QString name(QString platform);
|
||||
//! maps a platform to its brand
|
||||
static QString brand(QString platform);
|
||||
//! returns a map of usb-ids and their targets
|
||||
static QMap<int, QString> usbIdMap(enum MapType);
|
||||
//! get a value from system settings
|
||||
|
|
|
|||
|
|
@ -309,20 +309,13 @@ void Config::setDevices()
|
|||
platformList = SystemInfo::platforms(SystemInfo::PlatformAll);
|
||||
|
||||
QMap <QString, QString> manuf;
|
||||
QMap <QString, QString> devcs;
|
||||
for(int it = 0; it < platformList.size(); it++)
|
||||
{
|
||||
QString curname = SystemInfo::name(platformList.at(it)) +
|
||||
" (" +ServerInfo::platformValue(platformList.at(it),
|
||||
ServerInfo::CurStatus).toString() + ")";
|
||||
QString curbrand = SystemInfo::brand(platformList.at(it));
|
||||
QString curbrand = SystemInfo::platformValue(platformList.at(it),
|
||||
SystemInfo::CurBrand).toString();
|
||||
manuf.insertMulti(curbrand, platformList.at(it));
|
||||
devcs.insert(platformList.at(it), curname);
|
||||
}
|
||||
|
||||
QString platform;
|
||||
platform = devcs.value(RbSettings::value(RbSettings::Platform).toString());
|
||||
|
||||
// set up devices table
|
||||
ui.treeDevices->header()->hide();
|
||||
ui.treeDevices->expandAll();
|
||||
|
|
@ -334,25 +327,28 @@ void Config::setDevices()
|
|||
QTreeWidgetItem *w;
|
||||
QTreeWidgetItem *w2;
|
||||
QTreeWidgetItem *w3 = 0;
|
||||
|
||||
QString selected = RbSettings::value(RbSettings::Platform).toString();
|
||||
for(int c = 0; c < brands.size(); c++) {
|
||||
w = new QTreeWidgetItem();
|
||||
w->setFlags(Qt::ItemIsEnabled);
|
||||
w->setText(0, brands.at(c));
|
||||
items.append(w);
|
||||
|
||||
// go through platforms again for sake of order
|
||||
// go through platforms and add all players matching the current brand
|
||||
for(int it = 0; it < platformList.size(); it++) {
|
||||
|
||||
QString curname = SystemInfo::name(platformList.at(it)) +
|
||||
" (" +ServerInfo::platformValue(platformList.at(it),ServerInfo::CurStatus).toString() +")";
|
||||
QString curbrand = SystemInfo::brand(platformList.at(it));
|
||||
|
||||
if(curbrand != brands.at(c)) continue;
|
||||
// skip if not current brand
|
||||
if(!manuf.values(brands.at(c)).contains(platformList.at(it)))
|
||||
continue;
|
||||
// construct display name
|
||||
QString curname = SystemInfo::platformValue(platformList.at(it),
|
||||
SystemInfo::CurName).toString() +
|
||||
" (" +ServerInfo::platformValue(platformList.at(it),
|
||||
ServerInfo::CurStatus).toString() +")";
|
||||
qDebug() << "[Config] add supported device:" << brands.at(c) << curname;
|
||||
w2 = new QTreeWidgetItem(w, QStringList(curname));
|
||||
w2->setData(0, Qt::UserRole, platformList.at(it));
|
||||
|
||||
if(platform.contains(curname)) {
|
||||
if(platformList.at(it) == selected) {
|
||||
w2->setSelected(true);
|
||||
w->setExpanded(true);
|
||||
w3 = w2; // save pointer to hilight old selection
|
||||
|
|
@ -369,8 +365,10 @@ void Config::setDevices()
|
|||
while(widgetitem);
|
||||
// add new items
|
||||
ui.treeDevices->insertTopLevelItems(0, items);
|
||||
if(w3 != 0)
|
||||
if(w3 != 0) {
|
||||
ui.treeDevices->setCurrentItem(w3); // hilight old selection
|
||||
ui.treeDevices->scrollToItem(w3);
|
||||
}
|
||||
|
||||
// tts / encoder tab
|
||||
|
||||
|
|
@ -589,7 +587,8 @@ void Config::autodetect()
|
|||
|
||||
// find the new item
|
||||
// enumerate all platform items
|
||||
QList<QTreeWidgetItem*> itmList= ui.treeDevices->findItems("*",Qt::MatchWildcard);
|
||||
QList<QTreeWidgetItem*> itmList
|
||||
= ui.treeDevices->findItems("*",Qt::MatchWildcard);
|
||||
for(int i=0; i< itmList.size();i++)
|
||||
{
|
||||
//enumerate device items
|
||||
|
|
@ -602,6 +601,7 @@ void Config::autodetect()
|
|||
itmList.at(i)->child(j)->setSelected(true); //select the item
|
||||
itmList.at(i)->setExpanded(true); //expand the platform item
|
||||
//ui.treeDevices->indexOfTopLevelItem(itmList.at(i)->child(j));
|
||||
ui.treeDevices->scrollToItem(itmList.at(i)->child(j));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue