--- a/src/versit/qversitcontactexporter_p.cpp Fri Sep 17 08:34:34 2010 +0300
+++ b/src/versit/qversitcontactexporter_p.cpp Mon Oct 04 01:37:06 2010 +0300
@@ -41,7 +41,7 @@
#include "qversitcontactexporter.h"
#include "qversitcontactexporter_p.h"
-#include "qversitdefs_p.h"
+#include "qversitcontactsdefs_p.h"
#include "versitutils_p.h"
#include "qmobilityglobal.h"
@@ -66,6 +66,8 @@
#include <qcontactfamily.h>
#include <qcontactdisplaylabel.h>
#include <qcontactthumbnail.h>
+#include "qversitcontacthandler.h"
+#include "qversitcontactpluginloader_p.h"
#include <QUrl>
#include <QBuffer>
@@ -75,20 +77,19 @@
/*!
* Constructor.
*/
-QVersitContactExporterPrivate::QVersitContactExporterPrivate() :
+QVersitContactExporterPrivate::QVersitContactExporterPrivate(const QString& profile) :
mDetailHandler(NULL),
mDetailHandler2(NULL),
mDetailHandlerVersion(0),
mDefaultResourceHandler(new QVersitDefaultResourceHandler),
- mResourceHandler(mDefaultResourceHandler),
- mVersitType(QVersitDocument::InvalidType)
+ mResourceHandler(mDefaultResourceHandler)
{
// Detail mappings
int versitPropertyCount =
- sizeof(versitContactDetailMappings)/sizeof(VersitContactDetailMapping);
+ sizeof(versitContactDetailMappings)/sizeof(VersitDetailMapping);
for (int i=0; i < versitPropertyCount; i++) {
mPropertyMappings.insert(
- QLatin1String(versitContactDetailMappings[i].contactDetailDefinitionName),
+ QLatin1String(versitContactDetailMappings[i].detailDefinitionName),
QLatin1String(versitContactDetailMappings[i].versitPropertyName));
}
@@ -107,6 +108,8 @@
QLatin1String(versitSubTypeMappings[i].contactString),
QLatin1String(versitSubTypeMappings[i].versitString));
}
+
+ mPluginDetailHandlers = QVersitContactPluginLoader::instance()->createContactHandlers(profile);
}
/*!
@@ -126,15 +129,12 @@
QVersitDocument& document,
QVersitContactExporter::Error* error)
{
- mVersitType = document.type();
QList<QContactDetail> allDetails = contact.details();
if (allDetails.isEmpty()) {
*error = QVersitContactExporter::EmptyContactError;
return false;
}
- for (int i = 0; i < allDetails.size(); i++) {
- QContactDetail detail = allDetails.at(i);
-
+ foreach (const QContactDetail& detail, allDetails) {
// If the custom detail handler handles it, we don't have to.
if (mDetailHandler
&& mDetailHandler->preProcessDetail(contact, detail, &document))
@@ -188,9 +188,15 @@
encodeDisplayLabel(detail, document, &removedProperties, &generatedProperties, &processedFields);
}
+ // run plugin handlers
+ foreach (QVersitContactExporterDetailHandlerV2* handler, mPluginDetailHandlers) {
+ handler->detailProcessed(contact, detail, document,
+ &processedFields, &removedProperties, &generatedProperties);
+ }
+ // run the v2 handler, if set
if (mDetailHandler2 && mDetailHandlerVersion > 1) {
- mDetailHandler2->detailProcessed(contact, detail, processedFields, document,
- &removedProperties, &generatedProperties);
+ mDetailHandler2->detailProcessed(contact, detail, document,
+ &processedFields, &removedProperties, &generatedProperties);
}
foreach(const QVersitProperty& property, removedProperties) {
@@ -205,6 +211,11 @@
}
}
+ // run plugin handlers
+ foreach (QVersitContactExporterDetailHandlerV2* handler, mPluginDetailHandlers) {
+ handler->contactProcessed(contact, &document);
+ }
+ // run the v2 handler, if set
if (mDetailHandler2 && mDetailHandlerVersion > 1) {
mDetailHandler2->contactProcessed(contact, &document);
}
@@ -261,7 +272,8 @@
// Generate an FN field if none is already there
// Don't override previously exported FN properties (eg. exported by a DisplayLabel detail)
- QVersitProperty fnProperty = takeProperty(document, QLatin1String("FN"), removedProperties);
+ QVersitProperty fnProperty =
+ VersitUtils::takeProperty(document, QLatin1String("FN"), removedProperties);
if (fnProperty.value().isEmpty()) {
fnProperty.setName(QLatin1String("FN"));
if (!contactName.customLabel().isEmpty()) {
@@ -630,7 +642,8 @@
QSet<QString>* processedFields)
{
QContactNickname nicknameDetail = static_cast<QContactNickname>(detail);
- QVersitProperty property = takeProperty(document, QLatin1String("X-NICKNAME"), removedProperties);
+ QVersitProperty property =
+ VersitUtils::takeProperty(document, QLatin1String("X-NICKNAME"), removedProperties);
property.setName(QLatin1String("X-NICKNAME"));
QStringList value(property.variantValue().toStringList());
value.append(nicknameDetail.nickname());
@@ -651,7 +664,8 @@
QSet<QString>* processedFields)
{
QContactTag tagDetail = static_cast<QContactTag>(detail);
- QVersitProperty property = takeProperty(document, QLatin1String("CATEGORIES"), removedProperties);
+ QVersitProperty property =
+ VersitUtils::takeProperty(document, QLatin1String("CATEGORIES"), removedProperties);
property.setName(QLatin1String("CATEGORIES"));
QStringList value(property.variantValue().toStringList());
value.append(tagDetail.tag());
@@ -745,7 +759,8 @@
QSet<QString>* processedFields)
{
// Override any previous FN property
- QVersitProperty property = takeProperty(document, QLatin1String("FN"), removedProperties);
+ QVersitProperty property =
+ VersitUtils::takeProperty(document, QLatin1String("FN"), removedProperties);
property.setName(mPropertyMappings.value(detail.definitionName()));
QContactDisplayLabel displayLabel = static_cast<QContactDisplayLabel>(detail);
if (!displayLabel.label().isEmpty()) {
@@ -756,21 +771,6 @@
}
/*!
- * Finds a property in the \a document with the given \a propertyName, removes it and returns it.
- */
-QVersitProperty QVersitContactExporterPrivate::takeProperty(const QVersitDocument& document,
- const QString& propertyName,
- QList<QVersitProperty>* toBeRemoved) {
- foreach (const QVersitProperty& currentProperty, document.properties()) {
- if (currentProperty.name() == propertyName) {
- *toBeRemoved << currentProperty;
- return currentProperty;
- }
- }
- return QVersitProperty();
-}
-
-/*!
* Check if \a resourceIdentifier represents a valid remote resource
*/
bool QVersitContactExporterPrivate::isValidRemoteUrl(