diff options
| author | Kevin Wu Won <kevin.wu-won@nokia.com> | 2010-06-16 12:25:21 +1000 |
|---|---|---|
| committer | Kevin Wu Won <kevin.wu-won@nokia.com> | 2010-06-16 12:25:21 +1000 |
| commit | adf94b6d3639262063f89b2caf132cb8893b6c2e (patch) | |
| tree | 68ad0468c0312992ef9cc26f9dc2ed343c18e8ab /doc/src/snippets/qtversitdocsample/qtversitdocsample.cpp | |
| parent | 35c37ce638f588d8a35837aa764c33719dfaa205 (diff) | |
Documentation fixes for versit
Fixed compile warnings in qtversitdocsample (fixed to use createBackupHandler())
Beefed up documentation for QVersitDocument/Property
Diffstat (limited to 'doc/src/snippets/qtversitdocsample/qtversitdocsample.cpp')
| -rw-r--r-- | doc/src/snippets/qtversitdocsample/qtversitdocsample.cpp | 112 |
1 files changed, 10 insertions, 102 deletions
diff --git a/doc/src/snippets/qtversitdocsample/qtversitdocsample.cpp b/doc/src/snippets/qtversitdocsample/qtversitdocsample.cpp index 257251512d..c84f32700e 100644 --- a/doc/src/snippets/qtversitdocsample/qtversitdocsample.cpp +++ b/doc/src/snippets/qtversitdocsample/qtversitdocsample.cpp @@ -60,104 +60,6 @@ void completeExample(); void exportExample(); void importExample(); -//! [Detail handler] -class MyDetailHandler : public QVersitContactExporterDetailHandler { -public: - MyDetailHandler() : detailNumber(0) {} - bool preProcessDetail(const QContact& contact, const QContactDetail& detail, - QVersitDocument* document) { - Q_UNUSED(contact) Q_UNUSED(detail) Q_UNUSED(document) - return false; - } - /* eg. a detail with definition name "Detail1" and fields "Field1"="Value1" and - * "Field2"="Value2" will be exported to the vCard properties: - * G0.DETAIL1-FIELD1:Value1 - * G0.DETAIL1-FIELD2:Value2 - * And the next detail (say, "Detail2" with a field "Field3"="Value3" will generate: - * G1.DETAIL2-FIELD3:Value3 - * ie. Different details will have different vCard groups. - */ - bool postProcessDetail(const QContact& contact, const QContactDetail& detail, - bool alreadyProcessed, QVersitDocument* document) { - Q_UNUSED(contact) - // beware: if the base implementation exports some but not all fields, alreadyProcessed - // will be true and the unprocessed fields won't be exported - if (alreadyProcessed) - return false; - if (detail.definitionName() == QContactType::DefinitionName) - return false; // special case of an unhandled detail that we don't export - QVersitProperty property; - QVariantMap fields = detail.variantValues(); - // fields from the same detail have the same group so the importer can collate them - QString detailGroup = QLatin1String("G") + QString::number(detailNumber++); - for (QVariantMap::const_iterator it = fields.constBegin(); - it != fields.constEnd(); - it++) { - property.setGroups(QStringList(detailGroup)); - // beware: detail.definitionName and the field name will be made uppercase on export - property.setName(QLatin1String("X-QCONTACTDETAIL-") - + detail.definitionName() - + QLatin1String("-") - + it.key()); - // beware: this might not handle nonstring values properly: - property.setValue(it.value()); - document->addProperty(property); - } - return true; - } -private: - int detailNumber; -}; -//! [Detail handler] - -//! [Property handler] -class MyPropertyHandler : public QVersitContactImporterPropertyHandler { -public: - bool preProcessProperty(const QVersitDocument& document, const QVersitProperty& property, - int contactIndex, QContact* contact) { - Q_UNUSED(document) Q_UNUSED(property) Q_UNUSED(contactIndex) Q_UNUSED(contact) - return false; - } - /* eg. if the document has the properties: - * G0.DETAIL-FIELD1:Value1 - * G0.DETAIL-FIELD2:Value2 - * G1.DETAIL-FIELD1:Value3 - * This will generate two details - the first with fields "FIELD1"="Value1" and - * "FIELD2"="Value2" and the second with "FIELD1"="Value3" - * ie. the vCard groups determine which properties form a single detail. - */ - bool postProcessProperty(const QVersitDocument& document, const QVersitProperty& property, - bool alreadyProcessed, int contactIndex, QContact* contact) { - Q_UNUSED(document) Q_UNUSED(contactIndex) - const QString prefix = QLatin1String("X-QCONTACTDETAIL-"); - if (alreadyProcessed) - return false; - if (!property.name().startsWith(prefix)) - return false; - QString detailAndField = property.name().mid(prefix.size()); - QStringList detailAndFieldParts = detailAndField.split(QLatin1Char('-'), - QString::SkipEmptyParts); - if (detailAndFieldParts.size() != 2) - return false; - QString definitionName = detailAndFieldParts.at(0); - QString fieldName = detailAndFieldParts.at(1); - if (property.groups().size() != 1) - return false; - QString group = property.groups().first(); - // find a detail generated from the a property with the same group - QContactDetail detail = handledDetails.value(group); - // make sure the the existing detail has the same definition name - if (detail.definitionName() != definitionName) - detail = QContactDetail(definitionName); - detail.setValue(fieldName, property.value()); - contact->saveDetail(&detail); - handledDetails.insert(group, detail); - return false; - } - QMap<QString, QContactDetail> handledDetails; // map from group name to detail -}; -//! [Property handler] - //! [Resource handler] class MyResourceHandler : public QVersitDefaultResourceHandler { public: @@ -241,8 +143,9 @@ void exportExample() //! [Export example] QVersitContactExporter contactExporter; - MyDetailHandler detailHandler; - contactExporter.setDetailHandler(&detailHandler); + QVersitContactExporterDetailHandlerV2* backupHandler = + QVersitContactExporterDetailHandlerV2::createBackupHandler(); + contactExporter.setDetailHandler(backupHandler); QContact contact; // Create a name @@ -255,6 +158,8 @@ void exportExample() QList<QVersitDocument> versitDocuments = contactExporter.documents(); // detailHandler.mUnknownDetails now contains the list of unknown details + + delete backupHandler; //! [Export example] } @@ -263,8 +168,9 @@ void importExample() //! [Import example] QVersitContactImporter importer; - MyPropertyHandler propertyHandler; - importer.setPropertyHandler(&propertyHandler); + QVersitContactImporterPropertyHandlerV2* backupHandler = + QVersitContactImporterPropertyHandlerV2::createBackupHandler(); + importer.setPropertyHandler(backupHandler); QVersitDocument document; @@ -282,6 +188,8 @@ void importExample() // contactList.first() now contains the "N" property as a QContactName // propertyHandler.mUnknownProperties contains the list of unknown properties } + + delete backupHandler; //! [Import example] } |
