45 mServiceViewId(NmUiViewNone), |
45 mServiceViewId(NmUiViewNone), |
46 mForegroundService(false), |
46 mForegroundService(false), |
47 mEffects(NULL), |
47 mEffects(NULL), |
48 mAttaManager(NULL), |
48 mAttaManager(NULL), |
49 mSettingsViewLauncher(NULL), |
49 mSettingsViewLauncher(NULL), |
50 mViewReady(false) |
50 mViewReady(false), |
51 { |
51 mQueryDialog(NULL) |
|
52 { |
|
53 NM_FUNCTION; |
|
54 |
|
55 // TEMPORARY WORKAROUND TO PREVENT PANIC User panic 66, where there is |
|
56 // a PushL call to cleanup stack without any TRAP. |
|
57 #ifdef Q_OS_SYMBIAN |
|
58 TRAP_IGNORE(mUiEngine = NmUiEngine::instance()); |
|
59 #else |
|
60 mUiEngine = NmUiEngine::instance(); |
|
61 #endif |
|
62 |
52 // Create network access manager and cache for application use. |
63 // Create network access manager and cache for application use. |
53 mNetManager = new NmViewerViewNetManager(); |
64 mNetManager = new NmViewerViewNetManager(*mUiEngine); |
54 QNetworkDiskCache *cache = new QNetworkDiskCache(); |
65 QNetworkDiskCache *cache = new QNetworkDiskCache(); |
55 cache->setCacheDirectory(QDesktopServices::storageLocation(QDesktopServices::CacheLocation)); |
66 cache->setCacheDirectory(QDesktopServices::storageLocation(QDesktopServices::CacheLocation)); |
56 mNetManager->setCache(cache); |
67 mNetManager->setCache(cache); |
57 |
68 |
58 // TEMPORARY WORKAROUND TO PREVENT PANIC User panic 66, where there is |
|
59 // a PushL call to cleanup stack without any TRAP. |
|
60 #ifdef Q_OS_SYMBIAN |
|
61 TRAP_IGNORE(mUiEngine = NmUiEngine::instance()); |
|
62 #else |
|
63 mUiEngine = NmUiEngine::instance(); |
|
64 #endif |
|
65 createMainWindow(); |
69 createMainWindow(); |
66 |
70 |
67 // attachment manager can be shared between viewer and editor, ownership in application class |
71 // attachment manager can be shared between viewer and editor, ownership in application class |
68 mAttaManager = new NmAttachmentManager(*mUiEngine); |
72 mAttaManager = new NmAttachmentManager(*mUiEngine); |
69 |
73 |
70 #ifndef NM_WINS_ENV |
74 #ifndef NM_WINS_ENV |
71 mSendServiceInterface = |
75 mSendServiceInterface = |
72 new NmSendServiceInterface(NmSendServiceName, NULL, *mUiEngine, this); |
76 new NmSendServiceInterface(NmSendServiceName, NULL, *mUiEngine, this); |
73 mSendServiceInterface2 = |
77 mSendServiceInterface2 = |
74 new NmSendServiceInterface(emailFullServiceNameSend, NULL, *mUiEngine, this); |
78 new NmSendServiceInterface(emailFullServiceNameSend, NULL, *mUiEngine, this); |
|
79 mUriServiceInterface = |
|
80 new NmUriServiceInterface(NULL, *mUiEngine, this); |
75 mMailboxServiceInterface = |
81 mMailboxServiceInterface = |
76 new NmMailboxServiceInterface(NULL, *mUiEngine, this); |
82 new NmMailboxServiceInterface(NULL, *mUiEngine, this); |
77 mViewerServiceInterface = |
83 mViewerServiceInterface = |
78 new NmViewerServiceInterface(NULL, this, *mUiEngine); |
84 new NmViewerServiceInterface(NULL, this, *mUiEngine); |
79 #endif |
85 #endif |
105 mNetManager->cache()->clear(); |
119 mNetManager->cache()->clear(); |
106 } |
120 } |
107 delete mNetManager; |
121 delete mNetManager; |
108 mNetManager=NULL; |
122 mNetManager=NULL; |
109 } |
123 } |
|
124 // Effects needs to be deleted before MainWindow. |
|
125 delete mEffects; |
110 delete mMainWindow; |
126 delete mMainWindow; |
111 delete mAttaManager; |
127 delete mAttaManager; |
112 delete mEffects; |
|
113 delete mSettingsViewLauncher; |
128 delete mSettingsViewLauncher; |
114 } |
129 } |
115 |
130 |
116 /*! |
131 /*! |
117 Main application window creation |
132 Main application window creation |
118 */ |
133 */ |
119 void NmApplication::createMainWindow() |
134 void NmApplication::createMainWindow() |
120 { |
135 { |
121 NMLOG("nmailui: createMainWindow enter"); |
136 NM_FUNCTION; |
122 |
137 |
123 #ifndef NM_WINS_ENV |
138 #ifndef NM_WINS_ENV |
124 bool service = XQServiceUtil::isService(); |
139 bool service = XQServiceUtil::isService(); |
125 #else |
140 #else |
126 bool service = false; |
141 bool service = false; |
170 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMailboxList); |
185 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMailboxList); |
171 enterNmUiView(startParam); |
186 enterNmUiView(startParam); |
172 } |
187 } |
173 |
188 |
174 // Start to filter main window events to get "end key" event in all possible situations. Using |
189 // Start to filter main window events to get "end key" event in all possible situations. Using |
175 // event() is not enough to catch the event as it is only called if the view widget has the |
190 // event() is not enough to catch the event as it is only called if the view widget has the |
176 // focus. Note: if key capturing (xqkeycapture.h) is required it is probably best to implement |
191 // focus. Note: if key capturing (xqkeycapture.h) is required it is probably best to implement |
177 // an own QMainWindow class and do the capturing there, not in the views. |
192 // an own QMainWindow class and do the capturing there, not in the views. |
178 mMainWindow->installEventFilter(this); |
193 mMainWindow->installEventFilter(this); |
179 } |
194 } |
180 |
195 |
181 /*! |
196 /*! |
182 Slot. React to view ready signal and call |
197 Slot. React to view ready signal and call |
183 current view method. |
198 current view method. |
184 */ |
199 */ |
185 void NmApplication::viewReady() |
200 void NmApplication::viewReady() |
186 { |
201 { |
|
202 NM_FUNCTION; |
|
203 |
187 mViewReady = true; |
204 mViewReady = true; |
188 if (!mViewStack->isEmpty()) { |
205 if (!mViewStack->isEmpty()) { |
189 NmBaseView *currentView = mViewStack->top(); |
206 NmBaseView *currentView = mViewStack->top(); |
190 if (currentView){ |
207 if (currentView){ |
191 currentView->viewReady(); |
208 currentView->viewReady(); |
197 Event filter. End key is filtered from the main window and either the view takes case of the |
214 Event filter. End key is filtered from the main window and either the view takes case of the |
198 or the app is exited by default. |
215 or the app is exited by default. |
199 */ |
216 */ |
200 bool NmApplication::eventFilter(QObject *obj, QEvent *event) |
217 bool NmApplication::eventFilter(QObject *obj, QEvent *event) |
201 { |
218 { |
|
219 NM_FUNCTION; |
|
220 |
202 bool consumed = false; |
221 bool consumed = false; |
203 |
222 |
204 if (obj && obj == mMainWindow && event && event->type() == QEvent::KeyPress) { |
223 if (obj && obj == mMainWindow && event && event->type() == QEvent::KeyPress) { |
205 QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); |
224 QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); |
206 |
225 |
207 if (keyEvent->key() == Qt::Key_No) { // end key, the "red" key |
226 if (keyEvent->key() == Qt::Key_No) { // end key, the "red" key |
208 |
227 |
209 // exit application if no pending operations are on-going |
228 // exit application if no pending operations are on-going |
210 } |
229 } |
211 } |
230 } |
212 |
231 |
213 if (!consumed) { |
232 if (!consumed) { |
214 consumed = QObject::eventFilter(obj, event); |
233 consumed = QObject::eventFilter(obj, event); |
215 } |
234 } |
216 |
235 |
217 return consumed; |
236 return consumed; |
218 } |
237 } |
219 |
238 |
220 /*! |
239 /*! |
221 Push view to view stack |
240 Push view to view stack |
222 */ |
241 */ |
223 void NmApplication::pushView(NmBaseView *newView) |
242 void NmApplication::pushView(NmBaseView *newView) |
224 { |
243 { |
225 NMLOG("nmailui: pushView enter"); |
244 NM_FUNCTION; |
|
245 |
226 if (newView) { |
246 if (newView) { |
227 NMLOG("nmailui: view exists"); |
247 NM_COMMENT("nmailui: view exists"); |
228 newView->setNavigationAction(mBackAction); |
248 newView->setNavigationAction(mBackAction); |
229 |
249 |
230 // Store view to be hidden |
250 // Store view to be hidden |
231 NmBaseView *hideView(NULL); |
251 NmBaseView *hideView(NULL); |
232 if (!mViewStack->isEmpty()) { |
252 if (!mViewStack->isEmpty()) { |
356 /*! |
377 /*! |
357 Reset view stack. Remove and destroy view objects. |
378 Reset view stack. Remove and destroy view objects. |
358 */ |
379 */ |
359 void NmApplication::resetViewStack() |
380 void NmApplication::resetViewStack() |
360 { |
381 { |
361 NMLOG("nmailui: resetViewStack enter"); |
382 NM_FUNCTION; |
|
383 |
362 if (mViewStack && !mViewStack->isEmpty()) { |
384 if (mViewStack && !mViewStack->isEmpty()) { |
363 int viewCount = mViewStack->count(); |
385 int viewCount = mViewStack->count(); |
364 // Pop and destroy all views |
386 // Pop and destroy all views |
365 for (int i=0;i<viewCount;i++) { |
387 for (int i=0;i<viewCount;i++) { |
366 NmBaseView *view = mViewStack->pop(); |
388 NmBaseView *view = mViewStack->pop(); |
376 If requested view is already open, it is requested to reload. |
398 If requested view is already open, it is requested to reload. |
377 Otherwise view object is created and pushed to view stack |
399 Otherwise view object is created and pushed to view stack |
378 */ |
400 */ |
379 void NmApplication::enterNmUiView(NmUiStartParam* startParam) |
401 void NmApplication::enterNmUiView(NmUiStartParam* startParam) |
380 { |
402 { |
|
403 NM_FUNCTION; |
|
404 |
381 // Check the validity of start parameter object |
405 // Check the validity of start parameter object |
382 if (startParam) { |
406 if (startParam) { |
383 |
407 |
384 if (startParam->service() && mMainWindow) { |
408 if (startParam->service() && mMainWindow) { |
385 // Store the visibility state when the service was launched |
|
386 mForegroundService = mMainWindow->isVisible(); |
|
387 |
|
388 // When the message list is started as a service previous views are removed |
409 // When the message list is started as a service previous views are removed |
389 // from the stack. Open editors are not closed. |
410 // from the stack. Open editors are not closed. |
390 // Also if the view is same than the new one, keep it open (reload the content). |
411 // Also if the view is same than the new one, keep it open (reload the content). |
391 |
412 |
392 // at least one view must remain in the stack |
413 // at least one view must remain in the stack |
427 // a new mail list view |
448 // a new mail list view |
428 if (startParam->service() && !mViewStack->isEmpty() && |
449 if (startParam->service() && !mViewStack->isEmpty() && |
429 mViewStack->top()->nmailViewId()==NmUiViewMessageEditor) { |
450 mViewStack->top()->nmailViewId()==NmUiViewMessageEditor) { |
430 break; |
451 break; |
431 } |
452 } |
432 NmMessageListModel &messageListModel = mUiEngine->messageListModel( |
453 NmMessageListModel *messageListModel = &mUiEngine->messageListModel( |
433 startParam->mailboxId(), startParam->folderId()); |
454 startParam->mailboxId(), startParam->folderId()); |
434 NmMessageListView *msgList =new NmMessageListView( |
455 NmMessageListView *msgList =new NmMessageListView( |
435 *this, startParam, *mUiEngine, *mMbListModel, messageListModel, |
456 *this, startParam, *mUiEngine, *mMbListModel, messageListModel, |
436 new HbDocumentLoader(mMainWindow)); |
457 new HbDocumentLoader(mMainWindow)); |
437 pushView(msgList); |
458 pushView(msgList); |
439 break; |
460 break; |
440 case NmUiViewMessageSearchList: |
461 case NmUiViewMessageSearchList: |
441 { |
462 { |
442 // Check the topmost view. If it is an editor, do not open |
463 // Check the topmost view. If it is an editor, do not open |
443 // a new mail search list view. |
464 // a new mail search list view. |
444 if (startParam->service() && !mViewStack->isEmpty() && |
465 if (startParam->service() && !mViewStack->isEmpty() && |
445 mViewStack->top()->nmailViewId() == NmUiViewMessageEditor) { |
466 mViewStack->top()->nmailViewId() == NmUiViewMessageEditor) { |
446 break; |
467 break; |
447 } |
468 } |
448 |
469 |
449 NmMessageListModel &model = |
470 NmMessageListModel &model = |
455 |
476 |
456 pushView(searchListView); |
477 pushView(searchListView); |
457 } |
478 } |
458 break; |
479 break; |
459 case NmUiViewMessageViewer: |
480 case NmUiViewMessageViewer: |
460 pushView(new NmViewerView(*this, startParam, *mUiEngine, |
481 pushView(new NmViewerView(*this, startParam, *mUiEngine, |
461 mMainWindow, *mAttaManager)); |
482 mMainWindow, *mAttaManager)); |
462 break; |
483 break; |
463 case NmUiViewMessageEditor: |
484 case NmUiViewMessageEditor: |
464 pushView(new NmEditorView(*this, startParam, *mUiEngine)); |
485 pushView(new NmEditorView(*this, startParam, *mUiEngine, *mAttaManager)); |
465 break; |
486 break; |
466 default: |
487 default: |
467 // Reset view stack and exit application |
488 // Reset view stack and exit application |
468 delete startParam; |
489 delete startParam; |
469 startParam=NULL; |
490 startParam=NULL; |
484 View stack is cleared. Views can connect exit menu |
505 View stack is cleared. Views can connect exit menu |
485 selection to this slot. |
506 selection to this slot. |
486 */ |
507 */ |
487 void NmApplication::exitApplication() |
508 void NmApplication::exitApplication() |
488 { |
509 { |
489 NMLOG("NmApplication::exitApplication"); |
510 NM_FUNCTION; |
|
511 |
490 #ifndef NM_WINS_ENV |
512 #ifndef NM_WINS_ENV |
491 delete mSendServiceInterface; |
513 delete mSendServiceInterface; |
492 mSendServiceInterface = NULL; |
514 mSendServiceInterface = NULL; |
493 delete mSendServiceInterface2; |
515 delete mSendServiceInterface2; |
494 mSendServiceInterface2 = NULL; |
516 mSendServiceInterface2 = NULL; |
|
517 delete mUriServiceInterface; |
|
518 mUriServiceInterface = NULL; |
495 delete mMailboxServiceInterface; |
519 delete mMailboxServiceInterface; |
496 mMailboxServiceInterface = NULL; |
520 mMailboxServiceInterface = NULL; |
497 delete mViewerServiceInterface; |
521 delete mViewerServiceInterface; |
498 mViewerServiceInterface = NULL; |
522 mViewerServiceInterface = NULL; |
499 #endif |
523 #endif |
505 /*! |
529 /*! |
506 Exit the application in the next event loop |
530 Exit the application in the next event loop |
507 */ |
531 */ |
508 void NmApplication::delayedExitApplication() |
532 void NmApplication::delayedExitApplication() |
509 { |
533 { |
510 NMLOG("NmApplication::delayedExitApplication"); |
534 NM_FUNCTION; |
|
535 |
511 // Exit the application in the next event loop |
536 // Exit the application in the next event loop |
512 QTimer::singleShot(0, this, SLOT(exitApplication())); |
537 QTimer::singleShot(0, this, SLOT(exitApplication())); |
513 } |
538 } |
514 |
539 |
515 /*! |
540 /*! |
516 Getter for main window instance. |
541 Getter for main window instance. |
517 */ |
542 */ |
518 HbMainWindow* NmApplication::mainWindow() |
543 HbMainWindow* NmApplication::mainWindow() |
519 { |
544 { |
|
545 NM_FUNCTION; |
|
546 |
520 return mMainWindow; |
547 return mMainWindow; |
521 } |
548 } |
522 |
549 |
523 /*! |
550 /*! |
524 Getter for main UI extension manager |
551 Getter for main UI extension manager |
525 */ |
552 */ |
526 NmUiExtensionManager& NmApplication::extManager() |
553 NmUiExtensionManager& NmApplication::extManager() |
527 { |
554 { |
|
555 NM_FUNCTION; |
|
556 |
528 return *mExtensionManager; |
557 return *mExtensionManager; |
529 } |
558 } |
530 |
559 |
531 /*! |
560 /*! |
532 Getter for network access manager |
561 Getter for network access manager |
533 */ |
562 */ |
534 NmViewerViewNetManager& NmApplication::networkAccessManager() |
563 NmViewerViewNetManager& NmApplication::networkAccessManager() |
535 { |
564 { |
|
565 NM_FUNCTION; |
|
566 |
536 return *mNetManager; |
567 return *mNetManager; |
537 } |
568 } |
538 |
569 |
539 /*! |
570 /*! |
540 screen size. Function returns curtent screen size |
571 screen size. Function returns curtent screen size |
541 */ |
572 */ |
542 QSize NmApplication::screenSize() |
573 QSize NmApplication::screenSize() |
543 { |
574 { |
|
575 NM_FUNCTION; |
|
576 |
544 QSize ret(0,0); |
577 QSize ret(0,0); |
545 if (mMainWindow){ |
578 if (mMainWindow){ |
546 HbDeviceProfile currentP = HbDeviceProfile::current(); |
579 HbDeviceProfile currentP = HbDeviceProfile::current(); |
547 HbDeviceProfile altP(currentP.alternateProfileName()); |
580 HbDeviceProfile altP(currentP.alternateProfileName()); |
548 QSize curPSize = currentP.logicalSize(); |
581 QSize curPSize = currentP.logicalSize(); |
572 /*! |
605 /*! |
573 handles all asynchronous operation's completions at UI level |
606 handles all asynchronous operation's completions at UI level |
574 */ |
607 */ |
575 void NmApplication::handleOperationCompleted(const NmOperationCompletionEvent &event) |
608 void NmApplication::handleOperationCompleted(const NmOperationCompletionEvent &event) |
576 { |
609 { |
577 bool openSettings = NmUtilities::displayOperationCompletionNote(event); |
610 NM_FUNCTION; |
578 if(openSettings) { |
611 |
579 launchSettings(event.mMailboxId); |
612 if(event.mCompletionCode != NmNoError && event.mCompletionCode != NmCancelError) { |
|
613 if(event.mOperationType == Synch && event.mCompletionCode == NmAuthenticationError) { |
|
614 mLastOperationMailbox=event.mMailboxId; |
|
615 if (mQueryDialog){ |
|
616 delete mQueryDialog; |
|
617 mQueryDialog=NULL; |
|
618 } |
|
619 mQueryDialog = NmUtilities::displayQuestionNote(hbTrId("txt_mail_dialog_address_or_password_incorrect"), |
|
620 this, SLOT(launchSettings(HbAction*))); |
|
621 } |
|
622 if(event.mOperationType == Synch && event.mCompletionCode == NmServerConnectionError) { |
|
623 mLastOperationMailbox=event.mMailboxId; |
|
624 if (mQueryDialog){ |
|
625 delete mQueryDialog; |
|
626 mQueryDialog=NULL; |
|
627 } |
|
628 mQueryDialog = NmUtilities::displayQuestionNote(hbTrId("txt_mail_dialog_server_settings_incorrect"), |
|
629 this, SLOT(launchSettings(HbAction*))); |
|
630 } |
|
631 // following applies to all operation/event types |
|
632 if(event.mCompletionCode == NmConnectionError) { |
|
633 NmUtilities::displayWarningNote(hbTrId("txt_mail_dialog_mail_connection_error")); |
|
634 } |
580 } |
635 } |
581 } |
636 } |
582 |
637 |
583 /*! |
638 /*! |
584 launches settings view of the specified mailbox |
639 launches settings view of the specified mailbox |
585 */ |
640 */ |
586 void NmApplication::launchSettings(const NmId &mailboxId) |
641 void NmApplication::launchSettings(HbAction* action) |
587 { |
642 { |
588 // create settingslauncher if doesn't exist |
643 NM_FUNCTION; |
589 if(!mSettingsViewLauncher) { |
644 |
590 mSettingsViewLauncher = new NmSettingsViewLauncher(); |
645 // Check whether yes button was pressed |
591 } |
646 if (mQueryDialog&& action == mQueryDialog->actions().at(0)) { |
592 |
647 // create settingslauncher if doesn't exist |
593 if(mSettingsViewLauncher) { |
648 if(!mSettingsViewLauncher) { |
594 // mailboxname required |
649 mSettingsViewLauncher = new NmSettingsViewLauncher(); |
595 NmMailboxMetaData *mailboxMetaData = mUiEngine->mailboxById(mailboxId); // no ownership |
650 } |
596 if( mailboxMetaData ) { |
651 |
597 // launch |
652 if(mSettingsViewLauncher) { |
598 mSettingsViewLauncher->launchSettingsView(mailboxId, mailboxMetaData->name()); |
653 // mailboxname required |
599 } |
654 NmMailboxMetaData *mailboxMetaData = mUiEngine->mailboxById(mLastOperationMailbox); // no ownership |
600 } |
655 if( mailboxMetaData ) { |
601 } |
656 // launch |
|
657 mSettingsViewLauncher->launchSettingsView(mLastOperationMailbox, mailboxMetaData->name()); |
|
658 } |
|
659 } |
|
660 } |
|
661 } |
|
662 |
|
663 /*! |
|
664 Stores the visibility state, e.g. when the service was launched. |
|
665 \return true if the app was visible |
|
666 */ |
|
667 bool NmApplication::updateVisibilityState() |
|
668 { |
|
669 // At the moment there is no good way to check the foreground state |
|
670 QWindowSurface *surface = mMainWindow->windowSurface(); |
|
671 mForegroundService = (surface != NULL); |
|
672 NM_COMMENT(QString("NmApplication::updateVisibilityState fg=%1").arg(mForegroundService)); |
|
673 return mForegroundService; |
|
674 } |