[libcalamares] Provide some convenience functions for extracting configuration data
This commit is contained in:
parent
2d31e987c0
commit
f3eb557fdb
@ -326,5 +326,35 @@ crash()
|
|||||||
*a = 1;
|
*a = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
getBool( const QVariantMap& map, const QString& key, bool d )
|
||||||
|
{
|
||||||
|
bool result = d;
|
||||||
|
if ( map.contains( key ) )
|
||||||
|
{
|
||||||
|
auto v = map.value( key );
|
||||||
|
if ( v.type() == QVariant::Bool )
|
||||||
|
result = v.toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantMap
|
||||||
|
getSubMap( const QVariantMap& map, const QString& key, bool& success )
|
||||||
|
{
|
||||||
|
success = false;
|
||||||
|
|
||||||
|
if ( map.contains( key ) )
|
||||||
|
{
|
||||||
|
auto v = map.value( key );
|
||||||
|
if ( v.type() == QVariant::Map )
|
||||||
|
{
|
||||||
|
success = true;
|
||||||
|
return v.toMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QVariantMap();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,22 @@ namespace CalamaresUtils
|
|||||||
* @brief crash makes Calamares crash immediately.
|
* @brief crash makes Calamares crash immediately.
|
||||||
*/
|
*/
|
||||||
DLLEXPORT void crash();
|
DLLEXPORT void crash();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a bool value from a mapping with a given key; returns the default
|
||||||
|
* if no value is stored in the map.
|
||||||
|
*/
|
||||||
|
DLLEXPORT bool getBool( const QVariantMap& map, const QString& key, bool d );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a sub-map (i.e. a nested map) from the given mapping with the
|
||||||
|
* given key. @p success is set to true if the @p key exists
|
||||||
|
* in @p map and converts to a map, false otherwise.
|
||||||
|
*
|
||||||
|
* Returns an empty map if there is no such key or it is not a map-value.
|
||||||
|
* (e.g. if @p success is false).
|
||||||
|
*/
|
||||||
|
DLLEXPORT QVariantMap getSubMap( const QVariantMap& map, const QString& key, bool& success );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CALAMARESUTILS_H
|
#endif // CALAMARESUTILS_H
|
||||||
|
Loading…
Reference in New Issue
Block a user