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:
Dominik Riebeling 2010-03-01 22:45:17 +00:00
parent f67e3559c6
commit 8c8703038b
3 changed files with 20 additions and 36 deletions

View file

@ -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) QMap<int, QString> SystemInfo::usbIdMap(enum MapType type)
{ {
ensureSystemInfoExists(); ensureSystemInfoExists();

View file

@ -77,10 +77,6 @@ class SystemInfo : public QObject
QString variant=""); QString variant="");
//! returns a list of all languages //! returns a list of all languages
static QStringList languages(void); 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 //! returns a map of usb-ids and their targets
static QMap<int, QString> usbIdMap(enum MapType); static QMap<int, QString> usbIdMap(enum MapType);
//! get a value from system settings //! get a value from system settings

View file

@ -309,20 +309,13 @@ void Config::setDevices()
platformList = SystemInfo::platforms(SystemInfo::PlatformAll); platformList = SystemInfo::platforms(SystemInfo::PlatformAll);
QMap <QString, QString> manuf; QMap <QString, QString> manuf;
QMap <QString, QString> devcs;
for(int it = 0; it < platformList.size(); it++) for(int it = 0; it < platformList.size(); it++)
{ {
QString curname = SystemInfo::name(platformList.at(it)) + QString curbrand = SystemInfo::platformValue(platformList.at(it),
" (" +ServerInfo::platformValue(platformList.at(it), SystemInfo::CurBrand).toString();
ServerInfo::CurStatus).toString() + ")";
QString curbrand = SystemInfo::brand(platformList.at(it));
manuf.insertMulti(curbrand, platformList.at(it)); 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 // set up devices table
ui.treeDevices->header()->hide(); ui.treeDevices->header()->hide();
ui.treeDevices->expandAll(); ui.treeDevices->expandAll();
@ -334,25 +327,28 @@ void Config::setDevices()
QTreeWidgetItem *w; QTreeWidgetItem *w;
QTreeWidgetItem *w2; QTreeWidgetItem *w2;
QTreeWidgetItem *w3 = 0; QTreeWidgetItem *w3 = 0;
QString selected = RbSettings::value(RbSettings::Platform).toString();
for(int c = 0; c < brands.size(); c++) { for(int c = 0; c < brands.size(); c++) {
w = new QTreeWidgetItem(); w = new QTreeWidgetItem();
w->setFlags(Qt::ItemIsEnabled); w->setFlags(Qt::ItemIsEnabled);
w->setText(0, brands.at(c)); w->setText(0, brands.at(c));
items.append(w); items.append(w);
// go through platforms and add all players matching the current brand
// go through platforms again for sake of order
for(int it = 0; it < platformList.size(); it++) { for(int it = 0; it < platformList.size(); it++) {
// skip if not current brand
QString curname = SystemInfo::name(platformList.at(it)) + if(!manuf.values(brands.at(c)).contains(platformList.at(it)))
" (" +ServerInfo::platformValue(platformList.at(it),ServerInfo::CurStatus).toString() +")"; continue;
QString curbrand = SystemInfo::brand(platformList.at(it)); // construct display name
QString curname = SystemInfo::platformValue(platformList.at(it),
if(curbrand != brands.at(c)) continue; SystemInfo::CurName).toString() +
" (" +ServerInfo::platformValue(platformList.at(it),
ServerInfo::CurStatus).toString() +")";
qDebug() << "[Config] add supported device:" << brands.at(c) << curname; qDebug() << "[Config] add supported device:" << brands.at(c) << curname;
w2 = new QTreeWidgetItem(w, QStringList(curname)); w2 = new QTreeWidgetItem(w, QStringList(curname));
w2->setData(0, Qt::UserRole, platformList.at(it)); w2->setData(0, Qt::UserRole, platformList.at(it));
if(platform.contains(curname)) { if(platformList.at(it) == selected) {
w2->setSelected(true); w2->setSelected(true);
w->setExpanded(true); w->setExpanded(true);
w3 = w2; // save pointer to hilight old selection w3 = w2; // save pointer to hilight old selection
@ -369,8 +365,10 @@ void Config::setDevices()
while(widgetitem); while(widgetitem);
// add new items // add new items
ui.treeDevices->insertTopLevelItems(0, items); ui.treeDevices->insertTopLevelItems(0, items);
if(w3 != 0) if(w3 != 0) {
ui.treeDevices->setCurrentItem(w3); // hilight old selection ui.treeDevices->setCurrentItem(w3); // hilight old selection
ui.treeDevices->scrollToItem(w3);
}
// tts / encoder tab // tts / encoder tab
@ -589,7 +587,8 @@ void Config::autodetect()
// find the new item // find the new item
// enumerate all platform items // 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++) for(int i=0; i< itmList.size();i++)
{ {
//enumerate device items //enumerate device items
@ -602,6 +601,7 @@ void Config::autodetect()
itmList.at(i)->child(j)->setSelected(true); //select the item itmList.at(i)->child(j)->setSelected(true); //select the item
itmList.at(i)->setExpanded(true); //expand the platform item itmList.at(i)->setExpanded(true); //expand the platform item
//ui.treeDevices->indexOfTopLevelItem(itmList.at(i)->child(j)); //ui.treeDevices->indexOfTopLevelItem(itmList.at(i)->child(j));
ui.treeDevices->scrollToItem(itmList.at(i)->child(j));
break; break;
} }
} }