phonebookui/phonebookservices/src/cntservices.cpp
changeset 66 554fe4dbbb59
parent 61 d30183af6ca6
child 72 6abfb1094884
--- a/phonebookui/phonebookservices/src/cntservices.cpp	Mon Aug 23 16:06:28 2010 +0300
+++ b/phonebookui/phonebookservices/src/cntservices.cpp	Fri Sep 03 14:32:33 2010 +0300
@@ -83,15 +83,6 @@
     CntServiceViewManager* srvMng = static_cast<CntServiceViewManager*>(mViewManager);
     connect(srvMng, SIGNAL(applicationClosed()), this, SLOT(terminateService()));
 }
-/*
-void CntServices::setViewManager( CntAbstractViewManager& aViewManager )
-{
-    CNT_LOG
-    mViewManager = &aViewManager;
-    CntServiceViewManager* srvMng = static_cast<CntServiceViewManager*>(mViewManager);
-    connect(srvMng, SIGNAL(applicationClosed()), this, SLOT(terminateService()));
-}
-*/
 
 void CntServices::singleFetch(
     const QString &title, const QString &action,
@@ -227,6 +218,9 @@
         }
     vCardFile.close();
     
+    // check if the contact is in db already.
+    updateLocalId( contact );
+    
     // Save thumbnail images
     QList<QContactThumbnail> details = contact.details<QContactThumbnail>();
     for (int i = 0;i < details.count();i++)
@@ -550,6 +544,33 @@
         }
     }
 
+void CntServices::updateLocalId( QContact& aContact )
+{
+    CNT_ENTRY
+    if ( aContact.localId() == 0 )
+        {
+        QContactGuid guid = aContact.detail<QContactGuid>();
+        QString guidString = guid.guid();
+            
+        QContactDetailFilter filter;
+        filter.setDetailDefinitionName( QContactGuid::DefinitionName, QContactGuid::FieldGuid );
+        filter.setValue( guid.guid() );
+            
+        QContactManager& cm = mEngine->contactManager( SYMBIAN_BACKEND );
+        QList<QContactLocalId> idList = cm.contactIds( filter, QList<QContactSortOrder>() );
+        int count = idList.count();
+        
+        if ( !idList.isEmpty() )
+            {
+            QContactId id;
+            id.setLocalId( idList.first() );
+            id.setManagerUri( cm.managerUri() );
+            
+            aContact.setId( id );
+            }
+        }
+    CNT_EXIT
+}
 // This method is inherited from CntAbstractServiceProvider
 void CntServices::CompleteServiceAndCloseApp(const QVariant& retValue)
 {