omadm/omadmappui/src/NSmlDMDlgProfileView.cpp
changeset 0 3ce708148e4d
child 8 0a8136f75056
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Methods for Server Profile Settings dialog
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <akntextsettingpage.h>
       
    21 #include <aknpasswordsettingpage.h>
       
    22 #include <aknnotewrappers.h>
       
    23 #include <aknnavi.h>
       
    24 #include <ApUtils.h>
       
    25 #include <ApSettingsHandlerUI.h>
       
    26 #include <StringLoader.h>
       
    27 #include <featmgr.h>
       
    28 #include <ConnectionUiUtilities.h>
       
    29 #include <aknradiobuttonsettingpage.h>
       
    30 
       
    31 #include "NSmlDMSyncApp.h"
       
    32 #include "NSmlDMSyncDocument.h"
       
    33 #include "NSmlDMSyncAppUi.h"
       
    34 #include "NSmlDMDlgProfileView.h"
       
    35 #include "NSmlDMSyncProfile.h"
       
    36 #include "NSmlDMSyncAppEngine.h"
       
    37 #include "NSmlDMSyncDebug.h"
       
    38 #include "NSmlDMItemData.h"
       
    39 #include "nsmldmsyncinternalpskeys.h"
       
    40 #include <NSmlDMSync.rsg>
       
    41 #include <cmmanager.rsg>
       
    42 #include <ConnectionUiUtilities.rsg>
       
    43 #include <bautils.h> 
       
    44 
       
    45 #include <hlplch.h>
       
    46 #include <csxhelp/dm.hlp.hrh>
       
    47 
       
    48 _LIT( KACMManagerResDirAndFileName, "z:cmmanager.rsc" );
       
    49 _LIT(KConnectionUiUtilitiesRscPath, "z:ConnectionUiUtilities.rsc");
       
    50 _LIT(KDC_RESOURCE_FILES_DIR,"\\resource\\");  
       
    51 
       
    52 
       
    53 // ============================= MEMBER FUNCTIONS ==============================
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CNSmlDMDlgProfileView::NewL
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CNSmlDMDlgProfileView* CNSmlDMDlgProfileView::NewL( CNSmlDMSyncDocument* aDoc,
       
    60 		                                            TNSmlEditMode aMode,
       
    61 		                                            TInt aProfileId )
       
    62     {
       
    63     FLOG( "CNSmlDMDlgProfileView::NewL" );
       
    64 
       
    65     CNSmlDMDlgProfileView* self =
       
    66                             new ( ELeave ) CNSmlDMDlgProfileView( aDoc,
       
    67                                                                   aMode,
       
    68                                                                   aProfileId );
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL( R_SETTINGS_PROFILEMENU );
       
    71     CleanupStack::Pop();
       
    72     return( self );
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CNSmlDMDlgProfileView::CNSmlDMDlgProfileView
       
    77 // C++ default constructor can NOT contain any code, that
       
    78 // might leave.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CNSmlDMDlgProfileView::CNSmlDMDlgProfileView( CNSmlDMSyncDocument* aDoc,
       
    82                                               TNSmlEditMode aMode,
       
    83                                               TInt aProfileId  )
       
    84                                             : iDoc( aDoc ),
       
    85                                               iEditMode( aMode ),
       
    86                                               iProfileId( aProfileId ),
       
    87                                               iResourceOffset(KErrNotFound),
       
    88                                               iConnUtilResourceOffset(KErrNotFound)
       
    89 	{
       
    90 	FLOG( "[OMADM] CNSmlDMDlgProfileView::CNSmlDMDlgProfileView" );
       
    91 	
       
    92 	}
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // Destructor
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 CNSmlDMDlgProfileView::~CNSmlDMDlgProfileView()
       
    99     {
       
   100     FLOG( "[OMADM] ~CNSmlDMDlgProfileView:" );
       
   101     if(iResourceOffset >= 0)
       
   102         {
       
   103         CCoeEnv::Static()->DeleteResourceFile(iResourceOffset);
       
   104         }    
       
   105     if(iConnUtilResourceOffset >= 0)
       
   106         {
       
   107         CCoeEnv::Static()->DeleteResourceFile(iConnUtilResourceOffset);
       
   108         }
       
   109     if ( iNaviPane )
       
   110         {
       
   111         iNaviPane->Pop();
       
   112         }
       
   113     
       
   114 	if ( iProfileList )
       
   115 		{
       
   116 		iProfileList->ResetAndDestroy();
       
   117 		delete iProfileList;
       
   118 		}
       
   119 	iAvkonAppUi->RemoveFromStack( this );
       
   120 	FeatureManager::UnInitializeLib();
       
   121     }
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CNSmlDMDlgProfileView::OkToExitL
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 TBool CNSmlDMDlgProfileView::OkToExitL( TInt aButtonId )
       
   128 	{
       
   129 	FLOG( "[OMADM] CNSmlDMDlgProfileView::OkToExitL:" );
       
   130     
       
   131     if ( aButtonId == EAknSoftkeyChange )
       
   132         {
       
   133     	HandleOKL();
       
   134     	return EFalse;
       
   135         }
       
   136 	
       
   137 	if ( aButtonId == EAknSoftkeyBack )
       
   138         {
       
   139 		TBool closeDlg = ETrue;
       
   140 		TBool saveProfile = ETrue;
       
   141         //TInt index;
       
   142 		TInt retValue = CheckMandatoryFieldsL();
       
   143 		if ( retValue != KErrNotFound ) 
       
   144 			{
       
   145 			if ( ShowConfirmationNoteL( R_NSML_SETTINGS_SAVE_ANYWAY ) )
       
   146 				{
       
   147 				if ( iEditMode == ESmlCopyProfile  )
       
   148 					{
       
   149 					iDoc->MoveIndexToProfile( iProfileId );
       
   150 			        // This deletes the source profile
       
   151 			        //iDoc->DeleteProfile( index );
       
   152 			        iDoc->AppEngine()->DeleteProfileL( iProfileId );
       
   153 			        iDoc->MoveIndexToProfile( iOldProfileId );
       
   154 					}
       
   155 				else if ( iEditMode == ESmlNewProfile )
       
   156 				    {
       
   157 				    iDoc->AppEngine()->DeleteProfileL( iProfileId );
       
   158 				    }
       
   159 				//For CP stored umcompleted message
       
   160 				else if ( iEditMode == ESmlEditProfile )
       
   161 				    {
       
   162 				    iDoc->AppEngine()->DeleteProfileL( iProfileId );
       
   163 				    iDoc->RefreshProfileListL();
       
   164 				    iDoc->MoveIndexToProfile( iProfileId );
       
   165 				    }
       
   166 				//For CP umcompleted message
       
   167 				saveProfile = EFalse;
       
   168 				}
       
   169 			else
       
   170 				{
       
   171 				closeDlg = EFalse;
       
   172 				iProfileListBox->SetCurrentItemIndexAndDraw( retValue );
       
   173 				saveProfile = EFalse;
       
   174 				}
       
   175 			}
       
   176 		if ( saveProfile )
       
   177 			{
       
   178 			SaveProfileL();	
       
   179 			}
       
   180 		if ( closeDlg )
       
   181 			{
       
   182 			((CNSmlDMSyncAppUi*)iDoc->AppUi())->ChangeViewL( ETrue );
       
   183 			}
       
   184 		return closeDlg;
       
   185 		}
       
   186 	return CAknDialog::OkToExitL( aButtonId );
       
   187 	}
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CNSmlDMDlgProfileView::ProcessCommandL
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void CNSmlDMDlgProfileView::ProcessCommandL( TInt aCommandId )
       
   194 	{
       
   195 	FLOG( "[OMADM] CNSmlDMDlgProfileView::ProcessCommandL:" );
       
   196 	
       
   197 	HideMenu();
       
   198 	switch ( aCommandId )
       
   199 		{
       
   200      case EAknCmdHelp:             
       
   201 			{
       
   202 				if (FeatureManager::FeatureSupported( KFeatureIdHelp ))
       
   203              { 
       
   204 			          HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), ((CNSmlDMSyncAppUi*)iDoc->AppUi())->AppHelpContextL() ); 	
       
   205              }
       
   206 				
       
   207 			
       
   208             break;
       
   209 			}
       
   210 		case ENSmlSettChange:
       
   211 			{				
       
   212 			CNSmlDMProfileData* item = 
       
   213 			            GetItemForIndex( iProfileListBox->CurrentItemIndex());
       
   214 			if ( item->iItemType == CNSmlDMProfileData::ENSmlTypeListYesNo ||
       
   215 				 item->iItemType == CNSmlDMProfileData::ENSmlTypehttpListYesNo ||
       
   216 				 item->iItemType == CNSmlDMProfileData::ENSmlTypeList
       
   217 			    )
       
   218 				{
       
   219 				if ( EditSettingItemListL( *item ) )
       
   220 					{
       
   221 					//update listbox
       
   222 					AddProfileListItemL( iProfileListBox, iProfileList );
       
   223 					}
       
   224 				iProfileListBox->HandleItemAdditionL();
       
   225 				}
       
   226 			else
       
   227 				{
       
   228 				HandleOKL();
       
   229 				}
       
   230 			}			
       
   231 		    break;
       
   232 
       
   233 		case ENSmlSettExit:
       
   234 		case EAknCmdExit:
       
   235         case EEikCmdExit:
       
   236 			{
       
   237 			if ( CheckMandatoryFieldsL() >= KErrNone)
       
   238 				{
       
   239 				if ( !ShowConfirmationNoteL( R_NSML_SETTINGS_SAVE_ANYWAY ) )
       
   240 					{
       
   241 					return;
       
   242 					}
       
   243 				else if( iEditMode == ESmlEditProfile )	
       
   244 					{
       
   245 					iDoc->AppEngine()->DeleteProfileL( iProfileId );
       
   246 					}
       
   247 				}
       
   248 			TApaTaskList taskList(CEikonEnv::Static()->WsSession());
       
   249 	        TApaTask task1(taskList.FindApp( KFotaServerAppUid));
       
   250 	        if(task1.Exists())
       
   251 	        	{
       
   252 	        	FLOG( "ending fotaserver 1..." );
       
   253 	        	task1.EndTask();
       
   254 	        	}
       
   255 	        TApaTask task2(taskList.FindApp( KFotaServerAppUid));
       
   256 	        if(task2.Exists())
       
   257 	        	{
       
   258 	        	FLOG( "ending fotaserver 2..." );
       
   259 	        	task2.EndTask();
       
   260 	        	}
       
   261 	        TApaTask task3(taskList.FindApp( KFotaServerAppUid));
       
   262 	        if(task3.Exists())
       
   263 	        	{
       
   264 	        	FLOG( "ending fotaserver 3..." );
       
   265 	        	task3.EndTask();
       
   266 	        	}
       
   267 			STATIC_CAST( CNSmlDMSyncAppUi*, iEikonEnv->EikAppUi() )->DoExit();
       
   268 			}
       
   269 		    break;
       
   270 
       
   271 		default:
       
   272 	    	break;
       
   273 		}
       
   274 	}
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // CNSmlDMDlgProfileView::PreLayoutDynInitL
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 void CNSmlDMDlgProfileView::PreLayoutDynInitL()
       
   281     {
       
   282     FLOG(  "[OMADM] CNSmlDMDlgProfileView::PreLayoutDynInitL:");    
       
   283     TParse parse;
       
   284     parse.Set(KACMManagerResDirAndFileName, &KDC_RESOURCE_FILES_DIR, NULL);
       
   285     TFileName resourceFile;
       
   286     resourceFile.Append(parse.FullName());
       
   287     CEikonEnv* coeEnv = CEikonEnv::Static();
       
   288     RFs& fileSession = coeEnv->FsSession();    
       
   289     BaflUtils::NearestLanguageFile( fileSession, resourceFile );    
       
   290     if ( !BaflUtils::FileExists( fileSession, resourceFile ) )
       
   291         {
       
   292         User::Leave( KErrNotFound );
       
   293         }
       
   294      iResourceOffset = coeEnv->AddResourceFileL( resourceFile );
       
   295      
       
   296      TParse connutilname;
       
   297      connutilname.Set(KConnectionUiUtilitiesRscPath, &KDC_RESOURCE_FILES_DIR, NULL);     
       
   298      resourceFile.Zero();
       
   299      resourceFile.Append(connutilname.FullName());     
       
   300      BaflUtils::NearestLanguageFile( fileSession, resourceFile );     
       
   301      if ( !BaflUtils::FileExists( fileSession, resourceFile ) )
       
   302          {
       
   303          User::Leave( KErrNotFound );
       
   304          }
       
   305      iConnUtilResourceOffset = coeEnv->AddResourceFileL( resourceFile );
       
   306      
       
   307     iAvkonAppUi->AddToStackL( this );
       
   308 	FeatureManager::InitializeLibL();
       
   309 
       
   310 	iProfileListBox = (CAknSettingStyleListBox*)Control( ENSmlSettingList );
       
   311 	iProfileListBox->SetListBoxObserver( this );
       
   312 	iProfileListBox->CreateScrollBarFrameL( ETrue );
       
   313 	iProfileListBox->ScrollBarFrame()->SetScrollBarVisibilityL( 
       
   314 	                                                CEikScrollBarFrame::EOn,
       
   315 	                                                CEikScrollBarFrame::EAuto );
       
   316 
       
   317     iSyncAppEngine = iDoc->AppEngine();
       
   318 	iProfileList = new (ELeave) CArrayPtrFlat<CNSmlDMProfileData>(1);
       
   319 	
       
   320     if ( iEditMode == ESmlCopyProfile )
       
   321 		{
       
   322 		iOldProfileId = iProfileId;
       
   323 		iDoc->GetCopyProfileL( iProfileId );
       
   324 		iDoc->RefreshProfileListL();
       
   325 		iDoc->MoveIndexToProfile( iProfileId );
       
   326 		iServerIdChanged = ETrue;
       
   327 		}
       
   328 	else if ( iEditMode == ESmlNewProfile )
       
   329 		{
       
   330         iProfileId = iSyncAppEngine->CreateProfileL();
       
   331 		}
       
   332     CreateProfileSettingsListL();
       
   333     SetSettingTitleL();
       
   334     }
       
   335 
       
   336 // -----------------------------------------------------------------------------
       
   337 // CNSmlDMDlgProfileView::DynInitMenuPaneL
       
   338 // -----------------------------------------------------------------------------
       
   339 //
       
   340 void CNSmlDMDlgProfileView::DynInitMenuPaneL( TInt aResourceID,
       
   341                                               CEikMenuPane* aMenuPane )
       
   342 	{
       
   343      	FLOG( "[OMADM] CNSmlDMDlgProfileView::DynInitMenuPaneL:" );
       
   344      	
       
   345      	
       
   346      	if (aResourceID == R_SETTINGS_MENU  && 
       
   347      	                 !FeatureManager::FeatureSupported( KFeatureIdHelp ))
       
   348           {   aMenuPane->SetItemDimmed( EAknCmdHelp , ETrue );
       
   349           }
       
   350 	}
       
   351 
       
   352 // -----------------------------------------------------------------------------
       
   353 // CNSmlDMDlgProfileView::HandleListBoxEventL
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 void CNSmlDMDlgProfileView::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
   357                                                  TListBoxEvent aEventType )
       
   358 	{
       
   359 	FLOG( "[OMADM] CNSmlDMDlgProfileView::HandleListBoxEventL:" );
       
   360 	
       
   361 	if ( aEventType == EEventEnterKeyPressed ||
       
   362 	     aEventType == EEventItemSingleClicked )
       
   363 		{
       
   364 		HandleOKL();
       
   365 		}
       
   366 	}
       
   367 
       
   368 // -----------------------------------------------------------------------------
       
   369 // CNSmlDMDlgProfileView::HandleOKL
       
   370 // -----------------------------------------------------------------------------
       
   371 //
       
   372 void CNSmlDMDlgProfileView::HandleOKL()
       
   373 	{
       
   374 	FLOG( "[OMADM] CNSmlDMDlgProfileView::HandleOKL:");
       
   375 	
       
   376 	CNSmlDMProfileData* item = 
       
   377 	                    GetItemForIndex( iProfileListBox->CurrentItemIndex() );
       
   378 	if ( PrepareToEditSettingItemL( *item ) )
       
   379 		{
       
   380 		if ( iProfileListBox->CurrentItemIndex() == ENSmlServerId )
       
   381 			{	
       
   382 			iServerIdChanged = ETrue;
       
   383 			if ( CheckUniqueFieldsL() != KErrNotFound )
       
   384 				{
       
   385 				STATIC_CAST( CNSmlDMSyncAppUi*,
       
   386 				         iEikonEnv->EikAppUi())->ShowResourceErrorNoteL(
       
   387 				                              R_QTN_DM_CONF_SET_DUP_SERVER_ID );
       
   388 				}
       
   389 			else
       
   390 				{
       
   391 				iServerIdChanged = EFalse;
       
   392 				}	
       
   393 			}
       
   394 		else if ( iProfileListBox->CurrentItemIndex() == ENSmlConnType )
       
   395 			{
       
   396 			TBool hidden = 
       
   397 			    ( Item( ENSmlConnType )->iNumberData != EProfileInternet );
       
   398 			Item( ENSmlAccessPoint )->iHidden = hidden;			  
       
   399 			Item( ENSmlProfilePort )->iHidden = hidden;
       
   400 			Item( ENSmlHttpsUsed )->iHidden = hidden;
       
   401 			if(Item( ENSmlHttpsUsed )->iNumberData == 0 || hidden )
       
   402 			    {			    
       
   403 			    Item( ENSmlHttpsUsername )->iHidden = ETrue;
       
   404 			    Item( ENSmlHttpsPassword )->iHidden = ETrue;
       
   405 			    }
       
   406 			else
       
   407 			    {			    
       
   408 			    Item( ENSmlHttpsUsername )->iHidden = EFalse;
       
   409 			    Item( ENSmlHttpsPassword )->iHidden = EFalse;
       
   410 			    }			
       
   411 			}
       
   412 		//update listbox items
       
   413 		AddProfileListItemL( iProfileListBox, iProfileList );
       
   414 		}
       
   415 	iProfileListBox->HandleItemAdditionL();
       
   416 	}
       
   417 
       
   418 // -----------------------------------------------------------------------------
       
   419 // CNSmlDMDlgProfileView::OfferKeyEventL
       
   420 // -----------------------------------------------------------------------------
       
   421 //
       
   422 TKeyResponse CNSmlDMDlgProfileView::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   423                                                     TEventCode aType )
       
   424 	{
       
   425 	FLOG( "[OMADM] CNSmlDMDlgProfileView::OfferKeyEventL:" );
       
   426 	
       
   427 	if ( aType == EEventKey )
       
   428 		{
       
   429 		switch ( aKeyEvent.iCode )
       
   430 			{
       
   431 			case EKeyEscape:
       
   432                 {
       
   433                 iAvkonAppUi->ProcessCommandL( EAknCmdExit );
       
   434                 }
       
   435 			    break;
       
   436 			case EKeyEnter:
       
   437 			case EKeyOK: // OK button
       
   438                 {
       
   439 				HandleOKL();
       
   440                 return EKeyWasConsumed;
       
   441                 }
       
   442 			default:
       
   443 			    break;
       
   444 			}
       
   445 		}
       
   446 	return CEikDialog::OfferKeyEventL( aKeyEvent, aType);
       
   447 	}
       
   448 
       
   449 // -----------------------------------------------------------------------------
       
   450 // CNSmlDMDlgProfileView::AddProfileListItemL
       
   451 // -----------------------------------------------------------------------------
       
   452 //
       
   453 void CNSmlDMDlgProfileView::AddProfileListItemL( 
       
   454                                              CEikTextListBox* aListBox,
       
   455                                              CNSmlDMSettingItemList* aItemList )
       
   456 	{
       
   457 	FLOG( "[OMADM] CNSmlDMDlgProfileView::AddProfileListItemL:" );
       
   458 	
       
   459 	if ( ( !aListBox ) || ( !aItemList ) )
       
   460 		{
       
   461 		User::Leave( KErrNotFound );
       
   462 		}
       
   463 	CDesCArray* arr = (CDesCArray*)aListBox->Model()->ItemTextArray();
       
   464 	arr->Reset();
       
   465 
       
   466 	for ( TInt index = 0; index < aItemList->Count(); index++ )
       
   467 		{
       
   468 		if ( !(aItemList->At( index ))->iHidden )
       
   469 			{
       
   470 			TBool convert = 
       
   471 			           !( index == ENSmlProfileURL || index == ENSmlUsername /*|| index == ENSmlProfilePort*/ );
       
   472 			
       
   473 			arr->AppendL( (aItemList->At(index))->ItemToListLC( convert )->Des() );
       
   474 			(aItemList->At( index ))->iIndex = arr->Count() - 1;
       
   475 			
       
   476 			CleanupStack::PopAndDestroy(); //ItemToListLC()
       
   477 			}
       
   478 		else
       
   479 			{
       
   480 			(aItemList->At( index ))->iIndex = KErrNotFound;
       
   481 			}
       
   482 		}
       
   483 	}
       
   484 
       
   485 // -----------------------------------------------------------------------------
       
   486 // CNSmlDMDlgProfileView::CreateProfileSettingsListL
       
   487 // -----------------------------------------------------------------------------
       
   488 //
       
   489 void CNSmlDMDlgProfileView::CreateProfileSettingsListL()
       
   490 	{
       
   491 	FLOG( "[OMADM] CNSmlDMDlgProfileView::CreateProfileSettingsListL:" );
       
   492 	
       
   493 	CDesCArrayFlat* items = 
       
   494 	                iEikonEnv->ReadDesCArrayResourceL( R_SML_SETTINGS_ITEMS );
       
   495 	CleanupStack::PushL( items );
       
   496 	TInt index;
       
   497 	for ( index = 0; index < items->Count(); index++ )
       
   498 		{
       
   499 		iProfileList->AppendL( CNSmlDMProfileData::NewLC() );		
       
   500 		CleanupStack::Pop();
       
   501 		}
       
   502 	BuildHeaders( items );
       
   503 	BuildItemIds();
       
   504 	// Open profile	
       
   505 	iProfile = iSyncAppEngine->OpenProfileL( iProfileId, ESmlOpenReadWrite );
       
   506 
       
   507 	BuildProfileNameItemL();
       
   508 	BuildProfileServerIdItemL();
       
   509 	BuildProfileServerPasswordItemL();
       
   510 	BuildProfileConnectionTypeItemL();
       
   511 	BuildProfileAccessPointItemL();
       
   512     BuildProfileUrlItemL();
       
   513     BuildProfilePortItemL();
       
   514     BuildProfileUserNameandPassWordItemL();
       
   515     BuildProfileActiveAcceptedItemL();
       
   516     BuildProfileHttpsUsedItemL();
       
   517     BuildProfileHttpsUserNameAndPasswordItemL();
       
   518     
       
   519 	// Close profile
       
   520 	iSyncAppEngine->CloseProfile();
       
   521 	
       
   522 	AddProfileListItemL( iProfileListBox, iProfileList );
       
   523 	CleanupStack::PopAndDestroy( items );
       
   524 	}
       
   525 
       
   526 
       
   527 // -----------------------------------------------------------------------------
       
   528 // void CNSmlDMDlgProfileView::SaveProfileL
       
   529 // -----------------------------------------------------------------------------
       
   530 //
       
   531 void CNSmlDMDlgProfileView::SaveProfileL()
       
   532 	{
       
   533 	FLOG( "[OMADM] void CNSmlDMDlgProfileView::SaveProfileL:" );
       
   534 	
       
   535     TRAPD( err, iProfile = iSyncAppEngine->OpenProfileL( iProfileId, ESmlOpenReadWrite ) );
       
   536     if( err != KErrNone )
       
   537     	{
       
   538     	FLOG( "[OMADM] err != KErrNone--problem in opening the profile" );
       
   539     	// Profile could not be opened for saving
       
   540     	iDoc->RefreshProfileListL();
       
   541     	iDoc->MoveIndexToProfile( iProfileId );
       
   542     	return;
       
   543     	}
       
   544 
       
   545 	// Server name
       
   546 	iProfile->SetNameL( Item(ENSmlProfileName)->Value()->Des() );
       
   547 	// Server Id
       
   548 	iProfile->SetServerIdL( Item(ENSmlServerId)->Value()->Des() );
       
   549 	// Server password
       
   550 	iProfile->SetServerPasswordL( Item(ENSmlProfileDMServerPassword)->iValue );
       
   551 	// connection type
       
   552     iProfile->SetBearerTypeL( Item(ENSmlConnType)->iNumberData );
       
   553     // Accesspoint
       
   554     if ( Item(ENSmlAccessPoint)->iWapAPInUse )
       
   555         {
       
   556         // User has not edited accesspoint fiels so convert it back to iap
       
   557         SetAccessPointInfoL( Item(ENSmlAccessPoint)->iNumberData );
       
   558         }
       
   559     iProfile->SetAccessPointL( Item(ENSmlAccessPoint)->iNumberData );
       
   560     // Host address
       
   561     TInt num = Item( ENSmlProfilePort )->iNumberData;
       
   562 	iProfile->SetHostAddressL( Item(ENSmlProfileURL)->Value()->Des(), num );
       
   563 	// User name
       
   564     iProfile->SetUserNameL( Item(ENSmlUsername)->Value()->Des() );
       
   565     // User password
       
   566     iProfile->SetPasswordL( Item(ENSmlPassword)->iValue );
       
   567     // Active profile
       
   568 	if (Item(ENSmlServerAlertAllowed)->iNumberData)
       
   569 		{
       
   570 		iProfile->SetSASyncStateL( ESASyncStateEnable );
       
   571 		}
       
   572 	else
       
   573 		{
       
   574 		iProfile->SetSASyncStateL( ESASyncStateDisable );
       
   575 		}
       
   576     // Server alert allowed
       
   577     if ( Item(ENSmlServerAlertAllowed)->iNumberData )
       
   578         {
       
   579         if ( !Item(ENSmlServerAccept)->iNumberData )
       
   580 			{
       
   581 			iProfile->SetSASyncStateL( ESASyncStateConfirm );
       
   582 			}
       
   583 		}
       
   584     // Http authentication	
       
   585     iProfile->SetHttpUsedL( Item(ENSmlHttpsUsed)->iNumberData );
       
   586     // http username
       
   587     iProfile->SetHttpUserNameL( Item(ENSmlHttpsUsername)->Value()->Des() );
       
   588     // http password
       
   589     iProfile->SetHttpPasswordL( Item(ENSmlHttpsPassword)->iValue );
       
   590     
       
   591 	iProfile->SetCreatorId( KUidSmlSyncApp.iUid );
       
   592 	iProfileId = iProfile->ProfileId();
       
   593     iProfile->SaveL();
       
   594     iSyncAppEngine->CloseProfile();
       
   595     
       
   596 	iDoc->RefreshProfileListL();	
       
   597 	iDoc->MoveIndexToProfile( iProfileId );
       
   598 	}
       
   599 
       
   600 //-----------------------------------------------------------------------------
       
   601 // CNSmlDMDlgProfileView::Item
       
   602 //-----------------------------------------------------------------------------
       
   603 //
       
   604 CNSmlDMProfileData* CNSmlDMDlgProfileView::Item( TInt aItemId )
       
   605 	{
       
   606 	return iProfileList->At( aItemId );		
       
   607 	}
       
   608 
       
   609 // -----------------------------------------------------------------------------
       
   610 // CNSmlDMDlgProfileView::CheckMandatoryFieldsL
       
   611 // -----------------------------------------------------------------------------
       
   612 //
       
   613 TInt CNSmlDMDlgProfileView::CheckMandatoryFieldsL()
       
   614 	{
       
   615 	FLOG( "[OMADM] CNSmlDMDlgProfileView::CheckMandatoryFieldsL:" );
       
   616 	
       
   617 	TInt returnValue = KErrNotFound;
       
   618 
       
   619 	HBufC* emptyText =
       
   620 	    iEikonEnv->AllocReadResourceLC( R_QTN_SML_SET_VAL_FIELD_NONE );
       
   621 	HBufC* emptyAddr = 
       
   622 	    iEikonEnv->AllocReadResourceLC( R_QTN_SML_SET_VAL_HOSTADDR_FIELD_NONE );
       
   623 	
       
   624 	for ( TInt index = 0; index < iProfileList->Count(); index++ )
       
   625 		{
       
   626 		if ( Item(index)->iMandatory && 
       
   627 		   ( ( index == ENSmlServerId &&
       
   628 		           Item(index)->Value()->Des() == emptyText->Des() ) ||
       
   629 		     ( index == ENSmlProfileURL &&
       
   630 		           Item(index)->Value()->Des() == emptyAddr->Des() ) || 
       
   631 		     ( index == ENSmlUsername &&
       
   632 		           Item(index)->Value()->Des() == emptyText->Des() ) ||      
       
   633 		     ( Item(index)->Value()->Des().Length() == 0 ) ) )
       
   634 		    {
       
   635 			returnValue = Item(index)->iIndex;
       
   636 			break;
       
   637 			}
       
   638 		}
       
   639 	if ( returnValue == KErrNotFound )
       
   640 		{
       
   641 		returnValue = CheckUniqueFieldsL();
       
   642 		}
       
   643 	CleanupStack::PopAndDestroy( emptyAddr );
       
   644 	CleanupStack::PopAndDestroy( emptyText );
       
   645 	return returnValue;
       
   646 	}
       
   647 
       
   648 // -----------------------------------------------------------------------------
       
   649 // CNSmlDMDlgProfileView::CheckUniqueFieldsL
       
   650 // -----------------------------------------------------------------------------
       
   651 //
       
   652 TInt CNSmlDMDlgProfileView::CheckUniqueFieldsL()
       
   653 	{
       
   654 	FLOG( "[OMADM] CNSmlDMDlgProfileView::CheckUniqueFieldsL:" );
       
   655 	
       
   656     TInt returnValue( KErrNotFound );
       
   657 	CNSmlDMProfileData* item = Item(ENSmlServerId);
       
   658 
       
   659 	if ( iServerIdChanged )
       
   660 		{
       
   661 		if ( iEditMode != ESmlEditProfile )
       
   662 			{
       
   663 			if ( iSyncAppEngine->ServerIdFoundL( item->Value()->Des(),
       
   664 			                                     iProfileId ) )
       
   665 				{		
       
   666 				returnValue = ENSmlServerId;
       
   667 				}
       
   668 			}
       
   669 		else if ( ( iEditMode == ESmlEditProfile ) &&
       
   670 		          ( item->Value()->Des() != item->iValue ) )
       
   671 			{
       
   672 			if ( iSyncAppEngine->ServerIdFoundL( item->Value()->Des(),
       
   673 			                                     iProfileId ) )
       
   674 				{		
       
   675 				returnValue = ENSmlServerId;
       
   676 				}
       
   677 			}
       
   678 		}
       
   679         
       
   680 	return returnValue;
       
   681 	}
       
   682 
       
   683 // -----------------------------------------------------------------------------
       
   684 // CNSmlDMDlgProfileView::PrepareToEditSettingItemL
       
   685 // -----------------------------------------------------------------------------
       
   686 //
       
   687 TBool CNSmlDMDlgProfileView::PrepareToEditSettingItemL( 
       
   688                                                     CNSmlDMProfileData& aItem )
       
   689 	{
       
   690 	FLOG( "[OMADM] CNSmlDMDlgProfileView::PrepareToEditSettingItemL:" );
       
   691 	
       
   692 	TInt prompt = WarnUserOfChangeL();
       
   693 	if ( prompt )	//show confirmation if needed
       
   694 		{
       
   695 		if ( !ShowConfirmationNoteL( prompt ) )
       
   696 			{
       
   697 			return EFalse;
       
   698 			}
       
   699 		}
       
   700 	switch ( aItem.iItemType )
       
   701 		{
       
   702 		case CNSmlDMProfileData::ENSmlTypeIAP:
       
   703 		    {
       
   704 			return EditSettingItemAccessPointL( aItem );
       
   705 		    }
       
   706 			
       
   707 		case CNSmlDMProfileData::ENSmlTypeText:
       
   708 		    {
       
   709 			return EditSettingItemTextL( aItem );
       
   710 		    }
       
   711 
       
   712 		case CNSmlDMProfileData::ENSmlTypeSecret:
       
   713 			{
       
   714 			return EditSettingItemSecretL( aItem );
       
   715 			}
       
   716 
       
   717 		case CNSmlDMProfileData::ENSmlTypeNumber:
       
   718 		    {
       
   719 			return EditSettingItemNumberL( aItem );
       
   720 		    }
       
   721 
       
   722 		case CNSmlDMProfileData::ENSmlTypeList:
       
   723 		    {
       
   724 		    return EditConnectionSettingItemL( aItem );
       
   725 		    }
       
   726 		
       
   727 		case CNSmlDMProfileData::ENSmlTypeListYesNo:
       
   728 		    {
       
   729 		    return EditSettingItemListYesNoL( aItem );
       
   730 		    }
       
   731 
       
   732 		case CNSmlDMProfileData::ENSmlTypehttpListYesNo:
       
   733 		    {
       
   734 		    return EditHttpSettingItemListYesNoL( aItem );
       
   735 		    }
       
   736 		    
       
   737 		case CNSmlDMProfileData::ENSmlTypeTime:
       
   738 		    {
       
   739 			return EFalse;
       
   740 		    }
       
   741 		}
       
   742 	return EFalse;
       
   743 	}
       
   744 
       
   745 // -----------------------------------------------------------------------------
       
   746 // CNSmlDMDlgProfileView::EditSettingItemTextL
       
   747 // -----------------------------------------------------------------------------
       
   748 //
       
   749 TBool CNSmlDMDlgProfileView::EditSettingItemTextL( CNSmlDMProfileData& aItem )
       
   750 	{
       
   751     FLOG( "[OMADM] CNSmlDMDlgProfileView::EditSettingItemTextL:");
       
   752     
       
   753     TBool retVal = EFalse;
       
   754     TInt flags( CAknTextSettingPage::EZeroLengthAllowed );
       
   755 	if ( aItem.iMandatory )
       
   756 		{
       
   757 		flags = CAknTextSettingPage::EZeroLengthNotOffered;
       
   758 		}
       
   759 
       
   760 	HBufC* tmpBuf = HBufC::NewLC( aItem.iLength ); 
       
   761 	TPtr ptr( tmpBuf->Des() );
       
   762 	ptr.Zero();
       
   763 	//Language varaint error fix  EPZO-6Y88F9
       
   764 	HBufC* emptyText =
       
   765 	    iEikonEnv->AllocReadResourceLC( R_QTN_SML_SET_VAL_FIELD_NONE );
       
   766 	if ( aItem.Value()->Des() != emptyText->Des() )
       
   767 	{
       
   768 	ptr.Append( aItem.Value()->Des() );
       
   769 	}  
       
   770 	//Language varaint error fix  EPZO-6Y88F9
       
   771 	CAknTextSettingPage* dlg = 
       
   772 	        new (ELeave) CAknTextSettingPage( R_NSML_SETTINGS_TEXT, ptr, flags );
       
   773 	CleanupStack::PushL( dlg );
       
   774 	dlg->SetSettingTextL( aItem.Header()->Des() ); 
       
   775 	dlg->ConstructL();
       
   776 	dlg->TextControl()->SetTextLimit( aItem.iLength );
       
   777 
       
   778 	if ( aItem.iLatinInput )
       
   779 		{		
       
   780 		dlg->TextControl()->SetAvkonWrap( ETrue );
       
   781 		dlg->TextControl()->SetAknEditorCase( EAknEditorLowerCase );
       
   782 		dlg->TextControl()->SetAknEditorFlags( 
       
   783 		                                EAknEditorFlagNoT9 |
       
   784 		                                EAknEditorFlagLatinInputModesOnly );
       
   785 		}
       
   786 	CleanupStack::Pop( dlg );
       
   787 	
       
   788 	if ( ( dlg->ExecuteLD ( CAknSettingPage::EUpdateWhenChanged ) ) &&
       
   789 	     ( aItem.Value()->Des() != ptr ) )
       
   790 		{//Fix for RKCC-7BC8Z2 
       
   791 		if(aItem.iItemId== ENSmlProfileURL)    
       
   792 		{  TBuf<255> tempBuf;
       
   793 		   tempBuf.Zero();
       
   794 		  _LIT(Kfslash ,"/");
       
   795 		   for(TInt i= 0;i<ptr.Length();i++)
       
   796 		    {   TChar ch = ptr[i];
       
   797 		        TText* t = (TText*)ptr[i]; 
       
   798 		        if( ptr[i] == '\\') 
       
   799 		        {
       
   800 		          tempBuf.Append(Kfslash);	
       
   801 		        }
       
   802 			    else
       
   803 			    {
       
   804 			      tempBuf.Append(ch);	
       
   805 			    } 
       
   806 	    	}
       
   807 	    	if(tempBuf.Length())
       
   808 	    	{
       
   809 	    		ptr.Copy(tempBuf);
       
   810 	    	}
       
   811 		 }
       
   812 		aItem.SetValue(ptr);
       
   813 		retVal = ETrue;
       
   814 		}
       
   815 	CleanupStack::PopAndDestroy( emptyText ); 
       
   816 	CleanupStack::PopAndDestroy( tmpBuf );
       
   817 	return retVal;
       
   818 	}
       
   819 
       
   820 // -----------------------------------------------------------------------------
       
   821 // CNSmlDMDlgProfileView::EditSettingItemSecretL
       
   822 // -----------------------------------------------------------------------------
       
   823 //
       
   824 TBool CNSmlDMDlgProfileView::EditSettingItemSecretL( CNSmlDMProfileData& aItem )
       
   825 	{
       
   826 	FLOG( "[OMADM] CNSmlDMDlgProfileView::EditSettingItemSecretL:" );
       
   827 	
       
   828 	TBuf<KNSmlMaxTextLength128> buf;
       
   829 	CAknAlphaPasswordSettingPage* pwd =
       
   830 	         new (ELeave) CAknAlphaPasswordSettingPage( R_SETTING_PASSWORD,
       
   831 		                                                aItem.iValue,
       
   832 		                                                aItem.iValue  );
       
   833   	CleanupStack::PushL( pwd );
       
   834 
       
   835 	pwd->SetSettingTextL( aItem.Header()->Des() ); 
       
   836 	pwd->ConstructL();
       
   837 	pwd->AlphaPasswordEditor()->SetMaxLength( aItem.iLength );
       
   838 	//pwd->AlphaPasswordEditor()->RevealSecretText( ETrue );
       
   839 
       
   840 	CleanupStack::Pop( pwd );
       
   841 	if ( pwd->ExecuteLD(CAknSettingPage::EUpdateWhenChanged) )
       
   842 		{
       
   843 		buf.Fill('*', 4 );
       
   844 		aItem.SetValue( buf ); //the real value backed up
       
   845 		return ETrue;
       
   846 		}
       
   847 	return EFalse;
       
   848 	}
       
   849 
       
   850 // -----------------------------------------------------------------------------
       
   851 // CNSmlDMDlgProfileView::EditSettingItemNumberL
       
   852 // -----------------------------------------------------------------------------
       
   853 //
       
   854 TBool CNSmlDMDlgProfileView::EditSettingItemNumberL( CNSmlDMProfileData& aItem )
       
   855 	{
       
   856 	FLOG( "[OMADM] CNSmlDMDlgProfileView::EditSettingItemNumberL:" );
       
   857 	
       
   858 	CAknIntegerSettingPage * dlg = 
       
   859 	    new (ELeave) CAknIntegerSettingPage( 
       
   860 	                        R_SETTINGS_NUMBER,
       
   861 	                        aItem.iNumberData,
       
   862 	                        CAknIntegerSettingPage::EInvalidValueNotOffered) ;
       
   863 	CleanupStack::PushL( dlg );
       
   864 	dlg->SetSettingTextL( aItem.Header()->Des() );
       
   865 	dlg->ConstructL();
       
   866 	dlg->IntegerEditorControl()->SetAknEditorNumericKeymap(
       
   867 											EAknEditorPlainNumberModeKeymap );
       
   868     if ( aItem.iLatinInput )
       
   869 	 {
       
   870 		
       
   871     dlg->IntegerEditorControl()->SetAknEditorFlags( EAknEditorFlagLatinInputModesOnly );
       
   872     
       
   873     dlg->IntegerEditorControl()->SetValueL( aItem.iNumberData );
       
   874     
       
   875 	 }											
       
   876 	CleanupStack::Pop( dlg );
       
   877 
       
   878 	if ( dlg->ExecuteLD( CAknIntegerSettingPage::EUpdateWhenChanged ) )
       
   879 		{
       
   880 		   aItem.SetValue( aItem.iNumberData );
       
   881 		return ETrue;
       
   882 		}
       
   883 	return EFalse;
       
   884 	}
       
   885 
       
   886 // -----------------------------------------------------------------------------
       
   887 // CNSmlDMDlgProfileView::EditSettingItemListL
       
   888 // -----------------------------------------------------------------------------
       
   889 //
       
   890 TBool CNSmlDMDlgProfileView::EditSettingItemListL( CNSmlDMProfileData& aItem )
       
   891 	{
       
   892 	FLOG( "[OMADM] CNSmlDMDlgProfileView::EditSettingItemListL:" );
       
   893 	
       
   894 	TInt curSelection(aItem.iNumberData );
       
   895 	CDesCArray* stringData = iEikonEnv->ReadDesCArrayResourceL(aItem.iResource);
       
   896 	CleanupStack::PushL( stringData );
       
   897 	
       
   898 	CAknRadioButtonSettingPage* dlg = 
       
   899 	new (ELeave) CAknRadioButtonSettingPage( R_SETTINGS_RADIO,
       
   900 	                                         curSelection,
       
   901 	                                         stringData );
       
   902 	CleanupStack::PushL( dlg );
       
   903 	dlg->SetSettingTextL( aItem.Header()->Des() ); 
       
   904     CleanupStack::Pop( dlg );
       
   905 	if ( dlg->ExecuteLD() )
       
   906 		{
       
   907 		aItem.iNumberData = curSelection;
       
   908 		if ( aItem.iItemType == CNSmlDMProfileData::ENSmlTypehttpListYesNo )
       
   909 			{
       
   910 			if ( aItem.iNumberData == 1 )
       
   911 				{
       
   912 				Item( ENSmlHttpsUsername )->iHidden =  EFalse;
       
   913 				Item( ENSmlHttpsPassword )->iHidden =  EFalse;
       
   914 				}
       
   915 			else
       
   916 				{
       
   917 				Item( ENSmlHttpsUsername )->iHidden =  ETrue;
       
   918 				Item( ENSmlHttpsPassword )->iHidden =  ETrue;
       
   919 				}
       
   920 			}
       
   921 		aItem.SetValue( (*stringData)[curSelection] );
       
   922 		CleanupStack::PopAndDestroy(stringData);
       
   923 		return ETrue;
       
   924 		}
       
   925 	CleanupStack::PopAndDestroy(stringData);
       
   926 	return EFalse;
       
   927 	}
       
   928 
       
   929 // -----------------------------------------------------------------------------
       
   930 // CNSmlDMDlgProfileView::EditSettingItemAccessPointL
       
   931 // -----------------------------------------------------------------------------
       
   932 //
       
   933 TBool CNSmlDMDlgProfileView::EditSettingItemAccessPointL( 
       
   934                                                     CNSmlDMProfileData& aItem )
       
   935 	{
       
   936 	FLOG( "[OMADM] CNSmlDMDlgProfileView::EditSettingItemAccessPointL:" );
       
   937 	
       
   938 	TInt curSelection(ENsmlAlwaysAsk);
       
   939     if( aItem.iNumberData == KErrNotFound   ) //Always ask
       
   940        {       
       
   941        curSelection = ENsmlAlwaysAsk;
       
   942        }
       
   943     else if(aItem.iNumberData == KErrGeneral) //default conenction
       
   944         {
       
   945         curSelection = ENsmlDefaultConnection;
       
   946         }
       
   947     else
       
   948         {        
       
   949         curSelection = ENsmlIap;
       
   950         }
       
   951 
       
   952     HBufC* destName = StringLoader::LoadLC( 
       
   953 									R_CMMANAGERUI_SETT_DEFAULT_CONNECTION);
       
   954     HBufC* userdef = StringLoader::LoadLC(
       
   955 									R_CMMANAGERUI_SETT_USER_DEFINED);
       
   956     HBufC* title = StringLoader::LoadLC(
       
   957 									R_CMMANAGERUI_SETT_DESTINATION);
       
   958     HBufC* alwaysask = StringLoader::LoadLC(
       
   959 									R_ALWAYS_ASK_ALWAYS_ASK);
       
   960     
       
   961     CDesCArrayFlat* stringData = new (ELeave) CDesCArrayFlat( 3 );
       
   962     CleanupStack::PushL( stringData );
       
   963     stringData->AppendL(alwaysask->Des());
       
   964     stringData->AppendL(destName->Des());
       
   965     stringData->AppendL(userdef->Des());
       
   966 
       
   967     CAknRadioButtonSettingPage* dlg = 
       
   968     new (ELeave) CAknRadioButtonSettingPage( R_SETTINGS_RADIO,
       
   969             curSelection,
       
   970             stringData );
       
   971     CleanupStack::PushL( dlg );
       
   972     dlg->SetSettingTextL( title->Des() ); 
       
   973     CleanupStack::Pop( dlg );
       
   974 
       
   975     TInt ret = dlg->ExecuteLD(); 
       
   976 
       
   977 	TUint32 currentAccesspoint(0);
       
   978 	if ( !ret )
       
   979 		{		
       
   980 		CleanupStack::PopAndDestroy(5);
       
   981 		return EFalse; // user canceled "Always ask" dialog
       
   982 		}
       
   983 		
       
   984     if ( curSelection == ENsmlAlwaysAsk  )
       
   985     	{    	
       
   986     	aItem.SetValue( alwaysask->Des() );
       
   987 		aItem.iNumberData = KErrNotFound;    					
       
   988 		CleanupStack::PopAndDestroy(5);
       
   989 		return ETrue;  // user selected "Always ask" option 
       
   990     	}
       
   991     else if(curSelection == ENsmlDefaultConnection )
       
   992         {        
       
   993         aItem.SetValue( destName->Des() );
       
   994         aItem.iNumberData = KErrGeneral;
       
   995         CleanupStack::PopAndDestroy(5);        
       
   996         return ETrue;  // user selected "default connection" option 
       
   997         }
       
   998 	else
       
   999 	    {
       
  1000 	    CCommsDatabase* commDb = CCommsDatabase::NewL( EDatabaseTypeIAP );
       
  1001 	    CleanupStack::PushL( commDb );
       
  1002 	    CApUtils* aputils = CApUtils::NewLC(*commDb);
       
  1003 	    currentAccesspoint =  aItem.iNumberData ;
       
  1004         CleanupStack::PopAndDestroy( aputils );
       
  1005 	    CleanupStack::PopAndDestroy( commDb );
       
  1006 	    
       
  1007 	    FTRACE( RDebug::Print( 
       
  1008 	     _L("[OMADM] CNSmlDMDlgProfileView::EditSettingItemAccessPointL: current ap (%d)"),
       
  1009 	                                                currentAccesspoint ) );
       
  1010 	    }
       
  1011 	
       
  1012 	
       
  1013 	TInt apBearerFlags;
       
  1014 	if ( FeatureManager::FeatureSupported( KFeatureIdAppCsdSupport ) )
       
  1015 		{
       
  1016 		apBearerFlags = EApBearerTypeCSD | 
       
  1017 		                EApBearerTypeGPRS | 
       
  1018 		                EApBearerTypeHSCSD | 
       
  1019 		                EApBearerTypeWLAN;
       
  1020 		}
       
  1021 	else
       
  1022 		{
       
  1023 		apBearerFlags = EApBearerTypeGPRS | EApBearerTypeWLAN;
       
  1024 		}
       
  1025 
       
  1026 	CApSettingsHandler* handler = CApSettingsHandler::NewLC( 
       
  1027             ETrue,
       
  1028 			EApSettingsSelListIsPopUp,
       
  1029 			EApSettingsSelMenuSelectNormal,
       
  1030 			KEApIspTypeAll,
       
  1031 			apBearerFlags,
       
  1032 			KEApSortNameAscending );
       
  1033 
       
  1034     TInt retVal = KErrNone;
       
  1035     TUint32 selectedIap(0);
       
  1036 	TRAP_IGNORE( retVal = handler->RunSettingsL( currentAccesspoint,
       
  1037 	                                             selectedIap ) );
       
  1038 	CleanupStack::PopAndDestroy(handler);
       
  1039 	CleanupStack::PopAndDestroy(5);
       
  1040 
       
  1041     if ( retVal & KApUiEventSelected )
       
  1042 		{
       
  1043 		SetAccessPointInfoL( selectedIap );
       
  1044 		}
       
  1045 	else if ( retVal == KApUiEventExitRequested )
       
  1046 		{
       
  1047 		DoExitFromMenuL();
       
  1048 		}
       
  1049 	else
       
  1050 		{		
       
  1051 		//Keep previous selection
       
  1052 		}
       
  1053 	return ETrue;
       
  1054 	}
       
  1055 
       
  1056 // -----------------------------------------------------------------------------
       
  1057 // CNSmlDMDlgProfileView::SetAccessPointInfoL
       
  1058 // -----------------------------------------------------------------------------
       
  1059 //
       
  1060 void CNSmlDMDlgProfileView::SetAccessPointInfoL( TUint aId )
       
  1061 	{
       
  1062 	FLOG( "[OMADM] CNSmlDMDlgProfileView::SetAccessPointInfoL:");
       
  1063 	
       
  1064 	CCommsDatabase* commDb = CCommsDatabase::NewL( EDatabaseTypeIAP );
       
  1065 	CleanupStack::PushL( commDb );
       
  1066 
       
  1067 	TInt apBearerFilter;
       
  1068 
       
  1069 	if ( FeatureManager::FeatureSupported( KFeatureIdAppCsdSupport ) )
       
  1070 		{
       
  1071 		apBearerFilter = EApBearerTypeCSD | 
       
  1072 		                 EApBearerTypeGPRS | 
       
  1073 		                 EApBearerTypeHSCSD | 
       
  1074 		                 EApBearerTypeWLAN;
       
  1075 		}
       
  1076 	else
       
  1077 		{
       
  1078 		apBearerFilter = EApBearerTypeGPRS | EApBearerTypeWLAN;
       
  1079 		}
       
  1080 	CApSelect* apSelect = CApSelect::NewLC( *commDb,
       
  1081 	                                        KEApIspTypeAll,
       
  1082 	                                        apBearerFilter,
       
  1083 	                                        KEApSortUidAscending );
       
  1084 
       
  1085 	TBool retValue( EFalse );
       
  1086 
       
  1087 	if ( apSelect->MoveToFirst() )
       
  1088 		{
       
  1089 		if ( aId == apSelect->Uid() )
       
  1090 			{
       
  1091 			retValue = ETrue;		
       
  1092 			}
       
  1093 		while ( ( ! retValue ) && ( apSelect->MoveNext() ) )
       
  1094 			{
       
  1095 			if ( aId == apSelect->Uid() )
       
  1096 				{
       
  1097 				retValue = ETrue;
       
  1098 				}
       
  1099 			}
       
  1100 		}
       
  1101 
       
  1102 	if ( retValue )
       
  1103 		{
       
  1104 		CApUtils* aputils = CApUtils::NewLC(*commDb);
       
  1105 		TRAP_IGNORE( aId = aputils->IapIdFromWapIdL( aId ) );
       
  1106 
       
  1107 		FTRACE(RDebug::Print(_L("accesspoint after IapIdFromWapIdL (%d)"), aId));
       
  1108 		
       
  1109 		Item( ENSmlAccessPoint )->SetValue( apSelect->Name() );
       
  1110 		Item( ENSmlAccessPoint )->iNumberData = aId;
       
  1111 		Item( ENSmlAccessPoint )->iWapAPInUse = EFalse;
       
  1112 		
       
  1113 		CleanupStack::PopAndDestroy( aputils );
       
  1114 		}
       
  1115 	else
       
  1116 		{		
       
  1117 		HBufC* emptyText = 
       
  1118 		    iEikonEnv->AllocReadResourceLC(R_CMMANAGERUI_SETT_DEFAULT_CONNECTION);
       
  1119         Item( ENSmlAccessPoint )->SetValue( emptyText->Des() );
       
  1120 		Item( ENSmlAccessPoint )->iNumberData = KErrNotFound;
       
  1121 		Item( ENSmlAccessPoint )->iWapAPInUse = EFalse;
       
  1122 		CleanupStack::PopAndDestroy(emptyText);
       
  1123 		}
       
  1124 	
       
  1125 	CleanupStack::PopAndDestroy( apSelect );
       
  1126 	CleanupStack::PopAndDestroy( commDb );
       
  1127 	}
       
  1128 
       
  1129 // -----------------------------------------------------------------------------
       
  1130 // CNSmlDMDlgProfileView::GetAccessPointInfoL
       
  1131 // -----------------------------------------------------------------------------
       
  1132 //
       
  1133 void CNSmlDMDlgProfileView::GetAccessPointInfoL( TInt aId )
       
  1134 	{
       
  1135 	FTRACE( RDebug::Print( 
       
  1136 	 _L("[OMADM] CNSmlDMDlgProfileView::GetAccessPointInfoL: aId (%d)"), aId));
       
  1137     
       
  1138     TInt err = KErrNone;
       
  1139 	
       
  1140 	CCommsDatabase* commDb = CCommsDatabase::NewL( EDatabaseTypeIAP );
       
  1141 	CleanupStack::PushL( commDb );
       
  1142 	CApUtils* aputils = CApUtils::NewLC( *commDb );
       
  1143 	
       
  1144 	TBool apExists = EFalse;
       
  1145 	TRAP( err, apExists = aputils->IAPExistsL( aId ) );
       
  1146 	if (  aId == KErrNotFound )
       
  1147 		{
       
  1148 		HBufC* emptyText = 
       
  1149 		            iEikonEnv->AllocReadResourceLC( R_ALWAYS_ASK_ALWAYS_ASK );		
       
  1150         Item( ENSmlAccessPoint )->SetValue( emptyText->Des() );
       
  1151 		Item( ENSmlAccessPoint )->iNumberData = KErrNotFound;
       
  1152 		Item( ENSmlAccessPoint )->iWapAPInUse = EFalse;		
       
  1153 		CleanupStack::PopAndDestroy( emptyText );
       
  1154 		CleanupStack::PopAndDestroy( aputils );
       
  1155 		CleanupStack::PopAndDestroy( commDb );
       
  1156 		return;
       
  1157 		}
       
  1158 	else if(!apExists || aId == KErrGeneral) 
       
  1159 	    {
       
  1160 	    HBufC* emptyText = 
       
  1161 	    iEikonEnv->AllocReadResourceLC(R_CMMANAGERUI_SETT_DEFAULT_CONNECTION);
       
  1162 	    Item( ENSmlAccessPoint )->SetValue( emptyText->Des() );
       
  1163 	    Item( ENSmlAccessPoint )->iNumberData = KErrGeneral;
       
  1164 	    Item( ENSmlAccessPoint )->iWapAPInUse = EFalse;
       
  1165 	    CleanupStack::PopAndDestroy( emptyText );
       
  1166 	    CleanupStack::PopAndDestroy( aputils );
       
  1167 	    CleanupStack::PopAndDestroy( commDb );
       
  1168 	    return;
       
  1169 	    }
       
  1170 	else
       
  1171 	    {}
       
  1172     // convert internet ap to Wap ap
       
  1173 	TRAP( err, aId = aputils->WapIdFromIapIdL( aId ) );
       
  1174     CleanupStack::PopAndDestroy( aputils );
       
  1175     
       
  1176 	if ( err != KErrNone )
       
  1177 		{
       
  1178 		CleanupStack::PopAndDestroy( commDb );
       
  1179 		return;
       
  1180 		}
       
  1181 	
       
  1182     TInt apBearerFilter;
       
  1183 
       
  1184 	if ( FeatureManager::FeatureSupported( KFeatureIdAppCsdSupport ) )
       
  1185 		{
       
  1186 		apBearerFilter = EApBearerTypeCSD | 
       
  1187 		                 EApBearerTypeGPRS | 
       
  1188 		                 EApBearerTypeHSCSD | 
       
  1189 		                 EApBearerTypeWLAN;
       
  1190 		}
       
  1191 	else
       
  1192 		{
       
  1193 		apBearerFilter = EApBearerTypeGPRS | EApBearerTypeWLAN;
       
  1194 		}
       
  1195 	CApSelect* selector = CApSelect::NewLC(
       
  1196 	                             *commDb,
       
  1197 	                             KEApIspTypeAll,
       
  1198 		                         apBearerFilter,
       
  1199 		                         KEApSortUidAscending);
       
  1200 	
       
  1201 	TBool found = EFalse;
       
  1202 	
       
  1203 	// find access point with id aId
       
  1204 	if (selector->MoveToFirst())
       
  1205 		{
       
  1206 		if (aId == (TInt)selector->Uid())
       
  1207 			{
       
  1208 			found = ETrue;		
       
  1209 			}
       
  1210 		while (!found && selector->MoveNext())
       
  1211 			{
       
  1212 			if (aId == (TInt)selector->Uid())
       
  1213 				{
       
  1214 				found = ETrue;
       
  1215 				}
       
  1216 			}
       
  1217 		}
       
  1218 
       
  1219 	if (found) 
       
  1220 		{
       
  1221 		Item( ENSmlAccessPoint )->SetValue( selector->Name() );
       
  1222 		Item( ENSmlAccessPoint )->iNumberData = aId;
       
  1223 		Item( ENSmlAccessPoint )->iWapAPInUse = ETrue;
       
  1224 		}
       
  1225 	else
       
  1226 		{		
       
  1227 		HBufC* emptyText = 
       
  1228 		   iEikonEnv->AllocReadResourceLC(R_CMMANAGERUI_SETT_DEFAULT_CONNECTION);
       
  1229         Item( ENSmlAccessPoint )->SetValue( emptyText->Des() );
       
  1230 		Item( ENSmlAccessPoint )->iNumberData = KErrNotFound;
       
  1231 		CleanupStack::PopAndDestroy(emptyText);
       
  1232 		}
       
  1233 		
       
  1234     CleanupStack::PopAndDestroy(selector);
       
  1235     CleanupStack::PopAndDestroy(commDb);
       
  1236 
       
  1237 	}
       
  1238 
       
  1239 // -----------------------------------------------------------------------------
       
  1240 // CNSmlDMDlgProfileView::EditSettingItemListYesNoL
       
  1241 // -----------------------------------------------------------------------------
       
  1242 //
       
  1243 TBool CNSmlDMDlgProfileView::EditSettingItemListYesNoL( 
       
  1244                                                     CNSmlDMProfileData& aItem )
       
  1245 	{
       
  1246     FLOG( "[OMADM] CNSmlDMDlgProfileView::EditSettingItemListYesNoL:");
       
  1247 
       
  1248 	CDesCArray* stringData = 
       
  1249 	                      iEikonEnv->ReadDesCArrayResourceL( aItem.iResource );
       
  1250 	CleanupStack::PushL( stringData );
       
  1251 	
       
  1252 	if ( aItem.iNumberData == 0 )
       
  1253 		{
       
  1254 		aItem.iNumberData = 1;
       
  1255 		}
       
  1256 	else
       
  1257 		{
       
  1258 		aItem.iNumberData = 0;
       
  1259 		}
       
  1260 	
       
  1261 	aItem.SetValue( (*stringData)[aItem.iNumberData] );
       
  1262 	CleanupStack::PopAndDestroy( stringData );
       
  1263 	return ETrue;
       
  1264 	}
       
  1265 
       
  1266 
       
  1267 // -----------------------------------------------------------------------------
       
  1268 // CNSmlDMDlgProfileView::EditHttpSettingItemListYesNoL
       
  1269 // -----------------------------------------------------------------------------
       
  1270 //
       
  1271 TBool CNSmlDMDlgProfileView::EditHttpSettingItemListYesNoL( 
       
  1272                                                     CNSmlDMProfileData& aItem )
       
  1273 	{
       
  1274     FLOG( "[OMADM] CNSmlDMDlgProfileView::EditHttpSettingItemListYesNoL:" );
       
  1275 
       
  1276 	CDesCArray* stringData = 
       
  1277 	                      iEikonEnv->ReadDesCArrayResourceL( aItem.iResource );
       
  1278 	CleanupStack::PushL( stringData );
       
  1279 	
       
  1280 	if ( aItem.iNumberData == 0 )
       
  1281 		{
       
  1282 		aItem.iNumberData = 1;
       
  1283 		Item( ENSmlHttpsUsername )->iHidden =  EFalse;
       
  1284 		Item( ENSmlHttpsPassword )->iHidden =  EFalse;
       
  1285 		}
       
  1286 	else
       
  1287 		{
       
  1288 		aItem.iNumberData = 0;
       
  1289 		Item( ENSmlHttpsUsername )->iHidden =  ETrue;
       
  1290 		Item( ENSmlHttpsPassword )->iHidden =  ETrue;
       
  1291 		}
       
  1292 	
       
  1293 	aItem.SetValue( (*stringData)[aItem.iNumberData] );
       
  1294 	CleanupStack::PopAndDestroy( stringData );
       
  1295 	return ETrue;
       
  1296 	}
       
  1297 	
       
  1298 // ---------------------------------------------------------------------------------------------------
       
  1299 // CNSmlDMDlgProfileView::EditConnectionSettingItemL
       
  1300 // This method gets called when stylus single clck or MSK pressed on session mode item
       
  1301 // ---------------------------------------------------------------------------------------------------
       
  1302 //
       
  1303 TBool CNSmlDMDlgProfileView::EditConnectionSettingItemL( 
       
  1304                                                     CNSmlDMProfileData& aItem )
       
  1305     {
       
  1306     FLOG( "[OMADM] CNSmlDMDlgProfileView::EditConnectionSettingItemL:" );
       
  1307 
       
  1308     CDesCArray* stringData = 
       
  1309                           iEikonEnv->ReadDesCArrayResourceL( aItem.iResource );
       
  1310     CleanupStack::PushL( stringData );
       
  1311     TBool hidden = EFalse;
       
  1312     //Value of the setting item gets changed between Internet & Bluetooth for single click or msk press
       
  1313 	//If any new session mode like USB(third item) is going to add, radio button setting page should pop up
       
  1314     if ( aItem.iNumberData == EProfileInternet )
       
  1315         {
       
  1316         hidden = ETrue;
       
  1317         aItem.iNumberData = EProfileObexBlueTooth;
       
  1318         Item( ENSmlAccessPoint )->iHidden = ETrue;           
       
  1319         Item( ENSmlProfilePort )->iHidden = ETrue;
       
  1320         Item( ENSmlHttpsUsed )->iHidden = ETrue;        
       
  1321         }
       
  1322     else
       
  1323         {
       
  1324         hidden = EFalse;
       
  1325         aItem.iNumberData = EProfileInternet;
       
  1326         Item( ENSmlAccessPoint )->iHidden = EFalse;           
       
  1327         Item( ENSmlProfilePort )->iHidden = EFalse;
       
  1328         Item( ENSmlHttpsUsed )->iHidden = EFalse;        
       
  1329         }
       
  1330     
       
  1331     if(Item( ENSmlHttpsUsed )->iNumberData == 0 || hidden )
       
  1332         {               
       
  1333         Item( ENSmlHttpsUsername )->iHidden = ETrue;
       
  1334         Item( ENSmlHttpsPassword )->iHidden = ETrue;
       
  1335         }
       
  1336     else
       
  1337         {               
       
  1338         Item( ENSmlHttpsUsername )->iHidden = EFalse;
       
  1339         Item( ENSmlHttpsPassword )->iHidden = EFalse;
       
  1340         } 
       
  1341     
       
  1342     aItem.SetValue( (*stringData)[aItem.iNumberData] );
       
  1343     CleanupStack::PopAndDestroy( stringData );
       
  1344     return ETrue;
       
  1345     }
       
  1346 	
       
  1347 // -----------------------------------------------------------------------------
       
  1348 // CNSmlDMDlgProfileView::SetSettingTitleL
       
  1349 // -----------------------------------------------------------------------------
       
  1350 //
       
  1351 void CNSmlDMDlgProfileView::SetSettingTitleL()
       
  1352 	{
       
  1353 	FLOG( "[OMADM] CNSmlDMDlgProfileView::SetSettingTitleL:" );
       
  1354 	
       
  1355 	TBuf<KNSmlMaxTextLength128> title;
       
  1356 	StringLoader::Load( title, R_SML_SETTINGS_TITLE );
       
  1357 	CAknTitlePane* titlePane = 
       
  1358 	            (CAknTitlePane*) iAvkonAppUi->StatusPane()->ControlL( 
       
  1359 	                                      TUid::Uid( EEikStatusPaneUidTitle ) );
       
  1360 	titlePane->SetTextL( title );
       
  1361     iNaviPane = ( CAknNavigationControlContainer* )
       
  1362         iAvkonAppUi->StatusPane()->ControlL( TUid::Uid(EEikStatusPaneUidNavi) );
       
  1363     iNaviPane->PushDefaultL();
       
  1364     }
       
  1365 
       
  1366 // -----------------------------------------------------------------------------
       
  1367 // CNSmlDMDlgProfileView::ShowConfirmationNoteL
       
  1368 // -----------------------------------------------------------------------------
       
  1369 //
       
  1370 TBool CNSmlDMDlgProfileView::ShowConfirmationNoteL(TInt aResource)
       
  1371 	{
       
  1372 	FLOG( "[OMADM] CNSmlDMDlgProfileView::ShowConfirmationNoteL:" );
       
  1373 	
       
  1374 	HBufC* label = iEikonEnv->AllocReadResourceLC( aResource ); 
       
  1375 	CAknQueryDialog* queryDialog = new (ELeave) CAknQueryDialog;
       
  1376 	TBool retVal = queryDialog->ExecuteLD( R_STARTQUERY_NOTE, label->Des() );
       
  1377 	CleanupStack::PopAndDestroy( label );
       
  1378 	return retVal;
       
  1379 	}
       
  1380 
       
  1381 // -----------------------------------------------------------------------------
       
  1382 // CNSmlDMDlgProfileView::WarnUserOfChangeL
       
  1383 // -----------------------------------------------------------------------------
       
  1384 //
       
  1385 TInt CNSmlDMDlgProfileView::WarnUserOfChangeL()
       
  1386 	{
       
  1387 	FLOG( "[OMADM] CNSmlDMDlgProfileView::WarnUserOfChangeL:" );
       
  1388 	
       
  1389 	TInt prompt = KErrNone;
       
  1390     if ( iProfileListBox->CurrentItemIndex() == ENSmlServerId )
       
  1391         {
       
  1392     	HBufC* emptyText = 
       
  1393     	        iEikonEnv->AllocReadResourceLC( R_QTN_SML_SET_VAL_FIELD_NONE );
       
  1394     	if ( Item(ENSmlServerId)->Value()->Des() != emptyText->Des() )
       
  1395     		{
       
  1396     		prompt = R_QTN_DM_CONF_SET_SERVER_ID;
       
  1397     		}
       
  1398     	CleanupStack::PopAndDestroy( emptyText );
       
  1399         }
       
  1400 	return prompt; 	
       
  1401 	}
       
  1402 
       
  1403 // -----------------------------------------------------------------------------
       
  1404 // CNSmlDMDlgProfileView::DoExitFromMenuL
       
  1405 // -----------------------------------------------------------------------------
       
  1406 //
       
  1407 void CNSmlDMDlgProfileView::DoExitFromMenuL()
       
  1408 	{
       
  1409 	FLOG( "[OMADM] CNSmlDMDlgProfileView::DoExitFromMenuL:" );
       
  1410 	
       
  1411 	TInt retValue = CheckMandatoryFieldsL();
       
  1412 	if ( retValue >= KErrNone )
       
  1413 		{
       
  1414 		if ( !ShowConfirmationNoteL( R_NSML_SETTINGS_SAVE_ANYWAY ) )
       
  1415 			{
       
  1416 			return;
       
  1417 			}
       
  1418 		}
       
  1419 	((CNSmlDMSyncAppUi*)iDoc->AppUi())->ChangeViewL();
       
  1420 	((CNSmlDMSyncAppUi*)iDoc->AppUi())->DoExit();		
       
  1421 	}
       
  1422 
       
  1423 
       
  1424 
       
  1425 // -----------------------------------------------------------------------------
       
  1426 // CNSmlDMDlgProfileView::GetHelpContext
       
  1427 // -----------------------------------------------------------------------------
       
  1428 //
       
  1429 void CNSmlDMDlgProfileView::GetHelpContext(TCoeHelpContext& aContext) const
       
  1430 	{
       
  1431 	FLOG( "[OMADM] CNSmlDMDlgProfileView::GetHelpContext:");
       
  1432 	
       
  1433 	aContext.iMajor = KUidSmlSyncApp;
       
  1434     aContext.iContext = KDM_HLP_SETTINGS;
       
  1435 	}
       
  1436 	
       
  1437 
       
  1438 
       
  1439 // -----------------------------------------------------------------------------
       
  1440 // CNSmlDMDlgProfileView::BuildHeaders
       
  1441 // -----------------------------------------------------------------------------
       
  1442 //
       
  1443 void CNSmlDMDlgProfileView::BuildHeaders( CDesCArray* aHeaders )
       
  1444 	{	
       
  1445 	for ( TInt index = 0; index < iProfileList->Count(); index++ )
       
  1446 		{
       
  1447 		iProfileList->At(index)->SetHeader( (*aHeaders)[index] );
       
  1448 		}
       
  1449 	}
       
  1450 // -----------------------------------------------------------------------------
       
  1451 // CNSmlDMDlgProfileView::BuildItemIds
       
  1452 // -----------------------------------------------------------------------------
       
  1453 //
       
  1454 void CNSmlDMDlgProfileView::BuildItemIds( )
       
  1455 	{	
       
  1456 	for ( TInt index = 0; index < iProfileList->Count(); index++ )
       
  1457 		{
       
  1458 		iProfileList->At( index )->iItemId = index;
       
  1459 		}
       
  1460 	}
       
  1461 
       
  1462 // -----------------------------------------------------------------------------
       
  1463 // CNSmlDMDlgProfileView::BuildProfileNameItemL
       
  1464 // -----------------------------------------------------------------------------
       
  1465 //
       
  1466 void CNSmlDMDlgProfileView::BuildProfileNameItemL()
       
  1467 	{
       
  1468 	FLOG( "[OMADM] CNSmlDMDlgProfileView::BuildProfileNameItemL" );
       
  1469 	
       
  1470     CNSmlDMProfileData* item = Item(ENSmlProfileName);
       
  1471 	if ( EditMode() || CopyMode() )
       
  1472 		{
       
  1473         TBuf<KNSmlMaxItemLength> buf;
       
  1474         iProfile->GetName( buf );
       
  1475 		item->SetValue( buf );
       
  1476 		}
       
  1477 	//set default profile name if new or namelength is zero
       
  1478 	if ( ( iEditMode == ESmlNewProfile ) ||
       
  1479 	     ( item->Value()->Des().Length() == 0) )
       
  1480 		{
       
  1481 		item->SetValue( iDoc->GetNextProfileNameLC()->Des() );
       
  1482 		CleanupStack::PopAndDestroy();
       
  1483 		}
       
  1484 	item->iMandatory = ETrue;
       
  1485 	item->iLength = KNSmlMaxProfileNameLength;
       
  1486 	item->iItemType = CNSmlDMProfileData::ENSmlTypeText;
       
  1487 	}
       
  1488 
       
  1489 // -----------------------------------------------------------------------------
       
  1490 // CNSmlDMDlgProfileView::BuildProfileServerIdItemL
       
  1491 // -----------------------------------------------------------------------------
       
  1492 //
       
  1493 void CNSmlDMDlgProfileView::BuildProfileServerIdItemL()
       
  1494 	{
       
  1495 	FLOG( "[OMADM] CNSmlDMDlgProfileView::BuildProfileServerIdItemL" );
       
  1496     CNSmlDMProfileData* item = Item(ENSmlServerId);
       
  1497 	if ( EditMode() )
       
  1498 		{
       
  1499         TBuf<KNSmlMaxItemLength> buf;
       
  1500         iProfile->GetServerId( buf );
       
  1501         if( buf.Length() > 0 )       
       
  1502            {
       
  1503 		item->SetValue( buf );
       
  1504            } 
       
  1505 		}
       
  1506 	else
       
  1507 		{
       
  1508 		HBufC* emptyText = iEikonEnv->AllocReadResourceLC(
       
  1509 		                                         R_QTN_SML_SET_VAL_FIELD_NONE );
       
  1510 		item->SetValue( emptyText->Des() );
       
  1511 		CleanupStack::PopAndDestroy( emptyText );
       
  1512 		
       
  1513 		}
       
  1514 	item->iMandatory = ETrue;
       
  1515 	item->iLength = KNSmlDmServerIdMaxLength;
       
  1516 	item->iItemType = CNSmlDMProfileData::ENSmlTypeText;
       
  1517 	item->iLatinInput = ETrue;
       
  1518 	}
       
  1519 	
       
  1520 // -----------------------------------------------------------------------------
       
  1521 // CNSmlDMDlgProfileView::BuildProfileServerPasswordItemL
       
  1522 // -----------------------------------------------------------------------------
       
  1523 //
       
  1524 void CNSmlDMDlgProfileView::BuildProfileServerPasswordItemL()
       
  1525 	{
       
  1526 	FLOG( "[OMADM] CNSmlDMDlgProfileView::BuildProfileServerPasswordItemL" );
       
  1527 	
       
  1528     TBuf<KNSmlMaxTextLength256> buf;
       
  1529     CNSmlDMProfileData* item = Item(ENSmlProfileDMServerPassword);
       
  1530 	if ( EditMode() || CopyMode() )
       
  1531 		{
       
  1532         TBuf<KNSmlMaxItemLength> buf;
       
  1533         iProfile->GetServerPassword( buf );
       
  1534         item->iValue.Copy( buf );
       
  1535 		}
       
  1536 	else
       
  1537 		{
       
  1538 		item->iValue = KNullDesC;
       
  1539 		}
       
  1540 
       
  1541 	buf.Fill('*', 4 );
       
  1542 	item->SetValue(buf);
       
  1543 	item->iLength = KNSmlMaxPasswordLength;
       
  1544 	item->iItemType = CNSmlDMProfileData::ENSmlTypeSecret;	
       
  1545 	}
       
  1546 	
       
  1547 // -----------------------------------------------------------------------------
       
  1548 // CNSmlDMDlgProfileView::BuildProfileConnectionTypeItemL
       
  1549 // -----------------------------------------------------------------------------
       
  1550 //
       
  1551 void CNSmlDMDlgProfileView::BuildProfileConnectionTypeItemL()
       
  1552 	{
       
  1553 	FLOG( "[OMADM] CNSmlDMDlgProfileView::BuildProfileConnectionTypeItemL" );
       
  1554 	
       
  1555 	CNSmlDMProfileData* item = Item(ENSmlConnType);
       
  1556 	if ( EditMode() || CopyMode() )
       
  1557 		{
       
  1558         item->iNumberData = iProfile->BearerType();
       
  1559 		if ( ( item->iNumberData != EProfileObexBlueTooth ) && 
       
  1560 		     ( item->iNumberData != EProfileInternet ) )
       
  1561 			{
       
  1562 			//default to internet
       
  1563 			item->iNumberData = EProfileInternet;
       
  1564 			}
       
  1565 		}
       
  1566 	else
       
  1567 		{
       
  1568 		item->iNumberData = EProfileInternet;
       
  1569 		}
       
  1570 	CDesCArray* stringData = 
       
  1571 	                    iEikonEnv->ReadDesCArrayResourceL(R_SML_BEARER_TYPE);
       
  1572 	CleanupStack::PushL( stringData );
       
  1573 	
       
  1574 	if ( !FeatureManager::FeatureSupported( KFeatureIdSyncMlDmObex  ) )
       
  1575 		{
       
  1576 		item->iHidden = ETrue;
       
  1577 		item->iNumberData = EProfileInternet;
       
  1578 		}
       
  1579 	
       
  1580 	item->SetValue ( (*stringData)[item->iNumberData] );
       
  1581 	CleanupStack::PopAndDestroy( stringData );
       
  1582 	item->iResource = R_SML_BEARER_TYPE;
       
  1583 	item->iLength   = 80;
       
  1584 	item->iItemType = CNSmlDMProfileData::ENSmlTypeList;	
       
  1585 	}
       
  1586 	
       
  1587 // -----------------------------------------------------------------------------
       
  1588 // CNSmlDMDlgProfileView::BuildProfileAccessPointItemL
       
  1589 // -----------------------------------------------------------------------------
       
  1590 //
       
  1591 void CNSmlDMDlgProfileView::BuildProfileAccessPointItemL()
       
  1592 	{
       
  1593 	FLOG( "[OMADM] CNSmlDMDlgProfileView::BuildProfileAccessPointItemL" );
       
  1594 	
       
  1595 	CNSmlDMProfileData* item = Item(ENSmlAccessPoint);
       
  1596 	item->iWapAPInUse = EFalse;
       
  1597 	if ( EditMode() || CopyMode() )
       
  1598 		{
       
  1599         item->iNumberData = iProfile->AccessPointL();
       
  1600 		}
       
  1601 	else
       
  1602 		{
       
  1603 		item->iNumberData = KErrGeneral;
       
  1604 		}
       
  1605     GetAccessPointInfoL( item->iNumberData );
       
  1606 	item->iLength = 0;
       
  1607 	item->iItemType = CNSmlDMProfileData::ENSmlTypeIAP;
       
  1608 	item->iHidden = ( Item( ENSmlConnType )->iNumberData != EProfileInternet );	
       
  1609 	}
       
  1610 	
       
  1611 // -----------------------------------------------------------------------------
       
  1612 // CNSmlDMDlgProfileView::BuildProfileUrlItemL
       
  1613 // -----------------------------------------------------------------------------
       
  1614 //
       
  1615 void CNSmlDMDlgProfileView::BuildProfileUrlItemL()
       
  1616 	{
       
  1617 	FLOG( "[OMADM] CNSmlDMDlgProfileView::BuildProfileUrlItemL" );
       
  1618 	CNSmlDMProfileData* item = Item(ENSmlProfileURL);
       
  1619 	if ( EditMode() || CopyMode() )
       
  1620 		{
       
  1621 		iProfile->GetHostAddress( iBuf, item->iNumberData );
       
  1622 		if (iBuf.Length() > KNSmlMaxURLLength )
       
  1623 		  {
       
  1624 		    iBuf.SetLength(KNSmlMaxURLLength);
       
  1625 		  }
       
  1626 		if( iBuf.Length() > 0 )        
       
  1627            {
       
  1628 		item->SetValue( iBuf );
       
  1629            }   
       
  1630 		}
       
  1631 	else
       
  1632 		{
       
  1633 		HBufC* emptyAddr = iEikonEnv->AllocReadResourceLC( 
       
  1634 		                    R_QTN_SML_SET_VAL_HOSTADDR_FIELD_NONE );
       
  1635 	    item->SetValue( emptyAddr->Des() );
       
  1636 	    CleanupStack::PopAndDestroy(); //emptyAddr
       
  1637 		}
       
  1638     item->iLength = KNSmlMaxURLLength;
       
  1639 	item->iItemType = CNSmlDMProfileData::ENSmlTypeText;
       
  1640 	item->iLatinInput = ETrue;
       
  1641 	item->iMandatory = ETrue;	
       
  1642 	}
       
  1643 	
       
  1644 // -----------------------------------------------------------------------------
       
  1645 // CNSmlDMDlgProfileView::BuildProfilePortItemL
       
  1646 // -----------------------------------------------------------------------------
       
  1647 //
       
  1648 void CNSmlDMDlgProfileView::BuildProfilePortItemL()
       
  1649 	{
       
  1650 	FLOG( "[OMADM] CNSmlDMDlgProfileView::BuildProfilePortItemL" );
       
  1651     CNSmlDMProfileData* item = Item(ENSmlProfilePort);
       
  1652     iProfile->GetHostAddress( iBuf, item->iNumberData );
       
  1653 	
       
  1654 	if ( item->iNumberData <= KPortMaxSize && item->iNumberData >= KPortMinSize )
       
  1655 	{
       
  1656 	item->SetValue( item->iNumberData );    	
       
  1657 	}
       
  1658 	else
       
  1659 	{
       
  1660 	item->iNumberData = KDefaultHttpPort;	
       
  1661 	item->SetValue( item->iNumberData );
       
  1662 	}
       
  1663 
       
  1664 	item->iLength = KBufSize16;
       
  1665 	item->iItemType = CNSmlDMProfileData::ENSmlTypeNumber;	
       
  1666 	item->iHidden = ( Item( ENSmlConnType )->iNumberData != EProfileInternet );	
       
  1667 	item->iLatinInput = ETrue;	
       
  1668 	}
       
  1669 	
       
  1670 // -----------------------------------------------------------------------------
       
  1671 // CNSmlDMDlgProfileView::BuildProfileUserNameandPassWordItemL
       
  1672 // -----------------------------------------------------------------------------
       
  1673 //
       
  1674 void CNSmlDMDlgProfileView::BuildProfileUserNameandPassWordItemL()
       
  1675 	{
       
  1676 	FLOG( "[OMADM] CNSmlDMDlgProfileView::BuildProfileUserNameandPassWordItemL" );
       
  1677 	
       
  1678     CNSmlDMProfileData* item = Item(ENSmlUsername);
       
  1679     HBufC* emptyText = iEikonEnv->AllocReadResourceLC(
       
  1680 		                                         R_QTN_SML_SET_VAL_FIELD_NONE );
       
  1681     item->SetValue( emptyText->Des() );
       
  1682     CleanupStack::PopAndDestroy( emptyText );
       
  1683     TBuf<KNSmlMaxTextLength256> buf;
       
  1684     if ( EditMode() || CopyMode() )
       
  1685 		{
       
  1686         iProfile->GetUserName( buf );
       
  1687         if( buf.Length() > 0 )      
       
  1688            {
       
  1689         item->SetValue( buf );
       
  1690            } 
       
  1691 		}
       
  1692 	item->iMandatory = ETrue;
       
  1693 	item->iLength = KNSmlMaxUsernameLength;
       
  1694 	item->iLatinInput = ETrue;
       
  1695 	item->iItemType = CNSmlDMProfileData::ENSmlTypeText;
       
  1696 
       
  1697     item = Item(ENSmlPassword);
       
  1698 	if ( EditMode() || CopyMode() )
       
  1699 		{
       
  1700         TBuf<KNSmlMaxItemLength> buf;
       
  1701         iProfile->GetPassword( buf );
       
  1702         item->iValue.Copy( buf );
       
  1703 		}
       
  1704 	else
       
  1705 		{
       
  1706 		item->iValue = KNullDesC;
       
  1707 		}
       
  1708 
       
  1709 	buf.Fill('*', 4 ); //mask
       
  1710 	item->SetValue( buf );	
       
  1711 	item->iLength = KNSmlMaxPasswordLength;
       
  1712 	item->iItemType = CNSmlDMProfileData::ENSmlTypeSecret;	
       
  1713 	}
       
  1714 	
       
  1715 // -----------------------------------------------------------------------------
       
  1716 // CNSmlDMDlgProfileView::BuildProfileActiceAcceptedItemL
       
  1717 // -----------------------------------------------------------------------------
       
  1718 //
       
  1719 void CNSmlDMDlgProfileView::BuildProfileActiveAcceptedItemL()
       
  1720 	{
       
  1721 	FLOG( "[OMADM] CNSmlDMDlgProfileView::BuildProfileActiceAcceptedItemL" );
       
  1722 	
       
  1723 	CNSmlDMProfileData* item = Item(ENSmlServerAlertAllowed);
       
  1724     CDesCArray* stringData =
       
  1725                          iEikonEnv->ReadDesCArrayResourceL( R_NSML_YESNO_TYPE );
       
  1726 	CleanupStack::PushL( stringData );
       
  1727 
       
  1728 	if ( EditMode() || CopyMode() )
       
  1729 		{
       
  1730         if ( iProfile->SASyncState() == ESASyncStateDisable)
       
  1731 		    {
       
  1732 		    item->iNumberData = EFalse;
       
  1733 		    }
       
  1734 		else
       
  1735 		    {
       
  1736 		    item->iNumberData = ETrue;
       
  1737 		    }
       
  1738 		}
       
  1739 	else
       
  1740 		{
       
  1741 		item->iNumberData = ETrue;
       
  1742 		}
       
  1743 	item->iResource = R_NSML_YESNO_TYPE;
       
  1744 	item->SetValue( (*stringData)[item->iNumberData] );
       
  1745 	item->iLength = 0;
       
  1746 	item->iItemType = CNSmlDMProfileData::ENSmlTypeListYesNo;
       
  1747 	CleanupStack::PopAndDestroy( stringData );
       
  1748 
       
  1749 	item = Item(ENSmlServerAccept);
       
  1750 	if ( iDoc->SANSupport() )
       
  1751 	{   
       
  1752 		item->iHidden = ETrue;
       
  1753 		return;
       
  1754 	}	
       
  1755 	stringData = iEikonEnv->ReadDesCArrayResourceL( R_NSML_ACCEPT_YESNO_TYPE );
       
  1756 	CleanupStack::PushL( stringData );
       
  1757 	if ( EditMode() || CopyMode() )
       
  1758 		{
       
  1759         if ( iProfile->SASyncState() != ESASyncStateEnable )
       
  1760 		    {
       
  1761 		    item->iNumberData = EFalse;
       
  1762 		    }
       
  1763 		else
       
  1764 		    {
       
  1765 		    item->iNumberData = ETrue;
       
  1766 		    }
       
  1767 		}
       
  1768 	else
       
  1769 		{
       
  1770 		item->iNumberData = EFalse;
       
  1771 		}
       
  1772 	item->iResource = R_NSML_ACCEPT_YESNO_TYPE;
       
  1773 	item->SetValue( (*stringData)[item->iNumberData] );
       
  1774 	item->iLength = 0;
       
  1775 	item->iItemType = CNSmlDMProfileData::ENSmlTypeListYesNo;
       
  1776 	CleanupStack::PopAndDestroy( stringData );
       
  1777 	}
       
  1778 	
       
  1779 // -----------------------------------------------------------------------------
       
  1780 // CNSmlDMDlgProfileView::BuildProfileHttpsUserNameAndPasswordItemL
       
  1781 // -----------------------------------------------------------------------------
       
  1782 //
       
  1783 void CNSmlDMDlgProfileView::BuildProfileHttpsUserNameAndPasswordItemL()
       
  1784 	{
       
  1785 	FLOG( "[OMADM] CNSmlDMDlgProfileView::BuildProfileHttpsUserNameAndPasswordItemL" );
       
  1786 	
       
  1787 	CNSmlDMProfileData* item = Item( ENSmlHttpsUsername );
       
  1788 	HBufC* emptyText = iEikonEnv->AllocReadResourceLC(
       
  1789 		                                         R_QTN_SML_SET_VAL_FIELD_NONE );
       
  1790 	item->SetValue( emptyText->Des() );
       
  1791 	CleanupStack::PopAndDestroy( emptyText );
       
  1792     
       
  1793     TBuf<KNSmlMaxTextLength256> buf;
       
  1794     if ( EditMode() || CopyMode() )
       
  1795 		{
       
  1796         iProfile->GetHttpUserNameL( buf );
       
  1797         if( buf.Length() > 0 )      
       
  1798            {
       
  1799         item->SetValue( buf );
       
  1800            } 
       
  1801 		}
       
  1802 	item->iMandatory = ETrue;
       
  1803 	item->iLength = KNSmlMaxUsernameLength;
       
  1804 	item->iLatinInput = ETrue;
       
  1805 	item->iItemType = CNSmlDMProfileData::ENSmlTypeText;
       
  1806 	if( !iProfile->HttpUsedL() ||  Item( ENSmlConnType )->iNumberData != EProfileInternet )
       
  1807 	    {
       
  1808 	    item->iHidden = ETrue;
       
  1809 	    }
       
  1810     
       
  1811 	item = Item(ENSmlHttpsPassword);
       
  1812 	if ( EditMode() || CopyMode() )
       
  1813 		{
       
  1814         TBuf<KNSmlMaxItemLength> buf;
       
  1815         iProfile->GetHttpPasswordL( buf );
       
  1816         item->iValue.Copy( buf );
       
  1817 		}
       
  1818 	else
       
  1819 		{
       
  1820 		item->iValue = KNullDesC;
       
  1821 		}
       
  1822 
       
  1823 	buf.Fill( '*', KNumberofCharacters ); //mask with 4 stars
       
  1824 	item->SetValue( buf );	
       
  1825 	item->iLength = KNSmlMaxPasswordLength;
       
  1826 	item->iItemType = CNSmlDMProfileData::ENSmlTypeSecret;
       
  1827 	if( !iProfile->HttpUsedL() ||  Item( ENSmlConnType )->iNumberData != EProfileInternet    )
       
  1828 	    {
       
  1829 	    item->iHidden = ETrue;
       
  1830 	    }	
       
  1831 	}
       
  1832 	
       
  1833 // -----------------------------------------------------------------------------
       
  1834 // CNSmlDMDlgProfileView::BuildProfileHttpsUsedItemL
       
  1835 // -----------------------------------------------------------------------------
       
  1836 //
       
  1837 void CNSmlDMDlgProfileView::BuildProfileHttpsUsedItemL()
       
  1838 	{
       
  1839 	FLOG( "[OMADM] CNSmlDMDlgProfileView::BuildProfileHttpsUsedItemL" );
       
  1840 	
       
  1841 	CNSmlDMProfileData* item = Item( ENSmlHttpsUsed );
       
  1842 	CDesCArray* stringData = 
       
  1843 	        iEikonEnv->ReadDesCArrayResourceL( R_NSML_HTTPS_ACTIVE_YESNO_TYPE );
       
  1844 	CleanupStack::PushL( stringData );
       
  1845 	if ( EditMode() || CopyMode() )
       
  1846 		{
       
  1847         if ( iProfile->HttpUsedL() )
       
  1848 		    {
       
  1849 		    item->iNumberData = ETrue;
       
  1850 		    }
       
  1851 		else
       
  1852 		    {
       
  1853 		    item->iNumberData = EFalse;
       
  1854 		    }
       
  1855 		}
       
  1856 	else
       
  1857 		{
       
  1858 		item->iNumberData = EFalse;
       
  1859 		}
       
  1860 	item->iResource = R_NSML_HTTPS_ACTIVE_YESNO_TYPE;
       
  1861 	item->SetValue( (*stringData)[item->iNumberData] );
       
  1862 	item->iLength = 0;
       
  1863 	item->iItemType = CNSmlDMProfileData::ENSmlTypehttpListYesNo;
       
  1864 	item->iHidden = ( Item( ENSmlConnType )->iNumberData != EProfileInternet );    
       
  1865 	CleanupStack::PopAndDestroy( stringData );			
       
  1866 	}
       
  1867 	
       
  1868 // -----------------------------------------------------------------------------
       
  1869 // CNSmlDMDlgProfileView::GetItemForIndex
       
  1870 // -----------------------------------------------------------------------------
       
  1871 //
       
  1872 CNSmlDMProfileData* CNSmlDMDlgProfileView::GetItemForIndex( TInt aIndex )
       
  1873 	{
       
  1874 	FLOG( "[OMADM] CNSmlDMDlgProfileView::GetItemForIndex:" );
       
  1875 	
       
  1876 	TInt index = 0;
       
  1877 	while ( ( aIndex != IndexItem(index)->iIndex ) &&
       
  1878 	         ( index < iProfileList->Count() ) )
       
  1879 		{
       
  1880         index++;
       
  1881 		}
       
  1882 	return (*iProfileList)[index];
       
  1883 	}
       
  1884 	
       
  1885 //-----------------------------------------------------------------------------
       
  1886 // CNSmlDMDlgProfileView::IndexItem
       
  1887 //-----------------------------------------------------------------------------
       
  1888 //
       
  1889 CNSmlDMProfileData* CNSmlDMDlgProfileView::IndexItem( TInt aItemId )
       
  1890 	{
       
  1891 	FLOG( "[OMADM] CNSmlDMDlgProfileView::Item:" );
       
  1892 	
       
  1893 	CNSmlDMProfileData* item = NULL;
       
  1894 	TInt count = iProfileList->Count();
       
  1895 	for ( TInt index = 0; index < count; index++ )
       
  1896 		{
       
  1897 		CNSmlDMProfileData* temp = iProfileList->At(index);
       
  1898 		if ( temp->iItemId == aItemId )
       
  1899 			{
       
  1900 			item = temp;
       
  1901 			break;
       
  1902 			}
       
  1903 		}
       
  1904 	__ASSERT_DEBUG( item, TUtil::Panic( KErrGeneral ) );
       
  1905 	return item;
       
  1906 	}
       
  1907 
       
  1908 //-----------------------------------------------------------------------------
       
  1909 // CNSmlDMTextEditor::CNSmlDMTextEditor()
       
  1910 //-----------------------------------------------------------------------------
       
  1911 //
       
  1912 CNSmlDMTextEditor::CNSmlDMTextEditor(TInt aResourceID, 
       
  1913                                                      TDes& aText, 
       
  1914                                                      TInt aTextSettingPageFlags)                      
       
  1915  : CAknTextSettingPage(aResourceID, aText, aTextSettingPageFlags)
       
  1916 	{
       
  1917 		
       
  1918 	}
       
  1919 //-----------------------------------------------------------------------------
       
  1920 // CNSmlDMTextEditor::OfferKeyEventL()
       
  1921 //-----------------------------------------------------------------------------
       
  1922 //
       
  1923 TKeyResponse CNSmlDMTextEditor::OfferKeyEventL(const TKeyEvent& aKeyEvent, 
       
  1924                                                  TEventCode aType)
       
  1925     {
       
  1926 		    if(EKeyEnter == aKeyEvent.iCode)
       
  1927 		    {
       
  1928 		    	ProcessCommandL(EAknSoftkeySelect);
       
  1929 		    	return EKeyWasConsumed;
       
  1930 		    }
       
  1931 		    return CAknTextSettingPage::OfferKeyEventL(aKeyEvent, aType);
       
  1932     }
       
  1933 //-----------------------------------------------------------------------------
       
  1934 // CNSmlDMTextEditor::~CNSmlDMTextEditor()
       
  1935 //-----------------------------------------------------------------------------
       
  1936 //    
       
  1937 CNSmlDMTextEditor::~CNSmlDMTextEditor()
       
  1938   {
       
  1939 	
       
  1940   }    
       
  1941 // End of File