qtwaylandscanner: Send null for a null QString with allow-null

`toUtf8().constData()` on a null `QString` results in an empty
string sent over the wire, which is distinct from `null` when
the request has "allow-null" specified.

Notably `wl_data_offer.accept` uses a null mime_type for
"not accepted".

[ChangeLog][Important Behavior Changes][qtwaylandscanner] String
arguments in a request will now send null rather than empty string
for a null QString if the argument is declared with "allow-null".

Change-Id: I4b78246e4da7b60680d7797fd6309755f44d2bb6
Reviewed-by: David Edmundson <davidedmundson@kde.org>
This commit is contained in:
Kai Uwe Broulik 2024-02-20 17:03:50 +01:00
parent b0129c6af8
commit 75d324cbb9

View File

@ -196,7 +196,7 @@ Scanner::WaylandEvent Scanner::readEvent(QXmlStreamReader &xml, bool request)
.type = byteArrayValue(xml, "type"),
.interface = byteArrayValue(xml, "interface"),
.summary = byteArrayValue(xml, "summary"),
.allowNull = boolValue(xml, "allowNull"),
.allowNull = boolValue(xml, "allow-null"),
};
event.arguments.push_back(std::move(argument));
}
@ -937,9 +937,12 @@ bool Scanner::process()
printf(",\n");
QByteArray cType = waylandToCType(a.type, a.interface);
QByteArray qtType = waylandToQtType(a.type, a.interface, e.request);
if (a.type == "string")
printf(" %s.toUtf8().constData()", a.name.constData());
else if (a.type == "array")
if (a.type == "string") {
printf(" ");
if (a.allowNull)
printf("%s.isNull() ? nullptr : ", a.name.constData());
printf("%s.toUtf8().constData()", a.name.constData());
} else if (a.type == "array")
printf(" &%s_data", a.name.constData());
else if (cType == qtType)
printf(" %s", a.name.constData());
@ -1225,9 +1228,12 @@ bool Scanner::process()
} else {
QByteArray cType = waylandToCType(a.type, a.interface);
QByteArray qtType = waylandToQtType(a.type, a.interface, e.request);
if (a.type == "string")
printf(" %s.toUtf8().constData()", a.name.constData());
else if (a.type == "array")
if (a.type == "string") {
printf(" ");
if (a.allowNull)
printf("%s.isNull() ? nullptr : ", a.name.constData());
printf("%s.toUtf8().constData()", a.name.constData());
} else if (a.type == "array")
printf(" &%s_data", a.name.constData());
else if (cType == qtType)
printf(" %s", a.name.constData());