remotemgmt_plat/syncml_ds_customization_api/tsrc/SyncFwCustomizer/src/SyncFwCustomizerSettingItemList.cpp
branchRCL_3
changeset 11 06f47423ecee
equal deleted inserted replaced
9:57a65a3a658c 11:06f47423ecee
       
     1 /*
       
     2 * Copyright (c) 2009 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <avkon.hrh>
       
    19 #include <avkon.rsg>
       
    20 #include <eikmenup.h>
       
    21 #include <aknappui.h>
       
    22 #include <eikcmobs.h>
       
    23 #include <barsread.h>
       
    24 #include <stringloader.h>
       
    25 #include <gdi.h>
       
    26 #include <eikedwin.h>
       
    27 #include <eikenv.h>
       
    28 #include <aknnumedwin.h>
       
    29 #include <aknpopupfieldtext.h>
       
    30 #include <eikappui.h>
       
    31 #include <aknviewappui.h>
       
    32 #include <SyncFwCustomizer.rsg>
       
    33 #include <centralrepository.h>
       
    34 #include <NSmlOperatorDataCRKeys.h>
       
    35 
       
    36 #include "SyncFwCustomizerSettingItemList.h"
       
    37 #include "SyncFwCustomizerSettingItemListSettings.h"
       
    38 #include "SyncFwCustomizer.hrh"
       
    39 #include "SyncFwCustomizerSettingItemList.hrh"
       
    40 #include "SyncFwCustomizerSettingItemListView.h"
       
    41 
       
    42 /**
       
    43  * Construct the CSyncFwCustomizerSettingItemList instance
       
    44  * @param aCommandObserver command observer
       
    45  */ 
       
    46 CSyncFwCustomizerSettingItemList::CSyncFwCustomizerSettingItemList( 
       
    47 		TSyncFwCustomizerSettingItemListSettings& aSettings, 
       
    48 		MEikCommandObserver* aCommandObserver,
       
    49         CRepository& aRepository )
       
    50 	: iSettings( aSettings ), 
       
    51 	  iCommandObserver( aCommandObserver ), 
       
    52 	  iRepository( aRepository )
       
    53 	{
       
    54 	}
       
    55 
       
    56 /** 
       
    57  * Destroy any instance variables
       
    58  */
       
    59 CSyncFwCustomizerSettingItemList::~CSyncFwCustomizerSettingItemList()
       
    60 	{
       
    61 	}
       
    62 
       
    63 /**
       
    64  * Handle system notification that the container's size has changed.
       
    65  */
       
    66 void CSyncFwCustomizerSettingItemList::SizeChanged()
       
    67 	{
       
    68 	if ( ListBox() ) 
       
    69 		{
       
    70 		ListBox()->SetRect( Rect() );
       
    71 		}
       
    72 	}
       
    73 
       
    74 /**
       
    75  * Create one setting item at a time, identified by id.
       
    76  * CAknSettingItemList calls this method and takes ownership
       
    77  * of the returned value.  The CAknSettingItem object owns
       
    78  * a reference to the underlying data, which EditItemL() uses
       
    79  * to edit and store the value.
       
    80  */
       
    81 CAknSettingItem* CSyncFwCustomizerSettingItemList::CreateSettingItemL( TInt aId )
       
    82 	{
       
    83 	switch ( aId )
       
    84 		{
       
    85 		case ESyncFwCustomizerSettingItemListViewEdit1:
       
    86 			{			
       
    87 			CAknTextSettingItem* item = new ( ELeave ) 
       
    88 				CAknTextSettingItem( 
       
    89 					aId,
       
    90 					iSettings.ServerUrl() );
       
    91 			return item;
       
    92 			}
       
    93 			
       
    94 		case ESyncFwCustomizerSettingItemListViewSyncAdapterEditor:
       
    95 			{			
       
    96 			CAknIntegerEdwinSettingItem* item = new ( ELeave ) 
       
    97 				CAknIntegerEdwinSettingItem( 
       
    98 					aId,
       
    99 					iSettings.OperatorAdapterUid() );
       
   100 			return item;			
       
   101 			}
       
   102 			
       
   103 		case ESyncFwCustomizerSettingItemListViewIntegerEditor2:
       
   104 			{			
       
   105 			CAknIntegerEdwinSettingItem* item = new ( ELeave ) 
       
   106 				CAknIntegerEdwinSettingItem( 
       
   107 					aId,
       
   108 					iSettings.ProfileAdapterUid() );
       
   109 			return item;
       
   110 			}
       
   111 			
       
   112 		case ESyncFwCustomizerSettingItemListViewEdit2:
       
   113 			{			
       
   114 			CAknTextSettingItem* item = new ( ELeave ) 
       
   115 				CAknTextSettingItem( 
       
   116 					aId,
       
   117 					iSettings.SwV() );
       
   118 			return item;
       
   119 			}
       
   120 			
       
   121 		case ESyncFwCustomizerSettingItemListViewEdit3:
       
   122 			{			
       
   123 			CAknTextSettingItem* item = new ( ELeave ) 
       
   124 				CAknTextSettingItem( 
       
   125 					aId,
       
   126 					iSettings.Mod() );
       
   127 			return item;
       
   128 			}
       
   129 			
       
   130 		case ESyncFwCustomizerSettingItemListViewEnumeratedTextPopup1:
       
   131 			{			
       
   132 			CAknEnumeratedTextPopupSettingItem* item = new ( ELeave ) 
       
   133 				CAknEnumeratedTextPopupSettingItem( 
       
   134 					aId,
       
   135 					iSettings.SyncProfileVisibility() );
       
   136 			return item;
       
   137 			}
       
   138 			
       
   139 		case ESyncFwCustomizerSettingItemListViewEdit4:
       
   140 			{			
       
   141 			CAknTextSettingItem* item = new ( ELeave ) 
       
   142 				CAknTextSettingItem( 
       
   143 					aId,
       
   144 					iSettings.OperatorServerId() );
       
   145 			return item;
       
   146 			}
       
   147 		}
       
   148 		
       
   149 	return NULL;
       
   150 	}
       
   151 	
       
   152 /**
       
   153  * Edit the setting item identified by the given id and store
       
   154  * the changes into the store.
       
   155  * @param aIndex the index of the setting item in SettingItemArray()
       
   156  * @param aCalledFromMenu true: a menu item invoked editing, thus
       
   157  *	always show the edit page and interactively edit the item;
       
   158  *	false: change the item in place if possible, else show the edit page
       
   159  */
       
   160 void CSyncFwCustomizerSettingItemList::EditItemL ( TInt aIndex, TBool aCalledFromMenu )
       
   161 	{
       
   162 	CAknSettingItem* item = ( *SettingItemArray() )[aIndex];
       
   163 	switch ( item->Identifier() )
       
   164 		{
       
   165 		}
       
   166 	
       
   167 	CAknSettingItemList::EditItemL( aIndex, aCalledFromMenu );
       
   168 	
       
   169 	TBool storeValue = ETrue;
       
   170 	switch ( item->Identifier() )
       
   171 		{
       
   172 		}
       
   173 		
       
   174 	if ( storeValue )
       
   175 		{
       
   176 		item->StoreL();
       
   177 		SaveSettingValuesL();
       
   178 		}	
       
   179 	}
       
   180 
       
   181 /**
       
   182  *	Handle the "Change" option on the Options menu.  This is an
       
   183  *	alternative to the Selection key that forces the settings page
       
   184  *	to come up rather than changing the value in place (if possible).
       
   185  */
       
   186 void CSyncFwCustomizerSettingItemList::ChangeSelectedItemL()
       
   187 	{
       
   188 	if ( ListBox()->CurrentItemIndex() >= 0 )
       
   189 		{
       
   190 		EditItemL( ListBox()->CurrentItemIndex(), ETrue );
       
   191 		}
       
   192 	}
       
   193 
       
   194 void CSyncFwCustomizerSettingItemList::ResetSelectedItemL()
       
   195     {
       
   196     TInt key = 0;
       
   197     switch( ListBox()->CurrentItemIndex() )
       
   198         {
       
   199         case 0:
       
   200             key = KNsmlOpDsOperatorSyncServerURL;
       
   201             break;
       
   202         case 1:
       
   203             key = KNsmlOpDsOperatorAdapterUid;
       
   204             break;
       
   205         case 2:
       
   206             key = KNsmlOpDsProfileAdapterUid;
       
   207             break;
       
   208         case 3:
       
   209             key = KNsmlOpDsDevInfoSwVValue;
       
   210             break;
       
   211         case 4:
       
   212             key = KNsmlOpDsDevInfoModValue;
       
   213             break;
       
   214         case 5:
       
   215             key =  KNsmlOpDsSyncProfileVisibility;
       
   216             break;
       
   217         case 6:
       
   218             key = KNsmlOpDsOperatorSyncServerId;
       
   219             break;
       
   220         default:
       
   221             iRepository.Reset();
       
   222             break;
       
   223         }
       
   224 
       
   225     iRepository.Reset( key );
       
   226     LoadSettingValuesL();
       
   227     LoadSettingsL();
       
   228     DrawDeferred();
       
   229     }
       
   230 
       
   231 /**
       
   232  *	Load the initial contents of the setting items.  By default,
       
   233  *	the setting items are populated with the default values from
       
   234  * 	the design.  You can override those values here.
       
   235  *	<p>
       
   236  *	Note: this call alone does not update the UI.  
       
   237  *	LoadSettingsL() must be called afterwards.
       
   238  */
       
   239 void CSyncFwCustomizerSettingItemList::LoadSettingValuesL()
       
   240 	{
       
   241     TBuf<100> tmpDesc;  
       
   242     TBuf8<100> tmpDesc8;  
       
   243     TInt tmpInt = 0;
       
   244     
       
   245     iRepository.Get( KNsmlOpDsOperatorSyncServerURL, tmpDesc );
       
   246     iSettings.SetServerUrl( tmpDesc );
       
   247         
       
   248     iRepository.Get( KNsmlOpDsOperatorAdapterUid, tmpInt );     
       
   249     iSettings.SetOperatorAdapterUid( tmpInt ); 
       
   250     
       
   251     iRepository.Get( KNsmlOpDsProfileAdapterUid, tmpInt );     
       
   252     iSettings.SetProfileAdapterUid( tmpInt ); 
       
   253     
       
   254     iRepository.Get( KNsmlOpDsDevInfoSwVValue, tmpDesc8 );
       
   255     iSettings.SetSwV( tmpDesc8 );
       
   256 
       
   257     iRepository.Get( KNsmlOpDsDevInfoModValue, tmpDesc8 );
       
   258     iSettings.SetMod( tmpDesc8 );
       
   259 
       
   260     iRepository.Get( KNsmlOpDsSyncProfileVisibility, tmpInt );
       
   261     iSettings.SetSyncProfileVisibility( tmpInt );
       
   262     
       
   263     iRepository.Get( KNsmlOpDsOperatorSyncServerId, tmpDesc8 );
       
   264     iSettings.SetOperatorServerId( tmpDesc8 );   
       
   265 	}
       
   266 	
       
   267 /**
       
   268  *	Save the contents of the setting items.  Note, this is called
       
   269  *	whenever an item is changed and stored to the model, so it
       
   270  *	may be called multiple times or not at all.
       
   271  */
       
   272 void CSyncFwCustomizerSettingItemList::SaveSettingValuesL()
       
   273 	{
       
   274     TBuf<100> tmpDesc;  
       
   275     TBuf8<100> tmpDesc8;  
       
   276     TInt tmpInt = 0;
       
   277     
       
   278     tmpDesc = iSettings.ServerUrl();
       
   279     iRepository.Set( KNsmlOpDsOperatorSyncServerURL, tmpDesc );
       
   280         
       
   281     tmpInt = iSettings.OperatorAdapterUid(); 
       
   282     iRepository.Set( KNsmlOpDsOperatorAdapterUid, tmpInt );     
       
   283     
       
   284     tmpInt = iSettings.ProfileAdapterUid(); 
       
   285     iRepository.Set( KNsmlOpDsProfileAdapterUid, tmpInt );     
       
   286     
       
   287     tmpDesc8.Copy( iSettings.SwV() );
       
   288     iRepository.Set( KNsmlOpDsDevInfoSwVValue, tmpDesc8 );
       
   289 
       
   290     tmpDesc8.Copy( iSettings.Mod() );
       
   291     iRepository.Set( KNsmlOpDsDevInfoModValue, tmpDesc8 );
       
   292 
       
   293     tmpInt = iSettings.SyncProfileVisibility();
       
   294     iRepository.Set( KNsmlOpDsSyncProfileVisibility, tmpInt );
       
   295     
       
   296     tmpDesc8.Copy( iSettings.OperatorServerId() );
       
   297     iRepository.Set( KNsmlOpDsOperatorSyncServerId, tmpDesc8 );
       
   298 	}
       
   299 
       
   300 /** 
       
   301  * Handle global resource changes, such as scalable UI or skin events (override)
       
   302  */
       
   303 void CSyncFwCustomizerSettingItemList::HandleResourceChange( TInt aType )
       
   304 	{
       
   305 	CAknSettingItemList::HandleResourceChange( aType );
       
   306 	SetRect( iAvkonViewAppUi->View( TUid::Uid( ESyncFwCustomizerSettingItemListViewId ) )->ClientRect() );
       
   307 	}
       
   308 				
       
   309 /** 
       
   310  * Handle key event (override)
       
   311  * @param aKeyEvent key event
       
   312  * @param aType event code
       
   313  * @return EKeyWasConsumed if the event was handled, else EKeyWasNotConsumed
       
   314  */
       
   315 TKeyResponse CSyncFwCustomizerSettingItemList::OfferKeyEventL( 
       
   316 		const TKeyEvent& aKeyEvent, 
       
   317 		TEventCode aType )
       
   318 	{
       
   319 	if ( aKeyEvent.iCode == EKeyLeftArrow 
       
   320 		|| aKeyEvent.iCode == EKeyRightArrow )
       
   321 		{
       
   322 		// allow the tab control to get the arrow keys
       
   323 		return EKeyWasNotConsumed;
       
   324 		}
       
   325 	
       
   326 	return CAknSettingItemList::OfferKeyEventL( aKeyEvent, aType );
       
   327 	}
       
   328