📄 remotecam.cpp
字号:
// clear local pointer
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 CRemoteCamFormView::SaveImageL()
{
// Be sure that we have an image to be saved
if(iContainer->iImageReady)
{
// gets path where to save the image
TFileName newFilePathAndName(_L("C:\\aaaReca.jpg")); // now saving only as "aaaReca.jpg"
// Image name and path could be given
// in the bio message that triggers the camera.
// Create Format and Codec
iFormat->iSettings.iQualityFactor = KJpgSavingQualityFactor; // quality factor from 0 to 100 (55 used here)
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 );
iSavingImage = ETrue; // set flag, can't take new pictures when saving
CleanupStack::PopAndDestroy(1); // codec
iCurrentImage++; // increase the "index" by one (not used for anything at the moment)
}
}
/*
-------------------------------------------------------------------------------
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 CRemoteCamFormView::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 CRemoteCamFormView::MiuoConvertComplete(TInt /*aError*/)
{
iSavingImage = EFalse; // set flag, can take new pictures
}
/*
-------------------------------------------------------------------------------
MiuoOpenComplete();
Description: From MMdaImageUtilObserver, implement this if you use this
observer to open a imagefile.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CRemoteCamFormView::MiuoOpenComplete(TInt /*aError*/)
{
}
//
// CRemoteCamAppUi
//
/*
-------------------------------------------------------------------------------
~CRemoteCamAppUi
Description: Destructor
Return value: N/A
-------------------------------------------------------------------------------
*/
CRemoteCamAppUi::~CRemoteCamAppUi()
{
delete iMtm;
delete iMtmReg;
delete iSession; // must be last to be deleted
}
/*
-------------------------------------------------------------------------------
ConstructL();
Description: 2nd phase Constructor. Setting up attributes, construction
continues in CompleteConstructL() below.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CRemoteCamAppUi::ConstructL()
{
BaseConstructL();
// Create CMsvSession
iSession = CMsvSession::OpenAsyncL(*this); // new session is opened asynchronously
// CompleteConstructL() is called when async finishes
// Averell view launching
CRemoteCamFormView* view=new(ELeave)CRemoteCamFormView();
CleanupStack::PushL(view);
view->ConstructL();
AddViewL(view); // add created view to this AppUi
CleanupStack::Pop(); // view
ActivateLocalViewL( view->Id() ); // activate view
}
/*
-----------------------------------------------------------------------------
CompleteConstructL()
Creates client MTM registry when session is ready for use.
This completes model construction and is called after 'server
ready' event is received from async opening of CMsvSession.
-----------------------------------------------------------------------------
*/
void CRemoteCamAppUi::CompleteConstructL()
{
// We get a MtmClientRegistry from our session
// this registry is used to instantiate new mtms.
iMtmReg = CClientMtmRegistry::NewL(*iSession);
iMtm = iMtmReg->NewMtmL(KUidMsgTypeSMS); // create new SMS MTM
}
/*
-------------------------------------------------------------------------------
HandleKeyEventL
Description: Handles a key event (we are monitoring for the navibutton)
Return value: N/A
-------------------------------------------------------------------------------
*/
TKeyResponse CRemoteCamAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
{
TInt code = aKeyEvent.iCode;
switch(code)
{
case EKeyDevice3:
// take a preview picture
// camera is turned on/off in the TakePreviewL() function
static_cast<CRemoteCamFormView*>(View(KRemoteCamViewId))->TakePreviewL();
return (EKeyWasConsumed);
break;
default:
break;
}
return(EKeyWasNotConsumed); // default return value
}
/*
-------------------------------------------------------------------------------
HandleCommandL
Description: Handles a given command
Return value: N/A
-------------------------------------------------------------------------------
*/
void CRemoteCamAppUi::HandleCommandL(TInt aCommand)
{
switch (aCommand) // A switch statement that will be controlled by the command id get from the OfferKayEvent
{
case EAknSoftkeyExit: // If the exit command is selected
case EEikCmdExit: // If the exit command is selected
case EClose: // If the exit command is selected
CBaActiveScheduler::Exit(); // Call the CBaActiveScheduler's Exit function that stops the application's thread and destroys it.
break;
// "Take picture" was selected from the Options menu
case ERemoteCamTakePicture:
static_cast<CRemoteCamFormView*>(View(KRemoteCamViewId))->TurnCameraOnL();
static_cast<CRemoteCamFormView*>(View(KRemoteCamViewId))->TakePictureL();
static_cast<CRemoteCamFormView*>(View(KRemoteCamViewId))->TurnCameraOffL();
break;
// "Save image" was selected from the Options menu
case ERemoteCamSave:
// Then ask the view to save the current picture (can save the snapshot, if current bmp)
static_cast<CRemoteCamFormView*>(View(KRemoteCamViewId))->SaveImageL();
break;
default: // If the menu command is none of the above do nothing
break;
}
}
/*
-----------------------------------------------------------------------------
HandleSessionEventL()
Handles session event observer and calls event handling functions in
observer.
The type of event is indicated by the value of aEvent. The
interpretation of the TAny arguments depends on this type. For most
event types, the action that is taken, for example, updating the
display, is client-specific. All clients though should respond to
EMsvCloseSession and EMsvServerTerminated events.
-----------------------------------------------------------------------------
*/
void CRemoteCamAppUi::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/)
{
switch (aEvent)
{
case EMsvEntriesCreated: // A new entry has been created in the message server
// We are interested in messages that are created in Inbox
TMsvId* parent;
parent = static_cast<TMsvId*>(aArg2); // entry id from the session event
if ( *parent == KMsvGlobalInBoxIndexEntryId ) // new entry has been created in Inbox folder
{
// We take the created entry ids into a selection
CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>(aArg1);
//Process each created entry, one at a time.
for(TInt i = 0; i < entries->Count(); i++)
{
iMtm->SwitchCurrentEntryL(entries->At(i));
TMsvEntry entry = iMtm->Entry().Entry();
if( entry.iBioType == KUidRemoteCamMsg.iUid ) // message is our BIO message
{
// First turn on the camera
static_cast<CRemoteCamFormView*>(View(KRemoteCamViewId))->TurnCameraOnL();
// if message has commands, for an example save with filename "xxx",
// read message here
// delete message from server
iMtm->SwitchCurrentEntryL(*parent);
iMtm->Entry().DeleteL( entries->At(i) );
// Then ask the Camera to take a picture
static_cast<CRemoteCamFormView*>(View(KRemoteCamViewId))->TakePictureL();
// Then turn off the camera
static_cast<CRemoteCamFormView*>(View(KRemoteCamViewId))->TurnCameraOffL();
}
}
}
break;
// This event tells us that the messaging server session has been opened
case EMsvServerReady:
CompleteConstructL(); // Construct the mtm registry & sms mtm
break;
default:
// All other events are ignored
break;
}
}
//
// CRemoteCamDocument
//
/*
-----------------------------------------------------------------------------
CRemoteCamDocument
Creates new RemoteCam document.
Return Values: N/A
-----------------------------------------------------------------------------
*/
CRemoteCamDocument::CRemoteCamDocument(CEikApplication& aApp)
: CEikDocument(aApp)
{}
/*
-----------------------------------------------------------------------------
CreateAppUiL
Creates new CRemoteCamAppUi and returns a pointer to it.
Return Values: pointer to CRemoteCamAppUi
-----------------------------------------------------------------------------
*/
CEikAppUi* CRemoteCamDocument::CreateAppUiL()
{
CRemoteCamAppUi* appui = new (ELeave) CRemoteCamAppUi;
return appui;
}
//
// CRemoteCamApplication
//
/*
-----------------------------------------------------------------------------
CreateDocumentL()
Description: Creates new RemoteCam document.
Return Values: pointer to new CRemoteCamDocument object
-----------------------------------------------------------------------------
*/
CApaDocument* CRemoteCamApplication::CreateDocumentL()
{
return new (ELeave) CRemoteCamDocument(*this);
}
/*
-----------------------------------------------------------------------------
AppDllUid()
Return the UID of RemoteCam application.
Return Values: UID
-----------------------------------------------------------------------------
*/
TUid CRemoteCamApplication::AppDllUid() const
{
return KUidRemoteCamApp;
}
// OTHER EXPORTED FUNCTIONS
//=============================================================================
/*
-----------------------------------------------------------------------------
NewApplication
Creates new CRemoteCamApplication application and returns a pointer to it.
Return Values: pointer to CApaApplication
-----------------------------------------------------------------------------
*/
EXPORT_C CApaApplication* NewApplication()
{
return new CRemoteCamApplication;
}
/*
-----------------------------------------------------------------------------
E32Dll
Called when the DLL is loaded and unloaded.
Return Values: KErrNone
-----------------------------------------------------------------------------
*/
GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
{
return KErrNone;
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -