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 |
|
123 // Check status of silent mode. |
|
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; |
102 mSystemTone = new XQSystemToneService(); |
147 mSystemTone = new XQSystemToneService(); |
103 |
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(); |
294 Get list of unread counts in active mailboxes |
346 Get list of unread counts in active mailboxes |
295 \returns total number of unread mails |
347 \returns total number of unread mails |
296 */ |
348 */ |
297 int NmMailAgent::getTotalUnreadCount() const |
349 int NmMailAgent::getTotalUnreadCount() const |
298 { |
350 { |
|
351 NM_FUNCTION; |
|
352 |
299 int unreads = 0; |
353 int unreads = 0; |
300 foreach (const NmMailboxInfo *mailbox, mMailboxes) { |
354 foreach (const NmMailboxInfo *mailbox, mMailboxes) { |
301 if (mailbox->mActive && mailbox->mInboxActive) { |
355 if (mailbox->mActive && mailbox->mInboxActive) { |
302 unreads += mailbox->mUnreadMailIdList.count(); |
356 unreads += mailbox->mUnreadMailIdList.count(); |
303 } |
357 } |
528 Map the type name to mailbox info |
584 Map the type name to mailbox info |
529 \return NULL if no mailbox match the type |
585 \return NULL if no mailbox match the type |
530 */ |
586 */ |
531 NmMailboxInfo *NmMailAgent::getMailboxByType(const QString &type) |
587 NmMailboxInfo *NmMailAgent::getMailboxByType(const QString &type) |
532 { |
588 { |
|
589 NM_FUNCTION; |
|
590 |
533 foreach (NmMailboxInfo *mailbox, mMailboxes) { |
591 foreach (NmMailboxInfo *mailbox, mMailboxes) { |
534 // mailbox is shown in indicators |
592 // mailbox is shown in indicators |
535 if (mailbox->mIndicatorIndex >= 0 && mailbox->mActive) { |
593 if (mailbox->mIndicatorIndex >= 0 && mailbox->mActive) { |
536 QString typeName = QString(NmMailboxIndicatorType).arg(mailbox->mIndicatorIndex); |
594 QString typeName = QString(NmMailboxIndicatorType).arg(mailbox->mIndicatorIndex); |
537 |
595 |
565 launchMailbox(info->mId.id()); |
623 launchMailbox(info->mId.id()); |
566 } |
624 } |
567 } |
625 } |
568 |
626 |
569 /*! |
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 /*! |
570 Received from NmFrameworkAdapter messageEvent signal |
644 Received from NmFrameworkAdapter messageEvent signal |
571 \sa NmFrameworkAdapter |
645 \sa NmFrameworkAdapter |
572 */ |
646 */ |
573 void NmMailAgent::handleMessageEvent( |
647 void NmMailAgent::handleMessageEvent( |
574 NmMessageEvent event, |
648 NmMessageEvent event, |
575 const NmId &folderId, |
649 const NmId &folderId, |
576 const QList<NmId> &messageIds, |
650 const QList<NmId> &messageIds, |
577 const NmId& mailboxId) |
651 const NmId& mailboxId) |
578 { |
652 { |
579 NM_FUNCTION; |
653 NM_FUNCTION; |
|
654 |
580 NM_COMMENT(QString("NmMailAgent::handleMessageEvent(): event=%1, id=%2"). |
655 NM_COMMENT(QString("NmMailAgent::handleMessageEvent(): event=%1, id=%2"). |
581 arg(event).arg(mailboxId.id())); |
656 arg(event).arg(mailboxId.id())); |
582 |
657 |
583 bool updateNeeded = false; |
658 bool updateNeeded = false; |
584 bool activate = false; |
659 bool activate = false; |
917 \returns true if the tone was played |
992 \returns true if the tone was played |
918 */ |
993 */ |
919 bool NmMailAgent::playAlertTone() |
994 bool NmMailAgent::playAlertTone() |
920 { |
995 { |
921 NM_FUNCTION; |
996 NM_FUNCTION; |
922 bool played = false; |
997 bool played(false); |
923 |
998 |
924 if (mAlertToneAllowed) { |
999 if (mAlertToneAllowed) { |
925 if (mSystemTone) { |
1000 // Play tone only if system tone service is available and |
|
1001 // phone is not in silence mode. |
|
1002 if (mSystemTone && !mSilenceMode) { |
926 mSystemTone->playTone(XQSystemToneService::EmailAlertTone); |
1003 mSystemTone->playTone(XQSystemToneService::EmailAlertTone); |
927 } |
1004 } |
928 |
1005 |
929 // Execute the vibra effect. |
1006 // Execute the vibra effect. |
930 if (mVibra) { |
1007 if (mVibra) { |
979 \param mailboxId id of the mailbox |
1058 \param mailboxId id of the mailbox |
980 \param active true if the mailbox is active |
1059 \param active true if the mailbox is active |
981 */ |
1060 */ |
982 void NmMailAgent::storeMailboxActive(const NmId &mailboxId, bool active) |
1061 void NmMailAgent::storeMailboxActive(const NmId &mailboxId, bool active) |
983 { |
1062 { |
984 XQCentralRepositorySettingsKey key(NmRepositoryId, mailboxId.id()); |
1063 NM_FUNCTION; |
985 XQSettingsManager mgr; |
1064 |
986 XQCentralRepositoryUtils utils(mgr); |
1065 if (mSettingManager) { |
987 |
1066 XQCentralRepositorySettingsKey key(NmRepositoryId, mailboxId.id()); |
988 if (active) { |
1067 XQCentralRepositoryUtils utils(*mSettingManager); |
989 // when mailbox is active, key can be deleted |
1068 |
990 utils.deleteKey(key); |
1069 if (active) { |
991 } |
1070 // when mailbox is active, key can be deleted |
992 else { |
1071 utils.deleteKey(key); |
993 utils.createKey(key,(int)active); |
1072 } |
|
1073 else { |
|
1074 utils.createKey(key,(int)active); |
|
1075 } |
994 } |
1076 } |
995 } |
1077 } |
996 |
1078 |
997 /*! |
1079 /*! |
998 Get the mailbox activity state. |
1080 Get the mailbox activity state. |
999 \param mailboxId id of the mailbox |
1081 \param mailboxId id of the mailbox |
1000 \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 |
1001 */ |
1083 */ |
1002 bool NmMailAgent::isMailboxActive(const NmId &mailboxId) |
1084 bool NmMailAgent::isMailboxActive(const NmId &mailboxId) |
1003 { |
1085 { |
1004 XQCentralRepositorySettingsKey key(NmRepositoryId, mailboxId.id()); |
1086 NM_FUNCTION; |
1005 XQSettingsManager mgr; |
1087 |
1006 QVariant value = mgr.readItemValue(key,XQSettingsManager::TypeInt); |
1088 bool mailboxActive(true); |
1007 if (!value.isValid()) { |
1089 if (mSettingManager) { |
1008 // no valid value found, key missing? |
1090 XQCentralRepositorySettingsKey key(NmRepositoryId, mailboxId.id()); |
1009 NM_COMMENT("NmMailAgent::isMailboxActive - value not valid"); |
1091 QVariant value = mSettingManager->readItemValue(key, XQSettingsManager::TypeInt); |
1010 return true; |
1092 if (value.isValid()) { |
1011 } |
1093 NM_COMMENT(QString("NmMailAgent::isMailboxActive - value=%1").arg(value.toInt())); |
1012 NM_COMMENT(QString("NmMailAgent::isMailboxActive - value=%1").arg(value.toInt())); |
1094 mailboxActive = value.toInt(); |
1013 return value.toInt(); |
1095 } |
|
1096 } |
|
1097 return mailboxActive; |
1014 } |
1098 } |
1015 |
1099 |
1016 /*! |
1100 /*! |
1017 Delete all stored activity information for the mailbox id |
1101 Delete all stored activity information for the mailbox id |
1018 \param mailboxId id of the mailbox |
1102 \param mailboxId id of the mailbox |
1019 */ |
1103 */ |
1020 void NmMailAgent::deleteStoredMailboxActivity(const NmId &mailboxId) |
1104 void NmMailAgent::deleteStoredMailboxActivity(const NmId &mailboxId) |
1021 { |
1105 { |
|
1106 NM_FUNCTION; |
|
1107 |
1022 // deactivation delete the key too |
1108 // deactivation delete the key too |
1023 storeMailboxActive(mailboxId,false); |
1109 storeMailboxActive(mailboxId,false); |
1024 } |
1110 } |
1025 |
1111 |
1026 // End of file |
1112 // End of file |
1027 |
|