From 0d38ab954335556df39456af585a566ed8e022c8 Mon Sep 17 00:00:00 2001 From: David Laing Date: Mon, 5 Jul 2010 13:20:17 +1000 Subject: Revert "Revert "Merge branch 'master' of ../../mainline/qtmobility"" This reverts commit e38ebf00c0b539a7756b21946693e201269b976a. Conflicts: examples/telephony/dialer/dialer.pro src/s60installs/bwins/QtMultimediaKitu.def src/s60installs/bwins/QtServiceFrameworku.def src/s60installs/bwins/QtSystemInfou.def src/s60installs/eabi/QtSystemInfou.def --- .../qtversitdocsample/qtversitdocsample.cpp | 112 ++------------------- 1 file changed, 10 insertions(+), 102 deletions(-) (limited to 'doc/src/snippets/qtversitdocsample/qtversitdocsample.cpp') 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 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 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] } -- cgit v1.2.3