241 foreach(QObject* pluginObject, *plugins) { |
241 foreach(QObject* pluginObject, *plugins) { |
242 NmDataPluginInterface *plugin = |
242 NmDataPluginInterface *plugin = |
243 mPluginFactory->interfaceInstance(pluginObject); |
243 mPluginFactory->interfaceInstance(pluginObject); |
244 if (plugin) { |
244 if (plugin) { |
245 plugin->listMailboxes(mailboxes); |
245 plugin->listMailboxes(mailboxes); |
246 |
246 |
247 // Add the indicators |
247 // Add the indicators |
248 // Must be made in reverse order to show them properly in |
248 // Must be made in reverse order to show them properly in |
249 // HbIndicator menu |
249 // HbIndicator menu |
250 QListIterator<NmMailbox *> i(mailboxes); |
250 QListIterator<NmMailbox *> i(mailboxes); |
251 i.toBack(); |
251 i.toBack(); |
257 bool activate = updateUnreadCount(mailbox->id(), *mailboxInfo); |
257 bool activate = updateUnreadCount(mailbox->id(), *mailboxInfo); |
258 NM_COMMENT(QString("Mailbox %1 initial state: newUnread=%2 total=%3"). |
258 NM_COMMENT(QString("Mailbox %1 initial state: newUnread=%2 total=%3"). |
259 arg(mailboxInfo->mName). |
259 arg(mailboxInfo->mName). |
260 arg(mailboxInfo->mNewUnreadMailIdList.count()). |
260 arg(mailboxInfo->mNewUnreadMailIdList.count()). |
261 arg(mailboxInfo->mMailIdList.count())); |
261 arg(mailboxInfo->mMailIdList.count())); |
262 |
262 |
263 bool wasActive = isMailboxActive(mailbox->id()); |
263 bool wasActive = isMailboxActive(mailbox->id()); |
264 if (!wasActive) { |
264 if (!wasActive) { |
265 // do not activate the mailbox if it was left as hidden last time |
265 // do not activate the mailbox if it was left as hidden last time |
266 activate = false; |
266 activate = false; |
267 mailboxInfo->mNewUnreadMailIdList.clear(); |
267 mailboxInfo->mNewUnreadMailIdList.clear(); |
268 } |
268 } |
269 |
269 |
270 mailboxInfo->mOutboxMails = getOutboxCount(mailbox->id(), |
270 mailboxInfo->mOutboxMails = getOutboxCount(mailbox->id(), |
271 mailboxInfo->mOutboxFolderId); |
271 mailboxInfo->mOutboxFolderId); |
272 if (mailboxInfo->mOutboxMails > 0 && wasActive) { |
272 if (mailboxInfo->mOutboxMails > 0 && wasActive) { |
273 activate = true; |
273 activate = true; |
274 } |
274 } |
275 |
275 |
276 // Create indicator for visible mailboxes |
276 // Create indicator for visible mailboxes |
277 updateMailboxState(mailbox->id(), activate, false); |
277 updateMailboxState(mailbox->id(), activate, false); |
278 } |
278 } |
279 } |
279 } |
280 } |
280 } |
563 // Instance might be NULL if the service is not available. |
563 // Instance might be NULL if the service is not available. |
564 if (request) { |
564 if (request) { |
565 QList<QVariant> list; |
565 QList<QVariant> list; |
566 list.append(QVariant(mailboxId)); |
566 list.append(QVariant(mailboxId)); |
567 request->setArguments(list); |
567 request->setArguments(list); |
|
568 request->setSynchronous(EFalse); |
568 ok = request->send(); |
569 ok = request->send(); |
569 NM_COMMENT(QString("Launch ok=%1 error=%2").arg(ok).arg(request->lastError())); |
570 NM_COMMENT(QString("Launch ok=%1 error=%2").arg(ok).arg(request->lastError())); |
570 delete request; |
571 delete request; |
571 } |
572 } |
572 return ok; |
573 return ok; |
638 // The first mail created in the outbox |
639 // The first mail created in the outbox |
639 if (mailboxInfo->mOutboxMails <= 0) { |
640 if (mailboxInfo->mOutboxMails <= 0) { |
640 NM_COMMENT("NmMailAgent: first mail in outbox"); |
641 NM_COMMENT("NmMailAgent: first mail in outbox"); |
641 } |
642 } |
642 mailboxInfo->mOutboxMails += messageIds.count(); |
643 mailboxInfo->mOutboxMails += messageIds.count(); |
643 |
644 |
644 updateMailboxState(mailboxId,true,true); |
645 updateMailboxState(mailboxId,true,true); |
645 updateSendIndicator(); |
646 updateSendIndicator(); |
646 } |
647 } |
647 } |
648 } |
648 |
649 |
701 */ |
702 */ |
702 void NmMailAgent::handleMessageDeletedEvent(const NmId &folderId, const QList<NmId> &messageIds, |
703 void NmMailAgent::handleMessageDeletedEvent(const NmId &folderId, const QList<NmId> &messageIds, |
703 const NmId &mailboxId) |
704 const NmId &mailboxId) |
704 { |
705 { |
705 NM_FUNCTION; |
706 NM_FUNCTION; |
706 |
707 |
707 NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId); |
708 NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId); |
708 |
709 |
709 if (mailboxInfo) { |
710 if (mailboxInfo) { |
710 if (folderId == mailboxInfo->mInboxFolderId) { |
711 if (folderId == mailboxInfo->mInboxFolderId) { |
711 mailboxInfo->mInboxDeletedMessages++; |
712 mailboxInfo->mInboxDeletedMessages++; |
783 case NmMailboxCreated: |
784 case NmMailboxCreated: |
784 foreach (NmId mailboxId, mailboxIds) { |
785 foreach (NmId mailboxId, mailboxIds) { |
785 NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId); // create a new mailbox if needed |
786 NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId); // create a new mailbox if needed |
786 if (!mailboxInfo) { |
787 if (!mailboxInfo) { |
787 // Unable to initialise the mailbox. Try again later. |
788 // Unable to initialise the mailbox. Try again later. |
788 NM_COMMENT("Cannot initialise mailbox"); |
789 NM_COMMENT("Cannot initialise mailbox - retry in 200 ms"); |
789 |
790 mNewMailboxId=mailboxId; |
790 qRegisterMetaType<NmId>("NmId"); |
791 QTimer::singleShot(200, this, SLOT(delayedMailboxCreated())); |
791 QMetaObject::invokeMethod(this, "delayedMailboxCreated", |
|
792 Qt::QueuedConnection, Q_ARG(NmId,mailboxId)); |
|
793 } |
792 } |
794 |
793 |
795 // make sure the mailbox activity data is reseted |
794 // make sure the mailbox activity data is reseted |
796 deleteStoredMailboxActivity(mailboxId); |
795 deleteStoredMailboxActivity(mailboxId); |
797 } |
796 } |
815 updateMailboxState(mailboxId, true, true); |
814 updateMailboxState(mailboxId, true, true); |
816 } |
815 } |
817 } |
816 } |
818 } |
817 } |
819 delete mailbox; |
818 delete mailbox; |
|
819 mailbox = NULL; |
820 } |
820 } |
821 break; |
821 break; |
822 case NmMailboxDeleted: |
822 case NmMailboxDeleted: |
823 foreach (NmId mailboxId, mailboxIds) { |
823 foreach (NmId mailboxId, mailboxIds) { |
824 // Will hide also the indicator |
824 // Will hide also the indicator |
838 Called when mailbox is initialised with a delay. This may happen at least when |
838 Called when mailbox is initialised with a delay. This may happen at least when |
839 NmMailboxCreated event is received. |
839 NmMailboxCreated event is received. |
840 |
840 |
841 \param mailboxId id of the mailbox |
841 \param mailboxId id of the mailbox |
842 */ |
842 */ |
843 void NmMailAgent::delayedMailboxCreated(const NmId mailboxId) |
843 void NmMailAgent::delayedMailboxCreated() |
844 { |
844 { |
845 NM_FUNCTION; |
845 NM_FUNCTION; |
846 |
846 |
847 // create and subscribe to the mailbox, if not done earlier |
847 // create and subscribe to the mailbox, if not done earlier |
848 getMailboxInfo(mailboxId); |
848 getMailboxInfo(mNewMailboxId); |
849 } |
849 } |
850 |
850 |
851 |
851 |
852 /*! |
852 /*! |
853 Handles the view state changed UI event. The event notification is received |
853 Handles the view state changed UI event. The event notification is received |
868 NmMailboxInfo *info = getMailboxInfo(mailboxId); |
868 NmMailboxInfo *info = getMailboxInfo(mailboxId); |
869 |
869 |
870 if (info) { |
870 if (info) { |
871 // The message list view was shown. If the indicator of the mailbox |
871 // The message list view was shown. If the indicator of the mailbox |
872 // in question is active, deactivate it. |
872 // in question is active, deactivate it. |
873 updateMailboxState(info->mId, false, false); |
873 updateMailboxState(info->mId, false, false); |
874 resetMailboxState(info); |
874 resetMailboxState(info); |
875 } |
875 } |
876 } |
876 } |
877 } |
877 } |
878 |
878 |
908 \param info mailbox that will be reseted |
908 \param info mailbox that will be reseted |
909 */ |
909 */ |
910 void NmMailAgent::resetMailboxState(NmMailboxInfo *info) |
910 void NmMailAgent::resetMailboxState(NmMailboxInfo *info) |
911 { |
911 { |
912 NM_FUNCTION; |
912 NM_FUNCTION; |
913 |
913 |
914 info->mActive = false; // indicator is no longer active |
914 info->mActive = false; // indicator is no longer active |
915 info->mNewUnreadMailIdList.clear(); // no mails are no longer 'new' |
915 info->mNewUnreadMailIdList.clear(); // no mails are no longer 'new' |
916 storeMailboxActive(info->mId, false); |
916 storeMailboxActive(info->mId, false); |
917 updateUnreadIndicator(); |
917 updateUnreadIndicator(); |
918 } |
918 } |
1072 // get information of the mailbox |
1072 // get information of the mailbox |
1073 NmMailbox *mailbox = NULL; |
1073 NmMailbox *mailbox = NULL; |
1074 NmMailboxInfo *info = NULL; |
1074 NmMailboxInfo *info = NULL; |
1075 NmDataPluginInterface *plugin = mPluginFactory->interfaceInstance(id); |
1075 NmDataPluginInterface *plugin = mPluginFactory->interfaceInstance(id); |
1076 if (plugin) { |
1076 if (plugin) { |
1077 plugin->getMailboxById(id, mailbox); |
1077 int err = plugin->getMailboxById(id, mailbox); |
1078 if (mailbox) { |
1078 if (err == NmNoError && mailbox) { |
1079 info = createMailboxInfo(*mailbox,plugin); |
1079 info = createMailboxInfo(*mailbox,plugin); |
1080 } |
1080 } |
|
1081 delete mailbox; |
|
1082 mailbox = NULL; |
1081 } |
1083 } |
1082 |
1084 |
1083 return info; |
1085 return info; |
1084 } |
1086 } |
1085 |
1087 |
1185 bool played(false); |
1187 bool played(false); |
1186 |
1188 |
1187 if (mAlertToneAllowed) { |
1189 if (mAlertToneAllowed) { |
1188 // Play tone only when phone is not in silence mode. |
1190 // Play tone only when phone is not in silence mode. |
1189 if (!mSilenceMode) { |
1191 if (!mSilenceMode) { |
1190 // Must instantiate it again to make sure correct tone is played |
1192 // Must instantiate it again to make sure correct tone is played |
1191 XQSystemToneService systemTone; |
1193 XQSystemToneService systemTone; |
1192 systemTone.playTone(XQSystemToneService::EmailAlertTone); |
1194 systemTone.playTone(XQSystemToneService::EmailAlertTone); |
1193 } |
1195 } |
1194 |
1196 |
1195 // Execute the vibra effect. |
1197 // Execute the vibra effect. |