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 // |
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 { |
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, |
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 ); |
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 // --------------------------------------------------------------------------- |