Extend SystemInfo to allow distinguishing between platforms and variants.

Doing so removes the need to loop over all targets to fill in values for
target variants in ServerInfo.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24427 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dominik Riebeling 2010-01-31 21:57:45 +00:00
parent e953836328
commit ea4130fd2d
4 changed files with 49 additions and 34 deletions

View file

@ -51,33 +51,47 @@ void ServerInfo::readBuildInfo(QString file)
info.beginGroup("release");
QStringList keys = info.allKeys();
for(int i=0; i < keys.size(); i++)
{
setAllConfigPlatformValue(keys[i],ServerInfo::CurReleaseVersion,info.value(keys[i]));
}
info.endGroup();
info.beginGroup("status");
keys = info.allKeys();
for(int i=0; i < keys.size(); i++)
// get base platforms, handle variants with platforms in the loop
QStringList platforms = SystemInfo::platforms(SystemInfo::PlatformBase);
for(int i = 0; i < platforms.size(); i++)
{
switch(info.value(keys[i]).toInt())
// check if there are rbutil-variants of the current platform and handle
// them the same time.
QStringList variants;
variants = SystemInfo::platforms(SystemInfo::PlatformVariant, platforms.at(i));
QVariant release;
info.beginGroup("release");
if(keys.contains(platforms.at(i))) {
release = info.value(platforms.at(i));
}
info.endGroup();
info.beginGroup("status");
QString status = tr("Unknown");
switch(info.value(platforms.at(i)).toInt())
{
case 1:
ServerInfo::setAllConfigPlatformValue(keys[i],ServerInfo::CurStatus,tr("Unusable"));
status = tr("Unusable");
break;
case 2:
ServerInfo::setAllConfigPlatformValue(keys[i],ServerInfo::CurStatus,tr("Unstable"));
status = tr("Unstable");
break;
case 3:
ServerInfo::setAllConfigPlatformValue(keys[i],ServerInfo::CurStatus,tr("Stable"));
status = tr("Stable");
break;
default:
ServerInfo::setAllConfigPlatformValue(keys[i],ServerInfo::CurStatus,tr("Unknown"));
default:
break;
}
info.endGroup();
// set variants (if any)
for(int j = 0; j < variants.size(); ++j) {
setPlatformValue(variants.at(j), ServerInfo::CurStatus, status);
setPlatformValue(variants.at(j), ServerInfo::CurReleaseVersion, release);
}
}
info.endGroup();
}
void ServerInfo::readBleedingInfo(QString file)
@ -121,17 +135,6 @@ void ServerInfo::setPlatformValue(QString platform, enum ServerInfos info, QVari
qDebug() << "[ServerInfo] SET:" << s << serverInfos.value(s).toString();
}
void ServerInfo::setAllConfigPlatformValue(QString configplatform, ServerInfos info, QVariant value)
{
// insert intp all platforms where configurename matches
QStringList platforms = SystemInfo::platforms();
for(int i =0; i < platforms.size(); i++)
{
if(SystemInfo::platformValue(platforms.at(i),SystemInfo::CurConfigureModel) == configplatform)
setPlatformValue(platforms.at(i),info,value);
}
}
QVariant ServerInfo::platformValue(QString platform, enum ServerInfos info)
{
// locate setting item

View file

@ -49,8 +49,6 @@ class ServerInfo : public QObject
static QVariant platformValue(QString platform, enum ServerInfos setting);
private:
//! set a server info to all platforms where configurename matches
static void setAllConfigPlatformValue(QString configplatform,ServerInfos info, QVariant value);
//! set a server info value
static void setValue(enum ServerInfos setting , QVariant value);
//! set a value for a server info for a named platform.

View file

@ -107,7 +107,7 @@ QVariant SystemInfo::platformValue(QString platform, enum SystemInfos info)
return systemInfos->value(s, d);
}
QStringList SystemInfo::platforms()
QStringList SystemInfo::platforms(enum SystemInfo::PlatformType type, QString variant)
{
ensureSystemInfoExists();
@ -117,10 +117,17 @@ QStringList SystemInfo::platforms()
systemInfos->endGroup();
for(int i = 0; i < a.size(); i++)
{
//only add not disabled targets
QString target = systemInfos->value("platforms/"+a.at(i), "null").toString();
if(systemInfos->value(target+"/status").toString() != "disabled")
result.append(target);
// only add target if its not disabled
if(systemInfos->value(target+"/status").toString() == "disabled")
continue;
// report only base targets when PlatformBase is requested
if(type == PlatformBase && target.contains('.'))
continue;
// report only matching target if PlatformVariant is requested
if(type == PlatformVariant && !target.startsWith(variant))
continue;
result.append(target);
}
return result;
}

View file

@ -63,14 +63,21 @@ class SystemInfo : public QObject
CurConfigureModel,
};
enum PlatformType {
PlatformAll,
PlatformBase,
PlatformVariant
};
//! return a list of all platforms (rbutil internal names)
static QStringList platforms(void);
static QStringList platforms(enum PlatformType type = PlatformAll,
QString variant="");
//! returns a list of all languages
static QStringList languages(void);
//! maps a platform to its name
static QString name(QString plattform);
static QString name(QString platform);
//! maps a platform to its brand
static QString brand(QString plattform);
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