void LayoutParser::parseModifiers(const TagBindingPtr &binding) { static const QStringList keys_values(QString::fromLatin1("alt,shift,altshift").split(',')); const QXmlStreamAttributes attributes(m_xml.attributes()); const TagModifiers::Keys keys(enumValue("keys", keys_values, TagModifiers::Shift)); TagModifiersPtr new_modifiers(new TagModifiers(keys)); binding->appendModifiers(new_modifiers); while (m_xml.readNextStartElement()) { const QStringRef name(m_xml.name()); if (name == QLatin1String("binding")) { if (not new_modifiers->binding()) { parseBinding(new_modifiers); } else { error(QString::fromLatin1("Expected only one '<binding>', but got another one.")); } } else { error(QString::fromLatin1("Expected '<binding>', but got '<%1>'.").arg(name.toString())); } } if (not new_modifiers->binding()) { error(QString::fromLatin1("Expected exactly one '<binding>', but got none.")); } }
void ShellUI::reloadConfig() { m_properties.clear(); qDeleteAll(m_bindings); m_bindings.clear(); QJsonObject object; if (m_config.contains(QStringLiteral("Shell"))) { object = m_config[QStringLiteral("Shell")].toObject(); } else { QJsonParseError err; QJsonDocument doc = QJsonDocument::fromJson(defaultShell, &err); if (err.error != QJsonParseError::NoError) { qDebug() << "Cannot parse the default shell config" << err.errorString(); } object = doc.object(); m_config[QStringLiteral("Shell")] = object; } QJsonObject properties = object[QStringLiteral("properties")].toObject(); for (auto i = properties.constBegin(); i != properties.constEnd(); ++i) { setProperty(qPrintable(i.key()), i.value().toVariant()); m_properties << i.key(); } QJsonArray bindings = object[QStringLiteral("bindings")].toArray(); for (auto i = bindings.begin(); i != bindings.end(); ++i) { const QJsonObject &binding = (*i).toObject(); if (!parseBinding(binding)) { qDebug() << "Cannot parse binding" << binding; } } foreach (UiScreen *screen, m_screens) { loadScreen(screen); }
void LayoutParser::parseKey(const TagRowPtr &row) { static const QStringList styleValues(QString::fromLatin1("normal,special,deadkey").split(',')); static const QStringList widthValues(QString::fromLatin1("small,medium,large,x-large,xx-large,stretched").split(',')); const QXmlStreamAttributes attributes(m_xml.attributes()); const TagKey::Style style(enumValue("style", styleValues, TagKey::Normal)); const TagKey::Width width(enumValue("width", widthValues, TagKey::Medium)); const bool rtl(boolValue(attributes.value(QLatin1String("rtl")), false)); const QString id(attributes.value(QLatin1String("id")).toString()); TagKeyPtr new_key(new TagKey(style, width, rtl, id)); row->appendElement(new_key); while (m_xml.readNextStartElement()) { const QStringRef name(m_xml.name()); if (name == QLatin1String("binding")) { if (not new_key->binding()) { parseBinding(new_key); } else { error(QString::fromLatin1("Expected only one '<binding>', but got another one.")); } } else if (name == QLatin1String("extended")) { if (not new_key->extended()) { parseExtended(new_key); } else { error(QString::fromLatin1("Expected only one '<extended>', but got another one.")); } } else { error(QString::fromLatin1("Expected '<binding>' or '<extended>', but got '<%1>'.").arg(name.toString())); } } if (not new_key->binding()) { error(QString::fromLatin1("Expected exactly one '<binding>' but got none.")); } }