This repository has been archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
template_qml.go
671 lines (624 loc) · 21.8 KB
/
template_qml.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
/**
* Copyright (C) 2015 Deepin Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
**/
package main
import "fmt"
import "log"
import "os"
import "os/exec"
import "path"
import "strings"
import "text/template"
import "pkg.deepin.io/lib/dbus/introspect"
var __IFC_TEMPLATE_INIT_QML = `/*This file is auto generate by pkg.deepin.io/dbus-generator. Don't edit it*/
#include <QtDBus>
QVariant unmarsh(const QVariant&);
QVariant marsh(QDBusArgument target, const QVariant& arg, const QString& sig);
QVariant translateI18n(const char* dir, const char* domain, const QVariant v);
`
var __IFC_TEMPLATE_QML = `
#ifndef __{{ExportName}}_H__
#define __{{ExportName}}_H__
class {{ExportName}}Proxyer: public QDBusAbstractInterface
{
Q_OBJECT
public:
{{ExportName}}Proxyer(const QString &path, QObject* parent)
:QDBusAbstractInterface("{{DestName}}", path, "{{IfcName}}", QDBusConnection::{{BusType}}Bus(), parent)
{
if (!isValid()) {
qDebug() << "Create {{ExportName}} remote object failed : " << lastError().message();
}
}
QVariant fetchProperty(const char* name) {
QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(),
QLatin1String("org.freedesktop.DBus.Properties"),
QLatin1String("Get"));
msg << interface() << QString::fromUtf8(name);
QDBusMessage reply = connection().call(msg, QDBus::Block, timeout());
if (reply.type() != QDBusMessage::ReplyMessage) {
qDebug () << QDBusError(reply) << "at " << service() << path() << interface() << name;
return QVariant();
}
if (reply.signature() != QLatin1String("v")) {
QString errmsg = QLatin1String("Invalid signature org.freedesktop.DBus.Propertyies in return from call to ");
qDebug () << QDBusError(QDBusError::InvalidSignature, errmsg.arg(reply.signature()));
return QVariant();
}
QVariant value = qvariant_cast<QDBusVariant>(reply.arguments().at(0)).variant();
return value;
}
{{range .Properties}}
Q_PROPERTY(QDBusVariant {{.Name}} READ __get_{{.Name}}__ {{if PropWritable .}}WRITE __set_{{.Name}}__{{end}})
QDBusVariant __get_{{.Name}}__() { return QDBusVariant(fetchProperty("{{.Name}}")); }
{{if PropWritable .}}void __set_{{.Name}}__(const QDBusVariant &v) { setProperty("{{.Name}}", QVariant::fromValue(v)); }{{end}}
{{end}}
Q_SIGNALS:{{range .Signals}}
void {{.Name}}({{range $i, $e := .Args}}{{if ne $i 0}},{{end}}{{getQType $e.Type}} {{$e.Name}}{{end}});{{end}}
};
class {{ExportName}} : public QObject
{
Q_OBJECT
private:
QString m_path;
Q_SLOT void _propertiesChanged(const QDBusMessage &msg) {
QList<QVariant> arguments = msg.arguments();
if (3 != arguments.count())
return;
QString interfaceName = msg.arguments().at(0).toString();
if (interfaceName != "{{IfcName}}")
return;
QVariantMap changedProps = qdbus_cast<QVariantMap>(arguments.at(1).value<QDBusArgument>());
foreach(const QString &prop, changedProps.keys()) {
if (0) { {{range .Properties}}
} else if (prop == "{{.Name}}") {
Q_EMIT __{{Lower .Name}}Changed__(unmarsh(changedProps.value(prop)));{{end}}
}
}
}
void _rebuild()
{
delete m_ifc;
m_ifc = new {{ExportName}}Proxyer(m_path, this);
_setupSignalHandle();
}
void _setupSignalHandle() {
{{range .Signals}}
QObject::connect(m_ifc, SIGNAL({{.Name}}({{range $i, $e := .Args}}{{if ne $i 0}},{{end}}{{getQType $e.Type}}{{end}})),
this, SIGNAL({{Lower .Name}}({{range $i, $e := .Args}}{{if ne $i 0}},{{end}}{{getQType $e.Type}}{{end}})));
{{end}}
}
public:
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
const QString path() {
return m_path;
}
void setPath(const QString& path) {
QDBusConnection::{{BusType}}Bus().disconnect("{{DestName}}", m_path, "org.freedesktop.DBus.Properties", "PropertiesChanged",
this, SLOT(_propertiesChanged(QDBusMessage)));
m_path = path;
QDBusConnection::{{BusType}}Bus().connect("{{DestName}}", m_path, "org.freedesktop.DBus.Properties", "PropertiesChanged",
"sa{sv}as", this, SLOT(_propertiesChanged(QDBusMessage)));
_rebuild();
}
Q_SIGNAL void pathChanged(QString);
{{ExportName}}(QObject *parent=0) : QObject(parent), m_ifc(new {{ExportName}}Proxyer("{{Ifc2Obj IfcName}}", this))
{
_setupSignalHandle();
QDBusConnection::{{BusType}}Bus().connect("{{DestName}}", m_path, "org.freedesktop.DBus.Properties", "PropertiesChanged",
"sa{sv}as", this, SLOT(_propertiesChanged(QDBusMessage)));
}
{{range .Properties}}
Q_PROPERTY(QVariant {{Lower .Name}} READ __get_{{.Name}}__ {{if PropWritable .}}WRITE __set_{{.Name}}__{{end}} NOTIFY __{{Lower .Name}}Changed__){{end}}
//Property read methods{{range .Properties}}
const QVariant __get_{{.Name}}__() { return unmarsh(m_ifc->__get_{{.Name}}__().variant()); }{{end}}
//Property set methods :TODO check access{{range .Properties}}{{if PropWritable .}}
void __set_{{.Name}}__(const QVariant &v) {
QVariant marshedValue = marsh(QDBusArgument(), v, "{{.Type}}");
m_ifc->__set_{{.Name}}__(QDBusVariant(marshedValue));
Q_EMIT __{{Lower .Name}}Changed__(marshedValue);
}{{end}}{{end}}
public Q_SLOTS:{{range .Methods}} {{$outs := GetOuts .Args}} {{$ins := GetIns .Args}}
QVariant {{.Name}}({{range $i, $e := $ins}}{{if ne $i 0}}, {{end}}const QVariant &{{.Name}}{{end}}) {
QList<QVariant> argumentList;
argumentList{{range $ins}} << marsh(QDBusArgument(), {{.Name}}, "{{.Type}}"){{end}};
QDBusPendingReply<> call = m_ifc->asyncCallWithArgumentList(QLatin1String("{{.Name}}"), argumentList);
call.waitForFinished();
if (!call.isValid()) {
qDebug() << "Error at {{IfcName}}.{{.Name}}:" << call.error().message();
return QVariant();
}
QList<QVariant> args = call.reply().arguments();
{{ if eq (len $outs ) 0 }}
return QVariant();
{{ else if eq (len $outs) 1 }}
if (args.size() != 1) {
qDebug() << "Warning: \"{{IfcName}}.{{.Name}}\" excepted one output parameter, but got " << args.size();
return QVariant();
}
return {{QMLI18nWrapper (index $outs 0) "unmarsh(args[0])"}};
{{ else }}
if (args.size() != {{len $outs}}) {
qDebug() << "Warning: \"{{IfcName}}.{{.Name}}\" excepted {{len $outs}} output parameters, but got " << args.size();
return QVariant();
}
{{ range $i, $arg := $outs }}
args[{{$i}}] = {{QMLI18nWrapper $arg (printf "unmarsh(args[%d])" $i)}};
{{end}}
return args;
{{end}}
}
{{end}}
Q_SIGNALS:
//Property changed notify signal{{range .Properties}}
void __{{Lower .Name}}Changed__(QVariant);{{end}}
//DBus Interface's signal{{range .Signals}}
void {{Lower .Name}}({{range $i, $e := .Args}}{{if ne $i 0}},{{end}}{{getQType $e.Type}} {{$e.Name}}{{end}});{{end}}
private:
{{ExportName}}Proxyer *m_ifc;
};
#endif
`
var __GLOBAL_TEMPLATE_QML = `
#ifndef __DBUS_H__
#define __DBUS_H__
{{range GetModules}}
#include "{{.}}.h"{{end}}
#include <QQmlExtensionPlugin>
#include <qqml.h>
class DBusPlugin: public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "com.deepin.dde.daemon.DBus")
public:
void registerTypes(const char* uri) { {{range .Interfaces}}
qmlRegisterType<{{.ObjectName}}>(uri, 1, 0, "{{.ObjectName}}");{{end}}
}
};
#include <libintl.h>
QVariant translateI18n(const char* dir, const char* domain, const QVariant v)
{
if (v.type() != QMetaType::QString) {
return v;
}
bindtextdomain(domain, dir);
return QVariant::fromValue<QString>(dgettext(domain, v.toString().toLocal8Bit()));
}
` + _templateMarshUnMarsh + `
#endif
`
var __PROJECT_TEMPL_QML = `
TEMPLATE=lib
CONFIG += plugin
QT += qml dbus
TARGET = {{PkgName}}
DESTDIR = lib
OBJECTS_DIRS = tmp
MOC_DIR = tmp
HEADERS += plugin.h {{range GetModules}}{{.}}.h {{end}}
test.depends = lib/$(TARGET)
test.commands = (qmlscene -I . test.qml)
QMAKE_EXTRA_TARGETS += test
`
var __TEST_QML = `
import {{PkgName}} 1.0
import QtQuick 2.0
import QtQuick.Controls 1.0
Item { {{range .Interfaces}}
{{.ObjectName}} {
id: "{{Lower .ObjectName}}ID"
// path: "{{Ifc2Obj .Interface}}"
} {{end}}
width: 400; height: 400
TabView {
anchors.fill : parent
{{range .Interfaces}}
Tab { {{$ifc := GetInterfaceInfo .}} {{$objName := Lower .ObjectName }}
title: "{{.ObjectName}}"
Column {
{{range $ifc.Properties}}
Row {
Label {
text: "{{.Name}}:"
}
Text {
text: JSON.stringify({{$objName}}ID.{{Lower .Name}})
}
}{{end}}
}
}
{{end}}
}
}
`
func renderQMLProject(outputDir string, infos *Infos) {
writer, err := os.Create(path.Join(outputDir, "tt.pro"))
if err != nil {
panic(err)
}
template.Must(template.New("main").Funcs(template.FuncMap{
"BusType": func() string { return infos.BusType() },
"PkgName": func() string { return infos.PackageName() },
"GetModules": func() map[string]string {
r := make(map[string]string)
for _, ifc := range infos.ListInterfaces() {
r[ifc.OutFile] = ifc.OutFile
}
return r
},
}).Parse(__PROJECT_TEMPL_QML)).Execute(writer, infos)
writer.Close()
renderTestQML(infos)
}
func renderTestQML(infos *Infos) {
pkgName := infos.PackageName()
if pkgName == "" {
pkgName = getQMLPkgName("DBus." + infos.DestName())
}
os.MkdirAll(infos.OutputDir()+"/"+strings.Replace(pkgName, ".", "/", -1), 0755)
cmd_str := fmt.Sprintf("cd %s && ln -sv %s lib && qmake", infos.OutputDir(), strings.Replace(pkgName, ".", "/", -1))
cmd := exec.Command("bash", "-c", cmd_str)
err := cmd.Run()
if err != nil {
log.Fatal("Run: " + cmd_str + " failed(Did you have an valid qmake?) testQML code will not generated!")
}
qmldir, err := os.Create(path.Join(infos.OutputDir(), "lib", "qmldir"))
if err != nil {
panic(err)
}
moduleName := "DBus"
for _, f := range strings.Split(infos.DestName(), ".") {
moduleName += "." + upper(f)
}
qmldir.WriteString("module " + moduleName + "\n")
qmldir.WriteString("plugin " + infos.PackageName())
qmldir.Close()
writer, err := os.Create(path.Join(infos.OutputDir(), "test.qml"))
if err != nil {
panic(err)
}
template.Must(template.New("qmltest").Funcs(template.FuncMap{
"Lower": lower,
"GetInterfaceInfo": func(ifc _Interface) introspect.InterfaceInfo { return GetInterfaceInfo(infos.InputDir(), ifc) },
"BusType": func() string { return infos.BusType() },
"PkgName": func() string { return pkgName },
"Ifc2Obj": ifc2obj,
"GetModules": func() map[string]string {
r := make(map[string]string)
for _, ifc := range infos.ListInterfaces() {
r[ifc.OutFile] = ifc.OutFile
}
return r
},
}).Parse(__TEST_QML)).Execute(writer, infos)
}
func qtPropertyFilter(s string) string {
s = strings.TrimSpace(s)
if strings.HasPrefix(s, "QMap") {
return "QVariantMap"
} else if strings.HasPrefix(s, "QList") {
return "QVariantList"
} else if strings.HasPrefix(s, "QValueList") {
return "QVariantValueList"
}
return s
}
var sigToQtType = map[string]string{
"y": "uchar",
"b": "bool",
"n": "short",
"q": "ushort",
"i": "int",
"u": "uint",
"x": "qlonglong",
"t": "qulonglong",
"d": "double",
"s": "QString",
"g": "QDBusVariant",
"o": "QDBusObjectPath",
"v": "QDBusSignature",
"h": "uint",
}
func getQtSignaturesType(info *Infos) map[string]string {
sigs := make(map[string]string)
var store func(string)
store = func(sig string) {
if v, ok := sigToQtType[sig]; ok {
sigs[sig] = v
} else if sig == "as" {
sigs[sig] = "QStringList"
} else if sig == "so" {
fmt.Println("Warning: `so` isn't supported")
sigs[sig] = "QStringList"
} else if sig[0] == 'a' {
if sig[1] == '(' {
sigs[sig] = "QVariantList"
} else if sig[1] == '{' {
if len(sig) < 5 { // a{xx} has at least five characters
return
}
store(sig[2:3])
store(sig[3:strings.LastIndex(sig, "}")])
sigs[sig] = "QVariantMap"
} else {
store(sig[1:])
sigs[sig] = "QList< " + sigs[sig[1:]] + " >"
}
} else if sig[0] == '(' {
sigs[sig] = "QVariantList"
} else {
panic(fmt.Sprintf("parse signature failed:%q\n", sig))
}
}
for _, ifc := range info.ListInterfaces() {
info := GetInterfaceInfo(info.InputDir(), ifc)
for _, m := range info.Methods {
for _, a := range m.Args {
store(a.Type)
}
}
for _, p := range info.Properties {
store(p.Type)
}
for _, s := range info.Signals {
for _, ss := range s.Args {
store(ss.Type)
}
}
}
return sigs
}
var _templateMarshUnMarsh = `
inline
int getTypeId(const QString& sig) {
//TODO: this should staticly generate by xml info
if (0) { {{ range $key, $value := GetQtSignaturesType }}
} else if (sig == "{{$key}}") {
return qDBusRegisterMetaType<{{$value}} >();{{end}}
} else if (sig == "(iiii)") {
return qDBusRegisterMetaType<QRect>();
} else {
qDebug() << "Didn't support getTypeId" << sig << " please report it to [email protected]";
}
}
inline
QVariant qstring2dbus(QString value, char sig) {
switch (sig) {
case 'y':
return QVariant::fromValue(uchar(value[0].toLatin1()));
case 'n':
return QVariant::fromValue(value.toShort());
case 'q':
return QVariant::fromValue(value.toUShort());
case 'i':
return QVariant::fromValue(value.toInt());
case 'u':
return QVariant::fromValue(value.toUInt());
case 'x':
return QVariant::fromValue(value.toLongLong());
case 't':
return QVariant::fromValue(value.toULongLong());
case 'd':
return QVariant::fromValue(value.toDouble());
case 's':
return QVariant::fromValue(value);
case 'o':
return QVariant::fromValue(QDBusObjectPath(value));
case 'v':
return QVariant::fromValue(QDBusSignature(value));
default:
qDebug() << "Dict entry key should be an basic dbus type not an " << sig;
return QVariant();
}
}
QList<QString> splitStructureSignature(const QString& sig) {
if (sig.size() < 3 || sig[0] != '(' || sig[sig.size()-1] != ')') {
return QList<QString>();
}
QList<QString> sigs;
QString tmp = sig.mid(1, sig.size()-2);
while (tmp.size() != 0) {
switch (tmp[0].toLatin1()) {
case 'a':
if (tmp.size() < 2) {
return QList<QString>();
}
if (tmp[1] == '{') {
int lastIndex = tmp.lastIndexOf('}') + 1;
if (lastIndex == 0) return QList<QString>();
sigs.append(tmp.mid(0, lastIndex));
tmp = tmp.mid(lastIndex);
break;
} else if (tmp[1] == '(') {
int lastIndex = tmp.lastIndexOf(')') + 1;
if (lastIndex == 0) return QList<QString>();
sigs.append(tmp.mid(0, lastIndex));
tmp = tmp.mid(lastIndex);
break;
} else {
sigs.append(tmp.mid(0, 2));
tmp = tmp.mid(2);
break;
}
case '(': {
int lastIndex = tmp.lastIndexOf(')') + 1;
if (lastIndex == 0) return QList<QString>();
sigs.append(tmp.mid(0, lastIndex));
tmp = tmp.mid(lastIndex);
break;
}
case 'y': case 'b': case 'n': case 'q':
case 'i': case 'u': case 'x': case 't':
case 'd': case 's': case 'o': case 'g':
case 'h': case 'v':
sigs.append(QString(tmp[0]));
tmp = tmp.mid(1, tmp.size() - 1);
break;
default:
return QList<QString>();
}
}
return sigs;
}
QVariant marsh(QDBusArgument target, const QVariant& arg, const QString& sig) {
if (sig.size() == 0) {
return QVariant::fromValue(target);
}
switch (sig[0].toLatin1()) {
case 'y':
target << qstring2dbus(arg.value<QString>(), 'y').value<uchar>();
return QVariant::fromValue(target);
case 'b':
target << arg.value<bool>();
return QVariant::fromValue(target);
case 'n':
target << arg.value<short>();
return QVariant::fromValue(target);
case 'q':
target << arg.value<ushort>();
return QVariant::fromValue(target);
case 'i':
target << arg.value<qint32>();
return QVariant::fromValue(target);
case 'u':
target << arg.value<quint32>();
return QVariant::fromValue(target);
case 'x':
target << arg.value<qlonglong>();
return QVariant::fromValue(target);
case 't':
target << arg.value<qulonglong>();
return QVariant::fromValue(target);
case 'd':
target << arg.value<double>();
return QVariant::fromValue(target);
case 's':
target << arg.value<QString>();
return QVariant::fromValue(target);
case 'o':
target << QDBusObjectPath(arg.value<QString>());
return QVariant::fromValue(target);
case 'g':
target << QDBusSignature(arg.value<QString>());
return QVariant::fromValue(target);
case 'a':
{
if (sig.size() < 2) { return QVariant(); }
char s = sig[1].toLatin1();
if (s == '{') {
char key_sig = sig[2].toLatin1();
QString value_sig = sig.mid(3, sig.lastIndexOf('}') - 3);
target.beginMap(getTypeId(QString(key_sig)), getTypeId(value_sig));
//qDebug() << "BeginMap:" << key_sig << value_sig;
foreach(const QString& key, arg.value<QVariantMap>().keys()) {
//qDebug() << "KEY:" << key;
target.beginMapEntry();
//qDebug() <<"beginMapEntry";
marsh(target, qstring2dbus(key, key_sig), QString(key_sig));
marsh(target, arg.value<QVariantMap>()[key], value_sig);
//qDebug() <<"EndMapEntry";
target.endMapEntry();
}
//qDebug() << "EndMap";
target.endMap();
return QVariant::fromValue(target);
} else {
QString next = sig.right(sig.size() - 1);
target.beginArray(getTypeId(next));
foreach(const QVariant& v, arg.value<QVariantList>()) {
marsh(target, v, next);
}
target.endArray();
return QVariant::fromValue(target);
}
}
case '(':
{
QList<QString> sigs = splitStructureSignature(sig);
QVariantList values = arg.value<QVariantList>();
if (values.size() != sigs.size()) {
qDebug() << "structure (" << arg << ") didn't match signature :" << sigs;
return QVariant();
}
target.beginStructure();
for (int i=0; i < sigs.size(); i++) {
marsh(target, values[i], sigs[i]);
}
target.endStructure();
return QVariant::fromValue(target);
}
default:
qDebug() << "Panic didn't support marsh" << sig;
}
return QVariant::fromValue(target);
}
inline
QVariant unmarshDBus(const QDBusArgument &argument)
{
switch (argument.currentType()) {
case QDBusArgument::BasicType: {
QVariant v = argument.asVariant();
if (v.userType() == qMetaTypeId<QDBusObjectPath>())
return v.value<QDBusObjectPath>().path();
else if (v.userType() == qMetaTypeId<QDBusSignature>())
return v.value<QDBusSignature>().signature();
else
return v;
}
case QDBusArgument::VariantType: {
QVariant v = argument.asVariant().value<QDBusVariant>().variant();
if (v.userType() == qMetaTypeId<QDBusArgument>())
return unmarshDBus(v.value<QDBusArgument>());
else
return v;
}
case QDBusArgument::ArrayType: {
QVariantList list;
argument.beginArray();
while (!argument.atEnd())
list.append(unmarshDBus(argument));
argument.endArray();
return list;
}
case QDBusArgument::StructureType: {
QVariantList list;
argument.beginStructure();
while (!argument.atEnd())
list.append(unmarshDBus(argument));
argument.endStructure();
return QVariant::fromValue(list);
}
case QDBusArgument::MapType: {
QVariantMap map;
argument.beginMap();
while (!argument.atEnd()) {
argument.beginMapEntry();
QVariant key = unmarshDBus(argument);
QVariant value = unmarshDBus(argument);
map.insert(key.toString(), value);
argument.endMapEntry();
}
argument.endMap();
return map;
}
default:
return QVariant();
break;
}
}
QVariant unmarsh(const QVariant& v) {
if (v.userType() == qMetaTypeId<QDBusObjectPath>()) {
return QVariant::fromValue(v.value<QDBusObjectPath>().path());
} else if (v.userType() == qMetaTypeId<QDBusArgument>()) {
return unmarsh(unmarshDBus(v.value<QDBusArgument>()));
} else if (v.userType() == qMetaTypeId<QByteArray>()) {
return QString(v.value<QByteArray>());
}
return v;
}
`