Symbian OS Communications (779884), страница 52
Текст из файла (страница 52)
It does not wait for the messageto be sent. SendMessageConfirmedAndCloseL() does the same,but gets user confirmation for sending even if the process has the correctcapabilities.Finally, LaunchEditorAndCloseL() may be used to launch theappropriate message editor. In the above example the user would bepresented with a message containing a recipient and body text which canbe edited. A SendAs client who launches an editor delegates ownershipof the message to the editor. It makes little sense for the client to keeptrack of the message after this point, as the user can edit, save to drafts ordelete the message at any time.9.4.2 Asynchronous SendingA SendAs client which wishes to know if a message send succeeded mustuse the asynchronous methods RSendAsMessage::SendMessage()and RSendAsMessage::SendMessageConfirmed(). Both take aTRequestStatus that will be completed with an error code in theevent of failure, or completed with KErrNone if sending was successful.9.4.3 Creating AttachmentsAttachments and data cagingPre Symbian OS v9.0, the message store allowed each message entryto have a folder in the mail store and write or copy attachment filesat will.
These attachments were visible to all and could be opened bynavigating through the mail folder using a third-party file browser.The introduction of data caging means that the message server nowowns and polices access to a private message store – applications canno longer get direct access and must use message server APIs to beable to access or add attachments.Only the message server may access the private directory structurethat makes up the message store, but it’s useful to know the location(which may change in the future) for debugging purposes when using theemulator.\c\private\1000484b\Mail2\TECHNICAL DESCRIPTION249Several mechanisms are provided to facilitate reading and writing ofattachment data to the message store.
For RSendAs clients, there arethree ways of attaching files to a message. It’s up to the SendAs client todecide which is most appropriate for the data it is presenting.The SendWorkbench example project demonstrates the different methods of creating attachments using the SendAs API. SendWorkbenchexports an image file to a public directory and a private directory._LIT(KPrivateAttachmentFile, "C:\\private\\20009979\\sendasexample.jpg");_LIT(KPublicAttachmentFile, "c:\\data\\images\\sendasexample.jpg");Send attachment by copyThis is appropriate when an application stores reasonably-sized (less thana few 100 kB) data files, possibly in its private directory, and wants tosend the file as is by letting RSendAs create a copy of the file in themessage store.This method requires enough free disk space for an extra copy of thefile.void CSender::SendAttachmentL(){RSendAs sendAs;User::LeaveIfError(sendAs.Connect());CleanupClosePushL(sendAs);RSendAsMessage sendAsMessage;sendAsMessage.CreateL(sendAs, KUidFlickrMtm);CleanupClosePushL(sendAsMessage);TRequestStatus status;sendAsMessage.AddAttachment(KPublicAttachmentFile, status);User::WaitForRequest(status);// send the messagesendAsMessage.SendMessageAndCloseL();sendAs.Close();CleanupStack::PopAndDestroy(2,&sendAs);}An attachment may also be copied by file handle using the overloadof AddAttachment() which takes an RFile parameter – if the file tobe copied resides in an application’s private directory it is necessary touse this version of AddAttachment().Send as linked attachmentThis is ideal for large user data items stored on public areas of the disk.
Agood example is large JPG images, which in this example we’ll say arestored in c:\data\images.250SENDING MESSAGESRather than waste time and disk space by copying the file to themessage, only the full filename of the file is stored with the message.If the source file is deleted, removed or renamed then the link will bebroken. It’s up to the MTM what it does if the attachment is missing at thetime of sending._LIT(KPublicAttachmentFileNameAndPath, "c:\\data\\images\\sendastest.jpg");sendAsMessage.AddLinkedAttachment(KPublicAttachmentFileNameAndPath,iStatus);Building an attachment from another sourceOften an application needs to externalize data to a particular form beforeattaching it; for instance, the contacts engine must externalize contacts toa VCF file in order to send them over infrared or Bluetooth.A file can be built by writing data to a file handle provided by themessage server.
This avoids writing to a temporary file and trying toattach it._LIT(KPublicAttachmentFileName, "sendastest.jpg");_LIT(KPublicAttachmentFileNameAndPath,"c:\\data\\images\\sendastest.jpg");RFile attachmentFile;sendAsMessage.CreateAttachmentL(KPublicAttachmentFileNameAndPath,attachmentFile);RFs fs;User::LeaveIfError(fs.Connect());CleanupClosePushL(fs);RFile input;User::LeaveIfError(input.Open(fs, KSendAsTestAttachmentNameAndPath,EFileRead| EFileShareReadersOnly));CleanupClosePushL(input);TInt fileSize=0;User::LeaveIfError(input.Size(fileSize));HBufC8* fileBuf = HBufC8::NewMaxLC(fileSize);TPtr8 ptr(fileBuf->Des());User::LeaveIfError(input.Read(0,ptr,fileSize));User::LeaveIfError(attachmentFile.Write(ptr));CleanupStack::PopAndDestroy(3, &fs);handle.Close();9.5 Using the UI Platform Send DialogsThis section briefly explains how Send dialog classes are used to sendmessages and attachments by allowing the user to specify the bearer.USING THE UI PLATFORM SEND DIALOGS251A common task for an application developer is to add a Send item tothe application menu.
The SendWorkBench example shows how to useSendUI to present the user with a choice.9.5.1 Send dialog on S60 3rd editionOn S60 3rd edition, the SendUI functionality is available to any application that wishes to export data. For instance, Figure 9.5 shows the resultsof choosing the Send from the standard contacts application.The contact card can be sent as either a vCard attachment or as a‘smart’ text message. The Send menu offers a choice of bearers whichreflect this. In Figure 9.5 email is not listed as a bearer as no accountshave been created on this particular device.Creating a SendUI instanceCreate a CSendUi object as part of the application UI constructor.
Aninstance of CSendUi is kept for the lifetime of the app UI since itsservices are called repeatedly whenever the menu is displayed.iSendUI = CSendUi::NewL();Adding a send menu itemIt is possible to hardcode a Send item in the menu, but using SendUiensures that the menu text is localized correctly.In the fragment of code below, the new Send menu item sits at the topof the menu pane (Item index 0)Figure 9.5Sending a contact using the Send dialog on S60252SENDING MESSAGESvoid CSendWorkbenchAppUi::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane*aMenuPane){const KSendMenuItemIndex = 0;switch (aResourceId){case R_MENU:{iSendUI->AddSendMenuItemL(*aMenuPane, KSendMenuItemIndex,EOwnCommandSend);break;}}}Creating a message and setting the body textThe following fragment shows how to set up some simple rich text forsending._LIT(KTextSmall, "This is a small message which should easily fit into asingle SMS");CRichText* PrepareSmallTextLC(){CEikonEnv& ee = *CEikonEnv::Static();CRichText* rt = CRichText::NewL(ee.SystemParaFormatLayerL(),ee.SystemCharFormatLayerL());CleanupStack::PushL(rt);rt->InsertL(0,KTextSmall);return rt;}CMessageData is a key class in the SendUi API – it is populated withthe data and is passed to CSendUi as the payload.CMessageData* data = CMessageData::NewLC();CRichText* rtSmall = PrepareSmallTextLC();const TInt docLength = rt->DocumentLength();sc = TSendingCapabilities(docLength), docLength,TSendingCapabilities::ESupportsBodyText);data->SetBodyTextL(rtSmall);Attaching a fileconst KMaximumSizeUnknown = 0;sc = TSendingCapabilities(KMaximumSizeUnknown, KMaximumSizeUnknown,TSendingCapabilities::ESupportsAttachments);data->AppendAttachmentL(KPublicAttachmentFile); <KPublicAttachmentfileUSING THE UI PLATFORM SEND DIALOGS253Sending the messageiSendUI->ShowQueryAndSendL(data, sc);ShowQueryAndSendL() does not take ownership of data, but copiesthe data to the message store.
It’s safe to delete data as soon asShowQueryAndSendL() returns.Attaching a file from the private directoryA file in the private directory of the application is not accessible to otherprocesses, including the SendAs and messaging servers, and so it must beadded by handle.const KMaximumSizeUnknown = 0;sc = TSendingCapabilities(KMaximumSizeUnknown, KMaximumSizeUnknown,TSendingCapabilities::ESupportsAttachments);RFs fs;User::LeaveIfError(fs.Connect());CleanupClosePushL(fs);fs.ShareProtected();RFile file;User::LeaveIfError(file.Open(fs, KPrivateAttachmentFile, EFileRead));CleanupClosePushL(file);data->AppendAttachmentHandleL(file);CleanupStack::PopAndDestroy(2,fs);KPrivateAttachmentFile is the fully qualified filename for theattachment to be sent.9.5.2 Send dialog on UIQ3.0Adding a send menu itemUnlike S60, a UIQ application defines its Send menu item as a standardmenu resource.SendWorkBenchUIQ contains the following resource:RESOURCE QIK_COMMAND_LIST r_SendWorkbenchUIQ_commands{items ={QIK_COMMAND254SENDING MESSAGES{id = ECommandSendItem;type = EQikCommandTypeScreen;text = STRING_r_SendWorkbenchUIQ_send_item_cmd;}};/* more items here */}Creating a message and setting the body textCQikSendAsLogic is the simplest way of creating message content foruse with the Send dialog.