emailservices/nmailagent/src/nmmailagent.cpp
changeset 76 38bf5461e270
parent 74 6c59112cfd31
equal deleted inserted replaced
74:6c59112cfd31 76:38bf5461e270
   308             inboxId = mailboxInfo.mInboxFolderId.id();
   308             inboxId = mailboxInfo.mInboxFolderId.id();
   309         }
   309         }
   310 
   310 
   311         // get list of messages in inbox
   311         // get list of messages in inbox
   312         QList<NmMessageEnvelope*> messageList;
   312         QList<NmMessageEnvelope*> messageList;
   313         plugin->listMessages(mailboxId, inboxId, messageList);
   313         int err = plugin->listMessages(mailboxId, inboxId, messageList);
   314 
   314         if (err != KErrNone) {
       
   315             return false;
       
   316         }
   315         QList<NmId> newMessageIdList;
   317         QList<NmId> newMessageIdList;
   316 
   318 
   317         int unreadCount(0);
   319         int unreadCount(0);
   318         foreach (const NmMessageEnvelope* envelope, messageList) {
   320         foreach (const NmMessageEnvelope* envelope, messageList) {
   319             // if the message is not read, it is "unread"
   321             // if the message is not read, it is "unread"
   423 bool NmMailAgent::updateMailboxState(const NmId &mailboxId) 
   425 bool NmMailAgent::updateMailboxState(const NmId &mailboxId) 
   424 {
   426 {
   425     NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   427     NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   426     bool shown = false;
   428     bool shown = false;
   427     
   429     
   428     if( mailboxInfo->mActive && 
   430     if( mailboxInfo && mailboxInfo->mActive && 
   429         (mailboxInfo->mNewUnreadMailIdList.count() > 0 ||
   431         (mailboxInfo->mNewUnreadMailIdList.count() > 0 ||
   430          mailboxInfo->mOutboxMails>0)) {
   432          mailboxInfo->mOutboxMails>0)) {
   431         shown = true;
   433         shown = true;
   432     }
   434     }
   433     
   435     
   448 {
   450 {
   449     NM_FUNCTION;
   451     NM_FUNCTION;
   450 
   452 
   451     NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   453     NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   452     bool changed = false;
   454     bool changed = false;
   453     if (mailboxInfo->mActive != active ||
   455     if (mailboxInfo && (mailboxInfo->mActive != active ||
   454         refreshAlways) {
   456         refreshAlways) ) {
   455 
   457 
   456         // store the new state to permanent storage
   458         // store the new state to permanent storage
   457         storeMailboxActive(mailboxId, active);
   459         storeMailboxActive(mailboxId, active);
   458 
   460 
   459         mailboxInfo->mActive = active;
   461         mailboxInfo->mActive = active;
   586     NM_FUNCTION;
   588     NM_FUNCTION;
   587 
   589 
   588     // Check the new messages to make the indicator appear earlier
   590     // Check the new messages to make the indicator appear earlier
   589     NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   591     NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   590 
   592 
   591     // Inbox folder ID may be still unknown
   593     if(mailboxInfo){
   592     if (mailboxInfo->mInboxFolderId.id() == 0) {
   594         // Inbox folder ID may be still unknown
   593         NmDataPluginInterface *plugin =
   595         if (mailboxInfo->mInboxFolderId.id() == 0) {
   594             mPluginFactory->interfaceInstance(mailboxId);
   596             NmDataPluginInterface *plugin =
   595 
   597                 mPluginFactory->interfaceInstance(mailboxId);
   596         if (plugin) {
   598     
   597             mailboxInfo->mInboxFolderId =
   599             if (plugin) {
   598                 plugin->getStandardFolderId(mailboxId, NmFolderInbox);
   600                 mailboxInfo->mInboxFolderId =
   599         }
   601                     plugin->getStandardFolderId(mailboxId, NmFolderInbox);
   600     }
   602             }
   601 
   603         }
   602     if (folderId == mailboxInfo->mInboxFolderId) {
   604     
   603         mailboxInfo->mInboxCreatedMessages += messageIds.count();
   605         if (folderId == mailboxInfo->mInboxFolderId) {
   604 
   606             mailboxInfo->mInboxCreatedMessages += messageIds.count();
   605         foreach (NmId messageId, messageIds) {
   607     
   606             bool messageUnread = false;
   608             foreach (NmId messageId, messageIds) {
   607             mailboxInfo->mMailIdList.append(messageId);
   609                 bool messageUnread = false;
   608 
   610                 mailboxInfo->mMailIdList.append(messageId);
   609             // double check that the message ID is really new
   611     
   610             bool newMessage = true;
   612                 // double check that the message ID is really new
   611             if (mailboxInfo->mNewUnreadMailIdList.indexOf(messageId)>=0) {
   613                 bool newMessage = true;
   612                 newMessage = false;
   614                 if (mailboxInfo->mNewUnreadMailIdList.indexOf(messageId)>=0) {
   613             }
   615                     newMessage = false;
   614 
   616                 }
   615             // If it is a new message, update the mailbox status
   617     
   616             if (newMessage) {
   618                 // If it is a new message, update the mailbox status
   617                 if (getMessageUnreadInfo(folderId, messageId, mailboxId, messageUnread)) {
   619                 if (newMessage) {
   618                     if (messageUnread) {
   620                     if (getMessageUnreadInfo(folderId, messageId, mailboxId, messageUnread)) {
   619                         mailboxInfo->mNewUnreadMailIdList.append(messageId);
   621                         if (messageUnread) {
   620                         NM_COMMENT(QString(" new unread messages: count=%1").
   622                             mailboxInfo->mNewUnreadMailIdList.append(messageId);
   621                             arg(mailboxInfo->mNewUnreadMailIdList.count()));
   623                             NM_COMMENT(QString(" new unread messages: count=%1").
   622 
   624                                 arg(mailboxInfo->mNewUnreadMailIdList.count()));
   623                         if (!mUnreadIndicatorActive) {
   625     
   624                             // make the "@" appear immediatelly
   626                             if (!mUnreadIndicatorActive) {
   625                             updateUnreadIndicator(true);
   627                                 // make the "@" appear immediatelly
       
   628                                 updateUnreadIndicator(true);
       
   629                             }
       
   630                             updateMailboxState(mailboxId, true, false);
       
   631     
       
   632                             // Play the tone as well
       
   633                             playAlertTone();
   626                         }
   634                         }
   627                         updateMailboxState(mailboxId, true, false);
       
   628 
       
   629                         // Play the tone as well
       
   630                         playAlertTone();
       
   631                     }
   635                     }
   632                 }
   636                 }
   633             }
   637             }
   634         }
   638         }
   635     }
   639     
   636 
   640         // When created a new mail in the outbox, we are in sending state
   637     // When created a new mail in the outbox, we are in sending state
   641         if (mailboxInfo->mOutboxFolderId == folderId) {
   638     if (mailboxInfo->mOutboxFolderId == folderId) {
   642             // The first mail created in the outbox
   639         // The first mail created in the outbox
   643             if (mailboxInfo->mOutboxMails <= 0) {
   640         if (mailboxInfo->mOutboxMails <= 0) {
   644                 NM_COMMENT("NmMailAgent: first mail in outbox");
   641             NM_COMMENT("NmMailAgent: first mail in outbox");
   645             }
   642         }
   646             mailboxInfo->mOutboxMails += messageIds.count();
   643         mailboxInfo->mOutboxMails += messageIds.count();
   647     
   644 
   648             updateMailboxState(mailboxId,true,true);
   645         updateMailboxState(mailboxId,true,true);
   649             updateSendIndicator();
   646         updateSendIndicator();
   650         }
   647     }
   651     }
   648 }
   652 }
   649 
   653 
   650 
   654 
   651 /*!
   655 /*!