diff options
| author | Kevin Wu Won <kevin.wu-won@nokia.com> | 2010-02-25 17:02:41 +1000 |
|---|---|---|
| committer | Kevin Wu Won <kevin.wu-won@nokia.com> | 2010-03-11 10:42:48 +1000 |
| commit | 23524985d1890de0675bad879ed99cbc503d4d46 (patch) | |
| tree | 885a602b355a08cbaadcf74ade6dfa246a9978c3 /doc/src/snippets/qtversitdocsample/qtversitdocsample.cpp | |
| parent | 5ed03d7abfe0489bea6386a74a55544acdcd340d (diff) | |
Implemented changes to Versit API (error reporting, QByteArray reading/writing)
Added constructors to QVersitReader and Writer taking QByteArray and QIODevice.
Added setData() to QVersitReader
Added error reporting to QVersitContactImporter/Exporter
Renamed QVCI::importContacts to importDocuments (deprecated importContacts).
Added constructor QVersitDocument(VersitType)
Also made code in exporter/importer unit tests more terse
Fixed unit tests (ensured that contacts passed into the exporter have names)
Diffstat (limited to 'doc/src/snippets/qtversitdocsample/qtversitdocsample.cpp')
| -rw-r--r-- | doc/src/snippets/qtversitdocsample/qtversitdocsample.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/doc/src/snippets/qtversitdocsample/qtversitdocsample.cpp b/doc/src/snippets/qtversitdocsample/qtversitdocsample.cpp index 5f12351814..e37832a8da 100644 --- a/doc/src/snippets/qtversitdocsample/qtversitdocsample.cpp +++ b/doc/src/snippets/qtversitdocsample/qtversitdocsample.cpp @@ -137,6 +137,7 @@ void completeExample() input.seek(0); // Parse the input into QVersitDocuments + // Note: we could also use the more convenient QVersitReader(QByteArray) constructor. QVersitReader reader; reader.setDevice(&input); reader.startReading(); // Remember to check the return value @@ -145,15 +146,20 @@ void completeExample() // Convert the QVersitDocuments to QContacts QList<QVersitDocument> inputDocuments = reader.results(); QVersitContactImporter importer; - QList<QContact> contacts = importer.importContacts(inputDocuments); + if (!importer.importDocuments(inputDocuments)) + return; + QList<QContact> contacts = importer.contacts(); // Note that the QContacts are not saved yet. // Use QContactManager::saveContacts() for saving if necessary // Export the QContacts back to QVersitDocuments QVersitContactExporter exporter; - QList<QVersitDocument> outputDocuments = exporter.exportContacts(contacts); + if (!exporter.exportContacts(contacts)) + return; + QList<QVersitDocument> outputDocuments = exporter.documents(); // Encode the QVersitDocument back to a vCard + // Note: we could also use the more convenient QVersitWriter(QByteArray*) constructor. QBuffer output; output.open(QBuffer::ReadWrite); QVersitWriter writer; @@ -187,9 +193,9 @@ void exportExample() contactAvatar.setSubType(QContactAvatar::SubTypeTexturedMesh); contact.saveDetail(&contactAvatar); - QList<QContact> contactList; - contactList.append(contact); - QList<QVersitDocument> versitDocuments = contactExporter.exportContacts(contactList); + if (!contactExporter.exportContacts(QList<QContact>() << contact)) + return; + QList<QVersitDocument> versitDocuments = contactExporter.documents(); // detailHandler.mUnknownDetails now contains the list of unknown details //! [Export example] @@ -214,11 +220,10 @@ void importExample() property.setValue("some value"); document.addProperty(property); - QList<QVersitDocument> list; - list.append(document); - - QList<QContact> contactList = importer.importContacts(list); - // contactList.first() now contains the "N" property as a QContactName - // propertyHandler.mUnknownProperties contains the list of unknown properties + if (importer.importDocuments(QList<QVersitDocument>() << document)) { + QList<QContact> contactList = importer.contacts(); + // contactList.first() now contains the "N" property as a QContactName + // propertyHandler.mUnknownProperties contains the list of unknown properties + } //! [Import example] } |
