| author | Pat Downey <patd@symbian.org> | 
| Thu, 24 Jun 2010 13:18:58 +0100 | |
| changeset 36 | 844a5921f85b | 
| parent 34 | 84197e66a4bd | 
| child 44 | 36f374c67aa8 | 
| permissions | -rw-r--r-- | 
| 31 | 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 | ||
| 30 | // USER INCLUDES | |
| 31 | #include "uniscrollarea.h" | |
| 32 | #include "unicontentswidget.h" | |
| 33 | #include "univiewerfeeder.h" | |
| 34 | #include "convergedmessageid.h" | |
| 35 | #include "convergedmessage.h" | |
| 36 | #include "convergedmessageaddress.h" | |
| 37 | #include "conversationsenginedefines.h" | |
| 38 | #include "conversationsengine.h" | |
| 39 | #include "debugtraces.h" | |
| 40 | #include "nativemessageconsts.h" | |
| 41 | ||
| 42 | // LOCAL CONSTANTS | |
| 43 | const QString REPLY_ICON("qtg_mono_reply");
 | |
| 44 | const QString REPLY_ALL_ICON("qtg_mono_reply_all");
 | |
| 45 | const QString FORWARD_ICON("qtg_mono_forward_msg");
 | |
| 46 | const QString SEND_ICON("qtg_mono_send");
 | |
| 47 | const QString DELETE_ICON("qtg_mono_delete");
 | |
| 48 | ||
| 49 | //LOCALIZED CONSTANTS | |
| 50 | #define LOC_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
 | |
| 51 | #define LOC_BUTTON_DELETE hbTrId("txt_common_button_delete")
 | |
| 52 | #define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel")
 | |
| 53 | ||
| 54 | //---------------------------------------------------------------------------- | |
| 55 | // UnifiedViewer::UnifiedViewer | |
| 56 | // constructor | |
| 57 | //---------------------------------------------------------------------------- | |
| 34 
84197e66a4bd
Revision: 201021
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
31diff
changeset | 58 | UnifiedViewer::UnifiedViewer(const qint32 messageId, | 
| 
84197e66a4bd
Revision: 201021
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
31diff
changeset | 59 | int canForwardMessage, | 
| 
84197e66a4bd
Revision: 201021
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
31diff
changeset | 60 | QGraphicsItem *parent) : | 
| 
84197e66a4bd
Revision: 201021
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
31diff
changeset | 61 | MsgBaseView(parent), mForwardMessage(false) | 
| 31 | 62 | {
 | 
| 63 |     QDEBUG_WRITE("UnifiedViewer contruction start");
 | |
| 64 | ||
| 65 |     if (!HbStyleLoader::registerFilePath(":/layouts"))
 | |
| 66 |     {
 | |
| 67 |         QDEBUG_WRITE("ERROR: UnifiedViewer -> HbStyleLoader::registerFilePath");
 | |
| 68 | } | |
| 69 | ||
| 70 | mMessageId = messageId; | |
| 71 | mViewFeeder = new UniViewerFeeder(mMessageId, this); | |
| 72 | ||
| 34 
84197e66a4bd
Revision: 201021
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
31diff
changeset | 73 | if (canForwardMessage > 0) mForwardMessage = true; | 
| 
84197e66a4bd
Revision: 201021
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
31diff
changeset | 74 | |
| 31 | 75 | mScrollArea = new UniScrollArea(this); | 
| 76 | this->setWidget(mScrollArea); | |
| 77 | ||
| 78 | mContentsWidget = new UniContentsWidget(mViewFeeder,this); | |
| 79 | ||
| 80 | connect(mContentsWidget,SIGNAL(sendMessage(const QString&,const QString&)), | |
| 81 | this, SLOT(sendMessage(const QString&,const QString&))); | |
| 82 | ||
| 83 | connect(mScrollArea, SIGNAL(scrolledToNextSlide()), | |
| 84 | mContentsWidget, SLOT(populateNextSlide())); | |
| 85 | ||
| 86 | mScrollArea->setContentWidget(mContentsWidget); | |
| 87 | mScrollArea->setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); | |
| 88 | mScrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAutoHide); | |
| 89 | ||
| 90 |     QDEBUG_WRITE("UnifiedViewer contruction End");
 | |
| 91 | } | |
| 92 | ||
| 93 | //---------------------------------------------------------------------------- | |
| 94 | // UnifiedViewer::UnifiedViewer | |
| 95 | // Destructor | |
| 96 | //---------------------------------------------------------------------------- | |
| 97 | UnifiedViewer::~UnifiedViewer() | |
| 98 | {
 | |
| 99 |     HbStyleLoader::unregisterFilePath(":/layouts");
 | |
| 100 | } | |
| 101 | ||
| 102 | //---------------------------------------------------------------------------- | |
| 103 | // UnifiedViewer::createToolBar | |
| 104 | // Creates tool bar actions | |
| 105 | //---------------------------------------------------------------------------- | |
| 106 | void UnifiedViewer::createToolBar() | |
| 107 | {
 | |
| 108 | HbToolBar* toolbar = this->toolBar(); | |
| 109 | toolbar->setOrientation(Qt::Horizontal); | |
| 110 | ||
| 111 | int sendingState = mViewFeeder->sendingState(); | |
| 112 | ||
| 113 | if (mViewFeeder->sendingState() == ConvergedMessage::Failed) | |
| 114 |     {
 | |
| 115 | toolbar->addAction(HbIcon(SEND_ICON), ""); | |
| 116 | } | |
| 117 | else | |
| 118 |     {
 | |
| 119 | toolbar->addAction(HbIcon(REPLY_ICON), ""); | |
| 34 
84197e66a4bd
Revision: 201021
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
31diff
changeset | 120 | |
| 
84197e66a4bd
Revision: 201021
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
31diff
changeset | 121 | if (mViewFeeder->recipientCount() > 1) | 
| 
84197e66a4bd
Revision: 201021
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
31diff
changeset | 122 |         {
 | 
| 
84197e66a4bd
Revision: 201021
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
31diff
changeset | 123 | toolbar->addAction(HbIcon(REPLY_ALL_ICON), ""); | 
| 
84197e66a4bd
Revision: 201021
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
31diff
changeset | 124 | } | 
| 31 | 125 | } | 
| 126 | ||
| 34 
84197e66a4bd
Revision: 201021
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
31diff
changeset | 127 | if (mForwardMessage) | 
| 31 | 128 |     {
 | 
| 129 | toolbar->addAction(HbIcon(FORWARD_ICON), "", this, SLOT(handleFwdAction())); | |
| 130 | } | |
| 131 | ||
| 132 | toolbar->addAction(HbIcon(DELETE_ICON), "", this, SLOT(handleDeleteAction())); | |
| 133 | } | |
| 134 | ||
| 135 | //--------------------------------------------------------------- | |
| 136 | // UnifiedViewer::clearContent | |
| 137 | // @see header file | |
| 138 | //--------------------------------------------------------------- | |
| 139 | void UnifiedViewer::clearContent() | |
| 140 | {
 | |
| 141 |     QDEBUG_WRITE("UnifiedViewer clearContent start");
 | |
| 142 | ||
| 143 | mContentsWidget->clearContent(); | |
| 144 | mContentsWidget->resize(mContentsWidget->rect().width(), -1); | |
| 145 | mScrollArea->setPosToStart(); | |
| 146 | mViewFeeder->clearContent(); | |
| 147 | ||
| 148 |     QDEBUG_WRITE("UnifiedViewer clearContent End");
 | |
| 149 | } | |
| 150 | ||
| 151 | //--------------------------------------------------------------- | |
| 152 | // UnifiedViewer::populateContent | |
| 153 | // @see header file | |
| 154 | //--------------------------------------------------------------- | |
| 155 | void UnifiedViewer::populateContent(const qint32 messageId, bool update, int msgCount) | |
| 156 | {
 | |
| 157 |     QDEBUG_WRITE("UnifiedViewer populateContent Start");
 | |
| 158 | ||
| 159 | mMsgCount = msgCount; | |
| 160 | mMessageId = messageId; | |
| 161 | ||
| 162 |     QDEBUG_WRITE("UnifiedViewer feeder->updateContent START");
 | |
| 163 | ||
| 164 | if (update) | |
| 165 |     {
 | |
| 166 | mViewFeeder->updateContent(messageId); | |
| 167 | } | |
| 168 |     QDEBUG_WRITE("UnifiedViewer feeder->updateContent END");
 | |
| 169 | ||
| 170 | // Dont show the scroll bar. | |
| 171 | mScrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); | |
| 172 | ||
| 173 | if ( (mViewFeeder->msgType() == KSenduiMtmMmsUidValue) && | |
| 174 | (mViewFeeder->slideCount() > 0) ) | |
| 175 |     {
 | |
| 176 | mScrollArea->setTotalSlides(mViewFeeder->slideCount()); | |
| 177 | } | |
| 178 | else | |
| 179 |     {
 | |
| 180 | mScrollArea->setTotalSlides(1); | |
| 181 | } | |
| 182 | mScrollArea->resetCurrentSlide(); | |
| 183 | ||
| 184 | mContentsWidget->populateContent(); | |
| 185 | ||
| 186 | //Creation of toolbar now depends on content | |
| 187 | createToolBar(); | |
| 188 | ||
| 189 |     QDEBUG_WRITE("UnifiedViewer populateContent END");
 | |
| 190 | } | |
| 191 | ||
| 192 | //--------------------------------------------------------------- | |
| 193 | // UnifiedViewer::handleFwdAction | |
| 194 | // @see header file | |
| 195 | //--------------------------------------------------------------- | |
| 196 | void UnifiedViewer::handleFwdAction() | |
| 197 | {
 | |
| 198 | ConvergedMessage message; | |
| 199 | ConvergedMessageId id(mMessageId); | |
| 200 | message.setMessageId(id); | |
| 201 | if(mViewFeeder->msgType() == KSenduiMtmMmsUidValue) | |
| 202 |     {
 | |
| 203 | message.setMessageType(ConvergedMessage::Mms); | |
| 204 | } | |
| 205 | else | |
| 206 |     {
 | |
| 207 | message.setMessageType(ConvergedMessage::Sms); | |
| 208 | } | |
| 209 | ||
| 210 | QByteArray dataArray; | |
| 211 | QDataStream messageStream | |
| 212 | (&dataArray, QIODevice::WriteOnly | QIODevice::Append); | |
| 213 | message.serialize(messageStream); | |
| 214 | ||
| 215 | QVariantList params; | |
| 216 | params << MsgBaseView::UNIEDITOR; // target view | |
| 217 | params << MsgBaseView::UNIVIEWER; // source view | |
| 218 | ||
| 219 | params << dataArray; | |
| 220 | params << MsgBaseView::FORWARD_MSG; | |
| 221 | ||
| 222 | emit switchView(params); | |
| 223 | } | |
| 224 | ||
| 225 | //--------------------------------------------------------------- | |
| 226 | // UnifiedViewer::resizeEvent | |
| 227 | // @see header file | |
| 228 | //--------------------------------------------------------------- | |
| 229 | void UnifiedViewer::resizeEvent(QGraphicsSceneResizeEvent * event) | |
| 230 | {
 | |
| 231 | Q_UNUSED(event) | |
| 232 | mContentsWidget->resize(this->rect().width(), this->rect().height()+1); | |
| 233 | } | |
| 234 | ||
| 235 | //--------------------------------------------------------------- | |
| 236 | // UnifiedViewer::handleDeleteAction | |
| 237 | // @see header file | |
| 238 | //--------------------------------------------------------------- | |
| 239 | void UnifiedViewer::handleDeleteAction() | |
| 240 | {
 | |
| 241 | HbMessageBox::question(LOC_DELETE_MESSAGE,this,SLOT(onDialogDeleteMsg(HbAction*)), | |
| 242 | LOC_BUTTON_DELETE, | |
| 243 | LOC_BUTTON_CANCEL); | |
| 244 | } | |
| 245 | ||
| 246 | //--------------------------------------------------------------- | |
| 247 | // UnifiedViewer::sendMessage | |
| 248 | // @see header file | |
| 249 | //--------------------------------------------------------------- | |
| 250 | void UnifiedViewer::sendMessage(const QString& phoneNumber,const QString& alias) | |
| 251 |     {
 | |
| 252 | ConvergedMessage message; | |
| 253 | message.setBodyText(QString()); | |
| 254 | ||
| 255 | ConvergedMessageAddress address; | |
| 256 | address.setAlias(alias); | |
| 257 | address.setAddress(phoneNumber); | |
| 258 | message.addToRecipient(address); | |
| 259 | ||
| 260 | QByteArray dataArray; | |
| 261 | QDataStream messageStream | |
| 262 | (&dataArray, QIODevice::WriteOnly | QIODevice::Append); | |
| 263 | message.serialize(messageStream); | |
| 264 | ||
| 265 | QVariantList params; | |
| 266 | params << MsgBaseView::UNIEDITOR; | |
| 267 | params << MsgBaseView::UNIVIEWER; | |
| 268 | params << dataArray; | |
| 269 | ||
| 270 | emit switchView(params); | |
| 271 | } | |
| 272 | ||
| 273 | //--------------------------------------------------------------- | |
| 274 | // UnifiedViewer::onDialogDeleteMsg | |
| 275 | // @see header file | |
| 276 | //--------------------------------------------------------------- | |
| 277 | void UnifiedViewer::onDialogDeleteMsg(HbAction* action) | |
| 278 | {
 | |
| 279 | HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender()); | |
| 280 |     if (action == dlg->actions().at(0)) {
 | |
| 281 | QList<int> msgIdList; | |
| 282 | msgIdList << mMessageId; | |
| 283 | ||
| 284 | ConversationsEngine::instance()->deleteMessages(msgIdList); | |
| 285 | ||
| 286 | QVariantList param; | |
| 287 |         if (mMsgCount > 1) {
 | |
| 288 | param << MsgBaseView::CV; | |
| 289 | param << MsgBaseView::UNIVIEWER; | |
| 290 | } | |
| 291 |         else {
 | |
| 292 | param << MsgBaseView::CLV; | |
| 293 | param << MsgBaseView::UNIVIEWER; | |
| 294 | } | |
| 295 | ||
| 296 | QVariant dummy(QVariant::Invalid); | |
| 297 | param << dummy; | |
| 298 | emit switchView(param); | |
| 299 | } | |
| 300 | } | |
| 301 | ||
| 302 | // EOF |