emailservices/nmailagent/src/nmmailagent.cpp
changeset 72 64e38f08e49c
parent 65 478bc57ad291
equal deleted inserted replaced
65:478bc57ad291 72:64e38f08e49c
   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 
   247             // Add the indicators
   248         // Add the indicators
   248             // Must be made in reverse order to show them properly in
   249         // Must be made in reverse order to show them properly in
   249             // HbIndicator menu
   250         // HbIndicator menu
   250             QListIterator<NmMailbox *> i(mailboxes);
   251         QListIterator<NmMailbox *> i(mailboxes);
   251             i.toBack();
   252         i.toBack();
   252             while (i.hasPrevious()) {
   253         while (i.hasPrevious()) {
   253                 const NmMailbox *mailbox = i.previous();
   254             const NmMailbox *mailbox = i.previous();
   254                 if (mailbox) {
   255             if (mailbox) {
   255                     NmMailboxInfo *mailboxInfo = createMailboxInfo(*mailbox, plugin);
   256                 NmMailboxInfo *mailboxInfo = createMailboxInfo(*mailbox, plugin);
   256                     if (mailboxInfo) {
   257                 if (mailboxInfo) {
   257                         bool activate = updateUnreadCount(mailbox->id(), *mailboxInfo);
   258                     bool activate = updateUnreadCount(mailbox->id(), *mailboxInfo);
   258                         NM_COMMENT(QString("Mailbox %1 initial state: newUnread=%2 total=%3").
   259                     NM_COMMENT(QString("Mailbox %1 initial state: newUnread=%2 total=%3").
   259                             arg(mailboxInfo->mName).
   260                         arg(mailboxInfo->mName).
   260                             arg(mailboxInfo->mNewUnreadMailIdList.count()).
   261                         arg(mailboxInfo->mNewUnreadMailIdList.count()).
   261                             arg(mailboxInfo->mMailIdList.count()));
   262                         arg(mailboxInfo->mMailIdList.count()));
   262     
   263 
   263                         bool wasActive = isMailboxActive(mailbox->id());
   264                     bool wasActive = isMailboxActive(mailbox->id());
   264                         if (!wasActive) {
   265                     if (!wasActive) {
   265                             // do not activate the mailbox if it was left as hidden last time
   266                         // do not activate the mailbox if it was left as hidden last time
   266                             activate = false;
   267                         activate = false;
   267                             mailboxInfo->mNewUnreadMailIdList.clear();
   268                         mailboxInfo->mNewUnreadMailIdList.clear();
   268                         }
       
   269     
       
   270                         mailboxInfo->mOutboxMails = getOutboxCount(mailbox->id(),
       
   271                             mailboxInfo->mOutboxFolderId);
       
   272                         if (mailboxInfo->mOutboxMails > 0 && wasActive) {
       
   273                             activate = true;
       
   274                         }
       
   275     
       
   276                         // Create indicator for visible mailboxes
       
   277                         updateMailboxState(mailbox->id(), activate, false);
   269                     }
   278                     }
   270 
       
   271                     mailboxInfo->mOutboxMails = getOutboxCount(mailbox->id(),
       
   272                         mailboxInfo->mOutboxFolderId);
       
   273                     if (mailboxInfo->mOutboxMails > 0 && wasActive) {
       
   274                         activate = true;
       
   275                     }
       
   276 
       
   277                     // Create indicator for visible mailboxes
       
   278                     updateMailboxState(mailbox->id(), activate, false);
       
   279                 }
   279                 }
   280             }
   280             }
   281         }
   281             qDeleteAll(mailboxes);
   282         qDeleteAll(mailboxes);
   282         }
   283     }
   283     }
   284     updateUnreadIndicator();
   284     updateUnreadIndicator();
   285     updateSendIndicator();
   285     updateSendIndicator();
   286 }
   286 }
   287 
   287 
   466 
   466 
   467             updateIndicator(true,*mailboxInfo);
   467             updateIndicator(true,*mailboxInfo);
   468         }
   468         }
   469         else {
   469         else {
   470             // Indicator not anymore active. Release it.
   470             // Indicator not anymore active. Release it.
   471             if (mailboxInfo->mIndicatorIndex>=0) {
   471             if (mailboxInfo->mIndicatorIndex >= 0) {
   472                 updateIndicator(false,*mailboxInfo);
   472                 updateIndicator(false,*mailboxInfo);
   473                 mailboxInfo->mIndicatorIndex = NmAgentIndicatorNotSet;
   473                 mailboxInfo->mIndicatorIndex = NmAgentIndicatorNotSet;
   474             }
   474             }
   475         }
   475         }
   476     }
   476     }
   704 {
   704 {
   705     NM_FUNCTION;
   705     NM_FUNCTION;
   706     
   706     
   707     NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   707     NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   708 
   708 
   709     if (mailboxInfo && folderId == mailboxInfo->mInboxFolderId) {
   709     if (mailboxInfo) {
   710         mailboxInfo->mInboxDeletedMessages++;
   710         if (folderId == mailboxInfo->mInboxFolderId) {
   711 
   711             mailboxInfo->mInboxDeletedMessages++;
   712         // Clear the IDs from 'new unread messages' list
   712 
   713         foreach (NmId messageId, messageIds) {
   713             // Clear the IDs from 'new unread messages' list
   714             mailboxInfo->mNewUnreadMailIdList.removeAll(messageId);
   714             foreach (NmId messageId, messageIds) {
   715         }
   715                 mailboxInfo->mNewUnreadMailIdList.removeAll(messageId);
   716 
   716              }
   717         // All new unread messages are now deleted
   717 
   718         if (mailboxInfo->mNewUnreadMailIdList.count()==0) {
   718             // All new unread messages are now deleted
   719             NM_COMMENT(" No more new unread messages");
   719             if (mailboxInfo->mNewUnreadMailIdList.count()==0) {
   720             updateUnreadIndicator();
   720                 NM_COMMENT(" No more new unread messages");
       
   721                 updateUnreadIndicator();
       
   722                 updateMailboxState(mailboxId);
       
   723             }
       
   724         }
       
   725 
       
   726         // Deleted mails from the outbox
       
   727         if (mailboxInfo->mOutboxFolderId == folderId) {
       
   728             mailboxInfo->mOutboxMails -= messageIds.count();
       
   729 
       
   730             // Sanity check for the outbox count
       
   731             if (mailboxInfo->mOutboxMails < 0) {
       
   732                 mailboxInfo->mOutboxMails = 0;
       
   733             }
       
   734 
       
   735             // The last mail was now deleted from outbox
       
   736             if (mailboxInfo->mOutboxMails == 0) {
       
   737                 NM_COMMENT("NmMailAgent: last mail deleted from outbox");
       
   738                 updateSendIndicator();
       
   739             }
   721             updateMailboxState(mailboxId);
   740             updateMailboxState(mailboxId);
   722         }
   741         }
   723     }
       
   724 
       
   725     // Deleted mails from the outbox
       
   726     if (mailboxInfo->mOutboxFolderId == folderId) {
       
   727         mailboxInfo->mOutboxMails -= messageIds.count();
       
   728 
       
   729         // Sanity check for the outbox count
       
   730         if (mailboxInfo->mOutboxMails < 0) {
       
   731             mailboxInfo->mOutboxMails = 0;
       
   732         }
       
   733 
       
   734         // The last mail was now deleted from outbox
       
   735         if (mailboxInfo->mOutboxMails == 0) {
       
   736             NM_COMMENT("NmMailAgent: last mail deleted from outbox");
       
   737             updateSendIndicator();
       
   738         }
       
   739         updateMailboxState(mailboxId);
       
   740     }
   742     }
   741 }
   743 }
   742 
   744 
   743 /*!
   745 /*!
   744     Get next free indicator index, starting from 0.
   746     Get next free indicator index, starting from 0.
   752     int index = 0;
   754     int index = 0;
   753     bool found(false);
   755     bool found(false);
   754     do {
   756     do {
   755         found = false;
   757         found = false;
   756         foreach (NmMailboxInfo *mailbox, mMailboxes) {
   758         foreach (NmMailboxInfo *mailbox, mMailboxes) {
   757             if (mailbox->mIndicatorIndex == index &&
   759             if (mailbox->mIndicatorIndex == index) {
   758                 mailbox->mActive) {
       
   759                 found = true;
   760                 found = true;
   760                 index++;
   761                 index++;
       
   762                 break;
   761             }
   763             }
   762         }
   764         }
   763     }
   765     }
   764     while( found );
   766     while( found );
   765     return index;
   767     return index;