messagingapp/msgui/unifiedviewer/src/unifiedviewer.cpp
changeset 37 518b245aa84c
parent 25 84d9eb65b26f
child 41 25fe1fe642e3
equal deleted inserted replaced
25:84d9eb65b26f 37:518b245aa84c
    22 #include <HbAction>
    22 #include <HbAction>
    23 #include <HbToolBar>
    23 #include <HbToolBar>
    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 
    29 
    30 // USER INCLUDES
    30 // USER INCLUDES
    31 #include "uniscrollarea.h"
    31 #include "uniscrollarea.h"
    32 #include "unicontentswidget.h"
    32 #include "unicontentswidget.h"
    36 #include "convergedmessageaddress.h"
    36 #include "convergedmessageaddress.h"
    37 #include "conversationsenginedefines.h"
    37 #include "conversationsenginedefines.h"
    38 #include "conversationsengine.h"
    38 #include "conversationsengine.h"
    39 #include "debugtraces.h"
    39 #include "debugtraces.h"
    40 #include "nativemessageconsts.h"
    40 #include "nativemessageconsts.h"
    41 #include "mmsconformancecheck.h"
       
    42 #include "UniEditorGenUtils.h" // This is needed for KDefaultMaxSize
       
    43 
    41 
    44 // LOCAL CONSTANTS
    42 // LOCAL CONSTANTS
    45 const QString REPLY_ICON("qtg_mono_reply");
    43 const QString REPLY_ICON("qtg_mono_reply");
    46 const QString REPLY_ALL_ICON("qtg_mono_reply_all");
    44 const QString REPLY_ALL_ICON("qtg_mono_reply_all");
    47 const QString FORWARD_ICON("qtg_mono_forward");
    45 const QString FORWARD_ICON("qtg_mono_forward_msg");
    48 const QString SEND_ICON("qtg_mono_send");
    46 const QString SEND_ICON("qtg_mono_send");
    49 const QString DELETE_ICON("qtg_mono_delete");
    47 const QString DELETE_ICON("qtg_mono_delete");
    50 
    48 
    51 //LOCALIZED CONSTANTS
    49 //LOCALIZED CONSTANTS
    52 #define LOC_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
    50 #define LOC_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
    53 #define LOC_BUTTON_DELETE hbTrId("txt_common_button_delete")
       
    54 #define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel")
       
    55 
    51 
    56 //----------------------------------------------------------------------------
    52 //----------------------------------------------------------------------------
    57 // UnifiedViewer::UnifiedViewer
    53 // UnifiedViewer::UnifiedViewer
    58 // constructor
    54 // constructor
    59 //----------------------------------------------------------------------------
    55 //----------------------------------------------------------------------------
    60 UnifiedViewer::UnifiedViewer(const qint32 messageId, QGraphicsItem *parent) :
    56 UnifiedViewer::UnifiedViewer(const qint32 messageId, 
    61     MsgBaseView(parent)
    57                              int canForwardMessage,
       
    58                              QGraphicsItem *parent) :
       
    59     MsgBaseView(parent), mForwardMessage(false)
    62 {
    60 {
    63     QDEBUG_WRITE("UnifiedViewer contruction start");
    61     QDEBUG_WRITE("UnifiedViewer contruction start");
    64 
    62 
    65     if (!HbStyleLoader::registerFilePath(":/layouts"))
    63     if (!HbStyleLoader::registerFilePath(":/layouts"))
    66     {
    64     {
    68     }
    66     }
    69 
    67 
    70     mMessageId = messageId;
    68     mMessageId = messageId;
    71     mViewFeeder = new UniViewerFeeder(mMessageId, this);
    69     mViewFeeder = new UniViewerFeeder(mMessageId, this);
    72 
    70 
    73     mMainLayout = new QGraphicsLinearLayout(Qt::Vertical, this);
    71     if (canForwardMessage > 0) mForwardMessage = true;
    74 
    72     
    75     mScrollArea = new UniScrollArea(this);
    73     mScrollArea = new UniScrollArea(this);
       
    74     this->setWidget(mScrollArea);
    76 
    75 
    77     mContentsWidget = new UniContentsWidget(mViewFeeder,this);
    76     mContentsWidget = new UniContentsWidget(mViewFeeder,this);
    78 	
    77 
    79     connect(mContentsWidget,SIGNAL(sendMessage(const QString&)),
    78     connect(mContentsWidget,SIGNAL(sendMessage(const QString&,const QString&)),
    80             this, SLOT(sendMessage(const QString&)));
    79             this, SLOT(sendMessage(const QString&,const QString&)));
    81 
    80 
    82     connect(mScrollArea, SIGNAL(scrolledToNextSlide()),
    81     connect(mScrollArea, SIGNAL(scrolledToNextSlide()),
    83     mContentsWidget, SLOT(populateNextSlide()));
    82     mContentsWidget, SLOT(populateNextSlide()));
    84 
    83 
    85     mScrollArea->setContentWidget(mContentsWidget);
    84     mScrollArea->setContentWidget(mContentsWidget);
    86     mScrollArea->setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
    85     mScrollArea->setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
    87     mScrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAutoHide);
    86     mScrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAutoHide);
    88     mMainLayout->addItem(mScrollArea);
       
    89     mMainLayout->setSpacing(0);
       
    90     mMainLayout->setContentsMargins(0, 0, 0, 0);
       
    91 
       
    92     setLayout(mMainLayout);
       
    93 
    87 
    94     QDEBUG_WRITE("UnifiedViewer contruction End");
    88     QDEBUG_WRITE("UnifiedViewer contruction End");
    95 }
    89 }
    96 
    90 
    97 //----------------------------------------------------------------------------
    91 //----------------------------------------------------------------------------
   119         toolbar->addAction(HbIcon(SEND_ICON), "");
   113         toolbar->addAction(HbIcon(SEND_ICON), "");
   120     }
   114     }
   121     else
   115     else
   122     {
   116     {
   123         toolbar->addAction(HbIcon(REPLY_ICON), "");
   117         toolbar->addAction(HbIcon(REPLY_ICON), "");
   124         toolbar->addAction(HbIcon(REPLY_ALL_ICON), "");
   118 
   125     }
   119         if (mViewFeeder->recipientCount() > 1)
   126 
   120         {
   127     if (validateMsgForForward())
   121             toolbar->addAction(HbIcon(REPLY_ALL_ICON), "");
       
   122         }
       
   123     }
       
   124 
       
   125     if (mForwardMessage)    
   128     {
   126     {
   129         toolbar->addAction(HbIcon(FORWARD_ICON), "", this, SLOT(handleFwdAction()));
   127         toolbar->addAction(HbIcon(FORWARD_ICON), "", this, SLOT(handleFwdAction()));
   130     }
   128     }
   131 
   129 
   132     toolbar->addAction(HbIcon(DELETE_ICON), "", this, SLOT(handleDeleteAction()));
   130     toolbar->addAction(HbIcon(DELETE_ICON), "", this, SLOT(handleDeleteAction()));
   165     {
   163     {
   166         mViewFeeder->updateContent(messageId);
   164         mViewFeeder->updateContent(messageId);
   167     }
   165     }
   168     QDEBUG_WRITE("UnifiedViewer feeder->updateContent END");
   166     QDEBUG_WRITE("UnifiedViewer feeder->updateContent END");
   169 
   167 
       
   168     // Dont show the scroll bar.
       
   169     mScrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
       
   170 
   170     if ( (mViewFeeder->msgType() == KSenduiMtmMmsUidValue) &&
   171     if ( (mViewFeeder->msgType() == KSenduiMtmMmsUidValue) &&
   171          (mViewFeeder->slideCount() > 0) )
   172          (mViewFeeder->slideCount() > 0) )
   172     {
   173     {
   173         mScrollArea->setTotalSlides(mViewFeeder->slideCount());
   174         mScrollArea->setTotalSlides(mViewFeeder->slideCount());
   174     }
   175     }
   224 // @see header file
   225 // @see header file
   225 //---------------------------------------------------------------
   226 //---------------------------------------------------------------
   226 void UnifiedViewer::resizeEvent(QGraphicsSceneResizeEvent * event)
   227 void UnifiedViewer::resizeEvent(QGraphicsSceneResizeEvent * event)
   227 {
   228 {
   228     Q_UNUSED(event)
   229     Q_UNUSED(event)
   229     mContentsWidget->resize(this->rect().width(), -1);
   230     mContentsWidget->resize(this->rect().width(), this->rect().height()+1);
   230 }
   231 }
   231 
   232 
   232 //---------------------------------------------------------------
   233 //---------------------------------------------------------------
   233 // UnifiedViewer::handleDeleteAction
   234 // UnifiedViewer::handleDeleteAction
   234 // @see header file
   235 // @see header file
   235 //---------------------------------------------------------------
   236 //---------------------------------------------------------------
   236 void UnifiedViewer::handleDeleteAction()
   237 void UnifiedViewer::handleDeleteAction()
   237 {
   238 {
   238     bool result = HbMessageBox::question(LOC_DELETE_MESSAGE,
   239     HbMessageBox::question(LOC_DELETE_MESSAGE,this,
   239                                          LOC_BUTTON_DELETE, 
   240                            SLOT(onDialogDeleteMsg(HbAction*)),
   240                                          LOC_BUTTON_CANCEL);
   241                            HbMessageBox::Delete | HbMessageBox::Cancel);
   241     if (result)
       
   242     {
       
   243         QList<int> msgIdList;
       
   244         msgIdList << mMessageId;
       
   245 
       
   246         ConversationsEngine::instance()->deleteMessages(msgIdList);
       
   247 
       
   248         QVariantList param;
       
   249         if (mMsgCount > 1)
       
   250         {
       
   251             param << MsgBaseView::CV;
       
   252             param << MsgBaseView::UNIVIEWER;
       
   253         }
       
   254         else
       
   255         {
       
   256             param << MsgBaseView::CLV;
       
   257             param << MsgBaseView::UNIVIEWER;
       
   258         }
       
   259 
       
   260         QVariant dummy(QVariant::Invalid);
       
   261         param << dummy;
       
   262         emit switchView(param);
       
   263     }
       
   264 
       
   265 }
   242 }
   266 
   243 
   267 //---------------------------------------------------------------
   244 //---------------------------------------------------------------
   268 // UnifiedViewer::sendMessage
   245 // UnifiedViewer::sendMessage
   269 // @see header file
   246 // @see header file
   270 //---------------------------------------------------------------
   247 //---------------------------------------------------------------
   271 void UnifiedViewer::sendMessage(const QString& phoneNumber)
   248 void UnifiedViewer::sendMessage(const QString& phoneNumber,const QString& alias)
   272     {
   249     {
   273     ConvergedMessage message;
   250     ConvergedMessage message;
   274     message.setBodyText(QString());
   251     message.setBodyText(QString());
   275 
   252 
   276     ConvergedMessageAddress address;
   253     ConvergedMessageAddress address;
   277     address.setAlias(phoneNumber);
   254     address.setAlias(alias);
   278     address.setAddress(phoneNumber);
   255     address.setAddress(phoneNumber);
   279     message.addToRecipient(address);
   256     message.addToRecipient(address);
   280 
   257 
   281     QByteArray dataArray;
   258     QByteArray dataArray;
   282     QDataStream messageStream
   259     QDataStream messageStream
   290 
   267 
   291     emit switchView(params);
   268     emit switchView(params);
   292     }
   269     }
   293 
   270 
   294 //---------------------------------------------------------------
   271 //---------------------------------------------------------------
   295 // UnifiedViewer::validateMsgForForward
   272 // UnifiedViewer::onDialogDeleteMsg
   296 // @see header file
   273 // @see header file
   297 //---------------------------------------------------------------
   274 //---------------------------------------------------------------
   298 bool UnifiedViewer::validateMsgForForward()
   275 void UnifiedViewer::onDialogDeleteMsg(HbAction* action)
   299 {
   276 {
   300     if (mViewFeeder->msgType() == KSenduiMtmMmsUidValue)
   277     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
   301     {
   278     if (action == dlg->actions().at(0)) {
   302         bool retValue = false;
   279         QList<int> msgIdList;
   303 
   280         msgIdList << mMessageId;
   304         //Validate if the mms msg can be forwarded or not
   281 
   305         MmsConformanceCheck* mmsConformanceCheck = new MmsConformanceCheck;        
   282         ConversationsEngine::instance()->deleteMessages(msgIdList);
   306         retValue = mmsConformanceCheck->validateMsgForForward(mMessageId);
   283 
   307 
   284         QVariantList param;
   308         delete mmsConformanceCheck;        
   285         if (mMsgCount > 1) {
   309         return retValue;
   286             param << MsgBaseView::CV;
   310     }
   287             param << MsgBaseView::UNIVIEWER;
   311 
   288         }
   312     return true;
   289         else {
       
   290             param << MsgBaseView::CLV;
       
   291             param << MsgBaseView::UNIVIEWER;
       
   292         }
       
   293 
       
   294         QVariant dummy(QVariant::Invalid);
       
   295         param << dummy;
       
   296         emit switchView(param);
       
   297     }
   313 }
   298 }
   314 
   299 
   315 // EOF
   300 // EOF