phoneuis/Ussd/src/UssdAppUi.cpp
branchRCL_3
changeset 62 5266b1f337bd
child 69 8baf28733c3d
equal deleted inserted replaced
61:41a7f70b3818 62:5266b1f337bd
       
     1 /*
       
     2 * Copyright (c) 2002-2010 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:  Application UI class
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <ussd.rsg>
       
    20 #include <avkon.rsg>
       
    21 #include <eikmenub.h>
       
    22 #include <eikedwin.h>
       
    23 #include <avkon.hrh>
       
    24 #include <bldvariant.hrh>
       
    25 #include <featmgr.h>
       
    26 #include <AknDef.h>
       
    27 #include <hlplch.h>   // For HlpLauncher
       
    28 
       
    29 #include "UssdAppUi.h"
       
    30 #include "UssdContainer.h"
       
    31 #include "UssdComms.h"
       
    32 #include "ussd.hrh"
       
    33 #include "UssdLogger.h"
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CUssdAppUi::ConstructL
       
    38 // Creates all members
       
    39 // -----------------------------------------------------------------------------
       
    40 void CUssdAppUi::ConstructL()
       
    41     {
       
    42     _LOGSTRING( "CUssdAppUi::ConstructL =>" )
       
    43     // Sets up TLS, must be done before FeatureManager is used in USSD.
       
    44     FeatureManager::InitializeLibL();
       
    45 
       
    46     BaseConstructL(
       
    47         EAknEnableSkin | EAknEnableMSK | EAknSingleClickCompatible
       
    48         );
       
    49 
       
    50     // Softkeys at start:
       
    51     // With HELP: Options-Exit (defined in the resource file, default)
       
    52     // Without HELP: <empty>-Exit
       
    53     if ( !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
    54         {
       
    55         // Feature not supported, set correct softkeys.
       
    56         Cba()->SetCommandSetL( R_AVKON_SOFTKEYS_EXIT );
       
    57         iCbaResource = R_AVKON_SOFTKEYS_EXIT;
       
    58         Cba()->DrawNow();
       
    59         }
       
    60 
       
    61     iComms = CUssdComms::NewL();
       
    62 
       
    63     iAppContainer = new( ELeave ) CUssdContainer( *this );
       
    64     iAppContainer->SetMopParent( this );
       
    65     iAppContainer->ConstructL( ClientRect() );
       
    66     AddToStackL( iAppContainer );
       
    67     iIsAddedToStack = ETrue;
       
    68     _LOGSTRING( "CUssdAppUi::ConstructL <=" )
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CUssdAppUi::~CUssdAppUi
       
    73 // Destructor
       
    74 // Frees reserved resources
       
    75 // -----------------------------------------------------------------------------
       
    76 CUssdAppUi::~CUssdAppUi()
       
    77     {
       
    78     _LOGSTRING( "CUssdAppUi::~CUssdAppUi =>" )
       
    79     if ( iIsAddedToStack )
       
    80         {
       
    81         RemoveFromStack( iAppContainer );
       
    82         }
       
    83 
       
    84     delete iAppContainer;
       
    85 
       
    86     delete iComms;
       
    87 
       
    88     // Frees the TLS! Must be done after FeatureManager is used.
       
    89     FeatureManager::UnInitializeLib();
       
    90     _LOGSTRING( "CUssdAppUi::~CUssdAppUi <=" )
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CUssdAppUi::HandleCommandL
       
    95 // Handle commands from the user.
       
    96 // -----------------------------------------------------------------------------
       
    97 void CUssdAppUi::HandleCommandL( TInt aCommand )
       
    98     {
       
    99     _LOGSTRING2( "CUssdAppUi::HandleCommandL =>, aCommand=%d", 
       
   100     aCommand )
       
   101     switch ( aCommand )
       
   102         {
       
   103         case EAknCmdExit:
       
   104         case EEikCmdExit:
       
   105         case EAknSoftkeyExit:
       
   106         case EAknSoftkeyBack:
       
   107             {
       
   108             iComms->InformExitReason( EPhCltUserExit );
       
   109             Exit();
       
   110             break;
       
   111             }
       
   112 
       
   113         case EUssdMenuItemSend:
       
   114         case EUssdSoftkeySend:
       
   115             {
       
   116             // Send string and exit the application
       
   117             HBufC* buffer = iAppContainer->Editor().GetTextInHBufL();
       
   118             __ASSERT_DEBUG(
       
   119                 buffer->Length() <= KUssdEditorMaxLenght ,
       
   120                 User::Invariant() );
       
   121 
       
   122             if  ( buffer->Length() &&
       
   123                   buffer->Length() <= KUssdEditorMaxLenght &&
       
   124                   KErrNone == iComms->SendString( buffer->Des() ) )
       
   125                 {
       
   126                 iComms->InformExitReason( EPhCltSendCompleted );
       
   127                 Exit();                
       
   128                 }         
       
   129 
       
   130             delete buffer;
       
   131             break;
       
   132             }
       
   133 
       
   134         case EAknCmdHelp:
       
   135             {
       
   136             if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   137                 {
       
   138                  // Feature supported, launch the help application.
       
   139                 HlpLauncher::LaunchHelpApplicationL(
       
   140                     iEikonEnv->WsSession(), AppHelpContextL() );
       
   141                 }
       
   142             break;
       
   143             }
       
   144 
       
   145         default:
       
   146             break;
       
   147         }
       
   148     _LOGSTRING( "CUssdAppUi::HandleCommandL <=" )
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CUssdAppUi::HandleResourceChangeL
       
   153 // -----------------------------------------------------------------------------
       
   154 void CUssdAppUi::HandleResourceChangeL( TInt aType )
       
   155     {
       
   156     CAknAppUi::HandleResourceChangeL( aType );
       
   157 
       
   158     if( aType == KEikDynamicLayoutVariantSwitch )
       
   159         {
       
   160         iAppContainer->SetRect( ClientRect() );
       
   161         }
       
   162     }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CUssdAppUi::HandleForegroundEventL
       
   166 // Handle foreground event.
       
   167 // -----------------------------------------------------------------------------
       
   168 void CUssdAppUi::HandleForegroundEventL( TBool aForeground )
       
   169     {
       
   170     _LOGSTRING2( "CUssdAppUi::HandleForegroundEventL =>, aForeground=%d",
       
   171     aForeground )
       
   172     if ( iComms )
       
   173         {
       
   174         if ( aForeground )
       
   175             {
       
   176             // If app comes to foreground, we must know is the
       
   177             // editor needs clearing.
       
   178             if ( iComms->InformAppForeground() ) // ret ETrue if needs clearing
       
   179                 {
       
   180                 if ( iAppContainer )
       
   181                     {
       
   182                     iAppContainer->Editor().SetCursorPosL( 0, EFalse );
       
   183                     iAppContainer->Editor().Text()->Reset();
       
   184                     iAppContainer->Editor().HandleTextChangedL();
       
   185 
       
   186                     if ( !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   187                         {
       
   188                         SetSoftkeySendVisibleL( EFalse );
       
   189                         }
       
   190 
       
   191                     }
       
   192                 }
       
   193             }
       
   194         else
       
   195             {
       
   196             iComms->InformAppBackground();
       
   197             }
       
   198         }
       
   199 
       
   200     // Refresh message character counter
       
   201     if( aForeground && iAppContainer )
       
   202         {
       
   203         iAppContainer->UpdateNavipaneMsgLengthL();
       
   204         }
       
   205     
       
   206     CAknAppUi::HandleForegroundEventL( aForeground );
       
   207     _LOGSTRING( "CUssdAppUi::HandleForegroundEventL <=" )
       
   208     }
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CUssdAppUi::DynInitMenuPaneL
       
   212 // Set's Send option visible.
       
   213 //
       
   214 // If HELP is defined, the Options menu item 'Send' is removed if
       
   215 // the editor is empty. If it is not defined, the left softkey is 'Send' or
       
   216 // <empty>.
       
   217 // -----------------------------------------------------------------------------
       
   218 void CUssdAppUi::DynInitMenuPaneL(
       
   219     TInt aResourceId,
       
   220     CEikMenuPane* aMenuPane )
       
   221     {
       
   222     if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   223         {
       
   224         if ( aResourceId == R_USSD_MENU )
       
   225             {
       
   226             if ( aMenuPane )
       
   227                 {
       
   228                 aMenuPane->SetItemDimmed(
       
   229                     EUssdMenuItemSend,
       
   230                     iAppContainer->Editor().TextLength() == 0 );
       
   231                 }
       
   232             // If aMenuPane == NULL, do nothing.
       
   233             }
       
   234 
       
   235         // If aResourceId != R_USSD_MENU, do nothing
       
   236         }
       
   237 
       
   238     // If help not defined, do nothing
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CUssdAppUi::SetSofkeySendVisibleL
       
   243 // Sets Send softkey (in)visible.
       
   244 // -----------------------------------------------------------------------------
       
   245 void CUssdAppUi::SetSoftkeySendVisibleL(
       
   246     TBool aVisible )
       
   247     {
       
   248     if ( !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   249         {
       
   250         // Help not defined
       
   251         TInt newResource;
       
   252 
       
   253         if ( aVisible )
       
   254             {
       
   255             if ( iCbaResource == R_USSD_SOFTKEYS_SEND_EXIT )
       
   256                 {
       
   257                 return; // Send is already visible
       
   258                 }
       
   259             newResource = R_USSD_SOFTKEYS_SEND_EXIT; // change it
       
   260             }
       
   261         else
       
   262             {
       
   263             if ( iCbaResource == R_AVKON_SOFTKEYS_EXIT )
       
   264                 {
       
   265                 return; // Send is already invisible
       
   266                 }
       
   267             newResource = R_AVKON_SOFTKEYS_EXIT; // change it.
       
   268             }
       
   269 
       
   270         // Update Softkeys
       
   271         Cba()->SetCommandSetL( newResource );
       
   272         iCbaResource = newResource;
       
   273         Cba()->DrawNow();
       
   274         }
       
   275 
       
   276     // If help defined, do nothing.
       
   277     }
       
   278 
       
   279 // End of File