📄 camtimer.cpp
字号:
bmp = NULL;
}
/*
-------------------------------------------------------------------------------
SaveImageL();
Description: Save an image. This function starts an asynchronous series of
functions to save the image into a file.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CCamTimerFormView::SaveImageL()
{
// Delete old thumb nail-file
RFs fsSession;
User::LeaveIfError(fsSession.Connect());
CFileMan* fileMan = CFileMan::NewL(fsSession);
CleanupStack::PushL(fileMan);
fileMan->Delete(KThumbnailFilename,0);
CleanupStack::PopAndDestroy(); // FileMan
fsSession.Close();
// Be sure that we have an image to be saved
if(iContainer->iImageReady)
{
// gets path where to save the image
TFileName newFilePathAndName(KCamTimerFilename);
// Create Format and Codec
// quality factor from 0 to 100 (55 used here)
iFormat->iSettings.iQualityFactor = KJpgSavingQualityFactor;
iFormat->iSettings.iSampleScheme =
TMdaJpgSettings::TColorSampling(TMdaJpgSettings::EColor420);
TMdaPackage* codec = NULL;
CleanupStack::PushL(codec);
// create a file to save the image into
// this is done in an asynch function
iFileSaver->CreateL( newFilePathAndName, iFormat, codec, NULL );
// set flag, can't take new pictures when saving
iSavingImage = ETrue;
// codec
CleanupStack::PopAndDestroy(1);
// increase the "index" by one (not used for anything at the moment)
iCurrentImage++;
}
}
/*
-------------------------------------------------------------------------------
MiuoCreateComplete();
Description: This function is called when the asynch. function
iFileSaver->CreateL() completes. The error value tells if the
creation was successful. If it was, we have created a file
into which we can now save the image.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CCamTimerFormView::MiuoCreateComplete(TInt aError)
{
if (( aError == KErrNone) && iFileSaver)
{
TRAP( aError, iFileSaver->ConvertL(*(iContainer->GetBmpForSaving()),
TRect(0,0,0,0), 0));
}
else
{
User::Leave(aError);
}
}
/*
-------------------------------------------------------------------------------
MiuoConvertComplete();
Description: This function is called when the asynch. function
iFileSaver->ConvertL() completes. Now the image saving has
completed.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CCamTimerFormView::MiuoConvertComplete(TInt /*aError*/)
{
// set flag, can take new pictures
iSavingImage = EFalse;
}
/*
-------------------------------------------------------------------------------
MiuoOpenComplete();
Description: From MMdaImageUtilObserver, implement this if you use this
observer to open a imagefile.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CCamTimerFormView::MiuoOpenComplete(TInt /*aError*/)
{
}
//
// CCamTimerDialog class
//
/*
-------------------------------------------------------------------------------
CCamTimerDialog(TInt& aValue)
Description: C++ Constructor.
Return value: N/A
-------------------------------------------------------------------------------
*/
// C++ constructor, initialize data
CCamTimerDialog::CCamTimerDialog(TInt& aValue)
: iEditorValue(&aValue)
{
}
/*
-------------------------------------------------------------------------------
PreLayoutDynInitL()
Description: Function for doing pre layout events.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CCamTimerDialog::PreLayoutDynInitL()
{
// Make sure that editor's value is inside valid range
CheckEditorValue();
}
/*
-------------------------------------------------------------------------------
OkToExitL(TInt aButtonId)
Description: Function for doing on exit events
Return value: N/A
-------------------------------------------------------------------------------
*/
TBool CCamTimerDialog::OkToExitL(TInt aButtonId)
{
switch (aButtonId)
{
// If cancel is hit
case EAknSoftkeyCancel:
// Return ETrue and kill the dialog window
return ETrue;
break;
// If ok button is hit
case EAknSoftkeyOk:
// Get editor's value and set it to external variable
*iEditorValue=((CEikNumberEditor*)Control(ECamTimerNumberEditor))->Number();
return ETrue;
break;
// If any other key is hit
default:
// Return EFalse and do nothing else
return EFalse;
break;
}
}
/*
-------------------------------------------------------------------------------
CheckEditorValue()
Description: Checks that the editor value is within given minimum and maximum
Return value: N/A
-------------------------------------------------------------------------------
*/
void CCamTimerDialog::CheckEditorValue()
{
TInt min=1;
TInt max=20;
// Get the editor
CEikNumberEditor* editor=static_cast<CEikNumberEditor*>(Control(ECamTimerNumberEditor));
// Check if value to be set to editor is too high.
if(*iEditorValue<min)
// Set value to the editor's maximum value.
*iEditorValue=min;
// Check if value to be set to editor is too low.
if(*iEditorValue>max)
// Set value to the editor's minimum value.
*iEditorValue=max;
// Set value to editor.
editor->SetNumber(*iEditorValue);
}
//
// CCamTimerAppUi class
//
/*
-------------------------------------------------------------------------------
CCamTimerAppUi(TInt& aValue)
Description: C++ constructor
Return value: N/A
-------------------------------------------------------------------------------
*/
CCamTimerAppUi::CCamTimerAppUi(TInt& aValue)
: iWaitingTime(&aValue)
{
}
/*
-------------------------------------------------------------------------------
ConstructL();
Description: 2nd phase Constructor. Setting up attributes, construction
continues in CompleteConstructL() below.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CCamTimerAppUi::ConstructL()
{
BaseConstructL();
// Averell view launching
CCamTimerFormView* view=new(ELeave)CCamTimerFormView(iWaitingTime);
CleanupStack::PushL(view);
view->ConstructL();
// add created view to this AppUi
AddViewL(view);
// view
CleanupStack::Pop();
// activate view
ActivateLocalViewL( view->Id() );
}
/*
-------------------------------------------------------------------------------
~CCamTimerAppUi
Description: Destructor
Return value: N/A
-------------------------------------------------------------------------------
*/
CCamTimerAppUi::~CCamTimerAppUi()
{
}
/*
-------------------------------------------------------------------------------
HandleKeyEventL
Description: Handles a key event (we are monitoring for the navibutton)
Return value: N/A
-------------------------------------------------------------------------------
*/
TKeyResponse CCamTimerAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
{
TInt code = aKeyEvent.iCode;
switch(code)
{
// navigator button is pressed
case EKeyOK:
TInt temp;
temp=*iWaitingTime;
// Convert time to microseconds
*iWaitingTime*=1000000;
// Start the timing with preview pictures, take a picture and save it.
static_cast<CCamTimerFormView*>(View(KCamTimerViewId))->TimerL();
// Return the original waiting time in seconds
*iWaitingTime=temp;
return (EKeyWasConsumed);
break;
default:
break;
}
// default return value
return(EKeyWasNotConsumed);
}
/*
-------------------------------------------------------------------------------
HandleCommandL
Description: Handles a given command
Return value: N/A
-------------------------------------------------------------------------------
*/
void CCamTimerAppUi::HandleCommandL(TInt aCommand)
{
// A switch statement that will be controlled by the command id get from
// the OfferKayEvent
switch (aCommand)
{
// If the exit command is selected from the softkeys
case EAknSoftkeyExit:
// If the exit command is given by the framework
case EEikCmdExit:
// If the exit command is selected from the menu
case EClose:
// Call the CBaActiveScheduler's Exit function that stops
// the application's thread and destroys it.
CBaActiveScheduler::Exit();
break;
// "Start timing" was selected from the Options menu
case ECamTimerStartTiming:
TInt temp1;
temp1=*iWaitingTime;
// Convert time to microseconds
*iWaitingTime*=1000000;
// Start timing the picturetaking
static_cast<CCamTimerFormView*>(View(KCamTimerViewId))->TimerL();
// Return the waiting time value in seconds
*iWaitingTime=temp1;
break;
// "Set time" was selected from the Options menu
case ECamTimerSetTime:
// Start the dialog to ask the number of seconds desired for
// the timing.
// Call CmdDlgL function with the selection's resource id as argument.
// This will execute the dialog
CmdDlgL(R_CAMTIMER_DIALOG);
break;
case ECamTimerLaunchPhotoAlbum:
// Start the photo album application to rename and send your picture
// via IR/BT/MMS.
CCoeAppUi::ActivateViewL(TVwsViewId(KPhotoAlbumUid, TUid::Uid(1)));
break;
// If the menu command is none of the above do nothing
default:
break;
}
}
// This function creates the dialog for settings.
void CCamTimerAppUi::CmdDlgL(TInt aResourceId)
{
// If the resource id of the dialog to be executed is R_CAMTIMER_DIALOG
// do the following.
if(aResourceId == R_CAMTIMER_DIALOG)
// There can be multiple id comparisons here like this causing
// launching of different dialogs.
{
// Allocate memory for a new dialog of class CCamTimerDialog
CCamTimerDialog* dialog=new(ELeave)CCamTimerDialog(*iWaitingTime);
// Set the dialog to execution by calling its ExecuteLD function.
// The dialog will be deleted on return
dialog->ExecuteLD(R_CAMTIMER_DIALOG);
}
}
//
// CCamTimerDocument class
//
/*
-----------------------------------------------------------------------------
CCamTimerDocument
Creates new CamTimer document.
Return Values: N/A
-----------------------------------------------------------------------------
*/
CCamTimerDocument::CCamTimerDocument(CAknApplication& aApp)
: CAknDocument(aApp)
{
}
/*
-----------------------------------------------------------------------------
CreateAppUiL
Creates new CCamTimerAppUi and returns a pointer to it.
Return Values: pointer to CCamTimerAppUi
-----------------------------------------------------------------------------
*/
CEikAppUi* CCamTimerDocument::CreateAppUiL()
{
// Initialise the waiting time
iWaitingTime=KInitialValue;
CCamTimerAppUi* appui = new (ELeave) CCamTimerAppUi(iWaitingTime);
// Return the application ui that has been created
return appui;
}
//
// CCamTimerApplication class
//
/*
-----------------------------------------------------------------------------
CreateDocumentL()
Description: Creates new CamTimer document.
Return Values: pointer to new CCamTimerDocument object
-----------------------------------------------------------------------------
*/
CApaDocument* CCamTimerApplication::CreateDocumentL()
{
return new (ELeave) CCamTimerDocument(*this);
}
/*
-----------------------------------------------------------------------------
AppDllUid()
Return the UID of CamTimer application.
Return Values: UID
-----------------------------------------------------------------------------
*/
TUid CCamTimerApplication::AppDllUid() const
{
return KUidCamTimerApp;
}
// OTHER EXPORTED FUNCTIONS
//=============================================================================
/*
-----------------------------------------------------------------------------
NewApplication
Creates new CCamTimerApplication application and returns a pointer to it.
Return Values: pointer to CApaApplication
-----------------------------------------------------------------------------
*/
EXPORT_C CApaApplication* NewApplication()
{
return new CCamTimerApplication;
}
/*
-----------------------------------------------------------------------------
E32Dll
Called when the DLL is loaded.
Return Values: KErrNone
-----------------------------------------------------------------------------
*/
GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
{
return KErrNone;
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -