camerauis/cameraapp/generic/src/CamSettingsModel.cpp
changeset 0 1ddebce53859
child 1 f5ec9446e5bf
equal deleted inserted replaced
-1:000000000000 0:1ddebce53859
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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:  Manages all settings data.*
       
    15 */
       
    16 
       
    17 
       
    18 // ===========================================================================
       
    19 // Includes
       
    20 #include <StringLoader.h>
       
    21 #include <barsread.h>
       
    22 #include <AknQueryDialog.h>
       
    23 #include <ecam.h>
       
    24 #include <data_caging_path_literals.hrh>  // KDC_APP_RESOURCE_DIR
       
    25 
       
    26 #include <cameraapp.rsg>
       
    27 #include <vgacamsettings.rsg>
       
    28 
       
    29 #include "CamSettingsModel.h"
       
    30 #include "CamPanic.h"
       
    31 #include "mcamsettingsmodelobserver.h"
       
    32 #include "CamAppUiBase.h"
       
    33 #include "CamSharedDataKeys.h"
       
    34 #include "CamUtility.h"
       
    35 #include "CamVideoQualityLevel.h"
       
    36 
       
    37 #include "CameraVariant.hrh" // Variant CR key values
       
    38 #include "CameraappPrivateCRKeys.h" // CR keys
       
    39 #include "camactivepalettehandler.h"
       
    40 #include "CamAppUi.h"
       
    41 #include "camsettingconversion.h"
       
    42 #include "camconfiguration.h"
       
    43 #include "CamStaticSettingsModel.h"
       
    44 #include "CameraUiConfigManager.h"
       
    45 
       
    46 // ===========================================================================
       
    47 // Constants
       
    48 
       
    49 const TInt KDynamicArrayGranularity  =  3;
       
    50 _LIT( KCamNhdResourceFileName, "z:nhdcamsettings.rss" );  
       
    51 _LIT( KCamVgaResourceFileName, "z:vgacamsettings.rss" );  
       
    52 
       
    53 
       
    54 // ===========================================================================
       
    55 // Local methods
       
    56 inline TBool SettingIdMatches( const TInt*        aSettingId, 
       
    57                                const TIntSetting& aSettingItem )
       
    58   {
       
    59   return (*aSettingId == aSettingItem.iItemId);
       
    60   };
       
    61 
       
    62 inline TInt FindIndex( const RPointerArray<TIntSetting>& aSettingArray,
       
    63                        const TInt&                       aSettingId    )
       
    64   {
       
    65   return aSettingArray.Find( aSettingId, SettingIdMatches );
       
    66   };
       
    67 
       
    68 inline TInt FindIndex( const RPointerArray<TIntSetting>& aSettingArray,
       
    69                        const TIntSetting&                aSettingItem  )
       
    70   {
       
    71   return FindIndex( aSettingArray, aSettingItem.iItemId );
       
    72   };
       
    73 
       
    74 
       
    75 // ===========================================================================
       
    76 // Class methods
       
    77 
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // TCamVariantInfo constructor
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 TCamVariantInfo::TCamVariantInfo() 
       
    84   : iFlags           ( -1 ),
       
    85     iTimeLapseSupport( ECamSupportUnknown ),
       
    86     iAlwaysOnSupport ( ECamSupportUnknown ),
       
    87     iVersion         ( -1, 0, 0           ) 
       
    88   {
       
    89   }
       
    90     
       
    91 // ===========================================================================
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CCamSettingsModel::NewL
       
    95 // Symbian OS two-phased constructor 
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 CCamSettingsModel* CCamSettingsModel::NewL( CCamConfiguration& aConfiguration )
       
    99     {
       
   100     CCamSettingsModel* self = CCamSettingsModel::NewLC( aConfiguration );
       
   101     CleanupStack::Pop( self );
       
   102     return self;
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CCamSettingsModel::NewLC
       
   107 // Symbian OS two-phased constructor
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 CCamSettingsModel* CCamSettingsModel::NewLC( CCamConfiguration& aConfiguration )
       
   111     {
       
   112     CCamSettingsModel* self = new( ELeave ) CCamSettingsModel( aConfiguration );
       
   113     CleanupStack::PushL( self );
       
   114     self->ConstructL();
       
   115     return self;
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CCamSettingsModel::ResetUserSceneWithoutActivatingChangesL
       
   120 // Resets all user scene settings to their defaults without activating them.
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CCamSettingsModel::ResetUserSceneWithoutActivatingChangesL()
       
   124     {
       
   125     PRINT( _L("Camera => CCamSettingsModel::ResetUserSceneWithoutActivatingChangesL"))		
       
   126 
       
   127     // Reset the user scene data in the repository
       
   128     iStaticModel->ResetSettingItem( KCamCrUserSceneBaseScene );
       
   129     iStaticModel->ResetSettingItem( KCamCrUserSceneWhiteBalance );
       
   130     iStaticModel->ResetSettingItem( KCamCrUserSceneColourFilter );
       
   131     iStaticModel->ResetSettingItem( KCamCrUserSceneFlash );
       
   132     iStaticModel->ResetSettingItem( KCamCrUserSceneExposure );
       
   133 
       
   134     if ( iUiConfigManager->IsISOSupported() )
       
   135         {
       
   136         iStaticModel->ResetSettingItem( KCamCrUserSceneLightSensitivity );
       
   137         }
       
   138     iStaticModel->ResetSettingItem( KCamCrUserSceneContrast );
       
   139     iStaticModel->ResetSettingItem( KCamCrUserSceneImageSharpness );
       
   140 
       
   141     // Reload the static user scene settings
       
   142     iUserSceneSettings.ResetAndDestroy();
       
   143     iStaticModel->ReadFromCenRepL(
       
   144                     static_cast<TInt>( ECamSettingItemUserSceneRangeMin ),
       
   145                     static_cast<TInt>( ECamSettingItemUserSceneRangeMax ),
       
   146                     iUserSceneSettings
       
   147                    );
       
   148     PRINT( _L("Camera <= CCamSettingsModel::ResetUserSceneWithoutActivatingChangesL"))		
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CCamSettingsModel::ResetUserSceneL
       
   153 // Resets all user scene settings to their defaults.
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 void CCamSettingsModel::ResetUserSceneL()
       
   157     {
       
   158     PRINT( _L("Camera => CCamSettingsModel::ResetUserSceneL"))	
       
   159     // Reset the user scene based on scene in the repository to get the default value
       
   160     ResetUserSceneWithoutActivatingChangesL();
       
   161     TInt scene = IntegerSettingValue( ECamSettingItemDynamicPhotoScene );
       
   162     // If current scene is user scene
       
   163     if ( ECamSceneUser == scene )
       
   164         {
       
   165         // if the user scene is currently the photo scene then
       
   166         // activate all the default scene settings to the AP
       
   167         ActivateUserSceneSettingsL();
       
   168         }
       
   169     PRINT( _L("Camera <= CCamSettingsModel::ResetUserSceneL"))	    
       
   170     }
       
   171 
       
   172 
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // CCamSettingsModel::IntegerSettingValue
       
   176 // Returns the current integer value for the specified setting
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 TInt 
       
   180 CCamSettingsModel::IntegerSettingValue( TInt aSettingItem ) const
       
   181   {
       
   182   PRINT2( _L("Camera => CCamSettingsModel::IntegerSettingValue, id:%d [%s]"), 
       
   183           aSettingItem,
       
   184           KCamSettingItemNames[aSettingItem] );
       
   185 
       
   186   TInt value = KErrNotFound;
       
   187   // If the requested item is the photo quality value, this must
       
   188   // be filtered based on the current scene.
       
   189   if ( aSettingItem == ECamSettingItemPhotoQuality )
       
   190     {
       
   191     value = CurrentPhotoQualityValue();
       
   192     }
       
   193   // If the requested item is the photo size, this must be filtered based on
       
   194   // the current scene
       
   195   else if ( aSettingItem == ECamSettingItemPhotoSize )
       
   196     {
       
   197     value = CurrentPhotoResolution();
       
   198     }
       
   199   // If the requested item is the photo compression level, this must
       
   200   // be filtered based on the current scene, and burst mode.
       
   201   else if ( aSettingItem == ECamSettingItemPhotoCompression )
       
   202     {
       
   203     value = CurrentPhotoCompression();
       
   204     }
       
   205   else
       
   206     {
       
   207     // If we have previews active, check first if requested
       
   208     // setting is found among them. Settings model must pretend
       
   209     // that the current value is the one set to preview.
       
   210     TInt previewIndex( FindIndex( iSettingPreviews, aSettingItem ) );
       
   211     if( KErrNotFound != previewIndex )
       
   212       {
       
   213       PRINT( _L("Camera <> Setting item value in previewed currently!") );
       
   214       value = iSettingPreviews[previewIndex]->iValueId;
       
   215       
       
   216       if (ECamSettingItemDynamicSelfTimer == aSettingItem)     		//If the current setting Item is selftimer  
       
   217         {
       
   218         TInt settingIndex = SearchInSettingsListFor( iDynamicPhotoIntSettings, aSettingItem );  
       
   219         value = iDynamicPhotoIntSettings[settingIndex]->iValueId;	//Get the actual selftime setting value but not preview value
       
   220         }
       
   221       }
       
   222     // Otherwise, if setting item is in the dynamic photo settings return it's value.
       
   223     else if( ECamSettingItemDynamicPhotoRangeMax > aSettingItem 
       
   224           && ECamSettingItemDynamicPhotoRangeMin < aSettingItem )
       
   225       {
       
   226       TInt settingIndex = SearchInSettingsListFor( iDynamicPhotoIntSettings, aSettingItem );
       
   227       value = iDynamicPhotoIntSettings[settingIndex]->iValueId;
       
   228       }
       
   229     // Otherwise, if setting item is in the dynamic video settings return it's value.
       
   230     else if( ECamSettingItemDynamicVideoRangeMax > aSettingItem 
       
   231           && ECamSettingItemDynamicVideoRangeMin < aSettingItem )
       
   232       {
       
   233       TInt settingIndex = SearchInSettingsListFor( iDynamicVideoIntSettings, aSettingItem );
       
   234       value = iDynamicVideoIntSettings[settingIndex]->iValueId;
       
   235       }
       
   236     // Otherwise, if setting item is in the user scene settings return it's value.
       
   237     else if( ECamSettingItemUserSceneRangeMax > aSettingItem 
       
   238           && ECamSettingItemUserSceneRangeMin < aSettingItem )
       
   239       {
       
   240       TInt settingIndex = SearchInSettingsListFor( iUserSceneSettings, aSettingItem );
       
   241       value = iUserSceneSettings[settingIndex]->iValueId;
       
   242       }
       
   243     // Otherwise, if setting item is in the static video settings return it's value.
       
   244     else if( ECamSettingItemVideoClipLength == aSettingItem )
       
   245         {
       
   246         // Video clip length workaround
       
   247         // PRINT( _L("Camera <> ECamSettingItemVideoClipLength") );  
       
   248         TInt videoQuality = IntegerSettingValue( ECamSettingItemVideoQuality );
       
   249         value = iQualityLevels[videoQuality]->VideoLength();
       
   250         }
       
   251     else
       
   252         {
       
   253         value = iStaticModel->IntegerSettingValue( aSettingItem );
       
   254         }
       
   255     }
       
   256 
       
   257   PRINT1( _L("Camera <= CCamSettingsModel::IntegerSettingValue, value:%d"), value );
       
   258   return value;
       
   259   }
       
   260 
       
   261 
       
   262 
       
   263 
       
   264 // ---------------------------------------------------------------------------
       
   265 // CCamSettingsModel::SceneSettingValue
       
   266 // Returns the setting value for a specific field of a scene 
       
   267 // ---------------------------------------------------------------------------
       
   268 //
       
   269 TInt 
       
   270 CCamSettingsModel::SceneSettingValue( TInt aSceneId, 
       
   271                                       TInt aSceneField ) const
       
   272   {
       
   273   PRINT2( _L("CCamSettingsModel::SceneSettingValue, scene[%s] setting[%s]"), 
       
   274           KCamSceneNames[aSceneId],
       
   275           KCamSettingItemNames[aSceneField] );
       
   276 
       
   277   // If setting item is a scene in the photo scene list
       
   278   TInt sceneIndex = FindSceneInSceneList( aSceneId, iPhotoScenes );
       
   279   if ( sceneIndex != KErrNotFound )
       
   280     {
       
   281     // Search for the field in the scene's field list.
       
   282     const RPointerArray<TIntSetting>& sceneSettings = 
       
   283                                         iPhotoScenes[sceneIndex]->iSettings;
       
   284     TInt fieldCount = sceneSettings.Count();
       
   285     for ( TInt i = 0; i < fieldCount; ++i )
       
   286       {
       
   287       if ( sceneSettings[i]->iItemId == aSceneField )
       
   288         {
       
   289         return sceneSettings[i]->iValueId;
       
   290         }
       
   291       }
       
   292     }
       
   293 
       
   294   // Otherwise if setting item is a scene in the video scene list
       
   295   sceneIndex = FindSceneInSceneList( aSceneId, iVideoScenes );
       
   296   if ( sceneIndex != KErrNotFound )
       
   297     {
       
   298     // Search for the field in the scene's field list.
       
   299     const RPointerArray<TIntSetting>& sceneSettings = 
       
   300                                         iVideoScenes[sceneIndex]->iSettings;
       
   301     TInt fieldCount = sceneSettings.Count();
       
   302     for ( TInt i = 0; i < fieldCount; ++i )
       
   303       {
       
   304       if ( sceneSettings[i]->iItemId == aSceneField )
       
   305         {
       
   306         return sceneSettings[i]->iValueId;
       
   307         }
       
   308       }
       
   309     }
       
   310   
       
   311   else
       
   312     {
       
   313     PRINT( _L("Camera => CCamSettingsModel::ECamPanicUnknownSettingItem 3" ))
       
   314     CamPanic( ECamPanicUnknownSettingItem );
       
   315     }
       
   316   
       
   317   return sceneIndex;
       
   318   }
       
   319 
       
   320 // ---------------------------------------------------------------------------
       
   321 // CCamSettingsModel::SetIntegerSettingValueL
       
   322 // Sets a new integer value for the specified setting
       
   323 // ---------------------------------------------------------------------------
       
   324 //
       
   325 void 
       
   326 CCamSettingsModel::SetIntegerSettingValueL( TInt aSettingItem, 
       
   327                                             TInt aSettingValue )
       
   328   {
       
   329   PRINT ( _L("Camera => CCamSettingsModel::SetIntegerSettingValueL") );
       
   330   CCamAppUiBase* appUi = static_cast<CCamAppUiBase*>( iEnv->AppUi() );
       
   331   TCamSettingItemIds settingId( 
       
   332       static_cast<TCamSettingItemIds>(aSettingItem) );
       
   333 
       
   334   PRINT2( _L("Camera <> Setting item[%s] value:%d"), KCamSettingItemNames[settingId], aSettingValue );
       
   335 
       
   336   // -------------------------------------------------------
       
   337   // Dynamic image settings
       
   338   if( ECamSettingItemDynamicPhotoRangeMin < settingId
       
   339    && ECamSettingItemDynamicPhotoRangeMax > settingId )
       
   340     {
       
   341     TInt settingIndex = SearchInSettingsListFor( iDynamicPhotoIntSettings, 
       
   342                                                  settingId );
       
   343     iDynamicPhotoIntSettings[settingIndex]->iValueId = aSettingValue;
       
   344     
       
   345     // Changing scene
       
   346     if ( ECamSettingItemDynamicPhotoScene == settingId )
       
   347       {
       
   348        if ( ECamActiveCameraNone != appUi->ActiveCamera() || ( ECamActiveCameraNone == appUi->ActiveCamera() && ECamSceneAuto == aSettingValue ) )
       
   349            {
       
   350            PhotoSceneHasChangedL( aSettingValue );
       
   351            }
       
   352       }
       
   353     }
       
   354   // -------------------------------------------------------
       
   355   // Dynamic video settings
       
   356   else if( ECamSettingItemDynamicVideoRangeMin < settingId
       
   357         && ECamSettingItemDynamicVideoRangeMax > settingId )
       
   358     {
       
   359     TInt settingIndex = SearchInSettingsListFor( iDynamicVideoIntSettings, 
       
   360                                                  settingId );
       
   361     iDynamicVideoIntSettings[settingIndex]->iValueId = aSettingValue;
       
   362     if ( settingId == ECamSettingItemDynamicVideoScene )
       
   363       {
       
   364       VideoSceneHasChangedL( aSettingValue );
       
   365       }
       
   366     }
       
   367   // -------------------------------------------------------
       
   368   // User scene settings
       
   369   else if( ECamSettingItemUserSceneRangeMin < settingId
       
   370         && ECamSettingItemUserSceneRangeMax > settingId )
       
   371     {
       
   372     TBool userSceneModeSettingChanged = EFalse;
       
   373     // If the based-on scene has changed
       
   374     if ( settingId == ECamSettingItemUserSceneBasedOnScene )
       
   375       {
       
   376       TInt scene = IntegerSettingValue( ECamSettingItemDynamicPhotoScene );
       
   377       // If current scene is user scene
       
   378       if ( ECamSceneUser == scene )
       
   379         {
       
   380         // Handle other changes to the settings required by the change in scene.
       
   381         UserSceneHasChangedL( aSettingValue, ETrue );
       
   382         }
       
   383       // Otherwise the user scene hasn't been selected as the active scene
       
   384       // - the change option has just been selected in the scene setting list
       
   385       else 
       
   386         {
       
   387         // just handle a change in the scene
       
   388         UserSceneHasChangedL( aSettingValue, EFalse );
       
   389         }
       
   390       userSceneModeSettingChanged = ETrue;
       
   391       }
       
   392     // Writing values to CenRep for all the settings.
       
   393     TInt settingIndex = SearchInSettingsListFor( iUserSceneSettings, settingId );
       
   394     iUserSceneSettings[settingIndex]->iValueId = aSettingValue;
       
   395     SaveStaticSettingL( settingId );
       
   396     
       
   397     // If there is only one setting changed other than scene mode setting 
       
   398     // and if the Dynamic Scene mode is "User Scene" we update the new setting
       
   399     // value to the camera dynamic settings
       
   400     if ( !userSceneModeSettingChanged )
       
   401       {
       
   402       TInt scene = IntegerSettingValue( ECamSettingItemDynamicPhotoScene );
       
   403       // If user scene is the currently active photo scene then activate the
       
   404       // new user scene settings.
       
   405       if ( ECamSceneUser == scene )
       
   406         {
       
   407         CopyUserSceneSettingToCaptureSettingL( settingId );
       
   408         }
       
   409       }
       
   410     
       
   411     }
       
   412   // -------------------------------------------------------
       
   413   else
       
   414     {
       
   415     // use the static settings model
       
   416     iStaticModel->SetIntegerSettingValueL( aSettingItem, aSettingValue );
       
   417     }
       
   418   // -------------------------------------------------------
       
   419  
       
   420   NotifyObservers( settingId, aSettingValue ); 
       
   421 
       
   422   PRINT ( _L("Camera <= CCamSettingsModel::SetIntegerSettingValueL") );
       
   423   }
       
   424 
       
   425 
       
   426 // ---------------------------------------------------------------------------
       
   427 // CCamSettingsModel::SetTextSettingValueL
       
   428 // Sets a new text value for the specified setting
       
   429 // ---------------------------------------------------------------------------
       
   430 //
       
   431 void CCamSettingsModel::SetTextSettingValueL( TInt aSettingItem,
       
   432                                               const TDesC& aSettingValue )
       
   433     {
       
   434     iStaticModel->SetTextSettingValueL( aSettingItem, aSettingValue );
       
   435     NotifyObservers( (TCamSettingItemIds)aSettingItem, aSettingValue );
       
   436     }
       
   437 
       
   438 
       
   439 // ---------------------------------------------------------------------------
       
   440 // CCamSettingsModel::TextSettingValue
       
   441 // Returns the current text value for the specified setting
       
   442 // ---------------------------------------------------------------------------
       
   443 //
       
   444 TPtrC 
       
   445 CCamSettingsModel::TextSettingValue( TInt aSettingItem ) const
       
   446   {
       
   447   return iStaticModel->TextSettingValue( aSettingItem );
       
   448   }
       
   449 
       
   450 // ---------------------------------------------------------------------------
       
   451 // CCamSettingsModel::SettingValueEnabled
       
   452 // Returns ETrue if the setting value is currently enabled
       
   453 // ---------------------------------------------------------------------------
       
   454 //
       
   455 TBool CCamSettingsModel::SettingValueEnabled( TInt aSettingItem, 
       
   456                                              TInt aSettingValue ) const
       
   457     {
       
   458     TCamImageQualitySetting maxPhoto = static_cast<TCamImageQualitySetting>( iPhotoQualityLevels[iPhotoQualityLevels.Count() - 1].iPhotoResolution );
       
   459     // If the setting value is maximum photo size, and the current
       
   460     // scene is sports, then this setting value is disabled
       
   461     if ( ( aSettingItem == ECamSettingItemPhotoQuality ) && 
       
   462          ( aSettingValue == maxPhoto ) )
       
   463         {
       
   464         // If the current scene is sports, disable the option
       
   465         TCamSceneId scene = static_cast< TCamSceneId >
       
   466                ( IntegerSettingValue( ECamSettingItemDynamicPhotoScene ) );
       
   467         if ( scene == ECamSceneSports )
       
   468             {
       
   469             return EFalse;
       
   470             }
       
   471         // Otherwise, if the current scene is the user scene and
       
   472         // it is based on the 'Sports' scene then disable the option.
       
   473         else if ( scene == ECamSceneUser ) 
       
   474             {
       
   475             // ...Get the based on scene.
       
   476             TCamSceneId baseScene = static_cast< TCamSceneId >
       
   477                 ( IntegerSettingValue( ECamSettingItemUserSceneBasedOnScene ) );
       
   478             if ( baseScene == ECamSceneSports )
       
   479                 {
       
   480                 return EFalse;
       
   481                 }
       
   482             }
       
   483         else
       
   484             {
       
   485             // Otherwise, the option is enabled
       
   486             return ETrue;
       
   487             }       
       
   488         }
       
   489     // The high quality video setting is not supported if
       
   490     // the second camera is enabled
       
   491     else if ( aSettingItem == ECamSettingItemVideoQuality && 
       
   492               aSettingValue == ECamVideoQualityHigh &&
       
   493               static_cast<CCamAppUiBase*>( 
       
   494                     iEnv->AppUi() )->IsSecondCameraEnabled() )
       
   495         {
       
   496         return EFalse;
       
   497         }
       
   498     // All other setting item values are allowed
       
   499     else 
       
   500         {
       
   501         return ETrue;
       
   502         }
       
   503 
       
   504     return ETrue;
       
   505     }
       
   506 
       
   507 
       
   508 
       
   509 // ---------------------------------------------------------------------------
       
   510 //
       
   511 // ---------------------------------------------------------------------------
       
   512 //
       
   513 void 
       
   514 CCamSettingsModel
       
   515 ::AttachObserverL( const MCamSettingsModelObserver* aObserver )
       
   516   {
       
   517   if( aObserver )
       
   518     {
       
   519     TInt index = iObservers.Find( aObserver );
       
   520     if( KErrNotFound == index )
       
   521       {
       
   522       iObservers.AppendL( aObserver );
       
   523       }
       
   524     }
       
   525   }
       
   526 
       
   527 
       
   528 // ---------------------------------------------------------------------------
       
   529 //
       
   530 // ---------------------------------------------------------------------------
       
   531 //
       
   532 void
       
   533 CCamSettingsModel
       
   534 ::DetachObserver( const MCamSettingsModelObserver* aObserver )
       
   535   {
       
   536   if( aObserver )
       
   537     {
       
   538     TInt index = iObservers.Find( aObserver );
       
   539     if( KErrNotFound != index )
       
   540       {
       
   541       iObservers.Remove( index );
       
   542       }
       
   543     }
       
   544   }
       
   545 
       
   546 
       
   547 
       
   548 // ---------------------------------------------------------------------------
       
   549 // CCamSettingsModel::LoadSettingsL
       
   550 // Loads the settings from shared data, or if unable to from the resource file. 
       
   551 // ---------------------------------------------------------------------------
       
   552 //
       
   553 void 
       
   554 CCamSettingsModel::LoadSettingsL()   
       
   555   {
       
   556   PRINT( _L("Camera => CCamSettingsModel::LoadSettingsL"))
       
   557   // Remove any previously loaded values.
       
   558   UnloadSettings();
       
   559   
       
   560   PRINT( _L("Camera => CCamSettingsModel::LoadSettingsL B"))
       
   561   LoadDynamicSettingsL( R_CAM_PHOTO_DYNAMIC_SETTINGS_DATA, 
       
   562                         iDynamicPhotoIntSettings, 
       
   563                         iDynamicPhotoIntDefaults );
       
   564     
       
   565   PRINT( _L("Camera => CCamSettingsModel::LoadSettingsL C"))
       
   566   LoadDynamicSettingsL( R_CAM_VIDEO_DYNAMIC_SETTINGS_DATA, 
       
   567                         iDynamicVideoIntSettings, 
       
   568                         iDynamicVideoIntDefaults );
       
   569   
       
   570   PRINT( _L("Camera => CCamSettingsModel::LoadSettingsL D"))
       
   571   // Load image scene data
       
   572   LoadSceneDataL();
       
   573 
       
   574   // Load video scene data
       
   575   LoadSceneDataL( EFalse );
       
   576   
       
   577   PRINT( _L("Camera => CCamSettingsModel::LoadSettingsL E"))
       
   578   //LoadScenesDataL( R_CAM_VIDEO_SCENES_DATA, iVideoScenes );
       
   579   
       
   580   PRINT( _L("Camera <= CCamSettingsModel::LoadSettingsL"))
       
   581   }
       
   582     
       
   583 
       
   584 
       
   585 
       
   586 // ---------------------------------------------------------------------------
       
   587 // DynamicSettingDefaultValue
       
   588 //
       
   589 // ---------------------------------------------------------------------------
       
   590 //
       
   591 TInt 
       
   592 CCamSettingsModel::DynamicSettingDefaultValue( TInt aSettingId ) const
       
   593   {
       
   594   TInt value = KErrNotFound;
       
   595 
       
   596   TInt index = SearchInSettingsListFor( iDynamicPhotoIntSettings, aSettingId );
       
   597   if( KErrNotFound != index )
       
   598     {
       
   599   	value = iDynamicPhotoIntDefaults[index];
       
   600     }
       
   601   index = SearchInSettingsListFor( iDynamicVideoIntSettings, aSettingId );
       
   602   if( KErrNotFound != index )
       
   603     {
       
   604   	value = iDynamicVideoIntDefaults[index];
       
   605     }    
       
   606 
       
   607   return value;
       
   608   }
       
   609 
       
   610 // ---------------------------------------------------------------------------
       
   611 // CCamSettingsModel::SetDynamicSettingsToDefaults
       
   612 // Sets all dynamic settings to their defaults. 
       
   613 // ---------------------------------------------------------------------------
       
   614 //
       
   615 void CCamSettingsModel::SetDynamicSettingsToDefaults()
       
   616     {
       
   617     // Set photo dynamic settings to their defaults.
       
   618     TInt i;
       
   619     TInt settingsListCount = iDynamicPhotoIntSettings.Count();
       
   620     for ( i = 0; i < settingsListCount; ++i )
       
   621         {
       
   622         iDynamicPhotoIntSettings[i]->iValueId = iDynamicPhotoIntDefaults[i];
       
   623         }
       
   624     // Set video dynamic settings to their defaults.
       
   625     settingsListCount = iDynamicVideoIntSettings.Count();
       
   626     for ( i = 0; i < settingsListCount; ++i )
       
   627         {
       
   628         iDynamicVideoIntSettings[i]->iValueId = iDynamicVideoIntDefaults[i];
       
   629         }
       
   630     }
       
   631 
       
   632 // ---------------------------------------------------------------------------
       
   633 // CCamSettingsModel::SetDynamicSettingsToDefault
       
   634 // Sets a dynamic setting to its default. 
       
   635 // ---------------------------------------------------------------------------
       
   636 //
       
   637 void CCamSettingsModel::SetDynamicSettingToDefault( TInt aSettingItem )
       
   638     {
       
   639     // Set photo dynamic settings to their defaults.
       
   640     TInt i;
       
   641     TBool found = EFalse;
       
   642     TInt settingsListCount = iDynamicPhotoIntSettings.Count();
       
   643     for ( i = 0; i < settingsListCount && !found; ++i )
       
   644         {
       
   645         if ( aSettingItem == iDynamicPhotoIntSettings[i]->iItemId )
       
   646             {
       
   647             iDynamicPhotoIntSettings[i]->iValueId = iDynamicPhotoIntDefaults[i];
       
   648             found = ETrue;
       
   649             }
       
   650         }
       
   651     // Set video dynamic settings to their defaults.
       
   652     settingsListCount = iDynamicVideoIntSettings.Count();
       
   653     for ( i = 0; i < settingsListCount && !found; ++i )
       
   654         {
       
   655         if ( aSettingItem == iDynamicVideoIntSettings[i]->iItemId )
       
   656             {
       
   657             iDynamicVideoIntSettings[i]->iValueId = iDynamicVideoIntDefaults[i];
       
   658             found = ETrue;
       
   659             }
       
   660         }
       
   661 
       
   662     // NB no error is reported is it's not found
       
   663     }
       
   664 
       
   665 
       
   666 // ---------------------------------------------------------------------------
       
   667 // virtual SetDynamicSettingToSceneDefaultL
       
   668 //
       
   669 // Sets a dynamic setting to scene default. 
       
   670 // ---------------------------------------------------------------------------
       
   671 //
       
   672 TInt
       
   673 CCamSettingsModel::SetDynamicSettingToSceneDefaultL( TInt  aSceneId,
       
   674                                                      TInt  aSceneField,
       
   675                                                      TInt  aSettingId,
       
   676                                                      TBool aVideoScene )
       
   677   {
       
   678   PRINT( _L("Camera => CCamSettingsModel::SetDynamicSettingToSceneDefault") );
       
   679 
       
   680   RPointerArray<TIntSetting>* sceneSettings = NULL;
       
   681   TInt                        sceneIndex    = KErrNotFound;
       
   682 
       
   683   if( !aVideoScene )
       
   684     { 
       
   685     sceneIndex = FindSceneInSceneList( aSceneId, iPhotoScenes );
       
   686     if( KErrNotFound != sceneIndex )
       
   687       {
       
   688       sceneSettings = &(iPhotoScenes[sceneIndex]->iSettings);
       
   689       }
       
   690     }
       
   691   else
       
   692     {
       
   693     sceneIndex = FindSceneInSceneList( aSceneId, iVideoScenes );
       
   694     if( KErrNotFound != sceneIndex )
       
   695       {
       
   696       sceneSettings = &(iVideoScenes[sceneIndex]->iSettings);
       
   697       }
       
   698     }
       
   699  
       
   700   TInt settingIndex = KErrNotFound;
       
   701   if( sceneSettings )
       
   702     {
       
   703     settingIndex = SearchInSettingsListFor( *sceneSettings, aSceneField );
       
   704     if( settingIndex != KErrNotFound )
       
   705       {
       
   706       SetIntegerSettingValueL( aSettingId, 
       
   707                               (*sceneSettings)[settingIndex]->iValueId );
       
   708       }
       
   709     }
       
   710 
       
   711   PRINT( _L("Camera <= CCamSettingsModel::SetDynamicSettingToSceneDefault") );
       
   712   return settingIndex;
       
   713   }
       
   714 
       
   715 
       
   716 
       
   717 // ---------------------------------------------------------------------------
       
   718 // CCamSettingsModel::LoadStaticSettingsL
       
   719 // Loads the static settings from shared data. Required to update
       
   720 // the settings whenever get foreground event, incase of external
       
   721 // changes to the settings.
       
   722 // Note that static settings cannot be loaded until the AppUi has been created,
       
   723 // as which settings to use is dependent on if app is embedded or not.
       
   724 // ---------------------------------------------------------------------------
       
   725 //
       
   726 void CCamSettingsModel::LoadStaticSettingsL( TBool aIsEmbedded )
       
   727     {
       
   728     PRINT(_L("Camera => CCamSettingsModel::LoadStaticSettingsL" ))
       
   729     iEmbedded = aIsEmbedded;
       
   730 
       
   731     // The model needs to register as an observer of changes in burst mode
       
   732     // activation, as burst mode limits some settings values.
       
   733     // The model registers with the AppUi which is created after the model.
       
   734     // Registration is done here so we can guarantee that the AppUi has 
       
   735     // been created.
       
   736     CCamAppUiBase* appUi = static_cast<CCamAppUiBase*>
       
   737                                             ( iEnv->AppUi() );
       
   738     appUi->AddBurstModeObserverL(  this );
       
   739 
       
   740     // Free all memory currently used by the static settings.
       
   741     UnloadStaticSettings();
       
   742     
       
   743     iStaticModel->ReadFromCenRepL(
       
   744                     static_cast<TInt>( ECamSettingItemUserSceneRangeMin ),
       
   745                     static_cast<TInt>( ECamSettingItemUserSceneRangeMax ),
       
   746                     iUserSceneSettings
       
   747                    );
       
   748     iStaticModel->LoadStaticSettingsL( aIsEmbedded );
       
   749 
       
   750     PRINT(_L("Camera <= CCamSettingsModel::LoadStaticSettingsL" ))
       
   751 
       
   752     }
       
   753 
       
   754 
       
   755 // ---------------------------------------------------------------------------
       
   756 // CCamSettingsModel::SaveSettingsL
       
   757 // Saves the static settings to the shared data ini file
       
   758 // ---------------------------------------------------------------------------
       
   759 //
       
   760 void CCamSettingsModel::SaveSettingsL() 
       
   761   {
       
   762   // This method is removed as we save to the CenRep whenever some setting
       
   763   // is changed directly .. refer to SaveStaticSettingsL method
       
   764   }
       
   765 
       
   766 
       
   767 // ---------------------------------------------------------------------------
       
   768 // 
       
   769 // ---------------------------------------------------------------------------
       
   770 //
       
   771 void
       
   772 CCamSettingsModel::SaveStaticSettingL( TCamSettingItemIds aSettingId )
       
   773   {
       
   774   PRINT1( _L("Camera => CCamSettingsModel::SaveStaticSettingL, setting:[%s]"), 
       
   775           KCamSettingItemNames[aSettingId] );
       
   776   TBool callStaticModel = ETrue;
       
   777   
       
   778     {
       
   779     // All the User Specific Settings are saved here in the CenRep
       
   780     // and the remaining static settings are handled in the static model
       
   781     RPointerArray<TIntSetting>* settingArray = 
       
   782           MapSettingItem2SettingsList( aSettingId );
       
   783 
       
   784     if( settingArray == &iUserSceneSettings )
       
   785         {
       
   786         callStaticModel = EFalse;
       
   787         TUint32 crKey = CCamStaticSettingsModel::MapSettingItem2CRKey( aSettingId, iEmbedded );
       
   788         iStaticModel->SaveCenRepItemL( aSettingId, crKey, *settingArray );
       
   789         }
       
   790     }
       
   791   if ( callStaticModel )
       
   792     {
       
   793     iStaticModel->SaveStaticSettingL( aSettingId );
       
   794     }
       
   795   PRINT( _L("Camera <= CCamSettingsModel::SaveStaticSettingL") ); 
       
   796   }
       
   797 
       
   798 
       
   799 // ---------------------------------------------------------------------------
       
   800 //
       
   801 // ---------------------------------------------------------------------------
       
   802 //
       
   803 RPointerArray<TIntSetting>*
       
   804 CCamSettingsModel::MapSettingItem2SettingsList( TCamSettingItemIds aSettingId )
       
   805   {
       
   806   PRINT( _L("Camera => CCamSettingsModel::MapSettingItem2SettingsList") );
       
   807 
       
   808   RPointerArray<TIntSetting>* array( NULL );
       
   809 
       
   810   if( ECamSettingItemUserSceneRangeMin < aSettingId
       
   811         && ECamSettingItemUserSceneRangeMax > aSettingId )
       
   812     {
       
   813     array = &iUserSceneSettings;
       
   814     }
       
   815   else if( ECamSettingItemDynamicPhotoRangeMin < aSettingId
       
   816         && ECamSettingItemDynamicPhotoRangeMax > aSettingId )
       
   817     {
       
   818     array = &iDynamicPhotoIntSettings;
       
   819     }
       
   820   else if( ECamSettingItemDynamicVideoRangeMin < aSettingId
       
   821         && ECamSettingItemDynamicVideoRangeMax > aSettingId )
       
   822     {
       
   823     array = &iDynamicVideoIntSettings;
       
   824     }
       
   825   else
       
   826     {
       
   827     array = iStaticModel->MapSettingItem2SettingsList( aSettingId );
       
   828     }
       
   829 
       
   830   PRINT( _L("Camera <= CCamSettingsModel::MapSettingItem2SettingsList") );
       
   831   return array;
       
   832   }
       
   833 
       
   834 
       
   835 // ---------------------------------------------------------------------------
       
   836 // CCamSettingsModel::~CCamSettingsModel
       
   837 // Destructor
       
   838 // ---------------------------------------------------------------------------
       
   839 //
       
   840 CCamSettingsModel::~CCamSettingsModel()
       
   841   {
       
   842   PRINT( _L("Camera => ~CCamSettingsModel") );
       
   843 
       
   844   UnLoadResources(); 
       
   845 
       
   846   iObservers.Reset();
       
   847   iObservers.Close();
       
   848 
       
   849   iSettingPreviews.ResetAndDestroy();
       
   850   iSettingPreviews.Close();
       
   851 
       
   852  
       
   853   iUserSceneSettings.ResetAndDestroy();
       
   854   iUserSceneSettings.Close();
       
   855   
       
   856   iUserSceneSettingsBackup.ResetAndDestroy();
       
   857   iUserSceneSettingsBackup.Close();
       
   858   
       
   859   iDynamicPhotoIntSettings.ResetAndDestroy();
       
   860   iDynamicPhotoIntSettings.Close();
       
   861   
       
   862   iDynamicPhotoIntSettingsBackup.ResetAndDestroy();
       
   863   iDynamicPhotoIntSettingsBackup.Close();
       
   864   
       
   865   iDynamicPhotoIntDefaults.Close();
       
   866   
       
   867   iDynamicVideoIntSettings.ResetAndDestroy();
       
   868   iDynamicVideoIntSettings.Close();
       
   869   
       
   870   iDynamicVideoIntSettingsBackup.ResetAndDestroy();
       
   871   iDynamicVideoIntSettingsBackup.Close();
       
   872     
       
   873   iDynamicVideoIntDefaults.Close();
       
   874 
       
   875   iPhotoScenes.ResetAndDestroy();
       
   876   iPhotoScenes.Close();
       
   877   
       
   878   iVideoScenes.ResetAndDestroy();
       
   879   iVideoScenes.Close();
       
   880   
       
   881   iQualityLevels.ResetAndDestroy();
       
   882   iQualityLevels.Close();
       
   883   
       
   884   iVideoResolutions.Close();
       
   885   iPhotoQualityLevels.Close();
       
   886   iPhotoResolutions.Close();
       
   887   
       
   888   if ( iStaticModel )
       
   889     {
       
   890     delete iStaticModel;
       
   891     iStaticModel = NULL;
       
   892     }
       
   893 
       
   894   PRINT( _L("Camera <= ~CCamSettingsModel") );
       
   895   }
       
   896   
       
   897 // ---------------------------------------------------------------------------
       
   898 // CCamSettingsModel::CCamSettingsModel
       
   899 // C++ constructor
       
   900 // ---------------------------------------------------------------------------
       
   901 //
       
   902 CCamSettingsModel::CCamSettingsModel( CCamConfiguration& aConfiguration ) 
       
   903   : iDynamicPhotoIntDefaults( KDynamicArrayGranularity ), 
       
   904   	iDynamicVideoIntDefaults( KDynamicArrayGranularity ), 
       
   905   	iEngineReadyForVideoPrepare( ETrue ), 
       
   906   	iConfiguration( aConfiguration )
       
   907     {
       
   908     PRINT( _L("Camera => CCamSettingsModel::CCamSettingsModel") );  
       
   909 
       
   910     // set up secondary camera defaults
       
   911     // these values are not stored in the shared data file because
       
   912     // they do not persist when the camera is changed or the app is closed
       
   913 
       
   914     iSecondaryCameraSettings.iVideoQuality 
       
   915     = iConfiguration.SecondaryCameraVideoQuality();
       
   916     iSecondaryCameraSettings.iPhotoQuality 
       
   917     = iConfiguration.SecondaryCameraImageQuality();
       
   918 
       
   919     // Check that configuration can provide us secondary camera qualities
       
   920     // If either of them is unavailable, all we can do is panic
       
   921     PRINT( _L("Camera <> Checking secondary camera qualities") );  
       
   922     __ASSERT_ALWAYS( iSecondaryCameraSettings.iVideoQuality > 0, 
       
   923             CamPanic( ECamPanicSecondaryQualityMissing ) );
       
   924 
       
   925     __ASSERT_ALWAYS( iSecondaryCameraSettings.iPhotoQuality > 0, 
       
   926             CamPanic( ECamPanicSecondaryQualityMissing ) );
       
   927 
       
   928     // Check that configuration can provide us a MMS quality.
       
   929     // If not available, all we can do is panic. MMS quality is
       
   930     // needed in embedded mode.
       
   931     PRINT( _L("Camera <> Checking MMS quality") ); 
       
   932     __ASSERT_ALWAYS( iConfiguration.MmsImageQuality() > 0, 
       
   933                       CamPanic( ECamPanicMMSQualityMissing ) ); 
       
   934                       
       
   935                       
       
   936     PRINT( _L("Camera <= CCamSettingsModel::CCamSettingsModel") );                        
       
   937     }
       
   938 
       
   939 
       
   940 
       
   941 // ---------------------------------------------------------------------------
       
   942 // CCamSettingsModel::ConstructL
       
   943 // Symbian OS 2nd phase constructor
       
   944 // ---------------------------------------------------------------------------
       
   945 //
       
   946 void CCamSettingsModel::ConstructL()
       
   947     {
       
   948     PRINT( _L("Camera => CCamSettingsModel::ConstructL"))
       
   949     // Create reference to the CEikonEnv object, since it is used alot.
       
   950     iEnv = CEikonEnv::Static();
       
   951 
       
   952     LoadResourcesL(); 
       
   953                 
       
   954     iStaticModel = CCamStaticSettingsModel::NewL( iConfiguration );
       
   955     
       
   956     iUiConfigManager = iStaticModel->UiConfigManagerPtr();
       
   957     
       
   958     if ( !iUiConfigManager )CamPanic( ECamPanicNullPointer );
       
   959     
       
   960     PRINT( _L("Camera => CCamSettingsModel::ConstructL create respository"))
       
   961 
       
   962     // Load settings.
       
   963     LoadSettingsL();
       
   964 
       
   965     // Load the variant flags from the ini file
       
   966     ReadVariantFlagsL();
       
   967     
       
   968     // Load flag that specifies whether the engine should be updated with
       
   969     // settings after an engine Prepare..() call.
       
   970     // Create resource reader for reading photo static settings
       
   971     TResourceReader reader;
       
   972     iEnv->CreateResourceReaderLC( reader, R_CAM_ENGINE_UPDATE );
       
   973     iUpdateAfterPrepare = reader.ReadInt16();   
       
   974     // Pop resource reader.
       
   975     CleanupStack::PopAndDestroy();  
       
   976 
       
   977     // read in video quality levels
       
   978     TInt i;
       
   979     
       
   980     const TInt nVidQualities( iConfiguration.NumVideoQualities() );
       
   981     for ( i=0; i < nVidQualities; i++ )
       
   982         {
       
   983         TVideoQualitySettings set = iConfiguration.VideoQuality( i );
       
   984         CCamVideoQualityLevel* lev = CCamVideoQualityLevel::NewL( set );
       
   985         CleanupStack::PushL( lev );
       
   986         User::LeaveIfError( iQualityLevels.Append( lev ) );
       
   987         CleanupStack::Pop( lev );
       
   988         }                
       
   989 
       
   990     // read in (supported) video resolutions
       
   991     TResourceReader videoResReader;
       
   992     iEnv->CreateResourceReaderLC( videoResReader, R_CAM_VIDEO_RESOLUTION_ARRAY );
       
   993     
       
   994     // get array of supported values
       
   995     RArray<TInt> supportedVideoRes;
       
   996     CleanupClosePushL( supportedVideoRes );
       
   997     iConfiguration.GetPsiIntArrayL( ECamPsiSupportedVideoResolutions, supportedVideoRes );
       
   998 
       
   999     TInt numLevels = videoResReader.ReadInt16();
       
  1000 
       
  1001     for( i = 0; i < numLevels; i++ )
       
  1002         {
       
  1003         TSize videoRes;
       
  1004         videoRes.iWidth = videoResReader.ReadInt16();
       
  1005         videoRes.iHeight = videoResReader.ReadInt16();
       
  1006 
       
  1007         User::LeaveIfError( iVideoResolutions.Append( videoRes ) );   
       
  1008         }
       
  1009         
       
  1010     // Close array of support vid resolutions
       
  1011     CleanupStack::PopAndDestroy( &supportedVideoRes );
       
  1012 
       
  1013     // Pop resource reader.
       
  1014     CleanupStack::PopAndDestroy();
       
  1015 
       
  1016 
       
  1017     const TInt numQualities( iConfiguration.NumImageQualities() );
       
  1018     for( i=0; i<numQualities; i++ )
       
  1019       {
       
  1020       User::LeaveIfError( 
       
  1021         iPhotoQualityLevels.Append( iConfiguration.ImageQuality( i ) ) );        
       
  1022       }      
       
  1023 
       
  1024     // read in photo resolutions
       
  1025     TResourceReader photoResReader;
       
  1026     iEnv->CreateResourceReaderLC( photoResReader, R_CAM_PHOTO_RESOLUTION_ARRAY );
       
  1027     numLevels = photoResReader.ReadInt16();
       
  1028 
       
  1029     // get array of supported values
       
  1030     RArray<TInt> supportedStillRes;
       
  1031     CleanupClosePushL( supportedStillRes );
       
  1032     
       
  1033     iConfiguration.GetPsiIntArrayL( ECamPsiSupportedStillResolutions, supportedStillRes ); 
       
  1034 
       
  1035     for( i = 0; i < numLevels; i++ )  
       
  1036         {
       
  1037         TSize photoRes;
       
  1038         photoRes.iWidth = photoResReader.ReadInt16();
       
  1039         photoRes.iHeight = photoResReader.ReadInt16();
       
  1040 
       
  1041         User::LeaveIfError( iPhotoResolutions.Append( photoRes ) );
       
  1042             
       
  1043         }        
       
  1044         
       
  1045     iPreviousFaceTrack = ECamSettOn;
       
  1046     iPreviousSceneMode = ECamSceneAuto;
       
  1047     // Close array of support photo resolutions
       
  1048     CleanupStack::PopAndDestroy( &supportedStillRes );
       
  1049         
       
  1050     // Pop resource reader.
       
  1051     CleanupStack::PopAndDestroy();
       
  1052     
       
  1053     PRINT( _L("Camera <= CCamSettingsModel::ConstructL"))
       
  1054     }
       
  1055 
       
  1056 
       
  1057 
       
  1058 
       
  1059 // ---------------------------------------------------------------------------
       
  1060 // NotifyObservers
       
  1061 //
       
  1062 // Notify setting model observers, that a setting item value has changed.
       
  1063 // Overload for integer setting items.
       
  1064 // ---------------------------------------------------------------------------
       
  1065 //
       
  1066 void 
       
  1067 CCamSettingsModel::NotifyObservers( TCamSettingItemIds aSettingId, 
       
  1068                                     TInt               aSettingValue )
       
  1069   {
       
  1070   PRINT1( _L("Camera => CCamSettingsModel::NotifyObservers, observers:%d"), iObservers.Count() );
       
  1071   for( TInt i = 0; i < iObservers.Count(); i++ )
       
  1072     {
       
  1073     TRAP_IGNORE( iObservers[i]->IntSettingChangedL( aSettingId, 
       
  1074                                                     aSettingValue ) );
       
  1075     } 
       
  1076   PRINT ( _L("Camera <= CCamSettingsModel::NotifyObservers") );
       
  1077   }
       
  1078 
       
  1079 // ---------------------------------------------------------------------------
       
  1080 // NotifyObservers
       
  1081 //
       
  1082 // Notify setting model observers, that a setting item value has changed.
       
  1083 // Overload for text setting items.
       
  1084 // ---------------------------------------------------------------------------
       
  1085 //
       
  1086 void 
       
  1087 CCamSettingsModel::NotifyObservers( TCamSettingItemIds aSettingId, 
       
  1088                                     const TDesC&       aSettingValue )
       
  1089   {
       
  1090   for( TInt i = 0; i < iObservers.Count(); i++ )
       
  1091     {
       
  1092     TRAP_IGNORE( iObservers[i]->TextSettingChangedL( aSettingId, 
       
  1093                                                      aSettingValue ) );
       
  1094     } 
       
  1095   }
       
  1096 
       
  1097 
       
  1098 // ---------------------------------------------------------------------------
       
  1099 // ReadVariantFlagsL
       
  1100 //
       
  1101 // Read Central Repository key values in KCRUidCameraappVariant repository.
       
  1102 // ---------------------------------------------------------------------------
       
  1103 //
       
  1104 void 
       
  1105 CCamSettingsModel::ReadVariantFlagsL()
       
  1106   {
       
  1107   TInt crValue( 0 );
       
  1108   CRepository* cr = CRepository::NewLC( KCRUidCameraappVariant );
       
  1109 
       
  1110   // Get variant info general flags
       
  1111   User::LeaveIfError( cr->Get( KCamCrVariantFlags, crValue ) );
       
  1112   iVariantInfo.iFlags = crValue;
       
  1113 
       
  1114   // Get 'time lapse enabled' flag
       
  1115   User::LeaveIfError( cr->Get( KCamCrTimeLapseSupport, crValue ) );
       
  1116 
       
  1117   iVariantInfo.iTimeLapseSupport = (KCamCrTimeLapseIsSupported == crValue)
       
  1118                                  ? ECamSupportOn
       
  1119                                  : ECamSupportOff;
       
  1120 
       
  1121   // Get 'app always running' flag
       
  1122   User::LeaveIfError( cr->Get( KCamCrAppAlwaysRunning, crValue ) );
       
  1123   iVariantInfo.iAlwaysOnSupport = (KCamCrAppAlwaysRunningIsOn == crValue)
       
  1124                                 ? ECamSupportOn
       
  1125                                 : ECamSupportOff;
       
  1126 
       
  1127 
       
  1128   // Get Public Release version
       
  1129   User::LeaveIfError( cr->Get( KCamCrVersionMajor, crValue ) );
       
  1130   iVariantInfo.iVersion.iMajor = (TInt8) crValue;
       
  1131 
       
  1132   User::LeaveIfError( cr->Get( KCamCrVersionMinor, crValue ) );
       
  1133   iVariantInfo.iVersion.iMinor = (TInt8) crValue;
       
  1134 
       
  1135   User::LeaveIfError( cr->Get( KCamCrBuildNumber, crValue ) );
       
  1136   iVariantInfo.iVersion.iBuild = (TInt16) crValue;
       
  1137 
       
  1138   CleanupStack::PopAndDestroy( cr );  
       
  1139   }
       
  1140 
       
  1141 
       
  1142 // ---------------------------------------------------------------------------
       
  1143 // CCamSettingsModel::SettingIsForEngine
       
  1144 // Returns whether a particular setting is an engine setting, or not.
       
  1145 // ---------------------------------------------------------------------------
       
  1146 //
       
  1147 TBool CCamSettingsModel::SettingIsForEngine( TInt aSettingItem )
       
  1148     {
       
  1149     if ( ( aSettingItem == ECamSettingItemPhotoQuality ) ||
       
  1150          ( aSettingItem == ECamSettingItemVideoAudioRec ) ||
       
  1151          ( aSettingItem == ECamSettingItemVideoResolution ) ||
       
  1152          ( aSettingItem == ECamSettingItemVideoFileType ) || 
       
  1153          ( aSettingItem == ECamSettingItemVideoQuality ) )
       
  1154         {
       
  1155         return ETrue;
       
  1156         }
       
  1157     else
       
  1158         {
       
  1159         return EFalse;
       
  1160         }
       
  1161     }
       
  1162 
       
  1163 
       
  1164 // ---------------------------------------------------------------------------
       
  1165 // CCamSettingsModel::SearchInSettingsListFor
       
  1166 // Searches in a settings list for a particular setting item.
       
  1167 // ---------------------------------------------------------------------------
       
  1168 //
       
  1169 TInt CCamSettingsModel::SearchInSettingsListFor
       
  1170 ( const RPointerArray<TIntSetting>& aSettingsList, TInt aSettingItem ) const
       
  1171     {
       
  1172     TInt count = aSettingsList.Count();
       
  1173     PRINT2( _L("Camera => CCamSettingsModel::SearchInSettingsListFor item (%d) count (%d)"), aSettingItem, count)
       
  1174     TInt i;
       
  1175     for ( i = 0; i < count; ++i )
       
  1176         {
       
  1177         if ( aSettingsList[i]->iItemId == aSettingItem )
       
  1178             {
       
  1179             return i;
       
  1180             }
       
  1181         }
       
  1182 
       
  1183     return KErrNotFound;
       
  1184     }
       
  1185 
       
  1186 // ---------------------------------------------------------------------------
       
  1187 // CCamSettingsModel::FindSceneInSceneList
       
  1188 // Finds a scene in a particular scene list. 
       
  1189 // ---------------------------------------------------------------------------
       
  1190 //
       
  1191 TInt CCamSettingsModel::FindSceneInSceneList
       
  1192 ( TInt aSceneItemId, const RPointerArray<TSceneData >& aSceneList ) const
       
  1193     {
       
  1194     TInt count = aSceneList.Count();
       
  1195     TInt i;
       
  1196     for ( i = 0; i < count; ++i )
       
  1197         {
       
  1198         if ( aSceneList[i]->iSceneId == aSceneItemId )
       
  1199             {
       
  1200             return i;
       
  1201             }
       
  1202         }
       
  1203 
       
  1204     return KErrNotFound;
       
  1205     }
       
  1206 
       
  1207 // ---------------------------------------------------------------------------
       
  1208 // CCamSettingsModel::UserSceneHasChangedL
       
  1209 // Handles a change in the value for the user scene setting.
       
  1210 // That is, it updates the rest of the user setings.
       
  1211 // ---------------------------------------------------------------------------
       
  1212 //
       
  1213 void CCamSettingsModel::UserSceneHasChangedL( TInt aSceneId, TBool aActivate )
       
  1214     {
       
  1215 
       
  1216     // Set the user setup flash setting to that of the new scene.
       
  1217     TInt sceneFlash = DefaultSettingValueForScene( aSceneId, ECamSettingItemSceneFlashMode );
       
  1218     SetIntegerSettingValueL( ECamSettingItemUserSceneFlash, sceneFlash );
       
  1219 
       
  1220     // Set the user setup whitebalance to that of the new scene
       
  1221     TInt whiteBal = DefaultSettingValueForScene( aSceneId, ECamSettingItemSceneAWBMode );
       
  1222     SetIntegerSettingValueL( ECamSettingItemUserSceneWhitebalance, whiteBal );
       
  1223 
       
  1224     // Set the user setup sharpness to that of the new scene
       
  1225     TInt sharpness = DefaultSettingValueForScene( aSceneId, ECamSettingItemSceneSharpness );
       
  1226     SetIntegerSettingValueL( ECamSettingItemUserSceneImageSharpness, sharpness );
       
  1227 
       
  1228     // Set the user setup contrast to that of the new scene
       
  1229     TInt contrast = DefaultSettingValueForScene( aSceneId, ECamSettingItemSceneContrast );
       
  1230     SetIntegerSettingValueL( ECamSettingItemUserSceneContrast, contrast );
       
  1231     
       
  1232     // Set the scene
       
  1233     TInt settingIndex = SearchInSettingsListFor( iUserSceneSettings, 
       
  1234         ECamSettingItemUserSceneBasedOnScene );
       
  1235     iUserSceneSettings[settingIndex]->iValueId = aSceneId;
       
  1236 
       
  1237     // Save the new values.
       
  1238     SaveSettingsL();
       
  1239 
       
  1240     if ( aActivate )
       
  1241         {
       
  1242         // Activate user scene settings.
       
  1243         ActivateUserSceneSettingsL();
       
  1244         }
       
  1245     }
       
  1246 
       
  1247 // ---------------------------------------------------------------------------
       
  1248 // CCamSettingsModel::PhotoSceneHasChangedL
       
  1249 // Handles a change in the value for the photo scene setting.
       
  1250 // That is, it updates the rest of the photo dynamic setings.
       
  1251 // ---------------------------------------------------------------------------
       
  1252 //
       
  1253 void CCamSettingsModel::PhotoSceneHasChangedL( TInt aSceneId )
       
  1254     {
       
  1255     // If the scene has changed to a scene other than the "User" scene
       
  1256     // set capture setup values to defaults and the flash to scene flash.
       
  1257     if ( aSceneId != ECamSceneUser )
       
  1258         {
       
  1259         // Set all the photo capture setup values to their defaults, except
       
  1260         // for the scene setting.
       
  1261         TInt settingsCount = iDynamicPhotoIntSettings.Count();
       
  1262         TInt i;
       
  1263         for ( i = 0; i < settingsCount; ++i )
       
  1264             {
       
  1265             // If the setting item is not the scene change it's value, 
       
  1266             // and update the engine
       
  1267             if ( iDynamicPhotoIntSettings[i]->iItemId != ECamSettingItemDynamicPhotoScene )
       
  1268                 {
       
  1269                 SetIntegerSettingValueL( iDynamicPhotoIntSettings[i]->iItemId, 
       
  1270                     iDynamicPhotoIntDefaults[i] );
       
  1271                 }
       
  1272             }
       
  1273 
       
  1274         // Set the capture setup flash setting to that of the new scene.
       
  1275         TInt sceneFlash = DefaultSettingValueForScene( aSceneId, ECamSettingItemSceneFlashMode );
       
  1276         SetIntegerSettingValueL( ECamSettingItemDynamicPhotoFlash, sceneFlash );
       
  1277 
       
  1278         // Set the user setup whitebalance to that of the new scene
       
  1279         TInt whiteBal = DefaultSettingValueForScene( aSceneId, ECamSettingItemSceneAWBMode );
       
  1280         SetIntegerSettingValueL( ECamSettingItemDynamicPhotoWhiteBalance, whiteBal );
       
  1281 
       
  1282         // Set the user setup sharpness to that of the new scene
       
  1283         TInt sharpness = DefaultSettingValueForScene( aSceneId, ECamSettingItemSceneSharpness );
       
  1284         SetIntegerSettingValueL( ECamSettingItemDynamicPhotoImageSharpness, sharpness );
       
  1285 
       
  1286         // Set the user setup contrast to that of the new scene
       
  1287         TInt contrast = DefaultSettingValueForScene( aSceneId, ECamSettingItemSceneContrast );
       
  1288         SetIntegerSettingValueL( ECamSettingItemDynamicPhotoBrightness, contrast );
       
  1289                  
       
  1290 	    if ( iUiConfigManager->IsFaceTrackingSupported() ) // FT supported
       
  1291          {      
       
  1292          if ( ECamSceneScenery == aSceneId || ECamSceneSports == aSceneId )
       
  1293             {
       
  1294             if ( ECamSceneScenery != iPreviousSceneMode && ECamSceneSports != iPreviousSceneMode ) // <- DATAMAKE
       
  1295                {	
       
  1296                iPreviousFaceTrack = TCamSettingsOnOff( IntegerSettingValue( ECamSettingItemFaceTracking ) );	
       
  1297                }
       
  1298             SetIntegerSettingValueL( ECamSettingItemFaceTracking, ECamSettOff );	
       
  1299             }
       
  1300          else if ( ( ECamSceneScenery == iPreviousSceneMode ||
       
  1301                      ECamSceneSports == iPreviousSceneMode ) &&
       
  1302                    ( ECamSettOff == TCamSettingsOnOff( IntegerSettingValue( ECamSettingItemFaceTracking ) ) ) )
       
  1303              {
       
  1304              SetIntegerSettingValueL( ECamSettingItemFaceTracking, iPreviousFaceTrack );
       
  1305              iPreviousFaceTrack = TCamSettingsOnOff( IntegerSettingValue( ECamSettingItemFaceTracking ) );
       
  1306              CCamAppUiBase* appUi = static_cast<CCamAppUiBase*>( iEnv->AppUi() );
       
  1307              TRAP_IGNORE( appUi->APHandler()->UpdateActivePaletteL() );
       
  1308              }
       
  1309          }              
       
  1310 
       
  1311         // Update the engine with the scene settings.
       
  1312         //UpdateEngineWithSceneSettingsL( iPhotoScenes, aSceneId );
       
  1313         }
       
  1314 
       
  1315     // Otherwise, activate the user scene settings
       
  1316     else
       
  1317         {
       
  1318         ActivateUserSceneSettingsL();
       
  1319         }
       
  1320     iPreviousSceneMode = TCamSceneId( aSceneId ); // store scene mode setting
       
  1321     }
       
  1322 
       
  1323 // ---------------------------------------------------------------------------
       
  1324 // CCamSettingsModel::CopyUserSceneSettingToCaptureSettingL
       
  1325 // Copies a user scene setting across to the capture setup settings.
       
  1326 // ---------------------------------------------------------------------------
       
  1327 //
       
  1328 void CCamSettingsModel::CopyUserSceneSettingToCaptureSettingL( TInt aSettingItem )
       
  1329     {
       
  1330     // Determine the indexes of the user scene setting and 
       
  1331     // the corresponding photo capture setting.
       
  1332 
       
  1333     // ...determine the index of the user scene setting
       
  1334     TInt userIndex = SearchInSettingsListFor( iUserSceneSettings,
       
  1335         aSettingItem );
       
  1336 
       
  1337     // ...determine the index of the corresponding photo capture setting
       
  1338     TInt capIndex = 0;
       
  1339     switch ( aSettingItem )
       
  1340         {
       
  1341         case ECamSettingItemUserSceneWhitebalance:
       
  1342             {
       
  1343             capIndex = SearchInSettingsListFor( iDynamicPhotoIntSettings,
       
  1344                 ECamSettingItemDynamicPhotoWhiteBalance );
       
  1345             }
       
  1346             break;
       
  1347 
       
  1348         case ECamSettingItemUserSceneExposure:
       
  1349             {
       
  1350             capIndex = SearchInSettingsListFor( iDynamicPhotoIntSettings,
       
  1351                 ECamSettingItemDynamicPhotoExposure );
       
  1352             }
       
  1353             break;
       
  1354 
       
  1355         case ECamSettingItemUserSceneColourFilter:
       
  1356             {
       
  1357             capIndex = SearchInSettingsListFor( iDynamicPhotoIntSettings,
       
  1358                 ECamSettingItemDynamicPhotoColourFilter );
       
  1359             }
       
  1360             break;
       
  1361         case ECamSettingItemUserSceneFlash:
       
  1362             {
       
  1363             capIndex = SearchInSettingsListFor( iDynamicPhotoIntSettings,
       
  1364                 ECamSettingItemDynamicPhotoFlash );
       
  1365             }
       
  1366             break;
       
  1367 
       
  1368         case ECamSettingItemUserSceneBrightness:
       
  1369             {
       
  1370             capIndex = SearchInSettingsListFor( iDynamicPhotoIntSettings,
       
  1371                 ECamSettingItemDynamicPhotoBrightness );
       
  1372             }
       
  1373             break;
       
  1374         case ECamSettingItemUserSceneContrast:
       
  1375             {
       
  1376             capIndex = SearchInSettingsListFor( iDynamicPhotoIntSettings,
       
  1377                 ECamSettingItemDynamicPhotoContrast );
       
  1378             }
       
  1379             break;
       
  1380 
       
  1381         case ECamSettingItemUserSceneImageSharpness:
       
  1382             {
       
  1383             capIndex = SearchInSettingsListFor( iDynamicPhotoIntSettings,
       
  1384                 ECamSettingItemDynamicPhotoImageSharpness );
       
  1385             }
       
  1386             break;
       
  1387 
       
  1388         case ECamSettingItemUserSceneLightSensitivity:
       
  1389             {
       
  1390             capIndex = SearchInSettingsListFor(iDynamicPhotoIntSettings,
       
  1391                 ECamSettingItemDynamicPhotoLightSensitivity );
       
  1392             }
       
  1393             break;
       
  1394         default:
       
  1395         	PRINT( _L("Camera => CCamSettingsModel::ECamPanicUnknownSettingItem 6" ))
       
  1396             CamPanic( ECamPanicUnknownSettingItem );
       
  1397             break;
       
  1398         }
       
  1399 
       
  1400     // Copy the user scene setting across to the photo capture setting.
       
  1401     iDynamicPhotoIntSettings[capIndex]->iValueId = 
       
  1402         iUserSceneSettings[userIndex]->iValueId;
       
  1403 
       
  1404     }
       
  1405 
       
  1406 
       
  1407 // ---------------------------------------------------------------------------
       
  1408 // CCamSettingsModel::ActivateUserSceneSettings
       
  1409 // Activates the current user scene settings.
       
  1410 // ---------------------------------------------------------------------------
       
  1411 //
       
  1412 void CCamSettingsModel::ActivateUserSceneSettingsL()
       
  1413     {
       
  1414     PRINT( _L("Camera => CCamSettingsModel::ActivateUserSceneSettingsL"))
       
  1415     // Copy all the user scene settings to capture settings.
       
  1416     CopyUserSceneSettingToCaptureSettingL( 
       
  1417         ECamSettingItemUserSceneWhitebalance );
       
  1418     CopyUserSceneSettingToCaptureSettingL( 
       
  1419         ECamSettingItemUserSceneExposure );
       
  1420     CopyUserSceneSettingToCaptureSettingL( 
       
  1421         ECamSettingItemUserSceneColourFilter );
       
  1422     CopyUserSceneSettingToCaptureSettingL( 
       
  1423         ECamSettingItemUserSceneFlash );
       
  1424     CopyUserSceneSettingToCaptureSettingL( 
       
  1425         ECamSettingItemUserSceneBrightness );
       
  1426     CopyUserSceneSettingToCaptureSettingL( 
       
  1427         ECamSettingItemUserSceneContrast );
       
  1428     CopyUserSceneSettingToCaptureSettingL( 
       
  1429         ECamSettingItemUserSceneImageSharpness );
       
  1430 
       
  1431     if ( iUiConfigManager->IsISOSupported() )
       
  1432         {
       
  1433         CopyUserSceneSettingToCaptureSettingL(
       
  1434             ECamSettingItemUserSceneLightSensitivity );
       
  1435         }
       
  1436 
       
  1437     // Handled in appcontroller
       
  1438     //UpdateEngineWithPhotoCaptureSetupSettingsL();
       
  1439     PRINT( _L("Camera <= CCamSettingsModel::ActivateUserSceneSettingsL"))			
       
  1440     }
       
  1441 
       
  1442 // ---------------------------------------------------------------------------
       
  1443 // CCamSettingsModel::VideoSceneHasChangedL
       
  1444 // Handles a change in the value for the video scene setting.
       
  1445 // That is, it updates the rest of the video dynamic setings.
       
  1446 // ---------------------------------------------------------------------------
       
  1447 //
       
  1448 void CCamSettingsModel::VideoSceneHasChangedL( TInt /*aSettingValue*/ )
       
  1449     {
       
  1450     // Set all the video capture setup values to their defaults,
       
  1451     // except for the scene setting.
       
  1452     TInt settingsCount = iDynamicVideoIntSettings.Count();
       
  1453     TInt i;
       
  1454     for ( i = 0; i < settingsCount; ++i )
       
  1455         {
       
  1456         // If the setting item is not the scene change it's value.
       
  1457         if ( iDynamicVideoIntSettings[i]->iItemId != ECamSettingItemDynamicVideoScene )
       
  1458             {
       
  1459             SetIntegerSettingValueL( iDynamicVideoIntSettings[i]->iItemId, 
       
  1460                 iDynamicVideoIntDefaults[i] );
       
  1461             }
       
  1462         }
       
  1463 
       
  1464     // Update the engine with the scene settings.
       
  1465     //UpdateEngineWithSceneSettingsL( iVideoScenes, aSettingValue );
       
  1466     }
       
  1467 
       
  1468 
       
  1469 // ---------------------------------------------------------------------------
       
  1470 // CCamSettingsModel::PhotoSceneMaximumQuality
       
  1471 // Returns the highest allowed quality for the current photo scene.
       
  1472 // ---------------------------------------------------------------------------
       
  1473 //
       
  1474 TInt CCamSettingsModel::PhotoSceneMaximumQuality( TInt aSceneId ) const
       
  1475     {
       
  1476      // If the scene is the user scene return the maximum amount.
       
  1477      // This is to be changed once user scene has been implemented.
       
  1478      if ( aSceneId == ECamSceneUser )
       
  1479          {
       
  1480          // Get the scene that the user scene is based on and
       
  1481          // get the maximum resolution for this scene.
       
  1482          TInt settingIndex = SearchInSettingsListFor( 
       
  1483             iUserSceneSettings, ECamSettingItemUserSceneBasedOnScene );
       
  1484          TInt sceneId = iUserSceneSettings[settingIndex]->iValueId;
       
  1485 
       
  1486          return PhotoSceneMaximumQuality( sceneId );
       
  1487          }
       
  1488 
       
  1489     // Find the index to the scene.
       
  1490     TInt sceneIndex = FindSceneInSceneList( aSceneId, iPhotoScenes );
       
  1491     // Search for the maximum resolution item in this scene's item list.
       
  1492     TInt settingsCount = iPhotoScenes[sceneIndex]->iSettings.Count();
       
  1493     TInt i;
       
  1494     for ( i = 0; i < settingsCount; ++i )
       
  1495         {
       
  1496         if ( iPhotoScenes[sceneIndex]->iSettings[i]->iItemId == ECamSettingItemSceneMaxRes )
       
  1497             {
       
  1498             return iPhotoScenes[sceneIndex]->iSettings[i]->iValueId;
       
  1499             }
       
  1500         }
       
  1501 	PRINT( _L("Camera => CCamSettingsModel::ECamPanicUnknownSettingItem 7" ))
       
  1502     CamPanic( ECamPanicUnknownSettingItem );
       
  1503     // Remove warning
       
  1504     return KErrNotFound;  
       
  1505     }
       
  1506 
       
  1507 
       
  1508 // ---------------------------------------------------------------------------
       
  1509 // CCamSettingsModel::CurrentPhotoQualityValue
       
  1510 // Returns the current photo quality setting.
       
  1511 // ---------------------------------------------------------------------------
       
  1512 //
       
  1513 TInt CCamSettingsModel::CurrentPhotoQualityValue() const
       
  1514     {
       
  1515     return iStaticModel->IntegerSettingValue( ECamSettingItemPhotoQuality );
       
  1516     }
       
  1517     
       
  1518 // ---------------------------------------------------------------------------
       
  1519 // CCamSettingsModel::PhotoQualityArrayIndex
       
  1520 // Returns the photo quailty array index of a specified photo quality id
       
  1521 // ---------------------------------------------------------------------------
       
  1522 //
       
  1523 
       
  1524 TInt CCamSettingsModel::PhotoQualityArrayIndex(TInt aPhotoQualityId) const
       
  1525     {
       
  1526     for(TInt i=0;i<iPhotoQualityLevels.Count();i++)
       
  1527         {
       
  1528         if(iPhotoQualityLevels[i].iPhotoQualityId == aPhotoQualityId)
       
  1529             {
       
  1530             return i;
       
  1531             }
       
  1532         }
       
  1533     return KErrNotFound;        
       
  1534     }
       
  1535 
       
  1536 // ---------------------------------------------------------------------------
       
  1537 // CCamSettingsModel::CurrentPhotoCompression
       
  1538 // Returns the current photo quality level (value 1-100).
       
  1539 // ---------------------------------------------------------------------------
       
  1540 //
       
  1541 TInt CCamSettingsModel::CurrentPhotoCompression() const
       
  1542     {
       
  1543     TInt currentQualityLevel = PhotoQualityArrayIndex(CurrentPhotoQualityValue());
       
  1544 
       
  1545     if ( currentQualityLevel != KErrNotFound )
       
  1546         {
       
  1547         // Get the compression level for the current quality setting.
       
  1548         TCamPhotoQualitySetting quality = 
       
  1549             iPhotoQualityLevels[currentQualityLevel];
       
  1550         TInt compressionLevel = quality.iQualityLevel;
       
  1551         return compressionLevel;
       
  1552         }
       
  1553 
       
  1554 	PRINT( _L("Camera => CCamSettingsModel::ECamPanicUnknownSettingItem 10" ))
       
  1555     CamPanic( ECamPanicUnknownSettingItem );
       
  1556     // Remove warning
       
  1557     return KErrNotFound;
       
  1558     }
       
  1559 
       
  1560 
       
  1561 // ---------------------------------------------------------------------------
       
  1562 // CCamSettingsModel::CurrentPhotoResolution
       
  1563 // Returns the photo resolution from current Settings
       
  1564 // ---------------------------------------------------------------------------
       
  1565 //
       
  1566 TCamPhotoSizeId CCamSettingsModel::CurrentPhotoResolution() const
       
  1567     {
       
  1568     return PhotoResolution( CurrentPhotoQualityValue() );
       
  1569     }
       
  1570 
       
  1571 // ---------------------------------------------------------------------------
       
  1572 // CCamSettingsModel::PhotoResolution
       
  1573 // Returns the photo resolution for a particular quality index
       
  1574 // ---------------------------------------------------------------------------
       
  1575 //
       
  1576 TCamPhotoSizeId CCamSettingsModel::PhotoResolution( TInt aQualityIndex ) const
       
  1577     {
       
  1578     TInt qualityValue = PhotoQualityArrayIndex( aQualityIndex );
       
  1579 
       
  1580     if ( qualityValue != KErrNotFound )
       
  1581         {
       
  1582         TCamPhotoQualitySetting quality = 
       
  1583                 iPhotoQualityLevels[qualityValue];
       
  1584                 
       
  1585         return iConfiguration.MapResolutionToPhotoSize( quality.iPhotoResolution );
       
  1586         }
       
  1587 
       
  1588 	PRINT( _L("Camera => CCamSettingsModel::ECamPanicUnknownSettingItem 11" ))
       
  1589     CamPanic( ECamPanicUnknownSettingItem );
       
  1590     // Remove warning
       
  1591     return ECamPhotoSizeVGA; // We can never get here anyway
       
  1592     }
       
  1593 
       
  1594 // ---------------------------------------------------------------------------
       
  1595 // CCamSettingsModel::StorePrimaryCameraSettingsL
       
  1596 // Stores the primary camera settings so they can be reapplied when
       
  1597 // changing from front to back camera
       
  1598 // ---------------------------------------------------------------------------
       
  1599 //
       
  1600 void CCamSettingsModel::StorePrimaryCameraSettingsL()
       
  1601     {
       
  1602     PRINT( _L("Camera => CCamSettingsModel::StorePrimaryCameraSettingsL"))
       
  1603     iStaticModel->StorePrimaryCameraSettingsL();
       
  1604     CopySettingsL(iDynamicPhotoIntSettings, iDynamicPhotoIntSettingsBackup);
       
  1605     CopySettingsL(iDynamicVideoIntSettings, iDynamicVideoIntSettingsBackup);
       
  1606     CopySettingsL(iUserSceneSettings, iUserSceneSettingsBackup);
       
  1607     }
       
  1608 
       
  1609 // ---------------------------------------------------------------------------
       
  1610 // CCamSettingsModel::RestorePrimaryCameraSettingsL
       
  1611 // Restores the primary camera settings when
       
  1612 // changing from front to back camera
       
  1613 // ---------------------------------------------------------------------------
       
  1614 //
       
  1615 void CCamSettingsModel::RestorePrimaryCameraSettingsL()
       
  1616     {
       
  1617     // set the stored primary camera settings
       
  1618     iStaticModel->RestorePrimaryCameraSettingsL();
       
  1619     CopySettingsL(iDynamicPhotoIntSettingsBackup, iDynamicPhotoIntSettings, ETrue);
       
  1620     CopySettingsL(iDynamicVideoIntSettingsBackup, iDynamicVideoIntSettings, ETrue);
       
  1621     CopySettingsL(iUserSceneSettingsBackup, iUserSceneSettings, ETrue);
       
  1622     }
       
  1623 
       
  1624 // ---------------------------------------------------------------------------
       
  1625 // VariantInfo
       
  1626 // ---------------------------------------------------------------------------
       
  1627 //
       
  1628 const TCamVariantInfo& 
       
  1629 CCamSettingsModel::VariantInfo()
       
  1630   {
       
  1631   if( 0 > iVariantInfo.iFlags )
       
  1632     {
       
  1633     TRAP_IGNORE( ReadVariantFlagsL() );
       
  1634     }
       
  1635   return iVariantInfo;
       
  1636   }
       
  1637 
       
  1638 
       
  1639 // ---------------------------------------------------------------------------
       
  1640 // CCamSettingsModel::ResetRepository
       
  1641 // Reset Camera central repository file
       
  1642 // ---------------------------------------------------------------------------
       
  1643 //   
       
  1644  void CCamSettingsModel::ResetRepository()
       
  1645  	{
       
  1646  	iStaticModel->ResetRepository();
       
  1647  	}
       
  1648 
       
  1649 
       
  1650 
       
  1651 
       
  1652 // ===========================================================================
       
  1653 // From base class MCamSettingPreviewHandler
       
  1654 
       
  1655 // ---------------------------------------------------------------------------
       
  1656 //   
       
  1657 // ---------------------------------------------------------------------------
       
  1658 //
       
  1659 void 
       
  1660 CCamSettingsModel::ActivatePreviewL( const TCamSettingItemIds& aSettingId,
       
  1661                                            TInt                aSettingValue )
       
  1662   {
       
  1663   TInt index = FindIndex( iSettingPreviews, aSettingId );
       
  1664   if( KErrNotFound == index )
       
  1665     {
       
  1666     // Preview for this setting id did not exist yet.
       
  1667     TIntSetting* settingItem = new (ELeave) TIntSetting;
       
  1668     CleanupStack::PushL( settingItem );
       
  1669 
       
  1670     settingItem->iItemId  = aSettingId;
       
  1671     settingItem->iValueId = aSettingValue;
       
  1672 
       
  1673     iSettingPreviews.AppendL( settingItem );
       
  1674     CleanupStack::Pop( settingItem );
       
  1675     }
       
  1676   else
       
  1677     {
       
  1678     // If a preview exists, only update the value.
       
  1679     // Only one preview per setting item active at once.
       
  1680     iSettingPreviews[index]->iValueId = aSettingValue;
       
  1681     }
       
  1682   // The preview is considered as current setting value.
       
  1683   // Notify observers as if the setting value had changed.
       
  1684   NotifyObservers( aSettingId, aSettingValue );
       
  1685   }
       
  1686 
       
  1687 
       
  1688 // ---------------------------------------------------------------------------
       
  1689 //   
       
  1690 // ---------------------------------------------------------------------------
       
  1691 //
       
  1692 void 
       
  1693 CCamSettingsModel::CancelPreview( const TCamSettingItemIds& aSettingId )
       
  1694   {
       
  1695   TInt index = FindIndex( iSettingPreviews, aSettingId );
       
  1696 
       
  1697   if( KErrNotFound != index )
       
  1698     {
       
  1699     TIntSetting* settingItem = iSettingPreviews[index];
       
  1700     iSettingPreviews.Remove( index );
       
  1701     delete settingItem;
       
  1702     settingItem = NULL;
       
  1703     }
       
  1704   }
       
  1705     
       
  1706 
       
  1707 // ---------------------------------------------------------------------------
       
  1708 //   
       
  1709 // ---------------------------------------------------------------------------
       
  1710 //
       
  1711 void 
       
  1712 CCamSettingsModel::CancelPreviews( const RArray<TCamSettingItemIds> aSettingIds )
       
  1713   {
       
  1714   // Check if there is anything to cancel
       
  1715   if( 0 < iSettingPreviews.Count() )
       
  1716     {
       
  1717     for( TInt i = 0; i < aSettingIds.Count(); i++ )
       
  1718       {
       
  1719       CancelPreview( aSettingIds[i] );
       
  1720       }
       
  1721     }
       
  1722   }
       
  1723     
       
  1724 
       
  1725 // ---------------------------------------------------------------------------
       
  1726 //   
       
  1727 // ---------------------------------------------------------------------------
       
  1728 //
       
  1729 void 
       
  1730 CCamSettingsModel::CancelAllPreviews()
       
  1731   {
       
  1732   iSettingPreviews.ResetAndDestroy();
       
  1733   }
       
  1734 
       
  1735 
       
  1736 // ---------------------------------------------------------------------------
       
  1737 //   
       
  1738 // ---------------------------------------------------------------------------
       
  1739 //
       
  1740 void 
       
  1741 CCamSettingsModel::CommitPreviewL( const TCamSettingItemIds& aSettingId )
       
  1742   {
       
  1743   TInt index = FindIndex( iSettingPreviews, aSettingId );
       
  1744 
       
  1745   if( KErrNotFound != index )
       
  1746     {
       
  1747     TIntSetting* settingItem = iSettingPreviews[index];
       
  1748 
       
  1749     iSettingPreviews.Remove( index );
       
  1750 
       
  1751     CleanupStack::PushL( settingItem );
       
  1752     SetIntegerSettingValueL( settingItem->iItemId, settingItem->iValueId );
       
  1753     CleanupStack::PopAndDestroy( settingItem );
       
  1754     }
       
  1755   else
       
  1756     {
       
  1757     User::Leave( KErrNotFound );
       
  1758     }
       
  1759   }
       
  1760 
       
  1761 
       
  1762 // ---------------------------------------------------------------------------
       
  1763 //   
       
  1764 // ---------------------------------------------------------------------------
       
  1765 //
       
  1766 void 
       
  1767 CCamSettingsModel::CommitPreviewsL( const RArray<TCamSettingItemIds>& aSettingIds )
       
  1768   {
       
  1769   if( 0 < iSettingPreviews.Count() )
       
  1770     {
       
  1771     TInt all   ( KErrNone );
       
  1772     TInt single( KErrNone );
       
  1773 
       
  1774     for( TInt i = 0; i < aSettingIds.Count(); i++ )
       
  1775       {
       
  1776       TRAP( single, CommitPreviewL( aSettingIds[i] ) );
       
  1777 
       
  1778       if( KErrNone != single )
       
  1779         all = single;
       
  1780       }
       
  1781 
       
  1782     // Leave if there was problem with any of the previews.  
       
  1783     User::LeaveIfError( all );
       
  1784     }
       
  1785   }
       
  1786 
       
  1787 
       
  1788 // ---------------------------------------------------------------------------
       
  1789 //   
       
  1790 // ---------------------------------------------------------------------------
       
  1791 //
       
  1792 void 
       
  1793 CCamSettingsModel::CommitAllPreviewsL()
       
  1794   {
       
  1795   TInt all   ( KErrNone );
       
  1796   TInt single( KErrNone );
       
  1797   for( TInt i = 0; i < iSettingPreviews.Count(); i++ )
       
  1798     {    
       
  1799     TRAP( single, SetIntegerSettingValueL( iSettingPreviews[i]->iItemId, 
       
  1800                                            iSettingPreviews[i]->iValueId ) );
       
  1801 
       
  1802     if( KErrNone != single )
       
  1803       all = single;
       
  1804     }
       
  1805 
       
  1806   // Even if all commits are not successful, deactivate all previews.
       
  1807   iSettingPreviews.ResetAndDestroy();
       
  1808 
       
  1809   // Leave if there was problem with any of the previews.  
       
  1810   User::LeaveIfError( all );
       
  1811   }
       
  1812 
       
  1813 
       
  1814 // ---------------------------------------------------------------------------
       
  1815 //   
       
  1816 // ---------------------------------------------------------------------------
       
  1817 //
       
  1818 void 
       
  1819 CCamSettingsModel
       
  1820 ::ActivePreviewsL( RArray<TCamSettingItemIds>& aSettingIds ) const
       
  1821   {
       
  1822   aSettingIds.Reset();
       
  1823   aSettingIds.ReserveL( iSettingPreviews.Count() );
       
  1824   for( TInt i = 0; i < iSettingPreviews.Count(); i++ )
       
  1825     {
       
  1826     aSettingIds.AppendL( (TCamSettingItemIds)iSettingPreviews[i]->iItemId );
       
  1827     }
       
  1828   }
       
  1829 
       
  1830 // ===========================================================================
       
  1831 
       
  1832 
       
  1833 
       
  1834 // ---------------------------------------------------------------------------
       
  1835 // CCamSettingsModel::ImageResolutionFromIndex
       
  1836 // Returns the dimensions of the photo (in pixels) based on the size ID passed in
       
  1837 // ---------------------------------------------------------------------------
       
  1838 //
       
  1839 TSize CCamSettingsModel::ImageResolutionFromIndex( TCamPhotoSizeId aIndex )
       
  1840     {    
       
  1841     // TCamImageResolution imageRes = iConfiguration.MapPhotoSizeToResolution( aIndex );
       
  1842     return iPhotoResolutions[aIndex];
       
  1843     }
       
  1844 
       
  1845 // ---------------------------------------------------------------------------
       
  1846 // CCamSettingsModel::DefaultSettingValueForScene
       
  1847 // Returns the default value of a setting for a particular scene item.
       
  1848 // ---------------------------------------------------------------------------
       
  1849 //
       
  1850 TInt CCamSettingsModel::DefaultSettingValueForScene( TInt aSceneId, TInt aSettingId ) const
       
  1851     {
       
  1852     TInt sceneIndex = FindSceneInSceneList( aSceneId, iPhotoScenes );
       
  1853 
       
  1854     TInt settingIndex = SearchInSettingsListFor( 
       
  1855         iPhotoScenes[sceneIndex]->iSettings, aSettingId );
       
  1856 
       
  1857     return iPhotoScenes[sceneIndex]->iSettings[settingIndex]->iValueId;
       
  1858     }
       
  1859 
       
  1860 
       
  1861 // ---------------------------------------------------------------------------
       
  1862 // CCamSettingsModel::LoadDynamicSettingsL
       
  1863 // Loads the dynamic settings from resource file for a 
       
  1864 // particular group of settings, and stores their defaults. 
       
  1865 // ---------------------------------------------------------------------------
       
  1866 //
       
  1867 void CCamSettingsModel::LoadDynamicSettingsL( 
       
  1868     TInt aResourceId, 
       
  1869     RPointerArray<TIntSetting>& aSettingsList, 
       
  1870     RArray<TInt>&               aDefaultsList )
       
  1871   {
       
  1872   PRINT( _L("Camera => CCamSettingsModel::LoadDynamicSettingsL" ))
       
  1873   // Create resource reader for reading photo static settings
       
  1874   TResourceReader reader;
       
  1875   iEnv->CreateResourceReaderLC( reader, aResourceId );
       
  1876   TInt count = reader.ReadInt16();
       
  1877 
       
  1878   // for each entry in the resource, create a new setting item.
       
  1879   TInt i;
       
  1880   for ( i = 0; i < count; ++i )
       
  1881         {
       
  1882 
       
  1883         TIntSetting* newSetting = new (ELeave) TIntSetting;
       
  1884         CleanupStack::PushL( newSetting );
       
  1885 
       
  1886         // Read the data for this setting item from resource.
       
  1887         newSetting->iItemId = reader.ReadInt16();
       
  1888         newSetting->iValueId = reader.ReadInt16();
       
  1889         aDefaultsList.AppendL( newSetting->iValueId );
       
  1890 
       
  1891         // Add the new setting item and its associated key
       
  1892         // to the parallel arrays for static photo settings.
       
  1893         aSettingsList.AppendL( newSetting );
       
  1894         CleanupStack::Pop( newSetting );
       
  1895         }    
       
  1896 
       
  1897     CleanupStack::PopAndDestroy(); // reader
       
  1898     PRINT( _L("Camera <= CCamSettingsModel::LoadDynamicSettingsL" ))
       
  1899     }
       
  1900 
       
  1901 // ---------------------------------------------------------------------------
       
  1902 // CCamSettingsModel::LoadDynamicSettingsL
       
  1903 // Loads the dynamic settings from resource file for a 
       
  1904 // particular group of settings. 
       
  1905 // ---------------------------------------------------------------------------
       
  1906 //
       
  1907 void CCamSettingsModel::LoadDynamicSettingsL( TInt aResourceId, 
       
  1908                         RPointerArray<TIntSetting>& aSettingsList )
       
  1909     {
       
  1910     iStaticModel->LoadSettingsFromResourceL( aResourceId, aSettingsList );
       
  1911     }
       
  1912 
       
  1913 
       
  1914 // ---------------------------------------------------------------------------
       
  1915 // CCamSettingsModel::LoadScenesDataL
       
  1916 // Loads the scene data from resource file for a particular group of scenes. 
       
  1917 // ---------------------------------------------------------------------------
       
  1918 //
       
  1919 void CCamSettingsModel::LoadScenesDataL( TInt aResourceId, 
       
  1920     RPointerArray<TSceneData >& aSceneDataArray )
       
  1921     {
       
  1922     // Add array of defaults for static video settings
       
  1923     TResourceReader reader;
       
  1924     // Add array of defaults for static video settings
       
  1925     iEnv->CreateResourceReaderLC( reader, aResourceId );
       
  1926     TInt sceneCount = reader.ReadInt16();
       
  1927 
       
  1928     // for each entry in the resource array, create a new scene data item
       
  1929     TInt i;
       
  1930     for ( i = 0; i < sceneCount; i++ )
       
  1931         {
       
  1932         TSceneData * sceneData = new (ELeave) TSceneData ;
       
  1933         CleanupStack::PushL( sceneData );
       
  1934 
       
  1935         // Create a resource reader for reading only this scene's data.
       
  1936         TInt resourceID = reader.ReadInt32();
       
  1937         TResourceReader localReader;
       
  1938         iEnv->CreateResourceReaderLC
       
  1939             ( localReader, resourceID );
       
  1940 
       
  1941         // Read the data for this list item from resource.
       
  1942         // ...read scene id for the scene data
       
  1943         sceneData->iSceneId = localReader.ReadInt16();
       
  1944         // ...read settings for the scene data.
       
  1945         TInt settingsCount = localReader.ReadInt16();
       
  1946         TInt j;
       
  1947         for ( j = 0; j < settingsCount; ++j )
       
  1948             {
       
  1949             TIntSetting* setting = new (ELeave) TIntSetting;
       
  1950             CleanupStack::PushL( setting );
       
  1951             sceneData->iSettings.AppendL( setting );
       
  1952             CleanupStack::Pop( setting );
       
  1953             sceneData->iSettings[j]->iItemId = localReader.ReadInt16();
       
  1954             sceneData->iSettings[j]->iValueId = localReader.ReadInt16();
       
  1955             }
       
  1956 
       
  1957         CleanupStack::PopAndDestroy(); // local reader
       
  1958 
       
  1959         // Add the scene data to the scenes list.
       
  1960         aSceneDataArray.AppendL( sceneData );
       
  1961         CleanupStack::Pop( sceneData );
       
  1962         }  
       
  1963     
       
  1964     CleanupStack::PopAndDestroy(); // reader
       
  1965     }
       
  1966 
       
  1967 // ---------------------------------------------------------------------------
       
  1968 // CCamSettingsModel::LoadSceneDataL
       
  1969 // Loads the scene data from resource file for a particular group of scenes. 
       
  1970 // ---------------------------------------------------------------------------
       
  1971 //    
       
  1972 void CCamSettingsModel::LoadSceneDataL( TBool aPhotoSceneSettings )
       
  1973     {
       
  1974     RArray<TSceneSettings> supportedSceneSettings;
       
  1975     CleanupClosePushL( supportedSceneSettings );
       
  1976     
       
  1977     iUiConfigManager->SupportedSceneModesAndSettingsL( supportedSceneSettings,
       
  1978                                                       aPhotoSceneSettings );
       
  1979    
       
  1980     for ( TInt i = 0; i < supportedSceneSettings.Count(); i++ )
       
  1981         {
       
  1982         //
       
  1983         TSceneSettings scene = supportedSceneSettings[i];
       
  1984         if ( scene.iSupported ) // only if scenes are supported its appened to the list
       
  1985             {
       
  1986             TSceneData* sceneData = new ( ELeave ) TSceneData;
       
  1987             CleanupStack::PushL( sceneData );
       
  1988 
       
  1989             // identifier
       
  1990             sceneData->iSceneId = scene.iIdentifier;
       
  1991 
       
  1992             // exposure mode
       
  1993             TIntSetting* setting = new ( ELeave ) TIntSetting;
       
  1994             CleanupStack::PushL( setting );
       
  1995 
       
  1996             setting->iItemId = ECamSettingItemSceneAEMode;
       
  1997             setting->iValueId = scene.iExposureMode;
       
  1998 
       
  1999             sceneData->iSettings.AppendL( setting );
       
  2000             CleanupStack::Pop( setting );
       
  2001 
       
  2002             // white balance
       
  2003             setting = new ( ELeave ) TIntSetting;
       
  2004             CleanupStack::PushL( setting );
       
  2005 
       
  2006             setting->iItemId = ECamSettingItemSceneAWBMode;
       
  2007             setting->iValueId = scene.iWhiteBalance;
       
  2008 
       
  2009             sceneData->iSettings.AppendL( setting );
       
  2010             CleanupStack::Pop( setting );
       
  2011 
       
  2012             // flash
       
  2013             setting = new ( ELeave ) TIntSetting;
       
  2014             CleanupStack::PushL( setting );
       
  2015 
       
  2016             setting->iItemId = ECamSettingItemSceneFlashMode;
       
  2017             setting->iValueId = scene.iFlash;
       
  2018 
       
  2019             sceneData->iSettings.AppendL( setting );
       
  2020             CleanupStack::Pop( setting );
       
  2021 
       
  2022             // contrast
       
  2023             setting = new ( ELeave ) TIntSetting;
       
  2024             CleanupStack::PushL( setting );
       
  2025 
       
  2026             setting->iItemId = ECamSettingItemSceneContrast;
       
  2027             setting->iValueId = scene.iContrastMode;
       
  2028 
       
  2029             sceneData->iSettings.AppendL( setting );
       
  2030             CleanupStack::Pop( setting );
       
  2031 
       
  2032             // focal distance
       
  2033             setting = new ( ELeave ) TIntSetting;
       
  2034             CleanupStack::PushL( setting );
       
  2035 
       
  2036             setting->iItemId = ECamSettingItemSceneAFMode;
       
  2037             setting->iValueId = scene.iFocalDistance;
       
  2038 
       
  2039             sceneData->iSettings.AppendL( setting );
       
  2040             CleanupStack::Pop( setting );
       
  2041 
       
  2042             
       
  2043             if ( aPhotoSceneSettings )
       
  2044                 { 
       
  2045                 // load settings which are specific to photo scene
       
  2046                 
       
  2047                 // sharpness
       
  2048                 setting = new ( ELeave ) TIntSetting;
       
  2049                 CleanupStack::PushL( setting );
       
  2050 
       
  2051                 setting->iItemId = ECamSettingItemSceneSharpness;
       
  2052                 setting->iValueId = scene.iSharpnessMode;
       
  2053 
       
  2054                 sceneData->iSettings.AppendL( setting );
       
  2055                 CleanupStack::Pop( setting );
       
  2056                 
       
  2057                 
       
  2058                 // ISO
       
  2059                 setting = new ( ELeave ) TIntSetting;
       
  2060                 CleanupStack::PushL( setting );
       
  2061 
       
  2062                 setting->iItemId = ECamSettingItemSceneISO;
       
  2063                 setting->iValueId = scene.iLightSensitivityMode;
       
  2064 
       
  2065                 sceneData->iSettings.AppendL( setting );
       
  2066                 CleanupStack::Pop( setting );
       
  2067 
       
  2068                 // EV
       
  2069                 setting = new ( ELeave ) TIntSetting;
       
  2070                 CleanupStack::PushL( setting );
       
  2071 
       
  2072                 setting->iItemId = ECamSettingItemSceneEV;
       
  2073                 setting->iValueId = scene.iExposureCompensationValue;
       
  2074 
       
  2075                 sceneData->iSettings.AppendL( setting );
       
  2076                 CleanupStack::Pop( setting );
       
  2077                 }
       
  2078             else
       
  2079                 {
       
  2080                 // settings which are specific to video scene
       
  2081                 // framerate
       
  2082                 setting = new ( ELeave ) TIntSetting;
       
  2083                 CleanupStack::PushL( setting );
       
  2084                 
       
  2085                 setting->iItemId = ECamSettingItemSceneFramerate;
       
  2086                 setting->iValueId = scene.iFrameRate;
       
  2087                 
       
  2088                 sceneData->iSettings.AppendL( setting );
       
  2089                 CleanupStack::Pop( setting );
       
  2090                 }
       
  2091             // Add the scene data to the scenes list.
       
  2092             if ( aPhotoSceneSettings )
       
  2093                 {
       
  2094                 iPhotoScenes.AppendL( sceneData );                
       
  2095                 }
       
  2096             else
       
  2097                 {
       
  2098                 iVideoScenes.AppendL( sceneData );                
       
  2099                 }
       
  2100             CleanupStack::Pop( sceneData );
       
  2101             } // end if 
       
  2102         } // end for
       
  2103     CleanupStack::PopAndDestroy( &supportedSceneSettings );
       
  2104     }
       
  2105 
       
  2106 // ---------------------------------------------------------------------------
       
  2107 // CCamSettingsModel::UnloadSettings
       
  2108 // Remove any previously loaded settings.
       
  2109 // ---------------------------------------------------------------------------
       
  2110 //
       
  2111 void CCamSettingsModel::UnloadSettings()
       
  2112     {
       
  2113     PRINT( _L("Camera => CCamSettingsModel::UnloadSettings()" ))
       
  2114 
       
  2115     iDynamicPhotoIntSettings.ResetAndDestroy();
       
  2116     iDynamicVideoIntSettings.ResetAndDestroy();
       
  2117 
       
  2118     iPhotoScenes.ResetAndDestroy();
       
  2119     iVideoScenes.ResetAndDestroy();
       
  2120     PRINT( _L("Camera <= CCamSettingsModel::UnloadSettings()" ))
       
  2121     }
       
  2122 
       
  2123 // ---------------------------------------------------------------------------
       
  2124 // CCamSettingsModel::UnloadStaticSettings
       
  2125 // Remove any previously loaded static settings.
       
  2126 // ---------------------------------------------------------------------------
       
  2127 //
       
  2128 void CCamSettingsModel::UnloadStaticSettings()
       
  2129     {
       
  2130     PRINT( _L("Camera => CCamSettingsModel::UnloadStaticSettings()" ))
       
  2131     iUserSceneSettings.ResetAndDestroy();
       
  2132     PRINT( _L("Camera <= CCamSettingsModel::UnloadStaticSettings()" ))
       
  2133     }
       
  2134 
       
  2135 // ---------------------------------------------------------------------------
       
  2136 // CCamSettingsModel::BurstModeActiveL
       
  2137 // Track burst mode activation
       
  2138 // ---------------------------------------------------------------------------
       
  2139 //
       
  2140 void 
       
  2141 CCamSettingsModel::BurstModeActiveL( TBool aActive, TBool /*aStillModeActive*/ )
       
  2142   {
       
  2143   iBurstEnabled = aActive;
       
  2144   }
       
  2145 
       
  2146 
       
  2147 // ---------------------------------------------------------------------------
       
  2148 // CCamSettingsModel::VideoResolutions
       
  2149 // Return ref. to video resolutions array
       
  2150 // ---------------------------------------------------------------------------
       
  2151 //
       
  2152 const RArray<TSize>& 
       
  2153 CCamSettingsModel::VideoResolutions()
       
  2154   {
       
  2155   return iVideoResolutions;
       
  2156   }
       
  2157 
       
  2158 // ---------------------------------------------------------------------------
       
  2159 // CCamSettingsModel::VideoQualityArray
       
  2160 // Return ref. to video video quality level array
       
  2161 // ---------------------------------------------------------------------------
       
  2162 //
       
  2163 const RPointerArray<CCamVideoQualityLevel>& 
       
  2164 CCamSettingsModel::VideoQualityArray()
       
  2165   {
       
  2166   return iQualityLevels;
       
  2167   }
       
  2168   
       
  2169 // ---------------------------------------------------------------------------
       
  2170 // StaticSettingsModel
       
  2171 // 
       
  2172 // Gets the reference to the settings model
       
  2173 // ---------------------------------------------------------------------------
       
  2174 //
       
  2175 MCamStaticSettings& 
       
  2176 CCamSettingsModel::StaticSettingsModel() const
       
  2177   {
       
  2178   return *iStaticModel;
       
  2179   }
       
  2180 
       
  2181 // ===========================================================================
       
  2182 // TSceneData methods
       
  2183 
       
  2184 // ---------------------------------------------------------------------------
       
  2185 // TSceneData::~TSceneData
       
  2186 // Destructor
       
  2187 // ---------------------------------------------------------------------------
       
  2188 //
       
  2189 TSceneData::~TSceneData()
       
  2190     {
       
  2191     iSettings.ResetAndDestroy();
       
  2192     iSettings.Close();
       
  2193     }
       
  2194 
       
  2195 /*
       
  2196 * Is Image Scene supported
       
  2197 */
       
  2198  TBool CCamSettingsModel::IsImageSceneSupported( const TInt aSceneId ) const
       
  2199  {
       
  2200  if ( ECamSceneMacro == aSceneId && !iUiConfigManager->IsAutoFocusSupported() )
       
  2201      {
       
  2202      // if the photo scene is macro and if autofocus is not supported
       
  2203      // the macro scene mode is not visible in scene mode settings
       
  2204      return EFalse;
       
  2205      }
       
  2206  return ( KErrNotFound != FindSceneInSceneList( aSceneId, iPhotoScenes ) );
       
  2207  }
       
  2208 
       
  2209  /*
       
  2210  * Is Image Scene supported
       
  2211  */
       
  2212   TBool CCamSettingsModel::IsVideoSceneSupported( const TInt aSceneId ) const
       
  2213   {
       
  2214   return ( KErrNotFound != FindSceneInSceneList( aSceneId, iVideoScenes ) );
       
  2215   } 
       
  2216  
       
  2217 /*
       
  2218 *  Handle to Camera Ui Config Manager
       
  2219 */
       
  2220 CCameraUiConfigManager* CCamSettingsModel::UiConfigManagerPtr()
       
  2221     {
       
  2222     return iUiConfigManager;
       
  2223     }
       
  2224 
       
  2225 
       
  2226 // ---------------------------------------------------------------------------
       
  2227 // 
       
  2228 // ---------------------------------------------------------------------------
       
  2229 //
       
  2230 void CCamSettingsModel::LoadResourcesL()   
       
  2231     {
       
  2232     PRINT( _L("Camera => CCamSettingsModel::LoadResourcesL" ) )
       
  2233     if (iResourceFileOffset == 0)
       
  2234         {
       
  2235         TFileName resourceFile;
       
  2236         TParse parse;
       
  2237         if ( CamUtility::IsNhdDevice() )  
       
  2238             {
       
  2239             parse.Set( KCamNhdResourceFileName, &KDC_APP_RESOURCE_DIR, NULL ); 
       
  2240             }
       
  2241         else
       
  2242             {
       
  2243             parse.Set( KCamVgaResourceFileName, &KDC_APP_RESOURCE_DIR, NULL ); 
       
  2244             }
       
  2245         resourceFile = parse.FullName();
       
  2246         BaflUtils::NearestLanguageFile( iEnv->FsSession(), resourceFile );
       
  2247         iResourceFileOffset = iEnv->AddResourceFileL( resourceFile );
       
  2248         }
       
  2249     PRINT( _L("Camera <= CCamSettingsModel::LoadResourcesL" ) )
       
  2250     }
       
  2251 
       
  2252 
       
  2253 // ---------------------------------------------------------------------------
       
  2254 // 
       
  2255 // ---------------------------------------------------------------------------
       
  2256 //
       
  2257 void CCamSettingsModel::UnLoadResources()
       
  2258     {
       
  2259     if (iResourceFileOffset > 0)
       
  2260         {
       
  2261         iEnv->DeleteResourceFile( iResourceFileOffset );
       
  2262         iResourceFileOffset = 0;
       
  2263         }
       
  2264     } 
       
  2265     
       
  2266 // ---------------------------------------------------------------------------
       
  2267 // CCamSettingsModel::StoreFaceTrackingValue
       
  2268 //
       
  2269 // Store user defined FT value outside Sports and Scenery mode that setting
       
  2270 // can be rolled back. 
       
  2271 // ---------------------------------------------------------------------------
       
  2272 //   
       
  2273 void CCamSettingsModel::StoreFaceTrackingValue()
       
  2274    {
       
  2275    PRINT( _L("Camera => CCamSettingsModel::StoreFaceTrackingValue()" ) )	
       
  2276    
       
  2277    if ( !iUiConfigManager->IsFaceTrackingSupported() ) // FT not supported
       
  2278       {
       
  2279       PRINT( _L("Camera <= CCamSettingsModel::StoreFaceTrackingValue(), FT _not_ supported" ) )	
       
  2280       return;	
       
  2281       }
       
  2282    TInt activeScene = IntegerSettingValue( ECamSettingItemDynamicPhotoScene );	
       
  2283    if ( ECamSceneScenery == activeScene || ECamSceneSports == activeScene ) 	
       
  2284       {
       
  2285       PRINT( _L("Camera <> CCamSettingsModel::StoreFaceTrackingValue(), Scenery or Sports mode" ) )		      	      	
       
  2286       if ( iPreviousFaceTrack != TCamSettingsOnOff( IntegerSettingValue( ECamSettingItemFaceTracking ) ) )
       
  2287          {	
       
  2288          PRINT1( _L("Camera <> CCamSettingsModel::StoreFaceTrackingValue(), iPreviousFaceTrack [%d]" ), iPreviousFaceTrack )		      	      		
       
  2289          SetIntegerSettingValueL( ECamSettingItemFaceTracking, iPreviousFaceTrack );
       
  2290          }      	      	      
       
  2291       }
       
  2292    PRINT( _L("Camera <= CamSettingsModel::StoreFaceTrackingValue()" ) )	
       
  2293    }
       
  2294 
       
  2295 // ---------------------------------------------------------------------------
       
  2296 // CCamSettingsModel::CopySettingsL
       
  2297 //
       
  2298 // Backup and Restore Settings array
       
  2299 // ---------------------------------------------------------------------------
       
  2300 // 
       
  2301 void CCamSettingsModel::CopySettingsL(RPointerArray<TIntSetting>& aSrc,
       
  2302                  RPointerArray<TIntSetting>& aDest,
       
  2303                  TBool aRestore)
       
  2304     {
       
  2305     if(aRestore)
       
  2306         {
       
  2307         __ASSERT_DEBUG(aSrc.Count() == aDest.Count(), CamPanic(ECamPanicInvalidState));
       
  2308         TInt count = aSrc.Count();
       
  2309         TInt index = 0;
       
  2310         do
       
  2311             {
       
  2312             if(aSrc[index]->iItemId == aDest[index]->iItemId)
       
  2313                 {
       
  2314                 if(aSrc[index]->iValueId != aDest[index]->iValueId)
       
  2315                     {
       
  2316                     aDest[index]->iValueId = aSrc[index]->iValueId;
       
  2317                     }
       
  2318                 }
       
  2319             index++;
       
  2320             }while(index < count);
       
  2321         }
       
  2322     else
       
  2323         {
       
  2324         __ASSERT_DEBUG(aSrc.Count(), CamPanic(ECamPanicInvalidState));
       
  2325         aDest.ResetAndDestroy();
       
  2326         TInt count = aSrc.Count();
       
  2327         TInt index = 0;
       
  2328         do
       
  2329             {
       
  2330             TIntSetting* setting = new(ELeave) TIntSetting();
       
  2331             CleanupStack::PushL(setting);
       
  2332             setting->iItemId = aSrc[index]->iItemId;
       
  2333             setting->iValueId = aSrc[index]->iValueId;
       
  2334             aDest.AppendL(setting);
       
  2335             CleanupStack::Pop(setting);
       
  2336             index++;
       
  2337             }while(index < count);
       
  2338         }
       
  2339     
       
  2340     }
       
  2341 
       
  2342 // ===========================================================================
       
  2343 // end of File