305 from another application. The method sets the given data (e.g. recipients, |
305 from another application. The method sets the given data (e.g. recipients, |
306 attachments) to a mail composer (editor) view and displays it. |
306 attachments) to a mail composer (editor) view and displays it. |
307 |
307 |
308 \param data If used by Share UI, will contain the list of filenames to |
308 \param data If used by Share UI, will contain the list of filenames to |
309 attach. Can also contain a map with key value pairs containing |
309 attach. Can also contain a map with key value pairs containing |
310 subject and recipient data. |
310 subject and recipient data. |
311 */ |
311 */ |
312 void NmSendServiceInterface::send(QVariant data) |
312 void NmSendServiceInterface::send(QVariant data) |
313 { |
313 { |
314 NMLOG("NmSendServiceInterface::send()"); |
314 NMLOG("NmSendServiceInterface::send()"); |
315 |
315 |
316 #ifndef NM_WINS_ENV |
316 #ifndef NM_WINS_ENV |
317 // Make sure the NMail application is on the foreground. |
|
318 XQServiceUtil::toBackground(false); |
|
319 HbMainWindow *mainWindow = mApplication->mainWindow(); |
317 HbMainWindow *mainWindow = mApplication->mainWindow(); |
320 HbView *currentView = mainWindow->currentView(); |
318 mCurrentView = mainWindow->currentView(); |
321 |
319 |
322 // Hide the current view. |
320 // Hide the current view. |
323 if (currentView) { |
321 if (mCurrentView) { |
324 currentView->hide(); |
322 mCurrentView->hide(); |
325 } |
323 } |
326 |
324 |
327 // Check the given data. |
325 // Check the given data. |
328 NmStartParamDataHelper dataHelper; |
326 NmStartParamDataHelper dataHelper; |
329 bool validData = dataHelper.extractData(data); |
327 bool validData = dataHelper.extractData(data); |
330 |
328 |
331 NmMailboxListModel &mailboxListModel = mUiEngine.mailboxListModel(); |
329 NmMailboxListModel &mailboxListModel = mUiEngine.mailboxListModel(); |
332 const int count = mailboxListModel.rowCount(); |
330 const int count = mailboxListModel.rowCount(); |
333 NmId mailboxId(0); |
331 NmId mailboxId(0); |
334 bool launchEditor(true); |
332 |
335 |
333 mAsyncReqId = setCurrentRequestAsync(); |
|
334 |
336 if (!validData) { |
335 if (!validData) { |
337 // Failed to extract the data! |
336 // Failed to extract the data! |
338 NMLOG("NmSendServiceInterface::send(): Failed to process the given data!"); |
337 NMLOG("NmSendServiceInterface::send(): Failed to process the given data!"); |
339 launchEditor = false; |
338 cancelService(); |
340 } |
339 } |
341 else if (count == 0) { |
340 else if (count == 0) { |
342 // No mailboxes. |
341 // No mailboxes. |
343 HbMessageBox note(hbTrId("txt_mail_dialog_no_mailboxes_defined"), |
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"), |
344 HbMessageBox::MessageTypeInformation); |
352 HbMessageBox::MessageTypeInformation); |
345 note.setTimeout(HbMessageBox::NoTimeout); |
353 note.setTimeout(HbMessageBox::NoTimeout); |
346 note.exec(); |
354 note.exec(); |
347 launchEditor = false; |
355 if (mainWindow) { |
348 } |
356 mainWindow->show(); |
349 else if (count == 1) { |
357 } |
350 // A single mailbox exists. |
358 cancelService(); |
351 QModelIndex modelIndex = mailboxListModel.index(0, 0); |
359 } |
352 QVariant mailbox(mailboxListModel.data(modelIndex)); |
360 else { // count > 0 |
353 NmMailboxMetaData *mailboxMetaData = mailbox.value<NmMailboxMetaData*>(); |
361 // Make sure the NMail application is in the foreground. |
354 mailboxId = mailboxMetaData->id(); |
362 XQServiceUtil::toBackground(false); |
355 } |
363 |
356 else if (count > 1 && !selectMailbox(mailboxId)) { |
364 mStartParam = new NmUiStartParam( |
357 // More than one mailboxes exist but the user cancelled the mailbox |
365 NmUiViewMessageEditor, |
358 // selection dialog. |
366 0, // account id |
359 launchEditor = false; |
367 0, // folder id |
360 } |
368 0, // message id |
361 |
369 dataHelper.mEditorStartMode, // editor start mode |
362 mAsyncReqId = setCurrentRequestAsync(); |
370 dataHelper.mToAddresses, // address list |
|
371 dataHelper.mAttachmentList, // attachment list |
|
372 true, // start as service |
|
373 dataHelper.mSubject, // message subject |
|
374 dataHelper.mCcAddresses, // list containing cc recipient addresses |
|
375 dataHelper.mBccAddresses // list containing bcc recipient addresses |
|
376 ); |
|
377 |
|
378 if (count == 1) { |
|
379 // A single mailbox exists. |
|
380 QModelIndex modelIndex = mailboxListModel.index(0, 0); |
|
381 QVariant mailbox(mailboxListModel.data(modelIndex)); |
|
382 NmMailboxMetaData *mailboxMetaData = mailbox.value<NmMailboxMetaData*>(); |
|
383 mailboxId = mailboxMetaData->id(); |
|
384 launchEditorView(mailboxId); |
|
385 } |
|
386 else { // count > 1 |
|
387 if (!mSelectionDialog) { |
|
388 mSelectionDialog = |
|
389 new NmMailboxSelectionDialog(mUiEngine.mailboxListModel()); |
|
390 } |
|
391 connect(mSelectionDialog,SIGNAL(selectionDialogClosed(NmId&)), |
|
392 this,SLOT(selectionDialogClosed(NmId&))); |
|
393 mSelectionDialog->open(); |
|
394 |
|
395 // launch the editor when the dialog is closed |
|
396 } |
|
397 } |
|
398 } |
|
399 |
|
400 /*! |
|
401 Called when mailbox id is know and editor can be opened |
|
402 \param mailboxId mailbox using in editor |
|
403 */ |
|
404 void NmSendServiceInterface::launchEditorView(NmId mailboxId) |
|
405 { |
|
406 NMLOG(QString("NmSendServiceInterface::launchEditorView %1").arg(mailboxId.id())); |
|
407 // Make the previous view visible again. |
|
408 if (mCurrentView) { |
|
409 mCurrentView->show(); |
|
410 mCurrentView = NULL; |
|
411 } |
363 |
412 |
364 if (launchEditor) { |
413 if (mStartParam) { |
365 // Make the previous view visible again. |
414 mStartParam->setMailboxId(mailboxId); |
366 if (currentView) { |
415 mApplication->enterNmUiView(mStartParam); |
367 currentView->show(); |
416 mStartParam = NULL; // ownership passed |
368 } |
417 } |
369 |
418 completeRequest(mAsyncReqId, 1); |
370 NmUiStartParam *startParam = new NmUiStartParam( |
419 } |
371 NmUiViewMessageEditor, |
420 |
372 mailboxId, |
421 void NmSendServiceInterface::cancelService() |
373 0, // folder id |
422 { |
374 0, // message id |
423 NMLOG("NmSendServiceInterface::cancelService"); |
375 dataHelper.mEditorStartMode, // editor start mode |
424 delete mStartParam; |
376 dataHelper.mToAddresses, // address list |
425 mStartParam = NULL; |
377 dataHelper.mAttachmentList, // attachment list |
426 |
378 true, // start as service |
427 // If the service was started as embedded, do not hide the app. |
379 dataHelper.mSubject, // message subject |
428 if (!XQServiceUtil::isEmbedded()) { |
380 dataHelper.mCcAddresses, // list containing cc recipient addresses |
429 XQServiceUtil::toBackground(true); |
381 dataHelper.mBccAddresses // list containing bcc recipient addresses |
430 } |
382 ); |
431 |
383 |
432 completeRequest(mAsyncReqId, 0); |
384 mApplication->enterNmUiView(startParam); |
433 |
385 completeRequest(mAsyncReqId, 1); |
434 // If started as service, the application must be closed now. |
386 } |
435 if (XQServiceUtil::isService()) { |
|
436 connect(this, SIGNAL(returnValueDelivered()), |
|
437 mApplication, SLOT(delayedExitApplication())); |
|
438 } |
387 else { |
439 else { |
388 // Delete the extracted data since the editor was not launched and thus |
440 // Make the previous view visible again |
389 // NmUiStartParam did not take the ownership of the data. |
441 if (mCurrentView) { |
390 dataHelper.deleteData(); |
442 mCurrentView->show(); |
391 |
443 mCurrentView = NULL; |
392 // If the service was started as embedded, do not hide the app. |
444 } |
393 if (!XQServiceUtil::isEmbedded()) { |
445 } |
394 XQServiceUtil::toBackground(true); |
446 } |
395 } |
447 |
396 |
|
397 completeRequest(mAsyncReqId, 0); |
|
398 |
|
399 // If started as service, the application must be closed now. |
|
400 if (XQServiceUtil::isService()) { |
|
401 connect(this, SIGNAL(returnValueDelivered()), |
|
402 mApplication, SLOT(delayedExitApplication())); |
|
403 } |
|
404 else { |
|
405 // Make the previous view visible again. |
|
406 if (currentView) { |
|
407 currentView->show(); |
|
408 } |
|
409 } |
|
410 } |
|
411 #endif /* NM_WINS_ENV */ |
448 #endif /* NM_WINS_ENV */ |
412 } |
449 |
413 |
450 |
414 |
451 |
415 // End of file. |
452 // End of file. |