Skip to content

Commit

Permalink
Allow access to single variables from deviceinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernd Wachter committed Jun 13, 2013
1 parent d33e96b commit b1a485f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
20 changes: 20 additions & 0 deletions libssu/ssudeviceinfo.cpp
Expand Up @@ -337,6 +337,26 @@ QStringList SsuDeviceInfo::repos(bool rnd, int filter){
return result;
}

QVariant SsuDeviceInfo::variable(QString section, const QString &key){
if (!section.startsWith("var-"))
section = "var-" + section;

if (boardMappings->contains(section + "/" + key)){
return boardMappings->value(section + "/" + key);
}

if (boardMappings->contains(section + "/variables")){
QStringList sections = boardMappings->value(section + "/variables").toStringList();
foreach(const QString &section, sections){
QVariant value = variable(section, key);
if (value.type() != QMetaType::UnknownType)
return value;
}
}

return QVariant();
}

void SsuDeviceInfo::variableSection(QString section, QHash<QString, QString> *storageHash){
if (!section.startsWith("var-"))
section = "var-" + section;
Expand Down
8 changes: 7 additions & 1 deletion libssu/ssudeviceinfo.h
Expand Up @@ -71,12 +71,18 @@ class SsuDeviceInfo: public QObject {
* Override device model autodetection
*/
Q_INVOKABLE void setDeviceModel(QString model="");
/**
* Return a variable from the given variable section. 'var'- is automatically
* prepended to the section name if not specified already. Recursive search
* through several variable sections (specified in the section) is supported,
* returned will be the first occurence of the variable.
*/
QVariant variable(QString section, const QString &key);
/**
* Return the requested variable section. 'var-' is automatically
* prepended to the section name if not specified already.
*/
void variableSection(QString section, QHash<QString, QString> *storageHash);

/**
* Return a value from an adaptation section. Returns an empty string
* or a given default value if key does not exist.
Expand Down

0 comments on commit b1a485f

Please sign in to comment.