profilesapplication/Profiles/ProfileApp/UIsrc/CProfileSettingsView.cpp
branchRCL_3
changeset 19 cd54903d48da
equal deleted inserted replaced
18:b7fa36b488f8 19:cd54903d48da
       
     1 /*
       
     2 * Copyright (c) 2002 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: Settings view class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "CProfileSettingsView.h"
       
    21 
       
    22 #include    <aknViewAppUi.h>
       
    23 #include    <akntitle.h>
       
    24 #include    <akntabgrp.h>
       
    25 #include    <featmgr.h>
       
    26 #include    <MProfileEngineExtended.h>
       
    27 #include    <MProfilesNamesArray.h>
       
    28 #include    <CProfileEngineHandler.h>
       
    29 #include    <CProfileIndexHandler.h>
       
    30 #include    <CProfileTabHandler.h>
       
    31 #include    <profileapp.rsg>
       
    32 
       
    33 #include    "ProfilePanics.h"
       
    34 #include    "CProfileSettingsContainer.h"
       
    35 #include    "ProfileApp.hrh"
       
    36 
       
    37 
       
    38 
       
    39 /******************************************************************************
       
    40  * class CProfileTopControl
       
    41  ******************************************************************************/
       
    42 
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CProfileTopControl::NewL()
       
    46 // 
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CProfileTopControl* CProfileTopControl::NewL( CCoeControl* aFocusControl )
       
    50     {
       
    51     CProfileTopControl* self = new ( ELeave ) CProfileTopControl();
       
    52     self->iFocusControl = aFocusControl;
       
    53     return self;
       
    54     }
       
    55 
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CProfileTopControl::FocusChanged()
       
    59 // 
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 void CProfileTopControl::FocusChanged( TDrawNow aDrawNow )
       
    63     {
       
    64     // Not calling super::FocusChanged is intentional
       
    65     if( iFocusControl )
       
    66         {
       
    67         iFocusControl->SetFocus( IsFocused(), aDrawNow );
       
    68         }
       
    69     }
       
    70 
       
    71 
       
    72 /******************************************************************************
       
    73  * class CProfileDummyHandler
       
    74  ******************************************************************************/
       
    75 
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CProfileDummyHandler::CProfileDummyHandler()
       
    79 // 
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CProfileDummyHandler::CProfileDummyHandler()
       
    83     {
       
    84     }
       
    85 
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CProfileDummyHandler::~CProfileDummyHandler()
       
    89 // 
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 CProfileDummyHandler::~CProfileDummyHandler()
       
    93     {
       
    94     }
       
    95 
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CProfileDummyHandler::CreateSettingItemL()
       
    99 // 
       
   100 // This should never be called in Profiles App.
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 CAknSettingItem* CProfileDummyHandler::CreateSettingItemL( TInt /* aIdentifier */ )
       
   104     {
       
   105     User::Panic( KProfilePanicText, EProfilePanicInvalidSettingItemId );
       
   106     return NULL; // to make compiler happy
       
   107     }
       
   108 
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CProfileDummyHandler::SetObserver()
       
   112 // 
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void CProfileDummyHandler::SetObserver(MProfileExternalSettingsObserver& /* aObserver */ )
       
   116    {
       
   117    }
       
   118 
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CProfileDummyHandler::AllowedToChange()
       
   122 // 
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 TBool CProfileDummyHandler::AllowedToChange( TInt /* aSettingItemId */ ) const
       
   126     {
       
   127     return EFalse;
       
   128     }
       
   129 
       
   130 
       
   131 
       
   132 /******************************************************************************
       
   133  * class CProfileSettingsView
       
   134  ******************************************************************************/
       
   135 
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CProfileSettingsView::CProfileSettingsView
       
   139 // C++ constructor can NOT contain any code, that might leave.
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 CProfileSettingsView::CProfileSettingsView(
       
   143     CProfileEngineHandler& aEngineHandler,
       
   144     CProfileIndexHandler& aIndexHandler )
       
   145     :   iEngineHandler( aEngineHandler ),
       
   146         iIndexHandler( aIndexHandler )
       
   147     {
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CProfileSettingsView::ConstructL
       
   152 // Symbian 2nd phase constructor can leave.
       
   153 // -----------------------------------------------------------------------------
       
   154 void CProfileSettingsView::ConstructL()
       
   155     {
       
   156     BaseConstructL( R_PROFILE_SETTINGS_VIEW );
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CProfileSettingsView::NewLC
       
   161 // Two-phased constructor.
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 CProfileSettingsView* CProfileSettingsView::NewLC(
       
   165     CProfileEngineHandler& aEngineHandler,
       
   166     CProfileIndexHandler& aIndexHandler )
       
   167     {
       
   168     CProfileSettingsView* self = new( ELeave ) CProfileSettingsView(
       
   169         aEngineHandler, aIndexHandler );
       
   170     CleanupStack::PushL( self );
       
   171     self->ConstructL();
       
   172     return self;
       
   173     }
       
   174 
       
   175 // Destructor.
       
   176 CProfileSettingsView::~CProfileSettingsView()
       
   177     {
       
   178     if( iTopControl )
       
   179         {
       
   180         AppUi()->RemoveFromStack( iTopControl );
       
   181         }
       
   182     if( iTabHandler )
       
   183         {
       
   184         AppUi()->RemoveFromStack( iTabHandler->TabGroup() );
       
   185         }
       
   186     if( iContainer )
       
   187         {
       
   188         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   189         }
       
   190     delete iContainer;
       
   191     delete iTabHandler;
       
   192     delete iTopControl;
       
   193     delete iDummyHandler;
       
   194     }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CProfileSettingsView::Id
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 TUid CProfileSettingsView::Id() const
       
   201     {
       
   202     return KProfileAppSettingViewId;
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CProfileSettingsView::HandleCommandL
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 void CProfileSettingsView::HandleCommandL( TInt aCommand )
       
   210     {
       
   211     switch ( aCommand )
       
   212         {
       
   213         case EAknSoftkeyBack:
       
   214             {
       
   215             if( iContainer && iContainer->ItemEdited() )
       
   216                 {
       
   217                 break;
       
   218                 }
       
   219             AppUi()->HandleCommandL( aCommand );
       
   220             break;
       
   221             }
       
   222         case EAknSoftkeyChange: // From context specific options menu
       
   223         case EProfileCmdChange:
       
   224             {
       
   225             if( !iContainer )
       
   226                 {
       
   227                 break;
       
   228                 }
       
   229             iContainer->EditItemL(
       
   230                 iContainer->SettingItemArray()->ItemIndexFromVisibleIndex(
       
   231                     iContainer->ListBox()->CurrentItemIndex() ),
       
   232                     ( aCommand == EProfileCmdChange ) );
       
   233             break;
       
   234             }
       
   235         default:
       
   236             {
       
   237             AppUi()->HandleCommandL( aCommand );
       
   238             break;
       
   239             }
       
   240         }
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // CProfileSettingsView::DoActivateL
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 void CProfileSettingsView::DoActivateL(
       
   248     const TVwsViewId& /* aPrevViewId */,
       
   249     TUid aCustomMessageId,
       
   250     const TDesC8& aCustomMessage )
       
   251     {
       
   252     if ( !iContainer )
       
   253         {
       
   254         // If aCustomMessageId is the same as CProfileSettingsView id,
       
   255         // the caller is external. Check if profile id is given and open it.
       
   256         if( aCustomMessageId == KProfileAppSettingViewId )
       
   257 		    {
       
   258 		    TLex8 lex( aCustomMessage );
       
   259 		    TInt value = 0;
       
   260 		    lex.Val( value );
       
   261 		    TInt err = KErrNone;
       
   262 		    MProfilesNamesArray* profileNamesArray = iEngineHandler.Engine()->ProfilesNamesArrayLC();
       
   263 		    TInt index = profileNamesArray->FindById(value);
       
   264 		    CleanupStack::PopAndDestroy();
       
   265 		    TRAP( err, iIndexHandler.SetCurrentProfileIndex( index ) );	
       
   266 
       
   267 		    CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
       
   268 		    CleanupStack::PushL( cba );
       
   269 		    cba->SetCommandSetL( R_PROFILE_SETTINGS_VIEW_CBA_IDLE );
       
   270 		    CleanupStack::Pop( cba );
       
   271 		    cba->DrawDeferred();	
       
   272 		    }
       
   273 
       
   274         // Get pointer to navi pane
       
   275         CAknNavigationControlContainer* naviPane =
       
   276             static_cast<CAknNavigationControlContainer*>(
       
   277 		    StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
   278         // Get pointer to title pane
       
   279        	CAknTitlePane* titlePane = static_cast< CAknTitlePane* >(
       
   280 		    StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   281 
       
   282         //iTabHandler = CProfileTabHandler::NewL(
       
   283         //    iEngineHandler, iIndexHandler, *naviPane );
       
   284 
       
   285         iDummyHandler = new ( ELeave ) CProfileDummyHandler();
       
   286         iContainer = CProfileSettingsContainer::NewL(
       
   287             *this, iEngineHandler, *iDummyHandler, &iIndexHandler,
       
   288             iTabHandler, titlePane );
       
   289 
       
   290         iTopControl = CProfileTopControl::NewL( iContainer );
       
   291   
       
   292   		AppUi()->AddToViewStackL( *this, iContainer );
       
   293    		// Tab group must be added to stack last.
       
   294    		//AppUi()->AddToStackL( *this, iTabHandler->TabGroup() );
       
   295    		// Top control is always on top as it listens to focus changes (which
       
   296    		// will be routed to container to adapt highlight animation to focus)
       
   297    		AppUi()->AddToStackL( *this, iTopControl );
       
   298 
       
   299    		iContainer->MakeVisible( ETrue );
       
   300         }
       
   301    }
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // CProfileSettingsView::DoDeactivate
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 void CProfileSettingsView::DoDeactivate()
       
   308     {
       
   309     if( iTopControl )
       
   310         {
       
   311         AppUi()->RemoveFromStack( iTopControl );
       
   312         delete iTopControl;
       
   313         iTopControl = NULL;
       
   314         }
       
   315     if( iTabHandler )
       
   316         {
       
   317         AppUi()->RemoveFromStack( iTabHandler->TabGroup() );
       
   318         delete iTabHandler;
       
   319         iTabHandler = NULL;
       
   320         }
       
   321     if ( iContainer )
       
   322         {
       
   323         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   324         delete iContainer;
       
   325         iContainer = NULL;
       
   326         }
       
   327     delete iDummyHandler;
       
   328     iDummyHandler = NULL;
       
   329     }
       
   330 
       
   331 // -----------------------------------------------------------------------------
       
   332 // CProfileSettingsView::DynInitMenuPaneL
       
   333 // -----------------------------------------------------------------------------
       
   334 //
       
   335 void CProfileSettingsView::DynInitMenuPaneL(
       
   336     TInt aResourceId, CEikMenuPane* aMenuPane )
       
   337     {
       
   338     if( ( iContainer ) && 
       
   339         ( aResourceId == R_PROFILE_SETTINGS_VIEW_OPTIONS_MENUPANE ) )
       
   340         {
       
   341         // Check if the setting item is allowed to be changed
       
   342         // If not, hide "Change" from Options menu
       
   343         CAknSettingItemArray* array = iContainer->SettingItemArray();
       
   344         if( !iContainer->AllowedToChange(
       
   345             array->At( array->ItemIndexFromVisibleIndex(
       
   346             iContainer->ListBox()->CurrentItemIndex() ) )->Identifier() ) )
       
   347             {
       
   348             aMenuPane->SetItemDimmed( EProfileCmdChange, ETrue );
       
   349             }
       
   350         if( !FeatureManager::FeatureSupported( KFeatureIdHelp ) ) // Help
       
   351             {
       
   352             aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue );
       
   353             }
       
   354         }
       
   355     }
       
   356 
       
   357 // -----------------------------------------------------------------------------
       
   358 // CProfileSettingsView::UpdateClientRect
       
   359 // -----------------------------------------------------------------------------
       
   360 //
       
   361 void CProfileSettingsView::UpdateClientRect()
       
   362 	{
       
   363     iContainer->SetRect( ClientRect() );
       
   364 	}
       
   365 
       
   366 // -----------------------------------------------------------------------------
       
   367 // CProfileSettingsView::View
       
   368 // -----------------------------------------------------------------------------
       
   369 //
       
   370 CAknView& CProfileSettingsView::View()
       
   371     {
       
   372     return *this;
       
   373     }
       
   374 
       
   375 // End of File