/*! Returns the hash value for \a key. */ uint qHash(const QVersitProperty &key) { uint hash = QT_PREPEND_NAMESPACE(qHash)(key.name()) + QT_PREPEND_NAMESPACE(qHash)(key.value()); foreach (const QString& group, key.groups()) { hash += QT_PREPEND_NAMESPACE(qHash)(group); } QHash<QString,QString>::const_iterator it = key.parameters().constBegin(); QHash<QString,QString>::const_iterator end = key.parameters().constEnd(); while (it != end) { hash += QT_PREPEND_NAMESPACE(qHash)(it.key()) + QT_PREPEND_NAMESPACE(qHash)(it.value()); ++it; } return hash; }
void CntVersitPrefPlugin::propertyProcessed( const QVersitDocument& document, const QVersitProperty& property, const QContact& contact, bool* alreadyProcessed, QList<QContactDetail>* updatedDetails) { Q_UNUSED(document); Q_UNUSED(contact); if (*alreadyProcessed && !updatedDetails->isEmpty()) { QStringList typeParameters = property.parameters().values(QLatin1String("TYPE")); if (typeParameters.contains(QLatin1String("PREF"), Qt::CaseInsensitive)) { if ((mDetailMappings.value(property.name()) == QContactPhoneNumber::DefinitionName) || (mDetailMappings.value(property.name()) == QContactEmailAddress::DefinitionName) || (mDetailMappings.value(property.name()) == QContactOnlineAccount::DefinitionName) || (mDetailMappings.value(property.name()) == QContactUrl::DefinitionName)) { // This method is called before the corresponding detail gets imported to QContact. // setPreferredDetail() cannot be called here -> detail is stored and will be set // preferred after whole versit document is processed mPrefDetailList.append(updatedDetails->last()); } } } }
bool QVCardRestoreHandler::propertyProcessed( const QVersitProperty& property, QList<QContactDetail>* updatedDetails) { bool success = false; QString group; if (!property.groups().isEmpty()) group = property.groups().first(); if (property.name() == PropertyName) { if (property.groups().size() != 1) return false; QMultiHash<QString, QString> parameters = property.parameters(); QContactDetail::DetailType detailType = QContactDetail::DetailType(parameters.value(DetailTypeParameter).toUInt()); QString fieldName = parameters.value(FieldParameter); // Find a detail previously seen with the same definitionName, which was generated from // a property from the same group QContactDetail detail(detailType); foreach (const QContactDetail& previousDetail, mDetailGroupMap.detailsInGroup(group)) { if (previousDetail.type() == detailType) { detail = previousDetail; } } // If not found, it's a new empty detail with the definitionName set. detail.setValue(fieldName.toInt(), deserializeValue(property)); // Replace the equivalent detail in updatedDetails with the new one QMutableListIterator<QContactDetail> it(*updatedDetails); while (it.hasNext()) { if (it.next().key() == detail.key()) { it.remove(); break; } } updatedDetails->append(detail); success = true; } if (!group.isEmpty()) { // Keep track of which details were generated from which Versit groups foreach (const QContactDetail& detail, *updatedDetails) { mDetailGroupMap.insert(group, detail); } }
/*! * 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) {
QDebug operator<<(QDebug dbg, const QVersitProperty& property) { QStringList groups = property.groups(); QString name = property.name(); QMultiHash<QString,QString> parameters = property.parameters(); dbg.nospace() << "QVersitProperty("; foreach (const QString& group, groups) { dbg.nospace() << group << '.'; } dbg.nospace() << name; QHash<QString,QString>::const_iterator it; for (it = parameters.constBegin(); it != parameters.constEnd(); ++it) { dbg.nospace() << ';' << it.key() << '=' << it.value(); } if (property.valueType() == QVersitProperty::VersitDocumentType) dbg.nospace() << ':' << property.value<QVersitDocument>(); else dbg.nospace() << ':' << property.variantValue(); dbg.nospace() << ')'; return dbg.maybeSpace(); }
// ... then, do the rest of the properties. foreach (const QVersitProperty& property, properties) { QStringList typeParameters = property.parameters().values(QStringLiteral("TYPE")); if (!typeParameters.contains(QStringLiteral("PREF"), Qt::CaseInsensitive)) importProperty(document, property, contactIndex, contact); }