phonebookui/Phonebook2/CommonUI/src/CPbk2ViewStateTransformer.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Phonebook 2 view state transformer.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "CPbk2ViewStateTransformer.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include <CPbk2MigrationInterface.h>
       
    24 #include <CPbk2ViewState.h>
       
    25 
       
    26 // Virtual Phonebook
       
    27 #include <CVPbkContactManager.h>
       
    28 
       
    29 
       
    30 /// Unused namespace for local definitions
       
    31 namespace {
       
    32 
       
    33 /**
       
    34  * Custom cleanup item.
       
    35  *
       
    36  * @param aObj  Pointer to item pushed on to the stack.
       
    37  */
       
    38 void CleanupResetAndDestroy( TAny* aObj )
       
    39     {
       
    40     if ( aObj )
       
    41         {
       
    42         static_cast<RImplInfoPtrArray*>( aObj )->ResetAndDestroy();
       
    43         }
       
    44     }
       
    45 
       
    46 } /// namespace
       
    47 
       
    48 
       
    49 // --------------------------------------------------------------------------
       
    50 // CPbk2ViewStateTransformer::CPbk2ViewStateTransformer
       
    51 // --------------------------------------------------------------------------
       
    52 //
       
    53 CPbk2ViewStateTransformer::CPbk2ViewStateTransformer
       
    54         ( CVPbkContactManager& aContactManager ) :
       
    55             iContactManager( aContactManager )
       
    56     {
       
    57     }
       
    58 
       
    59 // --------------------------------------------------------------------------
       
    60 // CPbk2ViewStateTransformer::~CPbk2ViewStateTransformer
       
    61 // --------------------------------------------------------------------------
       
    62 //
       
    63 CPbk2ViewStateTransformer::~CPbk2ViewStateTransformer()
       
    64     {
       
    65     }
       
    66 
       
    67 // --------------------------------------------------------------------------
       
    68 // CPbk2ViewStateTransformer::NewL
       
    69 // --------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C CPbk2ViewStateTransformer* CPbk2ViewStateTransformer::NewLC(
       
    72         CVPbkContactManager& aContactManager)
       
    73     {
       
    74     CPbk2ViewStateTransformer* self =
       
    75         new( ELeave ) CPbk2ViewStateTransformer( aContactManager );
       
    76     CleanupStack::PushL( self );
       
    77     return self;
       
    78     }
       
    79 
       
    80 // --------------------------------------------------------------------------
       
    81 // CPbk2ViewStateTransformer::TransformLegacyViewStateToPbk2ViewStateLC
       
    82 // --------------------------------------------------------------------------
       
    83 //
       
    84 EXPORT_C CPbk2ViewState*
       
    85         CPbk2ViewStateTransformer::TransformLegacyViewStateToPbk2ViewStateLC
       
    86             ( const TDesC8& aCustomMessage )
       
    87     {
       
    88     // Function converts a Phonebook 1 view state
       
    89     // into Phonebook 2 view state
       
    90     CPbk2ViewState* pbk2ViewState = CPbk2ViewState::NewLC();
       
    91 
       
    92     // Check does the migration support implementation exist:
       
    93     RImplInfoPtrArray implementations;
       
    94     CleanupStack::PushL( TCleanupItem
       
    95         ( CleanupResetAndDestroy, &implementations ) );
       
    96     REComSession::ListImplementationsL(
       
    97             TUid::Uid( KPbk2MigrationSupportInterfaceUID ),
       
    98             implementations );
       
    99 
       
   100     CPbk2MigrationInterface* migrationSupport = NULL;
       
   101     if (implementations.Count() > 0)
       
   102         {
       
   103         // There should be only one implementation for migration
       
   104         // support component and we would like to use that one
       
   105         migrationSupport = CPbk2MigrationInterface::NewLC
       
   106             ( iContactManager );        
       
   107        
       
   108         // Fills pbk2ViewState with data from aCustomMessage
       
   109         migrationSupport->ConvertViewStateL
       
   110             ( aCustomMessage, *pbk2ViewState );
       
   111 
       
   112         // Destroy migration support instance
       
   113         CleanupStack::PopAndDestroy(); //migrationSupport
       
   114         }
       
   115     CleanupStack::PopAndDestroy(); // implementations
       
   116 
       
   117     return pbk2ViewState;
       
   118     }
       
   119 
       
   120 // End of File