phonebookui/Phonebook2/NamesListExtension/src/cpbk2openmycardcmd.cpp
branchRCL_3
changeset 6 e8e3147d53eb
parent 0 e686773b3f54
child 12 4ae315f230bc
equal deleted inserted replaced
5:81f8547efd4f 6:e8e3147d53eb
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 #include "cpbk2openmycardcmd.h"
    20 #include "cpbk2openmycardcmd.h"
       
    21 #include "cpbk2mycard.h"
    21 #include <CPbk2NamesListControl.h>
    22 #include <CPbk2NamesListControl.h>
    22 #include <MPbk2CommandObserver.h>
    23 #include <MPbk2CommandObserver.h>
    23 #include <MVPbkBaseContact.h>
    24 #include <MVPbkBaseContact.h>
    24 #include <ccappmycardpluginuids.hrh>
    25 #include <ccappmycardpluginuids.hrh>
       
    26 #include <spbcontactdatamodel.h>
       
    27 #include <pbk2exnameslistres.rsg>
       
    28 #include <CPbk2FieldPropertyArray.h>
       
    29 #include <CPbk2StoreSpecificFieldPropertyArray.h>
       
    30 #include <CPbk2PresentationContact.h>
       
    31 #include <CPbk2StorePropertyArray.h>
       
    32 #include <MVPbkContactStoreProperties.h>
       
    33 #include <MVPbkContactStore.h>
    25 
    34 
    26 //Cca
    35 //Cca
    27 #include <mccaparameter.h>
    36 #include <mccaparameter.h>
    28 #include <mccaconnection.h>
    37 #include <mccaconnection.h>
    29 #include <ccafactory.h>
    38 #include <ccafactory.h>
    30 
    39 
       
    40 #include <s32mem.h>
       
    41 
    31 // Debugging headers
    42 // Debugging headers
    32 #include <Pbk2Debug.h>
    43 #include <Pbk2Debug.h>
    33 #include <Pbk2Profile.h>
    44 #include <Pbk2Profile.h>
    34 
    45 
    35 // --------------------------------------------------------------------------
    46 // --------------------------------------------------------------------------
    36 // CPbk2OpenMyCardCmd::CPbk2OpenMyCardCmd
    47 // CPbk2OpenMyCardCmd::CPbk2OpenMyCardCmd
    37 // --------------------------------------------------------------------------
    48 // --------------------------------------------------------------------------
    38 //
    49 //
    39 CPbk2OpenMyCardCmd::CPbk2OpenMyCardCmd(
    50 CPbk2OpenMyCardCmd::CPbk2OpenMyCardCmd(
    40     MPbk2ContactUiControl* aUiControl,
    51     MPbk2ContactUiControl* aUiControl,
       
    52     CPbk2MyCard* aMyCard,
    41     MCCAConnection*& aCCAConnection ) :
    53     MCCAConnection*& aCCAConnection ) :
    42         CActive( EPriorityStandard ),
    54         CActive( EPriorityStandard ),
    43         iUiControl( aUiControl ),
    55         iUiControl( aUiControl ),
    44         iConnectionRef(aCCAConnection),
    56         iConnectionRef(aCCAConnection),
    45         iViewUid( TUid::Uid( KCCAMyCardPluginImplmentationUid ) ) // default mycard view
    57         iViewUid( TUid::Uid( KCCAMyCardPluginImplmentationUid ) ), // default mycard view
       
    58         iMyCard( aMyCard )
    46     {
    59     {
    47     CActiveScheduler::Add( this );
    60     CActiveScheduler::Add( this );
    48     }
    61     }
    49 
    62 
    50 // --------------------------------------------------------------------------
    63 // --------------------------------------------------------------------------
    59 
    72 
    60     if( iUiControl )
    73     if( iUiControl )
    61         {
    74         {
    62         iUiControl->RegisterCommand( NULL );
    75         iUiControl->RegisterCommand( NULL );
    63         }
    76         }
       
    77     delete iPresentationContact;
       
    78     delete iSpecificFieldProperties;
       
    79     delete iFieldProperties;
    64     }
    80     }
    65 
    81 
    66 // --------------------------------------------------------------------------
    82 // --------------------------------------------------------------------------
    67 // CPbk2OpenMyCardCmd::NewL
    83 // CPbk2OpenMyCardCmd::NewL
    68 // --------------------------------------------------------------------------
    84 // --------------------------------------------------------------------------
    69 //
    85 //
    70 CPbk2OpenMyCardCmd* CPbk2OpenMyCardCmd::NewL(
    86 CPbk2OpenMyCardCmd* CPbk2OpenMyCardCmd::NewL(
    71     MCCAConnection*& aCCAConnection,
    87     MCCAConnection*& aCCAConnection,
       
    88     CPbk2MyCard* aMyCard,
    72     MPbk2ContactUiControl* aUiControl )
    89     MPbk2ContactUiControl* aUiControl )
    73     {
    90     {
    74     CPbk2OpenMyCardCmd* self = new ( ELeave ) CPbk2OpenMyCardCmd
    91     CPbk2OpenMyCardCmd* self = new ( ELeave ) CPbk2OpenMyCardCmd(
    75         ( aUiControl, aCCAConnection );
    92         aUiControl, aMyCard, aCCAConnection );
    76     CleanupStack::PushL( self );
    93     CleanupStack::PushL( self );
    77     self->ConstructL();
    94     self->ConstructL();
    78     CleanupStack::Pop( self );
    95     CleanupStack::Pop( self );
    79     return self;
    96     return self;
    80     }
    97     }
   144 
   161 
   145     MCCAParameter* parameter = TCCAFactory::NewParameterL();
   162     MCCAParameter* parameter = TCCAFactory::NewParameterL();
   146     CleanupClosePushL( *parameter );
   163     CleanupClosePushL( *parameter );
   147     parameter->SetConnectionFlag( MCCAParameter::ENormal );
   164     parameter->SetConnectionFlag( MCCAParameter::ENormal );
   148     parameter->SetLaunchedViewUid( iViewUid );
   165     parameter->SetLaunchedViewUid( iViewUid );
       
   166     
       
   167     if( iMyCard )
       
   168         {
       
   169         // Speed up mycard launching by constructing the view model here.
       
   170         // This information is not mandatory for mycard launching however.
       
   171         CBufFlat* buffer = CBufFlat::NewL( KKilo );
       
   172         CleanupStack::PushL( buffer );
       
   173         RBufWriteStream stream( *buffer );
       
   174         CleanupClosePushL( stream );
       
   175 
       
   176         // create model and dump it into stream
       
   177         CSpbContactDataModel* model = CSpbContactDataModel::NewL( 
       
   178             iMyCard->ContactManager(), *CCoeEnv::Static(), 
       
   179             R_PBK2_MYCARD_FIELD_CLIP_SELECTOR );
       
   180         CleanupStack::PushL( model );
       
   181 
       
   182         if( iMyCard->MyCardState() == CPbk2MyCard::EExisting )
       
   183             {
       
   184             // preset contact data model to contain my cards data.
       
   185             CPbk2PresentationContact* contact = PresentationContactL();
       
   186             if( contact )
       
   187                 {
       
   188                 model->SetDataL( *contact, NULL );
       
   189                 }
       
   190             }
       
   191         model->ExternalizeL( stream );
       
   192         CleanupStack::PopAndDestroy( 2, &stream ); // model
       
   193 
       
   194         // set model dump as parameter
       
   195         TPtrC8 buf( buffer->Ptr( 0 ) );
       
   196         TPtrC16 data( (TUint16*)buf.Ptr(), ( buf.Size() + 1 ) / 2 );
       
   197         parameter->SetContactDataFlag( MCCAParameter::EContactDataModel );
       
   198         parameter->SetContactDataL( data );
       
   199         CleanupStack::PopAndDestroy( buffer ); 
       
   200         }
   149 
   201 
   150     // Sync call
   202     // Sync call
   151     iConnectionRef->LaunchAppL( *parameter );
   203     iConnectionRef->LaunchAppL( *parameter );
   152     CleanupStack::Pop();// parameter is taken care by iConnectionRef
   204     CleanupStack::Pop();// parameter is taken care by iConnectionRef
   153 
   205 
   164     TRequestStatus* status = &iStatus;
   216     TRequestStatus* status = &iStatus;
   165     User::RequestComplete( status, KErrNone );
   217     User::RequestComplete( status, KErrNone );
   166     SetActive();
   218     SetActive();
   167     }
   219     }
   168 
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // CPbk2OpenMyCardCmd::PresentationContactL
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 CPbk2PresentationContact* CPbk2OpenMyCardCmd::PresentationContactL()
       
   226     {
       
   227     if( !iPresentationContact )
       
   228         {
       
   229         if( !iMyCard )
       
   230             {
       
   231             return NULL;
       
   232             }
       
   233             
       
   234         MVPbkStoreContact* storeContact = iMyCard->MyCardStoreContact();
       
   235         if( !storeContact )
       
   236             {
       
   237             return NULL;
       
   238             }
       
   239         
       
   240         const MVPbkContactStoreProperties& storeProperties =
       
   241             storeContact->ParentStore().StoreProperties();
       
   242         const MVPbkFieldTypeList& supportedFieldTypes =
       
   243             storeProperties.SupportedFields();
       
   244     
       
   245         if( !iFieldProperties )
       
   246             {
       
   247             iFieldProperties = CPbk2FieldPropertyArray::NewL(
       
   248                 supportedFieldTypes, CCoeEnv::Static()->FsSession() );
       
   249             }
       
   250     
       
   251         // Create a field property list of the supported
       
   252         // field types of the used store
       
   253         CPbk2StorePropertyArray* pbk2StoreProperties = CPbk2StorePropertyArray::NewL();
       
   254         CleanupStack::PushL( pbk2StoreProperties );
       
   255     
       
   256         if( !iSpecificFieldProperties )
       
   257             {
       
   258             iSpecificFieldProperties = CPbk2StoreSpecificFieldPropertyArray::NewL(
       
   259                 *iFieldProperties,
       
   260                 *pbk2StoreProperties,
       
   261                 supportedFieldTypes,
       
   262                 storeContact->ParentStore() );
       
   263             }
       
   264     
       
   265         iPresentationContact = CPbk2PresentationContact::NewL( 
       
   266             *storeContact, *iSpecificFieldProperties );
       
   267         
       
   268         CleanupStack::PopAndDestroy( pbk2StoreProperties );
       
   269         }
       
   270     return iPresentationContact;
       
   271     }
       
   272 
       
   273 
   169 // --------------------------------------------------------------------------
   274 // --------------------------------------------------------------------------
   170 // CPbk2OpenMyCardCmd::IssueRequest
   275 // CPbk2OpenMyCardCmd::IssueRequest
   171 // --------------------------------------------------------------------------
   276 // --------------------------------------------------------------------------
   172 //
   277 //
   173 void CPbk2OpenMyCardCmd::RunL()
   278 void CPbk2OpenMyCardCmd::RunL()