src/versit/qversitcontactimporter_p.cpp
changeset 5 603d3f8b6302
parent 0 876b1a06bc25
equal deleted inserted replaced
3:e4ebb16b39ea 5:603d3f8b6302
    37 **
    37 **
    38 ** $QT_END_LICENSE$
    38 ** $QT_END_LICENSE$
    39 **
    39 **
    40 ****************************************************************************/
    40 ****************************************************************************/
    41 
    41 
    42 #include "qversitdefs_p.h"
    42 #include "qversitcontactsdefs_p.h"
    43 #include "qversitcontactimporter_p.h"
    43 #include "qversitcontactimporter_p.h"
    44 #include "qversitdocument.h"
    44 #include "qversitdocument.h"
    45 #include "qversitproperty.h"
    45 #include "qversitproperty.h"
    46 #include "qmobilityglobal.h"
    46 #include "qmobilityglobal.h"
       
    47 #include "qmobilitypluginsearch.h"
    47 
    48 
    48 #include <qcontactmanagerengine.h>
    49 #include <qcontactmanagerengine.h>
    49 #include <qcontact.h>
    50 #include <qcontact.h>
    50 #include <qcontactdetail.h>
    51 #include <qcontactdetail.h>
    51 #include <qcontactname.h>
    52 #include <qcontactname.h>
    66 #include <qcontactonlineaccount.h>
    67 #include <qcontactonlineaccount.h>
    67 #include <qcontactfamily.h>
    68 #include <qcontactfamily.h>
    68 #include <qcontactdisplaylabel.h>
    69 #include <qcontactdisplaylabel.h>
    69 #include <qcontactthumbnail.h>
    70 #include <qcontactthumbnail.h>
    70 #include <qcontactringtone.h>
    71 #include <qcontactringtone.h>
       
    72 #include "qversitcontacthandler.h"
       
    73 #include "qversitcontactpluginloader_p.h"
    71 
    74 
    72 #include <QHash>
    75 #include <QHash>
    73 #include <QFile>
    76 #include <QFile>
    74 
    77 
    75 QTM_USE_NAMESPACE
    78 QTM_USE_NAMESPACE
    76 
    79 
    77 /*!
    80 /*!
    78  * Constructor.
    81  * Constructor.
    79  */
    82  */
    80 QVersitContactImporterPrivate::QVersitContactImporterPrivate() :
    83 QVersitContactImporterPrivate::QVersitContactImporterPrivate(const QString& profile) :
    81     mPropertyHandler(NULL),
    84     mPropertyHandler(NULL),
    82     mPropertyHandler2(NULL),
    85     mPropertyHandler2(NULL),
    83     mPropertyHandlerVersion(0),
    86     mPropertyHandlerVersion(0),
    84     mDefaultResourceHandler(new QVersitDefaultResourceHandler),
    87     mDefaultResourceHandler(new QVersitDefaultResourceHandler),
    85     mResourceHandler(mDefaultResourceHandler)
    88     mResourceHandler(mDefaultResourceHandler)
    86 {
    89 {
    87     // Contact detail mappings
    90     // Contact detail mappings
    88     int versitPropertyCount =
    91     int versitPropertyCount =
    89         sizeof(versitContactDetailMappings)/sizeof(VersitContactDetailMapping);
    92         sizeof(versitContactDetailMappings)/sizeof(VersitDetailMapping);
    90     for (int i=0; i < versitPropertyCount; i++) {
    93     for (int i=0; i < versitPropertyCount; i++) {
    91         QString versitPropertyName =
    94         QString versitPropertyName =
    92             QLatin1String(versitContactDetailMappings[i].versitPropertyName);
    95             QLatin1String(versitContactDetailMappings[i].versitPropertyName);
    93         QPair<QString,QString> contactDetail;
    96         QPair<QString,QString> contactDetail;
    94         contactDetail.first =
    97         contactDetail.first =
    95             QLatin1String(versitContactDetailMappings[i].contactDetailDefinitionName);
    98             QLatin1String(versitContactDetailMappings[i].detailDefinitionName);
    96         contactDetail.second =
    99         contactDetail.second =
    97             QLatin1String(versitContactDetailMappings[i].contactDetailValueKey);
   100             QLatin1String(versitContactDetailMappings[i].detailFieldName);
    98         mDetailMappings.insert(versitPropertyName,contactDetail);
   101         mDetailMappings.insert(versitPropertyName,contactDetail);
    99     }
   102     }
   100 
   103 
   101     // Context mappings
   104     // Context mappings
   102     int contextCount = sizeof(versitContextMappings)/sizeof(VersitMapping);
   105     int contextCount = sizeof(versitContextMappings)/sizeof(VersitMapping);
   111     for (int i=0; i < subTypeCount; i++) {
   114     for (int i=0; i < subTypeCount; i++) {
   112         mSubTypeMappings.insert(
   115         mSubTypeMappings.insert(
   113             QLatin1String(versitSubTypeMappings[i].versitString),
   116             QLatin1String(versitSubTypeMappings[i].versitString),
   114             QLatin1String(versitSubTypeMappings[i].contactString));
   117             QLatin1String(versitSubTypeMappings[i].contactString));
   115     }
   118     }
       
   119 
       
   120     mPluginPropertyHandlers = QVersitContactPluginLoader::instance()->createContactHandlers(profile);
   116 }
   121 }
   117 
   122 
   118 /*!
   123 /*!
   119  * Destructor.
   124  * Destructor.
   120  */
   125  */
   121 QVersitContactImporterPrivate::~QVersitContactImporterPrivate()
   126 QVersitContactImporterPrivate::~QVersitContactImporterPrivate()
   122 {
   127 {
   123     delete mDefaultResourceHandler;
   128     delete mDefaultResourceHandler;
       
   129     foreach (QVersitContactHandler* pluginHandler, mPluginPropertyHandlers) {
       
   130         delete pluginHandler;
       
   131     }
   124 }
   132 }
   125 
   133 
   126 /*!
   134 /*!
   127  * Generates a QContact from \a versitDocument.
   135  * Generates a QContact from \a versitDocument.
   128  */
   136  */
   155     }
   163     }
   156 
   164 
   157     contact->setType(QContactType::TypeContact);
   165     contact->setType(QContactType::TypeContact);
   158     QContactManagerEngine::setContactDisplayLabel(contact, QVersitContactImporterPrivate::synthesizedDisplayLabel(*contact));
   166     QContactManagerEngine::setContactDisplayLabel(contact, QVersitContactImporterPrivate::synthesizedDisplayLabel(*contact));
   159 
   167 
       
   168     // run plugin handlers
       
   169     foreach (QVersitContactImporterPropertyHandlerV2* handler, mPluginPropertyHandlers) {
       
   170         handler->documentProcessed(document, contact);
       
   171     }
       
   172     // run the v2 handler, if set
   160     if (mPropertyHandler2 && mPropertyHandlerVersion > 1) {
   173     if (mPropertyHandler2 && mPropertyHandlerVersion > 1) {
   161         mPropertyHandler2->documentProcessed(document, contact);
   174         mPropertyHandler2->documentProcessed(document, contact);
   162     }
   175     }
   163 
   176 
   164     return true;
   177     return true;
   215     } else {
   228     } else {
   216         // Look up mDetailMappings for a simple mapping from property to detail.
   229         // Look up mDetailMappings for a simple mapping from property to detail.
   217         success = createNameValueDetail(property, contact, &updatedDetails);
   230         success = createNameValueDetail(property, contact, &updatedDetails);
   218     }
   231     }
   219 
   232 
       
   233     // run plugin handlers
       
   234     foreach (QVersitContactImporterPropertyHandlerV2* handler, mPluginPropertyHandlers) {
       
   235         handler->propertyProcessed(document, property, *contact, &success, &updatedDetails);
       
   236     }
       
   237     // run the v2 handler, if set
   220     if (mPropertyHandler2 && mPropertyHandlerVersion > 1) {
   238     if (mPropertyHandler2 && mPropertyHandlerVersion > 1) {
   221         mPropertyHandler2->propertyProcessed(document, property, success, *contact, &updatedDetails);
   239         mPropertyHandler2->propertyProcessed(document, property, *contact, &success, &updatedDetails);
   222     }
   240     }
   223 
   241 
   224     foreach (QContactDetail detail, updatedDetails) {
   242     foreach (QContactDetail detail, updatedDetails) {
   225         contact->saveDetail(&detail);
   243         contact->saveDetail(&detail);
   226     }
   244     }
   227 
   245 
       
   246     // run the v1 handler, if set
   228     if (mPropertyHandler && mPropertyHandlerVersion == 1)
   247     if (mPropertyHandler && mPropertyHandlerVersion == 1)
   229         mPropertyHandler->postProcessProperty(document, property, success, contactIndex, contact);
   248         mPropertyHandler->postProcessProperty(document, property, success, contactIndex, contact);
   230 }
   249 }
   231 /*!
   250 /*!
   232  * Creates a QContactName from \a property
   251  * Creates a QContactName from \a property