messagingapp/msgui/unifiedviewer/src/unifiedviewer.cpp
changeset 51 3507212d340e
parent 48 4f501b74aeb1
child 56 f42d9a78f435
equal deleted inserted replaced
49:2a272ef608c4 51:3507212d340e
    24 #include <hbmessagebox.h>
    24 #include <hbmessagebox.h>
    25 #include <hbnotificationdialog.h>
    25 #include <hbnotificationdialog.h>
    26 #include <HbStyleLoader>
    26 #include <HbStyleLoader>
    27 #include <centralrepository.h>
    27 #include <centralrepository.h>
    28 #include <MmsEngineDomainCRKeys.h>
    28 #include <MmsEngineDomainCRKeys.h>
       
    29 #include <ccsdefs.h>
    29 
    30 
    30 // USER INCLUDES
    31 // USER INCLUDES
    31 #include "uniscrollarea.h"
    32 #include "uniscrollarea.h"
    32 #include "unicontentswidget.h"
    33 #include "unicontentswidget.h"
    33 #include "univiewerfeeder.h"
    34 #include "univiewerfeeder.h"
    36 #include "convergedmessageaddress.h"
    37 #include "convergedmessageaddress.h"
    37 #include "conversationsenginedefines.h"
    38 #include "conversationsenginedefines.h"
    38 #include "conversationsengine.h"
    39 #include "conversationsengine.h"
    39 #include "debugtraces.h"
    40 #include "debugtraces.h"
    40 #include "nativemessageconsts.h"
    41 #include "nativemessageconsts.h"
       
    42 #include "mmsconformancecheck.h"
    41 
    43 
    42 // LOCAL CONSTANTS
    44 // LOCAL CONSTANTS
    43 const QString REPLY_ICON("qtg_mono_reply");
    45 const QString REPLY_ICON("qtg_mono_reply");
    44 const QString REPLY_ALL_ICON("qtg_mono_reply_all");
    46 const QString REPLY_ALL_ICON("qtg_mono_reply_all");
    45 const QString FORWARD_ICON("qtg_mono_forward_msg");
    47 const QString FORWARD_ICON("qtg_mono_forward_msg");
    46 const QString SEND_ICON("qtg_mono_send");
    48 const QString SEND_ICON("qtg_mono_send");
    47 const QString DELETE_ICON("qtg_mono_delete");
    49 const QString DELETE_ICON("qtg_mono_delete");
    48 
    50 
       
    51 //DB-file
       
    52 _LIT(KDbFileName, "c:[2002A542]conversations.db");
       
    53 // query to see if msg is forwardable
       
    54 _LIT(KSelectMsgPropertyStmt, " SELECT message_id, msg_property FROM conversation_messages WHERE message_id=:message_id ");
       
    55 
       
    56 
    49 //LOCALIZED CONSTANTS
    57 //LOCALIZED CONSTANTS
    50 #define LOC_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
    58 #define LOC_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
    51 #define LOC_DELETE_SHARED_MESSAGE hbTrId("txt_messaging_dialog_same_message_exists_in_multip")
    59 #define LOC_DELETE_SHARED_MESSAGE hbTrId("txt_messaging_dialog_same_message_exists_in_multip")
    52 
    60 
    53 //----------------------------------------------------------------------------
    61 //----------------------------------------------------------------------------
    54 // UnifiedViewer::UnifiedViewer
    62 // UnifiedViewer::UnifiedViewer
    55 // constructor
    63 // constructor
    56 //----------------------------------------------------------------------------
    64 //----------------------------------------------------------------------------
    57 UnifiedViewer::UnifiedViewer(const qint32 messageId, 
    65 UnifiedViewer::UnifiedViewer(const qint32 messageId,
    58                              int canForwardMessage,
       
    59                              QGraphicsItem *parent) :
    66                              QGraphicsItem *parent) :
    60     MsgBaseView(parent), mForwardMessage(false)
    67     MsgBaseView(parent)
    61 {
    68 {
    62     QDEBUG_WRITE("UnifiedViewer contruction start");
    69     QDEBUG_WRITE("UnifiedViewer contruction start");
    63 
    70 
    64     if (!HbStyleLoader::registerFilePath(":/layouts"))
    71     if (!HbStyleLoader::registerFilePath(":/layouts"))
    65     {
    72     {
    67     }
    74     }
    68 
    75 
    69     mMessageId = messageId;
    76     mMessageId = messageId;
    70     mViewFeeder = new UniViewerFeeder(mMessageId, this);
    77     mViewFeeder = new UniViewerFeeder(mMessageId, this);
    71 
    78 
    72     if (canForwardMessage > 0) mForwardMessage = true;
       
    73     
       
    74     mScrollArea = new UniScrollArea(this);
    79     mScrollArea = new UniScrollArea(this);
    75     this->setWidget(mScrollArea);
    80     this->setWidget(mScrollArea);
    76 
    81 
    77     mContentsWidget = new UniContentsWidget(mViewFeeder,this);
    82     mContentsWidget = new UniContentsWidget(mViewFeeder,this);
    78 
    83 
   125         {
   130         {
   126             toolbar->addAction(HbIcon(REPLY_ALL_ICON), "", this, SLOT(handleReplyAllAction()));
   131             toolbar->addAction(HbIcon(REPLY_ALL_ICON), "", this, SLOT(handleReplyAllAction()));
   127         }
   132         }
   128     }
   133     }
   129 
   134 
   130     if (mForwardMessage)    
   135     if (isForwardOk())
   131     {
   136     {
   132         toolbar->addAction(HbIcon(FORWARD_ICON), "", this, SLOT(handleFwdAction()));
   137         toolbar->addAction(HbIcon(FORWARD_ICON), "", this, SLOT(handleFwdAction()));
   133     }
   138     }
   134 
   139 
   135     toolbar->addAction(HbIcon(DELETE_ICON), "", this, SLOT(handleDeleteAction()));
   140     toolbar->addAction(HbIcon(DELETE_ICON), "", this, SLOT(handleDeleteAction()));
   186 
   191 
   187     mContentsWidget->populateContent();
   192     mContentsWidget->populateContent();
   188 
   193 
   189     //Creation of toolbar now depends on content
   194     //Creation of toolbar now depends on content
   190     createToolBar();
   195     createToolBar();
   191     
   196 
   192     QDEBUG_WRITE("UnifiedViewer populateContent END");
   197     QDEBUG_WRITE("UnifiedViewer populateContent END");
   193 }
   198 }
   194 
   199 
   195 //---------------------------------------------------------------
   200 //---------------------------------------------------------------
   196 // UnifiedViewer::handleFwdAction
   201 // UnifiedViewer::handleFwdAction
   197 // @see header file
   202 // @see header file
   198 //---------------------------------------------------------------
   203 //---------------------------------------------------------------
   199 void UnifiedViewer::handleFwdAction()
   204 void UnifiedViewer::handleFwdAction()
   200 {    
   205 {
   201     launchEditor(MsgBaseView::FORWARD_MSG);
   206     launchEditor(MsgBaseView::FORWARD_MSG);
   202 }
   207 }
   203 
   208 
   204 //---------------------------------------------------------------
   209 //---------------------------------------------------------------
   205 // UnifiedViewer::handleReplyAction
   210 // UnifiedViewer::handleReplyAction
   206 // @see header file
   211 // @see header file
   207 //---------------------------------------------------------------
   212 //---------------------------------------------------------------
   208 void UnifiedViewer::handleReplyAction()
   213 void UnifiedViewer::handleReplyAction()
   209 {
   214 {
   210     launchEditor(MsgBaseView::REPLY_MSG); 
   215     launchEditor(MsgBaseView::REPLY_MSG);
   211 }
   216 }
   212 
   217 
   213 //---------------------------------------------------------------
   218 //---------------------------------------------------------------
   214 // UnifiedViewer::handleReplyAllAction
   219 // UnifiedViewer::handleReplyAllAction
   215 // @see header file
   220 // @see header file
   234 // @see header file
   239 // @see header file
   235 //---------------------------------------------------------------
   240 //---------------------------------------------------------------
   236 void UnifiedViewer::handleDeleteAction()
   241 void UnifiedViewer::handleDeleteAction()
   237 {
   242 {
   238     QString txt = LOC_DELETE_MESSAGE;
   243     QString txt = LOC_DELETE_MESSAGE;
   239     
   244 
   240     //if mms and out going. check for sharing    
   245     //if mms and out going. check for sharing
   241     if((mViewFeeder->msgType() == KSenduiMtmMmsUidValue) && (!mViewFeeder->isIncoming()))
   246     if((mViewFeeder->msgType() == KSenduiMtmMmsUidValue) && (!mViewFeeder->isIncoming()))
   242     {
   247     {
   243         if(mViewFeeder->recipientCount() > 1 )
   248         if(mViewFeeder->recipientCount() > 1 )
   244         {
   249         {
   245             txt =  LOC_DELETE_SHARED_MESSAGE;
   250             txt =  LOC_DELETE_SHARED_MESSAGE;
   246         }
   251         }
   247     }
   252     }
   248     
   253 
   249     HbMessageBox::question(txt,this,SLOT(onDialogDeleteMsg(int)),
   254     HbMessageBox::question(txt,this,SLOT(onDialogDeleteMsg(int)),
   250                            HbMessageBox::Delete | HbMessageBox::Cancel);
   255                            HbMessageBox::Delete | HbMessageBox::Cancel);
   251 }
   256 }
   252 
   257 
   253 //---------------------------------------------------------------
   258 //---------------------------------------------------------------
   319     {
   324     {
   320         message.setMessageType(ConvergedMessage::Mms);
   325         message.setMessageType(ConvergedMessage::Mms);
   321     }
   326     }
   322     else
   327     else
   323     {
   328     {
   324         message.setMessageType(ConvergedMessage::Sms);    
   329         message.setMessageType(ConvergedMessage::Sms);
   325     }
   330     }
   326 
   331 
   327     QByteArray dataArray;
   332     QByteArray dataArray;
   328     QDataStream messageStream
   333     QDataStream messageStream
   329     (&dataArray, QIODevice::WriteOnly | QIODevice::Append);
   334     (&dataArray, QIODevice::WriteOnly | QIODevice::Append);
   333     params << MsgBaseView::UNIEDITOR; // target view
   338     params << MsgBaseView::UNIEDITOR; // target view
   334     params << MsgBaseView::UNIVIEWER; // source view
   339     params << MsgBaseView::UNIVIEWER; // source view
   335 
   340 
   336     params << dataArray;
   341     params << dataArray;
   337     params << operation;
   342     params << operation;
   338         
   343 
   339     emit switchView(params);
   344     emit switchView(params);
   340 }
   345 }
   341 
   346 
       
   347 //---------------------------------------------------------------
       
   348 // UnifiedViewer::isForwardOk
       
   349 // @see header file
       
   350 //---------------------------------------------------------------
       
   351 bool UnifiedViewer::isForwardOk()
       
   352 {
       
   353     bool canForwardMsg = true;
       
   354     if(mViewFeeder->msgType() == KSenduiMtmMmsUidValue)
       
   355     {
       
   356         // open DB
       
   357         RSqlDatabase sqlDb;
       
   358         TInt error = sqlDb.Open(KDbFileName);
       
   359         if(error == KErrNone)
       
   360         {
       
   361             RSqlStatement sqlSelectStmt;
       
   362             CleanupClosePushL(sqlSelectStmt);
       
   363             sqlSelectStmt.PrepareL(sqlDb,KSelectMsgPropertyStmt);
       
   364             TInt msgIdIndex = sqlSelectStmt.ParameterIndex(_L(":message_id"));
       
   365             sqlSelectStmt.BindInt(msgIdIndex, mMessageId);
       
   366             // read the flag
       
   367             TInt msgPropertyIndex =
       
   368                     sqlSelectStmt.ColumnIndex(_L("msg_property"));
       
   369             TInt retValue = 0;
       
   370             if (sqlSelectStmt.Next() == KSqlAtRow)
       
   371             {
       
   372                 retValue = static_cast<TInt>
       
   373                     (sqlSelectStmt.ColumnInt(msgPropertyIndex));
       
   374             }
       
   375             CleanupStack::PopAndDestroy(&sqlSelectStmt);
       
   376             sqlDb.Close();
       
   377             canForwardMsg = (retValue & EPreviewForward)? true:false;
       
   378         }
       
   379         else
       
   380         {
       
   381             // fall-back plan
       
   382             MmsConformanceCheck* mmsConformanceCheck = new MmsConformanceCheck;
       
   383             canForwardMsg = mmsConformanceCheck->validateMsgForForward(mMessageId);
       
   384             delete mmsConformanceCheck;
       
   385         }
       
   386     }
       
   387     return canForwardMsg;
       
   388 }
       
   389 
   342 // EOF
   390 // EOF