phonebookengines/VirtualPhonebook/VPbkSimStore/src/CContact.cpp
branchRCL_3
changeset 85 38bb213f60ba
parent 63 f4a778e096c2
equal deleted inserted replaced
74:6b5524b4f673 85:38bb213f60ba
    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>
       
    35 #include <MVPbkSimCntStore.h>
    33 #include <MVPbkSimCntStore.h>
    36 #include <MVPbkContactViewBase.h>
    34 #include <MVPbkContactViewBase.h>
    37 #include <MVPbkContactStoreProperties.h>
    35 #include <MVPbkContactStoreProperties.h>
    38 #include <RVPbkStreamedIntArray.h>
    36 #include <RVPbkStreamedIntArray.h>
    39 #include <TVPbkSimStoreProperty.h>
    37 #include <TVPbkSimStoreProperty.h>
    48 enum TContactFlags
    46 enum TContactFlags
    49     {
    47     {
    50     KNewContact = 1
    48     KNewContact = 1
    51     };
    49     };
    52 
    50 
    53 const TInt KDefinedAnrFieldTypeCount = 3;   // count of defined additional number types
       
    54 
       
    55 // ============================= LOCAL FUNCTIONS ===============================
    51 // ============================= LOCAL FUNCTIONS ===============================
    56 
    52 
    57 MVPbkContactObserver::TContactOp ConvertContactOperation(
    53 MVPbkContactObserver::TContactOp ConvertContactOperation(
    58     MVPbkSimContactObserver::TEvent aEvent )
    54     MVPbkSimContactObserver::TEvent aEvent )
    59     {
    55     {
   100                 result = aUsimProp.iMaxNumOfEmails;
    96                 result = aUsimProp.iMaxNumOfEmails;
   101                 }
    97                 }
   102             break;
    98             break;
   103             }
    99             }
   104         case EVPbkSimGsmNumber: // FALLTHROUGH
   100         case EVPbkSimGsmNumber: // FALLTHROUGH
   105         case EVPbkSimAdditionalNumberLast:    // the EVPbkSimAdditionalNumber
   101         case EVPbkSimAdditionalNumber:
   106             {
   102             {
   107             ++result; // always at least one number
   103             ++result; // always at least one number
   108             if ( aUsimProp.iMaxNumOfAnrs != KVPbkSimStorePropertyUndefined )
   104             if ( aUsimProp.iMaxNumOfAnrs != KVPbkSimStorePropertyUndefined )
   109                 {
   105                 {
   110                 if ( !FeatureManager::FeatureSupported(
   106                 result += aUsimProp.iMaxNumOfAnrs;
   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                     }
       
   122                 }
   107                 }
   123             break;
   108             break;
   124             }
   109             }
   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;
       
   134         default:
   110         default:
   135             {
   111             {
   136             // Do nothing
   112             // Do nothing
   137             break;
   113             break;
   138             }
   114             }
   141     }
   117     }
   142 }
   118 }
   143 
   119 
   144 namespace VPbkSimStore {
   120 namespace VPbkSimStore {
   145 
   121 
   146 _LIT( KEmptyData, "+" );    //the empty data, modifiy this string to keep its a special string.
       
   147 // ============================ MEMBER FUNCTIONS ===============================
   122 // ============================ MEMBER FUNCTIONS ===============================
   148 
   123 
   149 // -----------------------------------------------------------------------------
   124 // -----------------------------------------------------------------------------
   150 // CContact::CContact
   125 // CContact::CContact
   151 // C++ default constructor can NOT contain any code, that
   126 // C++ default constructor can NOT contain any code, that
   166     TBool aIsNewContact )
   141     TBool aIsNewContact )
   167     {
   142     {
   168     if ( aIsNewContact )
   143     if ( aIsNewContact )
   169         {
   144         {
   170         iFlags.Set( KNewContact );
   145         iFlags.Set( KNewContact );
   171         }
       
   172     if( FeatureManager::FeatureSupported( 
       
   173                         KFeatureIdFfTdClmcontactreplicationfromphonebooktousimcard ) )
       
   174         {
       
   175         RemoveAllEmptyFields( aSimContact );    //  remove the empty contacts where added before save.
       
   176         }
   146         }
   177     iFields.SetContact( *this, aSimContact );
   147     iFields.SetContact( *this, aSimContact );
   178     iAsyncOp = new( ELeave ) VPbkEngUtils::CVPbkAsyncOperation;
   148     iAsyncOp = new( ELeave ) VPbkEngUtils::CVPbkAsyncOperation;
   179     }
   149     }
   180 
   150 
   199 CContact::~CContact()
   169 CContact::~CContact()
   200     {
   170     {
   201     delete iStoreOperation;
   171     delete iStoreOperation;
   202     delete iAsyncOp;
   172     delete iAsyncOp;
   203     delete iSimContact;
   173     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();
       
   324     }
   174     }
   325 
   175 
   326 // -----------------------------------------------------------------------------
   176 // -----------------------------------------------------------------------------
   327 // CContact::ParentObject
   177 // CContact::ParentObject
   328 // -----------------------------------------------------------------------------
   178 // -----------------------------------------------------------------------------
   449     
   299     
   450     __ASSERT_DEBUG( simType != EVPbkSimUnknownType,
   300     __ASSERT_DEBUG( simType != EVPbkSimUnknownType,
   451         VPbkSimStore::Panic( ESimFieldTypeNotFound ) );
   301         VPbkSimStore::Panic( ESimFieldTypeNotFound ) );
   452 
   302 
   453     if ( simType == EVPbkSimGsmNumber || 
   303     if ( simType == EVPbkSimGsmNumber || 
   454          simType == EVPbkSimAdditionalNumberLast )  //the same field type as EVPbkSimGsmNumber
   304          simType == EVPbkSimAdditionalNumber )
   455         {
   305         {
   456         // EVPbkSimGsmNumber and EVPbkSimAdditionalNumber maps to same
   306         // EVPbkSimGsmNumber and EVPbkSimAdditionalNumber maps to same
   457         // VPbk field type. A sim contact can have only one EVPbkSimGsmNumber
   307         // VPbk field type. A sim contact can have only one EVPbkSimGsmNumber
   458         // field type and possibly many EVPbkSimAdditionalNumber types 
   308         // field type and possibly many EVPbkSimAdditionalNumber types 
   459         // depending on the USIM store.
   309         // depending on the USIM store.
   468             {
   318             {
   469             simType = EVPbkSimGsmNumber;
   319             simType = EVPbkSimGsmNumber;
   470             }
   320             }
   471         else
   321         else
   472             {
   322             {
   473             simType = EVPbkSimAdditionalNumberLast; 
   323             simType = EVPbkSimAdditionalNumber;
   474             }
   324             }
   475         }
   325         }
   476 
   326 
   477     CVPbkSimCntField* field = iSimContact->CreateFieldLC( simType );
   327     CVPbkSimCntField* field = iSimContact->CreateFieldLC( simType );
   478     TContactNewField* fieldWrapper = new( ELeave ) TContactNewField( field );
   328     TContactNewField* fieldWrapper = new( ELeave ) TContactNewField( field );
   569             {
   419             {
   570             User::Leave( KErrInUse );
   420             User::Leave( KErrInUse );
   571             }
   421             }
   572         // From the client point of view the MVPbkStoreContact is constant but
   422         // From the client point of view the MVPbkStoreContact is constant but
   573         // implementation needs a non const contact.
   423         // implementation needs a non const contact.
   574         if( FeatureManager::FeatureSupported( KFeatureIdFfTdClmcontactreplicationfromphonebooktousimcard ) )
       
   575             {
       
   576             FillWithEmptyFieldsL();
       
   577             }
       
   578         iStoreOperation = iSimContact->SaveL( const_cast<CContact&>( *this ));
   424         iStoreOperation = iSimContact->SaveL( const_cast<CContact&>( *this ));
   579         iObserver = &aObserver;
   425         iObserver = &aObserver;
   580         }
   426         }
   581     else
   427     else
   582         {
   428         {
   650     vpbkOpResult.iExtension = NULL;
   496     vpbkOpResult.iExtension = NULL;
   651     vpbkOpResult.iOpCode = ConvertContactOperation( aEvent );
   497     vpbkOpResult.iOpCode = ConvertContactOperation( aEvent );
   652     
   498     
   653     MVPbkContactObserver* observer = iObserver;
   499     MVPbkContactObserver* observer = iObserver;
   654     ResetContactOperationState();
   500     ResetContactOperationState();
   655     
       
   656     // remove filled placeholder fields.
       
   657     if( vpbkOpResult.iOpCode == MVPbkContactObserver::EContactCommit )
       
   658     	{
       
   659 		RemoveAllEmptyFields( *iSimContact );
       
   660     	}
       
   661     observer->ContactOperationCompleted( vpbkOpResult );
   501     observer->ContactOperationCompleted( vpbkOpResult );
   662     }
   502     }
   663 
   503 
   664 // -----------------------------------------------------------------------------
   504 // -----------------------------------------------------------------------------
   665 // CContact::ContactEventError
   505 // CContact::ContactEventError
   674     iStoreOperation = NULL;
   514     iStoreOperation = NULL;
   675     
   515     
   676     MVPbkContactObserver* observer = iObserver;
   516     MVPbkContactObserver* observer = iObserver;
   677     ResetContactOperationState();
   517     ResetContactOperationState();
   678     MVPbkContactObserver::TContactOp op = ConvertContactOperation( aEvent );
   518     MVPbkContactObserver::TContactOp op = ConvertContactOperation( aEvent );
   679     
       
   680     // remove filled placeholder fields.
       
   681     if( op == MVPbkContactObserver::EContactCommit )
       
   682     	{
       
   683 		RemoveAllEmptyFields( *iSimContact );
       
   684     	}
       
   685     observer->ContactOperationFailed( op, aError, EFalse );
   519     observer->ContactOperationFailed( op, aError, EFalse );
   686     } 
   520     } 
   687 
   521 
   688 // -----------------------------------------------------------------------------
   522 // -----------------------------------------------------------------------------
   689 // CContact::ResetContactOperationState
   523 // CContact::ResetContactOperationState