messagingapp/msgui/conversationview/src/msgconversationview.cpp
changeset 34 84197e66a4bd
parent 31 ebfee66fde93
child 43 35b64624a9e7
--- a/messagingapp/msgui/conversationview/src/msgconversationview.cpp	Fri Jun 04 10:25:39 2010 +0100
+++ b/messagingapp/msgui/conversationview/src/msgconversationview.cpp	Fri Jun 11 13:35:48 2010 +0300
@@ -24,11 +24,12 @@
 #include <HbMessageBox>
 #include <HbNotificationDialog>
 #include <HbFrameBackground>
-#include <XQServiceRequest.h>
+#include <xqservicerequest.h>
 #include <HbStaticVkbHost>
 #include <HbStyleLoader>
 #include <xqaiwrequest.h>
 #include <xqappmgr.h>
+#include <HbMainWindow>
 
 #include <QDir>
 #include <QDateTime>
@@ -41,6 +42,7 @@
 #include <MmsEngineDomainCRKeys.h>
 
 // USER INCLUDES
+#include "msgcontactsutil.h"
 #include "msgsendutil.h"
 #include "msgconversationviewitem.h"
 #include "conversationsengine.h"
@@ -62,7 +64,7 @@
 #define LOC_COMMON_DELETE hbTrId("txt_common_menu_delete")
 #define LOC_COMMON_FORWARD hbTrId("txt_common_menu_forward")
 #define LOC_COMMON_DOWNLOAD hbTrId("txt_messaging_menu_download")
-#define LOC_COMMON_SEND  hbTrId("txt_common_menu_send") 
+#define LOC_COMMON_SEND  hbTrId("txt_common_button_send") 
 #define LOC_COMMON_SAVE  hbTrId("txt_common_menu_save")
 #define LOC_BUTTON_DELETE hbTrId("txt_common_button_delete")
 #define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel")
@@ -78,12 +80,10 @@
 #define LOC_ADD_RECIPIENTS  hbTrId("txt_messaging_opt_add_recipients")
 #define LOC_ADD_SUBJECT     hbTrId("txt_messaging_opt_add_subject")
 
-#define LOC_MSG_SEND_FAILED hbTrId("txt_messaging_dpopinfo_sending_failed")
-
+#define LOC_MSG_SEND_FAILED hbTrId("txt_messaging_dialog_message_sending_failed")
 #define LOC_DIALOG_SMS_SETTINGS_INCOMPLETE hbTrId("txt_messaging_dialog_sms_settings_incomplete")
 #define LOC_DIALOG_SAVE_RINGTONE hbTrId("txt_conversations_dialog_save_ringing_tone")
-
-
+#define LOC_CONTACT_SAVED hbTrId("txt_messaging_dpopinfo_contact_saved")
 
 const int INVALID_MSGID = -1;
 const int INVALID_CONVID = -1;
@@ -102,10 +102,11 @@
     mEditorWidget(NULL),
     mContactCardWidget(contactCardWidget),
     mSendUtil(NULL),
-    mItemLongPressed(false),
     mVkbHost(NULL),
-    mVkbopened(false)
+    mVkbopened(false),
+    mVisibleIndex()
 {
+    connect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(onViewReady()));
     //create send utils
     mSendUtil = new MsgSendUtil(this);
     //initialize view
@@ -152,6 +153,11 @@
     
     connect(mConversationList, SIGNAL(activated(QModelIndex)),
             this, SLOT(openItem(QModelIndex)));
+    connect(this->mainWindow(), SIGNAL(aboutToChangeOrientation()),
+                this, SLOT(onOrientationAboutToBeChanged()));
+    
+    connect(this->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
+                    this, SLOT(onOrientationChanged(Qt::Orientation)));
 
     // Long tap list item
     connect(mConversationList, SIGNAL(longPressed(HbAbstractViewItem*, QPointF)),
@@ -241,8 +247,6 @@
 void MsgConversationView::longPressed(HbAbstractViewItem* viewItem,
     const QPointF& point)
 {    
-    mItemLongPressed = true;
-    
     MsgConversationViewItem* item = qgraphicsitem_cast<
             MsgConversationViewItem *> (viewItem);
 
@@ -266,11 +270,7 @@
         contextMenu->show();
 
     }
-    else
-    {
-        // For cases where the long tap check failed
-        mItemLongPressed = false;
-    }
+    
 }
 
 //---------------------------------------------------------------
@@ -296,6 +296,8 @@
 void MsgConversationView::addSaveItemToContextMenu(MsgConversationViewItem* item,
     HbMenu* contextMenu, int sendingState)
 {
+    Q_UNUSED(sendingState)
+
     int messageSubType = item->modelIndex().data(MessageSubType).toInt();
     int direction =  item->modelIndex().data(Direction).toInt();
     if ((messageSubType == ConvergedMessage::RingingTone) && 
@@ -374,12 +376,18 @@
     }
     
     qint32 messageId = item->modelIndex().data(ConvergedMsgId).toInt();
+    qint32 messageProperty = item->modelIndex().data(MessageProperty).toInt();
+    
+    bool canForwardMessage  = true;
+    if (messageType == ConvergedMessage::Mms){
+        canForwardMessage = (messageProperty & EPreviewForward)? true:false;
+    }            
 
     if( ((sendingState == ConvergedMessage::SentState) ||
         (sendingState == ConvergedMessage::Resend) ||
         (sendingState == ConvergedMessage::Failed) ||
         (direction == ConvergedMessage::Incoming) ) &&
-        (validateMsgForForward(messageType,messageId))	)
+        canForwardMessage)
     {
         HbAction *contextItem = contextMenu->addAction(LOC_COMMON_FORWARD);
         connect(contextItem, SIGNAL(triggered()),this, SLOT(forwardMessage()));
@@ -536,11 +544,12 @@
 //---------------------------------------------------------------
 void MsgConversationView::fetchImages()
 {
-    QString interface("Image");
-    QString operation("fetch(QVariantMap,QVariant)");
+    QString service("photos");
+    QString interface("com.nokia.symbian.IImageFetch");
+    QString operation("fetch(void)");
     XQAiwRequest* request = NULL;
     XQApplicationManager appManager;
-    request = appManager.create(interface, operation, true); // embedded
+    request = appManager.create(service,interface, operation, true); // embedded
     request->setSynchronous(true); // synchronous
     if(!request)
     {
@@ -553,11 +562,6 @@
     connect(request, SIGNAL(requestError(int,const QString&)),
         this, SLOT(serviceRequestError(int,const QString&)));
 
-    // Set arguments for request
-    QList<QVariant> args;
-    args << QVariantMap();
-    args << QVariant();
-    request->setArguments(args);
     // Make the request
     if (!request->send())
     {
@@ -814,14 +818,23 @@
 {
     qint32 messageId = index.data(ConvergedMsgId).toLongLong();
 
-    QString interface("com.nokia.services.btmsgdispservices.displaymsg");
+    QList<QVariant> args;
+    QString serviceName("com.nokia.services.btmsgdispservices.displaymsg");
     QString operation("displaymsg(int)");
+    XQAiwRequest* request;
+    XQApplicationManager appManager;
+    request = appManager.create(serviceName, "displaymsg", operation, true); // embedded
+    
+    if ( request == NULL )
+        {
+        return;
+        }
 
-    XQServiceRequest request(interface, operation, false);
-
-    request << messageId;
-
-    bool result = request.send();
+    args << QVariant(messageId);
+    
+    request->setArguments(args);
+    request->send();
+    delete request;    
 }
 
 //---------------------------------------------------------------
@@ -861,49 +874,63 @@
 //@see header
 //---------------------------------------------------------------
 void MsgConversationView::openItem(const QModelIndex & index)
-    {
+{
     // Return if invalid index.
     if (!index.isValid() || mVkbopened)
-        {
+    {
         return;
-        }
-
-    if(mItemLongPressed)
-        {
-        //reset the flag
-        mItemLongPressed = false;
-        return;
-        }
+    }
     
     int messageType = index.data(MessageType).toInt();
     int messageSubType = index.data(MessageSubType).toInt();
+    int messageId = index.data(ConvergedMsgId).toInt();
     
-    if (ConvergedMessage::BioMsg == messageType) {
-        if (ConvergedMessage::RingingTone == messageSubType) {
+    if (ConvergedMessage::BioMsg == messageType)
+    {
+        if (ConvergedMessage::RingingTone == messageSubType)
+        {
             HbMessageBox::question(LOC_DIALOG_SAVE_RINGTONE, this,
                     SLOT(onDialogSaveTone(HbAction*)), LOC_COMMON_SAVE, LOC_BUTTON_CANCEL);
             return;
         }
         else if(ConvergedMessage::Provisioning == messageSubType)
-            {
+        {
             int messageId = index.data(ConvergedMsgId).toInt();
             handleProvisoningMsg(messageId);
             QList<int> msgIdList;
             if(index.data(UnReadStatus).toInt())
-                {
+            {
                 msgIdList.clear();
                 msgIdList << messageId;
                 ConversationsEngine::instance()->markMessagesRead(msgIdList);
-                }
-            return;
             }
-        // Unsupported messages
-        else if (ConvergedMessage::VCard == messageSubType
-            || ConvergedMessage::VCal == messageSubType) {
+            return;
+        }
+        else if(ConvergedMessage::VCard == messageSubType)
+        {
+            QString filepath = index.data(Attachments).toStringList().at(0);
+            bool result = MsgContactsUtil::launchVCardViewer(filepath);
+            if(result)
+            {
+                HbNotificationDialog::launchDialog(LOC_CONTACT_SAVED);
+                int messageId = index.data(ConvergedMsgId).toInt();
+                QList<int> msgIdList;
+                if(index.data(UnReadStatus).toInt())
+                {
+                    msgIdList.clear();
+                    msgIdList << messageId;
+                    ConversationsEngine::instance()->markMessagesRead(msgIdList);
+                }
+            }
+            return;
+        }
+        else if(ConvergedMessage::VCal == messageSubType)
+        {
             return;
         }
     }
-    else if (ConvergedMessage::BT == messageType) {
+    else if (ConvergedMessage::BT == messageType)
+    {
         launchBtDisplayService(index);
         return;
     }
@@ -929,7 +956,14 @@
         }
     }
 
-    ConvergedMessage message;
+    int direction = index.data(Direction).toInt();
+
+    if (direction == ConvergedMessage::Outgoing && ConvergedMessage::Sms == messageType
+        && ConversationsEngine::instance()->getMsgSubType(messageId)== ConvergedMessage::NokiaService)
+    {
+        return;
+    }
+    
     // check whether message is in sending progress, then donot launch viewer.
     int location = index.data(MessageLocation).toInt();
     int sendingState = index.data(SendingState).toInt();
@@ -951,7 +985,7 @@
         (sendingState == ConvergedMessage::SentState)||
         (sendingState == ConvergedMessage::Failed) ||
         (sendingState == ConvergedMessage::Resend)))
-        {// do not launch viewer, show a note
+    {// do not launch viewer, show a note
         HbNotificationDialog* dlg = new HbNotificationDialog();
         dlg->setFocusPolicy(Qt::NoFocus);
         QString text(tr("Message Locked"));
@@ -960,69 +994,45 @@
         dlg->setAttribute(Qt::WA_DeleteOnClose, true);
         dlg->show();
         return;
-		}
-
-        // message id
-        qint32 messageId = index.data(ConvergedMsgId).toLongLong();
-        ConvergedMessageId msgId(messageId);
-        message.setMessageId(msgId);
-
-        // contact Id
-        qint32 contactId = index.data(ContactId).toLongLong();
-
-        // message type
-
-        message.setMessageType((ConvergedMessage::MessageType) messageType);
-        message.setMessageSubType((ConvergedMessage::MessageSubType) messageSubType);
-
-        if (messageType == ConvergedMessage::Mms)
-        {
-            message.setSubject(index.data(Subject).toString());
-            message.setPriority((ConvergedMessage::Priority) index.data(
-                MessagePriority).toInt());
-        }
-        else if (messageType == ConvergedMessage::IM)
-        {
-            // add body text and send to the message for IM case
-            message.setBodyText(index.data(BodyText).toString());
-        }
-
-        // time stamp
-        message.setTimeStamp(index.data(TimeStamp).toLongLong());
-
-        //Message direction
-        message.setDirection((ConvergedMessage::Direction)index.data(Direction).toInt());
-
-        // conatct name as address
-        ConvergedMessageAddress address;
-        address.setAlias(mContactCardWidget->address().at(0)->alias());
-        address.setAddress(mContactCardWidget->address().at(0)->address());
-        message.addToRecipient(address);
-
-        // Mark this message as read if its unread
-        QByteArray dataArray;
-        QDataStream messageStream
-        (&dataArray, QIODevice::WriteOnly | QIODevice::Append);
-        message.serialize(messageStream);
-        //if message unread, mark as read before opening view
-        QList<int> msgIdList;
-        if(index.data(UnReadStatus).toInt())
-            {
+	}
+   
+    
+    // contact Id
+    qint32 contactId = index.data(ContactId).toLongLong();  
+	    
+    //if message unread, mark as read before opening view
+    QList<int> msgIdList;
+    if(index.data(UnReadStatus).toInt())
+    {
         msgIdList.clear();
         msgIdList << messageId;
         ConversationsEngine::instance()->markMessagesRead(msgIdList);
-        }
+    }
+    
+    qint32 messageProperty = index.data(MessageProperty).toInt();
 
-        //switch view
-        QVariantList param;
-        param << MsgBaseView::UNIVIEWER;  // target view
-        param << MsgBaseView::CV; // source view
+    bool canForwardMessage  = true;
+    if (messageType == ConvergedMessage::Mms){
+        canForwardMessage = (messageProperty & EPreviewForward)? true:false;
+    } 
+    
+    //switch view
+    QVariantList param;
+    param << MsgBaseView::UNIVIEWER;  // target view
+    param << MsgBaseView::CV; // source view
 
-        param << contactId;
-        param << dataArray;
-        param << mMessageModel->rowCount();
-
-        emit switchView(param);
+    param << contactId;
+    param << messageId;
+    param << mMessageModel->rowCount();
+    if (canForwardMessage == true)
+    {
+      param << 1;
+    }
+    else
+   	{
+   		param << 0;
+   	}
+    emit switchView(param);
 }
 
 //---------------------------------------------------------------
@@ -1174,26 +1184,6 @@
 }
 
 //---------------------------------------------------------------
-// MsgConversationView::validateMsgForForward
-// @see header file
-//---------------------------------------------------------------
-bool MsgConversationView::validateMsgForForward(int &messageType,
-    qint32 &messageId)
-{
-    bool retValue = true;
-    if (messageType == ConvergedMessage::Mms)
-    {
-        //Validate if the mms msg can be forwarded or not
-        MmsConformanceCheck* mmsConformanceCheck = new MmsConformanceCheck;
-        retValue = mmsConformanceCheck->validateMsgForForward(messageId);
-        
-        delete mmsConformanceCheck;
-    }
-
-    return retValue;
-}
-
-//---------------------------------------------------------------
 // MsgConversationView::vkbOpened
 // @see header file
 //---------------------------------------------------------------
@@ -1201,9 +1191,7 @@
 {
     mVkbopened = true;
     
-    mContactCardWidget->connectSignals(false);
-    
-    emit hideChrome(true);
+    emit vkbOpened(true);
     
     QRectF appRect = mVkbHost->applicationArea();    
     qreal spacing = 0.0;
@@ -1229,9 +1217,7 @@
 {
     mVkbopened = false;
     
-    mContactCardWidget->connectSignals(true);
-    
-    emit hideChrome(false);
+    emit vkbOpened(false);
     
     this->setMaximumHeight(-1);
     connect(mVkbHost,SIGNAL(keypadOpened()),this,SLOT(vkbOpened()));
@@ -1251,27 +1237,25 @@
 //---------------------------------------------------------------
 // MsgConversationView::activateInputBlocker
 // @see header file
-//--------------------------------------------------------------
+//---------------------------------------------------------------
 void MsgConversationView::activateInputBlocker()
-    {
-        this->grabMouse();
-        this->grabKeyboard();
-    }
+{
+    mainWindow()->setInteractive(false);
+}
 
 //---------------------------------------------------------------
 // MsgConversationView::deactivateInputBlocker
 // @see header file
-//--------------------------------------------------------------
+//---------------------------------------------------------------
 void MsgConversationView::deactivateInputBlocker()
-    {    
-        this->ungrabKeyboard();
-        this->ungrabMouse();
-    }
+{
+    mainWindow()->setInteractive(true);
+}
 
 //---------------------------------------------------------------
 // MsgConversationView::handleProvisoningMsg
 // @see header file
-//--------------------------------------------------------------
+//---------------------------------------------------------------
 void MsgConversationView::handleProvisoningMsg(int msgId)
 	{
 		QString messageId;
@@ -1301,7 +1285,7 @@
 //---------------------------------------------------------------
 // MsgConversationView::onDialogSettingsLaunch
 // @see header file
-//--------------------------------------------------------------
+//---------------------------------------------------------------
 void MsgConversationView::onDialogSettingsLaunch(HbAction* action)
 {
     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
@@ -1319,7 +1303,7 @@
 //---------------------------------------------------------------
 // MsgConversationView::onDialogdeleteMsg
 // @see header file
-//--------------------------------------------------------------
+//---------------------------------------------------------------
 void MsgConversationView::onDialogdeleteMsg(HbAction* action)
 {
     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
@@ -1371,4 +1355,43 @@
     }
 }
 
+//---------------------------------------------------------------
+// MsgConversationView::onOrientationChanged
+// @see header file
+//---------------------------------------------------------------
+void MsgConversationView::onOrientationChanged(Qt::Orientation newOrientation)
+{
+    Q_UNUSED(newOrientation)
+
+    // On orientation change always make the preserved index(last visible item) to be visible
+    if(mVisibleIndex.isValid())
+    {
+    mConversationList->scrollTo(mVisibleIndex, HbAbstractItemView::PositionAtBottom);
+    mVisibleIndex = QModelIndex();
+    }
+}
+
+//---------------------------------------------------------------
+// MsgConversationView::onOrientationAboutToBeChanged
+// @see header file
+//---------------------------------------------------------------
+void MsgConversationView::onOrientationAboutToBeChanged()
+{
+    // Preserve the model index of the last visible item to be scrolled on orientation change
+    QList<HbAbstractViewItem *>items = mConversationList->visibleItems();
+    if (items.count() > 0) {
+        mVisibleIndex = items.last()->modelIndex();
+    }
+}
+
+//---------------------------------------------------------------
+// MsgConversationView::onViewReady
+// @see header file
+//---------------------------------------------------------------
+void MsgConversationView::onViewReady()
+{
+    //Disconnect list View's signals, for avoiding execution of the default implementaion
+    disconnect(mainWindow(), SIGNAL(aboutToChangeOrientation()), mConversationList, 0);
+    disconnect(mainWindow(), SIGNAL(orientationChanged(Qt: rientation)), mConversationList, 0);
+}
 // EOF