13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include <xqservicerequest.h> |
|
19 #include <email_services_api.h> |
|
20 |
|
21 #include "emailtrace.h" |
18 #include "emailtrace.h" |
22 #include "nmmailagentheaders.h" |
19 #include "nmmailagentheaders.h" |
23 #include "nmmailagent.h" |
20 #include "nmmailagent.h" |
24 |
21 |
|
22 #include <xqaiwdeclplat.h> |
|
23 #include <xqapplicationmanager.h> |
|
24 #include <xqaiwrequest.h> |
|
25 |
|
26 #include <xqsettingsmanager.h> |
|
27 #include <xqcentralrepositoryutils.h> |
25 #include <xqsystemtoneservice.h> |
28 #include <xqsystemtoneservice.h> |
26 |
29 |
27 // CONSTS |
30 // CONSTS |
28 const int NmAgentIndicatorNotSet = -1; |
31 const int NmAgentIndicatorNotSet = -1; |
29 const int NmAgentAlertToneTimer = 60000; // 60s |
32 const int NmAgentAlertToneTimer = 60000; // 60s |
|
33 const int NmAgentDefaultVibraDuration = 1000; // 1 second |
|
34 static const quint32 NmRepositoryId = 0x2002C326; |
30 static const QString NmMailboxIndicatorType = "com.nokia.nmail.indicatorplugin_%1/1.0"; |
35 static const QString NmMailboxIndicatorType = "com.nokia.nmail.indicatorplugin_%1/1.0"; |
31 static const QString NmSendIndicatorName = "com.nokia.nmail.indicatorplugin.send/1.0"; |
36 static const QString NmSendIndicatorName = "com.nokia.nmail.indicatorplugin.send/1.0"; |
32 static const QString NmUnreadIndicatorName = "com.nokia.nmail.indicatorplugin.unread/1.0"; |
37 static const QString NmUnreadIndicatorName = "com.nokia.nmail.indicatorplugin.unread/1.0"; |
33 |
38 |
34 |
39 |
121 this, SLOT(handleConnectionEvent(NmConnectState, const NmId, int)), |
128 this, SLOT(handleConnectionEvent(NmConnectState, const NmId, int)), |
122 Qt::UniqueConnection); |
129 Qt::UniqueConnection); |
123 } |
130 } |
124 } |
131 } |
125 |
132 |
|
133 // Construct the vibra interface instance. |
|
134 TRAP_IGNORE(mVibra = CHWRMVibra::NewL()); |
|
135 |
126 // load all current mailboxes |
136 // load all current mailboxes |
127 initMailboxStatus(); |
137 initMailboxStatus(); |
128 |
138 |
129 return true; |
139 return true; |
130 } |
140 } |
131 |
141 |
132 NmMailAgent::~NmMailAgent() |
142 NmMailAgent::~NmMailAgent() |
133 { |
143 { |
134 NM_FUNCTION; |
144 NM_FUNCTION; |
135 |
145 |
|
146 delete mVibra; |
|
147 //delete mSystemTone; |
|
148 |
136 qDeleteAll(mMailboxes); |
149 qDeleteAll(mMailboxes); |
|
150 |
137 //delete mSystemTone; |
151 //delete mSystemTone; |
138 NmDataPluginFactory::releaseInstance(mPluginFactory); |
152 NmDataPluginFactory::releaseInstance(mPluginFactory); |
139 } |
153 } |
140 |
154 |
141 /*! |
155 /*! |
164 const NmMailbox *mailbox = i.previous(); |
178 const NmMailbox *mailbox = i.previous(); |
165 if (mailbox) { |
179 if (mailbox) { |
166 NmMailboxInfo *mailboxInfo = createMailboxInfo(*mailbox,plugin); |
180 NmMailboxInfo *mailboxInfo = createMailboxInfo(*mailbox,plugin); |
167 if (mailboxInfo) { |
181 if (mailboxInfo) { |
168 bool activate = updateUnreadCount(mailbox->id(), *mailboxInfo); |
182 bool activate = updateUnreadCount(mailbox->id(), *mailboxInfo); |
|
183 bool wasActive = isMailboxActive(mailbox->id()); |
|
184 if (activate) { |
|
185 if(!wasActive) { |
|
186 // do not activate the mailbox if it was left as hidden last time |
|
187 activate = false; |
|
188 } |
|
189 else { |
|
190 // otherwise, activate the mailbox and show inbox state |
|
191 mailboxInfo->mInboxActive = true; |
|
192 } |
|
193 } |
|
194 |
169 mailboxInfo->mOutboxMails = getOutboxCount(mailbox->id()); |
195 mailboxInfo->mOutboxMails = getOutboxCount(mailbox->id()); |
170 if (mailboxInfo->mOutboxMails > 0) { |
196 if (mailboxInfo->mOutboxMails > 0 && wasActive) { |
171 activate = true; |
197 activate = true; |
172 } |
198 } |
173 |
199 |
174 // Create indicator for visible mailboxes |
200 // Create indicator for visible mailboxes |
175 updateMailboxState(mailbox->id(), |
201 updateMailboxState(mailbox->id(), activate, false); |
176 activate, false); |
|
177 } |
202 } |
178 } |
203 } |
179 } |
204 } |
180 qDeleteAll(mailboxes); |
205 qDeleteAll(mailboxes); |
181 } |
206 } |
|
207 updateUnreadIndicator(); |
182 updateSendIndicator(); |
208 updateSendIndicator(); |
183 } |
209 } |
184 |
210 |
185 /*! |
211 /*! |
186 Get mailbox unread count in inbox folder |
212 Get mailbox unread count in inbox folder |
304 |
330 |
305 NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId); |
331 NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId); |
306 bool changed = false; |
332 bool changed = false; |
307 if (mailboxInfo->mActive != active || |
333 if (mailboxInfo->mActive != active || |
308 refreshAlways) { |
334 refreshAlways) { |
|
335 |
|
336 // store the new state to permanent storage |
|
337 storeMailboxActive(mailboxId, active); |
|
338 |
309 mailboxInfo->mActive = active; |
339 mailboxInfo->mActive = active; |
310 changed = true; |
340 changed = true; |
311 if (active) { |
341 if (active) { |
312 // Mailbox is not yet assigned to any indicator |
342 // Mailbox is not yet assigned to any indicator |
313 if (mailboxInfo->mIndicatorIndex < 0) { |
343 if (mailboxInfo->mIndicatorIndex < 0) { |
396 */ |
426 */ |
397 bool NmMailAgent::launchMailbox(quint64 mailboxId) |
427 bool NmMailAgent::launchMailbox(quint64 mailboxId) |
398 { |
428 { |
399 NM_FUNCTION; |
429 NM_FUNCTION; |
400 |
430 |
401 XQServiceRequest request( |
431 XQApplicationManager appManager; |
402 emailFullServiceNameMailbox, |
432 XQAiwRequest *request = appManager.create( |
403 emailOperationViewInbox, |
433 XQI_EMAIL_INBOX_VIEW, XQOP_EMAIL_INBOX_VIEW, false); |
404 true); |
434 |
405 |
|
406 QList<QVariant> list; |
435 QList<QVariant> list; |
407 list.append(QVariant(mailboxId)); |
436 list.append(QVariant(mailboxId)); |
408 |
437 request->setArguments(list); |
409 request.setArguments(list); |
438 |
410 bool ok = request.send(); |
439 bool ok = request->send(); |
411 NM_COMMENT(QString("Launch ok=%1 error=%2").arg(ok).arg(request.latestError())); |
440 NM_COMMENT(QString("Launch ok=%1 error=%2").arg(ok).arg(request->lastError())); |
|
441 delete request; |
412 return ok; |
442 return ok; |
413 } |
443 } |
414 |
444 |
415 /*! |
445 /*! |
416 Get next free indicator index, starting from 0 |
446 Get next free indicator index, starting from 0 |
547 switch (event) { |
584 switch (event) { |
548 case NmMessageCreated: { |
585 case NmMessageCreated: { |
549 NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId); |
586 NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId); |
550 |
587 |
551 // Check the new messages to make the indicator appear earlier |
588 // Check the new messages to make the indicator appear earlier |
552 if (mailboxInfo->mSyncState == Synchronizing && |
589 if (mailboxInfo->mSyncState == Synchronizing) { |
553 mailboxInfo->mUnreadMailIdList.count()==0) { |
590 |
554 |
|
555 // Inbox folder ID may be still unknown |
591 // Inbox folder ID may be still unknown |
556 if (mailboxInfo->mInboxFolderId.id()==0) { |
592 if (mailboxInfo->mInboxFolderId.id()==0) { |
557 NmDataPluginInterface *plugin = mPluginFactory->interfaceInstance(mailboxId); |
593 NmDataPluginInterface *plugin = mPluginFactory->interfaceInstance(mailboxId); |
558 if (plugin) { |
594 if (plugin) { |
559 mailboxInfo->mInboxFolderId = |
595 mailboxInfo->mInboxFolderId = |
560 plugin->getStandardFolderId(mailboxId, NmFolderInbox); |
596 plugin->getStandardFolderId(mailboxId, NmFolderInbox); |
561 } |
597 } |
562 } |
598 } |
563 |
599 |
564 if (folderId == mailboxInfo->mInboxFolderId) { |
600 if (folderId == mailboxInfo->mInboxFolderId) { |
565 bool messageUnread = false; |
|
566 foreach (NmId messageId, messageIds) { |
601 foreach (NmId messageId, messageIds) { |
567 if (getMessageUnreadInfo(folderId, messageId, mailboxId, messageUnread)) { |
602 bool messageUnread = false; |
568 if (messageUnread) { |
603 |
569 mailboxInfo->mUnreadMailIdList.append(messageId); |
604 // Check the message if we can either play a tone or if the "@" is |
570 updateMailboxState(mailboxId, true, false); |
605 // not visible at the moment |
571 |
606 if (mAlertToneAllowed || !mUnreadIndicatorActive) { |
572 // make the "@" appear immediatelly |
607 if (getMessageUnreadInfo(folderId, messageId, mailboxId, messageUnread)) { |
573 updateUnreadIndicator(true); |
608 if (messageUnread) { |
574 |
609 mailboxInfo->mUnreadMailIdList.append(messageId); |
575 // Play the tone as well |
610 mailboxInfo->mInboxActive = true; |
576 playAlertTone(); |
611 updateMailboxState(mailboxId, true, false); |
|
612 |
|
613 // make the "@" appear immediatelly |
|
614 updateUnreadIndicator(true); |
|
615 |
|
616 // Play the tone as well |
|
617 playAlertTone(); |
|
618 } |
577 } |
619 } |
578 } |
620 } |
579 } |
621 } |
580 } |
622 } |
581 } |
623 } |
|
624 |
582 if (folderId==mailboxInfo->mInboxFolderId) { |
625 if (folderId==mailboxInfo->mInboxFolderId) { |
583 mailboxInfo->mInboxCreatedMessages++; |
626 mailboxInfo->mInboxCreatedMessages += messageIds.count(); |
584 } |
627 } |
585 |
628 |
586 // When created a new mail in the outbox, we are in sending state |
629 // When created a new mail in the outbox, we are in sending state |
587 if (mailboxInfo->mOutboxFolderId == folderId) { |
630 if (mailboxInfo->mOutboxFolderId == folderId) { |
588 // The first mail created in the outbox |
631 // The first mail created in the outbox |
589 if (mailboxInfo->mOutboxMails <= 0) { |
632 if (mailboxInfo->mOutboxMails <= 0) { |
590 NM_COMMENT("NmMailAgent: first mail in outbox"); |
633 NM_COMMENT("NmMailAgent: first mail in outbox"); |
591 activate = true; |
|
592 updateNeeded = true; |
|
593 } |
634 } |
|
635 // Always activate the indicator |
|
636 activate = true; |
|
637 updateNeeded = true; |
|
638 |
594 mailboxInfo->mOutboxMails += messageIds.count(); |
639 mailboxInfo->mOutboxMails += messageIds.count(); |
595 updateSendIndicator(); |
640 updateSendIndicator(); |
596 } |
641 } |
597 break; |
642 break; |
598 } |
643 } |
865 bool played = false; |
913 bool played = false; |
866 |
914 |
867 if (mAlertToneAllowed) { |
915 if (mAlertToneAllowed) { |
868 //mSystemTone->playTone(XQSystemToneService::EmailAlertTone); |
916 //mSystemTone->playTone(XQSystemToneService::EmailAlertTone); |
869 |
917 |
|
918 // Execute the vibra effect. |
|
919 if (mVibra) { |
|
920 TRAP_IGNORE(mVibra->StartVibraL(NmAgentDefaultVibraDuration)); |
|
921 } |
|
922 |
870 // play alert only once per minute |
923 // play alert only once per minute |
871 mAlertToneAllowed = false; |
924 mAlertToneAllowed = false; |
872 QTimer::singleShot(NmAgentAlertToneTimer, this, SLOT(enableAlertTone())); |
925 QTimer::singleShot(NmAgentAlertToneTimer, this, SLOT(enableAlertTone())); |
873 played = true; |
926 played = true; |
874 } |
927 } |
|
928 |
875 return played; |
929 return played; |
876 } |
930 } |
877 |
931 |
878 /*! |
932 /*! |
879 Allows alert tune to be played again |
933 Allows alert tune to be played again |
907 } |
961 } |
908 |
962 |
909 mLastOutboxCount = outboxMails; |
963 mLastOutboxCount = outboxMails; |
910 } |
964 } |
911 |
965 |
|
966 /*! |
|
967 Store the mailbox active information to permanent storage |
|
968 \param mailboxId id of the mailbox |
|
969 \param active true if the mailbox is active |
|
970 */ |
|
971 void NmMailAgent::storeMailboxActive(const NmId &mailboxId, bool active) |
|
972 { |
|
973 XQCentralRepositorySettingsKey key(NmRepositoryId, mailboxId.id()); |
|
974 XQSettingsManager mgr; |
|
975 XQCentralRepositoryUtils utils(mgr); |
|
976 |
|
977 if (active) { |
|
978 // when mailbox is active, key can be deleted |
|
979 utils.deleteKey(key); |
|
980 } |
|
981 else { |
|
982 utils.createKey(key,(int)active); |
|
983 } |
|
984 } |
|
985 |
|
986 /*! |
|
987 Get the mailbox activity state. |
|
988 \param mailboxId id of the mailbox |
|
989 \return true if the mailbox is active or no information was stored earlier |
|
990 */ |
|
991 bool NmMailAgent::isMailboxActive(const NmId &mailboxId) |
|
992 { |
|
993 XQCentralRepositorySettingsKey key(NmRepositoryId, mailboxId.id()); |
|
994 XQSettingsManager mgr; |
|
995 QVariant value = mgr.readItemValue(key,XQSettingsManager::TypeInt); |
|
996 if (!value.isValid()) { |
|
997 // no valid value found, key missing? |
|
998 NM_COMMENT("NmMailAgent::isMailboxActive - value not valid"); |
|
999 return true; |
|
1000 } |
|
1001 NM_COMMENT(QString("NmMailAgent::isMailboxActive - value=%1").arg(value.toInt())); |
|
1002 return value.toInt(); |
|
1003 } |
|
1004 |
|
1005 /*! |
|
1006 Delete all stored activity information for the mailbox id |
|
1007 \param mailboxId id of the mailbox |
|
1008 */ |
|
1009 void NmMailAgent::deleteStoredMailboxActivity(const NmId &mailboxId) |
|
1010 { |
|
1011 // deactivation delete the key too |
|
1012 storeMailboxActive(mailboxId,false); |
|
1013 } |
|
1014 |
912 // End of file |
1015 // End of file |
913 |
1016 |