From e83b4d33f8b104e30b033c6cfdb2a3b4d567cb67 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 8 Nov 2017 07:40:44 -0500 Subject: [PATCH] [libcalamares] Another convenience config-extraction function --- src/libcalamares/utils/CalamaresUtils.cpp | 12 ++++++++++++ src/libcalamares/utils/CalamaresUtils.h | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/src/libcalamares/utils/CalamaresUtils.cpp b/src/libcalamares/utils/CalamaresUtils.cpp index ae3a14497..75f6eecf3 100644 --- a/src/libcalamares/utils/CalamaresUtils.cpp +++ b/src/libcalamares/utils/CalamaresUtils.cpp @@ -340,6 +340,18 @@ getBool( const QVariantMap& map, const QString& key, bool d ) return result; } +QString +getString(const QVariantMap& map, const QString& key) +{ + if ( map.contains( key ) ) + { + auto v = map.value( key ); + if ( v.type() == QVariant::String ) + return v.toString(); + } + return QString(); +} + QVariantMap getSubMap( const QVariantMap& map, const QString& key, bool& success ) { diff --git a/src/libcalamares/utils/CalamaresUtils.h b/src/libcalamares/utils/CalamaresUtils.h index 651c6746a..1211aac54 100644 --- a/src/libcalamares/utils/CalamaresUtils.h +++ b/src/libcalamares/utils/CalamaresUtils.h @@ -104,6 +104,11 @@ namespace CalamaresUtils */ DLLEXPORT bool getBool( const QVariantMap& map, const QString& key, bool d ); + /** + * Get a string value from a mapping; returns empty QString if no value. + */ + DLLEXPORT QString getString( const QVariantMap& map, const QString& key ); + /** * 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