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