diff options
-rw-r--r-- | libqmenumodel/src/converter.cpp | 22 | ||||
-rw-r--r-- | tests/client/convertertest.cpp | 15 |
2 files changed, 36 insertions, 1 deletions
diff --git a/libqmenumodel/src/converter.cpp b/libqmenumodel/src/converter.cpp index 91cafab..9fd65ed 100644 --- a/libqmenumodel/src/converter.cpp +++ b/libqmenumodel/src/converter.cpp @@ -63,6 +63,15 @@ QVariant Converter::toQVariant(GVariant *value) gchar *bs = g_variant_dup_bytestring(value, &size); result.setValue(QByteArray::fromRawData(bs, size)); g_free(bs); + } else if (g_variant_type_equal(type, G_VARIANT_TYPE_BYTESTRING_ARRAY)) { + gsize size = 0; + const gchar **bsa = g_variant_get_bytestring_array(value, &size); + QByteArrayList list; + for (gsize i = 0; i < size; ++i) { + list << bsa[i]; + } + result.setValue(list); + g_free(bsa); } else if (g_variant_type_equal(type, G_VARIANT_TYPE_VARIANT)) { GVariant *var = g_variant_get_variant(value); result = toQVariant(var); @@ -117,7 +126,6 @@ QVariant Converter::toQVariant(GVariant *value) * G_VARIANT_TYPE_DICTIONARY * G_VARIANT_TYPE_STRING_ARRAY * G_VARIANT_TYPE_OBJECT_PATH_ARRAY - * G_VARIANT_TYPE_BYTESTRING_ARRAY */ return result; @@ -211,6 +219,18 @@ GVariant* Converter::toGVariant(const QVariant &value) g_variant_builder_unref(b); break; } + case QMetaType::QByteArrayList: + { + const QByteArrayList &list = qvariant_cast<QByteArrayList>(value); + GVariantBuilder *b = g_variant_builder_new(G_VARIANT_TYPE_BYTESTRING_ARRAY); + + for (const QByteArray &ba : list) { + g_variant_builder_add_value(b, g_variant_new_bytestring(ba)); + } + result = g_variant_builder_end(b); + g_variant_builder_unref(b); + break; + } case QVariant::List: { QVariantList lst = value.toList(); diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp index e61caa0..933ed2f 100644 --- a/tests/client/convertertest.cpp +++ b/tests/client/convertertest.cpp @@ -163,6 +163,14 @@ private Q_SLOTS: QVERIFY(compare(QVariant(QByteArray("42")), G_VARIANT_TYPE_BYTESTRING)); } + void testByteArrayListToGVariant() + { + // ByteArrayList + QVariant result; + result.setValue(QByteArrayList({"42", "53"})); + QVERIFY(compare(result, G_VARIANT_TYPE_BYTESTRING_ARRAY)); + } + void testMapToGVariant() { // Map @@ -235,6 +243,13 @@ private Q_SLOTS: QVERIFY(compare(g_variant_new_bytestring("53"), QVariant::ByteArray)); } + void testByteArrayListToQVariant() + { + // ByteArrayList + const gchar * byteArray[] = {"42", "53", NULL}; + QVERIFY(compare(g_variant_new_bytestring_array(byteArray, -1), QMetaType::QByteArrayList)); + } + void testTupleConversion() { QVariantList qTuple; |