Commit 0061080e authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

Support both check boxes and radio buttons

CanConvert also happily converts a string to a bool, so explicitly check for type
and for radio buttons we get a string telling us which is the currently checked action
parent 576f2c8d
......@@ -1057,12 +1057,18 @@ QVariantMap Menu::gMenuToDBusMenuProperties(const QVariantMap &source) const
if (args.count() == 1) {
const auto &firstArg = args.first();
// assume this is a checkbox
if (firstArg.canConvert<bool>() && !isMenu) {
result.insert(QStringLiteral("toggle-type"), QStringLiteral("checkbox"));
if (firstArg.toBool()) {
result.insert(QStringLiteral("toggle-state"), 1);
} else {
result.insert(QStringLiteral("toggle-state"), 0);
if (!isMenu) {
if (firstArg.type() == QVariant::Bool) {
result.insert(QStringLiteral("toggle-type"), QStringLiteral("checkbox"));
result.insert(QStringLiteral("toggle-state"), firstArg.toBool() ? 1 : 0);
} else if (firstArg.type() == QVariant::String) {
result.insert(QStringLiteral("toggle-type"), QStringLiteral("radio"));
const QString checkedAction = firstArg.toString();
if (!checkedAction.isEmpty() && actionName.endsWith(checkedAction)) {
result.insert(QStringLiteral("toggle-state"), 1);
} else {
result.insert(QStringLiteral("toggle-state"), 0);
}
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment