camerauis/cameraapp/generic/src/CamStandbyContainer.cpp
changeset 0 1ddebce53859
child 12 8c55c525d5d7
equal deleted inserted replaced
-1:000000000000 0:1ddebce53859
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Container for standby mode*
       
    15 */
       
    16 
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <aknview.h>
       
    20 #include <eiklabel.h>
       
    21 #include <StringLoader.h>
       
    22 #include <AknsFrameBackgroundControlContext.h>
       
    23 #include <AknsDrawUtils.h>
       
    24 #include <AknBidiTextUtils.h>
       
    25 #include <textresolver.h>
       
    26 #include "CamStandbyContainer.h"
       
    27 #include "CamTimer.h"
       
    28 #include "Cam.hrh"
       
    29 #include "CamUtility.h"
       
    30 #include "CamAppUi.h"
       
    31 #include "CamViewBase.h"
       
    32 #include <cameraapp.rsg>
       
    33 #include <vgacamsettings.rsg>
       
    34 #include <ctsydomainpskeys.h>
       
    35 
       
    36 // CONSTANTS
       
    37 
       
    38 const TInt KForegroundDelayTimeout = 500;
       
    39 
       
    40 // ================= MEMBER FUNCTIONS =======================
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // CCamStandbyContainer::NewL
       
    44 // Symbian OS two-phased constructor
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CCamStandbyContainer* CCamStandbyContainer::NewL( const TRect& aRect, CAknView& aView,
       
    48                                                   CCamAppController& aController,
       
    49                                                   TInt aError )
       
    50 
       
    51     {
       
    52     CCamStandbyContainer* self = 
       
    53                   new( ELeave ) CCamStandbyContainer( aController, aView, aError );
       
    54     CleanupStack::PushL( self );
       
    55     self->ConstructL( aRect, aError );
       
    56     CleanupStack::Pop( self );
       
    57     return self;
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // CCamStandbyContainer::~CCamStandbyContainer
       
    62 // Destructor
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CCamStandbyContainer::~CCamStandbyContainer()
       
    66   {
       
    67   PRINT( _L("Camera => ~CCamStandbyContainer"))
       
    68   if( iForegroundTimer )
       
    69     {
       
    70     iForegroundTimer->Cancel();
       
    71     delete iForegroundTimer;
       
    72     }
       
    73     
       
    74   delete iText;
       
    75   delete iWrappedLabelText;    
       
    76   PRINT( _L("Camera => ~CCamStandbyContainer") );
       
    77   }
       
    78   
       
    79 // ---------------------------------------------------------
       
    80 // CCamStandbyContainer::ConstructL
       
    81 // Symbian OS 2nd phase constructor
       
    82 // ---------------------------------------------------------
       
    83 //
       
    84 void CCamStandbyContainer::ConstructL( const TRect& aRect, TInt aError )
       
    85     {
       
    86     PRINT( _L("Camera => CCamStandbyContainer::ConstructL"))
       
    87     CCamContainerBase::BaseConstructL( aRect );
       
    88 
       
    89     iText = new ( ELeave ) CEikLabel;
       
    90     iText->SetContainerWindowL( *this );
       
    91 
       
    92     iText->SetAlignment( EHCenterVCenter );
       
    93     iText->SetExtent( TPoint( 0, 0 ), aRect.Size() );
       
    94     // tell the CEikLabel that it should not do the visual 
       
    95     // conversion (Arabic right to left) because the app 
       
    96     // will do it via 
       
    97     // AknBidiTextUtils::ConvertToVisualAndWrapToStringL
       
    98     iText->UseLogicalToVisualConversion( EFalse );
       
    99 
       
   100     // Get label text from resource
       
   101     HBufC* labelText;
       
   102     if ( static_cast<CCamAppUi*>( iEikonEnv->AppUi() )->IsConstructionComplete() )
       
   103         {
       
   104 	    switch( aError )
       
   105 	        {
       
   106 	        case KErrNone:
       
   107 	            labelText = StringLoader::LoadLC( R_CAM_STANDBY_TEXT );
       
   108 	            break;
       
   109 	        case KErrInUse:
       
   110 	            labelText = StringLoader::LoadLC( R_CAM_STANDBY_CAMERA_IN_USE_TEXT );
       
   111 	            break;
       
   112 	        case KErrNoMemory:
       
   113 	        	labelText = StringLoader::LoadLC( R_CAM_MEMLO_NOT_ENOUGH_MEMORY );
       
   114 	            break;
       
   115 	        case KErrPermissionDenied:
       
   116 	            labelText = StringLoader::LoadLC( R_CAM_STANDBY_CAMERA_DISABLED_TEXT );
       
   117                 break;
       
   118 	        default: // any other error
       
   119 	            labelText = StringLoader::LoadLC( R_CAM_STANDBY_CAMERA_UNAVAILABLE_TEXT );
       
   120 	            break;
       
   121 	        }
       
   122         }
       
   123 	 else
       
   124         {
       
   125         labelText = StringLoader::LoadLC( R_CAM_STANDBY_EMPTY_TEXT );
       
   126         }        
       
   127 
       
   128 
       
   129     iText->SetTextL( *labelText );
       
   130     // Wrap the text, where it doesn't fit.
       
   131     // ...Create the line width array necessary for ConvertToVisual..()
       
   132     const TInt KLabelMaxLines = 5;
       
   133     CArrayFix<TInt>* lineWidths = 
       
   134         new ( ELeave ) CArrayFixFlat<TInt> ( KLabelMaxLines );
       
   135     CleanupStack::PushL( lineWidths );
       
   136     for (TInt i = 0; i < KLabelMaxLines; ++i )
       
   137         {
       
   138         lineWidths->AppendL( aRect.Width() );            
       
   139         }
       
   140     // ...Create the text buffer that will receive the wrapped text.
       
   141     iWrappedLabelText = HBufC::NewL(
       
   142         labelText->Length() + KLabelMaxLines * ( KAknBidiExtraSpacePerLine + 1 ) );
       
   143     TPtr ptr = iWrappedLabelText->Des();
       
   144     // ...Get the wrapped text conversion.
       
   145     AknBidiTextUtils::ConvertToVisualAndWrapToStringL(
       
   146         labelText->Des(),
       
   147         *lineWidths,
       
   148         *AknLayoutUtils::FontFromId( EAknLogicalFontPrimaryFont ),
       
   149         ptr,
       
   150         ETrue
       
   151         );
       
   152     // ...Cleanup
       
   153     CleanupStack::PopAndDestroy( lineWidths );  
       
   154     CleanupStack::PopAndDestroy( labelText );
       
   155 
       
   156     // Set the wrapped text to the label.
       
   157     iText->SetTextL( *iWrappedLabelText );
       
   158 
       
   159     // Initialise foreground timer - used to delay the exit
       
   160     // from standby when foreground is gained
       
   161     iForegroundTimer = CCamTimer::NewL( KForegroundDelayTimeout,
       
   162                   TCallBack( CCamStandbyContainer::ForegroundTimeout, this ) );
       
   163 
       
   164     // Make sure fixed toolbar is on top of this window
       
   165     DrawableWindow()->SetOrdinalPosition( KCamPreCaptureWindowOrdinalPos );
       
   166     }
       
   167     
       
   168 // ---------------------------------------------------------------------------
       
   169 // CCamStandbyContainer::CCamStandbyContainer
       
   170 // C++ constructor
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 CCamStandbyContainer::CCamStandbyContainer( CCamAppController& aController,
       
   174                                                         CAknView& aView, TInt aError )
       
   175 : CCamContainerBase( aController, aView ), iStandbyError( aError )
       
   176     {
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------
       
   180 // CCamStandbyContainer::CountComponentControls
       
   181 // Returns the number of controls owned
       
   182 // ---------------------------------------------------------
       
   183 //
       
   184 TInt CCamStandbyContainer::CountComponentControls() const
       
   185     {
       
   186     TInt count = 1;
       
   187     return count; // Return the number of controls inside this container
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------
       
   191 // CCamStandbyContainer::ComponentControl
       
   192 // Return pointer to a contained control
       
   193 // ---------------------------------------------------------
       
   194 //
       
   195 CCoeControl* CCamStandbyContainer::ComponentControl( TInt aIndex ) const
       
   196     {
       
   197     switch ( aIndex )
       
   198         {
       
   199         case 0:
       
   200             {
       
   201             return iText;
       
   202             }
       
   203         default:
       
   204             {
       
   205             return NULL;
       
   206             }
       
   207         }
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------
       
   211 // CCamStandbyContainer::Draw
       
   212 // Draw control
       
   213 // ---------------------------------------------------------
       
   214 //
       
   215 void CCamStandbyContainer::Draw( const TRect& /*aRect*/ ) const
       
   216     {
       
   217     PRINT( _L("Camera => CCamStandbyContainer::Draw"))
       
   218     CWindowGc& gc = SystemGc();
       
   219     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   220     AknsDrawUtils::Background( skin, iBgContext, gc, Rect() );
       
   221 
       
   222     // override the label color
       
   223     TRgb color;
       
   224     AknsUtils::GetCachedColor( skin, color, KAknsIIDQsnTextColors,
       
   225                                             EAknsCIQsnTextColorsCG6 );
       
   226     TRAPD( ignore, AknLayoutUtils::OverrideControlColorL( *iText, 
       
   227         EColorLabelText, color ) );
       
   228     if ( ignore )
       
   229         { 
       
   230         // Do nothing ( removes build warning )
       
   231         }     
       
   232     }
       
   233 
       
   234 // ----------------------------------------------------------------
       
   235 // CCamStandbyContainer::OfferKeyEventL
       
   236 // Handles this application view's command keys
       
   237 // ----------------------------------------------------------------
       
   238 //
       
   239 TKeyResponse CCamStandbyContainer::OfferKeyEventL( 
       
   240     const TKeyEvent& aKeyEvent,
       
   241     TEventCode aType )
       
   242     {
       
   243     if ( iStandbyError != KErrNone )
       
   244         {
       
   245         return EKeyWasConsumed;
       
   246         }
       
   247 
       
   248     // if the select (OK) key is pressed
       
   249     if ( ( aType == EEventKey && aKeyEvent.iCode == EKeyOK )
       
   250         // if shutter key is pressed in main camera
       
   251         || ( aType == EEventKey && 
       
   252            ( aKeyEvent.iScanCode == iPrimaryCameraCaptureKeys[0] ||
       
   253                CCamContainerBase::IsShutterKeyL(aKeyEvent, aType) ) &&
       
   254                !static_cast<CCamAppUi*>( iEikonEnv->AppUi() )->IsSecondCameraEnabled() )
       
   255         || ( IsCaptureKeyL(aKeyEvent, aType)) )
       
   256         {
       
   257         // in case we receive an enter key or MSK key event in standby mode
       
   258         // we should not call HandleCommandL function with ECamCmdExitStandby
       
   259         // because by default application will get a left softkey command id
       
   260         // when MSK is pressed. In standby mode left softkey command id is
       
   261         // ECamCmdExitStandby
       
   262         if ( !( ( aType == EEventKey || 
       
   263                   aType == EEventKeyDown || 
       
   264                   aType == EEventKeyUp ) && 
       
   265                 ( aKeyEvent.iScanCode == EStdKeyDevice3 ||
       
   266                   aKeyEvent.iScanCode == EStdKeyEnter ) ) )
       
   267              {
       
   268              iView.HandleCommandL( ECamCmdExitStandby );
       
   269              }
       
   270         return EKeyWasConsumed;
       
   271         }
       
   272     // handle navi-key up/down, left/right
       
   273     else if ( aType == EEventKey &&
       
   274         ( aKeyEvent.iScanCode == EStdKeyDownArrow ||
       
   275           aKeyEvent.iScanCode == EStdKeyUpArrow ||
       
   276           aKeyEvent.iScanCode == EStdKeyLeftArrow ||
       
   277           aKeyEvent.iScanCode == EStdKeyRightArrow ) )
       
   278         {
       
   279         iView.HandleCommandL( ECamCmdExitStandby );
       
   280         return EKeyWasConsumed;
       
   281         }
       
   282     else if ( ( aType == EEventKeyDown || aType == EEventKeyUp ) && 
       
   283     	      ( aKeyEvent.iScanCode != EStdKeyYes ) )
       
   284         {
       
   285         if ( aType == EEventKeyDown )
       
   286             {
       
   287             if( IsZoomKeyL(aKeyEvent, aType ) )
       
   288             	{
       
   289             	iView.HandleCommandL( ECamCmdExitStandby );
       
   290             	}
       
   291             }           
       
   292         // consume key up/down presses
       
   293         return EKeyWasConsumed;
       
   294         }
       
   295     else
       
   296         {
       
   297         return CCamContainerBase::OfferKeyEventL( aKeyEvent, aType );
       
   298         }
       
   299     }
       
   300 
       
   301 // ----------------------------------------------------------------
       
   302 // CCamStandbyContainer::HandleForegroundEvent
       
   303 // Handle foreground event
       
   304 // ----------------------------------------------------------------
       
   305 //
       
   306 void CCamStandbyContainer::HandleForegroundEventL( TBool aForeground )
       
   307     {
       
   308     if ( aForeground )
       
   309         {
       
   310         // start timer to delay exit from standby
       
   311         if ( !iForegroundTimer->IsActive() )
       
   312             {
       
   313             iForegroundTimer->StartTimer();
       
   314             }
       
   315         }
       
   316     else
       
   317         {
       
   318         // set text label as blank
       
   319         TRAP_IGNORE( iText->SetTextL( KNullDesC ) );
       
   320         
       
   321         // cancel timer if active
       
   322         if ( iForegroundTimer->IsActive() )
       
   323             {
       
   324             iForegroundTimer->Cancel();
       
   325             }
       
   326         }
       
   327     }
       
   328     
       
   329 // ----------------------------------------------------------------
       
   330 // CCamStandbyContainer::GetStandbyError
       
   331 // Returns the current error
       
   332 // ----------------------------------------------------------------
       
   333 //
       
   334 TInt CCamStandbyContainer::GetStandbyError() const
       
   335     {
       
   336     return iStandbyError;
       
   337     }    
       
   338 
       
   339 // ----------------------------------------------------------------
       
   340 // CCamStandbyContainer::ForegroundTimeout
       
   341 // static callback function for foreground gain timeout
       
   342 // ----------------------------------------------------------------
       
   343 //
       
   344 TInt CCamStandbyContainer::ForegroundTimeout( TAny *aPtr )
       
   345     {
       
   346     return static_cast<CCamStandbyContainer*>( aPtr )->DoForegroundTimeout();
       
   347     }
       
   348 
       
   349 // ----------------------------------------------------------------
       
   350 // CCamStandbyContainer::DoForegroundTimeout
       
   351 // Implementation function for foreground gain timeout
       
   352 // ----------------------------------------------------------------
       
   353 //
       
   354 TInt CCamStandbyContainer::DoForegroundTimeout()
       
   355     {
       
   356     TRAPD( ignore, iView.HandleCommandL( ECamCmdExitStandby ) );
       
   357     if ( ignore )
       
   358         { 
       
   359         // Do nothing ( removes build warning )
       
   360         }             
       
   361     
       
   362     return EFalse;
       
   363     }
       
   364 
       
   365 // ----------------------------------------------------------------
       
   366 // CCamStandbyContainer::HandlePointerEventL
       
   367 // ----------------------------------------------------------------
       
   368 //
       
   369 void CCamStandbyContainer::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   370     {
       
   371     RDebug::Print(_L("CCamStandbyContainer::HandlePointerEventL iType=%d iPosition=(%d, %d)"),
       
   372         aPointerEvent.iType,
       
   373         aPointerEvent.iPosition.iX,
       
   374         aPointerEvent.iPosition.iY );
       
   375 
       
   376       TInt callType( EPSCTsyCallTypeUninitialized );
       
   377       RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallType, callType );
       
   378        if ( callType != EPSCTsyCallTypeH324Multimedia)
       
   379          {
       
   380     static_cast<CCamViewBase&>( iView ).HandleCommandAoL( ECamCmdExitStandby );
       
   381          }
       
   382          else
       
   383          {
       
   384          }
       
   385     }
       
   386 
       
   387 // -----------------------------------------------------------------------------
       
   388 // CCamStandbyContainer::CreateBackgroundContextL
       
   389 // -----------------------------------------------------------------------------
       
   390 //     
       
   391 void CCamStandbyContainer::CreateBackgroundContextL()
       
   392     {
       
   393     iBgContext = CAknsBasicBackgroundControlContext::NewL( 
       
   394         KAknsIIDQsnBgAreaMain, Rect(), EFalse );
       
   395     }
       
   396 
       
   397 // End of File