messagingapp/msgui/conversationview/src/msgconversationviewitem.cpp
changeset 27 e4592d119491
parent 25 84d9eb65b26f
child 47 5b14749788d7
--- a/messagingapp/msgui/conversationview/src/msgconversationviewitem.cpp	Mon May 03 12:29:07 2010 +0300
+++ b/messagingapp/msgui/conversationview/src/msgconversationviewitem.cpp	Fri May 14 15:49:35 2010 +0300
@@ -26,6 +26,7 @@
 #include <HbIconItem>
 #include <HbIconAnimationManager>
 #include <HbIconAnimator>
+#include <ccsdefs.h>
 
 // USER INCLUDES
 #include "msgconversationwidget.h"
@@ -56,11 +57,6 @@
     HbListViewItem(parent), mIncoming(false), mConversation(0),
             mMessageStateIconItem(0)
 {
-    mConversation = new MsgConversationWidget(this);
-    HbStyle::setItemName(mConversation, "msgconvwidget");
-
-    mMessageStateIconItem = new HbIconItem(this);
-    HbStyle::setItemName(mMessageStateIconItem, "msgStateIcon");
 }
 
 //---------------------------------------------------------------
@@ -69,7 +65,6 @@
 //---------------------------------------------------------------
 MsgConversationViewItem::~MsgConversationViewItem()
 {
-
 }
 
 //---------------------------------------------------------------
@@ -77,16 +72,23 @@
 // Create a new decorator item.
 //---------------------------------------------------------------
 MsgConversationViewItem* MsgConversationViewItem::createItem()
-{
-    return new MsgConversationViewItem();
-}
+    {
+    return new MsgConversationViewItem(*this);
+    }
 
 //---------------------------------------------------------------
 // MsgConversationViewItem::updateChildItems
 //
 //---------------------------------------------------------------
 void MsgConversationViewItem::updateChildItems()
-{
+    {
+
+    if (!mMessageStateIconItem)
+        {
+        mMessageStateIconItem = new HbIconItem(this);
+        HbStyle::setItemName(mMessageStateIconItem, "msgStateIcon");
+        }
+    
     QModelIndex index = modelIndex();
 
 #ifdef _DEBUG_TRACES_
@@ -94,192 +96,284 @@
             << index.data(ConvergedMsgId).toInt();
 #endif
 
-    // Create items common to each type of message
-
-    QString bodyText = index.data(BodyText).toString();
     int messageType = index.data(MessageType).toInt();
     int messageSubType = index.data(MessageSubType).toInt();
 
-    // Set message properties common to SMS/MMS/IM etc..
+    
+    if (messageType == ConvergedMessage::Sms)
+        {
+        	updateSmsTypeItem(index);
+        }
+    else if (messageType == ConvergedMessage::Mms || messageType
+            == ConvergedMessage::MmsNotification || messageType
+            == ConvergedMessage::BT)
+        {
+        updateMmsTypeItem(index, messageType, messageSubType);
+        }
+    else if (messageType == ConvergedMessage::BioMsg)
+        {
+        if (messageSubType == ConvergedMessage::VCard || messageSubType
+                == ConvergedMessage::RingingTone)
+            {
+            updateMmsTypeItem(index, messageType, messageSubType);
+            }
+        else
+            {
+            updateSmsTypeItem(index, messageSubType);
+            }
+        }
 
+#ifdef _DEBUG_TRACES_
+    qCritical() << "END MsgConversationViewItem::updateChildItems: "
+            << index.data(ConvergedMsgId).toInt();
+#endif
+
+    repolish();
+    HbListViewItem::updateChildItems();
+    }
+
+//---------------------------------------------------------------
+// MsgConversationViewItem::updateSmsTypeItem
+// @see header file
+//---------------------------------------------------------------
+void MsgConversationViewItem::updateSmsTypeItem(const QModelIndex& index, int messageSubType)
+    {
+    
+    if (!mConversation)
+        {
+        mConversation = new MsgConversationWidget(this);
+        HbStyle::setItemName(mConversation, "msgconvwidget");
+        }
+    mIncoming = false;
+    mConversation->resetProperties();
+    
     int direction = index.data(Direction).toInt();
-
-    if ( direction == ConvergedMessage::Incoming)
-    {
+    
+    if (direction == ConvergedMessage::Incoming)
+        {
         setIncoming(true);
         mConversation->setIncoming(true);
-        
-        if(messageType == ConvergedMessage::MmsNotification)
-        {
-            mConversation->setMMSNotification(true);
-            int notificationState = index.data(NotificationStatus).toInt();
-            mConversation->setNotificationState(notificationState);
-            setNotificationStateIcon(notificationState);
+
+        mMessageStateIconItem->setVisible(false);
         }
-        else
+    else if (direction == ConvergedMessage::Outgoing)
         {
-            mMessageStateIconItem->setVisible(false);
-        }
-    }
-    else if (direction == ConvergedMessage::Outgoing)
-    {
         setIncoming(false);
         mConversation->setIncoming(false);
 
         int sendingState = index.data(SendingState).toInt();
         mConversation->setSendingState(sendingState);
         setMessageStateIcon(sendingState);
-    }
+        }
 
     bool unreadStatus = index.data(UnReadStatus).toBool();
     mConversation->setUnread(unreadStatus);
-    // Create items common to SMS/MMS/IM etc...
+
     mConversation->drawBubbleFrame();
     mConversation->drawNewItemFrame();
 
     QDateTime dateTime;
     dateTime.setTime_t(index.data(TimeStamp).toUInt());
-    QString resendStateNote((index.data(SendingState).toInt() == ConvergedMessage::Resend)? LOC_RESEND_AT : "");
+    QString resendStateNote((index.data(SendingState).toInt()
+                    == ConvergedMessage::Resend) ? LOC_RESEND_AT : "");
     if (dateTime.date() == QDateTime::currentDateTime().date())
-    {
+        {
+
+        mConversation->setTimeStamp(resendStateNote + dateTime.toString(
+                        TIME_FORMAT));
+        }
+    else
+        {
+        mConversation->setTimeStamp(resendStateNote + dateTime.toString(
+                        DATE_FORMAT));
+        }
 
-        mConversation->setTimeStamp(resendStateNote + dateTime.toString(TIME_FORMAT));
-    }
+    if (messageSubType == ConvergedMessage::VCal)
+        {
+         mConversation->setSubject(LOC_UNSUPPORTED_MSG_TYPE);
+        }
     else
-    {
-        mConversation->setTimeStamp(resendStateNote + dateTime.toString(DATE_FORMAT));
+        {
+        QString bodyText = index.data(BodyText).toString();
+        bodyText.replace(QChar::ParagraphSeparator, QChar::LineSeparator);
+        bodyText.replace('\r', QChar::LineSeparator);
+        mConversation->setSubject(bodyText);
+        }
+    
+    //repolish
+    mConversation->repolishWidget();
     }
 
-    QDEBUG_WRITE_FORMAT("MsgConversationViewItem::updateChildItems msg type value",messageType)
-    
-    if (messageType == ConvergedMessage::Sms ||
-            messageType == ConvergedMessage::IM)
+//---------------------------------------------------------------
+// MsgConversationViewItem::updateMmsTypeItem
+// @see header file
+//---------------------------------------------------------------
+void MsgConversationViewItem::updateMmsTypeItem(const QModelIndex& index,
+        int messageType, int messageSubType)
     {
-        mConversation->setMMS(false);
-        bodyText.replace(QChar::ParagraphSeparator, QChar::LineSeparator);
-        bodyText.replace('\r', QChar::LineSeparator);
-        mConversation->setBodyText(bodyText);
-    }
-    else if (messageType == ConvergedMessage::Mms)
-    {
-        mConversation->setMMS(true);
-        QString attachments = index.data(Attachments).toString();
+    // create widget
+    if (!mConversation)
+        {
+        mConversation = new MsgConversationWidget(this);
+        HbStyle::setItemName(mConversation, "msgconvwidget");
+        }
+    mIncoming = false;
+    mConversation->resetProperties();
+    
+    mConversation->setMMS(true);
+    int direction = index.data(Direction).toInt();
+    QString bodyText = index.data(BodyText).toString();
+
+    if (direction == ConvergedMessage::Incoming)
+        {
+        setIncoming(true);
+        mConversation->setIncoming(true);
+
+        if (messageType == ConvergedMessage::MmsNotification)
+            {
+            mConversation->setMMSNotification(true);
+            int notificationState = index.data(NotificationStatus).toInt();
+            mConversation->setNotificationState(notificationState);
+            setNotificationStateIcon(notificationState);
+            }
+        else
+            {
+            mMessageStateIconItem->setVisible(false);
+            }
+        }
+    else if (direction == ConvergedMessage::Outgoing)
+        {
+        setIncoming(false);
+        mConversation->setIncoming(false);
+
+        int sendingState = index.data(SendingState).toInt();
+        mConversation->setSendingState(sendingState);
+        setMessageStateIcon(sendingState);
+        }
+
+    bool unreadStatus = index.data(UnReadStatus).toBool();
+    mConversation->setUnread(unreadStatus);
+
+    mConversation->drawBubbleFrame();
+    mConversation->drawNewItemFrame();
+
+    QDateTime dateTime;
+    dateTime.setTime_t(index.data(TimeStamp).toUInt());
+    QString resendStateNote((index.data(SendingState).toInt()
+            == ConvergedMessage::Resend) ? LOC_RESEND_AT : "");
+    if (dateTime.date() == QDateTime::currentDateTime().date())
+        {
+
+        mConversation->setTimeStamp(resendStateNote + dateTime.toString(
+                TIME_FORMAT));
+        }
+    else
+        {
+        mConversation->setTimeStamp(resendStateNote + dateTime.toString(
+                DATE_FORMAT));
+        }
+
+    if (messageType == ConvergedMessage::Mms)
+        {
+        //preview path
+        QString previewPath = index.data(Attachments).toString();
         QString subject = index.data(Subject).toString();
 
-        bool hasAttachments = (index.data(MessageProperty).toInt()
-            & ConvergedMessage::Attachment) ? true : false;
+        int msgProperty = index.data(MessageProperty).toInt();
+        bool hasAttachments = (msgProperty & EPreviewAttachment) ? true : false;
 
         if (hasAttachments)
-        {
+            {
             mConversation->setAttachment();
-        }
+            }
         else
-        {
+            {
             mConversation->setAttachment(false);
-        }
-        QStringList mediaFiles = attachments.split('|',
-            QString::SkipEmptyParts);
-        //Can be used for preview icon
-        QStringList imageFiles;
-
-        MsgViewUtils viewUtils;
-
-        for (int i = 0; i < mediaFiles.size(); ++i)
-        {
-            QString type = viewUtils.mimeTypeL(QDir::toNativeSeparators(
-                mediaFiles.at(i)));
+            }
+        
+        // Now set the media contents
+        
+        //preview image
+        bool hasImage = (msgProperty & EPreviewImage) ? true : false;
 
-            if (type.contains("image"))
+        if (hasImage)
             {
-                imageFiles << mediaFiles.at(i);
-                mConversation->setImage(true);
-            }
-            else if (type.contains("video"))
-            {
-                mConversation->setVideo(false);
+            int msgId = index.data(ConvergedMsgId).toInt();
+            mConversation->setPreviewIconPath(previewPath, msgId);
+            mConversation->setImage(true);
             }
-            else if (type.contains("audio"))
+
+        bool hasVideo = (msgProperty & EPreviewVideo) ? true : false;
+        
+        if (hasVideo)
             {
-                mConversation->setAudio(true);
+            mConversation->setVideo(true);
             }
-        }
-        // Now set the media contents
-        if (!imageFiles.isEmpty())
-        {
-            mConversation->setPreviewIconPath(imageFiles.at(0));
-        }
+
+        bool hasAudio = (msgProperty & EPreviewAudio) ? true : false;              
+        if (hasAudio)
+            {
+            mConversation->setAudio(true);
+            }
+
         mConversation->displayAudioIcon();
 
         int priority = index.data(MessagePriority).toInt();
         mConversation->setPriority(priority);
         mConversation->setSubject(subject);
-        mConversation->setBodyText(bodyText);        
-    } // END of ConvergedMessage::Mms
+        mConversation->setBodyText(bodyText);
+        }
     else if (messageType == ConvergedMessage::BioMsg)
-    {
+        {
         if (messageSubType == ConvergedMessage::RingingTone)
-        {
-            mConversation->setMMS(true);
+            {
             mConversation->setImage(false);
             mConversation->setAudio(true);
             mConversation->displayAudioIcon();
             mConversation->setSubject(LOC_RINGING_TONE);
-        }
+            }
         else if (messageSubType == ConvergedMessage::VCard)
-        {
-            mConversation->setMMS(true);
+            {
             mConversation->setImage(false);
             mConversation->setAudio(true);
             mConversation->displayAudioIcon(VCARD_ICON);
             mConversation->setSubject(LOC_BUSINESS_CARD);
             mConversation->setBodyText(bodyText);
+            }
         }
-        else
+    else if (messageType == ConvergedMessage::BT)
         {
-            mConversation->setMMS(false);
-            mConversation->setBodyText(LOC_UNSUPPORTED_MSG_TYPE);
-        }
-    }
-    else if (messageType == ConvergedMessage::BT)
-    {
-        mConversation->setMMS(true);
         QString deviceName = index.data(ConversationAddress).toString();
         mConversation->setSubject(deviceName);
         QString blueToothBody;
         if (messageSubType == ConvergedMessage::VCard)
-        {
+            {
             mConversation->setImage(false);
             mConversation->setAudio(true);
             mConversation->displayAudioIcon(VCARD_ICON);
             blueToothBody.append(LOC_BUSINESS_CARD);
             blueToothBody.append(QChar::LineSeparator);
             blueToothBody.append(bodyText);
-        }        
+            }
         else
-        {
+            {
             blueToothBody.append(bodyText);
-        }
+            }
         mConversation->setBodyText(blueToothBody);
-    }
-    else if(messageType == ConvergedMessage::MmsNotification)
-    {
-        mConversation->setMMS(true);
-        
+        }
+    else if (messageType == ConvergedMessage::MmsNotification)
+        {
         QString subject = index.data(Subject).toString();
         int priority = index.data(MessagePriority).toInt();
         mConversation->setPriority(priority);
         mConversation->setSubject(subject);
         mConversation->setBodyText(bodyText);
+        }
+    
+    //repolish widget
+    mConversation->repolishWidget();
     }
 
-#ifdef _DEBUG_TRACES_
-    qCritical() << "END MsgConversationViewItem::updateChildItems: "
-            << index.data(ConvergedMsgId).toInt();
-#endif
-
-    HbListViewItem::updateChildItems();
-}
-
 //---------------------------------------------------------------
 // MsgConversationViewItem::containsPoint
 //
@@ -318,7 +412,6 @@
     HbIconAnimationManager* iconAnimationManager = HbIconAnimationManager::global();
     switch (messageState)
     {
-
         case ConvergedMessage::Waiting:
         case ConvergedMessage::Scheduled:
         case ConvergedMessage::Sending:
@@ -376,7 +469,6 @@
     HbIconAnimationManager* iconAnimationManager = HbIconAnimationManager::global();
     switch (notificationState)
     {
-
         case ConvergedMessage::NotifRetrieving:
         case ConvergedMessage::NotifWaiting:
         {