17 |
17 |
18 #include "conversationsmodel.h" |
18 #include "conversationsmodel.h" |
19 #include "conversationsenginedefines.h" |
19 #include "conversationsenginedefines.h" |
20 #include "conversationmsgstorehandler.h" |
20 #include "conversationmsgstorehandler.h" |
21 #include "convergedmessage.h" |
21 #include "convergedmessage.h" |
22 #include "s60qconversions.h" |
22 #include <xqconversions.h> |
23 #include "conversationsengineutility.h" |
23 #include "conversationsengineutility.h" |
24 #include "unidatamodelloader.h" |
24 #include "unidatamodelloader.h" |
25 #include "unidatamodelplugininterface.h" |
25 #include "unidatamodelplugininterface.h" |
|
26 #include "ringbc.h" |
|
27 #include "msgcontacthandler.h" |
|
28 #include "mmsconformancecheck.h" |
26 #include <ccsconversationentry.h> |
29 #include <ccsconversationentry.h> |
|
30 #include <fileprotectionresolver.h> |
|
31 |
|
32 #include "debugtraces.h" |
|
33 |
27 #include <QFile> |
34 #include <QFile> |
28 #include <QFileInfo> |
35 #include <QFileInfo> |
29 |
36 #include <s32mem.h> |
30 // LOCAL CONSTANTS |
37 #include <s32strm.h> |
31 |
38 #include <fbs.h> |
|
39 #include <ccsdefs.h> |
|
40 |
|
41 //CONSTANTS |
|
42 _LIT(KDbFileName, "c:[2002A542]conversations.db"); |
|
43 |
|
44 // preview sql query |
|
45 _LIT(KSelectConvMsgsStmt, "SELECT message_id, msg_processingstate, subject, body_text, preview_path, msg_property, preview_icon FROM conversation_messages WHERE message_id=:message_id "); |
|
46 |
|
47 //selecet preview-icon query |
|
48 _LIT(KSelectPreviewIconStmt,"SELECT message_id, preview_icon FROM conversation_messages WHERE message_id = :message_id "); |
|
49 |
|
50 // preview-cache max cost (items) |
|
51 const int CACHE_COST = 50; |
|
52 //Preview thumbnail size |
|
53 const int KWidth = 9.5 * 6.7; |
|
54 const int KHeight = 9.5 * 6.7; |
32 //--------------------------------------------------------------- |
55 //--------------------------------------------------------------- |
33 // ConversationsModel::ConversationsModel |
56 // ConversationsModel::ConversationsModel |
34 // Constructor |
57 // Constructor |
35 //--------------------------------------------------------------- |
58 //--------------------------------------------------------------- |
36 ConversationsModel::ConversationsModel(ConversationMsgStoreHandler* msgStoreHandler, |
59 ConversationsModel::ConversationsModel(ConversationMsgStoreHandler* msgStoreHandler, |
37 QObject* parent) : |
60 QObject* parent) : |
38 QStandardItemModel(parent), mMsgStoreHandler(msgStoreHandler) |
61 QStandardItemModel(parent), mMsgStoreHandler(msgStoreHandler), iSqlDbOpen(EFalse) |
39 { |
62 { |
|
63 //Open SQL DB |
|
64 if (KErrNone == iSqlDb.Open(KDbFileName)) |
|
65 { |
|
66 iSqlDbOpen = ETrue; |
|
67 } |
|
68 previewIconCache.setMaxCost(CACHE_COST); |
|
69 |
|
70 int err = connect(this, SIGNAL(retrievePreviewIcon(int, QString&)), this, |
|
71 SLOT(updatePreviewIcon(int, QString&))); |
|
72 QCRITICAL_WRITE_FORMAT("Error from connect()", err) |
40 iDataModelPluginLoader = new UniDataModelLoader; |
73 iDataModelPluginLoader = new UniDataModelLoader; |
41 iMmsDataPlugin = iDataModelPluginLoader->getDataModelPlugin(ConvergedMessage::Mms); |
74 iMmsDataPlugin = iDataModelPluginLoader->getDataModelPlugin(ConvergedMessage::Mms); |
42 iBioMsgPlugin = iDataModelPluginLoader->getDataModelPlugin(ConvergedMessage::BioMsg); |
75 iBioMsgPlugin = iDataModelPluginLoader->getDataModelPlugin(ConvergedMessage::BioMsg); |
43 } |
76 } |
44 |
77 |
318 } |
368 } |
319 else { |
369 else { |
320 // sms bodytext |
370 // sms bodytext |
321 item.setData(subject, BodyText); |
371 item.setData(subject, BodyText); |
322 } |
372 } |
323 } |
373 |
|
374 QCRITICAL_WRITE("ConversationsModel::populateItem end."); |
|
375 } |
|
376 |
|
377 //--------------------------------------------------------------- |
|
378 // ConversationsModel::validateMsgForForward |
|
379 // @see header file |
|
380 //--------------------------------------------------------------- |
|
381 bool ConversationsModel::validateMsgForForward(qint32 messageId) |
|
382 { |
|
383 bool retValue = true; |
|
384 //Validate if the mms msg can be forwarded or not |
|
385 MmsConformanceCheck* mmsConformanceCheck = new MmsConformanceCheck; |
|
386 retValue = mmsConformanceCheck->validateMsgForForward(messageId); |
|
387 |
|
388 delete mmsConformanceCheck; |
|
389 return retValue; |
|
390 } |
|
391 |
324 |
392 |
325 //--------------------------------------------------------------- |
393 //--------------------------------------------------------------- |
326 // ConversationsModel::handleMMS |
394 // ConversationsModel::handleMMS |
327 // @see header |
395 // @see header |
328 //--------------------------------------------------------------- |
396 //--------------------------------------------------------------- |
329 void ConversationsModel::handleMMS(QStandardItem& item, const CCsConversationEntry& entry) |
397 void ConversationsModel::handleMMS(QStandardItem& item, const CCsConversationEntry& entry) |
330 { |
398 { |
331 iMmsDataPlugin->setMessageId(entry.EntryId()); |
399 //msg_id |
332 if (iMmsDataPlugin->attachmentCount() > 0) { |
400 int msgId = entry.EntryId(); |
333 item.setData(ConvergedMessage::Attachment, MessageProperty); |
401 |
334 } |
402 bool isEntryInDb = false; |
335 |
403 TInt err = KErrNone; |
336 int slideCount = iMmsDataPlugin->slideCount(); |
404 |
337 bool isBodyTextSet = false; |
405 //check if db is open and query db |
338 QString textContent; |
406 if (iSqlDbOpen) |
339 QStringList attachmentPaths; |
407 { |
340 |
408 RSqlStatement sqlSelectStmt; |
341 for (int i = 0; i < slideCount; ++i) { |
409 err = sqlSelectStmt.Prepare(iSqlDb, KSelectConvMsgsStmt); |
342 UniMessageInfoList objectList = iMmsDataPlugin->slideContent(i); |
410 |
343 for (int index = 0; index < objectList.count(); ++index) { |
411 // move to fallback option |
344 attachmentPaths.append(objectList[index]->path()); |
412 if (KErrNone == err) |
345 if (!isBodyTextSet && objectList[index]->mimetype().contains("text")) { |
413 { |
346 QFile file(objectList[index]->path()); |
414 TInt msgIdIndex = sqlSelectStmt.ParameterIndex(_L(":message_id")); |
347 if(file.open(QIODevice::ReadOnly)) |
415 TInt msgProcessingStateIndex = sqlSelectStmt.ColumnIndex(_L("msg_processingstate")); |
|
416 TInt subjectIndex = sqlSelectStmt.ColumnIndex(_L("subject")); |
|
417 TInt bodyIndex = sqlSelectStmt.ColumnIndex(_L("body_text")); |
|
418 TInt previewPathIndex = sqlSelectStmt.ColumnIndex( |
|
419 _L("preview_path")); |
|
420 TInt msgpropertyIndex = sqlSelectStmt.ColumnIndex( |
|
421 _L("msg_property")); |
|
422 TInt previewIconIndex = sqlSelectStmt.ColumnIndex( |
|
423 _L("preview_icon")); |
|
424 |
|
425 err = sqlSelectStmt.BindInt(msgIdIndex, msgId); |
|
426 |
|
427 // populate item |
|
428 if ((KErrNone == err) && (sqlSelectStmt.Next() == KSqlAtRow)) |
348 { |
429 { |
|
430 int msgProcessingState = 0; |
|
431 msgProcessingState = sqlSelectStmt.ColumnInt( |
|
432 msgProcessingStateIndex); |
|
433 if (msgProcessingState == EPreviewMsgProcessed) |
|
434 { |
|
435 // use entry to populate model only when, |
|
436 // entry is present in DB and its processing is over. |
|
437 RBuf subjectBuffer; |
|
438 subjectBuffer.Create(sqlSelectStmt.ColumnSize( |
|
439 subjectIndex)); |
|
440 sqlSelectStmt.ColumnText(subjectIndex, subjectBuffer); |
|
441 |
|
442 item.setData(XQConversions::s60DescToQString( |
|
443 subjectBuffer), Subject); |
|
444 subjectBuffer.Close(); |
|
445 |
|
446 RBuf bodyBuffer; |
|
447 bodyBuffer.Create(sqlSelectStmt.ColumnSize(bodyIndex)); |
|
448 sqlSelectStmt.ColumnText(bodyIndex, bodyBuffer); |
|
449 |
|
450 item.setData( |
|
451 XQConversions::s60DescToQString(bodyBuffer), |
|
452 BodyText); |
|
453 bodyBuffer.Close(); |
|
454 |
|
455 RBuf previewPathBuffer; |
|
456 previewPathBuffer.Create(sqlSelectStmt.ColumnSize( |
|
457 previewPathIndex)); |
|
458 sqlSelectStmt.ColumnText(previewPathIndex, |
|
459 previewPathBuffer); |
|
460 |
|
461 //Rightnow set inside attachments |
|
462 QString attachmentPath(XQConversions::s60DescToQString( |
|
463 previewPathBuffer)); |
|
464 |
|
465 item.setData(attachmentPath, Attachments); |
|
466 previewPathBuffer.Close(); |
|
467 |
|
468 int msgProperty = 0; |
|
469 msgProperty = sqlSelectStmt.ColumnInt(msgpropertyIndex); |
|
470 item.setData(msgProperty, MessageProperty); |
|
471 |
|
472 RSqlColumnReadStream stream; |
|
473 //Get data from binary column BLOB |
|
474 TInt err = stream.ColumnBinary(sqlSelectStmt, |
|
475 previewIconIndex); |
|
476 |
|
477 QCRITICAL_WRITE_FORMAT("Error from ColumnBinary()", err) |
|
478 |
|
479 if (err == KErrNone) |
|
480 { |
|
481 CFbsBitmap *bitmap = new CFbsBitmap; |
|
482 TRAPD(err,bitmap->InternalizeL(stream)); |
|
483 QCRITICAL_WRITE_FORMAT("Error from bitmap InternalizeL()", err) |
|
484 |
|
485 //convert bitmap to pixmap |
|
486 if (err == KErrNone) |
|
487 { |
|
488 TSize size = bitmap->SizeInPixels(); |
|
489 int bytesPerLine = bitmap->ScanLineLength( |
|
490 size.iWidth, bitmap->DisplayMode()); |
|
491 const uchar* dataPtr = |
|
492 (const uchar*) bitmap->DataAddress(); |
|
493 |
|
494 QPixmap pixmap = QPixmap::fromImage(QImage( |
|
495 dataPtr, size.iWidth, size.iHeight, |
|
496 bytesPerLine, QImage::Format_RGB16)); |
|
497 |
|
498 setPreviewIcon(pixmap, attachmentPath, msgId, |
|
499 true); |
|
500 |
|
501 } |
|
502 //remove bitmap |
|
503 delete bitmap; |
|
504 } |
|
505 |
|
506 //set flag to disable fallback option |
|
507 isEntryInDb = true; |
|
508 } |
|
509 } |
|
510 } |
|
511 sqlSelectStmt.Close(); |
|
512 } |
|
513 |
|
514 //fallback option incase of db operation failure or enry not found in DB |
|
515 //populate from data plugins |
|
516 if (!isEntryInDb || err != KErrNone) |
|
517 { |
|
518 int id = iMmsDataPlugin->setMessageId(entry.EntryId()); |
|
519 if(id <= 0) |
|
520 { |
|
521 // skip all |
|
522 return; |
|
523 } |
|
524 int msgProperty = 0; |
|
525 |
|
526 if (iMmsDataPlugin->attachmentCount() > 0) |
|
527 { |
|
528 msgProperty |= EPreviewAttachment; |
|
529 } |
|
530 |
|
531 if(validateMsgForForward(entry.EntryId())) |
|
532 { |
|
533 msgProperty |= EPreviewForward; |
|
534 } |
|
535 |
|
536 //subject |
|
537 item.setData(iMmsDataPlugin->subject(), Subject); |
|
538 |
|
539 int slideCount = iMmsDataPlugin->slideCount(); |
|
540 bool isBodyTextSet = false; |
|
541 bool isAudioSet = false; |
|
542 bool isImageSet = false; |
|
543 bool isVideoSet = false; |
|
544 QString textContent; |
|
545 QString videoPath; |
|
546 QString imagePath; |
|
547 |
|
548 for (int i = 0; i < slideCount; ++i) |
|
549 { |
|
550 UniMessageInfoList objectList = iMmsDataPlugin->slideContent(i); |
|
551 for (int index = 0; index < objectList.count(); ++index) |
|
552 { |
|
553 if (!isBodyTextSet && objectList[index]->mimetype().contains( |
|
554 "text")) |
|
555 { |
|
556 QFile file(objectList[index]->path()); |
|
557 file.open(QIODevice::ReadOnly); |
349 textContent = file.readAll(); |
558 textContent = file.readAll(); |
350 item.setData(textContent, BodyText); |
559 item.setData(textContent, BodyText); |
351 isBodyTextSet = true; |
560 isBodyTextSet = true; |
352 file.close(); |
561 file.close(); |
353 } |
562 } |
|
563 if (!isVideoSet && !isImageSet && objectList[index]->mimetype().contains( |
|
564 "image")) |
|
565 { |
|
566 isImageSet = true; |
|
567 msgProperty |= EPreviewImage; |
|
568 if (objectList[index]->isProtected()) |
|
569 { |
|
570 msgProperty |= EPreviewProtectedImage; |
|
571 } |
|
572 if (objectList[index]->isCorrupted()) |
|
573 { |
|
574 msgProperty |= EPreviewCorruptedImage; |
|
575 } |
|
576 imagePath = objectList[index]->path(); |
|
577 } |
|
578 if (!isVideoSet && !isAudioSet && objectList[index]->mimetype().contains( |
|
579 "audio")) |
|
580 { |
|
581 msgProperty |= EPreviewAudio; |
|
582 if (objectList[index]->isProtected()) |
|
583 { |
|
584 msgProperty |= EPreviewProtectedAudio; |
|
585 } |
|
586 if (objectList[index]->isCorrupted()) |
|
587 { |
|
588 msgProperty |= EPreviewCorruptedAudio; |
|
589 } |
|
590 isAudioSet = true; |
|
591 } |
|
592 if (!( isImageSet || isAudioSet) && !isVideoSet && objectList[index]->mimetype().contains( |
|
593 "video")) |
|
594 { |
|
595 isVideoSet = true; |
|
596 msgProperty |= EPreviewVideo; |
|
597 if (objectList[index]->isProtected()) |
|
598 { |
|
599 msgProperty |= EPreviewProtectedVideo; |
|
600 } |
|
601 if (objectList[index]->isCorrupted()) |
|
602 { |
|
603 msgProperty |= EPreviewCorruptedVideo; |
|
604 } |
|
605 videoPath = objectList[index]->path(); |
|
606 } |
354 } |
607 } |
355 } |
608 foreach(UniMessageInfo* slide,objectList) |
356 foreach(UniMessageInfo* slide,objectList) |
609 { |
|
610 delete slide; |
|
611 } |
|
612 } |
|
613 QPixmap pixmap; |
|
614 //populate item with the attachment list |
|
615 //TODO: This code is not required bcoz video icon is show and not preview |
|
616 if (isVideoSet) |
|
617 { |
|
618 item.setData(videoPath, Attachments); |
|
619 // Store thumbnail only for non protected, non corrupted content. |
|
620 if (!(EPreviewProtectedVideo & msgProperty) && |
|
621 !(EPreviewCorruptedVideo & msgProperty)) |
357 { |
622 { |
358 delete slide; |
623 setPreviewIcon(pixmap, videoPath, msgId, false); |
359 } |
624 } |
360 } |
625 } |
361 //populate item with the attachment list |
626 else if (isImageSet) |
362 item.setData(attachmentPaths.join("|"), Attachments); |
627 { |
363 if (entry.IsAttributeSet(ECsAttributeHighPriority)) { |
628 item.setData(imagePath, Attachments); |
|
629 // Store thumbnail only for non protected, non corrupted content. |
|
630 if (!(EPreviewProtectedImage & msgProperty) && |
|
631 !(EPreviewCorruptedImage & msgProperty)) |
|
632 { |
|
633 setPreviewIcon(pixmap, imagePath, msgId, false); |
|
634 } |
|
635 } |
|
636 //populate msgProperty |
|
637 item.setData(msgProperty, MessageProperty); |
|
638 } |
|
639 |
|
640 // fill other attributes |
|
641 if (entry.IsAttributeSet(ECsAttributeHighPriority)) |
|
642 { |
364 item.setData(ConvergedMessage::High, MessagePriority); |
643 item.setData(ConvergedMessage::High, MessagePriority); |
365 } |
644 } |
366 else if (entry.IsAttributeSet(ECsAttributeLowPriority)) { |
645 else if (entry.IsAttributeSet(ECsAttributeLowPriority)) |
|
646 { |
367 item.setData(ConvergedMessage::Low, MessagePriority); |
647 item.setData(ConvergedMessage::Low, MessagePriority); |
368 } |
648 } |
369 //subject |
|
370 item.setData(iMmsDataPlugin->subject(), Subject); |
|
371 } |
649 } |
372 |
650 |
373 //--------------------------------------------------------------- |
651 //--------------------------------------------------------------- |
374 // ConversationsModel::handleMMSNotification |
652 // ConversationsModel::handleMMSNotification |
375 // @see header |
653 // @see header |
376 //--------------------------------------------------------------- |
654 //--------------------------------------------------------------- |
377 void ConversationsModel::handleMMSNotification(QStandardItem& item, |
655 void ConversationsModel::handleMMSNotification(QStandardItem& item, |
378 const CCsConversationEntry& entry) |
656 const CCsConversationEntry& entry) |
379 { |
657 { |
380 // set context to current entry |
658 // set context to current entry |
381 mMsgStoreHandler->setNotificationMessageId(entry.EntryId()); |
659 TRAPD(err, mMsgStoreHandler->setNotificationMessageIdL(entry.EntryId())); |
382 |
660 if(err != KErrNone) |
|
661 { |
|
662 return; |
|
663 } |
|
664 |
383 // fetch relevent info to show in CV |
665 // fetch relevent info to show in CV |
384 // msg size |
666 // msg size |
385 QString estimatedMsgSizeStr = |
667 QString estimatedMsgSizeStr = QString("%1").arg(0); |
386 mMsgStoreHandler->NotificationMsgSize(); |
668 estimatedMsgSizeStr.append(" Kb"); |
387 |
669 TRAP_IGNORE(estimatedMsgSizeStr = |
|
670 mMsgStoreHandler->NotificationMsgSizeL()); |
|
671 |
388 // msg class type |
672 // msg class type |
389 QString classInfoStr = mMsgStoreHandler->NotificationClass(); |
673 QString classInfoStr = mMsgStoreHandler->NotificationClass(); |
390 |
674 |
391 // notification expiry date |
675 // notification expiry date |
392 //TODO: Need to do localization of digits used to show expiry time |
676 //TODO: Need to do localization of digits used to show expiry time |
393 TTime expiryTime; |
677 TTime expiryTime; |
394 QString expiryTimeStr; |
678 QString expiryTimeStr; |
395 mMsgStoreHandler->NotificationExpiryDate(expiryTime, expiryTimeStr); |
679 mMsgStoreHandler->NotificationExpiryDate(expiryTime, expiryTimeStr); |
396 |
680 |
397 // notification state e.g. waiting, retrieving etc |
681 // notification state e.g. waiting, retrieving etc |
398 QString statusStr; |
682 QString statusStr; |
399 int status; |
683 int status; |
400 mMsgStoreHandler->NotificationStatus(status, statusStr); |
684 mMsgStoreHandler->NotificationStatus(status, statusStr); |
401 |
685 |
402 // create data for bodytext role |
686 // create data for bodytext role |
403 QString dataText; |
687 QString dataText; |
404 dataText.append("Size: "); // TODO: use logical str name |
688 dataText.append("Size: "); // TODO: use logical str name |
405 dataText.append(estimatedMsgSizeStr); |
689 dataText.append(estimatedMsgSizeStr); |
406 dataText.append(QChar::LineSeparator); |
690 dataText.append(QChar::LineSeparator); |
480 if (iBioMsgPlugin->attachmentCount() > 0) { |
765 if (iBioMsgPlugin->attachmentCount() > 0) { |
481 UniMessageInfoList attList = iBioMsgPlugin->attachmentList(); |
766 UniMessageInfoList attList = iBioMsgPlugin->attachmentList(); |
482 QString attachmentPath = attList[0]->path(); |
767 QString attachmentPath = attList[0]->path(); |
483 |
768 |
484 //get display-name and set as bodytext |
769 //get display-name and set as bodytext |
485 QString displayName = ConversationsEngineUtility::getVcardDisplayName(attachmentPath); |
770 QString displayName = |
|
771 MsgContactHandler::getVCardDisplayName( |
|
772 attachmentPath); |
486 item.setData(displayName, BodyText); |
773 item.setData(displayName, BodyText); |
|
774 item.setData(attachmentPath, Attachments); |
487 |
775 |
488 // clear attachement list : its allocated at data model |
776 // clear attachement list : its allocated at data model |
489 while (!attList.isEmpty()) { |
777 while (!attList.isEmpty()) { |
490 delete attList.takeFirst(); |
778 delete attList.takeFirst(); |
491 } |
779 } |
492 } |
780 } |
493 } |
781 } |
494 else if (ConvergedMessage::VCal == msgSubType) { |
782 else if (ConvergedMessage::VCal == msgSubType) { |
495 //not supported |
783 //not supported |
|
784 } |
|
785 else if (ConvergedMessage::RingingTone == msgSubType) { |
|
786 if (iBioMsgPlugin->attachmentCount() > 0) { |
|
787 UniMessageInfoList attList = iBioMsgPlugin->attachmentList(); |
|
788 QString attachmentPath = attList[0]->path(); |
|
789 |
|
790 //get tone title, and set as bodytext |
|
791 RingBc ringBc; |
|
792 item.setData(ringBc.toneTitle(attachmentPath), BodyText); |
|
793 while (!attList.isEmpty()) { |
|
794 delete attList.takeFirst(); |
|
795 } |
|
796 } |
|
797 |
496 } |
798 } |
497 else { |
799 else { |
498 // description |
800 // description |
499 HBufC* description = entry.Description(); |
801 HBufC* description = entry.Description(); |
500 QString subject(""); |
802 QString subject(""); |
501 if (description && description->Length()) { |
803 if (description && description->Length()) { |
502 subject = (S60QConversions::s60DescToQString(*description)); |
804 subject = (XQConversions::s60DescToQString(*description)); |
503 item.setData(subject, BodyText); |
805 item.setData(subject, BodyText); |
504 } |
806 } |
505 } |
807 } |
506 } |
808 } |
507 |
809 |
|
810 //--------------------------------------------------------------- |
|
811 // ConversationsModel::getDBHandle() |
|
812 // @see header |
|
813 //--------------------------------------------------------------- |
|
814 RSqlDatabase& ConversationsModel::getDBHandle(TBool& isOpen) |
|
815 { |
|
816 isOpen = iSqlDbOpen; |
|
817 return iSqlDb; |
|
818 } |
|
819 |
|
820 //--------------------------------------------------------------- |
|
821 // ConversationsModel::setPreviewIcon() |
|
822 // @see header |
|
823 //--------------------------------------------------------------- |
|
824 void ConversationsModel::setPreviewIcon(QPixmap& pixmap, QString& filePath, |
|
825 int msgId, bool inDb) |
|
826 { |
|
827 |
|
828 //Since the population happens in reverse this check is needed so that |
|
829 //most recent items have their icons present in cache |
|
830 if (previewIconCache.totalCost() >= previewIconCache.maxCost()) |
|
831 return; |
|
832 |
|
833 // if not found in db, set from file path |
|
834 if (!inDb) |
|
835 { |
|
836 QPixmap pixmap(filePath); |
|
837 QPixmap scaledPixmap = pixmap.scaled(KWidth, KHeight, Qt::IgnoreAspectRatio); |
|
838 HbIcon *previewIcon = new HbIcon(scaledPixmap); |
|
839 |
|
840 previewIconCache.insert(msgId, previewIcon); |
|
841 |
|
842 } |
|
843 else |
|
844 { |
|
845 HbIcon *previewIcon = new HbIcon(pixmap); |
|
846 previewIconCache.insert(msgId, previewIcon); |
|
847 } |
|
848 } |
|
849 |
|
850 //--------------------------------------------------------------- |
|
851 // ConversationsModel::getPreviewIconItem() |
|
852 // @see header |
|
853 //--------------------------------------------------------------- |
|
854 HbIcon* ConversationsModel::getPreviewIconItem(int msgId, |
|
855 QString& filepath) const |
|
856 { |
|
857 QCRITICAL_WRITE("ConversationsModel::getPreviewIconItem start.") |
|
858 |
|
859 //Initialize icon from the Cache will be NULL if Item not present |
|
860 HbIcon* previewIcon = previewIconCache[msgId]; |
|
861 if (!previewIcon) |
|
862 { |
|
863 //This is done in this way as non-const function call cant be done here |
|
864 emit retrievePreviewIcon(msgId, filepath); |
|
865 |
|
866 previewIcon = previewIconCache[msgId]; |
|
867 } |
|
868 |
|
869 QCRITICAL_WRITE("ConversationsModel::getPreviewIconItem start.") |
|
870 |
|
871 return previewIcon; |
|
872 } |
|
873 |
|
874 //--------------------------------------------------------------- |
|
875 // ConversationsModel::updatePreviewIcon() |
|
876 // @see header |
|
877 //--------------------------------------------------------------- |
|
878 void ConversationsModel::updatePreviewIcon(int msgId, QString& filePath) |
|
879 { |
|
880 QCRITICAL_WRITE("ConversationsModel::updatePreviewIcon start.") |
|
881 |
|
882 //sql query to get preview-icon from DB |
|
883 bool imagePreviewed = false; |
|
884 QPixmap pixmap; |
|
885 |
|
886 if (iSqlDbOpen) |
|
887 { |
|
888 RSqlStatement sqlSelectPreviewIconStmt; |
|
889 TInt err = sqlSelectPreviewIconStmt.Prepare(iSqlDb, |
|
890 KSelectPreviewIconStmt); |
|
891 |
|
892 QCRITICAL_WRITE_FORMAT("Error from Prepare()", err) |
|
893 |
|
894 if (err == KErrNone) |
|
895 { |
|
896 //msg_id |
|
897 TInt msgIdIndex = sqlSelectPreviewIconStmt.ParameterIndex( |
|
898 _L(":message_id")); |
|
899 sqlSelectPreviewIconStmt.BindInt(msgIdIndex, msgId); |
|
900 |
|
901 // get preview-icon from DB |
|
902 err = sqlSelectPreviewIconStmt.Next(); |
|
903 QCRITICAL_WRITE_FORMAT("Error from Next()", err) |
|
904 |
|
905 if (err == KSqlAtRow) |
|
906 { |
|
907 TInt previewIconIndex = sqlSelectPreviewIconStmt.ColumnIndex( |
|
908 _L("preview_icon")); |
|
909 |
|
910 RSqlColumnReadStream stream; |
|
911 |
|
912 //Get data from binary column BLOB |
|
913 err = stream.ColumnBinary(sqlSelectPreviewIconStmt, |
|
914 previewIconIndex); |
|
915 |
|
916 QCRITICAL_WRITE_FORMAT("Error from ColumnBinary()", err) |
|
917 |
|
918 if (err == KErrNone) |
|
919 { |
|
920 CFbsBitmap *bitmap = new CFbsBitmap; |
|
921 TRAPD(err,bitmap->InternalizeL(stream)); |
|
922 QCRITICAL_WRITE_FORMAT("Error from bitmap InternalizeL()", err) |
|
923 |
|
924 //convert bitmap to pixmap |
|
925 if (err == KErrNone) |
|
926 { |
|
927 TSize size = bitmap->SizeInPixels(); |
|
928 int bytesPerLine = bitmap->ScanLineLength(size.iWidth, |
|
929 bitmap->DisplayMode()); |
|
930 const uchar* dataPtr = |
|
931 (const uchar*) bitmap->DataAddress(); |
|
932 |
|
933 pixmap = QPixmap::fromImage(QImage(dataPtr, |
|
934 size.iWidth, size.iHeight, bytesPerLine, |
|
935 QImage::Format_RGB16)); |
|
936 |
|
937 imagePreviewed = true; |
|
938 |
|
939 QCRITICAL_WRITE("Bitmap Conversion completed") |
|
940 } |
|
941 //remove bitmap |
|
942 delete bitmap; |
|
943 } |
|
944 //close stream |
|
945 stream.Close(); |
|
946 } |
|
947 } |
|
948 sqlSelectPreviewIconStmt.Close(); |
|
949 } |
|
950 |
|
951 // if not found in db, set from file path |
|
952 if (!imagePreviewed) |
|
953 { |
|
954 QPixmap orgPixmap(filePath); |
|
955 pixmap = orgPixmap.scaled(63.65, 63.65, Qt::IgnoreAspectRatio); |
|
956 } |
|
957 HbIcon * previewIcon = new HbIcon(pixmap); |
|
958 |
|
959 previewIconCache.insert(msgId, previewIcon); |
|
960 |
|
961 QCRITICAL_WRITE("ConversationsModel::updatePreviewIcon end.") |
|
962 |
|
963 } |
|
964 |
|
965 //--------------------------------------------------------------- |
|
966 // ConversationsModel::clearModel() |
|
967 // @see header |
|
968 //--------------------------------------------------------------- |
|
969 void ConversationsModel::clearModel() |
|
970 { |
|
971 clear(); |
|
972 previewIconCache.clear(); |
|
973 } |
|
974 |
|
975 void ConversationsModel:: emitConversationViewEmpty() |
|
976 { |
|
977 emit conversationViewEmpty(); |
|
978 } |
508 //EOF |
979 //EOF |