camerauis/cameraapp/generic/src/CamLocationIconController.cpp
branchRCL_3
changeset 24 bac7acad7cb3
child 25 2c87b2808fd7
equal deleted inserted replaced
23:61bc0f252b2b 24:bac7acad7cb3
       
     1 /*
       
     2 * Copyright (c) 2007-2010 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:  Implemantation for CCamLocationIconController class.
       
    15 *
       
    16 *  Copyright © 2007 Nokia.  All rights reserved.
       
    17 *  This material, including documentation and any related computer
       
    18 *  programs, is protected by copyright controlled by Nokia.  All
       
    19 *  rights are reserved.  Copying, including reproducing, storing,
       
    20 *  adapting or translating, any or all of this material requires the
       
    21 *  prior written consent of Nokia.  This material also contains
       
    22 *  confidential information which may not be disclosed to others
       
    23 *  without the prior written consent of Nokia.
       
    24 
       
    25 *
       
    26 *
       
    27 */
       
    28 
       
    29 
       
    30 #include "CamLocationIconController.h"
       
    31 
       
    32 #include <e32base.h>
       
    33 #include <e32property.h>                // RProperty
       
    34 #ifndef __WINSCW__
       
    35   #include <locationtrailpskeys.h>      // P&S keys
       
    36 #endif
       
    37 #include <AknsConstants.h>              // KAknsMessageSkinChange 
       
    38 #include <aknlayoutscalable_apps.cdl.h>
       
    39 #include <layoutmetadata.cdl.h>
       
    40 #include <cameraapp.mbg>
       
    41 
       
    42 #include "CamAppController.h"
       
    43 #include "CamIndicator.h"
       
    44 #include "CamIndicatorResourceReader.h"
       
    45 #include "CamIndicatorData.h"
       
    46 
       
    47 #include "CamPropertyWatcher.h"
       
    48 #include "CamUtility.h"
       
    49 #include "CamSettingsInternal.hrh"
       
    50 
       
    51 #include "CamControllerObservers.h"
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CCamLocationIconController::CCamLocationIconController
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CCamLocationIconController::CCamLocationIconController( CCamAppController& aController,
       
    58                                                         MCamLocationIconObserver& aObserver, 
       
    59                                                         TBool aCallbackActive ) :
       
    60     iController( aController ), iObserver( aObserver ), iCallbackActive( aCallbackActive )
       
    61     {
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CCamLocationIconController::~CCamLocationIconController
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CCamLocationIconController::~CCamLocationIconController()
       
    69   {
       
    70     PRINT ( _L("Camera => CCamLocationIconController::~CCamLocationIconController") );
       
    71      	
       
    72     iLocationIndicators.ResetAndDestroy();
       
    73     iLocationIndicators.Close();
       
    74     delete iLocationStateWatcher;
       
    75 
       
    76     iController.RemoveControllerObserver( this );
       
    77     
       
    78     PRINT ( _L("Camera <= CCamLocationIconController::~CCamLocationIconController") ); 	   
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CCamLocationIconController::NewL
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CCamLocationIconController* CCamLocationIconController::NewL(  CCamAppController& aController, 
       
    86                                                                MCamLocationIconObserver& aObserver, 
       
    87                                                                TBool aCallbackActive, TRect& aRect )
       
    88     {
       
    89     PRINT ( _L("Camera => CCamLocationIconController::NewL") );		
       
    90     
       
    91     CCamLocationIconController* self = 
       
    92         new (ELeave) CCamLocationIconController( aController, aObserver, aCallbackActive );
       
    93     CleanupStack::PushL( self );
       
    94     self->ConstructL(aRect);
       
    95     CleanupStack::Pop(); // self
       
    96     PRINT ( _L("Camera <= CCamLocationIconController::NewL") );
       
    97     return self;    
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // CCamLocationIconController::ConstructL
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 void CCamLocationIconController::ConstructL(TRect& aRect)
       
   105     {
       
   106     PRINT ( _L("Camera => CCamLocationIconController::ConstructL") );	
       
   107     iEnv = CEikonEnv::Static();
       
   108     iRect.SetRect(aRect.iTl, aRect.Size());
       
   109     //Change this later when the location active object has been finished!!
       
   110     iLocationState = KLocationSettingStateOff;
       
   111     CreateLocationIndicatorL();
       
   112     
       
   113 #ifndef __WINSCW__
       
   114     // Construct property watchers for location indicator status
       
   115     iLocationStateWatcher = CCamPropertyWatcher::NewL( *this, KPSUidLocationTrail, KLocationTrailState );
       
   116 
       
   117     // Subscribe to the properties 
       
   118     iLocationStateWatcher->Subscribe();
       
   119 #endif
       
   120 
       
   121     // Read initial values for location status
       
   122     ReadCurrentState();
       
   123     
       
   124     iController.AddControllerObserverL( this );
       
   125     
       
   126     PRINT ( _L( "Camera <= CCamLocationIconController::ConstructL" ) );	
       
   127     }
       
   128     
       
   129     
       
   130 //----------------------------------------------------------
       
   131 // CCamLocationIconController::CreateLocationIndicatorL
       
   132 //----------------------------------------------------------
       
   133 void CCamLocationIconController::CreateLocationIndicatorL()
       
   134     {
       
   135 	RArray<TInt> icons;
       
   136 	CleanupClosePushL( icons );
       
   137 	User::LeaveIfError( icons.Append( EMbmCameraappQgn_indi_cam4_geotag_off ) );
       
   138 	User::LeaveIfError( icons.Append( EMbmCameraappQgn_indi_cam4_geotag_off_mask ) );
       
   139 	User::LeaveIfError( icons.Append( EMbmCameraappQgn_indi_cam4_geotag_on ) );
       
   140 	User::LeaveIfError( icons.Append( EMbmCameraappQgn_indi_cam4_geotag_on_mask ) );
       
   141 	TInt count = icons.Count();
       
   142     // Get the icon rect
       
   143     TRect iconRect = Rect();
       
   144 		
       
   145     CCamIndicator* indicator;
       
   146 	for( TInt i = 0; i < count; i+=2 )
       
   147 		{
       
   148         indicator = CCamIndicator::NewL( iconRect );
       
   149         CleanupStack::PushL( indicator );
       
   150         indicator->AddIconL( icons[i], icons[i+1] ); // Bitmap & mask.
       
   151         indicator->SetRect( iconRect );
       
   152        
       
   153         User::LeaveIfError( iLocationIndicators.Append( indicator ) );
       
   154         CleanupStack::Pop( indicator );
       
   155 		}
       
   156 
       
   157 	CleanupStack::PopAndDestroy( &icons );
       
   158 
       
   159     }
       
   160 
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // CCamLocationIconController::SetCallbackActive
       
   164 // ---------------------------------------------------------------------------
       
   165 //    
       
   166 void CCamLocationIconController::SetCallbackActive( TBool aActive )
       
   167     {
       
   168     iCallbackActive = aActive;
       
   169     }
       
   170 
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // CCamLocationIconController::UpdateRect
       
   174 // ---------------------------------------------------------------------------
       
   175 //    
       
   176 void CCamLocationIconController::UpdateRect()
       
   177     {
       
   178     TInt i;
       
   179     TRect newRect = Rect();
       
   180     TInt count = iLocationIndicators.Count();
       
   181     
       
   182 	const TCamCameraMode mode = iController.CurrentMode();
       
   183 	const TCamCameraMode targetmode = iController.TargetMode();
       
   184 	TBool ShowIcon = ETrue;
       
   185 	if ( (targetmode != mode)
       
   186           || (( ECamControllerImage != targetmode )
       
   187            && ( ECamControllerVideo != targetmode )) ) 
       
   188 	    {
       
   189 	    ShowIcon = EFalse;
       
   190 		}
       
   191 		
       
   192     for ( i = 0; i < count; i++ )
       
   193         {
       
   194       	
       
   195         if ( ShowIcon ) 
       
   196             {
       
   197             iLocationIndicators[i]->DisplayIcon();
       
   198             } 
       
   199         else 
       
   200             {
       
   201             iLocationIndicators[i]->ClearIcon();
       
   202             }
       
   203         iLocationIndicators[i]->SetRect( newRect );
       
   204         }
       
   205     NotifyObserver();
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 // CCamLocationIconController::SetLocationState
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 void CCamLocationIconController::SetLocationState( TInt aState )
       
   213     {    	
       
   214     PRINT( _L("Camera => CCamLocationIconController::SetLocationState") );	    	
       
   215 
       
   216     // Possible location trail states are 0,1,2 and 3
       
   217     // but the GPS data is available only with the state 3
       
   218     // so that is when the icon is changed to on state.
       
   219     // Possible values
       
   220     // - TrailStopped (value 0 - off-icon)
       
   221     // - TrailStarted - No valid GPS data (value 1 - off-icon)
       
   222     // - TrailStarted - Searching GPS device (value 2 - off-icon)
       
   223     // - TrailStarted - GPS data available (value 3 - on-icon)
       
   224     if ( KCamLocationTrailGPSDataAvail == aState ) 
       
   225         {
       
   226     	iLocationState = KLocationSettingStateOn;
       
   227         }
       
   228     else
       
   229         {
       
   230     	iLocationState = KLocationSettingStateOff;
       
   231         }
       
   232 
       
   233     NotifyObserver();
       
   234         
       
   235     PRINT( _L("Camera <= CCamLocationIconController::SetLocationState") );	        
       
   236     }    
       
   237  
       
   238 // ---------------------------------------------------------------------------
       
   239 // CCamLocationIconController::Rect
       
   240 // Returns the rectangle defining the position and size
       
   241 // of the location icon
       
   242 // ----------------------------------------------------
       
   243 //
       
   244 TRect CCamLocationIconController::Rect() const
       
   245 	{
       
   246     TAknLayoutRect camIndicatorPane;
       
   247 	TAknLayoutRect layoutRect;
       
   248 	
       
   249     TSize screenSize;
       
   250     AknLayoutUtils::LayoutMetricsSize( AknLayoutUtils::EScreen, screenSize );
       
   251     TRect extent = TRect( TPoint(), screenSize );
       
   252 	
       
   253 	const TCamCameraMode targetmode = iController.TargetMode();
       
   254 	const TCamCaptureOperation operation =  iController.CurrentVideoOperation();
       
   255 	if ( ECamControllerVideo == targetmode )
       
   256 		{
       
   257 		if ( ( ECamCapturing == operation )||
       
   258 		     ( ECamPausing == operation )  ||
       
   259 			 ( ECamPaused == operation )   ||
       
   260 			 ( ECamResuming == operation ))
       
   261 			{
       
   262 	        if ( CamUtility::IsNhdDevice() ) 
       
   263 	            {
       
   264                 if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
   265                     {
       
   266                     camIndicatorPane.LayoutRect(
       
   267                         extent,
       
   268                         AknLayoutScalable_Apps::vid4_progress_pane( 1 ) );
       
   269                     layoutRect.LayoutRect(
       
   270                         camIndicatorPane.Rect(),
       
   271                         AknLayoutScalable_Apps::vid4_progress_pane_g5( 0 ) );
       
   272                     }
       
   273                 else  // portrait
       
   274                     {
       
   275                     camIndicatorPane.LayoutRect(
       
   276                         extent,
       
   277                         AknLayoutScalable_Apps::vid4_progress_pane( 0 ) );
       
   278                     layoutRect.LayoutRect(
       
   279                         camIndicatorPane.Rect(),
       
   280                         AknLayoutScalable_Apps::vid4_progress_pane_g5( 1 ) );
       
   281                     }
       
   282 	            }
       
   283 	        else
       
   284 	            {
       
   285 	            if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
   286 	                {
       
   287 	                camIndicatorPane.LayoutRect(
       
   288 	                    extent,
       
   289 	                    AknLayoutScalable_Apps::vid6_indi_pane( 0 ) );
       
   290 	                layoutRect.LayoutRect(
       
   291 	                    camIndicatorPane.Rect(),
       
   292 	                    AknLayoutScalable_Apps::vid6_indi_pane_g4( 1 ) );
       
   293 	                }
       
   294 	            else  // portrait
       
   295 	                {
       
   296 	                camIndicatorPane.LayoutRect(
       
   297 	                    extent,
       
   298 	                    AknLayoutScalable_Apps::vid6_indi_pane( 3 ) );
       
   299 	                layoutRect.LayoutRect(
       
   300 	                    camIndicatorPane.Rect(),
       
   301 	                    AknLayoutScalable_Apps::vid6_indi_pane_g4( 3 ) );
       
   302 	                }
       
   303 	            }
       
   304 			}
       
   305 		else
       
   306 			{
       
   307             if ( CamUtility::IsNhdDevice() ) 
       
   308                 {
       
   309                 if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
   310                     {
       
   311                     camIndicatorPane.LayoutRect( extent,
       
   312                              AknLayoutScalable_Apps::vid4_progress_pane( 1 ) ); // vid4_indicators_pane should be used
       
   313                     layoutRect.LayoutRect( camIndicatorPane.Rect(),
       
   314                         AknLayoutScalable_Apps::vid4_indicators_pane_g5( 0 ) );       
       
   315                     }
       
   316                 else  // portrait
       
   317                     {
       
   318                     camIndicatorPane.LayoutRect(
       
   319                         extent,
       
   320                         AknLayoutScalable_Apps::vid4_indicators_pane( 0 ) );
       
   321                     layoutRect.LayoutRect(
       
   322                         camIndicatorPane.Rect(),
       
   323                         AknLayoutScalable_Apps::vid4_indicators_pane_g5( 1 ) );
       
   324                     }
       
   325                 }
       
   326             else
       
   327                 {
       
   328                 if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
   329                     {
       
   330                     camIndicatorPane.LayoutRect(
       
   331                         extent,
       
   332                         AknLayoutScalable_Apps::vid6_indi_pane( 0 ) );
       
   333                     layoutRect.LayoutRect(
       
   334                         camIndicatorPane.Rect(),
       
   335                         AknLayoutScalable_Apps::vid6_indi_pane_g4( 0 ) );
       
   336                     }
       
   337                 else  // portrait
       
   338                     {
       
   339                     camIndicatorPane.LayoutRect(
       
   340                         extent,
       
   341                         AknLayoutScalable_Apps::vid6_indi_pane( 3 ) );
       
   342                     layoutRect.LayoutRect(
       
   343                         camIndicatorPane.Rect(),
       
   344                         AknLayoutScalable_Apps::vid6_indi_pane_g4( 2 ) );
       
   345                     }
       
   346                 }
       
   347 			}
       
   348 		}
       
   349 	else
       
   350 		{
       
   351         if ( CamUtility::IsNhdDevice() ) 
       
   352             {
       
   353     	    if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
   354     	        {
       
   355     	        camIndicatorPane.LayoutRect(
       
   356     	            extent,
       
   357     	            AknLayoutScalable_Apps::cam4_indicators_pane( 1 ) );
       
   358     	        layoutRect.LayoutRect(
       
   359     	            camIndicatorPane.Rect(),
       
   360     	            AknLayoutScalable_Apps::cam4_indicators_pane_g3( 0 ) );
       
   361     	        }
       
   362     	    else  // portrait
       
   363     	        {
       
   364     	        camIndicatorPane.LayoutRect(
       
   365     	            extent,
       
   366     	            AknLayoutScalable_Apps::cam4_indicators_pane( 0 ) );
       
   367     	        layoutRect.LayoutRect(
       
   368     	            camIndicatorPane.Rect(),
       
   369     	            AknLayoutScalable_Apps::cam4_indicators_pane_g3( 1 ) );
       
   370     	        }
       
   371             }
       
   372         else
       
   373             {
       
   374             if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
   375                 {
       
   376                 camIndicatorPane.LayoutRect(
       
   377                     extent,
       
   378                     AknLayoutScalable_Apps::cam6_indi_pane( 0 ) );
       
   379                 layoutRect.LayoutRect(
       
   380                     camIndicatorPane.Rect(),
       
   381                     AknLayoutScalable_Apps::cam6_indi_pane_g3( 0 ) );
       
   382                 }
       
   383             else  // portrait
       
   384                 {
       
   385                 camIndicatorPane.LayoutRect(
       
   386                     extent,
       
   387                     AknLayoutScalable_Apps::cam6_indi_pane( 3 ) );
       
   388                 layoutRect.LayoutRect(
       
   389                     camIndicatorPane.Rect(),
       
   390                     AknLayoutScalable_Apps::cam6_indi_pane_g3( 2 ) );
       
   391                 }
       
   392             }
       
   393 		}
       
   394     return layoutRect.Rect();
       
   395 	}
       
   396 
       
   397 // ---------------------------------------------------------------------------
       
   398 // CCamLocationIconController::Draw
       
   399 // ---------------------------------------------------------------------------
       
   400 //
       
   401 void CCamLocationIconController::Draw( CBitmapContext& aGc ) const
       
   402     {
       
   403     PRINT( _L("Camera => CCamLocationIconController::Draw") );
       
   404 
       
   405     // Make sure no brush is being used
       
   406     aGc.SetBrushStyle( CGraphicsContext::ENullBrush );    
       
   407     iLocationIndicators[iLocationState]->Draw( aGc );
       
   408 
       
   409     PRINT( _L("Camera <= CCamLocationIconController::Draw") );
       
   410     }    
       
   411 
       
   412 
       
   413 // ---------------------------------------------------------------------------
       
   414 // CCamLocationIconController::NotifyObserver
       
   415 // ---------------------------------------------------------------------------    
       
   416 //
       
   417 void CCamLocationIconController::NotifyObserver()
       
   418     {
       
   419     if( iCallbackActive )
       
   420         {
       
   421         iObserver.LocationIconUpdated();
       
   422         }
       
   423     }
       
   424 
       
   425 // ---------------------------------------------------------------------------
       
   426 // CCamLocationIconController::ReadCurrentState
       
   427 // ---------------------------------------------------------------------------
       
   428 //
       
   429 void CCamLocationIconController::ReadCurrentState()
       
   430     {
       
   431     PRINT( _L("Camera => CCamLocationIconController::ReadCurrentState") ); 	
       
   432     
       
   433     TInt locationState = KLocationSettingStateOff;
       
   434 #ifndef __WINSCW__
       
   435     TInt err = KErrNone;
       
   436 
       
   437     // Get the location state
       
   438     err = iLocationStateWatcher->Get( locationState );
       
   439     if( KErrNone == err && -1 != locationState && KCamLocationTrailStopped <= locationState && KCamLocationTrailGPSDataAvail >= locationState )
       
   440         {
       
   441         // We got an acceptable value
       
   442         SetLocationState( locationState );
       
   443         }
       
   444     else
       
   445         {
       
   446         // Default to off value
       
   447         SetLocationState( KLocationSettingStateOff );
       
   448         }
       
   449 #endif // __WINSCW__
       
   450 
       
   451     NotifyObserver();
       
   452     
       
   453     PRINT( _L("Camera <= CCamLocationIconController::ReadCurrentState") ); 	
       
   454     }
       
   455     
       
   456 // ---------------------------------------------------------------------------
       
   457 // CCamLocationIconController::HandlePropertyChangedL
       
   458 // ---------------------------------------------------------------------------    
       
   459 //
       
   460 #ifndef __WINSCW__    
       
   461 void CCamLocationIconController::HandlePropertyChangedL( const TUid& aCategory, const TUint aKey )
       
   462     {
       
   463     PRINT( _L("Camera => CCamLocationIconController::HandlePropertyChangedL") ); 	    	
       
   464 
       
   465     TInt value = KLocationSettingStateOff;
       
   466     if( KPSUidLocationTrail == aCategory && KLocationTrailState == aKey )
       
   467         {
       
   468         TInt err = iLocationStateWatcher->Get( value );
       
   469         if( KErrNone == err && -1 != value && KCamLocationTrailStopped <= value && KCamLocationTrailGPSDataAvail >= value )
       
   470             {
       
   471             SetLocationState( value );
       
   472             }
       
   473         }
       
   474     else
       
   475         {
       
   476         // Do nothing. For Lint.
       
   477         }
       
   478 
       
   479     PRINT( _L("Camera <= CCamLocationIconController::HandlePropertyChangedL") );
       
   480     }
       
   481 #else
       
   482 void CCamLocationIconController::HandlePropertyChangedL( const TUid& /*aCategory*/, const TUint /*aKey*/ )
       
   483   {
       
   484   // Empty
       
   485   }
       
   486 #endif // __WINSCW__
       
   487 
       
   488 
       
   489 // ---------------------------------------------------------------------------    
       
   490 // HandleControllerEventL
       
   491 //
       
   492 // Update the rect for any controller event
       
   493 // ---------------------------------------------------------------------------    
       
   494 //
       
   495 void 
       
   496 CCamLocationIconController::HandleControllerEventL( TCamControllerEvent aEvent,
       
   497                                                     TInt                /*aError*/ )
       
   498 	{
       
   499 	PRINT( _L("Camera => CCamLocationIconController::HandleControllerEventL") );
       
   500 	if ( ECamEventExitRequested != aEvent )
       
   501         {
       
   502         TBool locIconVisible( EFalse );
       
   503         locIconVisible = 
       
   504             iController.IntegerSettingValue( ECamSettingItemRecLocation ) == ECamLocationOn;
       
   505 
       
   506         if ( locIconVisible ) 
       
   507     	    {
       
   508     	    PRINT( _L("Camera => UpdateRect()") );
       
   509 	        UpdateRect();
       
   510 	        PRINT( _L("Camera <= UpdateRect()") );
       
   511     	    }
       
   512     	}
       
   513     PRINT( _L("Camera <= CCamLocationIconController::HandleControllerEventL") );
       
   514 	}
       
   515