|
1 // Copyright (c) 2003-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 #include <msvids.h> |
|
17 #include <push/unknownmimedefs.h> |
|
18 #include <bautils.h> // Bafl |
|
19 #include <barsc.h> // RResourceFile |
|
20 #include <barsread.h> // TResourceReader |
|
21 #include <wappushunknown.rsg> |
|
22 |
|
23 #include <push/cunknownpushmsgentry.h> |
|
24 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
25 #include "PushEntryPanic.h" |
|
26 #endif//SYMBIAN_ENABLE_SPLIT_HEADERS |
|
27 |
|
28 #ifdef __MESSAGING_API_V2__ |
|
29 #include "CAsyncWaiter.h" |
|
30 |
|
31 #include <cmsvattachment.h> |
|
32 #include <mmsvattachmentmanager.h> |
|
33 #endif // __MESSAGING_API_V2__ |
|
34 |
|
35 _LIT(KContentResourceFile, "\\system\\data\\wappushunknown.rsc"); |
|
36 |
|
37 GLDEF_C TPtrC16 LimitStringSize(const TPtrC16& aString, TInt aMaxSize); |
|
38 |
|
39 |
|
40 /** |
|
41 Allocates and constructs a new Unknown WAP Push message object. |
|
42 |
|
43 @return CUnknownPushMsgEntry* |
|
44 New Unknown WAP Push message object. |
|
45 */ |
|
46 EXPORT_C CUnknownPushMsgEntry* CUnknownPushMsgEntry::NewL() |
|
47 { |
|
48 CUnknownPushMsgEntry* self = new (ELeave) CUnknownPushMsgEntry(); |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(); |
|
51 CleanupStack::Pop(); |
|
52 return self; |
|
53 } |
|
54 |
|
55 |
|
56 /** |
|
57 Allocates and constructs a new Unknown WAP Push message object, specifying the AppId |
|
58 as a string. |
|
59 |
|
60 @param aAppURI |
|
61 AppId value as a string. |
|
62 |
|
63 @return CUnknownPushMsgEntry* |
|
64 New Unknown WAP Push message object. |
|
65 */ |
|
66 EXPORT_C CUnknownPushMsgEntry* CUnknownPushMsgEntry::NewL(const TPtrC8& aAppURI) |
|
67 { |
|
68 CUnknownPushMsgEntry* self = new (ELeave) CUnknownPushMsgEntry(); |
|
69 CleanupStack::PushL(self); |
|
70 self->ConstructL(aAppURI); |
|
71 CleanupStack::Pop(); |
|
72 return self; |
|
73 } |
|
74 |
|
75 |
|
76 /** |
|
77 Allocates and constructs a new Unknown WAP Push message object, |
|
78 specifying the AppId as a number. |
|
79 |
|
80 @param aAppID |
|
81 AppId value as a number. |
|
82 |
|
83 @return CUnknownPushMsgEntry* |
|
84 New Unknown WAP Push message object. |
|
85 */ |
|
86 EXPORT_C CUnknownPushMsgEntry* CUnknownPushMsgEntry::NewL(TInt& aAppID) |
|
87 { |
|
88 CUnknownPushMsgEntry* self = new (ELeave) CUnknownPushMsgEntry(); |
|
89 CleanupStack::PushL(self); |
|
90 self->ConstructL(aAppID); |
|
91 CleanupStack::Pop(); |
|
92 return self; |
|
93 } |
|
94 |
|
95 |
|
96 /** |
|
97 Destructor. |
|
98 */ |
|
99 EXPORT_C CUnknownPushMsgEntry::~CUnknownPushMsgEntry() |
|
100 { |
|
101 iRFs.Close(); |
|
102 delete iMessageData; |
|
103 delete iContentType; |
|
104 delete iFilename; |
|
105 } |
|
106 |
|
107 |
|
108 /** |
|
109 Sets the Content Type of the message. |
|
110 |
|
111 @param aContentType |
|
112 The content type of the message |
|
113 */ |
|
114 EXPORT_C void CUnknownPushMsgEntry::SetContentTypeL(const TDesC& aContentType) |
|
115 { |
|
116 HBufC* tempBuf = aContentType.AllocL(); |
|
117 |
|
118 delete iContentType; |
|
119 iContentType = tempBuf; |
|
120 } |
|
121 |
|
122 |
|
123 EXPORT_C const TDesC8& CUnknownPushMsgEntry::MessageData() const |
|
124 /** |
|
125 Gets the message data. |
|
126 |
|
127 If the buffer for the message data does not exist, a null descriptor is returned. |
|
128 |
|
129 @return |
|
130 Message data |
|
131 */ |
|
132 { |
|
133 if (iMessageData) |
|
134 return *iMessageData; |
|
135 else |
|
136 return KNullDesC8; |
|
137 } |
|
138 |
|
139 |
|
140 /** |
|
141 Sets the message data. |
|
142 |
|
143 @param aMessageData |
|
144 Message data |
|
145 */ |
|
146 EXPORT_C void CUnknownPushMsgEntry::SetMessageDataL(const TDesC8& aMessageData) |
|
147 { |
|
148 HBufC8* tempBuf = aMessageData.AllocL(); |
|
149 |
|
150 delete iMessageData; |
|
151 iMessageData = tempBuf; |
|
152 } |
|
153 |
|
154 |
|
155 /** |
|
156 Gets the content filename of the message. Content Filename is the name of the file where the |
|
157 Push message content is stored. |
|
158 |
|
159 If filename does not exist then a default filename is returned, which is defined in wappushunknown.rss file. |
|
160 |
|
161 Note the function will return the filename in memory which may not necessarily be the filename stored in the |
|
162 message store. RetrieveL should be called before calling this function to get the filename stored in the |
|
163 message store. |
|
164 |
|
165 @code |
|
166 // Create an unknown push message object. |
|
167 CUnknownPushMsgEntry* entry = CUnknownPushMsgEntry::NewL(); |
|
168 CleanupStack::PushL(entry); |
|
169 |
|
170 // Retrieve the required message from the message store. |
|
171 entry->RetrieveL(session, messageId); |
|
172 |
|
173 // Get file name |
|
174 TFileName fileName = entry->ContentFileNameL(); |
|
175 |
|
176 CleanupStack::PopAndDestroy(entry); |
|
177 @endcode |
|
178 |
|
179 @return |
|
180 The content filename of the message. |
|
181 |
|
182 @see CUnknownPushMsgEntry::RetrieveL() |
|
183 */ |
|
184 EXPORT_C const TDesC& CUnknownPushMsgEntry::ContentFileNameL() |
|
185 { |
|
186 if (iFilename && iFilename->Length()>0 && iFilename->Length() <= KMaxFileName) |
|
187 { |
|
188 // filename has been set |
|
189 return *iFilename; |
|
190 } |
|
191 else |
|
192 { |
|
193 TFileName filename = iDefaultBaseFilename; |
|
194 // append the extension based on the content type |
|
195 filename.Append(ContentTypeExtension(ContentType())); |
|
196 SetContentFileNameL(filename); |
|
197 return *iFilename; |
|
198 } |
|
199 } |
|
200 |
|
201 |
|
202 /** |
|
203 Sets the content filename of the message. Content Filename is the name of the file where the |
|
204 Push message content is stored. |
|
205 |
|
206 Note the function will only save the filename in memory. SaveL or UpdateL will have |
|
207 to be called to commit the changes to the message store. |
|
208 |
|
209 @code |
|
210 // Create an unknown push message object. |
|
211 CUnknownPushMsgEntry* entry = CUnknownPushMsgEntry::NewL(); |
|
212 CleanupStack::PushL(entry); |
|
213 |
|
214 // Retrieve the required message from the message store. |
|
215 entry->RetrieveL(session, messageId); |
|
216 |
|
217 // Set file name |
|
218 _LIT(KFilename, "image.jpg"); |
|
219 entry->SetContentFileNameL(KFilename); |
|
220 |
|
221 // Commit the changes to the message store. |
|
222 entry->UpdateL(session); |
|
223 |
|
224 CleanupStack::PopAndDestroy(entry); |
|
225 @endcode |
|
226 |
|
227 @param aFilename |
|
228 The content filename. |
|
229 |
|
230 @leave KErrBadName aFilename is not a valid Symbian OS file name. |
|
231 @leave TDesC::AllocL() |
|
232 */ |
|
233 EXPORT_C void CUnknownPushMsgEntry::SetContentFileNameL(const TDesC& aFilename) |
|
234 { |
|
235 // Check for valid filname. |
|
236 if (!iRFs.IsValidName(aFilename)) |
|
237 User::Leave(KErrBadName); |
|
238 |
|
239 HBufC* tempBuf = aFilename.AllocL(); |
|
240 delete iFilename; |
|
241 iFilename = tempBuf; |
|
242 } |
|
243 |
|
244 |
|
245 /** |
|
246 Constructor. |
|
247 Simply connects to the File Server before calling base class ConstructL(). |
|
248 */ |
|
249 void CUnknownPushMsgEntry::ConstructL() |
|
250 { |
|
251 User::LeaveIfError(iRFs.Connect()); |
|
252 CPushMsgEntryBase::ConstructL(); |
|
253 SetDefaultBaseFileNameL(); |
|
254 } |
|
255 |
|
256 |
|
257 /** |
|
258 Constructor. |
|
259 Simply connects to the File Server before calling base class ConstructL(). |
|
260 |
|
261 @param |
|
262 aAppURI set this value if AppId is in string form (must set aIsAnInt to EFalse). |
|
263 */ |
|
264 void CUnknownPushMsgEntry::ConstructL(const TPtrC8& aAppURI) |
|
265 { |
|
266 User::LeaveIfError(iRFs.Connect()); |
|
267 CPushMsgEntryBase::ConstructL(aAppURI); |
|
268 SetDefaultBaseFileNameL(); |
|
269 } |
|
270 |
|
271 |
|
272 /** |
|
273 Constructor. |
|
274 Simply connects to the File Server before calling base class ConstructL(). |
|
275 |
|
276 @param |
|
277 aAppID set this value if AppId is a number (must set aIsAnInt to ETrue). |
|
278 */ |
|
279 void CUnknownPushMsgEntry::ConstructL(TInt& aAppID) |
|
280 { |
|
281 User::LeaveIfError(iRFs.Connect()); |
|
282 CPushMsgEntryBase::ConstructL(aAppID); |
|
283 SetDefaultBaseFileNameL(); |
|
284 } |
|
285 |
|
286 |
|
287 /** |
|
288 Constructor. |
|
289 */ |
|
290 CUnknownPushMsgEntry::CUnknownPushMsgEntry() |
|
291 { |
|
292 } |
|
293 |
|
294 |
|
295 /** |
|
296 Opens wappushunknown.rss resource file for reading. |
|
297 |
|
298 @param aFile |
|
299 A resource file. |
|
300 */ |
|
301 void CUnknownPushMsgEntry::OpenResourceFileL(RResourceFile& aFile) |
|
302 { |
|
303 // open resource file |
|
304 TFileName fileName; |
|
305 Dll::FileName(fileName); |
|
306 TParse parse; |
|
307 parse.Set(KContentResourceFile, &fileName, 0); |
|
308 fileName=parse.FullName(); |
|
309 |
|
310 BaflUtils::NearestLanguageFile(iRFs, fileName); |
|
311 aFile.OpenL(iRFs, fileName); |
|
312 } |
|
313 |
|
314 |
|
315 /** |
|
316 Sets default content base filename |
|
317 */ |
|
318 void CUnknownPushMsgEntry::SetDefaultBaseFileNameL() |
|
319 { |
|
320 // generate default filename from the wappushunknown resource file. |
|
321 RResourceFile resourceFile; |
|
322 OpenResourceFileL(resourceFile); |
|
323 CleanupClosePushL(resourceFile); |
|
324 |
|
325 HBufC8* buf = resourceFile.AllocReadLC(CONTENT); |
|
326 TResourceReader reader; |
|
327 reader.SetBuffer(buf); |
|
328 |
|
329 iDefaultBaseFilename.Copy(reader.ReadTPtrC()); |
|
330 CleanupStack::PopAndDestroy(2,&resourceFile); // buf, resourceFile |
|
331 } |
|
332 |
|
333 |
|
334 /** |
|
335 Stores the Unknown Push message in the message store. |
|
336 |
|
337 Saves the message data in a new attachment file. This makes it more efficient for the UI |
|
338 to read the data. |
|
339 |
|
340 @param aSession |
|
341 Message server session |
|
342 |
|
343 @param aParent |
|
344 ID of the parent for the new entry. It is the caller's responsibility to ensure |
|
345 that the parent ID is correct. |
|
346 |
|
347 @return |
|
348 ID of the new message server entry. |
|
349 |
|
350 @see CPushMsgEntryBase::SaveL() |
|
351 */ |
|
352 EXPORT_C TMsvId CUnknownPushMsgEntry::SaveL(CMsvSession& aSession, TMsvId aParent) |
|
353 |
|
354 { |
|
355 CMsvEntry* entryPtr = aSession.GetEntryL(KMsvRootIndexEntryId); |
|
356 CleanupStack::PushL(entryPtr); |
|
357 |
|
358 // This tidies itself up |
|
359 TMsvId newEntry = CPushMsgEntryBase::SaveL(aSession, aParent); |
|
360 |
|
361 #ifdef __MESSAGING_API_V2__ |
|
362 TRAPD( |
|
363 saveError, |
|
364 TFileName fileName = ContentFileNameL(); |
|
365 entryPtr->SetEntryL(newEntry); |
|
366 CMsvStore* store = entryPtr->EditStoreL(); |
|
367 CleanupStack::PushL(store); |
|
368 SaveMessageBodyL(store->AttachmentManagerL(), fileName); |
|
369 store->CommitL(); |
|
370 CleanupStack::PopAndDestroy(store); |
|
371 ) |
|
372 #else |
|
373 TRAPD( |
|
374 saveError, |
|
375 TFileName fileName = ContentFileNameL(); |
|
376 entryPtr->SetEntryL(newEntry); |
|
377 SaveMessageBodyL(*entryPtr, fileName); |
|
378 ) |
|
379 #endif // __MESSAGING_API_V2__ |
|
380 |
|
381 if (saveError != KErrNone) |
|
382 { |
|
383 aSession.RemoveEntry(iEntry.Id()); |
|
384 User::Leave(saveError); |
|
385 } |
|
386 CleanupStack::PopAndDestroy(); //entryPtr |
|
387 return newEntry; |
|
388 } |
|
389 |
|
390 #ifdef __MESSAGING_API_V2__ |
|
391 void CUnknownPushMsgEntry::SaveMessageBodyL(MMsvAttachmentManager& aAttachManager, const TDesC& aFileName) |
|
392 #else |
|
393 /** |
|
394 Stores the Push message body data in an attachment file in the message store. |
|
395 |
|
396 @param aEntry |
|
397 Reference to the message entry. |
|
398 |
|
399 @param aFileName |
|
400 The name of the file where the message body data is to be stored. |
|
401 */ |
|
402 void CUnknownPushMsgEntry::SaveMessageBodyL(const CMsvEntry& aEntry, TFileName& aFileName) |
|
403 #endif // __MESSAGING_API_V2__ |
|
404 { |
|
405 #ifdef __MESSAGING_API_V2__ |
|
406 // Create an empty file attachment store the data |
|
407 CAsyncWaiter* waiter = CAsyncWaiter::NewL(); |
|
408 CleanupStack::PushL(waiter); |
|
409 CMsvAttachment* attachment = CMsvAttachment::NewL(CMsvAttachment::EMsvFile); |
|
410 CleanupStack::PushL(attachment); |
|
411 attachment->SetAttachmentNameL(aFileName); |
|
412 RFile file; |
|
413 aAttachManager.CreateAttachmentL(aFileName, file, attachment, waiter->iStatus); |
|
414 CleanupStack::Pop(attachment); // ownership passed |
|
415 waiter->StartAndWait(); |
|
416 User::LeaveIfError(waiter->Result()); |
|
417 CleanupStack::PopAndDestroy(waiter); |
|
418 CleanupClosePushL(file); |
|
419 |
|
420 // write the data to the attachment file, if message data exists |
|
421 if( iMessageData ) |
|
422 User::LeaveIfError(file.Write(*iMessageData)); |
|
423 |
|
424 CleanupStack::PopAndDestroy(&file); |
|
425 #else |
|
426 TFileName filePath; |
|
427 |
|
428 // create directory path for current entry, to put file into |
|
429 aEntry.GetFilePath(filePath); |
|
430 |
|
431 // check the path and file name is not too long... |
|
432 TParse parse; |
|
433 if (parse.Set(aFileName, &filePath, NULL) != KErrNone) |
|
434 { |
|
435 // Try with the default file name as the file name the client set may be too long. |
|
436 // If this leaves then the entry path is probably too long. Not much we |
|
437 // can do about that. |
|
438 TFileName defaultFileName; |
|
439 defaultFileName.Copy(iDefaultBaseFilename); |
|
440 defaultFileName.Append(ContentTypeExtension(ContentType())); |
|
441 User::LeaveIfError(parse.Set(defaultFileName, &filePath, NULL)); |
|
442 }; |
|
443 |
|
444 RFile file; |
|
445 User::LeaveIfError(file.Replace(iRFs, parse.FullName(), EFileWrite|EFileShareExclusive|EFileStream)); |
|
446 CleanupClosePushL(file); |
|
447 |
|
448 // Got this far, so it worked - write data to it |
|
449 TInt fileErr = KErrNone; |
|
450 if (iMessageData) |
|
451 { |
|
452 fileErr = file.Write(*iMessageData); |
|
453 } |
|
454 |
|
455 if(fileErr!=KErrNone) |
|
456 { |
|
457 iRFs.Delete(parse.FullName()); |
|
458 User::Leave(fileErr); |
|
459 } |
|
460 CleanupStack::PopAndDestroy(&file); // file |
|
461 #endif // __MESSAGING_API_V2__ |
|
462 } |
|
463 |
|
464 |
|
465 /** |
|
466 Updates an existing message server entry. |
|
467 |
|
468 The functionality is similiar to SaveL(), except no new entry is created. Before calling |
|
469 this function, the existing entry must be loaded into the object using RetrieveL(). |
|
470 |
|
471 @param aSession |
|
472 Message server session |
|
473 |
|
474 @see CUnknownPushMsgEntry::SaveL() |
|
475 @see CUnknownPushMsgEntry::RetrieveL() |
|
476 @see CPushMsgEntryBase::UpdateL() |
|
477 */ |
|
478 EXPORT_C void CUnknownPushMsgEntry::UpdateL(CMsvSession& aSession) |
|
479 { |
|
480 if (iHasServerEntry ==EFalse ) |
|
481 User::Leave(KWPushNoMsgIndexEntry); |
|
482 CMsvEntry* msvEntry = aSession.GetEntryL(iEntry.Id()); |
|
483 CleanupStack::PushL(msvEntry); |
|
484 |
|
485 //Can only overwrite a pushmessage of the same type |
|
486 // Mtm & Push Type Uid must be correct |
|
487 __ASSERT_ALWAYS( msvEntry->Entry().iMtm == KUidMtmWapPush, |
|
488 User::Panic(KPushPanicMoniker, EPushEntryWrongMTMtype)); |
|
489 __ASSERT_ALWAYS( msvEntry->Entry().iBioType == PushMsgType(), |
|
490 User::Panic(KPushPanicMoniker, EPushEntryWrongMsgtype)); |
|
491 |
|
492 // Remove existing contents of stream and store new data |
|
493 CMsvStore* store = msvEntry->EditStoreL(); |
|
494 CleanupStack::PushL(store); |
|
495 |
|
496 TUid streamId; |
|
497 streamId.iUid = PushMsgType(); |
|
498 RMsvWriteStream out; |
|
499 out.AssignLC(*store, streamId); |
|
500 ExternalizeL(out); |
|
501 |
|
502 #ifdef __MESSAGING_API_V2__ |
|
503 // remove all previous attachments |
|
504 MMsvAttachmentManager& manager = store->AttachmentManagerL(); |
|
505 CAsyncWaiter* waiter = CAsyncWaiter::NewL(); |
|
506 CleanupStack::PushL(waiter); |
|
507 TInt attachCount = manager.AttachmentCount(); |
|
508 for( TInt ii=attachCount-1; ii>=0; --ii ) |
|
509 { |
|
510 manager.RemoveAttachmentL(ii, waiter->iStatus); |
|
511 waiter->StartAndWait(); |
|
512 User::LeaveIfError(waiter->Result()); |
|
513 } |
|
514 CleanupStack::PopAndDestroy(waiter); |
|
515 |
|
516 // the message body data as an attachment |
|
517 TFileName dataFile = ContentFileNameL(); |
|
518 SaveMessageBodyL(manager, dataFile); |
|
519 |
|
520 // update the entry |
|
521 iEntry.iMtm = KUidMtmWapPush; |
|
522 SetPushMsgType(); |
|
523 msvEntry->ChangeL(iEntry); |
|
524 #else |
|
525 TFileName tempfile; |
|
526 tempfile.Copy(KTempUnknownFileName); |
|
527 tempfile.Append(ContentTypeExtension(ContentType())); |
|
528 SaveMessageBodyL(*msvEntry, tempfile); // NB this tidies up if it leaves |
|
529 |
|
530 // Ensure the defaults are set correctly. Assume others set by user |
|
531 iEntry.iMtm = KUidMtmWapPush; |
|
532 SetPushMsgType(); |
|
533 |
|
534 TRAPD(error, msvEntry->ChangeL(iEntry) ); |
|
535 |
|
536 TFileName filePath; |
|
537 msvEntry->GetFilePath(filePath); |
|
538 User::LeaveIfError(iRFs.SetSessionPath(filePath)); |
|
539 |
|
540 if (error != KErrNone) |
|
541 { |
|
542 // Delete the temporary file and then leave |
|
543 iRFs.Delete(tempfile); |
|
544 User::Leave(error); |
|
545 } |
|
546 |
|
547 // delete the old data file, rename the temp file |
|
548 CDir* dirList = NULL; |
|
549 User::LeaveIfError(iRFs.GetDir(filePath, KEntryAttNormal, ESortByName, dirList)); |
|
550 |
|
551 if (dirList) |
|
552 { |
|
553 TFileName localFile; |
|
554 for (TInt i=0; i< dirList->Count(); i++) |
|
555 { |
|
556 localFile = (*dirList)[i].iName; |
|
557 if (localFile.CompareF(tempfile) != 0) |
|
558 { |
|
559 // Delete if it is not the tempfile |
|
560 User::LeaveIfError(iRFs.Delete(localFile));// Delete the old file |
|
561 } |
|
562 } |
|
563 } |
|
564 delete dirList; |
|
565 |
|
566 // Construct the new filename |
|
567 TFileName dataFile = ContentFileNameL(); |
|
568 User::LeaveIfError(iRFs.Rename(tempfile, dataFile)); // Rename the temp file |
|
569 #endif // __MESSAGING_API_V2__ |
|
570 |
|
571 // Done the changes to the TMsvEntry, now commit changes to the stream & store |
|
572 out.CommitL(); |
|
573 out.Close(); // make sure we close the file |
|
574 store->CommitL(); |
|
575 CleanupStack::PopAndDestroy(3); //out, store, msventry |
|
576 iHasServerEntry = ETrue; |
|
577 } |
|
578 |
|
579 |
|
580 /** |
|
581 Retrieves Unknown Push message from the message store into the object. |
|
582 |
|
583 @param aSession |
|
584 Message server session |
|
585 |
|
586 @param aMsgId |
|
587 ID of the message entry to load |
|
588 |
|
589 @see CPushMsgEntryBase::RetrieveL() |
|
590 */ |
|
591 EXPORT_C void CUnknownPushMsgEntry::RetrieveL(CMsvSession& aSession, TMsvId aMsgId) |
|
592 { |
|
593 __ASSERT_ALWAYS(aMsgId!= KMsvNullIndexEntryId, |
|
594 User::Panic(KPushPanicMoniker, EPushEntryNullMsgId)); |
|
595 |
|
596 // Switch to our entry & then get the associated message store. |
|
597 CMsvEntry* msvEntry = aSession.GetEntryL(aMsgId); |
|
598 CleanupStack::PushL(msvEntry); |
|
599 // Set our TMsvEntry member variable |
|
600 iEntry = msvEntry->Entry(); |
|
601 |
|
602 //Create store & load in base class data |
|
603 CMsvStore* store = msvEntry->ReadStoreL(); |
|
604 CleanupStack::PushL(store); |
|
605 RestoreL(*store); |
|
606 |
|
607 #ifdef __MESSAGING_API_V2__ |
|
608 DoRetrieveAttachmentL(store->AttachmentManagerL()); |
|
609 #else |
|
610 DoRetrieveAttachmentL(*msvEntry); |
|
611 #endif // __MESSAGING_API_V2__ |
|
612 |
|
613 CleanupStack::PopAndDestroy(2); //store, msvEntry |
|
614 // Obviously has a server entry |
|
615 iHasServerEntry = ETrue; |
|
616 } |
|
617 |
|
618 #ifdef __MESSAGING_API_V2__ |
|
619 void CUnknownPushMsgEntry::DoRetrieveAttachmentL(MMsvAttachmentManager& aAttachManager) |
|
620 #else |
|
621 /** |
|
622 This function performs the loading of the data from the attachment file. |
|
623 It should be noted that if there is a lot of data then the creation of a copy of the |
|
624 data will squeeze the free memory. |
|
625 |
|
626 @param aEntry |
|
627 Current message entry to load |
|
628 |
|
629 @leave KErrNotFound The attachment file cannot be located in the message store. |
|
630 @leave KErrBadName Will leave if filename is not a valid Symbian OS file name. |
|
631 @leave TDesC::AllocL() |
|
632 @leave RFile::Open() |
|
633 */ |
|
634 void CUnknownPushMsgEntry::DoRetrieveAttachmentL(const CMsvEntry& aEntry) |
|
635 #endif // __MESSAGING_API_V2__ |
|
636 { |
|
637 TFileName fileName = ContentFileNameL(); |
|
638 |
|
639 #ifdef __MESSAGING_API_V2__ |
|
640 // get the attachment file that matches the filename |
|
641 RFile file; |
|
642 for( TInt ii=0; ii<aAttachManager.AttachmentCount(); ++ii ) |
|
643 { |
|
644 CMsvAttachment* attachment = aAttachManager.GetAttachmentInfoL(ii); |
|
645 CleanupStack::PushL(attachment); |
|
646 if( attachment->AttachmentName().CompareF(fileName) == 0 ) |
|
647 { |
|
648 // found the attachment, get the file and break from the loop |
|
649 CleanupStack::PopAndDestroy(attachment); // dont need anymore |
|
650 file = aAttachManager.GetAttachmentFileL(ii); |
|
651 break; |
|
652 } |
|
653 // if we get here, the attachment was not found, destroying the attachment |
|
654 // will be handled by the leave |
|
655 User::Leave(KErrNotFound); |
|
656 } |
|
657 #else |
|
658 // get directory for file from current entry |
|
659 TFileName filePath; |
|
660 aEntry.GetFilePath(filePath); |
|
661 |
|
662 // create the full file name with path |
|
663 TParse parse; |
|
664 parse.Set(fileName, &filePath, NULL); |
|
665 |
|
666 // create the file |
|
667 RFile file; |
|
668 User::LeaveIfError(file.Open(iRFs, parse.FullName(), EFileShareExclusive|EFileStream)); |
|
669 #endif // __MESSAGING_API_V2__ |
|
670 |
|
671 CleanupClosePushL(file); |
|
672 |
|
673 // find the size of the file |
|
674 TInt fileSize = 0; |
|
675 User::LeaveIfError(file.Size(fileSize)); |
|
676 |
|
677 // read into descriptor resizing as we go |
|
678 HBufC8* data = HBufC8::NewL(fileSize); |
|
679 TBuf8<KMaxFileName> fileChunk; |
|
680 TInt fileError = KErrNone; |
|
681 |
|
682 while(fileError ==KErrNone) |
|
683 { |
|
684 fileError = file.Read(fileChunk, fileChunk.MaxLength()); |
|
685 if(fileChunk.Length()==0) |
|
686 break; |
|
687 data->Des().Append(fileChunk); |
|
688 } |
|
689 |
|
690 // if it worked assign data to our message buffer |
|
691 delete iMessageData; |
|
692 iMessageData = data; |
|
693 |
|
694 // Close the file and the file server session |
|
695 CleanupStack::PopAndDestroy();//file |
|
696 if(fileError!=KErrNone) |
|
697 User::Leave(fileError); |
|
698 } |
|
699 |
|
700 |
|
701 /** |
|
702 Gets the Content type extension based on the content type supplied |
|
703 |
|
704 @param aContentType |
|
705 The content type |
|
706 */ |
|
707 const TDesC& CUnknownPushMsgEntry::ContentTypeExtension(const TDesC& aContentType) |
|
708 { |
|
709 if (aContentType.CompareF(KTextBasic)==0 || aContentType.Compare(KTextPlain)==0) |
|
710 return KUnknownTextExt; |
|
711 else if (aContentType.CompareF(KUnknownRTextExt)==0 ) |
|
712 return KUnknownRTextExt; |
|
713 else if (aContentType.CompareF(KTextXML) ==0 || aContentType.CompareF(KAppXML)==0) |
|
714 return KUnknownXmlExt; |
|
715 else if (aContentType.CompareF(KTextHTML) ==0) |
|
716 return KUnknownHtmlExt; |
|
717 else if (aContentType.CompareF(KTextWML)==0) |
|
718 return KUnknownWmlExt; |
|
719 else if (aContentType.CompareF(KImageGIF)==0) |
|
720 return KUnknownGifExt; |
|
721 else if (aContentType.CompareF(KImageJPEG)==0) |
|
722 return KUnknownJpegExt; |
|
723 else if (aContentType.CompareF(KImageTIFF)==0) |
|
724 return KUnknownTiffExt; |
|
725 else if (aContentType.CompareF(KImageWBMP) ==0) |
|
726 return KUnknownWbmpExt; |
|
727 else if (aContentType.CompareF(KAppSIS)==0) |
|
728 return KUnknownSISExt; |
|
729 else if (aContentType.CompareF(KAppWMLC)==0 || aContentType.CompareF(KAppWBXML)==0) |
|
730 return KUnknownWmlcExt; |
|
731 else if (aContentType.CompareF(KTextMSWord)==0 || |
|
732 aContentType.CompareF(KTextMSWord95)==0 || |
|
733 aContentType.CompareF(KTextMSWord97)==0 || |
|
734 aContentType.CompareF(KTextMSWord00)==0 || |
|
735 aContentType.CompareF(KTextMSWord2000)==0 ) |
|
736 return KUnknownDocExt; |
|
737 else |
|
738 return KStdUnknownExt; |
|
739 } |
|
740 |
|
741 |
|
742 /** |
|
743 Gets the value of the Uid for the Push Message type of the Push Entry. |
|
744 |
|
745 @return TInt32 |
|
746 Uid as a long integer. |
|
747 */ |
|
748 TInt32 CUnknownPushMsgEntry::PushMsgType() const |
|
749 { |
|
750 return KUidWapPushMsgUnknown.iUid; |
|
751 } |
|
752 |
|
753 |
|
754 /** |
|
755 Sets the Uid of the Push Message Entry to the value for an Unknown Push message. |
|
756 */ |
|
757 void CUnknownPushMsgEntry::SetPushMsgType() |
|
758 { |
|
759 iEntry.iBioType = KUidWapPushMsgUnknown.iUid; |
|
760 } |
|
761 |
|
762 |
|
763 /** |
|
764 Externalises Push message data to a write stream. |
|
765 |
|
766 Apart from the data stored by the base class, other data stored are Content Type, |
|
767 Time Sent and Content Filename. |
|
768 |
|
769 @param aStream |
|
770 The stream to which the data should be externalised. |
|
771 |
|
772 @see CPushMsgEntryBase::ExternalizeL() |
|
773 */ |
|
774 EXPORT_C void CUnknownPushMsgEntry::ExternalizeL(RMsvWriteStream& aStream) |
|
775 { |
|
776 CPushMsgEntryBase::ExternalizeL(aStream); |
|
777 |
|
778 aStream<<LimitStringSize(ContentType(), KLongestStringAllowed); |
|
779 aStream << iTimeSent.Int64(); |
|
780 |
|
781 aStream<<LimitStringSize(ContentFileNameL(), KLongestStringAllowed); |
|
782 } |
|
783 |
|
784 |
|
785 /** |
|
786 Internalises Push message data from a read stream. |
|
787 |
|
788 Apart from the data read by the base class, other data read are Content Type, Time Sent |
|
789 and Content Filename. |
|
790 |
|
791 @param aStream |
|
792 The stream from which the data should be internalised. |
|
793 |
|
794 @leave KErrOverflow |
|
795 If the length of the data read from the stream is greater than KLongestStringAllowed. |
|
796 |
|
797 @leave KErrNotSupported |
|
798 An older version of the stream was read that does support Content Filename. |
|
799 |
|
800 @leave HBufC::NewL |
|
801 |
|
802 @see CPushMsgEntryBase::InternalizeL() |
|
803 */ |
|
804 EXPORT_C void CUnknownPushMsgEntry::InternalizeL(RMsvReadStream& aStream) |
|
805 { |
|
806 CPushMsgEntryBase::InternalizeL(aStream); |
|
807 |
|
808 delete iContentType; |
|
809 iContentType = NULL; |
|
810 iContentType = HBufC::NewL(aStream, KLongestStringAllowed); |
|
811 |
|
812 TInt64 timeSent; |
|
813 aStream >> timeSent; |
|
814 iTimeSent = timeSent; |
|
815 |
|
816 delete iFilename; |
|
817 iFilename = NULL; |
|
818 TRAPD(error, iFilename = HBufC::NewL(aStream, KLongestStringAllowed)); |
|
819 if (error != KErrNone && error != KErrEof) |
|
820 { |
|
821 User::Leave(error); |
|
822 } |
|
823 else if(error == KErrEof) |
|
824 { |
|
825 User::Leave(KErrNotSupported); |
|
826 } |
|
827 } |
|
828 |
|
829 |
|
830 #ifndef EKA2 |
|
831 GLDEF_C TInt E32Dll(TDllReason/* aReason*/) |
|
832 { |
|
833 return (KErrNone); |
|
834 } |
|
835 #endif |