BIOexample.cpp
上传用户:sempras
上传日期:2007-03-04
资源大小:821k
文件大小:17k
- /*
- BIOexample.CPP - source file for BIOexample application
- C++ implementation
- */
- // Include Files
- #include <eiklabel.h> // for CEikLabel
- #include <e32std.h> // for TPckgBuf
- #include <smut.h> // for KUidMsgTypeSMS
- #include <txtrich.h> // for CRichText
- #include <eikenv.h> // for CEikonEnv
- #include <editwatc.h> // for TEditorParameters
- #include <txtfmlyr.h> // for CParaFormatLayer, CCharFormatLayer
- #include <sendui.h> // for CSendAppUi
- #include "BIOexample.h" // own header
- #include "BIOexample.hrh" // own enumerations
- // Constants
- const TUid KUidBIOexampleApp = { 0x101F402A }; // BIOexample application UID
- const TUid KUidExampleMessageType = { 0x1000ffff }; // example BIO message type UID
- _LIT(KBIOExampleTag, "//BIOEX #"); // Our BIO message identifier tag + '#' (defined also in bioexamplebif.rss)
- _LIT(KBIOExampleFrom, "From: ");
- _LIT(KBIOExampleMessage, "Message: ");
- const TInt KEditorTextLimit = 160;
- //
- // CBIOexampleContainer
- //
- CBIOexampleContainer::~CBIOexampleContainer()
- {
- delete iComponentControl;
- delete iSender;
- }
- void CBIOexampleContainer::ConstructL(TDes& aText, TDes& aSender)
- {
- ConstructContainerControlL(); // Construct self
- ConstructComponentControlL(aText, aSender); // Construct component control(s)
- }
- TInt CBIOexampleContainer::CountComponentControls() const
- {
- return 2; // iComponentControl is always there
- }
- CCoeControl* CBIOexampleContainer::ComponentControl(TInt aIndex) const
- {
- if(aIndex==0)
- return iComponentControl;
- if(aIndex==1)
- return iSender;
- return NULL;
- }
- void CBIOexampleContainer::ConstructContainerControlL()
- {
- CreateWindowL(); // Makes the control window owning
- }
- void CBIOexampleContainer::ConstructComponentControlL(TDes& aText, TDes& aSender)
- {
- iComponentControl=new(ELeave)CEikLabel; // Create a CEikLabel object
- iComponentControl->SetTextL(aText); // Set label text
-
- iSender = new(ELeave)CEikLabel;
- iSender->SetTextL(aSender);
-
- }
- void CBIOexampleContainer::SizeChanged()
- {
- TSize controlSize=iComponentControl->MinimumSize(); // Ask iComponentControl's size
- TSize containerSize=Rect().Size(); // containerSize is CBIOexampleContainer's own size and can be found in the size of its rectangle.
- TPoint controlPosition((containerSize.iWidth-controlSize.iWidth)/2,
- (containerSize.iHeight-controlSize.iHeight)/2); // Calculate a position for control that places it to the center of CBIOexampleContainer
- TRect controlRect(controlPosition,controlSize);
-
- iComponentControl->SetRect(controlRect); // Set iComponentControl a rect in which it is supposed to appear.
-
- controlSize=iSender->MinimumSize();
- controlPosition.SetXY((containerSize.iWidth-controlSize.iWidth)/2,
- ((containerSize.iHeight-controlSize.iHeight)/2) + controlSize.iHeight );
- TRect senderRect(controlPosition,controlSize);
- iSender->SetRect(senderRect);
- }
- void CBIOexampleContainer::Draw(const TRect& /*aRect*/) const
- {
- CGraphicsContext& gc=SystemGc(); // Get the graphics context in which to draw.
- gc.SetBrushStyle(CGraphicsContext::ESolidBrush); // Set brush style to solid. Initial value in a graphics context is ENullBrush.
- gc.DrawRect(Rect()); // Draw a rectangle.
- }
- TKeyResponse CBIOexampleContainer::OfferKeyEventL(const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/)
- {
- TKeyResponse response=EKeyWasNotConsumed; // not consuming any keys
- return response;
- }
- //
- // CBIOexampleAppUi
- //
- /*
- -------------------------------------------------------------------------------
- ~CBIOexampleAppUi
- Description: Destructor
- Return value: N/A
- -------------------------------------------------------------------------------
- */
- CBIOexampleAppUi::~CBIOexampleAppUi()
- {
- delete iContainerControl;
- iId = NULL;
- delete paraFormatLayer;
- delete charFormatLayer;
- delete messageBodyContent;
- delete sendAppUi;
- }
- /*
- -------------------------------------------------------------------------------
- ProcessCommandParametersL();
- Description: Processing the command line parameters (when message is opened
- from the messaging application, TMsvId of the message is passed
- in command line parameters)
- Return value: TBool
- -------------------------------------------------------------------------------
- */
- TBool CBIOexampleAppUi::ProcessCommandParametersL(TApaCommand /*aCommand*/,TFileName& /*aDocumentName*/,const TDesC8& aTail)
- {
- // Only aTail parameter is of interest to us, it contains TEditorParameters object that contains
- // the TMsvId as one attribute.
- // Checking the length of comm line params
- if (aTail.Length() > 0) // we have comm line params => program was started from Messaging application
- {
- iNormalStart = EFalse;
-
- // --- reading command line parameters ---
- // Get the parameters passed by the launching MTMUI
- TPckgBuf<TEditorParameters> paramPack; // the params are read into a TPckgBuf template (see SDK documentation for more info)
- paramPack.Copy(aTail);
- TEditorParameters params(paramPack());
- // saving the message id
- iId = ¶ms.iId;
- }
- else
- {
- // no command line params => program started manually
- iNormalStart = ETrue;
- }
- CompleteConstructL(); // complete construction with the command line parameters.
- return EFalse;
- }
- /*
- -------------------------------------------------------------------------------
- ConstructL();
- Description: 2nd phase Constructor. Setting up attributes, construction
- continues in CompleteConstructL() below.
- Return value: N/A
- -------------------------------------------------------------------------------
- */
- void CBIOexampleAppUi::ConstructL()
- {
- BaseConstructL();
- iNormalStart = ETrue; // at this point we suppose that no comm line params have been given
- iId = NULL; // set message id to NULL as default
- // for message sending
- paraFormatLayer=CParaFormatLayer::NewL();
- charFormatLayer=CCharFormatLayer::NewL();
- messageBodyContent=CRichText::NewL(paraFormatLayer, charFormatLayer);
-
- // create sendAppUi
- sendAppUi=CSendAppUi::NewL(EBIOexampleCmdSend); // New Send ui object (number 'EBIOexampleCmdSend' is tied
- // to our menu item "Send message" in "Messaging"
- }
- /*
- -------------------------------------------------------------------------------
- CompleteContructL();
- Description: Continuing construction... (after processing command line params)
- Return value: N/A
- -------------------------------------------------------------------------------
- */
- void CBIOexampleAppUi::CompleteConstructL()
- {
- TBuf<KEditorTextLimit> text, sender; // for reading & presenting the message sender & body
- sender.Append(KBIOExampleFrom); // insert field description ("From: ")
- // First check if app has been started from the messaging app or "the normal way", manually...
- if(iNormalStart == EFalse) // we have comm line params and will open up message with the given TMsvId
- {
-
- // read the message into descriptors
- ReadMessageL(text, sender);
- // read message text and locate "//BIOEX #" header part
- TInt pos;
- User::LeaveIfError(pos = text.Locate('#')); // # is in the message only to test string handling here (it could be omitted)
- pos++;
- text.Delete(0, pos); // delete message header tag
- // insert field description in front
- text.Insert(0, KBIOExampleMessage); // "Message: "
-
- // Delete message from messaging server
- DeleteMessageL(*iId);
- iId = NULL;
- }
- else // no comm line params, opening "empty" application
- {
- text.Append(KBIOExampleMessage); // "Message: "
- text.Append(_L("No message loaded")); // "Message: No message loaded"
- sender.Append(_L("N/A")); // "From: N/A"
- }
- // Then construct the UI components
- iContainerControl = new(ELeave) CBIOexampleContainer;
- iContainerControl->ConstructL(text, sender); // Construct a view control with message text and sender number (in normal start these are empty)
- iContainerControl->SetRect(ClientRect()); // Sets view control's extent to the space available
- iContainerControl->ActivateL(); // Activate the view control
- CCoeAppUi::AddToStackL(iContainerControl); // Add container to Control Stack to make it automatically receive key events.
- }
- /*
- -------------------------------------------------------------------------------
- ReadMessageL();
- Description: Read the message data. This could be done also in BIOexampleParser.
- Return value: N/A
- -------------------------------------------------------------------------------
- */
- void CBIOexampleAppUi::ReadMessageL(TDes& aText, TDes& aSender)
- {
- // Using the Send As API to read message
- CSendAs* sendAs=CSendAs::NewL(*this);
- sendAs->SetMtmL(KUidMsgTypeSMS); // this implementation assumes that message arrived over SMS
- CleanupStack::PushL(sendAs);
- if (sendAs->AvailableServices().Count() < 1)
- {
- User::Leave(KErrNotFound);
- }
- sendAs->SetService(0);
- CBaseMtm* smsMtm = sendAs->ClientRegistry().NewMtmL(KUidMsgTypeSMS);
- CleanupStack::PushL(smsMtm);
- smsMtm->SwitchCurrentEntryL(*iId);
- smsMtm->LoadMessageL();
- aText.Append( smsMtm->Body().Read(0) );
- aSender.Append( smsMtm->Entry().Entry().iDetails );
- CleanupStack::PopAndDestroy(2); // sendAs, smsMtm
- }
- /*
- -------------------------------------------------------------------------------
- HandleCommandL
- Description: Handles a given command
- Return value: N/A
- -------------------------------------------------------------------------------
- */
- void CBIOexampleAppUi::HandleCommandL(TInt aCommand)
- {
- switch(aCommand)
- {
- case EBIOexampleCmdSend:
- SendMessageL();
- break;
- case EClose:
- CBaActiveScheduler::Exit();
- break;
- default:
- break;
- }
- }
- /*
- -------------------------------------------------------------------------------
- SendMessageL();
- Description: Sending a new BIO message. This is done using the SendAppUi API.
- Return value: N/A
- -------------------------------------------------------------------------------
- */
- void CBIOexampleAppUi::SendMessageL()
- {
- //-- Sending a BIO message through the SendUi API: --
- // create parameters for sendUi object
- MDesC16Array* attachments = NULL; // no attachments
- const TUid bioTypeUid = KNullUid; // Our message UID (defined in bioexamplebif.rss file) would go
- // here but this type was not supported by SendUi so using KNullUid
- CPtrC16Array* recipients = NULL; // define recipients later (through msg editor UI)
- MDesC16Array* aliases = NULL; // no aliases
- // create message body (insert our BIO message identifier in the beginning)
- messageBodyContent->DeleteL( 0, messageBodyContent->DocumentLength() ); // first clear the document (the //BIOEX header of previous sending)
- messageBodyContent->InsertL( 0, KBIOExampleTag ); // our tag ( "//BIOEX #" ) the # is not needed by the BIO header, it is only our own message separator
- // Only "//BIOEX" is needed in the beginning for the system to recognize the message as 'BIOexample' message.
- // Sending message over SMS bearer
- sendAppUi->CreateAndSendMessageL(KUidMsgTypeSMS, messageBodyContent, attachments, bioTypeUid, recipients, aliases);
-
- // The message could be deleted after the sending with the delete function...
- // just get the newly created message id from somewhere (not implemented in this example)
- //DeleteMessage(messageId);
- }
- /*
- -------------------------------------------------------------------------------
- DeleteMessageL();
- Description: Delete message (with given id) from messaging server.
- Return value: N/A
- -------------------------------------------------------------------------------
- */
- void CBIOexampleAppUi::DeleteMessageL(TMsvId aEntryId)
- {
- CSendAs* sendAs=CSendAs::NewL(*this);
- sendAs->SetMtmL(KUidMsgTypeSMS);
- CleanupStack::PushL(sendAs);
- if (sendAs->AvailableServices().Count() < 1)
- {
- User::Leave(KErrNotFound);
- }
- sendAs->SetService(0);
- CBaseMtm* smsMtm = sendAs->ClientRegistry().NewMtmL(KUidMsgTypeSMS);
- CleanupStack::PushL(smsMtm);
- smsMtm->Session().RemoveEntry(aEntryId); // remove message entry from the server
- CleanupStack::PopAndDestroy(2); // sendAs, smsMtm
- }
- /*
- -------------------------------------------------------------------------------
- CapabilityOK
- Description: Returns component control with a given index.
- Return value: TBool
- -------------------------------------------------------------------------------
- */
- TBool CBIOexampleAppUi::CapabilityOK(TUid /*aCapabilty*/, TInt /*aResponse*/)
- {
- return ETrue;
- }
- //
- // CBIOexampleDocument
- //
- /*
- -----------------------------------------------------------------------------
- CBIOexampleDocument
- Creates new BIOexample document.
- Return Values: N/A
- -----------------------------------------------------------------------------
- */
- CBIOexampleDocument::CBIOexampleDocument(CEikApplication& aApp)
- : CEikDocument(aApp)
- {}
- /*
- -----------------------------------------------------------------------------
- CreateAppUiL
- Creates new CBIOexampleAppUi and returns a pointer to it.
- Return Values: pointer to CBIOexampleAppUi
- -----------------------------------------------------------------------------
- */
- CEikAppUi* CBIOexampleDocument::CreateAppUiL()
- {
- CBIOexampleAppUi* appui = new (ELeave) CBIOexampleAppUi;
- return appui;
- }
- //
- // CBIOexampleApplication
- //
- /*
- -----------------------------------------------------------------------------
- CreateDocumentL()
- Description: Creates new BIOexample document.
- Return Values: pointer to new CBIOexampleDocument object
- -----------------------------------------------------------------------------
- */
- CApaDocument* CBIOexampleApplication::CreateDocumentL()
- {
- return new (ELeave) CBIOexampleDocument(*this);
- }
- /*
- -----------------------------------------------------------------------------
- AppDllUid()
- Return the UID of BIOexample application.
- Return Values: UID
- -----------------------------------------------------------------------------
- */
- TUid CBIOexampleApplication::AppDllUid() const
- {
- return KUidBIOexampleApp;
- }
- // OTHER EXPORTED FUNCTIONS
- //=============================================================================
- /*
- -----------------------------------------------------------------------------
- NewApplication
- Creates new CBIOexampleApplication application and returns a pointer to it.
- Return Values: pointer to CApaApplication
- -----------------------------------------------------------------------------
- */
- EXPORT_C CApaApplication* NewApplication()
- {
- return new CBIOexampleApplication;
- }
- /*
- -----------------------------------------------------------------------------
- E32Dll
- Called when the DLL is loaded and unloaded.
- Return Values: KErrNone
- -----------------------------------------------------------------------------
- */
- GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
- {
- return KErrNone;
- }
- // End of File