1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 #ifndef __MTCLBASE_H__
23 #define __MTCLBASE_H__
29 #include <cmsvattachment.h>
31 #include <cmsvrecipientlist.h>
33 class CMsvAttachmentWaiter;
35 /** Specifies one or more parts of a message in message-forwarding, message-reply,
36 and message-validation functions.
38 Standard message parts are defined by the constants that can be added (or
39 bitwise-or'ed) together to specify multiple parts. Some message parts may
40 not be meaningful for some MTMs.
42 Specifies find attributes which modify the behaviour of the search text utility
43 provided by the Global Find API. This does not apply to v5.1 nor to v5. */
44 typedef TUint TMsvPartList;
46 class CParaFormatLayer;
47 class CCharFormatLayer;
51 // Prototype of expected factory function
53 typedef CBaseMtm* MtmFactoryFunctionL(CRegisteredMtmDll&, CMsvSession&);
56 /** Specifies function IDs for standard MTM functions.
58 The function IDs are specified such that they do not coincide
59 with the free area defined for MTM commands.
61 If MTMs also offer their own equivalents of these functions,
62 they may implement these function IDs by considering the
63 two IDs to be the same in their client MTM.
65 MTMs that support SendAs must support SendMessage.
67 enum TMtmStandardAsyncCommands
69 KMTMStandardFunctionsSendMessage = KMtmFirstFreeStandardMtmFunctionId
73 /***********************************************
74 ***********************************************/
75 class CBaseMtm : public CBase, public MMsvEntryObserver
76 /** Provides a high-level interface for accessing and manipulating a Message Server
79 Message client applications use the class to access such functionality polymorphically.
80 MTM implementers implement a derived class to provide such functionality for
81 their message protocol.
83 The following are some significant groups of functions:
85 Context functions: the SetCurrentEntryL() and SwitchCurrentEntryL() functions
86 change the context - the entry on which later actions are performed. After
87 creating a new Client-side MTM object, a message client application should
88 set an initial context before using other functions. Note that: any changes
89 made to an existing context are not automatically saved: the message client
90 application should ensure this itself by calling SaveMessageL(); no message
91 data for the new context is retrieved from the Message Server, to retrieve
92 entry data, call LoadMessageL() after setting the context; calling Body()
93 immediately after setting the context returns an empty CRichText object: this
94 is because the private cache of context body text that the base class maintains
95 is re-initialised to an empty value. MTM implementers should note that the
96 virtual ContextEntrySwitched() is called from these functions to allow derived
97 classes to also clear any caches of MTM-specific entry data.
99 Store and restore entry data functions: the changes that a message client
100 application makes to a message context through Client-side MTM functions,
101 such as altering the body text obtained through Body(), are, for efficiency,
102 cached in memory by a Client-side MTM. The message store and restore functions
103 are concerned with transferring data between that cache and committed storage.
104 Note that, unlike message contexts, message client applications are not expected
105 to manipulate directly service contexts. Instead, the corresponding User Interface
106 MTM will provide dialogs to allow the user to alter service settings, and
107 call Client-side MTM functions to handle their retrieval and storage. Symbian
108 OS v5 expects the base class functions to handle storage and retrieval for
109 both message and service contexts, and their implementations must detect what
110 the context is, and act accordingly. Post-v5, the API is clarified by restricting
111 the base class functions to handle message contexts only. To handle service
112 contexts, a Client-side MTM must define its own functions for the User Interface
115 Store and restore body text functions: the base class maintains a private
116 CRichText object cache to store the body text for the current context. This
117 can be accessed for reading and writing by message client applications through
118 Body(). StoreBodyL() and RestoreBodyL() encapsulate for implementers of derived
119 classes the retrieval and storage of this CRichText object to a CMsvStore.
121 Address list functions: the format and storage of message addresses is MTM-specific.
122 AddresseeList(), AddAddresseeL(), and RemoveAddressee() are designed to allow
123 clients with no MTM-specific knowledge to access address information in a
124 generic way. The base class has a protected data member iAddresseeList, an
125 array of descriptors, which these functions manipulate. Implementations should
126 save the address information to the appropriate place in the message store
127 when the message is stored.
129 MTM-specific functionality: MTM components can offer protocol-specific functionality
130 not provided by base class interface functions. MTM components define IDs
131 that correspond to each protocol-specific operation offered, and implement
132 the InvokeSyncFunctionL() and InvokeAsyncFunctionL() functions to allow clients
133 to access these operations by passing in the appropriate ID. Two functions
134 are provided to allow the MTM component to offer both synchronous and asynchronous
135 functionality. Message client applications can dynamically add user-interface
136 features for these operations using CBaseMtmUiData::MtmSpecificFunctions().
137 MTM developers should document the IDs if they wish to make the operations
138 available to clients.
144 IMPORT_C ~CBaseMtm();
145 IMPORT_C TUid Type() const;
148 IMPORT_C void SetCurrentEntryL(CMsvEntry* aEntry);
149 IMPORT_C void SwitchCurrentEntryL(TMsvId aId);
150 IMPORT_C CMsvEntry& Entry() const;
151 IMPORT_C TBool HasContext() const;
154 /** Commits cached changes to the storage controlled by the Message Server.
156 It can only be called on message contexts. It should be called in the following circumstances:
158 1. to preserve changes when the context is changed, or when the Client-side MTM
161 2. to enable other parts of the Messaging to access the updated entry, as required,
162 for example, before sending a message
166 An implementation must update the store and index entry relating to the message
167 context. Typically, the message store should be opened for editing with CMsvEntry::EditStoreL().
168 It should be updated as follows:
170 1. body text: call StoreBodyL() to update the store's body text stream
172 2. address list: update the appropriate MTM-specific area of the store from the
173 data in iAddresseeList
175 3. subject: if supported, update the appropriate MTM-specific area of the store
176 from the private cache set by SetSubjectL()
178 Changes can then be committed to the store with CMsvStore::CommitL().
180 The index entry should also be updated to reflect changes. Possible fields
181 that may need updating include: Description (for subject changes); Details
182 and Multiple Recipients (for recipient changes); and Size. Index entry changes
183 are committed using CMsvEntry::ChangeL().
185 The function should panic for non-message contexts. */
186 virtual void SaveMessageL()=0;
187 /** Loads the cache with the message data for the current context.
189 It can only be called on message contexts.
191 It is typically used after the context has been set with SetCurrentEntryL()
192 or SwitchCurrentEntryL(). CBaseMtm functions to manipulate the entry can only
193 be called after this function has been called.
197 An implementation must restore the store and index entry relating to the message
198 context. Typically, the message store should be opened for reading with CMsvEntry::ReadStoreL().
199 It should be then be read to set the following:
201 1. body text: call RestoreBodyL() to update the cached body text
203 2. address list: read the appropriate MTM-specific area of the store to update
206 3. subject: if supported, read the appropriate MTM-specific area of the store
207 and update the cache with SetSubjectL()
209 The function should panic for non-message contexts. */
210 virtual void LoadMessageL()=0;
211 /** Validates the current message context.
213 The precise validation performed is specific to the MTM, but, typically, checks
214 that the specified message parts are well-formed.
218 Implementation of this function is highly protocol-specific. A minimum step
219 is to check that the current context is a message.
221 @param aPartList Indicates the message parts for which validation is requested
223 @return If valid, KErrNone If invalid, identifies the invalid part(s). The
224 error value is the bitmask of the TMsvPartList IDs for each invalid part */
225 virtual TMsvPartList ValidateMessage(TMsvPartList aPartList)=0;
226 /** Searches the specified message part(s) for the plain-text version of the text
229 If the specified part list indicates a part that is not supported, or is not
230 present in the current message, the function behaves as if the specified part
231 exists but does not contain the required text.
235 The parts of the entry for which searching is allowed is implementation specific.
236 If no searching is supported, always return 0.
238 @param aTextToFind The plain-text version of the text to be found.
239 @param aPartList Indicates the message parts which should be searched.
240 @return If the text was not found, or searching is unsupported, 0. If the text
241 was found, a bitmask of the TMsvPartList IDs for each part in which the text
243 virtual TMsvPartList Find(const TDesC& aTextToFind, TMsvPartList aPartList)=0;
246 /** Creates a reply message to the current message context.
248 Some MTMs may support inclusion of elements, specified by aPartlist, from
249 the original message in the reply. The parent for the new entry is specified
252 The returned CMsvOperation object completes when creating the reply is complete.
253 On completion, the context is set to the reply message.
257 A typical implementation for this function would include the following steps:
259 1. create a new message in the specified destination by calling CMsvEntry::CreateL()
261 2. set the entry index values as appropriate
263 3. set the properties of the message as required. The normal minimum is to set
264 the address to the sender of the original message. An implementation may also
265 follow the options specified in aPartlist to set other properties, for example,
266 to include the original message text.
268 4. set the context to the reply
270 5. return a CMsvOperation-derived object to provide asynchronous control and
271 monitoring of the operation
273 If message replies are not supported, implementations should leave with KErrNotSupported.
275 The implementation of this function may be similar to that of ForwardL(),
276 allowing opportunities for code sharing.
278 @param aDestination The entry to which to assign the reply
279 @param aPartlist Defines the parts that are to be copied from the original
280 message into the reply
281 @param aCompletionStatus The request status to be completed when the operation
283 @leave KErrNotSupported The Client-side MTM does not support reply operations
284 @leave Other leave codes Dependent on implementation
285 @return If successful, this is an asynchronously completing reply operation.
286 If failed, this is a completed operation, with status set to the relevant
288 virtual CMsvOperation* ReplyL(TMsvId aDestination, TMsvPartList aPartlist, TRequestStatus& aCompletionStatus)=0;
289 /** Creates a forwarded message from the current message context.
292 support inclusion of elements, specified by aPartlist, from the original message
293 in the forwarded message. The parent for the new entry is specified in aDestination.
294 The returned CMsvOperation object completes when editing the forwarded message
295 is complete. On completion, the context is set to the forwarded message.
299 A typical implementation for this function would include the following steps:
301 1. create a new message in the specified destination by calling CMsvEntry::CreateL()
303 2. set the entry index values as appropriate
305 3. set message content as required. The normal minimum is to include the text
306 of the original message. An implementation may also follow the options specified
307 in aPartlist to include other properties of the original message.
309 4. set the context to the reply
311 5. return a CMsvOperation-derived object to provide asynchronous control and
312 monitoring of the operation
314 If forwarded messages are not supported, implementations should leave with
317 The implementation of this function may be similar to that of ReplyL(), allowing
318 opportunities for code sharing.
320 @param aDestination The entry to which to assign the forwarded message
321 @param aPartList Defines the parts that are to be copied from the original
322 message into the forwarded message
323 @param aCompletionStatus The request status to be completed when the operation
325 @leave KErrNotSupported The Client-side MTM does not support creation of forwarded
327 @leave Other leave codes Dependent on implementation
328 @return If successful, this is an asynchronously completing forward message
329 operation. If failed, this is a completed operation, with status set to the
330 relevant error code. */
331 virtual CMsvOperation* ForwardL(TMsvId aDestination, TMsvPartList aPartList, TRequestStatus& aCompletionStatus)=0;
333 // addresssee list (used by objects with no MTM knowledge)
334 IMPORT_C const CMsvRecipientList& AddresseeList() const;
336 /** Adds an addressee for the current context.
338 Addresses are not validated by checking their format by this function. Usually
339 that is performed by calling ValidateMessage().
343 Implementations should append the address to the object's address cache
344 in the protected iAddresseeList data member. Some implementations may also
345 wish to store addresses in an internal data structure appropriate for the
346 protocol, for example, a class holding message header information.
348 @param aRealAddress String representing an address to be added to the list
349 for the current message
350 @leave KErrNotSupported The message already has the maximum number of addressees
352 @leave Other leave codes Dependent on implementation */
353 virtual void AddAddresseeL(const TDesC& aRealAddress)=0;
354 /** Adds an addressee for the current context, and enables the client to specify
355 an alias, which may be useful for some protocols. For example, for fax, if
356 the address is the fax number, the alias could supply the recipient's name.
358 Addresses are not validated by checking their format by this function. Usually
359 that is performed by calling ValidateMessage().
363 Implementations should append the address to the object's address cache
364 in the protected iAddresseeList data member. Some implementations may also
365 wish to store addresses in an internal data structure appropriate for the
366 protocol, for example, a class holding message header information.
368 @param aRealAddress String representing an address to be added to the list
369 for the current message
370 @param aAlias Alias information
371 @leave KErrNotSupported The message already has the maximum number of addressees
373 @leave Other leave codes Dependent on implementation */
374 virtual void AddAddresseeL(const TDesC& aRealAddress, const TDesC& aAlias)=0;
376 IMPORT_C virtual void AddAddresseeL(TMsvRecipientType aType, const TDesC& aRealAddress);
377 IMPORT_C virtual void AddAddresseeL(TMsvRecipientType aType, const TDesC& aRealAddress, const TDesC& aAlias);
379 /** Removes an address from the current address list. The address is specified
380 by a zero-based index into the address list. If the index is not known, applications
381 can use AddresseeList() to retrieve the entire list to find the item.
385 Implementations should call iAddresseeList->Delete(aIndex) to remove the address
386 from in the address list protected data member.
388 @param aIndex Index of address to be removed */
389 virtual void RemoveAddressee(TInt aIndex)=0;
391 // standard data accessor/mutators
392 IMPORT_C CRichText& Body();
393 IMPORT_C const CRichText& Body() const;
394 IMPORT_C virtual void SetSubjectL(const TDesC& aSubject); // default leaves with KErrNotSupported
395 IMPORT_C virtual const TPtrC SubjectL() const; // default leaves with KErrNotSupported
398 IMPORT_C virtual TInt QueryCapability(TUid aCapability, TInt& aResponse); // default returns KErrNotSupported
399 /** Invokes synchronous protocol-specific operations. For asynchronous operations,
400 a similar function, InvokeAsyncFunctionL(), is available.
402 aSelection and aParameter allow data to be passed to the operation.
406 For functionality that requires message transport access, such as making a
407 connection, the implementation should pass the request onto the corresponding
408 Server-side MTM. This is done through calling CMsvSession::TransferCommandL().
409 Implementations may also provide protocol-specific functions themselves if
412 @param aFunctionId ID of the requested operation
413 @param aSelection Selection of message entries. This is used if the operation
414 requires message entries to work on.
415 @param aParameter Buffer containing input and output parameters. The format
416 of this is specific to the operation.
417 @leave KErrNotSupported aFunctionId is not a recognised operation ID
418 @leave Other leave codes Dependent on implementation */
419 virtual void InvokeSyncFunctionL(TInt aFunctionId,const CMsvEntrySelection& aSelection, TDes8& aParameter)=0;
420 /** Invokes asynchronous protocol-specific operations. For synchronous operations,
421 a similar function, InvokeSyncFunctionL(), is available.
423 aSelection and aParameter allow data to be passed to the operation. The TRequestStatus
424 and CMsvOperation objects are used as normal to control and monitor the operation.
428 For functionality that requires message transport access, such as making a
429 connection, the implementation should pass the request onto the corresponding
430 Server-side MTM. This is done through calling CMsvSession::TransferCommandL().
431 Implementations may also provide protocol-specific functions themselves if
434 InvokeAsyncFunctionL() should return a CMsvOperation-derived object to provide
435 asynchronous control and monitoring of the operation. If CMsvSession::TransferCommandL()
436 is called, this should be the CMsvOperation object returned by that function.
438 @param aFunctionId ID of the requested operation
439 @param aSelection Selection of message entries. This is used if the operation
440 requires message entries to work on.
441 @param aParameter Buffer containing input and output parameters. The format
442 of this is specific to the operation.
443 @param aCompletionStatus The request status to be completed when the operation
445 @leave KErrNotSupported aFunctionId is not a recognised operation ID
446 @leave Other leave codes Dependent on implementation
447 @return If successful, this is an asynchronously completing operation. If failed,
448 this is a completed operation, with status set to the relevant error code. */
449 virtual CMsvOperation* InvokeAsyncFunctionL(TInt aFunctionId,const CMsvEntrySelection& aSelection, TDes8& aParameter, TRequestStatus& aCompletionStatus)=0;
451 IMPORT_C CMsvSession& Session();
453 // Attachment functions to support the SendAs API
454 virtual inline void Filler1() {};
455 virtual inline void Filler2() {};
456 IMPORT_C virtual void AddAttachmentL(const TDesC& aFilePath, const TDesC8& aMimeType, TUint aCharset, TRequestStatus& aStatus);
457 IMPORT_C virtual void AddAttachmentL(RFile& aFile, const TDesC8& aMimeType, TUint aCharset, TRequestStatus& aStatus);
458 IMPORT_C virtual void AddLinkedAttachmentL(const TDesC& aFilePath, const TDesC8& aMimeType, TUint aCharset, TRequestStatus& aStatus);
459 IMPORT_C virtual void AddEntryAsAttachmentL(TMsvId aAttachmentId, TRequestStatus& aStatus);
460 IMPORT_C virtual void CreateAttachmentL(const TDesC& aFileName, RFile& aAttachmentFile, const TDesC8& aMimeType, TUint aCharset, TRequestStatus& aStatus);
461 IMPORT_C virtual void CancelAttachmentOperation();
463 IMPORT_C virtual void CreateMessageL(TMsvId aServiceId);
465 // BIO functions to support the SendAs API
466 // Entry().Entry().iBioType will be set by SendAs if this function does not leave.
467 // The default implementation in CBaseMtm is to do nothing.
468 IMPORT_C virtual void BioTypeChangedL(TUid aBioTypeUid);
470 IMPORT_C virtual TMsvId DefaultServiceL() const;
471 IMPORT_C virtual void RemoveDefaultServiceL();
472 IMPORT_C virtual void ChangeDefaultServiceL(const TMsvId& aService);
474 //For setting the character encoding value, options are 7-bit, 8-bit and 16-bit Unicode.
475 IMPORT_C TInt SetMessageCharacterSet(TUint aCharSet);
476 IMPORT_C void SetExtensionData(TAny* aSortData);
477 IMPORT_C TAny* GetExtensionData();
480 IMPORT_C CBaseMtm(CRegisteredMtmDll& aRegisteredMtmDll, CMsvSession& aSession);
482 IMPORT_C void StoreBodyL(CMsvStore& aStore);
483 IMPORT_C void RestoreBodyL(CMsvStore& aStore);
485 /** Called by the base class functions SwitchCurrentEntryL() and SetCurrentEntryL()
486 when the context is changed to another entry.
488 Client applications do not use this function. It is relevant only to implementers
493 An implementation should clear:
495 1. address data stored in iAddresseeList
497 2. any caches of MTM-specific entry data relating to a previous context. For
498 example, if the implementation has a private buffer storing a message subject,
499 for access through Subject(), this buffer should be cleared. */
500 virtual void ContextEntrySwitched()=0; // called after the context of this instance has been changed to another entry
502 IMPORT_C void HandleEntryEventL(TMsvEntryEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3);
504 // Method used for extension: called by non virtual methods that need
505 // to have a polymorphic behaviour.
506 IMPORT_C virtual TAny* GetInterface(TUid aUid);
509 IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
514 void AddFilePathAttachmentL(const TDesC& aFilePath, const TDesC8& aMimeType, TUint aCharset, CMsvAttachment::TMsvAttachmentType aType, TRequestStatus& aStatus);
519 /** The current context. */
520 CMsvEntry* iMsvEntry;
521 /** The address list for the current context. */
522 CMsvRecipientList* iAddresseeList;
524 /** Paragraph formatting applied to the CRichText object for the body text, as
525 returned by Body(). This is set to an empty CParaFormatLayer instance whenever
528 Implementations can modify this if they wish to apply particular formatting
530 CParaFormatLayer* iParaFormatLayer;
531 /** Character formatting applied to the CRichText object for the body text, as
534 Implementations can modify this if they wish to apply particular formatting
536 CCharFormatLayer* iCharFormatLayer;
542 CRichText* iRichTextBody;
543 CRegisteredMtmDll& iRegisteredMtmDll;
544 CMsvSession& iSession;
545 CMsvAttachmentWaiter* iAttachmentWaiter;
547 // Extra data member to allow for future extensions
548 TAny* iExtensionData;
552 #endif // __MTCLBASE_H__