PECengine/ListLibrary2/AttrListSrc/CPEngAttributeListTransactionManager.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Attribute list transaction manager
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "CPEngAttributeListTransactionManager.h"
       
    20 #include "PEngListLibraryFactory.h"
       
    21 #include "MPEngListLibFactory.h"
       
    22 #include "PEngPresenceEngineConsts2.h"
       
    23 #include "CPEngContactListTransactionManager.h"
       
    24 #include "CPEngContactListSettings.h"
       
    25 #include "CPEngAttributeListItem.h"
       
    26 #include "CPEngAttributeListTransCreateAttrList.h"
       
    27 #include "CPEngAttributeListTransDeleteAttrList.h"
       
    28 #include "MPEngStorageManager.h"
       
    29 #include "PEngAttrLibFactory.h"
       
    30 #include "MPEngPresenceAttrManager.h"
       
    31 #include "PEngMessagePacker.h"
       
    32 #include "PresenceDebugPrint.h"
       
    33 #include <e32std.h>
       
    34 
       
    35 
       
    36 // MACROS
       
    37 #define CONTINUE_IF( a )\
       
    38     if ( a )\
       
    39         {\
       
    40         continue;\
       
    41         }
       
    42 
       
    43 
       
    44 //Default granurality for ID lists
       
    45 const TInt KAttributeListIdGranurality = 3;
       
    46 
       
    47 
       
    48 
       
    49 // ============================ MEMBER FUNCTIONS ===============================
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CPEngAttributeListTransactionManager::CPEngAttributeListTransactionManager()
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CPEngAttributeListTransactionManager::CPEngAttributeListTransactionManager(
       
    56     MPEngListLibFactory& aFactory,
       
    57     TPEngWVCspVersion& aCSPVersion )
       
    58         : CPEngAttributeListManager( aFactory ),
       
    59         iCSPVersion( aCSPVersion )
       
    60     {
       
    61     }
       
    62 
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CPEngAttributeListTransactionManager::ConstructL()
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 void CPEngAttributeListTransactionManager::ConstructL(
       
    69     const CPEngSessionSlotId& aSessionSlot )
       
    70     {
       
    71     CPEngAttributeListManager::ConstructL( aSessionSlot );
       
    72     iContactListTransManager = static_cast <CPEngContactListTransactionManager*>
       
    73                                ( PEngListLibraryFactory::ContactListTransactionManagerLC( aSessionSlot ) );
       
    74 
       
    75     CleanupStack::Pop();
       
    76     }
       
    77 
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CPEngAttributeListTransactionManager::NewL()
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CPEngAttributeListTransactionManager* CPEngAttributeListTransactionManager::NewL(
       
    84     MPEngListLibFactory& aFactory,
       
    85     const CPEngSessionSlotId& aSessionSlot,
       
    86     TPEngWVCspVersion& aCSPVersion )
       
    87     {
       
    88     CPEngAttributeListTransactionManager* self = NewLC( aFactory,
       
    89                                                         aSessionSlot,
       
    90                                                         aCSPVersion );
       
    91     CleanupStack::Pop();
       
    92 
       
    93     return self;
       
    94     }
       
    95 
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CPEngAttributeListTransactionManager::NewLC()
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 CPEngAttributeListTransactionManager* CPEngAttributeListTransactionManager::NewLC(
       
   102     MPEngListLibFactory& aFactory,
       
   103     const CPEngSessionSlotId& aSessionSlot,
       
   104     TPEngWVCspVersion& aCSPVersion )
       
   105     {
       
   106     CPEngAttributeListTransactionManager* self =
       
   107         new( ELeave ) CPEngAttributeListTransactionManager( aFactory,
       
   108                                                             aCSPVersion );
       
   109 
       
   110     CleanupClosePushL( *self );
       
   111     self->ConstructL( aSessionSlot );
       
   112 
       
   113     return self;
       
   114     }
       
   115 
       
   116 
       
   117 //   Destructor
       
   118 CPEngAttributeListTransactionManager::~CPEngAttributeListTransactionManager()
       
   119     {
       
   120     if ( iContactListTransManager )
       
   121         {
       
   122         iContactListTransManager->Close();
       
   123         }
       
   124     }
       
   125 
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CPEngAttributeListTransactionManager::Close()
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 void CPEngAttributeListTransactionManager::Close()
       
   132     {
       
   133     iAccessCount--;
       
   134     if ( iAccessCount == 0 )
       
   135         {
       
   136         iFactory.RemoveAttrListTransManager( this );
       
   137         delete this;
       
   138         }
       
   139     }
       
   140 
       
   141 
       
   142 
       
   143 // =============================================================================
       
   144 // ============ Functions of the MPEngTransactionFactory class ===============
       
   145 // =============================================================================
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CPEngAttributeListTransactionManager::IncomingTransactionHandlerL()
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 MPEngIncomingTransactionHandler*
       
   152 CPEngAttributeListTransactionManager::IncomingTransactionHandlerL(
       
   153     const TDesC8& /* aIncomingRequest */ )
       
   154     {
       
   155     return NULL;
       
   156     }
       
   157 
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CPEngAttributeListTransactionManager::OutgoingTransactionHandlerL()
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CPEngAttributeListTransactionManager::OutgoingTransactionHandlerL(
       
   164     TInt aOperation,
       
   165     const TDesC& /*aData*/,
       
   166     RPointerArray<MPEngOutgoingTransactionHandler>& aHandlers )
       
   167     {
       
   168     PENG_DP( D_PENG_LIT( "CPEngAttributeListTransactionManager::OutgoingTransactionHandlerL()" ) );
       
   169 
       
   170     switch ( aOperation )
       
   171         {
       
   172         case EPEngTransOpAttrListPublish:
       
   173             {
       
   174             // Make sure that we are handling most up-to-date data
       
   175             iStorageManager->RetrieveL( *this );
       
   176 
       
   177             if ( !iSynchronized )
       
   178                 {
       
   179                 GetSyncHandlersL( aHandlers, aOperation );
       
   180                 }
       
   181             else
       
   182                 {
       
   183                 GetAttributeListsUpdateHandlersL( aHandlers, aOperation );
       
   184                 }
       
   185 
       
   186             break;
       
   187             }
       
   188 
       
   189         default:
       
   190             {
       
   191             }
       
   192         }
       
   193     }
       
   194 
       
   195 
       
   196 
       
   197 // =============================================================================
       
   198 // ============ From MPEngAttributeListTransactionManager ======================
       
   199 // =============================================================================
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CPEngAttributeListTransactionManager::AttributeListCreated()
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 void CPEngAttributeListTransactionManager::AttributeListCreated(
       
   206     const RArray<TUint32>& aAttrList )
       
   207     {
       
   208     TInt index ( FindAttributeList( aAttrList ) );
       
   209     if ( index != KErrNotFound )
       
   210         {
       
   211         iAttributeLists[ index ]->SetSynchronization( ETrue );
       
   212         }
       
   213     }
       
   214 
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // CPEngAttributeListTransactionManager::AttributeEngineSynchronizedL()
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 void CPEngAttributeListTransactionManager::AttributeEngineSynchronizedL()
       
   221     {
       
   222     iSyncHandlerCount--;
       
   223     if ( !iSyncHandlerCount )
       
   224         {
       
   225         iSynchronized = ETrue;
       
   226         StoreChangesL();
       
   227         }
       
   228     }
       
   229 
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CPEngAttributeListTransactionManager::CommitContactL()
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 void CPEngAttributeListTransactionManager::CommitContactListL(
       
   236     const TDesC& aContactList )
       
   237     {
       
   238     CommitContactL( aContactList,
       
   239                     &CPEngAttributeListItem::CommitContactListL,
       
   240                     iDeleteAttrListContactLists );
       
   241     }
       
   242 
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // CPEngAttributeListTransactionManager::CommitContactIdL()
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 void CPEngAttributeListTransactionManager::CommitContactIdL(
       
   249     const TDesC& aContactId )
       
   250     {
       
   251     CommitContactL( aContactId,
       
   252                     &CPEngAttributeListItem::CommitContactIdL,
       
   253                     iDeleteAttrListContactIDs );
       
   254     }
       
   255 
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // CPEngAttributeListTransactionManager::RollBackContactListL()
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 void CPEngAttributeListTransactionManager::RollBackContactListL(
       
   262     const TDesC& aContactList )
       
   263     {
       
   264     RollBackOneContactL( aContactList,
       
   265                          CPEngAttributeListItem::ENewContactLists,
       
   266                          iDeleteAttrListContactLists );
       
   267     }
       
   268 
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // CPEngAttributeListTransactionManager::RollBackContactIdL()
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 void CPEngAttributeListTransactionManager::RollBackContactIdL(
       
   275     const TDesC& aContactId )
       
   276     {
       
   277     RollBackOneContactL( aContactId,
       
   278                          CPEngAttributeListItem::ENewContactIDs,
       
   279                          iDeleteAttrListContactIDs );
       
   280     }
       
   281 
       
   282 
       
   283 // -----------------------------------------------------------------------------
       
   284 // CPEngAttributeListTransactionManager::CommitDefaultL()
       
   285 // -----------------------------------------------------------------------------
       
   286 //
       
   287 void CPEngAttributeListTransactionManager::CommitDefaultL()
       
   288     {
       
   289     // go through all Attribute lists and commit Default flag
       
   290     // if attribute list is without any contact after commiting
       
   291     // and it isn't default or to be new default,
       
   292     // this attribute list will be deleted in CompressAtrrListArray function
       
   293     for ( TInt x ( iAttributeLists.Count() - 1 ) ;  x >= 0 ; x-- )
       
   294         {
       
   295         // commit default to each
       
   296         iAttributeLists[x]->CommitDefault();
       
   297         }
       
   298     iDeleteDefaultAttrList = EFalse;
       
   299 
       
   300     // now compress array
       
   301     CompressArrListArray();
       
   302     }
       
   303 
       
   304 
       
   305 // -----------------------------------------------------------------------------
       
   306 // CPEngAttributeListTransactionManager::RollBackDefaultL()
       
   307 // -----------------------------------------------------------------------------
       
   308 //
       
   309 void CPEngAttributeListTransactionManager::RollBackDefaultL()
       
   310     {
       
   311     // go through all Attribute lists and commit Default flag
       
   312     // if attribute list is without any contact after commiting and it is not default
       
   313     // or to be new default, this attribute list will be deleted in CompressAtrrListArray function
       
   314     for ( TInt x ( iAttributeLists.Count() - 1 ) ;  x >= 0 ; x-- )
       
   315         {
       
   316         // commit default to each
       
   317         iAttributeLists[x]->SetNewDefault( EFalse );
       
   318         }
       
   319     iDeleteDefaultAttrList = EFalse;
       
   320 
       
   321     // now compress array
       
   322     CompressArrListArray();
       
   323     }
       
   324 
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CPEngAttributeListTransactionManager::CommitDefinedAttributeList()
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 void CPEngAttributeListTransactionManager::CommitDefinedContactsL(
       
   331     const CDesCArray* aContactLists,
       
   332     const CDesCArray* aContactIds )
       
   333     {
       
   334     // commit all contacts IDs and contact lists
       
   335     if ( aContactLists )
       
   336         {
       
   337         TInt count ( aContactLists->Count() );
       
   338         for ( TInt ii( 0 ) ; ii < count ; ii++ )
       
   339             {
       
   340             CommitContactListL( aContactLists->MdcaPoint( ii ) );
       
   341             }
       
   342         }
       
   343 
       
   344 
       
   345     if ( aContactIds )
       
   346         {
       
   347         TInt count ( aContactIds->Count() );
       
   348         for ( TInt i( 0 ) ; i < count ; i++ )
       
   349             {
       
   350             CommitContactIdL( aContactIds->MdcaPoint( i ) );
       
   351             }
       
   352         }
       
   353     }
       
   354 
       
   355 
       
   356 // -----------------------------------------------------------------------------
       
   357 // CPEngAttributeListTransactionManager::RollBackDefinedContactsL()
       
   358 // -----------------------------------------------------------------------------
       
   359 //
       
   360 void CPEngAttributeListTransactionManager::RollBackDefinedContactsL(
       
   361     const CDesCArray* aContactLists,
       
   362     const CDesCArray* aContactIds )
       
   363     {
       
   364     // RollBack all contacts IDs and contact lists
       
   365     if ( aContactLists )
       
   366         {
       
   367         TInt count ( aContactLists->Count() );
       
   368         for ( TInt ii( 0 ) ; ii < count ; ii++ )
       
   369             {
       
   370             RollBackContactListL( aContactLists->MdcaPoint( ii ) );
       
   371             }
       
   372         }
       
   373 
       
   374 
       
   375     if ( aContactIds )
       
   376         {
       
   377         TInt count ( aContactIds->Count() );
       
   378         for ( TInt i( 0 ) ; i < count ; i++ )
       
   379             {
       
   380             RollBackContactIdL( aContactIds->MdcaPoint( i ) );
       
   381             }
       
   382         }
       
   383     }
       
   384 
       
   385 
       
   386 // -----------------------------------------------------------------------------
       
   387 // CPEngAttributeListTransactionManager::StoreChangesToStoreL()
       
   388 // -----------------------------------------------------------------------------
       
   389 //
       
   390 void CPEngAttributeListTransactionManager::StoreChangesToStoreL()
       
   391     {
       
   392     User::LeaveIfError( StoreChangesL() );
       
   393     }
       
   394 
       
   395 
       
   396 // -----------------------------------------------------------------------------
       
   397 // CPEngAttributeListTransactionManager::GetSyncHandlersL()
       
   398 // -----------------------------------------------------------------------------
       
   399 //
       
   400 void CPEngAttributeListTransactionManager::GetSyncHandlersL(
       
   401     RPointerArray<MPEngOutgoingTransactionHandler>& aTransactionHandlers,
       
   402     TInt aOperationId )
       
   403     {
       
   404     // Commit all items in the lists before they are synchronized,
       
   405     // so desired changes are synchronized right a way
       
   406     CommitAllAttributeListL();
       
   407     StoreChangesL();
       
   408 
       
   409     // now create SyncAttributes list handlers
       
   410     iSyncHandlerCount = 0;
       
   411     TInt count ( iAttributeLists.Count() );
       
   412     for ( TInt y( 0 ) ;  y < count ; y++ )
       
   413         {
       
   414         // create attribute list only if it needed
       
   415         if ( CheckAttributeListServerValidityCurrent( *( iAttributeLists[y] ) ) )
       
   416             {
       
   417             // ETrue => this is sync handler
       
   418             CPEngAttributeListTransCreateAttrList* newHandler =
       
   419                 CPEngAttributeListTransCreateAttrList::NewLC(
       
   420                     *( iAttributeLists[y] ),
       
   421                     *this,
       
   422                     *iContactListTransManager,
       
   423                     *iAttributeManager,
       
   424                     iCSPVersion,
       
   425                     aOperationId,
       
   426                     ETrue );
       
   427 
       
   428             aTransactionHandlers.AppendL( newHandler );
       
   429             CleanupStack::Pop(); // newHandler
       
   430             iSyncHandlerCount++;
       
   431             }
       
   432         }
       
   433 
       
   434     // now check if there are some attribute lists to be deleted
       
   435     // GetDeleteAttributeListsHandlersL( aTransactionHandlers, aOperationId );
       
   436     }
       
   437 
       
   438 
       
   439 // -----------------------------------------------------------------------------
       
   440 // CPEngAttributeListTransactionManager::GetAttributeListsUpdateHandlersL()
       
   441 // -----------------------------------------------------------------------------
       
   442 //
       
   443 void CPEngAttributeListTransactionManager::GetAttributeListsUpdateHandlersL(
       
   444     RPointerArray<MPEngOutgoingTransactionHandler>& aTransactionHandlers,
       
   445     TInt aOperationId )
       
   446     {
       
   447     // go through all attributes and create all handlers which are necessary
       
   448     TInt count ( iAttributeLists.Count() );
       
   449     for ( TInt x( 0 ) ; x < count ; x++ )
       
   450         {
       
   451         if ( CheckAttributeListCreateNewValidity( *( iAttributeLists[x] ) ) )
       
   452             {
       
   453             // there is something to update, create handler
       
   454             CPEngAttributeListTransCreateAttrList* newHandler =
       
   455                 CPEngAttributeListTransCreateAttrList::NewLC(
       
   456                     *( iAttributeLists[ x ] ),
       
   457                     *this,
       
   458                     *iContactListTransManager,
       
   459                     *iAttributeManager,
       
   460                     iCSPVersion,
       
   461                     aOperationId );
       
   462             aTransactionHandlers.AppendL( newHandler );
       
   463             CleanupStack::Pop(); // newHandler
       
   464             }
       
   465 
       
   466         else
       
   467             {
       
   468             // Commit attribute list
       
   469             CommitAttributeListL( *( iAttributeLists[x]  ) );
       
   470             }
       
   471         }
       
   472 
       
   473     // now check if there are some attribute lists to be deleted
       
   474     GetDeleteAttributeListsHandlersL( aTransactionHandlers, aOperationId );
       
   475     StoreChangesL();
       
   476     }
       
   477 
       
   478 
       
   479 // -----------------------------------------------------------------------------
       
   480 // CPEngAttributeListTransactionManager::CompressArrListArray()
       
   481 // -----------------------------------------------------------------------------
       
   482 //
       
   483 void CPEngAttributeListTransactionManager::GetDeleteAttributeListsHandlersL(
       
   484     RPointerArray<MPEngOutgoingTransactionHandler>& aTransactionHandlers,
       
   485     TInt aOperationId )
       
   486     {
       
   487     if ( CheckAttributeListDeleteValidity() )
       
   488         {
       
   489         // there is something to delete from server, create handler
       
   490         CPEngAttributeListTransDeleteAttrList* newHandler;
       
   491         newHandler = CPEngAttributeListTransDeleteAttrList::NewLC(
       
   492                          *this,
       
   493                          *iContactListTransManager,
       
   494                          iDeleteAttrListContactLists,
       
   495                          iDeleteAttrListContactIDs,
       
   496                          iDeleteDefaultAttrList,
       
   497                          iCSPVersion,
       
   498                          aOperationId );
       
   499 
       
   500         aTransactionHandlers.AppendL( newHandler );
       
   501         CleanupStack::Pop(); // newHandler
       
   502         }
       
   503     else
       
   504         {
       
   505         CommitDeleteAttributeListL();
       
   506         }
       
   507     }
       
   508 
       
   509 
       
   510 // -----------------------------------------------------------------------------
       
   511 // CPEngAttributeListTransactionManager::CompressArrListArray()
       
   512 // -----------------------------------------------------------------------------
       
   513 //
       
   514 void CPEngAttributeListTransactionManager::CompressArrListArray()
       
   515     {
       
   516     // go through array from the end and delete all attribute lists
       
   517     // which does not hold any contact
       
   518     for ( TInt x ( iAttributeLists.Count() - 1 ) ; x >= 0 ; x-- )
       
   519         {
       
   520         if ( 0 == iAttributeLists[ x ]->ContactsCount() )
       
   521             {
       
   522             // no more contacts, delete attribute list
       
   523             delete iAttributeLists[ x ];
       
   524             iAttributeLists.Remove( x );
       
   525             }
       
   526         }
       
   527     }
       
   528 
       
   529 
       
   530 // -----------------------------------------------------------------------------
       
   531 // CPEngAttributeListTransactionManager::AppendDesArrayContentL()
       
   532 // -----------------------------------------------------------------------------
       
   533 //
       
   534 void CPEngAttributeListTransactionManager::AppendDesArrayContentL(
       
   535     const CDesC16Array& aOriginalDesArray,
       
   536     CDesC16Array& aNewDesArray )
       
   537     {
       
   538     TInt count ( aOriginalDesArray.Count() );
       
   539     for ( TInt x ( 0 ) ; x < count ; x++ )
       
   540         {
       
   541         aNewDesArray.AppendL( aOriginalDesArray[ x ] );
       
   542         }
       
   543     }
       
   544 
       
   545 
       
   546 // -----------------------------------------------------------------------------
       
   547 // CPEngAttributeListTransactionManager::AppendDesArrayContentL()
       
   548 // -----------------------------------------------------------------------------
       
   549 //
       
   550 TBool CPEngAttributeListTransactionManager::CheckAttributeListServerValidityCurrent(
       
   551     const CPEngAttributeListItem& aAttributeList )
       
   552     {
       
   553     return CheckAttributeListValidity( aAttributeList,
       
   554                                        CPEngAttributeListItem::ECurrentContactIDs,
       
   555                                        CPEngAttributeListItem::ECurrentContactLists,
       
   556                                        &CPEngAttributeListItem::CurrentlyDefault,
       
   557                                        EFalse );
       
   558     }
       
   559 
       
   560 
       
   561 // -----------------------------------------------------------------------------
       
   562 // CPEngAttributeListTransactionManager::CheckAttributeListCreateNewValidity()
       
   563 // -----------------------------------------------------------------------------
       
   564 //
       
   565 TBool CPEngAttributeListTransactionManager::CheckAttributeListCreateNewValidity(
       
   566     const CPEngAttributeListItem& aAttributeList )
       
   567     {
       
   568     return CheckAttributeListValidity( aAttributeList,
       
   569                                        CPEngAttributeListItem::ENewContactIDs,
       
   570                                        CPEngAttributeListItem::ENewContactLists,
       
   571                                        &CPEngAttributeListItem::NewDefault,
       
   572                                        EFalse );
       
   573     }
       
   574 
       
   575 
       
   576 // -----------------------------------------------------------------------------
       
   577 // CPEngAttributeListTransactionManager::CheckAttributeListDeleteValidity()
       
   578 // -----------------------------------------------------------------------------
       
   579 //
       
   580 TBool CPEngAttributeListTransactionManager::CheckAttributeListDeleteValidity()
       
   581     {
       
   582     TBool attrListValid( ETrue );
       
   583     if ( ( iDeleteAttrListContactIDs.Count() == 0 ) && !iDeleteDefaultAttrList )
       
   584         {
       
   585         attrListValid = EFalse;
       
   586         TInt cntListCount ( iDeleteAttrListContactLists.Count() );
       
   587         for ( TInt i ( 0 ) ; i < cntListCount ; i++ )
       
   588             {
       
   589             CPEngContactListSettings* cntSettings =
       
   590                 iContactListTransManager->ContactListSettingsOrNull(
       
   591                     iDeleteAttrListContactLists[ i ] );
       
   592 
       
   593             CONTINUE_IF( !cntSettings );
       
   594 
       
   595             attrListValid += cntSettings->Property( KPEngListExistsOnServer,
       
   596                                                     KPEngCntLstPropertyNativeCached );
       
   597 
       
   598             // if list exists, break away
       
   599             if ( attrListValid )
       
   600                 {
       
   601                 return ETrue;
       
   602                 }
       
   603             }
       
   604         }
       
   605 
       
   606     return attrListValid;
       
   607     }
       
   608 
       
   609 
       
   610 // -----------------------------------------------------------------------------
       
   611 // CPEngAttributeListTransactionManager::CommitAttributeList()
       
   612 // -----------------------------------------------------------------------------
       
   613 //
       
   614 void CPEngAttributeListTransactionManager::CommitAttributeListL(
       
   615     const CPEngAttributeListItem& aAttributeList )
       
   616     {
       
   617     CDesCArraySeg* newContactIDs = new ( ELeave ) CDesCArraySeg( KAttributeListIdGranurality );
       
   618     CleanupStack::PushL( newContactIDs );
       
   619 
       
   620     AppendDesArrayContentL( aAttributeList.ArrayOfContacts(
       
   621                                 CPEngAttributeListItem::ENewContactIDs ),
       
   622                             *newContactIDs );
       
   623 
       
   624 
       
   625     CDesCArraySeg* newContactLists =  new ( ELeave ) CDesCArraySeg( KAttributeListIdGranurality );
       
   626     CleanupStack::PushL( newContactLists );
       
   627 
       
   628     AppendDesArrayContentL( aAttributeList.ArrayOfContacts(
       
   629                                 CPEngAttributeListItem::ENewContactLists ),
       
   630                             *newContactLists );
       
   631 
       
   632 
       
   633     TBool newDefaulFlag( EFalse );
       
   634     if ( aAttributeList.NewDefault() )
       
   635         {
       
   636         newDefaulFlag = ETrue;
       
   637         }
       
   638 
       
   639 
       
   640     // commit all new contacts IDs and contact lists
       
   641     CommitDefinedContactsL( newContactIDs, newContactLists );
       
   642     CleanupStack::PopAndDestroy( 2 ); // newContactLists, newContactIDs
       
   643     if ( newDefaulFlag )
       
   644         {
       
   645         CommitDefaultL();
       
   646         }
       
   647     }
       
   648 
       
   649 
       
   650 // -----------------------------------------------------------------------------
       
   651 // CPEngAttributeListTransactionManager::CommitAttributeList()
       
   652 // -----------------------------------------------------------------------------
       
   653 //
       
   654 void CPEngAttributeListTransactionManager::CommitAllAttributeListL()
       
   655     {
       
   656     CDesCArraySeg* newContactIDs = new ( ELeave ) CDesCArraySeg( KAttributeListIdGranurality );
       
   657     CleanupStack::PushL( newContactIDs );
       
   658 
       
   659     CDesCArraySeg* newContactLists =  new ( ELeave ) CDesCArraySeg( KAttributeListIdGranurality );
       
   660     CleanupStack::PushL( newContactLists );
       
   661     TBool newDefaulFlag( EFalse );
       
   662 
       
   663 
       
   664     TInt count ( iAttributeLists.Count() );
       
   665     for ( TInt x ( 0 ) ; x < count ; x++ )
       
   666         {
       
   667         AppendDesArrayContentL( iAttributeLists[ x ]->ArrayOfContacts(
       
   668                                     CPEngAttributeListItem::ENewContactIDs ),
       
   669                                 *newContactIDs );
       
   670 
       
   671         AppendDesArrayContentL( iAttributeLists[ x ]->ArrayOfContacts(
       
   672                                     CPEngAttributeListItem::ENewContactLists ),
       
   673                                 *newContactLists );
       
   674 
       
   675         if ( iAttributeLists[ x ]->NewDefault() )
       
   676             {
       
   677             newDefaulFlag = ETrue;
       
   678             }
       
   679         }
       
   680 
       
   681 
       
   682     CommitDefinedContactsL( newContactLists, newContactIDs );
       
   683     CleanupStack::PopAndDestroy( 2 ); // newContactLists, newContactIDs
       
   684 
       
   685 
       
   686     if ( newDefaulFlag )
       
   687         {
       
   688         CommitDefaultL();
       
   689         }
       
   690     }
       
   691 
       
   692 
       
   693 // -----------------------------------------------------------------------------
       
   694 // CPEngAttributeListTransactionManager::CommitDeleteAttributeListL()
       
   695 // -----------------------------------------------------------------------------
       
   696 //
       
   697 void CPEngAttributeListTransactionManager::CommitDeleteAttributeListL()
       
   698     {
       
   699     CDesCArraySeg* contacts = new ( ELeave ) CDesCArraySeg( KAttributeListIdGranurality );
       
   700     CleanupStack::PushL( contacts );
       
   701 
       
   702     AppendDesArrayContentL( iDeleteAttrListContactIDs, *contacts );
       
   703     CommitDefinedContactsL( contacts, NULL );
       
   704 
       
   705     contacts->Reset();
       
   706 
       
   707     AppendDesArrayContentL( iDeleteAttrListContactLists, *contacts );
       
   708     CommitDefinedContactsL( NULL, contacts );
       
   709 
       
   710     CleanupStack::PopAndDestroy( ); // contacts
       
   711 
       
   712     if ( iDeleteDefaultAttrList )
       
   713         {
       
   714         CommitDefaultL();
       
   715         }
       
   716     }
       
   717 
       
   718 
       
   719 // -----------------------------------------------------------------------------
       
   720 // CPEngAttributeListTransactionManager::CommitContactL()
       
   721 // -----------------------------------------------------------------------------
       
   722 //
       
   723 void CPEngAttributeListTransactionManager::CommitContactL(
       
   724     const TDesC& aContact,
       
   725     CommitCall aCommitCall,
       
   726     CDesCArray& aDeleteArray )
       
   727     {
       
   728     // go through all Attribute lists and commit contact list to them
       
   729     // if attribute list is without any contact after commiting and it isn's
       
   730     // default or to be new default,
       
   731     // this attribute list will be deleted in  CompressAtrrListArray function
       
   732     for ( TInt x ( iAttributeLists.Count() - 1 ) ;  x >= 0 ; x-- )
       
   733         {
       
   734         ( iAttributeLists[x]->*aCommitCall )( aContact );
       
   735         }
       
   736 
       
   737 
       
   738     // now compress array
       
   739     // check if contact list was in to be deleted ones
       
   740     TInt position( 0 );
       
   741     TInt err ( aDeleteArray.FindIsq( aContact , position, ECmpFolded ) );
       
   742     if ( err == KErrNone )
       
   743         {
       
   744         aDeleteArray.Delete( position );
       
   745         }
       
   746 
       
   747     CompressArrListArray();
       
   748     }
       
   749 
       
   750 
       
   751 // -----------------------------------------------------------------------------
       
   752 // CPEngAttributeListTransactionManager::RollBackOneContactL()
       
   753 // -----------------------------------------------------------------------------
       
   754 //
       
   755 void CPEngAttributeListTransactionManager::RollBackOneContactL(
       
   756     const TDesC& aContact,
       
   757     CPEngAttributeListItem::TPEngAttrListItemArrays aNewCommitArray,
       
   758     CDesCArray& aDeleteArray )
       
   759     {
       
   760     // go through all Attribute lists and delete contact which does not exist
       
   761     // if attribute list is without any contact after commiting and
       
   762     // it is not default or to be new default, this attribute
       
   763     // list will be deleted in CompressAtrrListArray function
       
   764 
       
   765     // increment by one, this will remove that invalid contact also from
       
   766     // current
       
   767     CPEngAttributeListItem::TPEngAttrListItemArrays nextArray(
       
   768         static_cast<CPEngAttributeListItem::TPEngAttrListItemArrays>
       
   769         ( aNewCommitArray + 1 ) );
       
   770 
       
   771     for ( TInt x ( iAttributeLists.Count() - 1 ) ;  x >= 0 ; x-- )
       
   772         {
       
   773         // Delete contact from currect and also new
       
   774         iAttributeLists[x]->DeleteContactFromList( aContact, aNewCommitArray );
       
   775         iAttributeLists[x]->DeleteContactFromList( aContact, nextArray );
       
   776         }
       
   777 
       
   778 
       
   779     // check if contact list was in to be deleted ones
       
   780     TInt position( 0 );
       
   781     TInt err ( aDeleteArray.FindIsq( aContact , position, ECmpFolded ) );
       
   782     if ( err == KErrNone )
       
   783         {
       
   784         aDeleteArray.Delete( position );
       
   785         }
       
   786 
       
   787     // now compress array
       
   788     CompressArrListArray();
       
   789     }
       
   790 
       
   791 
       
   792 // -----------------------------------------------------------------------------
       
   793 // CPEngAttributeListTransactionManager::CheckAttributeListValidity()
       
   794 // -----------------------------------------------------------------------------
       
   795 //
       
   796 TBool CPEngAttributeListTransactionManager::CheckAttributeListValidity(
       
   797     const CPEngAttributeListItem& aAttributeList,
       
   798     CPEngAttributeListItem::TPEngAttrListItemArrays aIDsArray,
       
   799     CPEngAttributeListItem::TPEngAttrListItemArrays aCntListArray,
       
   800     ItemDefaultSet aDefaultSetCall,
       
   801     TBool aSynchronizeFlagIncluded )
       
   802     {
       
   803     // check is handler is needed, if any of the contact in the contact list
       
   804     // does not exist on the server an attr list
       
   805     // is not default, there is no need for transaction.
       
   806     TBool attrListValid( ETrue );
       
   807     if ( ( aAttributeList.ArrayOfContacts( aIDsArray ).Count() == 0 ) &&
       
   808          !( aAttributeList.*aDefaultSetCall )() )
       
   809         {
       
   810         attrListValid =  EFalse ;
       
   811         const CDesCArray& cntLstArray =
       
   812             aAttributeList.ArrayOfContacts( aCntListArray );
       
   813         TInt cntListCount ( cntLstArray.Count() );
       
   814         for ( TInt i ( 0 ) ; i < cntListCount ; i++ )
       
   815             {
       
   816             CPEngContactListSettings* cntSettings =
       
   817                 iContactListTransManager->ContactListSettingsOrNull( cntLstArray[ i ] );
       
   818 
       
   819             CONTINUE_IF( ( !cntSettings
       
   820                            ||
       
   821                            !( cntSettings->Property( KPEngListExistsOnServer,
       
   822                                                      KPEngCntLstPropertyNativeCached ) )
       
   823                          ) );
       
   824 
       
   825             attrListValid += ( !aSynchronizeFlagIncluded || cntSettings->Synchronized() );
       
   826 
       
   827             // if list exists, break the loop
       
   828             if ( attrListValid )
       
   829                 {
       
   830                 return ETrue;
       
   831                 }
       
   832             }
       
   833         }
       
   834 
       
   835     return attrListValid;
       
   836     }
       
   837 
       
   838 //  End of File
       
   839