📄 cameraappcontroller.cpp
字号:
void CCameraAppController::SnapL()
{
iCameraCaptureEngine->SnapL();
}
/*
-------------------------------------------------------------------------------
Gets the snapped image
-------------------------------------------------------------------------------
*/
CFbsBitmap& CCameraAppController::GetSnappedImage()
{
return *iBitmapSnap;
}
/*
-------------------------------------------------------------------------------
Checks if there is not enough free space left on drive C.检查C盘有没有足够的空间
如果C盘空间不足返回 ETrue
Returns ETrue if there is not enough space on drive C, EFalse otherwise.
-------------------------------------------------------------------------------
*/
TBool CCameraAppController::DiskSpaceBelowCriticalLevel()
{
TBool result = ETrue;
const TInt KDataSize = 500000;
TRAPD(err, (result = SysUtil::DiskSpaceBelowCriticalLevelL(
&(iEikEnv->FsSession()), KDataSize, EDriveC)));
if (err != KErrNone)
{
return ETrue;
}
else
{
return result;
}
}
/*
-------------------------------------------------------------------------------
Saves the snapped image on disk
-------------------------------------------------------------------------------
*/
void CCameraAppController::SaveImageL()
{
// Get the next usable file name
GetNextUsableFileName();
// Save the image
iCameraCaptureEngine->SaveImageL( QualityFactor(), &iNewFileName,
&(iEikEnv->FsSession()) );
}
/*
-------------------------------------------------------------------------------
Returns the current quality factor
-------------------------------------------------------------------------------
*/
TJpegQualityFactor CCameraAppController::QualityFactor() const
{
return KHighQualityFactor;
}
/*
-------------------------------------------------------------------------------
Initializes the sound player
-------------------------------------------------------------------------------
*/
void CCameraAppController::CreateSoundPlayerL()
{
// Only in 3rd Edition. The snap sound file can be found
// in \private\<UID3>\ folder.
RFs& fs = iEikEnv->FsSession();
User::LeaveIfError( fs.CreatePrivatePath( EDriveC ) );
User::LeaveIfError( fs.SetSessionToPrivate( EDriveC ) );
User::LeaveIfError( fs.PrivatePath(iSoundFilePath) );
iSoundPlayer = CMdaAudioPlayerUtility::NewL(
*this, EMdaPriorityMin, EMdaPriorityPreferenceNone);
}
/*
-------------------------------------------------------------------------------
Plays a sound according to aSoundId 播放声音
-------------------------------------------------------------------------------
*/
void CCameraAppController::PlaySound( TInt aSoundId )
{
TFileName soundFile(iSoundFilePath);
switch(aSoundId)
{
case ESoundIdSnap:
soundFile.Append(KSnapSoundFile);
break;
case ESoundIdFocused:
soundFile.Append(KFocusedSoundFile);
break;
default:
return;
}
TRAP_IGNORE(iSoundPlayer->OpenFileL(soundFile));
}
/*
-------------------------------------------------------------------------------
Shows the status of image conversion process
-------------------------------------------------------------------------------
*/
void CCameraAppController::ShowConversionStatusL( const TDesC& /*aStatus*/,
TBool /*aShowFileName*/ )
{
if( !iContainer )
return;
}
/*
-------------------------------------------------------------------------------
Returns whether the image conversion operation is in progress or not
-------------------------------------------------------------------------------
*/
TBool CCameraAppController::IsImageConversionInProgress()
{
return iCameraCaptureEngine->IsImageConversionInProgress();
}
/*
-------------------------------------------------------------------------------
Redraw navi tabs
-------------------------------------------------------------------------------
*/
void CCameraAppController::RedrawNaviPaneL()
{
if ( iCameraCaptureEngine )
{
iCameraCaptureEngine->SetEngineState( EEngineIdle );
}
}
/*
-------------------------------------------------------------------------------
Returns the engine state //返回引擎状态
-------------------------------------------------------------------------------
*/
TEngineState CCameraAppController::GetEngineState()
{
return iCameraCaptureEngine->GetEngineState();
}
/*
-------------------------------------------------------------------------------
Sets the engine state
-------------------------------------------------------------------------------
*/
void CCameraAppController::SetEngineState( TEngineState aState )
{
iCameraCaptureEngine->SetEngineState( aState );
}
/*
-------------------------------------------------------------------------------
Gets the next usable file name
-------------------------------------------------------------------------------
*/
void CCameraAppController::GetNextUsableFileName()
{
TInt index = 0;
do {
iNewFileName.Copy( iImagePath->Des() );
iNewFileName.Append( KImageFileName );
TBuf<KFileNameIndexMaxLength> num;
num.Num( index );
iNewFileName.Append( num );
iNewFileName.Append( KJpgFileExtension );
if ( !BaflUtils::FileExists( iEikEnv->FsSession(),
iNewFileName ) )
break;
index ++;
} while ( 1 );
}
/*
-------------------------------------------------------------------------------
Handles the error messages from the capture engine
-------------------------------------------------------------------------------
*/
void CCameraAppController::HandleError(TInt aError)
{
switch( aError )
{
case KErrNone:
break;
case KErrInUse:
// Since the camera is in use, we need to display a message
if ( iContainer )
{
HBufC* resCameraInUse = NULL;
TRAP_IGNORE(resCameraInUse = StringLoader::LoadL(R_CAMERA_IN_USE));
iContainer->ShowErrorMessage( *resCameraInUse );
delete resCameraInUse;
}
break;
case KErrHardwareNotAvailable:
if ( iContainer )
{
HBufC* resNoCamera = NULL;
TRAP_IGNORE(resNoCamera = StringLoader::LoadL(R_NO_CAMERA));
iContainer->ShowErrorMessage( *resNoCamera );
delete resNoCamera;
}
break;
case KErrExtensionNotSupported: // used when AF is not supported
break;
}
}
/*
-------------------------------------------------------------------------------
Returns whether the camera is being used by another application
//返回相机是否正在使用另一个程序
-------------------------------------------------------------------------------
*/
TBool CCameraAppController::IsCameraUsedByAnotherApp()
{
// return true if camera engine is not yet constructed
//如果引擎未创建,返回 相机
if( !iCameraCaptureEngine )
return ETrue;
return iCameraCaptureEngine->IsCameraUsedByAnotherApp();
}
/*
-------------------------------------------------------------------------------
Sets the zoom factor
-------------------------------------------------------------------------------
*/
TInt CCameraAppController::SetZoomL(TBool aEnable) // CSI: 40 # (Zoom factor is not an error code)
{
return iCameraCaptureEngine->SetZoomFactorL( aEnable );
}
/*
-------------------------------------------------------------------------------
Starts the optimised autofocus operation. 启动自动对焦
Does nothing if AF is not supported.
-------------------------------------------------------------------------------
*/
void CCameraAppController::StartFocusL()
{
iCameraCaptureEngine->StartFocusL();
}
/*
-------------------------------------------------------------------------------
Cancels an ongoing AF operation 取消自动对焦
-------------------------------------------------------------------------------
*/
void CCameraAppController::FocusCancel()
{
iCameraCaptureEngine->FocusCancel();
}
/*
-------------------------------------------------------------------------------
From MMdaAudioPlayerCallback. Called when initialization is complete.
-------------------------------------------------------------------------------
*/
void CCameraAppController::MapcInitComplete(TInt aError,
const TTimeIntervalMicroSeconds& /*aDuration*/)
{
if (!aError)
{
const TInt KSilencer = 3;
iSoundPlayer->SetVolume(iSoundPlayer->MaxVolume() / KSilencer);
iSoundPlayer->Play();
}
}
/*
-------------------------------------------------------------------------------
From MMdaAudioPlayerCallback. Called when playback is complete.
-------------------------------------------------------------------------------
*/
void CCameraAppController::MapcPlayComplete(TInt /*aError*/)
{
iSoundPlayer->Close();
}
/*
-------------------------------------------------------------------------------
Notifies the controller if the client rect size changes
-------------------------------------------------------------------------------
*/
void CCameraAppController::ClientRectChangedL(const TRect& aRect)
{
if( !iCameraCaptureEngine )
return;
iCameraCaptureEngine->ClientRectChangedL(aRect);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -