emailuis/nmailui/src/nmapplication.cpp
changeset 56 15bc1d5d6267
parent 51 d845db10c0d4
child 57 ae34e1715e21
equal deleted inserted replaced
51:d845db10c0d4 56:15bc1d5d6267
    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";
       
    29 
    24 /*!
    30 /*!
    25     \class NmApplication
    31     \class NmApplication
    26     \brief Application class, creates main window and handles view switching.
    32     \brief Application class, creates main window and handles view switching.
    27 */
    33 */
    28 
    34 
    43   mEffects(NULL),
    49   mEffects(NULL),
    44   mAttaManager(NULL),
    50   mAttaManager(NULL),
    45   mSettingsViewLauncher(NULL),
    51   mSettingsViewLauncher(NULL),
    46   mViewReady(false),
    52   mViewReady(false),
    47   mQueryDialog(NULL),
    53   mQueryDialog(NULL),
    48   mBackButtonPressed(false)
    54   mBackButtonPressed(false),
       
    55   mActivityUpdateNeeded(false)
    49 {
    56 {
    50     TRAP_IGNORE(mUiEngine = NmUiEngine::instance());
    57     TRAP_IGNORE(mUiEngine = NmUiEngine::instance());
    51     
    58     
    52     // Create network access manager and cache for application use.
    59     // Create network access manager and cache for application use.
    53     mNetManager = new NmViewerViewNetManager(*mUiEngine);
    60     mNetManager = new NmViewerViewNetManager(*mUiEngine);
   207         // Optimize the custom paint functions.
   214         // Optimize the custom paint functions.
   208         // Currently effects to NmViewerHeader::paint() and
   215         // Currently effects to NmViewerHeader::paint() and
   209         // NmAttachmentListWidget::paint().
   216         // NmAttachmentListWidget::paint().
   210         mMainWindow->setOptimizationFlag(QGraphicsView::DontSavePainterState);    
   217         mMainWindow->setOptimizationFlag(QGraphicsView::DontSavePainterState);    
   211     }
   218     }
       
   219     
       
   220 	// installed to get ApplicationActivate/Deactivate events
       
   221     QCoreApplication::instance()->installEventFilter(this);
   212 }
   222 }
   213 
   223 
   214 /*!
   224 /*!
   215     Slot. React to view ready signal and call current view method.
   225     Slot. React to view ready signal and call current view method.
   216 */
   226 */
   238         QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
   248         QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
   239         if (keyEvent->key() == Qt::Key_No) {
   249         if (keyEvent->key() == Qt::Key_No) {
   240             // End key, the "red" key.
   250             // End key, the "red" key.
   241             // Exit application if no pending operations are on-going.
   251             // Exit application if no pending operations are on-going.
   242         }
   252         }
       
   253     }
       
   254     else if (event->type()==QEvent::ApplicationActivate) {
       
   255         NM_COMMENT("NmApplication::eventFilter ApplicationActivate");
       
   256 		
       
   257 		// Activity thumbnails must be shown again
       
   258 		if (mActivityUpdateNeeded) {
       
   259 			mActivityUpdateNeeded = false;
       
   260             updateActivity();
       
   261 		}
       
   262     }
       
   263     else if (event->type()==QEvent::ApplicationDeactivate) {
       
   264         NM_COMMENT("NmApplication::eventFilter ApplicationDeactivate");
       
   265                 
       
   266         // hide the sync indicator when app goes to background
       
   267         mUiEngine->enableSyncIndicator(false);
   243     }
   268     }
   244     
   269     
   245     if (!consumed) {
   270     if (!consumed) {
   246         consumed = QObject::eventFilter(obj, event);
   271         consumed = QObject::eventFilter(obj, event);
   247     }
   272     }
   286         // Hide old view.
   311         // Hide old view.
   287         NM_COMMENT("NmApplication::pushView() : remove view.");
   312         NM_COMMENT("NmApplication::pushView() : remove view.");
   288         if (hideView) {
   313         if (hideView) {
   289             mMainWindow->removeView(hideView);
   314             mMainWindow->removeView(hideView);
   290         }
   315         }
       
   316         QTimer::singleShot(NmActivityUpdateDelayMs, this, SLOT(updateActivity()));
   291     }
   317     }
   292 }
   318 }
   293 
   319 
   294 /*!
   320 /*!
   295     Ask from view that is it ok to pop view. This kind of 2-phase popView is
   321     Ask from view that is it ok to pop view. This kind of 2-phase popView is
   328     // Hide the application
   354     // Hide the application
   329     XQServiceUtil::toBackground(true);
   355     XQServiceUtil::toBackground(true);
   330 
   356 
   331     // hide the sync indicator as well
   357     // hide the sync indicator as well
   332     mUiEngine->enableSyncIndicator(false);
   358     mUiEngine->enableSyncIndicator(false);
       
   359     
       
   360     // Hide the mail from the task switcher 
       
   361     TsTaskSettings taskSettings;
       
   362     taskSettings.setVisibility(false);
       
   363     
       
   364     // Remove also the mailbox item from the task switcher
       
   365     HbApplication* hbApp = dynamic_cast<HbApplication*>(parent());
       
   366     if (hbApp) {
       
   367         hbApp->activityManager()->removeActivity(NmActivityName);
       
   368     }
       
   369 	
       
   370 	// Update the activity when needed
       
   371 	mActivityUpdateNeeded = true;
   333 }
   372 }
   334 
   373 
   335 /*!
   374 /*!
   336     Pop view from view stack. View object is deleted.
   375     Pop view from view stack. View object is deleted.
   337 */
   376 */
   384                 mMainWindow->setCurrentView(showView);
   423                 mMainWindow->setCurrentView(showView);
   385                 // Store activated view id.
   424                 // Store activated view id.
   386                 mActiveViewId=showView->nmailViewId();
   425                 mActiveViewId=showView->nmailViewId();
   387                 // Perform send animation if requested.
   426                 // Perform send animation if requested.
   388                 mEffects->startEffect(NmUiEffects::NmEditorSendMessageAnimation);
   427                 mEffects->startEffect(NmUiEffects::NmEditorSendMessageAnimation);
       
   428                 QTimer::singleShot(NmActivityUpdateDelayMs, this, SLOT(updateActivity()));
   389             }
   429             }
   390             
   430             
   391             delete view;
   431             delete view;
   392             view = NULL;
   432             view = NULL;
   393             
   433             
   440 {
   480 {
   441     NM_FUNCTION;
   481     NM_FUNCTION;
   442     
   482     
   443     // Check the validity of start parameter object.
   483     // Check the validity of start parameter object.
   444     if (startParam) {
   484     if (startParam) {
       
   485     
       
   486         mCurrentMailboxId = startParam->mailboxId();
   445         
   487         
   446         if (startParam->service() && mMainWindow) {
   488         if (startParam->service() && mMainWindow) {
   447 			// When the message list is started as a service previous views
   489 			// When the message list is started as a service previous views
   448             // are removed from the stack. Open editors are not closed. Also
   490             // are removed from the stack. Open editors are not closed. Also
   449             // if the view is same than the new one, keep it open (reload the
   491             // if the view is same than the new one, keep it open (reload the
   550 */
   592 */
   551 void NmApplication::exitApplication()
   593 void NmApplication::exitApplication()
   552 {
   594 {
   553     NM_FUNCTION;
   595     NM_FUNCTION;
   554     
   596     
       
   597     HbApplication* hbApp = dynamic_cast<HbApplication*>(parent());
       
   598     hbApp->activityManager()->removeActivity("EmailInboxView");
       
   599     
   555     delete mSendServiceInterface;
   600     delete mSendServiceInterface;
   556     mSendServiceInterface = NULL;
   601     mSendServiceInterface = NULL;
   557     delete mSendServiceInterface2;
   602     delete mSendServiceInterface2;
   558     mSendServiceInterface2 = NULL;
   603     mSendServiceInterface2 = NULL;
   559     delete mUriServiceInterface;
   604     delete mUriServiceInterface;
   677         // Mailboxname required.
   722         // Mailboxname required.
   678         NmMailboxMetaData *mailboxMetaData = mUiEngine->mailboxById(mLastOperationMailbox); // No ownership.
   723         NmMailboxMetaData *mailboxMetaData = mUiEngine->mailboxById(mLastOperationMailbox); // No ownership.
   679         if( mailboxMetaData ) {
   724         if( mailboxMetaData ) {
   680             // Launch.
   725             // Launch.
   681             mSettingsViewLauncher->launchSettingsView(mLastOperationMailbox, mailboxMetaData->name());
   726             mSettingsViewLauncher->launchSettingsView(mLastOperationMailbox, mailboxMetaData->name());
       
   727             QTimer::singleShot(NmActivityUpdateDelayMs, this, SLOT(updateActivity()));
   682         }
   728         }
   683     }
   729     }
   684 }
   730 }
   685 
   731 
   686 /*!
   732 /*!
   693     QWindowSurface *surface = mMainWindow->windowSurface();
   739     QWindowSurface *surface = mMainWindow->windowSurface();
   694 	mForegroundService = (surface != 0);
   740 	mForegroundService = (surface != 0);
   695 	NM_COMMENT(QString("NmApplication::updateVisibilityState() : mForegroundService == %1").arg(mForegroundService));
   741 	NM_COMMENT(QString("NmApplication::updateVisibilityState() : mForegroundService == %1").arg(mForegroundService));
   696 	return mForegroundService;
   742 	return mForegroundService;
   697 }
   743 }
       
   744 
       
   745 /*!
       
   746     Update the thumbnail in the task switcher
       
   747 */
       
   748 void NmApplication::updateActivity()
       
   749 {
       
   750     NmMailboxMetaData *meta = mUiEngine->mailboxById(mCurrentMailboxId);
       
   751     HbApplication* hbApp = dynamic_cast<HbApplication*>(parent());
       
   752     if (hbApp) {
       
   753         if (meta) {
       
   754             TsTaskSettings tasksettings;
       
   755             tasksettings.setVisibility(false);
       
   756             QVariantHash metadata;
       
   757             metadata.insert(ActivityScreenshotKeyword, QPixmap::grabWidget(mainWindow(), mainWindow()->rect()));
       
   758             metadata.insert(ActivityApplicationName, meta->name());
       
   759             metadata.insert(ActivityVisibility, true);
       
   760             hbApp->activityManager()->removeActivity(NmActivityName);
       
   761             hbApp->activityManager()->addActivity(NmActivityName, QVariant(), metadata);
       
   762         }
       
   763         else {
       
   764             hbApp->activityManager()->removeActivity(NmActivityName);
       
   765             TsTaskSettings tasksettings;
       
   766             tasksettings.setVisibility(true);
       
   767         }
       
   768     }
       
   769 }