email/mail/EditorSrc/cmsgmailprioritysetting.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:  Priority setting item and setting page
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cmsgmailprioritysetting.h"
       
    20 #include "MsgMailEditorDocument.h"
       
    21 #include "MailLog.h"
       
    22 #include <MsgMailEditor.rsg>
       
    23 #include <StringLoader.h>
       
    24 
       
    25 
       
    26 inline void CMsgMailEditorPrioritySettingItem::ConstructL()
       
    27     {
       
    28     SetSettingValueL();
       
    29     }
       
    30 
       
    31 CMsgMailEditorPrioritySettingItem* 
       
    32     CMsgMailEditorPrioritySettingItem::NewL( 
       
    33     TInt aIdentifier, CMsgMailEditorDocument& aDocument )
       
    34     {
       
    35     CMsgMailEditorPrioritySettingItem* self =
       
    36         new( ELeave ) CMsgMailEditorPrioritySettingItem( 
       
    37         aIdentifier,  aDocument );
       
    38     CleanupStack::PushL( self );
       
    39 	self->ConstructL();
       
    40 	CleanupStack::Pop(self); // self
       
    41     return self;
       
    42     }
       
    43 
       
    44 
       
    45 CMsgMailEditorPrioritySettingItem::CMsgMailEditorPrioritySettingItem(
       
    46     TInt aIdentifier,
       
    47     CMsgMailEditorDocument& aDocument ): 
       
    48     CAknTextSettingItem( aIdentifier, iSettingValue ),  
       
    49     iDocument( aDocument )
       
    50     {
       
    51     // iSettingValue is set later
       
    52     }        
       
    53 
       
    54 CMsgMailEditorPrioritySettingItem::~CMsgMailEditorPrioritySettingItem()
       
    55     {
       
    56     iSettingValue.Close();
       
    57     delete iPriorityArray;
       
    58     }
       
    59 
       
    60 // ----------------------------------------------------------------------------
       
    61 //  // From CAknTextSettingItem
       
    62 // ----------------------------------------------------------------------------
       
    63 //        
       
    64 void CMsgMailEditorPrioritySettingItem::EditItemL( 
       
    65     TBool /* aCalledFromMenu */ )
       
    66     {
       
    67     TPtrC settingName = SettingName();
       
    68     TInt currentSelection( 0 );
       
    69     NameArrayL( currentSelection );
       
    70   
       
    71     CAknSettingPage* dlg = new( ELeave )CAknRadioButtonSettingPage(        
       
    72         &settingName, 
       
    73         SettingNumber(), 
       
    74         EEikCtTextButton,
       
    75         SettingEditorResourceId(), 
       
    76         SettingPageResourceId(), 
       
    77         currentSelection, 
       
    78         iPriorityArray );
       
    79     SetSettingPage( dlg );
       
    80     SettingPage()->SetSettingPageObserver( this ); // not used
       
    81     SettingPage()->ExecuteLD( CAknSettingPage::EUpdateWhenAccepted );
       
    82    
       
    83     SaveSettingValueL( currentSelection );
       
    84     SetSettingValueL();
       
    85     LoadL(); // update setting value to listbox
       
    86     UpdateListBoxTextL();    
       
    87     SetSettingPage( 0 ); // it is deleted now
       
    88     }
       
    89 
       
    90 
       
    91 // ----------------------------------------------------------------------------
       
    92 //  Create name array
       
    93 // ----------------------------------------------------------------------------
       
    94 //    
       
    95 void CMsgMailEditorPrioritySettingItem::NameArrayL(
       
    96     TInt& aSelected )
       
    97     {
       
    98     LOG("CMsgMailEditorPrioritySettingItem::NameArrayL");
       
    99       
       
   100     TInt itemCount(3);			// CSI: 47 # 3 items
       
   101     TMsvPriority priority = iDocument.CurrentEntry().Entry().Priority();
       
   102     aSelected = priority;
       
   103     delete iPriorityArray;
       
   104     iPriorityArray = NULL;
       
   105     iPriorityArray = new(ELeave)CDesCArrayFlat( itemCount );
       
   106                  
       
   107     HBufC* highPriority = GetPriorityTextLC( EMsvHighPriority );
       
   108     iPriorityArray->AppendL( *highPriority );
       
   109     CleanupStack::PopAndDestroy( highPriority );
       
   110     
       
   111     HBufC* normalPriority = GetPriorityTextLC( EMsvMediumPriority );
       
   112     iPriorityArray->AppendL( *normalPriority );
       
   113     CleanupStack::PopAndDestroy( normalPriority );    
       
   114     
       
   115     HBufC* lowPriority = GetPriorityTextLC( EMsvLowPriority );
       
   116     iPriorityArray->AppendL( *lowPriority );
       
   117     CleanupStack::PopAndDestroy( lowPriority );    
       
   118 
       
   119     ASSERT( iPriorityArray ); 
       
   120     }
       
   121 
       
   122 // ----------------------------------------------------------------------------
       
   123 //  Save selected mbox id to settings
       
   124 // ----------------------------------------------------------------------------
       
   125 //  
       
   126 void CMsgMailEditorPrioritySettingItem::SaveSettingValueL( 
       
   127     TInt aSelected )
       
   128     {
       
   129     CMsvEntry& message = iDocument.CurrentEntry();
       
   130     TMsvEntry tentry = message.Entry();
       
   131     ASSERT( tentry.iType == KUidMsvMessageEntry );    
       
   132     
       
   133     TMsvPriority newValue( EMsvMediumPriority );  
       
   134     switch ( aSelected )
       
   135         {    
       
   136         case 0: // high
       
   137             {
       
   138             newValue = EMsvHighPriority;
       
   139             break;
       
   140             }
       
   141         case 1: // normal
       
   142             {
       
   143             newValue = EMsvMediumPriority;
       
   144             break;
       
   145             }
       
   146         case 2:				// CSI: 47 # low
       
   147             {
       
   148             newValue = EMsvLowPriority;
       
   149             break;
       
   150             }
       
   151         default:
       
   152             {
       
   153             // unknown state
       
   154             ASSERT(0);
       
   155             }    
       
   156         }
       
   157     
       
   158     tentry.SetPriority( newValue );
       
   159     message.ChangeL( tentry );
       
   160     iDocument.SetChanged( ETrue );
       
   161     }
       
   162 
       
   163 // ----------------------------------------------------------------------------
       
   164 //  Set current mailbox name to setting list
       
   165 // ----------------------------------------------------------------------------
       
   166 //  
       
   167 void CMsgMailEditorPrioritySettingItem::SetSettingValueL()
       
   168     {
       
   169     ASSERT( iDocument.CurrentEntry().Entry().iType == KUidMsvMessageEntry );
       
   170     TMsvPriority priority = iDocument.CurrentEntry().Entry().Priority();
       
   171     
       
   172     HBufC* priorityText = GetPriorityTextLC( priority );
       
   173     iSettingValue.Close();
       
   174 	iSettingValue.CreateL( *priorityText );
       
   175 	CleanupStack::PopAndDestroy( priorityText );  
       
   176     }
       
   177 
       
   178 // ----------------------------------------------------------------------------
       
   179 //  get localised text for certain priority
       
   180 // ----------------------------------------------------------------------------
       
   181 //
       
   182 HBufC* CMsgMailEditorPrioritySettingItem::GetPriorityTextLC( 
       
   183     TMsvPriority aPriority )
       
   184     {
       
   185     TInt textResource(0);
       
   186     switch ( aPriority )
       
   187         {    
       
   188         case EMsvHighPriority:
       
   189             {
       
   190             textResource = R_QTN_MAIL_SETTING_PRIORITY_HIGH;
       
   191             break;
       
   192             }
       
   193         case EMsvMediumPriority:
       
   194             {
       
   195             textResource = R_QTN_MAIL_SETTING_PRIORITY_NORMAL;
       
   196             break;
       
   197             }
       
   198         case EMsvLowPriority:
       
   199             {
       
   200             textResource = R_QTN_MAIL_SETTING_PRIORITY_LOW;
       
   201             break;
       
   202             }
       
   203         default:
       
   204             {
       
   205             // unknown state
       
   206             ASSERT(0);
       
   207             }
       
   208         }
       
   209 	return StringLoader::LoadLC( textResource );    
       
   210     }
       
   211 
       
   212 // End of File