phoneuis/Ussd/src/UssdNaviPane.cpp
branchRCL_3
changeset 25 5266b1f337bd
equal deleted inserted replaced
24:41a7f70b3818 25:5266b1f337bd
       
     1 /*
       
     2 * Copyright (c) 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:  Declares navi pane control for application.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <gsmuset.h>                 // CCnvCharacterSetConverter
       
    21 #include    <aknenv.h>                  // CAknEnv
       
    22 #include    <aknnavide.h>               // CAknNavigationDecorator
       
    23 #include    <aknEditStateIndicator.h>
       
    24 #include    <AknIndicatorContainer.h>
       
    25 #include    <aknnavilabel.h>
       
    26 #include    "UssdComms.h" 
       
    27 #include    "UssdAppUi.h"
       
    28 #include    "UssdNaviPane.h"
       
    29 #include    "UssdLogger.h"
       
    30  
       
    31 #include <AknUtils.h>
       
    32 // CONSTANTS
       
    33 
       
    34 // Unicode char codes for GSM 03.38 7 bit ext table characters 
       
    35 static const TUint KUssdEdEuroSymbol = 0x20ac;
       
    36 static const TUint KUssdEdLeftSquareBracket = 0x5b;
       
    37 static const TUint KUssdEdReverseSolidus = 0x5c;
       
    38 static const TUint KUssdEdRightSquareBracket = 0x5d;
       
    39 static const TUint KUssdEdCircumflexAccent = 0x5e;
       
    40 static const TUint KUssdEdLeftCurlyBracket = 0x7b;
       
    41 static const TUint KUssdEdVerticalLine = 0x7c;
       
    42 static const TUint KUssdEdRightCurlyBracket = 0x7d;
       
    43 static const TUint KUssdEdTilde = 0x7e;
       
    44 static const TUint KUssdDownwardsArrowLeft = 0x21B2;
       
    45 static const TUint KUssdDownwardsArrowRight = 0x21B3;
       
    46 static const TUint KUssdCharDwithLine = 0xD0;
       
    47 static const TUint KUssdCharBigRhoo = 0xDE; 
       
    48 static const TUint KUssdCharSmallDelta = 0xF0;
       
    49 static const TUint KUssdCharSmallFii = 0xFE;
       
    50 // ============================ MEMBER FUNCTIONS ===============================
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CUssdNaviPane::CUssdNaviPane
       
    54 // C++ constructor can NOT contain any code, that
       
    55 // might leave.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CUssdNaviPane::CUssdNaviPane( CUssdAppUi& aAppUi ): iAppUi( aAppUi )
       
    59     {
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CUssdNaviPane::NewL
       
    64 //
       
    65 // Symbian 2nd phase constructor can leave.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CUssdNaviPane* CUssdNaviPane::NewL( CUssdAppUi& aAppUi )
       
    69     {
       
    70     CUssdNaviPane* self = new ( ELeave ) CUssdNaviPane( aAppUi );
       
    71     CleanupStack::PushL( self );
       
    72     self->ConstructL();
       
    73     CleanupStack::Pop( self );
       
    74     return self;
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CUssdNaviPane::ConstructL
       
    79 //
       
    80 // Symbian 2nd phase constructor can leave.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CUssdNaviPane::ConstructL()
       
    84     {
       
    85     _LOGSTRING( "CUssdNaviPane::ConstructL =>" )
       
    86     
       
    87     CreateExtraNaviLabelL();
       
    88 
       
    89     User::LeaveIfError( iPeninputServer.Connect() );
       
    90     iCharacterSetConverter = CCnvCharacterSetConverter::NewL();
       
    91 
       
    92     iCharacterSetConverter->PrepareToConvertToOrFromL(
       
    93         KCharacterSetIdentifierSms7Bit,
       
    94         iCoeEnv->FsSession() );
       
    95 
       
    96     iCharacterSetConverter->SetDowngradeForExoticLineTerminatingCharacters(
       
    97         CCnvCharacterSetConverter::EDowngradeExoticLineTerminatingCharactersToJustLineFeed );
       
    98     _LOGSTRING( "CUssdNaviPane::ConstructL <=" )
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CUssdNaviPane::~CUssdNaviPane
       
   103 // 
       
   104 // Destructor
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 CUssdNaviPane::~CUssdNaviPane()
       
   108     {
       
   109     _LOGSTRING( "CUssdNaviPane::~CUssdNaviPane =>" )
       
   110     iPeninputServer.Close();
       
   111     
       
   112     if ( iNaviPane && iNaviDecorator )
       
   113         {
       
   114         iNaviPane->Pop( iNaviDecorator );
       
   115         delete iNaviDecorator;
       
   116         iNaviDecorator = NULL;
       
   117         iNaviPane = NULL;
       
   118         }
       
   119     
       
   120     delete iCharacterSetConverter;
       
   121     iCharacterSetConverter = NULL;
       
   122 
       
   123     iNaviLabel = NULL;
       
   124     _LOGSTRING( "CUssdNaviPane::~CUssdNaviPane <=" )
       
   125     }
       
   126   
       
   127 // ----------------------------------------------------
       
   128 // CUssdNaviPane::CreateExtraNaviLabelL
       
   129 // Creates an extra navi label.
       
   130 // (other items were commented in a header).
       
   131 // ----------------------------------------------------
       
   132 //
       
   133 void CUssdNaviPane::CreateExtraNaviLabelL()
       
   134     {
       
   135       
       
   136     CEikStatusPane* sp = iAppUi.StatusPane();
       
   137     iNaviPane = static_cast<CAknNavigationControlContainer*>( 
       
   138         sp->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );     
       
   139     
       
   140     iNaviDecorator = iNaviPane->CreateNavigationLabelL( 
       
   141         KNullDesC );
       
   142     iNaviLabel = static_cast<CAknNaviLabel*>( 
       
   143         iNaviDecorator->DecoratedControl() );
       
   144     iNaviPane->PushL( *iNaviDecorator ) ;
       
   145     
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------
       
   149 // CUssdNaviPane::UpdateMsgLengthL
       
   150 // Update the message length information to navipane
       
   151 // (other items were commented in a header).
       
   152 // ---------------------------------------------------------
       
   153 //
       
   154 TInt CUssdNaviPane::UpdateMsgLengthL( const TDesC& aInputString, 
       
   155                                              CCoeControl* aControl )
       
   156     {
       
   157     _LOGSTRING2( "CUssdNaviPane::UpdateMsgLengthL =>, aInputString=%S",
       
   158     &aInputString )
       
   159     TInt maxLen(0);
       
   160     const TInt txtLen = aInputString.Length();
       
   161  
       
   162     HBufC* digitBuffer = HBufC::NewLC( EAknMaxIntegerDigits ); 
       
   163     TPtr bufPtr( digitBuffer->Des() );
       
   164  
       
   165     if ( NeedsToBeSentAsUnicodeL( aInputString ) )
       
   166         {
       
   167         bufPtr.AppendNum( KUssdEditorMaxLenght/2 - txtLen );
       
   168         maxLen=KUssdEditorMaxLenght/2;
       
   169         }
       
   170     else
       
   171         {
       
   172         TInt extendedCount = CountExtendedTableChars( aInputString );
       
   173         TInt totalLen = KUssdEditorMaxLenght - ( txtLen + extendedCount );
       
   174         if ( totalLen < 0 ) // last was alphabet extended when one left
       
   175             {
       
   176             GenerateBackSpaceKeyL( aControl );
       
   177             extendedCount--;
       
   178             totalLen = totalLen+2;
       
   179             }
       
   180         bufPtr.AppendNum( totalLen );
       
   181         maxLen=KUssdEditorMaxLenght-extendedCount;
       
   182         }
       
   183     
       
   184    AknTextUtils::LanguageSpecificNumberConversion( bufPtr );
       
   185 
       
   186     // Giving msg length string to indicator container
       
   187     MAknEditingStateIndicator* stateIndicator = 
       
   188         iAvkonEnv->EditingStateIndicator();
       
   189     if ( stateIndicator )
       
   190         {
       
   191         CAknIndicatorContainer* iIndicatorContainerSMS = 
       
   192             stateIndicator->IndicatorContainer();
       
   193         if ( iIndicatorContainerSMS )
       
   194             {
       
   195             iIndicatorContainerSMS->SetIndicatorState( 
       
   196                 TUid::Uid( EAknNaviPaneEditorIndicatorMessageLength ), 
       
   197                 EAknIndicatorStateOn );
       
   198             iIndicatorContainerSMS->SetIndicatorValueL(
       
   199                 TUid::Uid( EAknNaviPaneEditorIndicatorMessageLength ), 
       
   200                 *digitBuffer );
       
   201             }
       
   202         }
       
   203     
       
   204     iNaviLabel->SetTextL( *digitBuffer );
       
   205     _LOGSTRING(
       
   206     "CUssdNaviPane::UpdateMsgLengthL iPeninputServer.UpdateAppInfo" )
       
   207     iPeninputServer.UpdateAppInfo( *digitBuffer, EAppIndicatorMsg );
       
   208     CleanupStack::PopAndDestroy( digitBuffer );
       
   209     _LOGSTRING2( "CUssdNaviPane::UpdateMsgLengthL <=, maxLen=%d",
       
   210     maxLen )
       
   211     
       
   212     return maxLen;
       
   213     }
       
   214  
       
   215 
       
   216 // ---------------------------------------------------------
       
   217 // CUssdNaviPane::NeedsToBeSentAsUnicodeL
       
   218 // Checks if there are any unicode characters in the message
       
   219 // (other items were commented in a header).
       
   220 // ---------------------------------------------------------
       
   221 //
       
   222 TBool CUssdNaviPane::NeedsToBeSentAsUnicodeL( const TDesC& aInputString ) const
       
   223     {
       
   224     _LOGSTRING2(
       
   225     "CUssdNaviPane::NeedsToBeSentAsUnicodeL =>, aInputString=%S",
       
   226     &aInputString )
       
   227     
       
   228     TBool needsToBeSentAsUnicode = EFalse;
       
   229       
       
   230     for ( TPtrC remainderOfInputString( aInputString ); 
       
   231           remainderOfInputString.Length()>0 ; )
       
   232         {
       
   233         TBuf8<KUssdEditorMaxLenght> notUsedForeignParam;
       
   234         TInt numberOfUnconvertibleCharacters = 0;
       
   235         const TInt returnValue = 
       
   236             iCharacterSetConverter->ConvertFromUnicode( 
       
   237                 notUsedForeignParam,
       
   238                 remainderOfInputString, 
       
   239                 numberOfUnconvertibleCharacters );
       
   240         if ( ( returnValue < 0 ) || 
       
   241              ( numberOfUnconvertibleCharacters > 0 )) 
       
   242             // if there was an error in trying to do the conversion, or if 
       
   243             // there was an unconvertible character (e.g. a Chinese character)
       
   244             {
       
   245             TUint uChar;
       
   246             for ( TInt i = 0;i < remainderOfInputString.Length();i++ )
       
   247                 {
       
   248                 uChar = TUint( remainderOfInputString[ i ] );
       
   249                 if ( uChar ==  KUssdDownwardsArrowLeft || 
       
   250                      uChar == KUssdDownwardsArrowRight ||
       
   251                      uChar == KUssdCharDwithLine ||
       
   252                      uChar == KUssdCharBigRhoo ||
       
   253                      uChar == KUssdCharSmallDelta ||
       
   254                      uChar == KUssdCharSmallFii )
       
   255                     {
       
   256                     numberOfUnconvertibleCharacters--;
       
   257                     }  
       
   258                 }
       
   259                    
       
   260             if ( returnValue < 0 || numberOfUnconvertibleCharacters > 0  ) 
       
   261                 {
       
   262                 // if there was an error in trying to do the conversion, or if there was an
       
   263                 // unconvertible character (e.g. a Chinese character)
       
   264                 needsToBeSentAsUnicode = ETrue;
       
   265                 break;
       
   266                 }      
       
   267             }
       
   268         
       
   269         remainderOfInputString.Set( 
       
   270             remainderOfInputString.Right( returnValue ) );
       
   271         }
       
   272     _LOGSTRING2(
       
   273     "CUssdNaviPane::NeedsToBeSentAsUnicodeL <=, needsToBeSentAsUnicode=%d",
       
   274     needsToBeSentAsUnicode )
       
   275     return needsToBeSentAsUnicode;
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------
       
   279 // CUssdNaviPane::CountExtendedTableChars
       
   280 // Counts if there are 7bit extended table characters in message
       
   281 // (other items were commented in a header).
       
   282 // ---------------------------------------------------------
       
   283 //
       
   284 TInt CUssdNaviPane::CountExtendedTableChars( const TDesC& aInputString ) const
       
   285     {
       
   286     const TInt total = aInputString.Length();
       
   287     TInt extChars = 0;
       
   288     
       
   289     TUint uChar;
       
   290     for ( TInt i=0; i < total; i++ )
       
   291         {
       
   292         uChar = TUint(aInputString[i]);
       
   293         if (( uChar == KUssdEdLeftSquareBracket) || 
       
   294             ( uChar == KUssdEdReverseSolidus ) || 
       
   295             ( uChar == KUssdEdRightSquareBracket ) || 
       
   296             ( uChar == KUssdEdCircumflexAccent ) || 
       
   297             ( uChar == KUssdEdLeftCurlyBracket ) || 
       
   298             ( uChar == KUssdEdVerticalLine ) || 
       
   299             ( uChar == KUssdEdRightCurlyBracket ) || 
       
   300             ( uChar == KUssdEdTilde ) || 
       
   301             ( uChar == KUssdEdEuroSymbol )) 
       
   302             {
       
   303             extChars = extChars + 1;
       
   304             }
       
   305         }
       
   306     return extChars;
       
   307     }
       
   308 
       
   309 // ---------------------------------------------------------
       
   310 // CUssdNaviPane::GenerateBackSpaceKeyL
       
   311 // Generates a backspace key press event.
       
   312 // (other items were commented in a header).
       
   313 // ---------------------------------------------------------
       
   314 //
       
   315 void CUssdNaviPane::GenerateBackSpaceKeyL( CCoeControl* aControl )
       
   316     {
       
   317     TKeyEvent keyEvent;
       
   318     keyEvent.iCode = EKeyBackspace;
       
   319     keyEvent.iScanCode = EStdKeyBackspace;
       
   320     keyEvent.iRepeats = 1;
       
   321     keyEvent.iModifiers = 0;
       
   322     TEventCode type = EEventKey;
       
   323 
       
   324     if ( aControl )
       
   325         {
       
   326         aControl->OfferKeyEventL( keyEvent, type );
       
   327         }
       
   328     }
       
   329 
       
   330 // End of File