messagingapp/msgui/conversationview/src/msgconversationview.cpp
changeset 34 84197e66a4bd
parent 31 ebfee66fde93
child 43 35b64624a9e7
equal deleted inserted replaced
31:ebfee66fde93 34:84197e66a4bd
    22 #include <HbAction>
    22 #include <HbAction>
    23 #include <HbListView>
    23 #include <HbListView>
    24 #include <HbMessageBox>
    24 #include <HbMessageBox>
    25 #include <HbNotificationDialog>
    25 #include <HbNotificationDialog>
    26 #include <HbFrameBackground>
    26 #include <HbFrameBackground>
    27 #include <XQServiceRequest.h>
    27 #include <xqservicerequest.h>
    28 #include <HbStaticVkbHost>
    28 #include <HbStaticVkbHost>
    29 #include <HbStyleLoader>
    29 #include <HbStyleLoader>
    30 #include <xqaiwrequest.h>
    30 #include <xqaiwrequest.h>
    31 #include <xqappmgr.h>
    31 #include <xqappmgr.h>
       
    32 #include <HbMainWindow>
    32 
    33 
    33 #include <QDir>
    34 #include <QDir>
    34 #include <QDateTime>
    35 #include <QDateTime>
    35 #include <QGraphicsLinearLayout>
    36 #include <QGraphicsLinearLayout>
    36 #include <QStandardItemModel>
    37 #include <QStandardItemModel>
    39 #include <ccsdefs.h>
    40 #include <ccsdefs.h>
    40 #include <centralrepository.h>
    41 #include <centralrepository.h>
    41 #include <MmsEngineDomainCRKeys.h>
    42 #include <MmsEngineDomainCRKeys.h>
    42 
    43 
    43 // USER INCLUDES
    44 // USER INCLUDES
       
    45 #include "msgcontactsutil.h"
    44 #include "msgsendutil.h"
    46 #include "msgsendutil.h"
    45 #include "msgconversationviewitem.h"
    47 #include "msgconversationviewitem.h"
    46 #include "conversationsengine.h"
    48 #include "conversationsengine.h"
    47 #include "convergedmessageid.h"
    49 #include "convergedmessageid.h"
    48 #include "conversationsenginedefines.h"
    50 #include "conversationsenginedefines.h"
    60 
    62 
    61 #define LOC_COMMON_OPEN hbTrId("txt_common_menu_open")
    63 #define LOC_COMMON_OPEN hbTrId("txt_common_menu_open")
    62 #define LOC_COMMON_DELETE hbTrId("txt_common_menu_delete")
    64 #define LOC_COMMON_DELETE hbTrId("txt_common_menu_delete")
    63 #define LOC_COMMON_FORWARD hbTrId("txt_common_menu_forward")
    65 #define LOC_COMMON_FORWARD hbTrId("txt_common_menu_forward")
    64 #define LOC_COMMON_DOWNLOAD hbTrId("txt_messaging_menu_download")
    66 #define LOC_COMMON_DOWNLOAD hbTrId("txt_messaging_menu_download")
    65 #define LOC_COMMON_SEND  hbTrId("txt_common_menu_send") 
    67 #define LOC_COMMON_SEND  hbTrId("txt_common_button_send") 
    66 #define LOC_COMMON_SAVE  hbTrId("txt_common_menu_save")
    68 #define LOC_COMMON_SAVE  hbTrId("txt_common_menu_save")
    67 #define LOC_BUTTON_DELETE hbTrId("txt_common_button_delete")
    69 #define LOC_BUTTON_DELETE hbTrId("txt_common_button_delete")
    68 #define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel")
    70 #define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel")
    69 #define LOC_BUTTON_OK hbTrId("txt_common_button_ok")
    71 #define LOC_BUTTON_OK hbTrId("txt_common_button_ok")
    70 
    72 
    76 #define LOC_SOUND           hbTrId("txt_messaging_opt_attach_sub_sound")
    78 #define LOC_SOUND           hbTrId("txt_messaging_opt_attach_sub_sound")
    77 #define LOC_VCARD           hbTrId("txt_messaging_list_business_card")
    79 #define LOC_VCARD           hbTrId("txt_messaging_list_business_card")
    78 #define LOC_ADD_RECIPIENTS  hbTrId("txt_messaging_opt_add_recipients")
    80 #define LOC_ADD_RECIPIENTS  hbTrId("txt_messaging_opt_add_recipients")
    79 #define LOC_ADD_SUBJECT     hbTrId("txt_messaging_opt_add_subject")
    81 #define LOC_ADD_SUBJECT     hbTrId("txt_messaging_opt_add_subject")
    80 
    82 
    81 #define LOC_MSG_SEND_FAILED hbTrId("txt_messaging_dpopinfo_sending_failed")
    83 #define LOC_MSG_SEND_FAILED hbTrId("txt_messaging_dialog_message_sending_failed")
    82 
       
    83 #define LOC_DIALOG_SMS_SETTINGS_INCOMPLETE hbTrId("txt_messaging_dialog_sms_settings_incomplete")
    84 #define LOC_DIALOG_SMS_SETTINGS_INCOMPLETE hbTrId("txt_messaging_dialog_sms_settings_incomplete")
    84 #define LOC_DIALOG_SAVE_RINGTONE hbTrId("txt_conversations_dialog_save_ringing_tone")
    85 #define LOC_DIALOG_SAVE_RINGTONE hbTrId("txt_conversations_dialog_save_ringing_tone")
    85 
    86 #define LOC_CONTACT_SAVED hbTrId("txt_messaging_dpopinfo_contact_saved")
    86 
       
    87 
    87 
    88 const int INVALID_MSGID = -1;
    88 const int INVALID_MSGID = -1;
    89 const int INVALID_CONVID = -1;
    89 const int INVALID_CONVID = -1;
    90 const int CONTACT_INSERTION_MODE = 1;
    90 const int CONTACT_INSERTION_MODE = 1;
    91 const int VCARD_INSERTION_MODE = 0;
    91 const int VCARD_INSERTION_MODE = 0;
   100     mConversationList(NULL),
   100     mConversationList(NULL),
   101     mMessageModel(NULL),
   101     mMessageModel(NULL),
   102     mEditorWidget(NULL),
   102     mEditorWidget(NULL),
   103     mContactCardWidget(contactCardWidget),
   103     mContactCardWidget(contactCardWidget),
   104     mSendUtil(NULL),
   104     mSendUtil(NULL),
   105     mItemLongPressed(false),
       
   106     mVkbHost(NULL),
   105     mVkbHost(NULL),
   107     mVkbopened(false)
   106     mVkbopened(false),
   108 {
   107     mVisibleIndex()
       
   108 {
       
   109     connect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(onViewReady()));
   109     //create send utils
   110     //create send utils
   110     mSendUtil = new MsgSendUtil(this);
   111     mSendUtil = new MsgSendUtil(this);
   111     //initialize view
   112     //initialize view
   112     setupView();
   113     setupView();
   113     setupMenu();
   114     setupMenu();
   150             this, 
   151             this, 
   151             SLOT(populateConversationsView()));
   152             SLOT(populateConversationsView()));
   152     
   153     
   153     connect(mConversationList, SIGNAL(activated(QModelIndex)),
   154     connect(mConversationList, SIGNAL(activated(QModelIndex)),
   154             this, SLOT(openItem(QModelIndex)));
   155             this, SLOT(openItem(QModelIndex)));
       
   156     connect(this->mainWindow(), SIGNAL(aboutToChangeOrientation()),
       
   157                 this, SLOT(onOrientationAboutToBeChanged()));
       
   158     
       
   159     connect(this->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
       
   160                     this, SLOT(onOrientationChanged(Qt::Orientation)));
   155 
   161 
   156     // Long tap list item
   162     // Long tap list item
   157     connect(mConversationList, SIGNAL(longPressed(HbAbstractViewItem*, QPointF)),
   163     connect(mConversationList, SIGNAL(longPressed(HbAbstractViewItem*, QPointF)),
   158             this, SLOT(longPressed(HbAbstractViewItem*, QPointF)));
   164             this, SLOT(longPressed(HbAbstractViewItem*, QPointF)));
   159 
   165 
   239 // @see header file
   245 // @see header file
   240 //---------------------------------------------------------------
   246 //---------------------------------------------------------------
   241 void MsgConversationView::longPressed(HbAbstractViewItem* viewItem,
   247 void MsgConversationView::longPressed(HbAbstractViewItem* viewItem,
   242     const QPointF& point)
   248     const QPointF& point)
   243 {    
   249 {    
   244     mItemLongPressed = true;
       
   245     
       
   246     MsgConversationViewItem* item = qgraphicsitem_cast<
   250     MsgConversationViewItem* item = qgraphicsitem_cast<
   247             MsgConversationViewItem *> (viewItem);
   251             MsgConversationViewItem *> (viewItem);
   248 
   252 
   249     // Show the item-specific menu
   253     // Show the item-specific menu
   250     if (this->isVisible())
   254     if (this->isVisible())
   264         contextMenu->setPreferredPos(point);
   268         contextMenu->setPreferredPos(point);
   265         setContextMenu(item, contextMenu, sendingState);
   269         setContextMenu(item, contextMenu, sendingState);
   266         contextMenu->show();
   270         contextMenu->show();
   267 
   271 
   268     }
   272     }
   269     else
   273     
   270     {
       
   271         // For cases where the long tap check failed
       
   272         mItemLongPressed = false;
       
   273     }
       
   274 }
   274 }
   275 
   275 
   276 //---------------------------------------------------------------
   276 //---------------------------------------------------------------
   277 // MsgConversationView::setContextMenu
   277 // MsgConversationView::setContextMenu
   278 // @see header
   278 // @see header
   294 // @see header
   294 // @see header
   295 //---------------------------------------------------------------
   295 //---------------------------------------------------------------
   296 void MsgConversationView::addSaveItemToContextMenu(MsgConversationViewItem* item,
   296 void MsgConversationView::addSaveItemToContextMenu(MsgConversationViewItem* item,
   297     HbMenu* contextMenu, int sendingState)
   297     HbMenu* contextMenu, int sendingState)
   298 {
   298 {
       
   299     Q_UNUSED(sendingState)
       
   300 
   299     int messageSubType = item->modelIndex().data(MessageSubType).toInt();
   301     int messageSubType = item->modelIndex().data(MessageSubType).toInt();
   300     int direction =  item->modelIndex().data(Direction).toInt();
   302     int direction =  item->modelIndex().data(Direction).toInt();
   301     if ((messageSubType == ConvergedMessage::RingingTone) && 
   303     if ((messageSubType == ConvergedMessage::RingingTone) && 
   302         (direction == ConvergedMessage::Incoming)) {
   304         (direction == ConvergedMessage::Incoming)) {
   303         HbAction *contextItem = contextMenu->addAction(LOC_COMMON_SAVE);
   305         HbAction *contextItem = contextMenu->addAction(LOC_COMMON_SAVE);
   372     {
   374     {
   373         return;
   375         return;
   374     }
   376     }
   375     
   377     
   376     qint32 messageId = item->modelIndex().data(ConvergedMsgId).toInt();
   378     qint32 messageId = item->modelIndex().data(ConvergedMsgId).toInt();
       
   379     qint32 messageProperty = item->modelIndex().data(MessageProperty).toInt();
       
   380     
       
   381     bool canForwardMessage  = true;
       
   382     if (messageType == ConvergedMessage::Mms){
       
   383         canForwardMessage = (messageProperty & EPreviewForward)? true:false;
       
   384     }            
   377 
   385 
   378     if( ((sendingState == ConvergedMessage::SentState) ||
   386     if( ((sendingState == ConvergedMessage::SentState) ||
   379         (sendingState == ConvergedMessage::Resend) ||
   387         (sendingState == ConvergedMessage::Resend) ||
   380         (sendingState == ConvergedMessage::Failed) ||
   388         (sendingState == ConvergedMessage::Failed) ||
   381         (direction == ConvergedMessage::Incoming) ) &&
   389         (direction == ConvergedMessage::Incoming) ) &&
   382         (validateMsgForForward(messageType,messageId))	)
   390         canForwardMessage)
   383     {
   391     {
   384         HbAction *contextItem = contextMenu->addAction(LOC_COMMON_FORWARD);
   392         HbAction *contextItem = contextMenu->addAction(LOC_COMMON_FORWARD);
   385         connect(contextItem, SIGNAL(triggered()),this, SLOT(forwardMessage()));
   393         connect(contextItem, SIGNAL(triggered()),this, SLOT(forwardMessage()));
   386     }
   394     }
   387 
   395 
   534 // MsgConversationView::fetchImages
   542 // MsgConversationView::fetchImages
   535 // @see header file
   543 // @see header file
   536 //---------------------------------------------------------------
   544 //---------------------------------------------------------------
   537 void MsgConversationView::fetchImages()
   545 void MsgConversationView::fetchImages()
   538 {
   546 {
   539     QString interface("Image");
   547     QString service("photos");
   540     QString operation("fetch(QVariantMap,QVariant)");
   548     QString interface("com.nokia.symbian.IImageFetch");
       
   549     QString operation("fetch(void)");
   541     XQAiwRequest* request = NULL;
   550     XQAiwRequest* request = NULL;
   542     XQApplicationManager appManager;
   551     XQApplicationManager appManager;
   543     request = appManager.create(interface, operation, true); // embedded
   552     request = appManager.create(service,interface, operation, true); // embedded
   544     request->setSynchronous(true); // synchronous
   553     request->setSynchronous(true); // synchronous
   545     if(!request)
   554     if(!request)
   546     {
   555     {
   547         QDEBUG_WRITE("AIW-ERROR: NULL request");
   556         QDEBUG_WRITE("AIW-ERROR: NULL request");
   548         return;
   557         return;
   551     connect(request, SIGNAL(requestOk(const QVariant&)),
   560     connect(request, SIGNAL(requestOk(const QVariant&)),
   552         this, SLOT(imagesFetched(const QVariant&)));
   561         this, SLOT(imagesFetched(const QVariant&)));
   553     connect(request, SIGNAL(requestError(int,const QString&)),
   562     connect(request, SIGNAL(requestError(int,const QString&)),
   554         this, SLOT(serviceRequestError(int,const QString&)));
   563         this, SLOT(serviceRequestError(int,const QString&)));
   555 
   564 
   556     // Set arguments for request
       
   557     QList<QVariant> args;
       
   558     args << QVariantMap();
       
   559     args << QVariant();
       
   560     request->setArguments(args);
       
   561     // Make the request
   565     // Make the request
   562     if (!request->send())
   566     if (!request->send())
   563     {
   567     {
   564         QDEBUG_WRITE_FORMAT("AIW-ERROR: Request Send failed:" , request->lastError());
   568         QDEBUG_WRITE_FORMAT("AIW-ERROR: Request Send failed:" , request->lastError());
   565     }  
   569     }  
   812 //---------------------------------------------------------------
   816 //---------------------------------------------------------------
   813 void MsgConversationView::launchBtDisplayService(const QModelIndex & index)
   817 void MsgConversationView::launchBtDisplayService(const QModelIndex & index)
   814 {
   818 {
   815     qint32 messageId = index.data(ConvergedMsgId).toLongLong();
   819     qint32 messageId = index.data(ConvergedMsgId).toLongLong();
   816 
   820 
   817     QString interface("com.nokia.services.btmsgdispservices.displaymsg");
   821     QList<QVariant> args;
       
   822     QString serviceName("com.nokia.services.btmsgdispservices.displaymsg");
   818     QString operation("displaymsg(int)");
   823     QString operation("displaymsg(int)");
   819 
   824     XQAiwRequest* request;
   820     XQServiceRequest request(interface, operation, false);
   825     XQApplicationManager appManager;
   821 
   826     request = appManager.create(serviceName, "displaymsg", operation, true); // embedded
   822     request << messageId;
   827     
   823 
   828     if ( request == NULL )
   824     bool result = request.send();
   829         {
       
   830         return;
       
   831         }
       
   832 
       
   833     args << QVariant(messageId);
       
   834     
       
   835     request->setArguments(args);
       
   836     request->send();
       
   837     delete request;    
   825 }
   838 }
   826 
   839 
   827 //---------------------------------------------------------------
   840 //---------------------------------------------------------------
   828 // MsgConversationView::menuAboutToShow()
   841 // MsgConversationView::menuAboutToShow()
   829 // @See header
   842 // @See header
   859 //---------------------------------------------------------------
   872 //---------------------------------------------------------------
   860 //MsgConversationView::openItem
   873 //MsgConversationView::openItem
   861 //@see header
   874 //@see header
   862 //---------------------------------------------------------------
   875 //---------------------------------------------------------------
   863 void MsgConversationView::openItem(const QModelIndex & index)
   876 void MsgConversationView::openItem(const QModelIndex & index)
   864     {
   877 {
   865     // Return if invalid index.
   878     // Return if invalid index.
   866     if (!index.isValid() || mVkbopened)
   879     if (!index.isValid() || mVkbopened)
   867         {
   880     {
   868         return;
   881         return;
   869         }
   882     }
   870 
       
   871     if(mItemLongPressed)
       
   872         {
       
   873         //reset the flag
       
   874         mItemLongPressed = false;
       
   875         return;
       
   876         }
       
   877     
   883     
   878     int messageType = index.data(MessageType).toInt();
   884     int messageType = index.data(MessageType).toInt();
   879     int messageSubType = index.data(MessageSubType).toInt();
   885     int messageSubType = index.data(MessageSubType).toInt();
   880     
   886     int messageId = index.data(ConvergedMsgId).toInt();
   881     if (ConvergedMessage::BioMsg == messageType) {
   887     
   882         if (ConvergedMessage::RingingTone == messageSubType) {
   888     if (ConvergedMessage::BioMsg == messageType)
       
   889     {
       
   890         if (ConvergedMessage::RingingTone == messageSubType)
       
   891         {
   883             HbMessageBox::question(LOC_DIALOG_SAVE_RINGTONE, this,
   892             HbMessageBox::question(LOC_DIALOG_SAVE_RINGTONE, this,
   884                     SLOT(onDialogSaveTone(HbAction*)), LOC_COMMON_SAVE, LOC_BUTTON_CANCEL);
   893                     SLOT(onDialogSaveTone(HbAction*)), LOC_COMMON_SAVE, LOC_BUTTON_CANCEL);
   885             return;
   894             return;
   886         }
   895         }
   887         else if(ConvergedMessage::Provisioning == messageSubType)
   896         else if(ConvergedMessage::Provisioning == messageSubType)
   888             {
   897         {
   889             int messageId = index.data(ConvergedMsgId).toInt();
   898             int messageId = index.data(ConvergedMsgId).toInt();
   890             handleProvisoningMsg(messageId);
   899             handleProvisoningMsg(messageId);
   891             QList<int> msgIdList;
   900             QList<int> msgIdList;
   892             if(index.data(UnReadStatus).toInt())
   901             if(index.data(UnReadStatus).toInt())
   893                 {
   902             {
   894                 msgIdList.clear();
   903                 msgIdList.clear();
   895                 msgIdList << messageId;
   904                 msgIdList << messageId;
   896                 ConversationsEngine::instance()->markMessagesRead(msgIdList);
   905                 ConversationsEngine::instance()->markMessagesRead(msgIdList);
       
   906             }
       
   907             return;
       
   908         }
       
   909         else if(ConvergedMessage::VCard == messageSubType)
       
   910         {
       
   911             QString filepath = index.data(Attachments).toStringList().at(0);
       
   912             bool result = MsgContactsUtil::launchVCardViewer(filepath);
       
   913             if(result)
       
   914             {
       
   915                 HbNotificationDialog::launchDialog(LOC_CONTACT_SAVED);
       
   916                 int messageId = index.data(ConvergedMsgId).toInt();
       
   917                 QList<int> msgIdList;
       
   918                 if(index.data(UnReadStatus).toInt())
       
   919                 {
       
   920                     msgIdList.clear();
       
   921                     msgIdList << messageId;
       
   922                     ConversationsEngine::instance()->markMessagesRead(msgIdList);
   897                 }
   923                 }
       
   924             }
   898             return;
   925             return;
   899             }
   926         }
   900         // Unsupported messages
   927         else if(ConvergedMessage::VCal == messageSubType)
   901         else if (ConvergedMessage::VCard == messageSubType
   928         {
   902             || ConvergedMessage::VCal == messageSubType) {
       
   903             return;
   929             return;
   904         }
   930         }
   905     }
   931     }
   906     else if (ConvergedMessage::BT == messageType) {
   932     else if (ConvergedMessage::BT == messageType)
       
   933     {
   907         launchBtDisplayService(index);
   934         launchBtDisplayService(index);
   908         return;
   935         return;
   909     }
   936     }
   910     else if(ConvergedMessage::MmsNotification == messageType)
   937     else if(ConvergedMessage::MmsNotification == messageType)
   911     {
   938     {
   927                 LOC_BUTTON_CANCEL);
   954                 LOC_BUTTON_CANCEL);
   928             return;
   955             return;
   929         }
   956         }
   930     }
   957     }
   931 
   958 
   932     ConvergedMessage message;
   959     int direction = index.data(Direction).toInt();
       
   960 
       
   961     if (direction == ConvergedMessage::Outgoing && ConvergedMessage::Sms == messageType
       
   962         && ConversationsEngine::instance()->getMsgSubType(messageId)== ConvergedMessage::NokiaService)
       
   963     {
       
   964         return;
       
   965     }
       
   966     
   933     // check whether message is in sending progress, then donot launch viewer.
   967     // check whether message is in sending progress, then donot launch viewer.
   934     int location = index.data(MessageLocation).toInt();
   968     int location = index.data(MessageLocation).toInt();
   935     int sendingState = index.data(SendingState).toInt();
   969     int sendingState = index.data(SendingState).toInt();
   936     
   970     
   937     //If message is in Sending state or is Scheduled to be sent later,
   971     //If message is in Sending state or is Scheduled to be sent later,
   949     if( !((location == ConvergedMessage::Inbox) ||
   983     if( !((location == ConvergedMessage::Inbox) ||
   950         (location == ConvergedMessage::Sent) ||
   984         (location == ConvergedMessage::Sent) ||
   951         (sendingState == ConvergedMessage::SentState)||
   985         (sendingState == ConvergedMessage::SentState)||
   952         (sendingState == ConvergedMessage::Failed) ||
   986         (sendingState == ConvergedMessage::Failed) ||
   953         (sendingState == ConvergedMessage::Resend)))
   987         (sendingState == ConvergedMessage::Resend)))
   954         {// do not launch viewer, show a note
   988     {// do not launch viewer, show a note
   955         HbNotificationDialog* dlg = new HbNotificationDialog();
   989         HbNotificationDialog* dlg = new HbNotificationDialog();
   956         dlg->setFocusPolicy(Qt::NoFocus);
   990         dlg->setFocusPolicy(Qt::NoFocus);
   957         QString text(tr("Message Locked"));
   991         QString text(tr("Message Locked"));
   958         dlg->setText(text);
   992         dlg->setText(text);
   959         dlg->setDismissPolicy(HbPopup::TapAnywhere);
   993         dlg->setDismissPolicy(HbPopup::TapAnywhere);
   960         dlg->setAttribute(Qt::WA_DeleteOnClose, true);
   994         dlg->setAttribute(Qt::WA_DeleteOnClose, true);
   961         dlg->show();
   995         dlg->show();
   962         return;
   996         return;
   963 		}
   997 	}
   964 
   998    
   965         // message id
   999     
   966         qint32 messageId = index.data(ConvergedMsgId).toLongLong();
  1000     // contact Id
   967         ConvergedMessageId msgId(messageId);
  1001     qint32 contactId = index.data(ContactId).toLongLong();  
   968         message.setMessageId(msgId);
  1002 	    
   969 
  1003     //if message unread, mark as read before opening view
   970         // contact Id
  1004     QList<int> msgIdList;
   971         qint32 contactId = index.data(ContactId).toLongLong();
  1005     if(index.data(UnReadStatus).toInt())
   972 
  1006     {
   973         // message type
       
   974 
       
   975         message.setMessageType((ConvergedMessage::MessageType) messageType);
       
   976         message.setMessageSubType((ConvergedMessage::MessageSubType) messageSubType);
       
   977 
       
   978         if (messageType == ConvergedMessage::Mms)
       
   979         {
       
   980             message.setSubject(index.data(Subject).toString());
       
   981             message.setPriority((ConvergedMessage::Priority) index.data(
       
   982                 MessagePriority).toInt());
       
   983         }
       
   984         else if (messageType == ConvergedMessage::IM)
       
   985         {
       
   986             // add body text and send to the message for IM case
       
   987             message.setBodyText(index.data(BodyText).toString());
       
   988         }
       
   989 
       
   990         // time stamp
       
   991         message.setTimeStamp(index.data(TimeStamp).toLongLong());
       
   992 
       
   993         //Message direction
       
   994         message.setDirection((ConvergedMessage::Direction)index.data(Direction).toInt());
       
   995 
       
   996         // conatct name as address
       
   997         ConvergedMessageAddress address;
       
   998         address.setAlias(mContactCardWidget->address().at(0)->alias());
       
   999         address.setAddress(mContactCardWidget->address().at(0)->address());
       
  1000         message.addToRecipient(address);
       
  1001 
       
  1002         // Mark this message as read if its unread
       
  1003         QByteArray dataArray;
       
  1004         QDataStream messageStream
       
  1005         (&dataArray, QIODevice::WriteOnly | QIODevice::Append);
       
  1006         message.serialize(messageStream);
       
  1007         //if message unread, mark as read before opening view
       
  1008         QList<int> msgIdList;
       
  1009         if(index.data(UnReadStatus).toInt())
       
  1010             {
       
  1011         msgIdList.clear();
  1007         msgIdList.clear();
  1012         msgIdList << messageId;
  1008         msgIdList << messageId;
  1013         ConversationsEngine::instance()->markMessagesRead(msgIdList);
  1009         ConversationsEngine::instance()->markMessagesRead(msgIdList);
  1014         }
  1010     }
  1015 
  1011     
  1016         //switch view
  1012     qint32 messageProperty = index.data(MessageProperty).toInt();
  1017         QVariantList param;
  1013 
  1018         param << MsgBaseView::UNIVIEWER;  // target view
  1014     bool canForwardMessage  = true;
  1019         param << MsgBaseView::CV; // source view
  1015     if (messageType == ConvergedMessage::Mms){
  1020 
  1016         canForwardMessage = (messageProperty & EPreviewForward)? true:false;
  1021         param << contactId;
  1017     } 
  1022         param << dataArray;
  1018     
  1023         param << mMessageModel->rowCount();
  1019     //switch view
  1024 
  1020     QVariantList param;
  1025         emit switchView(param);
  1021     param << MsgBaseView::UNIVIEWER;  // target view
       
  1022     param << MsgBaseView::CV; // source view
       
  1023 
       
  1024     param << contactId;
       
  1025     param << messageId;
       
  1026     param << mMessageModel->rowCount();
       
  1027     if (canForwardMessage == true)
       
  1028     {
       
  1029       param << 1;
       
  1030     }
       
  1031     else
       
  1032    	{
       
  1033    		param << 0;
       
  1034    	}
       
  1035     emit switchView(param);
  1026 }
  1036 }
  1027 
  1037 
  1028 //---------------------------------------------------------------
  1038 //---------------------------------------------------------------
  1029 // MsgConversationView::launchUniEditor
  1039 // MsgConversationView::launchUniEditor
  1030 // @see header file
  1040 // @see header file
  1172     params << MsgBaseView::ADD_OTHERS;
  1182     params << MsgBaseView::ADD_OTHERS;
  1173     launchUniEditor(params);   
  1183     launchUniEditor(params);   
  1174 }
  1184 }
  1175 
  1185 
  1176 //---------------------------------------------------------------
  1186 //---------------------------------------------------------------
  1177 // MsgConversationView::validateMsgForForward
       
  1178 // @see header file
       
  1179 //---------------------------------------------------------------
       
  1180 bool MsgConversationView::validateMsgForForward(int &messageType,
       
  1181     qint32 &messageId)
       
  1182 {
       
  1183     bool retValue = true;
       
  1184     if (messageType == ConvergedMessage::Mms)
       
  1185     {
       
  1186         //Validate if the mms msg can be forwarded or not
       
  1187         MmsConformanceCheck* mmsConformanceCheck = new MmsConformanceCheck;
       
  1188         retValue = mmsConformanceCheck->validateMsgForForward(messageId);
       
  1189         
       
  1190         delete mmsConformanceCheck;
       
  1191     }
       
  1192 
       
  1193     return retValue;
       
  1194 }
       
  1195 
       
  1196 //---------------------------------------------------------------
       
  1197 // MsgConversationView::vkbOpened
  1187 // MsgConversationView::vkbOpened
  1198 // @see header file
  1188 // @see header file
  1199 //---------------------------------------------------------------
  1189 //---------------------------------------------------------------
  1200 void MsgConversationView::vkbOpened()
  1190 void MsgConversationView::vkbOpened()
  1201 {
  1191 {
  1202     mVkbopened = true;
  1192     mVkbopened = true;
  1203     
  1193     
  1204     mContactCardWidget->connectSignals(false);
  1194     emit vkbOpened(true);
  1205     
       
  1206     emit hideChrome(true);
       
  1207     
  1195     
  1208     QRectF appRect = mVkbHost->applicationArea();    
  1196     QRectF appRect = mVkbHost->applicationArea();    
  1209     qreal spacing = 0.0;
  1197     qreal spacing = 0.0;
  1210     qreal cardHeight = 0.0;
  1198     qreal cardHeight = 0.0;
  1211     if(mContactCardWidget->isVisible())
  1199     if(mContactCardWidget->isVisible())
  1227 //---------------------------------------------------------------
  1215 //---------------------------------------------------------------
  1228 void MsgConversationView::vkbClosed()
  1216 void MsgConversationView::vkbClosed()
  1229 {
  1217 {
  1230     mVkbopened = false;
  1218     mVkbopened = false;
  1231     
  1219     
  1232     mContactCardWidget->connectSignals(true);
  1220     emit vkbOpened(false);
  1233     
       
  1234     emit hideChrome(false);
       
  1235     
  1221     
  1236     this->setMaximumHeight(-1);
  1222     this->setMaximumHeight(-1);
  1237     connect(mVkbHost,SIGNAL(keypadOpened()),this,SLOT(vkbOpened()));
  1223     connect(mVkbHost,SIGNAL(keypadOpened()),this,SLOT(vkbOpened()));
  1238     
  1224     
  1239     scrollToBottom();
  1225     scrollToBottom();
  1249 }
  1235 }
  1250 
  1236 
  1251 //---------------------------------------------------------------
  1237 //---------------------------------------------------------------
  1252 // MsgConversationView::activateInputBlocker
  1238 // MsgConversationView::activateInputBlocker
  1253 // @see header file
  1239 // @see header file
  1254 //--------------------------------------------------------------
  1240 //---------------------------------------------------------------
  1255 void MsgConversationView::activateInputBlocker()
  1241 void MsgConversationView::activateInputBlocker()
  1256     {
  1242 {
  1257         this->grabMouse();
  1243     mainWindow()->setInteractive(false);
  1258         this->grabKeyboard();
  1244 }
  1259     }
       
  1260 
  1245 
  1261 //---------------------------------------------------------------
  1246 //---------------------------------------------------------------
  1262 // MsgConversationView::deactivateInputBlocker
  1247 // MsgConversationView::deactivateInputBlocker
  1263 // @see header file
  1248 // @see header file
  1264 //--------------------------------------------------------------
  1249 //---------------------------------------------------------------
  1265 void MsgConversationView::deactivateInputBlocker()
  1250 void MsgConversationView::deactivateInputBlocker()
  1266     {    
  1251 {
  1267         this->ungrabKeyboard();
  1252     mainWindow()->setInteractive(true);
  1268         this->ungrabMouse();
  1253 }
  1269     }
       
  1270 
  1254 
  1271 //---------------------------------------------------------------
  1255 //---------------------------------------------------------------
  1272 // MsgConversationView::handleProvisoningMsg
  1256 // MsgConversationView::handleProvisoningMsg
  1273 // @see header file
  1257 // @see header file
  1274 //--------------------------------------------------------------
  1258 //---------------------------------------------------------------
  1275 void MsgConversationView::handleProvisoningMsg(int msgId)
  1259 void MsgConversationView::handleProvisoningMsg(int msgId)
  1276 	{
  1260 	{
  1277 		QString messageId;
  1261 		QString messageId;
  1278     messageId.setNum(msgId);
  1262     messageId.setNum(msgId);
  1279 
  1263 
  1299 	}
  1283 	}
  1300 
  1284 
  1301 //---------------------------------------------------------------
  1285 //---------------------------------------------------------------
  1302 // MsgConversationView::onDialogSettingsLaunch
  1286 // MsgConversationView::onDialogSettingsLaunch
  1303 // @see header file
  1287 // @see header file
  1304 //--------------------------------------------------------------
  1288 //---------------------------------------------------------------
  1305 void MsgConversationView::onDialogSettingsLaunch(HbAction* action)
  1289 void MsgConversationView::onDialogSettingsLaunch(HbAction* action)
  1306 {
  1290 {
  1307     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
  1291     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
  1308     if (action == dlg->actions().at(0)) {
  1292     if (action == dlg->actions().at(0)) {
  1309         //switch to settings view
  1293         //switch to settings view
  1317 }
  1301 }
  1318 
  1302 
  1319 //---------------------------------------------------------------
  1303 //---------------------------------------------------------------
  1320 // MsgConversationView::onDialogdeleteMsg
  1304 // MsgConversationView::onDialogdeleteMsg
  1321 // @see header file
  1305 // @see header file
  1322 //--------------------------------------------------------------
  1306 //---------------------------------------------------------------
  1323 void MsgConversationView::onDialogdeleteMsg(HbAction* action)
  1307 void MsgConversationView::onDialogdeleteMsg(HbAction* action)
  1324 {
  1308 {
  1325     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
  1309     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
  1326     if (action == dlg->actions().at(0)) {
  1310     if (action == dlg->actions().at(0)) {
  1327         QModelIndex index = mConversationList->currentIndex();
  1311         QModelIndex index = mConversationList->currentIndex();
  1369     if (action == dlg->actions().at(0)) {
  1353     if (action == dlg->actions().at(0)) {
  1370         saveRingingTone();
  1354         saveRingingTone();
  1371     }
  1355     }
  1372 }
  1356 }
  1373 
  1357 
       
  1358 //---------------------------------------------------------------
       
  1359 // MsgConversationView::onOrientationChanged
       
  1360 // @see header file
       
  1361 //---------------------------------------------------------------
       
  1362 void MsgConversationView::onOrientationChanged(Qt::Orientation newOrientation)
       
  1363 {
       
  1364     Q_UNUSED(newOrientation)
       
  1365 
       
  1366     // On orientation change always make the preserved index(last visible item) to be visible
       
  1367     if(mVisibleIndex.isValid())
       
  1368     {
       
  1369     mConversationList->scrollTo(mVisibleIndex, HbAbstractItemView::PositionAtBottom);
       
  1370     mVisibleIndex = QModelIndex();
       
  1371     }
       
  1372 }
       
  1373 
       
  1374 //---------------------------------------------------------------
       
  1375 // MsgConversationView::onOrientationAboutToBeChanged
       
  1376 // @see header file
       
  1377 //---------------------------------------------------------------
       
  1378 void MsgConversationView::onOrientationAboutToBeChanged()
       
  1379 {
       
  1380     // Preserve the model index of the last visible item to be scrolled on orientation change
       
  1381     QList<HbAbstractViewItem *>items = mConversationList->visibleItems();
       
  1382     if (items.count() > 0) {
       
  1383         mVisibleIndex = items.last()->modelIndex();
       
  1384     }
       
  1385 }
       
  1386 
       
  1387 //---------------------------------------------------------------
       
  1388 // MsgConversationView::onViewReady
       
  1389 // @see header file
       
  1390 //---------------------------------------------------------------
       
  1391 void MsgConversationView::onViewReady()
       
  1392 {
       
  1393     //Disconnect list View's signals, for avoiding execution of the default implementaion
       
  1394     disconnect(mainWindow(), SIGNAL(aboutToChangeOrientation()), mConversationList, 0);
       
  1395     disconnect(mainWindow(), SIGNAL(orientationChanged(Qt: rientation)), mConversationList, 0);
       
  1396 }
  1374 // EOF
  1397 // EOF