phonebookui/Phonebook2/UIControls/src/CPbk2MemoryEntryDefaultsDlg.cpp
branchRCL_3
changeset 6 e8e3147d53eb
parent 0 e686773b3f54
child 7 b3431bff8c19
--- a/phonebookui/Phonebook2/UIControls/src/CPbk2MemoryEntryDefaultsDlg.cpp	Fri Mar 12 15:41:25 2010 +0200
+++ b/phonebookui/Phonebook2/UIControls/src/CPbk2MemoryEntryDefaultsDlg.cpp	Mon Mar 15 12:39:26 2010 +0200
@@ -59,6 +59,10 @@
 #include <aknlists.h>
 #include <aknPopup.h>
 
+// For checking mailbox accounts
+#include <EmailInterfaceFactory.h>
+#include <MEmailMailbox.h>
+
 // Debugging headers
 #include <Pbk2Debug.h>
 
@@ -798,11 +802,13 @@
     {
     TBool ret(ETrue);
 
-    // Skip the line if Email field not supported
-    if ( aSelectorID == VPbkFieldTypeSelectorFactory::EEmailEditorSelector &&
-         !FeatureManager::FeatureSupported( KFeatureIdEmailUi ) )
+    // Skip the line if Email field not supported or having no mailbox
+    if ( aSelectorID == VPbkFieldTypeSelectorFactory::EEmailEditorSelector )
         {
-        ret = EFalse;
+        if ( !FeatureManager::FeatureSupported( KFeatureIdEmailUi ) || !HasMailboxAccountsL() )
+        	{
+        	ret = EFalse;
+        	}
         }
     // Do not add video fields if they are not enabled
     else if ( ( aSelectorID == VPbkFieldTypeSelectorFactory::EVideoCallSelector ) &&
@@ -827,6 +833,41 @@
     }
 
 // --------------------------------------------------------------------------
+// CPbk2MemoryEntryDefaultsDlg::HasMailboxAccountsL
+// --------------------------------------------------------------------------
+//
+TBool CPbk2MemoryEntryDefaultsDlg::HasMailboxAccountsL() const
+	{
+	using namespace EmailInterface;
+
+	TBool result = EFalse;
+	CEmailInterfaceFactory* factory = CEmailInterfaceFactory::NewL();
+	CleanupStack::PushL( factory );
+	MEmailInterface* ifPtr = factory->InterfaceL( KEmailClientApiInterface );
+	MEmailClientApi* clientApi = static_cast<MEmailClientApi*>( ifPtr );
+	CleanupReleasePushL( *clientApi );
+	
+	// Get mailboxs
+	RMailboxPtrArray mailboxes;
+	clientApi->GetMailboxesL( mailboxes );
+	TInt count = mailboxes.Count();	
+	if ( count > 0 )
+		{
+		result = ETrue;
+		}
+	
+	// Release mailboxs before releasing clientapi
+	for ( TInt i=0; i<count; i++ )
+		{
+		MEmailMailbox* mailbox = mailboxes[i];
+		mailbox->Release();
+		}	
+	mailboxes.Close();	
+	CleanupStack::PopAndDestroy( 2 ); // clientApi and factory
+	
+	return result;
+	}
+// --------------------------------------------------------------------------
 // CPbk2MemoryEntryDefaultsDlg::IsAvailable
 // --------------------------------------------------------------------------
 //