37 NmEditorView::NmEditorView( |
37 NmEditorView::NmEditorView( |
38 NmApplication &application, |
38 NmApplication &application, |
39 NmUiStartParam* startParam, |
39 NmUiStartParam* startParam, |
40 NmUiEngine &uiEngine, |
40 NmUiEngine &uiEngine, |
41 QGraphicsItem *parent) |
41 QGraphicsItem *parent) |
42 : NmBaseView(startParam, parent), |
42 : NmBaseView(startParam, application, parent), |
43 mApplication(application), |
43 mApplication(application), |
44 mUiEngine(uiEngine), |
44 mUiEngine(uiEngine), |
45 mDocumentLoader(NULL), |
45 mDocumentLoader(NULL), |
46 mScrollArea(NULL), |
46 mScrollArea(NULL), |
47 mEditWidget(NULL), |
47 mEditWidget(NULL), |
52 mMessageCreationOperation(NULL), |
52 mMessageCreationOperation(NULL), |
53 mAddAttachmentOperation(NULL), |
53 mAddAttachmentOperation(NULL), |
54 mRemoveAttachmentOperation(NULL), |
54 mRemoveAttachmentOperation(NULL), |
55 mCheckOutboxOperation(NULL), |
55 mCheckOutboxOperation(NULL), |
56 mWaitDialog(NULL), |
56 mWaitDialog(NULL), |
57 mAttachmentPicker(NULL) |
57 mQueryDialog(NULL), |
|
58 mAttachmentPicker(NULL), |
|
59 mCcBccFieldVisible(false) |
58 { |
60 { |
59 mDocumentLoader = new HbDocumentLoader(); |
61 mDocumentLoader = new HbDocumentLoader(); |
60 // Set object name |
62 // Set object name |
61 setObjectName("NmEditorView"); |
63 setObjectName("NmEditorView"); |
62 // Set mailbox name to title pane |
64 // Set mailbox name to title pane |
202 { |
205 { |
203 return mScrollAreaContents; |
206 return mScrollAreaContents; |
204 } |
207 } |
205 |
208 |
206 /* |
209 /* |
207 Query user if we want to exit the editor |
210 Launch dialog for query user if we want to exit the editor |
208 */ |
211 */ |
209 bool NmEditorView::okToExitView() |
212 void NmEditorView::okToExitView() |
210 { |
213 { |
|
214 NmEditorHeader *header = mContentWidget->header(); |
|
215 |
211 bool okToExit = true; |
216 bool okToExit = true; |
212 |
|
213 NmEditorHeader *header = mContentWidget->header(); |
|
214 |
217 |
215 // show the query if the message has not been sent |
218 // show the query if the message has not been sent |
216 if (mMessage && header) { |
219 if (mMessage && header) { |
217 // see if editor has any content |
220 // see if editor has any content |
218 int toTextLength = 0; |
221 int toTextLength = 0; |
219 if (header->toField()) { |
222 if (header->toEdit()) { |
220 toTextLength = header->toField()->text().length(); |
223 toTextLength = header->toEdit()->text().length(); |
221 } |
224 } |
222 |
225 |
223 int ccTextLength = 0; |
226 int ccTextLength = 0; |
224 if (header->ccField()) { |
227 if (header->ccEdit()) { |
225 ccTextLength = header->ccField()->text().length(); |
228 ccTextLength = header->ccEdit()->text().length(); |
226 } |
229 } |
227 |
230 |
228 int bccTextLength = 0; |
231 int bccTextLength = 0; |
229 if (header->bccField()) { |
232 if (header->bccEdit()) { |
230 bccTextLength = header->bccField()->text().length(); |
233 bccTextLength = header->bccEdit()->text().length(); |
231 } |
234 } |
232 |
235 |
233 int subjectLength = 0; |
236 int subjectLength = 0; |
234 if (header->subjectField()) { |
237 if (header->subjectEdit()) { |
235 subjectLength = header->subjectField()->text().length(); |
238 subjectLength = header->subjectEdit()->text().length(); |
236 } |
239 } |
237 |
240 |
238 QList<NmMessagePart*> attachmentList; |
241 QList<NmMessagePart*> attachmentList; |
239 mMessage->attachmentList(attachmentList); |
242 mMessage->attachmentList(attachmentList); |
240 |
243 |
242 subjectLength == 0 && mContentWidget->editor()->document()->isEmpty() && |
245 subjectLength == 0 && mContentWidget->editor()->document()->isEmpty() && |
243 attachmentList.count() < 1); |
246 attachmentList.count() < 1); |
244 |
247 |
245 // content exists, verify exit from user |
248 // content exists, verify exit from user |
246 if (!okToExit) { |
249 if (!okToExit) { |
247 okToExit = NmUtilities::displayQuestionNote(hbTrId("txt_mail_dialog_delete_message")); |
250 if (mQueryDialog) { |
248 } |
251 delete mQueryDialog; |
249 } |
252 mQueryDialog = 0; |
250 |
253 } |
251 return okToExit; |
254 // Launch query dialog. |
|
255 mQueryDialog = NmUtilities::displayQuestionNote(hbTrId("txt_mail_dialog_delete_message"), |
|
256 this, |
|
257 SLOT(okToExitQuery(HbAction*))); |
|
258 } |
|
259 } |
|
260 |
|
261 // no need to query anything, just exit. |
|
262 if(okToExit) { |
|
263 QMetaObject::invokeMethod(&mApplication, |
|
264 "popView", |
|
265 Qt::QueuedConnection); |
|
266 } |
|
267 } |
|
268 |
|
269 /*! |
|
270 Handle the user selection is it ok to exit. |
|
271 */ |
|
272 void NmEditorView::okToExitQuery(HbAction* action) |
|
273 { |
|
274 // Check that 'Yes' button was pressed. Use loc string 'txt_mail_dialog_yes' when possible. |
|
275 if (action->text() == "Yes") { |
|
276 QMetaObject::invokeMethod(&mApplication, |
|
277 "popView", |
|
278 Qt::QueuedConnection); |
|
279 } |
252 } |
280 } |
253 |
281 |
254 /*! |
282 /*! |
255 About to exit view. Application calls this function when user has |
283 About to exit view. Application calls this function when user has |
256 pressed back key and editor needs to delete the draft message. This is |
284 pressed back key and editor needs to delete the draft message. This is |
422 QList<NmAddress> invalidAddresses; |
450 QList<NmAddress> invalidAddresses; |
423 if (mMessage) { |
451 if (mMessage) { |
424 NmUtilities::getRecipientsFromMessage(*mMessage, invalidAddresses, NmUtilities::InvalidAddress); |
452 NmUtilities::getRecipientsFromMessage(*mMessage, invalidAddresses, NmUtilities::InvalidAddress); |
425 } |
453 } |
426 |
454 |
427 bool okToSend = true; |
|
428 if (invalidAddresses.count() > 0) { |
455 if (invalidAddresses.count() > 0) { |
429 |
456 |
430 // invalid addresses found, verify send from user |
457 // invalid addresses found, verify send from user |
431 QString noteText = hbTrId("txt_mail_dialog_invalid_mail_address_send"); |
458 QString noteText = hbTrId("txt_mail_dialog_invalid_mail_address_send"); |
432 // set the first failing address to the note |
459 // set the first failing address to the note |
433 noteText = noteText.arg(invalidAddresses.at(0).address()); |
460 noteText = noteText.arg(invalidAddresses.at(0).address()); |
434 okToSend = NmUtilities::displayQuestionNote(noteText); |
461 |
435 } |
462 if (mQueryDialog) { |
436 |
463 delete mQueryDialog; |
437 if (okToSend) { |
464 mQueryDialog = 0; |
438 QList<NmOperation *> preliminaryOperations; |
465 } |
439 preliminaryOperations.append(mAddAttachmentOperation); |
466 // Launch query dialog. Pressing "yes" will finalize the sending. |
440 preliminaryOperations.append(mRemoveAttachmentOperation); |
467 mQueryDialog = NmUtilities::displayQuestionNote(noteText, |
441 // ownership of mMessage is transferred |
468 this, |
442 // NmOperations are automatically deleted after completion |
469 SLOT(invalidAddressQuery(HbAction*))); |
443 mUiEngine.sendMessage(mMessage, preliminaryOperations); |
470 } |
444 mMessage = NULL; |
471 else { |
445 preliminaryOperations.clear(); |
472 // no need to ask anything, just send |
446 mApplication.popView(); |
473 finalizeSending(); |
|
474 } |
|
475 } |
|
476 |
|
477 /*! |
|
478 Send the message after all checks have been done. |
|
479 */ |
|
480 void NmEditorView::finalizeSending() |
|
481 { |
|
482 QList<NmOperation *> preliminaryOperations; |
|
483 preliminaryOperations.append(mAddAttachmentOperation); |
|
484 preliminaryOperations.append(mRemoveAttachmentOperation); |
|
485 // ownership of mMessage is transferred |
|
486 // NmOperations are automatically deleted after completion |
|
487 mUiEngine.sendMessage(mMessage, preliminaryOperations); |
|
488 mMessage = NULL; |
|
489 preliminaryOperations.clear(); |
|
490 // Must use delayed editor view destruction so that query dialog |
|
491 // (which has signaled this) gets time to complete. |
|
492 QMetaObject::invokeMethod(&mApplication, |
|
493 "popView", |
|
494 Qt::QueuedConnection); |
|
495 } |
|
496 |
|
497 /*! |
|
498 Handle the user selection for invalid address query which was started by startSending. |
|
499 */ |
|
500 void NmEditorView::invalidAddressQuery(HbAction* action) |
|
501 { |
|
502 // Check that 'Yes' button was pressed. Use loc string 'txt_mail_dialog_yes' when possible. |
|
503 if (action->text() == "Yes") { |
|
504 finalizeSending(); |
447 } |
505 } |
448 } |
506 } |
449 |
507 |
450 /*! |
508 /*! |
451 This is signalled by mMessageCreationOperation when message is created. |
509 This is signalled by mMessageCreationOperation when message is created. |
483 if (bodyPart) { |
541 if (bodyPart) { |
484 bodyPart->setTextContent(mContentWidget->editor()->toPlainText(), NmContentTypeTextPlain); |
542 bodyPart->setTextContent(mContentWidget->editor()->toPlainText(), NmContentTypeTextPlain); |
485 } |
543 } |
486 } |
544 } |
487 if (mContentWidget && mContentWidget->header() ) { |
545 if (mContentWidget && mContentWidget->header() ) { |
488 if (mContentWidget->header()->subjectField()) { |
546 if (mContentWidget->header()->subjectEdit()) { |
489 mMessage->envelope().setSubject( |
547 mMessage->envelope().setSubject( |
490 mContentWidget->header()->subjectField()->text()); |
548 mContentWidget->header()->subjectEdit()->text()); |
491 } |
549 } |
492 if (mContentWidget->header()->toField()) { |
550 if (mContentWidget->header()->toEdit()) { |
493 QString toFieldText = |
551 QString toFieldText = |
494 mContentWidget->header()->toField()->text(); |
552 mContentWidget->header()->toEdit()->text(); |
495 |
553 |
496 // This verification of zero length string isn't needed |
554 // This verification of zero length string isn't needed |
497 // after list of addresses |
555 // after list of addresses |
498 if (toFieldText.length() > 0) { |
556 if (toFieldText.length() > 0) { |
499 mMessage->envelope().setToRecipients(mContentWidget->header()->toField()->emailAddressList()); |
557 mMessage->envelope().setToRecipients(mContentWidget->header()->toEdit()->emailAddressList()); |
500 } |
558 } |
501 } |
559 } |
502 if (mContentWidget->header()->ccField()) { |
560 if (mContentWidget->header()->ccEdit()) { |
503 QString ccFieldText = |
561 QString ccFieldText = |
504 mContentWidget->header()->ccField()->text(); |
562 mContentWidget->header()->ccEdit()->text(); |
505 |
563 |
506 if (ccFieldText.length() > 0) { |
564 if (ccFieldText.length() > 0) { |
507 mMessage->envelope().setCcRecipients(mContentWidget->header()->ccField()->emailAddressList()); |
565 mMessage->envelope().setCcRecipients(mContentWidget->header()->ccEdit()->emailAddressList()); |
508 } |
566 } |
509 } |
567 } |
510 if (mContentWidget->header()->bccField()) { |
568 if (mContentWidget->header()->bccEdit()) { |
511 QString bccFieldText = |
569 QString bccFieldText = |
512 mContentWidget->header()->bccField()->text(); |
570 mContentWidget->header()->bccEdit()->text(); |
513 |
571 |
514 if (bccFieldText.length() > 0) { |
572 if (bccFieldText.length() > 0) { |
515 mMessage->envelope().setBccRecipients(mContentWidget->header()->bccField()->emailAddressList()); |
573 mMessage->envelope().setBccRecipients(mContentWidget->header()->bccEdit()->emailAddressList()); |
516 } |
574 } |
517 } |
575 } |
518 } |
576 } |
519 } |
577 } |
520 } |
578 } |
557 toAddressesString = addressListToString(messageEnvelope.toRecipients()); |
615 toAddressesString = addressListToString(messageEnvelope.toRecipients()); |
558 ccAddressesString = addressListToString(messageEnvelope.ccRecipients()); |
616 ccAddressesString = addressListToString(messageEnvelope.ccRecipients()); |
559 bccAddressesString = addressListToString(messageEnvelope.bccRecipients()); |
617 bccAddressesString = addressListToString(messageEnvelope.bccRecipients()); |
560 } |
618 } |
561 |
619 |
562 mContentWidget->header()->toField()->setPlainText(toAddressesString); |
620 mContentWidget->header()->toEdit()->setPlainText(toAddressesString); |
563 mContentWidget->header()->ccField()->setPlainText(ccAddressesString); |
621 mContentWidget->header()->ccEdit()->setPlainText(ccAddressesString); |
564 mContentWidget->header()->bccField()->setPlainText(bccAddressesString); |
622 mContentWidget->header()->bccEdit()->setPlainText(bccAddressesString); |
565 |
623 |
566 if (ccAddressesString.length() || bccAddressesString.length()) { |
624 if (ccAddressesString.length() || bccAddressesString.length()) { |
567 // Since cc or/and bcc recipients exist, expand the group box to display |
625 // Since cc or/and bcc recipients exist, expand the group box to display |
568 // the addresses by expanding the group box. |
626 // the addresses by expanding the group box. |
569 mContentWidget->header()->setGroupBoxCollapsed(false); |
627 mContentWidget->header()->setFieldVisibility(true); |
570 } |
628 } |
571 |
629 |
572 // Set subject. |
630 // Set subject. |
573 if (useStartParam) { |
631 if (useStartParam) { |
574 QString *subject = mStartParam->subject(); |
632 QString *subject = mStartParam->subject(); |
575 |
633 |
576 if (subject) { |
634 if (subject) { |
577 mContentWidget->header()->subjectField()->setPlainText(*subject); |
635 mContentWidget->header()->subjectEdit()->setPlainText(*subject); |
578 } |
636 } |
579 } |
637 } |
580 else { |
638 else { |
581 // If a message is taken from the outbox, no subject formatting is done. |
639 // If a message is taken from the outbox, no subject formatting is done. |
582 NmId notUsed(0); |
640 NmId notUsed(0); |
585 mCheckOutboxOperation->getMessageId(notUsed)) { |
643 mCheckOutboxOperation->getMessageId(notUsed)) { |
586 editorStartMode = NmUiEditorCreateNew; |
644 editorStartMode = NmUiEditorCreateNew; |
587 } |
645 } |
588 |
646 |
589 // Construct the subject field. |
647 // Construct the subject field. |
590 mContentWidget->header()->subjectField()->setPlainText( |
648 mContentWidget->header()->subjectEdit()->setPlainText( |
591 addSubjectPrefix(editorStartMode, messageEnvelope.subject())); |
649 addSubjectPrefix(editorStartMode, messageEnvelope.subject())); |
592 } |
650 } |
593 |
651 |
594 // Set priority. |
652 // Set priority. |
595 mHeaderWidget->setPriority(messageEnvelope.priority()); |
653 mHeaderWidget->setPriority(messageEnvelope.priority()); |
728 createOptionsMenu. Functions asks menu commands from extension |
786 createOptionsMenu. Functions asks menu commands from extension |
729 to be added to options menu. |
787 to be added to options menu. |
730 */ |
788 */ |
731 void NmEditorView::createOptionsMenu() |
789 void NmEditorView::createOptionsMenu() |
732 { |
790 { |
733 if (!mPrioritySubMenu) { |
791 menu()->clearActions(); |
|
792 |
|
793 // Create CC/BCC options menu object |
|
794 if (mCcBccFieldVisible) { |
|
795 menu()->addAction(hbTrId("txt_mail_opt_hide_cc_bcc"), this, SLOT(switchCcBccFieldVisibility())); |
|
796 } |
|
797 else { |
|
798 menu()->addAction(hbTrId("txt_mail_opt_show_cc_bcc"), this, SLOT(switchCcBccFieldVisibility())); |
|
799 } |
|
800 |
|
801 // Create Priority options menu object |
|
802 if (!mPrioritySubMenu) { |
734 mPrioritySubMenu = new HbMenu(); |
803 mPrioritySubMenu = new HbMenu(); |
735 } |
804 } |
736 mPrioritySubMenu->clearActions(); |
805 mPrioritySubMenu->clearActions(); |
737 menu()->clearActions(); |
|
738 NmActionRequest request(this, NmActionOptionsMenu, NmActionContextViewEditor, |
806 NmActionRequest request(this, NmActionOptionsMenu, NmActionContextViewEditor, |
739 NmActionContextDataMessage, mStartParam->mailboxId(), mStartParam->folderId(), |
807 NmActionContextDataMessage, mStartParam->mailboxId(), mStartParam->folderId(), |
740 mStartParam->messageId()); |
808 mStartParam->messageId()); |
741 NmUiExtensionManager &extMngr = mApplication.extManager(); |
809 NmUiExtensionManager &extMngr = mApplication.extManager(); |
742 QList<NmAction*> list; |
810 QList<NmAction*> list; |
748 mPrioritySubMenu->setTitle(hbTrId("txt_mail_opt_add_priority")); |
816 mPrioritySubMenu->setTitle(hbTrId("txt_mail_opt_add_priority")); |
749 menu()->addMenu(mPrioritySubMenu); |
817 menu()->addMenu(mPrioritySubMenu); |
750 } |
818 } |
751 |
819 |
752 /*! |
820 /*! |
|
821 Show or hide Cc field |
|
822 */ |
|
823 void NmEditorView::switchCcBccFieldVisibility() |
|
824 { |
|
825 if (mCcBccFieldVisible) { |
|
826 mCcBccFieldVisible = false; |
|
827 } |
|
828 else { |
|
829 mCcBccFieldVisible = true; |
|
830 } |
|
831 mHeaderWidget->setFieldVisibility( mCcBccFieldVisible ); |
|
832 |
|
833 QTimer::singleShot(NmOrientationTimer, this, SLOT(sendHeaderHeightChanged())); |
|
834 } |
|
835 |
|
836 /*! |
753 handleActionCommand. From NmActionObserver, extension manager calls this |
837 handleActionCommand. From NmActionObserver, extension manager calls this |
754 call to handle menu command in the UI. |
838 call to handle menu command in the UI. |
755 */ |
839 */ |
756 void NmEditorView::handleActionCommand(NmActionResponse &actionResponse) |
840 void NmEditorView::handleActionCommand(NmActionResponse &actionResponse) |
757 { |
841 { |
896 |
994 |
897 // Link VKB to the action. This must be done to all |
995 // Link VKB to the action. This must be done to all |
898 // editors that show the button in VKB. |
996 // editors that show the button in VKB. |
899 HbEditorInterface editorInterface(mContentWidget->editor()); |
997 HbEditorInterface editorInterface(mContentWidget->editor()); |
900 editorInterface.addAction(list[i]); |
998 editorInterface.addAction(list[i]); |
901 HbEditorInterface toEditorInterface(mContentWidget->header()->toField()); |
999 HbEditorInterface toEditorInterface(mContentWidget->header()->toEdit()); |
902 toEditorInterface.addAction(list[i]); |
1000 toEditorInterface.addAction(list[i]); |
903 HbEditorInterface ccEditorInterface(mContentWidget->header()->ccField()); |
1001 HbEditorInterface ccEditorInterface(mContentWidget->header()->ccEdit()); |
904 ccEditorInterface.addAction(list[i]); |
1002 ccEditorInterface.addAction(list[i]); |
905 HbEditorInterface bccEditorInterface(mContentWidget->header()->bccField()); |
1003 HbEditorInterface bccEditorInterface(mContentWidget->header()->bccEdit()); |
906 bccEditorInterface.addAction(list[i]); |
1004 bccEditorInterface.addAction(list[i]); |
907 HbEditorInterface subjectEditorInterface(mContentWidget->header()->subjectField()); |
1005 HbEditorInterface subjectEditorInterface(mContentWidget->header()->subjectEdit()); |
908 subjectEditorInterface.addAction(list[i]); |
1006 subjectEditorInterface.addAction(list[i]); |
909 } |
1007 } |
910 } |
1008 } |
911 } |
1009 } |
912 |
1010 |
1066 } |
1164 } |
1067 |
1165 |
1068 // Add menu position check here, so that it does not go outside of the screen |
1166 // Add menu position check here, so that it does not go outside of the screen |
1069 QPointF menuPos(point.x(),point.y()); |
1167 QPointF menuPos(point.x(),point.y()); |
1070 mAttachmentListContextMenu->setPreferredPos(menuPos); |
1168 mAttachmentListContextMenu->setPreferredPos(menuPos); |
1071 mAttachmentListContextMenu->open(this, SLOT(contextButton(NmActionResponse&))); |
1169 mAttachmentListContextMenu->open(); |
1072 } |
|
1073 |
|
1074 /*! |
|
1075 Slot. Signaled when menu option is selected |
|
1076 */ |
|
1077 void NmEditorView::contextButton(NmActionResponse &result) |
|
1078 { |
|
1079 if (result.menuType() == NmActionContextMenu) { |
|
1080 switch (result.responseCommand()) { |
|
1081 case NmActionResponseCommandRemoveAttachment: { |
|
1082 removeAttachmentTriggered(); |
|
1083 break; |
|
1084 } |
|
1085 case NmActionResponseCommandOpenAttachment: { |
|
1086 openAttachmentTriggered(); |
|
1087 break; |
|
1088 } |
|
1089 default: |
|
1090 break; |
|
1091 } |
|
1092 } |
|
1093 } |
1170 } |
1094 |
1171 |
1095 /*! |
1172 /*! |
1096 This is signalled by mAddAttachmentOperation when the operation is |
1173 This is signalled by mAddAttachmentOperation when the operation is |
1097 completed for one attachment. |
1174 completed for one attachment. |