voiceui/vcommand/src/vcsettingscontainer.cpp
branchRCL_3
changeset 19 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2004-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:  Settings container
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <eiktxlbx.h>
       
    21 #include <aknlists.h>       // CAknSingleGraphicStyleListBox
       
    22 #include <barsread.h>       // TResourceReader
       
    23 #include <eikclbd.h>        // CColumnListBoxData
       
    24 #include <akntitle.h>
       
    25 #include <eikspane.h>
       
    26 #include <featmgr.h>
       
    27 #include <hlplch.h>
       
    28 #include <StringLoader.h>
       
    29 #include <AknQueryDialog.h>
       
    30 #include <aknnotewrappers.h>
       
    31 #include <csxhelp/vc.hlp.hrh>
       
    32 
       
    33 #include <vcommand.rsg>
       
    34 #include "vcapp.h"
       
    35 #include "vcappui.h"
       
    36 #include "vcsettingscontainer.h"
       
    37 #include "vcsettingsengine.h"
       
    38 #include "vcsettingsview.h"
       
    39 #include "vcsettingslist.h"
       
    40 #include "vcommandconstants.h"
       
    41 
       
    42 // ========================= MEMBER FUNCTIONS =================================
       
    43 
       
    44 // ----------------------------------------------------------------------------
       
    45 // CVCSettingsContainer::CVCSettingsContainer
       
    46 // C++ constructor
       
    47 // ----------------------------------------------------------------------------
       
    48 //
       
    49 CVCSettingsContainer::CVCSettingsContainer( CEikButtonGroupContainer& aCbaGroup ):
       
    50                                             iCbaGroup( aCbaGroup )
       
    51     {
       
    52     }
       
    53 
       
    54 
       
    55 // ----------------------------------------------------------------------------
       
    56 // CVCSettingsContainer::ConstructL
       
    57 // Symbian OS 2nd phase constructor
       
    58 // ----------------------------------------------------------------------------
       
    59 //
       
    60 void CVCSettingsContainer::ConstructL( const TRect& aRect )
       
    61     {
       
    62     CEikStatusPane* sp = STATIC_CAST( CAknAppUi*, iCoeEnv->AppUi() )->StatusPane();
       
    63     CAknTitlePane* title = STATIC_CAST( CAknTitlePane*,
       
    64             sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
    65 
       
    66     TResourceReader rReader;
       
    67     iCoeEnv->CreateResourceReaderLC( rReader, TitleResourceId() );
       
    68     title->SetFromResourceL( rReader );
       
    69     CleanupStack::PopAndDestroy(); //rReader
       
    70     
       
    71     CreateWindowL();
       
    72     iSettingsList = new ( ELeave ) CVCSettingsList();
       
    73     iSettingsList->SetContainerWindowL( *this );
       
    74     iSettingsList->ConstructL();
       
    75     iSettingsList->ListBox()->SetListBoxObserver( this );
       
    76     
       
    77     SetRect(aRect);
       
    78     ActivateL();
       
    79     }
       
    80 
       
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 // CVCSettingsContainer::~CVCSettingsContainer
       
    84 // ----------------------------------------------------------------------------
       
    85 //
       
    86 CVCSettingsContainer::~CVCSettingsContainer()
       
    87     {
       
    88     delete iSettingsList; 
       
    89 	}
       
    90 
       
    91 
       
    92 // ----------------------------------------------------------------------------
       
    93 // CVCSettingsContainer::CountComponentControls
       
    94 // From CCoeControl return the number of controls owned
       
    95 // ----------------------------------------------------------------------------
       
    96 //
       
    97 TInt CVCSettingsContainer::CountComponentControls() const
       
    98     {
       
    99     return 1;
       
   100     }
       
   101 
       
   102 
       
   103 // ----------------------------------------------------------------------------
       
   104 // CVCSettingsContainer::ComponentControl
       
   105 // From CCoeControl returns a control
       
   106 // ----------------------------------------------------------------------------
       
   107 //
       
   108 CCoeControl* CVCSettingsContainer::ComponentControl( TInt /*aIndex*/ ) const
       
   109     {
       
   110     return iSettingsList;
       
   111     }
       
   112 
       
   113 
       
   114 // ----------------------------------------------------------------------------
       
   115 // CVCSettingsContainer::EditCurrentL
       
   116 // Open setting page for currently selected setting item.
       
   117 // ----------------------------------------------------------------------------
       
   118 //
       
   119 void CVCSettingsContainer::EditCurrentL( TBool aCalledFromMenu )
       
   120     {
       
   121     TInt index = iSettingsList->ListBox()->CurrentItemIndex();
       
   122 
       
   123     iSettingsList->EditItemL( index, aCalledFromMenu );
       
   124 	}
       
   125 
       
   126 
       
   127 // ----------------------------------------------------------------------------
       
   128 // CVCSettingsContainer::ResetL
       
   129 // ----------------------------------------------------------------------------
       
   130 //
       
   131 void CVCSettingsContainer::ResetL()
       
   132     {
       
   133     CAknQueryDialog* dlg = CAknQueryDialog::NewL(CAknQueryDialog::EConfirmationTone);
       
   134     if ( dlg->ExecuteLD(R_VC_RESET_ADAPTATION_DIALOG) )
       
   135         {
       
   136         CVCSettingsEngine*	engine = CVCSettingsEngine::NewL();
       
   137         CleanupStack::PushL( engine );
       
   138 		engine->ResetAdaptationL();
       
   139 		CleanupStack::PopAndDestroy( engine ); // engine
       
   140 		}
       
   141 	}
       
   142 
       
   143 
       
   144 // ----------------------------------------------------------------------------
       
   145 // CVCSettingsContainer::SaveSettingsL
       
   146 // Save all settings.
       
   147 // ----------------------------------------------------------------------------
       
   148 //
       
   149 void CVCSettingsContainer::SaveSettingsL()
       
   150     {
       
   151     iSettingsList->SaveSettingsL();
       
   152     }
       
   153 
       
   154 
       
   155 // ----------------------------------------------------------------------------
       
   156 // CVCSettingsContainer::CurrentItemIndex
       
   157 // ----------------------------------------------------------------------------
       
   158 //
       
   159 TInt CVCSettingsContainer::CurrentItemIndex() const
       
   160 	{
       
   161 	return iSettingsList->ListBox()->CurrentItemIndex();
       
   162 	}
       
   163 
       
   164 
       
   165 // ----------------------------------------------------------------------------
       
   166 // CVCSettingsContainer::ItemListSize
       
   167 // ----------------------------------------------------------------------------
       
   168 //
       
   169 TInt CVCSettingsContainer::ItemListSize() const 
       
   170     {
       
   171     return iSettingsList->ListBox()->Model()->ItemTextArray()->MdcaCount();
       
   172     }
       
   173     
       
   174     
       
   175 // ----------------------------------------------------------------------------
       
   176 // CVCSettingsContainer::CurrentItemIndex
       
   177 // ----------------------------------------------------------------------------
       
   178 //
       
   179 TInt CVCSettingsContainer::CurrentItemIdentifier() const
       
   180 	{
       
   181 	CAknSettingItemArray* itemArray = iSettingsList->SettingItemArray();
       
   182 	TInt itemIndex = itemArray->ItemIndexFromVisibleIndex( CurrentItemIndex() );
       
   183     CAknSettingItem* settingItem = itemArray->At( itemIndex );
       
   184     return settingItem->Identifier();
       
   185 	}
       
   186 
       
   187 
       
   188 // ----------------------------------------------------------------------------
       
   189 // CVCSettingsContainer::OfferKeyEventL
       
   190 // Key event handling
       
   191 // ----------------------------------------------------------------------------
       
   192 //
       
   193 TKeyResponse CVCSettingsContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, 
       
   194                                                    TEventCode aType )
       
   195     {  
       
   196     TKeyResponse ret = iSettingsList->OfferKeyEventL( aKeyEvent, aType );
       
   197     
       
   198     // Change MSK
       
   199     if( aKeyEvent.iCode == EKeyUpArrow || aKeyEvent.iCode == EKeyDownArrow )
       
   200         {
       
   201         SetMiddleSoftkeyLabelL();
       
   202         }
       
   203         
       
   204     return ret;
       
   205     }
       
   206 
       
   207 
       
   208 // ----------------------------------------------------------------------------
       
   209 // CVCSettingsContainer::GetHelpContext
       
   210 // Gives the help context to be displayed
       
   211 // ----------------------------------------------------------------------------
       
   212 //
       
   213 void CVCSettingsContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   214     {
       
   215     aContext.iMajor = KUidHelp; 
       
   216     aContext.iContext = KHLP_VC_SET;
       
   217     }
       
   218     
       
   219     
       
   220 // ----------------------------------------------------------------------------
       
   221 // CVCSettingsContainer::TitleResourceId()
       
   222 // Returns profiles views status pane title .
       
   223 // ----------------------------------------------------------------------------
       
   224 //
       
   225 TInt CVCSettingsContainer::TitleResourceId() const
       
   226     {
       
   227     return R_VC_MAIN_VIEW_TITLE;
       
   228     }
       
   229     
       
   230     
       
   231 // ----------------------------------------------------------------------------
       
   232 // CVCSettingsContainer::IsTrainingOn
       
   233 // ----------------------------------------------------------------------------
       
   234 //
       
   235 void CVCSettingsContainer::FocusChanged(TDrawNow aDrawNow)
       
   236 	{
       
   237     if( iSettingsList )
       
   238         {
       
   239         iSettingsList->SetFocus( IsFocused(), aDrawNow );
       
   240         }
       
   241     }
       
   242      
       
   243      
       
   244 // ----------------------------------------------------------------------------
       
   245 // CVCSettingsContainer::HandleResourceChange
       
   246 // ----------------------------------------------------------------------------
       
   247 //
       
   248 void CVCSettingsContainer::HandleResourceChange(TInt aType)
       
   249     {   
       
   250     if ( aType == KEikDynamicLayoutVariantSwitch )
       
   251     	{
       
   252         TRect mainPaneRect;
       
   253         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane,
       
   254                                            mainPaneRect);
       
   255         SetRect( mainPaneRect );
       
   256         }
       
   257     CCoeControl::HandleResourceChange( aType );
       
   258     }     
       
   259         
       
   260         
       
   261 // ----------------------------------------------------------------------------
       
   262 // CVCSettingsContainer::SizeChanged
       
   263 // ----------------------------------------------------------------------------
       
   264 //
       
   265 void CVCSettingsContainer::SizeChanged()
       
   266     {
       
   267     if (iSettingsList)
       
   268         {
       
   269         iSettingsList->SetRect(Rect());
       
   270         }
       
   271     }
       
   272     
       
   273 // ----------------------------------------------------------------------------
       
   274 // CVCSettingsContainer::HandleControlEventL
       
   275 // ----------------------------------------------------------------------------
       
   276 //
       
   277 void CVCSettingsContainer::HandleControlEventL( CCoeControl* /*aControl*/,
       
   278                                                 TCoeEvent /*aEventType*/)
       
   279     {
       
   280     }
       
   281     
       
   282 // ---------------------------------------------------------------------------
       
   283 // CVCSettingsContainer::HandleListBoxEventL
       
   284 // ---------------------------------------------------------------------------
       
   285 //
       
   286 void CVCSettingsContainer::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
   287                                                 TListBoxEvent aEventType )
       
   288     {
       
   289     switch ( aEventType ) 
       
   290         {
       
   291         case EEventEnterKeyPressed:
       
   292         case EEventItemSingleClicked:
       
   293             {
       
   294             if ( CurrentItemIdentifier() == EVCResetItem )
       
   295                 {
       
   296                 ResetL();
       
   297                 }
       
   298             else
       
   299                 {
       
   300                 EditCurrentL( EFalse );
       
   301                 }            
       
   302             break;
       
   303             }
       
   304             
       
   305         default:
       
   306             break;
       
   307         }
       
   308     }
       
   309 
       
   310     
       
   311 // ----------------------------------------------------------------------------
       
   312 // CVCSettingsContainer::SetMiddleSoftkeyLabelL
       
   313 // ----------------------------------------------------------------------------
       
   314 //
       
   315 void CVCSettingsContainer::SetMiddleSoftkeyLabelL() const
       
   316     {    
       
   317     RemoveCommandFromMSK();
       
   318     
       
   319     if( CurrentItemIdentifier() == EVCResetItem )
       
   320         {
       
   321         DoSetMiddleSoftKeyLabelL( R_QTN_VC_SET_MSK_RESET, EVCCmdReset );
       
   322         }
       
   323     else
       
   324         {
       
   325         DoSetMiddleSoftKeyLabelL( R_QTN_VC_SET_MSK_CHANGE, EVCCmdChange );
       
   326         }
       
   327     }
       
   328     
       
   329 // ----------------------------------------------------------------------------
       
   330 // CVCSettingsContainer::SetMiddleSoftKeyLabelL
       
   331 // ----------------------------------------------------------------------------
       
   332 //
       
   333 void CVCSettingsContainer::DoSetMiddleSoftKeyLabelL( const TInt aResourceId,
       
   334                                                 const TInt aCommandId  ) const
       
   335     {
       
   336     HBufC* mskText = StringLoader::LoadLC( aResourceId );
       
   337     TPtr mskPtr = mskText->Des();
       
   338     iCbaGroup.AddCommandToStackL( KVcMskControlID, aCommandId, mskPtr );
       
   339     CleanupStack::PopAndDestroy( mskText );
       
   340     }
       
   341     
       
   342 // ----------------------------------------------------------------------------
       
   343 // CVCSettingsContainer::RemoveCommandFromMSK
       
   344 // ----------------------------------------------------------------------------
       
   345 //
       
   346 void CVCSettingsContainer::RemoveCommandFromMSK() const
       
   347     {
       
   348     iCbaGroup.RemoveCommandFromStack( KVcMskControlID, EVCCmdChange );
       
   349     iCbaGroup.RemoveCommandFromStack( KVcMskControlID, EVCCmdReset );
       
   350     }  
       
   351 
       
   352 // End of File
       
   353