phonebookengines/VirtualPhonebook/VPbkSimStore/src/CContact.cpp
branchRCL_3
changeset 58 d4f567ce2e7c
parent 0 e686773b3f54
child 64 c1e8ba0c2b16
equal deleted inserted replaced
57:2666d9724c76 58:d4f567ce2e7c
    28 #include "VPbkSimStoreError.h"
    28 #include "VPbkSimStoreError.h"
    29 
    29 
    30 #include <CVPbkAsyncOperation.h>
    30 #include <CVPbkAsyncOperation.h>
    31 #include <CVPbkContactLinkArray.h>
    31 #include <CVPbkContactLinkArray.h>
    32 #include <CVPbkSimContact.h>
    32 #include <CVPbkSimContact.h>
       
    33 #include <CVPbkSimCntField.h>
       
    34 #include <featmgr.h>
    33 #include <MVPbkSimCntStore.h>
    35 #include <MVPbkSimCntStore.h>
    34 #include <MVPbkContactViewBase.h>
    36 #include <MVPbkContactViewBase.h>
    35 #include <MVPbkContactStoreProperties.h>
    37 #include <MVPbkContactStoreProperties.h>
    36 #include <RVPbkStreamedIntArray.h>
    38 #include <RVPbkStreamedIntArray.h>
    37 #include <TVPbkSimStoreProperty.h>
    39 #include <TVPbkSimStoreProperty.h>
    46 enum TContactFlags
    48 enum TContactFlags
    47     {
    49     {
    48     KNewContact = 1
    50     KNewContact = 1
    49     };
    51     };
    50 
    52 
       
    53 const TInt KDefinedAnrFieldTypeCount = 3;   // count of defined additional number types
       
    54 
    51 // ============================= LOCAL FUNCTIONS ===============================
    55 // ============================= LOCAL FUNCTIONS ===============================
    52 
    56 
    53 MVPbkContactObserver::TContactOp ConvertContactOperation(
    57 MVPbkContactObserver::TContactOp ConvertContactOperation(
    54     MVPbkSimContactObserver::TEvent aEvent )
    58     MVPbkSimContactObserver::TEvent aEvent )
    55     {
    59     {
    96                 result = aUsimProp.iMaxNumOfEmails;
   100                 result = aUsimProp.iMaxNumOfEmails;
    97                 }
   101                 }
    98             break;
   102             break;
    99             }
   103             }
   100         case EVPbkSimGsmNumber: // FALLTHROUGH
   104         case EVPbkSimGsmNumber: // FALLTHROUGH
   101         case EVPbkSimAdditionalNumber:
   105         case EVPbkSimAdditionalNumberLast:    // the EVPbkSimAdditionalNumber
   102             {
   106             {
   103             ++result; // always at least one number
   107             ++result; // always at least one number
   104             if ( aUsimProp.iMaxNumOfAnrs != KVPbkSimStorePropertyUndefined )
   108             if ( aUsimProp.iMaxNumOfAnrs != KVPbkSimStorePropertyUndefined )
   105                 {
   109                 {
   106                 result += aUsimProp.iMaxNumOfAnrs;
   110                 if ( !FeatureManager::FeatureSupported(
       
   111                              KFeatureIdFfTdClmcontactreplicationfromphonebooktousimcard ) )
       
   112                     {
       
   113                     result += aUsimProp.iMaxNumOfAnrs;
       
   114                     }
       
   115                 else
       
   116                     {
       
   117                     if ( aUsimProp.iMaxNumOfAnrs - KDefinedAnrFieldTypeCount > 0 )
       
   118                         {
       
   119                         result += (aUsimProp.iMaxNumOfAnrs - KDefinedAnrFieldTypeCount);
       
   120                         }
       
   121                     }
   107                 }
   122                 }
   108             break;
   123             break;
   109             }
   124             }
       
   125         case EVPbkSimAdditionalNumber1:
       
   126             result = aUsimProp.iMaxNumOfAnrs >= 1 ? 1 : 0;   // according the max number of anrs.
       
   127             break;
       
   128         case EVPbkSimAdditionalNumber2:
       
   129             result = aUsimProp.iMaxNumOfAnrs >= 2 ? 1 : 0;
       
   130             break;
       
   131         case EVPbkSimAdditionalNumber3:
       
   132             result = aUsimProp.iMaxNumOfAnrs >= 3 ? 1 : 0;	
       
   133             break;
   110         default:
   134         default:
   111             {
   135             {
   112             // Do nothing
   136             // Do nothing
   113             break;
   137             break;
   114             }
   138             }
   117     }
   141     }
   118 }
   142 }
   119 
   143 
   120 namespace VPbkSimStore {
   144 namespace VPbkSimStore {
   121 
   145 
       
   146 _LIT( KEmptyData, "+" );    //the empty data, modifiy this string to keep its a special string.
   122 // ============================ MEMBER FUNCTIONS ===============================
   147 // ============================ MEMBER FUNCTIONS ===============================
   123 
   148 
   124 // -----------------------------------------------------------------------------
   149 // -----------------------------------------------------------------------------
   125 // CContact::CContact
   150 // CContact::CContact
   126 // C++ default constructor can NOT contain any code, that
   151 // C++ default constructor can NOT contain any code, that
   141     TBool aIsNewContact )
   166     TBool aIsNewContact )
   142     {
   167     {
   143     if ( aIsNewContact )
   168     if ( aIsNewContact )
   144         {
   169         {
   145         iFlags.Set( KNewContact );
   170         iFlags.Set( KNewContact );
       
   171         }
       
   172     if( FeatureManager::FeatureSupported( 
       
   173                         KFeatureIdFfTdClmcontactreplicationfromphonebooktousimcard ) )
       
   174         {
       
   175         RemoveAllEmptyFields( aSimContact );    //  remove the empty contacts where added before save.
   146         }
   176         }
   147     iFields.SetContact( *this, aSimContact );
   177     iFields.SetContact( *this, aSimContact );
   148     iAsyncOp = new( ELeave ) VPbkEngUtils::CVPbkAsyncOperation;
   178     iAsyncOp = new( ELeave ) VPbkEngUtils::CVPbkAsyncOperation;
   149     }
   179     }
   150 
   180 
   169 CContact::~CContact()
   199 CContact::~CContact()
   170     {
   200     {
   171     delete iStoreOperation;
   201     delete iStoreOperation;
   172     delete iAsyncOp;
   202     delete iAsyncOp;
   173     delete iSimContact;
   203     delete iSimContact;
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CContact::RemoveAllEmptyFields
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 void CContact::RemoveAllEmptyFields( CVPbkSimContact& aSimContact )
       
   211     {
       
   212     TInt i = aSimContact.FieldCount() - 1 ;
       
   213     while( i >= 0 )
       
   214         {
       
   215 		CVPbkSimCntField& cntField = aSimContact.FieldAt( i );
       
   216 		TVPbkSimCntFieldType simCntType = cntField.Type();
       
   217         if( simCntType ==  EVPbkSimGsmNumber
       
   218 		    || simCntType == EVPbkSimAdditionalNumber1
       
   219 			|| simCntType == EVPbkSimAdditionalNumber2
       
   220 			|| simCntType == EVPbkSimAdditionalNumber3
       
   221 			|| simCntType == EVPbkSimAdditionalNumberLast )
       
   222         	{
       
   223 			if( cntField. Data().Compare( KEmptyData ) == 0 )
       
   224 				{
       
   225 				aSimContact.DeleteField( i );
       
   226 				}
       
   227         	}
       
   228         i --;
       
   229         }
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CContact::FillWithEmptyFieldsL
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 void CContact::FillWithEmptyFieldsL() const
       
   237     {
       
   238     RPointerArray<CVPbkSimCntField> & contactFieldArray = iSimContact->FieldArray();
       
   239     TInt i = contactFieldArray.Count() - 1 ;
       
   240 	while( i >= 0 ) // remove all empty content.
       
   241 		{
       
   242 		CVPbkSimCntField& cntField = iSimContact->FieldAt( i );
       
   243 		TVPbkSimCntFieldType type = cntField.Type();
       
   244 		if( cntField. Data().Length() == 0 )
       
   245 			{
       
   246 			iSimContact->DeleteField( i );
       
   247 			}
       
   248 		i --;
       
   249 		}
       
   250 	
       
   251     if( contactFieldArray.Count() == 0 )  // no un-empty fields.
       
   252         {
       
   253         return;
       
   254         }
       
   255     CVPbkSimContact::TFieldLookup lookupAdnNumber = 
       
   256                        iSimContact->FindField( EVPbkSimAdditionalNumber );  
       
   257     if( lookupAdnNumber.EndOfLookup())  // if there is no additional number in the contact then no need to add placeholder
       
   258     	{
       
   259 		return;
       
   260     	}
       
   261     RPointerArray<CVPbkSimCntField> tempFieldArray;
       
   262     CleanupClosePushL( tempFieldArray );
       
   263     // mappings 
       
   264     CFieldTypeMappings & mappings = iParentStore.FieldTypeMappings();
       
   265     // supported types.
       
   266     const CSupportedFieldTypes& supportedTypes = iParentStore.SupportedFieldTypes();
       
   267 
       
   268     // check all supported field types in the fields list. If not exist created new.
       
   269     // if data length is 0, set data to empty data.
       
   270     for( int i = 0; i < supportedTypes.FieldTypeCount(); i ++ )
       
   271         {
       
   272         const MVPbkFieldType& fieldType = supportedTypes.FieldTypeAt( i );
       
   273         TVPbkSimCntFieldType simCntType = mappings.Match( fieldType );
       
   274         if( simCntType ==  EVPbkSimGsmNumber
       
   275 		    || simCntType == EVPbkSimAdditionalNumber1
       
   276 			|| simCntType == EVPbkSimAdditionalNumber2
       
   277 			|| simCntType == EVPbkSimAdditionalNumber3
       
   278 			|| simCntType == EVPbkSimAdditionalNumberLast )
       
   279             {
       
   280             CVPbkSimCntField * field = NULL;
       
   281             CVPbkSimContact::TFieldLookup lookup = 
       
   282                    iSimContact->FindField( simCntType );
       
   283 
       
   284             if( lookup.EndOfLookup() )
       
   285                 {
       
   286                 field= iSimContact->CreateFieldLC( simCntType );
       
   287                 field->SetDataL( KEmptyData );
       
   288                 tempFieldArray.Append( field );
       
   289                 CleanupStack::Pop();
       
   290                 }
       
   291              else
       
   292                 {
       
   293                 field = contactFieldArray[lookup.Index()];
       
   294                 if( field->Data().Length() == 0 )
       
   295                     {
       
   296                     field->SetDataL( KEmptyData );
       
   297                     }
       
   298                 if( simCntType == EVPbkSimAdditionalNumber1 
       
   299                     || simCntType == EVPbkSimAdditionalNumber2
       
   300                     || simCntType == EVPbkSimAdditionalNumber3 )
       
   301                     {
       
   302                     contactFieldArray.Remove( lookup.Index() );
       
   303                     tempFieldArray.AppendL( field );
       
   304                     }
       
   305                 }
       
   306             }
       
   307         }
       
   308     TInt j = contactFieldArray.Count() - 1;
       
   309     while( j >= 0 )  //  EVPbkSimAdditionalNumberLast type field will append at last.
       
   310         {
       
   311         if( contactFieldArray[j]->Type() == EVPbkSimAdditionalNumberLast )
       
   312             {
       
   313             tempFieldArray.AppendL( contactFieldArray[ j ] );
       
   314             contactFieldArray.Remove( j );
       
   315             }
       
   316         j --;
       
   317         }
       
   318     for( int i = 0; i < tempFieldArray.Count(); i ++ )
       
   319         {
       
   320         contactFieldArray.AppendL( tempFieldArray[i]);
       
   321         }
       
   322     tempFieldArray.Reset();
       
   323     CleanupStack::Pop();
   174     }
   324     }
   175 
   325 
   176 // -----------------------------------------------------------------------------
   326 // -----------------------------------------------------------------------------
   177 // CContact::ParentObject
   327 // CContact::ParentObject
   178 // -----------------------------------------------------------------------------
   328 // -----------------------------------------------------------------------------
   299     
   449     
   300     __ASSERT_DEBUG( simType != EVPbkSimUnknownType,
   450     __ASSERT_DEBUG( simType != EVPbkSimUnknownType,
   301         VPbkSimStore::Panic( ESimFieldTypeNotFound ) );
   451         VPbkSimStore::Panic( ESimFieldTypeNotFound ) );
   302 
   452 
   303     if ( simType == EVPbkSimGsmNumber || 
   453     if ( simType == EVPbkSimGsmNumber || 
   304          simType == EVPbkSimAdditionalNumber )
   454          simType == EVPbkSimAdditionalNumberLast )  //the same field type as EVPbkSimGsmNumber
   305         {
   455         {
   306         // EVPbkSimGsmNumber and EVPbkSimAdditionalNumber maps to same
   456         // EVPbkSimGsmNumber and EVPbkSimAdditionalNumber maps to same
   307         // VPbk field type. A sim contact can have only one EVPbkSimGsmNumber
   457         // VPbk field type. A sim contact can have only one EVPbkSimGsmNumber
   308         // field type and possibly many EVPbkSimAdditionalNumber types 
   458         // field type and possibly many EVPbkSimAdditionalNumber types 
   309         // depending on the USIM store.
   459         // depending on the USIM store.
   318             {
   468             {
   319             simType = EVPbkSimGsmNumber;
   469             simType = EVPbkSimGsmNumber;
   320             }
   470             }
   321         else
   471         else
   322             {
   472             {
   323             simType = EVPbkSimAdditionalNumber;
   473             simType = EVPbkSimAdditionalNumberLast; 
   324             }
   474             }
   325         }
   475         }
   326 
   476 
   327     CVPbkSimCntField* field = iSimContact->CreateFieldLC( simType );
   477     CVPbkSimCntField* field = iSimContact->CreateFieldLC( simType );
   328     TContactNewField* fieldWrapper = new( ELeave ) TContactNewField( field );
   478     TContactNewField* fieldWrapper = new( ELeave ) TContactNewField( field );
   419             {
   569             {
   420             User::Leave( KErrInUse );
   570             User::Leave( KErrInUse );
   421             }
   571             }
   422         // From the client point of view the MVPbkStoreContact is constant but
   572         // From the client point of view the MVPbkStoreContact is constant but
   423         // implementation needs a non const contact.
   573         // implementation needs a non const contact.
       
   574         if( FeatureManager::FeatureSupported( KFeatureIdFfTdClmcontactreplicationfromphonebooktousimcard ) )
       
   575             {
       
   576             FillWithEmptyFieldsL();
       
   577             }
   424         iStoreOperation = iSimContact->SaveL( const_cast<CContact&>( *this ));
   578         iStoreOperation = iSimContact->SaveL( const_cast<CContact&>( *this ));
   425         iObserver = &aObserver;
   579         iObserver = &aObserver;
   426         }
   580         }
   427     else
   581     else
   428         {
   582         {
   496     vpbkOpResult.iExtension = NULL;
   650     vpbkOpResult.iExtension = NULL;
   497     vpbkOpResult.iOpCode = ConvertContactOperation( aEvent );
   651     vpbkOpResult.iOpCode = ConvertContactOperation( aEvent );
   498     
   652     
   499     MVPbkContactObserver* observer = iObserver;
   653     MVPbkContactObserver* observer = iObserver;
   500     ResetContactOperationState();
   654     ResetContactOperationState();
       
   655     
       
   656     // remove filled placeholder fields.
       
   657     if( vpbkOpResult.iOpCode == MVPbkContactObserver::EContactCommit )
       
   658     	{
       
   659 		RemoveAllEmptyFields( *iSimContact );
       
   660     	}
   501     observer->ContactOperationCompleted( vpbkOpResult );
   661     observer->ContactOperationCompleted( vpbkOpResult );
   502     }
   662     }
   503 
   663 
   504 // -----------------------------------------------------------------------------
   664 // -----------------------------------------------------------------------------
   505 // CContact::ContactEventError
   665 // CContact::ContactEventError
   514     iStoreOperation = NULL;
   674     iStoreOperation = NULL;
   515     
   675     
   516     MVPbkContactObserver* observer = iObserver;
   676     MVPbkContactObserver* observer = iObserver;
   517     ResetContactOperationState();
   677     ResetContactOperationState();
   518     MVPbkContactObserver::TContactOp op = ConvertContactOperation( aEvent );
   678     MVPbkContactObserver::TContactOp op = ConvertContactOperation( aEvent );
       
   679     
       
   680     // remove filled placeholder fields.
       
   681     if( op == MVPbkContactObserver::EContactCommit )
       
   682     	{
       
   683 		RemoveAllEmptyFields( *iSimContact );
       
   684     	}
   519     observer->ContactOperationFailed( op, aError, EFalse );
   685     observer->ContactOperationFailed( op, aError, EFalse );
   520     } 
   686     } 
   521 
   687 
   522 // -----------------------------------------------------------------------------
   688 // -----------------------------------------------------------------------------
   523 // CContact::ResetContactOperationState
   689 // CContact::ResetContactOperationState