|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: CS Preview Plugin Handler, This class creates and updates sqlite based db |
|
15 * with the message-preview data. |
|
16 * |
|
17 */ |
|
18 // USER INCLUDES |
|
19 #include "ccspreviewpluginhandler.h" |
|
20 #include "UniObject.h" |
|
21 // SYSTEM INCLUDES |
|
22 #include <mmsclient.h> |
|
23 #include <mtclreg.h> |
|
24 #include <msvids.h> |
|
25 #include <e32const.h> |
|
26 #include <SendUiConsts.h> |
|
27 #include <utf.h> |
|
28 //CONSTANTS |
|
29 //DB-file |
|
30 _LIT(KDbFileName, "c:[2002A542]conversations.db"); |
|
31 //Encoding |
|
32 _LIT(KEncodingStmnt,"PRAGMA encoding=\"UTF-8\""); |
|
33 //Size |
|
34 _LIT(KCacheSizeStmnt,"PRAGMA default_cache_size = 1024"); |
|
35 // Create table query statement |
|
36 _LIT(KSqlCreateStmt, "CREATE TABLE IF NOT EXISTS conversation_messages ( message_id INTEGER PRIMARY KEY, msg_parsed INTEGER DEFAULT 0, subject TEXT(100), body_text TEXT(160), preview_path TEXT, msg_property INTEGER, preview_icon BLOB DEFAULT NULL ) " ); |
|
37 //Insert without bitmap query |
|
38 _LIT(KSqlInsertStmt, "INSERT OR REPLACE INTO conversation_messages (message_id, msg_parsed, subject, body_text, preview_path, msg_property ) VALUES( :message_id, :msg_parsed, :subject, :body_text, :preview_path, :msg_property )"); |
|
39 //update with bitmap query |
|
40 _LIT(KSqlUpdateBitmapStmt, "UPDATE conversation_messages SET preview_icon=:preview_icon WHERE message_id=:message_id " ); |
|
41 // query to see if msg_parsed is set |
|
42 _LIT(KSelectMsgParsedStmt, " SELECT message_id, msg_parsed FROM conversation_messages WHERE message_id=:message_id "); |
|
43 // Remove record from conversation_messages table. |
|
44 _LIT(KRemoveMsgStmnt,"DELETE FROM conversation_messages WHERE message_id=:message_id"); |
|
45 |
|
46 // NOTE:- DRAFTS ENTRIES ARE NOT HANDLED IN THE PLUGIN |
|
47 |
|
48 // ============================== MEMBER FUNCTIONS ============================ |
|
49 // ---------------------------------------------------------------------------- |
|
50 // CCsPreviewPluginHandler::NewL |
|
51 // Two Phase Construction |
|
52 // ---------------------------------------------------------------------------- |
|
53 // |
|
54 CCsPreviewPluginHandler* CCsPreviewPluginHandler::NewL( |
|
55 CCsPreviewPlugin *aMsgObserver) |
|
56 { |
|
57 PRINT ( _L("Enter CCsMsgHandler::NewL") ); |
|
58 |
|
59 CCsPreviewPluginHandler* self = new (ELeave) CCsPreviewPluginHandler(); |
|
60 CleanupStack::PushL(self); |
|
61 self->ConstructL(aMsgObserver); |
|
62 CleanupStack::Pop(self); |
|
63 |
|
64 PRINT ( _L("End CCsPreviewPluginHandler::NewL") ); |
|
65 |
|
66 return self; |
|
67 } |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // CCsPreviewPluginHandler::~CCsPreviewPluginHandler |
|
71 // Destructor |
|
72 // ---------------------------------------------------------------------------- |
|
73 // |
|
74 CCsPreviewPluginHandler::~CCsPreviewPluginHandler() |
|
75 { |
|
76 PRINT ( _L("Enter CCsPreviewPluginHandler::~CCsPreviewPluginHandler") ); |
|
77 |
|
78 iSqlDb.Close(); |
|
79 iThumbnailRequestArray.Close(); |
|
80 ifsSession.Close(); |
|
81 |
|
82 if (iMmsMtm) |
|
83 { |
|
84 delete iMmsMtm; |
|
85 iMmsMtm = NULL; |
|
86 } |
|
87 |
|
88 if (iMtmRegistry) |
|
89 { |
|
90 delete iMtmRegistry; |
|
91 iMtmRegistry = NULL; |
|
92 } |
|
93 |
|
94 if (iSession) |
|
95 { |
|
96 delete iSession; |
|
97 iSession = NULL; |
|
98 } |
|
99 |
|
100 if (iThumbnailManager) |
|
101 { |
|
102 delete iThumbnailManager; |
|
103 iThumbnailManager = NULL; |
|
104 } |
|
105 |
|
106 PRINT ( _L("End CCsPreviewPluginHandler::~CCsPreviewPluginHandler") ); |
|
107 } |
|
108 |
|
109 // ---------------------------------------------------------------------------- |
|
110 // CCsMsgHandler::ConstructL |
|
111 // Two Phase Construction |
|
112 // ---------------------------------------------------------------------------- |
|
113 // |
|
114 void CCsPreviewPluginHandler::ConstructL(CCsPreviewPlugin *aMsgObserver) |
|
115 { |
|
116 PRINT ( _L("Enter CCsPreviewPluginHandler::ConstructL") ); |
|
117 |
|
118 iMsgObserver = aMsgObserver; |
|
119 |
|
120 //file session connect |
|
121 User::LeaveIfError(ifsSession.Connect()); |
|
122 |
|
123 //create msv session |
|
124 iSession = CMsvSession::OpenSyncL(*this); |
|
125 |
|
126 //create mtm registry |
|
127 iMtmRegistry = CClientMtmRegistry::NewL(*iSession); |
|
128 |
|
129 //create mms client mtm |
|
130 iMmsMtm = static_cast<CMmsClientMtm*> (iMtmRegistry-> NewMtmL( |
|
131 KSenduiMtmMmsUid)); |
|
132 |
|
133 //create thumbnail manager |
|
134 iThumbnailManager = CThumbnailManager::NewL(*this); |
|
135 |
|
136 // open DB |
|
137 TInt error = iSqlDb.Open(KDbFileName); |
|
138 |
|
139 PRINT1 ( _L("End CCsPreviewPluginHandler::ConstructL open DB file error=%d"), error ); |
|
140 |
|
141 // if not found, create DB |
|
142 if (error == KErrNotFound) |
|
143 { |
|
144 //create sqlite-DB |
|
145 TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass); |
|
146 RSqlSecurityPolicy securityPolicy; |
|
147 securityPolicy.Create(defaultPolicy); |
|
148 |
|
149 // TODO, setting UID security policy |
|
150 //TSecurityPolicy readPolicy(ECapabilityReadUserData); |
|
151 //securityPolicy.SetDbPolicy(RSqlSecurityPolicy::EReadPolicy, readPolicy); |
|
152 |
|
153 iSqlDb.Create(KDbFileName, securityPolicy); |
|
154 |
|
155 //Create the table inside DB |
|
156 iSqlDb.Exec(KSqlCreateStmt); |
|
157 iSqlDb.Exec(KEncodingStmnt); |
|
158 iSqlDb.Exec(KCacheSizeStmnt); |
|
159 } |
|
160 else |
|
161 { |
|
162 User::LeaveIfError(error); |
|
163 } |
|
164 |
|
165 PRINT ( _L("End CCsPreviewPluginHandler::ConstructL") ); |
|
166 } |
|
167 |
|
168 // ---------------------------------------------------------------------------- |
|
169 // CCsPreviewPluginHandler::CCsPreviewPluginHandler |
|
170 // Two Phase Construction |
|
171 // ---------------------------------------------------------------------------- |
|
172 // |
|
173 CCsPreviewPluginHandler::CCsPreviewPluginHandler() |
|
174 { |
|
175 } |
|
176 |
|
177 // ---------------------------------------------------------------------------- |
|
178 // CCsPreviewPluginHandler::HandleSessionEventL |
|
179 // Implemented for MMsvSessionObserver |
|
180 // ---------------------------------------------------------------------------- |
|
181 // |
|
182 void CCsPreviewPluginHandler::HandleSessionEventL(TMsvSessionEvent aEvent, |
|
183 TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/) |
|
184 { |
|
185 PRINT1 ( _L("Enter CCsPreviewPluginHandler::HandleSessionEventL aEvent=%d"),aEvent ); |
|
186 |
|
187 CMsvEntrySelection* selection = NULL; |
|
188 TMsvId parent; |
|
189 |
|
190 //args |
|
191 if (aArg1 == NULL || aArg2 == NULL) |
|
192 { |
|
193 PRINT ( _L("Enter CCsPreviewPluginHandler::HandleSessionEventL arguments invalid")); |
|
194 return; |
|
195 } |
|
196 |
|
197 //start, processing the event |
|
198 selection = (CMsvEntrySelection*) aArg1; |
|
199 parent = *(TMsvId*) aArg2; |
|
200 |
|
201 //Drafts not handled |
|
202 if (KMsvDraftEntryIdValue == parent) |
|
203 { |
|
204 return; |
|
205 } |
|
206 |
|
207 switch (aEvent) |
|
208 { |
|
209 case EMsvEntriesChanged: |
|
210 case EMsvEntriesMoved: |
|
211 { |
|
212 HandleEventL(selection); |
|
213 } |
|
214 break; |
|
215 |
|
216 case EMsvEntriesDeleted: |
|
217 { |
|
218 for (TInt i = 0; i < selection->Count(); i++) |
|
219 { |
|
220 RSqlStatement sqlDeleteStmt; |
|
221 CleanupClosePushL(sqlDeleteStmt); |
|
222 sqlDeleteStmt.PrepareL(iSqlDb, KRemoveMsgStmnt); |
|
223 |
|
224 TInt messageIdIndex = sqlDeleteStmt.ParameterIndex(_L( |
|
225 ":message_id")); |
|
226 User::LeaveIfError(sqlDeleteStmt.BindInt(messageIdIndex, selection->At(i))); |
|
227 |
|
228 User::LeaveIfError(sqlDeleteStmt.Exec()); |
|
229 CleanupStack::PopAndDestroy(&sqlDeleteStmt); |
|
230 } |
|
231 } |
|
232 break; |
|
233 } |
|
234 |
|
235 PRINT ( _L("Exit CCsPreviewPluginHandler::HandleSessionEventL") ); |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------------------- |
|
239 // CCsPreviewPluginHandler::HandleEvent |
|
240 // Handle events |
|
241 // --------------------------------------------------------------------- |
|
242 // |
|
243 void CCsPreviewPluginHandler::HandleEventL(CMsvEntrySelection* aSelection) |
|
244 { |
|
245 PRINT ( _L("Enter CCsPreviewPluginHandler::HandleEvent") ); |
|
246 |
|
247 TMsvEntry entry; |
|
248 TMsvId service; |
|
249 TInt error = KErrNone; |
|
250 |
|
251 for (TInt i = 0; i < aSelection->Count(); i++) |
|
252 { |
|
253 error = iSession->GetEntry(aSelection->At(i), service, entry); |
|
254 |
|
255 if ( (KErrNone == error) && !entry.InPreparation() && entry.Visible() |
|
256 && (KSenduiMtmMmsUidValue == entry.iMtm.iUid)) |
|
257 { |
|
258 PRINT ( _L("Enter CCsPreviewPluginHandler::HandleEvent for loop started.") ); |
|
259 |
|
260 TInt msgId = entry.Id(); |
|
261 |
|
262 //check if the message is already parsed |
|
263 RSqlStatement sqlSelectStmt; |
|
264 CleanupClosePushL(sqlSelectStmt); |
|
265 sqlSelectStmt.PrepareL(iSqlDb,KSelectMsgParsedStmt); |
|
266 TInt messageIdIndex = sqlSelectStmt.ParameterIndex( |
|
267 _L(":message_id")); |
|
268 |
|
269 User::LeaveIfError(sqlSelectStmt.BindInt(messageIdIndex, msgId)); |
|
270 |
|
271 if (sqlSelectStmt.Next() == KSqlAtRow) |
|
272 { |
|
273 TInt parsedColIndex = sqlSelectStmt.ColumnIndex( |
|
274 _L("msg_parsed")); |
|
275 TInt msgParsed = sqlSelectStmt.ColumnInt(parsedColIndex); |
|
276 //if message alresdy parsed, move to next message. |
|
277 if (msgParsed) |
|
278 { |
|
279 CleanupStack::PopAndDestroy(&sqlSelectStmt); |
|
280 continue; |
|
281 } |
|
282 } |
|
283 CleanupStack::PopAndDestroy(&sqlSelectStmt); |
|
284 |
|
285 // update db with message preview data |
|
286 RSqlStatement sqlInsertStmt; |
|
287 CleanupClosePushL(sqlInsertStmt); |
|
288 sqlInsertStmt.PrepareL(iSqlDb, KSqlInsertStmt); |
|
289 |
|
290 // parse message |
|
291 iMmsMtm->SwitchCurrentEntryL(msgId); |
|
292 iMmsMtm->LoadMessageL(); |
|
293 |
|
294 CUniDataModel* iUniDataModel = CUniDataModel::NewL(ifsSession, |
|
295 *iMmsMtm); |
|
296 CleanupStack::PushL(iUniDataModel); |
|
297 iUniDataModel->RestoreL(*this, ETrue); |
|
298 |
|
299 //msg property |
|
300 TInt msgProperty = 0; |
|
301 if (iUniDataModel->AttachmentList().Count() > 0) |
|
302 { |
|
303 msgProperty |= EPreviewAttachment; |
|
304 } |
|
305 |
|
306 TPtrC videoPath; |
|
307 TPtrC imagePath; |
|
308 |
|
309 // preview parsing |
|
310 TInt slideCount = iUniDataModel->SmilModel().SlideCount(); |
|
311 TBool isBodyTextSet = EFalse; |
|
312 TBool isImageSet = EFalse; |
|
313 TBool isAudioSet = EFalse; |
|
314 TBool isVideoSet = EFalse; |
|
315 |
|
316 for (int i = 0; i < slideCount; i++) |
|
317 { |
|
318 int slideobjcount = |
|
319 iUniDataModel->SmilModel().SlideObjectCount(i); |
|
320 for (int j = 0; j < slideobjcount; j++) |
|
321 { |
|
322 CUniObject *obj = |
|
323 iUniDataModel->SmilModel(). GetObjectByIndex(i, j); |
|
324 |
|
325 TPtrC8 mimetype = obj->MimeType(); |
|
326 TMsvAttachmentId attachId = obj->AttachmentId(); |
|
327 |
|
328 //bodytext |
|
329 if (!isBodyTextSet && (mimetype.Find(_L8("text")) |
|
330 != KErrNotFound)) |
|
331 { |
|
332 //bind bodytext into statement |
|
333 BindBodyText(sqlInsertStmt, attachId); |
|
334 isBodyTextSet = ETrue; |
|
335 } |
|
336 |
|
337 //image parsing |
|
338 if (!isImageSet && (mimetype.Find(_L8("image")) |
|
339 != KErrNotFound)) |
|
340 { |
|
341 //get thumbnail for this image |
|
342 GetThumbNailL(attachId, mimetype, msgId); |
|
343 isImageSet = ETrue; |
|
344 imagePath.Set(obj->MediaInfo()->FullFilePath()); |
|
345 msgProperty |= EPreviewImage; |
|
346 } |
|
347 |
|
348 //audio content |
|
349 if (!isAudioSet && (mimetype.Find(_L8("audio")) |
|
350 != KErrNotFound)) |
|
351 { |
|
352 isAudioSet = ETrue; |
|
353 msgProperty |= EPreviewAudio; |
|
354 } |
|
355 |
|
356 //video content |
|
357 if (!isVideoSet && (mimetype.Find(_L8("video")) |
|
358 != KErrNotFound)) |
|
359 { |
|
360 videoPath.Set(obj->MediaInfo()->FullFilePath()); |
|
361 isVideoSet = ETrue; |
|
362 msgProperty |= EPreviewVideo; |
|
363 } |
|
364 } |
|
365 } |
|
366 |
|
367 //set preview path |
|
368 TInt previewPathIndex = sqlInsertStmt.ParameterIndex(_L( |
|
369 ":preview_path")); |
|
370 if (isVideoSet) |
|
371 { |
|
372 User::LeaveIfError(sqlInsertStmt.BindText(previewPathIndex, |
|
373 videoPath)); |
|
374 } |
|
375 else if (isImageSet) |
|
376 { |
|
377 User::LeaveIfError(sqlInsertStmt.BindText(previewPathIndex, |
|
378 imagePath)); |
|
379 } |
|
380 |
|
381 //msg_id |
|
382 TInt msgIdIndex = sqlInsertStmt.ParameterIndex(_L(":message_id")); |
|
383 User::LeaveIfError(sqlInsertStmt.BindInt(msgIdIndex, msgId)); |
|
384 |
|
385 //subjext |
|
386 TInt subjectIndex = sqlInsertStmt.ParameterIndex(_L(":subject")); |
|
387 User::LeaveIfError(sqlInsertStmt.BindText(subjectIndex, |
|
388 iMmsMtm->SubjectL())); |
|
389 |
|
390 //msg_property |
|
391 TInt msgPropertyIndex = sqlInsertStmt.ParameterIndex(_L( |
|
392 ":msg_property")); |
|
393 User::LeaveIfError(sqlInsertStmt.BindInt(msgPropertyIndex, |
|
394 msgProperty)); |
|
395 |
|
396 //msg-parsed |
|
397 TInt msgParsedIndex = sqlInsertStmt.ParameterIndex( |
|
398 _L(":msg_parsed")); |
|
399 User::LeaveIfError(sqlInsertStmt.BindInt(msgParsedIndex, 1)); // 1 as true |
|
400 |
|
401 //execute sql stament |
|
402 User::LeaveIfError(sqlInsertStmt.Exec()); |
|
403 |
|
404 //cleanup |
|
405 CleanupStack::PopAndDestroy(2, &sqlInsertStmt); |
|
406 } |
|
407 }//end for loop |
|
408 |
|
409 PRINT ( _L("Exit CCsPreviewPluginHandler::HandleEvent") ); |
|
410 } |
|
411 |
|
412 // ----------------------------------------------------------------------------- |
|
413 // CCsPreviewPluginHandler::RestoreReady() |
|
414 // |
|
415 // ----------------------------------------------------------------------------- |
|
416 // |
|
417 void CCsPreviewPluginHandler::RestoreReady(TInt /*aParseResult*/, TInt /*aError*/) |
|
418 { |
|
419 |
|
420 } |
|
421 |
|
422 // ----------------------------------------------------------------------------- |
|
423 // CCsPreviewPluginHandler::ThumbnailReady() |
|
424 // |
|
425 // ----------------------------------------------------------------------------- |
|
426 // |
|
427 void CCsPreviewPluginHandler::ThumbnailReady(TInt aError, |
|
428 MThumbnailData& aThumbnail, TThumbnailRequestId aId) |
|
429 { |
|
430 // This function must not leave. |
|
431 if (!aError) |
|
432 { |
|
433 PRINT ( _L("CCsPreviewPluginHandler::ThumbnailReady received.") ); |
|
434 TInt err; |
|
435 TRAP(err, HandleThumbnailReadyL(aThumbnail, aId)); |
|
436 PRINT1 ( _L("CCsPreviewPluginHandler::ThumbnailReady handling error= %d."), err ); |
|
437 } |
|
438 else |
|
439 { |
|
440 // An error occurred while getting the thumbnail. |
|
441 PRINT1 ( _L("End CCsPreviewPluginHandler::ThumbnailReady error= %d."), aError ); |
|
442 } |
|
443 } |
|
444 |
|
445 // ----------------------------------------------------------------------------- |
|
446 // CCsPreviewPluginHandler::ThumbnailPreviewReady() |
|
447 // callback |
|
448 // ----------------------------------------------------------------------------- |
|
449 // |
|
450 void CCsPreviewPluginHandler::ThumbnailPreviewReady( |
|
451 MThumbnailData& /*aThumbnail*/, TThumbnailRequestId /*aId*/) |
|
452 { |
|
453 |
|
454 } |
|
455 |
|
456 // ----------------------------------------------------------------------------- |
|
457 // CCsPreviewPluginHandler::HandleThumbnailReadyL() |
|
458 // |
|
459 // ----------------------------------------------------------------------------- |
|
460 // |
|
461 void CCsPreviewPluginHandler::HandleThumbnailReadyL(MThumbnailData& aThumbnail, |
|
462 TThumbnailRequestId aId) |
|
463 { |
|
464 //match response to request |
|
465 ThumbnailRequestData tempObj; |
|
466 tempObj.iRequestId = aId; |
|
467 |
|
468 TInt index = iThumbnailRequestArray.Find(tempObj, |
|
469 CCsPreviewPluginHandler::CompareByRequestId); |
|
470 if (index < 0) |
|
471 { |
|
472 PRINT ( _L("End CCsPreviewPluginHandler::HandleThumbnailReady request match not found.") ); |
|
473 return; |
|
474 } |
|
475 |
|
476 // get msg-id corresponding to the request-id |
|
477 TInt msgId = iThumbnailRequestArray[index].iMsgId; |
|
478 //remove the request from requestarray |
|
479 iThumbnailRequestArray.Remove(index); |
|
480 |
|
481 // get bitmap |
|
482 CFbsBitmap* bitmap = aThumbnail.Bitmap(); |
|
483 |
|
484 // sql-statment to set preview-icon |
|
485 RSqlStatement sqlInsertStmt; |
|
486 CleanupClosePushL(sqlInsertStmt); |
|
487 sqlInsertStmt.PrepareL(iSqlDb, KSqlUpdateBitmapStmt); |
|
488 |
|
489 TInt msgIdIndex = sqlInsertStmt.ParameterIndex(_L(":message_id")); |
|
490 TInt previewIconIndex = sqlInsertStmt.ParameterIndex(_L(":preview_icon")); |
|
491 |
|
492 User::LeaveIfError(sqlInsertStmt.BindInt(msgIdIndex, msgId)); |
|
493 |
|
494 RSqlParamWriteStream previewIconStream; |
|
495 CleanupClosePushL(previewIconStream); |
|
496 |
|
497 //bind data |
|
498 User::LeaveIfError(previewIconStream.BindBinary(sqlInsertStmt, previewIconIndex)); |
|
499 bitmap->ExternalizeL(previewIconStream); |
|
500 previewIconStream.CommitL(); |
|
501 |
|
502 //execute the statent |
|
503 User::LeaveIfError(sqlInsertStmt.Exec()); |
|
504 |
|
505 CleanupStack::PopAndDestroy(2,&sqlInsertStmt);//sqlInsertStmt,previewIconStream |
|
506 } |
|
507 |
|
508 //----------------------------------------------------------------------------- |
|
509 // CCsPreviewPluginHandler::CompareByRequestId |
|
510 // Compare to conversation entry object based on Entry Ids |
|
511 //---------------------------------------------------------------------------- |
|
512 TBool CCsPreviewPluginHandler::CompareByRequestId( |
|
513 const ThumbnailRequestData& aFirst, const ThumbnailRequestData& aSecond) |
|
514 { |
|
515 if (aFirst.iRequestId == aSecond.iRequestId) |
|
516 return ETrue; |
|
517 |
|
518 return EFalse; |
|
519 } |
|
520 |
|
521 // ----------------------------------------------------------------------------- |
|
522 // CCsPreviewPluginHandler::BindBodyText() |
|
523 // |
|
524 // ----------------------------------------------------------------------------- |
|
525 // |
|
526 void CCsPreviewPluginHandler::BindBodyText(RSqlStatement& sqlStmt, |
|
527 TMsvAttachmentId attachmentId) |
|
528 { |
|
529 //get file handle from attachmnet manager. |
|
530 CMsvStore * store = iMmsMtm->Entry().ReadStoreL(); |
|
531 CleanupStack::PushL(store); |
|
532 MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
533 RFile file = attachMan.GetAttachmentFileL(attachmentId); |
|
534 CleanupClosePushL(file); |
|
535 |
|
536 //read file contents to buffer |
|
537 TInt length; |
|
538 file.Size(length); |
|
539 HBufC8* bodyText = HBufC8::NewLC(length); |
|
540 TPtr8 textBuffer = bodyText->Des(); |
|
541 file.Read(textBuffer); |
|
542 |
|
543 // convert from HBufC8 to HBufC16 |
|
544 HBufC16 *text16 = HBufC16::NewLC(textBuffer.Length()); |
|
545 TPtr16 textPtr16 = text16->Des(); |
|
546 CnvUtfConverter::ConvertToUnicodeFromUtf8(textPtr16, textBuffer); |
|
547 |
|
548 //set bodytext in the sql statement |
|
549 TInt bodyTextIndex = sqlStmt.ParameterIndex(_L(":body_text")); |
|
550 sqlStmt.BindText(bodyTextIndex, textPtr16); |
|
551 |
|
552 CleanupStack::PopAndDestroy(4, store); //store,file, bodyText, text16 |
|
553 } |
|
554 |
|
555 // ----------------------------------------------------------------------------- |
|
556 // CCsPreviewPluginHandler::GetThumbNailL() |
|
557 // |
|
558 // ----------------------------------------------------------------------------- |
|
559 // |
|
560 void CCsPreviewPluginHandler::GetThumbNailL(TMsvAttachmentId attachmentId, |
|
561 TDesC8& mimeType, TMsvId msgId) |
|
562 { |
|
563 //Scale the image |
|
564 iThumbnailManager->SetFlagsL(CThumbnailManager::ECropToAspectRatio); |
|
565 // Preferred size is 100x100 (or less) |
|
566 iThumbnailManager->SetThumbnailSizeL(TSize(100, 100)); |
|
567 //optimize for performace |
|
568 iThumbnailManager->SetQualityPreferenceL( |
|
569 CThumbnailManager::EOptimizeForPerformance); |
|
570 |
|
571 // Create Thumbnail object source representing a path to a file |
|
572 HBufC* mimeInfo = HBufC::NewLC(mimeType.Length()); |
|
573 mimeInfo->Des().Copy(mimeType); |
|
574 |
|
575 CMsvStore * store = iMmsMtm->Entry().ReadStoreL(); |
|
576 CleanupStack::PushL(store); |
|
577 |
|
578 //get file handle from attachment manager. |
|
579 MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
580 RFile file = attachMan.GetAttachmentFileL(attachmentId); |
|
581 CleanupClosePushL(file); |
|
582 |
|
583 CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC( |
|
584 (RFile64&) file, mimeInfo->Des()); |
|
585 |
|
586 // Issue the request for thumbnail creation |
|
587 ThumbnailRequestData reqObject; |
|
588 reqObject.iMsgId = msgId; |
|
589 reqObject.iRequestId = iThumbnailManager->GetThumbnailL(*source); |
|
590 iThumbnailRequestArray.Append(reqObject); |
|
591 |
|
592 CleanupStack::PopAndDestroy(4, mimeInfo);//mimeInfo,store,file,source |
|
593 } |
|
594 |
|
595 // End of file |
|
596 |