14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "nmuiheaders.h" |
18 #include "nmuiheaders.h" |
19 #include <email_services_api.h> |
|
20 #include <e32base.h> |
19 #include <e32base.h> |
21 |
20 |
22 static const QString NmSendServiceName = "nmail.com.nokia.symbian.IFileShare"; |
21 static const QString NmSendServiceName = "nmail.com.nokia.symbian.IFileShare"; |
23 |
|
24 static const QString NmActivityName = "EmailInboxView"; |
22 static const QString NmActivityName = "EmailInboxView"; |
|
23 static const int NmErrorNoteDelay = 300000; |
25 |
24 |
26 /*! |
25 /*! |
27 \class NmApplication |
26 \class NmApplication |
28 \brief Application class, creates main window and handles view switching. |
27 \brief Application class, creates main window and handles view switching. |
29 */ |
28 */ |
30 |
29 |
31 |
30 |
32 /*! |
31 /*! |
33 Constructor. |
32 Constructor. |
34 */ |
33 */ |
35 NmApplication::NmApplication(QObject *parent, quint64 accountId) |
34 NmApplication::NmApplication(int &argc, char *argv[], Hb::ApplicationFlags flags) |
36 : QObject(parent), |
35 : HbApplication(argc,argv,flags), |
37 mMainWindow(NULL), |
36 mMainWindow(NULL), |
38 mViewStack(NULL), |
37 mViewStack(NULL), |
39 mActiveViewId(NmUiViewNone), |
38 mActiveViewId(NmUiViewNone), |
40 mUiEngine(NULL), |
39 mUiEngine(NULL), |
41 mBackAction(NULL), |
40 mBackAction(NULL), |
47 mAttaManager(NULL), |
46 mAttaManager(NULL), |
48 mSettingsViewLauncher(NULL), |
47 mSettingsViewLauncher(NULL), |
49 mViewReady(false), |
48 mViewReady(false), |
50 mQueryDialog(NULL), |
49 mQueryDialog(NULL), |
51 mBackButtonPressed(false), |
50 mBackButtonPressed(false), |
52 mApplicationHidden(false) |
51 mApplicationHidden(false), |
53 { |
52 mErrorNoteTimer(NULL) |
|
53 { |
|
54 // Load the translation file. |
|
55 QTranslator *translator = new QTranslator(this); |
|
56 QString lang = QLocale::system().name(); |
|
57 QString appName = "mail_"; |
|
58 QString path = "Z:/resource/qt/translations/"; |
|
59 translator->load(appName + lang, path); |
|
60 installTranslator(translator); |
|
61 setApplicationName(hbTrId("txt_mail_title_mail")); |
|
62 |
|
63 quint64 accountId = 0; |
|
64 QString activateId = this->activateId(); |
|
65 if (activateReason() == Hb::ActivationReasonActivity && |
|
66 activateId.startsWith(NmActivityName) ) { |
|
67 QString accountIdString = activateId.mid(NmActivityName.length()); |
|
68 accountId = accountIdString.toULongLong(); |
|
69 } |
|
70 |
54 TRAP_IGNORE(mUiEngine = NmUiEngine::instance()); |
71 TRAP_IGNORE(mUiEngine = NmUiEngine::instance()); |
55 |
72 |
56 // Create network access manager and cache for application use. |
73 // Create network access manager and cache for application use. |
57 mNetManager = new NmViewerViewNetManager(*mUiEngine); |
74 mNetManager = new NmViewerViewNetManager(*mUiEngine); |
58 QNetworkDiskCache *cache = new QNetworkDiskCache(); |
75 QNetworkDiskCache *cache = new QNetworkDiskCache(); |
59 cache->setCacheDirectory( |
76 cache->setCacheDirectory( |
60 QDesktopServices::storageLocation(QDesktopServices::CacheLocation)); |
77 QDesktopServices::storageLocation(QDesktopServices::CacheLocation)); |
406 } |
420 } |
407 mBackButtonPressed = false; |
421 mBackButtonPressed = false; |
408 |
422 |
409 // Move the application to background if closing the message list view |
423 // Move the application to background if closing the message list view |
410 if (topViewId == NmUiViewMessageList && mViewStack->size() == 1) { |
424 if (topViewId == NmUiViewMessageList && mViewStack->size() == 1) { |
411 hideApplication(); |
425 |
412 return; |
426 // if the application has been started as embedded service, |
|
427 // we must close it. Otherwise we cannot return back to the calling application. |
|
428 if (!XQServiceUtil::isEmbedded()) { |
|
429 hideApplication(); |
|
430 return; |
|
431 } |
413 } |
432 } |
414 |
433 |
415 mViewStack->pop(); |
434 mViewStack->pop(); |
416 // Call custom exit function. |
435 // Call custom exit function. |
417 view->aboutToExitView(); |
436 view->aboutToExitView(); |
739 mQueryDialog = NmUtilities::displayQuestionNote(hbTrId("txt_mail_dialog_server_settings_incorrect"), |
757 mQueryDialog = NmUtilities::displayQuestionNote(hbTrId("txt_mail_dialog_server_settings_incorrect"), |
740 this, SLOT(launchSettings(HbAction*))); |
758 this, SLOT(launchSettings(HbAction*))); |
741 } |
759 } |
742 // Following applies to all operation/event types. |
760 // Following applies to all operation/event types. |
743 if (event.mCompletionCode == NmConnectionError) { |
761 if (event.mCompletionCode == NmConnectionError) { |
744 NmUtilities::displayWarningNote(hbTrId("txt_mail_dialog_mail_connection_error")); |
762 // Create error note delayer timer when used for the first time |
|
763 if (!mErrorNoteTimer) { |
|
764 mErrorNoteTimer = new QTimer(this); |
|
765 } |
|
766 // Check whether mailbox id has changed, stop |
|
767 // timer in that case and note will be displayed even |
|
768 // before 5min delay has passed |
|
769 if (mLastErrorMailboxId != event.mMailboxId) { |
|
770 mErrorNoteTimer->stop(); |
|
771 } |
|
772 // Store mailbox id |
|
773 mLastErrorMailboxId = event.mMailboxId; |
|
774 // Show error note if timer is not active, e.g 5 minutes |
|
775 // have passed since last "mail connection error". |
|
776 if (!mErrorNoteTimer->isActive()) { |
|
777 NmUtilities::displayErrorNote(hbTrId("txt_mail_dialog_mail_connection_error")); |
|
778 // Start timer with 5 min timeout |
|
779 mErrorNoteTimer->start(NmErrorNoteDelay); |
|
780 } |
745 } |
781 } |
746 } |
782 } |
747 } |
783 } |
748 |
784 |
749 |
785 |
795 Update the thumbnail in the task switcher. |
831 Update the thumbnail in the task switcher. |
796 */ |
832 */ |
797 void NmApplication::updateActivity() |
833 void NmApplication::updateActivity() |
798 { |
834 { |
799 NmMailboxMetaData *meta = mUiEngine->mailboxById(mCurrentMailboxId); |
835 NmMailboxMetaData *meta = mUiEngine->mailboxById(mCurrentMailboxId); |
800 HbApplication* hbApp = dynamic_cast<HbApplication*>(parent()); |
836 |
801 |
837 // This will ensure that when service is started as a embedded service and a mail |
802 if (hbApp) { |
838 // process already exists the task activity will show the embedded service inside the |
803 // This will ensure that when service is started as a embedded service and a mail |
839 // calling processes activity and the already running mail process in its own activity. |
804 // process already exists the task activity will show the embedded service inside the |
840 if(!XQServiceUtil::isService() || !XQServiceUtil::isEmbedded()) { |
805 // calling processes activity and the already running mail process in its own activity. |
841 if (meta) { |
806 if(!XQServiceUtil::isService() || !XQServiceUtil::isEmbedded()) { |
842 TsTaskSettings tasksettings; |
807 if (meta) { |
843 tasksettings.setVisibility(false); |
808 TsTaskSettings tasksettings; |
844 QVariantHash metadata; |
809 tasksettings.setVisibility(false); |
845 metadata.insert(ActivityScreenshotKeyword, QPixmap::grabWidget(mainWindow(), mainWindow()->rect())); |
810 QVariantHash metadata; |
846 metadata.insert(ActivityApplicationName, meta->name()); |
811 metadata.insert(ActivityScreenshotKeyword, QPixmap::grabWidget(mainWindow(), mainWindow()->rect())); |
847 metadata.insert(ActivityVisibility, true); |
812 metadata.insert(ActivityApplicationName, meta->name()); |
848 activityManager()->removeActivity(NmActivityName); |
813 metadata.insert(ActivityVisibility, true); |
849 activityManager()->addActivity(NmActivityName, QVariant(), metadata); |
814 hbApp->activityManager()->removeActivity(NmActivityName); |
850 } |
815 hbApp->activityManager()->addActivity(NmActivityName, QVariant(), metadata); |
851 else { |
816 } |
852 activityManager()->removeActivity(NmActivityName); |
817 else { |
853 TsTaskSettings tasksettings; |
818 hbApp->activityManager()->removeActivity(NmActivityName); |
854 tasksettings.setVisibility(true); |
819 TsTaskSettings tasksettings; |
|
820 tasksettings.setVisibility(true); |
|
821 } |
|
822 } |
855 } |
823 } |
856 } |
824 } |
857 } |
825 |
858 |
826 /*! |
859 /*! |
827 Switch to activated mailbox |
860 Switch to activated mailbox |
828 */ |
861 */ |
829 void NmApplication::activityActivated() |
862 void NmApplication::activityActivated() |
830 { |
863 { |
831 HbApplication* hbApp = dynamic_cast<HbApplication*>(parent()); |
864 quint64 accountId(0); |
832 if (hbApp) { |
865 QString activateId = this->activateId(); |
833 quint64 accountId(0); |
866 if (activateReason() == Hb::ActivationReasonActivity && |
834 QString activateId = hbApp->activateId(); |
867 activateId.startsWith(NmActivityName) ) { |
835 if (hbApp->activateReason() == Hb::ActivationReasonActivity && |
868 QString accountIdString = activateId.mid(NmActivityName.length()); |
836 activateId.startsWith(NmActivityName) ) { |
869 accountId = accountIdString.toULongLong(); |
837 QString accountIdString = activateId.mid(NmActivityName.length()); |
870 QVariant mailbox; |
838 accountId = accountIdString.toULongLong(); |
871 mailbox.setValue(accountId); |
839 QVariant mailbox; |
872 mMailboxServiceInterface->displayInboxByMailboxId(mailbox); |
840 mailbox.setValue(accountId); |
873 } |
841 mMailboxServiceInterface->displayInboxByMailboxId(mailbox); |
874 } |
842 } |
875 |
843 } |
|
844 } |
|
845 |
|