Symbian OS Communications (779884), страница 53
Текст из файла (страница 53)
It contains methods for associating rich text andattachments with a message.iSendAsLogic = CQikSendAsLogic::NewL(iSmallText, KNullDesC, KSmallText);iSmallText is a CRichText instance whose ownership is transferred to iSendAsLogic. iSmallText will be deleted when themessage has been committed to the message store.
The second parameterKNullDesC indicates that there are no attachments, and KSmallTextis simply the subject of the message.Attaching a fileTUid capability;iSendAsLogic = CQikSendAsLogic::NewL(NULL, KAttachmentSource,KAttachmentText);capability = KUidMtmQuerySupportAttachments;The (messaging, not platsec) capability requests that only MTMs thatsupport attachments should be presented when the Send dialog is shown(capability is used below).Attaching a file from the private directoryAdding a file from a private application directory involves creating a fileserver session, an open file handle and transferring the ownership of thehandle to the send as logic.A BRIEF BACKGROUND TO MTMS255iSendAsLogic = CQikSendAsLogic::NewL();capability = KUidMtmQuerySupportAttachments;RFs fs;User::LeaveIfError(fs.Connect());CleanupClosePushL(fs);fs.ShareProtected();RFile file;User::LeaveIfError(file.Open(fs, KPrivateAttachmentFile, EFileRead));CleanupStack::Pop(&fs);iSendAsLogic->AddAttachmentL(file);KPrivateAttachmentFile is the fully qualified file name of theattachment to be sent.Invoking the SendAs dialog to send the messageWith the iSendAsLogic set up by the application in one of the waysdetailed above, the UIQ SendAs dialog has all the information it needs tosend the message, aside from which bearer should be used.The following call takes care of sending the message once it hasprompted the user.CQikSendAsDialog::RunDlgLD(iSendAsLogic, capability);The dialog takes ownership of CQikSendAsLogic and so deletes itbefore returning.9.6 A Brief Background to MTMsThe messaging architecture was designed as an extensible system withplugin modules known as MTMs.
An MTM is a group of DLLs whichprovide support for a particular message type. The messaging architectureallows client applications to determine at runtime which MTMs areinstalled on the device and when new MTMs are installed.9.6.1 HistoryOne of the goals of the original messaging architecture (which dates backto the Psion Series 5) was to allow smooth integration of an after-marketIMAP4 solution for the Psion Series 5mx.A mantra used in the creation of the architecture was that the mainmessaging application (or message centre) should contain no bearerspecific code, dealing only with abstract concepts of messages.256SENDING MESSAGESThe result is that the MTM framework is a delegation framework whichyields ‘chatty’ interactions between a messaging clients and the set ofinstalled MTMs.
The client can ask if an MTM supports a particularcapability and then take action.Since the IMAP4 MTM was developed, other technologies have beenintegrated into the messaging framework: OBEX over IR and OBEX overBluetooth MTMs, MMS, and email sync MTMs have been successfullyintegrated into OEM devices.The MTM architecture is heavily segmented by transport type ratherthan message type which can cause some misunderstanding for developers attempting to introduce a new message type.A full set of MTM plugins consists of an end-to-end solution for amessage type and transport. This includes an editor to create messages,a class to supply icons and a description for items in the list view of themessaging application, a class to store and manipulate messages, and aclass for sending and receiving a message. Most of these elements appearin figure 9.6, along with details of how they interact.UI DATA MTMMessaging ApplicationUI MTMClient MTMCMsvSessionClient server boundaryMessage serverServer MTMMessage storeFigure 9.6 High-level overview of the messaging architectureTHE FLICKR MTM2579.6.2 MTM diagramWhy four DLLs?In theory, it is not necessary to put each component in a separate DLL.The MTM registration resource file allows the entry point for each MTMto be defined, enabling packaging of one or more MTM components intoa single DLL.
However, the MTMs are often split into their own DLLs fora variety of reasons:• The MTM client-side DLL should remain separate from the serverside for platsec reasons: a server-side DLL will require one set ofcapabilities – those of the message server process – whereas a clientside DLL is likely to require a different set of capabilities – in theorythose of any application process into which it might be loaded. Seethe earlier discussion about the SendAs architecture for informationabout which DLLs are loaded into which processes.• The client and server MTMs are usually UI-agnostic and so can bebuilt for UIQ and S60, whereas UI and UI Data MTMs are closely tiedto the UI. Therefore it’s common to separate the client MTM into aseparate DLL from the UI and UI Data MTMs.• The reason for separate UI and UI Data MTM DLLs is that the UI DataMTM is designed to be lightweight and should not link to any morebinaries than necessary.Drawbacks of the current messaging architectureThe current messaging architecture does not cater well for developerscreating message types similar to an existing set of MTMs.
For example,when creating a set of MTMs to implement push email, it would be goodto plugin a push email transport and reuse the existing email editor andviewer. However, typically editors and viewers are hard-coded to handlecertain message types and, short of modifying the type of messages onthe fly, it’s not possible to achieve a high degree of reuse.
In practicethis means a developer will have to write four MTM DLLs as well as aneditor/viewer for the new message type.Creating a well-integrated MTM is larger than the scope of this chapter,but the example MTM provides a good starting point.9.7 The Flickr MTMThis section deals with the task of creating a new MTM.
It provides a veryspecific example of extending the messaging functionality to add an itemto the SendAs service, and hence to the UI Send dialogs.258SENDING MESSAGESBackground on the Flickr service and implementation of the flickupload DLL can be found in Chapter 11.9.7.1 GoalThe high-level goal of this example is to add a ‘to Flickr’ item to thestandard Send options in the S60 and UIQ Send dialogs. This allows usersto upload images to their Flickr account directly from a file manager,image gallery or any other application which uses SendUI.9.7.2 TestingThe MTM can be tested by using the SendWorkbench application toverify that ‘to Flickr’ appears in the Send menu when the data being sentcan be represented as an attachment. Files that do not contain imagesthat are passed to the Flickr MTM will fail with KErrNotSupported.ImplementationThe example introduces a new MTM which supports uploading imagesto Flickr.
The MTM is restricted to send only, and has just enoughfunctionality implemented to meet the goal. The UI for the MTM islimited to an ‘uploading to Flickr’ progress report.9.7.3 OverviewEvery MTM should derive at least four classes from the relevant SymbianMTM base classes. Since there is a lot of repetitive framework code,it’s easier to start with an existing example MTM, such as the TextMTMexample provided by Symbian, and modify it. Currently the TextMTM isnot shipped as part of S60 3rd edition SDK, but is distributed in the UIQ3.0SDK, in the folder \Symbian\UIQ3SDK\Examples\SymbianNotCompatible\Messaging\TextMTM. The reason this is in the ‘not compatible’ directory of the SDK is because the UI elements of the TextMTMexample are coded for Symbian’s reference UI – Techview – rather thanUIQ.Figure 9.7 shows how the classes in the Flickr MTM are built up.The role of each of these classes is to interpret and delegate requeststo something which makes sense for the message type.The UI Data MTM ensures that the MTM is reporting the correctcapabilities, the UI MTM ensures that edit and send operations do theright thing, the client MTM takes care of storing the message and theserver MTM acts as a message transport.THE FLICKR MTM259Symbian MessagingCBaseMtmUiDataCFlickrDataMtmCBaseMtmUiCBaseMtmCBaseServerMtmCFlickrUIMtmCFlickrClientMtmCFlickrServerMTM+QueryCapability()+CanCreateEntry()11CMTMFlickrSettingsUI Specific DialogFlickrUpload.dllFigure 9.7 Derivation of the Flickr MTM classes from the messaging frameworkMTM componentRoleCFlickrMtmUiDataReport capabilities, set thelocalizable ‘To Flickr’ text in thesend menuCFlickrMtmUiHandle message editing and progressusing UI-specific dialogsIn this example, message editing ismutated into a Send operation with aprogress dialogCFlickrMtmClientHandle message creation andvalidation, delegate sending tasks tothe server MTMCFlickrMtmServerSupports one operation, the sendingto Flickr using the FlickrUpload.dll.260SENDING MESSAGES9.8 The Flickr Data MTM9.8.1 CapabilitiesNot to be confused with platsec capabilities, the MTM architectureprovides a system for enquiring about MTM capabilities at runtime.The services provided by an MTM are not fixed.
There are somestandard services such as message creation, deletion and subscription,but also a large number of other services, the availability of which areindicated through the capability mechanism.The UI Data MTM provides lightweight capability checking.–thisallows services such as SendAs to quickly eliminate MTMs that cannotsend, for example.Each MTM component has a method called QueryCapability()which can be called to check if an MTM supports a service, or to querysimple parameters such as the maximum size of a message supported bythe MTM.The FlickrMTM supports creating new messages (this is obviouslyessential to support the SendAs service!), supports sending the messageand supports attachments. This is represented as follows;TInt CFlickrMtmUiData::QueryCapability(TUid aCapability, TInt& aResponse)const// Query for capability{switch (aCapability.iUid){case KUidMtmQueryCanCreateNewMsgValue:case KUidMtmQueryCanSendMsgValue:case KUidMtmQuerySupportAttachmentsValue:aResponse=ETrue;break;default:return KErrNotSupported;}return KErrNone;}SendUI also queries CanCreateEntryL() to check if the entrycan be created in a specific context.
For example that given a specificmessaging folder, CanCreateEntryL() will be called to test if a childentry be created using this MTM. Please note that although the returntype is TBool, there is a bug in some UI implementations which expectthis to return KErrNone to indicate success; returning ETrue on S60means that this MTM will never show up on the Send menu.TBool CFlickrMtmUiData::CanCreateEntryL(const TMsvEntry& aParent,TMsvEntry& aNewEntry, TInt& aReasonResourceId) const{THE FLICKR DATA MTM261__ASSERT_ALWAYS(aNewEntry.iMtm== KUidMsgTypeFlickr,Panic(EFlickrMtmDataWrongMtm));__ASSERT_ALWAYS(aNewEntry.iType!=KUidMsvAttachmentEntry,Panic(EFlickrMtmDataAttachmentsNotSupported));aReasonResourceId=0;// --- Can create services if they are off root --if (aNewEntry.iType == KUidMsvServiceEntry){return (aParent.Id() == KMsvRootIndexEntryIdValue) ? KErrNone :KErrNotSupported;}// --- Can create messages in local folders --if (aNewEntry.iType == KUidMsvMessageEntry){return (aParent.iMtm.iUid == KMsvLocalServiceIndexEntryIdValue) ?KErrNone : KErrNotSupported;}return KErrNotSupported;}An MTM UID is stamped on each message entry in the messagestore (including service settings), and the corresponding MTM is alwaysconsulted before an action is performed.