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