phonebookui/Phonebook2/USIMExtension/src/CPsu2LaunchViewCmd.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
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 USIM UI Extension launch view command.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CPsu2LaunchViewCmd.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include "CPsu2ViewManager.h"
       
    23 #include <Pbk2ProcessDecoratorFactory.h>
       
    24 #include <Pbk2USimUIRes.rsg>
       
    25 #include <CPbk2AppUiBase.h>
       
    26 #include <MPbk2ViewExplorer.h>
       
    27 #include <CPbk2SortOrderManager.h>
       
    28 
       
    29 // Virtual Phonebook
       
    30 #include <CVPbkContactManager.h>
       
    31 #include <VPbkContactStoreUris.h>
       
    32 #include <TVPbkContactStoreUriPtr.h>
       
    33 #include <MVPbkContactStore.h>
       
    34 #include <MVPbkContactStoreList.h>
       
    35 #include <MVPbkContactViewBase.h>
       
    36 #include <MPbk2CommandObserver.h>
       
    37 #include <MVPbkSimPhone.h>
       
    38 
       
    39 // System includes
       
    40 #include <coemain.h>
       
    41 
       
    42 /// Unnamed namespace for local definitions
       
    43 namespace {
       
    44 
       
    45 /**
       
    46  * Converts the given view id to related contact store URI.
       
    47  *
       
    48  * @param aViewId   Id to convert.
       
    49  * @return  Contact store URI.
       
    50  */
       
    51 const TDesC& GetURI(TPsu2ViewId aViewId)
       
    52     {
       
    53     switch (aViewId)
       
    54         {
       
    55         case EPsu2OwnNumberViewId:
       
    56             {
       
    57             return VPbkContactStoreUris::SimGlobalOwnNumberUri();
       
    58             }
       
    59         case EPsu2ServiceDialingViewId:
       
    60             {
       
    61             return VPbkContactStoreUris::SimGlobalSdnUri();
       
    62             }
       
    63         case EPsu2FixedDialingViewId:
       
    64             {
       
    65             return VPbkContactStoreUris::SimGlobalFdnUri();
       
    66             }
       
    67         default:
       
    68             {
       
    69             return KNullDesC;
       
    70             }
       
    71         }
       
    72     }
       
    73 
       
    74 } /// namespace
       
    75 
       
    76 
       
    77 // --------------------------------------------------------------------------
       
    78 // CPsu2LaunchViewCmd::CPsu2LaunchViewCmd
       
    79 // --------------------------------------------------------------------------
       
    80 //
       
    81 CPsu2LaunchViewCmd::CPsu2LaunchViewCmd
       
    82         ( CPsu2ViewManager& aViewManager, 
       
    83           TPsu2ViewId aViewId ) :
       
    84             CActive( EPriorityStandard ),
       
    85             iViewManager( aViewManager ),
       
    86             iViewId( aViewId ),
       
    87             iContactViewReady( EFalse )
       
    88     {
       
    89     }
       
    90 
       
    91 // --------------------------------------------------------------------------
       
    92 // CPsu2LaunchViewCmd::~CPsu2LaunchViewCmd
       
    93 // --------------------------------------------------------------------------
       
    94 //
       
    95 CPsu2LaunchViewCmd::~CPsu2LaunchViewCmd()
       
    96     {
       
    97     iViewManager.RemoveViewLaunchCallBack();    
       
    98     
       
    99     delete iDecorator;
       
   100     
       
   101     if (iVPbkView)
       
   102         {
       
   103         iVPbkView->RemoveObserver(*this);
       
   104         }
       
   105     iViewManager.DeregisterStoreAndView();
       
   106 
       
   107     Cancel();
       
   108     }
       
   109 
       
   110 
       
   111 // --------------------------------------------------------------------------
       
   112 // CPsu2LaunchViewCmd::ConstructL
       
   113 // --------------------------------------------------------------------------
       
   114 //
       
   115 inline void CPsu2LaunchViewCmd::ConstructL()
       
   116     {
       
   117     CActiveScheduler::Add( this );
       
   118 
       
   119     iDecorator = Pbk2ProcessDecoratorFactory::CreateWaitNoteDecoratorL
       
   120         ( R_QTN_FDN_READING_CONTACTS_WAIT_NOTE, ETrue );
       
   121     iDecorator->SetObserver( *this );
       
   122     }
       
   123 
       
   124 // --------------------------------------------------------------------------
       
   125 // CPsu2LaunchViewCmd::NewL
       
   126 // --------------------------------------------------------------------------
       
   127 //
       
   128 CPsu2LaunchViewCmd* CPsu2LaunchViewCmd::NewL
       
   129         ( CPsu2ViewManager& aViewManager, 
       
   130           TPsu2ViewId aViewId )
       
   131     {
       
   132     CPsu2LaunchViewCmd* self = new ( ELeave ) CPsu2LaunchViewCmd
       
   133         ( aViewManager, aViewId );
       
   134     CleanupStack::PushL( self );
       
   135     self->ConstructL();
       
   136     CleanupStack::Pop( self );
       
   137     return self;
       
   138     }
       
   139 
       
   140 // --------------------------------------------------------------------------
       
   141 // CPsu2LaunchViewCmd::RunL
       
   142 // --------------------------------------------------------------------------
       
   143 //
       
   144 void CPsu2LaunchViewCmd::RunL()
       
   145     {
       
   146     iDecorator->ProcessStartedL( 0 ); // wait note doesn't care about amount
       
   147     OpenStoreAndViewL();
       
   148     }
       
   149 
       
   150 // --------------------------------------------------------------------------
       
   151 // CPsu2LaunchViewCmd::DoCancel
       
   152 // --------------------------------------------------------------------------
       
   153 //
       
   154 void CPsu2LaunchViewCmd::DoCancel()
       
   155     {
       
   156     // Nothing to cancel
       
   157     }
       
   158 
       
   159 // --------------------------------------------------------------------------
       
   160 // CPsu2LaunchViewCmd::RunError
       
   161 // --------------------------------------------------------------------------
       
   162 //
       
   163 TInt CPsu2LaunchViewCmd::RunError( TInt aError )
       
   164     {
       
   165     HandleError( aError );
       
   166     return KErrNone;
       
   167     }
       
   168 
       
   169 // --------------------------------------------------------------------------
       
   170 // CPsu2LaunchViewCmd::ExecuteLD
       
   171 // --------------------------------------------------------------------------
       
   172 //
       
   173 void CPsu2LaunchViewCmd::ExecuteLD()
       
   174     {
       
   175     IssueRequest();
       
   176     }
       
   177 
       
   178 // --------------------------------------------------------------------------
       
   179 // CPsu2LaunchViewCmd::AddObserver
       
   180 // --------------------------------------------------------------------------
       
   181 //
       
   182 void CPsu2LaunchViewCmd::AddObserver( MPbk2CommandObserver& aObserver )
       
   183     {
       
   184     iCommandObserver = &aObserver;
       
   185     }
       
   186 
       
   187 // --------------------------------------------------------------------------
       
   188 // CPsu2LaunchViewCmd::ResetUiControl
       
   189 // --------------------------------------------------------------------------
       
   190 //
       
   191 void CPsu2LaunchViewCmd::ResetUiControl
       
   192         ( MPbk2ContactUiControl& /*aUiControl*/ )
       
   193     {
       
   194     // Do nothing
       
   195     }
       
   196 
       
   197 // --------------------------------------------------------------------------
       
   198 // CPsu2LaunchViewCmd::ProcessDismissed
       
   199 // --------------------------------------------------------------------------
       
   200 //
       
   201 void CPsu2LaunchViewCmd::ProcessDismissed( TInt aCancelCode )
       
   202     {
       
   203     if ( aCancelCode != EAknSoftkeyDone )
       
   204         {
       
   205         iVPbkView = NULL;
       
   206         }
       
   207     else
       
   208         {
       
   209         if ( iContactViewReady )
       
   210             {
       
   211             CPbk2AppUiBase<CAknViewAppUi>& appUi = static_cast<CPbk2AppUiBase<CAknViewAppUi>&>
       
   212                 ( *CEikonEnv::Static()->EikAppUi() );
       
   213             
       
   214             // if appUi is not in in foreground (that means phonebook2 has hidden itself in background
       
   215             // and names list view has been activated so that when re-enter phonebook user will see names 
       
   216             // list view is the first view ), then no need to active the fixed dialing view.
       
   217             if ( appUi.IsForeground() )
       
   218                 {
       
   219                 TRAPD( error, Phonebook2::Pbk2AppUi()->Pbk2ViewExplorer()->
       
   220                     ActivatePhonebook2ViewL( TUid::Uid( iViewId ), NULL ) );
       
   221                 if ( error != KErrNone )
       
   222                     {
       
   223                     HandleError( error );
       
   224                     }          
       
   225                 }
       
   226 
       
   227             if ( iVPbkView )
       
   228                 {
       
   229                 iVPbkView->RemoveObserver( *this );
       
   230                 }
       
   231             }
       
   232         }
       
   233     
       
   234     if ( iCommandObserver )
       
   235         {
       
   236         iCommandObserver->CommandFinished( *this );    
       
   237         }    
       
   238     }
       
   239 
       
   240 // --------------------------------------------------------------------------
       
   241 // CPsu2LaunchViewCmd::ContactViewReady
       
   242 // --------------------------------------------------------------------------
       
   243 //
       
   244 void CPsu2LaunchViewCmd::ContactViewReady( MVPbkContactViewBase& aView )
       
   245     {
       
   246     if ( iVPbkView == &aView )
       
   247         {
       
   248         iContactViewReady = ETrue;
       
   249         iDecorator->ProcessStopped();
       
   250         }
       
   251     }
       
   252 
       
   253 // --------------------------------------------------------------------------
       
   254 // CPsu2LaunchViewCmd::ContactViewUnavailable
       
   255 // --------------------------------------------------------------------------
       
   256 //
       
   257 void CPsu2LaunchViewCmd::ContactViewUnavailable
       
   258         ( MVPbkContactViewBase& /*aView*/ )
       
   259     {
       
   260     // Do nothing
       
   261     }
       
   262 
       
   263 // --------------------------------------------------------------------------
       
   264 // CPsu2LaunchViewCmd::ContactAddedToView
       
   265 // --------------------------------------------------------------------------
       
   266 //
       
   267 void CPsu2LaunchViewCmd::ContactAddedToView( 
       
   268         MVPbkContactViewBase& /*aView*/, 
       
   269         TInt /*aIndex*/,
       
   270         const MVPbkContactLink& /*aContactLink*/ )
       
   271     {
       
   272     // Do nothing
       
   273     }
       
   274 
       
   275 // --------------------------------------------------------------------------
       
   276 // CPsu2LaunchViewCmd::ContactRemovedFromView
       
   277 // --------------------------------------------------------------------------
       
   278 //
       
   279 void CPsu2LaunchViewCmd::ContactRemovedFromView( 
       
   280         MVPbkContactViewBase& /*aView*/, 
       
   281         TInt /*aIndex*/,
       
   282         const MVPbkContactLink& /*aContactLink*/ )
       
   283     {
       
   284     // Do nothing
       
   285     }
       
   286 
       
   287 // --------------------------------------------------------------------------
       
   288 // CPsu2LaunchViewCmd::ContactViewError
       
   289 // --------------------------------------------------------------------------
       
   290 //
       
   291 void CPsu2LaunchViewCmd::ContactViewError( 
       
   292         MVPbkContactViewBase& aView, 
       
   293         TInt aError,
       
   294         TBool /*aErrorNotified*/ )
       
   295     {
       
   296     if ( iVPbkView == &aView )
       
   297         {
       
   298         HandleError( aError );
       
   299         }
       
   300     }
       
   301 
       
   302 // --------------------------------------------------------------------------
       
   303 // CPsu2LaunchViewCmd::SetContactViewL
       
   304 // --------------------------------------------------------------------------
       
   305 //
       
   306 void CPsu2LaunchViewCmd::SetContactViewL( MVPbkContactViewBase& aContactView )
       
   307     {
       
   308     iVPbkView = &aContactView;
       
   309     iVPbkView->AddObserverL( *this );
       
   310     }
       
   311 
       
   312 // --------------------------------------------------------------------------
       
   313 // CPsu2LaunchViewCmd::HandleError
       
   314 // --------------------------------------------------------------------------
       
   315 //
       
   316 void CPsu2LaunchViewCmd::HandleError( TInt aError )
       
   317     {
       
   318     iDecorator->ProcessStopped();
       
   319     CCoeEnv::Static()->HandleError( aError );
       
   320     }
       
   321 
       
   322 // --------------------------------------------------------------------------
       
   323 // CPsu2LaunchViewCmd::IssueRequest
       
   324 // --------------------------------------------------------------------------
       
   325 //
       
   326 void CPsu2LaunchViewCmd::IssueRequest()
       
   327     {
       
   328     TRequestStatus* status = &iStatus;
       
   329     User::RequestComplete( status, KErrNone );
       
   330     SetActive();
       
   331     }
       
   332 
       
   333 // --------------------------------------------------------------------------
       
   334 // CPsu2LaunchViewCmd::OpenStoreAndViewL
       
   335 // --------------------------------------------------------------------------
       
   336 //
       
   337 void CPsu2LaunchViewCmd::OpenStoreAndViewL()
       
   338     {
       
   339     TVPbkContactStoreUriPtr uri( GetURI( iViewId ) );
       
   340     iViewManager.ResetAndInitiateStoreAndViewL( uri, iViewId, *this );
       
   341     iViewManager.RegisterStoreAndView();
       
   342     }
       
   343 
       
   344 //  End of File