gssettingsuis/Gs/GSFramework/src/GSBaseView.cpp
changeset 0 8c5d936e5675
child 14 9941bcf99348
equal deleted inserted replaced
-1:000000000000 0:8c5d936e5675
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  Base view for all General Settings views.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <gsbaseview.h>
       
    21 #include    <gsbasecontainer.h>
       
    22 
       
    23 #include    <aknnavide.h>
       
    24 #include    <akntabgrp.h>
       
    25 #include    <akntitle.h>
       
    26 #include    <AknUtils.h>
       
    27 #include    <aknViewAppUi.h>
       
    28 #include    <barsread.h>
       
    29 #include    <bautils.h> // BaflUtils
       
    30 #include    <bldvariant.hrh>
       
    31 #include    <featmgr.h>
       
    32 
       
    33 
       
    34 //Disabling warning caused by KGSDoActivateError constant
       
    35 #pragma diag_suppress 177
       
    36 // CONSTANTS
       
    37 _LIT( KGSDoActivateError, "DoActivateL" );
       
    38 
       
    39 // ========================= MEMBER FUNCTIONS ================================
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CGSBaseView::CGSBaseView
       
    43 //
       
    44 // C++ constructor
       
    45 // ---------------------------------------------------------------------------
       
    46 EXPORT_C CGSBaseView::CGSBaseView()
       
    47     : iResourceLoader( *iCoeEnv )
       
    48     {
       
    49     iAppUi = AppUi();
       
    50     iElaf = ( AknLayoutUtils::Variant() == EEuropeanVariant );
       
    51     }
       
    52 
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CGSBaseView::~CGSBaseView
       
    56 //
       
    57 // Destructor
       
    58 // ---------------------------------------------------------------------------
       
    59 EXPORT_C CGSBaseView::~CGSBaseView()
       
    60     {
       
    61     iResourceLoader.Close();
       
    62     if (iContainer)
       
    63         {
       
    64         AppUi()->RemoveFromViewStack( *this, iContainer );
       
    65         delete iContainer;
       
    66         }
       
    67     if ( iNaviPaneContext )
       
    68         {
       
    69         delete iNaviPaneContext;
       
    70         }
       
    71     }
       
    72 
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CGSBaseView::Container
       
    76 //
       
    77 //
       
    78 // ---------------------------------------------------------------------------
       
    79 EXPORT_C CGSBaseContainer* CGSBaseView::Container()
       
    80     {
       
    81     return iContainer;
       
    82     }
       
    83 
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // CGSBaseView::SetCurrentItem
       
    87 //
       
    88 //
       
    89 // ---------------------------------------------------------------------------
       
    90 EXPORT_C void CGSBaseView::SetCurrentItem( TInt aIndex )
       
    91     {
       
    92     iCurrentItem = aIndex;
       
    93     }
       
    94 
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CGSBaseView::HandleListBoxEventL
       
    98 //
       
    99 //
       
   100 // ---------------------------------------------------------------------------
       
   101 
       
   102 EXPORT_C void CGSBaseView::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
   103                                                 TListBoxEvent aEventType )
       
   104     {
       
   105     switch ( aEventType )
       
   106         {
       
   107         case EEventEnterKeyPressed:
       
   108         case EEventItemSingleClicked:
       
   109             HandleListBoxSelectionL();
       
   110             break;
       
   111         default:
       
   112            break;
       
   113         }
       
   114     }
       
   115 
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // CGSBaseView::SetNaviPaneL
       
   119 //
       
   120 //
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 EXPORT_C void CGSBaseView::SetNaviPaneL()
       
   124     {
       
   125     CAknNavigationControlContainer* naviControlContainer = 
       
   126                                             NaviControlContainerL();
       
   127     if ( iNaviPaneContext )
       
   128         {
       
   129         naviControlContainer->PushL( *iNaviPaneContext );
       
   130         }
       
   131     else
       
   132         {
       
   133         naviControlContainer->PushDefaultL();
       
   134         }
       
   135     }
       
   136 
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CGSBaseView::CreateNaviPaneContextL
       
   140 //
       
   141 //
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 EXPORT_C void CGSBaseView::CreateNaviPaneContextL( TInt aResourceId )
       
   145     {
       
   146     TResourceReader reader;
       
   147     iCoeEnv->CreateResourceReaderLC( reader, aResourceId );
       
   148     CAknNavigationControlContainer* naviControlContainer = 
       
   149                                              NaviControlContainerL();
       
   150     iNaviPaneContext = naviControlContainer->CreateMessageLabelL( reader );
       
   151     CleanupStack::PopAndDestroy();  // reader
       
   152     }
       
   153 
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // CGSBaseView::NaviControlContainerL
       
   157 //
       
   158 //
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 CAknNavigationControlContainer* CGSBaseView::NaviControlContainerL()
       
   162     {
       
   163     CAknNavigationControlContainer* control = NULL;
       
   164     if( !iNaviControlContainer )
       
   165         {
       
   166         iNaviControlContainer =
       
   167             static_cast<CAknNavigationControlContainer*>(
       
   168                 AppUi()->StatusPane()->ControlL( TUid::Uid(
       
   169                     EEikStatusPaneUidNavi ) ) );
       
   170         }
       
   171     else
       
   172         {
       
   173         control = iNaviControlContainer;
       
   174         }
       
   175     
       
   176     return control;
       
   177     }
       
   178 
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // CGSBaseView::HandleClientRectChange
       
   182 //
       
   183 //
       
   184 // ---------------------------------------------------------------------------
       
   185 void CGSBaseView::HandleClientRectChange()
       
   186     {
       
   187     if ( iContainer && iContainer->iListBox )
       
   188         {
       
   189         iContainer->SetRect( ClientRect() );
       
   190         }
       
   191     }
       
   192 
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CGSBaseView::DoActivateL
       
   196 // Activates the view.
       
   197 //
       
   198 // ---------------------------------------------------------------------------
       
   199 EXPORT_C void CGSBaseView::DoActivateL( const TVwsViewId& aPrevViewId,
       
   200                                         TUid /*aCustomMessageId*/,
       
   201                                         const TDesC8& /*aCustomMessage*/ )
       
   202     {
       
   203     iPrevViewId = aPrevViewId;
       
   204 //    if( iContainer )
       
   205 //        {
       
   206 //        AppUi()->RemoveFromViewStack( *this, iContainer );
       
   207 //
       
   208 //        delete iContainer;
       
   209 //        iContainer = NULL;
       
   210 //        }
       
   211     if ( !iContainer )
       
   212     	{
       
   213     	CreateContainerL();
       
   214 		AppUi()->AddToViewStackL( *this, iContainer );
       
   215 		iContainer->iListBox->SetListBoxObserver( this ) ;
       
   216 		iContainer->iListBox->SetTopItemIndex( iTopItemIndex );
       
   217 		iContainer->SetSelectedItem( iCurrentItem );
       
   218     	}
       
   219     }
       
   220 
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CGSBaseView::DoDeactivate()
       
   224 //
       
   225 //
       
   226 // ---------------------------------------------------------------------------
       
   227 EXPORT_C void CGSBaseView::DoDeactivate()
       
   228     {
       
   229     if ( iContainer )
       
   230         {
       
   231         iCurrentItem = iContainer->SelectedItem();
       
   232         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   233         delete iContainer;
       
   234         iContainer = NULL;
       
   235         }
       
   236     }
       
   237 
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // CGSBaseView::CreateContainerL()
       
   241 //
       
   242 //
       
   243 // ---------------------------------------------------------------------------
       
   244 //
       
   245 EXPORT_C void CGSBaseView::CreateContainerL()
       
   246     {
       
   247     NewContainerL();
       
   248     __ASSERT_DEBUG(
       
   249         iContainer, User::Panic( KGSDoActivateError, EGSViewPanicNullPtr ) );
       
   250     iContainer->SetMopParent( this );
       
   251 
       
   252     TRAPD( error, iContainer->ConstructL( ClientRect() ) );
       
   253 
       
   254     if ( error )
       
   255         {
       
   256         delete iContainer;
       
   257         iContainer = NULL;
       
   258         User::Leave( error );
       
   259         }
       
   260     }
       
   261 
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 // CGSBaseView::OpenLocalizedResourceFileL()
       
   265 //
       
   266 //
       
   267 // ---------------------------------------------------------------------------
       
   268 //
       
   269 EXPORT_C void CGSBaseView::OpenLocalizedResourceFileL(
       
   270     const TDesC& aResourceFileName,
       
   271     RConeResourceLoader& aResourceLoader )
       
   272     {
       
   273     RFs fsSession;
       
   274     User::LeaveIfError( fsSession.Connect() );
       
   275 
       
   276     // Find the resource file:
       
   277     TParse parse;
       
   278     parse.Set( aResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL );
       
   279     TFileName fileName( parse.FullName() );
       
   280 
       
   281     // Get language of resource file:
       
   282     BaflUtils::NearestLanguageFile( fsSession, fileName );
       
   283 
       
   284     // Open resource file:
       
   285     aResourceLoader.OpenL( fileName );
       
   286 
       
   287     // If leave occurs before this, close is called automatically when the
       
   288     // thread exits.
       
   289     fsSession.Close();
       
   290     }
       
   291 
       
   292 
       
   293 // -----------------------------------------------------------------------------
       
   294 // CGSBaseView::ResetSelectedItemIndex()
       
   295 //
       
   296 //
       
   297 // -----------------------------------------------------------------------------
       
   298 //
       
   299 EXPORT_C void CGSBaseView::ResetSelectedItemIndex()
       
   300     {
       
   301     iCurrentItem = 0;
       
   302     if( iContainer )
       
   303         {
       
   304         iContainer->SetSelectedItem( iCurrentItem );
       
   305         }
       
   306     }
       
   307 
       
   308 //End of File