emailuis/nmailui/src/nmeditorview.cpp
changeset 68 83cc6bae1de8
parent 66 084b5b1f02a7
child 74 6c59112cfd31
equal deleted inserted replaced
67:459da34cdb45 68:83cc6bae1de8
    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_VIEW_ATTACHMENT_EXTENSION =
       
    23     "attachmentTypeToolbarExtension";
    22 
    24 
    23 // extension list item frame.
    25 // extension list item frame.
    24 static const QString NmPopupListFrame = "qtg_fr_popup_list_normal";
    26 static const QString NmPopupListFrame = "qtg_fr_popup_list_normal";
    25 static const QString NmDelimiter("; ");
    27 static const QString NmDelimiter("; ");
    26 static const QString NmPriorityLow("low");
    28 static const QString NmPriorityLow("low");
    27 static const QString NmPriorityNormal("normal");
    29 static const QString NmPriorityNormal("normal");
    28 static const QString NmPriorityHigh("high");
    30 static const QString NmPriorityHigh("high");
    29 
    31 
       
    32 static const QString NmMimeTypeHtml("text/html");
       
    33 
       
    34 
    30 /*!
    35 /*!
    31 	\class NmEditorView
    36 	\class NmEditorView
    32 	\brief Mail editor view
    37 	\brief Mail editor view
    33 */
    38 */
    34 
    39 
    35 /*!
    40 
    36     Constructor
    41 /*!
       
    42     Class constructor.
    37 */
    43 */
    38 NmEditorView::NmEditorView(
    44 NmEditorView::NmEditorView(
    39     NmApplication &application,
    45     NmApplication &application,
    40     NmUiStartParam* startParam,
    46     NmUiStartParam* startParam,
    41     NmUiEngine &uiEngine,
    47     NmUiEngine &uiEngine,
    42     NmAttachmentManager &attaManager,
    48     NmAttachmentManager &attaManager,
    43     QGraphicsItem *parent)
    49     QGraphicsItem *parent)
    44     : NmBaseView(startParam, application, parent),
    50 : NmBaseView(startParam, application, parent),
    45       mApplication(application),
    51   mApplication(application),
    46       mUiEngine(uiEngine),
    52   mUiEngine(uiEngine),
    47       mAttaManager(attaManager),
    53   mAttaManager(attaManager),
    48       mDocumentLoader(NULL),
    54   mDocumentLoader(NULL),
    49       mHeaderWidget(NULL),
    55   mHeaderWidget(NULL),
    50       mMessage(NULL),
    56   mMessage(NULL),
    51       mContent(NULL),
    57   mContent(NULL),
    52       mAttachmentListContextMenu(NULL),
    58   mAttachmentListContextMenu(NULL),
    53       mMessageCreationOperation(NULL),
    59   mMessageCreationOperation(NULL),
    54       mAddAttachmentOperation(NULL),
    60   mAddAttachmentOperation(NULL),
    55       mRemoveAttachmentOperation(NULL),
    61   mRemoveAttachmentOperation(NULL),
    56       mWaitDialog(NULL),
    62   mWaitDialog(NULL),
    57       mQueryDialog(NULL),
    63   mQueryDialog(NULL),
    58       mAttachmentPicker(NULL),
    64   mAttachmentPicker(NULL),
    59       mCcBccFieldVisible(false),
    65   mCcBccFieldVisible(false),
    60       mServiceSendingDialog(NULL),
    66   mServiceSendingDialog(NULL),
    61       mHiddenPriorityName(NmPriorityNormal)
    67   mTBExtnContentWidget(NULL),
    62 {
    68   mHiddenPriorityName(NmPriorityNormal)
    63     NM_FUNCTION;
    69 {
    64     
    70     NM_FUNCTION;
    65     mDocumentLoader	= new NmUiDocumentLoader( mApplication.mainWindow() );
    71 
    66     // Set object name
    72     mDocumentLoader = new NmUiDocumentLoader(mApplication.mainWindow());
    67     setObjectName("NmEditorView");
    73 
    68     // call the createToolBar on load view layout
    74     // Set the object name.
       
    75     setObjectName(QString(NMUI_EDITOR_VIEW));
       
    76 
       
    77     // Load the view layout.
       
    78     loadViewLayout();
       
    79 
       
    80     // Create the toolbar.
    69     createToolBar();
    81     createToolBar();
    70     // Load view layout
    82 }
    71     loadViewLayout();
    83 
    72 }
    84 
    73 
    85 /*!
    74 /*!
    86     Class destructor.
    75     Destructor
       
    76 */
    87 */
    77 NmEditorView::~NmEditorView()
    88 NmEditorView::~NmEditorView()
    78 {
    89 {
    79     NM_FUNCTION;
    90     NM_FUNCTION;
    80     
    91 
    81     if (mRemoveAttachmentOperation && mRemoveAttachmentOperation->isRunning()) {
    92     if (mRemoveAttachmentOperation && mRemoveAttachmentOperation->isRunning()) {
    82         mRemoveAttachmentOperation->cancelOperation();
    93         mRemoveAttachmentOperation->cancelOperation();
    83     }
    94     }
       
    95 
    84     if (mAddAttachmentOperation && mAddAttachmentOperation->isRunning()) {
    96     if (mAddAttachmentOperation && mAddAttachmentOperation->isRunning()) {
    85         mAddAttachmentOperation->cancelOperation();
    97         mAddAttachmentOperation->cancelOperation();
    86     }
    98     }
       
    99 
    87     if (mMessageCreationOperation && mMessageCreationOperation->isRunning()) {
   100     if (mMessageCreationOperation && mMessageCreationOperation->isRunning()) {
    88         mMessageCreationOperation->cancelOperation();
   101         mMessageCreationOperation->cancelOperation();
    89     }
   102     }
       
   103 
    90     delete mMessage;
   104     delete mMessage;
    91     mWidgetList.clear();
   105     mWidgetList.clear();
    92     delete mDocumentLoader;
   106     delete mDocumentLoader;
    93     delete mPrioritySubMenu;
   107     delete mPrioritySubMenu;
    94     
   108 
    95     if (mAttachmentListContextMenu) {
   109     if (mAttachmentListContextMenu) {
    96         mAttachmentListContextMenu->clearActions();
   110         mAttachmentListContextMenu->clearActions();
    97         delete mAttachmentListContextMenu;
   111         delete mAttachmentListContextMenu;
    98     }
   112     }
       
   113 
    99     delete mWaitDialog;
   114     delete mWaitDialog;
   100     delete mQueryDialog;
   115     delete mQueryDialog;
   101     delete mAttachmentPicker;    
   116     delete mAttachmentPicker;
   102     mAttaManager.clearObserver();
   117     mAttaManager.clearObserver();
   103     mAttaManager.cancelFetch();
   118     mAttaManager.cancelFetch();
   104     
   119 
   105     // make sure virtual keyboard is closed
   120     // make sure virtual keyboard is closed
   106     QInputContext *ic = qApp->inputContext();
   121     QInputContext *ic = qApp->inputContext();
       
   122 
   107     if (ic) {
   123     if (ic) {
   108         QEvent *closeEvent = new QEvent(QEvent::CloseSoftwareInputPanel);
   124         QEvent *closeEvent = new QEvent(QEvent::CloseSoftwareInputPanel);
   109         ic->filterEvent(closeEvent);
   125         ic->filterEvent(closeEvent);
   110         delete closeEvent;
   126         delete closeEvent;
   111     }
   127     }
   112 }
   128 
   113 
   129     if (!mTBExtnContentWidget->parent()) {
   114 /*!
   130         delete mTBExtnContentWidget;
   115     View layout loading from XML
   131     }
       
   132 }
       
   133 
       
   134 
       
   135 /*!
       
   136     Loads the view layout from XML.
   116 */
   137 */
   117 void NmEditorView::loadViewLayout()
   138 void NmEditorView::loadViewLayout()
   118 {
   139 {
   119     NM_FUNCTION;
   140     NM_FUNCTION;
   120     
   141     
   121     mPrioritySubMenu = NULL;
   142     mPrioritySubMenu = NULL;
   122 
   143 
   123     // Use document loader to load the view
   144     // Use the document loader to load the view.
   124     bool ok(false);
       
   125 
       
   126     setObjectName(QString(NMUI_EDITOR_VIEW));
       
   127     QObjectList objectList;
   145     QObjectList objectList;
   128     objectList.append(this);
   146     objectList.append(this);
   129     // Pass the view to documentloader. Document loader uses this view
   147 
   130     // when docml is parsed, instead of creating new view.
   148     // Pass the view to documentloader. Document loader uses this view when
   131     // documentloader is created in constructor
   149     // docml is parsed, instead of creating new view. The document loader is
       
   150     // created in the constructor.
   132     mDocumentLoader->setObjectTree(objectList);
   151     mDocumentLoader->setObjectTree(objectList);
   133 
   152 
       
   153     bool ok(false);
   134     mWidgetList = mDocumentLoader->load(NMUI_EDITOR_VIEW_XML, &ok);
   154     mWidgetList = mDocumentLoader->load(NMUI_EDITOR_VIEW_XML, &ok);
   135 
   155 
   136    if (ok) {
   156    if (ok) {
   137         mContent = new NmEditorContent(this, mDocumentLoader, 
   157        mContent = new NmEditorContent(this, mDocumentLoader, 
   138             mApplication.networkAccessManager(), mApplication);
   158                                       mApplication.networkAccessManager(),
   139 
   159                                       mApplication);
   140         mHeaderWidget = mContent->header();
   160 
   141 
   161        mHeaderWidget = mContent->header();
   142         // Set default color for user - entered text if editor is in re/reAll/fw mode
   162 
   143         if (mStartParam) {
   163        // Set default color for user - entered text if editor is in re/reAll/fw
   144             NmUiEditorStartMode mode = mStartParam->editorStartMode();
   164        // mode.
   145             if (mode == NmUiEditorReply
   165        if (mStartParam) {
   146                 || mode == NmUiEditorReplyAll 
   166            NmUiEditorStartMode mode = mStartParam->editorStartMode();
   147                 || mode == NmUiEditorForward) {
   167 
   148                 mContent->editor()->setCustomTextColor(true, Qt::blue);
   168            if (mode == NmUiEditorReply ||
   149             }
   169                mode == NmUiEditorReplyAll || 
   150         }
   170                mode == NmUiEditorForward) {
   151 
   171                mContent->editor()->setCustomTextColor(true, Qt::blue);
   152         // the rest of the view initialization is done in viewReady()
   172            }
   153     }
   173        }
   154 }
   174 
       
   175        // Get the toolbar extension for adding attachments.
       
   176        mTBExtnContentWidget = qobject_cast<HbListWidget *>(
       
   177            mDocumentLoader->findWidget(NMUI_EDITOR_VIEW_ATTACHMENT_EXTENSION));
       
   178 
       
   179        // The rest of the view initialization is done in viewReady().
       
   180     }
       
   181 }
       
   182 
   155 
   183 
   156 /*!
   184 /*!
   157     Reload view contents with new start parameters
   185     Reload view contents with new start parameters
   158     Typically when view is already open and external view activation occurs
   186     Typically when view is already open and external view activation occurs
   159     for this same view
   187     for this same view
   160 */
   188 */
   161 void NmEditorView::reloadViewContents(NmUiStartParam* startParam)
   189 void NmEditorView::reloadViewContents(NmUiStartParam* startParam)
   162 {
   190 {
   163     NM_FUNCTION;
   191     NM_FUNCTION;
   164     
   192 
   165     // Check start parameter validity.
   193     // Check start parameter validity.
   166     if (startParam&&startParam->viewId()==NmUiViewMessageEditor) {
   194     if (startParam&&startParam->viewId()==NmUiViewMessageEditor) {
   167         // Delete existing start parameter data
   195         // Delete existing start parameter data
   168         delete mStartParam;
   196         delete mStartParam;
   169         mStartParam=NULL;
   197         mStartParam=NULL;
   189    be wrapped again.
   217    be wrapped again.
   190 */
   218 */
   191 void NmEditorView::orientationChanged(Qt::Orientation orientation)
   219 void NmEditorView::orientationChanged(Qt::Orientation orientation)
   192 {
   220 {
   193     NM_FUNCTION;
   221     NM_FUNCTION;
   194     
   222 
   195     Q_UNUSED(orientation);
   223     Q_UNUSED(orientation);
   196     
   224 
   197     // content widget height needs to be set according to the new orientation to get the scroll
   225     // content widget height needs to be set according to the new orientation to get the scroll
   198 	// area work correctly
   226 	// area work correctly
   199 	mHeaderWidget->sendDelayedHeaderHeightChanged();
   227 	mHeaderWidget->sendDelayedHeaderHeightChanged();
   200 	mHeaderWidget->adjustHeaderWidth();
   228 	mHeaderWidget->adjustHeaderWidth();
   201 }
   229 }
   203 /*!
   231 /*!
   204     This slot is signaled by VKB when it opens
   232     This slot is signaled by VKB when it opens
   205  */
   233  */
   206 void NmEditorView::vkbOpened()
   234 void NmEditorView::vkbOpened()
   207 {
   235 {
   208     showChrome(false);	
   236     showChrome(false);
   209 }
   237 }
   210 
   238 
   211 /*!
   239 /*!
   212     This slot is signaled by VKB when it closes.
   240     This slot is signaled by VKB when it closes.
   213  */
   241  */
   235     View id
   263     View id
   236 */
   264 */
   237 NmUiViewId NmEditorView::nmailViewId() const
   265 NmUiViewId NmEditorView::nmailViewId() const
   238 {
   266 {
   239     NM_FUNCTION;
   267     NM_FUNCTION;
   240     
   268 
   241     return NmUiViewMessageEditor;
   269     return NmUiViewMessageEditor;
   242 }
   270 }
   243 
   271 
   244 /*
   272 /*
   245    Launch dialog for query user if we want to exit the editor
   273    Launch dialog for query user if we want to exit the editor
   246 */
   274 */
   247 void NmEditorView::okToExitView()
   275 void NmEditorView::okToExitView()
   248 {
   276 {
   249     NM_FUNCTION;
   277     NM_FUNCTION;
   250        
   278 
   251     bool okToExit(true);
   279     bool okToExit(true);
   252     
   280 
   253     if (mContent) {
   281     if (mContent) {
   254         NmEditorHeader *header = mContent->header();
   282         NmEditorHeader *header = mContent->header();
   255         // show the query if the message has not been sent
   283         // show the query if the message has not been sent
   256         if (mMessage && header) {
   284         if (mMessage && header) {
   257             // see if editor has any content
   285             // see if editor has any content
   258             int subjectLength = 0;
   286             int subjectLength = 0;
   259             if (header->subjectEdit()) {
   287             if (header->subjectEdit()) {
   260                 subjectLength = header->subjectEdit()->text().length();
   288                 subjectLength = header->subjectEdit()->text().length();
   261             }
   289             }
   262             
   290 
   263             QList<NmMessagePart*> attachmentList;
   291             QList<NmMessagePart*> attachmentList;
   264             mMessage->attachmentList(attachmentList);
   292             mMessage->attachmentList(attachmentList);
   265             
   293 
   266             if (mContent->editor()) {
   294             if (mContent->editor()) {
   267                 okToExit = (subjectLength == 0 && mContent->editor()->document()->isEmpty());            
   295                 okToExit = (subjectLength == 0 && mContent->editor()->document()->isEmpty());
   268             }
   296             }
   269     
   297 
   270             // content exists, verify exit from user
   298             // content exists, verify exit from user
   271             if (!okToExit) {
   299             if (!okToExit) {
   272                 if (mQueryDialog) {
   300                 if (mQueryDialog) {
   273                     delete mQueryDialog;
   301                     delete mQueryDialog;
   274                     mQueryDialog = 0;
   302                     mQueryDialog = 0;
   275                 }
   303                 }
   276                 // Launch query dialog.
   304                 // Launch query dialog.
   277                 mQueryDialog = 
   305                 mQueryDialog =
   278                     NmUtilities::displayQuestionNote(hbTrId("txt_mail_dialog_save_message_to_drafts"),
   306                     NmUtilities::displayQuestionNote(hbTrId("txt_mail_dialog_save_message_to_drafts"),
   279                                                                 this,
   307                                                                 this,
   280                                                                 SLOT(okToExitQuery(HbAction*)));
   308                                                                 SLOT(okToExitQuery(HbAction*)));
   281             }
   309             }
   282         }    
   310         }
   283     }
   311     }
   284     
   312 
   285     // no need to query anything, just exit.
   313     // no need to query anything, just exit.
   286     if(okToExit) {
   314     if(okToExit) {
   287         QMetaObject::invokeMethod(&mApplication,
   315         QMetaObject::invokeMethod(&mApplication,
   288                                   "popView",
   316                                   "popView",
   289                                   Qt::QueuedConnection);
   317                                   Qt::QueuedConnection);
   294     Handle the user selection is it ok to exit.
   322     Handle the user selection is it ok to exit.
   295 */
   323 */
   296 void NmEditorView::okToExitQuery(HbAction *action)
   324 void NmEditorView::okToExitQuery(HbAction *action)
   297 {
   325 {
   298     NM_FUNCTION;
   326     NM_FUNCTION;
   299     
   327 
   300     HbMessageBox *dlg = static_cast<HbMessageBox*>(sender());
   328     HbMessageBox *dlg = static_cast<HbMessageBox*>(sender());
   301     // The first action in dialogs action list is for the "Yes"-button.
   329     // The first action in dialogs action list is for the "Yes"-button.
   302     if (action == dlg->actions().at(0)) {
   330     if (action == dlg->actions().at(0)) {
   303         safeToDraft();
   331         safeToDraft();
   304     }    
   332     }
   305     
   333 
   306     // Close the view
   334     // Close the view
   307     QMetaObject::invokeMethod(&mApplication,
   335     QMetaObject::invokeMethod(&mApplication,
   308                               "popView",
   336                               "popView",
   309                               Qt::QueuedConnection);
   337                               Qt::QueuedConnection);
   310 }
   338 }
   338     called when "auto-exiting" after a successful mail sending.
   366     called when "auto-exiting" after a successful mail sending.
   339 */
   367 */
   340 void NmEditorView::aboutToExitView()
   368 void NmEditorView::aboutToExitView()
   341 {
   369 {
   342     NM_FUNCTION;
   370     NM_FUNCTION;
   343     
   371 
   344     // These operations need to be stopped before message can be deleted
   372     // These operations need to be stopped before message can be deleted
   345     if (mAddAttachmentOperation && mAddAttachmentOperation->isRunning()) {
   373     if (mAddAttachmentOperation && mAddAttachmentOperation->isRunning()) {
   346         mAddAttachmentOperation->cancelOperation();
   374         mAddAttachmentOperation->cancelOperation();
   347     }
   375     }
   348     if (mRemoveAttachmentOperation && mRemoveAttachmentOperation->isRunning()) {
   376     if (mRemoveAttachmentOperation && mRemoveAttachmentOperation->isRunning()) {
   363 {
   391 {
   364     NM_FUNCTION;
   392     NM_FUNCTION;
   365 
   393 
   366     // Set mailbox name to title pane
   394     // Set mailbox name to title pane
   367     setMailboxName();
   395     setMailboxName();
   368     
   396 
   369     // Connect options menu about to show to create options menu function
   397     // Connect options menu about to show to create options menu function
   370     // Menu needs to be create "just-in-time"
   398     // Menu needs to be create "just-in-time"
   371     connect(menu(), SIGNAL(aboutToShow()), this, SLOT(createOptionsMenu()));
   399     connect(menu(), SIGNAL(aboutToShow()), this, SLOT(createOptionsMenu()));
   372     NmAction *dummy = new NmAction(0);
   400     NmAction *dummy = new NmAction(0);
   373     menu()->addAction(dummy);
   401     menu()->addAction(dummy);
   374 
   402 
   375     mVkbHost = new HbShrinkingVkbHost(this);
   403     mVkbHost = new HbShrinkingVkbHost(this);
   376     
   404 
   377     initializeVKB();
   405     initializeVKB();
   378     
   406 
   379     //start to listen VKB open and close signals for hiding the chrome.
   407     //start to listen VKB open and close signals for hiding the chrome.
   380     connect(mVkbHost, SIGNAL(keypadOpened()), this, SLOT(vkbOpened()));
   408     connect(mVkbHost, SIGNAL(keypadOpened()), this, SLOT(vkbOpened()));
   381     connect(mVkbHost, SIGNAL(keypadClosed()), this, SLOT(vkbClosed()));
   409     connect(mVkbHost, SIGNAL(keypadClosed()), this, SLOT(vkbClosed()));
   382     
   410 
   383     connect(mContent->header(), SIGNAL(recipientFieldsHaveContent(bool)),
   411     connect(mContent->header(), SIGNAL(recipientFieldsHaveContent(bool)),
   384             this, SLOT(setButtonsDimming(bool)) );
   412             this, SLOT(setButtonsDimming(bool)) );
   385 
   413 
   386     // Connect to observe orientation change events
   414     // Connect to observe orientation change events
   387     connect(mApplication.mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
   415     connect(mApplication.mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
   389     // Signal for handling the attachment list selection
   417     // Signal for handling the attachment list selection
   390     connect(mHeaderWidget, SIGNAL(attachmentShortPressed(NmId)),
   418     connect(mHeaderWidget, SIGNAL(attachmentShortPressed(NmId)),
   391             this, SLOT(openAttachmentTriggered(NmId)));
   419             this, SLOT(openAttachmentTriggered(NmId)));
   392     connect(mHeaderWidget, SIGNAL(attachmentLongPressed(NmId, QPointF)),
   420     connect(mHeaderWidget, SIGNAL(attachmentLongPressed(NmId, QPointF)),
   393             this, SLOT(attachmentLongPressed(NmId, QPointF)));
   421             this, SLOT(attachmentLongPressed(NmId, QPointF)));
   394     
   422 
   395     if (mStartParam) {
   423     if (mStartParam) {
   396         fetchMessageIfNeeded(*mStartParam);
   424         fetchMessageIfNeeded(*mStartParam);
   397     }
   425     }
   398     else { // execution cannot proceed without start param 
   426     else { // execution cannot proceed without start param
   399         QMetaObject::invokeMethod(&mApplication, "popView", Qt::QueuedConnection);
   427         QMetaObject::invokeMethod(&mApplication, "popView", Qt::QueuedConnection);
   400     }
   428     }
   401     
   429 
   402     // Adjust the header width according to the current screen width.
   430     // Adjust the header width according to the current screen width.
   403     mHeaderWidget->adjustHeaderWidth(); 
   431     mHeaderWidget->adjustHeaderWidth();
   404 }
   432 }
   405 
   433 
   406 /*!
   434 /*!
   407     If entering editor for forwarding or replying, use attachment manager
   435     If entering editor for forwarding or replying, use attachment manager
   408     to check that we have all message parts fetched. Also show dialog for
   436     to check that we have all message parts fetched. Also show dialog for
   409     fetching progress.
   437     fetching progress.
   410 */
   438 */
   411 void NmEditorView::fetchMessageIfNeeded(NmUiStartParam &startParam)
   439 void NmEditorView::fetchMessageIfNeeded(NmUiStartParam &startParam)
   412 {
   440 {
   413     NM_FUNCTION;
   441     NM_FUNCTION;
   414     
   442 
   415     if (startParam.editorStartMode() == NmUiEditorForward
   443     if (startParam.editorStartMode() == NmUiEditorForward
   416         || startParam.editorStartMode()== NmUiEditorReply
   444         || startParam.editorStartMode()== NmUiEditorReply
   417         || startParam.editorStartMode() == NmUiEditorReplyAll) {
   445         || startParam.editorStartMode() == NmUiEditorReplyAll) {
   418     
   446 
   419         fetchProgressDialogShow();
   447         fetchProgressDialogShow();
   420         mAttaManager.clearObserver();
   448         mAttaManager.clearObserver();
   421         mAttaManager.setObserver(this);
   449         mAttaManager.setObserver(this);
   422         mAttaManager.fetchAllMessageParts(
   450         mAttaManager.fetchAllMessageParts(
   423             startParam.mailboxId(),
   451             startParam.mailboxId(),
   433     Slot. Called when attachments fetch progress changes.
   461     Slot. Called when attachments fetch progress changes.
   434 */
   462 */
   435 void NmEditorView::progressChanged(int value)
   463 void NmEditorView::progressChanged(int value)
   436 {
   464 {
   437     NM_FUNCTION;
   465     NM_FUNCTION;
   438     
   466 
   439     Q_UNUSED(value);
   467     Q_UNUSED(value);
   440 }
   468 }
   441 
   469 
   442 /*!
   470 /*!
   443     Slot. Called when attachments fetch is completed. We can start
   471     Slot. Called when attachments fetch is completed. We can start
   444     message creation. 
   472     message creation.
   445 */
   473 */
   446 void NmEditorView::fetchCompleted(int result)
   474 void NmEditorView::fetchCompleted(int result)
   447 {
   475 {
   448     NM_FUNCTION;
   476     NM_FUNCTION;
   449     
   477 
   450     if (result == NmNoError && mStartParam) {
   478     if (result == NmNoError && mStartParam) {
   451         startMessageCreation(*mStartParam);
   479         startMessageCreation(*mStartParam);
   452     }
   480     }
   453     else {
   481     else {
   454         // Close "Loading mail content" dialog
   482         // Close "Loading mail content" dialog
   455         mWaitDialog->close();
   483         mWaitDialog->close();
   456         
   484 
   457         // Show a fetching failed note when the failure is not caused by a Device/System failure.
   485         // Show a fetching failed note when the failure is not caused by a Device/System failure.
   458         if (result != NmNoError && 
   486         if (result != NmNoError &&
   459             result != NmNotFoundError &&
   487             result != NmNotFoundError &&
   460             result != NmGeneralError &&
   488             result != NmGeneralError &&
   461             result != NmCancelError &&
   489             result != NmCancelError &&
   462             result != NmAuthenticationError &&
   490             result != NmAuthenticationError &&
   463             result != NmServerConnectionError &&
   491             result != NmServerConnectionError &&
   464             result != NmConnectionError) {         
   492             result != NmConnectionError) {
   465             HbNotificationDialog *note = new HbNotificationDialog();            
   493             HbNotificationDialog *note = new HbNotificationDialog();
   466             bool enalbeAttribute(true);
   494             bool enalbeAttribute(true);
   467             note->setAttribute(Qt::WA_DeleteOnClose, enalbeAttribute);           
   495             note->setAttribute(Qt::WA_DeleteOnClose, enalbeAttribute);
   468             note->setIcon(HbIcon(QLatin1String("note_warning")));        
   496             note->setIcon(HbIcon(QLatin1String("note_warning")));
   469             note->setTitle(hbTrId("txt_mail_dpopinfo_loading_failed"));
   497             note->setTitle(hbTrId("txt_mail_dpopinfo_loading_failed"));
   470             note->setTitleTextWrapping(Hb::TextWordWrap);      
   498             note->setTitleTextWrapping(Hb::TextWordWrap);
   471             note->setDismissPolicy(HbNotificationDialog::TapAnywhere);
   499             note->setDismissPolicy(HbNotificationDialog::TapAnywhere);
   472             note->setTimeout(HbNotificationDialog::StandardTimeout);       
   500             note->setTimeout(HbNotificationDialog::StandardTimeout);
   473             note->setSequentialShow(true);
   501             note->setSequentialShow(true);
   474             note->show();
   502             note->show();
   475         }
   503         }
   476         
   504 
   477         // Go back to Viewer view
   505         // Go back to Viewer view
   478         QMetaObject::invokeMethod(&mApplication, "popView", Qt::QueuedConnection);
   506         QMetaObject::invokeMethod(&mApplication, "popView", Qt::QueuedConnection);
   479     }
   507     }
   480 }
   508 }
   481 
   509 
   482 void NmEditorView::fetchProgressDialogShow()
   510 void NmEditorView::fetchProgressDialogShow()
   483 {
   511 {
   484     NM_FUNCTION;
   512     NM_FUNCTION;
   485     
   513 
   486     delete mWaitDialog;
   514     delete mWaitDialog;
   487     mWaitDialog = NULL;
   515     mWaitDialog = NULL;
   488     // Create new wait dialog and set it to me modal with dimmed background
   516     // Create new wait dialog and set it to me modal with dimmed background
   489     mWaitDialog = new HbProgressDialog(HbProgressDialog::WaitDialog);
   517     mWaitDialog = new HbProgressDialog(HbProgressDialog::WaitDialog);
   490     mWaitDialog->setModal(true);
   518     mWaitDialog->setModal(true);
   499     This is called by mFetchProgressDialog when the note is cancelled
   527     This is called by mFetchProgressDialog when the note is cancelled
   500  */
   528  */
   501 void NmEditorView::fetchProgressDialogCancelled()
   529 void NmEditorView::fetchProgressDialogCancelled()
   502 {
   530 {
   503     NM_FUNCTION;
   531     NM_FUNCTION;
   504     
   532 
   505     if (mAttaManager.isFetching()) { 
   533     if (mAttaManager.isFetching()) {
   506         mAttaManager.cancelFetch();
   534         mAttaManager.cancelFetch();
   507         mAttaManager.clearObserver();
   535         mAttaManager.clearObserver();
   508     }
   536     }
   509     else {   
   537     else {
   510         // For those email has no attachment or attachment has fetched.
   538         // For those email has no attachment or attachment has fetched.
   511         // Go back to Viewer view.
   539         // Go back to Viewer view.
   512         QMetaObject::invokeMethod(&mApplication, "popView", Qt::QueuedConnection);
   540         QMetaObject::invokeMethod(&mApplication, "popView", Qt::QueuedConnection);
   513     }
   541     }
   514 }
   542 }
   515 
   543 
   516 void NmEditorView::startMessageCreation(NmUiStartParam &startParam)
   544 void NmEditorView::startMessageCreation(NmUiStartParam &startParam)
   517 {
   545 {
   518     NM_FUNCTION;
   546     NM_FUNCTION;
       
   547     NM_TIMESTAMP("Start editor.");
   519     
   548     
   520     NmUiEditorStartMode startMode = startParam.editorStartMode();
   549     NmUiEditorStartMode startMode = startParam.editorStartMode();
   521     NmId mailboxId = startParam.mailboxId();
   550     NmId mailboxId = startParam.mailboxId();
   522     NmId folderId = startParam.folderId();
   551     NmId folderId = startParam.folderId();
   523     NmId msgId = startParam.messageId();
   552     NmId msgId = startParam.messageId();
   524     
   553 
   525     if (mMessageCreationOperation && mMessageCreationOperation->isRunning()) {
   554     if (mMessageCreationOperation && mMessageCreationOperation->isRunning()) {
   526         mMessageCreationOperation->cancelOperation();
   555         mMessageCreationOperation->cancelOperation();
   527     }
   556     }
   528 	  
   557 
   529     // original message is now fetched so start message creation
   558     // original message is now fetched so start message creation
   530     if (startMode == NmUiEditorForward) {
   559     if (startMode == NmUiEditorForward) {
   531         mMessageCreationOperation = mUiEngine.createForwardMessage(mailboxId, msgId);
   560         mMessageCreationOperation = mUiEngine.createForwardMessage(mailboxId, msgId);
   532     }
   561     }
   533     else if (startMode == NmUiEditorReply || startMode == NmUiEditorReplyAll) {
   562     else if (startMode == NmUiEditorReply || startMode == NmUiEditorReplyAll) {
   534         mMessageCreationOperation = mUiEngine.createReplyMessage(mailboxId, 
   563         mMessageCreationOperation = mUiEngine.createReplyMessage(mailboxId,
   535             msgId, 
   564             msgId,
   536             startMode == NmUiEditorReplyAll);
   565             startMode == NmUiEditorReplyAll);
   537     }
   566     }
   538     else if (startMode == NmUiEditorFromDrafts) {
   567     else if (startMode == NmUiEditorFromDrafts) {
   539         // Draft opened, so reload message and fill editor with message data.
   568         // Draft opened, so reload message and fill editor with message data.
   540         mMessage = mUiEngine.message(
   569         mMessage = mUiEngine.message(
   541             mStartParam->mailboxId(), 
   570             mStartParam->mailboxId(),
   542             mStartParam->folderId(), 
   571             mStartParam->folderId(),
   543             mStartParam->messageId());
   572             mStartParam->messageId());
   544         fillEditorWithMessageContents();
   573         fillEditorWithMessageContents();
   545     }
   574     }
   546     else {
   575     else {
   547         mMessageCreationOperation = mUiEngine.createNewMessage(mailboxId);
   576         mMessageCreationOperation = mUiEngine.createNewMessage(mailboxId);
   548     }
   577     }
   549     
   578 
   550     // operation continues in messageCreated() once it finishes ok
   579     // operation continues in messageCreated() once it finishes ok
   551     if (mMessageCreationOperation) {
   580     if (mMessageCreationOperation) {
   552         connect(mMessageCreationOperation,
   581         connect(mMessageCreationOperation,
   553                 SIGNAL(operationCompleted(int)),
   582                 SIGNAL(operationCompleted(int)),
   554                 this,
   583                 this,
   555                 SLOT(messageCreated(int)));
   584                 SLOT(messageCreated(int)));
   556     }    
   585     }
   557 }
   586 }
   558 
   587 
   559 /*!
   588 /*!
   560     Starting the message sending is handled here.
   589     Starting the message sending is handled here.
   561 */
   590 */
   562 void NmEditorView::startSending()
   591 void NmEditorView::startSending()
   563 {
   592 {
   564     NM_FUNCTION;
   593     NM_FUNCTION;
   565     
   594 
   566     // The message contents should be verified
   595     // The message contents should be verified
   567     updateMessageWithEditorContents();
   596     updateMessageWithEditorContents();
   568     
   597 
   569     // verify addresses before sending
   598     // verify addresses before sending
   570     QList<NmAddress> invalidAddresses;
   599     QList<NmAddress> invalidAddresses;
   571     if (mMessage) {
   600     if (mMessage) {
   572         NmUtilities::getRecipientsFromMessage(*mMessage, invalidAddresses, NmUtilities::NmInvalidAddress);
   601         NmUtilities::getRecipientsFromMessage(*mMessage, invalidAddresses, NmUtilities::NmInvalidAddress);
   573     }
   602     }
   574     
   603 
   575     if (invalidAddresses.count() > 0) {
   604     if (invalidAddresses.count() > 0) {
   576         
   605 
   577         // Invalid addresses found, verify send from user.
   606         // Invalid addresses found, verify send from user.
   578         // Set the first failing address to the note.
   607         // Set the first failing address to the note.
   579         QString noteText = 
   608         QString noteText =
   580             HbParameterLengthLimiter(
   609             HbParameterLengthLimiter(
   581                 "txt_mail_dialog_invalid_mail_address_send"
   610                 "txt_mail_dialog_invalid_mail_address_send"
   582                 ).arg(invalidAddresses.at(0).address());
   611                 ).arg(invalidAddresses.at(0).address());
   583         
   612 
   584         if (mQueryDialog) {
   613         if (mQueryDialog) {
   585             delete mQueryDialog;
   614             delete mQueryDialog;
   586             mQueryDialog = 0;
   615             mQueryDialog = 0;
   587         }
   616         }
   588         // Launch query dialog. Pressing "yes" will finalize the sending.
   617         // Launch query dialog. Pressing "yes" will finalize the sending.
   600     Send the message after all checks have been done.
   629     Send the message after all checks have been done.
   601 */
   630 */
   602 void NmEditorView::finalizeSending()
   631 void NmEditorView::finalizeSending()
   603 {
   632 {
   604     NM_FUNCTION;
   633     NM_FUNCTION;
   605     
   634 
   606     QList<NmOperation *> preliminaryOperations;
   635     QList<NmOperation *> preliminaryOperations;
   607     if (mAddAttachmentOperation && mAddAttachmentOperation->isRunning()) {
   636     if (mAddAttachmentOperation && mAddAttachmentOperation->isRunning()) {
   608         preliminaryOperations.append(mAddAttachmentOperation);
   637         preliminaryOperations.append(mAddAttachmentOperation);
   609     }
   638     }
   610     if (mRemoveAttachmentOperation && mRemoveAttachmentOperation->isRunning()) {
   639     if (mRemoveAttachmentOperation && mRemoveAttachmentOperation->isRunning()) {
   618 
   647 
   619     bool service = XQServiceUtil::isService();
   648     bool service = XQServiceUtil::isService();
   620 
   649 
   621     // If sending is started as a service, progress dialog needs to be shown
   650     // If sending is started as a service, progress dialog needs to be shown
   622     // so long that sending is finished otherwise we can close pop current view.
   651     // so long that sending is finished otherwise we can close pop current view.
   623     if (service && mStartParam && mStartParam->service() && 
   652     if (service && mStartParam && mStartParam->service() &&
   624         mUiEngine.isSendingMessage()) {
   653         mUiEngine.isSendingMessage()) {
   625         connect(&mUiEngine, SIGNAL(sendOperationCompleted()),
   654         connect(&mUiEngine, SIGNAL(sendOperationCompleted()),
   626             this, SLOT(handleSendOperationCompleted()), Qt::UniqueConnection);
   655             this, SLOT(handleSendOperationCompleted()), Qt::UniqueConnection);
   627 
   656 
   628         // Construct and setup the wait dialog.
   657         // Construct and setup the wait dialog.
   665     This is called when the view's geometry size has been changed, eg. when VKB is opened/closed.
   694     This is called when the view's geometry size has been changed, eg. when VKB is opened/closed.
   666 */
   695 */
   667 void NmEditorView::resizeEvent(QGraphicsSceneResizeEvent *event)
   696 void NmEditorView::resizeEvent(QGraphicsSceneResizeEvent *event)
   668 {
   697 {
   669     NM_FUNCTION;
   698     NM_FUNCTION;
   670     
   699 
   671     NmBaseView::resizeEvent(event);
   700     NmBaseView::resizeEvent(event);
   672     
   701 
   673     emit sizeChanged();
   702     emit sizeChanged();
   674 }
   703 }
   675 
   704 
   676 /*!
   705 /*!
   677     This is signalled by mMessageCreationOperation when message is created.
   706     This is signalled by mMessageCreationOperation when message is created.
   678 */
   707 */
   679 void NmEditorView::messageCreated(int result)
   708 void NmEditorView::messageCreated(int result)
   680 {
   709 {
   681     NM_FUNCTION;
   710     NM_FUNCTION;
       
   711     NM_TIMESTAMP("Editor opened.");
   682     
   712     
   683     delete mMessage;
   713     delete mMessage;
   684     mMessage = NULL;
   714     mMessage = NULL;
   685 
   715 
   686     // Close wait dialog here
   716     // Close wait dialog here
   687     if (mWaitDialog) {
   717     if (mWaitDialog) {
   688         mWaitDialog->close();
   718         mWaitDialog->close();
   689     }
   719     }
   690     
   720 
   691     if (result == NmNoError && mStartParam && mMessageCreationOperation) {
   721     if (result == NmNoError && mStartParam && mMessageCreationOperation) {
   692         NmUiEditorStartMode startMode = mStartParam->editorStartMode();
   722         NmUiEditorStartMode startMode = mStartParam->editorStartMode();
   693         
   723 
   694         // get message "again" from engine to update the message contents 
   724         // get message "again" from engine to update the message contents
   695         mMessage = mUiEngine.message(
   725         mMessage = mUiEngine.message(
   696             mStartParam->mailboxId(), 
   726             mStartParam->mailboxId(),
   697             mStartParam->folderId(), 
   727             mStartParam->folderId(),
   698             mMessageCreationOperation->getMessageId());
   728             mMessageCreationOperation->getMessageId());
   699         
   729 
   700         fillEditorWithMessageContents();       
   730         fillEditorWithMessageContents();
   701     }
   731     }
   702 }
   732 }
   703 
   733 
   704 /*!
   734 /*!
   705    Updates the message with the editor contents.
   735    Updates the message with the editor contents.
   706 */
   736 */
   707 void NmEditorView::updateMessageWithEditorContents()
   737 void NmEditorView::updateMessageWithEditorContents()
   708 {
   738 {
   709     NM_FUNCTION;
   739     NM_FUNCTION;
   710     
   740 
   711     if (mMessage) {
   741     if (mMessage) {
   712         if (mContent && mContent->editor()) {
   742         if (mContent && mContent->editor()) {
   713             NmMessagePart* bodyPart = mMessage->htmlBodyPart();
   743             NmMessagePart* bodyPart = mMessage->htmlBodyPart();
   714             if (bodyPart) {
   744             if (bodyPart) {
   715                 bodyPart->setTextContent(mContent->editor()->toHtml(), NmContentTypeTextHtml);
   745                 bodyPart->setTextContent(mContent->editor()->toHtml(), NmContentTypeTextHtml);
   729                     mContent->header()->toEdit()->text();
   759                     mContent->header()->toEdit()->text();
   730 
   760 
   731                 // This verification of zero length string isn't needed
   761                 // This verification of zero length string isn't needed
   732                 // after list of addresses
   762                 // after list of addresses
   733                 if (toFieldText.length() > 0) {
   763                 if (toFieldText.length() > 0) {
   734                     mMessage->envelope().setToRecipients(mContent->header()->toEdit()->emailAddressList());  
   764                     mMessage->envelope().setToRecipients(mContent->header()->toEdit()->emailAddressList());
   735                 }
   765                 }
   736             }
   766             }
   737             if (mContent->header()->ccEdit()) {
   767             if (mContent->header()->ccEdit()) {
   738                 QString ccFieldText =
   768                 QString ccFieldText =
   739                     mContent->header()->ccEdit()->text();
   769                     mContent->header()->ccEdit()->text();
   740 
   770 
   741                 if (ccFieldText.length() > 0) {
   771                 if (ccFieldText.length() > 0) {
   742                     mMessage->envelope().setCcRecipients(mContent->header()->ccEdit()->emailAddressList());      
   772                     mMessage->envelope().setCcRecipients(mContent->header()->ccEdit()->emailAddressList());
   743                 }
   773                 }
   744             }
   774             }
   745             if (mContent->header()->bccEdit()) {
   775             if (mContent->header()->bccEdit()) {
   746                 QString bccFieldText =
   776                 QString bccFieldText =
   747                     mContent->header()->bccEdit()->text();
   777                     mContent->header()->bccEdit()->text();
   748 
   778 
   749                 if (bccFieldText.length() > 0) {
   779                 if (bccFieldText.length() > 0) {
   750                     mMessage->envelope().setBccRecipients(mContent->header()->bccEdit()->emailAddressList());  
   780                     mMessage->envelope().setBccRecipients(mContent->header()->bccEdit()->emailAddressList());
   751                 }
   781                 }
   752             }
   782             }
   753         }
   783         }
   754     }
   784     }
   755 }
   785 }
   760     editor is launched.
   790     editor is launched.
   761 */
   791 */
   762 void NmEditorView::fillEditorWithMessageContents()
   792 void NmEditorView::fillEditorWithMessageContents()
   763 {
   793 {
   764     NM_FUNCTION;
   794     NM_FUNCTION;
   765     
   795 
   766     if (!mStartParam || !mMessage || !mContent) {
   796     if (!mStartParam || !mMessage || !mContent) {
   767         return;
   797         return;
   768     }
   798     }
   769 
   799 
   770     NmMessageEnvelope messageEnvelope(mMessage->envelope());
   800     NmMessageEnvelope messageEnvelope(mMessage->envelope());
   772 
   802 
   773     NmUiEditorStartMode editorStartMode = mStartParam->editorStartMode();
   803     NmUiEditorStartMode editorStartMode = mStartParam->editorStartMode();
   774 
   804 
   775     if (editorStartMode == NmUiEditorMailto) {
   805     if (editorStartMode == NmUiEditorMailto) {
   776         // Retrieve the message header data e.g. recipients from mStartParam.
   806         // Retrieve the message header data e.g. recipients from mStartParam.
   777         useStartParam = true;        
   807         useStartParam = true;
   778     }
   808     }
   779     
   809 
   780     // Set recipients (to, cc and bcc).
   810     // Set recipients (to, cc and bcc).
   781     QString toAddressesString;
   811     QString toAddressesString;
   782     QString ccAddressesString;
   812     QString ccAddressesString;
   783     QString bccAddressesString;
   813     QString bccAddressesString;
   784 
   814 
   785     if (useStartParam) {
   815     if (useStartParam) {
   786         toAddressesString = addressListToString(mStartParam->mailtoAddressList());
   816         QList<NmAddress *> toAddressList = mStartParam->mailtoAddressList();
   787         ccAddressesString = addressListToString(mStartParam->ccAddressList());
   817         QList<NmAddress *> ccAddressList = mStartParam->ccAddressList();
   788         bccAddressesString = addressListToString(mStartParam->bccAddressList());
   818         QList<NmAddress *> bccAddressList = mStartParam->bccAddressList();
       
   819         toAddressesString = addressListToString(toAddressList);
       
   820         ccAddressesString = addressListToString(ccAddressList);
       
   821         bccAddressesString = addressListToString(bccAddressList);
       
   822         // Also add recipients added for example from send service 
       
   823         // interface to recipient line edits.        
       
   824         mContent->header()->toEdit()->addContacts(toAddressList);
       
   825         mContent->header()->ccEdit()->addContacts(ccAddressList);
       
   826         mContent->header()->bccEdit()->addContacts(bccAddressList);
   789     }
   827     }
   790     else {
   828     else {
   791         toAddressesString = addressListToString(messageEnvelope.toRecipients());
   829         toAddressesString = addressListToString(messageEnvelope.toRecipients());
   792         ccAddressesString = addressListToString(messageEnvelope.ccRecipients());
   830         ccAddressesString = addressListToString(messageEnvelope.ccRecipients());
   793         bccAddressesString = addressListToString(messageEnvelope.bccRecipients());
   831         bccAddressesString = addressListToString(messageEnvelope.bccRecipients());
   822     if (editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll) {
   860     if (editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll) {
   823         //Clear the importance flag. Replied messages dont keep the importance
   861         //Clear the importance flag. Replied messages dont keep the importance
   824         setPriority(NmActionResponseCommandNone);
   862         setPriority(NmActionResponseCommandNone);
   825     }
   863     }
   826     mHeaderWidget->setPriority(messageEnvelope.priority());
   864     mHeaderWidget->setPriority(messageEnvelope.priority());
   827     
   865 
   828     NmMessage *originalMessage = NULL;
   866     NmMessage *originalMessage = NULL;
   829     
   867 
   830     // Set the message body.
   868     // Set the message body.
   831     if (editorStartMode==NmUiEditorReply||
   869     if (editorStartMode==NmUiEditorReply||
   832         editorStartMode==NmUiEditorReplyAll||
   870         editorStartMode==NmUiEditorReplyAll||
   833         editorStartMode==NmUiEditorForward||
   871         editorStartMode==NmUiEditorForward||
   834         editorStartMode==NmUiEditorFromDrafts){
   872         editorStartMode==NmUiEditorFromDrafts){
   835 
   873 
   836         // Use the body from the original message.
   874         // Use the body from the original message.
   837         originalMessage = mUiEngine.message(mStartParam->mailboxId(), 
   875         originalMessage = mUiEngine.message(mStartParam->mailboxId(),
   838                                             mStartParam->folderId(), 
   876                                             mStartParam->folderId(),
   839                                             mStartParam->messageId());
   877                                             mStartParam->messageId());
   840 
   878 
   841         if (originalMessage) {
   879         if (originalMessage) {
   842             NmMessagePart *plainPart = originalMessage->plainTextBodyPart();
   880             NmMessagePart *plainPart = originalMessage->plainTextBodyPart();
   843 
   881 
   858             }
   896             }
   859 
   897 
   860         }
   898         }
   861 
   899 
   862     }
   900     }
   863     
   901 
   864     QString *signature = NULL;
   902     QString *signature = NULL;
   865     // return value is not relevant here
   903     // return value is not relevant here
   866     mUiEngine.getSignature(mStartParam->mailboxId(), signature);
   904     mUiEngine.getSignature(mStartParam->mailboxId(), signature);
   867     
   905 
   868     mContent->setBodyContent(editorStartMode, originalMessage, signature);
   906     mContent->setBodyContent(editorStartMode, originalMessage, signature);
   869 
   907 
   870     delete signature;
   908     delete signature;
   871     signature = NULL;
   909     signature = NULL;
   872 
   910 
   889 
   927 
   890     if (fileList) {
   928     if (fileList) {
   891         addAttachments(*fileList);
   929         addAttachments(*fileList);
   892     }
   930     }
   893 
   931 
   894 }
   932     if (mStartParam->bodyText().length()) {
   895 
   933         // If the content is not HTML, use it as plain text
   896 
   934         if (mStartParam->bodyMimeType().compare(NmMimeTypeHtml, Qt::CaseInsensitive)) {
   897 /*!
   935 			mContent->editor()->setPlainText(mStartParam->bodyText());
   898     createToolBar. Function asks menu commands from extension
   936 		}
   899     to be added to toolbar owned by the HbView.
   937 		else {
       
   938 		    mContent->editor()->setHtml(mStartParam->bodyText());
       
   939 		}
       
   940     }
       
   941 }
       
   942 
       
   943 
       
   944 /*!
       
   945     Constructs the toolbar according to the actions received from the extension
       
   946     manager.
   900 */
   947 */
   901 void NmEditorView::createToolBar()
   948 void NmEditorView::createToolBar()
   902 {
   949 {
   903     NM_FUNCTION;
   950     NM_FUNCTION;
   904     
   951     
   905     HbToolBar *tb = toolBar();
   952     HbToolBar *tb = toolBar();
   906     NmUiExtensionManager &extMngr = mApplication.extManager();
   953     NmUiExtensionManager &extMngr = mApplication.extManager();
   907     if (tb && &extMngr && mStartParam) {
   954 
   908         tb->clearActions();
   955     if (!tb || !mStartParam) {
   909         NmActionRequest request(this, NmActionToolbar, NmActionContextViewEditor,
   956         return;
   910                 NmActionContextDataNone, mStartParam->mailboxId(), mStartParam->folderId() );
   957     }
   911         QList<NmAction *> list;
   958 
   912         extMngr.getActions(request, list);
   959     tb->clearActions();
   913         for (int i = 0; i < list.count(); i++) {
   960 
   914             tb->addAction(list[i]);
   961     NmActionRequest request(this,
   915             // If action has NmSendable condition, it is shown only when send action
   962                             NmActionToolbar,
   916             // is available, i.e. when at least one recipient field has data.
   963                             NmActionContextViewEditor,
   917             if( list[i]->availabilityCondition() == NmAction::NmSendable ) {
   964                             NmActionContextDataNone,
   918                 list[i]->setEnabled(false);
   965                             mStartParam->mailboxId(),
   919             }
   966                             mStartParam->folderId()); 
   920             else if (list[i]->availabilityCondition() == NmAction::NmAttachable) {
   967     QList<NmAction *> list;
   921                 HbToolBarExtension* extension = new HbToolBarExtension();
   968     extMngr.getActions(request, list);
   922                 mAttachmentPicker = new NmAttachmentPicker(this);
   969 
   923                 
   970     for (int i = 0; i < list.count(); i++) {
   924                 if (extension && mAttachmentPicker) {
   971         tb->addAction(list[i]);
   925                     connect(mAttachmentPicker, SIGNAL(attachmentsFetchOk(const QVariant &)),
   972 
   926                         this, SLOT(onAttachmentReqCompleted(const QVariant &)));
   973         // If action has NmSendable condition, it is shown only when send
   927                     
   974         // action is available, i.e. when at least one recipient field has
   928                     connect(this, SIGNAL(titleChanged(QString)), mAttachmentPicker,
   975         // data.
   929                         SLOT(setTitle(QString)));
   976         if (list[i]->availabilityCondition() == NmAction::NmSendable) {
   930 
   977             list[i]->setEnabled(false);
   931                     list[i]->setToolBarExtension(extension);
   978         }
   932                     
   979         else if (list[i]->availabilityCondition() == NmAction::NmAttachable &&
   933                     //content widget to get the items to a list
   980                  mTBExtnContentWidget) {
   934                     mTBExtnContentWidget = new HbListWidget();
   981             // Setup the toolbar extension for attachments.
   935                     mTBExtnContentWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
   982             HbToolBarExtension* extension = new HbToolBarExtension();
   936                     
   983             extension->setParent(this);
   937                     mTBExtnContentWidget->addItem(hbTrId("txt_mail_list_photo"));
   984             list[i]->setToolBarExtension(extension);
   938                     mTBExtnContentWidget->addItem(hbTrId("txt_mail_list_sound"));
   985 
   939                     mTBExtnContentWidget->addItem(hbTrId("txt_mail_list_video"));
   986             mTBExtnContentWidget->addItem(hbTrId("txt_mail_list_photo"));
   940                     mTBExtnContentWidget->addItem(hbTrId("txt_mail_list_other"));
   987             mTBExtnContentWidget->addItem(hbTrId("txt_mail_list_sound"));
   941                     mTBExtnContentWidget->addItem(hbTrId("txt_mail_list_new_photo"));
   988             mTBExtnContentWidget->addItem(hbTrId("txt_mail_list_video"));
   942                     mTBExtnContentWidget->addItem(hbTrId("txt_mail_list_new_video"));
   989             mTBExtnContentWidget->addItem(hbTrId("txt_mail_list_other"));
   943                     HbListViewItem *listView = mTBExtnContentWidget->listItemPrototype();
   990             mTBExtnContentWidget->addItem(hbTrId("txt_mail_list_new_photo"));
   944                     HbFrameBackground frame(NmPopupListFrame, HbFrameDrawer::NinePieces);
   991             mTBExtnContentWidget->addItem(hbTrId("txt_mail_list_new_video"));
   945                     listView->setDefaultFrame(frame);
   992 
   946                     
   993             HbListViewItem *listView = mTBExtnContentWidget->listItemPrototype();
   947                     connect(mTBExtnContentWidget, SIGNAL(activated(HbListWidgetItem*)), 
   994             HbFrameBackground frame(NmPopupListFrame, HbFrameDrawer::NinePieces);
   948                     		mAttachmentPicker, SLOT (selectFetcher(HbListWidgetItem*)));
   995             listView->setDefaultFrame(frame);
   949             
   996             
   950                     connect(mTBExtnContentWidget, SIGNAL(activated(HbListWidgetItem*)),
   997             extension->setContentWidget(mTBExtnContentWidget);
   951                             extension, SLOT(close()));
   998 
   952                                         
   999             connect(mTBExtnContentWidget, SIGNAL(activated(HbListWidgetItem*)),
   953                     extension->setContentWidget(mTBExtnContentWidget);
  1000                     extension, SLOT(close()));
   954                 }
  1001 
   955             }            
  1002             mAttachmentPicker = new NmAttachmentPicker(this);
   956         }        
  1003             
   957     }
  1004             connect(mAttachmentPicker, SIGNAL(attachmentsFetchOk(const QVariant &)),
   958 }
  1005                     this, SLOT(onAttachmentReqCompleted(const QVariant &)));
       
  1006             connect(this, SIGNAL(titleChanged(QString)),
       
  1007                     mAttachmentPicker, SLOT(setTitle(QString)));
       
  1008             connect(mTBExtnContentWidget, SIGNAL(activated(HbListWidgetItem*)), 
       
  1009                     mAttachmentPicker, SLOT (selectFetcher(HbListWidgetItem*)));
       
  1010         }
       
  1011     } // for ()        
       
  1012 }
       
  1013 
   959 
  1014 
   960 /*!
  1015 /*!
   961     createOptionsMenu. Functions asks menu commands from extension
  1016     createOptionsMenu. Functions asks menu commands from extension
   962     to be added to options menu.
  1017     to be added to options menu.
   963 */
  1018 */
   964 void NmEditorView::createOptionsMenu()
  1019 void NmEditorView::createOptionsMenu()
   965 {
  1020 {
   966     NM_FUNCTION;
  1021     NM_FUNCTION;
   967     
  1022 
   968     menu()->clearActions();
  1023     menu()->clearActions();
   969 
  1024 
   970 	// Create CC/BCC options menu object
  1025 	// Create CC/BCC options menu object
   971     if (mCcBccFieldVisible) {
  1026     if (mCcBccFieldVisible) {
   972         menu()->addAction(hbTrId("txt_mail_opt_hide_cc_bcc"), this, SLOT(switchCcBccFieldVisibility()));
  1027         menu()->addAction(hbTrId("txt_mail_opt_hide_cc_bcc"), this, SLOT(switchCcBccFieldVisibility()));
  1001     Show or hide Cc field
  1056     Show or hide Cc field
  1002 */
  1057 */
  1003 void NmEditorView::switchCcBccFieldVisibility()
  1058 void NmEditorView::switchCcBccFieldVisibility()
  1004 {
  1059 {
  1005     NM_FUNCTION;
  1060     NM_FUNCTION;
  1006     
  1061 
  1007     if (mCcBccFieldVisible) {
  1062     if (mCcBccFieldVisible) {
  1008     	mCcBccFieldVisible = false;
  1063     	mCcBccFieldVisible = false;
  1009     }
  1064     }
  1010     else {
  1065     else {
  1011     	mCcBccFieldVisible = true;
  1066     	mCcBccFieldVisible = true;
  1018     call to handle menu command in the UI.
  1073     call to handle menu command in the UI.
  1019 */
  1074 */
  1020 void NmEditorView::handleActionCommand(NmActionResponse &actionResponse)
  1075 void NmEditorView::handleActionCommand(NmActionResponse &actionResponse)
  1021 {
  1076 {
  1022     NM_FUNCTION;
  1077     NM_FUNCTION;
  1023     
  1078 
  1024     NmActionResponseCommand responseCommand = actionResponse.responseCommand();
  1079     NmActionResponseCommand responseCommand = actionResponse.responseCommand();
  1025     
  1080 
  1026     // Handle options menu
  1081     // Handle options menu
  1027     if (actionResponse.menuType() == NmActionOptionsMenu) {
  1082     if (actionResponse.menuType() == NmActionOptionsMenu) {
  1028         setPriority(responseCommand);
  1083         setPriority(responseCommand);
  1029     }
  1084     }
  1030     else if (actionResponse.menuType() == NmActionToolbar) {
  1085     else if (actionResponse.menuType() == NmActionToolbar) {
  1072    availability condition NmSendable set, will be enabled/disabled.
  1127    availability condition NmSendable set, will be enabled/disabled.
  1073 */
  1128 */
  1074 void NmEditorView::setButtonsDimming(bool enabled)
  1129 void NmEditorView::setButtonsDimming(bool enabled)
  1075 {
  1130 {
  1076     NM_FUNCTION;
  1131     NM_FUNCTION;
  1077     
  1132 
  1078     // Set the toolbar action states
  1133     // Set the toolbar action states
  1079     HbToolBar *tb = toolBar();
  1134     HbToolBar *tb = toolBar();
  1080     if (tb) {
  1135     if (tb) {
  1081         QList<QAction *> toolbarList = tb->actions();
  1136         QList<QAction *> toolbarList = tb->actions();
  1082         int count = toolbarList.count();
  1137         int count = toolbarList.count();
  1107     for all editors of the view.
  1162     for all editors of the view.
  1108 */
  1163 */
  1109 void NmEditorView::initializeVKB()
  1164 void NmEditorView::initializeVKB()
  1110 {
  1165 {
  1111     NM_FUNCTION;
  1166     NM_FUNCTION;
  1112     
  1167 
  1113     if (!mStartParam) {
  1168     if (!mStartParam) {
  1114         return;
  1169         return;
  1115     }
  1170     }
  1116     
  1171 
  1117     NmActionRequest request(this, NmActionVKB, NmActionContextViewEditor,
  1172     NmActionRequest request(this, NmActionVKB, NmActionContextViewEditor,
  1118          NmActionContextDataNone, mStartParam->mailboxId(), mStartParam->folderId() );
  1173          NmActionContextDataNone, mStartParam->mailboxId(), mStartParam->folderId() );
  1119     NmUiExtensionManager &extMngr = mApplication.extManager();
  1174     NmUiExtensionManager &extMngr = mApplication.extManager();
  1120     if (&extMngr) {
  1175     if (&extMngr) {
  1121         QList<NmAction *> list;
  1176         QList<NmAction *> list;
  1150     Set mailbox name to title
  1205     Set mailbox name to title
  1151 */
  1206 */
  1152 void NmEditorView::setMailboxName()
  1207 void NmEditorView::setMailboxName()
  1153 {
  1208 {
  1154     NM_FUNCTION;
  1209     NM_FUNCTION;
  1155     
  1210 
  1156     if (mStartParam){
  1211     if (mStartParam){
  1157         NmMailboxMetaData *meta = mUiEngine.mailboxById(mStartParam->mailboxId());
  1212         NmMailboxMetaData *meta = mUiEngine.mailboxById(mStartParam->mailboxId());
  1158         if (meta){
  1213         if (meta){
  1159             setTitle(meta->name());
  1214             setTitle(meta->name());
  1160         }
  1215         }
  1161     }
  1216     }
  1162 }
  1217 }
  1163 
  1218 
  1164 /*!
  1219 /*!
  1165    Adds a prefix to the subject for reply or forward. 
  1220    Adds a prefix to the subject for reply or forward.
  1166    Strips other occurrences of the prefix from the beginning.
  1221    Strips other occurrences of the prefix from the beginning.
  1167 */
  1222 */
  1168 QString NmEditorView::addSubjectPrefix( NmUiEditorStartMode startMode, const QString &subject )
  1223 QString NmEditorView::addSubjectPrefix( NmUiEditorStartMode startMode, const QString &subject )
  1169 {
  1224 {
  1170     NM_FUNCTION;
  1225     NM_FUNCTION;
  1171     
  1226 
  1172     QString newSubject(subject.trimmed());
  1227     QString newSubject(subject.trimmed());
  1173     
  1228 
  1174     if (startMode == NmUiEditorReply || startMode == NmUiEditorReplyAll || 
  1229     if (startMode == NmUiEditorReply || startMode == NmUiEditorReplyAll ||
  1175         startMode == NmUiEditorForward) {
  1230         startMode == NmUiEditorForward) {
  1176         QString rePrefix(hbTrId("txt_nmailui_reply_subject_prefix"));
  1231         QString rePrefix(hbTrId("txt_mail_reply_subject_prefix"));
  1177         QString fwPrefix(hbTrId("txt_nmailui_forward_subject_prefix"));
  1232         QString fwPrefix(hbTrId("txt_mail_forward_subject_prefix"));
  1178         
  1233 
  1179         // strip extra prefixes from beginning
  1234         // strip extra prefixes from beginning
  1180         int rePrefixLength(rePrefix.length());
  1235         int rePrefixLength(rePrefix.length());
  1181         int fwPrefixLength(fwPrefix.length());
  1236         int fwPrefixLength(fwPrefix.length());
  1182         
  1237 
  1183         bool startswithRe(newSubject.startsWith(rePrefix, Qt::CaseInsensitive));
  1238         bool startswithRe(newSubject.startsWith(rePrefix, Qt::CaseInsensitive));
  1184         bool startswithFw(newSubject.startsWith(fwPrefix, Qt::CaseInsensitive));
  1239         bool startswithFw(newSubject.startsWith(fwPrefix, Qt::CaseInsensitive));
  1185         
  1240 
  1186         while (startswithRe || startswithFw) {            
  1241         while (startswithRe || startswithFw) {
  1187             if (startswithRe) {
  1242             if (startswithRe) {
  1188                 newSubject.remove(0,rePrefixLength);
  1243                 newSubject.remove(0,rePrefixLength);
  1189                 newSubject = newSubject.trimmed();
  1244                 newSubject = newSubject.trimmed();
  1190             }
  1245             }
  1191             else if (startswithFw) {
  1246             else if (startswithFw) {
  1193                 newSubject = newSubject.trimmed();
  1248                 newSubject = newSubject.trimmed();
  1194             }
  1249             }
  1195             startswithRe = newSubject.startsWith(rePrefix, Qt::CaseInsensitive);
  1250             startswithRe = newSubject.startsWith(rePrefix, Qt::CaseInsensitive);
  1196             startswithFw = newSubject.startsWith(fwPrefix, Qt::CaseInsensitive);
  1251             startswithFw = newSubject.startsWith(fwPrefix, Qt::CaseInsensitive);
  1197         }
  1252         }
  1198         
  1253 
  1199         if (startMode == NmUiEditorReply || startMode == NmUiEditorReplyAll) {
  1254         if (startMode == NmUiEditorReply || startMode == NmUiEditorReplyAll) {
  1200             newSubject = rePrefix + " " + newSubject;
  1255             newSubject = rePrefix + " " + newSubject;
  1201         }
  1256         }
  1202         else if (startMode == NmUiEditorForward) {
  1257         else if (startMode == NmUiEditorForward) {
  1203             newSubject = fwPrefix + " " + newSubject;
  1258             newSubject = fwPrefix + " " + newSubject;
  1204         }
  1259         }
  1205     }
  1260     }
  1206     
  1261 
  1207     return newSubject;
  1262     return newSubject;
  1208 }
  1263 }
  1209 
  1264 
  1210 
  1265 
  1211 /*!
  1266 /*!
  1212     This slot is called when 'attachment picker' request has been performed succesfully
  1267     This slot is called when 'attachment picker' request has been performed succesfully
  1213     Parameter 'value' contains file currently one file name but later list of the files. 
  1268     Parameter 'value' contains file currently one file name but later list of the files.
  1214 */
  1269 */
  1215 void NmEditorView::onAttachmentReqCompleted(const QVariant &value)
  1270 void NmEditorView::onAttachmentReqCompleted(const QVariant &value)
  1216 {
  1271 {
  1217     NM_FUNCTION;
  1272     NM_FUNCTION;
  1218     
  1273 
  1219     //temporary fix for music picker back button:
  1274     //temporary fix for music picker back button:
  1220     //it shouldn't emit requestOk signal when nothing is selected
  1275     //it shouldn't emit requestOk signal when nothing is selected
  1221 	if (value.canConvert<QStringList>()) {
  1276 	if (value.canConvert<QStringList>()) {
  1222 	    QStringList list = value.toStringList();
  1277 	    QStringList list = value.toStringList();
  1223         if (!list.at(0).isEmpty()) {
  1278         if (!list.at(0).isEmpty()) {
  1240     NM_COMMENT(QString("Error message: %1").arg(errorMessage));
  1295     NM_COMMENT(QString("Error message: %1").arg(errorMessage));
  1241 }
  1296 }
  1242 
  1297 
  1243 /*!
  1298 /*!
  1244     Closes the wait dialog if one exists.
  1299     Closes the wait dialog if one exists.
  1245     
  1300 
  1246     This slot is called if the mail application has been started as a service
  1301     This slot is called if the mail application has been started as a service
  1247     and is about to close. Closing the application while still sending a message
  1302     and is about to close. Closing the application while still sending a message
  1248     may cause unwanted cancelling of the operation.
  1303     may cause unwanted cancelling of the operation.
  1249 */
  1304 */
  1250 void NmEditorView::handleSendOperationCompleted()
  1305 void NmEditorView::handleSendOperationCompleted()
  1260 }
  1315 }
  1261 
  1316 
  1262 /*!
  1317 /*!
  1263     Add list of attachments
  1318     Add list of attachments
  1264 */
  1319 */
  1265 void NmEditorView::addAttachments(const QStringList& fileNames) 
  1320 void NmEditorView::addAttachments(const QStringList& fileNames)
  1266 {
  1321 {
  1267     NM_FUNCTION;
  1322     NM_FUNCTION;
       
  1323     NM_TIMESTAMP("Add attachments.");
  1268     
  1324     
  1269     // Add attachment name into UI
  1325     // Add attachment name into UI
  1270     foreach (QString fileName, fileNames)  {
  1326     foreach (QString fileName, fileNames)  {
  1271         // At this phase attachment size and nmid are not known
  1327         // At this phase attachment size and nmid are not known
  1272         mHeaderWidget->addAttachment(fileName, QString("0"), NmId(0));
  1328         mHeaderWidget->addAttachment(fileName, QString("0"), NmId(0));
  1287         // Signal to inform completion of one attachment
  1343         // Signal to inform completion of one attachment
  1288         connect(mAddAttachmentOperation,
  1344         connect(mAddAttachmentOperation,
  1289                 SIGNAL(operationPartCompleted(const QString &, const NmId &, int)),
  1345                 SIGNAL(operationPartCompleted(const QString &, const NmId &, int)),
  1290                 this,
  1346                 this,
  1291                 SLOT(oneAttachmentAdded(const QString &, const NmId &, int)));
  1347                 SLOT(oneAttachmentAdded(const QString &, const NmId &, int)));
  1292     
  1348 
  1293         // Signal to inform the completion of the whole operation
  1349         // Signal to inform the completion of the whole operation
  1294         connect(mAddAttachmentOperation,
  1350         connect(mAddAttachmentOperation,
  1295                 SIGNAL(operationCompleted(int)),
  1351                 SIGNAL(operationCompleted(int)),
  1296                 this,
  1352                 this,
  1297                 SLOT(allAttachmentsAdded(int)));
  1353                 SLOT(allAttachmentsAdded(int)));
  1303     from UI by longpress.
  1359     from UI by longpress.
  1304 */
  1360 */
  1305 void NmEditorView::attachmentLongPressed(NmId attachmentPartId, QPointF point)
  1361 void NmEditorView::attachmentLongPressed(NmId attachmentPartId, QPointF point)
  1306 {
  1362 {
  1307     NM_FUNCTION;
  1363     NM_FUNCTION;
  1308     
  1364 
  1309     // Store id of the attachment to be removed into member.
  1365     // Store id of the attachment to be removed into member.
  1310     // It is used by removeAttachmentTriggered later if 'remove' selected.
  1366     // It is used by removeAttachmentTriggered later if 'remove' selected.
  1311     mSelectedAttachment = attachmentPartId;
  1367     mSelectedAttachment = attachmentPartId;
  1312 	
  1368 
  1313     if (!mAttachmentListContextMenu) {
  1369     if (!mAttachmentListContextMenu) {
  1314         mAttachmentListContextMenu = new HbMenu();
  1370         mAttachmentListContextMenu = new HbMenu();
  1315     }
  1371     }
  1316     mAttachmentListContextMenu->clearActions();
  1372     mAttachmentListContextMenu->clearActions();
  1317     NmActionRequest request(this, NmActionContextMenu, NmActionContextViewEditor,
  1373     NmActionRequest request(this, NmActionContextMenu, NmActionContextViewEditor,
  1337     completed for one attachment.
  1393     completed for one attachment.
  1338 */
  1394 */
  1339 void NmEditorView::oneAttachmentAdded(const QString &fileName, const NmId &msgPartId, int result)
  1395 void NmEditorView::oneAttachmentAdded(const QString &fileName, const NmId &msgPartId, int result)
  1340 {
  1396 {
  1341     NM_FUNCTION;
  1397     NM_FUNCTION;
  1342     
  1398 
  1343     if (result == NmNoError && mMessage) {
  1399     if (result == NmNoError && mMessage) {
  1344         // Need to get the message again because new attachment part has been added.
  1400         // Need to get the message again because new attachment part has been added.
  1345         NmId mailboxId = mMessage->envelope().mailboxId();
  1401         NmId mailboxId = mMessage->envelope().mailboxId();
  1346         NmId folderId = mMessage->envelope().folderId();
  1402         NmId folderId = mMessage->envelope().folderId();
  1347         NmId msgId = mMessage->envelope().messageId();
  1403         NmId msgId = mMessage->envelope().messageId();
  1348         NmMessagePriority messagePriority = mMessage->envelope().priority();        
  1404         NmMessagePriority messagePriority = mMessage->envelope().priority();
  1349         
  1405 
  1350         delete mMessage;
  1406         delete mMessage;
  1351         mMessage = NULL;
  1407         mMessage = NULL;
  1352         
  1408 
  1353         mMessage = mUiEngine.message(mailboxId, folderId, msgId);
  1409         mMessage = mUiEngine.message(mailboxId, folderId, msgId);
  1354 
  1410 
  1355         if (mMessage) {
  1411         if (mMessage) {
  1356             mMessage->envelope().setPriority(messagePriority);
  1412             mMessage->envelope().setPriority(messagePriority);
  1357             mMessage->envelope().setHasAttachments(true);
  1413             mMessage->envelope().setHasAttachments(true);
  1358             // Get attachment list from the message
  1414             // Get attachment list from the message
  1359             QList<NmMessagePart*> attachmentList;
  1415             QList<NmMessagePart*> attachmentList;
  1360             mMessage->attachmentList(attachmentList);
  1416             mMessage->attachmentList(attachmentList);
  1361         
  1417 
  1362             // Search newly added attachment from the list
  1418             // Search newly added attachment from the list
  1363             for (int i=0; i<attachmentList.count(); i++) {
  1419             for (int i=0; i<attachmentList.count(); i++) {
  1364                 if (attachmentList[i]->partId() == msgPartId) {
  1420                 if (attachmentList[i]->partId() == msgPartId) {
  1365                     // Get attachment file size and set it into UI
  1421                     // Get attachment file size and set it into UI
  1366                     mHeaderWidget->setAttachmentParameters(fileName,
  1422                     mHeaderWidget->setAttachmentParameters(fileName,
  1383     completed totally.
  1439     completed totally.
  1384 */
  1440 */
  1385 void NmEditorView::allAttachmentsAdded(int result)
  1441 void NmEditorView::allAttachmentsAdded(int result)
  1386 {
  1442 {
  1387     NM_FUNCTION;
  1443     NM_FUNCTION;
       
  1444     NM_TIMESTAMP("All attachments added.");
  1388     
  1445     
  1389     enableToolBarAttach(true);
  1446     enableToolBarAttach(true);
  1390     if (result != NmNoError) {
  1447     if (result != NmNoError) {
  1391         NmUtilities::displayWarningNote(hbTrId("txt_mail_dialog_unable_to_add_attachment"));
  1448         NmUtilities::displayWarningNote(hbTrId("txt_mail_dialog_unable_to_add_attachment"));
  1392     }
  1449     }
  1393 }
  1450 }
  1394 
  1451 
  1395 /*!
  1452 /*!
  1396    Sets priority for the message object that is being edited 
  1453    Sets priority for the message object that is being edited
  1397 */
  1454 */
  1398 void NmEditorView::setPriority(NmActionResponseCommand priority)
  1455 void NmEditorView::setPriority(NmActionResponseCommand priority)
  1399 {
  1456 {
  1400     NM_FUNCTION;
  1457     NM_FUNCTION;
  1401     
  1458 
  1402     mHeaderWidget->setPriority(priority);
  1459     mHeaderWidget->setPriority(priority);
  1403 
  1460 
  1404     if (mMessage) {
  1461     if (mMessage) {
  1405         NmMessagePriority messagePriority = NmMessagePriorityNormal;
  1462         NmMessagePriority messagePriority = NmMessagePriorityNormal;
  1406         mHiddenPriorityName = NmPriorityNormal;
  1463         mHiddenPriorityName = NmPriorityNormal;
  1407         
  1464 
  1408         if (priority == NmActionResponseCommandPriorityHigh) {
  1465         if (priority == NmActionResponseCommandPriorityHigh) {
  1409             messagePriority = NmMessagePriorityHigh;
  1466             messagePriority = NmMessagePriorityHigh;
  1410             mHiddenPriorityName = NmPriorityHigh;
  1467             mHiddenPriorityName = NmPriorityHigh;
  1411         }
  1468         }
  1412         else if (priority == NmActionResponseCommandPriorityLow) {
  1469         else if (priority == NmActionResponseCommandPriorityLow) {
  1426     \return String containing the addresses.
  1483     \return String containing the addresses.
  1427 */
  1484 */
  1428 QString NmEditorView::addressListToString(const QList<NmAddress*> &list) const
  1485 QString NmEditorView::addressListToString(const QList<NmAddress*> &list) const
  1429 {
  1486 {
  1430     NM_FUNCTION;
  1487     NM_FUNCTION;
  1431     
  1488 
  1432     QString addressesString;
  1489     QString addressesString;
  1433     QList<NmAddress*>::const_iterator i = list.constBegin();
  1490     QList<NmAddress*>::const_iterator i = list.constBegin();
  1434     
  1491 
  1435     while (i != list.constEnd() && *i) {
  1492     while (i != list.constEnd() && *i) {
  1436         if (i > list.constBegin()) {
  1493         // Prioritize display name. Add the delimiter in the end also if
  1437             // Add the delimiter.
  1494         // address list ends to display name.
       
  1495         if ((*i)->displayName().length() > 0) {
       
  1496             addressesString += (*i)->displayName();
  1438             addressesString += NmDelimiter;
  1497             addressesString += NmDelimiter;
  1439         }
  1498         }
  1440 
  1499         else {
  1441         addressesString += (*i)->address();
  1500             if (i > list.constBegin()) {
       
  1501                 // Add the delimiter.
       
  1502                 addressesString += NmDelimiter;
       
  1503             }
       
  1504             addressesString += (*i)->address();
       
  1505         }
  1442         ++i;
  1506         ++i;
  1443     }
  1507     }
  1444 
  1508 
  1445     return addressesString;
  1509     return addressesString;
  1446 }
  1510 }
  1454     \return String containing the addresses.
  1518     \return String containing the addresses.
  1455 */
  1519 */
  1456 QString NmEditorView::addressListToString(const QList<NmAddress> &list) const
  1520 QString NmEditorView::addressListToString(const QList<NmAddress> &list) const
  1457 {
  1521 {
  1458     NM_FUNCTION;
  1522     NM_FUNCTION;
  1459     
  1523 
  1460     QString addressesString;
  1524     QString addressesString;
  1461     QList<NmAddress>::const_iterator i = list.constBegin();
  1525     QList<NmAddress>::const_iterator i = list.constBegin();
  1462     
  1526 
  1463     while (i != list.constEnd()) {
  1527     while (i != list.constEnd()) {
  1464         if (i > list.constBegin()) {
  1528         if (i > list.constBegin()) {
  1465             // Add the delimiter.
  1529             // Add the delimiter.
  1466             addressesString += NmDelimiter;
  1530             addressesString += NmDelimiter;
  1467         }
  1531         }
  1477     This slot is called when 'remove' is selected from attachment list context menu.
  1541     This slot is called when 'remove' is selected from attachment list context menu.
  1478 */
  1542 */
  1479 void NmEditorView::removeAttachmentTriggered()
  1543 void NmEditorView::removeAttachmentTriggered()
  1480 {
  1544 {
  1481     NM_FUNCTION;
  1545     NM_FUNCTION;
  1482     
  1546 
  1483     // Cancel will delete previous operation
  1547     // Cancel will delete previous operation
  1484     if (mRemoveAttachmentOperation) {
  1548     if (mRemoveAttachmentOperation) {
  1485         if (!mRemoveAttachmentOperation->isRunning()) {
  1549         if (!mRemoveAttachmentOperation->isRunning()) {
  1486             mRemoveAttachmentOperation->cancelOperation();
  1550             mRemoveAttachmentOperation->cancelOperation();
  1487         }
  1551         }
  1504     completed. There is no need to update UI because it was already updated.
  1568     completed. There is no need to update UI because it was already updated.
  1505  */
  1569  */
  1506 void NmEditorView::attachmentRemoved(int result)
  1570 void NmEditorView::attachmentRemoved(int result)
  1507 {
  1571 {
  1508     NM_FUNCTION;
  1572     NM_FUNCTION;
  1509     
  1573 
  1510     // It is not desided yet what to do if operation fails
  1574     // It is not desided yet what to do if operation fails
  1511     Q_UNUSED(result);
  1575     Q_UNUSED(result);
  1512     
  1576 
  1513     if (mMessage) {
  1577     if (mMessage) {
  1514         // Reload message because one attachment has been removed
  1578         // Reload message because one attachment has been removed
  1515         NmId mailboxId = mMessage->envelope().mailboxId();
  1579         NmId mailboxId = mMessage->envelope().mailboxId();
  1516         NmId folderId = mMessage->envelope().folderId();
  1580         NmId folderId = mMessage->envelope().folderId();
  1517         NmId msgId = mMessage->envelope().messageId();
  1581         NmId msgId = mMessage->envelope().messageId();
  1518         NmMessagePriority messagePriority = mMessage->envelope().priority();    
  1582         NmMessagePriority messagePriority = mMessage->envelope().priority();
  1519 
  1583 
  1520         delete mMessage;
  1584         delete mMessage;
  1521         mMessage = NULL;
  1585         mMessage = NULL;
  1522     
  1586 
  1523         mMessage = mUiEngine.message(mailboxId, folderId, msgId);
  1587         mMessage = mUiEngine.message(mailboxId, folderId, msgId);
  1524         
  1588 
  1525         if(mMessage) {
  1589         if(mMessage) {
  1526             // Set the correct priority
  1590             // Set the correct priority
  1527             mMessage->envelope().setPriority(messagePriority);    
  1591             mMessage->envelope().setPriority(messagePriority);
  1528             
  1592 
  1529             // If there is no more attachments in the message, set the correct value
  1593             // If there is no more attachments in the message, set the correct value
  1530             QList<NmMessagePart*> attachmentList;
  1594             QList<NmMessagePart*> attachmentList;
  1531             mMessage->attachmentList(attachmentList);
  1595             mMessage->attachmentList(attachmentList);
  1532             if(attachmentList.count() == 0) {
  1596             if(attachmentList.count() == 0) {
  1533                 mMessage->envelope().setHasAttachments(false);
  1597                 mMessage->envelope().setHasAttachments(false);
  1550     		msgId, attachmentId);
  1614     		msgId, attachmentId);
  1551     int error = NmUtilities::openFile(file);
  1615     int error = NmUtilities::openFile(file);
  1552     file.close();
  1616     file.close();
  1553     if ( error == NmNotFoundError ) {
  1617     if ( error == NmNotFoundError ) {
  1554         HbMessageBox *box = NmUtilities::displayWarningNote(hbTrId("txt_mail_dialog_unable_to_open_attachment_file_ty"));
  1618         HbMessageBox *box = NmUtilities::displayWarningNote(hbTrId("txt_mail_dialog_unable_to_open_attachment_file_ty"));
  1555         box->setAttribute(Qt::WA_DeleteOnClose); 
  1619         box->setAttribute(Qt::WA_DeleteOnClose);
  1556     }
  1620     }
  1557 }
  1621 }
  1558 
  1622 
  1559 /*!
  1623 /*!
  1560    Enables/disables toolbar extension for attach
  1624    Enables/disables toolbar extension for attach
  1561 */
  1625 */
  1562 void NmEditorView::enableToolBarAttach(bool enable)
  1626 void NmEditorView::enableToolBarAttach(bool enable)
  1563 {
  1627 {
  1564     NM_FUNCTION;
  1628     NM_FUNCTION;
  1565     
  1629 
  1566     HbToolBar *tb = toolBar();
  1630     HbToolBar *tb = toolBar();
  1567     if (tb) {
  1631     if (tb) {
  1568         QList<QAction *> toolbarList = tb->actions();
  1632         QList<QAction *> toolbarList = tb->actions();
  1569         int count = toolbarList.count();
  1633         int count = toolbarList.count();
  1570         for (int i = 0; i < count; i++) {
  1634         for (int i = 0; i < count; i++) {