phonebookui/pbkcommonui/src/cntphonenumbermodel.cpp
changeset 46 efe85016a067
parent 40 b46a585f6909
child 47 7cbcb2896f0e
--- a/phonebookui/pbkcommonui/src/cntphonenumbermodel.cpp	Fri Jun 11 13:29:23 2010 +0300
+++ b/phonebookui/pbkcommonui/src/cntphonenumbermodel.cpp	Wed Jun 23 18:02:44 2010 +0300
@@ -17,6 +17,7 @@
 #include "cntphonenumbermodel.h"
 #include "cntdetailconst.h"
 #include "cntdetailmodelitem.h"
+#include "cntdetailorderinghelper.h"
 #include <hbdataformmodelitem.h>
 #include <QDebug>
 
@@ -26,22 +27,26 @@
     setParent( aParent );
     
     QList<QContactDetail> all;
-    foreach ( QContactDetail detail, mContact->details<QContactPhoneNumber>() )
+    foreach ( QContactDetail detail, CntDetailOrderingHelper::getOrderedSupportedPhoneNumbers(*mContact) )
+    {
         all.append( detail );
+        mNumberList.append( detail );
+    }
     
-    foreach ( QContactDetail detail, mContact->details<QContactOnlineAccount>() )
+    foreach ( QContactDetail detail, CntDetailOrderingHelper::getOrderedSupportedOnlineAccounts(*mContact) )
+    {
         all.append( detail );
+        mNumberList.append( detail );
+    }
     
     // if there's no details, add 
     if ( all.isEmpty() )
         {
-        QContactPhoneNumber mobileNumber;
-        mobileNumber.setSubTypes( QContactPhoneNumber::SubTypeMobile );
-        all.append( mobileNumber );
+        mMobileTemplate.setSubTypes( QContactPhoneNumber::SubTypeMobile );
+        all.append( mMobileTemplate );
 
-        QContactPhoneNumber landLineNumber;
-        landLineNumber.setSubTypes( QContactPhoneNumber::SubTypeLandline );
-        all.append( landLineNumber );
+        mLandlineTemplate.setSubTypes( QContactPhoneNumber::SubTypeLandline );
+        all.append( mLandlineTemplate );
         }
             
     HbDataFormModelItem* root = invisibleRootItem();
@@ -68,17 +73,32 @@
     for ( int i = 0; i < count; i++ ) {
         CntDetailModelItem* item = static_cast<CntDetailModelItem*>( root->childAt(i) );
         QContactDetail detail = item->detail();
-        mContact->saveDetail( &detail );
         
         if ( detail.definitionName() == QContactPhoneNumber::DefinitionName )
         {
+            QContactPhoneNumber number = detail;
+            if ( !mNumberList.contains(detail) )
+            {
+                mContact->saveDetail( &detail );
+            }
+            
             if ( detail.value(QContactPhoneNumber::FieldNumber).isEmpty() )
+            {
+                // this won't change the pointer value if the detail does not exists in contact.
+                // But, this is the situation in wk20...
                 mContact->removeDetail( &detail );
+            }
         }
         
         if ( detail.definitionName() == QContactOnlineAccount::DefinitionName )
         {
-            if ( detail.value(QContactOnlineAccount::FieldAccountUri).isEmpty() )
+            QContactOnlineAccount account = detail;
+            if ( !mNumberList.contains(detail) && !account.accountUri().isEmpty() )
+            {
+                mContact->saveDetail( &detail );
+            }
+            
+            if ( account.accountUri().isEmpty() )
             {
                 mContact->removeDetail( &detail );
             }