emailuis/nmailui/src/nmeditorview.cpp
changeset 48 10eaf342f539
parent 47 f83bd4ae1fe3
child 49 00c7ae862740
equal deleted inserted replaced
47:f83bd4ae1fe3 48:10eaf342f539
    39     : NmBaseView(startParam, application, parent),
    39     : NmBaseView(startParam, application, parent),
    40       mApplication(application),
    40       mApplication(application),
    41       mUiEngine(uiEngine),
    41       mUiEngine(uiEngine),
    42       mAttaManager(attaManager),
    42       mAttaManager(attaManager),
    43       mDocumentLoader(NULL),
    43       mDocumentLoader(NULL),
    44       mEditWidget(NULL),
       
    45       mHeaderWidget(NULL),
    44       mHeaderWidget(NULL),
    46       mMessage(NULL),
    45       mMessage(NULL),
    47       mContentWidget(NULL),
    46       mContent(NULL),
    48       mAttachmentListContextMenu(NULL),
    47       mAttachmentListContextMenu(NULL),
    49       mMessageCreationOperation(NULL),
    48       mMessageCreationOperation(NULL),
    50       mAddAttachmentOperation(NULL),
    49       mAddAttachmentOperation(NULL),
    51       mRemoveAttachmentOperation(NULL),
    50       mRemoveAttachmentOperation(NULL),
    52       mWaitDialog(NULL),
    51       mWaitDialog(NULL),
   126         QGraphicsWidget *view = mDocumentLoader->findWidget(NMUI_EDITOR_VIEW);
   125         QGraphicsWidget *view = mDocumentLoader->findWidget(NMUI_EDITOR_VIEW);
   127         if (view){
   126         if (view){
   128             setWidget(view);
   127             setWidget(view);
   129         }
   128         }
   130 
   129 
   131         mContentWidget = new NmEditorContent(this, mDocumentLoader, 
   130         mContent = new NmEditorContent(this, mDocumentLoader, 
   132             mApplication.networkAccessManager(), mApplication);
   131             mApplication.networkAccessManager(), mApplication);
   133 
   132 
   134         mEditWidget = mContentWidget->editor();
   133         mHeaderWidget = mContent->header();
   135 
       
   136         mHeaderWidget = mContentWidget->header();
       
   137 
   134 
   138         // Set default color for user - entered text if editor is in re/reAll/fw mode
   135         // Set default color for user - entered text if editor is in re/reAll/fw mode
   139         if (mStartParam) {
   136         if (mStartParam) {
   140             NmUiEditorStartMode mode = mStartParam->editorStartMode();
   137             NmUiEditorStartMode mode = mStartParam->editorStartMode();
   141             if (mode == NmUiEditorReply
   138             if (mode == NmUiEditorReply
   142                 || mode == NmUiEditorReplyAll 
   139                 || mode == NmUiEditorReplyAll 
   143                 || mode == NmUiEditorForward) {
   140                 || mode == NmUiEditorForward) {
   144                 mEditWidget->setCustomTextColor(true, Qt::blue);
   141                 mContent->editor()->setCustomTextColor(true, Qt::blue);
   145             }
   142             }
   146         }
   143         }
   147 
   144 
   148         // the rest of the view initialization is done in viewReady()
   145         // the rest of the view initialization is done in viewReady()
   149     }
   146     }
   186 */
   183 */
   187 void NmEditorView::orientationChanged(Qt::Orientation orientation)
   184 void NmEditorView::orientationChanged(Qt::Orientation orientation)
   188 {
   185 {
   189     NM_FUNCTION;
   186     NM_FUNCTION;
   190     
   187     
   191     // If switching to horizontal, chrome must be hided
   188     Q_UNUSED(orientation);
   192     if (mVkbHost && orientation == Qt::Horizontal &&
       
   193         mVkbHost->keypadStatus() == HbVkbHost::HbVkbStatusOpened) {
       
   194         showChrome(false);
       
   195     }
       
   196     
   189     
   197     // content widget height needs to be set according to the new orientation to get the scroll
   190     // content widget height needs to be set according to the new orientation to get the scroll
   198 	// area work correctly
   191 	// area work correctly
   199 	mHeaderWidget->sendDelayedHeaderHeightChanged();
   192 	mHeaderWidget->sendDelayedHeaderHeightChanged();
   200 }
   193 }
   202 /*!
   195 /*!
   203     This slot is signaled by VKB when it opens
   196     This slot is signaled by VKB when it opens
   204  */
   197  */
   205 void NmEditorView::vkbOpened()
   198 void NmEditorView::vkbOpened()
   206 {
   199 {
   207     if (mApplication.mainWindow()->orientation() == Qt::Horizontal) {
   200     showChrome(false);	
   208         showChrome(false);	
       
   209     }
       
   210 }
   201 }
   211 
   202 
   212 /*!
   203 /*!
   213     This slot is signaled by VKB when it closes.
   204     This slot is signaled by VKB when it closes.
   214  */
   205  */
   221     Hide or show chrome.
   212     Hide or show chrome.
   222  */
   213  */
   223 void NmEditorView::showChrome(bool show)
   214 void NmEditorView::showChrome(bool show)
   224 {
   215 {
   225     if (show) {
   216     if (show) {
   226         showItems(Hb::StatusBarItem | Hb::TitleBarItem | Hb::ToolBarItem);		
   217         showItems(Hb::StatusBarItem | Hb::TitleBarItem | Hb::ToolBarItem);
   227     }
   218     }
   228     else {
   219     else {
   229         hideItems(Hb::StatusBarItem | Hb::TitleBarItem | Hb::ToolBarItem);
   220         hideItems(Hb::StatusBarItem | Hb::TitleBarItem | Hb::ToolBarItem);
   230     }
   221     }
   231 }
   222 }
   247 {
   238 {
   248     NM_FUNCTION;
   239     NM_FUNCTION;
   249        
   240        
   250     bool okToExit(true);
   241     bool okToExit(true);
   251     
   242     
   252     if (mContentWidget) {
   243     if (mContent) {
   253         NmEditorHeader *header = mContentWidget->header();
   244         NmEditorHeader *header = mContent->header();
   254         // show the query if the message has not been sent
   245         // show the query if the message has not been sent
   255         if (mMessage && header) {
   246         if (mMessage && header) {
   256             // see if editor has any content
   247             // see if editor has any content
   257             int subjectLength = 0;
   248             int subjectLength = 0;
   258             if (header->subjectEdit()) {
   249             if (header->subjectEdit()) {
   260             }
   251             }
   261             
   252             
   262             QList<NmMessagePart*> attachmentList;
   253             QList<NmMessagePart*> attachmentList;
   263             mMessage->attachmentList(attachmentList);
   254             mMessage->attachmentList(attachmentList);
   264             
   255             
   265             if (mContentWidget->editor()) {
   256             if (mContent->editor()) {
   266                 okToExit = (subjectLength == 0 && mContentWidget->editor()->document()->isEmpty());            
   257                 okToExit = (subjectLength == 0 && mContent->editor()->document()->isEmpty());            
   267             }
   258             }
   268     
   259     
   269             // content exists, verify exit from user
   260             // content exists, verify exit from user
   270             if (!okToExit) {
   261             if (!okToExit) {
   271                 if (mQueryDialog) {
   262                 if (mQueryDialog) {
   359     // Menu needs to be create "just-in-time"
   350     // Menu needs to be create "just-in-time"
   360     connect(menu(), SIGNAL(aboutToShow()), this, SLOT(createOptionsMenu()));
   351     connect(menu(), SIGNAL(aboutToShow()), this, SLOT(createOptionsMenu()));
   361     NmAction *dummy = new NmAction(0);
   352     NmAction *dummy = new NmAction(0);
   362     menu()->addAction(dummy);
   353     menu()->addAction(dummy);
   363 
   354 
       
   355     mVkbHost = new HbShrinkingVkbHost(this);
       
   356     
   364     initializeVKB();
   357     initializeVKB();
   365     
   358     
   366     //Get VKB host instance and start to listen VKB open and close signals for hiding the chrome.
   359     //start to listen VKB open and close signals for hiding the chrome.
   367     HbEditorInterface editorInterface(mContentWidget->editor());
       
   368     mVkbHost = editorInterface.vkbHost();
       
   369     connect(mVkbHost, SIGNAL(keypadOpened()), this, SLOT(vkbOpened()));
   360     connect(mVkbHost, SIGNAL(keypadOpened()), this, SLOT(vkbOpened()));
   370     connect(mVkbHost, SIGNAL(keypadClosed()), this, SLOT(vkbClosed()));
   361     connect(mVkbHost, SIGNAL(keypadClosed()), this, SLOT(vkbClosed()));
   371 
   362     
   372     connect(mContentWidget->header(), SIGNAL(recipientFieldsHaveContent(bool)),
   363     connect(mContent->header(), SIGNAL(recipientFieldsHaveContent(bool)),
   373             this, SLOT(setButtonsDimming(bool)) );
   364             this, SLOT(setButtonsDimming(bool)) );
   374 
   365 
   375     // Connect to observe orientation change events
   366     // Connect to observe orientation change events
   376     connect(mApplication.mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
   367     connect(mApplication.mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
   377             this, SLOT(orientationChanged(Qt::Orientation)));
   368             this, SLOT(orientationChanged(Qt::Orientation)));
   644         finalizeSending();
   635         finalizeSending();
   645     }
   636     }
   646 }
   637 }
   647 
   638 
   648 /*!
   639 /*!
       
   640     This is called when the view's geometry size has been changed, eg. when VKB is opened/closed.
       
   641 */
       
   642 void NmEditorView::resizeEvent(QGraphicsSceneResizeEvent *event)
       
   643 {
       
   644     NM_FUNCTION;
       
   645     
       
   646     NmBaseView::resizeEvent(event);
       
   647     
       
   648     emit sizeChanged();
       
   649 }
       
   650 
       
   651 /*!
   649     This is signalled by mMessageCreationOperation when message is created.
   652     This is signalled by mMessageCreationOperation when message is created.
   650 */
   653 */
   651 void NmEditorView::messageCreated(int result)
   654 void NmEditorView::messageCreated(int result)
   652 {
   655 {
   653     NM_FUNCTION;
   656     NM_FUNCTION;
   679 void NmEditorView::updateMessageWithEditorContents()
   682 void NmEditorView::updateMessageWithEditorContents()
   680 {
   683 {
   681     NM_FUNCTION;
   684     NM_FUNCTION;
   682     
   685     
   683     if (mMessage) {
   686     if (mMessage) {
   684         if (mContentWidget && mContentWidget->editor()) {
   687         if (mContent && mContent->editor()) {
   685             NmMessagePart* bodyPart = mMessage->htmlBodyPart();
   688             NmMessagePart* bodyPart = mMessage->htmlBodyPart();
   686             if (bodyPart) {
   689             if (bodyPart) {
   687                 bodyPart->setTextContent(mContentWidget->editor()->toHtml(), NmContentTypeTextHtml);
   690                 bodyPart->setTextContent(mContent->editor()->toHtml(), NmContentTypeTextHtml);
   688             }
   691             }
   689             bodyPart = mMessage->plainTextBodyPart();
   692             bodyPart = mMessage->plainTextBodyPart();
   690             if (bodyPart) {
   693             if (bodyPart) {
   691                 bodyPart->setTextContent(mContentWidget->editor()->toPlainText(), NmContentTypeTextPlain);
   694                 bodyPart->setTextContent(mContent->editor()->toPlainText(), NmContentTypeTextPlain);
   692             }
   695             }
   693         }
   696         }
   694         if (mContentWidget && mContentWidget->header() ) {
   697         if (mContent && mContent->header() ) {
   695             if (mContentWidget->header()->subjectEdit()) {
   698             if (mContent->header()->subjectEdit()) {
   696                 mMessage->envelope().setSubject(
   699                 mMessage->envelope().setSubject(
   697                     mContentWidget->header()->subjectEdit()->text());
   700                     mContent->header()->subjectEdit()->text());
   698             }
   701             }
   699             if (mContentWidget->header()->toEdit()) {
   702             if (mContent->header()->toEdit()) {
   700                 QString toFieldText =
   703                 QString toFieldText =
   701                     mContentWidget->header()->toEdit()->text();
   704                     mContent->header()->toEdit()->text();
   702 
   705 
   703                 // This verification of zero length string isn't needed
   706                 // This verification of zero length string isn't needed
   704                 // after list of addresses
   707                 // after list of addresses
   705                 if (toFieldText.length() > 0) {
   708                 if (toFieldText.length() > 0) {
   706                     mMessage->envelope().setToRecipients(mContentWidget->header()->toEdit()->emailAddressList());  
   709                     mMessage->envelope().setToRecipients(mContent->header()->toEdit()->emailAddressList());  
   707                 }
   710                 }
   708             }
   711             }
   709             if (mContentWidget->header()->ccEdit()) {
   712             if (mContent->header()->ccEdit()) {
   710                 QString ccFieldText =
   713                 QString ccFieldText =
   711                     mContentWidget->header()->ccEdit()->text();
   714                     mContent->header()->ccEdit()->text();
   712 
   715 
   713                 if (ccFieldText.length() > 0) {
   716                 if (ccFieldText.length() > 0) {
   714                     mMessage->envelope().setCcRecipients(mContentWidget->header()->ccEdit()->emailAddressList());      
   717                     mMessage->envelope().setCcRecipients(mContent->header()->ccEdit()->emailAddressList());      
   715                 }
   718                 }
   716             }
   719             }
   717             if (mContentWidget->header()->bccEdit()) {
   720             if (mContent->header()->bccEdit()) {
   718                 QString bccFieldText =
   721                 QString bccFieldText =
   719                     mContentWidget->header()->bccEdit()->text();
   722                     mContent->header()->bccEdit()->text();
   720 
   723 
   721                 if (bccFieldText.length() > 0) {
   724                 if (bccFieldText.length() > 0) {
   722                     mMessage->envelope().setBccRecipients(mContentWidget->header()->bccEdit()->emailAddressList());  
   725                     mMessage->envelope().setBccRecipients(mContent->header()->bccEdit()->emailAddressList());  
   723                 }
   726                 }
   724             }
   727             }
   725         }
   728         }
   726     }
   729     }
   727 }
   730 }
   733 */
   736 */
   734 void NmEditorView::fillEditorWithMessageContents()
   737 void NmEditorView::fillEditorWithMessageContents()
   735 {
   738 {
   736     NM_FUNCTION;
   739     NM_FUNCTION;
   737     
   740     
   738     if (!mStartParam || !mMessage || !mContentWidget) {
   741     if (!mStartParam || !mMessage || !mContent) {
   739         return;
   742         return;
   740     }
   743     }
   741 
   744 
   742     NmMessageEnvelope messageEnvelope(mMessage->envelope());
   745     NmMessageEnvelope messageEnvelope(mMessage->envelope());
   743     bool useStartParam(false);
   746     bool useStartParam(false);
   763         toAddressesString = addressListToString(messageEnvelope.toRecipients());
   766         toAddressesString = addressListToString(messageEnvelope.toRecipients());
   764         ccAddressesString = addressListToString(messageEnvelope.ccRecipients());
   767         ccAddressesString = addressListToString(messageEnvelope.ccRecipients());
   765         bccAddressesString = addressListToString(messageEnvelope.bccRecipients());
   768         bccAddressesString = addressListToString(messageEnvelope.bccRecipients());
   766     }
   769     }
   767 
   770 
   768     mContentWidget->header()->toEdit()->setPlainText(toAddressesString);
   771     mContent->header()->toEdit()->setPlainText(toAddressesString);
   769     mContentWidget->header()->ccEdit()->setPlainText(ccAddressesString);
   772     mContent->header()->ccEdit()->setPlainText(ccAddressesString);
   770     mContentWidget->header()->bccEdit()->setPlainText(bccAddressesString);
   773     mContent->header()->bccEdit()->setPlainText(bccAddressesString);
   771 
   774 
   772     if (ccAddressesString.length() || bccAddressesString.length()) {
   775     if (ccAddressesString.length() || bccAddressesString.length()) {
   773         // Since cc or/and bcc recipients exist, expand the group box to display
   776         // Since cc or/and bcc recipients exist, expand the group box to display
   774         // the addresses by expanding the group box.
   777         // the addresses by expanding the group box.
   775         mContentWidget->header()->setFieldVisibility(true);
   778         mContent->header()->setFieldVisibility(true);
   776     }
   779     }
   777 
   780 
   778     // Set subject.
   781     // Set subject.
   779     if (useStartParam) {
   782     if (useStartParam) {
   780         QString *subject = mStartParam->subject();
   783         QString *subject = mStartParam->subject();
   781 
   784 
   782         if (subject) {
   785         if (subject) {
   783             mContentWidget->header()->subjectEdit()->setPlainText(*subject);
   786             mContent->header()->subjectEdit()->setPlainText(*subject);
   784         }
   787         }
   785     }
   788     }
   786     else {
   789     else {
   787         // Construct the subject field.
   790         // Construct the subject field.
   788         mContentWidget->header()->subjectEdit()->setPlainText(
   791         mContent->header()->subjectEdit()->setPlainText(
   789             addSubjectPrefix(editorStartMode, messageEnvelope.subject()));
   792             addSubjectPrefix(editorStartMode, messageEnvelope.subject()));
   790     }
   793     }
   791 
   794 
   792     // Set priority.
   795     // Set priority.
       
   796     if (editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll) {
       
   797         //Clear the importance flag. Replied messages dont keep the importance
       
   798         setPriority(NmActionResponseCommandNone);
       
   799     }
   793     mHeaderWidget->setPriority(messageEnvelope.priority());
   800     mHeaderWidget->setPriority(messageEnvelope.priority());
   794     
   801     
   795     // Set the message body.
   802     // Set the message body.
   796     if (editorStartMode==NmUiEditorReply||
   803     if (editorStartMode==NmUiEditorReply||
   797         editorStartMode==NmUiEditorReplyAll||
   804         editorStartMode==NmUiEditorReplyAll||
   820                                                originalMessage->envelope().folderId(),
   827                                                originalMessage->envelope().folderId(),
   821                                                originalMessage->envelope().messageId(),
   828                                                originalMessage->envelope().messageId(),
   822                                                *htmlPart);
   829                                                *htmlPart);
   823             }
   830             }
   824 
   831 
   825 		mContentWidget->setMessageData(*originalMessage, editorStartMode);
   832 		mContent->setMessageData(*originalMessage, editorStartMode);
   826         }
   833         }
   827 
   834 
   828         delete originalMessage;
   835         delete originalMessage;
   829         originalMessage = NULL;
   836         originalMessage = NULL;
   830     }
   837     }
  1040         }
  1047         }
  1041 
  1048 
  1042         // Set the VKB action states
  1049         // Set the VKB action states
  1043         // All editors of the view share the same action, so it is enough to set
  1050         // All editors of the view share the same action, so it is enough to set
  1044         // this only to one of them.
  1051         // this only to one of them.
  1045         HbEditorInterface editorInterface(mContentWidget->editor());
  1052         HbEditorInterface editorInterface(mContent->editor());
  1046         QList<HbAction *> vkbList = editorInterface.actions();
  1053         QList<HbAction *> vkbList = editorInterface.actions();
  1047         count = vkbList.count();
  1054         count = vkbList.count();
  1048         for (int i = 0; i < count; i++) {
  1055         for (int i = 0; i < count; i++) {
  1049             NmAction *action = static_cast<NmAction *>(vkbList[i]);
  1056             NmAction *action = static_cast<NmAction *>(vkbList[i]);
  1050             if (action->availabilityCondition() == NmAction::NmSendable) {
  1057             if (action->availabilityCondition() == NmAction::NmSendable) {
  1082             }
  1089             }
  1083             list[i]->setIcon(NmIcons::getIcon(NmIcons::NmIconSend));
  1090             list[i]->setIcon(NmIcons::getIcon(NmIcons::NmIconSend));
  1084 
  1091 
  1085             // Link VKB to the action. This must be done to all
  1092             // Link VKB to the action. This must be done to all
  1086             // editors that show the button in VKB.
  1093             // editors that show the button in VKB.
  1087             HbEditorInterface editorInterface(mContentWidget->editor());
  1094             HbEditorInterface editorInterface(mContent->editor());
  1088             editorInterface.addAction(list[i]);
  1095             editorInterface.addAction(list[i]);
  1089             HbEditorInterface toEditorInterface(mContentWidget->header()->toEdit());
  1096             HbEditorInterface toEditorInterface(mContent->header()->toEdit());
  1090             toEditorInterface.addAction(list[i]);
  1097             toEditorInterface.addAction(list[i]);
  1091             HbEditorInterface ccEditorInterface(mContentWidget->header()->ccEdit());
  1098             HbEditorInterface ccEditorInterface(mContent->header()->ccEdit());
  1092             ccEditorInterface.addAction(list[i]);
  1099             ccEditorInterface.addAction(list[i]);
  1093             HbEditorInterface bccEditorInterface(mContentWidget->header()->bccEdit());
  1100             HbEditorInterface bccEditorInterface(mContent->header()->bccEdit());
  1094             bccEditorInterface.addAction(list[i]);
  1101             bccEditorInterface.addAction(list[i]);
  1095             HbEditorInterface subjectEditorInterface(mContentWidget->header()->subjectEdit());
  1102             HbEditorInterface subjectEditorInterface(mContent->header()->subjectEdit());
  1096             subjectEditorInterface.addAction(list[i]);
  1103             subjectEditorInterface.addAction(list[i]);
  1097         }
  1104         }
  1098     }
  1105     }
  1099 }
  1106 }
  1100 
  1107