|
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 #include "mmsconformancecheck.h" |
|
42 #include "UniEditorGenUtils.h" // This is needed for KDefaultMaxSize |
|
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 //LOCALIZED CONSTANTS |
|
52 #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 |
|
56 //---------------------------------------------------------------------------- |
|
57 // UnifiedViewer::UnifiedViewer |
|
58 // constructor |
|
59 //---------------------------------------------------------------------------- |
|
60 UnifiedViewer::UnifiedViewer(const qint32 messageId, QGraphicsItem *parent) : |
|
61 MsgBaseView(parent) |
|
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 |
|
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), ""); |
|
118 toolbar->addAction(HbIcon(REPLY_ALL_ICON), ""); |
|
119 } |
|
120 |
|
121 if (validateMsgForForward()) |
|
122 { |
|
123 toolbar->addAction(HbIcon(FORWARD_ICON), "", this, SLOT(handleFwdAction())); |
|
124 } |
|
125 |
|
126 toolbar->addAction(HbIcon(DELETE_ICON), "", this, SLOT(handleDeleteAction())); |
|
127 } |
|
128 |
|
129 //--------------------------------------------------------------- |
|
130 // UnifiedViewer::clearContent |
|
131 // @see header file |
|
132 //--------------------------------------------------------------- |
|
133 void UnifiedViewer::clearContent() |
|
134 { |
|
135 QDEBUG_WRITE("UnifiedViewer clearContent start"); |
|
136 |
|
137 mContentsWidget->clearContent(); |
|
138 mContentsWidget->resize(mContentsWidget->rect().width(), -1); |
|
139 mScrollArea->setPosToStart(); |
|
140 mViewFeeder->clearContent(); |
|
141 |
|
142 QDEBUG_WRITE("UnifiedViewer clearContent End"); |
|
143 } |
|
144 |
|
145 //--------------------------------------------------------------- |
|
146 // UnifiedViewer::populateContent |
|
147 // @see header file |
|
148 //--------------------------------------------------------------- |
|
149 void UnifiedViewer::populateContent(const qint32 messageId, bool update, int msgCount) |
|
150 { |
|
151 QDEBUG_WRITE("UnifiedViewer populateContent Start"); |
|
152 |
|
153 mMsgCount = msgCount; |
|
154 mMessageId = messageId; |
|
155 |
|
156 QDEBUG_WRITE("UnifiedViewer feeder->updateContent START"); |
|
157 |
|
158 if (update) |
|
159 { |
|
160 mViewFeeder->updateContent(messageId); |
|
161 } |
|
162 QDEBUG_WRITE("UnifiedViewer feeder->updateContent END"); |
|
163 |
|
164 // Dont show the scroll bar. |
|
165 mScrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); |
|
166 |
|
167 if ( (mViewFeeder->msgType() == KSenduiMtmMmsUidValue) && |
|
168 (mViewFeeder->slideCount() > 0) ) |
|
169 { |
|
170 mScrollArea->setTotalSlides(mViewFeeder->slideCount()); |
|
171 } |
|
172 else |
|
173 { |
|
174 mScrollArea->setTotalSlides(1); |
|
175 } |
|
176 mScrollArea->resetCurrentSlide(); |
|
177 |
|
178 mContentsWidget->populateContent(); |
|
179 |
|
180 //Creation of toolbar now depends on content |
|
181 createToolBar(); |
|
182 |
|
183 QDEBUG_WRITE("UnifiedViewer populateContent END"); |
|
184 } |
|
185 |
|
186 //--------------------------------------------------------------- |
|
187 // UnifiedViewer::handleFwdAction |
|
188 // @see header file |
|
189 //--------------------------------------------------------------- |
|
190 void UnifiedViewer::handleFwdAction() |
|
191 { |
|
192 ConvergedMessage message; |
|
193 ConvergedMessageId id(mMessageId); |
|
194 message.setMessageId(id); |
|
195 if(mViewFeeder->msgType() == KSenduiMtmMmsUidValue) |
|
196 { |
|
197 message.setMessageType(ConvergedMessage::Mms); |
|
198 } |
|
199 else |
|
200 { |
|
201 message.setMessageType(ConvergedMessage::Sms); |
|
202 } |
|
203 |
|
204 QByteArray dataArray; |
|
205 QDataStream messageStream |
|
206 (&dataArray, QIODevice::WriteOnly | QIODevice::Append); |
|
207 message.serialize(messageStream); |
|
208 |
|
209 QVariantList params; |
|
210 params << MsgBaseView::UNIEDITOR; // target view |
|
211 params << MsgBaseView::UNIVIEWER; // source view |
|
212 |
|
213 params << dataArray; |
|
214 params << MsgBaseView::FORWARD_MSG; |
|
215 |
|
216 emit switchView(params); |
|
217 } |
|
218 |
|
219 //--------------------------------------------------------------- |
|
220 // UnifiedViewer::resizeEvent |
|
221 // @see header file |
|
222 //--------------------------------------------------------------- |
|
223 void UnifiedViewer::resizeEvent(QGraphicsSceneResizeEvent * event) |
|
224 { |
|
225 Q_UNUSED(event) |
|
226 mContentsWidget->resize(this->rect().width(), this->rect().height()+1); |
|
227 } |
|
228 |
|
229 //--------------------------------------------------------------- |
|
230 // UnifiedViewer::handleDeleteAction |
|
231 // @see header file |
|
232 //--------------------------------------------------------------- |
|
233 void UnifiedViewer::handleDeleteAction() |
|
234 { |
|
235 HbMessageBox::question(LOC_DELETE_MESSAGE,this,SLOT(onDialogDeleteMsg(HbAction*)), |
|
236 LOC_BUTTON_DELETE, |
|
237 LOC_BUTTON_CANCEL); |
|
238 } |
|
239 |
|
240 //--------------------------------------------------------------- |
|
241 // UnifiedViewer::sendMessage |
|
242 // @see header file |
|
243 //--------------------------------------------------------------- |
|
244 void UnifiedViewer::sendMessage(const QString& phoneNumber,const QString& alias) |
|
245 { |
|
246 ConvergedMessage message; |
|
247 message.setBodyText(QString()); |
|
248 |
|
249 ConvergedMessageAddress address; |
|
250 address.setAlias(alias); |
|
251 address.setAddress(phoneNumber); |
|
252 message.addToRecipient(address); |
|
253 |
|
254 QByteArray dataArray; |
|
255 QDataStream messageStream |
|
256 (&dataArray, QIODevice::WriteOnly | QIODevice::Append); |
|
257 message.serialize(messageStream); |
|
258 |
|
259 QVariantList params; |
|
260 params << MsgBaseView::UNIEDITOR; |
|
261 params << MsgBaseView::UNIVIEWER; |
|
262 params << dataArray; |
|
263 |
|
264 emit switchView(params); |
|
265 } |
|
266 |
|
267 //--------------------------------------------------------------- |
|
268 // UnifiedViewer::validateMsgForForward |
|
269 // @see header file |
|
270 //--------------------------------------------------------------- |
|
271 bool UnifiedViewer::validateMsgForForward() |
|
272 { |
|
273 if (mViewFeeder->msgType() == KSenduiMtmMmsUidValue) |
|
274 { |
|
275 bool retValue = false; |
|
276 |
|
277 //Validate if the mms msg can be forwarded or not |
|
278 MmsConformanceCheck* mmsConformanceCheck = new MmsConformanceCheck; |
|
279 retValue = mmsConformanceCheck->validateMsgForForward(mMessageId); |
|
280 |
|
281 delete mmsConformanceCheck; |
|
282 return retValue; |
|
283 } |
|
284 |
|
285 return true; |
|
286 } |
|
287 |
|
288 //--------------------------------------------------------------- |
|
289 // UnifiedViewer::onDialogDeleteMsg |
|
290 // @see header file |
|
291 //--------------------------------------------------------------- |
|
292 void UnifiedViewer::onDialogDeleteMsg(HbAction* action) |
|
293 { |
|
294 HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender()); |
|
295 if (action == dlg->actions().at(0)) { |
|
296 QList<int> msgIdList; |
|
297 msgIdList << mMessageId; |
|
298 |
|
299 ConversationsEngine::instance()->deleteMessages(msgIdList); |
|
300 |
|
301 QVariantList param; |
|
302 if (mMsgCount > 1) { |
|
303 param << MsgBaseView::CV; |
|
304 param << MsgBaseView::UNIVIEWER; |
|
305 } |
|
306 else { |
|
307 param << MsgBaseView::CLV; |
|
308 param << MsgBaseView::UNIVIEWER; |
|
309 } |
|
310 |
|
311 QVariant dummy(QVariant::Invalid); |
|
312 param << dummy; |
|
313 emit switchView(param); |
|
314 } |
|
315 } |
|
316 |
|
317 // EOF |