messagingapp/msgui/appengine/src/conversationssummarymodel.cpp
changeset 37 518b245aa84c
parent 25 84d9eb65b26f
child 41 25fe1fe642e3
equal deleted inserted replaced
25:84d9eb65b26f 37:518b245aa84c
    16  */
    16  */
    17 
    17 
    18 #include "conversationssummarymodel.h"
    18 #include "conversationssummarymodel.h"
    19 #include "conversationsenginedefines.h"
    19 #include "conversationsenginedefines.h"
    20 #include "conversationsengineutility.h"
    20 #include "conversationsengineutility.h"
    21 #include "s60qconversions.h"
    21 #include <xqconversions.h>
    22 #include "convergedmessage.h"
    22 #include "convergedmessage.h"
    23 #include "unidatamodelloader.h"
    23 #include "unidatamodelloader.h"
    24 #include "unidatamodelplugininterface.h"
    24 #include "unidatamodelplugininterface.h"
       
    25 #include "ringbc.h"
       
    26 #include "msgcontacthandler.h"
       
    27 #include "debugtraces.h"
    25 
    28 
    26 #include <ccsclientconversation.h>
    29 #include <ccsclientconversation.h>
    27 #include <ccsconversationentry.h>
    30 #include <ccsconversationentry.h>
    28 #include <QFile>
    31 #include <QFile>
    29 #include <QFileInfo>
    32 #include <QFileInfo>
    33 // @see header
    36 // @see header
    34 //---------------------------------------------------------------
    37 //---------------------------------------------------------------
    35 ConversationsSummaryModel::ConversationsSummaryModel(QObject* parent)
    38 ConversationsSummaryModel::ConversationsSummaryModel(QObject* parent)
    36 :QStandardItemModel(parent)
    39 :QStandardItemModel(parent)
    37     {
    40     {
       
    41     QStandardItemModel::setSortRole(TimeStamp);
       
    42     QStandardItemModel::sort(0, Qt::DescendingOrder);
    38     }
    43     }
    39 
    44 
    40 //---------------------------------------------------------------
    45 //---------------------------------------------------------------
    41 // ConversationsSummaryModel::~ConversationsSummaryModel
    46 // ConversationsSummaryModel::~ConversationsSummaryModel
    42 // @see header
    47 // @see header
   151 //---------------------------------------------------------------
   156 //---------------------------------------------------------------
   152 // ConversationsSummaryModel::addRow
   157 // ConversationsSummaryModel::addRow
   153 // @see header
   158 // @see header
   154 //---------------------------------------------------------------
   159 //---------------------------------------------------------------
   155 void ConversationsSummaryModel::addRow(
   160 void ConversationsSummaryModel::addRow(
   156         const CCsClientConversation& conversation)
   161         const CCsClientConversation& conversation, bool caching)
   157     {  
   162     {  
   158     int convId = conversation.GetConversationEntryId();
   163     int convId = conversation.GetConversationEntryId();
   159     
   164     
   160     //match convId in model, if found update else add item
   165     //match convId in model, if found update else add item
   161     QModelIndexList indexList = this->match(index(0, 0), 
   166     QModelIndexList indexList = this->match(index(0, 0), 
   173     {
   178     {
   174         // Update an existing item
   179         // Update an existing item
   175         QModelIndex index = indexList[0];
   180         QModelIndex index = indexList[0];
   176         QStandardItem* item = this->item(index.row(), 0);
   181         QStandardItem* item = this->item(index.row(), 0);
   177         populateItem(*item,conversation);
   182         populateItem(*item,conversation);
   178     }        
   183     }  
       
   184     // no need to sort if it is initial caching, as sorting is already done
       
   185     if (!caching)
       
   186         {
       
   187         QStandardItemModel::sort(0, Qt::DescendingOrder);
       
   188         }
   179     }
   189     }
   180 
   190 
   181 //---------------------------------------------------------------
   191 //---------------------------------------------------------------
   182 // ConversationsSummaryModel::deleteRow
   192 // ConversationsSummaryModel::deleteRow
   183 // @see header
   193 // @see header
   201 // @see header
   211 // @see header
   202 //---------------------------------------------------------------
   212 //---------------------------------------------------------------
   203 void ConversationsSummaryModel::populateItem(QStandardItem& item, 
   213 void ConversationsSummaryModel::populateItem(QStandardItem& item, 
   204         const CCsClientConversation& conversation)
   214         const CCsClientConversation& conversation)
   205     {
   215     {
       
   216     QCRITICAL_WRITE("ConversationsSummaryModel::populateItem start.");
       
   217             
   206     //get entry
   218     //get entry
   207     CCsConversationEntry* conEntry = conversation.GetConversationEntry(); 
   219     CCsConversationEntry* conEntry = conversation.GetConversationEntry(); 
   208     //error scenario
   220     //error scenario
   209     if(conEntry == NULL)
   221     if(conEntry == NULL)
   210         return;
   222         return;
   237     {       
   249     {       
   238         // description
   250         // description
   239         HBufC* body = conEntry->Description();
   251         HBufC* body = conEntry->Description();
   240         if( body && body->Length())
   252         if( body && body->Length())
   241         {     
   253         {     
   242             QString bodytext(S60QConversions::s60DescToQString(*body));
   254             QString bodytext(XQConversions::s60DescToQString(*body));
   243             item.setData(bodytext, BodyText); 
   255             item.setData(bodytext, BodyText); 
   244             item.setData(bodytext, Subject );
   256             item.setData(bodytext, Subject );
   245         }
   257         }
   246     }
   258     }
   247 
   259 
   260     HBufC* disName = conversation.GetDisplayName(); 
   272     HBufC* disName = conversation.GetDisplayName(); 
   261     QString displayName("");
   273     QString displayName("");
   262     //display name
   274     //display name
   263     if(disName && disName->Length())
   275     if(disName && disName->Length())
   264         {
   276         {
   265         displayName = S60QConversions::s60DescToQString(*disName);
   277         displayName = XQConversions::s60DescToQString(*disName);
   266         item.setData(displayName,DisplayName); 
   278         item.setData(displayName,DisplayName); 
   267         }
   279         }
   268     
   280     
   269     // contact number
   281     // contact number
   270     HBufC* contactno = conEntry->Contact();
   282     HBufC* contactno = conEntry->Contact();
   271     QString contactNumber("");
   283     QString contactNumber("");
   272     if ( contactno && contactno->Length() )
   284     if ( contactno && contactno->Length() )
   273         {
   285         {
   274         contactNumber = S60QConversions::s60DescToQString(*contactno);                  
   286         contactNumber = XQConversions::s60DescToQString(*contactno);                  
   275         }        
   287         }        
   276     item.setData(contactNumber, ConversationAddress);
   288     item.setData(contactNumber, ConversationAddress);
   277 
   289 
   278     //set the contactId
   290     //set the contactId
   279     int contactId = conversation.GetContactId();
   291     int contactId = conversation.GetContactId();
   280     item.setData(contactId, ContactId);
   292     item.setData(contactId, ContactId);
   281     
   293     
   282     // unread status        
   294     // unread status        
   283     item.setData(conEntry->IsAttributeSet(ECsAttributeUnread),UnReadStatus);      
   295     item.setData(conEntry->IsAttributeSet(ECsAttributeUnread),UnReadStatus); 
       
   296     
       
   297     QCRITICAL_WRITE("ConversationsSummaryModel::populateItem start.");
   284     }
   298     }
   285 
   299 
   286 
   300 
   287 //---------------------------------------------------------------
   301 //---------------------------------------------------------------
   288 // ConversationsModel::handleBlueToothMessages
   302 // ConversationsModel::handleBlueToothMessages
   291 void ConversationsSummaryModel::handleBlueToothMessages(QStandardItem& item,
   305 void ConversationsSummaryModel::handleBlueToothMessages(QStandardItem& item,
   292     const CCsConversationEntry& entry)
   306     const CCsConversationEntry& entry)
   293 {
   307 {
   294     //TODO, needs to be revisited again, once BT team provides the solution for
   308     //TODO, needs to be revisited again, once BT team provides the solution for
   295     //BT received as Biomsg issue.
   309     //BT received as Biomsg issue.
   296     QString description = S60QConversions::s60DescToQString(*(entry.Description()));
   310     QString description = XQConversions::s60DescToQString(*(entry.Description()));
   297 
   311 
   298     if (description.contains(".vcf") || description.contains(".ics")) // "vCard"
   312     if (description.contains(".vcf") || description.contains(".ics")) // "vCard"
   299     {
   313     {
   300         //message sub-type
   314         //message sub-type
   301         item.setData(ConvergedMessage::VCard, MessageSubType);
   315         item.setData(ConvergedMessage::VCard, MessageSubType);
   302 
   316 
   303         //parse vcf file to get the details
   317         //parse vcf file to get the details
   304         QString displayName = ConversationsEngineUtility::getVcardDisplayName(description);
   318         QString displayName = MsgContactHandler::getVCardDisplayName(
       
   319                 description);
   305         item.setData(displayName, BodyText);
   320         item.setData(displayName, BodyText);
   306     }
   321     }
   307     else 
   322     else 
   308     {
   323     {
   309         if (description.contains(".vcs")) // "vCalendar"
   324         if (description.contains(".vcs")) // "vCalendar"
   339         if (bioMsgPlugin->attachmentCount() > 0) {
   354         if (bioMsgPlugin->attachmentCount() > 0) {
   340             UniMessageInfoList attList = bioMsgPlugin->attachmentList();
   355             UniMessageInfoList attList = bioMsgPlugin->attachmentList();
   341             QString attachmentPath = attList[0]->path();
   356             QString attachmentPath = attList[0]->path();
   342 
   357 
   343             //get display-name and set as bodytext
   358             //get display-name and set as bodytext
   344             QString displayName = ConversationsEngineUtility::getVcardDisplayName(attachmentPath);
   359             QString displayName = MsgContactHandler::getVCardDisplayName(
       
   360                     attachmentPath);
   345             item.setData(displayName, BodyText);
   361             item.setData(displayName, BodyText);
   346 
   362 
   347             // clear attachement list : its allocated at data model
   363             // clear attachement list : its allocated at data model
   348             while (!attList.isEmpty()) {
   364             while (!attList.isEmpty()) {
   349                 delete attList.takeFirst();
   365                 delete attList.takeFirst();
   351         }
   367         }
   352     }
   368     }
   353     else if (ConvergedMessage::VCal == msgSubType) {
   369     else if (ConvergedMessage::VCal == msgSubType) {
   354         //not supported
   370         //not supported
   355     }
   371     }
   356     else {
   372     else if (ConvergedMessage::RingingTone == msgSubType) {
       
   373         if (bioMsgPlugin->attachmentCount() > 0) {
       
   374             UniMessageInfoList attList = bioMsgPlugin->attachmentList();
       
   375             QString attachmentPath = attList[0]->path();
       
   376             	
       
   377             //get tone title, and set as bodytext
       
   378             RingBc ringBc;
       
   379             item.setData(ringBc.toneTitle(attachmentPath), BodyText);
       
   380             while (!attList.isEmpty()) {
       
   381                 delete attList.takeFirst();
       
   382             }
       
   383         }
       
   384     }
       
   385 
       
   386    else if(ConvergedMessage::NokiaService == msgSubType){
       
   387         // This is a bio message so lets parse it and see if it has a associated attachment ..        
       
   388         if (bioMsgPlugin->attachmentCount() > 0) {
       
   389 				// TODO : need to confirm if we need to read from attachment
       
   390         }
       
   391         else {// description
       
   392             HBufC* description = entry.Description();
       
   393             QString subject("");
       
   394             if (description && description->Length()) {
       
   395                 subject = (XQConversions::s60DescToQString(*description));
       
   396                 item.setData(subject, BodyText);
       
   397             }
       
   398 
       
   399         }
       
   400 
       
   401     }
       
   402 
       
   403    else {
   357         // description
   404         // description
   358         HBufC* description = entry.Description();
   405         HBufC* description = entry.Description();
   359         QString subject("");
   406         QString subject("");
   360         if (description && description->Length()) {
   407         if (description && description->Length()) {
   361             subject = (S60QConversions::s60DescToQString(*description));
   408             subject = (XQConversions::s60DescToQString(*description));
   362             item.setData(subject, BodyText);
   409             item.setData(subject, BodyText);
   363         }
   410         }
   364     }
   411     }
   365     
   412     
   366     delete pluginLoader;
   413     delete pluginLoader;