emailuis/nmailui/src/nmapplication.cpp
changeset 62 a8c646b56683
parent 57 ae34e1715e21
child 66 084b5b1f02a7
equal deleted inserted replaced
57:ae34e1715e21 62:a8c646b56683
    46   mEffects(NULL),
    46   mEffects(NULL),
    47   mAttaManager(NULL),
    47   mAttaManager(NULL),
    48   mSettingsViewLauncher(NULL),
    48   mSettingsViewLauncher(NULL),
    49   mViewReady(false),
    49   mViewReady(false),
    50   mQueryDialog(NULL),
    50   mQueryDialog(NULL),
    51   mBackButtonPressed(false)
    51   mBackButtonPressed(false),
       
    52   mApplicationHidden(false)
    52 {
    53 {
    53     TRAP_IGNORE(mUiEngine = NmUiEngine::instance());
    54     TRAP_IGNORE(mUiEngine = NmUiEngine::instance());
    54     
    55     
    55     // Create network access manager and cache for application use.
    56     // Create network access manager and cache for application use.
    56     mNetManager = new NmViewerViewNetManager(*mUiEngine);
    57     mNetManager = new NmViewerViewNetManager(*mUiEngine);
   195             this,
   196             this,
   196             SLOT(handleOperationCompleted(const NmOperationCompletionEvent &)));
   197             SLOT(handleOperationCompleted(const NmOperationCompletionEvent &)));
   197     
   198     
   198     mMbListModel = &mUiEngine->mailboxListModel();
   199     mMbListModel = &mUiEngine->mailboxListModel();
   199     
   200     
   200     // ----------------------------------------------------------------------
   201 
   201     // TODO: Remove or comment out the following code block when the mail
       
   202     //       wizard starts to work with Mfe.
       
   203     // ----------------------------------------------------------------------
       
   204     // Start application to mailbox view. If started as service, there is no
       
   205     // need to create views.
       
   206     if (!service) {
       
   207         NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMailboxList);
       
   208         enterNmUiView(startParam);
       
   209     }
       
   210     // ----------------------------------------------------------------------
   202     // ----------------------------------------------------------------------
   211     
   203     
   212     if (mMainWindow) {
   204     if (mMainWindow) {
   213         // Start to filter main window events to get "end key" event in all
   205         // Start to filter main window events to get "end key" event in all
   214         // possible situations. Using event()is not enough to catch the event
   206         // possible situations. Using event()is not enough to catch the event
   262             // Exit application if no pending operations are on-going.
   254             // Exit application if no pending operations are on-going.
   263         }
   255         }
   264     }
   256     }
   265     else if (event && event->type() == QEvent::ApplicationActivate) {
   257     else if (event && event->type() == QEvent::ApplicationActivate) {
   266         NM_COMMENT("NmApplication::eventFilter ApplicationActivate");
   258         NM_COMMENT("NmApplication::eventFilter ApplicationActivate");
       
   259         mApplicationHidden = false;
   267 		// Update task switcher name & screenshot, we could have activated into some other mailbox
   260 		// Update task switcher name & screenshot, we could have activated into some other mailbox
   268         updateActivity();
   261         updateActivity();
   269     }
   262     }
   270     else if (event && event->type() == QEvent::ApplicationDeactivate) {
   263     else if (event && event->type() == QEvent::ApplicationDeactivate) {
   271         NM_COMMENT("NmApplication::eventFilter ApplicationDeactivate");
   264         NM_COMMENT("NmApplication::eventFilter ApplicationDeactivate");
   272         // Update the screenshot in the taskswitcher to represent current state
   265         // Update the screenshot in the taskswitcher to represent current state
   273         updateActivity();
   266         if (!mApplicationHidden) {
       
   267             updateActivity();
       
   268         }
   274         // hide the sync indicator when app goes to background
   269         // hide the sync indicator when app goes to background
   275         mUiEngine->enableSyncIndicator(false);
   270         mUiEngine->enableSyncIndicator(false);
   276     }
   271     }
   277     
   272     
   278     if (!consumed) {
   273     if (!consumed) {
   282     return consumed;
   277     return consumed;
   283 }
   278 }
   284 
   279 
   285 
   280 
   286 /*!
   281 /*!
   287     Push view to view stack.
   282     Pushes the given view into the view stack. The new view is also activated
       
   283     and shown. If the view stack contains other views, the one on the top is
       
   284     hidden.
       
   285 
       
   286     \param newView The view to push into the stack.
   288 */
   287 */
   289 void NmApplication::pushView(NmBaseView *newView)
   288 void NmApplication::pushView(NmBaseView *newView)
   290 {
   289 {
   291     if (newView && mViewStack) {
   290     if (newView && mViewStack) {
   292         NM_COMMENT("NmApplication::pushView() : view exists.");
   291         NM_COMMENT("NmApplication::pushView(): The given view is valid.");
   293         newView->setNavigationAction(mBackAction);
   292         newView->setNavigationAction(mBackAction);
   294         
   293         
   295         // Store view to be hidden.
   294         // Store the view to be hidden.
   296         NmBaseView *hideView(NULL);
   295         NmBaseView *viewToHide(NULL);
       
   296 
   297         if (!mViewStack->isEmpty()) {
   297         if (!mViewStack->isEmpty()) {
   298             hideView = mViewStack->top();
   298             // The stack contains at least one other view.
       
   299             viewToHide = mViewStack->top();
   299         }
   300         }
   300 		else {
   301 		else {
   301 			// viewReady should be informed immediately.
   302 			// viewReady should be informed immediately.
   302 			if (mViewReady) {
   303 			if (mViewReady) {
   303 				newView->viewReady();
   304 				newView->viewReady();
   304 			}
   305 			}
   305 		}
   306 		}
   306         
   307         
   307         // Activate new view.
   308         // Activate the new view.
   308     	NM_COMMENT("NmApplication::pushView() : add view.");
   309     	NM_COMMENT("NmApplication::pushView(): Adding the view into the stack.");
       
   310 
   309         mMainWindow->addView(newView);
   311         mMainWindow->addView(newView);
   310         mViewStack->push(newView);
   312         mViewStack->push(newView);
   311         mMainWindow->setCurrentView(newView);
   313         mMainWindow->setCurrentView(newView);
   312         mActiveViewId=newView->nmailViewId();
   314         mActiveViewId = newView->nmailViewId();
   313         
   315         
   314         // Set toolbars orientation.
   316         // Set the orientation of the toolbar.
   315         HbToolBar *tb = newView->toolBar();
   317         HbToolBar *tb = newView->toolBar();
       
   318 
   316         if (tb) {
   319         if (tb) {
   317             tb->setOrientation(Qt::Horizontal);
   320             tb->setOrientation(Qt::Horizontal);
   318         }
   321         }
   319         
   322         
   320         // Hide old view.
   323         // Hide the old view.
   321         NM_COMMENT("NmApplication::pushView() : remove view.");
   324         NM_COMMENT("NmApplication::pushView(): Removing the previous view.");
   322         if (hideView) {
   325 
   323             mMainWindow->removeView(hideView);
   326         if (viewToHide) {
       
   327             mMainWindow->removeView(viewToHide);
   324         }
   328         }
   325     }
   329     }
   326 }
   330 }
   327 
   331 
   328 /*!
   332 /*!
   358 /*!
   362 /*!
   359      Hide the application
   363      Hide the application
   360 */
   364 */
   361 void NmApplication::hideApplication()
   365 void NmApplication::hideApplication()
   362 {
   366 {
       
   367     mApplicationHidden = true;
       
   368     
   363     // Hide the application
   369     // Hide the application
   364     XQServiceUtil::toBackground(true);
   370     XQServiceUtil::toBackground(true);
   365 
   371 
   366     // hide the sync indicator as well
   372     // hide the sync indicator as well
   367     mUiEngine->enableSyncIndicator(false);
   373     mUiEngine->enableSyncIndicator(false);
   493     
   499     
   494         mCurrentMailboxId = startParam->mailboxId();
   500         mCurrentMailboxId = startParam->mailboxId();
   495         
   501         
   496         if (startParam->service() && mMainWindow) {
   502         if (startParam->service() && mMainWindow) {
   497 			// When the message list is started as a service previous views
   503 			// When the message list is started as a service previous views
   498             // are removed from the stack. Open editors are not closed. Also
   504             // are removed from the stack. Open editors are closed. Also
   499             // if the view is same than the new one, keep it open (reload the
   505             // if the view is same than the new one, keep it open (reload the
   500             // content).
   506             // content).
   501             
   507             
   502 		    // Reset the foreground service flag while popping the views.
   508 		    // Reset the foreground service flag while popping the views.
   503 		    bool previousForegroundService = mForegroundService;
   509 		    bool previousForegroundService = mForegroundService;
   536                     pushView(mbListView);
   542                     pushView(mbListView);
   537                 }
   543                 }
   538                 break;
   544                 break;
   539                 case NmUiViewMessageList:
   545                 case NmUiViewMessageList:
   540                 {
   546                 {
   541                     // Check the topmost view. If it is an editor, do not open
   547                     // Check the topmost view. If it is an editor, save to draft and close it.
   542                     // a new mail list view.
   548                     if (startParam->service() && !mViewStack->isEmpty() && 
   543                     if (startParam->service() && !mViewStack->isEmpty() &&
       
   544                         mViewStack->top()->nmailViewId()==NmUiViewMessageEditor) {
   549                         mViewStack->top()->nmailViewId()==NmUiViewMessageEditor) {
   545                         break;
   550                         QMetaObject::invokeMethod(mViewStack->top(),
       
   551                             "safeToDraft", Qt::DirectConnection);
       
   552                         popView();
   546                     }
   553                     }
   547                     NmMessageListModel *messageListModel = &mUiEngine->messageListModel(
   554 
   548                                                 startParam->mailboxId(), startParam->folderId());
   555                     NmMessageListModel *messageListModel =
   549                     NmMessageListView *msgList =new NmMessageListView(
   556                         &mUiEngine->messageListModel(startParam->mailboxId(),
   550                     		*this, startParam, *mUiEngine, *mMbListModel, messageListModel,
   557                                                      startParam->folderId());
   551                     		new HbDocumentLoader(mMainWindow));
   558                     NmMessageListView *msgList =
       
   559                         new NmMessageListView(*this, startParam, *mUiEngine,
       
   560                                               *mMbListModel, messageListModel,
       
   561                                               new HbDocumentLoader(mMainWindow));
   552                     pushView(msgList);
   562                     pushView(msgList);
       
   563                     
       
   564                     // Inform other processes about this event.
       
   565                     NmUiEventsNotifier::notifyViewStateChanged(NmUiEventsNotifier::NmViewShownEvent,
       
   566                                                                NmUiViewMessageList,
       
   567                                                                startParam->mailboxId());
   553                 }
   568                 }
   554                 break;
   569                 break;
   555                 case NmUiViewMessageSearchList:
   570                 case NmUiViewMessageSearchList:
   556                 {
   571                 {
   557                     // Check the topmost view. If it is an editor, do not open
   572                     // Check the topmost view. If it is an editor, save to draft and close it.
   558                     // a new mail search list view.
   573                     if (startParam->service() && !mViewStack->isEmpty() && 
   559                     if (startParam->service() && !mViewStack->isEmpty() &&
   574                         mViewStack->top()->nmailViewId()==NmUiViewMessageEditor) {
   560                         mViewStack->top()->nmailViewId() == NmUiViewMessageEditor) {
   575                         QMetaObject::invokeMethod(mViewStack->top(),
   561                         break;
   576                             "safeToDraft", Qt::DirectConnection);
       
   577                         popView();
   562                     }
   578                     }
   563                     
   579                     
   564                     NmMessageListModel &model =
   580                     NmMessageListModel &model =
   565                         mUiEngine->messageListModelForSearch(startParam->mailboxId());
   581                         mUiEngine->messageListModelForSearch(startParam->mailboxId());
   566                     
   582                     
   574                 case NmUiViewMessageViewer:
   590                 case NmUiViewMessageViewer:
   575                     pushView(new NmViewerView(*this, startParam, *mUiEngine,
   591                     pushView(new NmViewerView(*this, startParam, *mUiEngine,
   576                             mMainWindow, *mAttaManager));
   592                             mMainWindow, *mAttaManager));
   577                     break;
   593                     break;
   578                 case NmUiViewMessageEditor:
   594                 case NmUiViewMessageEditor:
       
   595                     // Check the topmost view. If it is an editor, save to draft and close it.
       
   596                     if (startParam->service() && !mViewStack->isEmpty() && 
       
   597                         mViewStack->top()->nmailViewId()==NmUiViewMessageEditor) {
       
   598                         QMetaObject::invokeMethod(mViewStack->top(),
       
   599                             "safeToDraft", Qt::DirectConnection);
       
   600                         popView();
       
   601                     }
   579                     pushView(new NmEditorView(*this, startParam, *mUiEngine, *mAttaManager));
   602                     pushView(new NmEditorView(*this, startParam, *mUiEngine, *mAttaManager));
   580                     break;
   603                     break;
   581                 default:
   604                 default:
   582                     // Reset view stack and exit application.
   605                     // Reset view stack and exit application.
   583                     delete startParam;
   606                     delete startParam;
   744     }
   767     }
   745 }
   768 }
   746 
   769 
   747 
   770 
   748 /*!
   771 /*!
       
   772    Check the foreground status of the application 
       
   773    \return true if the application is in the foreground
       
   774 */
       
   775 bool NmApplication::isForeground() const
       
   776 {
       
   777     // At the moment there is no good way to check the foreground state.
       
   778     QWindowSurface *surface = mMainWindow->windowSurface();
       
   779     return (surface != 0);
       
   780 }
       
   781 
       
   782 /*!
   749 	Stores the visibility state, e.g. when the service was launched.
   783 	Stores the visibility state, e.g. when the service was launched.
   750 	\return true if the app was visible.
   784 	\return true if the app was visible.
   751 */
   785 */
   752 bool NmApplication::updateVisibilityState()
   786 bool NmApplication::updateVisibilityState()
   753 {
   787 {
   754     // At the moment there is no good way to check the foreground state.
   788 	mForegroundService = isForeground();
   755     QWindowSurface *surface = mMainWindow->windowSurface();
       
   756 	mForegroundService = (surface != 0);
       
   757 	NM_COMMENT(QString("NmApplication::updateVisibilityState() : mForegroundService == %1").arg(mForegroundService));
   789 	NM_COMMENT(QString("NmApplication::updateVisibilityState() : mForegroundService == %1").arg(mForegroundService));
   758 	return mForegroundService;
   790 	return mForegroundService;
   759 }
   791 }
   760 
   792 
   761 
   793 
   766 {
   798 {
   767     NmMailboxMetaData *meta = mUiEngine->mailboxById(mCurrentMailboxId);
   799     NmMailboxMetaData *meta = mUiEngine->mailboxById(mCurrentMailboxId);
   768     HbApplication* hbApp = dynamic_cast<HbApplication*>(parent());
   800     HbApplication* hbApp = dynamic_cast<HbApplication*>(parent());
   769 
   801 
   770     if (hbApp) {
   802     if (hbApp) {
   771         if (meta) {
   803         // This will ensure that when service is started as a embedded service and a mail 
   772             TsTaskSettings tasksettings;
   804         // process already exists the task activity will show the embedded service inside the 
   773             tasksettings.setVisibility(false);
   805         // calling processes activity and the already running mail process in its own activity.
   774             QVariantHash metadata;
   806         if(!XQServiceUtil::isService() || !XQServiceUtil::isEmbedded()) {
   775             metadata.insert(ActivityScreenshotKeyword, QPixmap::grabWidget(mainWindow(), mainWindow()->rect()));
   807             if (meta) {
   776             metadata.insert(ActivityApplicationName, meta->name());
   808                 TsTaskSettings tasksettings;
   777             metadata.insert(ActivityVisibility, true);
   809                 tasksettings.setVisibility(false);
   778             hbApp->activityManager()->removeActivity(NmActivityName);
   810                 QVariantHash metadata;
   779             hbApp->activityManager()->addActivity(NmActivityName, QVariant(), metadata);
   811                 metadata.insert(ActivityScreenshotKeyword, QPixmap::grabWidget(mainWindow(), mainWindow()->rect()));
   780         }
   812                 metadata.insert(ActivityApplicationName, meta->name());
   781         else {
   813                 metadata.insert(ActivityVisibility, true);
   782             hbApp->activityManager()->removeActivity(NmActivityName);
   814                 hbApp->activityManager()->removeActivity(NmActivityName);
   783             TsTaskSettings tasksettings;
   815                 hbApp->activityManager()->addActivity(NmActivityName, QVariant(), metadata);
   784             tasksettings.setVisibility(true);
   816             }
   785         }
   817             else {
   786     }
   818                 hbApp->activityManager()->removeActivity(NmActivityName);
   787 }
   819                 TsTaskSettings tasksettings;
   788 
   820                 tasksettings.setVisibility(true);
       
   821             }
       
   822         }
       
   823     }
       
   824 }
   789 
   825 
   790 /*!
   826 /*!
   791 	Switch to activated mailbox
   827 	Switch to activated mailbox
   792 */
   828 */
   793 void NmApplication::activityActivated()
   829 void NmApplication::activityActivated()