emailuis/nmailui/src/nmviewerview.cpp
changeset 68 83cc6bae1de8
parent 66 084b5b1f02a7
child 74 6c59112cfd31
equal deleted inserted replaced
67:459da34cdb45 68:83cc6bae1de8
    31 static const int NmProgressValueComplete = 100;
    31 static const int NmProgressValueComplete = 100;
    32 static const QString NmParamTextHeightSecondary = "hb-param-text-height-secondary";
    32 static const QString NmParamTextHeightSecondary = "hb-param-text-height-secondary";
    33 static const QString NmHttpLinkScheme = "http";
    33 static const QString NmHttpLinkScheme = "http";
    34 static const QString NmHttpsLinkScheme = "https";
    34 static const QString NmHttpsLinkScheme = "https";
    35 static const QString NmMailtoLinkScheme = "mailto";
    35 static const QString NmMailtoLinkScheme = "mailto";
       
    36 static const QString NmImagePartInline = "inline";
       
    37 static const QString NmImagePartAttachment = "attachment";
    36 
    38 
    37 // Local constants
    39 // Local constants
    38 const qreal NmZoomFactor = 1.5;
    40 const qreal NmZoomFactor = 1.5;
    39 
    41 
    40 /*!
    42 /*!
    62 mMessage(NULL),
    64 mMessage(NULL),
    63 mScrollArea(NULL),
    65 mScrollArea(NULL),
    64 mViewerContent(NULL),
    66 mViewerContent(NULL),
    65 mWebView(NULL),
    67 mWebView(NULL),
    66 mHeaderWidget(NULL),
    68 mHeaderWidget(NULL),
       
    69 mMessagePartFetchingOperation(NULL),
    67 mMessageFetchingOperation(NULL),
    70 mMessageFetchingOperation(NULL),
    68 mDisplayingPlainText(false),
    71 mDisplayingPlainText(false),
    69 mDocumentLoader(NULL),
    72 mDocumentLoader(NULL),
    70 mScrollAreaContents(NULL),
    73 mScrollAreaContents(NULL),
    71 mScreenSize(QSize(0,0)),
    74 mScreenSize(QSize(0,0)),
   256     Function fecthes message data based on parameters
   259     Function fecthes message data based on parameters
   257 */
   260 */
   258 void NmViewerView::loadMessage()
   261 void NmViewerView::loadMessage()
   259 {
   262 {
   260     NM_FUNCTION;
   263     NM_FUNCTION;
       
   264     NM_TIMESTAMP("Loading message starts.");
   261     
   265     
   262     if (mMessage) {
   266     if (mMessage) {
   263         delete mMessage;
   267         delete mMessage;
   264         mMessage = NULL;
   268         mMessage = NULL;
   265     }
   269     }
   294         if (!body || (body && (body->fetchedSize() < body->size()))) {
   298         if (!body || (body && (body->fetchedSize() < body->size()))) {
   295             // start fetching operation
   299             // start fetching operation
   296             if (mMessageFetchingOperation && mMessageFetchingOperation->isRunning()) { 
   300             if (mMessageFetchingOperation && mMessageFetchingOperation->isRunning()) { 
   297                 mMessageFetchingOperation->cancelOperation();
   301                 mMessageFetchingOperation->cancelOperation();
   298             }
   302             }
   299             mMessageFetchingOperation = mUiEngine.fetchMessage(mailboxId, folderId, msgId);
   303             if (mMessagePartFetchingOperation && mMessagePartFetchingOperation->isRunning()) { 
       
   304                 mMessagePartFetchingOperation->cancelOperation();
       
   305             }
       
   306             
       
   307             if(body)
       
   308                 {
       
   309                 mMessagePartFetchingOperation = mUiEngine.fetchMessagePart(mailboxId, folderId, msgId,body->partId());
       
   310                 }
       
   311             else
       
   312                 {
       
   313                 mMessageFetchingOperation = mUiEngine.fetchMessage(mailboxId, folderId, msgId);
       
   314                 }
   300 
   315 
   301             if (mMessageFetchingOperation) {
   316             if (mMessageFetchingOperation) {
   302                 connect(mMessageFetchingOperation,
   317                 connect(mMessageFetchingOperation,
   303                         SIGNAL(operationCompleted(int)),
   318                         SIGNAL(operationCompleted(int)),
   304                         this,
   319                         this,
   305                         SLOT(messageFetched(int)));
   320                         SLOT(messageFetched(int)));
   306                 createAndShowWaitDialog();
   321                 createAndShowWaitDialog();
   307             }
   322             }
       
   323             
       
   324             if (mMessagePartFetchingOperation) {
       
   325                 connect(mMessagePartFetchingOperation,
       
   326                         SIGNAL(operationCompleted(int)),
       
   327                         this,
       
   328                         SLOT(messageFetched(int)));
       
   329                 createAndShowWaitDialog();
       
   330             }
       
   331             
   308         } else {
   332         } else {
   309             // message is fetched
   333             // message is fetched
   310             setMessageData();
   334             setMessageData();
   311         }
   335         }
   312     }
   336     }
   319 {
   343 {
   320     mWaitDialog->close();
   344     mWaitDialog->close();
   321     disconnect(mWaitDialog->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
   345     disconnect(mWaitDialog->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
   322                 this, SLOT(orientationChanged(Qt::Orientation)));
   346                 this, SLOT(orientationChanged(Qt::Orientation)));
   323     
   347     
   324     if (result == NmNoError && mMessageFetchingOperation) {
   348     if (result == NmNoError && (mMessageFetchingOperation || mMessagePartFetchingOperation)) {
   325         if (mMessage) {
   349         if (mMessage) {
   326             delete mMessage;
   350             delete mMessage;
   327             mMessage = NULL;
   351             mMessage = NULL;
   328         }
   352         }
   329         // Read start params and message object
   353         // Read start params and message object
   349 {
   373 {
   350     if (!mWaitNoteCancelled) {
   374     if (!mWaitNoteCancelled) {
   351         if (mMessageFetchingOperation && mMessageFetchingOperation->isRunning()) { 
   375         if (mMessageFetchingOperation && mMessageFetchingOperation->isRunning()) { 
   352 	        mMessageFetchingOperation->cancelOperation();
   376 	        mMessageFetchingOperation->cancelOperation();
   353         }
   377         }
       
   378         if (mMessagePartFetchingOperation && mMessagePartFetchingOperation->isRunning()) { 
       
   379             mMessagePartFetchingOperation->cancelOperation();
       
   380         }
       
   381         
   354         mWaitNoteCancelled = true;
   382         mWaitNoteCancelled = true;
   355         QMetaObject::invokeMethod(&mApplication, "prepareForPopView", Qt::QueuedConnection);
   383         QMetaObject::invokeMethod(&mApplication, "prepareForPopView", Qt::QueuedConnection);
   356     }
   384     }
   357 }
   385 }
   358 
   386 
   431         bool inserted(false);
   459         bool inserted(false);
   432         QList<NmMessagePart*> messageParts;
   460         QList<NmMessagePart*> messageParts;
   433         mMessage->attachmentList(messageParts);
   461         mMessage->attachmentList(messageParts);
   434         for (int i = 0; i < messageParts.count();i++) {
   462         for (int i = 0; i < messageParts.count();i++) {
   435             NmMessagePart *part = messageParts[i];
   463             NmMessagePart *part = messageParts[i];
   436             if (part &&
   464             // Inline images are not displayed in attachment list
   437                 ((part->contentDisposition().trimmed().startsWith("inline", Qt::CaseInsensitive)==false) ||
   465             if (part && !isInlineImage(part)) {               
   438                  (part->contentType().trimmed().startsWith("image", Qt::CaseInsensitive)==false))) {
       
   439                 QString fileName = part->attachmentName();
   466                 QString fileName = part->attachmentName();
   440                 // index starts from zero, next index is same as count
   467                 // index starts from zero, next index is same as count
   441                 int attaIndex = mAttaWidget->count();
   468                 int attaIndex = mAttaWidget->count();
   442                 mAttaWidget->insertAttachment(attaIndex, fileName,
   469                 mAttaWidget->insertAttachment(attaIndex, fileName,
   443                                               NmUtilities::attachmentSizeString(part->size()));
   470                                               NmUtilities::attachmentSizeString(part->size()));
   446                 if (mAttaManager.isFetching() && 
   473                 if (mAttaManager.isFetching() && 
   447                         mAttaManager.partIdUnderFetch() == part->partId()) {
   474                         mAttaManager.partIdUnderFetch() == part->partId()) {
   448                     mAttaIndexUnderFetch = attaIndex;
   475                     mAttaIndexUnderFetch = attaIndex;
   449                 }
   476                 }
   450                 inserted = true;
   477                 inserted = true;
   451             }
   478             }   
   452         }
   479         }
   453         if (inserted) {
   480         if (inserted) {
   454             QObject::connect(mAttaWidget, SIGNAL(itemActivated(int)),
   481             QObject::connect(mAttaWidget, SIGNAL(itemActivated(int)),
   455                     this, SLOT(openAttachment(int)));
   482                     this, SLOT(openAttachment(int)));
   456         }
   483         }
   551         for (int i=0; i < parts.count(); i++) {
   578         for (int i=0; i < parts.count(); i++) {
   552             NmMessagePart *child = parts[i];
   579             NmMessagePart *child = parts[i];
   553             // Browse through embedded image parts and add those
   580             // Browse through embedded image parts and add those
   554             // the web view.
   581             // the web view.
   555             bool isFetched = child->fetchedSize() >= child->size();
   582             bool isFetched = child->fetchedSize() >= child->size();
   556             if(child->contentType().startsWith("image", Qt::CaseInsensitive) &&
   583             // Read inline images to webkit memory if msg part content type IS image and
   557                child->contentDisposition().trimmed().startsWith("inline", Qt::CaseInsensitive)) {
   584             // content disposition IS NOT marked to be attachment
       
   585             if(isInlineImage(child)) {
   558                 QString contentId = child->contentId();
   586                 QString contentId = child->contentId();
   559                 if (isFetched) {
   587                 if (isFetched) {
   560                     int ret = mUiEngine.contentToMessagePart(
   588                     int ret = mUiEngine.contentToMessagePart(
   561                             mailboxId, folderId, messageId, *child);
   589                             mailboxId, folderId, messageId, *child);
   562                     if (ret == NmNoError) {
   590                     if (ret == NmNoError) {
   626     }
   654     }
   627     mDisplayingPlainText=true;  
   655     mDisplayingPlainText=true;  
   628     return msg;
   656     return msg;
   629 }
   657 }
   630 
   658 
   631 /*!
   659 
   632     Reload view contents with new start parameters
   660 /*!
   633     Typically when view is already open and external view activation occurs
   661     Reloads the view contents with new given start parameters. Typically, this
   634     for this same view
   662     method is called when the view is already open and an external view
       
   663     activation occurs for this same view.
       
   664 
       
   665     \param startParam The new parameters.
   635 */
   666 */
   636 void NmViewerView::reloadViewContents(NmUiStartParam* startParam)
   667 void NmViewerView::reloadViewContents(NmUiStartParam* startParam)
   637 {
   668 {
   638     // Check start parameter validity, message view cannot
   669     NM_FUNCTION;
   639     // be updated if given parameter is zero.
   670 
       
   671     // Check the validity of the start parameters. The message view cannot be
       
   672     // updated if the given message ID is invalid (zero).
   640     if (startParam && startParam->viewId() == NmUiViewMessageViewer &&
   673     if (startParam && startParam->viewId() == NmUiViewMessageViewer &&
   641         startParam->messageId()!= 0) {
   674         startParam->messageId() != 0) {
   642         // Delete existing start parameter data
   675         // Delete the existing start parameters and store the given parameters.
   643         delete mStartParam;
   676         delete mStartParam;
   644         mStartParam = NULL;
       
   645         // Store new start parameter data
       
   646         mStartParam = startParam;
   677         mStartParam = startParam;
   647         // Reload viewer with new message information
   678 
   648         setMessageData();
   679         // Reload the view using the new message information.
       
   680         setMailboxName();
       
   681         loadMessage(); // Updates mMessage.
       
   682 
       
   683         if (mHeaderWidget && mMessage) {
       
   684             // Update the sender, recipient and subject etc.
       
   685             mHeaderWidget->setMessage(mMessage);
       
   686         }
       
   687 
       
   688         setMessageData();        
   649     }
   689     }
   650     else {
   690     else {
   651         NMLOG("nmailui: Invalid viewer start parameter");
   691         NMLOG("NmViewerView::reloadViewContents(): Invalid start parameters!");
   652         // Unused start parameter needs to be deleted
   692 
       
   693         // Since we will not take ownership, the given parameters need to be
       
   694         // deleted.
   653         delete startParam;
   695         delete startParam;
   654     }
   696     }
   655 }
   697 }
       
   698 
   656 
   699 
   657 /*!
   700 /*!
   658     nmailViewId
   701     nmailViewId
   659 */
   702 */
   660 NmUiViewId NmViewerView::nmailViewId() const
   703 NmUiViewId NmViewerView::nmailViewId() const
   951                     mStartParam->messageId(), NmUiEditorReply);
   994                     mStartParam->messageId(), NmUiEditorReply);
   952                 mApplication.enterNmUiView(startParam);
   995                 mApplication.enterNmUiView(startParam);
   953             }
   996             }
   954             break;
   997             break;
   955             case NmActionResponseCommandReplyAll: {
   998             case NmActionResponseCommandReplyAll: {
       
   999                 NM_TIMESTAMP("Reply All chose.");
   956                 mAttaManager.cancelFetch();
  1000                 mAttaManager.cancelFetch();
   957                 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageEditor,
  1001                 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageEditor,
   958                     mStartParam->mailboxId(), mStartParam->folderId(),
  1002                     mStartParam->mailboxId(), mStartParam->folderId(),
   959                     mStartParam->messageId(), NmUiEditorReplyAll);
  1003                     mStartParam->messageId(), NmUiEditorReplyAll);
   960                 mApplication.enterNmUiView(startParam);
  1004                 mApplication.enterNmUiView(startParam);
   967                     mStartParam->messageId(), NmUiEditorForward);
  1011                     mStartParam->messageId(), NmUiEditorForward);
   968                 mApplication.enterNmUiView(startParam);
  1012                 mApplication.enterNmUiView(startParam);
   969             }
  1013             }
   970             break;
  1014             break;
   971             case NmActionResponseCommandDeleteMail: {
  1015             case NmActionResponseCommandDeleteMail: {
       
  1016                 NM_TIMESTAMP("Delete from viewer chose.");
   972                 mAttaManager.cancelFetch();
  1017                 mAttaManager.cancelFetch();
   973                 deleteMessage();
  1018                 deleteMessage();
   974                 }
  1019                 }
   975             break;
  1020             break;
   976             default:
  1021             default:
  1031 {
  1076 {
  1032     if ((mStartParam->viewId() == NmUiViewMessageViewer)
  1077     if ((mStartParam->viewId() == NmUiViewMessageViewer)
  1033         && (mStartParam->mailboxId()== mailboxId)
  1078         && (mStartParam->mailboxId()== mailboxId)
  1034         && (mStartParam->folderId()== folderId)
  1079         && (mStartParam->folderId()== folderId)
  1035         && (mStartParam->messageId()== messageId)) {
  1080         && (mStartParam->messageId()== messageId)) {
       
  1081         NM_TIMESTAMP("Message deleted.");
  1036         mApplication.prepareForPopView();
  1082         mApplication.prepareForPopView();
  1037     }
  1083     }
  1038 }
  1084 }
  1039 
  1085 
  1040 /*!
  1086 /*!
  1054     connect(mWaitDialog, SIGNAL(cancelled()), this, SLOT(waitNoteCancelled()));
  1100     connect(mWaitDialog, SIGNAL(cancelled()), this, SLOT(waitNoteCancelled()));
  1055     mWaitDialog->setText(hbTrId("txt_mail_dialog_loading_mail_content"));
  1101     mWaitDialog->setText(hbTrId("txt_mail_dialog_loading_mail_content"));
  1056     // Display wait dialog
  1102     // Display wait dialog
  1057     mWaitDialog->show(); 
  1103     mWaitDialog->show(); 
  1058 }
  1104 }
       
  1105 
       
  1106 
       
  1107 /*!
       
  1108     Helper function to determine whether message part is inline image.
       
  1109 */
       
  1110 bool NmViewerView::isInlineImage(NmMessagePart* part)
       
  1111 {
       
  1112     bool ret(false);
       
  1113     if (part){
       
  1114         // Check whether the message part is image
       
  1115         if (part->contentType().trimmed().startsWith("image", Qt::CaseInsensitive)) {
       
  1116             bool isMarkedInline(false);
       
  1117             bool isMarkedAttachment(false);
       
  1118             // Check whether the image has been marked correctly as an inline image
       
  1119             if (part->contentDisposition().trimmed().startsWith(NmImagePartInline, Qt::CaseInsensitive)) {
       
  1120                 isMarkedInline=true;
       
  1121             }            
       
  1122             // Check whether the image has been marked correctly as an attachment
       
  1123             else if (part->contentDisposition().trimmed().startsWith(NmImagePartAttachment, Qt::CaseInsensitive)) {
       
  1124                 isMarkedAttachment=true;
       
  1125             }       
       
  1126             // UI handles image as inline if it is correctly marked to be inline
       
  1127             // or hasn't been marked at all with content disposition
       
  1128             if (isMarkedInline || (!isMarkedInline && !isMarkedAttachment) ) {
       
  1129                 ret=true;
       
  1130             }            
       
  1131         }
       
  1132     }
       
  1133     return ret;
       
  1134 }
       
  1135