satengine/SatServer/Commands/SelectItemCmd/src/CSelectItemHandler.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2002-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:  Handles SelectItem command
       
    15 *
       
    16 */
       
    17 
       
    18 #include    <etelsat.h>
       
    19 #include    "MSatApi.h"
       
    20 #include    "MSatUtils.h"
       
    21 #include    "MSatUiSession.h"
       
    22 #include    "SatSOpcodes.h"
       
    23 #include    "MSatSUiClientHandler.h"
       
    24 #include    "CSelectItemHandler.h"
       
    25 #include    "SatLog.h"
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CSelectItemHandler::CSelectItemHandler
       
    31 // C++ default constructor can NOT contain any code, that
       
    32 // might leave.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CSelectItemHandler::CSelectItemHandler() :
       
    36     CSatCommandHandler(),
       
    37     iSelectItemData(),
       
    38     iSelectItemPckg( iSelectItemData ),
       
    39     iSelectItemRsp(),
       
    40     iSelectItemRspPckg( iSelectItemRsp ),
       
    41     // To be removed when icons are allowed in this command
       
    42     iIconCommand( EFalse )
       
    43     {
       
    44     LOG( SIMPLE,
       
    45         "SELECTITEM: CSelectItemHandler::CSelectItemHandler calling - exiting" )
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CSelectItemHandler::ConstructL
       
    50 // Symbian 2nd phase constructor can leave.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 void CSelectItemHandler::ConstructL()
       
    54     {
       
    55     LOG( SIMPLE, "SELECTITEM: CSelectItemHandler::ConstructL calling" )
       
    56 
       
    57     // Register service request handler for SelectItem command.
       
    58     iUtils->RegisterServiceRequestL(
       
    59         ESatSProactiveSelectItem,
       
    60         ESatSProactiveSelectItemResponse,
       
    61         this );
       
    62 
       
    63     LOG( SIMPLE, "SELECTITEM: CSelectItemHandler::ConstructL exiting" )
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CSelectItemHandler::NewL
       
    68 // Two-phased constructor.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CSelectItemHandler* CSelectItemHandler::NewL( MSatUtils* aUtils )
       
    72     {
       
    73     LOG( SIMPLE, "SELECTITEM: CSelectItemHandler::NewL calling" )
       
    74     CSelectItemHandler* self = new( ELeave ) CSelectItemHandler;
       
    75 
       
    76     CleanupStack::PushL( self );
       
    77     self->BaseConstructL( aUtils );
       
    78     self->ConstructL();
       
    79     CleanupStack::Pop( self );
       
    80 
       
    81     LOG( SIMPLE, "SELECTITEM: CSelectItemHandler::NewL exiting" )
       
    82     return self;
       
    83     }
       
    84 
       
    85 
       
    86 // Destructor
       
    87 CSelectItemHandler::~CSelectItemHandler()
       
    88     {
       
    89     LOG( SIMPLE, "SELECTITEM: CSelectItemHandler::~CSelectItemHandler calling" )
       
    90 
       
    91     Cancel();
       
    92 
       
    93     LOG( SIMPLE, "SELECTITEM: CSelectItemHandler::~CSelectItemHandler exiting" )
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CSelectItemHandler::ClientResponse
       
    98 // (other items were commented in a header).
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void CSelectItemHandler::ClientResponse()
       
   102     {
       
   103     LOG( SIMPLE, "SELECTITEM: CSelectItemHandler::ClientResponse calling" )
       
   104 
       
   105     //lint -e{961} Only these two cases need to be handeled.
       
   106     if ( RSat::KPSessionTerminatedByUser == iSelectItemRsp.iGeneralResult )
       
   107         {
       
   108         LOG( SIMPLE, "SELECTITEM: CSelectItemHandler::ClientResponse close \
       
   109              ui session" )
       
   110         // Next SimSession end will close the ui session.
       
   111         iUtils->NotifyEvent( MSatUtils::ESessionTerminatedByUser );
       
   112         }
       
   113     // If command had icon data and was done succesfully, report that icon
       
   114     // was not shown
       
   115     // To be removed when icons are allowed in this command
       
   116     else if ( ( RSat::KSuccess == iSelectItemRsp.iGeneralResult ) &&
       
   117         iIconCommand )
       
   118         {
       
   119         LOG( SIMPLE, "SELECTITEM: CSelectItemHandler::ClientResponse \
       
   120              KSuccessRequestedIconNotDisplayed" )
       
   121         iSelectItemRsp.iGeneralResult =
       
   122                     RSat::KSuccessRequestedIconNotDisplayed;
       
   123         }
       
   124 
       
   125     CSatCommandHandler::TerminalRsp( RSat::ESelectItem, iSelectItemRspPckg );
       
   126 
       
   127     LOG( SIMPLE, "SELECTITEM: CSelectItemHandler::ClientResponse exiting" )
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CSelectItemHandler::DoCancel
       
   132 // Cancels the sat request.
       
   133 // (other items were commented in a header).
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CSelectItemHandler::DoCancel()
       
   137     {
       
   138     LOG( SIMPLE, "SELECTITEM: CSelectItemHandler::DoCancel calling" )
       
   139 
       
   140     iUtils->USatAPI().NotifySelectItemCancel();
       
   141 
       
   142     LOG( SIMPLE, "SELECTITEM: CSelectItemHandler::DoCancel exiting" )
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CSelectItemHandler::IssueUSATRequest
       
   147 // (other items were commented in a header).
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 void CSelectItemHandler::IssueUSATRequest( TRequestStatus& aStatus )
       
   151     {
       
   152     LOG( SIMPLE, "SELECTITEM: CSelectItemHandler::IssueUSATRequest calling" )
       
   153 
       
   154     // Clear the IPC package.
       
   155     iSelectItemData.Reset();
       
   156     iSelectItemData.iDefaultItemId = 0;
       
   157     iSelectItemData.iIconId.iQualifier = RSat::EIconQualifierNotSet;
       
   158     iSelectItemData.iIconListQualifier = RSat::EIconQualifierNotSet;
       
   159     iSelectItemData.iIconId.iIdentifier = 0;
       
   160 
       
   161     iUtils->USatAPI().NotifySelectItem( aStatus, iSelectItemPckg );
       
   162 
       
   163     LOG( SIMPLE, "SELECTITEM: CSelectItemHandler::IssueUSATRequest exiting" )
       
   164     }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // CSelectItemHandler::CommandAllowed
       
   168 // (other items were commented in a header).
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 TBool CSelectItemHandler::CommandAllowed()
       
   172     {
       
   173     LOG( SIMPLE,
       
   174         "SELECTITEM: CSelectItemHandler::CommandAllowed calling" )
       
   175 
       
   176     TBool commandAllowed( ETrue );
       
   177     TBool nullText( EFalse );
       
   178     TInt err ( KErrNone );
       
   179     RSat::TItem item;
       
   180     TUint numberOfItems( iSelectItemData.NumberOfItems() );
       
   181     TBool titleIcon(
       
   182         ( RSat::ENotSelfExplanatory == iSelectItemData.iIconId.iQualifier ) ||
       
   183         ( RSat::ESelfExplanatory == iSelectItemData.iIconId.iQualifier ) );
       
   184     TBool itemIcons(
       
   185         ( RSat::ENotSelfExplanatory == iSelectItemData.iIconListQualifier ) ||
       
   186         ( RSat::ESelfExplanatory == iSelectItemData.iIconListQualifier ) );
       
   187     LOG2( NORMAL, "SELECTITEM: CSelectItemHandler::CommandAllowed \
       
   188           numberOfItems: %d", numberOfItems )
       
   189     // Check if some item does not have text
       
   190     for ( TUint count = 1; ( count <= numberOfItems ) && !nullText &&
       
   191         ( KErrNone == err ); count++ )
       
   192         {
       
   193         err = iSelectItemData.GetItem( count, item );
       
   194 
       
   195         if ( ( KErrNone == err ) && ( 0 == item.iItemString.Length() ) )
       
   196             {
       
   197             LOG( SIMPLE,
       
   198             "SELECTITEM: CSelectItemHandler::CommandAllowed null string" )
       
   199             nullText = ETrue;
       
   200             }
       
   201         }
       
   202 
       
   203     // If icon is provided without any text
       
   204     if ( ( ( RSat::EAlphaIdProvided != iSelectItemData.iAlphaId.iStatus ) &&
       
   205              titleIcon ) || ( nullText && itemIcons ) )
       
   206         {
       
   207         iSelectItemRsp.iGeneralResult = RSat::KCmdDataNotUnderstood;
       
   208         iSelectItemRsp.iInfoType = RSat::KNoAdditionalInfo;
       
   209         iSelectItemRsp.iAdditionalInfo.Zero();
       
   210         iSelectItemRsp.SetPCmdNumber( iSelectItemData.PCmdNumber() );
       
   211         TerminalRsp( RSat::ESelectItem, iSelectItemRspPckg );
       
   212         commandAllowed = EFalse;
       
   213         LOG( NORMAL, "SELECTITEM: CSelectItemHandler::\
       
   214             CommandAllowed icon received without alpha id" )
       
   215         }
       
   216     // Set icon command flag whether icon data was received and set qualifier
       
   217     // to no icon id
       
   218     // To be removed when icons are allowed in this command
       
   219     else if ( !titleIcon && !itemIcons )
       
   220         {
       
   221         LOG( NORMAL, "SELECTITEM: CSelectItemHandler::\
       
   222             CommandAllowed no icon " )
       
   223         iIconCommand = EFalse;
       
   224         }
       
   225     else
       
   226         {
       
   227         iIconCommand = ETrue;
       
   228 
       
   229         if ( titleIcon )
       
   230             {
       
   231             LOG( NORMAL, "SELECTITEM: CSelectItemHandler::\
       
   232             CommandAllowed titleIcon true " )
       
   233             iSelectItemData.iIconId.iQualifier = RSat::ENoIconId;
       
   234             }
       
   235 
       
   236         if ( itemIcons )
       
   237             {
       
   238             LOG( NORMAL, "SELECTITEM: CSelectItemHandler::\
       
   239             CommandAllowed itemIcons true " )
       
   240             iSelectItemData.iIconListQualifier = RSat::ENoIconId;
       
   241             }
       
   242         }
       
   243 
       
   244     LOG2( SIMPLE,
       
   245         "SELECTITEM: CSelectItemHandler::CommandAllowed exiting,\
       
   246         commandAllowed: %d", commandAllowed )
       
   247     return commandAllowed;
       
   248     }
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 // CSelectItemHandler::NeedUiSession
       
   252 // (other items were commented in a header).
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 TBool CSelectItemHandler::NeedUiSession()
       
   256     {
       
   257     LOG( NORMAL, "SELECTITEM: CSelectItemHandler::NeedUiSession calling" )
       
   258     // Notify Cover UI if it's supported
       
   259     if ( iUtils->CoverUiSupported() )
       
   260         {
       
   261         LOG( NORMAL, "SELECTITEM: CSelectItemHandler::NeedUiSession \
       
   262              CoverUiSupported" )
       
   263         TSatCommandData medEventData;
       
   264         medEventData.iPCmdNumber = RSat::ESelectItem;
       
   265         medEventData.iAlphaId =  iSelectItemData.iAlphaId;
       
   266         medEventData.iDuration.iNumOfUnits = KSatDefaultDuration;
       
   267         medEventData.iDuration.iTimeUnit = RSat::ESeconds;
       
   268         medEventData.iIconID = iSelectItemData.iIconId;
       
   269         TSatCommandPckg tPckg( medEventData );
       
   270         iUtils->RaiseSatEvent( tPckg );
       
   271         #ifdef ENABLE_SAT_LOGGING    
       
   272         TBuf<RSat::KAlphaIdMaxSize> logAlphaId;        
       
   273         logAlphaId.Copy( medEventData.iAlphaId.iAlphaId );                
       
   274         LOG2( NORMAL, "SELECTITEM: CSelectItemHandler::NeedUiSession \
       
   275         iAlphaId: %S", &logAlphaId )
       
   276         #endif
       
   277         }
       
   278     LOG( NORMAL, "SELECTITEM: CSelectItemHandler::NeedUiSession exiting" )
       
   279     return ETrue;
       
   280     }
       
   281 
       
   282 // -----------------------------------------------------------------------------
       
   283 // CSelectItemHandler::HandleCommand
       
   284 // (other items were commented in a header).
       
   285 // -----------------------------------------------------------------------------
       
   286 //
       
   287 void CSelectItemHandler::HandleCommand()
       
   288     {
       
   289     LOG( SIMPLE, "SELECTITEM: CSelectItemHandler::HandleCommand calling" )
       
   290 
       
   291     iUtils->NotifyEvent( MSatUtils::ESelectItemExecuting );
       
   292 
       
   293     MSatUiSession* uiSession = iUtils->SatUiHandler().UiSession();
       
   294     uiSession->SendCommand(
       
   295         &iSelectItemPckg,
       
   296         &iSelectItemRspPckg,
       
   297         ESatSProactiveSelectItem );
       
   298 
       
   299     LOG( SIMPLE, "SELECTITEM: CSelectItemHandler::HandleCommand exiting" )
       
   300     }
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // CSelectItemHandler::UiLaunchFailed
       
   304 // (other items were commented in a header).
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 void CSelectItemHandler::UiLaunchFailed()
       
   308     {
       
   309     LOG( SIMPLE, "SELECTITEM: CSelectItemHandler::UiLaunchFailed calling" )
       
   310 
       
   311     iSelectItemRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   312     iSelectItemRsp.iInfoType = RSat::KMeProblem;
       
   313     iSelectItemRsp.iAdditionalInfo.SetLength( 1 );
       
   314     iSelectItemRsp.iAdditionalInfo[0] = RSat::KNoSpecificMeProblem;
       
   315     iSelectItemRsp.SetPCmdNumber( iSelectItemData.PCmdNumber() );
       
   316     CSatCommandHandler::TerminalRsp( RSat::ESelectItem, iSelectItemRspPckg );
       
   317 
       
   318     LOG( SIMPLE, "SELECTITEM: CSelectItemHandler::UiLaunchFailed exiting" )
       
   319     }