24 #include <xqaiwrequest.h> |
24 #include <xqaiwrequest.h> |
25 |
25 |
26 #include <xqsettingsmanager.h> |
26 #include <xqsettingsmanager.h> |
27 #include <xqcentralrepositoryutils.h> |
27 #include <xqcentralrepositoryutils.h> |
28 #include <xqsystemtoneservice.h> |
28 #include <xqsystemtoneservice.h> |
|
29 #include <xqsettingskey.h> |
|
30 #include <ProfileEngineInternalCRKeys.h> |
29 |
31 |
30 // CONSTS |
32 // CONSTS |
31 const int NmAgentIndicatorNotSet = -1; |
33 const int NmAgentIndicatorNotSet = -1; |
32 const int NmAgentAlertToneTimer = 60000; // 60s |
34 const int NmAgentAlertToneTimer = 60000; // 60s |
33 const int NmAgentDefaultVibraDuration = 1000; // 1 second |
35 const int NmAgentDefaultVibraDuration = 1000; // 1 second |
34 static const quint32 NmRepositoryId = 0x2002C326; |
36 static const quint32 NmRepositoryId = 0x2002C326; |
35 static const QString NmMailboxIndicatorType = "com.nokia.nmail.indicatorplugin_%1/1.0"; |
37 static const QString NmMailboxIndicatorType = "com.nokia.nmail.indicatorplugin_%1/1.0"; |
36 static const QString NmSendIndicatorName = "com.nokia.nmail.indicatorplugin.send/1.0"; |
38 static const QString NmSendIndicatorName = "com.nokia.nmail.indicatorplugin.send/1.0"; |
37 static const QString NmUnreadIndicatorName = "com.nokia.nmail.indicatorplugin.unread/1.0"; |
39 static const QString NmUnreadIndicatorName = "com.nokia.nmail.indicatorplugin.unread/1.0"; |
|
40 const XQCentralRepositorySettingsKey NmSilenceModeKey(KCRUidProfileEngine.iUid, KProEngSilenceMode); |
|
41 const int NmSilenceModeOn = 1; |
|
42 |
|
43 /*! |
|
44 Helper method for finding out if XQSettingsKey and XQCentralRepositorySettingsKey points to |
|
45 same key. |
|
46 |
|
47 @param settingKey XQSettingsKey |
|
48 @param cenrepSettingKey XQCentralRepositorySettingsKey |
|
49 @return <code>true</code> if target, uid and key matches otherwise returns <code>false</code> |
|
50 */ |
|
51 bool keysEqual(const XQSettingsKey& settingKey, const XQCentralRepositorySettingsKey& cenrepSettingKey) |
|
52 { |
|
53 return ((settingKey.target() == cenrepSettingKey.target()) && |
|
54 (settingKey.uid() == cenrepSettingKey.uid()) && |
|
55 (settingKey.key() == cenrepSettingKey.key())); |
|
56 } |
38 |
57 |
39 |
58 |
40 /*! |
59 /*! |
41 \class NmMailAgent |
60 \class NmMailAgent |
42 |
61 |
97 if (!mPluginFactory) { |
118 if (!mPluginFactory) { |
98 NM_ERROR(1,"NmMailAgent::init(): PluginFactory not created"); |
119 NM_ERROR(1,"NmMailAgent::init(): PluginFactory not created"); |
99 return false; |
120 return false; |
100 } |
121 } |
101 |
122 |
102 //mSystemTone = new XQSystemToneService(); |
123 // Check status of silent mode. |
103 |
124 delete mSettingManager; |
|
125 mSettingManager = NULL; |
|
126 mSettingManager = new XQSettingsManager(); |
|
127 QVariant silenceMode = mSettingManager->readItemValue(NmSilenceModeKey, |
|
128 XQSettingsManager::TypeInt); |
|
129 mSilenceMode = silenceMode.toInt(); |
|
130 |
|
131 // Start monitoring silence mode key. |
|
132 bool monitoring(mSettingManager->startMonitoring(NmSilenceModeKey, XQSettingsManager::TypeInt)); |
|
133 monitoring &= connect(mSettingManager, |
|
134 SIGNAL(valueChanged(const XQSettingsKey&, const QVariant&)), |
|
135 this, |
|
136 SLOT(valueChanged(const XQSettingsKey&, const QVariant&)), |
|
137 Qt::UniqueConnection); |
|
138 |
|
139 // If silence mode monitoring can't be started, then change silence mode on to be sure |
|
140 // that no tone is played if silence mode is turned on at somepoint. |
|
141 if (!monitoring) { |
|
142 mSilenceMode = NmSilenceModeOn; |
|
143 } |
|
144 |
|
145 delete mSystemTone; |
|
146 mSystemTone = NULL; |
|
147 mSystemTone = new XQSystemToneService(); |
|
148 |
|
149 delete mIndicator; |
|
150 mIndicator = NULL; |
104 mIndicator = new HbIndicator(); |
151 mIndicator = new HbIndicator(); |
105 connect(mIndicator,SIGNAL(userActivated(const QString &, const QVariantMap&)), |
152 connect(mIndicator,SIGNAL(userActivated(const QString &, const QVariantMap&)), |
106 this, SLOT(indicatorActivated(const QString&, const QVariantMap&))); |
153 this, SLOT(indicatorActivated(const QString&, const QVariantMap&))); |
107 |
154 |
108 QList<QObject*> *plugins = mPluginFactory->pluginInstances(); |
155 QList<QObject*> *plugins = mPluginFactory->pluginInstances(); |
426 */ |
481 */ |
427 bool NmMailAgent::launchMailbox(quint64 mailboxId) |
482 bool NmMailAgent::launchMailbox(quint64 mailboxId) |
428 { |
483 { |
429 NM_FUNCTION; |
484 NM_FUNCTION; |
430 |
485 |
|
486 bool ok(false); |
431 XQApplicationManager appManager; |
487 XQApplicationManager appManager; |
432 XQAiwRequest *request = appManager.create( |
488 XQAiwRequest *request = appManager.create( |
433 XQI_EMAIL_INBOX_VIEW, XQOP_EMAIL_INBOX_VIEW, false); |
489 XQI_EMAIL_INBOX_VIEW, XQOP_EMAIL_INBOX_VIEW, false); |
434 |
490 // Instance might be NULL if the service is not available. |
435 QList<QVariant> list; |
491 if (request) { |
436 list.append(QVariant(mailboxId)); |
492 QList<QVariant> list; |
437 request->setArguments(list); |
493 list.append(QVariant(mailboxId)); |
438 |
494 request->setArguments(list); |
439 bool ok = request->send(); |
495 |
440 NM_COMMENT(QString("Launch ok=%1 error=%2").arg(ok).arg(request->lastError())); |
496 ok = request->send(); |
441 delete request; |
497 NM_COMMENT(QString("Launch ok=%1 error=%2").arg(ok).arg(request->lastError())); |
|
498 delete request; |
|
499 } |
442 return ok; |
500 return ok; |
443 } |
501 } |
444 |
502 |
445 /*! |
503 /*! |
446 Get next free indicator index, starting from 0 |
504 Get next free indicator index, starting from 0 |
563 launchMailbox(info->mId.id()); |
623 launchMailbox(info->mId.id()); |
564 } |
624 } |
565 } |
625 } |
566 |
626 |
567 /*! |
627 /*! |
|
628 Called when cenrep key value has been changed. |
|
629 - only silence mode key handled |
|
630 |
|
631 @param key changed key |
|
632 @param value value for a key. |
|
633 */ |
|
634 void NmMailAgent::valueChanged(const XQSettingsKey& key, const QVariant& value) |
|
635 { |
|
636 NM_FUNCTION; |
|
637 |
|
638 if(keysEqual(key, NmSilenceModeKey)) { |
|
639 mSilenceMode = value.toInt(); |
|
640 } |
|
641 } |
|
642 |
|
643 /*! |
568 Received from NmFrameworkAdapter messageEvent signal |
644 Received from NmFrameworkAdapter messageEvent signal |
569 \sa NmFrameworkAdapter |
645 \sa NmFrameworkAdapter |
570 */ |
646 */ |
571 void NmMailAgent::handleMessageEvent( |
647 void NmMailAgent::handleMessageEvent( |
572 NmMessageEvent event, |
648 NmMessageEvent event, |
573 const NmId &folderId, |
649 const NmId &folderId, |
574 const QList<NmId> &messageIds, |
650 const QList<NmId> &messageIds, |
575 const NmId& mailboxId) |
651 const NmId& mailboxId) |
576 { |
652 { |
577 NM_FUNCTION; |
653 NM_FUNCTION; |
|
654 |
578 NM_COMMENT(QString("NmMailAgent::handleMessageEvent(): event=%1, id=%2"). |
655 NM_COMMENT(QString("NmMailAgent::handleMessageEvent(): event=%1, id=%2"). |
579 arg(event).arg(mailboxId.id())); |
656 arg(event).arg(mailboxId.id())); |
580 |
657 |
581 bool updateNeeded = false; |
658 bool updateNeeded = false; |
582 bool activate = false; |
659 bool activate = false; |
583 |
660 |
584 switch (event) { |
661 switch (event) { |
585 case NmMessageCreated: { |
662 case NmMessageCreated: { |
|
663 // Check the new messages to make the indicator appear earlier |
586 NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId); |
664 NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId); |
587 |
665 |
588 // Check the new messages to make the indicator appear earlier |
666 // Inbox folder ID may be still unknown |
589 if (mailboxInfo->mSyncState == Synchronizing) { |
667 if (mailboxInfo->mInboxFolderId.id() == 0) { |
590 |
668 NmDataPluginInterface *plugin = |
591 // Inbox folder ID may be still unknown |
669 mPluginFactory->interfaceInstance(mailboxId); |
592 if (mailboxInfo->mInboxFolderId.id()==0) { |
670 |
593 NmDataPluginInterface *plugin = mPluginFactory->interfaceInstance(mailboxId); |
671 if (plugin) { |
594 if (plugin) { |
672 mailboxInfo->mInboxFolderId = |
595 mailboxInfo->mInboxFolderId = |
673 plugin->getStandardFolderId(mailboxId, NmFolderInbox); |
596 plugin->getStandardFolderId(mailboxId, NmFolderInbox); |
|
597 } |
|
598 } |
674 } |
599 |
675 } |
600 if (folderId == mailboxInfo->mInboxFolderId) { |
676 |
601 foreach (NmId messageId, messageIds) { |
677 if (folderId == mailboxInfo->mInboxFolderId) { |
602 bool messageUnread = false; |
678 foreach (NmId messageId, messageIds) { |
603 |
679 bool messageUnread = false; |
604 // Check the message if we can either play a tone or if the "@" is |
680 |
605 // not visible at the moment |
681 // Check the message if we can either play a tone or if the "@" is |
606 if (mAlertToneAllowed || !mUnreadIndicatorActive) { |
682 // not visible at the moment |
607 if (getMessageUnreadInfo(folderId, messageId, mailboxId, messageUnread)) { |
683 if (mAlertToneAllowed || !mUnreadIndicatorActive) { |
608 if (messageUnread) { |
684 if (getMessageUnreadInfo(folderId, messageId, mailboxId, messageUnread)) { |
609 mailboxInfo->mUnreadMailIdList.append(messageId); |
685 if (messageUnread) { |
610 mailboxInfo->mInboxActive = true; |
686 mailboxInfo->mUnreadMailIdList.append(messageId); |
611 updateMailboxState(mailboxId, true, false); |
687 mailboxInfo->mInboxActive = true; |
612 |
688 updateMailboxState(mailboxId, true, false); |
613 // make the "@" appear immediatelly |
689 |
614 updateUnreadIndicator(true); |
690 // make the "@" appear immediatelly |
615 |
691 updateUnreadIndicator(true); |
616 // Play the tone as well |
692 |
617 playAlertTone(); |
693 // Play the tone as well |
618 } |
694 playAlertTone(); |
619 } |
695 } |
620 } |
696 } |
621 } |
697 } |
622 } |
698 } |
623 } |
699 } |
624 |
700 |
625 if (folderId==mailboxInfo->mInboxFolderId) { |
701 if (folderId==mailboxInfo->mInboxFolderId) { |
626 mailboxInfo->mInboxCreatedMessages += messageIds.count(); |
702 mailboxInfo->mInboxCreatedMessages += messageIds.count(); |
627 } |
703 } |
628 |
704 |
629 // When created a new mail in the outbox, we are in sending state |
705 // When created a new mail in the outbox, we are in sending state |
908 \returns true if the tone was played |
992 \returns true if the tone was played |
909 */ |
993 */ |
910 bool NmMailAgent::playAlertTone() |
994 bool NmMailAgent::playAlertTone() |
911 { |
995 { |
912 NM_FUNCTION; |
996 NM_FUNCTION; |
913 bool played = false; |
997 bool played(false); |
914 |
998 |
915 if (mAlertToneAllowed) { |
999 if (mAlertToneAllowed) { |
916 //mSystemTone->playTone(XQSystemToneService::EmailAlertTone); |
1000 // Play tone only if system tone service is available and |
917 |
1001 // phone is not in silence mode. |
|
1002 if (mSystemTone && !mSilenceMode) { |
|
1003 mSystemTone->playTone(XQSystemToneService::EmailAlertTone); |
|
1004 } |
|
1005 |
918 // Execute the vibra effect. |
1006 // Execute the vibra effect. |
919 if (mVibra) { |
1007 if (mVibra) { |
920 TRAP_IGNORE(mVibra->StartVibraL(NmAgentDefaultVibraDuration)); |
1008 TRAP_IGNORE(mVibra->StartVibraL(NmAgentDefaultVibraDuration)); |
921 } |
1009 } |
922 |
1010 |
923 // play alert only once per minute |
1011 // play alert only once per minute |
924 mAlertToneAllowed = false; |
1012 mAlertToneAllowed = false; |
925 QTimer::singleShot(NmAgentAlertToneTimer, this, SLOT(enableAlertTone())); |
1013 QTimer::singleShot(NmAgentAlertToneTimer, this, SLOT(enableAlertTone())); |
926 played = true; |
1014 played = true; |
927 } |
1015 } |
968 \param mailboxId id of the mailbox |
1058 \param mailboxId id of the mailbox |
969 \param active true if the mailbox is active |
1059 \param active true if the mailbox is active |
970 */ |
1060 */ |
971 void NmMailAgent::storeMailboxActive(const NmId &mailboxId, bool active) |
1061 void NmMailAgent::storeMailboxActive(const NmId &mailboxId, bool active) |
972 { |
1062 { |
973 XQCentralRepositorySettingsKey key(NmRepositoryId, mailboxId.id()); |
1063 NM_FUNCTION; |
974 XQSettingsManager mgr; |
1064 |
975 XQCentralRepositoryUtils utils(mgr); |
1065 if (mSettingManager) { |
976 |
1066 XQCentralRepositorySettingsKey key(NmRepositoryId, mailboxId.id()); |
977 if (active) { |
1067 XQCentralRepositoryUtils utils(*mSettingManager); |
978 // when mailbox is active, key can be deleted |
1068 |
979 utils.deleteKey(key); |
1069 if (active) { |
980 } |
1070 // when mailbox is active, key can be deleted |
981 else { |
1071 utils.deleteKey(key); |
982 utils.createKey(key,(int)active); |
1072 } |
983 } |
1073 else { |
984 } |
1074 utils.createKey(key,(int)active); |
985 |
1075 } |
986 /*! |
1076 } |
987 Get the mailbox activity state. |
1077 } |
|
1078 |
|
1079 /*! |
|
1080 Get the mailbox activity state. |
988 \param mailboxId id of the mailbox |
1081 \param mailboxId id of the mailbox |
989 \return true if the mailbox is active or no information was stored earlier |
1082 \return true if the mailbox is active or no information was stored earlier |
990 */ |
1083 */ |
991 bool NmMailAgent::isMailboxActive(const NmId &mailboxId) |
1084 bool NmMailAgent::isMailboxActive(const NmId &mailboxId) |
992 { |
1085 { |
993 XQCentralRepositorySettingsKey key(NmRepositoryId, mailboxId.id()); |
1086 NM_FUNCTION; |
994 XQSettingsManager mgr; |
1087 |
995 QVariant value = mgr.readItemValue(key,XQSettingsManager::TypeInt); |
1088 bool mailboxActive(true); |
996 if (!value.isValid()) { |
1089 if (mSettingManager) { |
997 // no valid value found, key missing? |
1090 XQCentralRepositorySettingsKey key(NmRepositoryId, mailboxId.id()); |
998 NM_COMMENT("NmMailAgent::isMailboxActive - value not valid"); |
1091 QVariant value = mSettingManager->readItemValue(key, XQSettingsManager::TypeInt); |
999 return true; |
1092 if (value.isValid()) { |
1000 } |
1093 NM_COMMENT(QString("NmMailAgent::isMailboxActive - value=%1").arg(value.toInt())); |
1001 NM_COMMENT(QString("NmMailAgent::isMailboxActive - value=%1").arg(value.toInt())); |
1094 mailboxActive = value.toInt(); |
1002 return value.toInt(); |
1095 } |
|
1096 } |
|
1097 return mailboxActive; |
1003 } |
1098 } |
1004 |
1099 |
1005 /*! |
1100 /*! |
1006 Delete all stored activity information for the mailbox id |
1101 Delete all stored activity information for the mailbox id |
1007 \param mailboxId id of the mailbox |
1102 \param mailboxId id of the mailbox |
1008 */ |
1103 */ |
1009 void NmMailAgent::deleteStoredMailboxActivity(const NmId &mailboxId) |
1104 void NmMailAgent::deleteStoredMailboxActivity(const NmId &mailboxId) |
1010 { |
1105 { |
|
1106 NM_FUNCTION; |
|
1107 |
1011 // deactivation delete the key too |
1108 // deactivation delete the key too |
1012 storeMailboxActive(mailboxId,false); |
1109 storeMailboxActive(mailboxId,false); |
1013 } |
1110 } |
1014 |
1111 |
1015 // End of file |
1112 // End of file |
1016 |
|