emailuis/nmailui/src/nmviewerview.cpp
changeset 44 c2d07d913565
parent 43 99bcbff212ad
child 47 f83bd4ae1fe3
child 54 997a02608b3a
equal deleted inserted replaced
43:99bcbff212ad 44:c2d07d913565
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8  *
     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:
    15 *
    15  *
    16 */
    16  */
    17 
    17 
    18 #include "nmuiheaders.h"
    18 #include "nmuiheaders.h"
    19 
    19 
    20 static const char *NMUI_MESSAGE_VIEWER_XML = ":/docml/nmmailviewer.docml";
    20 static const char *NMUI_MESSAGE_VIEWER_XML = ":/docml/nmmailviewer.docml";
    21 static const char *NMUI_MESSAGE_VIEWER_VIEW = "nmailViewerView";
    21 static const char *NMUI_MESSAGE_VIEWER_VIEW = "nmailViewerView";
    56 mMessage(NULL),
    56 mMessage(NULL),
    57 mScrollArea(NULL),
    57 mScrollArea(NULL),
    58 mViewerContent(NULL),
    58 mViewerContent(NULL),
    59 mWebView(NULL),
    59 mWebView(NULL),
    60 mHeaderWidget(NULL),
    60 mHeaderWidget(NULL),
    61 mViewerContentLayout(NULL),
       
    62 mMessageFetchingOperation(NULL),
    61 mMessageFetchingOperation(NULL),
    63 mDisplayingPlainText(false),
    62 mDisplayingPlainText(false),
    64 mDocumentLoader(NULL),
    63 mDocumentLoader(NULL),
    65 mScrollAreaContents(NULL),
    64 mScrollAreaContents(NULL),
    66 mViewerHeaderContainer(NULL),
    65 mViewerHeaderContainer(NULL),
    69 webFrameloadingCompleted(false),
    68 webFrameloadingCompleted(false),
    70 mLatestLoadingSize(QSize(0,0)),
    69 mLatestLoadingSize(QSize(0,0)),
    71 mAttaIndexUnderFetch(NmNotFoundError),
    70 mAttaIndexUnderFetch(NmNotFoundError),
    72 mAttaWidget(NULL),
    71 mAttaWidget(NULL),
    73 mViewReady(false),
    72 mViewReady(false),
    74 mWaitNoteCancelled(false)
    73 mWaitNoteCancelled(false),
       
    74 mErrorNote(NULL)
    75     {
    75     {
    76     NM_FUNCTION;
       
    77     
       
    78     // Create documentloader
    76     // Create documentloader
    79     mDocumentLoader = new NmUiDocumentLoader(mMainWindow);
    77     mDocumentLoader = new NmUiDocumentLoader(mMainWindow);
    80     // Get screensize
    78     // Get screensize
    81     mScreenSize = mApplication.screenSize();
    79     mScreenSize = mApplication.screenSize();
    82     // Connect external delete handling to uiengine signal
    80     // Connect external delete handling to uiengine signal
    93 /*!
    91 /*!
    94     Destructor
    92     Destructor
    95 */
    93 */
    96 NmViewerView::~NmViewerView()
    94 NmViewerView::~NmViewerView()
    97 {
    95 {
    98     NM_FUNCTION;
    96     delete mErrorNote;
    99     
    97     mErrorNote=NULL;
   100     delete mWebView;
    98     delete mWebView;
   101     mWebView = NULL;
    99     mWebView = NULL;
   102     delete mMessage;
   100     delete mMessage;
   103     mMessage = NULL;
   101     mMessage = NULL;
   104     delete mDocumentLoader;
   102     delete mDocumentLoader;
   114 /*!
   112 /*!
   115     View is about to exit
   113     View is about to exit
   116 */
   114 */
   117 void NmViewerView::aboutToExitView()
   115 void NmViewerView::aboutToExitView()
   118 {
   116 {
   119     NM_FUNCTION;
       
   120     
       
   121     // View is about to exit, for safety, stop 
   117     // View is about to exit, for safety, stop 
   122     // loading of content before closing the view
   118     // loading of content before closing the view
   123     if (mWebView){
   119     if (mWebView){
   124         mWebView->stop();
   120         mWebView->stop();
   125         if (mWebView->page()){
   121         if (mWebView->page()){
   151         // Create content and content layout
   147         // Create content and content layout
   152         // qobject_cast not work in this case, using reinterpret_cast
   148         // qobject_cast not work in this case, using reinterpret_cast
   153         mViewerContent = reinterpret_cast<HbWidget *>(
   149         mViewerContent = reinterpret_cast<HbWidget *>(
   154                 mDocumentLoader->findObject(NMUI_MESSAGE_VIEWER_CONTENT));
   150                 mDocumentLoader->findObject(NMUI_MESSAGE_VIEWER_CONTENT));
   155         // Find scroll area
   151         // Find scroll area
   156         mScrollArea = reinterpret_cast<NmBaseViewScrollArea *>(
   152         mScrollArea = reinterpret_cast<HbScrollArea *>(
   157                 mDocumentLoader->findObject(NMUI_MESSAGE_VIEWER_SCROLL_AREA));
   153                 mDocumentLoader->findObject(NMUI_MESSAGE_VIEWER_SCROLL_AREA));
   158         if (mScrollArea) {
   154         if (mScrollArea) {
   159             mScrollArea->setParentItem(this);
   155             mScrollArea->setParentItem(this);
   160             mScrollArea->setScrollDirections(Qt::Vertical | Qt::Horizontal);
   156             mScrollArea->setScrollDirections(Qt::Vertical | Qt::Horizontal);
   161             connect(mScrollArea, SIGNAL(scrollPositionChanged(QPointF)),
   157             connect(mScrollArea, SIGNAL(scrollPositionChanged(QPointF)),
   162                 this, SLOT(contentScrollPositionChanged(QPointF)));
   158                 this, SLOT(contentScrollPositionChanged(QPointF)));
   163             connect(mScrollArea, SIGNAL(handleMousePressEvent(QGraphicsSceneMouseEvent*)),
       
   164                 this, SLOT(handleMousePressEvent(QGraphicsSceneMouseEvent*)));
       
   165             connect(mScrollArea, SIGNAL(handleMouseReleaseEvent(QGraphicsSceneMouseEvent*)),
       
   166                 this, SLOT(handleMouseReleaseEvent(QGraphicsSceneMouseEvent*)));
       
   167 
   159 
   168             // Get scroll area contents and set layout margins
   160             // Get scroll area contents and set layout margins
   169             mScrollAreaContents = qobject_cast<HbWidget *>(
   161             mScrollAreaContents = qobject_cast<HbWidget *>(
   170                     mDocumentLoader->findObject(NMUI_MESSAGE_VIEWER_SCROLL_AREA_CONTENTS));
   162                     mDocumentLoader->findObject(NMUI_MESSAGE_VIEWER_SCROLL_AREA_CONTENTS));
   171             if (mScrollAreaContents) {
   163             if (mScrollAreaContents) {
   198                 // Set auto load images and private browsing(no history) attributes
   190                 // Set auto load images and private browsing(no history) attributes
   199                 QWebSettings *settings = mWebView->settings();
   191                 QWebSettings *settings = mWebView->settings();
   200                 if (settings) {
   192                 if (settings) {
   201                     settings->setAttribute(QWebSettings::AutoLoadImages, true);
   193                     settings->setAttribute(QWebSettings::AutoLoadImages, true);
   202                     settings->setAttribute(QWebSettings::PrivateBrowsingEnabled, true);   
   194                     settings->setAttribute(QWebSettings::PrivateBrowsingEnabled, true);   
   203                 }                             
   195                 }
   204                 HbEditorInterface editorInterface(mWebView);
       
   205                 editorInterface.setInputConstraints(HbEditorConstraintIgnoreFocus);
       
   206                 mWebView->setAcceptedMouseButtons(Qt::NoButton);
       
   207                 QWebPage *page = mWebView->page();
   196                 QWebPage *page = mWebView->page();
   208                 if (page) {
   197                 if (page) {
   209                     QWebFrame *frame = page->mainFrame();
   198                     QWebFrame *frame = page->mainFrame();
   210                     if (frame) {
   199                     if (frame) {
   211                         frame->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOff);
   200                         frame->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOff);
   223 /*!
   212 /*!
   224     Lazy loading when view layout has been loaded
   213     Lazy loading when view layout has been loaded
   225 */
   214 */
   226 void NmViewerView::viewReady()
   215 void NmViewerView::viewReady()
   227 {
   216 {
   228     NM_FUNCTION;
       
   229     
       
   230     if (!mViewReady){
   217     if (!mViewReady){
   231         // Set mailbox name to title
   218         // Set mailbox name to title
   232         setMailboxName();
   219         setMailboxName();
   233         // Create toolbar if needed
   220         // Create toolbar if needed
   234         if (mToolbarEnabled) {
   221         if (mToolbarEnabled) {
   321 /*!
   308 /*!
   322     This is signalled by mMessageFetchingOperation when the original message is fetched.
   309     This is signalled by mMessageFetchingOperation when the original message is fetched.
   323  */
   310  */
   324 void NmViewerView::messageFetched(int result)
   311 void NmViewerView::messageFetched(int result)
   325 {
   312 {
   326     NM_FUNCTION;
       
   327     
       
   328     mWaitDialog->close();
   313     mWaitDialog->close();
   329 
   314     disconnect(mWaitDialog->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
       
   315                 this, SLOT(orientationChanged(Qt::Orientation)));
       
   316     
   330     if (result == NmNoError && mMessageFetchingOperation) {
   317     if (result == NmNoError && mMessageFetchingOperation) {
   331         if (mMessage) {
   318         if (mMessage) {
   332             delete mMessage;
   319             delete mMessage;
   333             mMessage = NULL;
   320             mMessage = NULL;
   334         }
   321         }
   351 /*!
   338 /*!
   352     This is signalled by mWaitDialog when the note is cancelled
   339     This is signalled by mWaitDialog when the note is cancelled
   353  */
   340  */
   354 void NmViewerView::waitNoteCancelled()
   341 void NmViewerView::waitNoteCancelled()
   355 {
   342 {
   356     NM_FUNCTION;
       
   357     
       
   358     if (!mWaitNoteCancelled) {
   343     if (!mWaitNoteCancelled) {
   359         if (mMessageFetchingOperation && mMessageFetchingOperation->isRunning()) { 
   344         if (mMessageFetchingOperation && mMessageFetchingOperation->isRunning()) { 
   360 	        mMessageFetchingOperation->cancelOperation();
   345 	        mMessageFetchingOperation->cancelOperation();
   361         }
   346         }
   362         mWaitNoteCancelled = true;
   347         mWaitNoteCancelled = true;
   384     if (page){
   369     if (page){
   385         // Set custom network access manager for embedded image handling
   370         // Set custom network access manager for embedded image handling
   386         NmViewerViewNetManager &netMngr = mApplication.networkAccessManager();
   371         NmViewerViewNetManager &netMngr = mApplication.networkAccessManager();
   387         netMngr.setView(this);
   372         netMngr.setView(this);
   388         page->setNetworkAccessManager(&netMngr);
   373         page->setNetworkAccessManager(&netMngr);
       
   374         QWebSettings *webSettings = page->settings();
       
   375         if (webSettings) {
       
   376             webSettings->setObjectCacheCapacities(0,0,0);
       
   377         }
   389 
   378 
   390         connect(page, SIGNAL(loadFinished(bool)),
   379         connect(page, SIGNAL(loadFinished(bool)),
   391                     this, SLOT(webFrameLoaded(bool)));
   380                     this, SLOT(webFrameLoaded(bool)));
   392         page->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
   381         page->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
   393         page->setContentEditable(false);
   382         page->setContentEditable(false);
   492         }
   481         }
   493         // attachment is fetched, open file
   482         // attachment is fetched, open file
   494         else if (messageParts[i]->partId() == attaId) {
   483         else if (messageParts[i]->partId() == attaId) {
   495             XQSharableFile file = mUiEngine.messagePartFile(mailboxId, folderId,
   484             XQSharableFile file = mUiEngine.messagePartFile(mailboxId, folderId,
   496                                                             messageId, attaId);
   485                                                             messageId, attaId);
   497             NmUtilities::openFile(file);
   486             int error = NmUtilities::openFile(file);
   498             file.close();
   487             file.close();
       
   488             if (error==NmNotFoundError){
       
   489                 delete mErrorNote;
       
   490                 mErrorNote=NULL;
       
   491                 mErrorNote = NmUtilities::displayWarningNote(hbTrId("txt_mail_dialog_unable_to_open_attachment_file_ty"));
       
   492             }
   499         }
   493         }
   500     }
   494     }
   501 }
   495 }
   502 
   496 
   503 /*!
   497 /*!
   590     Typically when view is already open and external view activation occurs
   584     Typically when view is already open and external view activation occurs
   591     for this same view
   585     for this same view
   592 */
   586 */
   593 void NmViewerView::reloadViewContents(NmUiStartParam* startParam)
   587 void NmViewerView::reloadViewContents(NmUiStartParam* startParam)
   594 {
   588 {
   595     NM_FUNCTION;
       
   596     
       
   597     // Check start parameter validity, message view cannot
   589     // Check start parameter validity, message view cannot
   598     // be updated if given parameter is zero.
   590     // be updated if given parameter is zero.
   599     if (startParam && startParam->viewId() == NmUiViewMessageViewer &&
   591     if (startParam && startParam->viewId() == NmUiViewMessageViewer &&
   600         startParam->messageId()!= 0) {
   592         startParam->messageId()!= 0) {
   601         // Delete existing start parameter data
   593         // Delete existing start parameter data
   616 /*!
   608 /*!
   617     nmailViewId
   609     nmailViewId
   618 */
   610 */
   619 NmUiViewId NmViewerView::nmailViewId() const
   611 NmUiViewId NmViewerView::nmailViewId() const
   620 {
   612 {
   621     NM_FUNCTION;
       
   622     
       
   623     return NmUiViewMessageViewer;
   613     return NmUiViewMessageViewer;
   624 }
   614 }
   625 
   615 
   626 /*!
   616 /*!
   627     Scale web view width
   617     Scale web view width
   628 */
   618 */
   629 void NmViewerView::webFrameLoaded(bool loaded)
   619 void NmViewerView::webFrameLoaded(bool loaded)
   630 {
   620 {
   631     NM_FUNCTION;
       
   632     
       
   633     if (loaded){
   621     if (loaded){
   634         webFrameloadingCompleted = true;
   622         webFrameloadingCompleted = true;
   635         // Scale web view after loading the
   623         // Scale web view after loading the
   636         // complete contents, including images
   624         // complete contents, including images
   637         QMetaObject::invokeMethod(this, "scaleWebViewWhenLoaded", Qt::QueuedConnection);       
   625         QMetaObject::invokeMethod(this, "scaleWebViewWhenLoaded", Qt::QueuedConnection);       
   641 /*!
   629 /*!
   642     Scale web view width when loading is ongoing
   630     Scale web view width when loading is ongoing
   643 */
   631 */
   644 void NmViewerView::scaleWebViewWhenLoading(const QSize &size)
   632 void NmViewerView::scaleWebViewWhenLoading(const QSize &size)
   645 {
   633 {
   646     NM_FUNCTION;
       
   647     
       
   648     // Try to scale web view while mainframe is being loaded.
   634     // Try to scale web view while mainframe is being loaded.
   649     // So that screen is scrollable even before images are fully loaded
   635     // So that screen is scrollable even before images are fully loaded
   650     // First check that new size is different than previous, no need to react if
   636     // First check that new size is different than previous, no need to react if
   651     // same size value is received more than once.
   637     // same size value is received more than once.
   652     if (size != mLatestLoadingSize) {
   638     if (size != mLatestLoadingSize) {
   671 /*!
   657 /*!
   672     Scale web view width when loading is completed
   658     Scale web view width when loading is completed
   673 */
   659 */
   674 void NmViewerView::scaleWebViewWhenLoaded()
   660 void NmViewerView::scaleWebViewWhenLoaded()
   675 {
   661 {
   676     NM_FUNCTION;
       
   677     
       
   678     if (mWebView&&mWebView->page()) {
   662     if (mWebView&&mWebView->page()) {
   679         QSizeF contentSize = mWebView->page()->mainFrame()->contentsSize();
   663         QSizeF contentSize = mWebView->page()->mainFrame()->contentsSize();
   680         int width = (int)contentSize.width();
   664         int width = (int)contentSize.width();
   681         int height = (int)contentSize.height();
   665         int height = (int)contentSize.height();
   682         // Set content (webview) width
   666         // Set content (webview) width
   705 /*!
   689 /*!
   706     Set new dimensions after orientation change.
   690     Set new dimensions after orientation change.
   707 */
   691 */
   708 void NmViewerView::adjustViewDimensions()
   692 void NmViewerView::adjustViewDimensions()
   709 {
   693 {
   710     NM_FUNCTION;
       
   711     
       
   712     // Update current screensize
   694     // Update current screensize
   713     mScreenSize = mApplication.screenSize();
   695     mScreenSize = mApplication.screenSize();
   714     // Scale header to screen width
   696     // Scale header to screen width
   715     if (mHeaderWidget){
   697     if (mHeaderWidget){
   716         mHeaderWidget->rescaleHeader(mScreenSize);
   698         mHeaderWidget->rescaleHeader(mScreenSize);
   757    landscape <-> portrait switch occurs because text needs to
   739    landscape <-> portrait switch occurs because text needs to
   758    be wrapped again.
   740    be wrapped again.
   759 */
   741 */
   760 void NmViewerView::orientationChanged(Qt::Orientation orientation)
   742 void NmViewerView::orientationChanged(Qt::Orientation orientation)
   761 {
   743 {
   762     NM_FUNCTION;
       
   763     
       
   764     Q_UNUSED(orientation);
   744     Q_UNUSED(orientation);
   765     QTimer::singleShot(NmOrientationTimer, this, SLOT(adjustViewDimensions()));
   745     QTimer::singleShot(NmOrientationTimer, this, SLOT(adjustViewDimensions()));
   766 }
   746 }
   767 
   747 
   768 /*!
   748 /*!
   792           mApplication.enterNmUiView(param);
   772           mApplication.enterNmUiView(param);
   793       }
   773       }
   794 }
   774 }
   795 
   775 
   796 /*!
   776 /*!
   797    Send mouse release event to web view
       
   798 */
       
   799 void NmViewerView::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
       
   800 {
       
   801     NM_FUNCTION;
       
   802     handleMouseEvent(event, false);
       
   803 
       
   804 }
       
   805 
       
   806 /*!
       
   807    Send mouse press event
       
   808 */
       
   809 void NmViewerView::handleMousePressEvent(QGraphicsSceneMouseEvent *event)
       
   810 {
       
   811     NM_FUNCTION;
       
   812     handleMouseEvent(event, true);
       
   813 }
       
   814 
       
   815 /*!
       
   816    Function can be used to check whether mouse event has
   777    Function can be used to check whether mouse event has
   817    occured on top of header area.
   778    occured on top of header area.
   818 */
   779 */
   819 bool NmViewerView::eventOnTopOfHeaderArea(QGraphicsSceneMouseEvent *event)
   780 bool NmViewerView::eventOnTopOfHeaderArea(QGraphicsSceneMouseEvent *event)
   820 {
   781 {
   821     NM_FUNCTION;
       
   822     
       
   823     bool ret(false);
   782     bool ret(false);
   824     if (event && mHeaderWidget) {
   783     if (event && mHeaderWidget) {
   825         QPointF lastReleasePoint = event->lastPos();
   784         QPointF lastReleasePoint = event->lastPos();
   826         QPointF contentWidgetPos = mScrollAreaContents->pos();
   785         QPointF contentWidgetPos = mScrollAreaContents->pos();
   827         int headerHeight = (int)mHeaderWidget->geometry().height();
   786         int headerHeight = (int)mHeaderWidget->geometry().height();
   835 /*!
   794 /*!
   836    get function for content widget web view.
   795    get function for content widget web view.
   837 */
   796 */
   838 NmMailViewerWK* NmViewerView::webView()
   797 NmMailViewerWK* NmViewerView::webView()
   839 {
   798 {
   840     NM_FUNCTION;
       
   841     
       
   842     return mWebView;
   799     return mWebView;
   843 }
   800 }
   844 
   801 
   845 /*!
   802 /*!
   846 
   803 
   887 /*!
   844 /*!
   888     Set mailbox name to title
   845     Set mailbox name to title
   889 */
   846 */
   890 void NmViewerView::setMailboxName()
   847 void NmViewerView::setMailboxName()
   891 {
   848 {
   892     NM_FUNCTION;
       
   893     
       
   894     if (mStartParam){
   849     if (mStartParam){
   895         NmMailboxMetaData *meta = mUiEngine.mailboxById(mStartParam->mailboxId());
   850         NmMailboxMetaData *meta = mUiEngine.mailboxById(mStartParam->mailboxId());
   896         if (meta) {
   851         if (meta) {
   897             setTitle(meta->name());
   852             setTitle(meta->name());
   898         }
   853         }
   904     Function reacts to scroll position change events and sets
   859     Function reacts to scroll position change events and sets
   905     header to correct position
   860     header to correct position
   906 */
   861 */
   907 void NmViewerView::contentScrollPositionChanged(const QPointF &newPosition)
   862 void NmViewerView::contentScrollPositionChanged(const QPointF &newPosition)
   908 {
   863 {
   909     NM_FUNCTION;
       
   910     
       
   911     if (mWebView&&mHeaderWidget){
   864     if (mWebView&&mHeaderWidget){
   912         QRectF webViewRect = mWebView->geometry();
   865         QRectF webViewRect = mWebView->geometry();
   913         QTransform tr;
   866         QTransform tr;
   914         qreal leftMovementThreshold(webViewRect.width()-mHeaderWidget->geometry().width());
   867         qreal leftMovementThreshold(webViewRect.width()-mHeaderWidget->geometry().width());
   915         if (newPosition.x()<0) {
   868         if (newPosition.x()<0) {
   933     createToolBar. Function asks menu commands from extension
   886     createToolBar. Function asks menu commands from extension
   934     to be added to toolbar owned by the HbView.
   887     to be added to toolbar owned by the HbView.
   935 */
   888 */
   936 void NmViewerView::createToolBar()
   889 void NmViewerView::createToolBar()
   937 {
   890 {
   938     NM_FUNCTION;
       
   939     
       
   940     HbToolBar *tb = toolBar();
   891     HbToolBar *tb = toolBar();
   941     NmUiExtensionManager &extMngr = mApplication.extManager();
   892     NmUiExtensionManager &extMngr = mApplication.extManager();
   942     if (tb && &extMngr && mStartParam) {
   893     if (tb && &extMngr && mStartParam) {
   943         tb->clearActions();
   894         tb->clearActions();
   944         NmActionRequest request(this, NmActionToolbar, NmActionContextViewViewer,
   895         NmActionRequest request(this, NmActionToolbar, NmActionContextViewViewer,
   955     createOptionsMenu. Functions asks menu commands from extension
   906     createOptionsMenu. Functions asks menu commands from extension
   956     to be added to options menu.
   907     to be added to options menu.
   957 */
   908 */
   958 void NmViewerView::createOptionsMenu()
   909 void NmViewerView::createOptionsMenu()
   959 {
   910 {
   960     NM_FUNCTION;
       
   961     
       
   962 	HbMenu *optionsMenu = menu();
   911 	HbMenu *optionsMenu = menu();
   963 	NmUiExtensionManager &extMngr = mApplication.extManager();
   912 	NmUiExtensionManager &extMngr = mApplication.extManager();
   964 	if (optionsMenu && &extMngr && mStartParam) {
   913 	if (optionsMenu && &extMngr && mStartParam) {
   965 		optionsMenu->clearActions();
   914 		optionsMenu->clearActions();
   966 		NmActionRequest request(this, NmActionOptionsMenu, NmActionContextViewViewer,
   915 		NmActionRequest request(this, NmActionOptionsMenu, NmActionContextViewViewer,
   978     handleActionCommand. From NmActionObserver, extension manager calls this
   927     handleActionCommand. From NmActionObserver, extension manager calls this
   979     call to handle menu command in the UI.
   928     call to handle menu command in the UI.
   980 */
   929 */
   981 void NmViewerView::handleActionCommand(NmActionResponse &actionResponse)
   930 void NmViewerView::handleActionCommand(NmActionResponse &actionResponse)
   982 {
   931 {
   983     NM_FUNCTION;
       
   984     
       
   985     bool showSendInProgressNote = false;
       
   986 
       
   987     // Handle options menu or toolbar
   932     // Handle options menu or toolbar
   988     if (actionResponse.menuType() == NmActionOptionsMenu ||
   933     if (actionResponse.menuType() == NmActionOptionsMenu ||
   989     	actionResponse.menuType() == NmActionToolbar) {
   934     	actionResponse.menuType() == NmActionToolbar) {
   990         switch (actionResponse.responseCommand()) {
   935         switch (actionResponse.responseCommand()) {
   991             case NmActionResponseCommandReply: {
   936             case NmActionResponseCommandReply: {
   992                 if (mUiEngine.isSendingMessage()) {
       
   993                     showSendInProgressNote = true;
       
   994                     break;
       
   995                 }
       
   996                 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageEditor,
   937                 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageEditor,
   997                     mStartParam->mailboxId(), mStartParam->folderId(),
   938                     mStartParam->mailboxId(), mStartParam->folderId(),
   998                     mStartParam->messageId(), NmUiEditorReply);
   939                     mStartParam->messageId(), NmUiEditorReply);
   999                 mApplication.enterNmUiView(startParam);
   940                 mApplication.enterNmUiView(startParam);
  1000             }
   941             }
  1001             break;
   942             break;
  1002             case NmActionResponseCommandReplyAll: {
   943             case NmActionResponseCommandReplyAll: {
  1003                 if (mUiEngine.isSendingMessage()) {
       
  1004                     showSendInProgressNote = true;
       
  1005                     break;
       
  1006                 }
       
  1007                 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageEditor,
   944                 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageEditor,
  1008                     mStartParam->mailboxId(), mStartParam->folderId(),
   945                     mStartParam->mailboxId(), mStartParam->folderId(),
  1009                     mStartParam->messageId(), NmUiEditorReplyAll);
   946                     mStartParam->messageId(), NmUiEditorReplyAll);
  1010                 mApplication.enterNmUiView(startParam);
   947                 mApplication.enterNmUiView(startParam);
  1011             }
   948             }
  1012             break;
   949             break;
  1013             case NmActionResponseCommandForward: {
   950             case NmActionResponseCommandForward: {
  1014                 if (mUiEngine.isSendingMessage()) {
       
  1015                     showSendInProgressNote = true;
       
  1016                     break;
       
  1017                 }
       
  1018                 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageEditor,
   951                 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageEditor,
  1019                     mStartParam->mailboxId(), mStartParam->folderId(),
   952                     mStartParam->mailboxId(), mStartParam->folderId(),
  1020                     mStartParam->messageId(), NmUiEditorForward);
   953                     mStartParam->messageId(), NmUiEditorForward);
  1021                 mApplication.enterNmUiView(startParam);
   954                 mApplication.enterNmUiView(startParam);
  1022             }
   955             }
  1027             break;
   960             break;
  1028             default:
   961             default:
  1029                 break;
   962                 break;
  1030         }
   963         }
  1031     }
   964     }
  1032 
       
  1033     if (showSendInProgressNote) {
       
  1034         QString noteText = hbTrId("txt_mail_dialog_still_sending");
       
  1035 
       
  1036         // get message subject from the message being sent
       
  1037         const NmMessage *message = mUiEngine.messageBeingSent();
       
  1038         if (message) {
       
  1039             noteText = noteText.arg(NmUtilities::truncate(message->envelope().subject(), 20));
       
  1040         }
       
  1041         HbMessageBox::warning(noteText);
       
  1042     }
       
  1043 }
   965 }
  1044 
   966 
  1045 /*!
   967 /*!
  1046     Deletes the currently open message
   968     Deletes the currently open message
  1047 */
   969 */
  1067 /*!
   989 /*!
  1068     This is called when attachment fetch progress changes
   990     This is called when attachment fetch progress changes
  1069 */
   991 */
  1070 void NmViewerView::progressChanged(int value)
   992 void NmViewerView::progressChanged(int value)
  1071 {
   993 {
  1072     NM_FUNCTION;
       
  1073     
       
  1074     if (mAttaIndexUnderFetch != NmNotFoundError) {
   994     if (mAttaIndexUnderFetch != NmNotFoundError) {
  1075         // emit signal
   995         // emit signal
  1076         if (mAttaWidget && mAttaWidget->progressValue(mAttaIndexUnderFetch) < value) {
   996         if (mAttaWidget && mAttaWidget->progressValue(mAttaIndexUnderFetch) < value) {
  1077             progressValueChanged(mAttaIndexUnderFetch, value);
   997             progressValueChanged(mAttaIndexUnderFetch, value);
  1078         }
   998         }
  1082 /*!
  1002 /*!
  1083     This is called when attachment fetch is completed
  1003     This is called when attachment fetch is completed
  1084 */
  1004 */
  1085 void NmViewerView::fetchCompleted(int result)
  1005 void NmViewerView::fetchCompleted(int result)
  1086 {
  1006 {
  1087     NM_FUNCTION;
       
  1088     
       
  1089     if (mAttaWidget && mAttaIndexUnderFetch != NmNotFoundError) {
  1007     if (mAttaWidget && mAttaIndexUnderFetch != NmNotFoundError) {
  1090         if (result == NmNoError) {
  1008         if (result == NmNoError) {
  1091             progressValueChanged(mAttaIndexUnderFetch, 100);
  1009             progressValueChanged(mAttaIndexUnderFetch, 100);
  1092             openAttachment(mAttaIndexUnderFetch);
  1010             openAttachment(mAttaIndexUnderFetch);
  1093         } else {
  1011         } else {
  1100 /*!
  1018 /*!
  1101     externalDelete. From NmMessageListModel, handles viewer shutdown when current message is deleted.
  1019     externalDelete. From NmMessageListModel, handles viewer shutdown when current message is deleted.
  1102 */
  1020 */
  1103 void NmViewerView::messageDeleted(const NmId &mailboxId, const NmId &folderId, const NmId &messageId)
  1021 void NmViewerView::messageDeleted(const NmId &mailboxId, const NmId &folderId, const NmId &messageId)
  1104 {
  1022 {
  1105     NM_FUNCTION;
       
  1106     
       
  1107     if ((mStartParam->viewId() == NmUiViewMessageViewer)
  1023     if ((mStartParam->viewId() == NmUiViewMessageViewer)
  1108         && (mStartParam->mailboxId()== mailboxId)
  1024         && (mStartParam->mailboxId()== mailboxId)
  1109         && (mStartParam->folderId()== folderId)
  1025         && (mStartParam->folderId()== folderId)
  1110         && (mStartParam->messageId()== messageId)) {
  1026         && (mStartParam->messageId()== messageId)) {
  1111         mApplication.prepareForPopView();
  1027         mApplication.prepareForPopView();
  1115 /*!
  1031 /*!
  1116     Helper function for wait dialog creation.
  1032     Helper function for wait dialog creation.
  1117 */
  1033 */
  1118 void NmViewerView::createAndShowWaitDialog()
  1034 void NmViewerView::createAndShowWaitDialog()
  1119 {
  1035 {
  1120     NM_FUNCTION;
       
  1121     
       
  1122     delete mWaitDialog;
  1036     delete mWaitDialog;
  1123     mWaitDialog = NULL;
  1037     mWaitDialog = NULL;
  1124     // Create new wait dialog and set it to me modal with dimmed background
  1038     // Create new wait dialog and set it to me modal with dimmed background
  1125     mWaitDialog = new HbProgressDialog(HbProgressDialog::WaitDialog);
  1039     mWaitDialog = new HbProgressDialog(HbProgressDialog::WaitDialog);
       
  1040     // Connect to observe orientation change events
       
  1041     connect(mWaitDialog->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
       
  1042                 this, SLOT(orientationChanged(Qt::Orientation)));
  1126     mWaitDialog->setModal(true);
  1043     mWaitDialog->setModal(true);
  1127     mWaitDialog->setBackgroundFaded(true);
  1044     mWaitDialog->setBackgroundFaded(true);
  1128     connect(mWaitDialog, SIGNAL(cancelled()), this, SLOT(waitNoteCancelled()));
  1045     connect(mWaitDialog, SIGNAL(cancelled()), this, SLOT(waitNoteCancelled()));
  1129     mWaitDialog->setText(hbTrId("txt_mail_dialog_loading_mail_content"));
  1046     mWaitDialog->setText(hbTrId("txt_mail_dialog_loading_mail_content"));
  1130     // Display wait dialog
  1047     // Display wait dialog
  1134 /*!
  1051 /*!
  1135     Helper function for width.
  1052     Helper function for width.
  1136 */
  1053 */
  1137 void NmViewerView::setWebViewWidth(int width)
  1054 void NmViewerView::setWebViewWidth(int width)
  1138 {
  1055 {
  1139     NM_FUNCTION;
       
  1140     
       
  1141     // null pointer check for mWebView in calling function
  1056     // null pointer check for mWebView in calling function
  1142     mWebView->setMinimumWidth(width);
  1057     mWebView->setMinimumWidth(width);
  1143     mWebView->setMaximumWidth(width);
  1058     mWebView->setMaximumWidth(width);
  1144     mWebView->setPreferredWidth(width);
  1059     mWebView->setPreferredWidth(width);
  1145 }
  1060 }
  1147 /*!
  1062 /*!
  1148     Helper function for heigth.
  1063     Helper function for heigth.
  1149 */
  1064 */
  1150 void NmViewerView::setWebViewHeighth(int height)
  1065 void NmViewerView::setWebViewHeighth(int height)
  1151 {
  1066 {
  1152     NM_FUNCTION;
       
  1153     
       
  1154     // null pointer check for mWebView in calling function
  1067     // null pointer check for mWebView in calling function
  1155     mWebView->setMinimumHeight(height);
  1068     mWebView->setMinimumHeight(height);
  1156     mWebView->setMaximumHeight(height);
  1069     mWebView->setMaximumHeight(height);
  1157     mWebView->setPreferredHeight(height);
  1070     mWebView->setPreferredHeight(height);
  1158 }
  1071 }
  1159 
       
  1160 /*!
       
  1161     Helper function for mouse events.
       
  1162 */
       
  1163 void NmViewerView::handleMouseEvent(QGraphicsSceneMouseEvent *event, bool pressed)
       
  1164 {
       
  1165     NM_FUNCTION;
       
  1166     NmMailViewerWK* view = webView();
       
  1167     if (event && view && mHeaderWidget && mScrollAreaContents) {
       
  1168         QPointF lastReleasePoint = event->pos();
       
  1169         QPointF contentWidgetPos = mScrollAreaContents->pos();
       
  1170         qreal headerHeight = mHeaderWidget->geometry().height();
       
  1171         qreal y = lastReleasePoint.y()-headerHeight;
       
  1172         y -= contentWidgetPos.y();
       
  1173         qreal x = lastReleasePoint.x()-contentWidgetPos.x();
       
  1174         const QPointF pointToWebView(x, y);
       
  1175         event->setPos(pointToWebView);
       
  1176         event->setAccepted(true);
       
  1177         if (pressed) {
       
  1178             view->sendMousePressEvent(event);
       
  1179         } else {
       
  1180             view->sendMouseReleaseEvent(event);
       
  1181         }
       
  1182     }
       
  1183 }