satengine/SatServer/SatInternalClient/src/CSatCSetUpMenuHandler.cpp
changeset 0 ff3b6d0fd310
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2002-2008 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:  This is the handler for the SIM Application Toolkit
       
    15 *                Set Up Menu proactive command.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include    <e32base.h>
       
    23 #include    <e32svr.h>
       
    24 #include    "RSatUiSession.h"
       
    25 #include    "MSatUiObserver.h"
       
    26 #include    "SatSOpcodes.h"
       
    27 #include    "CSatCSetUpMenuHandler.h"
       
    28 #include    "SatLog.h"
       
    29 
       
    30 // CONSTANTS
       
    31 const TInt8 KMenuItemPop( 3 );
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CSatCSetUpMenuHandler::CSatCSetUpMenuHandler
       
    37 // C++ default constructor can NOT contain any code, that
       
    38 // might leave.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CSatCSetUpMenuHandler::CSatCSetUpMenuHandler(
       
    42     TInt aPriority,
       
    43     RSatUiSession* aSession ) :
       
    44     CActive( aPriority ),
       
    45     iSession( aSession ),
       
    46     iSetUpMenuData(),
       
    47     iSetUpMenuPckg( iSetUpMenuData ),
       
    48     iSetUpMenuRsp(),
       
    49     iSetUpMenuRspPckg( iSetUpMenuRsp )
       
    50     {
       
    51     LOG( SIMPLE,
       
    52         "SATINTERNALCLIENT: CSatCSetUpMenuHandler::CSatCSetUpMenuHandler calling" )
       
    53 
       
    54     // Add to active scheduler.
       
    55     CActiveScheduler::Add( this );
       
    56 
       
    57     LOG( SIMPLE,
       
    58         "SATINTERNALCLIENT: CSatCSetUpMenuHandler::CSatCSetUpMenuHandler exiting" )
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CSatCSetUpMenuHandler::NewL
       
    63 // Two-phased constructor.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CSatCSetUpMenuHandler* CSatCSetUpMenuHandler::NewL(
       
    67     RSatUiSession* aSat )
       
    68     {
       
    69     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCSetUpMenuHandler::NewL calling" )
       
    70 
       
    71     // Perform the construction.
       
    72     CSatCSetUpMenuHandler* self =
       
    73         new ( ELeave ) CSatCSetUpMenuHandler( EPriorityLow, aSat );
       
    74 
       
    75     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCSetUpMenuHandler::NewL exiting" )
       
    76     return self;
       
    77     }
       
    78 
       
    79 // Destructor
       
    80 CSatCSetUpMenuHandler::~CSatCSetUpMenuHandler()
       
    81     {
       
    82     LOG( SIMPLE,
       
    83         "SATINTERNALCLIENT: CSatCSetUpMenuHandler::~CSatCSetUpMenuHandler calling" )
       
    84 
       
    85     // Cancel any outstanding requests.
       
    86     Cancel();
       
    87     iSession = NULL;
       
    88 
       
    89     LOG( SIMPLE,
       
    90         "SATINTERNALCLIENT: CSatCSetUpMenuHandler::~CSatCSetUpMenuHandler exiting" )
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CSatCSetUpMenuHandler::Start
       
    95 // Starts the handler.
       
    96 // (other items were commented in a header).
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 
       
   100 void CSatCSetUpMenuHandler::Start()
       
   101     {
       
   102     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCSetUpMenuHandler::Start calling" )
       
   103 
       
   104     // Empty the IPC data
       
   105     RSat::TSetUpMenuV2 temp;
       
   106     iSetUpMenuData = temp;
       
   107     RSat::TSetUpMenuRspV1 temp2;
       
   108     iSetUpMenuRsp = temp2;
       
   109 
       
   110     // Request Set Up Menu notification.
       
   111     TIpcArgs arguments( &iSetUpMenuPckg );
       
   112 
       
   113     // Pass the Set Up Menu IPC package.
       
   114     iSession->CreateRequest( ESatSProactiveSetUpMenu, arguments, iStatus );
       
   115 
       
   116     // Set this handler to active so that it can receive requests.
       
   117     SetActive();
       
   118 
       
   119     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCSetUpMenuHandler::Start exiting" )
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CSatCSetUpMenuHandler::RunL
       
   124 // Handles the command.
       
   125 // (other items were commented in a header).
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 void CSatCSetUpMenuHandler::RunL()
       
   129     {
       
   130     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCSetUpMenuHandler::RunL calling" )
       
   131 
       
   132     // Check the status of the asnychronous operation
       
   133     if ( KErrNone != iStatus.Int() )
       
   134         {
       
   135         LOG2(
       
   136             SIMPLE,
       
   137             "SATINTERNALCLIENT: CSatCSetUpMenuHandler::RunL exiting, error: %d",
       
   138             iStatus.Int() )
       
   139         }
       
   140     else 
       
   141         {
       
   142         // Save the contents of the data for envelope Menu Selection.
       
   143         iOldSetUpMenuData = iSetUpMenuData;
       
   144 
       
   145         // Create the menu item array.
       
   146         CDesCArrayFlat* menuItems = new( ELeave ) CDesCArrayFlat( 1 );
       
   147         CleanupStack::PushL( menuItems );
       
   148 
       
   149         // Create the next action indicator array.
       
   150         CArrayFixFlat<TSatAction>* menuActions =
       
   151             new( ELeave ) CArrayFixFlat<TSatAction>( 1 );
       
   152         CleanupStack::PushL( menuActions );
       
   153 
       
   154         // Create the menu item icon array.
       
   155         CArrayFixFlat<TInt>* menuIcons =
       
   156             new( ELeave ) CArrayFixFlat<TInt>( 1 );
       
   157         CleanupStack::PushL( menuIcons );
       
   158 
       
   159         // Fetch all the menu items.
       
   160         // Note that the indexing starts from 1 in SIM item lists.
       
   161         const TInt menuItemCount(
       
   162             static_cast<TInt>( iSetUpMenuData.NumberOfItems() ) );
       
   163         LOG2( SIMPLE,
       
   164         "SATINTERNALCLIENT: CSatCSetUpMenuHandler::RunL menuItemCount: %d",
       
   165         menuItemCount )
       
   166         for ( TInt currentItem = 1;
       
   167               currentItem <= menuItemCount;
       
   168               currentItem++ )
       
   169             {
       
   170             RSat::TItem item;
       
   171             TInt action;
       
   172             TInt icon( KErrNotFound );
       
   173 
       
   174             // Fetch all data for this index.
       
   175             iSetUpMenuData.GetItem( static_cast<TUint>( currentItem ),
       
   176                                     item,
       
   177                                     action,
       
   178                                     icon );
       
   179 
       
   180             // Save the item name
       
   181             menuItems->AppendL( item.iItemString );
       
   182 
       
   183             // Save icon identifier.
       
   184             // icon will be KErrNotFound (-1) if it is not present in the
       
   185             // SAT menu.
       
   186             menuIcons->AppendL( icon );
       
   187             
       
   188             if ( KErrNotFound != action )
       
   189                 {
       
   190                 LOG2( SIMPLE,
       
   191                 "SATINTERNALCLIENT: CSatCSetUpMenuHandler::RunL action: %d", action )
       
   192                 // Save the next action indicator, if found.
       
   193                 menuActions->AppendL( STATIC_CAST( TSatAction, action ) );
       
   194                 }
       
   195             }
       
   196 
       
   197         // Indicates whether help is available
       
   198         TBool helpIsAvailable( EFalse );
       
   199         if ( RSat::EHelpAvailable == iSetUpMenuData.iHelp )
       
   200             {
       
   201             LOG( SIMPLE, 
       
   202             "SATINTERNALCLIENT: CSatCSetUpMenuHandler::RunL EHelpAvailable" )
       
   203             helpIsAvailable = ETrue;
       
   204             }
       
   205 
       
   206         // Has to be casted to TInt before casting to TSatIconQualifier,
       
   207         // because gcc warns about the direct cast.
       
   208         const struct TSatIconId iconId = { iSetUpMenuData.iIconId.iIdentifier,
       
   209             static_cast<TSatIconQualifier>(
       
   210                 static_cast<TInt>( iSetUpMenuData.iIconId.iQualifier ) ) };
       
   211 
       
   212         const enum TSatIconQualifier iconListQualifier(
       
   213             static_cast<TSatIconQualifier>(
       
   214                 static_cast<TInt>( iSetUpMenuData.iIconListQualifier ) ) );
       
   215 
       
   216         const enum TSatSelectionPreference selectionPreference(
       
   217             static_cast<TSatSelectionPreference>(
       
   218                 static_cast<TInt>( iSetUpMenuData.iPreference ) ) );
       
   219 
       
   220         // Notify the registered client and save the response.
       
   221         TSatUiResponse response(
       
   222             iSession->SatUiObserver()->SetUpMenuL(
       
   223             iSetUpMenuData.iAlphaId.iAlphaId,
       
   224             *menuItems,
       
   225             menuActions,
       
   226             helpIsAvailable,
       
   227             iconId,
       
   228             menuIcons,
       
   229             iconListQualifier,
       
   230             selectionPreference ) );
       
   231             
       
   232         LOG2( SIMPLE,
       
   233         "SATINTERNALCLIENT: CSatCSetUpMenuHandler::RunL response: %x", response )
       
   234         // Examine the client response.
       
   235         switch ( response )
       
   236             {
       
   237             case ESatSuccess:
       
   238                 {
       
   239                 break;
       
   240                 }
       
   241             case ESatFailure:
       
   242                 {
       
   243                 iSession->Panic( ESatSetUpMenuFailure );
       
   244                 break;
       
   245                 }
       
   246             case ESatSessionTerminatedByUser:
       
   247             case ESatBackwardModeRequestedByUser:
       
   248             case ESatNoResponseFromUser:
       
   249             case EHelpRequestedByUser:
       
   250             case EPCmdNotAcceptedByUser:
       
   251             case ESatCmdDataNotUnderstood:
       
   252             default:
       
   253                 {
       
   254                 iSession->Panic( ESatInvalidResponse );
       
   255                 break;
       
   256                 }
       
   257             }
       
   258 
       
   259         // Destroy the array objects: menuIcons, menuActions, menuItems.
       
   260         CleanupStack::PopAndDestroy( KMenuItemPop, menuItems );
       
   261         }
       
   262 
       
   263     // Renew the service request.
       
   264     Start();
       
   265 
       
   266     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCSetUpMenuHandler::RunL exiting" )
       
   267     }
       
   268 
       
   269 // -----------------------------------------------------------------------------
       
   270 // CSatCSetUpMenuHandler::DoCancel
       
   271 // Cancels the pending request.
       
   272 // (other items were commented in a header).
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 void CSatCSetUpMenuHandler::DoCancel()
       
   276     {
       
   277     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCSetUpMenuHandler::DoCancel calling" )
       
   278 
       
   279     // Complete the request with cancel code.
       
   280     TRequestStatus* requestStatus = &iStatus;
       
   281     User::RequestComplete( requestStatus, KErrCancel );
       
   282 
       
   283     LOG( SIMPLE, "SATINTERNALCLIENT: CSatCSetUpMenuHandler::DoCancel exiting" )
       
   284     }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CSatCSetUpMenuHandler::OldSetUpMenuData
       
   288 // Returns a pointer to a old the command data object.
       
   289 // (other items were commented in a header).
       
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 RSat::TSetUpMenuV2 CSatCSetUpMenuHandler::OldSetUpMenuData() const
       
   293     {
       
   294     LOG( SIMPLE,
       
   295         "SATINTERNALCLIENT: CSatCSetUpMenuHandler::OldSetUpMenuData calling-exiting" )
       
   296     return iOldSetUpMenuData;
       
   297     }
       
   298 
       
   299 //  End of File