aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel/src
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2016-10-25 16:50:59 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2016-10-25 16:50:59 +0200
commit6d2076c889b4d914672e2bbfd1c218252b9ed1cf (patch)
tree26a0a54cda65dfcc755b303cfd241b42c6069f18 /libqmenumodel/src
parentd25887f16168be0d55e1b9618fe89815c3edf26c (diff)
downloadqmenumodel-6d2076c889b4d914672e2bbfd1c218252b9ed1cf.tar.gz
qmenumodel-6d2076c889b4d914672e2bbfd1c218252b9ed1cf.tar.bz2
qmenumodel-6d2076c889b4d914672e2bbfd1c218252b9ed1cf.zip
Converter: add support to String Arrays
Diffstat (limited to 'libqmenumodel/src')
-rw-r--r--libqmenumodel/src/converter.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/libqmenumodel/src/converter.cpp b/libqmenumodel/src/converter.cpp
index 1b63272..e2a31c0 100644
--- a/libqmenumodel/src/converter.cpp
+++ b/libqmenumodel/src/converter.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 Canonical Ltd.
+ * Copyright 2012-2016 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@@ -15,6 +15,7 @@
*
* Authors:
* Renato Araujo Oliveira Filho <renato@canonical.com>
+ * Marco Trevisan <marco.trevisan@canonical.com>
*/
extern "C" {
@@ -58,6 +59,14 @@ QVariant Converter::toQVariant(GVariant *value)
gsize size = 0;
const gchar *v = g_variant_get_string(value, &size);
result.setValue(QString::fromUtf8(v, size));
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_STRING_ARRAY)) {
+ gsize size = 0;
+ const gchar **sa = g_variant_get_strv(value, &size);
+ QStringList list;
+ for (gsize i = 0; i < size; ++i) {
+ list << QString::fromUtf8(sa[i]);
+ }
+ result.setValue(list);
} else if (g_variant_type_equal(type, G_VARIANT_TYPE_BYTESTRING)) {
gsize size = 0;
gchar *bs = g_variant_dup_bytestring(value, &size);
@@ -124,7 +133,6 @@ QVariant Converter::toQVariant(GVariant *value)
* G_VARIANT_TYPE_UNIT
* G_VARIANT_TYPE_DICT_ENTRY
* G_VARIANT_TYPE_DICTIONARY
- * G_VARIANT_TYPE_STRING_ARRAY
* G_VARIANT_TYPE_OBJECT_PATH_ARRAY
*/
@@ -238,6 +246,17 @@ GVariant* Converter::toGVariant(const QVariant &value)
g_variant_builder_unref(b);
break;
}
+ case QVariant::StringList:
+ {
+ GVariantBuilder *b = g_variant_builder_new(G_VARIANT_TYPE_STRING_ARRAY);
+
+ for (const QString &s : value.toStringList()) {
+ g_variant_builder_add(b, "s", s.toUtf8().data());
+ }
+ result = g_variant_builder_end(b);
+ g_variant_builder_unref(b);
+ break;
+ }
default:
qWarning() << "QVariant type not supported:" << value.type();
}