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