phonebookui/Phonebook2/MigrationSupport/src/CPbk2MigrationSupport.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  Migration support for Phonebook 2.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include "CPbk2MigrationSupport.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include <CPbk2ViewState.h>
       
    24 
       
    25 // Virtual Phonebook
       
    26 #include <CVPbkContactIdConverter.h>
       
    27 #include <CVPbkContactManager.h>
       
    28 #include <TVPbkContactStoreUriPtr.h>
       
    29 #include <MVPbkContactStoreList.h>
       
    30 #include <CVPbkContactLinkArray.h>
       
    31 #include <VPbkContactStoreUris.h>
       
    32 
       
    33 // Phonebook 1
       
    34 #include <CPbkViewState.h>
       
    35 
       
    36 /// Unnamed namespace for local definitions
       
    37 namespace {
       
    38 
       
    39 #ifdef _DEBUG
       
    40 
       
    41 enum TPanicCode
       
    42     {
       
    43     EPanicPreCond_ConstructL = 1,
       
    44     EPanicPreCond_NewL
       
    45     };
       
    46 
       
    47 void Panic(TPanicCode aPanicCode)
       
    48     {
       
    49     _LIT(KPanicText, "CPbk2MigrationSupport");
       
    50     User::Panic(KPanicText, aPanicCode);
       
    51     };
       
    52 
       
    53 #endif // _DEBUG
       
    54 
       
    55 } /// namespace
       
    56 
       
    57 
       
    58 // --------------------------------------------------------------------------
       
    59 // CPbk2MigrationSupport::CPbk2MigrationSupport
       
    60 // --------------------------------------------------------------------------
       
    61 //
       
    62 inline CPbk2MigrationSupport::CPbk2MigrationSupport
       
    63         ( CVPbkContactManager* aContactManager ) :
       
    64             iContactManager( *aContactManager )
       
    65     {
       
    66     }
       
    67 
       
    68 // --------------------------------------------------------------------------
       
    69 // CPbk2MigrationSupport::~CPbk2MigrationSupport
       
    70 // --------------------------------------------------------------------------
       
    71 //
       
    72 CPbk2MigrationSupport::~CPbk2MigrationSupport()
       
    73     {
       
    74     delete iIdConverter;
       
    75     }
       
    76 
       
    77 // --------------------------------------------------------------------------
       
    78 // CPbk2MigrationSupport::NewL
       
    79 // --------------------------------------------------------------------------
       
    80 //
       
    81 CPbk2MigrationSupport* CPbk2MigrationSupport::NewL( TAny* aParam )
       
    82     {
       
    83     __ASSERT_DEBUG( aParam, Panic( EPanicPreCond_NewL ) );
       
    84 
       
    85     CVPbkContactManager* contactManager =
       
    86         static_cast<CVPbkContactManager*>( aParam );
       
    87 
       
    88     CPbk2MigrationSupport* self =
       
    89         new ( ELeave ) CPbk2MigrationSupport( contactManager );
       
    90     CleanupStack::PushL( self );
       
    91     self->ConstructL();
       
    92     CleanupStack::Pop( self );
       
    93     return self;
       
    94     }
       
    95 
       
    96 // --------------------------------------------------------------------------
       
    97 // CPbk2MigrationSupport::ConstructL
       
    98 // --------------------------------------------------------------------------
       
    99 //
       
   100 inline void CPbk2MigrationSupport::ConstructL()
       
   101     {
       
   102     // Find Contacts Model store URI from the contact manager
       
   103     TVPbkContactStoreUriPtr uri( VPbkContactStoreUris::DefaultCntDbUri() );
       
   104     MVPbkContactStore* defaultStore =
       
   105             iContactManager.ContactStoresL().Find( uri );
       
   106     User::LeaveIfNull( defaultStore );
       
   107     iIdConverter = CVPbkContactIdConverter::NewL( *defaultStore );
       
   108     }
       
   109 
       
   110 // --------------------------------------------------------------------------
       
   111 // CPbk2MigrationSupport::ConvertViewStateL
       
   112 // --------------------------------------------------------------------------
       
   113 //
       
   114 void CPbk2MigrationSupport::ConvertViewStateL
       
   115         ( const TDesC8& aCustomMessage, CPbk2ViewState& aViewState )
       
   116     {
       
   117     CPbkViewState* viewState = CPbkViewState::NewLC( aCustomMessage );
       
   118 
       
   119     // 1. Convert a contact id to a contact link for focus
       
   120     // TContactItemId FocusedContactId()
       
   121     //      -> void SetFocusedContact( MVPbkContactLink* aContact )
       
   122     if ( viewState->FocusedContactId() != KNullContactId )
       
   123         {
       
   124         MVPbkContactLink* focusIdLink = iIdConverter->IdentifierToLinkLC(
       
   125                 viewState->FocusedContactId() );
       
   126         aViewState.SetFocusedContact( focusIdLink );
       
   127         CleanupStack::Pop(); // focusIdLink
       
   128         }
       
   129 
       
   130     // 2. Convert a contact id to contact link for top focus
       
   131     // TContactItemId TopContactId()
       
   132     //      -> void SetTopContact( MVPbkContactLink* aTopContact )
       
   133     if ( viewState->TopContactId() != KNullContactId )
       
   134         {
       
   135         MVPbkContactLink* topIdLink = iIdConverter->IdentifierToLinkLC(
       
   136                 viewState->TopContactId() );
       
   137         aViewState.SetFocusedContact( topIdLink );
       
   138         CleanupStack::Pop(); // topIdLink
       
   139         }
       
   140 
       
   141     // 3. Convert a contact id to contact link for setting parent contact
       
   142     // TContactItemId ParentContactId()
       
   143     //      -> void SetParentContact( MVPbkContactLink* aParentContact )
       
   144     if ( viewState->ParentContactId() != KNullContactId )
       
   145         {
       
   146         MVPbkContactLink* parentIdLink = iIdConverter->IdentifierToLinkLC(
       
   147                 viewState->ParentContactId() );
       
   148         aViewState.SetFocusedContact( parentIdLink );
       
   149         CleanupStack::Pop(); // parentIdLink
       
   150         }
       
   151 
       
   152     // 4. Convert a contact id array to contact link array
       
   153     //    for marking contacts
       
   154     // CContactIdArray* MarkedContactIds()
       
   155     //      -> void SetMarkedContacts( MVPbkContactLinkArray* aArray )
       
   156     if (viewState->MarkedContactIds())
       
   157         {
       
   158         CVPbkContactLinkArray* linkArray = CVPbkContactLinkArray::NewLC();
       
   159         CContactIdArray* ids = viewState->MarkedContactIds();
       
   160         for( TInt i = 0; i < ids->Count(); ++i )
       
   161             {
       
   162             TContactItemId cid = ( *ids )[i];
       
   163             MVPbkContactLink* markedIdLink =
       
   164                 iIdConverter->IdentifierToLinkLC( cid );
       
   165             linkArray->AppendL( markedIdLink );
       
   166             CleanupStack::Pop(); // markedIdLink
       
   167             }
       
   168         aViewState.SetMarkedContacts( linkArray );
       
   169         CleanupStack::Pop(); // linkArray
       
   170         }
       
   171 
       
   172     // 5. Convert a field index to a field index for focus
       
   173     // TInt FocusedFieldIndex()
       
   174     //      -> void SetFocusedFieldIndex( TInt aIndex )
       
   175     aViewState.SetFocusedFieldIndex( viewState->FocusedFieldIndex() );
       
   176 
       
   177     // 6. Convert a top index to a index for top focus
       
   178     // TInt TopFieldIndex()
       
   179     //      -> void SetTopFieldIndex( TInt aIndex )
       
   180     aViewState.SetTopFieldIndex( viewState->TopFieldIndex() );
       
   181 
       
   182     // 7. Convert flags to flags
       
   183     // TUint Flags()
       
   184     //      -> void SetFlags( TUint aFlags )
       
   185     aViewState.SetFlags( viewState->Flags() );
       
   186 
       
   187     CleanupStack::PopAndDestroy( viewState );
       
   188     }
       
   189 
       
   190 // End of File