messagingapp/msgui/unifiedviewer/src/unifiedviewer.cpp
changeset 23 238255e8b033
child 25 84d9eb65b26f
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
       
     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 
       
    28 // USER INCLUDES
       
    29 #include "uniscrollarea.h"
       
    30 #include "unicontentswidget.h"
       
    31 #include "univiewerfeeder.h"
       
    32 #include "convergedmessageid.h"
       
    33 #include "convergedmessage.h"
       
    34 #include "convergedmessageaddress.h"
       
    35 #include "conversationsenginedefines.h"
       
    36 #include "conversationsengine.h"
       
    37 #include "debugtraces.h"
       
    38 #include "nativemessageconsts.h"
       
    39 
       
    40 // LOCAL CONSTANTS
       
    41 const QString REPLY_ICON("qtg_mono_reply.svg");
       
    42 const QString REPLY_ALL_ICON("qtg_mono_reply_all.svg");
       
    43 const QString FORWARD_ICON("qtg_mono_forward.svg");
       
    44 const QString DELETE_ICON("qtg_mono_delete.svg");
       
    45 
       
    46 //LOCALIZED CONSTANTS
       
    47 #define LOC_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
       
    48 #define LOC_BUTTON_DELETE hbTrId("txt_common_button_delete")
       
    49 #define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel")
       
    50 #define LOC_DELETE_POPINFO hbTrId("txt_messaging_dpopinfo_message_deleted")
       
    51 
       
    52 //----------------------------------------------------------------------------
       
    53 // UnifiedViewer::UnifiedViewer
       
    54 // constructor
       
    55 //----------------------------------------------------------------------------
       
    56 UnifiedViewer::UnifiedViewer(const qint32 messageId, QGraphicsItem *parent) :
       
    57     MsgBaseView(parent)
       
    58 {
       
    59     QDEBUG_WRITE("UnifiedViewer contruction start");
       
    60 
       
    61     if (!HbStyleLoader::registerFilePath(":/layouts"))
       
    62     {
       
    63         QDEBUG_WRITE("ERROR: UnifiedViewer -> HbStyleLoader::registerFilePath");
       
    64     }
       
    65 
       
    66     mMessageId = messageId;
       
    67     mViewFeeder = new UniViewerFeeder(mMessageId, this);
       
    68 
       
    69     mMainLayout = new QGraphicsLinearLayout(Qt::Vertical, this);
       
    70 
       
    71     mScrollArea = new UniScrollArea(this);
       
    72 
       
    73     mContentsWidget = new UniContentsWidget(mViewFeeder,this);
       
    74 	
       
    75     connect(mContentsWidget,SIGNAL(sendMessage(const QString&)),
       
    76             this, SLOT(sendMessage(const QString&)));
       
    77 
       
    78     connect(mScrollArea, SIGNAL(scrolledToNextSlide()),
       
    79     mContentsWidget, SLOT(populateNextSlide()));
       
    80 
       
    81     mScrollArea->setContentWidget(mContentsWidget);
       
    82     mScrollArea->setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
       
    83     mScrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAutoHide);
       
    84     mMainLayout->addItem(mScrollArea);
       
    85     mMainLayout->setSpacing(0);
       
    86     mMainLayout->setContentsMargins(0, 0, 0, 0);
       
    87 
       
    88     setLayout(mMainLayout);
       
    89 
       
    90     createToolBar();
       
    91 
       
    92     QDEBUG_WRITE("UnifiedViewer contruction End");
       
    93 }
       
    94 
       
    95 //----------------------------------------------------------------------------
       
    96 // UnifiedViewer::UnifiedViewer
       
    97 // Destructor
       
    98 //----------------------------------------------------------------------------
       
    99 UnifiedViewer::~UnifiedViewer()
       
   100 {
       
   101     HbStyleLoader::unregisterFilePath(":/layouts");
       
   102 
       
   103 }
       
   104 
       
   105 //----------------------------------------------------------------------------
       
   106 // UnifiedViewer::createToolBar
       
   107 // Creates tool bar actions
       
   108 //----------------------------------------------------------------------------
       
   109 void UnifiedViewer::createToolBar()
       
   110 {
       
   111     HbToolBar *toolBar = this->toolBar();
       
   112     toolBar->setOrientation(Qt::Horizontal);
       
   113 
       
   114     HbAction* replyAction = new HbAction(HbIcon(REPLY_ICON), "", this);
       
   115     toolBar->addAction(replyAction);
       
   116 
       
   117     HbAction* replyAllAction = new HbAction(HbIcon(REPLY_ALL_ICON), "", this);
       
   118     toolBar->addAction(replyAllAction);
       
   119 
       
   120     HbAction* forwardAction = new HbAction(HbIcon(FORWARD_ICON), "", this);
       
   121     toolBar->addAction(forwardAction);
       
   122 
       
   123     HbAction* deleteAction = new HbAction(HbIcon(DELETE_ICON), "", this);
       
   124     toolBar->addAction(deleteAction);
       
   125 
       
   126     connect(deleteAction, SIGNAL(triggered()),
       
   127     this, SLOT(handleDeleteAction()));
       
   128 }
       
   129 
       
   130 //---------------------------------------------------------------
       
   131 // UnifiedViewer::clearContent
       
   132 // @see header file
       
   133 //---------------------------------------------------------------
       
   134 void UnifiedViewer::clearContent()
       
   135 {
       
   136     QDEBUG_WRITE("UnifiedViewer clearContent start");
       
   137 
       
   138     mContentsWidget->clearContent();
       
   139     mContentsWidget->resize(mContentsWidget->rect().width(), -1);
       
   140     mScrollArea->setPosToStart();
       
   141     mViewFeeder->clearContent();
       
   142 
       
   143     QDEBUG_WRITE("UnifiedViewer clearContent End");
       
   144 }
       
   145 
       
   146 //---------------------------------------------------------------
       
   147 // UnifiedViewer::populateContent
       
   148 // @see header file
       
   149 //---------------------------------------------------------------
       
   150 void UnifiedViewer::populateContent(const qint32 messageId, bool update, int msgCount)
       
   151 {
       
   152     QDEBUG_WRITE("UnifiedViewer populateContent Start");
       
   153 
       
   154     mMsgCount = msgCount;
       
   155     mMessageId = messageId;
       
   156 
       
   157     QDEBUG_WRITE("UnifiedViewer feeder->updateContent START");
       
   158 
       
   159     if (update)
       
   160     {
       
   161         mViewFeeder->updateContent(messageId);
       
   162     }
       
   163     QDEBUG_WRITE("UnifiedViewer feeder->updateContent END");
       
   164 
       
   165     if ( (mViewFeeder->msgType() == KSenduiMtmMmsUidValue) &&
       
   166          (mViewFeeder->slideCount() > 0) )
       
   167     {
       
   168         mScrollArea->setTotalSlides(mViewFeeder->slideCount());
       
   169     }
       
   170     else
       
   171     {
       
   172         mScrollArea->setTotalSlides(1);
       
   173     }
       
   174     mScrollArea->resetCurrentSlide();
       
   175 
       
   176     mContentsWidget->populateContent();
       
   177 
       
   178     QDEBUG_WRITE("UnifiedViewer populateContent END");
       
   179 }
       
   180 
       
   181 //---------------------------------------------------------------
       
   182 // UnifiedViewer::handleFwdAction
       
   183 // @see header file
       
   184 //---------------------------------------------------------------
       
   185 void UnifiedViewer::handleFwdAction()
       
   186 {
       
   187 }
       
   188 
       
   189 //---------------------------------------------------------------
       
   190 // UnifiedViewer::resizeEvent
       
   191 // @see header file
       
   192 //---------------------------------------------------------------
       
   193 void UnifiedViewer::resizeEvent(QGraphicsSceneResizeEvent * event)
       
   194 {
       
   195     Q_UNUSED(event)
       
   196     mContentsWidget->resize(this->rect().width(), -1);
       
   197 }
       
   198 
       
   199 //---------------------------------------------------------------
       
   200 // UnifiedViewer::handleDeleteAction
       
   201 // @see header file
       
   202 //---------------------------------------------------------------
       
   203 void UnifiedViewer::handleDeleteAction()
       
   204 {
       
   205     bool result = HbMessageBox::question(LOC_DELETE_MESSAGE,
       
   206                                          LOC_BUTTON_DELETE, 
       
   207                                          LOC_BUTTON_CANCEL);
       
   208     if (result)
       
   209     {
       
   210         QList<int> msgIdList;
       
   211         msgIdList << mMessageId;
       
   212 
       
   213         ConversationsEngine::instance()->deleteMessages(msgIdList);
       
   214         HbNotificationDialog::launchDialog(LOC_DELETE_POPINFO);
       
   215 
       
   216         QVariantList param;
       
   217         if (mMsgCount > 1)
       
   218         {
       
   219             param << MsgBaseView::CV;
       
   220             param << MsgBaseView::UNIVIEWER;
       
   221         }
       
   222         else
       
   223         {
       
   224             param << MsgBaseView::CLV;
       
   225             param << MsgBaseView::UNIVIEWER;
       
   226         }
       
   227 
       
   228         QVariant dummy(QVariant::Invalid);
       
   229         param << dummy;
       
   230         emit switchView(param);
       
   231     }
       
   232 
       
   233 }
       
   234 
       
   235 //---------------------------------------------------------------
       
   236 // UnifiedViewer::sendMessage
       
   237 // @see header file
       
   238 //---------------------------------------------------------------
       
   239 void UnifiedViewer::sendMessage(const QString& phoneNumber)
       
   240     {
       
   241     ConvergedMessage message;
       
   242     message.setBodyText(QString());
       
   243 
       
   244     ConvergedMessageAddress address;
       
   245     address.setAlias(phoneNumber);
       
   246     address.setAddress(phoneNumber);
       
   247     message.addToRecipient(address);
       
   248 
       
   249     QByteArray dataArray;
       
   250     QDataStream messageStream
       
   251     (&dataArray, QIODevice::WriteOnly | QIODevice::Append);
       
   252     message.serialize(messageStream);
       
   253 
       
   254     QVariantList params;
       
   255     params << MsgBaseView::UNIEDITOR;
       
   256     params << MsgBaseView::UNIVIEWER;
       
   257     params << dataArray;
       
   258 
       
   259     emit switchView(params);
       
   260     }
       
   261 // EOF