|
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: |
|
15 * class to manage differnt messaging views. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "msgviewmanager.h" |
|
20 |
|
21 #include <HbMainWindow> |
|
22 #include <HbAction> |
|
23 #include <xqserviceutil.h> |
|
24 #include <QSqlQuery> |
|
25 #include <QSqlError> |
|
26 #include <HbApplication> |
|
27 #include <xqappmgr.h> |
|
28 #include <hbmessagebox.h> |
|
29 #include <HbView> |
|
30 |
|
31 #include "conversationsengine.h" |
|
32 #include "msglistview.h" |
|
33 #include "msgunieditorview.h" |
|
34 #include "msgconversationbaseview.h" |
|
35 #include "unifiedviewer.h" |
|
36 #include "draftslistview.h" |
|
37 #include "msgsettingsview.h" |
|
38 #include "convergedmessageid.h" |
|
39 #include "ringbc.h" |
|
40 #include "unidatamodelloader.h" |
|
41 #include "unidatamodelplugininterface.h" |
|
42 #include "msgcontacthandler.h" |
|
43 #include "debugtraces.h" |
|
44 #include "msgaudiofetcherview.h" |
|
45 |
|
46 // LOCALIZATION |
|
47 #define LOC_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message") |
|
48 #define LOC_DIALOG_SAVE_RINGTONE hbTrId("txt_conversations_dialog_save_ringing_tone") |
|
49 |
|
50 const qint64 NULL_CONVERSATIONID = -1; |
|
51 |
|
52 MsgViewManager::MsgViewManager(bool serviceRequest, HbMainWindow* mainWindow, QObject* parent,int activityMsgId) : |
|
53 QObject(parent), mMainWindow(mainWindow), mUniEditor(0), mListView(0), mConversationView(0), |
|
54 mUniViewer(0), mDraftsListView(0), mSettingsView(0), mAudioFetcherView(0), mBackAction(0), |
|
55 mServiceRequest(serviceRequest), mConversationId(-1), mViewServiceRequest(false),mMessageId(-1) |
|
56 { |
|
57 //creating back action. |
|
58 mBackAction = new HbAction(Hb::BackNaviAction, this); |
|
59 connect(mBackAction, SIGNAL(triggered()), this, SLOT(onBackAction())); |
|
60 |
|
61 //create clv as first view if not a service request. |
|
62 if (!mServiceRequest) { |
|
63 |
|
64 if(activityMsgId == NULL_CONVERSATIONID) |
|
65 { |
|
66 QVariantList param; |
|
67 param << MsgBaseView::CLV; |
|
68 param << MsgBaseView::CLV; |
|
69 switchView(param); |
|
70 } |
|
71 else |
|
72 { |
|
73 openUniEditorActivity(activityMsgId); |
|
74 } |
|
75 } |
|
76 else |
|
77 { |
|
78 mDummyview = new HbView(); |
|
79 mMainWindow->addView(mDummyview); |
|
80 mMainWindow->setCurrentView(mDummyview); |
|
81 mViewTobeDeleted << mDummyview; |
|
82 } |
|
83 } |
|
84 |
|
85 MsgViewManager::~MsgViewManager() |
|
86 { |
|
87 // TODO Auto-generated destructor stub |
|
88 mEditorData.clear(); |
|
89 } |
|
90 |
|
91 void MsgViewManager::onBackAction() |
|
92 { |
|
93 switch (mCurrentView) { |
|
94 case MsgBaseView::CLV: |
|
95 { |
|
96 // if its viewer service then quit the application |
|
97 if (mViewServiceRequest) { |
|
98 HbApplication::quit(); |
|
99 break; |
|
100 } |
|
101 |
|
102 if (!mServiceRequest) { |
|
103 HbApplication::quit(); |
|
104 } |
|
105 else { |
|
106 completeServiceRequest(); |
|
107 } |
|
108 |
|
109 break; |
|
110 } |
|
111 |
|
112 case MsgBaseView::CV: |
|
113 { |
|
114 mConversationId = -1; //reset the conversation view id since its closed |
|
115 |
|
116 //Save content to drafts before switching to clv |
|
117 mConversationView->saveContentToDrafts(); |
|
118 |
|
119 //marking messages as red in CV. |
|
120 mConversationView->markMessagesAsRead(); |
|
121 |
|
122 // reset the conversation id published |
|
123 mConversationView->setPSCVId(false); |
|
124 |
|
125 //clearing content of cv. |
|
126 mConversationView->clearContent(); |
|
127 |
|
128 // if service request for veiwer the just switch to univiewer. |
|
129 if (mViewServiceRequest) { |
|
130 mCurrentView = MsgBaseView::UNIVIEWER; |
|
131 mMainWindow->setCurrentView(mUniViewer); |
|
132 break; |
|
133 } |
|
134 |
|
135 if (mServiceRequest) { |
|
136 completeServiceRequest(); |
|
137 } |
|
138 else { |
|
139 //switch to clv. |
|
140 QVariantList param; |
|
141 param << MsgBaseView::CLV; |
|
142 param << MsgBaseView::CV; |
|
143 switchView(param); |
|
144 } |
|
145 |
|
146 break; |
|
147 } |
|
148 |
|
149 case MsgBaseView::DLV: |
|
150 { |
|
151 if (mServiceRequest) { |
|
152 completeServiceRequest(); |
|
153 } |
|
154 else { |
|
155 //switch to clv. |
|
156 QVariantList param; |
|
157 param << MsgBaseView::CLV; |
|
158 param << MsgBaseView::DLV; |
|
159 switchView(param); |
|
160 } |
|
161 |
|
162 break; |
|
163 } |
|
164 |
|
165 case MsgBaseView::UNIEDITOR: |
|
166 { |
|
167 //Save content to drafts before switching to clv |
|
168 mUniEditor->saveContentToDrafts(); |
|
169 |
|
170 // if service request for veiwer the just switch to univiewer. |
|
171 if (mViewServiceRequest) { |
|
172 mCurrentView = MsgBaseView::UNIVIEWER; |
|
173 mMainWindow->setCurrentView(mUniViewer); |
|
174 break; |
|
175 } |
|
176 |
|
177 //switch to clv. |
|
178 if (mServiceRequest) { |
|
179 completeServiceRequest(); |
|
180 } |
|
181 else { |
|
182 //switch to previous view. |
|
183 QVariantList param; |
|
184 param << mPreviousView; |
|
185 param << MsgBaseView::UNIEDITOR; |
|
186 |
|
187 if(mPreviousView == MsgBaseView::CV) { |
|
188 param << mConversationId; |
|
189 } |
|
190 else if(mPreviousView == MsgBaseView::UNIVIEWER){ |
|
191 qint32 contactId = mViewerData.at(0).toLongLong(); |
|
192 qint32 messageId = mViewerData.at(1).toInt(); |
|
193 int msgCount = mViewerData.at(2).toInt(); |
|
194 |
|
195 param << contactId; |
|
196 param << messageId; |
|
197 param << msgCount; |
|
198 } |
|
199 else if(mPreviousView == MsgBaseView::UNIEDITOR){ |
|
200 //TODO: Remove error handling once Audio fetcher |
|
201 //becomes dialog |
|
202 param[0] = MsgBaseView::CLV; |
|
203 } |
|
204 |
|
205 switchView(param); |
|
206 } |
|
207 |
|
208 break; |
|
209 } |
|
210 |
|
211 case MsgBaseView::UNIVIEWER: |
|
212 { |
|
213 // if its launched via service request quit the app |
|
214 if (mViewServiceRequest) { |
|
215 HbApplication::quit(); |
|
216 } |
|
217 else { |
|
218 QVariantList param; |
|
219 if (mConversationId != -1) |
|
220 { |
|
221 //this means CV is till open then just open the fresh CV |
|
222 param << MsgBaseView::CV; |
|
223 param << MsgBaseView::UNIVIEWER; |
|
224 param << mConversationView->conversationId(); |
|
225 } |
|
226 else |
|
227 { |
|
228 param << MsgBaseView::CLV; |
|
229 param << MsgBaseView::UNIVIEWER; |
|
230 } |
|
231 switchView(param); |
|
232 |
|
233 } |
|
234 break; |
|
235 } |
|
236 case MsgBaseView::MSGSETTINGS: |
|
237 { |
|
238 QVariantList param; |
|
239 param << MsgBaseView::DEFAULT; |
|
240 param << MsgBaseView::MSGSETTINGS; |
|
241 switchView(param); |
|
242 break; |
|
243 } |
|
244 case MsgBaseView::AUDIOFETCHER: |
|
245 { |
|
246 // switch back to previous view |
|
247 QVariantList param; |
|
248 param << mPreviousView; |
|
249 param << MsgBaseView::AUDIOFETCHER; |
|
250 if(mPreviousView == MsgBaseView::CV) |
|
251 { |
|
252 param << mConversationId; |
|
253 } |
|
254 switchView(param); |
|
255 break; |
|
256 } |
|
257 default: |
|
258 { |
|
259 break; |
|
260 } |
|
261 } |
|
262 } |
|
263 |
|
264 void MsgViewManager::switchView(const QVariantList& data) |
|
265 { |
|
266 QCRITICAL_WRITE("MsgViewManager::switchView start."); |
|
267 |
|
268 int viewId = data.at(0).toInt(); |
|
269 |
|
270 switch (viewId) { |
|
271 case MsgBaseView::DEFAULT: |
|
272 { |
|
273 handleDefault(data); |
|
274 break; |
|
275 } |
|
276 case MsgBaseView::CLV: |
|
277 { |
|
278 switchToClv(data); |
|
279 break; |
|
280 } |
|
281 |
|
282 case MsgBaseView::CV: |
|
283 { |
|
284 switchToCv(data); |
|
285 break; |
|
286 } |
|
287 |
|
288 case MsgBaseView::DLV: |
|
289 { |
|
290 switchToDlv(data); |
|
291 break; |
|
292 } |
|
293 |
|
294 case MsgBaseView::UNIEDITOR: |
|
295 { |
|
296 switchToUniEditor(data); |
|
297 break; |
|
298 } |
|
299 |
|
300 case MsgBaseView::UNIVIEWER: |
|
301 { |
|
302 switchToUniViewer(data); |
|
303 break; |
|
304 } |
|
305 |
|
306 case MsgBaseView::MSGSETTINGS: |
|
307 { |
|
308 switchToMsgSettings(data); |
|
309 break; |
|
310 } |
|
311 case MsgBaseView::AUDIOFETCHER: |
|
312 { |
|
313 switchToAudioFetcher(data); |
|
314 break; |
|
315 } |
|
316 } |
|
317 QCRITICAL_WRITE("MsgViewManager::switchView end."); |
|
318 } |
|
319 |
|
320 void MsgViewManager::deletePreviousView() |
|
321 { |
|
322 while(mViewTobeDeleted.count()) |
|
323 { |
|
324 HbView* v = mViewTobeDeleted.takeAt(0); |
|
325 mMainWindow->removeView(v); |
|
326 delete v; |
|
327 } |
|
328 } |
|
329 |
|
330 |
|
331 void MsgViewManager::send(const qint32 contactId, const QString phoneNumber, |
|
332 const QString displayName) |
|
333 { |
|
334 qint64 conversationId = ConversationsEngine::instance()-> getConversationIdFromContactId( |
|
335 contactId); |
|
336 |
|
337 //set mode to viewer, if conversations found else send mode. |
|
338 QVariantList param; |
|
339 if (conversationId > 0) { |
|
340 param << MsgBaseView::CV; |
|
341 param << MsgBaseView::SERVICE; |
|
342 param << conversationId; |
|
343 } |
|
344 else { |
|
345 ConvergedMessage message; |
|
346 ConvergedMessageAddress address; |
|
347 address.setAddress(phoneNumber); |
|
348 address.setAlias(displayName); |
|
349 message.addToRecipient(address); |
|
350 |
|
351 QByteArray dataArray; |
|
352 QDataStream messageStream(&dataArray, QIODevice::WriteOnly | QIODevice::Append); |
|
353 message.serialize(messageStream); |
|
354 |
|
355 param << MsgBaseView::UNIEDITOR; |
|
356 param << MsgBaseView::SERVICE; |
|
357 param << dataArray; |
|
358 } |
|
359 switchView(param); |
|
360 XQServiceUtil::toBackground(false); |
|
361 } |
|
362 |
|
363 void MsgViewManager::send(const QString phoneNumber, const QString alias, const QString bodyText) |
|
364 { |
|
365 ConvergedMessage message; |
|
366 ConvergedMessageAddress address; |
|
367 address.setAddress(phoneNumber); |
|
368 address.setAlias(alias); |
|
369 message.addToRecipient(address); |
|
370 message.setBodyText(bodyText); |
|
371 |
|
372 QVariantList param; |
|
373 QByteArray dataArray; |
|
374 QDataStream messageStream(&dataArray, QIODevice::WriteOnly | QIODevice::Append); |
|
375 message.serialize(messageStream); |
|
376 |
|
377 param << MsgBaseView::UNIEDITOR; |
|
378 param << MsgBaseView::SERVICE; |
|
379 param << dataArray; |
|
380 |
|
381 switchView(param); |
|
382 XQServiceUtil::toBackground(false); |
|
383 } |
|
384 |
|
385 void MsgViewManager::setServiceRequest(bool request) |
|
386 { |
|
387 mServiceRequest = request; |
|
388 mViewAtServiceRequest = mCurrentView; |
|
389 } |
|
390 |
|
391 void MsgViewManager::switchToLastSavedView() |
|
392 { |
|
393 QVariantList param; |
|
394 |
|
395 switch (mViewAtServiceRequest) { |
|
396 case MsgBaseView::CV: |
|
397 { |
|
398 param << MsgBaseView::CV; |
|
399 param << MsgBaseView::SERVICE; |
|
400 param << mConversationId; |
|
401 break; |
|
402 } |
|
403 case MsgBaseView::UNIVIEWER: |
|
404 { |
|
405 param << MsgBaseView::UNIVIEWER; |
|
406 param << MsgBaseView::SERVICE; |
|
407 break; |
|
408 } |
|
409 default: |
|
410 { |
|
411 param << MsgBaseView::CLV; |
|
412 param << MsgBaseView::SERVICE; |
|
413 break; |
|
414 } |
|
415 } |
|
416 switchView(param); |
|
417 } |
|
418 |
|
419 void MsgViewManager::open(qint64 conversationId) |
|
420 { |
|
421 QVariantList param; |
|
422 |
|
423 if (conversationId < 0) { |
|
424 param << MsgBaseView::CLV; |
|
425 param << MsgBaseView::SERVICE; |
|
426 |
|
427 if( mCurrentView == MsgBaseView::CV && mConversationView) |
|
428 { |
|
429 mConversationView->setPSCVId(false); |
|
430 } |
|
431 } |
|
432 else { |
|
433 param << MsgBaseView::CV; |
|
434 param << MsgBaseView::SERVICE; |
|
435 param << conversationId; |
|
436 } |
|
437 |
|
438 switchView(param); |
|
439 XQServiceUtil::toBackground(false); |
|
440 } |
|
441 |
|
442 void MsgViewManager::send(QVariant data) |
|
443 { |
|
444 ConvergedMessage message; |
|
445 ConvergedMessageAttachmentList attachmentList; |
|
446 // handle multiple files from sendUI |
|
447 // e.g. contacts can send multiple vcards |
|
448 QStringList receivedFiles = data.toStringList(); |
|
449 int recFileCount = receivedFiles.count(); |
|
450 for (int i = 0; i < recFileCount; i++) { |
|
451 ConvergedMessageAttachment *attachment = |
|
452 new ConvergedMessageAttachment(receivedFiles.at(i)); |
|
453 attachmentList.append(attachment); |
|
454 } |
|
455 message.addAttachments(attachmentList); |
|
456 |
|
457 QByteArray dataArray; |
|
458 QDataStream messageStream(&dataArray, QIODevice::WriteOnly | QIODevice::Append); |
|
459 message.serialize(messageStream); |
|
460 |
|
461 QVariantList param; |
|
462 param << MsgBaseView::UNIEDITOR; |
|
463 param << MsgBaseView::SERVICE; |
|
464 param << dataArray; |
|
465 |
|
466 switchView(param); |
|
467 XQServiceUtil::toBackground(false); |
|
468 } |
|
469 |
|
470 qint64 MsgViewManager::findConversationId(const QString phoneNum) |
|
471 { |
|
472 return ConversationsEngine::instance()-> getConversationIdFromAddress(phoneNum); |
|
473 } |
|
474 |
|
475 //will be depricated in future. |
|
476 void MsgViewManager::openEditor(QString phoneNumber, QString name) |
|
477 { |
|
478 ConvergedMessage message; |
|
479 ConvergedMessageAddress address; |
|
480 address.setAddress(phoneNumber); |
|
481 address.setAlias(name); |
|
482 message.addToRecipient(address); |
|
483 |
|
484 QByteArray dataArray; |
|
485 QDataStream messageStream(&dataArray, QIODevice::WriteOnly | QIODevice::Append); |
|
486 message.serialize(messageStream); |
|
487 |
|
488 QVariantList param; |
|
489 param << MsgBaseView::UNIEDITOR; |
|
490 param << MsgBaseView::SERVICE; |
|
491 param << dataArray; |
|
492 |
|
493 switchView(param); |
|
494 XQServiceUtil::toBackground(false); |
|
495 } |
|
496 |
|
497 void MsgViewManager::completeServiceRequest() |
|
498 { |
|
499 mServiceRequest = false; |
|
500 XQServiceUtil::toBackground(true); |
|
501 switchToLastSavedView(); |
|
502 } |
|
503 |
|
504 void MsgViewManager::switchToClv(const QVariantList& data) |
|
505 { |
|
506 mPreviousView = data.at(1).toInt(); |
|
507 |
|
508 // delete case from viewer service |
|
509 if (mViewServiceRequest && (mPreviousView == MsgBaseView::UNIVIEWER)) { |
|
510 // quit the application |
|
511 HbApplication::quit(); |
|
512 } |
|
513 |
|
514 // this is the case when viewer/editor is opened and contacts update takes |
|
515 // place resulting in CV close, the view should directly come to CLV |
|
516 // bypassing the CV |
|
517 if ((mCurrentView == MsgBaseView::UNIVIEWER |
|
518 && mPreviousView != MsgBaseView::UNIVIEWER) |
|
519 || (mCurrentView == MsgBaseView::UNIEDITOR |
|
520 && mPreviousView != MsgBaseView::UNIEDITOR)) |
|
521 { |
|
522 //dont do anything |
|
523 //wait for the back from viewer/editor |
|
524 //and reset the open CV id |
|
525 mConversationId = -1; |
|
526 return; |
|
527 } |
|
528 |
|
529 //delete UniEditor |
|
530 if (mUniEditor) |
|
531 { |
|
532 appendViewToBeDeleted(mUniEditor); |
|
533 mUniEditor = NULL; |
|
534 } |
|
535 |
|
536 //delete UniViewer |
|
537 if (mUniViewer) |
|
538 { |
|
539 appendViewToBeDeleted(mUniViewer); |
|
540 mUniViewer = NULL; |
|
541 } |
|
542 |
|
543 if (mConversationView) { |
|
544 mConversationView->saveContentToDrafts(); |
|
545 //clearing content of cv. |
|
546 mConversationView->clearContent(); |
|
547 //reset the open CV id |
|
548 mConversationId = -1; |
|
549 } |
|
550 |
|
551 //switch to CLV. |
|
552 mCurrentView = MsgBaseView::CLV; |
|
553 if (!mListView) { |
|
554 mListView = new MsgListView(); |
|
555 mListView->setNavigationAction(mBackAction); |
|
556 connect(mListView, SIGNAL(switchView(const QVariantList&)), this, |
|
557 SLOT(switchView(const QVariantList&))); |
|
558 mMainWindow->addView(mListView); |
|
559 } |
|
560 |
|
561 mMainWindow->setCurrentView(mListView,true,Hb::ViewSwitchSequential); |
|
562 } |
|
563 |
|
564 void MsgViewManager::switchToCv(const QVariantList& data) |
|
565 { |
|
566 QCRITICAL_WRITE("MsgViewManager::switchToCv start."); |
|
567 |
|
568 //switch to CV. |
|
569 mCurrentView = MsgBaseView::CV; |
|
570 mPreviousView = data.at(1).toInt(); |
|
571 |
|
572 // delete case from viewer service |
|
573 if (mViewServiceRequest && (mPreviousView == MsgBaseView::UNIVIEWER)) { |
|
574 // quit the application |
|
575 HbApplication::quit(); |
|
576 } |
|
577 |
|
578 // delete Audio Fetcher view |
|
579 if(mAudioFetcherView) |
|
580 { |
|
581 appendViewToBeDeleted(mAudioFetcherView); |
|
582 mAudioFetcherView = NULL; |
|
583 } |
|
584 |
|
585 //delete UniEditor |
|
586 if (mUniEditor) |
|
587 { |
|
588 // Save to drafts if CV is launched via service |
|
589 if (mPreviousView == MsgBaseView::SERVICE) { |
|
590 mUniEditor->saveContentToDrafts(); |
|
591 } |
|
592 appendViewToBeDeleted(mUniEditor); |
|
593 mUniEditor = NULL; |
|
594 } |
|
595 |
|
596 //delete UniViewer |
|
597 if (mUniViewer) |
|
598 { |
|
599 appendViewToBeDeleted(mUniViewer); |
|
600 mUniViewer = NULL; |
|
601 } |
|
602 |
|
603 QVariant var = data.at(2); |
|
604 qint64 conversationId; |
|
605 if (var.type() == QVariant::String) { |
|
606 QString phoneNumber = var.toString(); |
|
607 qint32 contactId = findContactId(phoneNumber); |
|
608 if (contactId != -1) { |
|
609 conversationId = ConversationsEngine::instance()->getConversationIdFromContactId(contactId); |
|
610 } |
|
611 else { |
|
612 conversationId = findConversationId(phoneNumber); |
|
613 } |
|
614 |
|
615 if (conversationId == NULL_CONVERSATIONID) { |
|
616 QVariantList param; |
|
617 param << MsgBaseView::CLV; |
|
618 param << MsgBaseView::CV; |
|
619 |
|
620 if( mCurrentView == MsgBaseView::CV && mConversationView){ |
|
621 mConversationView->setPSCVId(false); |
|
622 } |
|
623 |
|
624 switchView(param); |
|
625 return; |
|
626 } |
|
627 } |
|
628 else if (var.type() == QVariant::Invalid) { |
|
629 // this case comes when a message is deleted from |
|
630 // Unified viewer set curent view as conversation view |
|
631 // and return |
|
632 mMainWindow->setCurrentView(mConversationView,true,Hb::ViewSwitchSequential); |
|
633 |
|
634 // publish already opened conversation's id |
|
635 mConversationView->setPSCVId(true); |
|
636 return; |
|
637 } |
|
638 else { |
|
639 conversationId = var.toLongLong(); |
|
640 } |
|
641 //switch to CV. |
|
642 mConversationId = conversationId; |
|
643 |
|
644 if (!mConversationView) { |
|
645 mConversationView = new MsgConversationBaseView(); |
|
646 mConversationView->setNavigationAction(mBackAction); |
|
647 connect(mConversationView, SIGNAL(switchView(const QVariantList&)), this, |
|
648 SLOT(switchView(const QVariantList&))); |
|
649 |
|
650 mMainWindow->addView(mConversationView); |
|
651 } |
|
652 else if (mConversationView->conversationId() != mConversationId){ |
|
653 //Save content to drafts before switching to different CV |
|
654 mConversationView->saveContentToDrafts(); |
|
655 //clearing content of current cv. |
|
656 mConversationView->clearContent(); |
|
657 } |
|
658 |
|
659 mConversationView->openConversation(conversationId); |
|
660 mMainWindow->setCurrentView(mConversationView,true,Hb::ViewSwitchSequential); |
|
661 |
|
662 QCRITICAL_WRITE("MsgViewManager::switchToCv end."); |
|
663 } |
|
664 |
|
665 void MsgViewManager::switchToDlv(const QVariantList& data) |
|
666 { |
|
667 //delete UniEditor |
|
668 if (mUniEditor) |
|
669 { |
|
670 appendViewToBeDeleted(mUniEditor); |
|
671 mUniEditor = NULL; |
|
672 } |
|
673 |
|
674 //switch to DLV. |
|
675 mCurrentView = MsgBaseView::DLV; |
|
676 mPreviousView = data.at(1).toInt(); |
|
677 |
|
678 if (!mDraftsListView) { |
|
679 mDraftsListView = new DraftsListView(); |
|
680 mDraftsListView->setNavigationAction(mBackAction); |
|
681 connect(mDraftsListView, SIGNAL(switchView(const QVariantList&)), this, |
|
682 SLOT(switchView(const QVariantList&))); |
|
683 |
|
684 mMainWindow->addView(mDraftsListView); |
|
685 } |
|
686 mMainWindow->setCurrentView(mDraftsListView,true,Hb::ViewSwitchSequential); |
|
687 } |
|
688 |
|
689 void MsgViewManager::switchToUniEditor(const QVariantList& data) |
|
690 { |
|
691 QCRITICAL_WRITE("MsgViewManager::switchToUniEditor start."); |
|
692 |
|
693 /** |
|
694 * Editor is tried to open again before exiting the previously |
|
695 * opened editor. Multi taping in DLV or Forward. |
|
696 */ |
|
697 if (mUniEditor && !mAudioFetcherView) |
|
698 { |
|
699 return; |
|
700 } |
|
701 |
|
702 mCurrentView = MsgBaseView::UNIEDITOR; |
|
703 if(MsgBaseView::AUDIOFETCHER != data.at(1).toInt()) |
|
704 { |
|
705 mPreviousView = data.at(1).toInt(); |
|
706 } |
|
707 |
|
708 // delete Audio Fetcher view |
|
709 if(mAudioFetcherView) |
|
710 { |
|
711 appendViewToBeDeleted(mAudioFetcherView); |
|
712 mAudioFetcherView = NULL; |
|
713 } |
|
714 |
|
715 // delete UniViewer |
|
716 if (mUniViewer ) |
|
717 { |
|
718 appendViewToBeDeleted(mUniViewer); |
|
719 mUniViewer = NULL; |
|
720 } |
|
721 |
|
722 if (mConversationView) |
|
723 { |
|
724 //clearing content of cv. |
|
725 mConversationView->clearContent(); |
|
726 } |
|
727 |
|
728 // reset conversation id published |
|
729 if(mPreviousView == MsgBaseView::CV && mConversationView) |
|
730 { |
|
731 mConversationView->setPSCVId(false); |
|
732 } |
|
733 |
|
734 //swich to unieditor. |
|
735 if (!mUniEditor) { |
|
736 mUniEditor = new MsgUnifiedEditorView(); |
|
737 mMainWindow->addView(mUniEditor); |
|
738 mUniEditor->setNavigationAction(mBackAction); |
|
739 connect(mUniEditor, SIGNAL(switchView(const QVariantList&)), this, |
|
740 SLOT(switchView(const QVariantList&))); |
|
741 } |
|
742 |
|
743 // check if additional data for unieditor's consumption is available |
|
744 if (data.length() > 2) { |
|
745 QVariantList editorData; |
|
746 // i=2 because view manager consumed first two args |
|
747 for (int i = 2; i < data.length(); i++) { |
|
748 editorData << data.at(i); |
|
749 } |
|
750 |
|
751 if (MsgBaseView::DLV == mPreviousView) { |
|
752 //Populate editor after view ready indication |
|
753 populateUniEditorAfterViewReady(editorData); |
|
754 } |
|
755 else { |
|
756 mUniEditor->populateContent(editorData); |
|
757 } |
|
758 } |
|
759 |
|
760 mMainWindow->setCurrentView(mUniEditor,true,Hb::ViewSwitchSequential); |
|
761 |
|
762 QCRITICAL_WRITE("MsgViewManager::switchToUniEditor end."); |
|
763 } |
|
764 |
|
765 void MsgViewManager::switchToUniViewer(const QVariantList& data) |
|
766 { |
|
767 /** |
|
768 * Viewer is tried to open again before exiting the previously |
|
769 * opened viewer. Multi taping bubbles in CV. |
|
770 */ |
|
771 if (mUniViewer) { |
|
772 return; |
|
773 } |
|
774 |
|
775 if (mUniEditor) |
|
776 { |
|
777 appendViewToBeDeleted(mUniEditor); |
|
778 mUniEditor = NULL; |
|
779 } |
|
780 |
|
781 //Clear the old viewer data |
|
782 mViewerData.clear(); |
|
783 |
|
784 mCurrentView = MsgBaseView::UNIVIEWER; |
|
785 mPreviousView = data.at(1).toInt(); |
|
786 |
|
787 //switch to univiewer. |
|
788 if (data.length() > 2) { |
|
789 qint32 contactId = data.at(2).toLongLong(); |
|
790 qint32 messageId = data.at(3).toInt(); |
|
791 int msgCount = data.at(4).toInt(); |
|
792 |
|
793 //Save the viewer data to be used when u come back from Editor |
|
794 mViewerData << contactId; |
|
795 mViewerData << messageId; |
|
796 mViewerData << msgCount; |
|
797 |
|
798 if (!mUniViewer) { |
|
799 mUniViewer = new UnifiedViewer(messageId); |
|
800 mUniViewer->setNavigationAction(mBackAction); |
|
801 mMainWindow->addView(mUniViewer); |
|
802 connect(mUniViewer, SIGNAL(switchView(const QVariantList&)), this, |
|
803 SLOT(switchView(const QVariantList&))); |
|
804 } |
|
805 mUniViewer->populateContent(messageId, true, msgCount); |
|
806 } |
|
807 |
|
808 if(mPreviousView==MsgBaseView::CV && mConversationView) |
|
809 { |
|
810 mConversationView->setPSCVId(false); |
|
811 } |
|
812 |
|
813 mMainWindow->setCurrentView(mUniViewer,true,Hb::ViewSwitchSequential); |
|
814 } |
|
815 void MsgViewManager::switchToMsgSettings(const QVariantList& data) |
|
816 { |
|
817 int previousView = data.at(1).toInt(); |
|
818 |
|
819 MsgSettingsView::SettingsView view = MsgSettingsView::DefaultView; |
|
820 if (previousView == MsgBaseView::UNIEDITOR || previousView |
|
821 == MsgBaseView::CV) |
|
822 { |
|
823 view = (MsgSettingsView::SettingsView)data.at(2).toInt(); |
|
824 } |
|
825 |
|
826 //launch settings service |
|
827 QList<QVariant> args; |
|
828 QString serviceName("messagesettings"); |
|
829 QString interfaceName("com.nokia.symbian.IMessageSettings"); |
|
830 QString operation("launchSettings(int)"); |
|
831 XQAiwRequest* request; |
|
832 XQApplicationManager appManager; |
|
833 request = appManager.create(serviceName, interfaceName, operation, true); //embedded |
|
834 if ( request == NULL ) |
|
835 { |
|
836 return; |
|
837 } |
|
838 |
|
839 args << view; |
|
840 |
|
841 request->setArguments(args); |
|
842 |
|
843 if(previousView==MsgBaseView::CV && mConversationView){ |
|
844 mConversationView->setPSCVId(false); |
|
845 } |
|
846 |
|
847 if(!request->send()) |
|
848 { |
|
849 QDEBUG_WRITE("launchSettings failed") |
|
850 } |
|
851 delete request; |
|
852 |
|
853 |
|
854 if(previousView==MsgBaseView::CV && mConversationView){ |
|
855 mConversationView->setPSCVId(true); |
|
856 } |
|
857 } |
|
858 |
|
859 void MsgViewManager::handleDefault(const QVariantList& data) |
|
860 { |
|
861 //special handling incase we switch from settings-view |
|
862 int previousViewId = data.at(1).toInt(); |
|
863 if (MsgBaseView::MSGSETTINGS == previousViewId) { |
|
864 //switch to view, where from settings view was launched |
|
865 mCurrentView = mPreviousView; |
|
866 mPreviousView = previousViewId; |
|
867 //remove the settings view from main window |
|
868 if (mSettingsView) |
|
869 { |
|
870 appendViewToBeDeleted(mSettingsView); |
|
871 mSettingsView = NULL; |
|
872 } |
|
873 switch (mCurrentView) { |
|
874 case MsgBaseView::CLV: |
|
875 { |
|
876 if (mListView) |
|
877 mMainWindow->setCurrentView(mListView,true,Hb::ViewSwitchSequential); |
|
878 break; |
|
879 } |
|
880 case MsgBaseView::CV: |
|
881 { |
|
882 if (mConversationView) |
|
883 mMainWindow->setCurrentView(mConversationView,true,Hb::ViewSwitchSequential); |
|
884 break; |
|
885 } |
|
886 case MsgBaseView::DLV: |
|
887 { |
|
888 if (mDraftsListView) |
|
889 mMainWindow->setCurrentView(mDraftsListView,true,Hb::ViewSwitchSequential); |
|
890 break; |
|
891 } |
|
892 case MsgBaseView::UNIEDITOR: |
|
893 { |
|
894 if (mServiceRequest) { |
|
895 mMainWindow->setCurrentView(mUniEditor,true,Hb::ViewSwitchSequential); |
|
896 } |
|
897 else { |
|
898 mMainWindow->setCurrentView(mUniEditor,true,Hb::ViewSwitchSequential); |
|
899 } |
|
900 break; |
|
901 } |
|
902 } |
|
903 } |
|
904 } |
|
905 |
|
906 void MsgViewManager::view(int msgId) |
|
907 { |
|
908 int msgType; |
|
909 int msgSubType; |
|
910 mMessageId = msgId; |
|
911 qint32 messageId(msgId); |
|
912 ConversationsEngine::instance()->markAsReadAndGetType(messageId, msgType, msgSubType); |
|
913 |
|
914 switch (msgType) { |
|
915 case ConvergedMessage::Sms: |
|
916 case ConvergedMessage::Mms: |
|
917 case ConvergedMessage::MmsNotification: |
|
918 { |
|
919 handleSmsMmsMsg(msgId); |
|
920 break; |
|
921 } |
|
922 case ConvergedMessage::BioMsg: |
|
923 { |
|
924 if (msgSubType == ConvergedMessage::RingingTone) { |
|
925 handleRingtoneMsg(msgId); |
|
926 |
|
927 } |
|
928 else if (msgSubType == ConvergedMessage::Provisioning) { |
|
929 handleProvisoningMsg(msgId); |
|
930 } |
|
931 break; |
|
932 } |
|
933 case ConvergedMessage::BT: |
|
934 { |
|
935 break; |
|
936 } |
|
937 default: |
|
938 { |
|
939 // for un supported message show delete option |
|
940 HbMessageBox::question(LOC_DELETE_MESSAGE,this, |
|
941 SLOT(onDialogDeleteMsg(HbAction*)), |
|
942 HbMessageBox::Delete | HbMessageBox::Cancel); |
|
943 break; |
|
944 } |
|
945 } |
|
946 } |
|
947 |
|
948 // ---------------------------------------------------------------------------- |
|
949 // MsgViewManager::handleSmsMmsMsg |
|
950 // @see header |
|
951 // ---------------------------------------------------------------------------- |
|
952 void MsgViewManager::handleSmsMmsMsg(int msgId) |
|
953 { |
|
954 mViewServiceRequest = true; |
|
955 |
|
956 mCurrentView = MsgBaseView::UNIVIEWER; |
|
957 |
|
958 if (!mUniViewer) { |
|
959 mUniViewer = new UnifiedViewer(msgId); |
|
960 mUniViewer->setNavigationAction(mBackAction); |
|
961 mMainWindow->addView(mUniViewer); |
|
962 connect(mUniViewer, SIGNAL(switchView(const QVariantList&)), this, |
|
963 SLOT(switchView(const QVariantList&))); |
|
964 } |
|
965 mUniViewer->populateContent(msgId, true, -1); |
|
966 |
|
967 mMainWindow->setCurrentView(mUniViewer,true,Hb::ViewSwitchSequential); |
|
968 } |
|
969 |
|
970 // ---------------------------------------------------------------------------- |
|
971 // MsgViewManager::handleRingtoneMsg |
|
972 // @see header |
|
973 // ---------------------------------------------------------------------------- |
|
974 void MsgViewManager::handleRingtoneMsg(int msgId) |
|
975 { |
|
976 mMessageId = msgId; |
|
977 HbMessageBox::question(LOC_DIALOG_SAVE_RINGTONE, this, |
|
978 SLOT(onDialogSaveTone(HbAction*)), |
|
979 HbMessageBox::Save | HbMessageBox::Cancel); |
|
980 } |
|
981 |
|
982 // ---------------------------------------------------------------------------- |
|
983 // MsgViewManager::handleProvisoningMsg |
|
984 // @see header |
|
985 // ---------------------------------------------------------------------------- |
|
986 void MsgViewManager::handleProvisoningMsg(int msgId) |
|
987 { |
|
988 QString messageId; |
|
989 messageId.setNum(msgId); |
|
990 |
|
991 XQApplicationManager* aiwMgr = new XQApplicationManager(); |
|
992 |
|
993 XQAiwRequest* request = aiwMgr->create("com.nokia.services.MDM", "Provisioning", |
|
994 "ProcessMessage(QString)", true); // embedded |
|
995 |
|
996 if (request) { |
|
997 QList<QVariant> args; |
|
998 args << QVariant(messageId); |
|
999 request->setArguments(args); |
|
1000 |
|
1001 // Send the request |
|
1002 bool res = request->send(); |
|
1003 |
|
1004 // Cleanup |
|
1005 delete request; |
|
1006 } |
|
1007 |
|
1008 delete aiwMgr; |
|
1009 |
|
1010 // close the application once its handled |
|
1011 HbApplication::quit(); |
|
1012 } |
|
1013 |
|
1014 void MsgViewManager::setViewInteractive() |
|
1015 { |
|
1016 if(!mMainWindow->isInteractive()) |
|
1017 { |
|
1018 mMainWindow->setInteractive(true); |
|
1019 } |
|
1020 |
|
1021 disconnect(mMainWindow, SIGNAL(viewReady()),this,SLOT(setViewInteractive())); |
|
1022 } |
|
1023 |
|
1024 void MsgViewManager::appendViewToBeDeleted(HbView* view) |
|
1025 { |
|
1026 if (view) |
|
1027 { |
|
1028 mViewTobeDeleted << view; |
|
1029 connect(mMainWindow, SIGNAL(viewReady()), this, SLOT(deletePreviousView()), Qt::UniqueConnection); |
|
1030 } |
|
1031 } |
|
1032 |
|
1033 // ---------------------------------------------------------------------------- |
|
1034 // MsgViewManager::populateEditorAfterViewReady |
|
1035 // @see header |
|
1036 // ---------------------------------------------------------------------------- |
|
1037 void MsgViewManager::populateUniEditorAfterViewReady(const QVariantList& editorData) |
|
1038 { |
|
1039 QCRITICAL_WRITE("MsgViewManager::populateUniEditorAfterViewReady start."); |
|
1040 //Save the editor data and use it in ViewReady handler |
|
1041 mEditorData = editorData; |
|
1042 connect(mMainWindow, SIGNAL(viewReady()), this, SLOT(populateUniEditorView())); |
|
1043 QCRITICAL_WRITE("MsgViewManager::populateUniEditorAfterViewReady end."); |
|
1044 } |
|
1045 |
|
1046 // ---------------------------------------------------------------------------- |
|
1047 // MsgViewManager::populateUniEditorView |
|
1048 // @see header |
|
1049 // ---------------------------------------------------------------------------- |
|
1050 void MsgViewManager::populateUniEditorView() |
|
1051 { |
|
1052 QCRITICAL_WRITE("MsgViewManager::populateUniEditorView start."); |
|
1053 if (mUniEditor) |
|
1054 { |
|
1055 mUniEditor->openDraftsMessage(mEditorData); |
|
1056 } |
|
1057 mEditorData.clear(); |
|
1058 |
|
1059 disconnect(mMainWindow, SIGNAL(viewReady()), this, |
|
1060 SLOT(populateUniEditorView())); |
|
1061 QCRITICAL_WRITE("MsgViewManager::populateUniEditorView end."); |
|
1062 } |
|
1063 |
|
1064 // ---------------------------------------------------------------------------- |
|
1065 // MsgViewManager::onDialogDeleteMsg |
|
1066 // @see header |
|
1067 // ---------------------------------------------------------------------------- |
|
1068 void MsgViewManager::onDialogDeleteMsg(HbAction* action) |
|
1069 { |
|
1070 HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender()); |
|
1071 if (action == dlg->actions().at(0)) { |
|
1072 QList<int> msgIdList; |
|
1073 msgIdList << mMessageId; |
|
1074 ConversationsEngine::instance()->deleteMessages(msgIdList); |
|
1075 } |
|
1076 HbApplication::quit(); // exit after handling |
|
1077 } |
|
1078 |
|
1079 // ---------------------------------------------------------------------------- |
|
1080 // MsgViewManager::onDialogSaveTone |
|
1081 // @see header |
|
1082 // ---------------------------------------------------------------------------- |
|
1083 void MsgViewManager::onDialogSaveTone(HbAction* action) |
|
1084 { |
|
1085 HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender()); |
|
1086 if (action == dlg->actions().at(0)) { |
|
1087 UniDataModelLoader* pluginLoader = new UniDataModelLoader(); |
|
1088 UniDataModelPluginInterface* pluginInterface = pluginLoader->getDataModelPlugin( |
|
1089 ConvergedMessage::BioMsg); |
|
1090 pluginInterface->setMessageId(mMessageId); |
|
1091 UniMessageInfoList attachments = pluginInterface->attachmentList(); |
|
1092 |
|
1093 QString attachmentPath = attachments.at(0)->path(); |
|
1094 |
|
1095 RingBc* ringBc = new RingBc(); |
|
1096 ringBc->saveTone(attachmentPath); |
|
1097 |
|
1098 // clear attachement list : its allocated at data model |
|
1099 while (!attachments.isEmpty()) { |
|
1100 delete attachments.takeFirst(); |
|
1101 } |
|
1102 |
|
1103 delete ringBc; |
|
1104 delete pluginLoader; |
|
1105 } |
|
1106 |
|
1107 // close the application once its handled |
|
1108 HbApplication::quit(); |
|
1109 } |
|
1110 |
|
1111 // ---------------------------------------------------------------------------- |
|
1112 // MsgViewManager::currentView |
|
1113 // @see header |
|
1114 // ---------------------------------------------------------------------------- |
|
1115 int MsgViewManager::currentView() |
|
1116 { |
|
1117 return mCurrentView; |
|
1118 } |
|
1119 |
|
1120 // ---------------------------------------------------------------------------- |
|
1121 // MsgViewManager::switchToAudioFetcher |
|
1122 // @see header |
|
1123 // ---------------------------------------------------------------------------- |
|
1124 void MsgViewManager::switchToAudioFetcher(const QVariantList& data) |
|
1125 { |
|
1126 /** |
|
1127 * Audio Fetcher is tried to open again |
|
1128 */ |
|
1129 if(mAudioFetcherView) |
|
1130 { |
|
1131 return; |
|
1132 } |
|
1133 |
|
1134 //switch to Audio Fetcher view |
|
1135 mCurrentView = MsgBaseView::AUDIOFETCHER; |
|
1136 mPreviousView = data.at(1).toInt(); |
|
1137 QVariantList editorData; |
|
1138 // i=2 because view manager consumed first two args |
|
1139 for (int i = 2; i < data.length(); i++) { |
|
1140 editorData << data.at(i); |
|
1141 } |
|
1142 mAudioFetcherView = new MsgAudioFetcherView(editorData); |
|
1143 mAudioFetcherView->setNavigationAction(mBackAction); |
|
1144 connect(mAudioFetcherView, SIGNAL(switchView(const QVariantList&)), this, |
|
1145 SLOT(switchView(const QVariantList&))); |
|
1146 |
|
1147 if(mPreviousView==MsgBaseView::CV && mConversationView) |
|
1148 { |
|
1149 mConversationView->setPSCVId(false); |
|
1150 } |
|
1151 |
|
1152 mMainWindow->addView(mAudioFetcherView); |
|
1153 mMainWindow->setCurrentView(mAudioFetcherView,true,Hb::ViewSwitchSequential); |
|
1154 } |
|
1155 |
|
1156 // ---------------------------------------------------------------------------- |
|
1157 // MsgViewManager::saveContentToDraft |
|
1158 // @see header |
|
1159 // ---------------------------------------------------------------------------- |
|
1160 int MsgViewManager::saveContentToDraft() |
|
1161 { |
|
1162 int msgId = NULL_CONVERSATIONID; |
|
1163 if( mCurrentView == MsgBaseView::CV ) |
|
1164 { |
|
1165 msgId = mConversationView->saveContentToDrafts(); |
|
1166 } |
|
1167 else if( mCurrentView ==MsgBaseView::UNIEDITOR) |
|
1168 { |
|
1169 msgId = mUniEditor->saveContentToDrafts(); |
|
1170 } |
|
1171 return msgId; |
|
1172 } |
|
1173 |
|
1174 // ---------------------------------------------------------------------------- |
|
1175 // MsgViewManager::saveContentToDraft |
|
1176 // @see header |
|
1177 // ---------------------------------------------------------------------------- |
|
1178 void MsgViewManager::openUniEditorActivity(int activityMsgId) |
|
1179 { |
|
1180 int msgType; |
|
1181 int msgSubType; |
|
1182 |
|
1183 qint32 messageId(activityMsgId); |
|
1184 // get the message type |
|
1185 ConversationsEngine::instance()->markAsReadAndGetType(messageId, msgType, msgSubType); |
|
1186 |
|
1187 if (!mUniEditor) { |
|
1188 mUniEditor = new MsgUnifiedEditorView(); |
|
1189 mMainWindow->addView(mUniEditor); |
|
1190 mUniEditor->setNavigationAction(mBackAction); |
|
1191 connect(mUniEditor, SIGNAL(switchView(const QVariantList&)), this, |
|
1192 SLOT(switchView(const QVariantList&))); |
|
1193 } |
|
1194 |
|
1195 // buffer data to open the draft message |
|
1196 ConvergedMessageId convergedMsgId(activityMsgId); |
|
1197 ConvergedMessage message; |
|
1198 message.setMessageType((ConvergedMessage::MessageType) msgType); |
|
1199 message.setMessageId(convergedMsgId); |
|
1200 |
|
1201 // Launch uni-editor view |
|
1202 QByteArray dataArray; |
|
1203 QDataStream messageStream(&dataArray, QIODevice::WriteOnly | QIODevice::Append); |
|
1204 message.serialize(messageStream); |
|
1205 |
|
1206 QVariantList editorData; |
|
1207 editorData << dataArray; |
|
1208 mUniEditor->openDraftsMessage(editorData); |
|
1209 |
|
1210 // set the current view |
|
1211 mCurrentView = MsgBaseView::UNIEDITOR; |
|
1212 mPreviousView =MsgBaseView::CLV; |
|
1213 mMainWindow->setCurrentView(mUniEditor,true,Hb::ViewSwitchSequential); |
|
1214 } |
|
1215 |
|
1216 // ---------------------------------------------------------------------------- |
|
1217 // MsgViewManager::findContactId |
|
1218 // @see header |
|
1219 // ---------------------------------------------------------------------------- |
|
1220 qint32 MsgViewManager::findContactId(QString address) |
|
1221 { |
|
1222 QString displayLabel; |
|
1223 int count; |
|
1224 int localId = |
|
1225 MsgContactHandler::resolveContactDisplayName(address, |
|
1226 displayLabel, |
|
1227 count); |
|
1228 |
|
1229 return localId; |
|
1230 } |
|
1231 |
|
1232 //EOF |