messagingapp/msgui/unifiedviewer/src/unifiedviewer.cpp
changeset 51 3507212d340e
parent 48 4f501b74aeb1
child 56 f42d9a78f435
--- a/messagingapp/msgui/unifiedviewer/src/unifiedviewer.cpp	Tue Aug 03 21:34:40 2010 +0530
+++ b/messagingapp/msgui/unifiedviewer/src/unifiedviewer.cpp	Fri Aug 06 23:19:50 2010 +0530
@@ -26,6 +26,7 @@
 #include <HbStyleLoader>
 #include <centralrepository.h>
 #include <MmsEngineDomainCRKeys.h>
+#include <ccsdefs.h>
 
 // USER INCLUDES
 #include "uniscrollarea.h"
@@ -38,6 +39,7 @@
 #include "conversationsengine.h"
 #include "debugtraces.h"
 #include "nativemessageconsts.h"
+#include "mmsconformancecheck.h"
 
 // LOCAL CONSTANTS
 const QString REPLY_ICON("qtg_mono_reply");
@@ -46,6 +48,12 @@
 const QString SEND_ICON("qtg_mono_send");
 const QString DELETE_ICON("qtg_mono_delete");
 
+//DB-file
+_LIT(KDbFileName, "c:[2002A542]conversations.db");
+// query to see if msg is forwardable
+_LIT(KSelectMsgPropertyStmt, " SELECT message_id, msg_property FROM conversation_messages WHERE message_id=:message_id ");
+
+
 //LOCALIZED CONSTANTS
 #define LOC_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
 #define LOC_DELETE_SHARED_MESSAGE hbTrId("txt_messaging_dialog_same_message_exists_in_multip")
@@ -54,10 +62,9 @@
 // UnifiedViewer::UnifiedViewer
 // constructor
 //----------------------------------------------------------------------------
-UnifiedViewer::UnifiedViewer(const qint32 messageId, 
-                             int canForwardMessage,
+UnifiedViewer::UnifiedViewer(const qint32 messageId,
                              QGraphicsItem *parent) :
-    MsgBaseView(parent), mForwardMessage(false)
+    MsgBaseView(parent)
 {
     QDEBUG_WRITE("UnifiedViewer contruction start");
 
@@ -69,8 +76,6 @@
     mMessageId = messageId;
     mViewFeeder = new UniViewerFeeder(mMessageId, this);
 
-    if (canForwardMessage > 0) mForwardMessage = true;
-    
     mScrollArea = new UniScrollArea(this);
     this->setWidget(mScrollArea);
 
@@ -127,7 +132,7 @@
         }
     }
 
-    if (mForwardMessage)    
+    if (isForwardOk())
     {
         toolbar->addAction(HbIcon(FORWARD_ICON), "", this, SLOT(handleFwdAction()));
     }
@@ -188,7 +193,7 @@
 
     //Creation of toolbar now depends on content
     createToolBar();
-    
+
     QDEBUG_WRITE("UnifiedViewer populateContent END");
 }
 
@@ -197,7 +202,7 @@
 // @see header file
 //---------------------------------------------------------------
 void UnifiedViewer::handleFwdAction()
-{    
+{
     launchEditor(MsgBaseView::FORWARD_MSG);
 }
 
@@ -207,7 +212,7 @@
 //---------------------------------------------------------------
 void UnifiedViewer::handleReplyAction()
 {
-    launchEditor(MsgBaseView::REPLY_MSG); 
+    launchEditor(MsgBaseView::REPLY_MSG);
 }
 
 //---------------------------------------------------------------
@@ -236,8 +241,8 @@
 void UnifiedViewer::handleDeleteAction()
 {
     QString txt = LOC_DELETE_MESSAGE;
-    
-    //if mms and out going. check for sharing    
+
+    //if mms and out going. check for sharing
     if((mViewFeeder->msgType() == KSenduiMtmMmsUidValue) && (!mViewFeeder->isIncoming()))
     {
         if(mViewFeeder->recipientCount() > 1 )
@@ -245,7 +250,7 @@
             txt =  LOC_DELETE_SHARED_MESSAGE;
         }
     }
-    
+
     HbMessageBox::question(txt,this,SLOT(onDialogDeleteMsg(int)),
                            HbMessageBox::Delete | HbMessageBox::Cancel);
 }
@@ -321,7 +326,7 @@
     }
     else
     {
-        message.setMessageType(ConvergedMessage::Sms);    
+        message.setMessageType(ConvergedMessage::Sms);
     }
 
     QByteArray dataArray;
@@ -335,8 +340,51 @@
 
     params << dataArray;
     params << operation;
-        
+
     emit switchView(params);
 }
 
+//---------------------------------------------------------------
+// UnifiedViewer::isForwardOk
+// @see header file
+//---------------------------------------------------------------
+bool UnifiedViewer::isForwardOk()
+{
+    bool canForwardMsg = true;
+    if(mViewFeeder->msgType() == KSenduiMtmMmsUidValue)
+    {
+        // open DB
+        RSqlDatabase sqlDb;
+        TInt error = sqlDb.Open(KDbFileName);
+        if(error == KErrNone)
+        {
+            RSqlStatement sqlSelectStmt;
+            CleanupClosePushL(sqlSelectStmt);
+            sqlSelectStmt.PrepareL(sqlDb,KSelectMsgPropertyStmt);
+            TInt msgIdIndex = sqlSelectStmt.ParameterIndex(_L(":message_id"));
+            sqlSelectStmt.BindInt(msgIdIndex, mMessageId);
+            // read the flag
+            TInt msgPropertyIndex =
+                    sqlSelectStmt.ColumnIndex(_L("msg_property"));
+            TInt retValue = 0;
+            if (sqlSelectStmt.Next() == KSqlAtRow)
+            {
+                retValue = static_cast<TInt>
+                    (sqlSelectStmt.ColumnInt(msgPropertyIndex));
+            }
+            CleanupStack::PopAndDestroy(&sqlSelectStmt);
+            sqlDb.Close();
+            canForwardMsg = (retValue & EPreviewForward)? true:false;
+        }
+        else
+        {
+            // fall-back plan
+            MmsConformanceCheck* mmsConformanceCheck = new MmsConformanceCheck;
+            canForwardMsg = mmsConformanceCheck->validateMsgForForward(mMessageId);
+            delete mmsConformanceCheck;
+        }
+    }
+    return canForwardMsg;
+}
+
 // EOF