/*! * Encodes the \a property and writes it to the device. */ void QVCard30Writer::encodeVersitProperty(const QVersitProperty& property) { QVersitProperty modifiedProperty(property); QString name = mPropertyNameMappings.value(property.name(),property.name()); modifiedProperty.setName(name); encodeGroupsAndName(modifiedProperty); QVariant variant(modifiedProperty.variantValue()); if (variant.type() == QVariant::ByteArray) { modifiedProperty.insertParameter(QLatin1String("ENCODING"), QLatin1String("b")); } encodeParameters(modifiedProperty.parameters()); writeString(QLatin1String(":")); QString renderedValue; QByteArray renderedBytes; if (variant.canConvert<QVersitDocument>()) { QVersitDocument embeddedDocument = variant.value<QVersitDocument>(); QByteArray data; QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); QVCard30Writer subWriter(mType); subWriter.setCodec(mCodec); subWriter.setDevice(&buffer); subWriter.encodeVersitDocument(embeddedDocument); QString documentString(mCodec->toUnicode(data)); backSlashEscape(&documentString); renderedValue = documentString; } else if (variant.type() == QVariant::String) { renderedValue = variant.toString(); if (property.valueType() != QVersitProperty::PreformattedType) { backSlashEscape(&renderedValue); } } else if (variant.type() == QVariant::StringList) { // We need to backslash escape and concatenate the values in the list QStringList values = property.variantValue().toStringList(); QString separator; if (property.valueType() == QVersitProperty::CompoundType) { separator = QLatin1String(";"); } else { if (property.valueType() != QVersitProperty::ListType) { qWarning("Variant value is a QStringList but the property's value type is neither " "CompoundType or ListType"); } // Assume it's a ListType separator = QLatin1String(","); } bool first = true; foreach (QString value, values) { if (!(value.isEmpty() && property.valueType() == QVersitProperty::ListType)) { if (!first) { renderedValue += separator; } backSlashEscape(&value); renderedValue += value; first = false; } } } else if (variant.type() == QVariant::ByteArray) {
/*! * Encodes the \a property and writes it to the device. */ void QVCard21Writer::encodeVersitProperty(const QVersitProperty& property) { encodeGroupsAndName(property); QMultiHash<QString,QString> parameters = property.parameters(); QVariant variant(property.variantValue()); QString renderedValue; QByteArray renderedBytes; /* Structured values need to have their components backslash-escaped (in vCard 2.1, semicolons must be escaped for compound values and commas must be escaped for list values). */ if (variant.type() == QVariant::StringList) { QStringList values = property.variantValue().toStringList(); QString separator; if (property.valueType() == QVersitProperty::CompoundType) { separator = QLatin1String(";"); } else { if (property.valueType() != QVersitProperty::ListType) { qWarning("Variant value is a QStringList but the property's value type is neither " "CompoundType or ListType"); } // Assume it's a ListType separator = QLatin1String(","); } QString replacement = QLatin1Char('\\') + separator; QRegExp separatorRegex = QRegExp(separator); // Check first if any of the values need to be UTF-8 encoded (if so, all of them must be // UTF-8 encoded) bool forceUtf8 = requiresUtf8(values); bool first = true; foreach (QString value, values) { if (!(value.isEmpty() && property.valueType() == QVersitProperty::ListType)) { encodeVersitValue(parameters, value, forceUtf8); if (!first) { renderedValue += separator; } renderedValue += value.replace(separatorRegex, replacement); first = false; } } } else if (variant.type() == QVariant::String) {