aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2016-10-18 15:39:20 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2016-10-18 15:39:20 +0200
commitc42bc210a32f06b2850fbe010be9356d477330b0 (patch)
treec6b02b386ab026be9ec6bfa488c3c13d8e383e68
parente87701e0f2d5f3b7dd291c7b8c62e407b5abf4c7 (diff)
downloadqmenumodel-c42bc210a32f06b2850fbe010be9356d477330b0.tar.gz
qmenumodel-c42bc210a32f06b2850fbe010be9356d477330b0.tar.bz2
qmenumodel-c42bc210a32f06b2850fbe010be9356d477330b0.zip
Converter: add support for ByteArrayList
-rw-r--r--libqmenumodel/src/converter.cpp22
-rw-r--r--tests/client/convertertest.cpp15
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;