messagingapp/msgui/msgapp/src/msglistviewitem.cpp
changeset 23 238255e8b033
child 25 84d9eb65b26f
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  Item decorator of the message list view.
       
    15  *
       
    16  */
       
    17 
       
    18 // SYSTEM INCLUDES
       
    19 #include "msglistviewitem.h"
       
    20 
       
    21 #include <QDateTime>
       
    22 #include <hbframeitem.h>
       
    23 #include <hbframedrawer.h>
       
    24 #include <HbTextItem>
       
    25 #include <HbFrameItem>
       
    26 
       
    27 #include "msgcommondefines.h"
       
    28 #include "conversationsengine.h"
       
    29 #include "conversationsenginedefines.h"
       
    30 #include "msgutils.h"
       
    31 #include "convergedmessage.h"
       
    32 #include "debugtraces.h"
       
    33 
       
    34 #define NEW_ITEM_FRAME ":/newitem/qtg_fr_list_new_item"
       
    35 #define LOC_RINGING_TONE hbTrId("txt_messaging_dpopinfo_ringing_tone")
       
    36 
       
    37 const QString LIST_ITEM_BG_FRAME("qtg_fr_list_normal");
       
    38 
       
    39 //---------------------------------------------------------------
       
    40 // MsgListViewItem::MsgListViewItem
       
    41 // Constructor
       
    42 //---------------------------------------------------------------
       
    43 MsgListViewItem::MsgListViewItem(QGraphicsItem* parent) :
       
    44     HbListViewItem(parent),
       
    45     mUnReadMsg(false),
       
    46     mNewMsgIndicatorItem(NULL),
       
    47     mBgFrameItem(NULL),
       
    48     mAddressLabelItem(NULL),
       
    49     mTimestampItem(NULL),
       
    50     mPreviewLabelItem(NULL),
       
    51     mUnreadCountItem(NULL),
       
    52     mPresenceIndicatorItem(NULL)
       
    53 {
       
    54 }
       
    55 
       
    56 //---------------------------------------------------------------
       
    57 // HbAbstractViewItem::createItem
       
    58 // @see header
       
    59 //---------------------------------------------------------------
       
    60 HbAbstractViewItem* MsgListViewItem::createItem()
       
    61 {
       
    62     return new MsgListViewItem(*this);
       
    63 }
       
    64 
       
    65 //---------------------------------------------------------------
       
    66 // MsgListViewItem::updateChildItems
       
    67 // @see header
       
    68 //---------------------------------------------------------------
       
    69 void MsgListViewItem::updateChildItems()
       
    70 {
       
    71     if (!mAddressLabelItem)
       
    72     {
       
    73         mAddressLabelItem = new HbTextItem(this);
       
    74         HbStyle::setItemName(mAddressLabelItem, "addressLabel");
       
    75     }
       
    76     if (!mTimestampItem)
       
    77     {
       
    78         mTimestampItem = new HbTextItem(this);
       
    79         HbStyle::setItemName(mTimestampItem, "timeLabel");
       
    80     }
       
    81     if (!mPreviewLabelItem)
       
    82     {
       
    83         mPreviewLabelItem = new HbTextItem(this);
       
    84         mPreviewLabelItem->setTextWrapping(Hb::TextWordWrap);
       
    85         HbStyle::setItemName(mPreviewLabelItem, "previewLabel");
       
    86     }
       
    87     if (!mUnreadCountItem)
       
    88     {
       
    89         mUnreadCountItem = new HbTextItem(this);
       
    90         HbStyle::setItemName(mUnreadCountItem, "unreadCount");
       
    91     }
       
    92     if (!mNewMsgIndicatorItem)
       
    93     {
       
    94         mNewMsgIndicatorItem = new HbFrameItem(this);
       
    95         HbStyle::setItemName(mNewMsgIndicatorItem, "newMsgIndicator");
       
    96 
       
    97         mNewMsgIndicatorItem->frameDrawer().setFrameType(
       
    98             HbFrameDrawer::ThreePiecesVertical);
       
    99     }
       
   100     if (!mBgFrameItem)
       
   101     {
       
   102         mBgFrameItem = new HbFrameItem(this);
       
   103         mBgFrameItem->setZValue(-1.0);
       
   104         HbStyle::setItemName(mBgFrameItem, "bgFrame");
       
   105         
       
   106         mBgFrameItem->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME);
       
   107         mBgFrameItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
       
   108     }
       
   109 
       
   110     // Time Stamp.
       
   111     QDateTime dateTime;
       
   112     dateTime.setTime_t(modelIndex().data(TimeStamp).toUInt());
       
   113     QString dateString;
       
   114     if (dateTime.date() == QDateTime::currentDateTime().date())
       
   115     {
       
   116         dateString = MsgUtils::dateTimeToString(dateTime, TIME_FORMAT);
       
   117     }
       
   118     else
       
   119     {
       
   120         dateString = MsgUtils::dateTimeToString(dateTime, DATE_FORMAT);
       
   121     }
       
   122 
       
   123     mTimestampItem->setText(dateString);
       
   124 
       
   125     //Sender
       
   126     QString firstName = modelIndex().data(FirstName).toString();
       
   127     QString lastName = modelIndex().data(LastName).toString();
       
   128     QString nickName = modelIndex().data(NickName).toString();
       
   129     QString contactAddress = modelIndex().data(ConversationAddress).toString();
       
   130     QString contactName;
       
   131 
       
   132     if (!nickName.isEmpty())
       
   133     {
       
   134         contactName.append(nickName);
       
   135     }
       
   136     else if (firstName.isEmpty() && lastName.isEmpty())
       
   137     {
       
   138         contactName.append(contactAddress);
       
   139     }
       
   140     else if (lastName.isEmpty())
       
   141     {
       
   142         contactName.append(firstName);
       
   143     }
       
   144     else if (firstName.isEmpty())
       
   145     {
       
   146         contactName.append(lastName);
       
   147     }
       
   148     else
       
   149     {
       
   150         // If both first Name and last name are present
       
   151         contactName.append(firstName);
       
   152         contactName.append(" ");
       
   153         contactName.append(lastName);
       
   154     }
       
   155     mAddressLabelItem->setText(contactName);
       
   156 
       
   157     // Latest Message
       
   158     int messageType = modelIndex().data(MessageType).toInt();
       
   159     QString previewText;
       
   160     // Set the message text depending upon the message type
       
   161     if (messageType == ConvergedMessage::Mms)
       
   162     {
       
   163         QDEBUG_WRITE("MsgListViewItem::updateChildItems Mms block")
       
   164         previewText = modelIndex().data(Subject).toString();
       
   165     }
       
   166     else if(messageType == ConvergedMessage::RingingTone)
       
   167     {
       
   168         QDEBUG_WRITE("MsgListViewItem::updateChildItems RingingTone block")
       
   169         previewText = LOC_RINGING_TONE;
       
   170     }
       
   171 	else if (messageType == ConvergedMessage::VCard)
       
   172     {
       
   173         previewText = QString("Business Card");
       
   174     }
       
   175     else if (messageType == ConvergedMessage::VCal)
       
   176     {
       
   177         previewText = QString("Calender Event");
       
   178     }
       
   179     else if(messageType == ConvergedMessage::BioMsg)
       
   180     {
       
   181         previewText = QString("Unsupported Type");
       
   182     }
       
   183     else
       
   184     {
       
   185         QDEBUG_WRITE("MsgListViewItem::updateChildItems default block")
       
   186         previewText = modelIndex().data(BodyText).toString();
       
   187     }
       
   188     mPreviewLabelItem->setText(previewText);
       
   189 
       
   190     // Unread message count
       
   191     int unreadCount = modelIndex().data(UnreadCount).toInt();
       
   192     QString unRead;
       
   193     if (unreadCount > 0)
       
   194     {
       
   195         unRead.append(tr("(%n)", "", unreadCount));
       
   196         mUnreadCountItem->setText(unRead);
       
   197         mUnReadMsg = true;
       
   198         mNewMsgIndicatorItem->frameDrawer().setFrameGraphicsName(NEW_ITEM_FRAME);
       
   199     }
       
   200     else
       
   201     {
       
   202         mUnreadCountItem->setText("");
       
   203         mNewMsgIndicatorItem->frameDrawer().setFrameGraphicsName(QString());
       
   204         mUnReadMsg = false;
       
   205         repolish();
       
   206     }
       
   207 
       
   208     HbListViewItem::updateChildItems();
       
   209 }
       
   210 
       
   211 //---------------------------------------------------------------
       
   212 // MsgListViewItem::paint.
       
   213 // @see header
       
   214 //---------------------------------------------------------------
       
   215 /*void MsgListViewItem::paint(QPainter *painter,
       
   216  const QStyleOptionGraphicsItem *option,
       
   217  QWidget *widget)
       
   218  {
       
   219 
       
   220  }
       
   221  */
       
   222 
       
   223 //---------------------------------------------------------------
       
   224 // MsgListViewItem::setWidgetContent
       
   225 // @see header file
       
   226 //---------------------------------------------------------------
       
   227 void MsgListViewItem::setHasUnReadMsg(bool unread)
       
   228 {
       
   229     mUnReadMsg = unread;
       
   230 }
       
   231 
       
   232 //---------------------------------------------------------------
       
   233 // MsgListViewItem::setWidgetContent
       
   234 // @see header file
       
   235 //---------------------------------------------------------------
       
   236 bool MsgListViewItem::hasUnReadMsg()
       
   237 {
       
   238     return mUnReadMsg;
       
   239 }
       
   240 
       
   241 //EOF