camerauis/cameraapp/generic/src/CamUserSceneSetupContainer.cpp
changeset 0 1ddebce53859
child 2 e8773a61782d
equal deleted inserted replaced
-1:000000000000 0:1ddebce53859
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Implements container for the user scene setup list.*
       
    15 */
       
    16 
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "CamUserSceneSetupContainer.h"
       
    20 #include "CamUserSceneSetupItemArray.h"
       
    21 #include "CamAppController.h"
       
    22 #include "CamSettings.hrh"
       
    23 #include "Cam.hrh"
       
    24 #include "CamPanic.h"
       
    25 #include <aknlists.h>
       
    26 #include <AknIconArray.h>
       
    27 #include <barsread.h>
       
    28 #include <aknview.h>
       
    29 
       
    30 #include "CamUtility.h"
       
    31 
       
    32 
       
    33 // ================= MEMBER FUNCTIONS =======================
       
    34 
       
    35 // ---------------------------------------------------------
       
    36 // CCamUserSceneSetupContainer::NewLC
       
    37 // Symbian two-phased constructor.
       
    38 // ---------------------------------------------------------
       
    39 //
       
    40 CCamUserSceneSetupContainer* CCamUserSceneSetupContainer::NewLC
       
    41 ( const TRect& aRect, TInt aResourceId, 
       
    42     CCamAppController& aController, 
       
    43     CAknView& aView )
       
    44     {
       
    45     CCamUserSceneSetupContainer* self =
       
    46         new ( ELeave ) CCamUserSceneSetupContainer( aController, 
       
    47         aView );
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL( aRect, aResourceId );
       
    50     return self;
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------
       
    54 // CCamUserSceneSetupContainer::NewL
       
    55 // Symbian two-phased constructor.
       
    56 // ---------------------------------------------------------
       
    57 //
       
    58 CCamUserSceneSetupContainer* CCamUserSceneSetupContainer::NewL
       
    59 ( const TRect& aRect, TInt aResourceId, 
       
    60     CCamAppController& aController, 
       
    61     CAknView& aView )
       
    62     {
       
    63     CCamUserSceneSetupContainer* self = 
       
    64         CCamUserSceneSetupContainer::NewLC
       
    65         ( aRect, aResourceId, aController, 
       
    66        aView );
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------
       
    72 // CCamUserSceneSetupContainer::~CCamUserSceneSetupContainer
       
    73 // Destructor
       
    74 // ---------------------------------------------------------
       
    75 //
       
    76 CCamUserSceneSetupContainer::~CCamUserSceneSetupContainer()
       
    77   {
       
    78   PRINT( _L("Camera => ~CCamUserSceneSetupContainer" ))  
       
    79   delete iUserSceneSetupList;
       
    80   delete iUserSceneSetupItemArray;
       
    81   PRINT( _L("Camera <= ~CCamUserSceneSetupContainer" ))  
       
    82   }
       
    83 
       
    84 // ---------------------------------------------------------
       
    85 // CCamUserSceneSetupContainer::HandleChangeInItemArrayOrVisibilityL
       
    86 // Handles a change in the item list visibility.
       
    87 // ---------------------------------------------------------
       
    88 //
       
    89 void CCamUserSceneSetupContainer::UpdateDisplayL()
       
    90     {
       
    91     ListBox()->DrawNow();
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------
       
    95 // CCamUserSceneSetupContainer::TitlePaneTextResourceId
       
    96 // Returns the resource Id of the title for this container.
       
    97 // ---------------------------------------------------------
       
    98 //
       
    99 TInt CCamUserSceneSetupContainer::TitlePaneTextResourceId()
       
   100     {
       
   101     return iTitleResourceId;
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------
       
   105 // CCamUserSceneSetupContainer::UpdateListItems
       
   106 // Updates the list items with the settings model values.
       
   107 // ---------------------------------------------------------
       
   108 //
       
   109 void CCamUserSceneSetupContainer::UpdateListItems( void )
       
   110     {
       
   111     TInt listItemCount = iUserSceneSetupItemArray->Count();
       
   112     TInt i;
       
   113     for ( i = 0; i < listItemCount; ++i )
       
   114         {
       
   115         UpdateListItem( i );
       
   116         }
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------
       
   120 // CCamUserSceneSetupContainer::UpdateCurrentListItem
       
   121 // Updates the current list item with it's associated
       
   122 // settings model value.
       
   123 // ---------------------------------------------------------
       
   124 //
       
   125 void CCamUserSceneSetupContainer::UpdateCurrentListItem()
       
   126     {
       
   127     TInt selectedItemIndex = iUserSceneSetupList->CurrentItemIndex();
       
   128     UpdateListItem( selectedItemIndex );
       
   129     }
       
   130     
       
   131 // ---------------------------------------------------------
       
   132 // CCamUserSceneSetupContainer::HandleListBoxEventL
       
   133 // Handles a list box event.
       
   134 // ---------------------------------------------------------
       
   135 //
       
   136 void CCamUserSceneSetupContainer::HandleListBoxEventL
       
   137 ( CEikListBox* /*aListBox*/, TListBoxEvent aEventType )
       
   138 	{
       
   139 	switch( aEventType )
       
   140 		{
       
   141 		case EEventEnterKeyPressed: // fallthrough
       
   142 		case EEventItemDoubleClicked: 
       
   143         case EEventItemSingleClicked:
       
   144 			{
       
   145             HandleSelectionL();
       
   146             }
       
   147 			break;
       
   148 
       
   149 		default:
       
   150 			break;			
       
   151 		}
       
   152 	}
       
   153 
       
   154 // ---------------------------------------------------------
       
   155 // CCamUserSceneSetupContainer::HandleSelectionL
       
   156 // Handles the user selection of a list item.
       
   157 // ---------------------------------------------------------
       
   158 //
       
   159 void CCamUserSceneSetupContainer::HandleSelectionL( void )
       
   160     {
       
   161     TInt CommandId = CommandIdForActivatingCurrentItemControl();
       
   162     iView.HandleCommandL( CommandId );
       
   163     }
       
   164     
       
   165 
       
   166 
       
   167 // ---------------------------------------------------------
       
   168 // CCamUserSceneSetupContainer::CCamUserSceneSetupContainer
       
   169 // C++ constructor
       
   170 // ---------------------------------------------------------
       
   171 //
       
   172 CCamUserSceneSetupContainer::CCamUserSceneSetupContainer
       
   173 ( CCamAppController& aController, 
       
   174     CAknView& aView )
       
   175 : CCamContainerBase( aController, aView )
       
   176     {
       
   177 
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------
       
   181 // CCamUserSceneSetupContainer::ConstructL
       
   182 // 2nd phase constructor
       
   183 // ---------------------------------------------------------
       
   184 //
       
   185 void CCamUserSceneSetupContainer::ConstructL
       
   186 ( const TRect& aRect, TInt aResourceId )
       
   187     {
       
   188     const TInt KSettingItemArrayGranularity = 5;
       
   189 
       
   190     CreateWindowL();
       
   191 
       
   192 	// Create the listbox in the right style
       
   193     iUserSceneSetupList = new ( ELeave ) CAknSettingStyleListBox;
       
   194    	iUserSceneSetupList->ConstructL( this, CEikListBox::ELeftDownInViewRect );
       
   195     iUserSceneSetupList->DisableSingleClick( ETrue );
       
   196 
       
   197 	TPoint pos = iEikonEnv->EikAppUi()->ClientRect().iTl;
       
   198 	TSize size = iUserSceneSetupList->MinimumSize();
       
   199 	SetExtent( pos, size ); 
       
   200 
       
   201 
       
   202 	// Setup the scroll bar
       
   203 	iUserSceneSetupList->CreateScrollBarFrameL( ETrue );
       
   204 	iUserSceneSetupList->ScrollBarFrame()->
       
   205         SetScrollBarVisibilityL( CEikScrollBarFrame::EOn, 
       
   206             CEikScrollBarFrame::EAuto );
       
   207             
       
   208     iTitleResourceId = aResourceId;
       
   209 
       
   210             
       
   211     // get array of supported resources from psi
       
   212     RArray<TInt> userSceneResourceIds;
       
   213     CleanupClosePushL( userSceneResourceIds );
       
   214     
       
   215     User::LeaveIfError( CamUtility::GetPsiIntArrayL( ECamPsiUserSceneResourceIds, userSceneResourceIds ) );
       
   216 
       
   217     // ...get the number of items in this user scene setup list.
       
   218     TInt itemCount = userSceneResourceIds.Count(); 
       
   219 	iUserSceneSetupItemArray = new ( ELeave ) 
       
   220         CCamUserSceneSetupItemArray( itemCount );
       
   221     iUserSceneSetupItemArray->ConstructL();
       
   222 	
       
   223 	// Make the icon array
       
   224 	CArrayPtrFlat<CGulIcon>* iconArray = new ( ELeave )
       
   225         CAknIconArray( KSettingItemArrayGranularity );
       
   226 	CleanupStack::PushL( iconArray );
       
   227 
       
   228     // Create all the user scene setup list items defined in the resource.
       
   229 	TInt i;
       
   230 	for ( i=0; i < itemCount; ++i )
       
   231 		{
       
   232         CCamUserSceneSetupListItem* listItem = 
       
   233             CCamUserSceneSetupListItem::NewL( userSceneResourceIds[i] );
       
   234         CleanupStack::PushL( listItem );
       
   235         // Ownership is transferred
       
   236         iUserSceneSetupItemArray->AppendL( listItem ); 
       
   237         CleanupStack::Pop( listItem );
       
   238 		}
       
   239 		
       
   240 	
       
   241 	// Update the display
       
   242 	UpdateDisplayL();
       
   243 
       
   244 	// Looks like we have no choice but to give ownership 
       
   245     // of this to the listbox.
       
   246 	// There is no flag as there is for the item data
       
   247 	ListBox()->ItemDrawer()->FormattedCellData()->SetIconArrayL( iconArray ); 
       
   248 
       
   249     // iconArray now has ownership transferred
       
   250 	CleanupStack::Pop( iconArray );  
       
   251     
       
   252     CleanupStack::PopAndDestroy( &userSceneResourceIds );	
       
   253 
       
   254 	CTextListBoxModel* model= iUserSceneSetupList->Model();
       
   255 	model->SetItemTextArray( iUserSceneSetupItemArray );
       
   256     // Ownership retained by SettingItemList
       
   257 	model->SetOwnershipType( ELbmDoesNotOwnItemArray ); 
       
   258 
       
   259    	TAknLayoutRect layoutRect;
       
   260 	layoutRect.LayoutRect( TRect( 
       
   261         TPoint( 0, 0 ), iAvkonAppUi->ClientRect().Size() ), 
       
   262         AKN_LAYOUT_WINDOW_list_gen_pane( 0 ) );
       
   263 	iUserSceneSetupList->SetRect( layoutRect.Rect() );
       
   264 
       
   265 	ListBox()->SetCurrentItemIndex( 0 );
       
   266 	ListBox()->SetListBoxObserver( this );
       
   267 	ListBox()->UpdateScrollBarsL();
       
   268 
       
   269     SetRect( aRect );
       
   270     ActivateL();
       
   271 
       
   272     UpdateListItems();
       
   273     }
       
   274 
       
   275 
       
   276 
       
   277 // ---------------------------------------------------------
       
   278 // CCamUserSceneSetupContainer::UpdateListItem
       
   279 // Updates a list item with its corresponding settings model value.
       
   280 // ---------------------------------------------------------
       
   281 //
       
   282 void CCamUserSceneSetupContainer::UpdateListItem( TInt aIndex )
       
   283     {     
       
   284     // Get the current value for this list item from the settings model.
       
   285     // ...get settings model id for list item.
       
   286     TInt settingsModelId = 
       
   287             iUserSceneSetupItemArray->At( aIndex )->SettingsModelTypeId();
       
   288     if ( settingsModelId != ECamSettingItemUserSceneReset )
       
   289         {
       
   290         // ...use id to get current value.
       
   291         TInt currentVal = iController.IntegerSettingValue( settingsModelId );
       
   292     
       
   293         // Update list item with the current value.
       
   294         iUserSceneSetupItemArray->At( aIndex )->SetCurrentValue( currentVal );
       
   295         }
       
   296     }
       
   297 
       
   298 
       
   299 // ----------------------------------------------------
       
   300 // CCamUserSceneSetupContainer::CommandIdForActivatingCurrentItemControl
       
   301 // Returns the command id for activating the current list item control.
       
   302 // ----------------------------------------------------
       
   303 //
       
   304 TInt CCamUserSceneSetupContainer::CommandIdForActivatingCurrentItemControl()
       
   305     {
       
   306     // Get the settings model type id for the selected item.
       
   307     // ...get settings model id for list item.  
       
   308     TInt currentIndex = iUserSceneSetupList->CurrentItemIndex();
       
   309     
       
   310     // ...get settings model id for list item.
       
   311     TInt settingsModelId = 
       
   312         iUserSceneSetupItemArray->At( currentIndex )->
       
   313             SettingsModelTypeId();
       
   314     // Convert settings model id to command id that activates the
       
   315     // control for the selected item.
       
   316     TInt commandId = -1;
       
   317     switch ( settingsModelId )
       
   318         {
       
   319         case ECamSettingItemUserSceneBasedOnScene:
       
   320             {
       
   321             commandId = ECamCmdCaptureSetupSceneUser;
       
   322             }
       
   323             break;
       
   324         case ECamSettingItemUserSceneWhitebalance:
       
   325             {
       
   326             commandId = ECamCmdCaptureSetupWhiteBalanceUser;
       
   327             }
       
   328             break;
       
   329         case ECamSettingItemUserSceneExposure:
       
   330             {
       
   331             commandId = ECamCmdCaptureSetupExposureUser;
       
   332             }
       
   333             break;
       
   334         case ECamSettingItemUserSceneColourFilter:
       
   335             {
       
   336             commandId = ECamCmdCaptureSetupColourFilterUser;
       
   337             }
       
   338             break;
       
   339         case ECamSettingItemUserSceneFlash:
       
   340             {
       
   341             commandId = ECamCmdCaptureSetupFlashUser;
       
   342             }
       
   343             break;
       
   344         case ECamSettingItemUserSceneReset:
       
   345             {
       
   346             commandId = ECamCmdUserSceneReset;
       
   347             }
       
   348             break;
       
   349         case ECamSettingItemUserSceneBrightness:
       
   350             {
       
   351             commandId = ECamCmdCaptureSetupBrightnessUser;
       
   352             }
       
   353             break;
       
   354         case ECamSettingItemUserSceneContrast:
       
   355             {
       
   356             commandId = ECamCmdCaptureSetupContrastUser;
       
   357             }
       
   358             break;
       
   359 
       
   360         case ECamSettingItemUserSceneImageSharpness:
       
   361             {
       
   362             commandId = ECamCmdCaptureSetupImageSharpnessUser;
       
   363             }
       
   364             break;
       
   365 
       
   366         case ECamSettingItemUserSceneLightSensitivity:
       
   367             {
       
   368             commandId = ECamCmdCaptureSetupLightSensitivityUser;
       
   369             }
       
   370             break;
       
   371         default:
       
   372             {
       
   373             CamPanic( ECamPanicCaptureSetupMenuUnknownItem );
       
   374             }
       
   375         }
       
   376     return commandId;
       
   377     }
       
   378 
       
   379 
       
   380 
       
   381 // ---------------------------------------------------------
       
   382 // CCamUserSceneSetupContainer::CountComponentControls
       
   383 // ---------------------------------------------------------
       
   384 //
       
   385 TInt CCamUserSceneSetupContainer::CountComponentControls() const
       
   386     {
       
   387 	return 1;
       
   388 	}
       
   389 
       
   390 // ---------------------------------------------------------
       
   391 // CCamUserSceneSetupContainer::ComponentControl
       
   392 // ---------------------------------------------------------
       
   393 //
       
   394 CCoeControl* CCamUserSceneSetupContainer::ComponentControl
       
   395 ( TInt aIndex ) const
       
   396     {
       
   397     switch( aIndex )
       
   398         {
       
   399         case 0:
       
   400             return iUserSceneSetupList;
       
   401         default:
       
   402             return NULL;            
       
   403         }
       
   404         
       
   405     // Should never get here
       
   406     }
       
   407 
       
   408 // ---------------------------------------------------------------------------
       
   409 // CCamUserSceneSetupContainer::OfferKeyEventL
       
   410 // Key event handling
       
   411 // ---------------------------------------------------------------------------
       
   412 //
       
   413 TKeyResponse CCamUserSceneSetupContainer::OfferKeyEventL(
       
   414     const TKeyEvent& aKeyEvent,
       
   415     TEventCode aType )
       
   416     {
       
   417 	return iUserSceneSetupList->OfferKeyEventL( aKeyEvent, aType );
       
   418     }
       
   419 
       
   420 // ---------------------------------------------------------------------------
       
   421 // CCamUserSceneSetupContainer::ListBox
       
   422 // Returns a pointer to the list box
       
   423 // ---------------------------------------------------------------------------
       
   424 //
       
   425 CEikFormattedCellListBox* CCamUserSceneSetupContainer::ListBox()
       
   426 	{
       
   427 	return ( iUserSceneSetupList );
       
   428 	}
       
   429 
       
   430 // ---------------------------------------------------------------------------
       
   431 // CCamUserSceneSetupContainer::IsUserSceneResetHighlighted
       
   432 // Returns wheather user scene restore is highlighted
       
   433 // ---------------------------------------------------------------------------
       
   434 //
       
   435 TBool CCamUserSceneSetupContainer::IsUserSceneResetHighlighted()
       
   436 	{
       
   437     TInt currentIndex = iUserSceneSetupList->CurrentItemIndex();
       
   438     // ...get settings model id for list item.
       
   439     TInt settingsModelId = 
       
   440         iUserSceneSetupItemArray->At( currentIndex )->SettingsModelTypeId();
       
   441     if ( settingsModelId == ECamSettingItemUserSceneReset )
       
   442         {
       
   443         return ETrue;
       
   444         }
       
   445     else 
       
   446         {
       
   447         return EFalse;
       
   448         }
       
   449 	}
       
   450 
       
   451 // End of File