systemsettings/GSAccessoryPlugin/src/gsaccbaseview.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2002-2008 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:  Declaration of CGSAccBaseView class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aknradiobuttonsettingpage.h>
       
    20 #include <aknViewAppUi.h>
       
    21 #include <featmgr.h>
       
    22 #include <gsaccessoryplugin.rsg>
       
    23 #include <gscommon.hrh>
       
    24 #include <hlplch.h> // For HlpLauncher
       
    25 
       
    26 #include "gsaccbasecontainer.h"
       
    27 #include "gsaccbaseview.h"
       
    28 #include "gsaccessorypluginconst.hrh"
       
    29 #include "gsaccessorypluginmodel.h"
       
    30 #include "gsaccprofilelist.h"
       
    31 #include "trace.h"
       
    32 
       
    33 // ========================= MEMBER FUNCTIONS ================================
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CGSAccBaseView::~CGSAccBaseView
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CGSAccBaseView::~CGSAccBaseView()
       
    40     {
       
    41     FUNC_LOG;
       
    42 
       
    43     delete iContainer;
       
    44     }
       
    45 
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CGSAccBaseView::HandleCommandL()
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 void CGSAccBaseView::HandleCommandL( TInt aCommand )
       
    52     {
       
    53     FUNC_LOG;
       
    54 
       
    55     switch ( aCommand )
       
    56         {
       
    57         case EGSMSKCmdAppChange:
       
    58             // Forward command to sub-class.
       
    59             HandleListBoxSelectionL( iContainer->CurrentFeatureId() );
       
    60             break;
       
    61         case EAknSoftkeyBack:
       
    62             // Go back to accessories main view.
       
    63             AppUi()->ActivateLocalViewL( TUid::Uid( KGSAccessoryPluginUid ) );
       
    64             break;
       
    65         case EAknCmdHelp:
       
    66             {
       
    67             // Launch help if it is supported.
       
    68             if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
    69                 {
       
    70                 HlpLauncher::LaunchHelpApplicationL(
       
    71                     iEikonEnv->WsSession(), AppUi()->AppHelpContextL() );
       
    72                 }
       
    73             break;
       
    74             }
       
    75         default:
       
    76             // Let framework handle other commands.
       
    77             AppUi()->HandleCommandL( aCommand );
       
    78             break;
       
    79         }
       
    80     }
       
    81 
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CGSAccBaseView::DoActivateL
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 void CGSAccBaseView::DoActivateL(
       
    88     const TVwsViewId& /*aPrevViewId*/,
       
    89     TUid /*aCustomMessageId*/,
       
    90     const TDesC8& /*aCustomMessage*/ )
       
    91     {
       
    92     FUNC_LOG;
       
    93 
       
    94     DestroyContainer();
       
    95     CreateContainerL();
       
    96 
       
    97     AppUi()->AddToViewStackL( *this, iContainer );
       
    98     iContainer->iListBox->SetListBoxObserver( this );
       
    99     }
       
   100 
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CGSAccBaseView::DoDeactivate()
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 void CGSAccBaseView::DoDeactivate()
       
   107     {
       
   108     FUNC_LOG;
       
   109 
       
   110     DestroyContainer();
       
   111     }
       
   112 
       
   113 
       
   114 // ----------------------------------------------------------------------------
       
   115 // CGSAccBaseView::DynInitMenuPaneL()
       
   116 // ----------------------------------------------------------------------------
       
   117 //
       
   118 void CGSAccBaseView::DynInitMenuPaneL(
       
   119     TInt aResourceId,
       
   120     CEikMenuPane* aMenuPane )
       
   121     {
       
   122     FUNC_LOG;
       
   123 
       
   124     if ( aResourceId == R_GS_MENU_ITEM_HELP )
       
   125         {
       
   126         User::LeaveIfNull( aMenuPane );
       
   127         // Dim help item unless help feature is supported.
       
   128         aMenuPane->SetItemDimmed(
       
   129             EAknCmdHelp,
       
   130             !FeatureManager::FeatureSupported( KFeatureIdHelp ) );
       
   131         }
       
   132     }
       
   133 
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 // CGSAccBaseView::HandleListBoxEventL
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 void CGSAccBaseView::HandleListBoxEventL(
       
   140     CEikListBox* /*aListBox*/,
       
   141     TListBoxEvent aEventType )
       
   142     {
       
   143     FUNC_LOG;
       
   144 
       
   145     switch ( aEventType )
       
   146         {
       
   147         case EEventEnterKeyPressed:
       
   148         case EEventItemSingleClicked:
       
   149             HandleListBoxSelectionL( iContainer->CurrentFeatureId() );
       
   150             break;
       
   151         default:
       
   152            break;
       
   153         }
       
   154     }
       
   155 
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // CGSAccBaseView::CGSAccBaseView
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 CGSAccBaseView::CGSAccBaseView( CGSAccessoryPluginModel& aModel )
       
   162   : iModel( aModel )
       
   163     {
       
   164     FUNC_LOG;
       
   165     }
       
   166 
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // CGSAccBaseView::UpdateListBoxL
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 void CGSAccBaseView::UpdateListBoxL( TInt aItemId )
       
   173     {
       
   174     FUNC_LOG;
       
   175     ASSERT_TRACE( iContainer );
       
   176 
       
   177     iContainer->UpdateListBoxL( aItemId );
       
   178     }
       
   179 
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // CGSAccBaseView::ShowRadioButtonSettingsPageL()
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 TBool CGSAccBaseView::ShowRadioButtonSettingsPageL(
       
   186     TInt aDlgResourceID,
       
   187     TInt aItemsResourceID,
       
   188     TInt& aCurrentSelectionIndex ) const
       
   189     {
       
   190     FUNC_LOG;
       
   191 
       
   192     CDesCArrayFlat* items =
       
   193         iCoeEnv->ReadDesC16ArrayResourceL( aItemsResourceID );
       
   194     CleanupStack::PushL( items );
       
   195 
       
   196     TBool ret = ShowRadioButtonSettingsPageL(
       
   197         aDlgResourceID, *items, aCurrentSelectionIndex );
       
   198 
       
   199     CleanupStack::PopAndDestroy( items );
       
   200     return ret;
       
   201     }
       
   202 
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // CGSAccBaseView::ShowRadioButtonSettingsPageL()
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 TBool CGSAccBaseView::ShowRadioButtonSettingsPageL(
       
   209     TInt aDlgResourceID,
       
   210     const MDesCArray& aItemArray,
       
   211     TInt& aCurrentSelectionIndex ) const
       
   212     {
       
   213     FUNC_LOG;
       
   214 
       
   215     CAknRadioButtonSettingPage* dlg =
       
   216         new ( ELeave ) CAknRadioButtonSettingPage(
       
   217             aDlgResourceID,
       
   218             aCurrentSelectionIndex,
       
   219             &aItemArray );
       
   220 
       
   221     TBool ret = dlg->ExecuteLD( CAknSettingPage::EUpdateWhenChanged );
       
   222 
       
   223     INFO_1( "CAknRadioButtonSettingPage::ExecuteLD returned %d", ret );
       
   224     return ret;
       
   225     }
       
   226 
       
   227 
       
   228 // ---------------------------------------------------------------------------
       
   229 // CGSAccBaseView::ChangeDefaultProfileL()
       
   230 // ---------------------------------------------------------------------------
       
   231 //
       
   232 void CGSAccBaseView::ChangeDefaultProfileL(
       
   233     TInt aProfileKey,
       
   234     TInt aListBoxId )
       
   235     {
       
   236     FUNC_LOG;
       
   237 
       
   238     // Read current value
       
   239     TInt current = iModel.ProfileList().IndexByIdL(
       
   240         iModel.DefaultProfileByKey( aProfileKey ), iCoeEnv );
       
   241 
       
   242     // Query new value from user
       
   243     TBool update = ShowRadioButtonSettingsPageL(
       
   244         R_ACC_DEFAULT_PROFILE_SETTING_PAGE,
       
   245         iModel.ProfileList().NameListL( iCoeEnv ),
       
   246         current );
       
   247 
       
   248     if ( update )
       
   249         {
       
   250         // Store new value
       
   251         iModel.SetDefaultProfileByKeyL(
       
   252             aProfileKey,
       
   253             iModel.ProfileList().IdByIndexL( current, iCoeEnv ) );
       
   254         UpdateListBoxL( aListBoxId );
       
   255         }
       
   256     }
       
   257 
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // CGSAccBaseView::ChangeAutoAnswerModeSettingL()
       
   261 // ---------------------------------------------------------------------------
       
   262 //
       
   263 void CGSAccBaseView::ChangeAutoAnswerModeSettingL(
       
   264     TInt aAutoAnswerKey,
       
   265     TInt aListBoxId,
       
   266     TBool aUseSettingPage )
       
   267     {
       
   268     FUNC_LOG;
       
   269 
       
   270     TInt currentValue = iModel.AutoAnswerModeByKey( aAutoAnswerKey );
       
   271     TBool updateValue( EFalse );
       
   272 
       
   273     // Value is updated either by setting page or simply switching to other
       
   274     // value (On<->Off).
       
   275     if ( aUseSettingPage )
       
   276         {
       
   277         updateValue = ShowRadioButtonSettingsPageL(
       
   278             R_ACC_AUTO_ANSWER_SETTING_PAGE,
       
   279             R_ACC_AUTO_ANSWER_SETTING_PAGE_LBX,
       
   280             currentValue );
       
   281         }
       
   282     else
       
   283         {
       
   284         // User pressed selection key instead of opening setting page.
       
   285         // Do not ask user input from dialog - just flip the value:
       
   286         // 0 -> 1, 1 -> 0.
       
   287         iModel.FlipValue( currentValue );
       
   288         updateValue = ETrue;
       
   289         }
       
   290 
       
   291     if ( updateValue ) // If value was changed, store it.
       
   292         {
       
   293         iModel.SetAutoAnswerModeByKeyL( aAutoAnswerKey, currentValue );
       
   294         UpdateListBoxL( aListBoxId );
       
   295         }
       
   296     }
       
   297 
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // CGSAccBaseView::ChangeLightModeSettingL()
       
   301 // ---------------------------------------------------------------------------
       
   302 //
       
   303 void CGSAccBaseView::ChangeLightModeSettingL(
       
   304     TAccMode aAccMode,
       
   305     TInt aAccSetting,
       
   306     TInt aListBoxId,
       
   307     TBool aSettingPage )
       
   308     {
       
   309     FUNC_LOG;
       
   310 
       
   311     TInt currentValue = iModel.LightMode( aAccMode, aAccSetting );
       
   312     TBool updateValue( EFalse );
       
   313 
       
   314     // Value is updated either by setting page or simply switching to other
       
   315     // value (On<->Off).
       
   316     if ( aSettingPage )
       
   317         {
       
   318         updateValue = ShowRadioButtonSettingsPageL(
       
   319             R_ACC_LIGHTS_SETTING_PAGE,
       
   320             R_ACC_LIGHTS_SETTING_PAGE_LBX,
       
   321             currentValue );
       
   322         }
       
   323     else
       
   324         {
       
   325         // User pressed selection key instead of opening setting page.
       
   326         // Do not ask user input from dialog - just flip the value:
       
   327         // 0 -> 1, 1 -> 0.
       
   328         iModel.FlipValue( currentValue );
       
   329         updateValue = ETrue;
       
   330         }
       
   331 
       
   332     if ( updateValue )
       
   333         {
       
   334         iModel.SetLightModeL( aAccMode, aAccSetting, currentValue );
       
   335         UpdateListBoxL( aListBoxId );
       
   336         }
       
   337     }
       
   338 
       
   339 
       
   340 // ---------------------------------------------------------------------------
       
   341 // CGSAccBaseView::CreateContainerL()
       
   342 // ---------------------------------------------------------------------------
       
   343 //
       
   344 void CGSAccBaseView::CreateContainerL()
       
   345     {
       
   346     FUNC_LOG;
       
   347 
       
   348     NewContainerL(); // Derived class should assign object to iContainer.
       
   349     ASSERT_TRACE( iContainer );
       
   350 
       
   351     iContainer->SetMopParent( this );
       
   352     TRAPD( error, iContainer->ConstructL( ClientRect() ) );
       
   353     ERROR( error, "Failed to create container" );
       
   354 
       
   355     if ( error )
       
   356         {
       
   357         delete iContainer;
       
   358         iContainer = NULL;
       
   359         User::Leave( error );
       
   360         }
       
   361     }
       
   362 
       
   363 
       
   364 // ---------------------------------------------------------------------------
       
   365 // CGSAccBaseView::DestroyContainer()
       
   366 // ---------------------------------------------------------------------------
       
   367 //
       
   368 void CGSAccBaseView::DestroyContainer()
       
   369     {
       
   370     FUNC_LOG;
       
   371 
       
   372     if ( iContainer )
       
   373         {
       
   374         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   375         delete iContainer;
       
   376         iContainer = NULL;
       
   377         }
       
   378     }