messagingapp/msgui/appengine/src/conversationssummarymodel.cpp
branchGCC_SURGE
changeset 47 5b14749788d7
parent 27 e4592d119491
parent 44 36f374c67aa8
equal deleted inserted replaced
35:a32b19fb291e 47:5b14749788d7
    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"
    25 #include "ringbc.h"
    26 #include "msgcontacthandler.h"
    26 #include "msgcontacthandler.h"
       
    27 #include "debugtraces.h"
       
    28 
    27 #include <ccsclientconversation.h>
    29 #include <ccsclientconversation.h>
    28 #include <ccsconversationentry.h>
    30 #include <ccsconversationentry.h>
    29 #include <QFile>
    31 #include <QFile>
    30 #include <QFileInfo>
    32 #include <QFileInfo>
    31 
    33 
    34 // @see header
    36 // @see header
    35 //---------------------------------------------------------------
    37 //---------------------------------------------------------------
    36 ConversationsSummaryModel::ConversationsSummaryModel(QObject* parent)
    38 ConversationsSummaryModel::ConversationsSummaryModel(QObject* parent)
    37 :QStandardItemModel(parent)
    39 :QStandardItemModel(parent)
    38     {
    40     {
       
    41     QStandardItemModel::setSortRole(TimeStamp);
       
    42     QStandardItemModel::sort(0, Qt::DescendingOrder);
    39     }
    43     }
    40 
    44 
    41 //---------------------------------------------------------------
    45 //---------------------------------------------------------------
    42 // ConversationsSummaryModel::~ConversationsSummaryModel
    46 // ConversationsSummaryModel::~ConversationsSummaryModel
    43 // @see header
    47 // @see header
   152 //---------------------------------------------------------------
   156 //---------------------------------------------------------------
   153 // ConversationsSummaryModel::addRow
   157 // ConversationsSummaryModel::addRow
   154 // @see header
   158 // @see header
   155 //---------------------------------------------------------------
   159 //---------------------------------------------------------------
   156 void ConversationsSummaryModel::addRow(
   160 void ConversationsSummaryModel::addRow(
   157         const CCsClientConversation& conversation)
   161         const CCsClientConversation& conversation, bool caching)
   158     {  
   162     {  
   159     int convId = conversation.GetConversationEntryId();
   163     int convId = conversation.GetConversationEntryId();
   160     
   164     
   161     //match convId in model, if found update else add item
   165     //match convId in model, if found update else add item
   162     QModelIndexList indexList = this->match(index(0, 0), 
   166     QModelIndexList indexList = this->match(index(0, 0), 
   174     {
   178     {
   175         // Update an existing item
   179         // Update an existing item
   176         QModelIndex index = indexList[0];
   180         QModelIndex index = indexList[0];
   177         QStandardItem* item = this->item(index.row(), 0);
   181         QStandardItem* item = this->item(index.row(), 0);
   178         populateItem(*item,conversation);
   182         populateItem(*item,conversation);
   179     }        
   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         }
   180     }
   189     }
   181 
   190 
   182 //---------------------------------------------------------------
   191 //---------------------------------------------------------------
   183 // ConversationsSummaryModel::deleteRow
   192 // ConversationsSummaryModel::deleteRow
   184 // @see header
   193 // @see header
   202 // @see header
   211 // @see header
   203 //---------------------------------------------------------------
   212 //---------------------------------------------------------------
   204 void ConversationsSummaryModel::populateItem(QStandardItem& item, 
   213 void ConversationsSummaryModel::populateItem(QStandardItem& item, 
   205         const CCsClientConversation& conversation)
   214         const CCsClientConversation& conversation)
   206     {
   215     {
       
   216     QCRITICAL_WRITE("ConversationsSummaryModel::populateItem start.");
       
   217             
   207     //get entry
   218     //get entry
   208     CCsConversationEntry* conEntry = conversation.GetConversationEntry(); 
   219     CCsConversationEntry* conEntry = conversation.GetConversationEntry(); 
   209     //error scenario
   220     //error scenario
   210     if(conEntry == NULL)
   221     if(conEntry == NULL)
   211         return;
   222         return;
   238     {       
   249     {       
   239         // description
   250         // description
   240         HBufC* body = conEntry->Description();
   251         HBufC* body = conEntry->Description();
   241         if( body && body->Length())
   252         if( body && body->Length())
   242         {     
   253         {     
   243             QString bodytext(S60QConversions::s60DescToQString(*body));
   254             QString bodytext(XQConversions::s60DescToQString(*body));
   244             item.setData(bodytext, BodyText); 
   255             item.setData(bodytext, BodyText); 
   245             item.setData(bodytext, Subject );
   256             item.setData(bodytext, Subject );
   246         }
   257         }
   247     }
   258     }
   248 
   259 
   261     HBufC* disName = conversation.GetDisplayName(); 
   272     HBufC* disName = conversation.GetDisplayName(); 
   262     QString displayName("");
   273     QString displayName("");
   263     //display name
   274     //display name
   264     if(disName && disName->Length())
   275     if(disName && disName->Length())
   265         {
   276         {
   266         displayName = S60QConversions::s60DescToQString(*disName);
   277         displayName = XQConversions::s60DescToQString(*disName);
   267         item.setData(displayName,DisplayName); 
   278         item.setData(displayName,DisplayName); 
   268         }
   279         }
   269     
   280     
   270     // contact number
   281     // contact number
   271     HBufC* contactno = conEntry->Contact();
   282     HBufC* contactno = conEntry->Contact();
   272     QString contactNumber("");
   283     QString contactNumber("");
   273     if ( contactno && contactno->Length() )
   284     if ( contactno && contactno->Length() )
   274         {
   285         {
   275         contactNumber = S60QConversions::s60DescToQString(*contactno);                  
   286         contactNumber = XQConversions::s60DescToQString(*contactno);                  
   276         }        
   287         }        
   277     item.setData(contactNumber, ConversationAddress);
   288     item.setData(contactNumber, ConversationAddress);
   278 
   289 
   279     //set the contactId
   290     //set the contactId
   280     int contactId = conversation.GetContactId();
   291     int contactId = conversation.GetContactId();
   281     item.setData(contactId, ContactId);
   292     item.setData(contactId, ContactId);
   282     
   293     
   283     // unread status        
   294     // unread status        
   284     item.setData(conEntry->IsAttributeSet(ECsAttributeUnread),UnReadStatus);      
   295     item.setData(conEntry->IsAttributeSet(ECsAttributeUnread),UnReadStatus); 
       
   296     
       
   297     QCRITICAL_WRITE("ConversationsSummaryModel::populateItem start.");
   285     }
   298     }
   286 
   299 
   287 
   300 
   288 //---------------------------------------------------------------
   301 //---------------------------------------------------------------
   289 // ConversationsModel::handleBlueToothMessages
   302 // ConversationsModel::handleBlueToothMessages
   292 void ConversationsSummaryModel::handleBlueToothMessages(QStandardItem& item,
   305 void ConversationsSummaryModel::handleBlueToothMessages(QStandardItem& item,
   293     const CCsConversationEntry& entry)
   306     const CCsConversationEntry& entry)
   294 {
   307 {
   295     //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
   296     //BT received as Biomsg issue.
   309     //BT received as Biomsg issue.
   297     QString description = S60QConversions::s60DescToQString(*(entry.Description()));
   310     QString description = XQConversions::s60DescToQString(*(entry.Description()));
   298 
   311 
   299     if (description.contains(".vcf") || description.contains(".ics")) // "vCard"
   312     if (description.contains(".vcf") || description.contains(".ics")) // "vCard"
   300     {
   313     {
   301         //message sub-type
   314         //message sub-type
   302         item.setData(ConvergedMessage::VCard, MessageSubType);
   315         item.setData(ConvergedMessage::VCard, MessageSubType);
   367             while (!attList.isEmpty()) {
   380             while (!attList.isEmpty()) {
   368                 delete attList.takeFirst();
   381                 delete attList.takeFirst();
   369             }
   382             }
   370         }
   383         }
   371     }
   384     }
   372     else {
   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 {
   373         // description
   404         // description
   374         HBufC* description = entry.Description();
   405         HBufC* description = entry.Description();
   375         QString subject("");
   406         QString subject("");
   376         if (description && description->Length()) {
   407         if (description && description->Length()) {
   377             subject = (S60QConversions::s60DescToQString(*description));
   408             subject = (XQConversions::s60DescToQString(*description));
   378             item.setData(subject, BodyText);
   409             item.setData(subject, BodyText);
   379         }
   410         }
   380     }
   411     }
   381     
   412     
   382     delete pluginLoader;
   413     delete pluginLoader;