56 mWaitDialog(NULL), |
56 mWaitDialog(NULL), |
57 mQueryDialog(NULL), |
57 mQueryDialog(NULL), |
58 mAttachmentPicker(NULL), |
58 mAttachmentPicker(NULL), |
59 mCcBccFieldVisible(false), |
59 mCcBccFieldVisible(false), |
60 mServiceSendingDialog(NULL), |
60 mServiceSendingDialog(NULL), |
61 mIsNotFetchedBefore(true), |
|
62 mHiddenPriorityName(NmPriorityNormal) |
61 mHiddenPriorityName(NmPriorityNormal) |
63 { |
62 { |
64 NM_FUNCTION; |
63 NM_FUNCTION; |
65 |
64 |
66 mDocumentLoader = new HbDocumentLoader(); |
65 mDocumentLoader = new HbDocumentLoader(); |
67 // Set object name |
66 // Set object name |
68 setObjectName("NmEditorView"); |
67 setObjectName("NmEditorView"); |
69 // Set mailbox name to title pane |
|
70 setMailboxName(); |
|
71 // call the createToolBar on load view layout |
68 // call the createToolBar on load view layout |
72 createToolBar(); |
69 createToolBar(); |
73 // Load view layout |
70 // Load view layout |
74 loadViewLayout(); |
71 loadViewLayout(); |
75 } |
72 } |
299 NM_FUNCTION; |
296 NM_FUNCTION; |
300 |
297 |
301 HbMessageBox *dlg = static_cast<HbMessageBox*>(sender()); |
298 HbMessageBox *dlg = static_cast<HbMessageBox*>(sender()); |
302 // The first action in dialogs action list is for the "Yes"-button. |
299 // The first action in dialogs action list is for the "Yes"-button. |
303 if (action == dlg->actions().at(0)) { |
300 if (action == dlg->actions().at(0)) { |
304 |
301 safeToDraft(); |
305 // Update draft message with content. |
|
306 updateMessageWithEditorContents(); |
|
307 |
|
308 // Save message to drafts |
|
309 QList<NmOperation *> preliminaryOperations; |
|
310 if (mAddAttachmentOperation && mAddAttachmentOperation->isRunning()) { |
|
311 preliminaryOperations.append(mAddAttachmentOperation); |
|
312 } |
|
313 if (mRemoveAttachmentOperation && mRemoveAttachmentOperation->isRunning()) { |
|
314 preliminaryOperations.append(mRemoveAttachmentOperation); |
|
315 } |
|
316 // ownership of mMessage is transferred |
|
317 // NmOperations are automatically deleted after completion |
|
318 mUiEngine.saveDraftMessage(mMessage, preliminaryOperations); |
|
319 mMessage = NULL; |
|
320 preliminaryOperations.clear(); |
|
321 } |
302 } |
322 |
303 |
323 // Close the view |
304 // Close the view |
324 QMetaObject::invokeMethod(&mApplication, |
305 QMetaObject::invokeMethod(&mApplication, |
325 "popView", |
306 "popView", |
326 Qt::QueuedConnection); |
307 Qt::QueuedConnection); |
327 } |
308 } |
328 |
309 |
329 /*! |
310 /*! |
|
311 Public slot to handle draft saving. |
|
312 */ |
|
313 void NmEditorView::safeToDraft() |
|
314 { |
|
315 // Update draft message with content. |
|
316 updateMessageWithEditorContents(); |
|
317 |
|
318 // Save message to drafts |
|
319 QList<NmOperation *> preliminaryOperations; |
|
320 if (mAddAttachmentOperation && mAddAttachmentOperation->isRunning()) { |
|
321 preliminaryOperations.append(mAddAttachmentOperation); |
|
322 } |
|
323 if (mRemoveAttachmentOperation && mRemoveAttachmentOperation->isRunning()) { |
|
324 preliminaryOperations.append(mRemoveAttachmentOperation); |
|
325 } |
|
326 // ownership of mMessage is transferred |
|
327 // NmOperations are automatically deleted after completion |
|
328 mUiEngine.saveDraftMessage(mMessage, preliminaryOperations); |
|
329 mMessage = NULL; |
|
330 preliminaryOperations.clear(); |
|
331 } |
|
332 |
|
333 /*! |
330 About to exit view. Application calls this function when user has |
334 About to exit view. Application calls this function when user has |
331 pressed back key and editor needs to delete the draft message. This is |
335 pressed back key and editor needs to delete the draft message. This is |
332 called when "auto-exiting" after a successful mail sending. |
336 called when "auto-exiting" after a successful mail sending. |
333 */ |
337 */ |
334 void NmEditorView::aboutToExitView() |
338 void NmEditorView::aboutToExitView() |
354 Lazy loading when view layout has been loaded |
358 Lazy loading when view layout has been loaded |
355 */ |
359 */ |
356 void NmEditorView::viewReady() |
360 void NmEditorView::viewReady() |
357 { |
361 { |
358 NM_FUNCTION; |
362 NM_FUNCTION; |
|
363 |
|
364 // Set mailbox name to title pane |
|
365 setMailboxName(); |
359 |
366 |
360 // Connect options menu about to show to create options menu function |
367 // Connect options menu about to show to create options menu function |
361 // Menu needs to be create "just-in-time" |
368 // Menu needs to be create "just-in-time" |
362 connect(menu(), SIGNAL(aboutToShow()), this, SLOT(createOptionsMenu())); |
369 connect(menu(), SIGNAL(aboutToShow()), this, SLOT(createOptionsMenu())); |
363 NmAction *dummy = new NmAction(0); |
370 NmAction *dummy = new NmAction(0); |
387 fetchMessageIfNeeded(*mStartParam); |
394 fetchMessageIfNeeded(*mStartParam); |
388 } |
395 } |
389 else { // execution cannot proceed without start param |
396 else { // execution cannot proceed without start param |
390 QMetaObject::invokeMethod(&mApplication, "popView", Qt::QueuedConnection); |
397 QMetaObject::invokeMethod(&mApplication, "popView", Qt::QueuedConnection); |
391 } |
398 } |
|
399 |
|
400 // Adjust the header width according to the current screen width. |
|
401 mHeaderWidget->adjustHeaderWidth(); |
392 } |
402 } |
393 |
403 |
394 /*! |
404 /*! |
395 If entering editor for forwarding or replying, use attachment manager |
405 If entering editor for forwarding or replying, use attachment manager |
396 to check that we have all message parts fetched. Also show dialog for |
406 to check that we have all message parts fetched. Also show dialog for |
398 */ |
408 */ |
399 void NmEditorView::fetchMessageIfNeeded(NmUiStartParam &startParam) |
409 void NmEditorView::fetchMessageIfNeeded(NmUiStartParam &startParam) |
400 { |
410 { |
401 NM_FUNCTION; |
411 NM_FUNCTION; |
402 |
412 |
403 if (mIsNotFetchedBefore == true) { |
413 if (startParam.editorStartMode() == NmUiEditorForward |
404 if (startParam.editorStartMode() == NmUiEditorForward |
414 || startParam.editorStartMode()== NmUiEditorReply |
405 || startParam.editorStartMode()== NmUiEditorReply |
415 || startParam.editorStartMode() == NmUiEditorReplyAll) { |
406 || startParam.editorStartMode() == NmUiEditorReplyAll) { |
416 |
407 |
417 fetchProgressDialogShow(); |
408 fetchProgressDialogShow(); |
418 mAttaManager.clearObserver(); |
409 mAttaManager.clearObserver(); |
419 mAttaManager.setObserver(this); |
410 mAttaManager.setObserver(this); |
420 mAttaManager.fetchAllMessageParts( |
411 mAttaManager.fetchAllMessageParts( |
421 startParam.mailboxId(), |
412 startParam.mailboxId(), |
422 startParam.folderId(), |
413 startParam.folderId(), |
423 startParam.messageId()); |
414 startParam.messageId()); |
424 } |
415 } |
425 else { |
416 else { |
426 startMessageCreation(startParam); |
417 startMessageCreation(startParam); |
|
418 } |
|
419 |
|
420 mIsNotFetchedBefore = false; |
|
421 } |
427 } |
422 } |
428 } |
423 |
429 |
424 /*! |
430 /*! |
425 Slot. Called when attachments fetch progress changes. |
431 Slot. Called when attachments fetch progress changes. |
441 |
447 |
442 if (result == NmNoError && mStartParam) { |
448 if (result == NmNoError && mStartParam) { |
443 startMessageCreation(*mStartParam); |
449 startMessageCreation(*mStartParam); |
444 } |
450 } |
445 else { |
451 else { |
446 // Show the fetching failed note only when |
452 // Close "Loading mail content" dialog |
447 // the error is not Device/System errors, |
453 mWaitDialog->close(); |
|
454 |
|
455 // Show a fetching failed note when the failure is not caused by a Device/System failure. |
448 if (result != NmNoError && |
456 if (result != NmNoError && |
449 result != NmNotFoundError && |
457 result != NmNotFoundError && |
450 result != NmGeneralError && |
458 result != NmGeneralError && |
451 result != NmCancelError && |
459 result != NmCancelError && |
452 result != NmAuthenticationError && |
460 result != NmAuthenticationError && |
453 result != NmServerConnectionError && |
461 result != NmServerConnectionError && |
454 result != NmConnectionError) { |
462 result != NmConnectionError) { |
455 |
463 HbNotificationDialog *note = new HbNotificationDialog(); |
456 HbNotificationDialog *note = new HbNotificationDialog(); |
|
457 |
|
458 bool enalbeAttribute(true); |
464 bool enalbeAttribute(true); |
459 note->setAttribute(Qt::WA_DeleteOnClose, enalbeAttribute); |
465 note->setAttribute(Qt::WA_DeleteOnClose, enalbeAttribute); |
460 |
466 note->setIcon(HbIcon(QLatin1String("note_warning"))); |
461 note->setIcon(HbIcon(QLatin1String("note_warning"))); |
|
462 |
|
463 note->setTitle(hbTrId("txt_mail_dpopinfo_loading_failed")); |
467 note->setTitle(hbTrId("txt_mail_dpopinfo_loading_failed")); |
464 note->setTitleTextWrapping(Hb::TextWordWrap); |
468 note->setTitleTextWrapping(Hb::TextWordWrap); |
465 |
|
466 note->setDismissPolicy(HbNotificationDialog::TapAnywhere); |
469 note->setDismissPolicy(HbNotificationDialog::TapAnywhere); |
467 note->setTimeout(HbNotificationDialog::StandardTimeout); |
470 note->setTimeout(HbNotificationDialog::StandardTimeout); |
468 |
|
469 note->setSequentialShow(true); |
471 note->setSequentialShow(true); |
470 note->show(); |
472 note->show(); |
471 } |
473 } |
472 |
474 |
473 mWaitDialog->close(); |
475 // Go back to Viewer view |
474 QMetaObject::invokeMethod(&mApplication, "popView", Qt::QueuedConnection); |
476 QMetaObject::invokeMethod(&mApplication, "popView", Qt::QueuedConnection); |
475 } |
477 } |
476 } |
478 } |
477 |
479 |
478 void NmEditorView::fetchProgressDialogShow() |
480 void NmEditorView::fetchProgressDialogShow() |
496 */ |
498 */ |
497 void NmEditorView::fetchProgressDialogCancelled() |
499 void NmEditorView::fetchProgressDialogCancelled() |
498 { |
500 { |
499 NM_FUNCTION; |
501 NM_FUNCTION; |
500 |
502 |
501 if (mAttaManager.isFetching()) { |
503 if (mAttaManager.isFetching()) { |
502 mAttaManager.cancelFetch(); |
504 mAttaManager.cancelFetch(); |
503 mAttaManager.clearObserver(); |
505 mAttaManager.clearObserver(); |
504 } |
506 } |
505 QMetaObject::invokeMethod(&mApplication, "popView", Qt::QueuedConnection); |
507 else { |
|
508 // For those email has no attachment or attachment has fetched. |
|
509 // Go back to Viewer view. |
|
510 QMetaObject::invokeMethod(&mApplication, "popView", Qt::QueuedConnection); |
|
511 } |
506 } |
512 } |
507 |
513 |
508 void NmEditorView::startMessageCreation(NmUiStartParam &startParam) |
514 void NmEditorView::startMessageCreation(NmUiStartParam &startParam) |
509 { |
515 { |
510 NM_FUNCTION; |
516 NM_FUNCTION; |
564 NmUtilities::getRecipientsFromMessage(*mMessage, invalidAddresses, NmUtilities::NmInvalidAddress); |
570 NmUtilities::getRecipientsFromMessage(*mMessage, invalidAddresses, NmUtilities::NmInvalidAddress); |
565 } |
571 } |
566 |
572 |
567 if (invalidAddresses.count() > 0) { |
573 if (invalidAddresses.count() > 0) { |
568 |
574 |
569 // invalid addresses found, verify send from user |
575 // Invalid addresses found, verify send from user. |
570 QString noteText = hbTrId("txt_mail_dialog_invalid_mail_address_send"); |
576 // Set the first failing address to the note. |
571 // set the first failing address to the note |
577 QString noteText = |
572 noteText = noteText.arg(invalidAddresses.at(0).address()); |
578 HbParameterLengthLimiter( |
|
579 "txt_mail_dialog_invalid_mail_address_send" |
|
580 ).arg(invalidAddresses.at(0).address()); |
573 |
581 |
574 if (mQueryDialog) { |
582 if (mQueryDialog) { |
575 delete mQueryDialog; |
583 delete mQueryDialog; |
576 mQueryDialog = 0; |
584 mQueryDialog = 0; |
577 } |
585 } |
788 mContent->header()->bccEdit()->setPlainText(bccAddressesString); |
796 mContent->header()->bccEdit()->setPlainText(bccAddressesString); |
789 |
797 |
790 if (ccAddressesString.length() || bccAddressesString.length()) { |
798 if (ccAddressesString.length() || bccAddressesString.length()) { |
791 // Since cc or/and bcc recipients exist, expand the group box to display |
799 // Since cc or/and bcc recipients exist, expand the group box to display |
792 // the addresses by expanding the group box. |
800 // the addresses by expanding the group box. |
793 mContent->header()->setFieldVisibility(true); |
801 mCcBccFieldVisible = true; |
|
802 mHeaderWidget->setFieldVisibility(mCcBccFieldVisible); |
794 } |
803 } |
795 |
804 |
796 // Set subject. |
805 // Set subject. |
797 if (useStartParam) { |
806 if (useStartParam) { |
798 QString *subject = mStartParam->subject(); |
807 QString *subject = mStartParam->subject(); |
811 if (editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll) { |
820 if (editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll) { |
812 //Clear the importance flag. Replied messages dont keep the importance |
821 //Clear the importance flag. Replied messages dont keep the importance |
813 setPriority(NmActionResponseCommandNone); |
822 setPriority(NmActionResponseCommandNone); |
814 } |
823 } |
815 mHeaderWidget->setPriority(messageEnvelope.priority()); |
824 mHeaderWidget->setPriority(messageEnvelope.priority()); |
|
825 |
|
826 NmMessage *originalMessage = NULL; |
816 |
827 |
817 // Set the message body. |
828 // Set the message body. |
818 if (editorStartMode==NmUiEditorReply|| |
829 if (editorStartMode==NmUiEditorReply|| |
819 editorStartMode==NmUiEditorReplyAll|| |
830 editorStartMode==NmUiEditorReplyAll|| |
820 editorStartMode==NmUiEditorForward|| |
831 editorStartMode==NmUiEditorForward|| |
821 editorStartMode==NmUiEditorFromDrafts){ |
832 editorStartMode==NmUiEditorFromDrafts){ |
822 |
833 |
823 // Use the body from the original message. |
834 // Use the body from the original message. |
824 NmMessage *originalMessage = mUiEngine.message(mStartParam->mailboxId(), |
835 originalMessage = mUiEngine.message(mStartParam->mailboxId(), |
825 mStartParam->folderId(), |
836 mStartParam->folderId(), |
826 mStartParam->messageId()); |
837 mStartParam->messageId()); |
827 |
838 |
828 if (originalMessage) { |
839 if (originalMessage) { |
829 NmMessagePart *plainPart = originalMessage->plainTextBodyPart(); |
840 NmMessagePart *plainPart = originalMessage->plainTextBodyPart(); |
830 |
841 |
831 if (plainPart) { |
842 if (plainPart) { |
842 originalMessage->envelope().folderId(), |
853 originalMessage->envelope().folderId(), |
843 originalMessage->envelope().messageId(), |
854 originalMessage->envelope().messageId(), |
844 *htmlPart); |
855 *htmlPart); |
845 } |
856 } |
846 |
857 |
847 mContent->setMessageData(*originalMessage, editorStartMode); |
858 } |
848 } |
859 |
849 |
860 } |
850 delete originalMessage; |
861 |
851 originalMessage = NULL; |
862 QString *signature = NULL; |
852 } |
863 // return value is not relevant here |
853 |
864 mUiEngine.getSignature(mStartParam->mailboxId(), signature); |
|
865 |
|
866 mContent->setBodyContent(editorStartMode, originalMessage, signature); |
|
867 |
|
868 delete signature; |
|
869 signature = NULL; |
|
870 |
|
871 delete originalMessage; |
|
872 originalMessage = NULL; |
|
873 |
854 // Get list of attachments from the message and set those into UI attachment list |
874 // Get list of attachments from the message and set those into UI attachment list |
855 QList<NmMessagePart*> attachments; |
875 QList<NmMessagePart*> attachments; |
856 mMessage->attachmentList(attachments); |
876 mMessage->attachmentList(attachments); |
857 |
877 |
858 for (int i=0; i<attachments.count(); i++) { |
878 for (int i=0; i<attachments.count(); i++) { |
899 HbToolBarExtension* extension = new HbToolBarExtension(); |
919 HbToolBarExtension* extension = new HbToolBarExtension(); |
900 mAttachmentPicker = new NmAttachmentPicker(this); |
920 mAttachmentPicker = new NmAttachmentPicker(this); |
901 |
921 |
902 if (extension && mAttachmentPicker) { |
922 if (extension && mAttachmentPicker) { |
903 connect(mAttachmentPicker, SIGNAL(attachmentsFetchOk(const QVariant &)), |
923 connect(mAttachmentPicker, SIGNAL(attachmentsFetchOk(const QVariant &)), |
904 this, SLOT(onAttachmentReqCompleted(const QVariant &))); |
924 this, SLOT(onAttachmentReqCompleted(const QVariant &))); |
905 |
925 |
|
926 connect(this, SIGNAL(titleChanged(QString)), mAttachmentPicker, |
|
927 SLOT(setTitle(QString))); |
|
928 |
906 list[i]->setToolBarExtension(extension); |
929 list[i]->setToolBarExtension(extension); |
907 |
930 |
908 //content widget to get the items to a list |
931 //content widget to get the items to a list |
909 mTBExtnContentWidget = new HbListWidget(); |
932 mTBExtnContentWidget = new HbListWidget(); |
910 mTBExtnContentWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); |
933 mTBExtnContentWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); |
1543 int count = toolbarList.count(); |
1566 int count = toolbarList.count(); |
1544 for (int i = 0; i < count; i++) { |
1567 for (int i = 0; i < count; i++) { |
1545 NmAction *action = static_cast<NmAction *>(toolbarList[i]); |
1568 NmAction *action = static_cast<NmAction *>(toolbarList[i]); |
1546 if (action->availabilityCondition() == NmAction::NmAttachable) { |
1569 if (action->availabilityCondition() == NmAction::NmAttachable) { |
1547 action->setEnabled(enable); |
1570 action->setEnabled(enable); |
1548 } |
1571 if (enable) { |
1549 } |
1572 // For some reason 'Add attachment' toolbar button stays dimmed sometimes, |
1550 } |
1573 // showItems will fix the situation. |
1551 } |
1574 showItems(Hb::ToolBarItem); |
|
1575 } |
|
1576 } |
|
1577 } |
|
1578 } |
|
1579 } |