|
1 // Copyright (c) 2001-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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 //class include |
|
17 #include <obexclientmtm.h> |
|
18 |
|
19 //system includes |
|
20 #include <e32std.h> |
|
21 #include <e32base.h> |
|
22 #include <txtrich.h> // CRichText |
|
23 |
|
24 #include <mtmuids.h> // KUidMtmQueryCanSendMsg |
|
25 #include <msvreg.h> // CRegisteredMtmDll |
|
26 #include <mtmdef.h> // KUidMtmQueryxxx & TMsvPartList flags |
|
27 #include <msvuids.h> // KUidMsvMessageEntry |
|
28 #include <obexheader.h> // CObexMtmHeader |
|
29 |
|
30 |
|
31 #include <mmsvattachmentmanager.h> |
|
32 #include <msvids.h> |
|
33 |
|
34 |
|
35 #include <obexheaderlist.h> |
|
36 |
|
37 //user includes |
|
38 #include "obexClientMtmPanic.h" |
|
39 |
|
40 |
|
41 const TInt KMaxObexPasswordLength = 30; |
|
42 |
|
43 // |
|
44 // CObexClientMtm |
|
45 // |
|
46 EXPORT_C CObexClientMtm::CObexClientMtm(CRegisteredMtmDll& aRegisteredMtmDll, CMsvSession& aMsvSession, TUid aMsgTypeUid) |
|
47 : CBaseMtm(aRegisteredMtmDll, aMsvSession), |
|
48 iMsgTypeUid(aMsgTypeUid) |
|
49 /** |
|
50 * Constructor. Initialises iMsgTypeUid with Uid provided by the derived class. |
|
51 * |
|
52 * @param aRegisteredMtmDll Registration data for MTM DLL. |
|
53 * @param aMsvSession CMsvSession of the client requesting the object. |
|
54 * @param aMsgTypeUid Uid of the message |
|
55 */ |
|
56 { |
|
57 } |
|
58 |
|
59 EXPORT_C void CObexClientMtm::ConstructL() |
|
60 /** |
|
61 * Empty implementation provided for future-proofing. |
|
62 */ |
|
63 { |
|
64 } |
|
65 |
|
66 EXPORT_C CObexClientMtm::~CObexClientMtm() |
|
67 /** |
|
68 * Destructor deletes FileNameExternaliser and Header |
|
69 */ |
|
70 { |
|
71 delete iHeader; |
|
72 } |
|
73 |
|
74 EXPORT_C void CObexClientMtm::SaveMessageL() |
|
75 /** |
|
76 * Commits cached changes to the message store, by calling CommitChangesL. |
|
77 * |
|
78 * @leave KErrXxx System-wide error codes if message cannot be saved. |
|
79 */ |
|
80 { |
|
81 //Commit header to store. |
|
82 CMsvStore* store = iMsvEntry->EditStoreL(); |
|
83 CleanupStack::PushL(store); |
|
84 iHeader->StoreL(*store); |
|
85 store->CommitL(); |
|
86 CleanupStack::PopAndDestroy(); |
|
87 |
|
88 CommitChangesL(); |
|
89 |
|
90 } |
|
91 |
|
92 EXPORT_C void CObexClientMtm::CommitChangesL() |
|
93 /** |
|
94 * Commits cached changes to the message store. |
|
95 * |
|
96 * @leave KErrXxx System-wide error codes if changes cannot be committed. |
|
97 */ |
|
98 { // OBEX messages are very simple. Outgoing data is expected to be in attachments. To save space filenames |
|
99 // can be stored within entry (instead of making copies of the data), which will be loaded upon send. |
|
100 if(Body().DocumentLength() > 0) |
|
101 { |
|
102 User::Leave(KErrNotSupported); // Data is not expected in the message body |
|
103 } |
|
104 |
|
105 // Update entry details |
|
106 TMsvEntry messageEntry=iMsvEntry->Entry(); |
|
107 |
|
108 // since CBaseMtm::CreateMessageL creates message as in preparation and non-visible, |
|
109 // must now make it visible and not in preparation |
|
110 messageEntry.SetVisible(ETrue); |
|
111 messageEntry.SetInPreparation(EFalse); |
|
112 |
|
113 messageEntry.iSize = GetAttachmentSizeL(); |
|
114 messageEntry.iDescription.Set(SubjectL()); |
|
115 |
|
116 if (AddresseeList().Count() > 0) |
|
117 messageEntry.iDetails.Set(AddresseeList()[0]); |
|
118 |
|
119 // Display the required send status. |
|
120 messageEntry.SetSendingState(KMsvSendStateWaiting); // Quartz are checking this flag for ir messaging for sending |
|
121 |
|
122 // update the contents of the message entry |
|
123 iMsvEntry->ChangeL(messageEntry); |
|
124 } |
|
125 |
|
126 |
|
127 |
|
128 EXPORT_C void CObexClientMtm::CreateMessageL(TMsvId /*aServiceId*/) |
|
129 /** |
|
130 * Create a new message for this MTM. This creates a new messaging entry, then |
|
131 * re-initialises the MTM's CObexMtmHeader object. |
|
132 * |
|
133 * @param aServiceId The ID of the service for which the message is to be created |
|
134 * @leave KErrXxx Standard EPOC error codes if construction of new objects fails |
|
135 */ |
|
136 { |
|
137 // First create the message as normal: this creates a new entry of the current MTM type |
|
138 CBaseMtm::CreateMessageL(KMsvRootIndexEntryId); |
|
139 |
|
140 // Now call ContextEntrySwitched as this isn't called from CBaseMtm::CreateMessageL |
|
141 ContextEntrySwitched(); |
|
142 |
|
143 // Now create a new iHeader |
|
144 InitialiseHeaderL(); |
|
145 } |
|
146 |
|
147 |
|
148 EXPORT_C void CObexClientMtm::LoadMessageL() |
|
149 /** |
|
150 * This function loads the header from the message store |
|
151 * |
|
152 * @leave KErrXXX system-wide error codes |
|
153 */ |
|
154 { |
|
155 __ASSERT_DEBUG(iMsvEntry!=NULL,gPanic(EObexMtmNoCMsvEntrySet)); |
|
156 __ASSERT_DEBUG(iMsvEntry->Entry().iType.iUid==KUidMsvMessageEntryValue, gPanic(EObexMtmNotAMessageEntry)); |
|
157 |
|
158 //(Re-)initialise header to appropriate CObexMtmHeader derived class |
|
159 InitialiseHeaderL(); |
|
160 |
|
161 |
|
162 // INC042015: |
|
163 // catch and "pre-process" here errors in ReadStoreL. |
|
164 // Ignore the error if the leave occurs because there is no store, UNLESS the message |
|
165 // is being sent (in this case the header IS needed). |
|
166 CMsvStore* store = NULL; |
|
167 TRAPD(err, store = iMsvEntry->ReadStoreL() ); |
|
168 if (err == KErrNone) // store is OK |
|
169 { |
|
170 CleanupStack::PushL(store); |
|
171 iHeader->RestoreL(*store); |
|
172 CleanupStack::PopAndDestroy(); |
|
173 } |
|
174 else if ( (err == KErrNotFound) && (iMsvEntry->Entry().Parent() != KMsvGlobalOutBoxIndexEntryId) ) |
|
175 { // ignore error in this particular case: the header is not needed. |
|
176 return; |
|
177 } |
|
178 else // in all other cases, pass on the error as was done before |
|
179 { |
|
180 User::LeaveIfError(err); |
|
181 } |
|
182 } |
|
183 |
|
184 |
|
185 EXPORT_C TInt32 CObexClientMtm::GetAttachmentSizeL() |
|
186 /** |
|
187 * This function calculates the size of all attachments to the message by either: |
|
188 * |
|
189 * @li summing the sizes of each of the children or; |
|
190 * @li reading in all of the filenames from the store, and summing their sizes.* |
|
191 * |
|
192 * @return total size of the attachments. |
|
193 * @leave KErrXXX system-wide error codes |
|
194 */ |
|
195 { |
|
196 TInt size=0; //Total attachment size |
|
197 |
|
198 |
|
199 |
|
200 // size has not yet been set, must be using the Attachment API, so use |
|
201 // the Attachment API to calculate size |
|
202 CMsvStore* store = iMsvEntry->ReadStoreL(); |
|
203 CleanupStack::PushL(store); |
|
204 MMsvAttachmentManager& manager = store->AttachmentManagerL(); |
|
205 TInt attachmentCount = manager.AttachmentCount(); |
|
206 for( TInt ii=0; ii<attachmentCount; ++ii ) |
|
207 { |
|
208 // loop through each attachment... |
|
209 CMsvAttachment* attachmentInfo = manager.GetAttachmentInfoL(ii); |
|
210 if( attachmentInfo->Type() == CMsvAttachment::EMsvMessageEntry ) |
|
211 { |
|
212 // Only EFileAttachment and ELinkedFile are supported |
|
213 User::Leave(KErrArgument); |
|
214 } |
|
215 size += attachmentInfo->Size(); |
|
216 delete attachmentInfo; |
|
217 } |
|
218 CleanupStack::PopAndDestroy(store); |
|
219 |
|
220 |
|
221 return size; |
|
222 } |
|
223 |
|
224 // |
|
225 |
|
226 EXPORT_C CMsvOperation* CObexClientMtm::ReplyL(TMsvId /*aReplyEntryId*/, TMsvPartList /*aPartlist*/, TRequestStatus& /*aCompletionStatus*/) |
|
227 /** |
|
228 * Unsupported |
|
229 * |
|
230 * @leave Leaves always with KErrNotSupported |
|
231 */ |
|
232 { |
|
233 User::Leave(KErrNotSupported); |
|
234 return (CMsvOperation*)NULL; |
|
235 } |
|
236 |
|
237 EXPORT_C CMsvOperation* CObexClientMtm::ForwardL(TMsvId /*aForwardEntryId*/, TMsvPartList /*aPartList*/, TRequestStatus& /*aCompletionStatus*/) |
|
238 /** |
|
239 * Unsupported |
|
240 * |
|
241 * @leave Leaves always with KErrNotSupported |
|
242 */ |
|
243 { |
|
244 User::Leave(KErrNotSupported); |
|
245 return (CMsvOperation*)NULL; |
|
246 } |
|
247 |
|
248 EXPORT_C TUint CObexClientMtm::ValidateMessage(TMsvPartList aPartList) |
|
249 /** |
|
250 * Ensure that the current message context part indicated is valid. Currently only works on KMsvMessagePartRecipient--all other parts |
|
251 * are assumed to be valid |
|
252 * |
|
253 * @param aPartList Bitmask indicating parts of message to be validated |
|
254 * @return Bitmask of any invalid parts--KErrNone otherwise |
|
255 */ |
|
256 { |
|
257 TMsvPartList failed = KErrNone; // No errors. |
|
258 |
|
259 if (!iAddresseeList) |
|
260 { |
|
261 return KMsvMessagePartRecipient; |
|
262 } |
|
263 |
|
264 if(aPartList & KMsvMessagePartRecipient) |
|
265 { |
|
266 // All actual recipients should have at least one character. |
|
267 for (TInt ii=0; ii < iAddresseeList->Count(); ++ii) |
|
268 { |
|
269 if((*iAddresseeList)[ii].Length() == 0) |
|
270 { |
|
271 failed |= KMsvMessagePartRecipient; |
|
272 break; |
|
273 } |
|
274 } |
|
275 } |
|
276 return failed; |
|
277 } |
|
278 |
|
279 |
|
280 EXPORT_C TMsvPartList CObexClientMtm::Find(const TDesC& /*aTextToFind*/, TMsvPartList /*aPartList*/) |
|
281 /** |
|
282 * Finds the given text within the specified parts of the current message context. NOT IMPLEMENTED! |
|
283 * |
|
284 * @param aTextToFind Reference to the text to search for in the specified message parts |
|
285 * @param aPartList Bitmask indicating parts of message to be searched for the text |
|
286 * @return Bitmask of any parts containing the message text |
|
287 */ |
|
288 { |
|
289 return 0; |
|
290 } |
|
291 |
|
292 |
|
293 EXPORT_C void CObexClientMtm::SetSubjectL(const TDesC& aSubject) |
|
294 /** |
|
295 * Sets the subject of the current message context |
|
296 * |
|
297 * @param aSubject Reference to the new message subject text |
|
298 * @leave Leaves if creation of new HBufC fails |
|
299 */ |
|
300 { |
|
301 iHeader->SetSubjectL(aSubject); |
|
302 } |
|
303 |
|
304 |
|
305 EXPORT_C const TPtrC CObexClientMtm::SubjectL() const |
|
306 /** |
|
307 * Returns the subject of the current message context. Will not leave. |
|
308 * |
|
309 * @return const TPtrC representation of the Subject, or an empty TPtrC if the subject hasn't been set |
|
310 * @leave Never |
|
311 */ |
|
312 { |
|
313 return iHeader->Subject(); |
|
314 } |
|
315 |
|
316 |
|
317 EXPORT_C void CObexClientMtm::AddAddresseeL(const TDesC& aRealAddress) |
|
318 /** |
|
319 * Adds addressee to the addressee "list". Note that this MUST be a TDesC containing binary data representing |
|
320 * the TSockAddress of the addressee, usually as a TDesC16. This function will then package the data directly into |
|
321 * 8 bit data. |
|
322 * NB: Only ONE addressee is supported |
|
323 * |
|
324 * @param aRealAddress Reference to the address of the recipient |
|
325 * @leave KErrXXX if address cannot be appended |
|
326 * @leave KErrAlreadyExists if the Addressee "list" already contains an entry |
|
327 */ |
|
328 { |
|
329 if (iAddresseeList->Count()==0) |
|
330 { |
|
331 //list is empty--OK to add addressee |
|
332 iAddresseeList->AppendL(aRealAddress); |
|
333 |
|
334 } |
|
335 else |
|
336 { |
|
337 //list already contains an entry--leave with KErrAlreadyExists |
|
338 User::Leave(KErrAlreadyExists); |
|
339 } |
|
340 } |
|
341 |
|
342 EXPORT_C void CObexClientMtm::AddAddresseeL(const TDesC& aRealAddress, const TDesC& /*aAlias*/) |
|
343 |
|
344 /** |
|
345 * Adds addressee to the addressee "list". Note that this MUST be a TDesC containing binary data representing |
|
346 * the TSockAddress of the addressee, usually as a TDesC16. This function will then package the data directly into |
|
347 * 8 bit data. |
|
348 * NB: Only ONE addressee is supported |
|
349 * |
|
350 * @param aRealAddress Reference to the address of the recipient |
|
351 * @param aAlias Reference to the alias of the recipient--ignored in this implementation |
|
352 * @leave KErrXXX if address cannot be appended |
|
353 * @leave KErrAlreadyExists if the Addressee "list" already contains an entry |
|
354 */ |
|
355 { |
|
356 AddAddresseeL(aRealAddress); |
|
357 } |
|
358 |
|
359 EXPORT_C void CObexClientMtm::RemoveAddressee(TInt /*aIndex*/) |
|
360 /** |
|
361 * Removes addressee at index aIndex from the addressee "list". |
|
362 * |
|
363 * @param aIndex zero-based index of the addressee (ignored since "there can be only one"). |
|
364 */ |
|
365 { |
|
366 if (iAddresseeList->Count() > 0) //since only one addressee is supported anyhow |
|
367 { |
|
368 iAddresseeList->Delete(0); |
|
369 } |
|
370 } |
|
371 |
|
372 EXPORT_C void CObexClientMtm::ContextEntrySwitched() |
|
373 /** |
|
374 * Resets the MTM when the context is switched. |
|
375 * Must be called by the derived class's ContextEntrySwitched prior to constructing a new header. |
|
376 */ |
|
377 { |
|
378 iAddresseeList->Reset(); |
|
379 delete iHeader; //will be reconstructed in LoadMessageL() |
|
380 iHeader = NULL; |
|
381 } |
|
382 |
|
383 |
|
384 EXPORT_C TInt CObexClientMtm::QueryCapability(TUid aCapability, TInt& aResponse) |
|
385 /** |
|
386 * Gives the capability of the MTM. |
|
387 * |
|
388 * @param aCapability capability to be queried |
|
389 * @param aResponse capability dependent return value. |
|
390 * @return KErrNone if the capability is supported, or KErrNotSupported if not. |
|
391 */ |
|
392 { |
|
393 TInt error = KErrNone; |
|
394 switch (aCapability.iUid) |
|
395 { |
|
396 case KUidMtmQueryMaxBodySizeValue: |
|
397 case KUidMtmQueryMaxTotalMsgSizeValue: |
|
398 aResponse = KMaxTInt; |
|
399 break; |
|
400 case KUidMtmQuerySupportAttachmentsValue: |
|
401 case KUidMtmQuerySupportSubjectValue: |
|
402 case KUidMtmQueryCanSendMsgValue: |
|
403 case KUidMtmQuerySupportsBioMsgValue: |
|
404 case KUidMtmQuerySendAsMessageSendSupportValue: |
|
405 break; |
|
406 case KUidMtmQueryMaxRecipientCountValue: |
|
407 aResponse = 1; |
|
408 break; |
|
409 case KUidMtmQuerySupportedBodyValue: |
|
410 aResponse = KMtm7BitBody + KMtm8BitBody + KMtm16BitBody + KMtmBinaryBody; |
|
411 break; |
|
412 case KUidMsvMtmQueryEditorUidValue: // Return NULL for editor value because there is no OBEX editor. |
|
413 break; |
|
414 default: |
|
415 return KErrNotSupported; |
|
416 } |
|
417 return error; |
|
418 } |
|
419 |
|
420 /** |
|
421 Obex based MTMs do not support message entry attachments. This method will leave with |
|
422 KErrNotSupported. |
|
423 @param aAttachmentId This is not supported. |
|
424 @leave KErrNotSupported This method is not supported. |
|
425 */ |
|
426 EXPORT_C void CObexClientMtm::CreateMessageAttachmentL(TMsvId /*aAttachmentId*/) |
|
427 { |
|
428 User::Leave(KErrNotSupported); |
|
429 } |
|
430 |
|
431 /** |
|
432 No functionality is provided by this method. Leaves with KErrNotSupported. |
|
433 @param aFunctionId Unused. |
|
434 @param aSelection Unused. |
|
435 @param aParameter Unused. |
|
436 @leave KErrNotSupported |
|
437 */ |
|
438 EXPORT_C void CObexClientMtm::InvokeSyncFunctionL(TInt /*aFunctionId*/, const CMsvEntrySelection& /*aSelection*/, TDes8& /*aParameter*/) |
|
439 { |
|
440 User::Leave(KErrNotSupported); |
|
441 } |
|
442 |
|
443 |