libcalamares: handle variants in Python

The Python helpers need a couple of obscure QVariants,
do not add them to the "global" list of compatible variant types.
This commit is contained in:
Adriaan de Groot 2023-09-03 16:51:54 +02:00
parent cdb2eb8b9a
commit 25250179da

View File

@ -11,6 +11,7 @@
#include "PythonHelper.h" #include "PythonHelper.h"
#include "GlobalStorage.h" #include "GlobalStorage.h"
#include "compat/Variant.h"
#include "utils/Dirs.h" #include "utils/Dirs.h"
#include "utils/Logger.h" #include "utils/Logger.h"
@ -29,41 +30,56 @@ variantToPyObject( const QVariant& variant )
#ifdef __clang__ #ifdef __clang__
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wswitch-enum" #pragma clang diagnostic ignored "-Wswitch-enum"
#endif
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
const auto HashVariantType = QVariant::Hash;
const auto IntVariantType = QVariant::Int;
const auto UIntVariantType = QVariant::UInt;
#else
const auto HashVariantType = QMetaType::Type::QVariantHash;
const auto IntVariantType = QMetaType::Type::Int;
const auto UIntVariantType = QMetaType::Type::UInt;
#endif #endif
// 49 enumeration values not handled // 49 enumeration values not handled
switch ( variant.type() ) switch ( Calamares::typeOf( variant ) )
{ {
case QVariant::Map: case Calamares::MapVariantType:
return variantMapToPyDict( variant.toMap() ); return variantMapToPyDict( variant.toMap() );
case QVariant::Hash: case HashVariantType:
return variantHashToPyDict( variant.toHash() ); return variantHashToPyDict( variant.toHash() );
case QVariant::List: case Calamares::ListVariantType:
case QVariant::StringList: case Calamares::StringListVariantType:
return variantListToPyList( variant.toList() ); return variantListToPyList( variant.toList() );
case QVariant::Int: case IntVariantType:
return bp::object( variant.toInt() ); return bp::object( variant.toInt() );
case QVariant::UInt: case UIntVariantType:
return bp::object( variant.toUInt() ); return bp::object( variant.toUInt() );
case QVariant::LongLong: case Calamares::LongLongVariantType:
return bp::object( variant.toLongLong() ); return bp::object( variant.toLongLong() );
case QVariant::ULongLong: case Calamares::ULongLongVariantType:
return bp::object( variant.toULongLong() ); return bp::object( variant.toULongLong() );
case QVariant::Double: case Calamares::DoubleVariantType:
return bp::object( variant.toDouble() ); return bp::object( variant.toDouble() );
case QVariant::Char: case Calamares::CharVariantType:
case QVariant::String: #if QT_VERSION > QT_VERSION_CHECK( 6, 0, 0 )
case QMetaType::Type::QChar:
#endif
case Calamares::StringVariantType:
return bp::object( variant.toString().toStdString() ); return bp::object( variant.toString().toStdString() );
case QVariant::Bool: case Calamares::BoolVariantType:
return bp::object( variant.toBool() ); return bp::object( variant.toBool() );
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
case QVariant::Invalid: case QVariant::Invalid:
#endif
default: default:
return bp::object(); return bp::object();
} }