240 QVersitProperty::ListType); |
240 QVersitProperty::ListType); |
241 mValueTypeMap.insert(qMakePair(QVersitDocument::VCard21Type, QString::fromAscii("CATEGORIES")), |
241 mValueTypeMap.insert(qMakePair(QVersitDocument::VCard21Type, QString::fromAscii("CATEGORIES")), |
242 QVersitProperty::ListType); |
242 QVersitProperty::ListType); |
243 mValueTypeMap.insert(qMakePair(QVersitDocument::VCard30Type, QString::fromAscii("CATEGORIES")), |
243 mValueTypeMap.insert(qMakePair(QVersitDocument::VCard30Type, QString::fromAscii("CATEGORIES")), |
244 QVersitProperty::ListType); |
244 QVersitProperty::ListType); |
|
245 mValueTypeMap.insert(qMakePair(QVersitDocument::VCard21Type, QString::fromAscii("X-CHILDREN")), |
|
246 QVersitProperty::ListType); |
|
247 mValueTypeMap.insert(qMakePair(QVersitDocument::VCard30Type, QString::fromAscii("X-CHILDREN")), |
|
248 QVersitProperty::ListType); |
|
249 mValueTypeMap.insert(qMakePair(QVersitDocument::VCard21Type, QString::fromAscii("X-NICKNAME")), |
|
250 QVersitProperty::ListType); |
|
251 mValueTypeMap.insert(qMakePair(QVersitDocument::VCard30Type, QString::fromAscii("X-NICKNAME")), |
|
252 QVersitProperty::ListType); |
245 } |
253 } |
246 |
254 |
247 /*! Destroy a reader. */ |
255 /*! Destroy a reader. */ |
248 QVersitReaderPrivate::~QVersitReaderPrivate() |
256 QVersitReaderPrivate::~QVersitReaderPrivate() |
249 { |
257 { |
420 extractPropertyGroupsAndName(cursor, lineReader.codec()); |
428 extractPropertyGroupsAndName(cursor, lineReader.codec()); |
421 |
429 |
422 QVersitProperty property; |
430 QVersitProperty property; |
423 property.setGroups(groupsAndName.first); |
431 property.setGroups(groupsAndName.first); |
424 property.setName(groupsAndName.second); |
432 property.setName(groupsAndName.second); |
|
433 // set the propertyValueType |
|
434 QPair<QVersitDocument::VersitType, QString> key = |
|
435 qMakePair(versitType, property.name()); |
|
436 if (mValueTypeMap.contains(key)) |
|
437 property.setValueType(mValueTypeMap.value(key)); |
425 |
438 |
426 if (versitType == QVersitDocument::VCard21Type) |
439 if (versitType == QVersitDocument::VCard21Type) |
427 parseVCard21Property(cursor, property, lineReader); |
440 parseVCard21Property(cursor, property, lineReader); |
428 else if (versitType == QVersitDocument::VCard30Type) |
441 else if (versitType == QVersitDocument::VCard30Type) |
429 parseVCard30Property(cursor, property, lineReader); |
442 parseVCard30Property(cursor, property, lineReader); |
438 LineReader& lineReader) |
451 LineReader& lineReader) |
439 { |
452 { |
440 property.setParameters(extractVCard21PropertyParams(cursor, lineReader.codec())); |
453 property.setParameters(extractVCard21PropertyParams(cursor, lineReader.codec())); |
441 |
454 |
442 QByteArray value = extractPropertyValue(cursor); |
455 QByteArray value = extractPropertyValue(cursor); |
443 if (mValueTypeMap.value(qMakePair(QVersitDocument::VCard21Type, property.name())) |
456 if (property.valueType() == QVersitProperty::VersitDocumentType) { |
444 == QVersitProperty::VersitDocumentType) { |
|
445 // Hack to handle cases where start of document is on the same or next line as "AGENT:" |
457 // Hack to handle cases where start of document is on the same or next line as "AGENT:" |
446 bool foundBegin = false; |
458 bool foundBegin = false; |
447 if (value == "BEGIN:VCARD") { |
459 if (value == "BEGIN:VCARD") { |
448 foundBegin = true; |
460 foundBegin = true; |
449 } else if (value.isEmpty()) { |
461 } else if (value.isEmpty()) { |
460 } else { |
472 } else { |
461 QTextCodec* codec; |
473 QTextCodec* codec; |
462 QVariant valueVariant(decodeCharset(value, property, lineReader.codec(), &codec)); |
474 QVariant valueVariant(decodeCharset(value, property, lineReader.codec(), &codec)); |
463 bool isBinary = unencode(valueVariant, cursor, property, codec, lineReader); |
475 bool isBinary = unencode(valueVariant, cursor, property, codec, lineReader); |
464 property.setValue(valueVariant); |
476 property.setValue(valueVariant); |
465 if (!isBinary) { |
477 if (isBinary) |
466 splitStructuredValue(QVersitDocument::VCard21Type, property, false); |
478 property.setValueType(QVersitProperty::BinaryType); |
467 } |
479 else |
|
480 splitStructuredValue(property, false); |
468 } |
481 } |
469 } |
482 } |
470 |
483 |
471 /*! |
484 /*! |
472 * Parses the property according to vCard 3.0 syntax. |
485 * Parses the property according to vCard 3.0 syntax. |
479 QByteArray value = extractPropertyValue(cursor); |
492 QByteArray value = extractPropertyValue(cursor); |
480 |
493 |
481 QTextCodec* codec; |
494 QTextCodec* codec; |
482 QString valueString(decodeCharset(value, property, lineReader.codec(), &codec)); |
495 QString valueString(decodeCharset(value, property, lineReader.codec(), &codec)); |
483 |
496 |
484 if (mValueTypeMap.value(qMakePair(QVersitDocument::VCard30Type, property.name())) |
497 if (property.valueType() == QVersitProperty::VersitDocumentType) { |
485 == QVersitProperty::VersitDocumentType) { |
|
486 removeBackSlashEscaping(valueString); |
498 removeBackSlashEscaping(valueString); |
487 // Make a line reader from the value of the property. |
499 // Make a line reader from the value of the property. |
488 QByteArray subDocumentValue(codec->fromUnicode(valueString)); |
500 QByteArray subDocumentValue(codec->fromUnicode(valueString)); |
489 QBuffer subDocumentData(&subDocumentValue); |
501 QBuffer subDocumentData(&subDocumentValue); |
490 subDocumentData.open(QIODevice::ReadOnly); |
502 subDocumentData.open(QIODevice::ReadOnly); |
499 } |
511 } |
500 } else { |
512 } else { |
501 QVariant valueVariant(valueString); |
513 QVariant valueVariant(valueString); |
502 bool isBinary = unencode(valueVariant, cursor, property, codec, lineReader); |
514 bool isBinary = unencode(valueVariant, cursor, property, codec, lineReader); |
503 property.setValue(valueVariant); |
515 property.setValue(valueVariant); |
504 if (!isBinary) { |
516 if (isBinary) { |
505 bool isList = splitStructuredValue(QVersitDocument::VCard30Type, property, true); |
517 property.setValueType(QVersitProperty::BinaryType); |
|
518 } else { |
|
519 bool isList = splitStructuredValue(property, true); |
506 // Do backslash unescaping |
520 // Do backslash unescaping |
507 if (isList) { |
521 if (isList) { |
508 QStringList list = property.value<QStringList>(); |
522 QStringList list = property.value<QStringList>(); |
509 for (int i = 0; i < list.length(); i++) { |
523 for (int i = 0; i < list.length(); i++) { |
510 removeBackSlashEscaping(list[i]); |
524 removeBackSlashEscaping(list[i]); |
866 * value is split according to the type of structuring (compound vs. list) it is known to have. |
880 * value is split according to the type of structuring (compound vs. list) it is known to have. |
867 * Returns true if and only if such a split happened (ie. the property value holds a QStringList on |
881 * Returns true if and only if such a split happened (ie. the property value holds a QStringList on |
868 * exit). |
882 * exit). |
869 */ |
883 */ |
870 bool QVersitReaderPrivate::splitStructuredValue( |
884 bool QVersitReaderPrivate::splitStructuredValue( |
871 QVersitDocument::VersitType type, QVersitProperty& property, |
885 QVersitProperty& property, |
872 bool hasEscapedBackslashes) const |
886 bool hasEscapedBackslashes) const |
873 { |
887 { |
874 QVariant variant = property.variantValue(); |
888 QVariant variant = property.variantValue(); |
875 QPair<QVersitDocument::VersitType,QString> key = qMakePair(type, property.name()); |
889 if (property.valueType() == QVersitProperty::CompoundType) { |
876 if (mValueTypeMap.contains(key)) { |
890 variant.setValue(splitValue(variant.toString(), QLatin1Char(';'), |
877 if (mValueTypeMap.value(key) == QVersitProperty::CompoundType) { |
891 QString::KeepEmptyParts, hasEscapedBackslashes)); |
878 variant.setValue(splitValue(variant.toString(), QLatin1Char(';'), |
892 property.setValue(variant); |
879 QString::KeepEmptyParts, hasEscapedBackslashes)); |
893 return true; |
880 property.setValue(variant); |
894 } else if (property.valueType() == QVersitProperty::ListType) { |
881 property.setValueType(QVersitProperty::CompoundType); |
895 variant.setValue(splitValue(variant.toString(), QLatin1Char(','), |
882 } else if (mValueTypeMap.value(key) == QVersitProperty::ListType) { |
896 QString::SkipEmptyParts, hasEscapedBackslashes)); |
883 variant.setValue(splitValue(variant.toString(), QLatin1Char(','), |
897 property.setValue(variant); |
884 QString::SkipEmptyParts, hasEscapedBackslashes)); |
|
885 property.setValue(variant); |
|
886 property.setValueType(QVersitProperty::ListType); |
|
887 } |
|
888 return true; |
898 return true; |
889 } |
899 } |
890 return false; |
900 return false; |
891 } |
901 } |
892 |
902 |