email/mail/EditorSrc/cmsgmailremotemailboxsetting.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Remote mailbox setting item and setting page
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cmsgmailremotemailboxsetting.h"
       
    20 #include "MsgMailEditorDocument.h"
       
    21 #include "MailLog.h"
       
    22 #include <MsgMailEditor.rsg>
       
    23 #include <StringLoader.h>
       
    24 #include <ImumInternalApi.h>
       
    25 #include <ImumInHealthServices.h>
       
    26 #include <muiuflags.h>
       
    27 #include <cemailaccounts.h>				// CEmailAccounts
       
    28 
       
    29 inline void CMsgMailEditorRemoteMailboxSettingItem::ConstructL()
       
    30     {
       
    31     SetSettingValueL();
       
    32     }
       
    33 
       
    34 CMsgMailEditorRemoteMailboxSettingItem* 
       
    35     CMsgMailEditorRemoteMailboxSettingItem::NewL( 
       
    36     TInt aIdentifier, CMsgMailEditorDocument& aDocument )
       
    37     {
       
    38         CMsgMailEditorRemoteMailboxSettingItem* self =
       
    39             new( ELeave ) CMsgMailEditorRemoteMailboxSettingItem( 
       
    40             aIdentifier,  aDocument );
       
    41         CleanupStack::PushL( self );
       
    42     	self->ConstructL();
       
    43     	CleanupStack::Pop(self); // self
       
    44         return self;
       
    45     }
       
    46 
       
    47 
       
    48 CMsgMailEditorRemoteMailboxSettingItem::CMsgMailEditorRemoteMailboxSettingItem(
       
    49     TInt aIdentifier,
       
    50     CMsgMailEditorDocument& aDocument ): 
       
    51     CAknTextSettingItem( aIdentifier, iSettingValue ),  
       
    52     iDocument( aDocument )
       
    53     {
       
    54     // iSettingValue is set later
       
    55     }        
       
    56 
       
    57 CMsgMailEditorRemoteMailboxSettingItem::~CMsgMailEditorRemoteMailboxSettingItem()
       
    58     {
       
    59     iSettingValue.Close();
       
    60     delete iMailBoxIdArray;
       
    61     delete iServiceArray;
       
    62     }
       
    63 
       
    64 // ----------------------------------------------------------------------------
       
    65 //  // From CAknTextSettingItem
       
    66 // ----------------------------------------------------------------------------
       
    67 //        
       
    68 void CMsgMailEditorRemoteMailboxSettingItem::EditItemL( 
       
    69     TBool /* aCalledFromMenu */ )
       
    70     {
       
    71     TPtrC settingName = SettingName();
       
    72     TInt currentSelection( KErrNotFound );
       
    73     NameArrayL( currentSelection );
       
    74   
       
    75     CAknSettingPage* dlg = new( ELeave )CAknRadioButtonSettingPage(        
       
    76         &settingName, 
       
    77         SettingNumber(), 
       
    78         EEikCtTextButton,
       
    79         SettingEditorResourceId(), 
       
    80         SettingPageResourceId(), 
       
    81         currentSelection, 
       
    82         iMailBoxIdArray );
       
    83     SetSettingPage( dlg );
       
    84     SettingPage()->SetSettingPageObserver( this ); 
       
    85     SettingPage()->ExecuteLD( CAknSettingPage::EUpdateWhenAccepted );
       
    86    
       
    87     SaveSettingValueL( currentSelection );
       
    88     SetSettingValueL();
       
    89     LoadL(); // update setting value to listbox
       
    90     UpdateListBoxTextL();    
       
    91     SetSettingPage( 0 ); // it is deleted now
       
    92     }
       
    93 
       
    94 
       
    95 // ----------------------------------------------------------------------------
       
    96 //  Create name array
       
    97 // ----------------------------------------------------------------------------
       
    98 //    
       
    99 void CMsgMailEditorRemoteMailboxSettingItem::NameArrayL(
       
   100     TInt& aSelected )
       
   101     {
       
   102     LOG("CMsgMailEditorRemoteMailboxSettingItem::NameArrayL");
       
   103     
       
   104     // TImumInMboxListRequest does not work so we need to do this hard way
       
   105     // POP & IMAP service iRelatedId points to STMP service, so we use that
       
   106     TInt64 flags = MImumInHealthServices::EFlagSetHealthyReceiving;
       
   107     MImumInHealthServices::RMailboxIdArray mbox = 
       
   108         iDocument.GetHealthyMailboxListL( flags );
       
   109     TInt itemCount = mbox.Count();
       
   110     
       
   111     //+1 if itemCount=0
       
   112     delete iMailBoxIdArray;
       
   113     iMailBoxIdArray = NULL;
       
   114     iMailBoxIdArray = new(ELeave)CDesCArrayFlat(itemCount+1);
       
   115         
       
   116     delete iServiceArray;
       
   117     iServiceArray = NULL;
       
   118     iServiceArray = new(ELeave) CMsvEntrySelection;
       
   119           
       
   120     TMsvId id;
       
   121     TMsvEntry entry;
       
   122     CMsvSession& session = iDocument.Session();   
       
   123     for(TInt i=0; i<itemCount; i++)
       
   124         {
       
   125         session.GetEntry(mbox[i], id, entry);
       
   126         iMailBoxIdArray->AppendL(entry.iDetails);
       
   127         if ( entry.iDetails == SettingTextL() )
       
   128             {
       
   129             // set selection index
       
   130             aSelected = iMailBoxIdArray->Count() - 1;
       
   131             }
       
   132         iServiceArray->AppendL( entry.iRelatedId );  
       
   133         }
       
   134     ASSERT( iServiceArray->Count() == iMailBoxIdArray->Count() ); 
       
   135     }
       
   136 
       
   137 // ----------------------------------------------------------------------------
       
   138 //  Save selected mbox id to settings
       
   139 // ----------------------------------------------------------------------------
       
   140 //  
       
   141 void CMsgMailEditorRemoteMailboxSettingItem::SaveSettingValueL( 
       
   142     TInt aSelected )
       
   143     {
       
   144     ASSERT( iServiceArray );
       
   145     if( aSelected != KErrNotFound )
       
   146         {
       
   147         ASSERT( aSelected >= 0 && aSelected < iServiceArray->Count() );
       
   148         iDocument.SendOptions().SetServiceId( (*iServiceArray)[aSelected] );
       
   149         iDocument.SetChanged( ETrue );
       
   150         
       
   151         //Update header because mailbox is selected.
       
   152         UpdateReplyToL(aSelected);
       
   153         }
       
   154     }
       
   155     
       
   156 // ----------------------------------------------------------------------------
       
   157 //  Updates Reply-to value for mail header.
       
   158 // ----------------------------------------------------------------------------
       
   159 //  
       
   160 void CMsgMailEditorRemoteMailboxSettingItem::UpdateReplyToL( 
       
   161     TInt aSelected )
       
   162     {
       
   163     //Get smtp account and load smtp settings
       
   164 	CEmailAccounts* smtpAccount = CEmailAccounts::NewLC();
       
   165     CImSmtpSettings* smtpSet=new(ELeave)CImSmtpSettings();
       
   166     CleanupStack::PushL(smtpSet);
       
   167     
       
   168     TInt tempArrayCount = iServiceArray->Count();
       
   169     
       
   170     
       
   171     // Checks that a aSelected is in the leagal range.
       
   172     if( !( aSelected >= 0 && aSelected < tempArrayCount ) )
       
   173     	{
       
   174     	return;
       
   175     	}
       
   176     
       
   177     const TMsvId smtpSetId = (*iServiceArray)[aSelected];
       
   178 
       
   179     TSmtpAccount accountParams;
       
   180     smtpAccount->GetSmtpAccountL( smtpSetId, accountParams );
       
   181 	smtpAccount->LoadSmtpSettingsL(accountParams, *smtpSet);
       
   182         
       
   183     //Check that if reply to address is same as mailbox address
       
   184     //do not add "reply to" field for header. Otherwise "reply to" field
       
   185     //would always be visible.
       
   186     if(smtpSet->ReplyToAddress().Compare(smtpSet->EmailAddress() ) != 0)
       
   187         {
       
   188         CImHeader& header = iDocument.HeaderL();
       
   189         header.SetReplyToL( smtpSet->ReplyToAddress() );
       
   190         }    
       
   191     else
       
   192     	{
       
   193         CImHeader& header = iDocument.HeaderL();
       
   194         header.SetReplyToL( KNullDesC16 );
       
   195     	}
       
   196     CleanupStack::PopAndDestroy(2, smtpAccount);		// CSI: 47,12 # smtpAccount, smtpSet   
       
   197     
       
   198     }
       
   199 
       
   200 // ----------------------------------------------------------------------------
       
   201 //  Set current mailbox name to setting list
       
   202 // ----------------------------------------------------------------------------
       
   203 //  
       
   204 void CMsgMailEditorRemoteMailboxSettingItem::SetSettingValueL()
       
   205     {
       
   206    	CMsgMailPreferences& prefs = iDocument.SendOptions();
       
   207 	// set current remote mailbox name to listbox
       
   208 	TMsvId service( prefs.ServiceId() );  //get current Service id
       
   209 	TMsvId parent(0);
       
   210 	TMsvEntry child;
       
   211 
       
   212 	TInt err( iDocument.Session().GetEntry(service, parent, child) );
       
   213     
       
   214     iSettingValue.Close();
       
   215 	if (!err)
       
   216 		{
       
   217 		iSettingValue.CreateL( child.iDetails );
       
   218 		}
       
   219 	else
       
   220 		{
       
   221 		HBufC* noRmBox = StringLoader::LoadLC(R_TEXT_NO_RMBOX);
       
   222 		iSettingValue.CreateL( *noRmBox );
       
   223 		CleanupStack::PopAndDestroy(noRmBox); //noRmBox
       
   224 		}
       
   225     }
       
   226 
       
   227 // End of File