multimediacommsengine/tsrc/testdriver/testclient/ui/src/CTcSettingsDialogS60.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <aknlists.h>
       
    19 #include <aknsettingitemlist.h>
       
    20 #include <akntitle.h>
       
    21 
       
    22 #include "CTcIAPManager.h"
       
    23 #include "CTcSettingsDialog.h"
       
    24 
       
    25 #include "TTcSettings.h"
       
    26 #include "TestClient.hrh"
       
    27 #include <TestClient.rsg>
       
    28 
       
    29 CTcSettingsDialog::CTcSettingsDialog( TTcSettings& aSettings )
       
    30 	: iSettings( aSettings ),
       
    31 	  iSettingItems( 2, EFalse, 1 )	// granularity, isnumered, 1st ordinal
       
    32 	{
       
    33 	}
       
    34 
       
    35 CTcSettingsDialog::~CTcSettingsDialog()
       
    36 	{
       
    37 	// Delete setting items
       
    38 	iSettingItems.ResetAndDestroy();
       
    39 	// Set title pane text back to default, ignore any errors
       
    40 	TRAP_IGNORE( SetTitleL( -1 ) )
       
    41 	delete iIAPManager;
       
    42 	}
       
    43 
       
    44 void CTcSettingsDialog::ConstructL()
       
    45 	{
       
    46 	// Use base class to construct our menubar
       
    47 	CAknDialog::ConstructL( R_TC_SETTINGS_MENUBAR );
       
    48 	iIAPManager = CTcIAPManager::NewL();
       
    49 	// Make sure there's at least one IAP
       
    50 	if( iIAPManager->Count() == 0 )
       
    51 		{
       
    52 		User::Leave( KErrNotSupported );
       
    53 		}
       
    54 	}
       
    55 
       
    56 void CTcSettingsDialog::PreLayoutDynInitL()
       
    57 	{
       
    58 	TInt id( 0 );
       
    59  	HBufC* itemTitle;
       
    60 	CAknSettingItem* settingItem;
       
    61 
       
    62 	// Create and initialize Bearer setting item from the resource file.
       
    63 	CAknEnumeratedTextPopupSettingItem* textSettingItem =
       
    64 								new( ELeave ) CAknEnumeratedTextPopupSettingItem( 0, iSettings.iBearerType );
       
    65 	CleanupStack::PushL( textSettingItem );
       
    66 	itemTitle = iCoeEnv->AllocReadResourceLC( R_TC_SETTINGS_MODE_TITLE );
       
    67 	textSettingItem->ConstructL( EFalse, id++, *itemTitle, NULL, R_TC_SETTINGS_MODE_PAGE, EAknCtPopupField, 0, R_TC_SETTINGS_MODE_TEXTS );
       
    68 	CleanupStack::PopAndDestroy(); // itemTitle
       
    69 	iSettingItems.AppendL( textSettingItem );
       
    70 	CleanupStack::Pop(); // textSettingItem
       
    71 	
       
    72 	
       
    73 	// Create and initialize remote tcp address setting item from the resource file.
       
    74 	iSettings.iTCPRemoteAddr.Output( iRemoteAddrText );
       
    75 	settingItem = new( ELeave ) CAknTextSettingItem( 0, iRemoteAddrText );
       
    76 	CleanupStack::PushL( settingItem );
       
    77 	_LIT(KEmptyItemText, "None");
       
    78 	settingItem->SetEmptyItemTextL(KEmptyItemText);
       
    79 	itemTitle = iCoeEnv->AllocReadResourceLC( R_TC_SETTINGS_TCPREMOTEADDR_TITLE );
       
    80 	settingItem->ConstructL( EFalse, id++, *itemTitle, NULL, R_TC_SETTINGS_TCPREMOTEADDR_PAGE, -1 );
       
    81 	CleanupStack::PopAndDestroy(); // itemTitle
       
    82 	iSettingItems.AppendL( settingItem );
       
    83 	CleanupStack::Pop(); // settingitem
       
    84 
       
    85 	// Create and initialize TCP port setting item from the resource file.
       
    86 	settingItem = new( ELeave ) CAknIntegerEdwinSettingItem( 0, iSettings.iTCPPort );
       
    87 	CleanupStack::PushL( settingItem );
       
    88 	itemTitle = iCoeEnv->AllocReadResourceLC( R_TC_SETTINGS_TCPPORT_TITLE );
       
    89 	settingItem->ConstructL( EFalse, id++, *itemTitle, NULL, R_TC_SETTINGS_TCPPORT_PAGE, EEikCtEdwin );
       
    90 	CleanupStack::PopAndDestroy(); // itemTitle
       
    91 	iSettingItems.AppendL( settingItem );
       
    92 	CleanupStack::Pop(); // settingitem
       
    93 
       
    94 	// Create and initialize IAP name setting item from the resource file.
       
    95 	TUint32 tmpId( iSettings.iIAPId );
       
    96 	iSettings.iIAPId = 0;
       
    97 	textSettingItem = new( ELeave ) CAknEnumeratedTextPopupSettingItem( 0, iSettings.iIAPId );
       
    98 	CleanupStack::PushL( textSettingItem );
       
    99 	itemTitle = iCoeEnv->AllocReadResourceLC( R_TC_SETTINGS_IAPNAME_TITLE );
       
   100 	textSettingItem->ConstructL( EFalse, id++, *itemTitle, NULL, R_TC_SETTINGS_IAPNAME_PAGE, EAknCtPopupField, 0, R_TC_SETTINGS_IAPNAME_TEXTS );
       
   101 	CleanupStack::PopAndDestroy(); // itemTitle
       
   102 	iSettingItems.AppendL( textSettingItem );
       
   103 	CleanupStack::Pop(); // textSettingItem
       
   104 
       
   105 	// Get text array from setting item
       
   106 	CArrayPtr< CAknEnumeratedText >* texts = textSettingItem->EnumeratedTextArray();
       
   107 	CAknEnumeratedText* dummy = texts->At( 0 );
       
   108 	texts->Delete( 0 );
       
   109 	delete dummy;
       
   110 
       
   111 	// Populate text array from IAP Manager
       
   112 	TInt count = iIAPManager->Count();
       
   113 	for( TInt i = 0; i < count; i++ )
       
   114 		{
       
   115 		// Read IAP id and name
       
   116 		TInt iapId = iIAPManager->Id( i );
       
   117 		TBuf< 64 > text16;
       
   118 		text16.Copy( iIAPManager->Name( i ) );
       
   119 		HBufC* text = text16.AllocLC();
       
   120 
       
   121 		// Create enumerated text item
       
   122 		CAknEnumeratedText* enumeratedText = new( ELeave ) CAknEnumeratedText( iapId, text );
       
   123 		CleanupStack::Pop( text );
       
   124 
       
   125 		// Store text item to the array
       
   126 		CleanupStack::PushL( enumeratedText );
       
   127 		texts->AppendL( enumeratedText );
       
   128 		CleanupStack::Pop( enumeratedText );
       
   129 		}
       
   130 
       
   131 	// Make sure iIAPId is a valid one
       
   132 	// (the setting list item won't work otherwise);
       
   133 	// Somebody might have removed our previously selected IAP
       
   134 	// - in that case the first IAP is selected instead.
       
   135 	iSettings.iIAPId = iIAPManager->Id( 0 );
       
   136 	for( TInt j = 0; j < count; j++ )
       
   137 		{
       
   138 		if( tmpId == iIAPManager->Id( j ) )
       
   139 			{
       
   140 			iSettings.iIAPId = tmpId;
       
   141 			break;
       
   142 			}
       
   143 		}
       
   144 
       
   145 	textSettingItem->LoadL();
       
   146 
       
   147     // Create and initialize CSY name setting item from the resource file.
       
   148     textSettingItem = new( ELeave ) CAknEnumeratedTextPopupSettingItem( 0, iSettings.iCSYName );
       
   149 	CleanupStack::PushL( textSettingItem );
       
   150 	itemTitle = iCoeEnv->AllocReadResourceLC( R_TC_SETTINGS_CSYNAME_TITLE );
       
   151 	textSettingItem->ConstructL( EFalse, id++, *itemTitle, NULL, R_TC_SETTINGS_MODE_PAGE, EAknCtPopupField, 0, R_TC_SETTINGS_CSYNAME_TEXTS );
       
   152 	CleanupStack::PopAndDestroy(); // itemTitle
       
   153 	iSettingItems.AppendL( textSettingItem );
       
   154 	CleanupStack::Pop(); // textSettingItem
       
   155 	
       
   156 	// Create and initialize Comm port setting item from the resource file.
       
   157     textSettingItem = new( ELeave ) CAknEnumeratedTextPopupSettingItem( 0, iSettings.iCommPort );
       
   158 	CleanupStack::PushL( textSettingItem );
       
   159 	itemTitle = iCoeEnv->AllocReadResourceLC( R_TC_SETTINGS_CSYNAME_TITLE );
       
   160 	textSettingItem->ConstructL( EFalse, id++, *itemTitle, NULL, R_TC_SETTINGS_COMMPORT_PAGE, EAknCtPopupField, 0, R_TC_SETTINGS_COMMPORT_TEXTS );
       
   161 	CleanupStack::PopAndDestroy(); // itemTitle
       
   162 	iSettingItems.AppendL( textSettingItem );
       
   163 	CleanupStack::Pop(); // textSettingItem
       
   164 	
       
   165 	// Create and initialize Baudrate setting item from the resource file.
       
   166 	settingItem = new( ELeave ) CAknIntegerEdwinSettingItem( 0, iSettings.iBaudrate );
       
   167 	CleanupStack::PushL( settingItem );
       
   168 	itemTitle = iCoeEnv->AllocReadResourceLC( R_TC_SETTINGS_BAUDRATE_TITLE );
       
   169 	settingItem->ConstructL( EFalse, id++, *itemTitle, NULL, R_TC_SETTINGS_BAUDRATE_PAGE, EEikCtEdwin );
       
   170 	CleanupStack::PopAndDestroy(); // itemTitle
       
   171 	iSettingItems.AppendL( settingItem );
       
   172 	CleanupStack::Pop(); // settingitem
       
   173 
       
   174 
       
   175 	// Create and initialize AutoConnect setting item from the resource file.
       
   176 	settingItem = new( ELeave ) CAknBinaryPopupSettingItem( 0, iSettings.iAutoConnect );
       
   177 	CleanupStack::PushL( settingItem );
       
   178 	itemTitle = iCoeEnv->AllocReadResourceLC( R_TC_SETTINGS_AUTOCONNECT_TITLE );
       
   179 	settingItem->ConstructL( EFalse, id++, *itemTitle, NULL, R_TC_SETTINGS_AUTOCONNECT_PAGE, EAknCtPopupField, 0, R_TC_SETTINGS_AUTOCONNECT_TEXTS );
       
   180 	CleanupStack::PopAndDestroy(); // itemTitle
       
   181 	iSettingItems.AppendL( settingItem );
       
   182 	CleanupStack::Pop(); // settingitem
       
   183 
       
   184 	// Give the setting item list to the listbox, retain ownership
       
   185 	CAknSettingStyleListBox* lb = ListBoxL();
       
   186 	CTextListBoxModel* model = lb->Model();
       
   187 	model->SetItemTextArray( &iSettingItems );
       
   188 	model->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   189 	iSettingItems.RecalculateVisibleIndicesL();
       
   190 
       
   191 	// Register for listbox notifications
       
   192 	lb->SetListBoxObserver( this );
       
   193 
       
   194 	// Create scroll indicators
       
   195 	lb->CreateScrollBarFrameL();
       
   196 	lb->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
       
   197 												   CEikScrollBarFrame::EAuto );
       
   198 	// Update listbox and scroll indicators
       
   199 	lb->HandleItemAdditionL();
       
   200 	lb->UpdateScrollBarsL();
       
   201 
       
   202 	// Now that we're fully constructed, change the title pane text
       
   203 	SetTitleL( R_TC_SETTINGS_DLG_TITLE );
       
   204 	}
       
   205 
       
   206 TBool CTcSettingsDialog::OkToExitL( TInt aKeycode )
       
   207 	{
       
   208 	
       
   209 	if( aKeycode == EAknSoftkeyOptions )
       
   210 		{
       
   211 		DisplayMenuL();
       
   212 		return EFalse;
       
   213 		}
       
   214 	else
       
   215 		{
       
   216 		// Save remote address to settings 
       
   217 		// or show error note if address is invalid
       
   218 		if (KErrNone != iSettings.iTCPRemoteAddr.Input(iRemoteAddrText))
       
   219 				{
       
   220 				_LIT(KInvalidAddressText, "Invalid remote IP");
       
   221 				CEikonEnv::Static()->AlertWin(KInvalidAddressText);
       
   222 				return EFalse;
       
   223 				}
       
   224 		
       
   225 		// Save settings to file
       
   226 		TInt count = iSettingItems.Count();
       
   227 		for( TInt i = 0; i < count; i++ )
       
   228 				{
       
   229 				iSettingItems.At( i )->StoreL();
       
   230 				}
       
   231 		iSettings.Store();
       
   232 		}
       
   233 	return ETrue;
       
   234 	}
       
   235 
       
   236 void CTcSettingsDialog::HandleListBoxEventL( CEikListBox* aListBox,
       
   237 											 TListBoxEvent aEventType )
       
   238 	{
       
   239 	// Edit in popup mode if ProcessCommandL( ECmdChange ) has requested so
       
   240 	TBool isPopUp( EFalse );
       
   241 	if( aEventType == EEventEditingStarted )
       
   242 		{
       
   243 		isPopUp = ETrue;
       
   244 		}
       
   245 
       
   246 	// Start editing (if there's an item to edit :-)
       
   247 	TInt index( aListBox->CurrentItemIndex() );
       
   248 	if( index >=0 )	// index is -1 if there are no items in the list
       
   249 		{
       
   250         iSettingItems.At( index )->EditItemL( isPopUp );
       
   251         aListBox->DrawItem( index );
       
   252 		}
       
   253 	}
       
   254 
       
   255 void CTcSettingsDialog::SetTitleL( TInt aResourceId ) const
       
   256 	{
       
   257 	// Get pointer to the title pane
       
   258 	CAknTitlePane* title =
       
   259 		static_cast< CAknTitlePane* >(
       
   260 			CEikonEnv::Static()
       
   261 				->AppUiFactory()
       
   262 					->StatusPane()
       
   263 						->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   264 	// Make sure we have a valid pointer
       
   265 	User::LeaveIfNull( title );
       
   266 
       
   267 	// Reset the text back to default or set a new one
       
   268 	if( aResourceId == -1 )
       
   269 		{
       
   270 		title->SetTextToDefaultL();
       
   271 		}
       
   272 	else
       
   273 		{
       
   274 		// Read the title text from resource file and put it to the title pane
       
   275 		HBufC* titleText = iCoeEnv->AllocReadResourceLC( aResourceId );
       
   276 		title->SetTextL( *titleText );
       
   277 		CleanupStack::PopAndDestroy(); // titleText
       
   278 		}
       
   279 	}
       
   280 
       
   281 void CTcSettingsDialog::ProcessCommandL( TInt aCommandId )
       
   282 	{
       
   283 	// Close the popup menu now.
       
   284 	HideMenu();
       
   285 
       
   286 	switch( aCommandId )
       
   287 		{
       
   288 		case ECmdChange:
       
   289 			{
       
   290 			HandleListBoxEventL( ListBoxL(), EEventEditingStarted );
       
   291 			break;
       
   292 			}
       
   293 		case EEikCmdExit:
       
   294 			{
       
   295 			TryExitL( EAknSoftkeyExit );
       
   296 			break;
       
   297 			}
       
   298 		default:
       
   299 			{
       
   300 			// Forward to application UI by default
       
   301 			CEikonEnv::Static()->EikAppUi()->HandleCommandL( aCommandId );
       
   302 			}
       
   303 		}
       
   304 	}
       
   305 
       
   306 TKeyResponse CTcSettingsDialog::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   307 												TEventCode aType )
       
   308 	{
       
   309 	
       
   310 	// Make settings permanent on each keypress,
       
   311 	// i.e. store values from setting items to TTcSettings
       
   312 	TInt count = iSettingItems.Count();
       
   313 	for( TInt i = 0; i < count; i++ )
       
   314 		{
       
   315 		iSettingItems.At( i )->StoreL();
       
   316 		}
       
   317 
       
   318 	// Save to file. This is done to ensure that settings are not lost
       
   319 	// if the power is lost unexpectedly.
       
   320 	iSettings.Store();
       
   321 
       
   322 	// Forward to the base class
       
   323 	return CAknDialog::OfferKeyEventL( aKeyEvent, aType );
       
   324 	}
       
   325 
       
   326 CAknSettingStyleListBox* CTcSettingsDialog::ListBoxL() const
       
   327 	{
       
   328 	CAknSettingStyleListBox* lb =
       
   329 		static_cast< CAknSettingStyleListBox* >( Control( ECtrlSettingsList ) );
       
   330 	User::LeaveIfNull( lb );
       
   331 	return lb;
       
   332 	}