📄 cameraappappui.cpp
字号:
/*
* Copyright ?2008 Nokia Corporation.
*/
#include <avkon.hrh>
#include <eikmenup.h>
#include <CameraApp.rsg>
#include <apgcli.h>
#include <hal.h>
#include <hlplch.h> // HlpLauncher
#include <aknnotewrappers.h>
#include <centralrepository.h>
#include <ProfileEngineSDKCRKeys.h>
#include <aknmessagequerydialog.h> // CAknMessageQueryDialog
#include <stringloader.h>
#include "CameraAppAppUi.h"
#include "CameraAppView.h"
#include "Cameraapp.hrh"
#include "CameraAppController.h"
#include "CameraAppBaseContainer.h"
#include "CameraApp.pan"
#include "cameraappapp.h"
//#include "CameraApp_sc.hlp.hrh"
/*
-------------------------------------------------------------------------------
Constructor. Initializes member variables.
-------------------------------------------------------------------------------
*/
CCameraAppAppUi::CCameraAppAppUi()
: CAknViewAppUi(),
iController( 0 )
{
}
/*
-------------------------------------------------------------------------------
Symbian OS 2nd phase constructor
-------------------------------------------------------------------------------
*/
void CCameraAppAppUi::ConstructL()
{
// Try to resolve the best orientation for the app
BaseConstructL(EAknEnableSkin|ResolveCameraOrientation());
// Resolve the Media Gallery application's UID (a native app)
iMediaGalleryUid3 = KMediaGalleryUID3PostFP1;
// Create a camera controller
iController = new (ELeave) CCameraAppController(*this);
iController->ConstructL();
CAknAppUiBase::TAppUiOrientation orientation = Orientation();
if (orientation == CAknAppUiBase::EAppUiOrientationPortrait)
{
iController->SetCameraOrientation(ECameraPortrait);
}
else
{
iController->SetCameraOrientation(ECameraLandscape);
}
iView = CCameraAppView::NewLC();
AddViewL( iView ); // transfer ownership to CAknViewAppUi
CleanupStack::Pop(iView);
SetDefaultViewL(*iView);
// Make this class observe changes in foreground events
iEikonEnv->AddForegroundObserverL( *this );
// Default mode is viewfinding
iCameraMode = EViewFinding;
}
void CCameraAppAppUi::HandleGainingForeground()
{
// Application gets focused so reserve the camera
// if it was disabled (ResetEngine() called)
if (!iController)
{
ResetEngine();
}
}
void CCameraAppAppUi::HandleLosingForeground()
{
// Application loses focus so release the camera
if (iController)
{
// Delete old controller and capture engine
delete iController;
iController = NULL;
}
}
/*
-------------------------------------------------------------------------------
Reset controller and capture engine
-------------------------------------------------------------------------------
*/
void CCameraAppAppUi::ResetEngine()
{
// Delete old controller and capture engine
if (iController)
{
delete iController;
iController = NULL;
}
// Create new controller and capture engine
iController = new (ELeave) CCameraAppController(*this);
iController->ConstructL();
// Set new controller pointers
iView->iContainer->SetController(iController);
iController->SetAppContainer(iView->iContainer);
// Check orientation
CAknAppUiBase::TAppUiOrientation orientation = Orientation();
if (orientation == CAknAppUiBase::EAppUiOrientationPortrait)
{
iController->SetCameraOrientation(ECameraPortrait);
}
else
{
iController->SetCameraOrientation(ECameraLandscape);
}
iController->SkipFrames(KNumOfFrames);
iController->InitializeCameraL( ClientRect() );
iController->StartViewFinderL();
iCameraMode = EViewFinding;
}
/*
-------------------------------------------------------------------------------
Destructor. Frees reserved resources.
-------------------------------------------------------------------------------
*/
CCameraAppAppUi::~CCameraAppAppUi()
{
if (iController)
delete iController;
}
void CCameraAppAppUi::HandleResourceChangeL( TInt aType )
{
CAknAppUi::HandleResourceChangeL( aType );
if ( aType==KEikDynamicLayoutVariantSwitch )
{
static_cast<CCameraAppView*>( View( TUid::Uid( EViewIdStandard ) ) )->HandleSizeChange( aType );
// Reset engine if app is in foreground. If not ResetEngine() will be
// called when app is coming to foreground later.
if (IsForeground())
{
ResetEngine();
}
}
}
/*
-------------------------------------------------------------------------------
Takes care of key event handling
-------------------------------------------------------------------------------
*/
TKeyResponse CCameraAppAppUi::HandleKeyEventL(
const TKeyEvent& aKeyEvent,TEventCode aType)
{
if (!iController)
{
return EKeyWasNotConsumed;
}
if (iController->IsCameraUsedByAnotherApp())
{
return EKeyWasNotConsumed;
}
// handle autofocus requests
if (aKeyEvent.iScanCode == KStdKeyCameraFocus)
{
TEngineState state = iController->GetEngineState();
if ( state != EEngineIdle && state != EFocusing )
{
return EKeyWasConsumed;
}
switch ( aType )
{
case EEventKeyDown:
iController->StartFocusL();
break;
case EEventKeyUp:
iController->FocusCancel();
break;
default:
break;
}
return EKeyWasConsumed;
}
switch ( aKeyEvent.iCode )
{
case EKeyUpArrow:
{
// Increase the zoom factor if possible. It has reached the high
// limit then it will not change.
if ( iCameraMode == EViewFinding )
iController->SetZoomL( ETrue );
return EKeyWasConsumed;
}
case EKeyDownArrow:
{
// Decrease the zoom factor if possible. It has reached the low
// limit then it will not change.
if ( iCameraMode == EViewFinding )
iController->SetZoomL( EFalse );
return EKeyWasConsumed;
}
case EKeyOK:
case EKeyCamera:
case KKeyCameraShutter:
{
DoSnapL();
return EKeyWasConsumed;
}
default:
break;
}
return EKeyWasNotConsumed;
}
/*
-------------------------------------------------------------------------------
Takes care of command handling
-------------------------------------------------------------------------------
*/
void CCameraAppAppUi::HandleCommandL(TInt aCommand)
{
switch ( aCommand )
{
case EAknSoftkeyExit:
case EAknSoftkeyBack:
case EEikCmdExit:
{
// If the image saving is in progress, we should not exit. We
// have to wait for the conversion to be finished just in case
// we will get a partially converted image in the
// default images folder
if ( iController && iController->IsImageConversionInProgress() )
return;
Exit();
break;
}
case ECameraAppCmdSnap:
{
DoSnapL();
break;
}
case ECameraAppCmdNewImage:
{
DoNewImageL();
break;
}
case ECameraAppCmdGotoGallery:
{
GoToMediaGalleryL();
break;
}
case ECameraAppCmdFRNormal:
{
iController->SetFocusRangeL( CCamAutoFocus::ERangeNormal );
break;
}
case ECameraAppCmdFRMacro:
{
iController->SetFocusRangeL( CCamAutoFocus::ERangeMacro );
break;
}
case ECameraAppCmdFRPortrait:
{
iController->SetFocusRangeL( CCamAutoFocus::ERangePortrait );
break;
}
case ECameraAppCmdFRInfinite:
{
iController->SetFocusRangeL( CCamAutoFocus::ERangeInfinite );
break;
}
case ECameraAppCmdHelp:
{
CArrayFix <TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL();
HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), buf);
break;
}
case ECameraAppCmdAbout:
{
HBufC* title = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TITLE);
HBufC* msg = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TEXT);
// Note: CodeScanner gives a false positive of "Neglected to put
// variable on cleanup stack (Id: 35)" on dlg.
CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL(*msg); // CSI: 35 #
dlg->PrepareLC(R_DIALOG_ABOUT);
dlg->SetHeaderTextL(*title);
dlg->RunLD();
CleanupStack::PopAndDestroy(msg);
CleanupStack::PopAndDestroy(title);
break;
}
default:
break;
}
}
/*
-------------------------------------------------------------------------------
Activates Media Gallery view
-------------------------------------------------------------------------------
*/
void CCameraAppAppUi::GoToMediaGalleryL()
{
// Gets viewId to activate Media Gallery view
TVwsViewId id = TVwsViewId( TUid::Uid(iMediaGalleryUid3),
TUid::Uid(KMediaGalleryListViewUID) );
const TDesC& temp = iController->ImagePath();
HBufC8* buf = HBufC8::NewLC(temp.Length());
buf->Des().Copy(temp);
ActivateViewL(id, TUid::Uid( KMediaGalleryCmdMoveFocusTo ), *buf);
CleanupStack::PopAndDestroy(buf);
}
/*
-------------------------------------------------------------------------------
Returns the camera mode
-------------------------------------------------------------------------------
*/
TCameraMode CCameraAppAppUi::CameraMode()
{
return iCameraMode;
}
/*
-------------------------------------------------------------------------------
Takes a picture if possible
-------------------------------------------------------------------------------
*/
void CCameraAppAppUi::DoSnapL()
{
// If the image is still being converted, then stop going further.
TEngineState state = iController->GetEngineState();
if ( state != EEngineIdle && state != EConverted )
return;
if ( iController->IsCameraUsedByAnotherApp() )
return;
// Snap the picture and save the image into the specific location
if ( iCameraMode == EViewFinding )
{
// Ensure that there is enough free space left
if (iController->DiskSpaceBelowCriticalLevel())
{
HBufC* resMemoryLow = StringLoader::LoadLC(R_MEMORY_LOW);
_LIT(KMemoryLowHdr, "");
iEikonEnv->InfoWinL(*resMemoryLow, KMemoryLowHdr);
CleanupStack::PopAndDestroy(resMemoryLow);
}
else
{
// In 3rd Ed. devices, play sound only if not in Meeting or Silent
// profile
CRepository* cRepository = CRepository::NewL(KCRUidProfileEngine);
TInt currentProfileId;
User::LeaveIfError(cRepository->Get(KProEngActiveProfile,currentProfileId));
delete cRepository;
if (currentProfileId != 1 && currentProfileId != 2) // CSI: 47 # (1 = Meeting, 2 = Silent)
{
iController->PlaySound(ESoundIdSnap);
}
iController->SnapL();
iCameraMode = EImageSnapped;
}
}
else if ( iCameraMode == EImageSnapped )
{
// Since the camera has taken one picture, then do the viewfinding
// again
DoNewImageL();
}
}
/*
-------------------------------------------------------------------------------
Starts the viewfinder after taking a picture. Also updates the navi tabs.
-------------------------------------------------------------------------------
*/
void CCameraAppAppUi::DoNewImageL()
{
// Redisplay the default navi pane
iController->RedrawNaviPaneL();
//Start the viewfinder
iController->StartViewFinderL();
iCameraMode = EViewFinding;
}
/*
-------------------------------------------------------------------------------
Returns the help context for this application
-------------------------------------------------------------------------------
*/
CArrayFix <TCoeHelpContext>* CCameraAppAppUi::HelpContextL() const
{
CArrayFixFlat <TCoeHelpContext>* array = new (ELeave)CArrayFixFlat <TCoeHelpContext>(1);
CleanupStack::PushL(array);
_LIT(KContextApplication,"Just temp");
array->AppendL(TCoeHelpContext(KUidHelpFile, KContextApplication));
CleanupStack::Pop(array);
return array;
}
/*
-------------------------------------------------------------------------------
Returns KAppOrientationLandscape for devices where the camera is designed to
work in landscape orientation, 0 for others.
-------------------------------------------------------------------------------
*/
TUint32 CCameraAppAppUi::ResolveCameraOrientation()
{
TUint32 ret = 0;
TInt mUid;
HAL::Get(HAL::EMachineUid, mUid);
// for S60 3rd Edition devices (MachineUID == 0x20??????), assume landscape
if( mUid > 0x20000000 )
{
ret = EAppOrientationLandscape;
}
// ...with these exceptions:
switch( mUid )
{
case 0x20000602: // 5500
case 0x20000606: // 6290
case 0x20002495: // E50
case 0x20002D7F: // E61i
case 0x20000604: // E65
case 0x20001857: // E70 (orientation follows cover position)
case 0x200005FF: // N71
case 0x200005FC: // N91
{
ret = 0;
break;
}
case 0x10200F98: // N90 (2nd Ed, FP3)
{
ret = EAppOrientationLandscape;
break;
}
default:
{
break;
}
}
return ret;
}
// end of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -