Merge lp:~larsu/gsettings-qt/support-ass into lp:gsettings-qt

Proposed by Lars Karlitski on 2015-08-25
Status: Approved
Approved by: Iain Lane on 2015-08-25
Approved revision: 74
Proposed branch: lp:~larsu/gsettings-qt/support-ass
Merge into: lp:gsettings-qt
Diff against target: 98 lines (+40/-0)
3 files modified
src/qconftypes.cpp (+31/-0)
tests/com.canonical.gsettings.test.gschema.xml (+3/-0)
tests/tst_GSettings.qml (+6/-0)
To merge this branch: bzr merge lp:~larsu/gsettings-qt/support-ass
Reviewer Review Type Date Requested Status
Iain Lane 2015-08-25 Approve on 2015-08-25
Review via email: mp+269045@code.launchpad.net

Commit Message

qconftypes: support a(ss)

Expose it as a QVariantList of QStringLists, as that should make using it from qml easiest.

Description of the Change

qconftypes: support a(ss)

Expose it as a QVariantList of QStringLists, as that should make using it from qml easiest.

To post a comment you must log in.
Iain Lane (laney) wrote :

One question which might or might not make sense to fix.

Otherwise, thanks.

review: Approve
Lars Karlitski (larsu) wrote :

> Does it make sense to check for == 1 and save just the first thing?

I don't think so. Invalid values should always be rejected. For example, we also don't accept an array containing one string for a string-typed key (or the other way around).

Unmerged revisions

74. By Lars Karlitski on 2015-08-25

qconftypes: support a(ss)

Expose it as a QVariantList of QStringLists, as that should make using
it from qml easiest.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/qconftypes.cpp'
2--- src/qconftypes.cpp 2014-07-30 10:52:28 +0000
3+++ src/qconftypes.cpp 2015-08-25 11:29:17 +0000
4@@ -54,6 +54,7 @@
5 * string array* as QStringList QVariant::StringList
6 * byte array ay QByteArray QVariant::ByteArray
7 * dictionary a{ss} QVariantMap QVariant::Map
8+ * string tuple array a(ss) QVariantList QVariant::List
9 *
10 * [*] not strictly an array, but called as such for sake of
11 * consistency with the 'a' appearing in the DBus type system
12@@ -110,6 +111,9 @@
13 else if (g_variant_type_equal(gtype, G_VARIANT_TYPE ("a{ss}")))
14 return QVariant::Map;
15
16+ else if (g_variant_type_equal(gtype, G_VARIANT_TYPE ("a(ss)")))
17+ return QVariant::List;
18+
19 // fall through
20 default:
21 return QVariant::Invalid;
22@@ -173,6 +177,17 @@
23 map.insert(key, QVariant(val));
24
25 return map;
26+ } else if (g_variant_is_of_type(value, G_VARIANT_TYPE("a(ss)"))) {
27+ GVariantIter iter;
28+ QVariantList list;
29+ const gchar *first;
30+ const gchar *second;
31+
32+ g_variant_iter_init (&iter, value);
33+ while (g_variant_iter_next (&iter, "(&s&s)", &first, &second))
34+ list.append (QVariant(QStringList() << first << second));
35+
36+ return QVariant(list);
37 }
38
39 // fall through
40@@ -246,6 +261,22 @@
41 }
42 return g_variant_builder_end (&builder);
43 }
44+ if (g_variant_type_equal(gtype, G_VARIANT_TYPE ("a(ss)"))) {
45+ const QVariantList list = v.value<QVariantList>();
46+ GVariantBuilder builder;
47+
48+ g_variant_builder_init(&builder, G_VARIANT_TYPE ("a(ss)"));
49+
50+ Q_FOREACH (const QVariant &vtuple, list) {
51+ QStringList tuple = vtuple.toStringList();
52+ if (tuple.size() == 2)
53+ g_variant_builder_add(&builder, "(ss)", tuple[0].toUtf8().constData(), tuple[1].toUtf8().constData());
54+ else
55+ g_variant_builder_add(&builder, "(ss)", "", "");
56+ }
57+
58+ return g_variant_builder_end(&builder);
59+ }
60
61 // fall through
62 default:
63
64=== modified file 'tests/com.canonical.gsettings.test.gschema.xml'
65--- tests/com.canonical.gsettings.test.gschema.xml 2014-08-01 16:47:07 +0000
66+++ tests/com.canonical.gsettings.test.gschema.xml 2015-08-25 11:29:17 +0000
67@@ -27,5 +27,8 @@
68 <key name="test-map" type="a{ss}">
69 <default>{'foo': 'one', 'bar': 'two'}</default>
70 </key>
71+ <key name="test-ass" type="a(ss)">
72+ <default>[('one', 'two'), ('three', 'four')]</default>
73+ </key>
74 </schema>
75 </schemalist>
76
77=== modified file 'tests/tst_GSettings.qml'
78--- tests/tst_GSettings.qml 2015-06-02 10:10:03 +0000
79+++ tests/tst_GSettings.qml 2015-08-25 11:29:17 +0000
80@@ -38,6 +38,7 @@
81 compare(settings.testString, 'hello');
82 compare(settings.testStringList, ['one', 'two', 'three']);
83 compare(settings.testMap, {'foo': 'one', 'bar': 'two'});
84+ compare(settings.testAss, [['one', 'two'], ['three', 'four']]);
85
86 compare(testCase.bindingTest, 'hello');
87 }
88@@ -65,6 +66,11 @@
89 settings.testMap = {};
90 compare(settings.testMap, {});
91
92+ settings.testAss = []
93+ compare(settings.testAss, [])
94+ settings.testAss = [['foo', 'bar']]
95+ compare(settings.testAss, [['foo', 'bar']])
96+
97 settings.testEnum = 'two';
98 compare(settings.testEnum, 'two');
99

Subscribers

People subscribed via source and target branches

to all changes: