emailuis/nmailui/src/nmapplication.cpp
changeset 57 ae34e1715e21
parent 56 15bc1d5d6267
child 62 a8c646b56683
equal deleted inserted replaced
56:15bc1d5d6267 57:ae34e1715e21
    19 #include <email_services_api.h>
    19 #include <email_services_api.h>
    20 #include <e32base.h>
    20 #include <e32base.h>
    21 
    21 
    22 static const QString NmSendServiceName = "nmail.com.nokia.symbian.IFileShare";
    22 static const QString NmSendServiceName = "nmail.com.nokia.symbian.IFileShare";
    23 
    23 
    24 // Delay before a screenshot is taken after view activation so that view has time to draw itself,
       
    25 // testing seems to indicate 500ms to be a good value
       
    26 static const int NmActivityUpdateDelayMs = 500;
       
    27 
       
    28 static const QString NmActivityName = "EmailInboxView";
    24 static const QString NmActivityName = "EmailInboxView";
    29 
    25 
    30 /*!
    26 /*!
    31     \class NmApplication
    27     \class NmApplication
    32     \brief Application class, creates main window and handles view switching.
    28     \brief Application class, creates main window and handles view switching.
    33 */
    29 */
    34 
    30 
       
    31 
    35 /*!
    32 /*!
    36     Constructor.
    33     Constructor.
    37 */
    34 */
    38 NmApplication::NmApplication(QObject *parent, quint32 accountId)
    35 NmApplication::NmApplication(QObject *parent, quint64 accountId)
    39 : QObject(parent),
    36 : QObject(parent),
    40   mMainWindow(NULL),
    37   mMainWindow(NULL),
    41   mViewStack(NULL),
    38   mViewStack(NULL),
    42   mActiveViewId(NmUiViewNone),
    39   mActiveViewId(NmUiViewNone),
    43   mUiEngine(NULL),
    40   mUiEngine(NULL),
    49   mEffects(NULL),
    46   mEffects(NULL),
    50   mAttaManager(NULL),
    47   mAttaManager(NULL),
    51   mSettingsViewLauncher(NULL),
    48   mSettingsViewLauncher(NULL),
    52   mViewReady(false),
    49   mViewReady(false),
    53   mQueryDialog(NULL),
    50   mQueryDialog(NULL),
    54   mBackButtonPressed(false),
    51   mBackButtonPressed(false)
    55   mActivityUpdateNeeded(false)
       
    56 {
    52 {
    57     TRAP_IGNORE(mUiEngine = NmUiEngine::instance());
    53     TRAP_IGNORE(mUiEngine = NmUiEngine::instance());
    58     
    54     
    59     // Create network access manager and cache for application use.
    55     // Create network access manager and cache for application use.
    60     mNetManager = new NmViewerViewNetManager(*mUiEngine);
    56     mNetManager = new NmViewerViewNetManager(*mUiEngine);
    80     mViewerServiceInterface =
    76     mViewerServiceInterface =
    81         new NmViewerServiceInterface(NULL, this, *mUiEngine);
    77         new NmViewerServiceInterface(NULL, this, *mUiEngine);
    82     
    78     
    83     if(accountId != 0) {
    79     if(accountId != 0) {
    84         QVariant mailbox;
    80         QVariant mailbox;
    85         mailbox.setValue(mUiEngine->getPluginIdByMailboxId(accountId).id());
    81         mailbox.setValue(accountId);
    86         mMailboxServiceInterface->displayInboxByMailboxId(mailbox);
    82         mMailboxServiceInterface->displayInboxByMailboxId(mailbox);
    87     }
    83     }
    88     
    84     
    89     mEffects = new NmUiEffects(*mMainWindow);
    85     mEffects = new NmUiEffects(*mMainWindow);
    90 }
    86     
       
    87     QObject::connect(parent, SIGNAL(activate()), this, SLOT(activityActivated()));
       
    88 }
       
    89 
    91 
    90 
    92 /*!
    91 /*!
    93     Destructor.
    92     Destructor.
    94 */
    93 */
    95 NmApplication::~NmApplication()
    94 NmApplication::~NmApplication()
    96 {
    95 {
       
    96     // Remove the event filter early since catching application activated/
       
    97     // deactivated events now may cause a crash.
       
    98     QCoreApplication::instance()->removeEventFilter(this);
       
    99 
    97     if (mQueryDialog) {
   100     if (mQueryDialog) {
    98         delete mQueryDialog;
   101         delete mQueryDialog;
    99         mQueryDialog = NULL;
   102         mQueryDialog = NULL;
   100     }
   103     }
   101     
   104     
   107     
   110     
   108     resetViewStack();
   111     resetViewStack();
   109     delete mViewStack;
   112     delete mViewStack;
   110     
   113     
   111     NmIcons::freeIcons();
   114     NmIcons::freeIcons();
       
   115 
   112     NmUiEngine::releaseInstance(mUiEngine);
   116     NmUiEngine::releaseInstance(mUiEngine);
   113     mUiEngine = NULL;
   117     mUiEngine = NULL;
   114     
   118     
   115     delete mBackAction;
   119     delete mBackAction;
   116     
   120     
   127     
   131     
   128     if (mNetManager) {
   132     if (mNetManager) {
   129         if (mNetManager->cache()) {
   133         if (mNetManager->cache()) {
   130             mNetManager->cache()->clear();
   134             mNetManager->cache()->clear();
   131         }
   135         }
   132     delete mNetManager;
   136 
   133     mNetManager = NULL;
   137         delete mNetManager;
       
   138         mNetManager = NULL;
   134     }
   139     }
   135     
   140     
   136     // Effects need to be deleted before MainWindow.
   141     // Effects need to be deleted before MainWindow.
   137     delete mEffects;
   142     delete mEffects;
   138     delete mMainWindow;
   143     delete mMainWindow;
   139     delete mAttaManager;
   144     delete mAttaManager;
   140     delete mSettingsViewLauncher;
   145     delete mSettingsViewLauncher;
   141 }
   146 }
       
   147 
   142 
   148 
   143 /*!
   149 /*!
   144     Main application window creation.
   150     Main application window creation.
   145 */
   151 */
   146 void NmApplication::createMainWindow()
   152 void NmApplication::createMainWindow()
   215         // Currently effects to NmViewerHeader::paint() and
   221         // Currently effects to NmViewerHeader::paint() and
   216         // NmAttachmentListWidget::paint().
   222         // NmAttachmentListWidget::paint().
   217         mMainWindow->setOptimizationFlag(QGraphicsView::DontSavePainterState);    
   223         mMainWindow->setOptimizationFlag(QGraphicsView::DontSavePainterState);    
   218     }
   224     }
   219     
   225     
   220 	// installed to get ApplicationActivate/Deactivate events
   226 	// Install the event filter in order to receive ApplicationActivate/Deactivate
       
   227     // events.
   221     QCoreApplication::instance()->installEventFilter(this);
   228     QCoreApplication::instance()->installEventFilter(this);
   222 }
   229 }
   223 
   230 
       
   231 
   224 /*!
   232 /*!
   225     Slot. React to view ready signal and call current view method.
   233     Slot. React to view ready signal and call current view method.
   226 */
   234 */
   227 void NmApplication::viewReady()
   235 void NmApplication::viewReady()
   228 {
   236 {
   229     mViewReady = true;
   237     mViewReady = true;
       
   238 
   230     if (mViewStack && !mViewStack->isEmpty()) {
   239     if (mViewStack && !mViewStack->isEmpty()) {
   231     	NmBaseView *currentView = mViewStack->top();
   240     	NmBaseView *currentView = mViewStack->top();
       
   241 
   232         if (currentView) {
   242         if (currentView) {
   233             currentView->viewReady();
   243             currentView->viewReady();
   234             emit applicationReady();
   244             emit applicationReady();
   235         }
   245         }
   236     }
   246     }
   237 }
   247 }
   238 
   248 
   239 /*!
   249 
   240     Event filter. End key is filtered from the main window and either the
   250 /*!
   241     view takes case of the or the app is exited by default.
   251     Event filter. End key is filtered from the main window and either the view
       
   252     takes case or the app is exited by default.
   242 */
   253 */
   243 bool NmApplication::eventFilter(QObject *obj, QEvent *event)
   254 bool NmApplication::eventFilter(QObject *obj, QEvent *event)
   244 {
   255 {
   245     bool consumed(false);
   256     bool consumed(false);
   246     
   257 
   247     if (obj && obj == mMainWindow && event && event->type() == QEvent::KeyPress) {
   258     if (obj && obj == mMainWindow && event && event->type() == QEvent::KeyPress) {
   248         QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
   259         QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
   249         if (keyEvent->key() == Qt::Key_No) {
   260         if (keyEvent->key() == Qt::Key_No) {
   250             // End key, the "red" key.
   261             // End key, the "red" key.
   251             // Exit application if no pending operations are on-going.
   262             // Exit application if no pending operations are on-going.
   252         }
   263         }
   253     }
   264     }
   254     else if (event->type()==QEvent::ApplicationActivate) {
   265     else if (event && event->type() == QEvent::ApplicationActivate) {
   255         NM_COMMENT("NmApplication::eventFilter ApplicationActivate");
   266         NM_COMMENT("NmApplication::eventFilter ApplicationActivate");
   256 		
   267 		// Update task switcher name & screenshot, we could have activated into some other mailbox
   257 		// Activity thumbnails must be shown again
   268         updateActivity();
   258 		if (mActivityUpdateNeeded) {
   269     }
   259 			mActivityUpdateNeeded = false;
   270     else if (event && event->type() == QEvent::ApplicationDeactivate) {
   260             updateActivity();
       
   261 		}
       
   262     }
       
   263     else if (event->type()==QEvent::ApplicationDeactivate) {
       
   264         NM_COMMENT("NmApplication::eventFilter ApplicationDeactivate");
   271         NM_COMMENT("NmApplication::eventFilter ApplicationDeactivate");
   265                 
   272         // Update the screenshot in the taskswitcher to represent current state
       
   273         updateActivity();
   266         // hide the sync indicator when app goes to background
   274         // hide the sync indicator when app goes to background
   267         mUiEngine->enableSyncIndicator(false);
   275         mUiEngine->enableSyncIndicator(false);
   268     }
   276     }
   269     
   277     
   270     if (!consumed) {
   278     if (!consumed) {
   271         consumed = QObject::eventFilter(obj, event);
   279         consumed = QObject::eventFilter(obj, event);
   272     }
   280     }
   273     
   281     
   274     return consumed;
   282     return consumed;
   275 }
   283 }
       
   284 
   276 
   285 
   277 /*!
   286 /*!
   278     Push view to view stack.
   287     Push view to view stack.
   279 */
   288 */
   280 void NmApplication::pushView(NmBaseView *newView)
   289 void NmApplication::pushView(NmBaseView *newView)
   311         // Hide old view.
   320         // Hide old view.
   312         NM_COMMENT("NmApplication::pushView() : remove view.");
   321         NM_COMMENT("NmApplication::pushView() : remove view.");
   313         if (hideView) {
   322         if (hideView) {
   314             mMainWindow->removeView(hideView);
   323             mMainWindow->removeView(hideView);
   315         }
   324         }
   316         QTimer::singleShot(NmActivityUpdateDelayMs, this, SLOT(updateActivity()));
       
   317     }
   325     }
   318 }
   326 }
   319 
   327 
   320 /*!
   328 /*!
   321     Ask from view that is it ok to pop view. This kind of 2-phase popView is
   329     Ask from view that is it ok to pop view. This kind of 2-phase popView is
   344     else if (mViewStack && mViewStack->size() == 0) {
   352     else if (mViewStack && mViewStack->size() == 0) {
   345         exitApplication();
   353         exitApplication();
   346     }
   354     }
   347 }
   355 }
   348 
   356 
       
   357 
   349 /*!
   358 /*!
   350      Hide the application
   359      Hide the application
   351 */
   360 */
   352 void NmApplication::hideApplication()
   361 void NmApplication::hideApplication()
   353 {
   362 {
   364     // Remove also the mailbox item from the task switcher
   373     // Remove also the mailbox item from the task switcher
   365     HbApplication* hbApp = dynamic_cast<HbApplication*>(parent());
   374     HbApplication* hbApp = dynamic_cast<HbApplication*>(parent());
   366     if (hbApp) {
   375     if (hbApp) {
   367         hbApp->activityManager()->removeActivity(NmActivityName);
   376         hbApp->activityManager()->removeActivity(NmActivityName);
   368     }
   377     }
   369 	
   378 }
   370 	// Update the activity when needed
   379 
   371 	mActivityUpdateNeeded = true;
       
   372 }
       
   373 
   380 
   374 /*!
   381 /*!
   375     Pop view from view stack. View object is deleted.
   382     Pop view from view stack. View object is deleted.
   376 */
   383 */
   377 void NmApplication::popView()
   384 void NmApplication::popView()
   423                 mMainWindow->setCurrentView(showView);
   430                 mMainWindow->setCurrentView(showView);
   424                 // Store activated view id.
   431                 // Store activated view id.
   425                 mActiveViewId=showView->nmailViewId();
   432                 mActiveViewId=showView->nmailViewId();
   426                 // Perform send animation if requested.
   433                 // Perform send animation if requested.
   427                 mEffects->startEffect(NmUiEffects::NmEditorSendMessageAnimation);
   434                 mEffects->startEffect(NmUiEffects::NmEditorSendMessageAnimation);
   428                 QTimer::singleShot(NmActivityUpdateDelayMs, this, SLOT(updateActivity()));
       
   429             }
   435             }
   430             
   436             
   431             delete view;
   437             delete view;
   432             view = NULL;
   438             view = NULL;
   433             
   439             
   452     if (mViewStack && mViewStack->size() == 0) {
   458     if (mViewStack && mViewStack->size() == 0) {
   453         exitApplication();
   459         exitApplication();
   454     }
   460     }
   455 }
   461 }
   456 
   462 
       
   463 
   457 /*!
   464 /*!
   458     Reset view stack. Remove and destroy view objects.
   465     Reset view stack. Remove and destroy view objects.
   459 */
   466 */
   460 void NmApplication::resetViewStack()
   467 void NmApplication::resetViewStack()
   461 {
   468 {
   468             delete view;
   475             delete view;
   469         }
   476         }
   470 	    mActiveViewId = NmUiViewNone;
   477 	    mActiveViewId = NmUiViewNone;
   471     }
   478     }
   472 }
   479 }
       
   480 
   473 
   481 
   474 /*!
   482 /*!
   475     Function activates view based on viewId parameter. If requested view is
   483     Function activates view based on viewId parameter. If requested view is
   476     already open, it is requested to reload. Otherwise view object is created
   484     already open, it is requested to reload. Otherwise view object is created
   477     and pushed to view stack.
   485     and pushed to view stack.
   584             mServiceViewId = mActiveViewId;
   592             mServiceViewId = mActiveViewId;
   585 		}
   593 		}
   586     }
   594     }
   587 }
   595 }
   588 
   596 
       
   597 
   589 /*!
   598 /*!
   590     Function can be used from views to exit the application. View stack is
   599     Function can be used from views to exit the application. View stack is
   591     cleared. Views can connect exit menu selection to this slot.
   600     cleared. Views can connect exit menu selection to this slot.
   592 */
   601 */
   593 void NmApplication::exitApplication()
   602 void NmApplication::exitApplication()
   609     mViewerServiceInterface = NULL;
   618     mViewerServiceInterface = NULL;
   610     resetViewStack();
   619     resetViewStack();
   611     qApp->quit();
   620     qApp->quit();
   612 }
   621 }
   613 
   622 
       
   623 
   614 /*!
   624 /*!
   615    Exit the application in the next event loop.
   625    Exit the application in the next event loop.
   616 */
   626 */
   617 void NmApplication::delayedExitApplication()
   627 void NmApplication::delayedExitApplication()
   618 {
   628 {
   619     // Exit the application in the next event loop.
   629     // Exit the application in the next event loop.
   620     QMetaObject::invokeMethod(this, "exitApplication", Qt::QueuedConnection);
   630     QMetaObject::invokeMethod(this, "exitApplication", Qt::QueuedConnection);
   621 }
   631 }
   622 
   632 
       
   633 
   623 /*!
   634 /*!
   624     Getter for main window instance.
   635     Getter for main window instance.
   625 */
   636 */
   626 HbMainWindow *NmApplication::mainWindow()
   637 HbMainWindow *NmApplication::mainWindow()
   627 {
   638 {
   628     return mMainWindow;
   639     return mMainWindow;
   629 }
   640 }
   630 
   641 
       
   642 
   631 /*!
   643 /*!
   632     Getter for main UI extension manager.
   644     Getter for main UI extension manager.
   633 */
   645 */
   634 NmUiExtensionManager &NmApplication::extManager()
   646 NmUiExtensionManager &NmApplication::extManager()
   635 {
   647 {
   636     return *mExtensionManager;
   648     return *mExtensionManager;
   637 }
   649 }
   638 
   650 
       
   651 
   639 /*!
   652 /*!
   640     Getter for network access manager.
   653     Getter for network access manager.
   641 */
   654 */
   642 NmViewerViewNetManager &NmApplication::networkAccessManager()
   655 NmViewerViewNetManager &NmApplication::networkAccessManager()
   643 {
   656 {
   644     return *mNetManager;
   657     return *mNetManager;
   645 }
   658 }
       
   659 
   646 
   660 
   647 /*!
   661 /*!
   648     Get the screen size. Function returns curtent screen size.
   662     Get the screen size. Function returns curtent screen size.
   649 */
   663 */
   650 QSize NmApplication::screenSize()
   664 QSize NmApplication::screenSize()
   675         }
   689         }
   676     }
   690     }
   677     return ret;
   691     return ret;
   678 }
   692 }
   679 
   693 
       
   694 
   680 /*!
   695 /*!
   681     Handles all asynchronous operation's completions at UI level.
   696     Handles all asynchronous operation's completions at UI level.
   682 */
   697 */
   683 void NmApplication::handleOperationCompleted(const NmOperationCompletionEvent &event)
   698 void NmApplication::handleOperationCompleted(const NmOperationCompletionEvent &event)
   684 {
   699 {
   706             NmUtilities::displayWarningNote(hbTrId("txt_mail_dialog_mail_connection_error"));
   721             NmUtilities::displayWarningNote(hbTrId("txt_mail_dialog_mail_connection_error"));
   707         }
   722         }
   708     }
   723     }
   709 }
   724 }
   710 
   725 
       
   726 
   711 /*!
   727 /*!
   712     Launches settings view of the specified mailbox.
   728     Launches settings view of the specified mailbox.
   713 */
   729 */
   714 void NmApplication::launchSettings(HbAction* action)
   730 void NmApplication::launchSettings(HbAction* action)
   715 {
   731 {
   722         // Mailboxname required.
   738         // Mailboxname required.
   723         NmMailboxMetaData *mailboxMetaData = mUiEngine->mailboxById(mLastOperationMailbox); // No ownership.
   739         NmMailboxMetaData *mailboxMetaData = mUiEngine->mailboxById(mLastOperationMailbox); // No ownership.
   724         if( mailboxMetaData ) {
   740         if( mailboxMetaData ) {
   725             // Launch.
   741             // Launch.
   726             mSettingsViewLauncher->launchSettingsView(mLastOperationMailbox, mailboxMetaData->name());
   742             mSettingsViewLauncher->launchSettingsView(mLastOperationMailbox, mailboxMetaData->name());
   727             QTimer::singleShot(NmActivityUpdateDelayMs, this, SLOT(updateActivity()));
   743         }
   728         }
   744     }
   729     }
   745 }
   730 }
   746 
   731 
   747 
   732 /*!
   748 /*!
   733 	Stores the visibility state, e.g. when the service was launched.
   749 	Stores the visibility state, e.g. when the service was launched.
   734 	\return true if the app was visible.
   750 	\return true if the app was visible.
   735 */
   751 */
   740 	mForegroundService = (surface != 0);
   756 	mForegroundService = (surface != 0);
   741 	NM_COMMENT(QString("NmApplication::updateVisibilityState() : mForegroundService == %1").arg(mForegroundService));
   757 	NM_COMMENT(QString("NmApplication::updateVisibilityState() : mForegroundService == %1").arg(mForegroundService));
   742 	return mForegroundService;
   758 	return mForegroundService;
   743 }
   759 }
   744 
   760 
   745 /*!
   761 
   746     Update the thumbnail in the task switcher
   762 /*!
       
   763     Update the thumbnail in the task switcher.
   747 */
   764 */
   748 void NmApplication::updateActivity()
   765 void NmApplication::updateActivity()
   749 {
   766 {
   750     NmMailboxMetaData *meta = mUiEngine->mailboxById(mCurrentMailboxId);
   767     NmMailboxMetaData *meta = mUiEngine->mailboxById(mCurrentMailboxId);
   751     HbApplication* hbApp = dynamic_cast<HbApplication*>(parent());
   768     HbApplication* hbApp = dynamic_cast<HbApplication*>(parent());
       
   769 
   752     if (hbApp) {
   770     if (hbApp) {
   753         if (meta) {
   771         if (meta) {
   754             TsTaskSettings tasksettings;
   772             TsTaskSettings tasksettings;
   755             tasksettings.setVisibility(false);
   773             tasksettings.setVisibility(false);
   756             QVariantHash metadata;
   774             QVariantHash metadata;
   765             TsTaskSettings tasksettings;
   783             TsTaskSettings tasksettings;
   766             tasksettings.setVisibility(true);
   784             tasksettings.setVisibility(true);
   767         }
   785         }
   768     }
   786     }
   769 }
   787 }
       
   788 
       
   789 
       
   790 /*!
       
   791 	Switch to activated mailbox
       
   792 */
       
   793 void NmApplication::activityActivated()
       
   794 {
       
   795     HbApplication* hbApp = dynamic_cast<HbApplication*>(parent());
       
   796     if (hbApp) {
       
   797         quint64 accountId(0);
       
   798         QString activateId = hbApp->activateId();
       
   799         if (hbApp->activateReason() == Hb::ActivationReasonActivity &&
       
   800                 activateId.startsWith(NmActivityName) ) {
       
   801             QString accountIdString = activateId.mid(NmActivityName.length());
       
   802             accountId = accountIdString.toULongLong();
       
   803             QVariant mailbox;
       
   804             mailbox.setValue(accountId);
       
   805             mMailboxServiceInterface->displayInboxByMailboxId(mailbox);
       
   806         }
       
   807     }
       
   808 }
       
   809