|
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:Conversation (chat) view for messaging application. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "msgconversationview.h" |
|
19 |
|
20 // SYSTEM INCLUDES |
|
21 #include <HbMenu> |
|
22 #include <HbAction> |
|
23 #include <HbInstance> |
|
24 #include <HbApplication> |
|
25 #include <HbDialog> |
|
26 #include <HbLabel> |
|
27 #include <HbWidget> |
|
28 #include <HbListView> |
|
29 #include <hbmessagebox.h> |
|
30 #include <hbnotificationdialog.h> |
|
31 #include <HbEffect> |
|
32 |
|
33 #include <QDir> |
|
34 #include <QLibraryInfo> |
|
35 #include <QPluginLoader> |
|
36 #include <QDateTime> |
|
37 #include <QGraphicsLinearLayout> |
|
38 #include <QStandardItemModel> |
|
39 |
|
40 // USER INCLUDES |
|
41 #include "msguiutilsmanager.h" |
|
42 #include "msgconversationviewitem.h" |
|
43 #include "conversationsengine.h" |
|
44 #include "convergedmessageid.h" |
|
45 #include "convergedmessage.h" |
|
46 #include "conversationsenginedefines.h" |
|
47 #include "msgcontactcardwidget.h" |
|
48 #include "msgeditorwidget.h" |
|
49 #include "msgviewdefines.h" |
|
50 #include "debugtraces.h" |
|
51 #include "unidatamodelloader.h" |
|
52 #include "unidatamodelplugininterface.h" |
|
53 #include "ringbc.h" |
|
54 |
|
55 // LOCAL CONSTANTS |
|
56 const QString M_SERVER("mserver"); |
|
57 const QString SMS("sms"); |
|
58 |
|
59 #define LOC_COMMON_OPEN hbTrId("txt_common_menu_open") |
|
60 #define LOC_COMMON_DELETE hbTrId("txt_common_menu_delete") |
|
61 #define LOC_COMMON_FORWARD hbTrId("txt_common_menu_forward") |
|
62 #define LOC_COMMON_SAVE hbTrId("txt_common_menu_save") |
|
63 |
|
64 #define LOC_DELETE_CONVERSATION hbTrId("txt_messaging_dialog_delete_conversation") |
|
65 #define LOC_BUTTON_DELETE hbTrId("txt_common_button_delete") |
|
66 #define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel") |
|
67 |
|
68 #define LOC_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message") |
|
69 #define LOC_DELETE_POPINFO hbTrId("txt_messaging_dpopinfo_message_deleted") |
|
70 |
|
71 const QString HELP(QObject::tr("Help")); |
|
72 |
|
73 #define LOC_ADD hbTrId("txt_messaging_opt_add") |
|
74 #define LOC_RECIPIENTS hbTrId("txt_messaging_opt_sub_recipients") |
|
75 #define LOC_SUBJECT hbTrId("txt_messaging_opt_sub_subject") |
|
76 |
|
77 #define LOC_ATTACH hbTrId("txt_messaging_opt_attach") |
|
78 #define LOC_PHOTO hbTrId("txt_messaging_opt_attach_sub_photo") |
|
79 #define LOC_VIDEO hbTrId("txt_messaging_opt_attach_sub_video") |
|
80 #define LOC_SOUND hbTrId("txt_messaging_opt_attach_sub_sound") |
|
81 #define LOC_MORE hbTrId("txt_messaging_opt_attach_sub_more") |
|
82 |
|
83 const QString PLUGINPATH("conversationviewplugin.dll"); |
|
84 |
|
85 const int INVALID_MSGID = -1; |
|
86 //--------------------------------------------------------------- |
|
87 // MsgConversationView::MsgConversationView |
|
88 // @see header file |
|
89 //--------------------------------------------------------------- |
|
90 MsgConversationView::MsgConversationView(MsgContactCardWidget *contactCardWidget, |
|
91 QGraphicsItem *parent) : |
|
92 MsgBaseView(parent), |
|
93 mConversationList(NULL), |
|
94 mMessageModel(NULL), |
|
95 mEditorWidget(NULL), |
|
96 mContactCardWidget(contactCardWidget), |
|
97 mUiUtilsManager(NULL) |
|
98 { |
|
99 // Initialize the Utils manager |
|
100 mUiUtilsManager = new MsgUiUtilsManager(this); |
|
101 // connect the error signal from UtilsManager to the slot |
|
102 // in the conversation view. |
|
103 connect(mUiUtilsManager, |
|
104 SIGNAL(serviceError(const QString&)), |
|
105 this, |
|
106 SLOT(serviceError(const QString&))); |
|
107 |
|
108 connect(mUiUtilsManager, SIGNAL(imagesFetched(const QVariant&)), |
|
109 this, SLOT(imagesFetched(const QVariant&))); |
|
110 connect(mUiUtilsManager, SIGNAL(audiosFetched(const QVariant&)), |
|
111 this, SLOT(audiosFetched(const QVariant&))); |
|
112 |
|
113 //initialize view |
|
114 setupView(); |
|
115 addMenu(); |
|
116 } |
|
117 |
|
118 //--------------------------------------------------------------- |
|
119 // MsgConversationView::~MsgConversationView |
|
120 // @see header file |
|
121 //--------------------------------------------------------------- |
|
122 MsgConversationView::~MsgConversationView() |
|
123 { |
|
124 mConversationList->setModel(NULL); |
|
125 } |
|
126 //--------------------------------------------------------------- |
|
127 // MsgConversationView::setupView |
|
128 // @see header file |
|
129 //--------------------------------------------------------------- |
|
130 void MsgConversationView::setupView() |
|
131 { |
|
132 // Create HbListView and set properties |
|
133 mConversationList = new HbListView(); |
|
134 style()->registerPlugin(PLUGINPATH); |
|
135 mConversationList->setLayoutName("custom"); |
|
136 mConversationList->setItemRecycling(true); |
|
137 MsgConversationViewItem *item = new MsgConversationViewItem(this); |
|
138 mConversationList->setItemPrototype(item); |
|
139 mConversationList->setSelectionMode(HbListView::NoSelection); |
|
140 mConversationList->setClampingStyle(HbScrollArea::BounceBackClamping); |
|
141 mConversationList->setScrollingStyle(HbScrollArea::PanOrFlick); |
|
142 |
|
143 |
|
144 mMessageModel = ConversationsEngine::instance()->getConversationsModel(); |
|
145 |
|
146 connect(ConversationsEngine::instance(), |
|
147 SIGNAL(conversationModelPopulated()), |
|
148 this, |
|
149 SLOT(populateConversationsView())); |
|
150 |
|
151 connect(mConversationList, SIGNAL(activated(QModelIndex)), |
|
152 this, SLOT(openItem(QModelIndex))); |
|
153 |
|
154 // Long tap list item |
|
155 connect(mConversationList, SIGNAL(longPressed(HbAbstractViewItem*, QPointF)), |
|
156 this, SLOT(longPressed(HbAbstractViewItem*, QPointF))); |
|
157 |
|
158 // Create message editor widget. |
|
159 mEditorWidget = new MsgEditorWidget(); |
|
160 |
|
161 connect(mEditorWidget, SIGNAL(sendMessage()), this, SLOT(send())); |
|
162 connect(mEditorWidget, SIGNAL(replyStarted()), this, SIGNAL(replyStarted())); |
|
163 |
|
164 QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(Qt::Vertical); |
|
165 mainLayout->setContentsMargins(CONTENT_MARGIN, CONTENT_MARGIN, |
|
166 CONTENT_MARGIN, CONTENT_MARGIN); |
|
167 mainLayout->setSpacing(CONTENT_SPACING); |
|
168 mainLayout->addItem(mConversationList); |
|
169 mainLayout->addItem(mEditorWidget); |
|
170 setLayout(mainLayout); |
|
171 |
|
172 // Refresh view to show the header details |
|
173 refreshView(); |
|
174 |
|
175 HbEffect::add(QString("ConversationView"), |
|
176 QString(":/xml/conversationview_effect.fxml"), |
|
177 QString("show") ); |
|
178 } |
|
179 |
|
180 //--------------------------------------------------------------- |
|
181 // MsgConversationView::addMenu |
|
182 // @see header file |
|
183 //--------------------------------------------------------------- |
|
184 void MsgConversationView::addMenu() |
|
185 { |
|
186 HbMenu *mainMenu = new HbMenu(); |
|
187 |
|
188 // Clear conversation |
|
189 HbAction* clearConversation = mainMenu->addAction(LOC_COMMON_DELETE); |
|
190 connect(clearConversation, SIGNAL(triggered()), this, SLOT(deleteAll())); |
|
191 |
|
192 // Attach sub-menu |
|
193 HbMenu *attachSubMenu = mainMenu->addMenu(LOC_ATTACH); |
|
194 |
|
195 HbAction *addPhoto = attachSubMenu->addAction(LOC_PHOTO); |
|
196 connect(addPhoto, SIGNAL(triggered()),mUiUtilsManager, SLOT(fetchImages())); |
|
197 |
|
198 HbAction *addVideo = attachSubMenu->addAction(LOC_VIDEO); |
|
199 connect(addVideo, SIGNAL(triggered()),mUiUtilsManager, SLOT(fetchVideo())); |
|
200 |
|
201 HbAction *addSound = attachSubMenu->addAction(LOC_SOUND); |
|
202 connect(addSound, SIGNAL(triggered()),mUiUtilsManager, SLOT(fetchAudio())); |
|
203 |
|
204 HbAction *addOther = attachSubMenu->addAction(LOC_MORE); |
|
205 connect(addOther, SIGNAL(triggered()),mUiUtilsManager, SLOT(fetchOther())); |
|
206 |
|
207 HbMenu *addSubMenu = mainMenu->addMenu(LOC_ADD); |
|
208 |
|
209 HbAction *addRecipients = addSubMenu->addAction(LOC_RECIPIENTS); |
|
210 connect(addRecipients, SIGNAL(triggered()), this, SLOT(addRecipients())); |
|
211 |
|
212 HbAction *addSubject = addSubMenu->addAction(LOC_SUBJECT); |
|
213 connect(addSubject, SIGNAL(triggered()),this, SLOT(addSubject())); |
|
214 |
|
215 // Help |
|
216 HbAction* help = mainMenu->addAction(HELP); |
|
217 connect(help, SIGNAL(triggered()),this, SLOT(launchHelp())); |
|
218 |
|
219 setMenu(mainMenu); |
|
220 } |
|
221 |
|
222 //--------------------------------------------------------------- |
|
223 // MsgConversationView::refreshView() |
|
224 // @see header file |
|
225 //--------------------------------------------------------------- |
|
226 void MsgConversationView::refreshView() |
|
227 { |
|
228 mContactCardWidget->updateContents(); |
|
229 mContactCardWidget->resize(mContactCardWidget->boundingRect().size()); |
|
230 scrollToBottom(); |
|
231 } |
|
232 |
|
233 //--------------------------------------------------------------- |
|
234 // MsgConversationView::scrollToBottom() |
|
235 // @see header file |
|
236 //--------------------------------------------------------------- |
|
237 void MsgConversationView::scrollToBottom() |
|
238 { |
|
239 const int rowCnt = mMessageModel->rowCount(); |
|
240 mConversationList->scrollTo( |
|
241 mMessageModel->index(rowCnt - 1, 0)); |
|
242 } |
|
243 |
|
244 //--------------------------------------------------------------- |
|
245 // MsgConversationView::longPressed |
|
246 // @see header file |
|
247 //--------------------------------------------------------------- |
|
248 void MsgConversationView::longPressed(HbAbstractViewItem* viewItem, |
|
249 const QPointF& point) |
|
250 { |
|
251 MsgConversationViewItem* item = qgraphicsitem_cast< |
|
252 MsgConversationViewItem *> (viewItem); |
|
253 |
|
254 bool inSide = false; |
|
255 |
|
256 if (item) |
|
257 { |
|
258 inSide = item->containsPoint(point); |
|
259 } |
|
260 |
|
261 //If point is within the item then show the item-specific menu |
|
262 if (this->isVisible() && inSide) |
|
263 { |
|
264 //If message is in Sending state or is Scheduled to be sent later, |
|
265 //do not allow any operations on the message |
|
266 int sendingState = item->modelIndex().data(SendingState).toInt(); |
|
267 if(sendingState == ConvergedMessage::Suspended || |
|
268 sendingState == ConvergedMessage::Resend || |
|
269 sendingState == ConvergedMessage::Scheduled || |
|
270 sendingState == ConvergedMessage::Sending || |
|
271 sendingState == ConvergedMessage::Waiting) |
|
272 { |
|
273 return; |
|
274 } |
|
275 |
|
276 // Create new menu |
|
277 HbMenu *contextMenu = new HbMenu(); |
|
278 |
|
279 int messageType = item->modelIndex().data(MessageType).toInt(); |
|
280 |
|
281 // Add the menu items |
|
282 HbAction *contextItem4 = contextMenu->addAction(LOC_COMMON_OPEN); |
|
283 connect(contextItem4, SIGNAL(triggered()), |
|
284 this, SLOT(openItem())); |
|
285 |
|
286 HbAction *contextItem3 = contextMenu->addAction(LOC_COMMON_DELETE); |
|
287 connect(contextItem3, SIGNAL(triggered()), |
|
288 this, SLOT(deleteItem())); |
|
289 |
|
290 // for provisioning messages don't add forward option |
|
291 if(messageType != ConvergedMessage::Provisioning && |
|
292 messageType != ConvergedMessage::RingingTone) |
|
293 { |
|
294 HbAction *contextItem2 = contextMenu->addAction(LOC_COMMON_FORWARD); |
|
295 connect(contextItem2, SIGNAL(triggered()), |
|
296 this, SLOT(forwardMessage())); |
|
297 } |
|
298 |
|
299 |
|
300 contextMenu->exec(point); |
|
301 |
|
302 // Cleanup |
|
303 delete contextMenu; |
|
304 } |
|
305 } |
|
306 |
|
307 //--------------------------------------------------------------- |
|
308 // MsgEditorPrivate::send |
|
309 // @see header |
|
310 //--------------------------------------------------------------- |
|
311 void MsgConversationView::send() |
|
312 { |
|
313 mUiUtilsManager->activateInputBlocker(this); |
|
314 ConvergedMessageAddressList addresses; |
|
315 addresses = mContactCardWidget->address(); |
|
316 int sendResult = KErrNone; |
|
317 |
|
318 // Populate the ConvergedMessage. |
|
319 if (!addresses.isEmpty()) |
|
320 { |
|
321 ConvergedMessage msg; |
|
322 populateForSending(msg); |
|
323 msg.addToRecipients(addresses); |
|
324 |
|
325 // Send |
|
326 sendResult = mUiUtilsManager->send(msg); |
|
327 if( sendResult == KErrNone) |
|
328 { |
|
329 mEditorWidget->clear(); |
|
330 } |
|
331 } |
|
332 mUiUtilsManager->deactivateInputBlocker(); |
|
333 if( sendResult == KErrNotFound) |
|
334 { |
|
335 //switch to settings view |
|
336 QVariantList param; |
|
337 param << MsgBaseView::MSGSETTINGS; |
|
338 param << MsgBaseView::CV; |
|
339 emit switchView(param); |
|
340 } |
|
341 } |
|
342 |
|
343 //--------------------------------------------------------------- |
|
344 // MsgConversationView::deleteAll |
|
345 // Deletes all the conversations |
|
346 //--------------------------------------------------------------- |
|
347 void MsgConversationView::deleteAll() |
|
348 { |
|
349 bool result = HbMessageBox::question(LOC_DELETE_CONVERSATION, |
|
350 LOC_BUTTON_DELETE, |
|
351 LOC_BUTTON_CANCEL); |
|
352 if(result) |
|
353 { |
|
354 ConversationsEngine* engine = ConversationsEngine::instance(); |
|
355 engine->deleteConversations(engine->getCurrentConversationId()); |
|
356 //show dialog |
|
357 HbNotificationDialog::launchDialog("Conversation Deleted"); |
|
358 //switch to CLV |
|
359 QVariantList param; |
|
360 param << MsgBaseView::CLV; // target view |
|
361 param << MsgBaseView::CV; // source view |
|
362 emit switchView(param); |
|
363 } |
|
364 } |
|
365 |
|
366 //--------------------------------------------------------------- |
|
367 // MsgConversationView::addPhoto() |
|
368 // @see header file |
|
369 //--------------------------------------------------------------- |
|
370 void MsgConversationView::imagesFetched(const QVariant& result ) |
|
371 { |
|
372 if(result.canConvert<QStringList>()) |
|
373 { |
|
374 QStringList fileList = result.value<QStringList>(); |
|
375 if ( fileList.size()>0 ) |
|
376 { |
|
377 QString filepath(fileList.at(0)); |
|
378 launchUniEditor(MsgBaseView::ADD_PHOTO, filepath); |
|
379 } |
|
380 } |
|
381 } |
|
382 |
|
383 //--------------------------------------------------------------- |
|
384 // MsgConversationView::audiosFetched() |
|
385 // @see header file |
|
386 //--------------------------------------------------------------- |
|
387 void MsgConversationView::audiosFetched(const QVariant& result ) |
|
388 { |
|
389 if(result.canConvert<QStringList>()) |
|
390 { |
|
391 QStringList fileList = result.value<QStringList>(); |
|
392 if ( fileList.size()>0 && !fileList.at(0).isEmpty()) |
|
393 { |
|
394 QString filepath(QDir::toNativeSeparators(fileList.at(0))); |
|
395 launchUniEditor(MsgBaseView::ADD_AUDIO, filepath); |
|
396 } |
|
397 } |
|
398 } |
|
399 |
|
400 //--------------------------------------------------------------- |
|
401 // MsgConversationView::addRecipients() |
|
402 // @see header file |
|
403 //--------------------------------------------------------------- |
|
404 void MsgConversationView::addRecipients() |
|
405 { |
|
406 QString filepath; |
|
407 launchUniEditor(MsgBaseView::ADD_RECIPIENTS, filepath); |
|
408 } |
|
409 |
|
410 //--------------------------------------------------------------- |
|
411 // MsgConversationView::addSubject() |
|
412 // @see header file |
|
413 //--------------------------------------------------------------- |
|
414 void MsgConversationView::addSubject() |
|
415 { |
|
416 |
|
417 QString filepath; |
|
418 launchUniEditor(MsgBaseView::ADD_SUBJECT, filepath); |
|
419 } |
|
420 |
|
421 //--------------------------------------------------------------- |
|
422 // MsgConversationView::launchHelp() |
|
423 // Launches the help content |
|
424 //--------------------------------------------------------------- |
|
425 void MsgConversationView::launchHelp() |
|
426 { |
|
427 } |
|
428 |
|
429 //--------------------------------------------------------------- |
|
430 // MsgConversationView::exitApp() |
|
431 // Exits the application |
|
432 //--------------------------------------------------------------- |
|
433 void MsgConversationView::exitApp() |
|
434 { |
|
435 HbApplication::quit(); |
|
436 } |
|
437 |
|
438 //--------------------------------------------------------------- |
|
439 // MsgConversationView::forwardMessage() |
|
440 // Forwards the message |
|
441 //--------------------------------------------------------------- |
|
442 void MsgConversationView::forwardMessage() |
|
443 { |
|
444 } |
|
445 |
|
446 //--------------------------------------------------------------- |
|
447 // MsgConversationView::deleteItem() |
|
448 // Deletes the message |
|
449 //--------------------------------------------------------------- |
|
450 void MsgConversationView::deleteItem() |
|
451 { |
|
452 QModelIndex index = mConversationList->currentIndex(); |
|
453 int count = mMessageModel->rowCount(); |
|
454 //delete message |
|
455 qint32 messageId = index.data(ConvergedMsgId).toLongLong(); |
|
456 |
|
457 bool result = HbMessageBox::question(LOC_DELETE_MESSAGE, |
|
458 LOC_BUTTON_DELETE, |
|
459 LOC_BUTTON_CANCEL); |
|
460 if(result) |
|
461 { |
|
462 if (messageId) |
|
463 { |
|
464 QList<int> msgIdList; |
|
465 msgIdList.append(messageId); |
|
466 ConversationsEngine::instance()->deleteMessages(msgIdList); |
|
467 HbNotificationDialog::launchDialog(LOC_DELETE_POPINFO); |
|
468 //switch view |
|
469 if (count == 1) |
|
470 { |
|
471 QVariantList param; |
|
472 param << MsgBaseView::CLV; // target view |
|
473 param << MsgBaseView::CV; // source view |
|
474 emit switchView(param); |
|
475 } |
|
476 } |
|
477 } |
|
478 } |
|
479 |
|
480 //--------------------------------------------------------------- |
|
481 // MsgConversationView::openItem() |
|
482 // Opens the message |
|
483 //--------------------------------------------------------------- |
|
484 void MsgConversationView::openItem() |
|
485 { |
|
486 QModelIndex index = mConversationList->currentIndex(); |
|
487 openItem(index); |
|
488 } |
|
489 |
|
490 //--------------------------------------------------------------- |
|
491 // MsgConversationView::setMessageData() |
|
492 // Set message data |
|
493 //--------------------------------------------------------------- |
|
494 void MsgConversationView::setMessageData(const ConvergedMessage &message) |
|
495 { |
|
496 mEditorWidget->setContent(message.bodyText()); |
|
497 } |
|
498 |
|
499 //--------------------------------------------------------------- |
|
500 // MsgConversationView::clearEditors() |
|
501 // @See header |
|
502 //--------------------------------------------------------------- |
|
503 void MsgConversationView::clearEditors() |
|
504 { |
|
505 mEditorWidget->clear(); |
|
506 mConversationList->setModel(NULL); |
|
507 mContactCardWidget->clearContent(); |
|
508 } |
|
509 |
|
510 //--------------------------------------------------------------- |
|
511 // MsgConversationView::saveContentToDrafts() |
|
512 // @See header |
|
513 //--------------------------------------------------------------- |
|
514 bool MsgConversationView::saveContentToDrafts() |
|
515 { |
|
516 int msgId = INVALID_MSGID; |
|
517 if(!mEditorWidget->content().isEmpty()) |
|
518 { |
|
519 mUiUtilsManager->activateInputBlocker(this); |
|
520 ConvergedMessageAddressList addresses; |
|
521 addresses = mContactCardWidget->address(); |
|
522 |
|
523 // Populate the ConvergedMessage. |
|
524 if (!addresses.isEmpty()) |
|
525 { |
|
526 ConvergedMessage msg; |
|
527 populateForSending(msg); |
|
528 msg.addToRecipients(addresses); |
|
529 |
|
530 // Send |
|
531 msgId = mUiUtilsManager->saveToDrafts(msg); |
|
532 |
|
533 mEditorWidget->clear(); |
|
534 } |
|
535 mUiUtilsManager->deactivateInputBlocker(); |
|
536 } |
|
537 return ((msgId > INVALID_MSGID)? true : false); |
|
538 } |
|
539 |
|
540 //--------------------------------------------------------------- |
|
541 // MsgConversationView::loadCommandPlugin() |
|
542 // @See header |
|
543 //--------------------------------------------------------------- |
|
544 bool MsgConversationView::loadCommandPlugin() |
|
545 { |
|
546 /* |
|
547 #ifdef _DEBUG |
|
548 QDir dir(QLibraryInfo::location(QLibraryInfo::PluginsPath)); |
|
549 dir.cd("messaging"); |
|
550 #else |
|
551 QDir dir("Z:/resource/qt/plugins/messaging"); |
|
552 #endif |
|
553 #ifdef _DEBUG_TRACES_ |
|
554 qDebug() << "MsgConversationView::plugins path" << dir.path(); |
|
555 #endif |
|
556 |
|
557 // load the plugins |
|
558 QFileInfoList entries = dir.entryInfoList(QDir::Files | QDir::Readable); |
|
559 foreach (QFileInfo entry, entries) |
|
560 { |
|
561 QPluginLoader loader(entry.absoluteFilePath()); |
|
562 #ifdef _DEBUG_TRACES_ |
|
563 qDebug() << "MsgConversationView::absolute path" |
|
564 << entry.absoluteFilePath(); |
|
565 #endif |
|
566 mMsgCmdPlugin = qobject_cast<MsgCommandPluginInterface*> ( |
|
567 loader.instance()); |
|
568 if (mMsgCmdPlugin) |
|
569 { |
|
570 return true; |
|
571 } |
|
572 }*/ |
|
573 return false; |
|
574 } |
|
575 |
|
576 //--------------------------------------------------------------- |
|
577 //MsgConversationView::parseServiceId() |
|
578 //@see header |
|
579 //--------------------------------------------------------------- |
|
580 QString MsgConversationView::parseServiceId(const QString &serviceId) |
|
581 { |
|
582 QStringList services = serviceId.split('.'); |
|
583 // the service id is in the form "messaging.mserver.mms" |
|
584 // split the string by '.' and compare the middle part |
|
585 // by the server names. |
|
586 return services[1]; |
|
587 } |
|
588 |
|
589 //--------------------------------------------------------------- |
|
590 //MsgConversationView::currentMessageType() |
|
591 //@see header |
|
592 //--------------------------------------------------------------- |
|
593 int MsgConversationView::currentMessageType() |
|
594 { |
|
595 QString serviceId = mEditorWidget->serviceId(); |
|
596 QString sendClientType = parseServiceId(serviceId); |
|
597 |
|
598 ConvergedMessage::MessageType messageType = ConvergedMessage::None; |
|
599 if ( (M_SERVER == sendClientType) && serviceId.contains(SMS)) |
|
600 { |
|
601 messageType = ConvergedMessage::Sms; |
|
602 } |
|
603 return messageType; |
|
604 } |
|
605 //--------------------------------------------------------------- |
|
606 //MsgConversationView::populateForSending() |
|
607 //@see header |
|
608 //--------------------------------------------------------------- |
|
609 void MsgConversationView::populateForSending(ConvergedMessage &message) |
|
610 { |
|
611 ConvergedMessage::MessageType messageType = |
|
612 static_cast<ConvergedMessage::MessageType> (currentMessageType()); |
|
613 |
|
614 if (ConvergedMessage::Sms == messageType) |
|
615 { |
|
616 message.setMessageType(messageType); |
|
617 message.setBodyText(mEditorWidget->content()); |
|
618 message.setDirection(ConvergedMessage::Outgoing); |
|
619 QDateTime time = QDateTime::currentDateTime(); |
|
620 message.setTimeStamp(time.toTime_t()); |
|
621 } |
|
622 } |
|
623 |
|
624 //--------------------------------------------------------------- |
|
625 // MsgConversationView::serviceError() |
|
626 // @See header |
|
627 //--------------------------------------------------------------- |
|
628 void MsgConversationView::serviceError(const QString& error) |
|
629 { |
|
630 Q_UNUSED(error) |
|
631 // HbDialog popup; |
|
632 // |
|
633 // popup.setDismissPolicy(HbDialog::TapAnywhere); |
|
634 // popup.setHeadingWidget(new HbLabel(tr("Error Notification"))); |
|
635 // |
|
636 // /// set a label as the content widget in the popup. |
|
637 // HbLabel contentLabel(error); |
|
638 // popup.setContentWidget(&contentLabel); |
|
639 // |
|
640 // popup.setPrimaryAction(new HbAction(tr("Ok"), &popup)); |
|
641 // popup.exec(); |
|
642 } |
|
643 |
|
644 //--------------------------------------------------------------- |
|
645 //MsgConversationView::openItem |
|
646 //@see header |
|
647 //--------------------------------------------------------------- |
|
648 void MsgConversationView::openItem(const QModelIndex & index) |
|
649 { |
|
650 int messageType = index.data(MessageType).toInt(); |
|
651 if(messageType == ConvergedMessage::RingingTone ) |
|
652 { |
|
653 if(RingBc::askSaveQuery()) |
|
654 { |
|
655 saveRingingTone(); |
|
656 } |
|
657 return; |
|
658 } |
|
659 |
|
660 /// smart messages hardcoded due to common handling |
|
661 if (messageType == ConvergedMessage::BioMsg |
|
662 || messageType >= ConvergedMessage::VCard) |
|
663 { |
|
664 return; |
|
665 } |
|
666 |
|
667 ConvergedMessage message; |
|
668 // check whether message is in sending progress, then donot launch viewer. |
|
669 int location = index.data(MessageLocation).toInt(); |
|
670 int sendingState = index.data(SendingState).toInt(); |
|
671 |
|
672 //If message is in Sending state or is Scheduled to be sent later, |
|
673 //do not open the message |
|
674 if(sendingState == ConvergedMessage::Suspended || |
|
675 sendingState == ConvergedMessage::Resend || |
|
676 sendingState == ConvergedMessage::Scheduled || |
|
677 sendingState == ConvergedMessage::Sending || |
|
678 sendingState == ConvergedMessage::Waiting) |
|
679 { |
|
680 return; |
|
681 } |
|
682 |
|
683 //TODO: sendingState check should be removed once msg |
|
684 // movement lock issue is resolved from mw |
|
685 if( !((location == ConvergedMessage::Inbox) || |
|
686 (location == ConvergedMessage::Sent) || |
|
687 (sendingState == ConvergedMessage::SentState)) ) |
|
688 {// do not launch viewer, show a note |
|
689 HbNotificationDialog* dlg = new HbNotificationDialog(); |
|
690 dlg->setFocusPolicy(Qt::NoFocus); |
|
691 QString text(tr("Message Locked")); |
|
692 dlg->setText(text); |
|
693 dlg->setDismissPolicy(HbPopup::TapAnywhere); |
|
694 dlg->setAttribute(Qt::WA_DeleteOnClose, true); |
|
695 dlg->show(); |
|
696 return; |
|
697 } |
|
698 |
|
699 // message id |
|
700 qint32 messageId = index.data(ConvergedMsgId).toLongLong(); |
|
701 ConvergedMessageId msgId(messageId); |
|
702 message.setMessageId(msgId); |
|
703 |
|
704 // contact Id |
|
705 qint32 contactId = index.data(ContactId).toLongLong(); |
|
706 |
|
707 // message type |
|
708 |
|
709 message.setMessageType((ConvergedMessage::MessageType) messageType); |
|
710 |
|
711 if (messageType == ConvergedMessage::Mms) |
|
712 { |
|
713 message.setSubject(index.data(Subject).toString()); |
|
714 message.setPriority((ConvergedMessage::Priority) index.data( |
|
715 MessagePriority).toInt()); |
|
716 } |
|
717 else if (messageType == ConvergedMessage::IM) |
|
718 { |
|
719 // add body text and send to the message for IM case |
|
720 message.setBodyText(index.data(BodyText).toString()); |
|
721 } |
|
722 |
|
723 // time stamp |
|
724 message.setTimeStamp(index.data(TimeStamp).toLongLong()); |
|
725 |
|
726 //Message direction |
|
727 message.setDirection((ConvergedMessage::Direction)index.data(Direction).toInt()); |
|
728 |
|
729 // conatct name as address |
|
730 ConvergedMessageAddress address; |
|
731 address.setAlias(mContactCardWidget->address().at(0)->alias()); |
|
732 address.setAddress(mContactCardWidget->address().at(0)->address()); |
|
733 message.addToRecipient(address); |
|
734 |
|
735 // Mark this message as read if its unread |
|
736 QByteArray dataArray; |
|
737 QDataStream messageStream |
|
738 (&dataArray, QIODevice::WriteOnly | QIODevice::Append); |
|
739 message.serialize(messageStream); |
|
740 //if message unread, mark as read before opening view |
|
741 QList<int> msgIdList; |
|
742 if(index.data(UnReadStatus).toInt()) |
|
743 { |
|
744 msgIdList.clear(); |
|
745 msgIdList << messageId; |
|
746 ConversationsEngine::instance()->markMessagesRead(msgIdList); |
|
747 } |
|
748 |
|
749 //switch view |
|
750 QVariantList param; |
|
751 param << MsgBaseView::UNIVIEWER; // target view |
|
752 param << MsgBaseView::CV; // source view |
|
753 |
|
754 param << contactId; |
|
755 param << dataArray; |
|
756 param << mMessageModel->rowCount(); |
|
757 |
|
758 emit switchView(param); |
|
759 } |
|
760 |
|
761 //--------------------------------------------------------------- |
|
762 // MsgConversationView::launchUniEditor |
|
763 // @see header file |
|
764 //--------------------------------------------------------------- |
|
765 void MsgConversationView::launchUniEditor(const int editorFields, QString& filepath) |
|
766 { |
|
767 ConvergedMessage message; |
|
768 message.setBodyText(mEditorWidget->content()); |
|
769 |
|
770 ConvergedMessageAddress address; |
|
771 address.setAlias(mContactCardWidget->address().at(0)->alias()); |
|
772 address.setAddress(mContactCardWidget->address().at(0)->address()); |
|
773 message.addToRecipient(address); |
|
774 |
|
775 if(!filepath.isEmpty()) |
|
776 { |
|
777 ConvergedMessageAttachment* attachment = new ConvergedMessageAttachment(filepath); |
|
778 ConvergedMessageAttachmentList attachmentList; |
|
779 attachmentList.append(attachment); |
|
780 message.addAttachments(attachmentList); |
|
781 } |
|
782 |
|
783 QByteArray dataArray; |
|
784 QDataStream messageStream |
|
785 (&dataArray, QIODevice::WriteOnly | QIODevice::Append); |
|
786 message.serialize(messageStream); |
|
787 |
|
788 QVariantList params; |
|
789 params << MsgBaseView::UNIEDITOR; // target view |
|
790 params << MsgBaseView::CV; // source view |
|
791 |
|
792 params << dataArray; |
|
793 params << editorFields; |
|
794 |
|
795 clearEditors(); |
|
796 emit switchView(params); |
|
797 } |
|
798 |
|
799 //--------------------------------------------------------------- |
|
800 // MsgConversationView::populateConversationsView |
|
801 // @see header file |
|
802 //--------------------------------------------------------------- |
|
803 void MsgConversationView::populateConversationsView() |
|
804 { |
|
805 connect(mMessageModel, SIGNAL(conversationModelUpdated()), |
|
806 this, SLOT(refreshView())); |
|
807 |
|
808 mConversationList->setModel(mMessageModel); |
|
809 |
|
810 refreshView(); |
|
811 |
|
812 HbEffect::start(this,QString("ConversationView"), |
|
813 QString("show"),this,"effectFinished"); |
|
814 } |
|
815 |
|
816 //--------------------------------------------------------------- |
|
817 // MsgConversationView::effectFinished |
|
818 // @see header file |
|
819 //--------------------------------------------------------------- |
|
820 void MsgConversationView::effectFinished( |
|
821 const HbEffect::EffectStatus& /*status*/) |
|
822 { |
|
823 // Effect is finished. Start fetching remaing conversations |
|
824 ConversationsEngine::instance()->fetchMoreConversations(); |
|
825 } |
|
826 |
|
827 //--------------------------------------------------------------- |
|
828 // MsgConversationView::saveRingingTone |
|
829 // @see header file |
|
830 //--------------------------------------------------------------- |
|
831 void MsgConversationView::saveRingingTone() |
|
832 { |
|
833 QModelIndex index = mConversationList->currentIndex(); |
|
834 int messageId = index.data(ConvergedMsgId).toInt(); |
|
835 |
|
836 UniDataModelLoader* pluginLoader = new UniDataModelLoader(); |
|
837 pluginLoader->loadPlugins(); |
|
838 UniDataModelPluginInterface* pluginInterface = |
|
839 pluginLoader->getDataModelPlugin("bio:vcal"); |
|
840 pluginInterface->setMessageId(messageId); |
|
841 UniMessageInfoList attachments = pluginInterface->attachmentList(); |
|
842 |
|
843 QString attachmentPath = attachments[0]->path(); |
|
844 |
|
845 RingBc* ringBc = new RingBc(); |
|
846 |
|
847 ringBc->saveTone(attachmentPath); |
|
848 |
|
849 // clear attachement list : its allocated at data model |
|
850 while(!attachments.isEmpty()) |
|
851 { |
|
852 delete attachments.takeFirst(); |
|
853 } |
|
854 |
|
855 delete ringBc; |
|
856 delete pluginLoader; |
|
857 } |
|
858 |
|
859 // EOF |