@ -19,6 +19,7 @@
# include "GeoIPJSON.h"
# include "utils/CalamaresUtils.h"
# include "utils/Logger.h"
# include "utils/YamlUtils.h"
@ -31,6 +32,24 @@ GeoIPJSON::GeoIPJSON(const QString& attribute)
{
}
static QString
selectMap ( const QVariantMap & m , const QStringList & l , int index )
{
if ( index > = l . count ( ) )
return QString ( ) ;
QString attributeName = l [ index ] ;
if ( index = = l . count ( ) - 1 )
return CalamaresUtils : : getString ( m , attributeName ) ;
else
{
bool success = false ; // bogus
if ( m . contains ( attributeName ) )
return selectMap ( CalamaresUtils : : getSubMap ( m , attributeName , success ) , l , index + 1 ) ;
return QString ( ) ;
}
}
GeoIP : : RegionZonePair
GeoIPJSON : : processReply ( const QByteArray & data )
{
@ -43,12 +62,7 @@ GeoIPJSON::processReply( const QByteArray& data )
var . isValid ( ) & &
var . type ( ) = = QVariant : : Map )
{
QVariantMap map = var . toMap ( ) ;
if ( map . contains ( m_element ) & &
! map . value ( m_element ) . toString ( ) . isEmpty ( ) )
{
return splitTZString ( map . value ( m_element ) . toString ( ) ) ;
}
return splitTZString ( selectMap ( var . toMap ( ) , m_element . split ( ' . ' ) , 0 ) ) ;
}
else
cWarning ( ) < < " Invalid YAML data for GeoIPJSON " ;