wvuing/IMPSConnectionUI/UISrc/CCnUiTermsOfUseDlg.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2006 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:  UI dialog for showing the Terms of use of a certain server
       
    15 *
       
    16 */
       
    17 
       
    18 #include    "ccnuitermsofusedlg.h"
       
    19 
       
    20 #include    "CnUiCommon.hrh"
       
    21 
       
    22 #include    <txtrich.h>
       
    23 #include    <aknenv.h>
       
    24 #include    <aknsettingcache.h>
       
    25 #include    <bldvariant.hrh>
       
    26 #include    <aknquerydialog.h>
       
    27 #include    <stringloader.h>
       
    28 #include    <eikmenup.h>
       
    29 #include    <avkon.rsg>
       
    30 #include    <avkon.hrh>
       
    31 #include    <eikappui.h>
       
    32 #include    <eikenv.h>
       
    33 #include    <aknutils.h>
       
    34 #include    <aknsutils.h>
       
    35 #include    <hlplch.h>
       
    36 #include    <featmgr.h>
       
    37 #include    <aknsbasicbackgroundcontrolcontext.h>
       
    38 #include    <akneditstateindicator.h>
       
    39 #include    <eikrted.h> // CEikRichTextEditor
       
    40 #include    <barsread.h>
       
    41 #include    <applayout.cdl.h> //cdl
       
    42 #include    <aknlayoutscalable_apps.cdl.h>
       
    43 #include    <impsconnectionuing.rsg>
       
    44 // item finder (Automatic highlight)
       
    45 #include    <finditemmenu.rsg>
       
    46 #include    <finditemmenu.h>
       
    47 #include    <finditem.hrh>
       
    48 #include    <finditemdialog.h>
       
    49 // title pane handling
       
    50 #include    <akntitle.h>
       
    51 #include    <aknlists.h>
       
    52 #include    <aknnavi.h>
       
    53 #include    <utf.h>
       
    54 #include    <txtetext.h>
       
    55 
       
    56 #include    "impscommonuibuilddefinitions.h"
       
    57 
       
    58 const TInt KTextMargin = 100;  // normal text margin in twips
       
    59 const TInt KSpaceBefore = 10;  // space before each paragraph (twips)
       
    60 const TInt KPixelsBetweenLines = 5; // pixels between text lines
       
    61 const TInt KIMAcceptIndex = 1; // which item "Accept" is in the resource file
       
    62 
       
    63 _LIT( KLineBreak, "\n" );
       
    64 
       
    65 // ======== MEMBER FUNCTIONS ========
       
    66 
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // RunDialogLD
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 TInt CCnUiTermsOfUseDlg::RunDialogLD( TInt aResourceId )
       
    73     {
       
    74     TInt retVal;
       
    75     iRetVal = &retVal;
       
    76 
       
    77     ExecuteLD( aResourceId );
       
    78 
       
    79     return retVal;
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // NewL()
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 CCnUiTermsOfUseDlg* CCnUiTermsOfUseDlg::NewL( const TDesC& aToUFileName )
       
    87     {
       
    88     CCnUiTermsOfUseDlg* self = CCnUiTermsOfUseDlg::NewLC( aToUFileName );
       
    89     CleanupStack::Pop( self );
       
    90     return self;
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // NewLC()
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 CCnUiTermsOfUseDlg* CCnUiTermsOfUseDlg::NewLC( const TDesC& aToUFileName )
       
    98     {
       
    99     CCnUiTermsOfUseDlg* self = new( ELeave ) CCnUiTermsOfUseDlg;
       
   100     CleanupStack::PushL( self );
       
   101     self->ConstructL( aToUFileName );
       
   102     return self;
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------
       
   106 // CCnUiTermsOfUseDlg::ConstructL()
       
   107 // ---------------------------------------------------------
       
   108 //
       
   109 void CCnUiTermsOfUseDlg::ConstructL( const TDesC& aToUFileName )
       
   110     {
       
   111     CAknDialog::ConstructL( R_CNUI_TERMS_OF_USE_MENUBAR );
       
   112 
       
   113     // This dlg uses only context menu
       
   114     iMenuBar->SetMenuType( CEikMenuBar::EMenuContext );
       
   115 
       
   116     iBgContext = CAknsBasicBackgroundControlContext::NewL(
       
   117                      KAknsIIDQsnBgAreaMainMessage, Rect(), ETrue );
       
   118 
       
   119     iFindItemMenu = CFindItemMenu::NewL( EIMPSCommonUIFindMenuPlaceHolder );
       
   120     iFindItemMenu->AttachItemFinderMenuL( R_CNUI_TERMS_OF_USE_MENUBAR );
       
   121     iFindItemMenu->HandleItemFinderCommandL( EFindItemCmdEnableAutoFind );
       
   122 
       
   123     iItemFinder = CItemFinder::NewL();
       
   124     iItemFinder->AddObserver( *this );
       
   125 
       
   126     iToUFileName = aToUFileName.AllocL();
       
   127 
       
   128     SetNewTitleTextL();
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // Destructor
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 CCnUiTermsOfUseDlg::~CCnUiTermsOfUseDlg()
       
   136     {
       
   137     TRAP_IGNORE( RestoreTitlePaneTextL() );
       
   138 
       
   139     AknsUtils::DeregisterControlPosition( this );
       
   140 
       
   141     delete iBgContext;
       
   142     delete iItemFinder;
       
   143     delete iFindItemMenu;
       
   144     delete iOldTitleText;
       
   145     delete iToUFileName;
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 //  C++ constructor
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 CCnUiTermsOfUseDlg::CCnUiTermsOfUseDlg()
       
   153     {
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------
       
   157 // CCnUiTermsOfUseDlg::ProcessCommandL( TInt aCommand )
       
   158 // ---------------------------------------------------------
       
   159 //
       
   160 void CCnUiTermsOfUseDlg::ProcessCommandL( TInt aCommand )
       
   161     {
       
   162     if ( iFindItemMenu && iFindItemMenu->CommandIsValidL( aCommand ) )
       
   163         {
       
   164         iFindItemMenu->HandleItemFinderCommandL( aCommand );
       
   165         return;
       
   166         }
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CCnUiTermsOfUseDlg::DynInitMenuPaneL
       
   171 // (other items were commented in a header).
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 void CCnUiTermsOfUseDlg::DynInitMenuPaneL( TInt aResourceId,
       
   175                                            CEikMenuPane* aMenuPane )
       
   176     {
       
   177     switch ( aResourceId )
       
   178         {
       
   179         case R_CNUI_TERMS_OF_USE_MENU:
       
   180             {
       
   181             iFindItemMenu->AddItemFindMenuL( iItemFinder, aMenuPane,
       
   182                                              EIMPSCommonUIFindMenuPlaceHolder,
       
   183                                              KNullDesC ); // we can ignore the sender here
       
   184 
       
   185             // remove placeholder
       
   186             aMenuPane->SetItemDimmed( EIMPSCommonUIFindMenuPlaceHolder, ETrue );
       
   187             aMenuPane->SetItemDimmed( EFindItemCmdDisableAutoFind, ETrue );
       
   188             break;
       
   189             }
       
   190         default:
       
   191             {
       
   192             // update find menu
       
   193             iFindItemMenu->UpdateItemFinderMenuL( aResourceId, aMenuPane );
       
   194             break;
       
   195             }
       
   196         }
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------
       
   200 // CCnUiTermsOfUseDlg::HandleParsingComplete()
       
   201 // (other items were commented in a header).
       
   202 // ---------------------------------------------------------
       
   203 //
       
   204 void CCnUiTermsOfUseDlg::HandleParsingComplete()
       
   205     {
       
   206     TRAPD( err, UpdateCbaL() );
       
   207     if ( err )
       
   208         {
       
   209         CActiveScheduler::Current()->Error( err );
       
   210         }
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------
       
   214 // CCnUiTermsOfUseDlg::PreLayoutDynInitL()
       
   215 // (other items were commented in a header).
       
   216 // ---------------------------------------------------------
       
   217 //
       
   218 void CCnUiTermsOfUseDlg::PreLayoutDynInitL()
       
   219     {
       
   220     CAknDialog::PreLayoutDynInitL();
       
   221     AknsUtils::RegisterControlPosition( this );
       
   222 
       
   223     iEditor = static_cast<CEikRichTextEditor*>( Control( ETOURichEditorId ) );
       
   224 
       
   225     iParaFormatLayer = CParaFormatLayer::NewL();
       
   226     iEditor->SetParaFormatLayer( iParaFormatLayer );    // takes the ownership
       
   227 
       
   228     iCharFormatLayer = CCharFormatLayer::NewL();
       
   229     iEditor->SetCharFormatLayer( iCharFormatLayer );    // takes the ownership
       
   230 
       
   231     // Update text color from skin
       
   232     UpdateTextColorL();
       
   233 
       
   234     // Get ToU message
       
   235     HBufC* touText = ReadToUMessageLC();
       
   236     iEditor->SetTextL( touText );
       
   237     CleanupStack::PopAndDestroy( touText );
       
   238 
       
   239     iEditor->CreateScrollBarFrameL();
       
   240     // Only vertical scrollbar is needed
       
   241     iEditor->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   242         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   243     }
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // CCnUiTermsOfUseDlg::PostLayoutDynInitL
       
   247 // (other items were commented in a header).
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 void CCnUiTermsOfUseDlg::PostLayoutDynInitL()
       
   251     {
       
   252     CAknDialog::PostLayoutDynInitL();
       
   253 
       
   254     // Insert paragraph delimiter to make
       
   255     // iItemFinder scroll the view all the way down
       
   256     TChar lb( CEditableText::EParagraphDelimiter );
       
   257     iEditor->Text()->InsertL( iEditor->TextLength(), lb );
       
   258 
       
   259     iItemFinder->SetEditor( &iEditor );
       
   260 
       
   261     if ( iBgContext )
       
   262         {
       
   263         iBgContext->SetRect( Rect() );
       
   264         iBgContext->SetParentPos( PositionRelativeToScreen() );
       
   265         }
       
   266     }
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // CCnUiTermsOfUseDlg::SetSizeAndPosition
       
   270 // (other items were commented in a header).
       
   271 // -----------------------------------------------------------------------------
       
   272 //
       
   273 void CCnUiTermsOfUseDlg::SetSizeAndPosition( const TSize& /*aSize*/ )
       
   274     {
       
   275     // dialog fills the mainpane
       
   276     TRect mainPane;
       
   277     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPane );
       
   278     SetRect( mainPane );
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------
       
   282 // CCnUiTermsOfUseDlg::OkToExitL( TInt aButtonId )
       
   283 // (other items were commented in a header).
       
   284 // ---------------------------------------------------------
       
   285 //
       
   286 TBool CCnUiTermsOfUseDlg::OkToExitL( TInt aButtonId )
       
   287     {
       
   288     switch ( aButtonId )
       
   289         {
       
   290         case EAknSoftkeyCancel:
       
   291             {
       
   292             if ( AskCancelConfirmationL() )
       
   293                 {
       
   294                 // user cancelled
       
   295                 *iRetVal = EAknSoftkeyCancel;
       
   296                 return ETrue;
       
   297                 }
       
   298             return EFalse;
       
   299             }
       
   300         case EIMPSCommonUITOUContinue:
       
   301             {
       
   302             // Try to scroll down
       
   303             if ( iItemFinder->NextItemOrScrollL( CItemFinder::ENextDown ) )
       
   304                 {
       
   305                 // Not yet at bottom => return
       
   306                 UpdateCbaL();
       
   307                 return EFalse;
       
   308                 }
       
   309 
       
   310             TInt retVal = AcceptTermsL();
       
   311             switch ( retVal )
       
   312                 {
       
   313                 case KIMAcceptIndex:
       
   314                     {
       
   315                     // user accepted the terms
       
   316                     *iRetVal = EAknSoftkeyOk;
       
   317                     return ETrue;
       
   318                     }
       
   319 
       
   320                 case EAknSoftkeyCancel:
       
   321                     {
       
   322                     return EFalse;
       
   323                     }
       
   324                 default:
       
   325                     {
       
   326                     // user did not accept the query
       
   327                     *iRetVal = EAknSoftkeyCancel;
       
   328                     return ETrue;
       
   329                     }
       
   330                 }
       
   331             }
       
   332         case EAknSoftkeyContextOptions: // MSK command
       
   333             {
       
   334             DisplayMenuL();
       
   335             return EFalse;
       
   336             }
       
   337         case EAknSoftkeyEmpty:
       
   338             {
       
   339             return EFalse;
       
   340             }
       
   341         default:
       
   342             {
       
   343             return ETrue;
       
   344             }
       
   345         }
       
   346     }
       
   347 
       
   348 // -----------------------------------------------------------------------------
       
   349 // CCnUiTermsOfUseDlg::OfferKeyEventL
       
   350 // (other items were commented in a header).
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 TKeyResponse CCnUiTermsOfUseDlg::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   354                                                  TEventCode aType )
       
   355     {
       
   356     if ( aType != EEventKey )
       
   357         {
       
   358         return EKeyWasNotConsumed;
       
   359         }
       
   360 
       
   361     switch ( aKeyEvent.iCode )
       
   362         {
       
   363         case EKeyEnter: // flowthrough
       
   364         case EKeyOK:
       
   365             {
       
   366             CItemFinder::CFindItemExt& curItem = iItemFinder->CurrentItemExt();
       
   367             if ( curItem.iItemType != CItemFinder::ENoneSelected )
       
   368                 {
       
   369                 DisplayMenuL();
       
   370                 }
       
   371             return EKeyWasConsumed;
       
   372             }
       
   373         case EKeyBackspace:
       
   374             {
       
   375             return EKeyWasConsumed;
       
   376             }
       
   377 
       
   378         case EKeyUpArrow:
       
   379             {
       
   380             TKeyResponse res =
       
   381                 iItemFinder->NextItemOrScrollL( CItemFinder::ENextUp ) ?
       
   382                 EKeyWasConsumed : EKeyWasNotConsumed;
       
   383             if ( res == EKeyWasConsumed )
       
   384                 {
       
   385                 UpdateCbaL();
       
   386                 }
       
   387             return res;
       
   388             }
       
   389 
       
   390         case EKeyDownArrow:
       
   391             {
       
   392             TKeyResponse res =
       
   393                 iItemFinder->NextItemOrScrollL( CItemFinder::ENextDown ) ?
       
   394                 EKeyWasConsumed : EKeyWasNotConsumed;
       
   395             if ( res == EKeyWasConsumed )
       
   396                 {
       
   397                 UpdateCbaL();
       
   398                 }
       
   399             return res;
       
   400             }
       
   401 
       
   402         case EKeyRightArrow:
       
   403             {
       
   404             return EKeyWasConsumed;
       
   405             }
       
   406 
       
   407         case EKeyEscape: // handle dialog shutdown.
       
   408             {
       
   409             TryExitL( EAknSoftkeyExit );
       
   410             return EKeyWasConsumed;
       
   411             }
       
   412         default:
       
   413             {
       
   414             return EKeyWasNotConsumed;
       
   415             }
       
   416         }
       
   417     }
       
   418 
       
   419 // ---------------------------------------------------------
       
   420 // CCnUiTermsOfUseDlg::MopSupplyObject
       
   421 //
       
   422 // ---------------------------------------------------------
       
   423 //
       
   424 
       
   425 TTypeUid::Ptr CCnUiTermsOfUseDlg::MopSupplyObject( TTypeUid aId )
       
   426     {
       
   427     if ( aId.iUid == MAknsControlContext::ETypeId )
       
   428         {
       
   429         return MAknsControlContext::SupplyMopObject( aId, iBgContext );
       
   430         }
       
   431 
       
   432     return CCoeControl::MopSupplyObject( aId );
       
   433     }
       
   434 
       
   435 
       
   436 // ---------------------------------------------------------
       
   437 // CCnUiTermsOfUseDlg::SizeChanged
       
   438 //
       
   439 // ---------------------------------------------------------
       
   440 //
       
   441 void CCnUiTermsOfUseDlg::SizeChanged()
       
   442     {
       
   443     // base class method
       
   444     CAknDialog::SizeChanged();
       
   445 
       
   446     if ( iBgContext )
       
   447         {
       
   448         iBgContext->SetRect( Rect() );
       
   449         iBgContext->SetParentPos( PositionRelativeToScreen() );
       
   450         }
       
   451 
       
   452     if ( iEditor )
       
   453         {
       
   454         iEditor->SetRect( Rect() );
       
   455         }
       
   456 
       
   457     // Update the font to correct size
       
   458     if ( iParaFormatLayer && iCharFormatLayer )
       
   459         {
       
   460         // Correct font
       
   461         const CFont* font = AknLayoutUtils::FontFromId( EAknLogicalFontSecondaryFont );
       
   462 
       
   463         // format richtext
       
   464         TInt lineSpacing( font->HeightInPixels() + KPixelsBetweenLines );
       
   465         CParaFormat paraFormat;
       
   466         TParaFormatMask paraFormatMask;
       
   467         paraFormat.iLineSpacingControl =
       
   468             CParaFormat::ELineSpacingExactlyInPixels;
       
   469         paraFormatMask.SetAttrib( EAttLineSpacingControl );
       
   470         paraFormat.iLineSpacingInTwips = lineSpacing;
       
   471         paraFormatMask.SetAttrib( EAttLineSpacing );
       
   472         paraFormat.iLanguage =
       
   473             CAknEnv::Static()->SettingCache().InputLanguage();
       
   474         paraFormatMask.SetAttrib( EAttParaLanguage );
       
   475         paraFormat.iLeftMarginInTwips = KTextMargin;
       
   476         paraFormatMask.SetAttrib( EAttLeftMargin );
       
   477         paraFormat.iSpaceBeforeInTwips = KSpaceBefore;
       
   478         paraFormatMask.SetAttrib( EAttSpaceBefore );
       
   479 
       
   480         TCharFormat charFormat;
       
   481         TCharFormatMask charFormatMask;
       
   482         charFormat.iFontSpec = font->FontSpecInTwips();
       
   483         charFormatMask.SetAttrib( EAttFontTypeface );
       
   484         charFormatMask.SetAttrib( EAttFontHeight );
       
   485 
       
   486         //can't leave here
       
   487         TRAPD( err, iParaFormatLayer->SetL( &paraFormat, paraFormatMask );
       
   488                iCharFormatLayer->SetL( charFormat, charFormatMask );
       
   489                iEditor->HandleTextChangedL(); );
       
   490         if ( err != KErrNone )
       
   491             {
       
   492             CActiveScheduler::Current()->Error( err );
       
   493             }
       
   494         }
       
   495     }
       
   496 
       
   497 // ---------------------------------------------------------
       
   498 // CCnUiTermsOfUseDlg::AskCancelConfirmationL
       
   499 //
       
   500 // ---------------------------------------------------------
       
   501 //
       
   502 TInt CCnUiTermsOfUseDlg::AskCancelConfirmationL()
       
   503     {
       
   504     HBufC* prompt = iCoeEnv->AllocReadResourceLC( R_QTN_CHAT_CANCEL_TERMSOFUSE );
       
   505     CAknQueryDialog* query = CAknQueryDialog::NewL();
       
   506     CleanupStack::PushL( query );
       
   507     query->SetPromptL( *prompt );
       
   508     CleanupStack::Pop( query ); //query
       
   509     TInt ret( query->ExecuteLD( R_GENERAL_QUERY ) );
       
   510     CleanupStack::PopAndDestroy( prompt ); //prompt
       
   511     return ret;
       
   512     }
       
   513 
       
   514 // ---------------------------------------------------------
       
   515 // CCnUiTermsOfUseDlg::AcceptTermsL
       
   516 //
       
   517 // ---------------------------------------------------------
       
   518 //
       
   519 TInt CCnUiTermsOfUseDlg::AcceptTermsL()
       
   520     {
       
   521     TInt selection = -1;
       
   522     // CodeScanner warning "neglected to put variable on cleanup stack (id: 35)"
       
   523     // Ignored, because PrepareLC is called after this one
       
   524     CAknListQueryDialog* listQuery =
       
   525         new ( ELeave ) CAknListQueryDialog( &selection ); // CSI: 35 # see above
       
   526     listQuery->PrepareLC( R_CNUI_ACCEPT_TERMS_OF_USE_LISTQUERY );
       
   527 
       
   528     // Set item texts
       
   529     CDesCArray* listTexts = NULL;
       
   530     listTexts = CCoeEnv::Static()->ReadDesC16ArrayResourceL(
       
   531                     R_CNUI_ACCEPT_TERMS_OF_USE_LISTQUERY_ARRAY );
       
   532     listQuery->SetItemTextArray( listTexts );
       
   533     listQuery->SetOwnershipType( ELbmOwnsItemArray );
       
   534 
       
   535     if ( listQuery->RunLD() == EAknSoftkeyCancel )
       
   536         {
       
   537         return EAknSoftkeyCancel;
       
   538         }
       
   539     else
       
   540         {
       
   541         return selection;
       
   542         }
       
   543     }
       
   544 
       
   545 // ---------------------------------------------------------
       
   546 // CCnUiTermsOfUseDlg::SetNewTitleText
       
   547 // (other items were commented in a header).
       
   548 // ---------------------------------------------------------
       
   549 //
       
   550 void CCnUiTermsOfUseDlg::SetNewTitleTextL()
       
   551     {
       
   552     CAknTitlePane* title = GetTitlePaneInstanceL();
       
   553 
       
   554     // Store old one
       
   555     HBufC* tmp = title->Text()->AllocL();
       
   556     delete iOldTitleText;
       
   557     iOldTitleText = tmp;
       
   558 
       
   559     // Clear the navi pane
       
   560     // Get pointer to status-pane
       
   561     CEikStatusPane* statusPane = CEikonEnv::Static()->AppUiFactory()->
       
   562                                  StatusPane();
       
   563     // Get pointer to navi-pane
       
   564     CAknNavigationControlContainer* naviPane =
       
   565         static_cast<CAknNavigationControlContainer*>(
       
   566             statusPane->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
   567     naviPane->PushDefaultL( ETrue );
       
   568 
       
   569     // Set the new text
       
   570     HBufC* tempTitle = iEikonEnv->AllocReadResourceLC( R_QTN_CHAT_TOU_TITLE );
       
   571     title->SetTextL( *tempTitle );
       
   572     CleanupStack::PopAndDestroy( tempTitle );
       
   573     }
       
   574 
       
   575 // ---------------------------------------------------------
       
   576 // CCnUiTermsOfUseDlg::GetTitlePaneInstanceL
       
   577 // Gets titlepane instance from CEikonEnv
       
   578 // (other items were commented in a header).
       
   579 // ---------------------------------------------------------
       
   580 //
       
   581 CAknTitlePane* CCnUiTermsOfUseDlg::GetTitlePaneInstanceL() const
       
   582     {
       
   583     CAknTitlePane* title = static_cast< CAknTitlePane* >
       
   584                            ( CEikonEnv::Static()->AppUiFactory()->StatusPane()->ControlL(
       
   585                                  TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   586     if ( !title )
       
   587         {
       
   588         User::Leave( KErrNotSupported );
       
   589         }
       
   590     return title;
       
   591     }
       
   592 
       
   593 // ---------------------------------------------------------
       
   594 // CCnUiTermsOfUseDlg::DoRestoreTitlePaneTextL() const
       
   595 // Does the actual restoring.
       
   596 // (other items were commented in a header).
       
   597 // ---------------------------------------------------------
       
   598 //
       
   599 void CCnUiTermsOfUseDlg::RestoreTitlePaneTextL() const
       
   600     {
       
   601     CAknTitlePane* title = GetTitlePaneInstanceL();
       
   602 
       
   603     if ( iOldTitleText )
       
   604         {
       
   605         title->SetTextL( *iOldTitleText );
       
   606         }
       
   607     else
       
   608         {
       
   609         title->SetTextToDefaultL();
       
   610         }
       
   611 
       
   612     // restore the navi pane
       
   613     // Get pointer to status-pane
       
   614     CEikStatusPane* statusPane = CEikonEnv::Static()->AppUiFactory()->
       
   615                                  StatusPane();
       
   616     // Get pointer to navi-pane
       
   617     CAknNavigationControlContainer* naviPane =
       
   618         static_cast<CAknNavigationControlContainer*>(
       
   619             statusPane->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
   620     naviPane->Pop();
       
   621     }
       
   622 
       
   623 // ---------------------------------------------------------
       
   624 // CCnUiTermsOfUseDlg::UpdateCbaL()
       
   625 // (other items were commented in a header).
       
   626 // ---------------------------------------------------------
       
   627 //
       
   628 void CCnUiTermsOfUseDlg::UpdateCbaL()
       
   629     {
       
   630     TInt cbaRes = R_CNUI_TERMS_OF_USE_DIALOG_CBA;
       
   631     CItemFinder::CFindItemExt& curItem = iItemFinder->CurrentItemExt();
       
   632 
       
   633     if ( curItem.iItemType != CItemFinder::ENoneSelected )
       
   634         {
       
   635         cbaRes = R_CNUI_SOFTKEYS_CONTINUE_CANCEL__CONTEXTOPTIONS;
       
   636         }
       
   637 
       
   638     CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
       
   639     cba->SetCommandSetL( cbaRes );
       
   640     cba->DrawNow();
       
   641     }
       
   642 
       
   643 // ---------------------------------------------------------
       
   644 // CCnUiTermsOfUseDlg::UpdateTextColorL()
       
   645 // (other items were commented in a header).
       
   646 // ---------------------------------------------------------
       
   647 //
       
   648 void CCnUiTermsOfUseDlg::UpdateTextColorL()
       
   649     {
       
   650     if ( !iEditor )
       
   651         {
       
   652         return;
       
   653         }
       
   654 
       
   655     // Get text color from skin
       
   656     TRgb textColor( KRgbBlack );
       
   657     AknsUtils::GetCachedColor( AknsUtils::SkinInstance(),
       
   658                                textColor,
       
   659                                KAknsIIDQsnTextColors,
       
   660                                EAknsCIQsnTextColorsCG6 );
       
   661     TCharFormat charFormat;
       
   662     TCharFormatMask charFormatMask;
       
   663     charFormat.iFontPresentation.iTextColor = textColor;
       
   664     charFormatMask.SetAttrib( EAttColor );
       
   665 
       
   666     // Apply format
       
   667     int length = iEditor->RichText()->DocumentLength();
       
   668     iEditor->RichText()->SetInsertCharFormatL( charFormat, charFormatMask, length );
       
   669     iEditor->RichText()->ApplyCharFormatL( charFormat, charFormatMask, 0, length );
       
   670     }
       
   671 
       
   672 // ---------------------------------------------------------
       
   673 // CCnUiTermsOfUseDlg::HandleResourceChange
       
   674 // (other items were commented in a header).
       
   675 // ---------------------------------------------------------
       
   676 //
       
   677 void CCnUiTermsOfUseDlg::HandleResourceChange( TInt aType )
       
   678     {
       
   679     if ( aType == KAknsMessageSkinChange )
       
   680         {
       
   681         // When skin changes, we need to update text color
       
   682         TRAP_IGNORE( UpdateTextColorL();
       
   683                      iEditor->HandleTextChangedL(); );
       
   684         }
       
   685     CAknDialog::HandleResourceChange( aType );
       
   686     }
       
   687 
       
   688 // ---------------------------------------------------------
       
   689 // CCnUiTermsOfUseDlg::ReadToUMessageLC
       
   690 // (other items were commented in a header).
       
   691 // ---------------------------------------------------------
       
   692 //
       
   693 HBufC* CCnUiTermsOfUseDlg::ReadToUMessageLC()
       
   694     {
       
   695     // Open file
       
   696     RFile handle;
       
   697     RFs& rfsSession = CCoeEnv::Static()->FsSession();
       
   698     User::LeaveIfError( handle.Open( rfsSession , *iToUFileName, EFileRead ) );
       
   699     CleanupClosePushL( handle );
       
   700 
       
   701     // Read tou message
       
   702     TInt size = -1;
       
   703     User::LeaveIfError( handle.Size( size ) );
       
   704     HBufC8* touText = HBufC8::NewLC( size );
       
   705     TPtr8 touMsg( touText->Des() );
       
   706     User::LeaveIfError( handle.Read( touMsg ) );
       
   707 
       
   708     // Convert result to HBufC*
       
   709     HBufC* temp = CnvUtfConverter::ConvertToUnicodeFromUtf8L( *touText );
       
   710     CleanupStack::PopAndDestroy( 2 ); // toutext, handle
       
   711     CleanupStack::PushL( temp );
       
   712 
       
   713     // Convert '\n' linebreaks to CEditableText::ELineBreak type line breaks
       
   714     TPtr ptr( temp->Des() );
       
   715     AknTextUtils::ReplaceCharacters( ptr, KLineBreak, CEditableText::ELineBreak );
       
   716 
       
   717     return temp;
       
   718     }
       
   719 
       
   720 // End of file