messagingapp/msgui/unifiedviewer/src/unifiedviewer.cpp
branchRCL_3
changeset 57 ebe688cedc25
equal deleted inserted replaced
54:fa1df4b99609 57:ebe688cedc25
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: Main view of unified viewer
       
    15  *
       
    16  */
       
    17 
       
    18 #include "unifiedviewer.h"
       
    19 
       
    20 // SYSTEM INCLUDES
       
    21 #include <QGraphicsLinearLayout>
       
    22 #include <HbAction>
       
    23 #include <HbToolBar>
       
    24 #include <hbmessagebox.h>
       
    25 #include <hbnotificationdialog.h>
       
    26 #include <HbStyleLoader>
       
    27 #include <centralrepository.h>
       
    28 #include <MmsEngineDomainCRKeys.h>
       
    29 #include <ccsdefs.h>
       
    30 
       
    31 // USER INCLUDES
       
    32 #include "uniscrollarea.h"
       
    33 #include "unicontentswidget.h"
       
    34 #include "univiewerfeeder.h"
       
    35 #include "convergedmessageid.h"
       
    36 #include "convergedmessage.h"
       
    37 #include "convergedmessageaddress.h"
       
    38 #include "conversationsenginedefines.h"
       
    39 #include "conversationsengine.h"
       
    40 #include "debugtraces.h"
       
    41 #include "nativemessageconsts.h"
       
    42 #include "mmsconformancecheck.h"
       
    43 
       
    44 // LOCAL CONSTANTS
       
    45 const QString REPLY_ICON("qtg_mono_reply");
       
    46 const QString REPLY_ALL_ICON("qtg_mono_reply_all");
       
    47 const QString FORWARD_ICON("qtg_mono_forward_msg");
       
    48 const QString SEND_ICON("qtg_mono_send");
       
    49 const QString DELETE_ICON("qtg_mono_delete");
       
    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 
       
    57 //LOCALIZED CONSTANTS
       
    58 #define LOC_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
       
    59 #define LOC_DELETE_SHARED_MESSAGE hbTrId("txt_messaging_dialog_same_message_exists_in_multip")
       
    60 
       
    61 //----------------------------------------------------------------------------
       
    62 // UnifiedViewer::UnifiedViewer
       
    63 // constructor
       
    64 //----------------------------------------------------------------------------
       
    65 UnifiedViewer::UnifiedViewer(const qint32 messageId,
       
    66                              QGraphicsItem *parent) :
       
    67     MsgBaseView(parent)
       
    68 {
       
    69     QDEBUG_WRITE("UnifiedViewer contruction start");
       
    70 
       
    71     if (!HbStyleLoader::registerFilePath(":/layouts"))
       
    72     {
       
    73         QDEBUG_WRITE("ERROR: UnifiedViewer -> HbStyleLoader::registerFilePath");
       
    74     }
       
    75 
       
    76     mMessageId = messageId;
       
    77     mViewFeeder = new UniViewerFeeder(mMessageId, this);
       
    78 
       
    79     mScrollArea = new UniScrollArea(this);
       
    80     this->setWidget(mScrollArea);
       
    81 
       
    82     mContentsWidget = new UniContentsWidget(mViewFeeder,this);
       
    83 
       
    84     connect(mContentsWidget,SIGNAL(sendMessage(const QString&,const QString&)),
       
    85             this, SLOT(sendMessage(const QString&,const QString&)));
       
    86 
       
    87     connect(mScrollArea, SIGNAL(scrolledToNextSlide()),
       
    88     mContentsWidget, SLOT(populateNextSlide()));
       
    89 
       
    90     mScrollArea->setContentWidget(mContentsWidget);
       
    91     mScrollArea->setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
       
    92     mScrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAutoHide);
       
    93 
       
    94     QDEBUG_WRITE("UnifiedViewer contruction End");
       
    95 }
       
    96 
       
    97 //----------------------------------------------------------------------------
       
    98 // UnifiedViewer::UnifiedViewer
       
    99 // Destructor
       
   100 //----------------------------------------------------------------------------
       
   101 UnifiedViewer::~UnifiedViewer()
       
   102 {
       
   103     HbStyleLoader::unregisterFilePath(":/layouts");
       
   104 }
       
   105 
       
   106 //----------------------------------------------------------------------------
       
   107 // UnifiedViewer::createToolBar
       
   108 // Creates tool bar actions
       
   109 //----------------------------------------------------------------------------
       
   110 void UnifiedViewer::createToolBar()
       
   111 {
       
   112     HbToolBar* toolbar = this->toolBar();
       
   113     toolbar->setOrientation(Qt::Horizontal);
       
   114 
       
   115     int sendingState = mViewFeeder->sendingState();
       
   116 
       
   117     if (mViewFeeder->sendingState() == ConvergedMessage::Failed)
       
   118     {
       
   119         toolbar->addAction(HbIcon(SEND_ICON), "");
       
   120     }
       
   121     else
       
   122     {
       
   123         // do not show reply option for multi recipient outgoing message
       
   124         if(!(!mViewFeeder->isIncoming() && mViewFeeder->recipientCount()>1))
       
   125         {
       
   126             toolbar->addAction(HbIcon(REPLY_ICON), "", this, SLOT(handleReplyAction()));
       
   127         }
       
   128 
       
   129         if (mViewFeeder->recipientCount() > 1)
       
   130         {
       
   131             toolbar->addAction(HbIcon(REPLY_ALL_ICON), "", this, SLOT(handleReplyAllAction()));
       
   132         }
       
   133     }
       
   134 
       
   135     if (isForwardOk())
       
   136     {
       
   137         toolbar->addAction(HbIcon(FORWARD_ICON), "", this, SLOT(handleFwdAction()));
       
   138     }
       
   139 
       
   140     toolbar->addAction(HbIcon(DELETE_ICON), "", this, SLOT(handleDeleteAction()));
       
   141 }
       
   142 
       
   143 //---------------------------------------------------------------
       
   144 // UnifiedViewer::clearContent
       
   145 // @see header file
       
   146 //---------------------------------------------------------------
       
   147 void UnifiedViewer::clearContent()
       
   148 {
       
   149     QDEBUG_WRITE("UnifiedViewer clearContent start");
       
   150 
       
   151     mContentsWidget->clearContent();
       
   152     mContentsWidget->resize(mContentsWidget->rect().width(), -1);
       
   153     mScrollArea->setPosToStart();
       
   154     mViewFeeder->clearContent();
       
   155 
       
   156     QDEBUG_WRITE("UnifiedViewer clearContent End");
       
   157 }
       
   158 
       
   159 //---------------------------------------------------------------
       
   160 // UnifiedViewer::populateContent
       
   161 // @see header file
       
   162 //---------------------------------------------------------------
       
   163 void UnifiedViewer::populateContent(const qint32 messageId, bool update, int msgCount)
       
   164 {
       
   165     QDEBUG_WRITE("UnifiedViewer populateContent Start");
       
   166 
       
   167     mMsgCount = msgCount;
       
   168     mMessageId = messageId;
       
   169 
       
   170     QDEBUG_WRITE("UnifiedViewer feeder->updateContent START");
       
   171 
       
   172     if (update)
       
   173     {
       
   174         mViewFeeder->updateContent(messageId);
       
   175     }
       
   176     QDEBUG_WRITE("UnifiedViewer feeder->updateContent END");
       
   177 
       
   178     // Dont show the scroll bar.
       
   179     mScrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
       
   180 
       
   181     if ( (mViewFeeder->msgType() == KSenduiMtmMmsUidValue) &&
       
   182          (mViewFeeder->slideCount() > 0) )
       
   183     {
       
   184         mScrollArea->setTotalSlides(mViewFeeder->slideCount());
       
   185     }
       
   186     else
       
   187     {
       
   188         mScrollArea->setTotalSlides(1);
       
   189     }
       
   190     mScrollArea->resetCurrentSlide();
       
   191 
       
   192     mContentsWidget->populateContent();
       
   193 
       
   194     //Creation of toolbar now depends on content
       
   195     createToolBar();
       
   196 
       
   197     QDEBUG_WRITE("UnifiedViewer populateContent END");
       
   198 }
       
   199 
       
   200 //---------------------------------------------------------------
       
   201 // UnifiedViewer::handleFwdAction
       
   202 // @see header file
       
   203 //---------------------------------------------------------------
       
   204 void UnifiedViewer::handleFwdAction()
       
   205 {
       
   206     launchEditor(MsgBaseView::FORWARD_MSG);
       
   207 }
       
   208 
       
   209 //---------------------------------------------------------------
       
   210 // UnifiedViewer::handleReplyAction
       
   211 // @see header file
       
   212 //---------------------------------------------------------------
       
   213 void UnifiedViewer::handleReplyAction()
       
   214 {
       
   215     launchEditor(MsgBaseView::REPLY_MSG);
       
   216 }
       
   217 
       
   218 //---------------------------------------------------------------
       
   219 // UnifiedViewer::handleReplyAllAction
       
   220 // @see header file
       
   221 //---------------------------------------------------------------
       
   222 void UnifiedViewer::handleReplyAllAction()
       
   223 {
       
   224     launchEditor(MsgBaseView::REPLY_ALL_MSG);
       
   225 }
       
   226 
       
   227 //---------------------------------------------------------------
       
   228 // UnifiedViewer::resizeEvent
       
   229 // @see header file
       
   230 //---------------------------------------------------------------
       
   231 void UnifiedViewer::resizeEvent(QGraphicsSceneResizeEvent * event)
       
   232 {
       
   233     Q_UNUSED(event)
       
   234     mContentsWidget->resize(this->rect().width(), this->rect().height()+1);
       
   235 }
       
   236 
       
   237 //---------------------------------------------------------------
       
   238 // UnifiedViewer::handleDeleteAction
       
   239 // @see header file
       
   240 //---------------------------------------------------------------
       
   241 void UnifiedViewer::handleDeleteAction()
       
   242 {
       
   243     QString txt = LOC_DELETE_MESSAGE;
       
   244 
       
   245     //if mms and out going. check for sharing
       
   246     if((mViewFeeder->msgType() == KSenduiMtmMmsUidValue) && (!mViewFeeder->isIncoming()))
       
   247     {
       
   248         if(mViewFeeder->recipientCount() > 1 )
       
   249         {
       
   250             txt =  LOC_DELETE_SHARED_MESSAGE;
       
   251         }
       
   252     }
       
   253 
       
   254     HbMessageBox::question(txt,this,SLOT(onDialogDeleteMsg(int)),
       
   255                            HbMessageBox::Delete | HbMessageBox::Cancel);
       
   256 }
       
   257 
       
   258 //---------------------------------------------------------------
       
   259 // UnifiedViewer::sendMessage
       
   260 // @see header file
       
   261 //---------------------------------------------------------------
       
   262 void UnifiedViewer::sendMessage(const QString& phoneNumber,const QString& alias)
       
   263     {
       
   264     ConvergedMessage message;
       
   265     message.setBodyText(QString());
       
   266 
       
   267     ConvergedMessageAddress address;
       
   268     address.setAlias(alias);
       
   269     address.setAddress(phoneNumber);
       
   270     message.addToRecipient(address);
       
   271 
       
   272     QByteArray dataArray;
       
   273     QDataStream messageStream
       
   274     (&dataArray, QIODevice::WriteOnly | QIODevice::Append);
       
   275     message.serialize(messageStream);
       
   276 
       
   277     QVariantList params;
       
   278     params << MsgBaseView::UNIEDITOR;
       
   279     params << MsgBaseView::UNIVIEWER;
       
   280     params << dataArray;
       
   281 
       
   282     emit switchView(params);
       
   283     }
       
   284 
       
   285 //---------------------------------------------------------------
       
   286 // UnifiedViewer::onDialogDeleteMsg
       
   287 // @see header file
       
   288 //---------------------------------------------------------------
       
   289 void UnifiedViewer::onDialogDeleteMsg(int val)
       
   290 {
       
   291     if (val == HbMessageBox::Delete) {
       
   292         QList<int> msgIdList;
       
   293         msgIdList << mMessageId;
       
   294 
       
   295         ConversationsEngine::instance()->deleteMessages(msgIdList);
       
   296 
       
   297         QVariantList param;
       
   298         if (mMsgCount > 1) {
       
   299             param << MsgBaseView::CV;
       
   300             param << MsgBaseView::UNIVIEWER;
       
   301         }
       
   302         else {
       
   303             param << MsgBaseView::CLV;
       
   304             param << MsgBaseView::UNIVIEWER;
       
   305         }
       
   306 
       
   307         QVariant dummy(QVariant::Invalid);
       
   308         param << dummy;
       
   309         emit switchView(param);
       
   310     }
       
   311 }
       
   312 
       
   313 //---------------------------------------------------------------
       
   314 // UnifiedViewer::launchEditor
       
   315 // @see header file
       
   316 //---------------------------------------------------------------
       
   317 void UnifiedViewer::launchEditor(
       
   318         MsgBaseView::UniEditorOperation operation)
       
   319 {
       
   320     ConvergedMessage message;
       
   321     ConvergedMessageId id(mMessageId);
       
   322     message.setMessageId(id);
       
   323     if(mViewFeeder->msgType() == KSenduiMtmMmsUidValue)
       
   324     {
       
   325         message.setMessageType(ConvergedMessage::Mms);
       
   326     }
       
   327     else
       
   328     {
       
   329         message.setMessageType(ConvergedMessage::Sms);
       
   330     }
       
   331 
       
   332     QByteArray dataArray;
       
   333     QDataStream messageStream
       
   334     (&dataArray, QIODevice::WriteOnly | QIODevice::Append);
       
   335     message.serialize(messageStream);
       
   336 
       
   337     QVariantList params;
       
   338     params << MsgBaseView::UNIEDITOR; // target view
       
   339     params << MsgBaseView::UNIVIEWER; // source view
       
   340 
       
   341     params << dataArray;
       
   342     params << operation;
       
   343 
       
   344     emit switchView(params);
       
   345 }
       
   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 
       
   390 // EOF