|
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 #include <centralrepository.h> |
|
29 #include <MmsConformance.h> |
|
30 #include <mmsconst.h> |
|
31 #include <msgmediainfo.h> |
|
32 #include <MsgMediaResolver.h> |
|
33 #include <fileprotectionresolver.h> |
|
34 #include <MmsEngineInternalCRKeys.h> |
|
35 //CONSTANTS |
|
36 //DB-file |
|
37 _LIT(KDbFileName, "c:[2002A542]conversations.db"); |
|
38 //Encoding |
|
39 _LIT(KEncodingStmnt,"PRAGMA encoding=\"UTF-8\""); |
|
40 //Size |
|
41 _LIT(KCacheSizeStmnt,"PRAGMA default_cache_size = 1024"); |
|
42 // Create table query statement |
|
43 _LIT(KSqlCreateStmt, "CREATE TABLE IF NOT EXISTS conversation_messages ( message_id INTEGER PRIMARY KEY, msg_processingstate INTEGER DEFAULT 0, subject TEXT(100), body_text TEXT(160), preview_path TEXT, msg_property INTEGER, preview_icon BLOB DEFAULT NULL ) " ); |
|
44 //Create an empty record for the given message id |
|
45 _LIT(KSqlBasicInsertStmt, "INSERT OR REPLACE INTO conversation_messages ( message_id ) VALUES( :message_id )"); |
|
46 //Insert without bitmap query |
|
47 _LIT(KSqlInsertStmt, "INSERT OR REPLACE INTO conversation_messages ( message_id, msg_processingstate, subject, body_text, preview_path, msg_property ) VALUES( :message_id, :msg_processingstate, :subject, :body_text, :preview_path, :msg_property )"); |
|
48 //update processing-state flag of a message |
|
49 _LIT(KSqlUpdateProcessingStateStmt, "UPDATE conversation_messages SET msg_processingstate=:msg_processingstate WHERE message_id=:message_id " ); |
|
50 //update with bitmap query |
|
51 _LIT(KSqlUpdateBitmapStmt, "UPDATE conversation_messages SET preview_icon=:preview_icon WHERE message_id=:message_id " ); |
|
52 // query to see if msg is under process at the moment |
|
53 _LIT(KSelectProcessingStateStmt, " SELECT message_id, msg_processingstate FROM conversation_messages WHERE message_id=:message_id "); |
|
54 // Remove record from conversation_messages table. |
|
55 _LIT(KRemoveMsgStmnt,"DELETE FROM conversation_messages WHERE message_id=:message_id"); |
|
56 |
|
57 const TInt KDefaultMaxSize = 300 * 1024; |
|
58 //Preview thumbnail size |
|
59 const TInt KWidth = 9.5 * 6.7; |
|
60 const TInt KHeight = 9.5 * 6.7; |
|
61 |
|
62 // NOTE:- DRAFTS ENTRIES ARE NOT HANDLED IN THE PLUGIN |
|
63 |
|
64 // ============================== MEMBER FUNCTIONS ============================ |
|
65 // ---------------------------------------------------------------------------- |
|
66 // CCsPreviewPluginHandler::NewL |
|
67 // Two Phase Construction |
|
68 // ---------------------------------------------------------------------------- |
|
69 // |
|
70 CCsPreviewPluginHandler* CCsPreviewPluginHandler::NewL( |
|
71 CCsPreviewPlugin *aMsgObserver) |
|
72 { |
|
73 PRINT ( _L("Enter CCsMsgHandler::NewL") ); |
|
74 |
|
75 CCsPreviewPluginHandler* self = new (ELeave) CCsPreviewPluginHandler(); |
|
76 CleanupStack::PushL(self); |
|
77 self->ConstructL(aMsgObserver); |
|
78 CleanupStack::Pop(self); |
|
79 |
|
80 PRINT ( _L("End CCsPreviewPluginHandler::NewL") ); |
|
81 |
|
82 return self; |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // CCsPreviewPluginHandler::~CCsPreviewPluginHandler |
|
87 // Destructor |
|
88 // ---------------------------------------------------------------------------- |
|
89 // |
|
90 CCsPreviewPluginHandler::~CCsPreviewPluginHandler() |
|
91 { |
|
92 PRINT ( _L("Enter CCsPreviewPluginHandler::~CCsPreviewPluginHandler") ); |
|
93 |
|
94 iSqlDb.Close(); |
|
95 iThumbnailRequestArray.Close(); |
|
96 ifsSession.Close(); |
|
97 |
|
98 if (iMmsMtm) |
|
99 { |
|
100 delete iMmsMtm; |
|
101 iMmsMtm = NULL; |
|
102 } |
|
103 |
|
104 if (iMtmRegistry) |
|
105 { |
|
106 delete iMtmRegistry; |
|
107 iMtmRegistry = NULL; |
|
108 } |
|
109 |
|
110 if (iSession) |
|
111 { |
|
112 delete iSession; |
|
113 iSession = NULL; |
|
114 } |
|
115 |
|
116 if (iThumbnailManager) |
|
117 { |
|
118 delete iThumbnailManager; |
|
119 iThumbnailManager = NULL; |
|
120 } |
|
121 |
|
122 PRINT ( _L("End CCsPreviewPluginHandler::~CCsPreviewPluginHandler") ); |
|
123 } |
|
124 |
|
125 // ---------------------------------------------------------------------------- |
|
126 // CCsMsgHandler::ConstructL |
|
127 // Two Phase Construction |
|
128 // ---------------------------------------------------------------------------- |
|
129 // |
|
130 void CCsPreviewPluginHandler::ConstructL(CCsPreviewPlugin *aMsgObserver) |
|
131 { |
|
132 PRINT ( _L("Enter CCsPreviewPluginHandler::ConstructL") ); |
|
133 |
|
134 iMsgObserver = aMsgObserver; |
|
135 |
|
136 //file session connect |
|
137 User::LeaveIfError(ifsSession.Connect()); |
|
138 |
|
139 //create msv session |
|
140 iSession = CMsvSession::OpenSyncL(*this); |
|
141 |
|
142 //create mtm registry |
|
143 iMtmRegistry = CClientMtmRegistry::NewL(*iSession); |
|
144 |
|
145 //create mms client mtm |
|
146 iMmsMtm = static_cast<CMmsClientMtm*> (iMtmRegistry-> NewMtmL( |
|
147 KSenduiMtmMmsUid)); |
|
148 |
|
149 //create thumbnail manager |
|
150 iThumbnailManager = CThumbnailManager::NewL(*this); |
|
151 |
|
152 // open DB |
|
153 TInt error = iSqlDb.Open(KDbFileName); |
|
154 |
|
155 PRINT1 ( _L("End CCsPreviewPluginHandler::ConstructL open DB file error=%d"), error ); |
|
156 |
|
157 // if not found, create DB |
|
158 if (error == KErrNotFound) |
|
159 { |
|
160 //create sqlite-DB |
|
161 TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass); |
|
162 RSqlSecurityPolicy securityPolicy; |
|
163 securityPolicy.Create(defaultPolicy); |
|
164 |
|
165 // TODO, setting UID security policy |
|
166 //TSecurityPolicy readPolicy(ECapabilityReadUserData); |
|
167 //securityPolicy.SetDbPolicy(RSqlSecurityPolicy::EReadPolicy, readPolicy); |
|
168 |
|
169 iSqlDb.Create(KDbFileName, securityPolicy); |
|
170 |
|
171 //Create the table inside DB |
|
172 iSqlDb.Exec(KSqlCreateStmt); |
|
173 iSqlDb.Exec(KEncodingStmnt); |
|
174 iSqlDb.Exec(KCacheSizeStmnt); |
|
175 } |
|
176 else |
|
177 { |
|
178 User::LeaveIfError(error); |
|
179 } |
|
180 |
|
181 //get the max size of mms from the repository |
|
182 TRAP_IGNORE( |
|
183 CRepository* repository = CRepository::NewL(KCRUidMmsEngine); |
|
184 CleanupStack::PushL(repository); |
|
185 |
|
186 //Fetch and set max mms composition size |
|
187 TInt maxSize = KDefaultMaxSize; |
|
188 repository->Get( KMmsEngineMaximumSendSize, maxSize ); |
|
189 iMaxMmsSize = maxSize; |
|
190 |
|
191 //Fetch and set creation mode |
|
192 TInt creationMode = EMmsCreationModeRestricted; |
|
193 repository->Get(KMmsEngineCreationMode, creationMode); |
|
194 iCreationMode = creationMode; |
|
195 |
|
196 CleanupStack::PopAndDestroy(repository); |
|
197 ); |
|
198 PRINT ( _L("End CCsPreviewPluginHandler::ConstructL") ); |
|
199 } |
|
200 |
|
201 // ---------------------------------------------------------------------------- |
|
202 // CCsPreviewPluginHandler::CCsPreviewPluginHandler |
|
203 // Two Phase Construction |
|
204 // ---------------------------------------------------------------------------- |
|
205 // |
|
206 CCsPreviewPluginHandler::CCsPreviewPluginHandler() |
|
207 { |
|
208 } |
|
209 |
|
210 // ---------------------------------------------------------------------------- |
|
211 // CCsPreviewPluginHandler::HandleSessionEventL |
|
212 // Implemented for MMsvSessionObserver |
|
213 // ---------------------------------------------------------------------------- |
|
214 // |
|
215 void CCsPreviewPluginHandler::HandleSessionEventL(TMsvSessionEvent aEvent, |
|
216 TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/) |
|
217 { |
|
218 PRINT1 ( _L("Enter CCsPreviewPluginHandler::HandleSessionEventL aEvent=%d"),aEvent ); |
|
219 |
|
220 CMsvEntrySelection* selection = NULL; |
|
221 TMsvId parent; |
|
222 |
|
223 //args |
|
224 if (aArg1 == NULL || aArg2 == NULL) |
|
225 { |
|
226 PRINT ( _L("Enter CCsPreviewPluginHandler::HandleSessionEventL arguments invalid")); |
|
227 return; |
|
228 } |
|
229 |
|
230 //start, processing the event |
|
231 selection = (CMsvEntrySelection*) aArg1; |
|
232 parent = *(TMsvId*) aArg2; |
|
233 |
|
234 //Drafts not handled |
|
235 if (KMsvDraftEntryIdValue == parent) |
|
236 { |
|
237 return; |
|
238 } |
|
239 |
|
240 switch (aEvent) |
|
241 { |
|
242 case EMsvEntriesChanged: |
|
243 case EMsvEntriesMoved: |
|
244 { |
|
245 HandleEventL(selection); |
|
246 } |
|
247 break; |
|
248 |
|
249 case EMsvEntriesDeleted: |
|
250 { |
|
251 for (TInt i = 0; i < selection->Count(); i++) |
|
252 { |
|
253 RSqlStatement sqlDeleteStmt; |
|
254 CleanupClosePushL(sqlDeleteStmt); |
|
255 sqlDeleteStmt.PrepareL(iSqlDb, KRemoveMsgStmnt); |
|
256 |
|
257 TInt messageIdIndex = sqlDeleteStmt.ParameterIndex(_L( |
|
258 ":message_id")); |
|
259 User::LeaveIfError(sqlDeleteStmt.BindInt(messageIdIndex, selection->At(i))); |
|
260 |
|
261 User::LeaveIfError(sqlDeleteStmt.Exec()); |
|
262 CleanupStack::PopAndDestroy(&sqlDeleteStmt); |
|
263 } |
|
264 } |
|
265 break; |
|
266 } |
|
267 |
|
268 PRINT ( _L("Exit CCsPreviewPluginHandler::HandleSessionEventL") ); |
|
269 } |
|
270 |
|
271 // --------------------------------------------------------------------- |
|
272 // CCsPreviewPluginHandler::HandleEvent |
|
273 // Handle events |
|
274 // --------------------------------------------------------------------- |
|
275 // |
|
276 void CCsPreviewPluginHandler::HandleEventL(CMsvEntrySelection* aSelection) |
|
277 { |
|
278 PRINT ( _L("Enter CCsPreviewPluginHandler::HandleEvent") ); |
|
279 |
|
280 TMsvEntry entry; |
|
281 TMsvId service; |
|
282 TInt error = KErrNone; |
|
283 |
|
284 for (TInt i = 0; i < aSelection->Count(); i++) |
|
285 { |
|
286 error = iSession->GetEntry(aSelection->At(i), service, entry); |
|
287 |
|
288 if ( (KErrNone == error) && !entry.InPreparation() && entry.Visible() |
|
289 && (KSenduiMtmMmsUidValue == entry.iMtm.iUid)) |
|
290 { |
|
291 PRINT ( _L("Enter CCsPreviewPluginHandler::HandleEvent for loop started.") ); |
|
292 |
|
293 TInt msgId = entry.Id(); |
|
294 |
|
295 // check if the msg is already under processing Or processed |
|
296 if( EPreviewMsgNotProcessed != msgProcessingState(msgId) ) |
|
297 { |
|
298 // skip processing this event for the given message |
|
299 continue; |
|
300 } |
|
301 else |
|
302 { |
|
303 // start processing message, set flag |
|
304 setMsgProcessingState(msgId, EPreviewMsgProcessing); |
|
305 } |
|
306 |
|
307 // update db with message preview data |
|
308 RSqlStatement sqlInsertStmt; |
|
309 CleanupClosePushL(sqlInsertStmt); |
|
310 sqlInsertStmt.PrepareL(iSqlDb, KSqlInsertStmt); |
|
311 |
|
312 // parse message |
|
313 iMmsMtm->SwitchCurrentEntryL(msgId); |
|
314 iMmsMtm->LoadMessageL(); |
|
315 |
|
316 CUniDataModel* iUniDataModel = CUniDataModel::NewL(ifsSession, |
|
317 *iMmsMtm); |
|
318 CleanupStack::PushL(iUniDataModel); |
|
319 iUniDataModel->RestoreL(*this, ETrue); |
|
320 |
|
321 //msg property |
|
322 TInt msgProperty = 0; |
|
323 if (iUniDataModel->AttachmentList().Count() > 0) |
|
324 { |
|
325 msgProperty |= EPreviewAttachment; |
|
326 } |
|
327 |
|
328 //check for msg forward |
|
329 //Validate if the mms msg can be forwarded or not |
|
330 if (ValidateMsgForForward(iUniDataModel)) |
|
331 { |
|
332 msgProperty |= EPreviewForward; |
|
333 } |
|
334 |
|
335 TPtrC videoPath; |
|
336 TPtrC imagePath; |
|
337 |
|
338 // preview parsing |
|
339 TInt slideCount = iUniDataModel->SmilModel().SlideCount(); |
|
340 TBool isBodyTextSet = EFalse; |
|
341 TBool isImageSet = EFalse; |
|
342 TBool isAudioSet = EFalse; |
|
343 TBool isVideoSet = EFalse; |
|
344 |
|
345 for (int i = 0; i < slideCount; i++) |
|
346 { |
|
347 int slideobjcount = |
|
348 iUniDataModel->SmilModel().SlideObjectCount(i); |
|
349 for (int j = 0; j < slideobjcount; j++) |
|
350 { |
|
351 CUniObject *obj = |
|
352 iUniDataModel->SmilModel(). GetObjectByIndex(i, j); |
|
353 CMsgMediaInfo *mediaInfo = obj->MediaInfo(); |
|
354 |
|
355 TPtrC8 mimetype = obj->MimeType(); |
|
356 TMsvAttachmentId attachId = obj->AttachmentId(); |
|
357 |
|
358 //bodytext |
|
359 if (!isBodyTextSet && (mimetype.Find(_L8("text")) |
|
360 != KErrNotFound)) |
|
361 { |
|
362 //bind bodytext into statement |
|
363 BindBodyText(sqlInsertStmt, attachId); |
|
364 isBodyTextSet = ETrue; |
|
365 } |
|
366 |
|
367 //image parsing |
|
368 if (!isVideoSet && !isImageSet && (mimetype.Find(_L8("image")) |
|
369 != KErrNotFound)) |
|
370 { |
|
371 //get thumbnail for this image |
|
372 isImageSet = ETrue; |
|
373 imagePath.Set(mediaInfo->FullFilePath()); |
|
374 msgProperty |= EPreviewImage; |
|
375 |
|
376 if (EFileProtNoProtection != mediaInfo->Protection()) |
|
377 { |
|
378 msgProperty |= EPreviewProtectedImage; |
|
379 } |
|
380 if (mediaInfo->Corrupt()) |
|
381 { |
|
382 msgProperty |= EPreviewCorruptedImage; |
|
383 } |
|
384 |
|
385 if (!(EPreviewProtectedImage & msgProperty) && |
|
386 !(EPreviewCorruptedImage & msgProperty)) |
|
387 { |
|
388 //Generate thumbnail for non protected, |
|
389 //non corrupted image. |
|
390 GetThumbNailL(attachId, mimetype, msgId); |
|
391 } |
|
392 } |
|
393 |
|
394 //audio content |
|
395 if (!isVideoSet && !isAudioSet && (mimetype.Find(_L8("audio")) |
|
396 != KErrNotFound)) |
|
397 { |
|
398 isAudioSet = ETrue; |
|
399 msgProperty |= EPreviewAudio; |
|
400 if (EFileProtNoProtection != mediaInfo->Protection()) |
|
401 { |
|
402 msgProperty |= EPreviewProtectedAudio; |
|
403 } |
|
404 if (mediaInfo->Corrupt()) |
|
405 { |
|
406 msgProperty |= EPreviewCorruptedAudio; |
|
407 } |
|
408 } |
|
409 |
|
410 //video content |
|
411 if (!( isImageSet || isAudioSet) && !isVideoSet && (mimetype.Find(_L8("video")) |
|
412 != KErrNotFound)) |
|
413 { |
|
414 videoPath.Set(mediaInfo->FullFilePath()); |
|
415 isVideoSet = ETrue; |
|
416 msgProperty |= EPreviewVideo; |
|
417 if (EFileProtNoProtection != mediaInfo->Protection()) |
|
418 { |
|
419 msgProperty |= EPreviewProtectedVideo; |
|
420 } |
|
421 if (mediaInfo->Corrupt()) |
|
422 { |
|
423 msgProperty |= EPreviewCorruptedVideo; |
|
424 } |
|
425 } |
|
426 } |
|
427 } |
|
428 |
|
429 //set preview path |
|
430 TInt previewPathIndex = sqlInsertStmt.ParameterIndex(_L( |
|
431 ":preview_path")); |
|
432 if (isVideoSet) |
|
433 { |
|
434 User::LeaveIfError(sqlInsertStmt.BindText(previewPathIndex, |
|
435 videoPath)); |
|
436 } |
|
437 else if (isImageSet) |
|
438 { |
|
439 User::LeaveIfError(sqlInsertStmt.BindText(previewPathIndex, |
|
440 imagePath)); |
|
441 } |
|
442 |
|
443 //msg_id |
|
444 TInt msgIdIndex = sqlInsertStmt.ParameterIndex(_L(":message_id")); |
|
445 User::LeaveIfError(sqlInsertStmt.BindInt(msgIdIndex, msgId)); |
|
446 |
|
447 //subjext |
|
448 TInt subjectIndex = sqlInsertStmt.ParameterIndex(_L(":subject")); |
|
449 User::LeaveIfError(sqlInsertStmt.BindText(subjectIndex, |
|
450 iMmsMtm->SubjectL())); |
|
451 |
|
452 //msg_property |
|
453 TInt msgPropertyIndex = sqlInsertStmt.ParameterIndex(_L( |
|
454 ":msg_property")); |
|
455 User::LeaveIfError(sqlInsertStmt.BindInt(msgPropertyIndex, |
|
456 msgProperty)); |
|
457 |
|
458 //msg_processingstate |
|
459 TInt msgProcessingStateIndex = sqlInsertStmt.ParameterIndex(_L(":msg_processingstate")); |
|
460 User::LeaveIfError(sqlInsertStmt.BindInt(msgProcessingStateIndex, EPreviewMsgProcessed)); |
|
461 |
|
462 //execute sql stament |
|
463 User::LeaveIfError(sqlInsertStmt.Exec()); |
|
464 |
|
465 //cleanup |
|
466 CleanupStack::PopAndDestroy(2, &sqlInsertStmt); |
|
467 } |
|
468 }//end for loop |
|
469 |
|
470 PRINT ( _L("Exit CCsPreviewPluginHandler::HandleEvent") ); |
|
471 } |
|
472 |
|
473 // ----------------------------------------------------------------------------- |
|
474 // CCsPreviewPluginHandler::RestoreReady() |
|
475 // |
|
476 // ----------------------------------------------------------------------------- |
|
477 // |
|
478 void CCsPreviewPluginHandler::RestoreReady(TInt /*aParseResult*/, TInt /*aError*/) |
|
479 { |
|
480 |
|
481 } |
|
482 |
|
483 // ----------------------------------------------------------------------------- |
|
484 // CCsPreviewPluginHandler::ThumbnailReady() |
|
485 // |
|
486 // ----------------------------------------------------------------------------- |
|
487 // |
|
488 void CCsPreviewPluginHandler::ThumbnailReady(TInt aError, |
|
489 MThumbnailData& aThumbnail, TThumbnailRequestId aId) |
|
490 { |
|
491 // This function must not leave. |
|
492 if (!aError) |
|
493 { |
|
494 PRINT ( _L("CCsPreviewPluginHandler::ThumbnailReady received.") ); |
|
495 TInt err; |
|
496 TRAP(err, HandleThumbnailReadyL(aThumbnail, aId)); |
|
497 PRINT1 ( _L("CCsPreviewPluginHandler::ThumbnailReady handling error= %d."), err ); |
|
498 } |
|
499 else |
|
500 { |
|
501 // An error occurred while getting the thumbnail. |
|
502 PRINT1 ( _L("End CCsPreviewPluginHandler::ThumbnailReady error= %d."), aError ); |
|
503 } |
|
504 } |
|
505 |
|
506 // ----------------------------------------------------------------------------- |
|
507 // CCsPreviewPluginHandler::ThumbnailPreviewReady() |
|
508 // callback |
|
509 // ----------------------------------------------------------------------------- |
|
510 // |
|
511 void CCsPreviewPluginHandler::ThumbnailPreviewReady( |
|
512 MThumbnailData& /*aThumbnail*/, TThumbnailRequestId /*aId*/) |
|
513 { |
|
514 |
|
515 } |
|
516 |
|
517 // ----------------------------------------------------------------------------- |
|
518 // CCsPreviewPluginHandler::HandleThumbnailReadyL() |
|
519 // |
|
520 // ----------------------------------------------------------------------------- |
|
521 // |
|
522 void CCsPreviewPluginHandler::HandleThumbnailReadyL(MThumbnailData& aThumbnail, |
|
523 TThumbnailRequestId aId) |
|
524 { |
|
525 //match response to request |
|
526 ThumbnailRequestData tempObj; |
|
527 tempObj.iRequestId = aId; |
|
528 |
|
529 TInt index = iThumbnailRequestArray.Find(tempObj, |
|
530 CCsPreviewPluginHandler::CompareByRequestId); |
|
531 if (index < 0) |
|
532 { |
|
533 PRINT ( _L("End CCsPreviewPluginHandler::HandleThumbnailReady request match not found.") ); |
|
534 return; |
|
535 } |
|
536 |
|
537 // get msg-id corresponding to the request-id |
|
538 TInt msgId = iThumbnailRequestArray[index].iMsgId; |
|
539 //remove the request from requestarray |
|
540 iThumbnailRequestArray.Remove(index); |
|
541 |
|
542 // get bitmap |
|
543 CFbsBitmap* bitmap = aThumbnail.Bitmap(); |
|
544 |
|
545 // sql-statment to set preview-icon |
|
546 RSqlStatement sqlInsertStmt; |
|
547 CleanupClosePushL(sqlInsertStmt); |
|
548 sqlInsertStmt.PrepareL(iSqlDb, KSqlUpdateBitmapStmt); |
|
549 |
|
550 TInt msgIdIndex = sqlInsertStmt.ParameterIndex(_L(":message_id")); |
|
551 TInt previewIconIndex = sqlInsertStmt.ParameterIndex(_L(":preview_icon")); |
|
552 |
|
553 User::LeaveIfError(sqlInsertStmt.BindInt(msgIdIndex, msgId)); |
|
554 |
|
555 RSqlParamWriteStream previewIconStream; |
|
556 CleanupClosePushL(previewIconStream); |
|
557 |
|
558 //bind data |
|
559 User::LeaveIfError(previewIconStream.BindBinary(sqlInsertStmt, previewIconIndex)); |
|
560 bitmap->ExternalizeL(previewIconStream); |
|
561 previewIconStream.CommitL(); |
|
562 |
|
563 //execute the statent |
|
564 User::LeaveIfError(sqlInsertStmt.Exec()); |
|
565 |
|
566 CleanupStack::PopAndDestroy(2,&sqlInsertStmt);//sqlInsertStmt,previewIconStream |
|
567 } |
|
568 |
|
569 TBool CCsPreviewPluginHandler::ValidateMsgForForward(CUniDataModel* aUniDataModel) |
|
570 { |
|
571 TBool retValue = ETrue; |
|
572 |
|
573 //1. Check the slide count more than 1 |
|
574 if (aUniDataModel->SmilModel().SlideCount() > 1) |
|
575 { |
|
576 retValue = EFalse; |
|
577 return retValue; |
|
578 } |
|
579 |
|
580 //2. message sixe check |
|
581 //Fetch and set max mms composition size |
|
582 if (iMmsMtm->MessageSize() > iMaxMmsSize) |
|
583 { |
|
584 retValue = EFalse; |
|
585 return retValue; |
|
586 } |
|
587 |
|
588 //3. If there is restricted content then return false |
|
589 RArray<TMsvAttachmentId>* pathList = GetSlideAttachmentIds( |
|
590 0, |
|
591 aUniDataModel); |
|
592 |
|
593 CleanupStack::PushL(pathList); |
|
594 |
|
595 for (int i = 0; i < pathList->Count(); i++) |
|
596 { |
|
597 TMsvAttachmentId aId = (*pathList)[i]; |
|
598 CMsvStore * store = iMmsMtm->Entry().ReadStoreL(); |
|
599 CleanupStack::PushL(store); |
|
600 MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
601 RFile fileHandle = attachMan.GetAttachmentFileL(aId); |
|
602 //close the store |
|
603 CleanupStack::PopAndDestroy(store); |
|
604 |
|
605 if (CheckModeForInsertL(fileHandle) != EInsertSuccess) |
|
606 { |
|
607 retValue = EFalse; |
|
608 break; |
|
609 } |
|
610 } |
|
611 |
|
612 if (retValue == EFalse) |
|
613 { |
|
614 CleanupStack::PopAndDestroy(pathList); |
|
615 return retValue; |
|
616 } |
|
617 |
|
618 CleanupStack::Pop(pathList); |
|
619 delete pathList; |
|
620 pathList = NULL; |
|
621 |
|
622 //4. check the same case for all attachments |
|
623 pathList = GetAttachmentIdList(aUniDataModel); |
|
624 CleanupStack::PushL(pathList); |
|
625 |
|
626 for (int i = 0; i < pathList->Count(); i++) |
|
627 { |
|
628 TMsvAttachmentId aId = (*pathList)[i]; |
|
629 CMsvStore * store = iMmsMtm->Entry().ReadStoreL(); |
|
630 CleanupStack::PushL(store); |
|
631 MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
632 RFile fileHandle = attachMan.GetAttachmentFileL(aId); |
|
633 //close the store |
|
634 CleanupStack::PopAndDestroy(store); |
|
635 |
|
636 if (CheckModeForInsertL(fileHandle) != EInsertSuccess) |
|
637 { |
|
638 retValue = EFalse; |
|
639 break; |
|
640 } |
|
641 } |
|
642 |
|
643 CleanupStack::PopAndDestroy(pathList); |
|
644 return retValue; |
|
645 } |
|
646 |
|
647 RArray<TMsvAttachmentId>* |
|
648 CCsPreviewPluginHandler::GetSlideAttachmentIds(TInt aSlideNum, |
|
649 CUniDataModel* aUniDataModel) |
|
650 { |
|
651 TInt slideObjectCount = |
|
652 aUniDataModel->SmilModel().SlideObjectCount(aSlideNum); |
|
653 |
|
654 RArray<TMsvAttachmentId> *attachmentIdList = new (ELeave) RArray< |
|
655 TMsvAttachmentId> (); |
|
656 for (TInt i = 0; i < slideObjectCount; i++) |
|
657 { |
|
658 CUniObject *obj = |
|
659 aUniDataModel->SmilModel().GetObjectByIndex(aSlideNum, i); |
|
660 attachmentIdList->Append(obj->AttachmentId()); |
|
661 } |
|
662 return attachmentIdList; |
|
663 } |
|
664 |
|
665 RArray<TMsvAttachmentId>* |
|
666 CCsPreviewPluginHandler::GetAttachmentIdList(CUniDataModel* aUniDataModel) |
|
667 { |
|
668 TInt attcount = aUniDataModel->AttachmentList().Count(); |
|
669 RArray<TMsvAttachmentId> *attachmentIdList = new (ELeave) RArray< |
|
670 TMsvAttachmentId> (); |
|
671 |
|
672 for (TInt i = 0; i < attcount; i++) |
|
673 { |
|
674 CUniObject *obj = aUniDataModel->AttachmentList().GetByIndex(i); |
|
675 |
|
676 attachmentIdList->AppendL(obj->AttachmentId()); |
|
677 } |
|
678 return attachmentIdList; |
|
679 } |
|
680 |
|
681 TInt CCsPreviewPluginHandler::CheckModeForInsertL(RFile aFileHandle) |
|
682 { |
|
683 CleanupClosePushL(aFileHandle); |
|
684 |
|
685 CMmsConformance* mmsConformance = CMmsConformance::NewL(); |
|
686 mmsConformance->CheckCharacterSet(EFalse); |
|
687 |
|
688 CleanupStack::PushL(mmsConformance); |
|
689 |
|
690 CMsgMediaResolver* mediaResolver = CMsgMediaResolver::NewL(); |
|
691 mediaResolver->SetCharacterSetRecognition(EFalse); |
|
692 |
|
693 CleanupStack::PushL(mediaResolver); |
|
694 |
|
695 CMsgMediaInfo* info = mediaResolver->CreateMediaInfoL(aFileHandle); |
|
696 mediaResolver->ParseInfoDetailsL(info, aFileHandle); |
|
697 |
|
698 TMmsConformance conformance = mmsConformance->MediaConformance(*info); |
|
699 iConfStatus = conformance.iConfStatus; |
|
700 |
|
701 CleanupStack::PopAndDestroy(3); |
|
702 |
|
703 // In "free" mode user can insert images that are larger by dimensions than allowed by conformance |
|
704 if (iCreationMode != EMmsCreationModeRestricted) |
|
705 { |
|
706 TInt i = EMmsConfNokFreeModeOnly | EMmsConfNokScalingNeeded |
|
707 | EMmsConfNokTooBig; |
|
708 TInt j = ~ (EMmsConfNokFreeModeOnly | EMmsConfNokScalingNeeded |
|
709 | EMmsConfNokTooBig); |
|
710 |
|
711 // If user answers yes to Guided mode confirmation query he/she moves to free mode |
|
712 if ( (iConfStatus & i) && ! (iConfStatus & j)) |
|
713 { |
|
714 if (iCreationMode == EMmsCreationModeFree || info->Protection() |
|
715 & EFileProtSuperDistributable) |
|
716 { |
|
717 // SuperDistribution not checked here |
|
718 // Mask "FreeModeOnly" and "ScalingNeeded" away in free mode |
|
719 iConfStatus &= ~EMmsConfNokFreeModeOnly; |
|
720 iConfStatus &= ~EMmsConfNokScalingNeeded; |
|
721 } |
|
722 else |
|
723 { |
|
724 delete info; |
|
725 //query not accepted. Stop insertion. |
|
726 return EInsertQueryAbort; |
|
727 } |
|
728 } |
|
729 } |
|
730 else if (iConfStatus & EMmsConfNokDRM || iConfStatus |
|
731 & EMmsConfNokNotEnoughInfo || iConfStatus & EMmsConfNokNotSupported |
|
732 || iConfStatus & EMmsConfNokFreeModeOnly || iConfStatus |
|
733 & EMmsConfNokCorrupt) |
|
734 { |
|
735 delete info; |
|
736 return EInsertNotSupported; |
|
737 } |
|
738 |
|
739 delete info; |
|
740 return EInsertSuccess; |
|
741 } |
|
742 |
|
743 //----------------------------------------------------------------------------- |
|
744 // CCsPreviewPluginHandler::CompareByRequestId |
|
745 // Compare to conversation entry object based on Entry Ids |
|
746 //---------------------------------------------------------------------------- |
|
747 TBool CCsPreviewPluginHandler::CompareByRequestId( |
|
748 const ThumbnailRequestData& aFirst, const ThumbnailRequestData& aSecond) |
|
749 { |
|
750 if (aFirst.iRequestId == aSecond.iRequestId) |
|
751 return ETrue; |
|
752 |
|
753 return EFalse; |
|
754 } |
|
755 |
|
756 // ----------------------------------------------------------------------------- |
|
757 // CCsPreviewPluginHandler::BindBodyText() |
|
758 // |
|
759 // ----------------------------------------------------------------------------- |
|
760 // |
|
761 void CCsPreviewPluginHandler::BindBodyText(RSqlStatement& sqlStmt, |
|
762 TMsvAttachmentId attachmentId) |
|
763 { |
|
764 //get file handle from attachmnet manager. |
|
765 CMsvStore * store = iMmsMtm->Entry().ReadStoreL(); |
|
766 CleanupStack::PushL(store); |
|
767 MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
768 RFile file = attachMan.GetAttachmentFileL(attachmentId); |
|
769 CleanupClosePushL(file); |
|
770 |
|
771 //read file contents to buffer |
|
772 TInt length; |
|
773 file.Size(length); |
|
774 HBufC8* bodyText = HBufC8::NewLC(length); |
|
775 TPtr8 textBuffer = bodyText->Des(); |
|
776 file.Read(textBuffer); |
|
777 |
|
778 // convert from HBufC8 to HBufC16 |
|
779 HBufC16 *text16 = HBufC16::NewLC(textBuffer.Length()); |
|
780 TPtr16 textPtr16 = text16->Des(); |
|
781 CnvUtfConverter::ConvertToUnicodeFromUtf8(textPtr16, textBuffer); |
|
782 |
|
783 //set bodytext in the sql statement |
|
784 TInt bodyTextIndex = sqlStmt.ParameterIndex(_L(":body_text")); |
|
785 sqlStmt.BindText(bodyTextIndex, textPtr16); |
|
786 |
|
787 CleanupStack::PopAndDestroy(4, store); //store,file, bodyText, text16 |
|
788 } |
|
789 |
|
790 // ----------------------------------------------------------------------------- |
|
791 // CCsPreviewPluginHandler::GetThumbNailL() |
|
792 // |
|
793 // ----------------------------------------------------------------------------- |
|
794 // |
|
795 void CCsPreviewPluginHandler::GetThumbNailL(TMsvAttachmentId attachmentId, |
|
796 TDesC8& mimeType, TMsvId msgId) |
|
797 { |
|
798 //Scale the image |
|
799 iThumbnailManager->SetFlagsL(CThumbnailManager::ECropToAspectRatio); |
|
800 |
|
801 //TODO replace with hb-param-graphic-size-image-portrait * value of un in pixcels |
|
802 iThumbnailManager->SetThumbnailSizeL(TSize(KWidth, KHeight)); |
|
803 |
|
804 //optimize for performace |
|
805 iThumbnailManager->SetQualityPreferenceL( |
|
806 CThumbnailManager::EOptimizeForPerformance); |
|
807 |
|
808 // Create Thumbnail object source representing a path to a file |
|
809 HBufC* mimeInfo = HBufC::NewLC(mimeType.Length()); |
|
810 mimeInfo->Des().Copy(mimeType); |
|
811 |
|
812 CMsvStore * store = iMmsMtm->Entry().ReadStoreL(); |
|
813 CleanupStack::PushL(store); |
|
814 |
|
815 //get file handle from attachment manager. |
|
816 MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
817 RFile file = attachMan.GetAttachmentFileL(attachmentId); |
|
818 CleanupClosePushL(file); |
|
819 |
|
820 CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC( |
|
821 (RFile64&) file, mimeInfo->Des()); |
|
822 |
|
823 // Issue the request for thumbnail creation |
|
824 ThumbnailRequestData reqObject; |
|
825 reqObject.iMsgId = msgId; |
|
826 reqObject.iRequestId = iThumbnailManager->GetThumbnailL(*source); |
|
827 iThumbnailRequestArray.Append(reqObject); |
|
828 |
|
829 CleanupStack::PopAndDestroy(4, mimeInfo);//mimeInfo,store,file,source |
|
830 } |
|
831 |
|
832 // ----------------------------------------------------------------------------- |
|
833 // CCsPreviewPluginHandler::msgProcessingState |
|
834 // |
|
835 // ----------------------------------------------------------------------------- |
|
836 // |
|
837 TInt CCsPreviewPluginHandler::msgProcessingState(TMsvId aMsgId) |
|
838 { |
|
839 TInt retState = EPreviewMsgNotProcessed; |
|
840 |
|
841 // sql-statement to check if msg's under processing flag is set or not |
|
842 RSqlStatement sqlSelectStmt; |
|
843 CleanupClosePushL(sqlSelectStmt); |
|
844 sqlSelectStmt.PrepareL(iSqlDb,KSelectProcessingStateStmt); |
|
845 |
|
846 TInt msgIdIndex = sqlSelectStmt.ParameterIndex(_L(":message_id")); |
|
847 User::LeaveIfError(sqlSelectStmt.BindInt(msgIdIndex, aMsgId)); |
|
848 |
|
849 // read the flag |
|
850 TInt msgProcessingStateIndex = sqlSelectStmt.ColumnIndex(_L("msg_processingstate")); |
|
851 if (sqlSelectStmt.Next() == KSqlAtRow) |
|
852 { |
|
853 retState = static_cast<TInt>(sqlSelectStmt.ColumnInt(msgProcessingStateIndex)); |
|
854 } |
|
855 else |
|
856 { |
|
857 // this is first event for this msgid, hence record doesn't exist |
|
858 // create an empty record, so that we can set & use flags |
|
859 RSqlStatement sqlBasicInsertStmt; |
|
860 CleanupClosePushL(sqlBasicInsertStmt); |
|
861 sqlBasicInsertStmt.PrepareL(iSqlDb, KSqlBasicInsertStmt); |
|
862 TInt index_msgid = sqlBasicInsertStmt.ParameterIndex(_L(":message_id")); |
|
863 User::LeaveIfError(sqlBasicInsertStmt.BindInt(index_msgid, aMsgId)); |
|
864 User::LeaveIfError(sqlBasicInsertStmt.Exec()); |
|
865 CleanupStack::PopAndDestroy(&sqlBasicInsertStmt); |
|
866 } |
|
867 // cleanup |
|
868 CleanupStack::PopAndDestroy(&sqlSelectStmt); |
|
869 return retState; |
|
870 } |
|
871 |
|
872 // ----------------------------------------------------------------------------- |
|
873 // CCsPreviewPluginHandler::setMsgProcessingState |
|
874 // |
|
875 // ----------------------------------------------------------------------------- |
|
876 // |
|
877 void CCsPreviewPluginHandler::setMsgProcessingState(TMsvId aMsgId, TInt aState) |
|
878 { |
|
879 // sql-statment to set/reset msg's under processing flag |
|
880 RSqlStatement sqlUpdateStmt; |
|
881 CleanupClosePushL(sqlUpdateStmt); |
|
882 sqlUpdateStmt.PrepareL(iSqlDb, KSqlUpdateProcessingStateStmt); |
|
883 |
|
884 TInt msgIdIndex = sqlUpdateStmt.ParameterIndex(_L(":message_id")); |
|
885 User::LeaveIfError(sqlUpdateStmt.BindInt(msgIdIndex, aMsgId)); |
|
886 |
|
887 // bind data |
|
888 TInt msgProcessingStateIndex = sqlUpdateStmt.ParameterIndex(_L(":msg_processingstate")); |
|
889 User::LeaveIfError(sqlUpdateStmt.BindInt(msgProcessingStateIndex, aState)); |
|
890 |
|
891 // execute the statement |
|
892 User::LeaveIfError(sqlUpdateStmt.Exec()); |
|
893 // cleanup |
|
894 CleanupStack::PopAndDestroy(&sqlUpdateStmt); |
|
895 } |
|
896 |
|
897 // End of file |
|
898 |