emailuis/nmailui/src/nmeditorview.cpp
changeset 54 997a02608b3a
parent 53 bf7eb7911fc5
child 59 16ed8d08d0b1
equal deleted inserted replaced
53:bf7eb7911fc5 54:997a02608b3a
    17 #include "nmuiheaders.h"
    17 #include "nmuiheaders.h"
    18 
    18 
    19 // Layout file and view
    19 // Layout file and view
    20 static const char *NMUI_EDITOR_VIEW_XML = ":/docml/nmeditorview.docml";
    20 static const char *NMUI_EDITOR_VIEW_XML = ":/docml/nmeditorview.docml";
    21 static const char *NMUI_EDITOR_VIEW= "editorview";
    21 static const char *NMUI_EDITOR_VIEW= "editorview";
    22 static const char *NMUI_EDITOR_SCROLL_AREA = "scrollArea";
    22 
    23 static const char *NMUI_EDITOR_SCROLL_AREA_CONTENTS = "scrollAreaContents";
    23 static const QString NmDelimiter("; ");
    24 
       
    25 static const int NmOrientationTimer=100;
       
    26 
       
    27 static const QString Delimiter("; ");
       
    28 
    24 
    29 /*!
    25 /*!
    30 	\class NmEditorView
    26 	\class NmEditorView
    31 	\brief Mail editor view
    27 	\brief Mail editor view
    32 */
    28 */
    43     : NmBaseView(startParam, application, parent),
    39     : NmBaseView(startParam, application, parent),
    44       mApplication(application),
    40       mApplication(application),
    45       mUiEngine(uiEngine),
    41       mUiEngine(uiEngine),
    46       mAttaManager(attaManager),
    42       mAttaManager(attaManager),
    47       mDocumentLoader(NULL),
    43       mDocumentLoader(NULL),
    48       mScrollArea(NULL),
       
    49       mEditWidget(NULL),
       
    50       mHeaderWidget(NULL),
    44       mHeaderWidget(NULL),
    51       mMessage(NULL),
    45       mMessage(NULL),
    52       mContentWidget(NULL),
    46       mContent(NULL),
    53       mAttachmentListContextMenu(NULL),
    47       mAttachmentListContextMenu(NULL),
    54       mMessageCreationOperation(NULL),
    48       mMessageCreationOperation(NULL),
    55       mAddAttachmentOperation(NULL),
    49       mAddAttachmentOperation(NULL),
    56       mRemoveAttachmentOperation(NULL),
    50       mRemoveAttachmentOperation(NULL),
    57       mWaitDialog(NULL),
    51       mWaitDialog(NULL),
    90         mMessageCreationOperation->cancelOperation();
    84         mMessageCreationOperation->cancelOperation();
    91     }
    85     }
    92     delete mMessage;
    86     delete mMessage;
    93     mWidgetList.clear();
    87     mWidgetList.clear();
    94     delete mDocumentLoader;
    88     delete mDocumentLoader;
    95     delete mContentWidget;
       
    96     delete mPrioritySubMenu;
    89     delete mPrioritySubMenu;
    97     
    90     
    98     if (mAttachmentListContextMenu) {
    91     if (mAttachmentListContextMenu) {
    99         mAttachmentListContextMenu->clearActions();
    92         mAttachmentListContextMenu->clearActions();
   100         delete mAttachmentListContextMenu;
    93         delete mAttachmentListContextMenu;
   122     NM_FUNCTION;
   115     NM_FUNCTION;
   123     
   116     
   124     mPrioritySubMenu = NULL;
   117     mPrioritySubMenu = NULL;
   125 
   118 
   126     // Use document loader to load the view
   119     // Use document loader to load the view
   127     bool ok = false;
   120     bool ok(false);
       
   121 
       
   122     setObjectName(QString(NMUI_EDITOR_VIEW));
       
   123     QObjectList objectList;
       
   124     objectList.append(this);
       
   125     // Pass the view to documentloader. Document loader uses this view
       
   126     // when docml is parsed, instead of creating new view.
       
   127     // documentloader is created in constructor
       
   128     mDocumentLoader->setObjectTree(objectList);
       
   129 
   128     mWidgetList = mDocumentLoader->load(NMUI_EDITOR_VIEW_XML, &ok);
   130     mWidgetList = mDocumentLoader->load(NMUI_EDITOR_VIEW_XML, &ok);
   129 
   131 
   130     if (ok == true && mWidgetList.count()) {
   132    if (ok) {
   131         // Set view
   133         mContent = new NmEditorContent(this, mDocumentLoader, 
   132         QGraphicsWidget *view = mDocumentLoader->findWidget(NMUI_EDITOR_VIEW);
   134             mApplication.networkAccessManager(), mApplication);
   133         if (view){
   135 
   134             setWidget(view);
   136         mHeaderWidget = mContent->header();
   135         }
       
   136 
       
   137         mScrollArea = qobject_cast<NmBaseViewScrollArea *>
       
   138             (mDocumentLoader->findObject(NMUI_EDITOR_SCROLL_AREA));
       
   139         mScrollAreaContents = qobject_cast<HbWidget *>
       
   140              (mDocumentLoader->findObject(NMUI_EDITOR_SCROLL_AREA_CONTENTS));
       
   141 
       
   142         mContentWidget = new NmEditorContent(mScrollArea, this, mDocumentLoader, 
       
   143             mApplication.networkAccessManager());
       
   144         mEditWidget = mContentWidget->editor();
       
   145         mHeaderWidget = mContentWidget->header();
       
   146 
   137 
   147         // Set default color for user - entered text if editor is in re/reAll/fw mode
   138         // Set default color for user - entered text if editor is in re/reAll/fw mode
   148         if (mStartParam) {
   139         if (mStartParam) {
   149             NmUiEditorStartMode mode = mStartParam->editorStartMode();
   140             NmUiEditorStartMode mode = mStartParam->editorStartMode();
   150             if (mode == NmUiEditorReply
   141             if (mode == NmUiEditorReply
   151                 || mode == NmUiEditorReplyAll 
   142                 || mode == NmUiEditorReplyAll 
   152                 || mode == NmUiEditorForward) {
   143                 || mode == NmUiEditorForward) {
   153                 mEditWidget->setCustomTextColor(true, Qt::blue);
   144                 mContent->editor()->setCustomTextColor(true, Qt::blue);
   154             }
   145             }
   155         }
   146         }
   156 
   147 
   157         // the rest of the view initialization is done in viewReady()
   148         // the rest of the view initialization is done in viewReady()
   158     }
   149     }
   196 void NmEditorView::orientationChanged(Qt::Orientation orientation)
   187 void NmEditorView::orientationChanged(Qt::Orientation orientation)
   197 {
   188 {
   198     NM_FUNCTION;
   189     NM_FUNCTION;
   199     
   190     
   200     Q_UNUSED(orientation);
   191     Q_UNUSED(orientation);
   201     // Adjust content height
   192     
   202     QTimer::singleShot(NmOrientationTimer, this, SLOT(adjustViewDimensions()));
   193     // content widget height needs to be set according to the new orientation to get the scroll
   203     QTimer::singleShot(NmOrientationTimer, mHeaderWidget, SLOT(sendHeaderHeightChanged()));
   194 	// area work correctly
   204 }
   195 	mHeaderWidget->sendDelayedHeaderHeightChanged();
   205 
   196 }
   206 /*!
   197 
   207     Set new dimensions after orientation change.
   198 /*!
   208 */
   199     This slot is signaled by VKB when it opens
   209 void NmEditorView::adjustViewDimensions()
   200  */
   210 {
   201 void NmEditorView::vkbOpened()
   211     NM_FUNCTION;
   202 {
   212     
   203     showChrome(false);	
   213     if (mScrollAreaContents) {
   204 }
   214         const QSize reso = mApplication.screenSize();
   205 
   215         mScrollAreaContents->setMinimumWidth(reso.width());
   206 /*!
   216         mScrollAreaContents->setMaximumWidth(reso.width());
   207     This slot is signaled by VKB when it closes.
       
   208  */
       
   209 void NmEditorView::vkbClosed()
       
   210 {
       
   211 	showChrome(true);
       
   212 }
       
   213 
       
   214 /*!
       
   215     Hide or show chrome.
       
   216  */
       
   217 void NmEditorView::showChrome(bool show)
       
   218 {
       
   219     if (show) {
       
   220         showItems(Hb::StatusBarItem | Hb::TitleBarItem | Hb::ToolBarItem);
       
   221     }
       
   222     else {
       
   223         hideItems(Hb::StatusBarItem | Hb::TitleBarItem | Hb::ToolBarItem);
   217     }
   224     }
   218 }
   225 }
   219 
   226 
   220 /*!
   227 /*!
   221     View id
   228     View id
   223 NmUiViewId NmEditorView::nmailViewId() const
   230 NmUiViewId NmEditorView::nmailViewId() const
   224 {
   231 {
   225     NM_FUNCTION;
   232     NM_FUNCTION;
   226     
   233     
   227     return NmUiViewMessageEditor;
   234     return NmUiViewMessageEditor;
   228 }
       
   229 
       
   230 /*!
       
   231     ScrollArea contents
       
   232 */
       
   233 HbWidget* NmEditorView::scrollAreaContents()
       
   234 {
       
   235     NM_FUNCTION;
       
   236     
       
   237     return mScrollAreaContents;
       
   238 }
   235 }
   239 
   236 
   240 /*
   237 /*
   241    Launch dialog for query user if we want to exit the editor
   238    Launch dialog for query user if we want to exit the editor
   242 */
   239 */
   243 void NmEditorView::okToExitView()
   240 void NmEditorView::okToExitView()
   244 {
   241 {
   245     NM_FUNCTION;
   242     NM_FUNCTION;
   246     
   243        
   247     NmEditorHeader *header = mContentWidget->header();
   244     bool okToExit(true);
   248     
   245     
   249     bool okToExit = true;
   246     if (mContent) {
   250     
   247         NmEditorHeader *header = mContent->header();
   251     // show the query if the message has not been sent
   248         // show the query if the message has not been sent
   252     if (mMessage && header) {
   249         if (mMessage && header) {
   253         // see if editor has any content
   250             // see if editor has any content
   254         int subjectLength = 0;
   251             int subjectLength = 0;
   255         if (header->subjectEdit()) {
   252             if (header->subjectEdit()) {
   256             subjectLength = header->subjectEdit()->text().length();
   253                 subjectLength = header->subjectEdit()->text().length();
   257         }
   254             }
   258         
   255             
   259         QList<NmMessagePart*> attachmentList;
   256             QList<NmMessagePart*> attachmentList;
   260         mMessage->attachmentList(attachmentList);
   257             mMessage->attachmentList(attachmentList);
   261                     
   258             
   262         okToExit = (subjectLength == 0 && mContentWidget->editor()->document()->isEmpty());
   259             if (mContent->editor()) {
   263 
   260                 okToExit = (subjectLength == 0 && mContent->editor()->document()->isEmpty());            
   264         // content exists, verify exit from user
   261             }
   265         if (!okToExit) {
   262     
   266             if (mQueryDialog) {
   263             // content exists, verify exit from user
   267                 delete mQueryDialog;
   264             if (!okToExit) {
   268                 mQueryDialog = 0;
   265                 if (mQueryDialog) {
   269             }
   266                     delete mQueryDialog;
   270             // Launch query dialog.
   267                     mQueryDialog = 0;
   271             mQueryDialog = 
   268                 }
   272                 NmUtilities::displayQuestionNote(hbTrId("txt_mail_dialog_save_message_to_drafts"),
   269                 // Launch query dialog.
   273                                                             this,
   270                 mQueryDialog = 
   274                                                             SLOT(okToExitQuery(HbAction*)));
   271                     NmUtilities::displayQuestionNote(hbTrId("txt_mail_dialog_save_message_to_drafts"),
   275         }
   272                                                                 this,
       
   273                                                                 SLOT(okToExitQuery(HbAction*)));
       
   274             }
       
   275         }    
   276     }
   276     }
   277     
   277     
   278     // no need to query anything, just exit.
   278     // no need to query anything, just exit.
   279     if(okToExit) {
   279     if(okToExit) {
   280         QMetaObject::invokeMethod(&mApplication,
   280         QMetaObject::invokeMethod(&mApplication,
   284 }
   284 }
   285 
   285 
   286 /*!
   286 /*!
   287     Handle the user selection is it ok to exit.
   287     Handle the user selection is it ok to exit.
   288 */
   288 */
   289 void NmEditorView::okToExitQuery(HbAction* action)
   289 void NmEditorView::okToExitQuery(HbAction *action)
   290 {
   290 {
   291     NM_FUNCTION;
   291     NM_FUNCTION;
   292     
   292     
   293     HbMessageBox *dlg = static_cast<HbMessageBox*>(sender());
   293     HbMessageBox *dlg = static_cast<HbMessageBox*>(sender());
   294     // The first action in dialogs action list is for the "Yes"-button.
   294     // The first action in dialogs action list is for the "Yes"-button.
   353     // Menu needs to be create "just-in-time"
   353     // Menu needs to be create "just-in-time"
   354     connect(menu(), SIGNAL(aboutToShow()), this, SLOT(createOptionsMenu()));
   354     connect(menu(), SIGNAL(aboutToShow()), this, SLOT(createOptionsMenu()));
   355     NmAction *dummy = new NmAction(0);
   355     NmAction *dummy = new NmAction(0);
   356     menu()->addAction(dummy);
   356     menu()->addAction(dummy);
   357 
   357 
       
   358     mVkbHost = new HbShrinkingVkbHost(this);
       
   359     
   358     initializeVKB();
   360     initializeVKB();
   359     connect(mContentWidget->header(), SIGNAL(recipientFieldsHaveContent(bool)),
   361     
       
   362     //start to listen VKB open and close signals for hiding the chrome.
       
   363     connect(mVkbHost, SIGNAL(keypadOpened()), this, SLOT(vkbOpened()));
       
   364     connect(mVkbHost, SIGNAL(keypadClosed()), this, SLOT(vkbClosed()));
       
   365     
       
   366     connect(mContent->header(), SIGNAL(recipientFieldsHaveContent(bool)),
   360             this, SLOT(setButtonsDimming(bool)) );
   367             this, SLOT(setButtonsDimming(bool)) );
   361 
   368 
   362     // Set dimensions
       
   363     adjustViewDimensions();
       
   364 	
       
   365     // Connect to observe orientation change events
   369     // Connect to observe orientation change events
   366     connect(mApplication.mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
   370     connect(mApplication.mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
   367             this, SLOT(orientationChanged(Qt::Orientation)));
   371             this, SLOT(orientationChanged(Qt::Orientation)));
   368     // Signal for handling the attachment list selection
   372     // Signal for handling the attachment list selection
   369     connect(mHeaderWidget, SIGNAL(attachmentShortPressed(NmId)),
   373     connect(mHeaderWidget, SIGNAL(attachmentShortPressed(NmId)),
   425     
   429     
   426     if (result == NmNoError && mStartParam) {
   430     if (result == NmNoError && mStartParam) {
   427         startMessageCreation(*mStartParam);
   431         startMessageCreation(*mStartParam);
   428     }
   432     }
   429     else {
   433     else {
   430         mWaitDialog->close();
   434         // Show the fetching failed note only when
   431 		
   435         // the error is not Device/System errors, 
   432         // Show fetching failed note         
   436         if (result != NmNoError && 
   433         HbNotificationDialog *note = new HbNotificationDialog(); 
   437             result != NmNotFoundError &&
   434         note->setIcon(HbIcon(QLatin1String("note_warning")));
   438             result != NmGeneralError &&
   435         QString noteText = hbTrId("txt_mail_dpopinfo_loading_failed");
   439             result != NmCancelError &&
   436         note->setTitle(noteText);
   440             result != NmAuthenticationError &&
   437         note->setTitleTextWrapping(Hb::TextWordWrap);
   441             result != NmServerConnectionError &&
   438         note->setDismissPolicy(HbPopup::TapAnywhere);
   442             result != NmConnectionError) {
   439         note->setAttribute(Qt::WA_DeleteOnClose);
   443             
   440         note->setSequentialShow(true);
   444             HbNotificationDialog *note = new HbNotificationDialog(); 
   441         note->show();
   445             
       
   446             bool enalbeAttribute(true);
       
   447             note->setAttribute(Qt::WA_DeleteOnClose, enalbeAttribute);
       
   448             
       
   449             note->setIcon(HbIcon(QLatin1String("note_warning")));
       
   450             
       
   451             note->setTitle(hbTrId("txt_mail_dpopinfo_loading_failed"));
       
   452             note->setTitleTextWrapping(Hb::TextWordWrap);
       
   453             
       
   454             note->setDismissPolicy(HbNotificationDialog::TapAnywhere);
       
   455             note->setTimeout(HbNotificationDialog::StandardTimeout);
       
   456             
       
   457             note->setSequentialShow(true);
       
   458             note->show();
       
   459         }
   442         
   460         
       
   461         mWaitDialog->close();         
   443         QMetaObject::invokeMethod(&mApplication, "popView", Qt::QueuedConnection);
   462         QMetaObject::invokeMethod(&mApplication, "popView", Qt::QueuedConnection);
   444     }
   463     }
   445 }
   464 }
   446 
   465 
   447 void NmEditorView::fetchProgressDialogShow()
   466 void NmEditorView::fetchProgressDialogShow()
   484     NmId msgId = startParam.messageId();
   503     NmId msgId = startParam.messageId();
   485     
   504     
   486     if (mMessageCreationOperation && mMessageCreationOperation->isRunning()) {
   505     if (mMessageCreationOperation && mMessageCreationOperation->isRunning()) {
   487         mMessageCreationOperation->cancelOperation();
   506         mMessageCreationOperation->cancelOperation();
   488     }
   507     }
   489 	
   508 	  
   490     // original message is now fetched so start message creation
   509     // original message is now fetched so start message creation
   491     if (startMode == NmUiEditorForward) {
   510     if (startMode == NmUiEditorForward) {
   492         mMessageCreationOperation = mUiEngine.createForwardMessage(mailboxId, msgId);
   511         mMessageCreationOperation = mUiEngine.createForwardMessage(mailboxId, msgId);
   493     }
   512     }
   494     else if (startMode == NmUiEditorReply || startMode == NmUiEditorReplyAll) {
   513     else if (startMode == NmUiEditorReply || startMode == NmUiEditorReplyAll) {
   528     updateMessageWithEditorContents();
   547     updateMessageWithEditorContents();
   529     
   548     
   530     // verify addresses before sending
   549     // verify addresses before sending
   531     QList<NmAddress> invalidAddresses;
   550     QList<NmAddress> invalidAddresses;
   532     if (mMessage) {
   551     if (mMessage) {
   533         NmUtilities::getRecipientsFromMessage(*mMessage, invalidAddresses, NmUtilities::InvalidAddress);
   552         NmUtilities::getRecipientsFromMessage(*mMessage, invalidAddresses, NmUtilities::NmInvalidAddress);
   534     }
   553     }
   535     
   554     
   536     if (invalidAddresses.count() > 0) {
   555     if (invalidAddresses.count() > 0) {
   537         
   556         
   538         // invalid addresses found, verify send from user
   557         // invalid addresses found, verify send from user
   573     // NmOperations are automatically deleted after completion
   592     // NmOperations are automatically deleted after completion
   574     mUiEngine.sendMessage(mMessage, preliminaryOperations);
   593     mUiEngine.sendMessage(mMessage, preliminaryOperations);
   575     mMessage = NULL;
   594     mMessage = NULL;
   576     preliminaryOperations.clear();
   595     preliminaryOperations.clear();
   577 
   596 
   578 #ifndef NM_WINS_ENV
       
   579     bool service = XQServiceUtil::isService();
   597     bool service = XQServiceUtil::isService();
   580 #else
       
   581     bool service = false;
       
   582 #endif
       
   583 
   598 
   584     // If sending is started as a service, progress dialog needs to be shown
   599     // If sending is started as a service, progress dialog needs to be shown
   585     // so long that sending is finished otherwise we can close pop current view.
   600     // so long that sending is finished otherwise we can close pop current view.
   586     if (service && mStartParam && mStartParam->service() && 
   601     if (service && mStartParam && mStartParam->service() && 
   587         mUiEngine.isSendingMessage()) {
   602         mUiEngine.isSendingMessage()) {
   593         mServiceSendingDialog->setAttribute(Qt::WA_DeleteOnClose);
   608         mServiceSendingDialog->setAttribute(Qt::WA_DeleteOnClose);
   594         mServiceSendingDialog->setText(hbTrId("txt_mail_shareui_sending_please_wait"));
   609         mServiceSendingDialog->setText(hbTrId("txt_mail_shareui_sending_please_wait"));
   595         connect(mServiceSendingDialog, SIGNAL(cancelled()),
   610         connect(mServiceSendingDialog, SIGNAL(cancelled()),
   596             this, SLOT(sendProgressDialogCancelled()));
   611             this, SLOT(sendProgressDialogCancelled()));
   597 
   612 
   598 #ifndef NM_WINS_ENV
       
   599         if (!XQServiceUtil::isEmbedded()) {
   613         if (!XQServiceUtil::isEmbedded()) {
   600             // Hide the application.
   614             // Hide the application.
   601             XQServiceUtil::toBackground(true);
   615             XQServiceUtil::toBackground(true);
   602         }
   616         }
   603 #endif
       
   604          // Display the wait dialog.
   617          // Display the wait dialog.
   605          mServiceSendingDialog->setModal(true);
   618          mServiceSendingDialog->setModal(true);
   606          mServiceSendingDialog->setBackgroundFaded(true);
   619          mServiceSendingDialog->setBackgroundFaded(true);
   607          mServiceSendingDialog->show();
   620          mServiceSendingDialog->show();
   608     } else {
   621     } else {
   622     HbMessageBox *dlg = static_cast<HbMessageBox*>(sender());
   635     HbMessageBox *dlg = static_cast<HbMessageBox*>(sender());
   623     // The first action in dialogs action list is for the "Yes"-button.
   636     // The first action in dialogs action list is for the "Yes"-button.
   624     if (action == dlg->actions().at(0)) {
   637     if (action == dlg->actions().at(0)) {
   625         finalizeSending();
   638         finalizeSending();
   626     }
   639     }
       
   640 }
       
   641 
       
   642 /*!
       
   643     This is called when the view's geometry size has been changed, eg. when VKB is opened/closed.
       
   644 */
       
   645 void NmEditorView::resizeEvent(QGraphicsSceneResizeEvent *event)
       
   646 {
       
   647     NM_FUNCTION;
       
   648     
       
   649     NmBaseView::resizeEvent(event);
       
   650     
       
   651     emit sizeChanged();
   627 }
   652 }
   628 
   653 
   629 /*!
   654 /*!
   630     This is signalled by mMessageCreationOperation when message is created.
   655     This is signalled by mMessageCreationOperation when message is created.
   631 */
   656 */
   660 void NmEditorView::updateMessageWithEditorContents()
   685 void NmEditorView::updateMessageWithEditorContents()
   661 {
   686 {
   662     NM_FUNCTION;
   687     NM_FUNCTION;
   663     
   688     
   664     if (mMessage) {
   689     if (mMessage) {
   665         if (mContentWidget && mContentWidget->editor()) {
   690         if (mContent && mContent->editor()) {
   666             NmMessagePart* bodyPart = mMessage->htmlBodyPart();
   691             NmMessagePart* bodyPart = mMessage->htmlBodyPart();
   667             if (bodyPart) {
   692             if (bodyPart) {
   668                 bodyPart->setTextContent(mContentWidget->editor()->toHtml(), NmContentTypeTextHtml);
   693                 bodyPart->setTextContent(mContent->editor()->toHtml(), NmContentTypeTextHtml);
   669             }
   694             }
   670             bodyPart = mMessage->plainTextBodyPart();
   695             bodyPart = mMessage->plainTextBodyPart();
   671             if (bodyPart) {
   696             if (bodyPart) {
   672                 bodyPart->setTextContent(mContentWidget->editor()->toPlainText(), NmContentTypeTextPlain);
   697                 bodyPart->setTextContent(mContent->editor()->toPlainText(), NmContentTypeTextPlain);
   673             }
   698             }
   674         }
   699         }
   675         if (mContentWidget && mContentWidget->header() ) {
   700         if (mContent && mContent->header() ) {
   676             if (mContentWidget->header()->subjectEdit()) {
   701             if (mContent->header()->subjectEdit()) {
   677                 mMessage->envelope().setSubject(
   702                 mMessage->envelope().setSubject(
   678                     mContentWidget->header()->subjectEdit()->text());
   703                     mContent->header()->subjectEdit()->text());
   679             }
   704             }
   680             if (mContentWidget->header()->toEdit()) {
   705             if (mContent->header()->toEdit()) {
   681                 QString toFieldText =
   706                 QString toFieldText =
   682                     mContentWidget->header()->toEdit()->text();
   707                     mContent->header()->toEdit()->text();
   683 
   708 
   684                 // This verification of zero length string isn't needed
   709                 // This verification of zero length string isn't needed
   685                 // after list of addresses
   710                 // after list of addresses
   686                 if (toFieldText.length() > 0) {
   711                 if (toFieldText.length() > 0) {
   687                     mMessage->envelope().setToRecipients(mContentWidget->header()->toEdit()->emailAddressList());  
   712                     mMessage->envelope().setToRecipients(mContent->header()->toEdit()->emailAddressList());  
   688                 }
   713                 }
   689             }
   714             }
   690             if (mContentWidget->header()->ccEdit()) {
   715             if (mContent->header()->ccEdit()) {
   691                 QString ccFieldText =
   716                 QString ccFieldText =
   692                     mContentWidget->header()->ccEdit()->text();
   717                     mContent->header()->ccEdit()->text();
   693 
   718 
   694                 if (ccFieldText.length() > 0) {
   719                 if (ccFieldText.length() > 0) {
   695                     mMessage->envelope().setCcRecipients(mContentWidget->header()->ccEdit()->emailAddressList());      
   720                     mMessage->envelope().setCcRecipients(mContent->header()->ccEdit()->emailAddressList());      
   696                 }
   721                 }
   697             }
   722             }
   698             if (mContentWidget->header()->bccEdit()) {
   723             if (mContent->header()->bccEdit()) {
   699                 QString bccFieldText =
   724                 QString bccFieldText =
   700                     mContentWidget->header()->bccEdit()->text();
   725                     mContent->header()->bccEdit()->text();
   701 
   726 
   702                 if (bccFieldText.length() > 0) {
   727                 if (bccFieldText.length() > 0) {
   703                     mMessage->envelope().setBccRecipients(mContentWidget->header()->bccEdit()->emailAddressList());  
   728                     mMessage->envelope().setBccRecipients(mContent->header()->bccEdit()->emailAddressList());  
   704                 }
   729                 }
   705             }
   730             }
   706         }
   731         }
   707     }
   732     }
   708 }
   733 }
   714 */
   739 */
   715 void NmEditorView::fillEditorWithMessageContents()
   740 void NmEditorView::fillEditorWithMessageContents()
   716 {
   741 {
   717     NM_FUNCTION;
   742     NM_FUNCTION;
   718     
   743     
   719     if (!mStartParam || !mMessage || !mContentWidget) {
   744     if (!mStartParam || !mMessage || !mContent) {
   720         return;
   745         return;
   721     }
   746     }
   722 
   747 
   723     NmMessageEnvelope messageEnvelope(mMessage->envelope());
   748     NmMessageEnvelope messageEnvelope(mMessage->envelope());
   724     bool useStartParam(false);
   749     bool useStartParam(false);
   744         toAddressesString = addressListToString(messageEnvelope.toRecipients());
   769         toAddressesString = addressListToString(messageEnvelope.toRecipients());
   745         ccAddressesString = addressListToString(messageEnvelope.ccRecipients());
   770         ccAddressesString = addressListToString(messageEnvelope.ccRecipients());
   746         bccAddressesString = addressListToString(messageEnvelope.bccRecipients());
   771         bccAddressesString = addressListToString(messageEnvelope.bccRecipients());
   747     }
   772     }
   748 
   773 
   749     mContentWidget->header()->toEdit()->setPlainText(toAddressesString);
   774     mContent->header()->toEdit()->setPlainText(toAddressesString);
   750     mContentWidget->header()->ccEdit()->setPlainText(ccAddressesString);
   775     mContent->header()->ccEdit()->setPlainText(ccAddressesString);
   751     mContentWidget->header()->bccEdit()->setPlainText(bccAddressesString);
   776     mContent->header()->bccEdit()->setPlainText(bccAddressesString);
   752 
   777 
   753     if (ccAddressesString.length() || bccAddressesString.length()) {
   778     if (ccAddressesString.length() || bccAddressesString.length()) {
   754         // Since cc or/and bcc recipients exist, expand the group box to display
   779         // Since cc or/and bcc recipients exist, expand the group box to display
   755         // the addresses by expanding the group box.
   780         // the addresses by expanding the group box.
   756         mContentWidget->header()->setFieldVisibility(true);
   781         mContent->header()->setFieldVisibility(true);
   757     }
   782     }
   758 
   783 
   759     // Set subject.
   784     // Set subject.
   760     if (useStartParam) {
   785     if (useStartParam) {
   761         QString *subject = mStartParam->subject();
   786         QString *subject = mStartParam->subject();
   762 
   787 
   763         if (subject) {
   788         if (subject) {
   764             mContentWidget->header()->subjectEdit()->setPlainText(*subject);
   789             mContent->header()->subjectEdit()->setPlainText(*subject);
   765         }
   790         }
   766     }
   791     }
   767     else {
   792     else {
   768         // Construct the subject field.
   793         // Construct the subject field.
   769         mContentWidget->header()->subjectEdit()->setPlainText(
   794         mContent->header()->subjectEdit()->setPlainText(
   770             addSubjectPrefix(editorStartMode, messageEnvelope.subject()));
   795             addSubjectPrefix(editorStartMode, messageEnvelope.subject()));
   771     }
   796     }
   772 
   797 
   773     // Set priority.
   798     // Set priority.
       
   799     if (editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll) {
       
   800         //Clear the importance flag. Replied messages dont keep the importance
       
   801         setPriority(NmActionResponseCommandNone);
       
   802     }
   774     mHeaderWidget->setPriority(messageEnvelope.priority());
   803     mHeaderWidget->setPriority(messageEnvelope.priority());
   775     
   804     
   776     // Set the message body.
   805     // Set the message body.
   777     if (editorStartMode==NmUiEditorReply||
   806     if (editorStartMode==NmUiEditorReply||
   778         editorStartMode==NmUiEditorReplyAll||
   807         editorStartMode==NmUiEditorReplyAll||
   801                                                originalMessage->envelope().folderId(),
   830                                                originalMessage->envelope().folderId(),
   802                                                originalMessage->envelope().messageId(),
   831                                                originalMessage->envelope().messageId(),
   803                                                *htmlPart);
   832                                                *htmlPart);
   804             }
   833             }
   805 
   834 
   806             if (editorStartMode==NmUiEditorFromDrafts) {
   835 		mContent->setMessageData(*originalMessage, editorStartMode);
   807                 mContentWidget->setMessageData(*originalMessage, false);
       
   808             }
       
   809             else {
       
   810                 mContentWidget->setMessageData(*originalMessage);
       
   811             }
       
   812         }
   836         }
   813 
   837 
   814         delete originalMessage;
   838         delete originalMessage;
   815         originalMessage = NULL;
   839         originalMessage = NULL;
   816     }
   840     }
  1026         }
  1050         }
  1027 
  1051 
  1028         // Set the VKB action states
  1052         // Set the VKB action states
  1029         // All editors of the view share the same action, so it is enough to set
  1053         // All editors of the view share the same action, so it is enough to set
  1030         // this only to one of them.
  1054         // this only to one of them.
  1031         HbEditorInterface editorInterface(mContentWidget->editor());
  1055         HbEditorInterface editorInterface(mContent->editor());
  1032         QList<HbAction *> vkbList = editorInterface.actions();
  1056         QList<HbAction *> vkbList = editorInterface.actions();
  1033         count = vkbList.count();
  1057         count = vkbList.count();
  1034         for (int i = 0; i < count; i++) {
  1058         for (int i = 0; i < count; i++) {
  1035             NmAction *action = static_cast<NmAction *>(vkbList[i]);
  1059             NmAction *action = static_cast<NmAction *>(vkbList[i]);
  1036             if (action->availabilityCondition() == NmAction::NmSendable) {
  1060             if (action->availabilityCondition() == NmAction::NmSendable) {
  1068             }
  1092             }
  1069             list[i]->setIcon(NmIcons::getIcon(NmIcons::NmIconSend));
  1093             list[i]->setIcon(NmIcons::getIcon(NmIcons::NmIconSend));
  1070 
  1094 
  1071             // Link VKB to the action. This must be done to all
  1095             // Link VKB to the action. This must be done to all
  1072             // editors that show the button in VKB.
  1096             // editors that show the button in VKB.
  1073             HbEditorInterface editorInterface(mContentWidget->editor());
  1097             HbEditorInterface editorInterface(mContent->editor());
  1074             editorInterface.addAction(list[i]);
  1098             editorInterface.addAction(list[i]);
  1075             HbEditorInterface toEditorInterface(mContentWidget->header()->toEdit());
  1099             HbEditorInterface toEditorInterface(mContent->header()->toEdit());
  1076             toEditorInterface.addAction(list[i]);
  1100             toEditorInterface.addAction(list[i]);
  1077             HbEditorInterface ccEditorInterface(mContentWidget->header()->ccEdit());
  1101             HbEditorInterface ccEditorInterface(mContent->header()->ccEdit());
  1078             ccEditorInterface.addAction(list[i]);
  1102             ccEditorInterface.addAction(list[i]);
  1079             HbEditorInterface bccEditorInterface(mContentWidget->header()->bccEdit());
  1103             HbEditorInterface bccEditorInterface(mContent->header()->bccEdit());
  1080             bccEditorInterface.addAction(list[i]);
  1104             bccEditorInterface.addAction(list[i]);
  1081             HbEditorInterface subjectEditorInterface(mContentWidget->header()->subjectEdit());
  1105             HbEditorInterface subjectEditorInterface(mContent->header()->subjectEdit());
  1082             subjectEditorInterface.addAction(list[i]);
  1106             subjectEditorInterface.addAction(list[i]);
  1083         }
  1107         }
  1084     }
  1108     }
  1085 }
  1109 }
  1086 
  1110 
  1281     if (result == NmNoError && mMessage) {
  1305     if (result == NmNoError && mMessage) {
  1282         // Need to get the message again because new attachment part has been added.
  1306         // Need to get the message again because new attachment part has been added.
  1283         NmId mailboxId = mMessage->envelope().mailboxId();
  1307         NmId mailboxId = mMessage->envelope().mailboxId();
  1284         NmId folderId = mMessage->envelope().folderId();
  1308         NmId folderId = mMessage->envelope().folderId();
  1285         NmId msgId = mMessage->envelope().messageId();
  1309         NmId msgId = mMessage->envelope().messageId();
  1286 
  1310         NmMessagePriority messagePriority = mMessage->envelope().priority();        
       
  1311         
  1287         delete mMessage;
  1312         delete mMessage;
  1288         mMessage = NULL;
  1313         mMessage = NULL;
  1289         
  1314         
  1290         mMessage = mUiEngine.message(mailboxId, folderId, msgId);
  1315         mMessage = mUiEngine.message(mailboxId, folderId, msgId);
  1291 
  1316 
  1292         if (mMessage) {
  1317         if (mMessage) {
       
  1318             mMessage->envelope().setPriority(messagePriority);
       
  1319             mMessage->envelope().setHasAttachments(true);
  1293             // Get attachment list from the message
  1320             // Get attachment list from the message
  1294             QList<NmMessagePart*> attachmentList;
  1321             QList<NmMessagePart*> attachmentList;
  1295             mMessage->attachmentList(attachmentList);
  1322             mMessage->attachmentList(attachmentList);
  1296         
  1323         
  1297             // Search newly added attachment from the list
  1324             // Search newly added attachment from the list
  1365     QList<NmAddress*>::const_iterator i = list.constBegin();
  1392     QList<NmAddress*>::const_iterator i = list.constBegin();
  1366     
  1393     
  1367     while (i != list.constEnd() && *i) {
  1394     while (i != list.constEnd() && *i) {
  1368         if (i > list.constBegin()) {
  1395         if (i > list.constBegin()) {
  1369             // Add the delimiter.
  1396             // Add the delimiter.
  1370             addressesString += Delimiter;
  1397             addressesString += NmDelimiter;
  1371         }
  1398         }
  1372 
  1399 
  1373         addressesString += (*i)->address();
  1400         addressesString += (*i)->address();
  1374         ++i;
  1401         ++i;
  1375     }
  1402     }
  1393     QList<NmAddress>::const_iterator i = list.constBegin();
  1420     QList<NmAddress>::const_iterator i = list.constBegin();
  1394     
  1421     
  1395     while (i != list.constEnd()) {
  1422     while (i != list.constEnd()) {
  1396         if (i > list.constBegin()) {
  1423         if (i > list.constBegin()) {
  1397             // Add the delimiter.
  1424             // Add the delimiter.
  1398             addressesString += Delimiter;
  1425             addressesString += NmDelimiter;
  1399         }
  1426         }
  1400 
  1427 
  1401         addressesString += (*i).address();
  1428         addressesString += (*i).address();
  1402         ++i;
  1429         ++i;
  1403     }
  1430     }
  1445     if (mMessage) {
  1472     if (mMessage) {
  1446         // Reload message because one attachment has been removed
  1473         // Reload message because one attachment has been removed
  1447         NmId mailboxId = mMessage->envelope().mailboxId();
  1474         NmId mailboxId = mMessage->envelope().mailboxId();
  1448         NmId folderId = mMessage->envelope().folderId();
  1475         NmId folderId = mMessage->envelope().folderId();
  1449         NmId msgId = mMessage->envelope().messageId();
  1476         NmId msgId = mMessage->envelope().messageId();
       
  1477         NmMessagePriority messagePriority = mMessage->envelope().priority();    
  1450 
  1478 
  1451         delete mMessage;
  1479         delete mMessage;
  1452         mMessage = NULL;
  1480         mMessage = NULL;
  1453     
  1481     
  1454         mMessage = mUiEngine.message(mailboxId, folderId, msgId);
  1482         mMessage = mUiEngine.message(mailboxId, folderId, msgId);
       
  1483         
       
  1484         if(mMessage) {
       
  1485             // Set the correct priority
       
  1486             mMessage->envelope().setPriority(messagePriority);    
       
  1487             
       
  1488             // If there is no more attachments in the message, set the correct value
       
  1489             QList<NmMessagePart*> attachmentList;
       
  1490             mMessage->attachmentList(attachmentList);
       
  1491             if(attachmentList.count() == 0) {
       
  1492                 mMessage->envelope().setHasAttachments(false);
       
  1493             }
       
  1494         }
  1455     }
  1495     }
  1456 }
  1496 }
  1457 
  1497 
  1458 /*!
  1498 /*!
  1459     This slot is called when 'open' is selected from attachment list context menu.
  1499     This slot is called when 'open' is selected from attachment list context menu.
  1491                 action->setEnabled(enable);
  1531                 action->setEnabled(enable);
  1492             }
  1532             }
  1493         }
  1533         }
  1494     }
  1534     }
  1495 }
  1535 }
  1496 
       
  1497 
       
  1498 // End of file.