36 mCcAddresses(0), |
36 mCcAddresses(0), |
37 mBccAddresses(0), |
37 mBccAddresses(0), |
38 mAttachmentList(0), |
38 mAttachmentList(0), |
39 mEditorStartMode(NmUiEditorCreateNew) |
39 mEditorStartMode(NmUiEditorCreateNew) |
40 { |
40 { |
|
41 NM_FUNCTION; |
41 } |
42 } |
42 |
43 |
43 /*! |
44 /*! |
44 Class destructor. |
45 Class destructor. |
45 */ |
46 */ |
46 inline ~NmStartParamDataHelper() |
47 inline ~NmStartParamDataHelper() |
47 { |
48 { |
|
49 NM_FUNCTION; |
48 } |
50 } |
49 |
51 |
50 /*! |
52 /*! |
51 Extracts the data from the given QVariant into the class members. |
53 Extracts the data from the given QVariant into the class members. |
52 \param data QVariant containing the data. |
54 \param data QVariant containing the data. |
53 \return True if success, false otherwise. |
55 \return True if success, false otherwise. |
54 */ |
56 */ |
55 inline bool extractData(const QVariant &data) |
57 inline bool extractData(const QVariant &data) |
56 { |
58 { |
57 QVariant::Type dataType = data.type(); |
59 NM_FUNCTION; |
58 bool success = false; |
60 |
59 |
61 bool success(false); |
60 switch (dataType) { |
62 |
61 case QVariant::String: { |
63 if (data.canConvert(QVariant::Map)) { |
62 // The given data contains a single attachment. |
64 // The given data may contain a mail subject and recipient lists. |
63 QString attachment = data.toString(); |
65 QMap<QString, QVariant> map = data.toMap(); |
64 mAttachmentList = new QStringList(attachment); |
66 success = processMap(map); |
65 success = true; |
67 } |
66 break; |
68 else if (data.canConvert(QVariant::StringList)) { |
67 } |
69 QStringList attachmentList = data.toStringList(); |
68 case QVariant::StringList: { |
70 mAttachmentList = new QStringList(attachmentList); |
69 // The given data contains a list of attachments. |
71 success = true; |
70 QStringList attachmentList = data.toStringList(); |
72 } |
71 mAttachmentList = new QStringList(attachmentList); |
73 else { |
72 success = true; |
74 // Data type not supported! |
73 break; |
75 NM_ERROR(1,"NmStartParamDataHelper::extractData(): data type not supported"); |
74 } |
76 } |
75 case QVariant::Map: { |
|
76 // The given data may contain a mail subject and recipient lists. |
|
77 QMap<QString, QVariant> map = data.toMap(); |
|
78 success = processMap(map); |
|
79 break; |
|
80 } |
|
81 default: { |
|
82 // Data type not supported! |
|
83 NMLOG("NmStartParamDataHelper::extractData(): Data type not supported!"); |
|
84 break; |
|
85 } |
|
86 } // switch () |
|
87 |
77 |
88 // Determine the editor start mode. |
78 // Determine the editor start mode. |
89 if (mToAddresses || mCcAddresses || mBccAddresses) { |
79 if (mToAddresses || mCcAddresses || mBccAddresses) { |
90 mEditorStartMode = NmUiEditorMailto; |
80 mEditorStartMode = NmUiEditorMailto; |
91 } |
81 } |
135 \param map The map to extract the data from. |
127 \param map The map to extract the data from. |
136 \return True if success, false otherwise. |
128 \return True if success, false otherwise. |
137 */ |
129 */ |
138 inline bool processMap(const QMap<QString, QVariant> &map) |
130 inline bool processMap(const QMap<QString, QVariant> &map) |
139 { |
131 { |
|
132 NM_FUNCTION; |
|
133 |
140 QMap<QString, QVariant>::const_iterator i = map.constBegin(); |
134 QMap<QString, QVariant>::const_iterator i = map.constBegin(); |
141 QString key; |
135 QString key; |
142 QVariant value; |
136 QVariant value; |
143 |
137 |
144 while (i != map.constEnd()) { |
138 while (i != map.constEnd()) { |
252 */ |
247 */ |
253 NmSendServiceInterface::NmSendServiceInterface(QString interfaceName, |
248 NmSendServiceInterface::NmSendServiceInterface(QString interfaceName, |
254 QObject *parent, |
249 QObject *parent, |
255 NmUiEngine &uiEngine, |
250 NmUiEngine &uiEngine, |
256 NmApplication *application) |
251 NmApplication *application) |
257 #ifndef NM_WINS_ENV |
|
258 : XQServiceProvider(interfaceName, parent), |
252 : XQServiceProvider(interfaceName, parent), |
259 #else |
|
260 : QObject(parent), |
|
261 #endif |
|
262 mApplication(application), |
253 mApplication(application), |
263 mUiEngine(uiEngine), |
254 mUiEngine(uiEngine), |
264 mAsyncReqId(0), |
255 mAsyncReqId(0), |
265 mStartParam(NULL), |
256 mStartParam(NULL), |
266 mSelectionDialog(NULL), |
257 mSelectionDialog(NULL), |
267 mCurrentView(NULL) |
258 mCurrentView(NULL) |
268 { |
259 { |
269 #ifndef NM_WINS_ENV |
|
270 publishAll(); |
260 publishAll(); |
271 #endif |
|
272 } |
261 } |
273 |
262 |
274 |
263 |
275 /*! |
264 /*! |
276 Class desctructor. |
265 Class desctructor. |
277 */ |
266 */ |
278 NmSendServiceInterface::~NmSendServiceInterface() |
267 NmSendServiceInterface::~NmSendServiceInterface() |
279 { |
268 { |
|
269 NM_FUNCTION; |
|
270 |
280 delete mStartParam; |
271 delete mStartParam; |
281 delete mSelectionDialog; |
272 delete mSelectionDialog; |
282 } |
273 } |
283 |
274 |
284 |
275 |
287 \param mailboxId Where the ID of the selected mailbox is set. |
278 \param mailboxId Where the ID of the selected mailbox is set. |
288 \return True if a mailbox was selected, false otherwise. |
279 \return True if a mailbox was selected, false otherwise. |
289 */ |
280 */ |
290 void NmSendServiceInterface::selectionDialogClosed(NmId &mailboxId) |
281 void NmSendServiceInterface::selectionDialogClosed(NmId &mailboxId) |
291 { |
282 { |
292 NMLOG("NmSendServiceInterface::selectionDialogClosed"); |
283 NM_FUNCTION; |
|
284 |
293 if (mailboxId.id()) { // mailbox selected |
285 if (mailboxId.id()) { // mailbox selected |
294 launchEditorView(mailboxId); |
286 launchEditorView(mailboxId); |
295 } |
287 } |
296 else { |
288 else { |
297 cancelService(); |
289 cancelService(); |
309 attach. Can also contain a map with key value pairs containing |
301 attach. Can also contain a map with key value pairs containing |
310 subject and recipient data. |
302 subject and recipient data. |
311 */ |
303 */ |
312 void NmSendServiceInterface::send(QVariant data) |
304 void NmSendServiceInterface::send(QVariant data) |
313 { |
305 { |
314 NMLOG("NmSendServiceInterface::send()"); |
306 NM_FUNCTION; |
315 |
307 |
316 #ifndef NM_WINS_ENV |
308 HbMainWindow *mainWindow(NULL); |
317 HbMainWindow *mainWindow = mApplication->mainWindow(); |
309 |
318 mCurrentView = mainWindow->currentView(); |
310 // Make sure that qmail stays background if user presses back in editorview |
319 |
311 if (mApplication) { |
320 // Hide the current view. |
312 mApplication->updateVisibilityState(); |
321 if (mCurrentView) { |
313 |
322 mCurrentView->hide(); |
314 mainWindow = mApplication->mainWindow(); |
|
315 mCurrentView = mainWindow->currentView(); |
|
316 |
|
317 // Hide the current view. |
|
318 if (mCurrentView) { |
|
319 mCurrentView->hide(); |
|
320 } |
323 } |
321 } |
324 |
322 |
325 // Check the given data. |
323 // Check the given data. |
326 NmStartParamDataHelper dataHelper; |
324 NmStartParamDataHelper dataHelper; |
327 bool validData = dataHelper.extractData(data); |
325 bool validData = dataHelper.extractData(data); |
329 NmMailboxListModel &mailboxListModel = mUiEngine.mailboxListModel(); |
327 NmMailboxListModel &mailboxListModel = mUiEngine.mailboxListModel(); |
330 const int count = mailboxListModel.rowCount(); |
328 const int count = mailboxListModel.rowCount(); |
331 NmId mailboxId(0); |
329 NmId mailboxId(0); |
332 |
330 |
333 mAsyncReqId = setCurrentRequestAsync(); |
331 mAsyncReqId = setCurrentRequestAsync(); |
334 |
332 |
335 if (!validData) { |
333 if (!validData) { |
336 // Failed to extract the data! |
334 // Failed to extract the data! |
337 NMLOG("NmSendServiceInterface::send(): Failed to process the given data!"); |
335 NM_ERROR(1,"NmSendServiceInterface::send(): failed to process the given data"); |
338 cancelService(); |
336 cancelService(); |
339 } |
337 } |
340 else if (count == 0) { |
338 else if (count == 0) { |
341 // No mailboxes. |
|
342 if (mainWindow) { |
|
343 mainWindow->hide(); |
|
344 } |
|
345 |
|
346 // Hide the app if it not embedded |
|
347 if (!XQServiceUtil::isEmbedded()) { |
|
348 XQServiceUtil::toBackground(true); |
|
349 } |
|
350 |
|
351 HbDeviceMessageBox note(hbTrId("txt_mail_dialog_no_mailboxes_defined"), |
339 HbDeviceMessageBox note(hbTrId("txt_mail_dialog_no_mailboxes_defined"), |
352 HbMessageBox::MessageTypeInformation); |
340 HbMessageBox::MessageTypeInformation); |
353 note.setTimeout(HbMessageBox::NoTimeout); |
341 note.setTimeout(HbMessageBox::NoTimeout); |
354 note.exec(); |
342 note.show(); |
|
343 cancelService(); |
|
344 } |
|
345 else { // count > 0 |
355 if (mainWindow) { |
346 if (mainWindow) { |
356 mainWindow->show(); |
347 mainWindow->show(); |
357 } |
348 } |
358 cancelService(); |
|
359 } |
|
360 else { // count > 0 |
|
361 // Make sure the NMail application is in the foreground. |
|
362 XQServiceUtil::toBackground(false); |
|
363 |
349 |
364 mStartParam = new NmUiStartParam( |
350 mStartParam = new NmUiStartParam( |
365 NmUiViewMessageEditor, |
351 NmUiViewMessageEditor, |
366 0, // account id |
352 0, // account id |
367 0, // folder id |
353 0, // folder id |
386 else { // count > 1 |
372 else { // count > 1 |
387 if (!mSelectionDialog) { |
373 if (!mSelectionDialog) { |
388 mSelectionDialog = |
374 mSelectionDialog = |
389 new NmMailboxSelectionDialog(mUiEngine.mailboxListModel()); |
375 new NmMailboxSelectionDialog(mUiEngine.mailboxListModel()); |
390 } |
376 } |
391 connect(mSelectionDialog,SIGNAL(selectionDialogClosed(NmId&)), |
377 |
392 this,SLOT(selectionDialogClosed(NmId&))); |
378 connect(mSelectionDialog, SIGNAL(selectionDialogClosed(NmId&)), |
|
379 this, SLOT(selectionDialogClosed(NmId&))); |
393 mSelectionDialog->open(); |
380 mSelectionDialog->open(); |
394 |
381 |
395 // launch the editor when the dialog is closed |
382 // launch the editor when the dialog is closed |
396 } |
383 } |
397 } |
384 } |
399 |
386 |
400 /*! |
387 /*! |
401 Called when mailbox id is know and editor can be opened |
388 Called when mailbox id is know and editor can be opened |
402 \param mailboxId mailbox using in editor |
389 \param mailboxId mailbox using in editor |
403 */ |
390 */ |
404 void NmSendServiceInterface::launchEditorView(NmId mailboxId) |
391 void NmSendServiceInterface::launchEditorView(NmId mailboxId) |
405 { |
392 { |
406 NMLOG(QString("NmSendServiceInterface::launchEditorView %1").arg(mailboxId.id())); |
393 NM_FUNCTION; |
|
394 NM_COMMENT(QString("NmSendServiceInterface::launchEditorView(): mailboxId=%1").arg(mailboxId.id())); |
|
395 |
407 // Make the previous view visible again. |
396 // Make the previous view visible again. |
408 if (mCurrentView) { |
397 if (mCurrentView) { |
409 mCurrentView->show(); |
398 mCurrentView->show(); |
410 mCurrentView = NULL; |
399 mCurrentView = NULL; |
411 } |
400 } |
412 |
401 |
413 if (mStartParam) { |
402 if (mStartParam) { |
414 mStartParam->setMailboxId(mailboxId); |
403 mStartParam->setMailboxId(mailboxId); |
415 mApplication->enterNmUiView(mStartParam); |
404 mApplication->enterNmUiView(mStartParam); |
416 mStartParam = NULL; // ownership passed |
405 mStartParam = NULL; // ownership passed |
417 } |
406 } |
418 completeRequest(mAsyncReqId, 1); |
407 completeRequest(mAsyncReqId, 1); |
419 } |
408 mAsyncReqId = 0; |
420 |
409 } |
421 void NmSendServiceInterface::cancelService() |
410 |
422 { |
411 void NmSendServiceInterface::cancelService() |
423 NMLOG("NmSendServiceInterface::cancelService"); |
412 { |
|
413 NM_FUNCTION; |
|
414 |
424 delete mStartParam; |
415 delete mStartParam; |
425 mStartParam = NULL; |
416 mStartParam = NULL; |
426 |
417 |
427 // If the service was started as embedded, do not hide the app. |
418 // If the service was started as embedded, do not hide the app. |
428 if (!XQServiceUtil::isEmbedded()) { |
419 if (!XQServiceUtil::isEmbedded()) { |
429 XQServiceUtil::toBackground(true); |
420 XQServiceUtil::toBackground(true); |
430 } |
421 } |
431 |
422 |
432 completeRequest(mAsyncReqId, 0); |
423 completeRequest(mAsyncReqId, 0); |
|
424 mAsyncReqId = 0; |
433 |
425 |
434 // If started as service, the application must be closed now. |
426 // If started as service, the application must be closed now. |
435 if (XQServiceUtil::isService()) { |
427 if (XQServiceUtil::isService()) { |
436 connect(this, SIGNAL(returnValueDelivered()), |
428 connect(this, SIGNAL(returnValueDelivered()), |
437 mApplication, SLOT(delayedExitApplication())); |
429 mApplication, SLOT(delayedExitApplication())); |