phonebookui/Phonebook2/NamesListExtension/src/CPbk2NlxOpenCcaCmd.cpp
changeset 0 e686773b3f54
child 9 0d28c1c5b6dd
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 CCA launcher command
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPbk2NlxOpenCcaCmd.h"
       
    21 #include <CPbk2NamesListControl.h>
       
    22 #include <MPbk2CommandObserver.h>
       
    23 #include <MVPbkBaseContact.h>
       
    24 
       
    25 //Cca
       
    26 #include <mccaparameter.h>
       
    27 #include <mccaconnection.h>
       
    28 #include <ccafactory.h>
       
    29 
       
    30 // Debugging headers
       
    31 #include <Pbk2Debug.h>
       
    32 #include <Pbk2Profile.h>
       
    33 
       
    34 // --------------------------------------------------------------------------
       
    35 // CPbk2NlxOpenCcaCmd::CPbk2NlxOpenCcaCmd
       
    36 // --------------------------------------------------------------------------
       
    37 //
       
    38 CPbk2NlxOpenCcaCmd::CPbk2NlxOpenCcaCmd(
       
    39     MPbk2ContactUiControl& aUiControl,
       
    40     MCCAConnection*& aCCAConnection ) :
       
    41         CActive( EPriorityStandard ),
       
    42         iUiControl( &aUiControl ),
       
    43         iConnectionRef(aCCAConnection)
       
    44     {
       
    45     CActiveScheduler::Add( this );
       
    46     }
       
    47 
       
    48 // --------------------------------------------------------------------------
       
    49 // CPbk2NlxOpenCcaCmd::~CPbk2NlxOpenCcaCmd
       
    50 // --------------------------------------------------------------------------
       
    51 //
       
    52 CPbk2NlxOpenCcaCmd::~CPbk2NlxOpenCcaCmd()
       
    53     {
       
    54     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
    55         ("CPbk2NlxOpenCcaCmd(%x)::~CPbk2NlxOpenCcaCmd()"), this);
       
    56 
       
    57     if (IsActive())
       
    58         {
       
    59         Cancel();
       
    60         }
       
    61     
       
    62     if( iUiControl )
       
    63         {
       
    64         iUiControl->RegisterCommand( NULL );
       
    65         }
       
    66     }
       
    67 
       
    68 // --------------------------------------------------------------------------
       
    69 // CPbk2NlxOpenCcaCmd::NewL
       
    70 // --------------------------------------------------------------------------
       
    71 //
       
    72 CPbk2NlxOpenCcaCmd* CPbk2NlxOpenCcaCmd::NewL(
       
    73     MPbk2ContactUiControl& aUiControl,
       
    74     MCCAConnection*& aCCAConnection )
       
    75     {
       
    76     CPbk2NlxOpenCcaCmd* self = new ( ELeave ) CPbk2NlxOpenCcaCmd
       
    77         ( aUiControl, aCCAConnection );
       
    78     CleanupStack::PushL( self );
       
    79     self->ConstructL();
       
    80     CleanupStack::Pop( self );
       
    81     return self;
       
    82     }
       
    83 
       
    84 // --------------------------------------------------------------------------
       
    85 // CPbk2NlxOpenCcaCmd::ConstructL
       
    86 // --------------------------------------------------------------------------
       
    87 //
       
    88 void CPbk2NlxOpenCcaCmd::ConstructL()
       
    89     {    
       
    90     if( iUiControl )
       
    91         {
       
    92         iUiControl->RegisterCommand( this );
       
    93         }    
       
    94     }
       
    95     
       
    96 // --------------------------------------------------------------------------
       
    97 // CPbk2NlxOpenCcaCmd::ExecuteLD
       
    98 // --------------------------------------------------------------------------
       
    99 //
       
   100 void CPbk2NlxOpenCcaCmd::ExecuteLD()
       
   101     {
       
   102     iState = ELaunching;
       
   103     IssueRequest();
       
   104     }
       
   105     
       
   106 // --------------------------------------------------------------------------
       
   107 // CPbk2NlxOpenCcaCmd::ResetUiControl
       
   108 // --------------------------------------------------------------------------
       
   109 //
       
   110 void CPbk2NlxOpenCcaCmd::ResetUiControl( MPbk2ContactUiControl& aUiControl )
       
   111     {
       
   112     if ( iUiControl == &aUiControl )
       
   113         {
       
   114         iUiControl = NULL;
       
   115         }
       
   116     }
       
   117     
       
   118 // --------------------------------------------------------------------------
       
   119 // CPbk2NlxOpenCcaCmd::AddObserver
       
   120 // --------------------------------------------------------------------------
       
   121 //
       
   122 void CPbk2NlxOpenCcaCmd::AddObserver( MPbk2CommandObserver& aObserver )
       
   123     {
       
   124     iCommandObserver = &aObserver;
       
   125     }        
       
   126     
       
   127 // --------------------------------------------------------------------------
       
   128 // CPbk2NlxOpenCcaCmd::LaunchCcaL
       
   129 // --------------------------------------------------------------------------
       
   130 //
       
   131 void CPbk2NlxOpenCcaCmd::LaunchCcaL()
       
   132     {   
       
   133     if (iUiControl)
       
   134         {
       
   135         if(!iConnectionRef)
       
   136             {
       
   137             iConnectionRef = TCCAFactory::NewConnectionL();
       
   138             }
       
   139         
       
   140         MCCAParameter* parameter = TCCAFactory::NewParameterL();
       
   141         CleanupClosePushL( *parameter );
       
   142         parameter->SetConnectionFlag(MCCAParameter::ENormal);
       
   143         parameter->SetContactDataFlag(MCCAParameter::EContactLink);
       
   144         
       
   145         const MVPbkBaseContact* contact = iUiControl->FocusedContactL();  
       
   146         
       
   147         if(contact) 
       
   148             {
       
   149             MVPbkContactLink* link = contact->CreateLinkLC(); 
       
   150 
       
   151             if (link)
       
   152                 {
       
   153                 HBufC8* link8 = link->PackLC();                        
       
   154                 HBufC16* link16 = HBufC16::NewLC( link8->Length() );
       
   155                 link16->Des().Copy( *link8);
       
   156                 parameter->SetContactDataL(link16->Des());
       
   157                 CleanupStack::PopAndDestroy(3); 
       
   158                 }
       
   159 
       
   160             // Sync call
       
   161             iConnectionRef->LaunchAppL( *parameter );
       
   162             CleanupStack::Pop();// parameter is taken care by iConnectionRef
       
   163             }
       
   164         }
       
   165     iState = ERunning;
       
   166     IssueRequest();
       
   167     }
       
   168 
       
   169 // --------------------------------------------------------------------------
       
   170 // CPbk2NlxOpenCcaCmd::IssueRequest
       
   171 // --------------------------------------------------------------------------
       
   172 //
       
   173 void CPbk2NlxOpenCcaCmd::IssueRequest()
       
   174     {
       
   175     TRequestStatus* status = &iStatus;
       
   176     User::RequestComplete( status, KErrNone );
       
   177     SetActive();
       
   178     }
       
   179 
       
   180 // --------------------------------------------------------------------------
       
   181 // CPbk2NlxOpenCcaCmd::IssueRequest
       
   182 // --------------------------------------------------------------------------
       
   183 //
       
   184 void CPbk2NlxOpenCcaCmd::RunL()
       
   185     {
       
   186     if ( iState == ELaunching )
       
   187         {
       
   188         LaunchCcaL();   //Sync
       
   189         }
       
   190     if ( iState == ERunning )
       
   191         {
       
   192         if ( iUiControl )
       
   193             {
       
   194             iUiControl->UpdateAfterCommandExecution();  
       
   195             }            
       
   196         // Asynchronous delete of this command object
       
   197         iCommandObserver->CommandFinished( *this );
       
   198         }
       
   199     }
       
   200 
       
   201 // --------------------------------------------------------------------------
       
   202 // CPbk2NlxOpenCcaCmd::IssueRequest
       
   203 // --------------------------------------------------------------------------
       
   204 //
       
   205 void CPbk2NlxOpenCcaCmd::DoCancel()
       
   206     {
       
   207     // Do nothing
       
   208     }
       
   209 
       
   210 // --------------------------------------------------------------------------
       
   211 // CPbk2NlxOpenCcaCmd::RunError
       
   212 // --------------------------------------------------------------------------
       
   213 //
       
   214 TInt CPbk2NlxOpenCcaCmd::RunError(TInt aError)
       
   215     {
       
   216     // Forward all errors to the framework. They will be
       
   217     // displayed on screen to the user. Typically there 
       
   218     // should not be any errors.
       
   219     
       
   220     return aError;
       
   221     }
       
   222 
       
   223 //  End of File