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 static const QString NmActivityName = "EmailInboxView"; |
|
25 |
24 /*! |
26 /*! |
25 \class NmApplication |
27 \class NmApplication |
26 \brief Application class, creates main window and handles view switching. |
28 \brief Application class, creates main window and handles view switching. |
27 */ |
29 */ |
28 |
30 |
|
31 |
29 /*! |
32 /*! |
30 Constructor. |
33 Constructor. |
31 */ |
34 */ |
32 NmApplication::NmApplication(QObject *parent, quint32 accountId) |
35 NmApplication::NmApplication(QObject *parent, quint64 accountId) |
33 : QObject(parent), |
36 : QObject(parent), |
34 mMainWindow(NULL), |
37 mMainWindow(NULL), |
35 mViewStack(NULL), |
38 mViewStack(NULL), |
36 mActiveViewId(NmUiViewNone), |
39 mActiveViewId(NmUiViewNone), |
37 mUiEngine(NULL), |
40 mUiEngine(NULL), |
73 mViewerServiceInterface = |
76 mViewerServiceInterface = |
74 new NmViewerServiceInterface(NULL, this, *mUiEngine); |
77 new NmViewerServiceInterface(NULL, this, *mUiEngine); |
75 |
78 |
76 if(accountId != 0) { |
79 if(accountId != 0) { |
77 QVariant mailbox; |
80 QVariant mailbox; |
78 mailbox.setValue(mUiEngine->getPluginIdByMailboxId(accountId).id()); |
81 mailbox.setValue(accountId); |
79 mMailboxServiceInterface->displayInboxByMailboxId(mailbox); |
82 mMailboxServiceInterface->displayInboxByMailboxId(mailbox); |
80 } |
83 } |
81 |
84 |
82 mEffects = new NmUiEffects(*mMainWindow); |
85 mEffects = new NmUiEffects(*mMainWindow); |
83 } |
86 |
|
87 QObject::connect(parent, SIGNAL(activate()), this, SLOT(activityActivated())); |
|
88 } |
|
89 |
84 |
90 |
85 /*! |
91 /*! |
86 Destructor. |
92 Destructor. |
87 */ |
93 */ |
88 NmApplication::~NmApplication() |
94 NmApplication::~NmApplication() |
89 { |
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 |
90 if (mQueryDialog) { |
100 if (mQueryDialog) { |
91 delete mQueryDialog; |
101 delete mQueryDialog; |
92 mQueryDialog = NULL; |
102 mQueryDialog = NULL; |
93 } |
103 } |
94 |
104 |
207 // Optimize the custom paint functions. |
220 // Optimize the custom paint functions. |
208 // Currently effects to NmViewerHeader::paint() and |
221 // Currently effects to NmViewerHeader::paint() and |
209 // NmAttachmentListWidget::paint(). |
222 // NmAttachmentListWidget::paint(). |
210 mMainWindow->setOptimizationFlag(QGraphicsView::DontSavePainterState); |
223 mMainWindow->setOptimizationFlag(QGraphicsView::DontSavePainterState); |
211 } |
224 } |
212 } |
225 |
|
226 // Install the event filter in order to receive ApplicationActivate/Deactivate |
|
227 // events. |
|
228 QCoreApplication::instance()->installEventFilter(this); |
|
229 } |
|
230 |
213 |
231 |
214 /*! |
232 /*! |
215 Slot. React to view ready signal and call current view method. |
233 Slot. React to view ready signal and call current view method. |
216 */ |
234 */ |
217 void NmApplication::viewReady() |
235 void NmApplication::viewReady() |
218 { |
236 { |
219 mViewReady = true; |
237 mViewReady = true; |
|
238 |
220 if (mViewStack && !mViewStack->isEmpty()) { |
239 if (mViewStack && !mViewStack->isEmpty()) { |
221 NmBaseView *currentView = mViewStack->top(); |
240 NmBaseView *currentView = mViewStack->top(); |
|
241 |
222 if (currentView) { |
242 if (currentView) { |
223 currentView->viewReady(); |
243 currentView->viewReady(); |
224 } |
244 emit applicationReady(); |
225 } |
245 } |
226 } |
246 } |
227 |
247 } |
228 /*! |
248 |
229 Event filter. End key is filtered from the main window and either the |
249 |
230 view takes case of the or the app is exited by default. |
250 /*! |
|
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. |
231 */ |
253 */ |
232 bool NmApplication::eventFilter(QObject *obj, QEvent *event) |
254 bool NmApplication::eventFilter(QObject *obj, QEvent *event) |
233 { |
255 { |
234 bool consumed(false); |
256 bool consumed(false); |
235 |
257 |
236 if (obj && obj == mMainWindow && event && event->type() == QEvent::KeyPress) { |
258 if (obj && obj == mMainWindow && event && event->type() == QEvent::KeyPress) { |
237 QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); |
259 QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); |
238 if (keyEvent->key() == Qt::Key_No) { |
260 if (keyEvent->key() == Qt::Key_No) { |
239 // End key, the "red" key. |
261 // End key, the "red" key. |
240 // Exit application if no pending operations are on-going. |
262 // Exit application if no pending operations are on-going. |
241 } |
263 } |
242 } |
264 } |
|
265 else if (event && event->type() == QEvent::ApplicationActivate) { |
|
266 NM_COMMENT("NmApplication::eventFilter ApplicationActivate"); |
|
267 // Update task switcher name & screenshot, we could have activated into some other mailbox |
|
268 updateActivity(); |
|
269 } |
|
270 else if (event && event->type() == QEvent::ApplicationDeactivate) { |
|
271 NM_COMMENT("NmApplication::eventFilter ApplicationDeactivate"); |
|
272 // Update the screenshot in the taskswitcher to represent current state |
|
273 updateActivity(); |
|
274 // hide the sync indicator when app goes to background |
|
275 mUiEngine->enableSyncIndicator(false); |
|
276 } |
243 |
277 |
244 if (!consumed) { |
278 if (!consumed) { |
245 consumed = QObject::eventFilter(obj, event); |
279 consumed = QObject::eventFilter(obj, event); |
246 } |
280 } |
247 |
281 |
248 return consumed; |
282 return consumed; |
249 } |
283 } |
|
284 |
250 |
285 |
251 /*! |
286 /*! |
252 Push view to view stack. |
287 Push view to view stack. |
253 */ |
288 */ |
254 void NmApplication::pushView(NmBaseView *newView) |
289 void NmApplication::pushView(NmBaseView *newView) |
317 else if (mViewStack && mViewStack->size() == 0) { |
352 else if (mViewStack && mViewStack->size() == 0) { |
318 exitApplication(); |
353 exitApplication(); |
319 } |
354 } |
320 } |
355 } |
321 |
356 |
|
357 |
|
358 /*! |
|
359 Hide the application |
|
360 */ |
|
361 void NmApplication::hideApplication() |
|
362 { |
|
363 // Hide the application |
|
364 XQServiceUtil::toBackground(true); |
|
365 |
|
366 // hide the sync indicator as well |
|
367 mUiEngine->enableSyncIndicator(false); |
|
368 |
|
369 // Hide the mail from the task switcher |
|
370 TsTaskSettings taskSettings; |
|
371 taskSettings.setVisibility(false); |
|
372 |
|
373 // Remove also the mailbox item from the task switcher |
|
374 HbApplication* hbApp = dynamic_cast<HbApplication*>(parent()); |
|
375 if (hbApp) { |
|
376 hbApp->activityManager()->removeActivity(NmActivityName); |
|
377 } |
|
378 } |
|
379 |
|
380 |
322 /*! |
381 /*! |
323 Pop view from view stack. View object is deleted. |
382 Pop view from view stack. View object is deleted. |
324 */ |
383 */ |
325 void NmApplication::popView() |
384 void NmApplication::popView() |
326 { |
385 { |
338 if (!mBackButtonPressed) { |
397 if (!mBackButtonPressed) { |
339 mEffects->prepareEffect(NmUiEffects::NmEditorSendMessageAnimation); |
398 mEffects->prepareEffect(NmUiEffects::NmEditorSendMessageAnimation); |
340 } |
399 } |
341 } |
400 } |
342 mBackButtonPressed = false; |
401 mBackButtonPressed = false; |
|
402 |
|
403 // Move the application to background if closing the message list view |
|
404 if (topViewId == NmUiViewMessageList && mViewStack->size() == 1) { |
|
405 hideApplication(); |
|
406 return; |
|
407 } |
|
408 |
343 mViewStack->pop(); |
409 mViewStack->pop(); |
344 // Call custom exit function. |
410 // Call custom exit function. |
345 view->aboutToExitView(); |
411 view->aboutToExitView(); |
346 // Remove view from stack. |
412 // Remove view from stack. |
347 mMainWindow->removeView(view); |
413 mMainWindow->removeView(view); |
420 { |
488 { |
421 NM_FUNCTION; |
489 NM_FUNCTION; |
422 |
490 |
423 // Check the validity of start parameter object. |
491 // Check the validity of start parameter object. |
424 if (startParam) { |
492 if (startParam) { |
|
493 |
|
494 mCurrentMailboxId = startParam->mailboxId(); |
425 |
495 |
426 if (startParam->service() && mMainWindow) { |
496 if (startParam->service() && mMainWindow) { |
427 // When the message list is started as a service previous views |
497 // When the message list is started as a service previous views |
428 // are removed from the stack. Open editors are not closed. Also |
498 // are removed from the stack. Open editors are not closed. Also |
429 // if the view is same than the new one, keep it open (reload the |
499 // if the view is same than the new one, keep it open (reload the |
522 mServiceViewId = mActiveViewId; |
592 mServiceViewId = mActiveViewId; |
523 } |
593 } |
524 } |
594 } |
525 } |
595 } |
526 |
596 |
|
597 |
527 /*! |
598 /*! |
528 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 |
529 cleared. Views can connect exit menu selection to this slot. |
600 cleared. Views can connect exit menu selection to this slot. |
530 */ |
601 */ |
531 void NmApplication::exitApplication() |
602 void NmApplication::exitApplication() |
532 { |
603 { |
533 NM_FUNCTION; |
604 NM_FUNCTION; |
|
605 |
|
606 HbApplication* hbApp = dynamic_cast<HbApplication*>(parent()); |
|
607 hbApp->activityManager()->removeActivity("EmailInboxView"); |
534 |
608 |
535 delete mSendServiceInterface; |
609 delete mSendServiceInterface; |
536 mSendServiceInterface = NULL; |
610 mSendServiceInterface = NULL; |
537 delete mSendServiceInterface2; |
611 delete mSendServiceInterface2; |
538 mSendServiceInterface2 = NULL; |
612 mSendServiceInterface2 = NULL; |
544 mViewerServiceInterface = NULL; |
618 mViewerServiceInterface = NULL; |
545 resetViewStack(); |
619 resetViewStack(); |
546 qApp->quit(); |
620 qApp->quit(); |
547 } |
621 } |
548 |
622 |
|
623 |
549 /*! |
624 /*! |
550 Exit the application in the next event loop. |
625 Exit the application in the next event loop. |
551 */ |
626 */ |
552 void NmApplication::delayedExitApplication() |
627 void NmApplication::delayedExitApplication() |
553 { |
628 { |
554 // Exit the application in the next event loop. |
629 // Exit the application in the next event loop. |
555 QMetaObject::invokeMethod(this, "exitApplication", Qt::QueuedConnection); |
630 QMetaObject::invokeMethod(this, "exitApplication", Qt::QueuedConnection); |
556 } |
631 } |
557 |
632 |
|
633 |
558 /*! |
634 /*! |
559 Getter for main window instance. |
635 Getter for main window instance. |
560 */ |
636 */ |
561 HbMainWindow *NmApplication::mainWindow() |
637 HbMainWindow *NmApplication::mainWindow() |
562 { |
638 { |
563 return mMainWindow; |
639 return mMainWindow; |
564 } |
640 } |
565 |
641 |
|
642 |
566 /*! |
643 /*! |
567 Getter for main UI extension manager. |
644 Getter for main UI extension manager. |
568 */ |
645 */ |
569 NmUiExtensionManager &NmApplication::extManager() |
646 NmUiExtensionManager &NmApplication::extManager() |
570 { |
647 { |
571 return *mExtensionManager; |
648 return *mExtensionManager; |
572 } |
649 } |
573 |
650 |
|
651 |
574 /*! |
652 /*! |
575 Getter for network access manager. |
653 Getter for network access manager. |
576 */ |
654 */ |
577 NmViewerViewNetManager &NmApplication::networkAccessManager() |
655 NmViewerViewNetManager &NmApplication::networkAccessManager() |
578 { |
656 { |
579 return *mNetManager; |
657 return *mNetManager; |
580 } |
658 } |
|
659 |
581 |
660 |
582 /*! |
661 /*! |
583 Get the screen size. Function returns curtent screen size. |
662 Get the screen size. Function returns curtent screen size. |
584 */ |
663 */ |
585 QSize NmApplication::screenSize() |
664 QSize NmApplication::screenSize() |
673 QWindowSurface *surface = mMainWindow->windowSurface(); |
755 QWindowSurface *surface = mMainWindow->windowSurface(); |
674 mForegroundService = (surface != 0); |
756 mForegroundService = (surface != 0); |
675 NM_COMMENT(QString("NmApplication::updateVisibilityState() : mForegroundService == %1").arg(mForegroundService)); |
757 NM_COMMENT(QString("NmApplication::updateVisibilityState() : mForegroundService == %1").arg(mForegroundService)); |
676 return mForegroundService; |
758 return mForegroundService; |
677 } |
759 } |
|
760 |
|
761 |
|
762 /*! |
|
763 Update the thumbnail in the task switcher. |
|
764 */ |
|
765 void NmApplication::updateActivity() |
|
766 { |
|
767 NmMailboxMetaData *meta = mUiEngine->mailboxById(mCurrentMailboxId); |
|
768 HbApplication* hbApp = dynamic_cast<HbApplication*>(parent()); |
|
769 |
|
770 if (hbApp) { |
|
771 if (meta) { |
|
772 TsTaskSettings tasksettings; |
|
773 tasksettings.setVisibility(false); |
|
774 QVariantHash metadata; |
|
775 metadata.insert(ActivityScreenshotKeyword, QPixmap::grabWidget(mainWindow(), mainWindow()->rect())); |
|
776 metadata.insert(ActivityApplicationName, meta->name()); |
|
777 metadata.insert(ActivityVisibility, true); |
|
778 hbApp->activityManager()->removeActivity(NmActivityName); |
|
779 hbApp->activityManager()->addActivity(NmActivityName, QVariant(), metadata); |
|
780 } |
|
781 else { |
|
782 hbApp->activityManager()->removeActivity(NmActivityName); |
|
783 TsTaskSettings tasksettings; |
|
784 tasksettings.setVisibility(true); |
|
785 } |
|
786 } |
|
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 |