messagingapp/msgui/conversationview/src/msgconversationviewitem.cpp
changeset 27 e4592d119491
parent 25 84d9eb65b26f
child 47 5b14749788d7
equal deleted inserted replaced
25:84d9eb65b26f 27:e4592d119491
    24 #include <QChar>
    24 #include <QChar>
    25 #include <HbTextItem>
    25 #include <HbTextItem>
    26 #include <HbIconItem>
    26 #include <HbIconItem>
    27 #include <HbIconAnimationManager>
    27 #include <HbIconAnimationManager>
    28 #include <HbIconAnimator>
    28 #include <HbIconAnimator>
       
    29 #include <ccsdefs.h>
    29 
    30 
    30 // USER INCLUDES
    31 // USER INCLUDES
    31 #include "msgconversationwidget.h"
    32 #include "msgconversationwidget.h"
    32 #include "msgviewdefines.h"
    33 #include "msgviewdefines.h"
    33 #include "msgviewutils.h"
    34 #include "msgviewutils.h"
    54 //---------------------------------------------------------------
    55 //---------------------------------------------------------------
    55 MsgConversationViewItem::MsgConversationViewItem(QGraphicsItem* parent) :
    56 MsgConversationViewItem::MsgConversationViewItem(QGraphicsItem* parent) :
    56     HbListViewItem(parent), mIncoming(false), mConversation(0),
    57     HbListViewItem(parent), mIncoming(false), mConversation(0),
    57             mMessageStateIconItem(0)
    58             mMessageStateIconItem(0)
    58 {
    59 {
    59     mConversation = new MsgConversationWidget(this);
       
    60     HbStyle::setItemName(mConversation, "msgconvwidget");
       
    61 
       
    62     mMessageStateIconItem = new HbIconItem(this);
       
    63     HbStyle::setItemName(mMessageStateIconItem, "msgStateIcon");
       
    64 }
    60 }
    65 
    61 
    66 //---------------------------------------------------------------
    62 //---------------------------------------------------------------
    67 // MsgConversationViewItem::MsgConversationViewItem
    63 // MsgConversationViewItem::MsgConversationViewItem
    68 // Destructor
    64 // Destructor
    69 //---------------------------------------------------------------
    65 //---------------------------------------------------------------
    70 MsgConversationViewItem::~MsgConversationViewItem()
    66 MsgConversationViewItem::~MsgConversationViewItem()
    71 {
    67 {
    72 
       
    73 }
    68 }
    74 
    69 
    75 //---------------------------------------------------------------
    70 //---------------------------------------------------------------
    76 // MsgConversationViewItem::createItem
    71 // MsgConversationViewItem::createItem
    77 // Create a new decorator item.
    72 // Create a new decorator item.
    78 //---------------------------------------------------------------
    73 //---------------------------------------------------------------
    79 MsgConversationViewItem* MsgConversationViewItem::createItem()
    74 MsgConversationViewItem* MsgConversationViewItem::createItem()
    80 {
    75     {
    81     return new MsgConversationViewItem();
    76     return new MsgConversationViewItem(*this);
    82 }
    77     }
    83 
    78 
    84 //---------------------------------------------------------------
    79 //---------------------------------------------------------------
    85 // MsgConversationViewItem::updateChildItems
    80 // MsgConversationViewItem::updateChildItems
    86 //
    81 //
    87 //---------------------------------------------------------------
    82 //---------------------------------------------------------------
    88 void MsgConversationViewItem::updateChildItems()
    83 void MsgConversationViewItem::updateChildItems()
    89 {
    84     {
       
    85 
       
    86     if (!mMessageStateIconItem)
       
    87         {
       
    88         mMessageStateIconItem = new HbIconItem(this);
       
    89         HbStyle::setItemName(mMessageStateIconItem, "msgStateIcon");
       
    90         }
       
    91     
    90     QModelIndex index = modelIndex();
    92     QModelIndex index = modelIndex();
    91 
    93 
    92 #ifdef _DEBUG_TRACES_
    94 #ifdef _DEBUG_TRACES_
    93     qCritical() << "START MsgConversationViewItem::updateChildItems: "
    95     qCritical() << "START MsgConversationViewItem::updateChildItems: "
    94             << index.data(ConvergedMsgId).toInt();
    96             << index.data(ConvergedMsgId).toInt();
    95 #endif
    97 #endif
    96 
    98 
    97     // Create items common to each type of message
       
    98 
       
    99     QString bodyText = index.data(BodyText).toString();
       
   100     int messageType = index.data(MessageType).toInt();
    99     int messageType = index.data(MessageType).toInt();
   101     int messageSubType = index.data(MessageSubType).toInt();
   100     int messageSubType = index.data(MessageSubType).toInt();
   102 
   101 
   103     // Set message properties common to SMS/MMS/IM etc..
   102     
   104 
   103     if (messageType == ConvergedMessage::Sms)
       
   104         {
       
   105         	updateSmsTypeItem(index);
       
   106         }
       
   107     else if (messageType == ConvergedMessage::Mms || messageType
       
   108             == ConvergedMessage::MmsNotification || messageType
       
   109             == ConvergedMessage::BT)
       
   110         {
       
   111         updateMmsTypeItem(index, messageType, messageSubType);
       
   112         }
       
   113     else if (messageType == ConvergedMessage::BioMsg)
       
   114         {
       
   115         if (messageSubType == ConvergedMessage::VCard || messageSubType
       
   116                 == ConvergedMessage::RingingTone)
       
   117             {
       
   118             updateMmsTypeItem(index, messageType, messageSubType);
       
   119             }
       
   120         else
       
   121             {
       
   122             updateSmsTypeItem(index, messageSubType);
       
   123             }
       
   124         }
       
   125 
       
   126 #ifdef _DEBUG_TRACES_
       
   127     qCritical() << "END MsgConversationViewItem::updateChildItems: "
       
   128             << index.data(ConvergedMsgId).toInt();
       
   129 #endif
       
   130 
       
   131     repolish();
       
   132     HbListViewItem::updateChildItems();
       
   133     }
       
   134 
       
   135 //---------------------------------------------------------------
       
   136 // MsgConversationViewItem::updateSmsTypeItem
       
   137 // @see header file
       
   138 //---------------------------------------------------------------
       
   139 void MsgConversationViewItem::updateSmsTypeItem(const QModelIndex& index, int messageSubType)
       
   140     {
       
   141     
       
   142     if (!mConversation)
       
   143         {
       
   144         mConversation = new MsgConversationWidget(this);
       
   145         HbStyle::setItemName(mConversation, "msgconvwidget");
       
   146         }
       
   147     mIncoming = false;
       
   148     mConversation->resetProperties();
       
   149     
   105     int direction = index.data(Direction).toInt();
   150     int direction = index.data(Direction).toInt();
   106 
   151     
   107     if ( direction == ConvergedMessage::Incoming)
   152     if (direction == ConvergedMessage::Incoming)
   108     {
   153         {
   109         setIncoming(true);
   154         setIncoming(true);
   110         mConversation->setIncoming(true);
   155         mConversation->setIncoming(true);
   111         
   156 
   112         if(messageType == ConvergedMessage::MmsNotification)
   157         mMessageStateIconItem->setVisible(false);
   113         {
   158         }
       
   159     else if (direction == ConvergedMessage::Outgoing)
       
   160         {
       
   161         setIncoming(false);
       
   162         mConversation->setIncoming(false);
       
   163 
       
   164         int sendingState = index.data(SendingState).toInt();
       
   165         mConversation->setSendingState(sendingState);
       
   166         setMessageStateIcon(sendingState);
       
   167         }
       
   168 
       
   169     bool unreadStatus = index.data(UnReadStatus).toBool();
       
   170     mConversation->setUnread(unreadStatus);
       
   171 
       
   172     mConversation->drawBubbleFrame();
       
   173     mConversation->drawNewItemFrame();
       
   174 
       
   175     QDateTime dateTime;
       
   176     dateTime.setTime_t(index.data(TimeStamp).toUInt());
       
   177     QString resendStateNote((index.data(SendingState).toInt()
       
   178                     == ConvergedMessage::Resend) ? LOC_RESEND_AT : "");
       
   179     if (dateTime.date() == QDateTime::currentDateTime().date())
       
   180         {
       
   181 
       
   182         mConversation->setTimeStamp(resendStateNote + dateTime.toString(
       
   183                         TIME_FORMAT));
       
   184         }
       
   185     else
       
   186         {
       
   187         mConversation->setTimeStamp(resendStateNote + dateTime.toString(
       
   188                         DATE_FORMAT));
       
   189         }
       
   190 
       
   191     if (messageSubType == ConvergedMessage::VCal)
       
   192         {
       
   193          mConversation->setSubject(LOC_UNSUPPORTED_MSG_TYPE);
       
   194         }
       
   195     else
       
   196         {
       
   197         QString bodyText = index.data(BodyText).toString();
       
   198         bodyText.replace(QChar::ParagraphSeparator, QChar::LineSeparator);
       
   199         bodyText.replace('\r', QChar::LineSeparator);
       
   200         mConversation->setSubject(bodyText);
       
   201         }
       
   202     
       
   203     //repolish
       
   204     mConversation->repolishWidget();
       
   205     }
       
   206 
       
   207 //---------------------------------------------------------------
       
   208 // MsgConversationViewItem::updateMmsTypeItem
       
   209 // @see header file
       
   210 //---------------------------------------------------------------
       
   211 void MsgConversationViewItem::updateMmsTypeItem(const QModelIndex& index,
       
   212         int messageType, int messageSubType)
       
   213     {
       
   214     // create widget
       
   215     if (!mConversation)
       
   216         {
       
   217         mConversation = new MsgConversationWidget(this);
       
   218         HbStyle::setItemName(mConversation, "msgconvwidget");
       
   219         }
       
   220     mIncoming = false;
       
   221     mConversation->resetProperties();
       
   222     
       
   223     mConversation->setMMS(true);
       
   224     int direction = index.data(Direction).toInt();
       
   225     QString bodyText = index.data(BodyText).toString();
       
   226 
       
   227     if (direction == ConvergedMessage::Incoming)
       
   228         {
       
   229         setIncoming(true);
       
   230         mConversation->setIncoming(true);
       
   231 
       
   232         if (messageType == ConvergedMessage::MmsNotification)
       
   233             {
   114             mConversation->setMMSNotification(true);
   234             mConversation->setMMSNotification(true);
   115             int notificationState = index.data(NotificationStatus).toInt();
   235             int notificationState = index.data(NotificationStatus).toInt();
   116             mConversation->setNotificationState(notificationState);
   236             mConversation->setNotificationState(notificationState);
   117             setNotificationStateIcon(notificationState);
   237             setNotificationStateIcon(notificationState);
   118         }
   238             }
   119         else
   239         else
   120         {
   240             {
   121             mMessageStateIconItem->setVisible(false);
   241             mMessageStateIconItem->setVisible(false);
   122         }
   242             }
   123     }
   243         }
   124     else if (direction == ConvergedMessage::Outgoing)
   244     else if (direction == ConvergedMessage::Outgoing)
   125     {
   245         {
   126         setIncoming(false);
   246         setIncoming(false);
   127         mConversation->setIncoming(false);
   247         mConversation->setIncoming(false);
   128 
   248 
   129         int sendingState = index.data(SendingState).toInt();
   249         int sendingState = index.data(SendingState).toInt();
   130         mConversation->setSendingState(sendingState);
   250         mConversation->setSendingState(sendingState);
   131         setMessageStateIcon(sendingState);
   251         setMessageStateIcon(sendingState);
   132     }
   252         }
   133 
   253 
   134     bool unreadStatus = index.data(UnReadStatus).toBool();
   254     bool unreadStatus = index.data(UnReadStatus).toBool();
   135     mConversation->setUnread(unreadStatus);
   255     mConversation->setUnread(unreadStatus);
   136     // Create items common to SMS/MMS/IM etc...
   256 
   137     mConversation->drawBubbleFrame();
   257     mConversation->drawBubbleFrame();
   138     mConversation->drawNewItemFrame();
   258     mConversation->drawNewItemFrame();
   139 
   259 
   140     QDateTime dateTime;
   260     QDateTime dateTime;
   141     dateTime.setTime_t(index.data(TimeStamp).toUInt());
   261     dateTime.setTime_t(index.data(TimeStamp).toUInt());
   142     QString resendStateNote((index.data(SendingState).toInt() == ConvergedMessage::Resend)? LOC_RESEND_AT : "");
   262     QString resendStateNote((index.data(SendingState).toInt()
       
   263             == ConvergedMessage::Resend) ? LOC_RESEND_AT : "");
   143     if (dateTime.date() == QDateTime::currentDateTime().date())
   264     if (dateTime.date() == QDateTime::currentDateTime().date())
   144     {
   265         {
   145 
   266 
   146         mConversation->setTimeStamp(resendStateNote + dateTime.toString(TIME_FORMAT));
   267         mConversation->setTimeStamp(resendStateNote + dateTime.toString(
   147     }
   268                 TIME_FORMAT));
       
   269         }
   148     else
   270     else
   149     {
   271         {
   150         mConversation->setTimeStamp(resendStateNote + dateTime.toString(DATE_FORMAT));
   272         mConversation->setTimeStamp(resendStateNote + dateTime.toString(
   151     }
   273                 DATE_FORMAT));
   152 
   274         }
   153     QDEBUG_WRITE_FORMAT("MsgConversationViewItem::updateChildItems msg type value",messageType)
   275 
   154     
   276     if (messageType == ConvergedMessage::Mms)
   155     if (messageType == ConvergedMessage::Sms ||
   277         {
   156             messageType == ConvergedMessage::IM)
   278         //preview path
   157     {
   279         QString previewPath = index.data(Attachments).toString();
   158         mConversation->setMMS(false);
       
   159         bodyText.replace(QChar::ParagraphSeparator, QChar::LineSeparator);
       
   160         bodyText.replace('\r', QChar::LineSeparator);
       
   161         mConversation->setBodyText(bodyText);
       
   162     }
       
   163     else if (messageType == ConvergedMessage::Mms)
       
   164     {
       
   165         mConversation->setMMS(true);
       
   166         QString attachments = index.data(Attachments).toString();
       
   167         QString subject = index.data(Subject).toString();
   280         QString subject = index.data(Subject).toString();
   168 
   281 
   169         bool hasAttachments = (index.data(MessageProperty).toInt()
   282         int msgProperty = index.data(MessageProperty).toInt();
   170             & ConvergedMessage::Attachment) ? true : false;
   283         bool hasAttachments = (msgProperty & EPreviewAttachment) ? true : false;
   171 
   284 
   172         if (hasAttachments)
   285         if (hasAttachments)
   173         {
   286             {
   174             mConversation->setAttachment();
   287             mConversation->setAttachment();
   175         }
   288             }
   176         else
   289         else
   177         {
   290             {
   178             mConversation->setAttachment(false);
   291             mConversation->setAttachment(false);
   179         }
   292             }
   180         QStringList mediaFiles = attachments.split('|',
   293         
   181             QString::SkipEmptyParts);
       
   182         //Can be used for preview icon
       
   183         QStringList imageFiles;
       
   184 
       
   185         MsgViewUtils viewUtils;
       
   186 
       
   187         for (int i = 0; i < mediaFiles.size(); ++i)
       
   188         {
       
   189             QString type = viewUtils.mimeTypeL(QDir::toNativeSeparators(
       
   190                 mediaFiles.at(i)));
       
   191 
       
   192             if (type.contains("image"))
       
   193             {
       
   194                 imageFiles << mediaFiles.at(i);
       
   195                 mConversation->setImage(true);
       
   196             }
       
   197             else if (type.contains("video"))
       
   198             {
       
   199                 mConversation->setVideo(false);
       
   200             }
       
   201             else if (type.contains("audio"))
       
   202             {
       
   203                 mConversation->setAudio(true);
       
   204             }
       
   205         }
       
   206         // Now set the media contents
   294         // Now set the media contents
   207         if (!imageFiles.isEmpty())
   295         
   208         {
   296         //preview image
   209             mConversation->setPreviewIconPath(imageFiles.at(0));
   297         bool hasImage = (msgProperty & EPreviewImage) ? true : false;
   210         }
   298 
       
   299         if (hasImage)
       
   300             {
       
   301             int msgId = index.data(ConvergedMsgId).toInt();
       
   302             mConversation->setPreviewIconPath(previewPath, msgId);
       
   303             mConversation->setImage(true);
       
   304             }
       
   305 
       
   306         bool hasVideo = (msgProperty & EPreviewVideo) ? true : false;
       
   307         
       
   308         if (hasVideo)
       
   309             {
       
   310             mConversation->setVideo(true);
       
   311             }
       
   312 
       
   313         bool hasAudio = (msgProperty & EPreviewAudio) ? true : false;              
       
   314         if (hasAudio)
       
   315             {
       
   316             mConversation->setAudio(true);
       
   317             }
       
   318 
   211         mConversation->displayAudioIcon();
   319         mConversation->displayAudioIcon();
   212 
   320 
   213         int priority = index.data(MessagePriority).toInt();
   321         int priority = index.data(MessagePriority).toInt();
   214         mConversation->setPriority(priority);
   322         mConversation->setPriority(priority);
   215         mConversation->setSubject(subject);
   323         mConversation->setSubject(subject);
   216         mConversation->setBodyText(bodyText);        
   324         mConversation->setBodyText(bodyText);
   217     } // END of ConvergedMessage::Mms
   325         }
   218     else if (messageType == ConvergedMessage::BioMsg)
   326     else if (messageType == ConvergedMessage::BioMsg)
   219     {
   327         {
   220         if (messageSubType == ConvergedMessage::RingingTone)
   328         if (messageSubType == ConvergedMessage::RingingTone)
   221         {
   329             {
   222             mConversation->setMMS(true);
       
   223             mConversation->setImage(false);
   330             mConversation->setImage(false);
   224             mConversation->setAudio(true);
   331             mConversation->setAudio(true);
   225             mConversation->displayAudioIcon();
   332             mConversation->displayAudioIcon();
   226             mConversation->setSubject(LOC_RINGING_TONE);
   333             mConversation->setSubject(LOC_RINGING_TONE);
   227         }
   334             }
   228         else if (messageSubType == ConvergedMessage::VCard)
   335         else if (messageSubType == ConvergedMessage::VCard)
   229         {
   336             {
   230             mConversation->setMMS(true);
       
   231             mConversation->setImage(false);
   337             mConversation->setImage(false);
   232             mConversation->setAudio(true);
   338             mConversation->setAudio(true);
   233             mConversation->displayAudioIcon(VCARD_ICON);
   339             mConversation->displayAudioIcon(VCARD_ICON);
   234             mConversation->setSubject(LOC_BUSINESS_CARD);
   340             mConversation->setSubject(LOC_BUSINESS_CARD);
   235             mConversation->setBodyText(bodyText);
   341             mConversation->setBodyText(bodyText);
   236         }
   342             }
   237         else
   343         }
   238         {
       
   239             mConversation->setMMS(false);
       
   240             mConversation->setBodyText(LOC_UNSUPPORTED_MSG_TYPE);
       
   241         }
       
   242     }
       
   243     else if (messageType == ConvergedMessage::BT)
   344     else if (messageType == ConvergedMessage::BT)
   244     {
   345         {
   245         mConversation->setMMS(true);
       
   246         QString deviceName = index.data(ConversationAddress).toString();
   346         QString deviceName = index.data(ConversationAddress).toString();
   247         mConversation->setSubject(deviceName);
   347         mConversation->setSubject(deviceName);
   248         QString blueToothBody;
   348         QString blueToothBody;
   249         if (messageSubType == ConvergedMessage::VCard)
   349         if (messageSubType == ConvergedMessage::VCard)
   250         {
   350             {
   251             mConversation->setImage(false);
   351             mConversation->setImage(false);
   252             mConversation->setAudio(true);
   352             mConversation->setAudio(true);
   253             mConversation->displayAudioIcon(VCARD_ICON);
   353             mConversation->displayAudioIcon(VCARD_ICON);
   254             blueToothBody.append(LOC_BUSINESS_CARD);
   354             blueToothBody.append(LOC_BUSINESS_CARD);
   255             blueToothBody.append(QChar::LineSeparator);
   355             blueToothBody.append(QChar::LineSeparator);
   256             blueToothBody.append(bodyText);
   356             blueToothBody.append(bodyText);
   257         }        
   357             }
   258         else
   358         else
   259         {
   359             {
   260             blueToothBody.append(bodyText);
   360             blueToothBody.append(bodyText);
   261         }
   361             }
   262         mConversation->setBodyText(blueToothBody);
   362         mConversation->setBodyText(blueToothBody);
   263     }
   363         }
   264     else if(messageType == ConvergedMessage::MmsNotification)
   364     else if (messageType == ConvergedMessage::MmsNotification)
   265     {
   365         {
   266         mConversation->setMMS(true);
       
   267         
       
   268         QString subject = index.data(Subject).toString();
   366         QString subject = index.data(Subject).toString();
   269         int priority = index.data(MessagePriority).toInt();
   367         int priority = index.data(MessagePriority).toInt();
   270         mConversation->setPriority(priority);
   368         mConversation->setPriority(priority);
   271         mConversation->setSubject(subject);
   369         mConversation->setSubject(subject);
   272         mConversation->setBodyText(bodyText);
   370         mConversation->setBodyText(bodyText);
       
   371         }
       
   372     
       
   373     //repolish widget
       
   374     mConversation->repolishWidget();
   273     }
   375     }
   274 
       
   275 #ifdef _DEBUG_TRACES_
       
   276     qCritical() << "END MsgConversationViewItem::updateChildItems: "
       
   277             << index.data(ConvergedMsgId).toInt();
       
   278 #endif
       
   279 
       
   280     HbListViewItem::updateChildItems();
       
   281 }
       
   282 
   376 
   283 //---------------------------------------------------------------
   377 //---------------------------------------------------------------
   284 // MsgConversationViewItem::containsPoint
   378 // MsgConversationViewItem::containsPoint
   285 //
   379 //
   286 //---------------------------------------------------------------
   380 //---------------------------------------------------------------
   316 {
   410 {
   317     HbIconAnimator& iconAnimator = mMessageStateIconItem->animator();
   411     HbIconAnimator& iconAnimator = mMessageStateIconItem->animator();
   318     HbIconAnimationManager* iconAnimationManager = HbIconAnimationManager::global();
   412     HbIconAnimationManager* iconAnimationManager = HbIconAnimationManager::global();
   319     switch (messageState)
   413     switch (messageState)
   320     {
   414     {
   321 
       
   322         case ConvergedMessage::Waiting:
   415         case ConvergedMessage::Waiting:
   323         case ConvergedMessage::Scheduled:
   416         case ConvergedMessage::Scheduled:
   324         case ConvergedMessage::Sending:
   417         case ConvergedMessage::Sending:
   325         { 
   418         { 
   326  	        bool defined = iconAnimationManager->addDefinitionFile(ANIMATION_FILE);
   419  	        bool defined = iconAnimationManager->addDefinitionFile(ANIMATION_FILE);
   374 {
   467 {
   375     HbIconAnimator& iconAnimator = mMessageStateIconItem->animator();
   468     HbIconAnimator& iconAnimator = mMessageStateIconItem->animator();
   376     HbIconAnimationManager* iconAnimationManager = HbIconAnimationManager::global();
   469     HbIconAnimationManager* iconAnimationManager = HbIconAnimationManager::global();
   377     switch (notificationState)
   470     switch (notificationState)
   378     {
   471     {
   379 
       
   380         case ConvergedMessage::NotifRetrieving:
   472         case ConvergedMessage::NotifRetrieving:
   381         case ConvergedMessage::NotifWaiting:
   473         case ConvergedMessage::NotifWaiting:
   382         { 
   474         { 
   383             //TODO: Temp icon until official icons are received
   475             //TODO: Temp icon until official icons are received
   384             bool defined = iconAnimationManager->addDefinitionFile(ANIMATION_FILE);
   476             bool defined = iconAnimationManager->addDefinitionFile(ANIMATION_FILE);