emailuis/nmailui/src/nmeditorview.cpp
changeset 23 2dc6caa42ec3
parent 20 ecc8def7944a
child 27 9ba4404ef423
equal deleted inserted replaced
20:ecc8def7944a 23:2dc6caa42ec3
    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 static const char *NMUI_EDITOR_SCROLL_AREA = "scrollArea";
    23 static const char *NMUI_EDITOR_SCROLL_AREA_CONTENTS = "scrollAreaContents";
    23 static const char *NMUI_EDITOR_SCROLL_AREA_CONTENTS = "scrollAreaContents";
    24 
    24 
    25 static const int nmOrientationTimer=100;
    25 static const int NmOrientationTimer=100;
    26 
    26 
    27 static const QString Delimiter("; ");
    27 static const QString Delimiter("; ");
    28 
    28 
    29 /*!
    29 /*!
    30 	\class NmEditorView
    30 	\class NmEditorView
    57       mAttachmentPicker(NULL)
    57       mAttachmentPicker(NULL)
    58 {
    58 {
    59     mDocumentLoader	= new HbDocumentLoader();
    59     mDocumentLoader	= new HbDocumentLoader();
    60     // Set object name
    60     // Set object name
    61     setObjectName("NmEditorView");
    61     setObjectName("NmEditorView");
       
    62     // Set mailbox name to title pane
       
    63     setMailboxName();
    62     // Load view layout
    64     // Load view layout
    63     loadViewLayout();
    65     loadViewLayout();
    64     // Set mailbox name to title pane
       
    65     setMailboxName();
       
    66     // Set message data
       
    67     setMessageData();
       
    68 }
    66 }
    69 
    67 
    70 /*!
    68 /*!
    71     Destructor
    69     Destructor
    72 */
    70 */
    73 NmEditorView::~NmEditorView()
    71 NmEditorView::~NmEditorView()
    74 {
    72 {
    75     // It is clearer that the operations are not owned by parent QObject as
    73     if (mRemoveAttachmentOperation && mRemoveAttachmentOperation->isRunning()) {
    76     // they are not allocated in the constructor.
    74         mRemoveAttachmentOperation->cancelOperation();
    77     delete mRemoveAttachmentOperation;
    75     }
    78     delete mAddAttachmentOperation;
    76     if (mAddAttachmentOperation && mAddAttachmentOperation->isRunning()) {
    79     delete mMessageCreationOperation;
    77         mAddAttachmentOperation->cancelOperation();
    80     delete mCheckOutboxOperation;
    78     }
       
    79     if (mMessageCreationOperation && mMessageCreationOperation->isRunning()) {
       
    80         mMessageCreationOperation->cancelOperation();
       
    81     }
       
    82     if (mCheckOutboxOperation && mCheckOutboxOperation->isRunning()) {
       
    83         mCheckOutboxOperation->cancelOperation();
       
    84     }
    81     delete mMessage;
    85     delete mMessage;
    82     mWidgetList.clear();
    86     mWidgetList.clear();
    83     delete mDocumentLoader;
    87     delete mDocumentLoader;
    84     delete mContentWidget;
    88     delete mContentWidget;
    85     delete mPrioritySubMenu;
    89     delete mPrioritySubMenu;
   121         mHeaderWidget = mContentWidget->header();
   125         mHeaderWidget = mContentWidget->header();
   122 
   126 
   123         // Set default color for user - entered text if editor is in re/reAll/fw mode
   127         // Set default color for user - entered text if editor is in re/reAll/fw mode
   124         NmUiEditorStartMode mode = mStartParam->editorStartMode();
   128         NmUiEditorStartMode mode = mStartParam->editorStartMode();
   125         if (mode == NmUiEditorReply || mode == NmUiEditorReplyAll || mode == NmUiEditorForward) {
   129         if (mode == NmUiEditorReply || mode == NmUiEditorReplyAll || mode == NmUiEditorForward) {
   126         mEditWidget->setCustomTextColor(true, Qt::blue);
   130             mEditWidget->setCustomTextColor(true, Qt::blue);
   127         }
   131         }
   128     }
   132 
   129 
   133         // the rest of the view initialization is done in viewReady()
   130     // Connect signals from background scroll area
   134     }
   131     connect(mScrollArea, SIGNAL(handleMousePressEvent(QGraphicsSceneMouseEvent*)),
       
   132             this, SLOT(sendMousePressEventToScroll(QGraphicsSceneMouseEvent*)));
       
   133     connect(mScrollArea, SIGNAL(handleMouseReleaseEvent(QGraphicsSceneMouseEvent*)),
       
   134             this, SLOT(sendMouseReleaseEventToScroll(QGraphicsSceneMouseEvent*)));
       
   135     connect(mScrollArea, SIGNAL(handleMouseMoveEvent(QGraphicsSceneMouseEvent*)),
       
   136             this, SLOT(sendMouseMoveEventToScroll(QGraphicsSceneMouseEvent*)));
       
   137 
       
   138     connect(mScrollArea, SIGNAL(handleLongPressGesture(const QPointF &)),
       
   139                 this, SLOT(sendLongPressGesture(const QPointF &)));
       
   140 
       
   141     // Connect options menu about to show to create options menu function
       
   142     // Menu needs to be create "just-in-time"
       
   143     connect(menu(), SIGNAL(aboutToShow()), this, SLOT(createOptionsMenu()));
       
   144     NmAction *dummy = new NmAction(0);
       
   145     menu()->addAction(dummy);
       
   146 
       
   147     initializeVKB();
       
   148     connect(mContentWidget->header(), SIGNAL(recipientFieldsHaveContent(bool)),
       
   149             this, SLOT(setButtonsDimming(bool)) );
       
   150 
       
   151     // call the createToolBar on load view layout
       
   152     createToolBar();
       
   153 
       
   154     // Set dimensions
       
   155     adjustViewDimensions();
       
   156 	
       
   157     // Connect to observe orientation change events
       
   158     connect(mApplication.mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
       
   159             this, SLOT(orientationChanged(Qt::Orientation)));
       
   160     // Signal for handling the attachment list selection
       
   161     connect(mHeaderWidget, SIGNAL(attachmentLongPressed(NmId, QPointF)),
       
   162             this, SLOT(attachmentLongPressed(NmId, QPointF)));
       
   163 }
   135 }
   164 
   136 
   165 /*!
   137 /*!
   166     Reload view contents with new start parameters
   138     Reload view contents with new start parameters
   167     Typically when view is already open and external view activation occurs
   139     Typically when view is already open and external view activation occurs
   197 */
   169 */
   198 void NmEditorView::orientationChanged(Qt::Orientation orientation)
   170 void NmEditorView::orientationChanged(Qt::Orientation orientation)
   199 {
   171 {
   200     Q_UNUSED(orientation);
   172     Q_UNUSED(orientation);
   201     // Adjust content height
   173     // Adjust content height
   202     QTimer::singleShot(nmOrientationTimer, this, SLOT(adjustViewDimensions()));
   174     QTimer::singleShot(NmOrientationTimer, this, SLOT(adjustViewDimensions()));
   203     QTimer::singleShot(nmOrientationTimer, mHeaderWidget, SLOT(sendHeaderHeightChanged()));
   175     QTimer::singleShot(NmOrientationTimer, mHeaderWidget, SLOT(sendHeaderHeightChanged()));
   204 }
   176 }
   205 
   177 
   206 /*!
   178 /*!
   207     Set new dimensions after orientation change.
   179     Set new dimensions after orientation change.
   208 */
   180 */
   236 */
   208 */
   237 bool NmEditorView::okToExitView()
   209 bool NmEditorView::okToExitView()
   238 {
   210 {
   239     bool okToExit = true;
   211     bool okToExit = true;
   240 
   212 
       
   213     NmEditorHeader *header = mContentWidget->header();
       
   214     
   241     // show the query if the message has not been sent
   215     // show the query if the message has not been sent
   242     if (mMessage && mContentWidget->header()) {
   216     if (mMessage && header) {
   243         // see if editor has any content
   217         // see if editor has any content
   244         NmEditorHeader *header = mContentWidget->header();
       
   245 
       
   246         int toTextLength = 0;
   218         int toTextLength = 0;
   247         if (header->toField()) {
   219         if (header->toField()) {
   248             toTextLength = header->toField()->text().length();
   220             toTextLength = header->toField()->text().length();
   249         }
   221         }
   250         
   222         
   261         int subjectLength = 0;
   233         int subjectLength = 0;
   262         if (header->subjectField()) {
   234         if (header->subjectField()) {
   263             subjectLength = header->subjectField()->text().length();
   235             subjectLength = header->subjectField()->text().length();
   264         }
   236         }
   265         
   237         
       
   238         QList<NmMessagePart*> attachmentList;
       
   239         mMessage->attachmentList(attachmentList);
       
   240                     
   266         okToExit = (toTextLength == 0 && ccTextLength == 0 && bccTextLength == 0 && 
   241         okToExit = (toTextLength == 0 && ccTextLength == 0 && bccTextLength == 0 && 
   267             subjectLength == 0 && mContentWidget->editor()->document()->isEmpty());
   242             subjectLength == 0 && mContentWidget->editor()->document()->isEmpty() &&
       
   243             attachmentList.count() < 1);
   268 
   244 
   269         // content exists, verify exit from user
   245         // content exists, verify exit from user
   270         if (!okToExit) {
   246         if (!okToExit) {
   271             HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   247             okToExit = NmUtilities::displayQuestionNote(hbTrId("txt_mail_dialog_delete_message"));
   272             messageBox->setText(hbTrId("txt_mail_dialog_delete_message"));
       
   273             messageBox->setTimeout(HbMessageBox::NoTimeout);
       
   274         
       
   275             // Read user selection
       
   276             HbAction *action = messageBox->exec(); 
       
   277             okToExit = (action == messageBox->primaryAction());
       
   278         }
   248         }
   279     }
   249     }
   280 
   250 
   281     return okToExit;
   251     return okToExit;
   282 }
   252 }
   312             // Hide the application.
   282             // Hide the application.
   313             XQServiceUtil::toBackground(true);
   283             XQServiceUtil::toBackground(true);
   314         }
   284         }
   315 
   285 
   316         // Display the wait dialog.
   286         // Display the wait dialog.
   317         mWaitDialog->exec();
   287         mWaitDialog->setModal(false);
       
   288         mWaitDialog->setBackgroundFaded(false);
       
   289         mWaitDialog->show();
   318         delete mWaitDialog;
   290         delete mWaitDialog;
   319         mWaitDialog = NULL;
   291         mWaitDialog = NULL;
   320     }
   292     }
   321 
   293 
   322     // These operations need to be stopped before message can be deleted
   294     // These operations need to be stopped before message can be deleted
   323     delete mAddAttachmentOperation;
   295     if (mAddAttachmentOperation && mAddAttachmentOperation->isRunning()) {
   324     mAddAttachmentOperation = NULL;
   296         mAddAttachmentOperation->cancelOperation();
   325     delete mRemoveAttachmentOperation;
   297     }
   326     mRemoveAttachmentOperation = NULL;
   298     if (mRemoveAttachmentOperation && mRemoveAttachmentOperation->isRunning()) {
       
   299         mRemoveAttachmentOperation->cancelOperation();
       
   300     }
   327 
   301 
   328     if (mMessage) { // this is NULL if sending is started
   302     if (mMessage) { // this is NULL if sending is started
   329         // Delete message from drafts
   303         // Delete message from drafts
   330         NmId mailboxId = mMessage->mailboxId();
   304         NmId mailboxId = mMessage->envelope().mailboxId();
   331         NmId folderId = mMessage->parentId();
   305         NmId folderId = mMessage->envelope().folderId();
   332         NmId msgId = mMessage->envelope().id();
   306         NmId msgId = mMessage->envelope().messageId();
   333         mUiEngine.removeMessage(mailboxId, folderId, msgId);
   307         mUiEngine.removeMessage(mailboxId, folderId, msgId);
   334     }
   308     }
       
   309 }
       
   310 
       
   311 /*!
       
   312     Lazy loading when view layout has been loaded
       
   313 */
       
   314 void NmEditorView::viewReady()
       
   315 {
       
   316     // Connect signals from background scroll area
       
   317     connect(mScrollArea, SIGNAL(handleMousePressEvent(QGraphicsSceneMouseEvent*)),
       
   318             this, SLOT(sendMousePressEventToScroll(QGraphicsSceneMouseEvent*)));
       
   319     connect(mScrollArea, SIGNAL(handleMouseReleaseEvent(QGraphicsSceneMouseEvent*)),
       
   320             this, SLOT(sendMouseReleaseEventToScroll(QGraphicsSceneMouseEvent*)));
       
   321     connect(mScrollArea, SIGNAL(handleMouseMoveEvent(QGraphicsSceneMouseEvent*)),
       
   322             this, SLOT(sendMouseMoveEventToScroll(QGraphicsSceneMouseEvent*)));
       
   323 
       
   324     connect(mScrollArea, SIGNAL(handleLongPressGesture(const QPointF &)),
       
   325                 this, SLOT(sendLongPressGesture(const QPointF &)));
       
   326 
       
   327     // Connect options menu about to show to create options menu function
       
   328     // Menu needs to be create "just-in-time"
       
   329     connect(menu(), SIGNAL(aboutToShow()), this, SLOT(createOptionsMenu()));
       
   330     NmAction *dummy = new NmAction(0);
       
   331     menu()->addAction(dummy);
       
   332 
       
   333     initializeVKB();
       
   334     connect(mContentWidget->header(), SIGNAL(recipientFieldsHaveContent(bool)),
       
   335             this, SLOT(setButtonsDimming(bool)) );
       
   336 
       
   337     // call the createToolBar on load view layout
       
   338     createToolBar();
       
   339 
       
   340     // Set dimensions
       
   341     adjustViewDimensions();
       
   342 	
       
   343     // Connect to observe orientation change events
       
   344     connect(mApplication.mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
       
   345             this, SLOT(orientationChanged(Qt::Orientation)));
       
   346     // Signal for handling the attachment list selection
       
   347     connect(mHeaderWidget, SIGNAL(attachmentLongPressed(NmId, QPointF)),
       
   348             this, SLOT(attachmentLongPressed(NmId, QPointF)));
       
   349     
       
   350     // Set message data
       
   351     setMessageData();
   335 }
   352 }
   336 
   353 
   337 /*!
   354 /*!
   338     Find message data based on start parameters.  Method is called
   355     Find message data based on start parameters.  Method is called
   339     when editor is started. If message data is found it means that
   356     when editor is started. If message data is found it means that
   340     operation is forward or reply message.
   357     operation is forward or reply message.
   341 */
   358 */
   342 void NmEditorView::setMessageData()
   359 void NmEditorView::setMessageData()
   343 {
   360 {
   344     // Check the outbox.
   361     // Check the outbox.
   345     delete mCheckOutboxOperation;
   362     if (mCheckOutboxOperation && mCheckOutboxOperation->isRunning()) {
   346     mCheckOutboxOperation = NULL;
   363         mCheckOutboxOperation->cancelOperation();
       
   364         NMLOG("NmEditorView::setMessageData old mCheckOutboxOperation running");
       
   365     }
   347 	
   366 	
   348     mCheckOutboxOperation = mUiEngine.checkOutbox(mStartParam->mailboxId());
   367     mCheckOutboxOperation = mUiEngine.checkOutbox(mStartParam->mailboxId());
   349     
   368     
   350     if (mCheckOutboxOperation) {
   369     if (mCheckOutboxOperation) {
   351         connect(mCheckOutboxOperation, SIGNAL(operationCompleted(int)),
   370         connect(mCheckOutboxOperation, SIGNAL(operationCompleted(int)),
   358 
   377 
   359 /*!
   378 /*!
   360 */
   379 */
   361 void NmEditorView::startMessageCreation(NmUiEditorStartMode startMode)
   380 void NmEditorView::startMessageCreation(NmUiEditorStartMode startMode)
   362 {
   381 {
       
   382     NMLOG("NmEditorView::startMessageCreation ");
   363     NmId mailboxId = mStartParam->mailboxId();
   383     NmId mailboxId = mStartParam->mailboxId();
   364     NmId folderId = mStartParam->folderId();
   384     NmId folderId = mStartParam->folderId();
   365     NmId msgId = mStartParam->messageId();
   385     NmId msgId = mStartParam->messageId();
   366     
   386     
   367     delete mMessageCreationOperation;
   387     if (mMessageCreationOperation && mMessageCreationOperation->isRunning()) {
   368     mMessageCreationOperation = NULL;
   388         mMessageCreationOperation->cancelOperation();
       
   389     }
   369 	
   390 	
   370     // original message is now fetched so start message creation
   391     // original message is now fetched so start message creation
   371     if (startMode == NmUiEditorForward) {
   392     if (startMode == NmUiEditorForward) {
   372         mMessageCreationOperation = mUiEngine.createForwardMessage(mailboxId, msgId);
   393         mMessageCreationOperation = mUiEngine.createForwardMessage(mailboxId, msgId);
   373     }
   394     }
   405     
   426     
   406     bool okToSend = true;
   427     bool okToSend = true;
   407     if (invalidAddresses.count() > 0) {
   428     if (invalidAddresses.count() > 0) {
   408         
   429         
   409         // invalid addresses found, verify send from user
   430         // invalid addresses found, verify send from user
   410         HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
       
   411         QString noteText = hbTrId("txt_mail_dialog_invalid_mail_address_send");
   431         QString noteText = hbTrId("txt_mail_dialog_invalid_mail_address_send");
   412         // set the first failing address to the note
   432         // set the first failing address to the note
   413         noteText = noteText.arg(invalidAddresses.at(0).address());
   433         noteText = noteText.arg(invalidAddresses.at(0).address());
   414         messageBox->setText(noteText);
   434         okToSend = NmUtilities::displayQuestionNote(noteText);
   415         messageBox->setTimeout(HbMessageBox::NoTimeout);
       
   416 
       
   417         // Read user selection
       
   418         HbAction *action = messageBox->exec();
       
   419         okToSend = (action == messageBox->primaryAction());
       
   420     }
   435     }
   421     
   436     
   422     if (okToSend) {
   437     if (okToSend) {
   423         QList<NmOperation *> preliminaryOperations;
   438         QList<NmOperation *> preliminaryOperations;
   424         preliminaryOperations.append(mAddAttachmentOperation);
   439         preliminaryOperations.append(mAddAttachmentOperation);
   425         preliminaryOperations.append(mRemoveAttachmentOperation);
   440         preliminaryOperations.append(mRemoveAttachmentOperation);
   426         // ownership of mMessage is transferred
   441         // ownership of mMessage is transferred
   427         // ownerships of NmOperations in preliminaryOperations are transferred
   442         // NmOperations are automatically deleted after completion
   428         mUiEngine.sendMessage(mMessage, preliminaryOperations);
   443         mUiEngine.sendMessage(mMessage, preliminaryOperations);
   429         mMessage = NULL;
   444         mMessage = NULL;
   430         mAddAttachmentOperation = NULL;
       
   431         mRemoveAttachmentOperation = NULL;
       
   432         preliminaryOperations.clear();
   445         preliminaryOperations.clear();
   433         // sending animation should be shown here, then exit
   446         mApplication.popView();
   434         QTimer::singleShot(1000, &mApplication, SLOT(popView()));
       
   435     }
   447     }
   436 }
   448 }
   437 
   449 
   438 /*!
   450 /*!
   439     This is signalled by mMessageCreationOperation when message is created.
   451     This is signalled by mMessageCreationOperation when message is created.
   585     // Set the message body.
   597     // Set the message body.
   586     // Fetch plain text part form message store.
   598     // Fetch plain text part form message store.
   587     NmMessagePart *plainPart = mMessage->plainTextBodyPart();
   599     NmMessagePart *plainPart = mMessage->plainTextBodyPart();
   588 
   600 
   589     if (plainPart) {
   601     if (plainPart) {
   590         mUiEngine.contentToMessagePart(mMessage->mailboxId(),
   602         mUiEngine.contentToMessagePart(mMessage->envelope().mailboxId(),
   591                                        mMessage->parentId(),
   603                                        mMessage->envelope().folderId(),
   592                                        mMessage->envelope().id(),
   604                                        mMessage->envelope().messageId(),
   593                                        *plainPart);
   605                                        *plainPart);
   594     }
   606     }
   595 
   607 
   596     // Fetch html part form message store.
   608     // Fetch html part form message store.
   597     NmMessagePart *htmlPart = mMessage->htmlBodyPart();
   609     NmMessagePart *htmlPart = mMessage->htmlBodyPart();
   598 
   610 
   599     if (htmlPart) {
   611     if (htmlPart) {
   600         mUiEngine.contentToMessagePart(mMessage->mailboxId(),
   612         mUiEngine.contentToMessagePart(mMessage->envelope().mailboxId(),
   601                                        mMessage->parentId(),
   613                                        mMessage->envelope().folderId(),
   602                                        mMessage->envelope().id(),
   614                                        mMessage->envelope().messageId(),
   603                                        *htmlPart);
   615                                        *htmlPart);
   604     }
   616     }
   605 
   617 
   606     // Fetch attachment.html part form message store if such exists.
   618     // Fetch attachment.html part form message store if such exists.
   607     QList<NmMessagePart*> parts;
   619     QList<NmMessagePart*> parts;
   613             attachmentHtml = part;
   625             attachmentHtml = part;
   614         }
   626         }
   615     }
   627     }
   616 
   628 
   617     if (attachmentHtml) {
   629     if (attachmentHtml) {
   618         mUiEngine.contentToMessagePart(mMessage->mailboxId(),
   630         mUiEngine.contentToMessagePart(mMessage->envelope().mailboxId(),
   619                                        mMessage->parentId(),
   631                                        mMessage->envelope().folderId(),
   620                                        mMessage->envelope().id(),
   632                                        mMessage->envelope().messageId(),
   621                                        *attachmentHtml);
   633                                        *attachmentHtml);
   622     }
   634     }
   623 
   635 
   624     // Set content data
   636     // Set content data
   625     if (editorStartMode==NmUiEditorReply||
   637     if (editorStartMode==NmUiEditorReply||
   643 
   655 
   644     for (int i=0; i<attachments.count(); i++) {
   656     for (int i=0; i<attachments.count(); i++) {
   645         mHeaderWidget->addAttachment(
   657         mHeaderWidget->addAttachment(
   646             attachments[i]->attachmentName(),
   658             attachments[i]->attachmentName(),
   647             QString::number(attachments[i]->size()),
   659             QString::number(attachments[i]->size()),
   648             attachments[i]->id());
   660             attachments[i]->partId());
   649     }
   661     }
   650 
   662 
   651     if (mStartParam) {
   663     if (mStartParam) {
   652         // Attach passed files to the message.
   664         // Attach passed files to the message.
   653         QStringList *fileList = mStartParam->attachmentList();
   665         QStringList *fileList = mStartParam->attachmentList();
   682             // If action has NmSendable condition, it is shown only when send action
   694             // If action has NmSendable condition, it is shown only when send action
   683             // is available, i.e. when at least one recipient field has data.
   695             // is available, i.e. when at least one recipient field has data.
   684             if( list[i]->availabilityCondition() == NmAction::NmSendable ) {
   696             if( list[i]->availabilityCondition() == NmAction::NmSendable ) {
   685                 list[i]->setEnabled(false);
   697                 list[i]->setEnabled(false);
   686             }
   698             }
   687             //object name set in NmBaseClientPlugin::createEditorViewCommands
   699             else if (list[i]->availabilityCondition() == NmAction::NmAttachable) {
   688             //temporary solution
       
   689             else if (list[i]->objectName() == "baseclientplugin_attachaction") {
       
   690                 HbToolBarExtension* extension = new HbToolBarExtension();
   700                 HbToolBarExtension* extension = new HbToolBarExtension();
   691                 mAttachmentPicker = new NmAttachmentPicker(this);
   701                 mAttachmentPicker = new NmAttachmentPicker(this);
   692                 
   702                 
   693                 if (extension && mAttachmentPicker) {
   703                 if (extension && mAttachmentPicker) {
   694                     connect(mAttachmentPicker, SIGNAL(attachmentsFetchOk(const QVariant &)),
   704                     connect(mAttachmentPicker, SIGNAL(attachmentsFetchOk(const QVariant &)),
   754     else if (actionResponse.menuType() == NmActionToolbar) {
   764     else if (actionResponse.menuType() == NmActionToolbar) {
   755         switch (responseCommand) {
   765         switch (responseCommand) {
   756         case NmActionResponseCommandSendMail: {
   766         case NmActionResponseCommandSendMail: {
   757             // Just in case send mail would be somehow accessible during message creation or
   767             // Just in case send mail would be somehow accessible during message creation or
   758             // outobox checking
   768             // outobox checking
   759             if (!mCheckOutboxOperation->isRunning()
   769             if ((!mCheckOutboxOperation || !mCheckOutboxOperation->isRunning()) 
   760                 && (!mMessageCreationOperation || !mMessageCreationOperation->isRunning())) {
   770                 && (!mMessageCreationOperation || !mMessageCreationOperation->isRunning())) {
   761                 startSending();
   771                 startSending();
   762             }
   772             }
   763             break;
   773             break;
   764         }
   774         }
   765         default:
   775         default:
   766             break;
   776             break;
   767         }
       
   768     }
       
   769     else if (actionResponse.menuType() == NmActionContextMenu) {
       
   770         switch (responseCommand) {
       
   771         case NmActionResponseCommandRemoveAttachment: {
       
   772             removeAttachmentTriggered();
       
   773             break;
       
   774         }
       
   775         case NmActionResponseCommandOpenAttachment: {
       
   776             openAttachmentTriggered();
       
   777             break;
       
   778         }
       
   779         default:
       
   780         	break;
       
   781         }
   777         }
   782     }
   778     }
   783 }
   779 }
   784 
   780 
   785 /*!
   781 /*!
   935 {
   931 {
   936     QString newSubject(subject.trimmed());
   932     QString newSubject(subject.trimmed());
   937     
   933     
   938     if (startMode == NmUiEditorReply || startMode == NmUiEditorReplyAll || 
   934     if (startMode == NmUiEditorReply || startMode == NmUiEditorReplyAll || 
   939         startMode == NmUiEditorForward) {
   935         startMode == NmUiEditorForward) {
   940         QString rePrefix(QObject::tr("Re:", "txt_nmailui_reply_subject_prefix"));
   936         QString rePrefix(hbTrId("txt_nmailui_reply_subject_prefix"));
   941         QString fwPrefix(QObject::tr("Fw:", "txt_nmailui_forward_subject_prefix"));
   937         QString fwPrefix(hbTrId("txt_nmailui_forward_subject_prefix"));
   942         
   938         
   943         // strip extra prefixes from beginning
   939         // strip extra prefixes from beginning
   944         int rePrefixLength(rePrefix.length());
   940         int rePrefixLength(rePrefix.length());
   945         int fwPrefixLength(fwPrefix.length());
   941         int fwPrefixLength(fwPrefix.length());
   946         
   942         
   976     This slot is called when 'attachment picker' request has been performed succesfully
   972     This slot is called when 'attachment picker' request has been performed succesfully
   977     Parameter 'value' contains file currently one file name but later list of the files. 
   973     Parameter 'value' contains file currently one file name but later list of the files. 
   978 */
   974 */
   979 void NmEditorView::onAttachmentReqCompleted(const QVariant &value)
   975 void NmEditorView::onAttachmentReqCompleted(const QVariant &value)
   980 {
   976 {
   981     if (!value.isNull()) {
   977     //temporary fix for music picker back button:
   982         addAttachments(value.toStringList());
   978     //it shouldn't emit requestOk signal when nothing is selected
       
   979 	if (value.canConvert<QStringList>()) {
       
   980 	    QStringList list = value.toStringList();
       
   981         if (!list.at(0).isEmpty()) {
       
   982             addAttachments(list);
       
   983         }
   983     }
   984     }
   984 }
   985 }
   985 
   986 
   986 
   987 
   987 /*!
   988 /*!
  1010     foreach (QString fileName, fileNames)  {
  1011     foreach (QString fileName, fileNames)  {
  1011         // At this phase attachment size and nmid are not known
  1012         // At this phase attachment size and nmid are not known
  1012         mHeaderWidget->addAttachment(fileName, QString("0"), NmId(0));
  1013         mHeaderWidget->addAttachment(fileName, QString("0"), NmId(0));
  1013         NMLOG(fileName);
  1014         NMLOG(fileName);
  1014     }
  1015     }
  1015 
  1016     //  Cancel previous operation if it's not running.
  1016     // Delete previous operation if it's not running.
       
  1017     if (mAddAttachmentOperation) {
  1017     if (mAddAttachmentOperation) {
  1018         if (!mAddAttachmentOperation->isRunning()) {
  1018         if (!mAddAttachmentOperation->isRunning()) {
  1019             delete mAddAttachmentOperation;
  1019             mAddAttachmentOperation->cancelOperation();
  1020             mAddAttachmentOperation = NULL;
  1020         }
  1021         }
  1021     }
  1022     }
  1022     // Start operation to attach file or list of files into mail message.
  1023     if (!mAddAttachmentOperation) {
  1023     // This will also copy files into message store.
  1024         // Start operation to attach file or list of files into mail message.
  1024     mAddAttachmentOperation = mUiEngine.addAttachments(*mMessage, fileNames);
  1025         // This will also copy files into message store.
  1025 
  1026         mAddAttachmentOperation = mUiEngine.addAttachments(*mMessage, fileNames);
  1026     if (mAddAttachmentOperation) {
  1027 
  1027         enableToolBarAttach(false);
  1028         if (mAddAttachmentOperation) {
  1028         // Signal to inform completion of one attachment
  1029             enableToolBarAttach(false);
  1029         connect(mAddAttachmentOperation,
  1030             // Signal to inform completion of one attachment
  1030                 SIGNAL(operationPartCompleted(const QString &, const NmId &, int)),
  1031             connect(mAddAttachmentOperation,
  1031                 this,
  1032                     SIGNAL(operationPartCompleted(const QString &, const NmId &, int)),
  1032                 SLOT(oneAttachmentAdded(const QString &, const NmId &, int)));
  1033                     this,
  1033     
  1034                     SLOT(oneAttachmentAdded(const QString &, const NmId &, int)));
  1034         // Signal to inform the completion of the whole operation
  1035         
  1035         connect(mAddAttachmentOperation,
  1036             // Signal to inform the completion of the whole operation
  1036                 SIGNAL(operationCompleted(int)),
  1037             connect(mAddAttachmentOperation,
  1037                 this,
  1038                     SIGNAL(operationCompleted(int)),
  1038                 SLOT(allAttachmentsAdded(int)));
  1039                     this,
       
  1040                     SLOT(allAttachmentsAdded(int)));
       
  1041         }
       
  1042     }
  1039     }
  1043 }
  1040 }
  1044 
  1041 
  1045 /*!
  1042 /*!
  1046     This slot is called to create context menu when attachment has been selected
  1043     This slot is called to create context menu when attachment has been selected
  1068         }
  1065         }
  1069     }
  1066     }
  1070 
  1067 
  1071     // Add menu position check here, so that it does not go outside of the screen
  1068     // Add menu position check here, so that it does not go outside of the screen
  1072     QPointF menuPos(point.x(),point.y());
  1069     QPointF menuPos(point.x(),point.y());
  1073     mAttachmentListContextMenu->exec(menuPos);
  1070     mAttachmentListContextMenu->setPreferredPos(menuPos);
       
  1071     mAttachmentListContextMenu->open(this, SLOT(contextButton(NmActionResponse&)));
       
  1072 }
       
  1073 
       
  1074 /*!
       
  1075     Slot. Signaled when menu option is selected
       
  1076 */
       
  1077 void NmEditorView::contextButton(NmActionResponse &result)
       
  1078 {
       
  1079     if (result.menuType() == NmActionContextMenu) {
       
  1080         switch (result.responseCommand()) {
       
  1081         case NmActionResponseCommandRemoveAttachment: {
       
  1082             removeAttachmentTriggered();
       
  1083             break;
       
  1084         }
       
  1085         case NmActionResponseCommandOpenAttachment: {
       
  1086             openAttachmentTriggered();
       
  1087             break;
       
  1088         }
       
  1089         default:
       
  1090             break;
       
  1091         }
       
  1092     }
  1074 }
  1093 }
  1075 
  1094 
  1076 /*!
  1095 /*!
  1077     This is signalled by mAddAttachmentOperation when the operation is
  1096     This is signalled by mAddAttachmentOperation when the operation is
  1078     completed for one attachment.
  1097     completed for one attachment.
  1079 */
  1098 */
  1080 void NmEditorView::oneAttachmentAdded(const QString &fileName, const NmId &msgPartId, int result)
  1099 void NmEditorView::oneAttachmentAdded(const QString &fileName, const NmId &msgPartId, int result)
  1081 {
  1100 {
  1082     if (result == NmNoError && mMessage) {
  1101     if (result == NmNoError && mMessage) {
  1083         // Need to get the message again because new attachment part has been added.
  1102         // Need to get the message again because new attachment part has been added.
  1084         NmId mailboxId = mMessage->mailboxId();
  1103         NmId mailboxId = mMessage->envelope().mailboxId();
  1085         NmId folderId = mMessage->parentId();
  1104         NmId folderId = mMessage->envelope().folderId();
  1086         NmId msgId = mMessage->envelope().id();
  1105         NmId msgId = mMessage->envelope().messageId();
  1087 
  1106 
  1088         delete mMessage;
  1107         delete mMessage;
  1089         mMessage = NULL;
  1108         mMessage = NULL;
  1090         
  1109         
  1091         mMessage = mUiEngine.message(mailboxId, folderId, msgId);
  1110         mMessage = mUiEngine.message(mailboxId, folderId, msgId);
  1095             QList<NmMessagePart*> attachmentList;
  1114             QList<NmMessagePart*> attachmentList;
  1096             mMessage->attachmentList(attachmentList);
  1115             mMessage->attachmentList(attachmentList);
  1097         
  1116         
  1098             // Search newly added attachment from the list
  1117             // Search newly added attachment from the list
  1099             for (int i=0; i<attachmentList.count(); i++) {
  1118             for (int i=0; i<attachmentList.count(); i++) {
  1100                 if (attachmentList[i]->id() == msgPartId) {
  1119                 if (attachmentList[i]->partId() == msgPartId) {
  1101                     // Get attachment file size and set it into UI
  1120                     // Get attachment file size and set it into UI
  1102                     mHeaderWidget->setAttachmentParameters(fileName,
  1121                     mHeaderWidget->setAttachmentParameters(fileName,
  1103                         msgPartId,
  1122                         msgPartId,
  1104                         QString().setNum(attachmentList[i]->size()),
  1123                         QString().setNum(attachmentList[i]->size()),
  1105                         result);
  1124                         result);
  1120 */
  1139 */
  1121 void NmEditorView::allAttachmentsAdded(int result)
  1140 void NmEditorView::allAttachmentsAdded(int result)
  1122 {
  1141 {
  1123     enableToolBarAttach(true);
  1142     enableToolBarAttach(true);
  1124     if (result != NmNoError) {
  1143     if (result != NmNoError) {
  1125         HbMessageBox::warning(hbTrId("txt_mail_dialog_unable_to_add_attachment"));
  1144         NmUtilities::displayWarningNote(hbTrId("txt_mail_dialog_unable_to_add_attachment"));
  1126     }
  1145     }
  1127 }
  1146 }
  1128 
  1147 
  1129 /*!
  1148 /*!
  1130     This is signalled by mCheckOutboxOperation when the operation is complete.
  1149     This is signalled by mCheckOutboxOperation when the operation is complete.
  1149                 messageId);
  1168                 messageId);
  1150             
  1169             
  1151             fillEditorWithMessageContents();
  1170             fillEditorWithMessageContents();
  1152             
  1171             
  1153             if (mMessage) {
  1172             if (mMessage) {
  1154                 HbMessageBox::warning(
  1173                 NmUtilities::displayWarningNote(
  1155                     hbTrId("txt_mail_dialog_sending failed").arg(
  1174                     hbTrId("txt_mail_dialog_sending failed").arg(
  1156                         NmUtilities::truncate(
  1175                         NmUtilities::truncate(
  1157                             mMessage->envelope().subject(), 20)));
  1176                             mMessage->envelope().subject(), 20)));
  1158             }
  1177             }
  1159         }
  1178         }
  1239 /*!
  1258 /*!
  1240     This slot is called when 'remove' is selected from attachment list context menu.
  1259     This slot is called when 'remove' is selected from attachment list context menu.
  1241 */
  1260 */
  1242 void NmEditorView::removeAttachmentTriggered()
  1261 void NmEditorView::removeAttachmentTriggered()
  1243 {
  1262 {
  1244     // Delete previous operation
  1263     // Cancel will delete previous operation
  1245     if (mRemoveAttachmentOperation) {
  1264     if (mRemoveAttachmentOperation) {
  1246         if (!mRemoveAttachmentOperation->isRunning()) {
  1265         if (!mRemoveAttachmentOperation->isRunning()) {
  1247             delete mRemoveAttachmentOperation;
  1266             mRemoveAttachmentOperation->cancelOperation();
  1248             mRemoveAttachmentOperation = NULL;
  1267         }
  1249         }
  1268     }
  1250     }
  1269     // Remove from UI
  1251     if (!mRemoveAttachmentOperation) {
  1270     mHeaderWidget->removeAttachment(mSelectedAttachment);
  1252         // Remove from UI
  1271     // Remove from message store
  1253         mHeaderWidget->removeAttachment(mSelectedAttachment);
  1272     mRemoveAttachmentOperation = mUiEngine.removeAttachment(*mMessage, mSelectedAttachment);
  1254         // Remove from message store
  1273     if (mRemoveAttachmentOperation) {
  1255         mRemoveAttachmentOperation = mUiEngine.removeAttachment(*mMessage, mSelectedAttachment);
  1274         // Signal to inform the remove operation completion
  1256         if (mRemoveAttachmentOperation) {
  1275         connect(mRemoveAttachmentOperation,
  1257             // Signal to inform the remove operation completion
  1276                 SIGNAL(operationCompleted(int)),
  1258             connect(mRemoveAttachmentOperation,
  1277                 this,
  1259                     SIGNAL(operationCompleted(int)),
  1278                 SLOT(attachmentRemoved(int)));
  1260                     this,
       
  1261                     SLOT(attachmentRemoved(int)));
       
  1262         }
       
  1263     }
  1279     }
  1264 }
  1280 }
  1265 
  1281 
  1266 /*!
  1282 /*!
  1267     This slot is called by mRemoveAttachmentOperation when the operation is
  1283     This slot is called by mRemoveAttachmentOperation when the operation is
  1272     // It is not desided yet what to do if operation fails
  1288     // It is not desided yet what to do if operation fails
  1273     Q_UNUSED(result);
  1289     Q_UNUSED(result);
  1274     
  1290     
  1275     if (mMessage) {
  1291     if (mMessage) {
  1276         // Reload message because one attachment has been removed
  1292         // Reload message because one attachment has been removed
  1277         NmId mailboxId = mMessage->mailboxId();
  1293         NmId mailboxId = mMessage->envelope().mailboxId();
  1278         NmId folderId = mMessage->parentId();
  1294         NmId folderId = mMessage->envelope().folderId();
  1279         NmId msgId = mMessage->envelope().id();
  1295         NmId msgId = mMessage->envelope().messageId();
  1280 
  1296 
  1281         delete mMessage;
  1297         delete mMessage;
  1282         mMessage = NULL;
  1298         mMessage = NULL;
  1283     
  1299     
  1284         mMessage = mUiEngine.message(mailboxId, folderId, msgId);
  1300         mMessage = mUiEngine.message(mailboxId, folderId, msgId);
  1302     if (tb) {
  1318     if (tb) {
  1303         QList<QAction *> toolbarList = tb->actions();
  1319         QList<QAction *> toolbarList = tb->actions();
  1304         int count = toolbarList.count();
  1320         int count = toolbarList.count();
  1305         for (int i = 0; i < count; i++) {
  1321         for (int i = 0; i < count; i++) {
  1306             NmAction *action = static_cast<NmAction *>(toolbarList[i]);
  1322             NmAction *action = static_cast<NmAction *>(toolbarList[i]);
  1307             //object name set in NmBaseClientPlugin::createEditorViewCommands
  1323             if (action->availabilityCondition() == NmAction::NmAttachable) {
  1308             //temporary solution
       
  1309             if (action->objectName() == "baseclientplugin_attachaction") {
       
  1310                 action->setEnabled(enable);
  1324                 action->setEnabled(enable);
  1311             }
  1325             }
  1312         }
  1326         }
  1313     }
  1327     }
  1314 }
  1328 }