37
|
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: Manages differnt messaging views.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "msgserviceviewmanager.h"
|
|
19 |
|
|
20 |
#include <HbMainWindow>
|
|
21 |
#include <HbAction>
|
|
22 |
#include <HbApplication>
|
|
23 |
#include <hbmessagebox.h>
|
|
24 |
|
|
25 |
#include <xqserviceutil.h>
|
|
26 |
#include <xqappmgr.h>
|
|
27 |
|
|
28 |
#include "msgunieditorview.h"
|
|
29 |
#include "unifiedviewer.h"
|
|
30 |
#include "msgstorehandler.h"
|
|
31 |
|
|
32 |
#include "msgsettingsview.h"
|
|
33 |
#include "convergedmessageid.h"
|
|
34 |
#include "ringbc.h"
|
|
35 |
#include "unidatamodelloader.h"
|
|
36 |
#include "unidatamodelplugininterface.h"
|
|
37 |
|
|
38 |
// LOCALIZATION
|
|
39 |
#define LOC_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
|
|
40 |
#define LOC_DLG_SAVE_RINGTONE hbTrId("txt_conversations_dialog_save_ringing_tone")
|
|
41 |
|
|
42 |
//----------------------------------------------------------------------------
|
|
43 |
// MsgViewInterface::MsgViewInterface
|
|
44 |
// @see header
|
|
45 |
//----------------------------------------------------------------------------
|
|
46 |
MsgServiceViewManager::MsgServiceViewManager(MsgStoreHandler* storeHandler,
|
|
47 |
HbMainWindow* mainWindow, QObject* parent) :
|
|
48 |
QObject(parent), mMainWindow(mainWindow), mUniEditor(NULL),
|
|
49 |
mUniViewer(NULL), mSettingsView(NULL), mBackAction(NULL),
|
|
50 |
mStoreHandler(storeHandler),mMessageId(-1)
|
|
51 |
{
|
|
52 |
//creating back action.
|
|
53 |
mBackAction = new HbAction(Hb::BackNaviAction, this);
|
|
54 |
connect(mBackAction, SIGNAL(triggered()), this, SLOT(onBackAction()));
|
|
55 |
|
|
56 |
// create a temp view : which is required for lazy loading of other views
|
|
57 |
HbView* tempView = new HbView();
|
|
58 |
mMainWindow->addView(tempView);
|
|
59 |
mMainWindow->setCurrentView(tempView);
|
|
60 |
}
|
|
61 |
|
|
62 |
//----------------------------------------------------------------------------
|
|
63 |
// MsgServiceViewManager::~MsgServiceViewManager
|
|
64 |
// @see header
|
|
65 |
//----------------------------------------------------------------------------
|
|
66 |
MsgServiceViewManager::~MsgServiceViewManager()
|
|
67 |
{
|
|
68 |
|
|
69 |
}
|
|
70 |
|
|
71 |
//----------------------------------------------------------------------------
|
|
72 |
// MsgServiceViewManager::onBackAction
|
|
73 |
// @see header
|
|
74 |
//----------------------------------------------------------------------------
|
|
75 |
void MsgServiceViewManager::onBackAction()
|
|
76 |
{
|
|
77 |
switch(mCurrentView)
|
|
78 |
{
|
|
79 |
case MsgBaseView::UNIEDITOR:
|
|
80 |
{
|
|
81 |
mUniEditor->saveContentToDrafts();
|
|
82 |
HbApplication::quit();
|
|
83 |
break;
|
|
84 |
}
|
|
85 |
case MsgBaseView::MSGSETTINGS:
|
|
86 |
{
|
|
87 |
//delete the settings instance
|
|
88 |
if (mSettingsView)
|
|
89 |
{
|
|
90 |
mMainWindow->removeView(mSettingsView);
|
|
91 |
delete mSettingsView;
|
|
92 |
mSettingsView = NULL;
|
|
93 |
}
|
|
94 |
if(mUniEditor)
|
|
95 |
{
|
|
96 |
mMainWindow->setCurrentView(mUniEditor);
|
|
97 |
mCurrentView = MsgBaseView::UNIEDITOR;
|
|
98 |
}
|
|
99 |
else
|
|
100 |
{
|
|
101 |
ConvergedMessage message;
|
|
102 |
QVariantList param;
|
|
103 |
QByteArray dataArray;
|
|
104 |
QDataStream messageStream(&dataArray,
|
|
105 |
QIODevice::WriteOnly | QIODevice::Append);
|
|
106 |
message.serialize(messageStream);
|
|
107 |
param << dataArray;
|
|
108 |
|
|
109 |
// switch to editor
|
|
110 |
switchToUniEditor(param);
|
|
111 |
}
|
|
112 |
break;
|
|
113 |
}
|
|
114 |
case MsgBaseView::UNIVIEWER:
|
|
115 |
default:
|
|
116 |
{
|
|
117 |
HbApplication::quit();
|
|
118 |
break;
|
|
119 |
}
|
|
120 |
|
|
121 |
}
|
|
122 |
}
|
|
123 |
|
|
124 |
//----------------------------------------------------------------------------
|
|
125 |
// MsgServiceViewManager::switchView
|
|
126 |
// @see header
|
|
127 |
//----------------------------------------------------------------------------
|
|
128 |
void MsgServiceViewManager::switchView(const QVariantList& data)
|
|
129 |
{
|
|
130 |
int viewId = data.at(0).toInt();
|
|
131 |
switch (viewId) {
|
|
132 |
case MsgBaseView::UNIEDITOR:
|
|
133 |
{
|
|
134 |
// except first 2 parameters pass other parameters
|
|
135 |
QVariantList editorData;
|
|
136 |
for(int a = 2; a < data.length(); ++a)
|
|
137 |
{
|
|
138 |
editorData << data.at(a);
|
|
139 |
}
|
|
140 |
switchToUniEditor(editorData);
|
|
141 |
break;
|
|
142 |
}
|
|
143 |
|
|
144 |
case MsgBaseView::MSGSETTINGS:
|
|
145 |
{
|
|
146 |
switchToMsgSettings(data);
|
|
147 |
break;
|
|
148 |
}
|
|
149 |
default:
|
|
150 |
{
|
|
151 |
HbApplication::quit();
|
|
152 |
}
|
|
153 |
}
|
|
154 |
}
|
|
155 |
|
|
156 |
//----------------------------------------------------------------------------
|
|
157 |
// MsgServiceViewManager::send
|
|
158 |
// @see header
|
|
159 |
//----------------------------------------------------------------------------
|
|
160 |
void MsgServiceViewManager::send(const QString phoneNumber,
|
|
161 |
const qint32 contactId,
|
|
162 |
const QString displayName)
|
|
163 |
{
|
|
164 |
ConvergedMessage message;
|
|
165 |
ConvergedMessageAddress address;
|
|
166 |
address.setAddress(phoneNumber);
|
|
167 |
address.setAlias(displayName);
|
|
168 |
message.addToRecipient(address);
|
|
169 |
|
|
170 |
QVariantList param;
|
|
171 |
QByteArray dataArray;
|
|
172 |
QDataStream messageStream(&dataArray,
|
|
173 |
QIODevice::WriteOnly | QIODevice::Append);
|
|
174 |
message.serialize(messageStream);
|
|
175 |
param << dataArray;
|
|
176 |
|
|
177 |
// switch to editor
|
|
178 |
switchToUniEditor(param);
|
|
179 |
|
|
180 |
XQServiceUtil::toBackground(false);
|
|
181 |
}
|
|
182 |
|
|
183 |
//----------------------------------------------------------------------------
|
|
184 |
// MsgServiceViewManager::send
|
|
185 |
// @see header
|
|
186 |
//----------------------------------------------------------------------------
|
|
187 |
void MsgServiceViewManager::send(const QString phoneNumber,
|
|
188 |
const QString alias,
|
|
189 |
const QString bodyText)
|
|
190 |
{
|
|
191 |
ConvergedMessage message;
|
|
192 |
ConvergedMessageAddress address;
|
|
193 |
address.setAddress(phoneNumber);
|
|
194 |
address.setAlias(alias);
|
|
195 |
message.addToRecipient(address);
|
|
196 |
message.setBodyText(bodyText);
|
|
197 |
|
|
198 |
QVariantList param;
|
|
199 |
QByteArray dataArray;
|
|
200 |
QDataStream messageStream(&dataArray,
|
|
201 |
QIODevice::WriteOnly | QIODevice::Append);
|
|
202 |
message.serialize(messageStream);
|
|
203 |
param << dataArray;
|
|
204 |
|
|
205 |
// switch to editor
|
|
206 |
switchToUniEditor(param);
|
|
207 |
|
|
208 |
XQServiceUtil::toBackground(false);
|
|
209 |
}
|
|
210 |
|
|
211 |
//----------------------------------------------------------------------------
|
|
212 |
// MsgServiceViewManager::send
|
|
213 |
// @see header
|
|
214 |
//----------------------------------------------------------------------------
|
|
215 |
void MsgServiceViewManager::send(const QVariantMap addressList,
|
|
216 |
const QString bodyText)
|
|
217 |
{
|
|
218 |
QStringList phoneNumList = addressList.keys();
|
|
219 |
|
|
220 |
ConvergedMessageAddressList addrList;
|
|
221 |
|
|
222 |
int count = phoneNumList.count();
|
|
223 |
for( int i = 0; i < count; ++ i )
|
|
224 |
{
|
|
225 |
QString phNum = phoneNumList[i];
|
|
226 |
ConvergedMessageAddress* address = new ConvergedMessageAddress(phNum,
|
|
227 |
addressList.value(phNum).toString());
|
|
228 |
addrList.append(address);
|
|
229 |
}
|
|
230 |
|
|
231 |
ConvergedMessage message;
|
|
232 |
message.addToRecipients(addrList);
|
|
233 |
message.setBodyText(bodyText);
|
|
234 |
|
|
235 |
QVariantList param;
|
|
236 |
QByteArray dataArray;
|
|
237 |
QDataStream messageStream(&dataArray,
|
|
238 |
QIODevice::WriteOnly | QIODevice::Append);
|
|
239 |
message.serialize(messageStream);
|
|
240 |
param << dataArray;
|
|
241 |
|
|
242 |
// switch to editor
|
|
243 |
switchToUniEditor(param);
|
|
244 |
|
|
245 |
XQServiceUtil::toBackground(false);
|
|
246 |
}
|
|
247 |
|
|
248 |
//----------------------------------------------------------------------------
|
|
249 |
// MsgServiceViewManager::send
|
|
250 |
// @see header
|
|
251 |
//----------------------------------------------------------------------------
|
|
252 |
void MsgServiceViewManager::send(QVariant data)
|
|
253 |
{
|
|
254 |
ConvergedMessage message;
|
|
255 |
ConvergedMessageAttachmentList attachmentList;
|
|
256 |
// handle multiple files from sendUI
|
|
257 |
// e.g. contacts can send multiple vcards
|
|
258 |
QStringList receivedFiles = data.toStringList();
|
|
259 |
int recFileCount = receivedFiles.count();
|
|
260 |
for (int i = 0; i < recFileCount; i++) {
|
|
261 |
ConvergedMessageAttachment *attachment =
|
|
262 |
new ConvergedMessageAttachment(receivedFiles.at(i));
|
|
263 |
attachmentList.append(attachment);
|
|
264 |
}
|
|
265 |
message.addAttachments(attachmentList);
|
|
266 |
|
|
267 |
QVariantList param;
|
|
268 |
QByteArray dataArray;
|
|
269 |
QDataStream messageStream(&dataArray,
|
|
270 |
QIODevice::WriteOnly | QIODevice::Append);
|
|
271 |
message.serialize(messageStream);
|
|
272 |
param << dataArray;
|
|
273 |
|
|
274 |
// switch to editor
|
|
275 |
switchToUniEditor(param);
|
|
276 |
|
|
277 |
XQServiceUtil::toBackground(false);
|
|
278 |
}
|
|
279 |
|
|
280 |
//----------------------------------------------------------------------------
|
|
281 |
// MsgServiceViewManager::switchToUniEditor
|
|
282 |
// @see header
|
|
283 |
//----------------------------------------------------------------------------
|
|
284 |
void MsgServiceViewManager::switchToUniEditor(const QVariantList& editorData)
|
|
285 |
{
|
|
286 |
// construct
|
|
287 |
if (!mUniEditor) {
|
|
288 |
mUniEditor = new MsgUnifiedEditorView();
|
|
289 |
mMainWindow->addView(mUniEditor);
|
|
290 |
mUniEditor->setNavigationAction(mBackAction);
|
|
291 |
connect(mUniEditor, SIGNAL(switchView(const QVariantList&)), this,
|
|
292 |
SLOT(switchView(const QVariantList&)));
|
|
293 |
// construct completion : viewReady() signal was not called when
|
|
294 |
// editor is constructed first time.
|
|
295 |
// mUniEditor->doDelayedConstruction();
|
|
296 |
}
|
|
297 |
|
|
298 |
// populate
|
|
299 |
mUniEditor->populateContent(editorData);
|
|
300 |
|
|
301 |
// set current view as editor
|
|
302 |
mMainWindow->setCurrentView(mUniEditor);
|
|
303 |
mCurrentView = MsgBaseView::UNIEDITOR;
|
|
304 |
}
|
|
305 |
|
|
306 |
//----------------------------------------------------------------------------
|
|
307 |
// MsgServiceViewManager::switchToMsgSettings
|
|
308 |
// @see header
|
|
309 |
//----------------------------------------------------------------------------
|
|
310 |
void MsgServiceViewManager::switchToMsgSettings(const QVariantList& data)
|
|
311 |
{
|
|
312 |
MsgSettingsView::SettingsView view = MsgSettingsView::DefaultView;
|
|
313 |
|
|
314 |
if (mCurrentView == MsgBaseView::UNIEDITOR)
|
|
315 |
{
|
|
316 |
view = (MsgSettingsView::SettingsView)data.at(2).toInt();
|
|
317 |
}
|
|
318 |
|
|
319 |
mCurrentView = MsgBaseView::MSGSETTINGS;
|
|
320 |
|
|
321 |
if (!mSettingsView) {
|
|
322 |
mSettingsView = new MsgSettingsView(view);
|
|
323 |
mSettingsView->setNavigationAction(mBackAction);
|
|
324 |
mMainWindow->addView(mSettingsView);
|
|
325 |
}
|
|
326 |
mMainWindow->setCurrentView(mSettingsView);
|
|
327 |
}
|
|
328 |
|
|
329 |
//----------------------------------------------------------------------------
|
|
330 |
// MsgServiceViewManager::view
|
|
331 |
// @see header
|
|
332 |
//----------------------------------------------------------------------------
|
|
333 |
void MsgServiceViewManager::view(int msgId)
|
|
334 |
{
|
|
335 |
int msgType;
|
|
336 |
int msgSubType;
|
|
337 |
|
|
338 |
mMessageId = msgId;
|
|
339 |
// Mark as read and get message type
|
|
340 |
mStoreHandler->markAsReadAndGetType(msgId,msgType,msgSubType);
|
|
341 |
|
|
342 |
switch (msgType) {
|
|
343 |
case ConvergedMessage::Sms:
|
|
344 |
case ConvergedMessage::Mms:
|
|
345 |
case ConvergedMessage::MmsNotification:
|
|
346 |
{
|
|
347 |
handleSmsMmsMsg(msgId);
|
|
348 |
break;
|
|
349 |
}
|
|
350 |
case ConvergedMessage::BioMsg:
|
|
351 |
{
|
|
352 |
if (msgSubType == ConvergedMessage::RingingTone) {
|
|
353 |
handleRingtoneMsg(msgId);
|
|
354 |
}
|
|
355 |
else if (msgSubType == ConvergedMessage::Provisioning) {
|
|
356 |
handleProvisoningMsg(msgId);
|
|
357 |
}
|
|
358 |
break;
|
|
359 |
}
|
|
360 |
case ConvergedMessage::BT:
|
|
361 |
{
|
|
362 |
handleBTMessage(msgId);
|
|
363 |
break;
|
|
364 |
}
|
|
365 |
default:
|
|
366 |
{
|
|
367 |
// for un supported message show delete option
|
|
368 |
HbMessageBox::question(LOC_DELETE_MESSAGE,
|
|
369 |
this,SLOT(onDialogDeleteMsg(HbAction*)),
|
|
370 |
HbMessageBox::Delete | HbMessageBox::Cancel);
|
|
371 |
break;
|
|
372 |
}
|
|
373 |
}
|
|
374 |
}
|
|
375 |
|
|
376 |
// ----------------------------------------------------------------------------
|
|
377 |
// MsgServiceViewManager::handleSmsMmsMsg
|
|
378 |
// @see header
|
|
379 |
// ----------------------------------------------------------------------------
|
|
380 |
void MsgServiceViewManager::handleSmsMmsMsg(int msgId)
|
|
381 |
{
|
|
382 |
if (!mUniViewer) {
|
|
383 |
mUniViewer = new UnifiedViewer(msgId);
|
|
384 |
mUniViewer->setNavigationAction(mBackAction);
|
|
385 |
mMainWindow->addView(mUniViewer);
|
|
386 |
connect(mUniViewer, SIGNAL(switchView(const QVariantList&)), this,
|
|
387 |
SLOT(switchView(const QVariantList&)));
|
|
388 |
}
|
|
389 |
mUniViewer->populateContent(msgId, true, 1);
|
|
390 |
|
|
391 |
mMainWindow->setCurrentView(mUniViewer);
|
|
392 |
|
|
393 |
// set current view as viewer
|
|
394 |
mCurrentView = MsgBaseView::UNIVIEWER;
|
|
395 |
}
|
|
396 |
|
|
397 |
// ----------------------------------------------------------------------------
|
|
398 |
// MsgServiceViewManager::handleRingtoneMsg
|
|
399 |
// @see header
|
|
400 |
// ----------------------------------------------------------------------------
|
|
401 |
void MsgServiceViewManager::handleRingtoneMsg(int msgId)
|
|
402 |
{
|
|
403 |
mMessageId = msgId;
|
|
404 |
HbMessageBox::question(LOC_DLG_SAVE_RINGTONE, this,
|
|
405 |
SLOT(onDialogSaveTone(HbAction*)),
|
|
406 |
HbMessageBox::Save | HbMessageBox::Cancel);
|
|
407 |
}
|
|
408 |
|
|
409 |
// ----------------------------------------------------------------------------
|
|
410 |
// MsgServiceViewManager::handleProvisoningMsg
|
|
411 |
// @see header
|
|
412 |
// ----------------------------------------------------------------------------
|
|
413 |
void MsgServiceViewManager::handleProvisoningMsg(int msgId)
|
|
414 |
{
|
|
415 |
QString messageId;
|
|
416 |
messageId.setNum(msgId);
|
|
417 |
|
|
418 |
XQApplicationManager* aiwMgr = new XQApplicationManager();
|
|
419 |
|
|
420 |
XQAiwRequest* request = aiwMgr->create("com.nokia.services.MDM",
|
|
421 |
"Provisioning",
|
|
422 |
"ProcessMessage(QString)", true); // embedded
|
|
423 |
|
|
424 |
if (request) {
|
|
425 |
QList<QVariant> args;
|
|
426 |
args << QVariant(messageId);
|
|
427 |
request->setArguments(args);
|
|
428 |
|
|
429 |
// Send the request
|
|
430 |
bool res = request->send();
|
|
431 |
|
|
432 |
// Cleanup
|
|
433 |
delete request;
|
|
434 |
}
|
|
435 |
|
|
436 |
delete aiwMgr;
|
|
437 |
|
|
438 |
// close the application once its handled
|
|
439 |
HbApplication::quit();
|
|
440 |
}
|
|
441 |
|
|
442 |
//-----------------------------------------------------------------------------
|
|
443 |
//MsgServiceViewManager::handleBTMessage()
|
|
444 |
//@see header
|
|
445 |
//-----------------------------------------------------------------------------
|
|
446 |
void MsgServiceViewManager::handleBTMessage(int msgId)
|
|
447 |
{
|
|
448 |
XQApplicationManager* aiwMgr = new XQApplicationManager();
|
|
449 |
XQAiwRequest* request =
|
|
450 |
aiwMgr->create("com.nokia.services.btmsgdispservices", "displaymsg",
|
|
451 |
"displaymsg(int)", true); // embedded
|
|
452 |
|
|
453 |
if (request) {
|
|
454 |
QList<QVariant> args;
|
|
455 |
args << QVariant(msgId);
|
|
456 |
request->setArguments(args);
|
|
457 |
|
|
458 |
// Send the request
|
|
459 |
bool res = request->send();
|
|
460 |
|
|
461 |
// Cleanup
|
|
462 |
delete request;
|
|
463 |
}
|
|
464 |
|
|
465 |
delete aiwMgr;
|
|
466 |
|
|
467 |
// close the application once its handled
|
|
468 |
HbApplication::quit();
|
|
469 |
}
|
|
470 |
|
|
471 |
//-----------------------------------------------------------------------------
|
|
472 |
//MsgServiceViewManager::onDialogDeleteMsg()
|
|
473 |
//@see header
|
|
474 |
//-----------------------------------------------------------------------------
|
|
475 |
void MsgServiceViewManager::onDialogDeleteMsg(HbAction* action)
|
|
476 |
{
|
|
477 |
HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
|
|
478 |
if (action == dlg->actions().at(0)) {
|
|
479 |
mStoreHandler->deleteMessage(mMessageId);
|
|
480 |
}
|
|
481 |
HbApplication::quit(); // exit after handling
|
|
482 |
}
|
|
483 |
|
|
484 |
//-----------------------------------------------------------------------------
|
|
485 |
//MsgServiceViewManager::onDialogSaveTone()
|
|
486 |
//@see header
|
|
487 |
//-----------------------------------------------------------------------------
|
|
488 |
|
|
489 |
void MsgServiceViewManager::onDialogSaveTone(HbAction* action)
|
|
490 |
{
|
|
491 |
HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
|
|
492 |
if (action == dlg->actions().at(0)) {
|
|
493 |
|
|
494 |
UniDataModelLoader* pluginLoader = new UniDataModelLoader();
|
|
495 |
UniDataModelPluginInterface* pluginInterface = pluginLoader->getDataModelPlugin(
|
|
496 |
ConvergedMessage::BioMsg);
|
|
497 |
pluginInterface->setMessageId(mMessageId);
|
|
498 |
UniMessageInfoList attachments = pluginInterface->attachmentList();
|
|
499 |
|
|
500 |
QString attachmentPath = attachments.at(0)->path();
|
|
501 |
|
|
502 |
RingBc* ringBc = new RingBc();
|
|
503 |
ringBc->saveTone(attachmentPath);
|
|
504 |
|
|
505 |
// clear attachement list : its allocated at data model
|
|
506 |
while (!attachments.isEmpty()) {
|
|
507 |
delete attachments.takeFirst();
|
|
508 |
}
|
|
509 |
|
|
510 |
delete ringBc;
|
|
511 |
delete pluginLoader;
|
|
512 |
}
|
|
513 |
|
|
514 |
// close the application once its handled
|
|
515 |
HbApplication::quit();
|
|
516 |
}
|
|
517 |
|