emailservices/emailserver/cmailhandlerplugin/src/cmailcpshandler.cpp
branchRCL_3
changeset 8 e1b6206813b4
parent 4 e7aa27f58ae1
child 10 f5907b1a1053
equal deleted inserted replaced
4:e7aa27f58ae1 8:e1b6206813b4
    22 #include <AknUtils.h>
    22 #include <AknUtils.h>
    23 #include <apgcli.h>
    23 #include <apgcli.h>
    24 #include <centralrepository.h>
    24 #include <centralrepository.h>
    25 #include <starterdomaincrkeys.h>
    25 #include <starterdomaincrkeys.h>
    26 #include <startupdomainpskeys.h>
    26 #include <startupdomainpskeys.h>
       
    27 #include <emailobserverinterface.hrh>
       
    28 #include <emailobserverplugin.h>
       
    29 #include <memaildata.h>
       
    30 #include <memailmailboxdata.h>
    27 
    31 
    28 #include "emailtrace.h"
    32 #include "emailtrace.h"
    29 #include "CFSMailClient.h"
    33 #include "cfsmailclient.h"
    30 #include "CFSMailBox.h"
    34 #include "cfsmailbox.h"
    31 #include "CFSMailFolder.h"
    35 #include "cfsmailfolder.h"
    32 #include "cmailcpshandler.h"
    36 #include "cmailcpshandler.h"
    33 #include "cmailcpssettings.h"
    37 #include "cmailcpssettings.h"
    34 #include "cmailcpsif.h"
    38 #include "cmailcpsif.h"
    35 #include "cmailmessagedetails.h"
    39 #include "cmailmessagedetails.h"
    36 #include "cmailmailboxdetails.h"
    40 #include "cmailmailboxdetails.h"
       
    41 #include "cmailexternalaccount.h"
    37 #include "cmailcpsifconsts.h"
    42 #include "cmailcpsifconsts.h"
    38 #include "FreestyleEmailUiConstants.h"
    43 #include "FreestyleEmailUiConstants.h"
       
    44 #include "cmailpluginproxy.h"
       
    45 #include "cmailhandlerpluginpanic.h"
       
    46 
       
    47 using namespace EmailInterface;
    39 
    48 
    40 // ---------------------------------------------------------
    49 // ---------------------------------------------------------
    41 // CMailCpsHandler::CMailCpsHandler
    50 // CMailCpsHandler::CMailCpsHandler
    42 // ---------------------------------------------------------
    51 // ---------------------------------------------------------
    43 //
    52 //
    79     iLiwIf = CMailCpsIf::NewL(this);
    88     iLiwIf = CMailCpsIf::NewL(this);
    80     // Leaves if CenRep file not found
    89     // Leaves if CenRep file not found
    81     iSettings = CMailCpsSettings::NewL( MailClient() );
    90     iSettings = CMailCpsSettings::NewL( MailClient() );
    82 
    91 
    83     InitializeL();
    92     InitializeL();
    84     
    93     InitializeExternalAccountsL();
       
    94 
    85     iSettings->StartObservingL( this );
    95     iSettings->StartObservingL( this );
    86     }
    96     }
    87 
    97 
    88 // ---------------------------------------------------------
    98 // ---------------------------------------------------------
    89 // CMailCpsHandler::~CMailCpsHandler
    99 // CMailCpsHandler::~CMailCpsHandler
    93     {
   103     {
    94     FUNC_LOG;
   104     FUNC_LOG;
    95     delete iLiwIf;
   105     delete iLiwIf;
    96     delete iSettings;
   106     delete iSettings;
    97     iAccountsArray.ResetAndDestroy();
   107     iAccountsArray.ResetAndDestroy();
       
   108     iExternalPlugins.ResetAndDestroy();
    98     }
   109     }
    99 
   110 
   100 // ---------------------------------------------------------
   111 // ---------------------------------------------------------
   101 // CMailCpsHandler::Reset
   112 // CMailCpsHandler::Reset
   102 // ---------------------------------------------------------
   113 // ---------------------------------------------------------
   162             }
   173             }
   163         }
   174         }
   164     }
   175     }
   165 
   176 
   166 // ---------------------------------------------------------
   177 // ---------------------------------------------------------
       
   178 // CMailCpsHandler::InitializeExternalAccountsL
       
   179 // ---------------------------------------------------------
       
   180 //
       
   181 void CMailCpsHandler::InitializeExternalAccountsL()
       
   182     {
       
   183     FUNC_LOG;
       
   184     // Read external account data from settings
       
   185     RPointerArray<CMailExternalAccount> extAccounts;
       
   186     CleanupClosePushL( extAccounts );
       
   187     iSettings->GetExtMailboxesL( extAccounts );
       
   188 
       
   189     // Delete removed plugins
       
   190     RemoveUnusedPluginsL( extAccounts );
       
   191 
       
   192     // Instantiate new plugins
       
   193     AddNewPluginsL( extAccounts );
       
   194 
       
   195     // Set accounts under correct pluginProxies
       
   196     SelectAndUpdateExtAccountsL( extAccounts );
       
   197 
       
   198     __ASSERT_DEBUG( extAccounts.Count() == 0, Panic( ECmailHandlerPluginPanicNoFailedState ) );
       
   199     CleanupStack::PopAndDestroy();
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------
       
   203 // CMailCpsHandler::RemoveUnusedPluginsL
       
   204 // ---------------------------------------------------------
       
   205 //
       
   206 void CMailCpsHandler::RemoveUnusedPluginsL( RPointerArray<CMailExternalAccount>& aAccounts )
       
   207     {
       
   208     FUNC_LOG;
       
   209     for ( TInt i = 0; i < iExternalPlugins.Count(); i++ )
       
   210         {
       
   211         if ( !IsPluginInArray( iExternalPlugins[i]->PluginId(), aAccounts ) )
       
   212             {
       
   213             // all plugin's accounts have been removed from widget settings, unloading resources
       
   214             CMailPluginProxy* proxy = iExternalPlugins[i];
       
   215             iExternalPlugins.Remove(i--); // also change the loop index
       
   216             delete proxy;
       
   217             }
       
   218         }
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------
       
   222 // CMailCpsHandler::AddNewPluginsL
       
   223 // ---------------------------------------------------------
       
   224 //
       
   225 void CMailCpsHandler::AddNewPluginsL( RPointerArray<CMailExternalAccount>& aAccounts )
       
   226     {
       
   227     FUNC_LOG;
       
   228     for ( TInt i = 0; i < aAccounts.Count(); i++ )
       
   229         {
       
   230         if ( !IsPluginInArray( aAccounts[i]->PluginId(), iExternalPlugins ) )
       
   231             {
       
   232             // new plugin instantiation
       
   233             INFO_1("Instantiating plugin 0x%x", aAccounts[i]->PluginId() );
       
   234             CMailPluginProxy* proxy = CMailPluginProxy::NewL( aAccounts[i]->PluginId(), *iLiwIf );
       
   235             CleanupStack::PushL( proxy );
       
   236             iExternalPlugins.AppendL( proxy );
       
   237             CleanupStack::Pop( proxy );
       
   238             }
       
   239         }
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------
       
   243 // CMailCpsHandler::UpdateExtAccountsL
       
   244 // ---------------------------------------------------------
       
   245 //
       
   246 void CMailCpsHandler::SelectAndUpdateExtAccountsL( RPointerArray<CMailExternalAccount>& aAccounts )
       
   247     {
       
   248     FUNC_LOG;
       
   249     for ( TInt i = 0; i < iExternalPlugins.Count(); i++ )
       
   250         {
       
   251         iExternalPlugins[i]->SelectAndUpdateAccountsL( aAccounts );
       
   252         }
       
   253     }
       
   254 
       
   255 // ---------------------------------------------------------
       
   256 // CMailCpsHandler::IsPluginInArray
       
   257 // ---------------------------------------------------------
       
   258 //
       
   259 TBool CMailCpsHandler::IsPluginInArray( const TInt aPluginId, RPointerArray<CMailExternalAccount>& aAccounts )
       
   260     {
       
   261     FUNC_LOG;
       
   262     TBool found( EFalse );
       
   263     for ( TInt i = 0; i < aAccounts.Count(); i++ )
       
   264         {
       
   265         if ( aAccounts[i]->PluginId() == aPluginId )
       
   266             {
       
   267             found = ETrue;
       
   268             }
       
   269         }
       
   270     return found;
       
   271     }
       
   272 
       
   273 // ---------------------------------------------------------
       
   274 // CMailCpsHandler::IsPluginInArray
       
   275 // ---------------------------------------------------------
       
   276 //
       
   277 TBool CMailCpsHandler::IsPluginInArray( const TInt aPluginId, RPointerArray<CMailPluginProxy>& aPlugins )
       
   278     {
       
   279     FUNC_LOG;
       
   280     TBool found( EFalse );
       
   281     for ( TInt i = 0; i < aPlugins.Count(); i++ )
       
   282         {
       
   283         if ( aPlugins[i]->PluginId() == aPluginId )
       
   284             {
       
   285             found = ETrue;
       
   286             }
       
   287         }
       
   288     return found;
       
   289     }
       
   290 
       
   291 // ---------------------------------------------------------
   167 // CMailCpsHandler::CreateMailboxDetailsL
   292 // CMailCpsHandler::CreateMailboxDetailsL
   168 // ---------------------------------------------------------
   293 // ---------------------------------------------------------
   169 //
   294 //
   170 CMailMailboxDetails* CMailCpsHandler::CreateMailboxDetailsL( CFSMailBox& aMailbox )
   295 CMailMailboxDetails* CMailCpsHandler::CreateMailboxDetailsL( CFSMailBox& aMailbox )
   171     {
   296     {
   184     {
   309     {
   185     FUNC_LOG;
   310     FUNC_LOG;
   186     Reset();
   311     Reset();
   187     // Trying to keep callback interface non-leaving
   312     // Trying to keep callback interface non-leaving
   188     TRAP_IGNORE( InitializeL() );
   313     TRAP_IGNORE( InitializeL() );
       
   314     TRAP_IGNORE( InitializeExternalAccountsL() );
   189     // Update widget contents after settings change
   315     // Update widget contents after settings change
   190     TRAP_IGNORE( UpdateFullL() );
   316     TRAP_IGNORE( UpdateFullL() );
   191     }
   317     }
   192 
   318 
   193 // ---------------------------------------------------------
   319 // ---------------------------------------------------------
   213 void CMailCpsHandler::UpdateMailboxesL(TInt aInstance, const TDesC& aContentId)
   339 void CMailCpsHandler::UpdateMailboxesL(TInt aInstance, const TDesC& aContentId)
   214     {
   340     {
   215     FUNC_LOG;
   341     FUNC_LOG;
   216     TInt row(1); // start from first row
   342     TInt row(1); // start from first row
   217     TInt mailbox(0);
   343     TInt mailbox(0);
   218     
   344     TBool found( EFalse );
       
   345     // try to find mailbox with matching contentId
   219     for ( mailbox = 0; mailbox < iAccountsArray.Count(); mailbox++ )
   346     for ( mailbox = 0; mailbox < iAccountsArray.Count(); mailbox++ )
   220         {           
   347         {
   221         TInt compare = aContentId.Compare(*iAccountsArray[mailbox]->iWidgetInstance);
   348         if ( !aContentId.Compare( *iAccountsArray[mailbox]->iWidgetInstance ) )
   222         if (!compare)
   349             {
   223             {
   350             INFO_1("iAccountsArray.Count() == %d", iAccountsArray.Count());
       
   351             found = ETrue;
   224             break;
   352             break;
   225             }
   353             }
   226         }
   354         }
   227 
   355 
   228     // Update fields from left to right
   356     // if contentId found from array, update the mailbox
   229     UpdateMailBoxIconL( mailbox, aInstance, row );
   357     if ( found )
   230     UpdateMailboxNameL( mailbox, aInstance, row );
   358         {
   231 	UpdateIndicatorIconL( mailbox, aInstance, row );
   359         // Update fields from left to right
   232 	row++;
   360         UpdateMailBoxIconL( mailbox, aInstance, row );
   233 	UpdateMessagesL( mailbox, aInstance, 1, row);
   361         UpdateMailboxNameL( mailbox, aInstance, row );
   234 	row++;
   362         UpdateIndicatorIconL( mailbox, aInstance, row );
   235 	UpdateMessagesL( mailbox, aInstance, 2, row);
   363         row++;
       
   364         UpdateMessagesL( mailbox, aInstance, 1, row);
       
   365         row++;
       
   366         UpdateMessagesL( mailbox, aInstance, 2, row);
       
   367         }
   236     }
   368     }
   237 
   369 
   238 // ---------------------------------------------------------
   370 // ---------------------------------------------------------
   239 // CMailCpsHandler::UpdateMailboxNameL
   371 // CMailCpsHandler::UpdateMailboxNameL
   240 // ---------------------------------------------------------
   372 // ---------------------------------------------------------
   599     if ( aMailBoxNumber < iAccountsArray.Count() )
   731     if ( aMailBoxNumber < iAccountsArray.Count() )
   600         {
   732         {
   601         TFSMailMsgId mailBoxId;
   733         TFSMailMsgId mailBoxId;
   602         mailBoxId = iAccountsArray[aMailBoxNumber]->iMailboxId;    
   734         mailBoxId = iAccountsArray[aMailBoxNumber]->iMailboxId;    
   603     
   735     
   604         if ( GetUnseenCountL(mailBoxId) > 0 )
   736         if ( iSettings->GetNewMailState( mailBoxId ) )
   605             {
   737             {
   606             iLiwIf->PublishIndicatorIconL( aWidgetInstance,
   738             iLiwIf->PublishIndicatorIconL( aWidgetInstance,
   607                                            aRowNumber,
   739                                            aRowNumber,
   608                                            EMbmCmailhandlerpluginQgn_indi_ai_eplg_unread );
   740                                            EMbmCmailhandlerpluginQgn_stat_message_mail_uni );
   609             }
   741             }
   610     
   742     
   611         else if( !IsOutboxEmptyL(mailBoxId) )
   743         else if( !IsOutboxEmptyL(mailBoxId) )
   612             {
   744             {
   613             iLiwIf->PublishIndicatorIconL( aWidgetInstance,
   745             iLiwIf->PublishIndicatorIconL( aWidgetInstance,
   614                                            aRowNumber,                
   746                                            aRowNumber,                
   615                                            EMbmCmailhandlerpluginQgn_prop_mce_outbox_small);
   747                                            EMbmCmailhandlerpluginQgn_indi_cmail_outbox_msg);
   616             }
   748             }
   617         else
   749         else
   618             {    
   750             {    
   619             iLiwIf->PublishIndicatorIconL( aWidgetInstance,
   751             iLiwIf->PublishIndicatorIconL( aWidgetInstance,
   620                                            aRowNumber,
   752                                            aRowNumber,
   702             break;
   834             break;
   703             }
   835             }
   704         case TFSEventMailboxRenamed:
   836         case TFSEventMailboxRenamed:
   705             {
   837             {
   706             HandleMailboxRenamedEventL( aMailbox );
   838             HandleMailboxRenamedEventL( aMailbox );
       
   839             UpdateFullL();
   707             break;
   840             break;
   708             }
   841             }
   709         case TFSEventMailboxDeleted:
   842         case TFSEventMailboxDeleted:
   710             {
   843             {
   711             HandleMailboxDeletedEventL( aMailbox );
   844             HandleMailboxDeletedEventL( aMailbox );
       
   845             UpdateFullL();
   712             break;
   846             break;
   713             }
   847             }
   714         case TFSEventMailboxSettingsChanged:
   848         case TFSEventMailboxSettingsChanged:
   715             {
   849             {
   716 //            HandleMailboxDeletedEventL( aMailbox );
   850 //            HandleMailboxDeletedEventL( aMailbox );
   718             break;
   852             break;
   719             }            
   853             }            
   720         case TFSEventNewMail:
   854         case TFSEventNewMail:
   721             {
   855             {
   722             HandleNewMailEventL( aMailbox, aParam1, aParam2 );
   856             HandleNewMailEventL( aMailbox, aParam1, aParam2 );
       
   857             UpdateFullL();
   723             break;
   858             break;
   724             }
   859             }
   725         case TFSEventMailDeleted:
   860         case TFSEventMailDeleted:
   726             {
   861             {
   727             HandleMailDeletedEventL( aMailbox, aParam1, aParam2 );
   862             HandleMailDeletedEventL( aMailbox, aParam1, aParam2 );
       
   863             UpdateFullL();
   728             break;
   864             break;
   729             }
   865             }
   730         case TFSEventMailChanged:
   866         case TFSEventMailChanged:
   731             {
   867             {
   732             HandleMailChangedEventL( aMailbox, aParam1, aParam2 );
   868             HandleMailChangedEventL( aMailbox, aParam1, aParam2 );
   740         default:
   876         default:
   741             {
   877             {
   742             break;
   878             break;
   743             }            
   879             }            
   744         }
   880         }
   745 	UpdateFullL();
       
   746     }
   881     }
   747 
   882 
   748 // ---------------------------------------------------------
   883 // ---------------------------------------------------------
   749 // CMailCpsHandler::HandleNewMailboxEventL
   884 // CMailCpsHandler::HandleNewMailboxEventL
   750 // ---------------------------------------------------------
   885 // ---------------------------------------------------------
   829             delete tmp;
   964             delete tmp;
   830             tmp = NULL;
   965             tmp = NULL;
   831 
   966 
   832             // Remove from cenrep
   967             // Remove from cenrep
   833             iSettings->RemoveMailboxL( aMailbox );
   968             iSettings->RemoveMailboxL( aMailbox );
       
   969             iSettings->ToggleWidgetNewMailIconL( EFalse, aMailbox );
   834             break;
   970             break;
   835             }
   971             }
   836         }
   972         }
   837     }
   973     }
   838 
   974 
   842 //
   978 //
   843 void CMailCpsHandler::HandleNewMailEventL(
   979 void CMailCpsHandler::HandleNewMailEventL(
   844     TFSMailMsgId aMailbox, TAny* aParam1, TAny* aParam2 )
   980     TFSMailMsgId aMailbox, TAny* aParam1, TAny* aParam2 )
   845     {
   981     {
   846     FUNC_LOG;
   982     FUNC_LOG;
       
   983     
       
   984     iSettings->ToggleWidgetNewMailIconL( ETrue, aMailbox );
       
   985     
   847     // Basic assertions
   986     // Basic assertions
   848     if ( !aParam1 || !aParam2 )
   987     if ( !aParam1 || !aParam2 )
   849         {
   988         {
   850         User::Leave( KErrArgument );
   989         User::Leave( KErrArgument );
   851         }
   990         }
  1587 //
  1726 //
  1588 void CMailCpsHandler::LaunchEmailUIL( const TDesC& aContentId )
  1727 void CMailCpsHandler::LaunchEmailUIL( const TDesC& aContentId )
  1589     {
  1728     {
  1590     FUNC_LOG;
  1729     FUNC_LOG;
  1591 
  1730 
  1592     TUid mailBoxUid;
  1731     TInt nativeMailboxId( iSettings->GetMailboxUidByContentId( aContentId ) );
  1593     mailBoxUid.iUid = iSettings->GetMailboxUidByContentId(aContentId);
  1732     // Is the contentId related to internal mailbox or external?
  1594     TFSMailMsgId mailBoxId;
  1733     if( nativeMailboxId )
  1595     mailBoxId.SetId(mailBoxUid.iUid);
  1734         {
  1596     TUid pluginUid;
  1735         TUid mailBoxUid;
  1597     pluginUid.iUid = iSettings->GetPluginUidByContentId(aContentId);
  1736         mailBoxUid.iUid = nativeMailboxId;
  1598     mailBoxId.SetPluginId(pluginUid);
       
  1599     CFSMailBox* mailBox = MailClient().GetMailBoxByUidL( mailBoxId );
       
  1600     CleanupStack::PushL( mailBox );
       
  1601     if ( mailBox )
       
  1602         {
       
  1603         TFSMailMsgId inboxFolderId = mailBox->GetStandardFolderId( EFSInbox );    
       
  1604         
  1737         
  1605         TMailListActivationData tmp;
  1738         TFSMailMsgId mailBoxId;
  1606         tmp.iFolderId = inboxFolderId;
  1739         mailBoxId.SetId(mailBoxUid.iUid);
  1607         tmp.iMailBoxId = mailBoxId; 
  1740         TUid pluginUid;
  1608         const TPckgBuf<TMailListActivationData> pkgOut( tmp );
  1741         pluginUid.iUid = iSettings->GetPluginUidByContentId(aContentId);
  1609         iEnv->EikAppUi()->ActivateViewL( TVwsViewId(KUidEmailUi, KMailListId), 
  1742         mailBoxId.SetPluginId(pluginUid);
  1610                                          KStartListWithFolderId, 
  1743         CFSMailBox* mailBox = MailClient().GetMailBoxByUidL( mailBoxId );
  1611                                          pkgOut);
  1744         CleanupStack::PushL( mailBox );
  1612         }
  1745         if ( mailBox )
  1613     CleanupStack::PopAndDestroy( mailBox );
  1746             {
       
  1747             TFSMailMsgId inboxFolderId = mailBox->GetStandardFolderId( EFSInbox );
       
  1748     
       
  1749             TMailListActivationData tmp;
       
  1750             tmp.iFolderId = inboxFolderId;
       
  1751             tmp.iMailBoxId = mailBoxId;
       
  1752             const TPckgBuf<TMailListActivationData> pkgOut( tmp );
       
  1753             iEnv->EikAppUi()->ActivateViewL( TVwsViewId(KUidEmailUi, KMailListId),
       
  1754                                              KStartListWithFolderId,
       
  1755                                              pkgOut);
       
  1756             }
       
  1757         CleanupStack::PopAndDestroy( mailBox );
       
  1758         }
       
  1759     else
       
  1760         {
       
  1761         LaunchExtAppL( aContentId );
       
  1762         }
  1614     }
  1763     }
  1615 
  1764 
  1616 // -----------------------------------------------------------------------------
  1765 // -----------------------------------------------------------------------------
  1617 //  CMailCpsHandler::LaunchEmailUIL()
  1766 //  CMailCpsHandler::LaunchEmailUIL()
  1618 // -----------------------------------------------------------------------------
  1767 // -----------------------------------------------------------------------------
  1623     TUid viewUid(KNullUid);
  1772     TUid viewUid(KNullUid);
  1624     iEnv->EikAppUi()->ActivateViewL( TVwsViewId(KUidWizardApp, KUidEmailWizardView), 
  1773     iEnv->EikAppUi()->ActivateViewL( TVwsViewId(KUidWizardApp, KUidEmailWizardView), 
  1625                                      viewUid, 
  1774                                      viewUid, 
  1626                                      KNullDesC8);
  1775                                      KNullDesC8);
  1627     }
  1776     }
       
  1777 
       
  1778 // -----------------------------------------------------------------------------
       
  1779 //  CMailCpsHandler::LaunchExtAppL()
       
  1780 // -----------------------------------------------------------------------------
       
  1781 //
       
  1782 void CMailCpsHandler::LaunchExtAppL( const TDesC& aContentId )
       
  1783     {
       
  1784     FUNC_LOG;
       
  1785     CMailPluginProxy* plugin = GetExtPluginL( aContentId );
       
  1786     if ( plugin )
       
  1787         {
       
  1788         plugin->LaunchExtAppL( aContentId );
       
  1789         }
       
  1790     }
       
  1791 
       
  1792 // -----------------------------------------------------------------------------
       
  1793 //  CMailCpsHandler::GetExtPluginL
       
  1794 // -----------------------------------------------------------------------------
       
  1795 //
       
  1796 CMailPluginProxy* CMailCpsHandler::GetExtPluginL( const TDesC& aContentId )
       
  1797     {
       
  1798     FUNC_LOG;
       
  1799     CMailPluginProxy* plugin( NULL );
       
  1800     for( TInt i = 0; i < iExternalPlugins.Count(); i++ )
       
  1801         {
       
  1802         if ( iExternalPlugins[i]->HasAccount( aContentId ) )
       
  1803             {
       
  1804             plugin = iExternalPlugins[i];
       
  1805             }
       
  1806         }
       
  1807     return plugin;
       
  1808     }
       
  1809 
       
  1810 // -----------------------------------------------------------------------------
       
  1811 //  CMailCpsHandler::UpdateExtAccountL
       
  1812 // -----------------------------------------------------------------------------
       
  1813 //
       
  1814 void CMailCpsHandler::UpdateExtAccountL( const TDesC& aContentId )
       
  1815     {
       
  1816     FUNC_LOG;
       
  1817     // Look up plugin that handles this account
       
  1818     CMailPluginProxy* plugin = GetExtPluginL( aContentId );
       
  1819     if ( plugin )
       
  1820         {
       
  1821         // Publish its data
       
  1822         plugin->UpdateAccountL( aContentId );
       
  1823         }
       
  1824     }
       
  1825 
  1628 // ---------------------------------------------------------------------------
  1826 // ---------------------------------------------------------------------------
  1629 // CMailCpsHandler::AssociateWidget
  1827 // CMailCpsHandler::AssociateWidget
  1630 // ---------------------------------------------------------------------------
  1828 // ---------------------------------------------------------------------------
  1631 //
  1829 //
  1632 TBool CMailCpsHandler::AssociateWidgetToSetting( const TDesC& aContentId )
  1830 TBool CMailCpsHandler::AssociateWidgetToSetting( const TDesC& aContentId )
  1650         iSettings->DissociateWidgetFromSettingL( aContentId );
  1848         iSettings->DissociateWidgetFromSettingL( aContentId );
  1651         }
  1849         }
  1652     }
  1850     }
  1653 
  1851 
  1654 // ---------------------------------------------------------------------------
  1852 // ---------------------------------------------------------------------------
       
  1853 // CMailCpsHandler::TotalMailboxCount
       
  1854 // ---------------------------------------------------------------------------
       
  1855 //
       
  1856 TInt CMailCpsHandler::TotalMailboxCountL()
       
  1857     {
       
  1858     FUNC_LOG;
       
  1859     return TotalIntMailboxCount() + TotalExtMailboxCountL();
       
  1860     }
       
  1861 
       
  1862 // ---------------------------------------------------------------------------
  1655 // CMailCpsHandler::GetMailboxCount
  1863 // CMailCpsHandler::GetMailboxCount
  1656 // ---------------------------------------------------------------------------
  1864 // ---------------------------------------------------------------------------
  1657 //
  1865 //
  1658 TInt CMailCpsHandler::GetMailboxCount()
  1866 TInt CMailCpsHandler::TotalIntMailboxCount()
  1659     {
  1867     {
  1660     FUNC_LOG;
  1868     FUNC_LOG;
  1661     return iSettings->GetTotalMailboxCount();
  1869     return iSettings->TotalIntMailboxCount();
       
  1870     }
       
  1871 
       
  1872 // ---------------------------------------------------------
       
  1873 // CMailCpsHandler::TotalExtMailboxCount
       
  1874 // ---------------------------------------------------------
       
  1875 //
       
  1876 TInt CMailCpsHandler::TotalExtMailboxCountL()
       
  1877     {
       
  1878     FUNC_LOG;
       
  1879     TInt totalMailboxCount( 0 );
       
  1880     TUid interfaceUid = TUid::Uid( KEmailObserverInterfaceUid );
       
  1881     RImplInfoPtrArray plugins;
       
  1882     CleanupClosePushL( plugins );
       
  1883     REComSession::ListImplementationsL( interfaceUid, plugins);
       
  1884 
       
  1885     for ( TInt i = 0; i < plugins.Count(); i++ )
       
  1886         {
       
  1887         TUid implUid = plugins[i]->ImplementationUid();
       
  1888         INFO_1("Instantiating plugin %d", implUid.iUid);
       
  1889         EmailInterface::CEmailObserverPlugin* plugin = 
       
  1890             EmailInterface::CEmailObserverPlugin::NewL( implUid, this );
       
  1891         MEmailData& data( plugin->EmailDataL() );
       
  1892         totalMailboxCount += data.MailboxesL().Count();
       
  1893         }
       
  1894     
       
  1895     CleanupStack::PopAndDestroy(); // plugins
       
  1896     return totalMailboxCount;
  1662     }
  1897     }
  1663 
  1898 
  1664 // ---------------------------------------------------------------------------
  1899 // ---------------------------------------------------------------------------
  1665 // CMailCpsHandler::ManualAccountSelectionL
  1900 // CMailCpsHandler::ManualAccountSelectionL
  1666 // ---------------------------------------------------------------------------
  1901 // ---------------------------------------------------------------------------
  1679     else
  1914     else
  1680         {
  1915         {
  1681         if (!iSettings->FindFromContentIdListL(aContentId))
  1916         if (!iSettings->FindFromContentIdListL(aContentId))
  1682             {
  1917             {
  1683             iSettings->AddToContentIdListL(aContentId);
  1918             iSettings->AddToContentIdListL(aContentId);
  1684             if (GetMailboxCount())
  1919             if ( TotalMailboxCountL() )
  1685                 {
  1920                 {
  1686                 LaunchWidgetSettingsL(aContentId);
  1921                 LaunchWidgetSettingsL(aContentId);
  1687                 }
  1922                 }
  1688             else
  1923             else
  1689                 {
  1924                 {
  1717         }
  1952         }
  1718 
  1953 
  1719     return ret;
  1954     return ret;
  1720     }
  1955     }
  1721 
  1956 
       
  1957 // ---------------------------------------------------------------------------
       
  1958 // CMailCpsHandler::EmailObserverEvent
       
  1959 // ---------------------------------------------------------------------------
       
  1960 void CMailCpsHandler::EmailObserverEvent( EmailInterface::MEmailData& /*aData*/ )
       
  1961     {
       
  1962     // Nothing to do
       
  1963     }