messagingapp/msgui/appengine/src/conversationsmodel.cpp
branchGCC_SURGE
changeset 47 5b14749788d7
parent 27 e4592d119491
parent 44 36f374c67aa8
equal deleted inserted replaced
35:a32b19fb291e 47:5b14749788d7
    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"
    26 #include "ringbc.h"
    27 #include "msgcontacthandler.h"
    27 #include "msgcontacthandler.h"
       
    28 #include "mmsconformancecheck.h"
    28 #include <ccsconversationentry.h>
    29 #include <ccsconversationentry.h>
       
    30 #include <fileprotectionresolver.h>
    29 
    31 
    30 #include "debugtraces.h"
    32 #include "debugtraces.h"
    31 
    33 
    32 #include <QFile>
    34 #include <QFile>
    33 #include <QFileInfo>
    35 #include <QFileInfo>
    34 #include <s32mem.h>
    36 #include <s32mem.h>
       
    37 #include <s32strm.h>
       
    38 #include <fbs.h>
    35 #include <ccsdefs.h>
    39 #include <ccsdefs.h>
    36 
    40 
    37 //CONSTANTS
    41 //CONSTANTS
    38 _LIT(KDbFileName, "c:[2002A542]conversations.db");
    42 _LIT(KDbFileName, "c:[2002A542]conversations.db");
       
    43 
    39 // preview sql query
    44 // preview sql query
    40 _LIT(KSelectConvMsgsStmt, "SELECT message_id, subject, body_text, preview_path, msg_property FROM conversation_messages WHERE message_id=:message_id ");
    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 ");
    41 
    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;
    42 //---------------------------------------------------------------
    55 //---------------------------------------------------------------
    43 // ConversationsModel::ConversationsModel
    56 // ConversationsModel::ConversationsModel
    44 // Constructor
    57 // Constructor
    45 //---------------------------------------------------------------
    58 //---------------------------------------------------------------
    46 ConversationsModel::ConversationsModel(ConversationMsgStoreHandler* msgStoreHandler,
    59 ConversationsModel::ConversationsModel(ConversationMsgStoreHandler* msgStoreHandler,
    50     //Open SQL DB
    63     //Open SQL DB
    51     if (KErrNone == iSqlDb.Open(KDbFileName))
    64     if (KErrNone == iSqlDb.Open(KDbFileName))
    52     {
    65     {
    53         iSqlDbOpen = ETrue;
    66         iSqlDbOpen = ETrue;
    54     }
    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)
    55     iDataModelPluginLoader = new UniDataModelLoader;
    73     iDataModelPluginLoader = new UniDataModelLoader;
    56     iMmsDataPlugin = iDataModelPluginLoader->getDataModelPlugin(ConvergedMessage::Mms);
    74     iMmsDataPlugin = iDataModelPluginLoader->getDataModelPlugin(ConvergedMessage::Mms);
    57     iBioMsgPlugin = iDataModelPluginLoader->getDataModelPlugin(ConvergedMessage::BioMsg);
    75     iBioMsgPlugin = iDataModelPluginLoader->getDataModelPlugin(ConvergedMessage::BioMsg);
    58 }
    76 }
    59 
    77 
    63 //---------------------------------------------------------------
    81 //---------------------------------------------------------------
    64 ConversationsModel::~ConversationsModel()
    82 ConversationsModel::~ConversationsModel()
    65 {
    83 {
    66     //Close SQL-DB
    84     //Close SQL-DB
    67     iSqlDb.Close();
    85     iSqlDb.Close();
       
    86 
       
    87 	//clear preview-cache
       
    88     previewIconCache.clear();
    68 
    89 
    69     if (iDataModelPluginLoader) {
    90     if (iDataModelPluginLoader) {
    70         delete iDataModelPluginLoader;
    91         delete iDataModelPluginLoader;
    71         iDataModelPluginLoader = NULL;
    92         iDataModelPluginLoader = NULL;
    72     }
    93     }
   144     case SendingState:
   165     case SendingState:
   145     {
   166     {
   146         value = item->data(SendingState);
   167         value = item->data(SendingState);
   147         break;
   168         break;
   148     }
   169     }
       
   170     case PreviewIcon:
       
   171     {
       
   172         QString filepath(item->data(Attachments).toString());
       
   173         int msgId = item->data(ConvergedMsgId).toInt();
       
   174         HbIcon *icon = getPreviewIconItem(msgId, filepath);
       
   175         return *icon;
       
   176     }
   149     case MessagePriority:
   177     case MessagePriority:
   150     {
   178     {
   151         value = item->data(MessagePriority);
   179         value = item->data(MessagePriority);
   152         break;
   180         break;
   153     }
   181     }
   176         value = item->data(UnreadCount);
   204         value = item->data(UnreadCount);
   177         break;
   205         break;
   178     }
   206     }
   179     case DisplayName: // Fall through start
   207     case DisplayName: // Fall through start
   180         value = item->data(DisplayName);
   208         value = item->data(DisplayName);
   181         break;    
   209         break;
   182     case Avatar: // Fall througn end
   210     case Avatar: // Fall througn end
   183         value = item->data(Avatar);
   211         value = item->data(Avatar);
   184         break;
   212         break;
   185     case NotificationStatus:
   213     case NotificationStatus:
   186         value = item->data(NotificationStatus);
   214         value = item->data(NotificationStatus);
   270 
   298 
   271     // description
   299     // description
   272     HBufC* description = entry.Description();
   300     HBufC* description = entry.Description();
   273     QString subject("");
   301     QString subject("");
   274     if (description && description->Length()) {
   302     if (description && description->Length()) {
   275         subject = (S60QConversions::s60DescToQString(*description));     
   303         subject = (XQConversions::s60DescToQString(*description));     
   276     }
   304     }
   277 
   305 
   278     // time stamp 
   306     // time stamp
   279     TTime unixEpoch(KUnixEpoch);
   307     TTime unixEpoch(KUnixEpoch);
   280     TTimeIntervalSeconds seconds;
   308     TTimeIntervalSeconds seconds;
   281     TTime timeStamp(entry.TimeStamp());
   309     TTime timeStamp(entry.TimeStamp());
   282     timeStamp.SecondsFrom(unixEpoch, seconds);
   310     timeStamp.SecondsFrom(unixEpoch, seconds);
   283     item.setData(seconds.Int(), TimeStamp);
   311     item.setData(seconds.Int(), TimeStamp);
   284 
   312 
   285     //contact details
   313     //contact details
   286     HBufC* contact = entry.Contact();
   314     HBufC* contact = entry.Contact();
   287     if (contact && contact->Length()) {
   315     if (contact && contact->Length()) {
   288         item.setData(S60QConversions::s60DescToQString(*contact), ConversationAddress);
   316         item.setData(XQConversions::s60DescToQString(*contact), ConversationAddress);
   289     }
   317     }
   290 
   318 
   291     // message type.
   319     // message type.
   292     int msgType = ConversationsEngineUtility::messageType(entry.GetType());
   320     int msgType = ConversationsEngineUtility::messageType(entry.GetType());
   293     item.setData(msgType, MessageType);
   321     item.setData(msgType, MessageType);
   320     }
   348     }
   321     else {
   349     else {
   322         item.setData(ConvergedMessage::Outbox, MessageLocation);
   350         item.setData(ConvergedMessage::Outbox, MessageLocation);
   323     }
   351     }
   324 
   352 
   325     //message specific handling    
   353     //message specific handling
   326     if (msgType == ConvergedMessage::Mms) {
   354     if (msgType == ConvergedMessage::Mms) {
   327         QCRITICAL_WRITE("ConversationsModel::populateItem  MMS start.")
   355         QCRITICAL_WRITE("ConversationsModel::populateItem  MMS start.")
   328         handleMMS(item, entry);
   356         handleMMS(item, entry);
   329         QCRITICAL_WRITE("ConversationsModel::populateItem MMS end.")
   357         QCRITICAL_WRITE("ConversationsModel::populateItem MMS end.")
   330     }
   358     }
   345 
   373 
   346     QCRITICAL_WRITE("ConversationsModel::populateItem end.");
   374     QCRITICAL_WRITE("ConversationsModel::populateItem end.");
   347 }
   375 }
   348 
   376 
   349 //---------------------------------------------------------------
   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 
       
   392 
       
   393 //---------------------------------------------------------------
   350 // ConversationsModel::handleMMS
   394 // ConversationsModel::handleMMS
   351 // @see header
   395 // @see header
   352 //---------------------------------------------------------------
   396 //---------------------------------------------------------------
   353 void ConversationsModel::handleMMS(QStandardItem& item, const CCsConversationEntry& entry)
   397 void ConversationsModel::handleMMS(QStandardItem& item, const CCsConversationEntry& entry)
   354 {
   398 {
   355     //msg_id
   399     //msg_id
   356     int msgId = entry.EntryId();
   400     int msgId = entry.EntryId();
   357 
   401 
   358     bool isEntryInDb = false;
   402     bool isEntryInDb = false;
   359     TInt err = KErrNone;
   403     TInt err = KErrNone;
   360     
   404 
   361     //check if db is open and query db
   405     //check if db is open and query db
   362     if (iSqlDbOpen)
   406     if (iSqlDbOpen)
   363     {
   407     {
   364         RSqlStatement sqlSelectStmt;
   408         RSqlStatement sqlSelectStmt;
   365         err = sqlSelectStmt.Prepare(iSqlDb, KSelectConvMsgsStmt);
   409         err = sqlSelectStmt.Prepare(iSqlDb, KSelectConvMsgsStmt);
   366 
   410 
   367         // move to fallback option
   411         // move to fallback option
   368         if (KErrNone == err)
   412         if (KErrNone == err)
   369             {
   413             {
   370             TInt msgIdIndex = sqlSelectStmt.ParameterIndex(_L(":message_id"));
   414             TInt msgIdIndex = sqlSelectStmt.ParameterIndex(_L(":message_id"));
       
   415             TInt msgProcessingStateIndex = sqlSelectStmt.ColumnIndex(_L("msg_processingstate"));
   371             TInt subjectIndex = sqlSelectStmt.ColumnIndex(_L("subject"));
   416             TInt subjectIndex = sqlSelectStmt.ColumnIndex(_L("subject"));
   372             TInt bodyIndex = sqlSelectStmt.ColumnIndex(_L("body_text"));
   417             TInt bodyIndex = sqlSelectStmt.ColumnIndex(_L("body_text"));
   373             TInt previewPathIndex = sqlSelectStmt.ColumnIndex(
   418             TInt previewPathIndex = sqlSelectStmt.ColumnIndex(
   374                     _L("preview_path"));
   419                     _L("preview_path"));
   375             TInt msgpropertyIndex = sqlSelectStmt.ColumnIndex(
   420             TInt msgpropertyIndex = sqlSelectStmt.ColumnIndex(
   376                     _L("msg_property"));
   421                 _L("msg_property"));
       
   422             TInt previewIconIndex = sqlSelectStmt.ColumnIndex(
       
   423                 _L("preview_icon"));
   377 
   424 
   378             err = sqlSelectStmt.BindInt(msgIdIndex, msgId);
   425             err = sqlSelectStmt.BindInt(msgIdIndex, msgId);
   379             
   426 
   380             // populate item
   427             // populate item
   381             if ((KErrNone == err) && (sqlSelectStmt.Next() == KSqlAtRow))
   428             if ((KErrNone == err) && (sqlSelectStmt.Next() == KSqlAtRow))
   382                 {
   429                 {
   383                 RBuf subjectBuffer;
   430                 int msgProcessingState = 0;
   384                 subjectBuffer.Create(sqlSelectStmt.ColumnSize(subjectIndex));
   431                 msgProcessingState = sqlSelectStmt.ColumnInt(
   385                 sqlSelectStmt.ColumnText(subjectIndex, subjectBuffer);
   432                         msgProcessingStateIndex);
   386 
   433                 if (msgProcessingState == EPreviewMsgProcessed)
   387                 item.setData(
   434                     {
   388                         S60QConversions::s60DescToQString(subjectBuffer),
   435                     // use entry to populate model only when,
   389                         Subject);
   436                     // entry is present in DB and its processing is over.
   390                 subjectBuffer.Close();
   437                     RBuf subjectBuffer;
   391 
   438                     subjectBuffer.Create(sqlSelectStmt.ColumnSize(
   392                 RBuf bodyBuffer;
   439                             subjectIndex));
   393                 bodyBuffer.Create(sqlSelectStmt.ColumnSize(bodyIndex));
   440                     sqlSelectStmt.ColumnText(subjectIndex, subjectBuffer);
   394                 sqlSelectStmt.ColumnText(bodyIndex, bodyBuffer);
   441 
   395 
   442                     item.setData(XQConversions::s60DescToQString(
   396                 item.setData(S60QConversions::s60DescToQString(bodyBuffer),
   443                             subjectBuffer), Subject);
   397                         BodyText);
   444                     subjectBuffer.Close();
   398                 bodyBuffer.Close();
   445 
   399 
   446                     RBuf bodyBuffer;
   400                 RBuf previewPathBuffer;
   447                     bodyBuffer.Create(sqlSelectStmt.ColumnSize(bodyIndex));
   401                 previewPathBuffer.Create(sqlSelectStmt.ColumnSize(
   448                     sqlSelectStmt.ColumnText(bodyIndex, bodyBuffer);
   402                         previewPathIndex));
   449 
   403                 sqlSelectStmt.ColumnText(previewPathIndex, previewPathBuffer);
   450                     item.setData(
   404 
   451                             XQConversions::s60DescToQString(bodyBuffer),
   405                 //Rightnow set inside attachments
   452                             BodyText);
   406                 item.setData(S60QConversions::s60DescToQString(
   453                     bodyBuffer.Close();
   407                         previewPathBuffer), Attachments);
   454 
   408                 previewPathBuffer.Close();
   455                     RBuf previewPathBuffer;
   409 
   456                     previewPathBuffer.Create(sqlSelectStmt.ColumnSize(
   410                 int msgProperty = 0;
   457                             previewPathIndex));
   411                 msgProperty = sqlSelectStmt.ColumnInt(msgpropertyIndex);
   458                     sqlSelectStmt.ColumnText(previewPathIndex,
   412                 item.setData(msgProperty, MessageProperty);
   459                             previewPathBuffer);
   413 
   460 
   414                 //set flag to disable fallback option
   461                     //Rightnow set inside attachments
   415                 isEntryInDb = true;
   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                     }
   416                 }
   509                 }
   417             }
   510             }
   418         sqlSelectStmt.Close();
   511         sqlSelectStmt.Close();
   419         }
   512         }
   420 
   513 
   421     //fallback option incase of db operation failure or enry not found in DB
   514     //fallback option incase of db operation failure or enry not found in DB
   422     //populate from data plugins
   515     //populate from data plugins
   423     if (!isEntryInDb || err != KErrNone)
   516     if (!isEntryInDb || err != KErrNone)
   424     {
   517     {
   425         iMmsDataPlugin->setMessageId(entry.EntryId());
   518         int error = iMmsDataPlugin->setMessageId(entry.EntryId());
       
   519         if(error != KErrNone)
       
   520         {
       
   521             // skip all
       
   522             return;
       
   523         }
   426         int msgProperty = 0;
   524         int msgProperty = 0;
   427 
   525 
   428         if (iMmsDataPlugin->attachmentCount() > 0)
   526         if (iMmsDataPlugin->attachmentCount() > 0)
   429         {
   527         {
   430             msgProperty |= EPreviewAttachment;
   528             msgProperty |= EPreviewAttachment;
       
   529         }
       
   530 
       
   531         if(validateMsgForForward(entry.EntryId()))
       
   532         {
       
   533             msgProperty |= EPreviewForward;
   431         }
   534         }
   432 
   535 
   433         //subject
   536         //subject
   434         item.setData(iMmsDataPlugin->subject(), Subject);
   537         item.setData(iMmsDataPlugin->subject(), Subject);
   435 
   538 
   455                     textContent = file.readAll();
   558                     textContent = file.readAll();
   456                     item.setData(textContent, BodyText);
   559                     item.setData(textContent, BodyText);
   457                     isBodyTextSet = true;
   560                     isBodyTextSet = true;
   458                     file.close();
   561                     file.close();
   459                 }
   562                 }
   460                 if (!isImageSet && objectList[index]->mimetype().contains(
   563                 if (!isVideoSet && !isImageSet && objectList[index]->mimetype().contains(
   461                     "image"))
   564                     "image"))
   462                 {
   565                 {
   463                     isImageSet = true;
   566                     isImageSet = true;
   464                     msgProperty |= EPreviewImage;
   567                     msgProperty |= EPreviewImage;
       
   568                     if (objectList[index]->isProtected())
       
   569                     {
       
   570                         msgProperty |= EPreviewProtectedImage;
       
   571                     }
       
   572                     if (objectList[index]->isCorrupted())
       
   573                     {
       
   574                         msgProperty |= EPreviewCorruptedImage;
       
   575                     }
   465                     imagePath = objectList[index]->path();
   576                     imagePath = objectList[index]->path();
   466                 }
   577                 }
   467                 if (!isAudioSet && objectList[index]->mimetype().contains(
   578                 if (!isVideoSet && !isAudioSet && objectList[index]->mimetype().contains(
   468                     "audio"))
   579                     "audio"))
   469                 {
   580                 {
   470                     msgProperty |= EPreviewAudio;
   581                     msgProperty |= EPreviewAudio;
       
   582                     if (objectList[index]->isProtected())
       
   583                     {
       
   584                         msgProperty |= EPreviewProtectedAudio;
       
   585                     }
       
   586                     if (objectList[index]->isCorrupted())
       
   587                     {
       
   588                         msgProperty |= EPreviewCorruptedAudio;
       
   589                     }
   471                     isAudioSet = true;
   590                     isAudioSet = true;
   472                 }
   591                 }
   473                 if (!isVideoSet && objectList[index]->mimetype().contains(
   592                 if (!( isImageSet || isAudioSet) && !isVideoSet && objectList[index]->mimetype().contains(
   474                     "video"))
   593                     "video"))
   475                 {
   594                 {
   476                     isVideoSet = true;
   595                     isVideoSet = true;
   477                     msgProperty |= EPreviewVideo;
   596                     msgProperty |= EPreviewVideo;
       
   597                     if (objectList[index]->isProtected())
       
   598                     {
       
   599                         msgProperty |= EPreviewProtectedVideo;
       
   600                     }
       
   601                     if (objectList[index]->isCorrupted())
       
   602                     {
       
   603                         msgProperty |= EPreviewCorruptedVideo;
       
   604                     }
   478                     videoPath = objectList[index]->path();
   605                     videoPath = objectList[index]->path();
   479                 }
   606                 }
   480             }
   607             }
   481             foreach(UniMessageInfo* slide,objectList)
   608             foreach(UniMessageInfo* slide,objectList)
   482                 {
   609                 {
   483                     delete slide;
   610                     delete slide;
   484                 }
   611                 }
   485         }
   612         }
       
   613         QPixmap pixmap;
   486         //populate item  with the attachment list
   614         //populate item  with the attachment list
       
   615         //TODO: This code is not required bcoz video icon is show and not preview  
   487         if (isVideoSet)
   616         if (isVideoSet)
   488         {
   617         {
   489             item.setData(videoPath, Attachments);
   618             item.setData(videoPath, Attachments);
       
   619             // Store thumbnail only for non protected, non corrupted content.
       
   620             if (!(EPreviewProtectedVideo & msgProperty) &&
       
   621                 !(EPreviewCorruptedVideo & msgProperty))
       
   622             {
       
   623                 setPreviewIcon(pixmap, videoPath, msgId, false);
       
   624             }
   490         }
   625         }
   491         else if (isImageSet)
   626         else if (isImageSet)
   492         {
   627         {
   493             item.setData(imagePath, Attachments);
   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             }
   494         }
   635         }
   495         //populate msgProperty
   636         //populate msgProperty
   496         item.setData(msgProperty, MessageProperty);
   637         item.setData(msgProperty, MessageProperty);
   497     }
   638     }
   498 
   639 
   518     TRAPD(err, mMsgStoreHandler->setNotificationMessageIdL(entry.EntryId()));
   659     TRAPD(err, mMsgStoreHandler->setNotificationMessageIdL(entry.EntryId()));
   519     if(err != KErrNone)
   660     if(err != KErrNone)
   520     {
   661     {
   521         return;
   662         return;
   522     }
   663     }
   523     
   664 
   524     // fetch relevent info to show in CV
   665     // fetch relevent info to show in CV
   525     // msg size
   666     // msg size
   526     QString estimatedMsgSizeStr = QString("%1").arg(0);
   667     QString estimatedMsgSizeStr = QString("%1").arg(0);
   527     estimatedMsgSizeStr.append(" Kb");
   668     estimatedMsgSizeStr.append(" Kb");
   528     TRAP_IGNORE(estimatedMsgSizeStr = 
   669     TRAP_IGNORE(estimatedMsgSizeStr =
   529             mMsgStoreHandler->NotificationMsgSizeL());
   670             mMsgStoreHandler->NotificationMsgSizeL());
   530     
   671 
   531     // msg class type
   672     // msg class type
   532     QString classInfoStr = mMsgStoreHandler->NotificationClass();
   673     QString classInfoStr = mMsgStoreHandler->NotificationClass();
   533     
   674 
   534     // notification expiry date
   675     // notification expiry date
   535     //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
   536     TTime expiryTime;
   677     TTime expiryTime;
   537     QString expiryTimeStr;
   678     QString expiryTimeStr;
   538     mMsgStoreHandler->NotificationExpiryDate(expiryTime, expiryTimeStr);
   679     mMsgStoreHandler->NotificationExpiryDate(expiryTime, expiryTimeStr);
   539     
   680 
   540     // notification state e.g. waiting, retrieving etc
   681     // notification state e.g. waiting, retrieving etc
   541     QString statusStr;
   682     QString statusStr;
   542     int status;
   683     int status;
   543     mMsgStoreHandler->NotificationStatus(status, statusStr);
   684     mMsgStoreHandler->NotificationStatus(status, statusStr);
   544     
   685 
   545     // create data for bodytext role
   686     // create data for bodytext role
   546     QString dataText;
   687     QString dataText;
   547     dataText.append("Size: "); // TODO: use logical str name
   688     dataText.append("Size: "); // TODO: use logical str name
   548     dataText.append(estimatedMsgSizeStr);
   689     dataText.append(estimatedMsgSizeStr);
   549     dataText.append(QChar::LineSeparator);
   690     dataText.append(QChar::LineSeparator);
   578 void ConversationsModel::handleBlueToothMessages(QStandardItem& item,
   719 void ConversationsModel::handleBlueToothMessages(QStandardItem& item,
   579     const CCsConversationEntry& entry)
   720     const CCsConversationEntry& entry)
   580 {
   721 {
   581     //TODO, needs to be revisited again, once BT team provides the solution for
   722     //TODO, needs to be revisited again, once BT team provides the solution for
   582     //BT received as Biomsg issue.
   723     //BT received as Biomsg issue.
   583     QString description = S60QConversions::s60DescToQString(*(entry.Description()));
   724     QString description = XQConversions::s60DescToQString(*(entry.Description()));
   584 
   725 
   585     if (description.contains(".vcf") || description.contains(".ics")) // "vCard"
   726     if (description.contains(".vcf") || description.contains(".ics")) // "vCard"
   586     {
   727     {
   587         //message sub-type
   728         //message sub-type
   588         item.setData(ConvergedMessage::VCard, MessageSubType);
   729         item.setData(ConvergedMessage::VCard, MessageSubType);
   589 
   730 
   590         //parse vcf file to get the details
   731         //parse vcf file to get the details
   591         QString displayName = MsgContactHandler::getVCardDisplayName(
   732         QString displayName = MsgContactHandler::getVCardDisplayName(
   592                 description);
   733                 description);
   593         item.setData(displayName, BodyText);
   734         item.setData(displayName, BodyText);
   594     }    
   735     }
   595     else 
   736     else
   596     {
   737     {
   597         if (description.contains(".vcs")) // "vCalendar"
   738         if (description.contains(".vcs")) // "vCalendar"
   598         {
   739         {
   599             //message sub-type
   740             //message sub-type
   600             item.setData(ConvergedMessage::VCal, MessageSubType);
   741             item.setData(ConvergedMessage::VCal, MessageSubType);
   624         if (iBioMsgPlugin->attachmentCount() > 0) {
   765         if (iBioMsgPlugin->attachmentCount() > 0) {
   625             UniMessageInfoList attList = iBioMsgPlugin->attachmentList();
   766             UniMessageInfoList attList = iBioMsgPlugin->attachmentList();
   626             QString attachmentPath = attList[0]->path();
   767             QString attachmentPath = attList[0]->path();
   627 
   768 
   628             //get display-name and set as bodytext
   769             //get display-name and set as bodytext
   629             QString displayName = 
   770             QString displayName =
   630                     MsgContactHandler::getVCardDisplayName(
   771                     MsgContactHandler::getVCardDisplayName(
   631                             attachmentPath);
   772                             attachmentPath);
   632             item.setData(displayName, BodyText);
   773             item.setData(displayName, BodyText);
       
   774             item.setData(attachmentPath, Attachments);
   633 
   775 
   634             // clear attachement list : its allocated at data model
   776             // clear attachement list : its allocated at data model
   635             while (!attList.isEmpty()) {
   777             while (!attList.isEmpty()) {
   636                 delete attList.takeFirst();
   778                 delete attList.takeFirst();
   637             }
   779             }
   657     else {
   799     else {
   658         // description
   800         // description
   659         HBufC* description = entry.Description();
   801         HBufC* description = entry.Description();
   660         QString subject("");
   802         QString subject("");
   661         if (description && description->Length()) {
   803         if (description && description->Length()) {
   662             subject = (S60QConversions::s60DescToQString(*description));
   804             subject = (XQConversions::s60DescToQString(*description));
   663             item.setData(subject, BodyText);
   805             item.setData(subject, BodyText);
   664         }
   806         }
   665     }
   807     }
   666 }
   808 }
   667 
   809 
   672 RSqlDatabase& ConversationsModel::getDBHandle(TBool& isOpen)
   814 RSqlDatabase& ConversationsModel::getDBHandle(TBool& isOpen)
   673 {
   815 {
   674     isOpen = iSqlDbOpen;
   816     isOpen = iSqlDbOpen;
   675     return iSqlDb;
   817     return iSqlDb;
   676 }
   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 }
   677 //EOF
   979 //EOF