emailuis/nmailui/src/nmviewerview.cpp
changeset 54 997a02608b3a
parent 53 bf7eb7911fc5
child 59 16ed8d08d0b1
equal deleted inserted replaced
53:bf7eb7911fc5 54:997a02608b3a
     9  * Initial Contributors:
     9  * Initial Contributors:
    10  * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11  *
    11  *
    12  * Contributors:
    12  * Contributors:
    13  *
    13  *
    14  * Description:
    14  * Description: Mail viewer implementation.
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 #include "nmuiheaders.h"
    18 #include "nmuiheaders.h"
    19 
    19 
    23 static const char *NMUI_MESSAGE_VIEWER_SCROLL_AREA = "viewerScrollArea";
    23 static const char *NMUI_MESSAGE_VIEWER_SCROLL_AREA = "viewerScrollArea";
    24 static const char *NMUI_MESSAGE_VIEWER_SCROLL_AREA_CONTENTS = "viewerScrollAreaContents";
    24 static const char *NMUI_MESSAGE_VIEWER_SCROLL_AREA_CONTENTS = "viewerScrollAreaContents";
    25 static const char *NMUI_MESSAGE_VIEWER_HEADER = "viewerHeader";
    25 static const char *NMUI_MESSAGE_VIEWER_HEADER = "viewerHeader";
    26 static const char *NMUI_MESSAGE_VIEWER_ATTALIST = "viewerAttaList";
    26 static const char *NMUI_MESSAGE_VIEWER_ATTALIST = "viewerAttaList";
    27 static const char *NMUI_MESSAGE_VIEWER_SCROLL_WEB_VIEW = "viewerWebView";
    27 static const char *NMUI_MESSAGE_VIEWER_SCROLL_WEB_VIEW = "viewerWebView";
    28 
       
    29 static const int NmOrientationTimer = 100;
    28 static const int NmOrientationTimer = 100;
    30 static const int NmHeaderMargin = 3;
    29 static const int NmHeaderMargin = 3;
    31 
    30 static const int NmWhitePixmapSize = 10;
       
    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";
       
    34 static const QString NmHttpsLinkScheme = "https";
       
    35 static const QString NmMailtoLinkScheme = "mailto";
    33 
    36 
    34 /*!
    37 /*!
    35 	\class NmViewerView
    38 	\class NmViewerView
    36 	\brief Mail viewer class
    39 	\brief Mail viewer class
    37 */
    40 */
    60 mHeaderWidget(NULL),
    63 mHeaderWidget(NULL),
    61 mMessageFetchingOperation(NULL),
    64 mMessageFetchingOperation(NULL),
    62 mDisplayingPlainText(false),
    65 mDisplayingPlainText(false),
    63 mDocumentLoader(NULL),
    66 mDocumentLoader(NULL),
    64 mScrollAreaContents(NULL),
    67 mScrollAreaContents(NULL),
    65 mViewerHeaderContainer(NULL),
       
    66 mScreenSize(QSize(0,0)),
    68 mScreenSize(QSize(0,0)),
    67 mWaitDialog(NULL),
    69 mWaitDialog(NULL),
    68 webFrameloadingCompleted(false),
    70 webFrameloadingCompleted(false),
    69 mLatestLoadingSize(QSize(0,0)),
    71 mLatestLoadingSize(QSize(0,0)),
    70 mAttaIndexUnderFetch(NmNotFoundError),
    72 mAttaIndexUnderFetch(NmNotFoundError),
    71 mAttaWidget(NULL),
    73 mAttaWidget(NULL),
    72 mViewReady(false),
    74 mViewReady(false),
    73 mWaitNoteCancelled(false),
    75 mWaitNoteCancelled(false),
    74 mErrorNote(NULL)
    76 mErrorNote(NULL)
    75     {
    77 {
    76     // Create documentloader
    78     // Create documentloader
    77     mDocumentLoader = new NmUiDocumentLoader(mMainWindow);
    79     mDocumentLoader = new NmUiDocumentLoader(mMainWindow);
    78     // Get screensize
    80     // Get screensize
    79     mScreenSize = mApplication.screenSize();
    81     mScreenSize = mApplication.screenSize();
    80     // Connect external delete handling to uiengine signal
    82     // Connect external delete handling to uiengine signal
   115 void NmViewerView::aboutToExitView()
   117 void NmViewerView::aboutToExitView()
   116 {
   118 {
   117     // View is about to exit, for safety, stop 
   119     // View is about to exit, for safety, stop 
   118     // loading of content before closing the view
   120     // loading of content before closing the view
   119     if (mWebView){
   121     if (mWebView){
       
   122         mAttaManager.cancelFetch();
   120         mWebView->stop();
   123         mWebView->stop();
   121         if (mWebView->page()){
   124         if (mWebView->page()){
   122             mWebView->page()->deleteLater();
   125             mWebView->page()->deleteLater();
   123         }
   126         }
   124     }
   127     }
   130 void NmViewerView::loadViewLayout()
   133 void NmViewerView::loadViewLayout()
   131 {
   134 {
   132     NM_FUNCTION;
   135     NM_FUNCTION;
   133     
   136     
   134     // Use document loader to load the view
   137     // Use document loader to load the view
   135     bool ok = false;
   138     bool ok(false);
   136     setObjectName(QString(NMUI_MESSAGE_VIEWER_VIEW));
   139     setObjectName(QString(NMUI_MESSAGE_VIEWER_VIEW));
   137     QObjectList objectList;
   140    QObjectList objectList;
   138     objectList.append(this);
   141    objectList.append(this);
   139     // Pass the view to documentloader. Document loader uses this view
   142    // Pass the view to documentloader. Document loader uses this view
   140     // when docml is parsed, instead of creating new view.
   143    // when docml is parsed, instead of creating new view.
   141     // documentloader is created in constructor
   144    // documentloader is created in constructor
   142     mDocumentLoader->setObjectTree(objectList);
   145    mDocumentLoader->setObjectTree(objectList);
   143     mWidgetList = mDocumentLoader->load(NMUI_MESSAGE_VIEWER_XML, &ok);
   146    mWidgetList = mDocumentLoader->load(NMUI_MESSAGE_VIEWER_XML, &ok);
   144     int widgetCount = mWidgetList.count();
   147 
   145     if (ok == true && widgetCount)
   148    if (ok)
   146     {
   149    {
   147         // Create content and content layout
   150         // Create content and content layout
   148         // qobject_cast not work in this case, using reinterpret_cast
   151         // qobject_cast not work in this case, using reinterpret_cast
   149         mViewerContent = reinterpret_cast<HbWidget *>(
   152         mViewerContent = reinterpret_cast<HbWidget *>(
   150                 mDocumentLoader->findObject(NMUI_MESSAGE_VIEWER_CONTENT));
   153                 mDocumentLoader->findObject(NMUI_MESSAGE_VIEWER_CONTENT));
   151         // Find scroll area
   154         // Find scroll area
   164                 QGraphicsLayout *layout = mScrollAreaContents->layout();
   167                 QGraphicsLayout *layout = mScrollAreaContents->layout();
   165                 if (layout){
   168                 if (layout){
   166                     layout->setContentsMargins(0,0,0,0);
   169                     layout->setContentsMargins(0,0,0,0);
   167                 }
   170                 }
   168                 // Set white pixmap to backgrounditem 
   171                 // Set white pixmap to backgrounditem 
   169                 QPixmap whitePixmap(10,10);
   172                 QPixmap whitePixmap(NmWhitePixmapSize,NmWhitePixmapSize);
   170                 whitePixmap.fill(Qt::white);
   173                 whitePixmap.fill(Qt::white);
   171                 QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(whitePixmap);
   174                 QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(whitePixmap);
   172                 mScrollAreaContents->setBackgroundItem(pixmapItem);
   175                 mScrollAreaContents->setBackgroundItem(pixmapItem);
   173             }
   176             }
   174 
   177 
   184 
   187 
   185             // Load webview
   188             // Load webview
   186             mWebView = reinterpret_cast<NmMailViewerWK *>(
   189             mWebView = reinterpret_cast<NmMailViewerWK *>(
   187                     mDocumentLoader->findObject(QString(NMUI_MESSAGE_VIEWER_SCROLL_WEB_VIEW)));
   190                     mDocumentLoader->findObject(QString(NMUI_MESSAGE_VIEWER_SCROLL_WEB_VIEW)));
   188             if (mWebView) {
   191             if (mWebView) {
   189                 mWebView->setParentView(this);
       
   190                 // Set auto load images and private browsing(no history) attributes
   192                 // Set auto load images and private browsing(no history) attributes
   191                 QWebSettings *settings = mWebView->settings();
   193                 QWebSettings *settings = mWebView->settings();
   192                 if (settings) {
   194                 if (settings) {
   193                     settings->setAttribute(QWebSettings::AutoLoadImages, true);
   195                     settings->setAttribute(QWebSettings::AutoLoadImages, true);
   194                     settings->setAttribute(QWebSettings::PrivateBrowsingEnabled, true);   
   196                     settings->setAttribute(QWebSettings::PrivateBrowsingEnabled, true);   
   383     }
   385     }
   384 
   386 
   385   	// if everything is ok, set message to html viewer
   387   	// if everything is ok, set message to html viewer
   386     if (mMessage && mWebView && page) {
   388     if (mMessage && mWebView && page) {
   387         // Set initial size of component and content before loading data
   389         // Set initial size of component and content before loading data
   388         mWebView->setMaximumWidth(mScreenSize.width());
   390         mWebView->setPreferredWidth(mScreenSize.width());
   389         page->setPreferredContentsSize(mScreenSize);
   391         QRectF myGeometry = geometry();
       
   392         page->setViewportSize(myGeometry.size().toSize());
   390         //Set message data to html viewer.
   393         //Set message data to html viewer.
   391         mWebView->setHtml(formatMessage());
   394         mWebView->setHtml(formatMessage());
   392         // Connect to link clicked
   395         // Connect to link clicked
   393         QObject::connect(page, SIGNAL(linkClicked(const QUrl&)),
   396         QObject::connect(page, SIGNAL(linkClicked(const QUrl&)),
   394                 this, SLOT(linkClicked(const QUrl&)));
   397                 this, SLOT(linkClicked(const QUrl&)));
   414         // Set atta widget text color black since header has static white bg.
   417         // Set atta widget text color black since header has static white bg.
   415         mAttaWidget->setTextColor(Qt::black);
   418         mAttaWidget->setTextColor(Qt::black);
   416         // Set attawidget minimum & maximum size
   419         // Set attawidget minimum & maximum size
   417         mAttaWidget->setMinimumWidth(mScreenSize.width());
   420         mAttaWidget->setMinimumWidth(mScreenSize.width());
   418         mAttaWidget->setMaximumWidth(mScreenSize.width());
   421         mAttaWidget->setMaximumWidth(mScreenSize.width());
   419         bool inserted = false;
   422         bool inserted(false);
   420         QList<NmMessagePart*> messageParts;
   423         QList<NmMessagePart*> messageParts;
   421         mMessage->attachmentList(messageParts);
   424         mMessage->attachmentList(messageParts);
   422         for (int i = 0; i < messageParts.count();i++) {
   425         for (int i = 0; i < messageParts.count();i++) {
   423             NmMessagePart *part = messageParts[i];
   426             NmMessagePart *part = messageParts[i];
   424             if (part &&
   427             if (part &&
   456 
   459 
   457 */
   460 */
   458 void NmViewerView::openAttachment(int index)
   461 void NmViewerView::openAttachment(int index)
   459 {
   462 {
   460     NM_FUNCTION;
   463     NM_FUNCTION;
   461     
   464     if (index >= 0) {
   462     NmId attaId = mAttaIdList.at(index);
   465         NmId attaId = mAttaIdList.at(index);
   463     // reload message to get updates part sizes
   466         // reload message to get updates part sizes
   464     loadMessage();
   467         loadMessage();
   465     QList<NmMessagePart*> messageParts;
   468         QList<NmMessagePart*> messageParts;
   466     mMessage->attachmentList(messageParts);
   469         if (mMessage) {
   467     NmId mailboxId = mMessage->envelope().mailboxId();
   470             mMessage->attachmentList(messageParts);
   468     NmId folderId = mMessage->envelope().folderId();
   471              NmId mailboxId = mMessage->envelope().mailboxId();
   469     NmId messageId = mMessage->envelope().messageId();
   472              NmId folderId = mMessage->envelope().folderId();
   470     for (int i = 0; i < messageParts.count(); i++) {
   473              NmId messageId = mMessage->envelope().messageId();
   471         // message part found have to found
   474              for (int i = 0; i < messageParts.count(); i++) {
   472         // and its fetched size is smaller than size, then start part fetch
   475                  // message part found have to found
   473         if (messageParts[i]->partId() == attaId &&
   476                  // and its fetched size is smaller than size, then start part fetch
   474             messageParts[i]->size() > messageParts[i]->fetchedSize()) {
   477                  if (messageParts[i]->partId() == attaId &&
   475             // do not start if there's already ongoing fetch
   478                      messageParts[i]->size() > messageParts[i]->fetchedSize()) {
   476             if (mAttaIndexUnderFetch == NmNotFoundError) {
   479                      // do not start if there's already ongoing fetch
   477                 mAttaIndexUnderFetch = index;
   480                      if (mAttaIndexUnderFetch == NmNotFoundError) {
   478                 mAttaManager.fetchAttachment(mailboxId, folderId,
   481                          mAttaIndexUnderFetch = index;
   479                                              messageId, attaId);
   482                          mAttaManager.fetchAttachment(mailboxId, folderId,
   480             }
   483                                                       messageId, attaId);
   481         }
   484                      }
   482         // attachment is fetched, open file
   485                  }
   483         else if (messageParts[i]->partId() == attaId) {
   486                  // attachment is fetched, open file
   484             XQSharableFile file = mUiEngine.messagePartFile(mailboxId, folderId,
   487                  else if (messageParts[i]->partId() == attaId) {
   485                                                             messageId, attaId);
   488                      mAttaManager.cancelFetch();
   486             int error = NmUtilities::openFile(file);
   489                      XQSharableFile file = mUiEngine.messagePartFile(mailboxId, folderId,
   487             file.close();
   490                                                                      messageId, attaId);
   488             if (error==NmNotFoundError){
   491                      int error = NmUtilities::openFile(file);
   489                 delete mErrorNote;
   492                      file.close();
   490                 mErrorNote=NULL;
   493                      if (error==NmNotFoundError){
   491                 mErrorNote = NmUtilities::displayWarningNote(hbTrId("txt_mail_dialog_unable_to_open_attachment_file_ty"));
   494                          delete mErrorNote;
   492             }
   495                          mErrorNote=NULL;
   493         }
   496                          mErrorNote = NmUtilities::displayWarningNote(
       
   497                                  hbTrId("txt_mail_dialog_unable_to_open_attachment_file_ty"));
       
   498                      }
       
   499                  }
       
   500              }            
       
   501          }
   494     }
   502     }
   495 }
   503 }
   496 
   504 
   497 /*!
   505 /*!
   498     Function formats message based on actual data
   506     Function formats message based on actual data
   500 QString NmViewerView::formatMessage()
   508 QString NmViewerView::formatMessage()
   501 {
   509 {
   502     NM_FUNCTION;
   510     NM_FUNCTION;
   503     
   511     
   504     QString msg = "";
   512     QString msg = "";
   505     // null pointer check for mMessage is done before calling this function
   513     if (mMessage) {
   506     NmId mailboxId = mMessage->envelope().mailboxId();
   514         NmMessagePart *html = mMessage->htmlBodyPart();
   507     NmId folderId = mMessage->envelope().folderId();
   515         if (html) {
   508     NmId messageId = mMessage->envelope().messageId();
   516             msg += formatHtmlMessage(html);
   509     NmMessagePart *html = mMessage->htmlBodyPart();
   517         }
   510     if (html) {
   518         else {
       
   519             NmMessagePart *plain = mMessage->plainTextBodyPart();
       
   520             if (plain) {
       
   521                 msg += formatPlainTextMessage(plain);
       
   522             }
       
   523         }    
       
   524     }
       
   525     return msg;
       
   526 }
       
   527 
       
   528 /*!
       
   529     Function formats html message
       
   530 */
       
   531 QString NmViewerView::formatHtmlMessage(NmMessagePart *html)
       
   532 {    
       
   533     NM_FUNCTION;
       
   534 
       
   535     QString msg = "";
       
   536     if (html && mMessage) {
       
   537         NmId mailboxId = mMessage->envelope().mailboxId();
       
   538         NmId folderId = mMessage->envelope().folderId();
       
   539         NmId messageId = mMessage->envelope().messageId();
   511         QList<NmMessagePart*> parts;
   540         QList<NmMessagePart*> parts;
   512         mMessage->attachmentList(parts);
   541         mMessage->attachmentList(parts);
   513         for (int i=0; i < parts.count(); i++) {
   542         for (int i=0; i < parts.count(); i++) {
   514             NmMessagePart *child = parts[i];
   543             NmMessagePart *child = parts[i];
   515             // Browse through embedded image parts and add those
   544             // Browse through embedded image parts and add those
   531                 }
   560                 }
   532             }
   561             }
   533         }
   562         }
   534         int ret = mUiEngine.contentToMessagePart(mailboxId, folderId, messageId, *html);
   563         int ret = mUiEngine.contentToMessagePart(mailboxId, folderId, messageId, *html);
   535         if (ret == NmNoError) {
   564         if (ret == NmNoError) {
   536             msg = html->textContent();
   565          msg = html->textContent();
   537         }
   566         }    
   538     }
   567     }
   539     else {
   568     return msg;
   540         NmMessagePart *plain = mMessage->plainTextBodyPart();
   569 }
   541         if (plain) {
   570 
   542             int ret = mUiEngine.contentToMessagePart(mailboxId, folderId,
   571 /*!
   543                                                      messageId, *plain);
   572     Function formats plain text message message
   544             if (ret == NmNoError) {
   573 */
   545                 QTextDocument document;
   574 QString NmViewerView::formatPlainTextMessage(NmMessagePart *plain)
   546                 // set font
   575 {
   547                 QFont currentFont = document.defaultFont();
   576     NM_FUNCTION;
   548                 currentFont.setWeight(QFont::Normal);
   577       
   549                 qreal secondarySize;
   578     QString msg = "";
   550                 HbStyle myStyle;
   579     if (plain && mMessage) {
   551                 bool found = myStyle.parameter(NmParamTextHeightSecondary, secondarySize);
   580         NmId mailboxId = mMessage->envelope().mailboxId();
   552                 if (found) {
   581         NmId folderId = mMessage->envelope().folderId();
   553                     HbFontSpec fontSpec(HbFontSpec::Secondary);
   582         NmId messageId = mMessage->envelope().messageId();
   554                     fontSpec.setTextHeight(secondarySize);
   583         int ret = mUiEngine.contentToMessagePart(mailboxId, folderId,
   555                     currentFont.setPixelSize(fontSpec.font().pixelSize());
   584                                                  messageId, *plain);
       
   585         if (ret == NmNoError) {
       
   586             QTextDocument document;
       
   587             // set font
       
   588             QFont currentFont = document.defaultFont();
       
   589             currentFont.setWeight(QFont::Normal);
       
   590             qreal secondarySize;
       
   591             HbStyle myStyle;
       
   592             bool found = myStyle.parameter(NmParamTextHeightSecondary, secondarySize);
       
   593             if (found) {
       
   594                 HbFontSpec fontSpec(HbFontSpec::Secondary);
       
   595                 fontSpec.setTextHeight(secondarySize);
       
   596                 currentFont.setPixelSize(fontSpec.font().pixelSize());
       
   597             }
       
   598             document.setDefaultFont(currentFont);
       
   599             // convert to html
       
   600             document.setPlainText(plain->textContent());
       
   601             msg = document.toHtml();
       
   602     
       
   603             if (qApp->layoutDirection()==Qt::RightToLeft){
       
   604                 // add right alignment to document css section
       
   605                 QRegExp rx("(<style type=\"text/css\">)(.+)(</style>)", Qt::CaseInsensitive);
       
   606                 rx.setMinimal(true);
       
   607                 int pos = rx.indexIn(msg);
       
   608                 if (pos > -1) {
       
   609                     QString newStr = rx.cap(1);
       
   610                     newStr.append(rx.cap(2));
       
   611                     newStr.append("p { text-align: right } ");
       
   612                     newStr.append(rx.cap(3));
       
   613                     msg.replace(rx, newStr);
   556                 }
   614                 }
   557                 document.setDefaultFont(currentFont);
   615             }
   558                 // convert to html
   616         }    
   559                 document.setPlainText(plain->textContent());
   617     }
   560                 msg = document.toHtml();
   618     mDisplayingPlainText=true;  
   561 
       
   562                 if (qApp->layoutDirection()==Qt::RightToLeft){
       
   563                     // add right alignment to document css section
       
   564                     QRegExp rx("(<style type=\"text/css\">)(.+)(</style>)", Qt::CaseInsensitive);
       
   565                     rx.setMinimal(true);
       
   566                     int pos = rx.indexIn(msg);
       
   567                     if (pos > -1) {
       
   568                         QString newStr = rx.cap(1);
       
   569                         newStr.append(rx.cap(2));
       
   570                         newStr.append("p { text-align: right } ");
       
   571                         newStr.append(rx.cap(3));
       
   572                         msg.replace(rx, newStr);
       
   573                     }
       
   574                 }
       
   575             }
       
   576             mDisplayingPlainText=true;
       
   577         }
       
   578     }
       
   579     return msg;
   619     return msg;
   580 }
   620 }
   581 
   621 
   582 /*!
   622 /*!
   583     Reload view contents with new start parameters
   623     Reload view contents with new start parameters
   635     // So that screen is scrollable even before images are fully loaded
   675     // So that screen is scrollable even before images are fully loaded
   636     // First check that new size is different than previous, no need to react if
   676     // First check that new size is different than previous, no need to react if
   637     // same size value is received more than once.
   677     // same size value is received more than once.
   638     if (size != mLatestLoadingSize) {
   678     if (size != mLatestLoadingSize) {
   639         if (!webFrameloadingCompleted && mWebView && mWebView->page() &&
   679         if (!webFrameloadingCompleted && mWebView && mWebView->page() &&
   640             (size.width() > mScreenSize.width() || size.height() > mScreenSize.height())) {
   680             (size.width() > mScreenSize.width() || size.height() > geometry().height())) {
   641             int width = (int)size.width();
   681             int width = (int)size.width();
   642             int height = (int)size.height();
   682             int height = (int)size.height();
   643             // Set content (webview) width
   683             // Set content (webview) width
   644             if (mDisplayingPlainText){
   684             if (mDisplayingPlainText){
   645                 setWebViewWidth(mScreenSize.width());
   685                 mWebView->setPreferredWidth(geometry().width());           
   646             }
   686             }
   647             else {
   687             else {
   648                 setWebViewWidth(width);
   688                 mWebView->setPreferredWidth(width);
   649             }
   689             }
   650             mWebView->setMinimumHeight(height);
   690             mWebView->setPreferredHeight(height);        
   651             mWebView->setPreferredHeight(height);
       
   652         }
   691         }
   653     }
   692     }
   654     mLatestLoadingSize = size;
   693     mLatestLoadingSize = size;
   655 }
   694 }
   656 
   695 
   657 /*!
   696 /*!
   658     Scale web view width when loading is completed
   697     Scale web view width when loading is completed
   659 */
   698 */
   660 void NmViewerView::scaleWebViewWhenLoaded()
   699 void NmViewerView::scaleWebViewWhenLoaded()
   661 {
   700 {
   662     if (mWebView&&mWebView->page()) {
   701     QRectF myGeometry = geometry();
   663         QSizeF contentSize = mWebView->page()->mainFrame()->contentsSize();
   702     QWebPage *page = mWebView->page();
       
   703     if (mWebView && page) {
       
   704         page->setViewportSize(myGeometry.size().toSize());
       
   705         QSizeF contentSize = page->mainFrame()->contentsSize();
   664         int width = (int)contentSize.width();
   706         int width = (int)contentSize.width();
   665         int height = (int)contentSize.height();
   707         int height = (int)contentSize.height();  
   666         // Set content (webview) width
   708         mWebView->setPreferredWidth(width);
   667         if (mDisplayingPlainText) {
   709         mWebView->setPreferredHeight(height);
   668             mWebView->page()->setPreferredContentsSize(mScreenSize);
   710     }
   669             setWebViewWidth(mScreenSize.width());
   711 }
   670         } else {
       
   671             setWebViewWidth(width);
       
   672         }
       
   673         // Set content (webview) height
       
   674         if (mScrollAreaContents){
       
   675             QRectF contentRect = mScrollAreaContents->geometry();
       
   676             if (contentRect.height()<geometry().height()){
       
   677                 contentRect.setHeight(geometry().height());
       
   678                 mViewerContent->setPreferredHeight(contentRect.height());
       
   679                 qreal webViewHeight = geometry().height()-mHeaderWidget->geometry().height();
       
   680                 setWebViewHeighth(webViewHeight);
       
   681             } else {
       
   682                 setWebViewHeighth(height);
       
   683             }
       
   684         }
       
   685     }
       
   686 }
       
   687 
       
   688 
   712 
   689 /*!
   713 /*!
   690     Set new dimensions after orientation change.
   714     Set new dimensions after orientation change.
   691 */
   715 */
   692 void NmViewerView::adjustViewDimensions()
   716 void NmViewerView::adjustViewDimensions()
   699     }
   723     }
   700     if (mAttaWidget){
   724     if (mAttaWidget){
   701         // Set attawidget minimum & maximum size
   725         // Set attawidget minimum & maximum size
   702         mAttaWidget->setMinimumWidth(mScreenSize.width());
   726         mAttaWidget->setMinimumWidth(mScreenSize.width());
   703         mAttaWidget->setMaximumWidth(mScreenSize.width());
   727         mAttaWidget->setMaximumWidth(mScreenSize.width());
   704     }
   728     }    
   705 
   729     scaleWebViewWhenLoaded();
   706     // Scale web view and its contens
       
   707     if (mWebView){
       
   708         if (mDisplayingPlainText){
       
   709             mWebView->setMaximumWidth((int)mScreenSize.width());
       
   710             mWebView->page()->setPreferredContentsSize(QSize((int)mScreenSize.width(),
       
   711                                            (int)mScreenSize.height()));
       
   712         }
       
   713         else{
       
   714             // Check whether contentsize fits to screen
       
   715             // and if not, set preferred size again to allow panning
       
   716             QSizeF contentSize = mWebView->page()->mainFrame()->contentsSize();
       
   717             if (contentSize.width()>mScreenSize.width()){
       
   718                 mWebView->setMaximumWidth((int)contentSize.width());
       
   719                 mWebView->page()->setPreferredContentsSize(QSize((int)contentSize.width(),
       
   720                                                            (int)contentSize.height()));
       
   721             }
       
   722             else{
       
   723                 mWebView->setMaximumWidth((int)mScreenSize.width());
       
   724                 mWebView->page()->setPreferredContentsSize(QSize((int)mScreenSize.width(),
       
   725                                                (int)mScreenSize.height()));
       
   726             }
       
   727         }
       
   728     }
       
   729 
   730 
   730     if (mToolbarEnabled) {
   731     if (mToolbarEnabled) {
   731 		// Re-create toolbar in orientation switch
   732 		// Re-create toolbar in orientation switch
   732 		createToolBar();
   733 		createToolBar();
   733     }
   734     }
   734 }
   735 }
   735 
   736 
   736 
       
   737 /*!
   737 /*!
   738    Screen orientation changed. Web view needs to be scaled when
   738    Screen orientation changed. Web view needs to be scaled when
   739    landscape <-> portrait switch occurs because text needs to
   739    landscape <-> portrait switch occurs because text needs to
   740    be wrapped again.
   740    be wrapped again.
   741 */
   741 */
   750 */
   750 */
   751 void NmViewerView::linkClicked(const QUrl& link)
   751 void NmViewerView::linkClicked(const QUrl& link)
   752 {
   752 {
   753     NM_FUNCTION;
   753     NM_FUNCTION;
   754     
   754     
   755       if (link.scheme() == "http" ||
   755     if (link.scheme() == NmHttpLinkScheme ||
   756           link.scheme() == "https" ) {
   756         link.scheme() == NmHttpsLinkScheme) {
   757           QDesktopServices::openUrl(link);
   757         mAttaManager.cancelFetch();
   758       }
   758         QDesktopServices::openUrl(link);
   759       else if (link.scheme() == "mailto"){
   759     } else if (link.scheme() == NmMailtoLinkScheme){
   760           QList<NmAddress*> *addrList = new QList<NmAddress*>();
   760         mAttaManager.cancelFetch();
   761           NmAddress *mailtoAddr = new NmAddress();
   761         QList<NmAddress*> *addrList = new QList<NmAddress*>();
   762           QString address = link.toString(QUrl::RemoveScheme);
   762         NmAddress *mailtoAddr = new NmAddress();
   763           mailtoAddr->setAddress(address);
   763         QString address = link.toString(QUrl::RemoveScheme);
   764           mailtoAddr->setDisplayName(address);
   764         mailtoAddr->setAddress(address);
   765           addrList->append(mailtoAddr);
   765         mailtoAddr->setDisplayName(address);
   766           // Create start parameters. Address list ownership
   766         addrList->append(mailtoAddr);
   767           // is transferred to startparam object
   767         // Create start parameters. Address list ownership
   768           NmUiStartParam* param = new NmUiStartParam(NmUiViewMessageEditor,
   768         // is transferred to startparam object
   769                                                      mStartParam->mailboxId(),
   769         NmUiStartParam* param = new NmUiStartParam(NmUiViewMessageEditor,
   770                                                       mStartParam->folderId(),
   770                                                    mStartParam->mailboxId(),
   771                                                      0, NmUiEditorMailto, addrList );
   771                                                    mStartParam->folderId(),
   772           mApplication.enterNmUiView(param);
   772                                                    0,
   773       }
   773                                                    NmUiEditorMailto,
       
   774                                                    addrList);
       
   775         mApplication.enterNmUiView(param);
       
   776     }    
   774 }
   777 }
   775 
   778 
   776 /*!
   779 /*!
   777    Function can be used to check whether mouse event has
   780    Function can be used to check whether mouse event has
   778    occured on top of header area.
   781    occured on top of header area.
   790     }
   793     }
   791     return ret;
   794     return ret;
   792 }
   795 }
   793 
   796 
   794 /*!
   797 /*!
   795    get function for content widget web view.
   798     Get function for content widget web view.
   796 */
   799 */
   797 NmMailViewerWK* NmViewerView::webView()
   800 NmMailViewerWK* NmViewerView::webView()
   798 {
   801 {
   799     return mWebView;
   802     return mWebView;
   800 }
   803 }
   801 
   804 
   802 /*!
   805 /*!
   803 
   806     Get function for message being viewed
   804 */
   807 */
   805 NmMessage* NmViewerView::message()
   808 NmMessage* NmViewerView::message()
   806 {
   809 {
   807     return mMessage;
   810     return mMessage;
   808 }
   811 }
   932     // Handle options menu or toolbar
   935     // Handle options menu or toolbar
   933     if (actionResponse.menuType() == NmActionOptionsMenu ||
   936     if (actionResponse.menuType() == NmActionOptionsMenu ||
   934     	actionResponse.menuType() == NmActionToolbar) {
   937     	actionResponse.menuType() == NmActionToolbar) {
   935         switch (actionResponse.responseCommand()) {
   938         switch (actionResponse.responseCommand()) {
   936             case NmActionResponseCommandReply: {
   939             case NmActionResponseCommandReply: {
       
   940                 mAttaManager.cancelFetch();
   937                 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageEditor,
   941                 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageEditor,
   938                     mStartParam->mailboxId(), mStartParam->folderId(),
   942                     mStartParam->mailboxId(), mStartParam->folderId(),
   939                     mStartParam->messageId(), NmUiEditorReply);
   943                     mStartParam->messageId(), NmUiEditorReply);
   940                 mApplication.enterNmUiView(startParam);
   944                 mApplication.enterNmUiView(startParam);
   941             }
   945             }
   942             break;
   946             break;
   943             case NmActionResponseCommandReplyAll: {
   947             case NmActionResponseCommandReplyAll: {
       
   948                 mAttaManager.cancelFetch();
   944                 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageEditor,
   949                 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageEditor,
   945                     mStartParam->mailboxId(), mStartParam->folderId(),
   950                     mStartParam->mailboxId(), mStartParam->folderId(),
   946                     mStartParam->messageId(), NmUiEditorReplyAll);
   951                     mStartParam->messageId(), NmUiEditorReplyAll);
   947                 mApplication.enterNmUiView(startParam);
   952                 mApplication.enterNmUiView(startParam);
   948             }
   953             }
   949             break;
   954             break;
   950             case NmActionResponseCommandForward: {
   955             case NmActionResponseCommandForward: {
       
   956                 mAttaManager.cancelFetch();
   951                 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageEditor,
   957                 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageEditor,
   952                     mStartParam->mailboxId(), mStartParam->folderId(),
   958                     mStartParam->mailboxId(), mStartParam->folderId(),
   953                     mStartParam->messageId(), NmUiEditorForward);
   959                     mStartParam->messageId(), NmUiEditorForward);
   954                 mApplication.enterNmUiView(startParam);
   960                 mApplication.enterNmUiView(startParam);
   955             }
   961             }
   956             break;
   962             break;
   957             case NmActionResponseCommandDeleteMail: {
   963             case NmActionResponseCommandDeleteMail: {
       
   964                 mAttaManager.cancelFetch();
   958                 deleteMessage();
   965                 deleteMessage();
   959                 }
   966                 }
   960             break;
   967             break;
   961             default:
   968             default:
   962                 break;
   969                 break;
   970 void NmViewerView::deleteMessage()
   977 void NmViewerView::deleteMessage()
   971 {
   978 {
   972     NM_FUNCTION;
   979     NM_FUNCTION;
   973     
   980     
   974     QList<NmId> messageList;
   981     QList<NmId> messageList;
   975     messageList.append(mStartParam->messageId());
   982     messageList.append(mStartParam->messageId());  
   976     
       
   977     int err = mUiEngine.deleteMessages(mStartParam->mailboxId(),
   983     int err = mUiEngine.deleteMessages(mStartParam->mailboxId(),
   978                                        mStartParam->folderId(),
   984                                        mStartParam->folderId(),
   979                                        messageList);
   985                                        messageList);
   980     
       
   981     messageList.clear();
   986     messageList.clear();
   982     if (NmNoError != err) {
       
   983         // Failed to delete the messages!
       
   984         NMLOG(QString("NmViewerView::handleActionCommand(): failed err=%1").arg(err));
       
   985     }
       
   986 }
   987 }
   987 
   988 
   988 
   989 
   989 /*!
   990 /*!
   990     This is called when attachment fetch progress changes
   991     This is called when attachment fetch progress changes
  1004 */
  1005 */
  1005 void NmViewerView::fetchCompleted(int result)
  1006 void NmViewerView::fetchCompleted(int result)
  1006 {
  1007 {
  1007     if (mAttaWidget && mAttaIndexUnderFetch != NmNotFoundError) {
  1008     if (mAttaWidget && mAttaIndexUnderFetch != NmNotFoundError) {
  1008         if (result == NmNoError) {
  1009         if (result == NmNoError) {
  1009             progressValueChanged(mAttaIndexUnderFetch, 100);
  1010             progressValueChanged(mAttaIndexUnderFetch, NmProgressValueComplete);
  1010             openAttachment(mAttaIndexUnderFetch);
  1011             openAttachment(mAttaIndexUnderFetch);
  1011         } else {
  1012         } else {
  1012             mAttaWidget->hideProgressBar(mAttaIndexUnderFetch);
  1013             mAttaWidget->hideProgressBar(mAttaIndexUnderFetch);
  1013         }
  1014         }
  1014     }
  1015     }
  1015     mAttaIndexUnderFetch = NmNotFoundError;
  1016     mAttaIndexUnderFetch = NmNotFoundError;
  1016 }
  1017 }
  1017 
  1018 
  1018 /*!
  1019 /*!
  1019     externalDelete. From NmMessageListModel, handles viewer shutdown when current message is deleted.
  1020     externalDelete. From NmUiEngine, handles viewer shutdown when current message is deleted.
  1020 */
  1021 */
  1021 void NmViewerView::messageDeleted(const NmId &mailboxId, const NmId &folderId, const NmId &messageId)
  1022 void NmViewerView::messageDeleted(const NmId &mailboxId, const NmId &folderId, const NmId &messageId)
  1022 {
  1023 {
  1023     if ((mStartParam->viewId() == NmUiViewMessageViewer)
  1024     if ((mStartParam->viewId() == NmUiViewMessageViewer)
  1024         && (mStartParam->mailboxId()== mailboxId)
  1025         && (mStartParam->mailboxId()== mailboxId)
  1045     connect(mWaitDialog, SIGNAL(cancelled()), this, SLOT(waitNoteCancelled()));
  1046     connect(mWaitDialog, SIGNAL(cancelled()), this, SLOT(waitNoteCancelled()));
  1046     mWaitDialog->setText(hbTrId("txt_mail_dialog_loading_mail_content"));
  1047     mWaitDialog->setText(hbTrId("txt_mail_dialog_loading_mail_content"));
  1047     // Display wait dialog
  1048     // Display wait dialog
  1048     mWaitDialog->show(); 
  1049     mWaitDialog->show(); 
  1049 }
  1050 }
  1050 
       
  1051 /*!
       
  1052     Helper function for width.
       
  1053 */
       
  1054 void NmViewerView::setWebViewWidth(int width)
       
  1055 {
       
  1056     // null pointer check for mWebView in calling function
       
  1057     mWebView->setMinimumWidth(width);
       
  1058     mWebView->setMaximumWidth(width);
       
  1059     mWebView->setPreferredWidth(width);
       
  1060 }
       
  1061 
       
  1062 /*!
       
  1063     Helper function for heigth.
       
  1064 */
       
  1065 void NmViewerView::setWebViewHeighth(int height)
       
  1066 {
       
  1067     // null pointer check for mWebView in calling function
       
  1068     mWebView->setMinimumHeight(height);
       
  1069     mWebView->setMaximumHeight(height);
       
  1070     mWebView->setPreferredHeight(height);
       
  1071 }