email/mail/EditorSrc/cmsgmailreplytosetting.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:  Reply-to setting item and setting page
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cmsgmailreplytosetting.h"
       
    20 #include "MsgMailEditorDocument.h"
       
    21 #include "MailLog.h"
       
    22 #include "MailUtils.h"
       
    23 #include <MuiuMsvUiServiceUtilities.h>
       
    24 #include <MsgMailEditor.rsg>
       
    25 #include <StringLoader.h>
       
    26 
       
    27 // const
       
    28 const TInt KMaxEmailAddressLength(100); // KStringLength
       
    29 
       
    30 inline void CMsgMailEditorReplyToSettingItem::ConstructL()
       
    31     {  
       
    32     SetSettingValueL();
       
    33     }
       
    34 
       
    35 CMsgMailEditorReplyToSettingItem* 
       
    36     CMsgMailEditorReplyToSettingItem::NewL( 
       
    37     TInt aIdentifier, CMsgMailEditorDocument& aDocument )
       
    38     {
       
    39     CMsgMailEditorReplyToSettingItem* self =
       
    40         new( ELeave ) CMsgMailEditorReplyToSettingItem( 
       
    41         aIdentifier,  aDocument );
       
    42     CleanupStack::PushL( self );
       
    43 	self->ConstructL();
       
    44 	CleanupStack::Pop(self); // self
       
    45     return self;
       
    46     }
       
    47 
       
    48 
       
    49 CMsgMailEditorReplyToSettingItem::CMsgMailEditorReplyToSettingItem(
       
    50     TInt aIdentifier,
       
    51     CMsgMailEditorDocument& aDocument ): 
       
    52     CAknTextSettingItem( aIdentifier, iSettingValue ),  
       
    53     iDocument( aDocument )
       
    54     {
       
    55     // iSettingValue is set later   
       
    56     }        
       
    57 
       
    58 CMsgMailEditorReplyToSettingItem::~CMsgMailEditorReplyToSettingItem()
       
    59     {
       
    60     iSettingValue.Close();
       
    61     }
       
    62 
       
    63 // ----------------------------------------------------------------------------
       
    64 //  // From CAknTextSettingItem
       
    65 // ----------------------------------------------------------------------------
       
    66 //        
       
    67 void CMsgMailEditorReplyToSettingItem::EditItemL( 
       
    68     TBool /* aCalledFromMenu */ )
       
    69     {
       
    70     TPtrC settingName = SettingName();
       
    71     
       
    72     SetInitialValueL();
       
    73     CAknTextSettingItem::LoadL(); // update setting value to listbox
       
    74     SetSettingPageFlags( CAknTextSettingPage::EZeroLengthAllowed );
       
    75         
       
    76     CAknSettingPage* dlg = new( ELeave )CMsgMailEditorReplyToSettingPage(        
       
    77         &settingName, 
       
    78         SettingNumber(), 
       
    79         EEikCtTextButton,
       
    80         SettingEditorResourceId(), 
       
    81         SettingPageResourceId(), 
       
    82         InternalTextPtr(), 
       
    83         SettingPageFlags() );
       
    84     SetSettingPage( dlg );
       
    85     SettingPage()->SetSettingPageObserver( this ); // not used
       
    86     SettingPage()->ExecuteLD( CAknSettingPage::EUpdateWhenAccepted );
       
    87 
       
    88     SaveSettingValueL();
       
    89     SetSettingValueL();
       
    90     CAknTextSettingItem::LoadL(); // update setting value to listbox
       
    91     UpdateListBoxTextL();    
       
    92     SetSettingPage( 0 ); // it is deleted now
       
    93     }
       
    94     
       
    95 // ----------------------------------------------------------------------------
       
    96 //  // From CAknTextSettingItem
       
    97 // ----------------------------------------------------------------------------
       
    98 //
       
    99 void CMsgMailEditorReplyToSettingItem::LoadL()
       
   100     {
       
   101     SetSettingValueL();
       
   102     CAknTextSettingItem::LoadL();
       
   103     }
       
   104 
       
   105 // ----------------------------------------------------------------------------
       
   106 //  Save to settings
       
   107 // ----------------------------------------------------------------------------
       
   108 //  
       
   109 void CMsgMailEditorReplyToSettingItem::SaveSettingValueL()
       
   110     {
       
   111     // get store for the message
       
   112     CMsvStore* store = iDocument.CurrentEntry().EditStoreL();
       
   113     CleanupStack::PushL(store);
       
   114 
       
   115     CImHeader& header = iDocument.HeaderL();
       
   116     TPtr editedText = InternalTextPtr();
       
   117 #if defined (_UNICODE)
       
   118     header.SetReplyToL( editedText );
       
   119 #else    
       
   120     HBufC8* replyto = HBufC8::NewLC( editedText.Length() );
       
   121     replyto->Des().Copy( editedText );
       
   122     header.SetReplyToL( *replyto );
       
   123     CleanupStack::PopAndDestroy( replyto );    
       
   124 #endif // _UNICODE   
       
   125     iDocument.SetChanged( ETrue );
       
   126     
       
   127     // store message header
       
   128     header.StoreL( *store );
       
   129     store->CommitL();
       
   130     CleanupStack::PopAndDestroy( store );  
       
   131     }
       
   132 
       
   133 // ----------------------------------------------------------------------------
       
   134 //  Set current reply-to address to setting list
       
   135 // ----------------------------------------------------------------------------
       
   136 //  
       
   137 void CMsgMailEditorReplyToSettingItem::SetSettingValueL()
       
   138     {
       
   139     // Reply to address
       
   140    	CImHeader& header = iDocument.HeaderL();
       
   141 
       
   142     iSettingValue.Close();
       
   143     iSettingValue.CreateL( header.ReplyTo() );
       
   144     }
       
   145     
       
   146 // ----------------------------------------------------------------------------
       
   147 //  Set initial value to editor
       
   148 // ----------------------------------------------------------------------------
       
   149 //  
       
   150 void CMsgMailEditorReplyToSettingItem::SetInitialValueL()
       
   151     {
       
   152     // alloc new buffer for new value
       
   153     iSettingValue.Close();
       
   154     iSettingValue.CreateL( KMaxEmailAddressLength );
       
   155     
       
   156     // current Reply to address
       
   157    	CImHeader& header = iDocument.HeaderL();    
       
   158     iSettingValue.Append( header.ReplyTo() );
       
   159     }
       
   160     
       
   161 CMsgMailEditorReplyToSettingPage::CMsgMailEditorReplyToSettingPage(
       
   162     TInt aResourceID,
       
   163     TDes& aText, 
       
   164     TInt aTextSettingPageFlags )
       
   165     : CAknTextSettingPage( 
       
   166         aResourceID, aText, aTextSettingPageFlags )
       
   167 	{
       
   168 	}
       
   169 
       
   170 CMsgMailEditorReplyToSettingPage::CMsgMailEditorReplyToSettingPage(	
       
   171     const TDesC* aSettingText, 
       
   172     TInt aSettingNumber, 
       
   173     TInt aControlType,
       
   174     TInt aEditorResourceId, 
       
   175     TInt aResourceID,
       
   176     TDes& aText, 
       
   177     TInt aTextSettingPageFlags )
       
   178     : CAknTextSettingPage( 
       
   179       aSettingText, 
       
   180       aSettingNumber,
       
   181       aControlType, 
       
   182       aEditorResourceId, 
       
   183       aResourceID,
       
   184       aText,
       
   185       aTextSettingPageFlags )
       
   186     {
       
   187     }
       
   188 
       
   189 CMsgMailEditorReplyToSettingPage::~CMsgMailEditorReplyToSettingPage()
       
   190 	{
       
   191 	}
       
   192 
       
   193 // ----------------------------------------------------------------------------
       
   194 //  From CAknTextSettingPage
       
   195 // ----------------------------------------------------------------------------
       
   196 // 
       
   197 TBool CMsgMailEditorReplyToSettingPage::OkToExitL( TBool aAccept )
       
   198     {
       
   199     if ( !aAccept )
       
   200         {
       
   201         return ETrue;
       
   202         }    
       
   203     
       
   204     TBool retVal( ETrue );
       
   205     HBufC* editedText = TextControl()->GetTextInHBufL();
       
   206     if ( editedText && editedText->Length() )
       
   207         {
       
   208         CleanupStack::PushL( editedText );
       
   209         retVal = MsvUiServiceUtilities::IsValidEmailAddressL( *editedText );
       
   210         CleanupStack::PopAndDestroy( editedText );
       
   211         }
       
   212     if ( !retVal )
       
   213         {
       
   214         MailUtils::InformationNoteL( R_QTN_MCE_ERROR_MISSING_CHARACTER );
       
   215         // Highlight the email address if it is in a wrong format.
       
   216         TextControl()->SelectAllL();
       
   217         }
       
   218    
       
   219     return retVal;
       
   220     }
       
   221 // End of File