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), |
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 |
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) |
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() |
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 |