omads/omadsappui/AspSyncUtil/src/AspProfileDialog.cpp
branchRCL_3
changeset 24 8e7494275d3a
parent 23 2bb96f4ecad8
child 25 4f0867e42d62
equal deleted inserted replaced
23:2bb96f4ecad8 24:8e7494275d3a
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include "AspProfileDialog.h"
       
    23 #include "AspContentDialog.h"
       
    24 #include "AspSyncUtil.rh"
       
    25 #include "AspDebug.h"
       
    26 #include <csxhelp/ds.hlp.hrh>
       
    27 
       
    28 #include <aspsyncutil.mbg>  // for bitmap enumerations
       
    29 #include <AknIconArray.h>   // for GulArray
       
    30 #include <aknpasswordsettingpage.h>     // CAknAlphaPasswordSettingPage
       
    31 #include <ConnectionUiUtilities.h>      // CConnectionUiUtilities
       
    32 #include <featmgr.h>   // FeatureManager
       
    33 #include <cmdefconnvalues.h>
       
    34 #include <cmmanager.h>
       
    35 
       
    36 #include "AspSchedule.h"
       
    37 
       
    38 const TInt KMSKControlId( CEikButtonGroupContainer::EMiddleSoftkeyPosition );
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 
       
    41 
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CAspProfileDialog::ShowDialogL
       
    45 // 
       
    46 // -----------------------------------------------------------------------------
       
    47 TBool CAspProfileDialog::ShowDialogL(const TAspParam& aParam)
       
    48 	{
       
    49 	CAspProfileDialog* dialog = CAspProfileDialog::NewL(aParam);
       
    50 
       
    51 	TBool ret = dialog->ExecuteLD(R_ASP_PROFILE_DIALOG);
       
    52 
       
    53     return ret;
       
    54 	}
       
    55 
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CAspProfileDialog::NewL
       
    59 //
       
    60 // -----------------------------------------------------------------------------
       
    61 CAspProfileDialog* CAspProfileDialog::NewL(const TAspParam& aParam)
       
    62     {
       
    63     FLOG( _L("CAspProfileDialog::NewL START") );
       
    64 
       
    65     CAspProfileDialog* self = new ( ELeave ) CAspProfileDialog(aParam);
       
    66     CleanupStack::PushL(self);
       
    67     self->ConstructL();
       
    68     CleanupStack::Pop(self);
       
    69 
       
    70     FLOG( _L("CAspProfileDialog::NewL END") );
       
    71     return self;
       
    72     }
       
    73 
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CAspProfileDialog::CAspProfileDialog
       
    77 // 
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 CAspProfileDialog::CAspProfileDialog(const TAspParam& aParam)
       
    81 	{
       
    82     iSyncSession = aParam.iSyncSession;
       
    83     iApplicationId = aParam.iApplicationId;
       
    84     iProfile = aParam.iProfile;
       
    85     iContentList = aParam.iContentList;
       
    86     iProfileList = aParam.iProfileList;
       
    87     iEditMode = aParam.iMode;
       
    88     iMSKEmpty = EFalse;
       
    89        
       
    90 	__ASSERT_ALWAYS(iProfile, TUtil::Panic(KErrGeneral));
       
    91 	__ASSERT_ALWAYS(iContentList, TUtil::Panic(KErrGeneral));
       
    92 	__ASSERT_ALWAYS(iSyncSession, TUtil::Panic(KErrGeneral));
       
    93     }
       
    94 
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CAspProfileDialog::ConstructL
       
    98 //
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void CAspProfileDialog::ConstructL()
       
   102     {
       
   103     FLOG( _L("CAspProfileDialog::ConstructL START") );
       
   104 	
       
   105 	// contruct menu for our dialog
       
   106 	CAknDialog::ConstructL(R_ASP_PROFILE_DIALOG_MENU);
       
   107 
       
   108 	iResHandler = CAspResHandler::NewL();
       
   109 
       
   110 	iSettingList = new (ELeave) CArrayPtrFlat<CAspListItemData>(1);
       
   111 
       
   112     TAspParam param(KErrNotFound, iSyncSession);
       
   113 	iBearerHandler = CAspBearerHandler::NewL(param);
       
   114 	iApHandler = CAspAccessPointHandler::NewL(param);
       
   115 	
       
   116 	// get previous title so it can be restored
       
   117 	iSettingEnforcement = TUtil::SettingEnforcementState();
       
   118 	iStatusPaneHandler = CStatusPaneHandler::NewL(iAvkonAppUi);
       
   119 	iStatusPaneHandler->StoreOriginalTitleL();
       
   120 	
       
   121 	FLOG( _L("CAspProfileDialog::ConstructL END") );
       
   122     } 
       
   123 
       
   124 
       
   125 // ----------------------------------------------------------------------------
       
   126 // Destructor
       
   127 //
       
   128 // ----------------------------------------------------------------------------
       
   129 //
       
   130 CAspProfileDialog::~CAspProfileDialog()
       
   131     {
       
   132     FLOG( _L("CAspProfileDialog::~CAspProfileDialog START") );
       
   133 
       
   134 	delete iResHandler;
       
   135 	
       
   136 	if (iSettingList)
       
   137 		{
       
   138 		iSettingList->ResetAndDestroy();
       
   139 	    delete iSettingList;
       
   140 		}
       
   141 
       
   142 	delete iStatusPaneHandler;
       
   143 	delete iBearerHandler;
       
   144 	delete iApHandler;
       
   145 	
       
   146     if (iAvkonAppUi)
       
   147     	{
       
   148     	iAvkonAppUi->RemoveFromStack(this);
       
   149     	}
       
   150 
       
   151 	FLOG( _L("CAspProfileDialog::~CAspProfileDialog END") );
       
   152     }
       
   153 
       
   154 
       
   155 //------------------------------------------------------------------------------
       
   156 // CAspProfileDialog::ActivateL
       
   157 //
       
   158 // Called by system when dialog is activated.
       
   159 //------------------------------------------------------------------------------
       
   160 //
       
   161 void CAspProfileDialog::ActivateL()
       
   162 	{
       
   163     CAknDialog::ActivateL();
       
   164 
       
   165 	// this cannot be in ConstructL which is executed before dialog is launched
       
   166 	iAvkonAppUi->AddToStackL(this);
       
   167     }
       
   168 
       
   169 
       
   170 //------------------------------------------------------------------------------
       
   171 // CAspContentListDialog::GetHelpContext
       
   172 //
       
   173 //------------------------------------------------------------------------------
       
   174 //
       
   175 void CAspProfileDialog::GetHelpContext(TCoeHelpContext& aContext) const
       
   176 	{
       
   177 	aContext.iMajor = KUidSmlSyncApp;
       
   178 	aContext.iContext = KDS_HLP_SETTINGS;    
       
   179 	}
       
   180 
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CAspProfileDialog::HandleListBoxEventL
       
   184 // 
       
   185 // -----------------------------------------------------------------------------
       
   186 void CAspProfileDialog::HandleListBoxEventL(CEikListBox* /*aListBox*/,
       
   187                                             TListBoxEvent aEventType)
       
   188 	{
       
   189 	if( AknLayoutUtils::PenEnabled() )  
       
   190 	  {
       
   191 	   switch ( aEventType )
       
   192         {
       
   193         case EEventItemSingleClicked:
       
   194               HandleOKL();
       
   195               break;
       
   196          case EEventEnterKeyPressed :
       
   197          
       
   198          case EEventItemDraggingActioned :
       
   199          case EEventPenDownOnItem :
       
   200         	  if(iEditMode != EDialogModeSettingEnforcement)
       
   201 				    {
       
   202 				    TRAPD(err ,CheckContentSettingL());//folder
       
   203 		         	User::LeaveIfError(err);
       
   204 				    }
       
   205               break;
       
   206          default:
       
   207               break;
       
   208         }
       
   209 		
       
   210 	  }
       
   211     
       
   212 	}
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CAspProfileDialog::PreLayoutDynInitL
       
   216 // 
       
   217 // -----------------------------------------------------------------------------
       
   218 //
       
   219 void CAspProfileDialog::PreLayoutDynInitL()
       
   220     {
       
   221     iSettingListBox = (CAknSettingStyleListBox*) ControlOrNull (EAspProfileDialogList);
       
   222     
       
   223    	__ASSERT_ALWAYS(iSettingListBox, TUtil::Panic(KErrGeneral));
       
   224     
       
   225 	iSettingListBox->SetListBoxObserver(this);
       
   226 	iSettingListBox->CreateScrollBarFrameL(ETrue);
       
   227 	iSettingListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   228 	                 CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto);
       
   229 	
       
   230 	SetIconsL();
       
   231 	
       
   232 	// create array of setting items (iSettingList)
       
   233 	CreateSettingsListL();
       
   234 
       
   235 	// add setting headers into listbox
       
   236 	UpdateListBoxL(iSettingListBox, iSettingList);
       
   237 	
       
   238 	if (iEditMode == EDialogModeEditMandatory)
       
   239 		{
       
   240 		TInt index = CheckMandatoryFields();
       
   241 		if (index != KErrNotFound)
       
   242 			{
       
   243 			ListBox()->SetCurrentItemIndexAndDraw(index);
       
   244 			}
       
   245 		}
       
   246 	
       
   247 	TInt curIndex = ListBox()->CurrentItemIndex();
       
   248 		
       
   249 	CAspListItemData* curItem = GetItemForIndex(curIndex);
       
   250 	TBool isPCSuite = CAspProfile::IsPCSuiteProfile(iProfile);
       
   251     	
       
   252    	//if((isPCSuite && curItem->iHidden == EVisibilityReadOnly)
       
   253    	if(curItem->iHidden == EVisibilityReadOnly
       
   254    		|| iEditMode == EDialogModeSettingEnforcement)
       
   255    	{
       
   256    	   	 SetEmptyMiddleSoftKeyLabelL();
       
   257    	}
       
   258    	
       
   259 #ifdef RD_DSUI_TIMEDSYNC 
       
   260 	iStatusPaneHandler->SetTitleL(R_ASP_TITLE_PROFILE_SETTINGS);
       
   261 #else
       
   262     iProfile->GetName(iBuf);
       
   263     iStatusPaneHandler->SetTitleL(iBuf);
       
   264 #endif
       
   265 	iStatusPaneHandler->SetNaviPaneTitleL(KNullDesC);
       
   266     }
       
   267 
       
   268 
       
   269 // ----------------------------------------------------------------------------
       
   270 // CAspProfileDialog::SetMiddleSoftKeyLabelL
       
   271 //
       
   272 // ----------------------------------------------------------------------------
       
   273 //
       
   274 void CAspProfileDialog::SetEmptyMiddleSoftKeyLabelL()
       
   275     {
       
   276     ButtonGroupContainer().RemoveCommandFromStack(KMSKControlId,EAknSoftkeyOpen );
       
   277     HBufC* middleSKText = StringLoader::LoadLC( R_TEXT_SOFTKEY_EMPTY );
       
   278 
       
   279     ButtonGroupContainer().AddCommandToStackL(
       
   280         KMSKControlId,
       
   281         EAknSoftkeyEmpty,
       
   282         *middleSKText );
       
   283     iMSKEmpty= ETrue;
       
   284     CleanupStack::PopAndDestroy( middleSKText );
       
   285     }
       
   286 // ----------------------------------------------------------------------------
       
   287 // CAspProfileDialog::SetIconsL
       
   288 //
       
   289 // ----------------------------------------------------------------------------
       
   290 //
       
   291 void CAspProfileDialog::SetIconsL()
       
   292     {
       
   293     if (!iSettingListBox)
       
   294     	{
       
   295     	return;
       
   296     	}
       
   297  
       
   298  	TFileName bitmapName;
       
   299 	CAspResHandler::GetBitmapFileName(bitmapName);
       
   300 	CArrayPtr<CGulIcon>* icons = new (ELeave) CAknIconArray(KDefaultArraySize);
       
   301 	CleanupStack::PushL(icons);
       
   302 	
       
   303 	// Create the lock icon as the last icon in the table
       
   304 	CFbsBitmap* skinnedBitmap = NULL;
       
   305     CFbsBitmap* skinnedMask = NULL;
       
   306     
       
   307 	// Make the icon and put it in the array
       
   308     CGulIcon* icon = CGulIcon::NewL();
       
   309     CleanupStack::PushL(icon);
       
   310     icon->SetBitmapsOwnedExternally(EFalse);
       
   311 		
       
   312     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   313     // Create color icon
       
   314     AknsUtils::CreateColorIconL(skin,
       
   315 							    KAknsIIDQgnIndiSettProtectedAdd, 
       
   316 							    KAknsIIDQsnIconColors,
       
   317 							    EAknsCIQsnIconColorsCG13,
       
   318 							    skinnedBitmap, 
       
   319 							    skinnedMask,
       
   320 							    bitmapName,
       
   321 							    EMbmAspsyncutilQgn_indi_sett_protected_add, 
       
   322 							    EMbmAspsyncutilQgn_indi_sett_protected_add_mask,
       
   323 							    KRgbBlack
       
   324 							   );
       
   325 	
       
   326     icon->SetMask(skinnedMask);     // ownership transferred
       
   327     icon->SetBitmap(skinnedBitmap); // ownership transferred
       
   328     
       
   329 	icons->AppendL( icon );  
       
   330 
       
   331 	CleanupStack::Pop(icon); // icon
       
   332     // Create the lock icon for highlight
       
   333     skinnedBitmap = NULL;
       
   334     skinnedMask = NULL;
       
   335     
       
   336     // delete old icons
       
   337     CArrayPtr<CGulIcon>* arr =
       
   338 		iSettingListBox->ItemDrawer()->FormattedCellData()->IconArray();
       
   339     
       
   340     if (arr)
       
   341     	{
       
   342     	arr->ResetAndDestroy();
       
   343 	    delete arr;
       
   344 	    arr = NULL;
       
   345     	}
       
   346 
       
   347 	iSettingListBox->ItemDrawer()->FormattedCellData()->SetIconArrayL(icons);
       
   348 	CleanupStack::Pop(icons);
       
   349     }
       
   350 
       
   351 // -----------------------------------------------------------------------------
       
   352 // CAspProfileDialog::IconL
       
   353 // 
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 CGulIcon* CAspProfileDialog::IconL(TAknsItemID aId, const TDesC& aFileName, TInt aFileIndex, TInt aFileMaskIndex)
       
   357 	{
       
   358     return TDialogUtil::CreateIconL(aId, aFileName, aFileIndex, aFileMaskIndex);
       
   359 	}
       
   360 
       
   361 
       
   362 //------------------------------------------------------------------------------
       
   363 // CAspProfileDialog::DynInitMenuPaneL
       
   364 //
       
   365 // Called by system before menu is shown.
       
   366 //------------------------------------------------------------------------------
       
   367 //
       
   368 void CAspProfileDialog::DynInitMenuPaneL(TInt /*aResourceID*/, CEikMenuPane* aMenuPane)
       
   369 	{
       
   370    
       
   371    	if (ListBox()->Model()->NumberOfItems() == 0) 
       
   372 		{
       
   373 		TDialogUtil::DeleteMenuItem(aMenuPane, EAspMenuCmdChange);
       
   374 		return;
       
   375 		}
       
   376 
       
   377 	CAspListItemData* item = GetItemForIndex(ListBox()->CurrentItemIndex());
       
   378 	if (item->iHidden == EVisibilityReadOnly)
       
   379 		{
       
   380 		TDialogUtil::DeleteMenuItem(aMenuPane, EAspMenuCmdChange);
       
   381 		}
       
   382 	
       
   383 	if (!FeatureManager::FeatureSupported(KFeatureIdHelp))
       
   384 		{
       
   385 		TDialogUtil::DeleteMenuItem(aMenuPane, EAknCmdHelp);
       
   386 		}
       
   387 	
       
   388     }
       
   389 
       
   390 
       
   391 //------------------------------------------------------------------------------
       
   392 // CAspProfileDialog::ProcessCommandL
       
   393 //
       
   394 // Handle commands from menu.
       
   395 //------------------------------------------------------------------------------
       
   396 //
       
   397 void CAspProfileDialog::ProcessCommandL(TInt aCommandId)
       
   398 	{
       
   399 	HideMenu();
       
   400 
       
   401 	switch (aCommandId)
       
   402 		{
       
   403 		case EAknCmdHelp:
       
   404 			{
       
   405 			TUtil::LaunchHelpAppL(iEikonEnv);
       
   406             break;
       
   407 			}
       
   408 
       
   409 		case EAspMenuCmdChange:
       
   410 		case EAspMenuCmdOpen:
       
   411 			{				
       
   412     		CAspListItemData* item = GetItemForIndex(ListBox()->CurrentItemIndex());
       
   413 
       
   414 			if (item->iItemType == CAspListItemData::ETypeListYesNo)
       
   415 				{
       
   416 				// open editor for Yes/No setting
       
   417 				if (EditSettingItemListL(*item))
       
   418 					{
       
   419 					SetVisibilityL();
       
   420 					UpdateListBoxL(ListBox(), iSettingList);
       
   421 					}
       
   422 				}				
       
   423 			else
       
   424 				{
       
   425 				HandleOKL();
       
   426 				}
       
   427 
       
   428 			break;
       
   429 			}
       
   430 		    
       
   431         case EAspMenuCmdExit:
       
   432         case EAknCmdExit:
       
   433         case EEikCmdExit:
       
   434 			{
       
   435 			// close dialog and exit calling application
       
   436 			iAvkonAppUi->ProcessCommandL(EAknCmdExit);
       
   437 			break;
       
   438 			}
       
   439 
       
   440 		default:			
       
   441 		    break;
       
   442 		}
       
   443 	}
       
   444 
       
   445 
       
   446 //------------------------------------------------------------------------------
       
   447 // CAspProfileDialog::OkToExitL
       
   448 //
       
   449 //------------------------------------------------------------------------------
       
   450 //
       
   451 TBool CAspProfileDialog::OkToExitL(TInt aButtonId)
       
   452 	{
       
   453 	if (aButtonId == EEikBidCancel)
       
   454 		{
       
   455 		// save silently and close dialog
       
   456 		
       
   457 		CheckSettingValues(aButtonId);
       
   458 
       
   459 		TRAP_IGNORE(SaveSettingsL());
       
   460 		return ETrue; // close dialog
       
   461 		}
       
   462 
       
   463 	if (aButtonId == EAknSoftkeyBack)
       
   464         {
       
   465         TBool ret = CheckSettingValues(aButtonId);
       
   466         if (!ret)
       
   467         	{
       
   468         	return EFalse; // leave dialog open
       
   469         	}
       
   470         	
       
   471 		TRAP_IGNORE(SaveSettingsL());
       
   472 		return ETrue; // close dialog
       
   473 		}
       
   474 		
       
   475 	if (aButtonId == EAknSoftkeyOpen || aButtonId == EAknSoftkeyEmpty)  // MSK
       
   476         {
       
   477 		CAspListItemData* item = GetItemForIndex(ListBox()->CurrentItemIndex());
       
   478 		if (item->iHidden == EVisibilityReadOnly)
       
   479 			{
       
   480     		if(iEditMode == EDialogModeSettingEnforcement)
       
   481     		{
       
   482     			TDialogUtil::ShowInformationNoteL(R_ASP_PROTECTED_SETTING);
       
   483     		}
       
   484      		else
       
   485      		{
       
   486 			TDialogUtil::ShowInformationNoteL(R_ASP_NOTE_READ_ONLY);
       
   487      		}
       
   488 			return EFalse;
       
   489 			}
       
   490 
       
   491         HandleOKL();
       
   492 		return EFalse;  // leave dialog open
       
   493 		}
       
   494 		
       
   495 	if (aButtonId == EAknSoftkeyOptions)	
       
   496 		{
       
   497 		if (iCommandSetId == R_ASP_CBA_OPTIONS_BACK_OPEN)
       
   498 			{
       
   499 			UpdateMenuL(R_ASP_PROFILE_CONTEXT_MENU);
       
   500 			}	
       
   501 		else 
       
   502 			{
       
   503 			UpdateMenuL(R_ASP_PROFILE_DIALOG_MENU);	
       
   504 			}
       
   505 		return EFalse;
       
   506 		}
       
   507 	return CAknDialog::OkToExitL(aButtonId);
       
   508 	}
       
   509 
       
   510 
       
   511 //------------------------------------------------------------------------------
       
   512 // CAspProfileDialog::CheckSettingValuesL
       
   513 //
       
   514 //------------------------------------------------------------------------------
       
   515 //
       
   516 TBool CAspProfileDialog::CheckSettingValuesL(TInt aButtonId)
       
   517 	{
       
   518     if (iEditMode == EDialogModeReadOnly || 
       
   519         iEditMode == EDialogModeSettingEnforcement)
       
   520     	{
       
   521     	return ETrue;
       
   522     	}
       
   523 	
       
   524 	if (aButtonId == EEikBidCancel)
       
   525 		{
       
   526 		TInt index = CheckUniqueServerId();
       
   527 		if (index != KErrNotFound)
       
   528 			{
       
   529 			Item(EAspServerId)->SetValueL(iOldServerId);
       
   530 			}
       
   531 
       
   532 		return ETrue;
       
   533 		}
       
   534 
       
   535 	TInt mandatoryIndex = CheckMandatoryFields();
       
   536 	if (mandatoryIndex != KErrNotFound)
       
   537 		{
       
   538 		if (!TDialogUtil::ShowConfirmationQueryL(R_ASP_EXIT_ANYWAY))
       
   539 			{
       
   540 			ListBox()->SetCurrentItemIndexAndDraw(mandatoryIndex);
       
   541 			return EFalse; // leave dialog open
       
   542 			}
       
   543 				
       
   544 	    TInt serverIdIndex = CheckUniqueServerId();
       
   545 	    if (serverIdIndex != KErrNotFound)
       
   546 	    	{
       
   547 	    	Item(EAspServerId)->SetValueL(iOldServerId);
       
   548 	    	}
       
   549 		}
       
   550 	else
       
   551 		{
       
   552 		TInt serverIdIndex = CheckUniqueServerId();
       
   553 	    if (serverIdIndex != KErrNotFound)
       
   554 		    {
       
   555 		    if (!TDialogUtil::ShowConfirmationQueryL(R_ASP_SERVER_ID_EXISTS))
       
   556 			    {
       
   557 			    ListBox()->SetCurrentItemIndexAndDraw(serverIdIndex);
       
   558 			    return EFalse; // leave dialog open
       
   559 			    }
       
   560 		    else
       
   561 			    {
       
   562 			    Item(EAspServerId)->SetValueL(iOldServerId);
       
   563 			    }
       
   564 		    }
       
   565 		}
       
   566 
       
   567     return ETrue;
       
   568 	}
       
   569 
       
   570 
       
   571 //------------------------------------------------------------------------------
       
   572 // CAspProfileDialog::CheckSettingValues
       
   573 //
       
   574 //------------------------------------------------------------------------------
       
   575 //
       
   576 TBool CAspProfileDialog::CheckSettingValues(TInt aButtonId)
       
   577 	{
       
   578 	TBool ret = EFalse;
       
   579 	
       
   580 	TRAPD(err, ret = CheckSettingValuesL(aButtonId));
       
   581 	if (err != KErrNone)
       
   582 		{
       
   583 		return ETrue;
       
   584 		}
       
   585 
       
   586 	return ret;
       
   587 	}
       
   588 
       
   589 
       
   590 // ----------------------------------------------------------------------------
       
   591 // CAspProfileDialog::OfferKeyEventL
       
   592 // 
       
   593 // ----------------------------------------------------------------------------
       
   594 //
       
   595 TKeyResponse CAspProfileDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   596 	{
       
   597 	if (aType == EEventKey)
       
   598 		{
       
   599 		switch (aKeyEvent.iCode)
       
   600 			{
       
   601 			case EKeyEnter:
       
   602 				{
       
   603 					HandleOKL();
       
   604 					return EKeyWasConsumed;
       
   605 				}
       
   606 			case EKeyEscape:  // framework calls this when dialog must shut down
       
   607 				{
       
   608 				return CAknDialog::OfferKeyEventL(aKeyEvent, aType);
       
   609         		}
       
   610 			case EKeyUpArrow:
       
   611 			case EKeyDownArrow:
       
   612 			    {
       
   613 			    	if(iEditMode != EDialogModeSettingEnforcement)
       
   614 				    {
       
   615 				    TRAPD(err ,CheckContentSettingL(aKeyEvent));//folder
       
   616 		         	User::LeaveIfError(err);
       
   617 				    }
       
   618 			    break;
       
   619 			    }
       
   620             default:
       
   621 				{
       
   622 			    break;
       
   623 				}
       
   624 			}
       
   625 		}
       
   626 
       
   627 	return CAknDialog::OfferKeyEventL( aKeyEvent, aType);
       
   628 	}
       
   629 
       
   630 // ---------------------------------------------------------------------------------------------
       
   631 // CAspProfileDialog::CheckContentSetting
       
   632 // modifies MSK and menu item depending on the item in the list box when touch events are handled
       
   633 // ----------------------------------------------------------------------------------------------
       
   634 //
       
   635 
       
   636 void CAspProfileDialog::CheckContentSettingL()
       
   637 {
       
   638 	TInt curIndex = ListBox()->CurrentItemIndex();
       
   639 	TInt count = iSettingList->Count();
       
   640 	CAspListItemData* lastItem = (*iSettingList)[--count];
       
   641 	
       
   642 
       
   643 		
       
   644 	CAspListItemData* curItem = GetItemForIndex(curIndex);
       
   645 	TBool isPCSuite = CAspProfile::IsPCSuiteProfile(iProfile);
       
   646 	if(isPCSuite && (curItem->iHidden == EVisibilityReadOnly))
       
   647 	{
       
   648    		SetEmptyMiddleSoftKeyLabelL();
       
   649    		return;
       
   650 	}
       
   651 	if(curItem->iItemId != EAspSyncContent)
       
   652 		{
       
   653 		if(iCommandSetId != R_ASP_CBA_OPTIONS_BACK_CHANGE || iMSKEmpty)
       
   654 			{
       
   655 			UpdateCbaL(R_ASP_CBA_OPTIONS_BACK_CHANGE);
       
   656 		
       
   657 			}
       
   658 		return;		
       
   659 		}
       
   660 	UpdateCbaL( R_ASP_CBA_OPTIONS_BACK_OPEN);
       
   661 
       
   662 }
       
   663 
       
   664 // ----------------------------------------------------------------------------
       
   665 // CAspProfileDialog::CheckContentSetting
       
   666 // modifies MSK depending on the item
       
   667 // ----------------------------------------------------------------------------
       
   668 //
       
   669 
       
   670 void CAspProfileDialog::CheckContentSettingL(const TKeyEvent& aKeyEvent)
       
   671 	{
       
   672 	
       
   673 	TInt curIndex = ListBox()->CurrentItemIndex();
       
   674 	TInt count = iSettingList->Count();
       
   675 	CAspListItemData* lastItem = (*iSettingList)[--count];
       
   676 	
       
   677 	switch (aKeyEvent.iCode)
       
   678 		{
       
   679 		case EKeyUpArrow:
       
   680 			{
       
   681 				if (curIndex)
       
   682 				{
       
   683 					curIndex--;
       
   684 				}
       
   685 				else
       
   686 				{
       
   687 				    curIndex = lastItem->iIndex;
       
   688 				}
       
   689 			break;
       
   690 			}
       
   691 		case EKeyDownArrow:
       
   692 			{
       
   693 				if (curIndex == lastItem->iIndex)
       
   694 				{
       
   695 				curIndex = 0;
       
   696 				}
       
   697 				else
       
   698 				{
       
   699 				curIndex++;
       
   700 				}
       
   701 			break;
       
   702 			}
       
   703 		}
       
   704 		
       
   705 	CAspListItemData* curItem = GetItemForIndex(curIndex);
       
   706 	if(curItem->iHidden == EVisibilityReadOnly)
       
   707 	{
       
   708    		SetEmptyMiddleSoftKeyLabelL();
       
   709    		return;
       
   710 	}
       
   711 	if(curItem->iItemId != EAspSyncContent)
       
   712 		{
       
   713 		if(iCommandSetId != R_ASP_CBA_OPTIONS_BACK_CHANGE || iMSKEmpty)
       
   714 			{
       
   715 			UpdateCbaL(R_ASP_CBA_OPTIONS_BACK_CHANGE);
       
   716 		
       
   717 			}
       
   718 		return;		
       
   719 		}
       
   720 	UpdateCbaL( R_ASP_CBA_OPTIONS_BACK_OPEN);
       
   721 
       
   722 	}
       
   723 
       
   724 // ----------------------------------------------------------------------------
       
   725 // CAspProfileDialog::HandleResourceChange
       
   726 // 
       
   727 // ----------------------------------------------------------------------------
       
   728 //
       
   729 void CAspProfileDialog::HandleResourceChange(TInt aType)
       
   730     {   
       
   731     if (aType == KEikDynamicLayoutVariantSwitch) //Handle change in layout orientation
       
   732         {
       
   733         TRect mainPaneRect;
       
   734         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
       
   735         SetRect(mainPaneRect);
       
   736         iSettingListBox->SetSize(mainPaneRect.Size());
       
   737         CCoeControl::HandleResourceChange(aType);
       
   738 		DrawDeferred();
       
   739 	    return;
       
   740 		}
       
   741 		
       
   742     if (aType == KAknsMessageSkinChange)
       
   743         {
       
   744         TRAP_IGNORE(SetIconsL());
       
   745         }
       
   746 		
       
   747     CCoeControl::HandleResourceChange(aType);
       
   748     }
       
   749 
       
   750 
       
   751 //------------------------------------------------------------------------------
       
   752 // CAspProfileDialog::CheckMandatoryFields
       
   753 //
       
   754 // Check that all mandatory fields are filled.
       
   755 //------------------------------------------------------------------------------
       
   756 //
       
   757 TInt CAspProfileDialog::CheckMandatoryFields()
       
   758 	{ 
       
   759 	TInt count = iSettingList->Count();
       
   760 	for (TInt i=0; i<count; i++)
       
   761 		{
       
   762 		CAspListItemData* item = (*iSettingList)[i];
       
   763 		
       
   764 		if (!CheckMandatoryContentFields(item))
       
   765 			{
       
   766 			return item->iIndex;
       
   767 			}
       
   768 			
       
   769 		if ( item->iMandatory && item->IsEmpty() && (item->iHidden == EVisibilityNormal) )
       
   770 			{
       
   771 			return item->iIndex;
       
   772 			}
       
   773 		}
       
   774 
       
   775     return KErrNotFound;
       
   776 	}
       
   777 
       
   778 
       
   779 //------------------------------------------------------------------------------
       
   780 // CAspProfileDialog::CheckUniqueServerId
       
   781 //
       
   782 //------------------------------------------------------------------------------
       
   783 //
       
   784 TInt CAspProfileDialog::CheckUniqueServerId()
       
   785 	{
       
   786 	TPtrC ptr = Item(EAspServerId)->Value();
       
   787 	
       
   788 	if (iOldServerId.Compare(ptr) == 0)
       
   789 		{
       
   790 		return KErrNotFound;  // server id has not changed
       
   791 		}
       
   792 	
       
   793 	if (!iProfileList)
       
   794 		{
       
   795 		return KErrNotFound;
       
   796 		}
       
   797 
       
   798 	TInt profileId = iProfile->ProfileId();
       
   799 
       
   800 	if (iProfileList->IsUniqueServerId(Item(EAspServerId)->Value(), profileId))
       
   801 		{
       
   802 		return KErrNotFound;
       
   803 		}
       
   804 		
       
   805 	return Item(EAspServerId)->iIndex;
       
   806 	}
       
   807 
       
   808 
       
   809 //------------------------------------------------------------------------------
       
   810 // CAspProfileDialog::CheckMandatoryContentFields
       
   811 //
       
   812 // Check that all mandatory fields are filled.
       
   813 //------------------------------------------------------------------------------
       
   814 //
       
   815 TBool CAspProfileDialog::CheckMandatoryContentFields(CAspListItemData* aListItem)
       
   816 	{
       
   817 	if (aListItem->iItemType != CAspListItemData::ETypeSyncContent)
       
   818 		{
       
   819 		return ETrue;
       
   820 		}
       
   821 		
       
   822 	TInt index = iContentList->FindTaskIndexForProvider(aListItem->iNumberData);
       
   823 	if (index == KErrNotFound)
       
   824 		{
       
   825 		return ETrue;
       
   826 		}
       
   827 		
       
   828 	TAspTaskItem& item = iContentList->TaskItem(index);
       
   829 	if (item.iEnabled && !item.iRemoteDatabaseDefined)
       
   830 		{
       
   831 		return EFalse;
       
   832 		}
       
   833 		
       
   834     return ETrue;
       
   835 	}
       
   836 
       
   837 
       
   838 //------------------------------------------------------------------------------
       
   839 // CAspProfileDialog::HandleOKL
       
   840 //
       
   841 //------------------------------------------------------------------------------
       
   842 //
       
   843 void CAspProfileDialog::HandleOKL()
       
   844 	{
       
   845 	CAspListItemData* item = GetItemForIndex(ListBox()->CurrentItemIndex());
       
   846 
       
   847 	if (item->iHidden == EVisibilityReadOnly)
       
   848 		{
       
   849 			if(iEditMode == EDialogModeSettingEnforcement)
       
   850       		{
       
   851     			TDialogUtil::ShowInformationNoteL(R_ASP_PROTECTED_SETTING);
       
   852     		}
       
   853      		else
       
   854      		{
       
   855 			TDialogUtil::ShowInformationNoteL(R_ASP_NOTE_READ_ONLY);
       
   856      		}
       
   857 		return;
       
   858 		}
       
   859 
       
   860 	if (EditSettingItemL(*item))
       
   861 		{
       
   862 		SetVisibilityL();
       
   863 		UpdateListBoxL(ListBox(), iSettingList);
       
   864 		}
       
   865 	}
       
   866 
       
   867 
       
   868 // ----------------------------------------------------------------------------
       
   869 // CAspProfileDialog::CreateSettingsListL
       
   870 // 
       
   871 // Function creates setting list array (iSettingsList).
       
   872 // Note: enum TAspConnectionSettings must match with string array
       
   873 // (R_ASP_CONNECTION_DIALOG_SETTING_ITEMS).
       
   874 // ----------------------------------------------------------------------------
       
   875 //
       
   876 void CAspProfileDialog::CreateSettingsListL()
       
   877 	{
       
   878 	// read setting headers from resource
       
   879 	CDesCArray* arr = iResHandler->ReadDesArrayLC(R_ASP_CONNECTION_DIALOG_SETTING_ITEMS);
       
   880 	
       
   881 	// add one CAspListItemData for each setting
       
   882 	AddItemL(EAspProfileName, arr);
       
   883 	AddItemL(EAspProtocolVersion, arr);
       
   884 	AddItemL(EAspServerId, arr);
       
   885 
       
   886 	AddItemL(EAspConnType, arr);
       
   887 	AddItemL(EAspAccessPoint,R_ASP_NETWORK_DESTINATION);
       
   888 	AddItemL(EAspHostAddress, arr);
       
   889 	AddItemL(EAspPort, arr);
       
   890 	AddItemL(EAspUsername, arr);
       
   891 	AddItemL(EAspPassword, arr);
       
   892 	
       
   893 #ifdef __SYNCML_DS_ALERT
       
   894 	AddItemL(EAspServerAlert, arr);
       
   895 #endif
       
   896 
       
   897 	AddItemL(EAspHttpsUsername, arr);
       
   898 	AddItemL(EAspHttpsPassword, arr);
       
   899 	
       
   900 	AddItemL(EAspSyncDirection, arr);
       
   901 	
       
   902 #ifndef	RD_DSUI_TIMEDSYNC 
       
   903 	AddContentItemsL();
       
   904 #endif
       
   905 
       
   906 	// write setting data into each CAspListItemData
       
   907 	TInt count=iSettingList->Count();
       
   908 	for (TInt i=0; i<count; i++)
       
   909 		{
       
   910 		InitSettingItemL((*iSettingList)[i]);
       
   911 		}
       
   912 
       
   913 	SetVisibilityL();  // find out what setting appear on UI
       
   914 
       
   915 	CleanupStack::PopAndDestroy(arr);
       
   916 	}
       
   917 
       
   918 
       
   919 // ----------------------------------------------------------------------------
       
   920 // CAspProfileDialog::AddItemL
       
   921 // 
       
   922 // ----------------------------------------------------------------------------
       
   923 //
       
   924 void CAspProfileDialog::AddItemL(TInt aItemId, CDesCArray* aHeaders)
       
   925 	{
       
   926     CAspListItemData* item = CAspListItemData::NewLC();
       
   927 	item->SetHeaderL((*aHeaders)[aItemId]);
       
   928 	item->iItemId = aItemId;
       
   929 	iSettingList->AppendL(item);
       
   930 	CleanupStack::Pop(item);
       
   931 	}
       
   932 
       
   933 
       
   934 // ----------------------------------------------------------------------------
       
   935 // CAspProfileDialog::AddItemL
       
   936 // 
       
   937 // ----------------------------------------------------------------------------
       
   938 //
       
   939 void CAspProfileDialog::AddItemL(TInt aItemId, TInt aResourceId)
       
   940 	{
       
   941     CAspListItemData* item = CAspListItemData::NewLC();
       
   942 	item->SetHeaderL(aResourceId);
       
   943 	item->iItemId = aItemId;
       
   944 	iSettingList->AppendL(item);
       
   945 	CleanupStack::Pop(item);
       
   946 	}
       
   947 
       
   948 
       
   949 // ----------------------------------------------------------------------------
       
   950 // CAspProfileDialog::AddContentItemsL
       
   951 // 
       
   952 // ----------------------------------------------------------------------------
       
   953 //
       
   954 void CAspProfileDialog::AddContentItemsL()
       
   955 	{
       
   956    	TInt count = iContentList->ProviderCount();
       
   957 
       
   958 	for (TInt i=0; i<count; i++)
       
   959 		{
       
   960 		TAspProviderItem& providerItem = iContentList->ProviderItem(i);
       
   961 		TInt appId = TUtil::AppIdFromProviderId(providerItem.iDataProviderId);
       
   962 		if (iApplicationId != EApplicationIdSync && iApplicationId != appId)
       
   963 			{
       
   964 			continue;
       
   965 			}
       
   966 		
       
   967         // In Phonebooks synchronization settings, remove another provider from
       
   968         //  end of settings item list (unless platform's contacts adapter is
       
   969         //  is defined as operator specific adapter and thus there is no dedicated
       
   970         //  operator specific adapter)
       
   971         if (appId == EApplicationIdContact)
       
   972             {
       
   973             TInt operatorUid = CAspProfile::OperatorAdapterUidL();
       
   974             if ( operatorUid != KUidNSmlAdapterContact.iUid &&
       
   975                 operatorUid != 0 )
       
   976                 {
       
   977                 // Operator profile: do not display s60 contacts adapter
       
   978                 if (CAspProfile::IsOperatorProfileL(iProfile))
       
   979                     {
       
   980                     if (operatorUid != providerItem.iDataProviderId)
       
   981                         {
       
   982                         continue;   
       
   983                         }
       
   984                     }
       
   985                 // Non-operator profile: Do not display operator adapter
       
   986                 else if (operatorUid == providerItem.iDataProviderId)
       
   987                     {
       
   988                     continue;                    
       
   989                     }                    
       
   990                 }
       
   991             }
       
   992 
       
   993 		HBufC* firstLine = CAspResHandler::GetContentSettingLC(
       
   994 		                                   providerItem.iDataProviderId,
       
   995 		                                   providerItem.iDisplayName);
       
   996 		
       
   997 	    CAspListItemData* item = CAspListItemData::NewLC();
       
   998     
       
   999     	item->SetHeaderL(firstLine->Des());
       
  1000 	    item->iItemId = EAspSyncContent;
       
  1001 	    item->iItemType = CAspListItemData::ETypeSyncContent;
       
  1002 	    item->iNumberData = providerItem.iDataProviderId;
       
  1003 	    iSettingList->AppendL(item);
       
  1004 	    CleanupStack::Pop(item);
       
  1005 	    
       
  1006 	    CleanupStack::PopAndDestroy(firstLine);
       
  1007     	}
       
  1008 	}
       
  1009 
       
  1010 
       
  1011 // ----------------------------------------------------------------------------
       
  1012 // CAspProfileDialog::UpdateListBoxL
       
  1013 // 
       
  1014 // Add settings headers into listbox.
       
  1015 // ----------------------------------------------------------------------------
       
  1016 //
       
  1017 void CAspProfileDialog::UpdateListBoxL(CEikTextListBox* aListBox,
       
  1018                                        CAspSettingList* aItemList)
       
  1019 	{
       
  1020 	CDesCArray* arr = (CDesCArray*)aListBox->Model()->ItemTextArray();
       
  1021 	arr->Reset();
       
  1022 
       
  1023 	TInt count = aItemList->Count();
       
  1024 	for (TInt i=0; i<count; i++ )
       
  1025 		{	
       
  1026 		CAspListItemData* item = (*aItemList)[i];
       
  1027 		TInt id = item->iItemId;
       
  1028 		
       
  1029 		TBool convert = ETrue;
       
  1030 	   TBool isPCSuite=CAspProfile::IsPCSuiteProfile(iProfile);
       
  1031        TBool readOnly = iProfile->DeleteAllowed();
       
  1032        if(isPCSuite && !readOnly||iSettingEnforcement)
       
  1033         {
       
  1034                 if(id==EAspAccessPoint || id==EAspSyncDirection ||id==EAspConnType)
       
  1035         	       convert = EFalse;//no number conversion
       
  1036         }
       
  1037        if(!isPCSuite &&!readOnly)
       
  1038        {
       
  1039                 if(id==EAspAccessPoint ||id==EAspConnType)
       
  1040         	       convert = EFalse;//no number conversion
       
  1041        }	
       
  1042 		if (id == EAspServerId || id == EAspHostAddress ||
       
  1043 	       id == EAspPort || id == EAspUsername || id == EAspHttpsUsername||iSettingEnforcement)
       
  1044 			{
       
  1045 			convert = EFalse; // no number conversion
       
  1046 			}
       
  1047 
       
  1048 		if (item->iHidden != EVisibilityHidden)
       
  1049 			{
       
  1050 			HBufC* hBuf = item->ListItemTextL(convert);
       
  1051 			CleanupStack::PushL(hBuf);
       
  1052 			
       
  1053 			arr->AppendL(hBuf->Des());
       
  1054 			
       
  1055 			// store listbox index (from zero up) into setting item 
       
  1056 			item->iIndex = arr->Count() - 1;
       
  1057 
       
  1058 			CleanupStack::PopAndDestroy(hBuf);
       
  1059 			}
       
  1060 		else
       
  1061 			{
       
  1062 			item->iIndex = KErrNotFound;
       
  1063 			}
       
  1064 		}
       
  1065 
       
  1066 	ListBox()->HandleItemAdditionL();
       
  1067 	}
       
  1068 
       
  1069 
       
  1070 // -----------------------------------------------------------------------------
       
  1071 // CAspProfileDialog::SetVisibilityL
       
  1072 // 
       
  1073 // -----------------------------------------------------------------------------
       
  1074 //
       
  1075 void CAspProfileDialog::SetVisibilityL()
       
  1076 	{
       
  1077     TBool isPCSuite = CAspProfile::IsPCSuiteProfile(iProfile);
       
  1078     
       
  1079     TBool readOnly = iProfile->DeleteAllowed();
       
  1080 	
       
  1081 	if (Item(EAspProtocolVersion)->iNumberData == EAspProtocol_1_1)
       
  1082 		{
       
  1083 		Item(EAspServerId)->iHidden = EVisibilityHidden;
       
  1084 		}
       
  1085 	else if (isPCSuite || !readOnly)
       
  1086 		{
       
  1087 		Item(EAspServerId)->iHidden = EVisibilityReadOnly;
       
  1088 		}
       
  1089 	else
       
  1090 		{
       
  1091 		Item(EAspServerId)->iHidden = EVisibilityNormal;
       
  1092 		}
       
  1093 	
       
  1094 	
       
  1095 	if (isPCSuite || !readOnly)
       
  1096 		{
       
  1097 		Item(EAspConnType)->iHidden = EVisibilityReadOnly;
       
  1098 		}
       
  1099 	else
       
  1100 		{
       
  1101 		Item(EAspConnType)->iHidden = EVisibilityNormal;
       
  1102 		}
       
  1103 
       
  1104 	if (isPCSuite || !readOnly)
       
  1105 		{
       
  1106 		Item(EAspHostAddress)->iHidden = EVisibilityReadOnly;
       
  1107 		}
       
  1108 	else
       
  1109 		{
       
  1110 		Item(EAspHostAddress)->iHidden = EVisibilityNormal;
       
  1111 		}
       
  1112 		
       
  1113 	if(isPCSuite)
       
  1114 	{
       
  1115 		Item(EAspSyncDirection)->iHidden = EVisibilityReadOnly;
       
  1116 	}
       
  1117 	else
       
  1118 	{
       
  1119 		Item(EAspSyncDirection)->iHidden = EVisibilityNormal;
       
  1120 	}
       
  1121     
       
  1122 		
       
  1123 
       
  1124 	if (iBearerHandler->SupportedBearerCount() == 1)
       
  1125 		{
       
  1126 		Item(EAspConnType)->iHidden = EVisibilityReadOnly;
       
  1127 		}
       
  1128 	
       
  1129     Item(EAspUsername)->iHidden = EVisibilityNormal;
       
  1130 	Item(EAspPassword)->iHidden = EVisibilityNormal;
       
  1131 
       
  1132 	if (Item(EAspConnType)->iNumberData != EAspBearerInternet)
       
  1133 		{
       
  1134 		Item(EAspAccessPoint)->iHidden = EVisibilityHidden;
       
  1135 		Item(EAspPort)->iHidden = EVisibilityHidden;
       
  1136 		Item(EAspHttpsUsername)->iHidden = EVisibilityHidden;
       
  1137 		Item(EAspHttpsPassword)->iHidden = EVisibilityHidden;
       
  1138     	}
       
  1139 	else
       
  1140 		{
       
  1141 		Item(EAspAccessPoint)->iHidden = EVisibilityNormal;
       
  1142 		Item(EAspPort)->iHidden = EVisibilityNormal;
       
  1143 		Item(EAspHttpsUsername)->iHidden = EVisibilityNormal;
       
  1144 		Item(EAspHttpsPassword)->iHidden = EVisibilityNormal;
       
  1145 		}
       
  1146 		
       
  1147 #ifdef __SYNCML_DS_ALERT
       
  1148     Item(EAspServerAlert)->iHidden = EVisibilityNormal;
       
  1149 #endif
       
  1150 	
       
  1151     if (iEditMode == EDialogModeReadOnly || 
       
  1152         iEditMode == EDialogModeSettingEnforcement ||
       
  1153         iProfile->IsReadOnlyOperatorProfileL() )
       
  1154     	{
       
  1155     	SetAllReadOnly();
       
  1156     	}
       
  1157 	}
       
  1158 
       
  1159 
       
  1160 // -----------------------------------------------------------------------------
       
  1161 // CAspContentDialog::SetAllReadOnly
       
  1162 // 
       
  1163 // -----------------------------------------------------------------------------
       
  1164 //
       
  1165 void CAspProfileDialog::SetAllReadOnly()
       
  1166 	{
       
  1167 	TInt count = iSettingList->Count();
       
  1168 
       
  1169 	for (TInt i=0; i<count; i++ )
       
  1170 		{
       
  1171 		CAspListItemData* item = (*iSettingList)[i];
       
  1172 		if (item->iHidden != EVisibilityHidden)
       
  1173 			{
       
  1174 			item->iHidden = EVisibilityReadOnly;
       
  1175 			}
       
  1176 		}
       
  1177 	}
       
  1178 
       
  1179 
       
  1180 // -----------------------------------------------------------------------------
       
  1181 // CAspProfileDialog::InitSettingItemL
       
  1182 // 
       
  1183 // Constructs CAspListItemData for one connection setting.
       
  1184 // -----------------------------------------------------------------------------
       
  1185 //
       
  1186 void CAspProfileDialog::InitSettingItemL(CAspListItemData* aItem)
       
  1187 	{
       
  1188 	__ASSERT_ALWAYS(aItem, TUtil::Panic(KErrGeneral));	
       
  1189 	
       
  1190 	iBuf = KNullDesC;  // reset common buffer
       
  1191 	
       
  1192 	switch (aItem->iItemId)
       
  1193 		{
       
  1194 		case EAspProfileName:
       
  1195 			{
       
  1196 			iProfile->GetName(iBuf);
       
  1197 			aItem->SetValueL(iBuf);
       
  1198 			aItem->SetDisplayValueL(R_ASP_MUST_BE_DEFINED);
       
  1199 			
       
  1200 			aItem->iMaxLength = KAspMaxProfileNameLength;
       
  1201 			aItem->iLatinInput = EFalse;
       
  1202 			aItem->iItemType = CAspListItemData::ETypeText;
       
  1203 			aItem->iMandatory = ETrue;
       
  1204 			break;
       
  1205 			}
       
  1206 
       
  1207 		case EAspProtocolVersion:
       
  1208 			{
       
  1209 			CDesCArray* arr = iResHandler->ReadDesArrayLC(R_ASP_PROTOCOL_VERSION);
       
  1210     
       
  1211     		aItem->iNumberData = iProfile->ProtocolVersion();
       
  1212 			aItem->SetValueL((*arr)[aItem->iNumberData]);
       
  1213 				
       
  1214 			aItem->iResource = R_ASP_PROTOCOL_VERSION;
       
  1215 			aItem->iItemType = CAspListItemData::ETypeProtocolList;
       
  1216 			
       
  1217 			CleanupStack::PopAndDestroy(arr);
       
  1218 			break;
       
  1219 			}
       
  1220 
       
  1221 		case EAspServerId:
       
  1222 			{
       
  1223 			iProfile->GetServerId(iBuf);
       
  1224 			aItem->SetValueL(iBuf);
       
  1225 			if(TDialogUtil::IsPCSuiteDesC(iBuf))
       
  1226 			{
       
  1227 				aItem->SetDisplayValueL(R_ASP_PC_SUITE_PROFILE);	
       
  1228 			}
       
  1229 			else
       
  1230 			{
       
  1231 			aItem->SetDisplayValueL(R_ASP_SETTING_VALUE_NONE);
       
  1232 			}
       
  1233 
       
  1234 			aItem->iMaxLength = KAspMaxServerIdLength;
       
  1235 			aItem->iLatinInput = ETrue;
       
  1236 			aItem->iItemType = CAspListItemData::ETypeText;
       
  1237 			
       
  1238 			TUtil::StrCopy(iOldServerId, iBuf);
       
  1239 			break;
       
  1240 			}
       
  1241 		
       
  1242 		
       
  1243 		case EAspConnType:
       
  1244 			{
       
  1245 			aItem->iNumberData = iProfile->BearerType();
       
  1246 
       
  1247 			if (!iBearerHandler->IsSupported(aItem->iNumberData))
       
  1248 				{
       
  1249 				aItem->iNumberData = iBearerHandler->DefaultBearer();
       
  1250 				}
       
  1251 
       
  1252  			iBearerHandler->GetBearerName(iBuf, aItem->iNumberData);
       
  1253 			aItem->SetValueL(iBuf);
       
  1254 			aItem->iItemType = CAspListItemData::ETypeBearerList;
       
  1255 
       
  1256 			break;
       
  1257 			}
       
  1258 		
       
  1259 		case EAspAccessPoint:
       
  1260 			{
       
  1261 			TAspAccessPointItem item;
       
  1262 	        item.iUid = iProfile->AccessPointL();
       
  1263 	        TInt ret = iApHandler->GetInternetApInfo(item);
       
  1264 	        if (ret == KErrNone)
       
  1265 	        	{
       
  1266 	        	aItem->iNumberData = item.iUid;
       
  1267 	        	aItem->SetValueL(item.iName);
       
  1268 	        	aItem->iResource = R_ASP_NETWORK_CONNECTION;
       
  1269 	        	}
       
  1270 	        else
       
  1271 	        	{
       
  1272 	        	aItem->iNumberData = CAspAccessPointHandler::KDefaultConnection;	
       
  1273 	        	aItem->SetDisplayValueL(R_ASP_DEFAULT_CONNECTION);
       
  1274 	        	aItem->iResource = R_ASP_NETWORK_CONNECTION;
       
  1275 	        	}
       
  1276 	        aItem->iItemType = CAspListItemData::ETypeInternetAccessPoint;
       
  1277 			break;
       
  1278 			}
       
  1279 		
       
  1280 		case EAspHostAddress:
       
  1281 			{
       
  1282 			iProfile->GetHostAddress(iBuf, aItem->iNumberData);
       
  1283 			aItem->SetValueL(iBuf);
       
  1284 			if(TDialogUtil::IsPCSuiteDesC(iBuf))
       
  1285 			{
       
  1286 				aItem->SetDisplayValueL(R_ASP_PC_SUITE_PROFILE);	
       
  1287 	 		}
       
  1288 	        else
       
  1289 	        {
       
  1290 	        	aItem->SetDisplayValueL(R_ASP_MUST_BE_DEFINED);
       
  1291 	        }
       
  1292 			
       
  1293 			aItem->iMaxLength = KAspMaxURILength;
       
  1294 			aItem->iLatinInput = ETrue;
       
  1295 			aItem->iItemType = CAspListItemData::ETypeHostAddress;
       
  1296 			aItem->iMandatory = ETrue;
       
  1297 			
       
  1298 			break;
       
  1299 			}
       
  1300 		    
       
  1301 		case EAspPort:
       
  1302 			{
       
  1303 			iProfile->GetHostAddress(iBuf, aItem->iNumberData);
       
  1304 			if ( aItem->iNumberData > TURIParser::EMaxURIPortNumber || aItem->iNumberData < TURIParser::EMinURIPortNumber)
       
  1305   					 	aItem->iNumberData = TURIParser::EDefaultHttpPort;	
       
  1306 			aItem->SetValueL(aItem->iNumberData);
       
  1307 			
       
  1308 			aItem->iMaxLength = KBufSize16;
       
  1309 			aItem->iMaxValue = TURIParser::EMaxURIPortNumber;
       
  1310 			aItem->iMinValue = TURIParser::EMinURIPortNumber;
       
  1311 			aItem->iItemType = CAspListItemData::ETypeNumber;
       
  1312 			aItem->iLatinInput = ETrue;
       
  1313 			break;
       
  1314 			}
       
  1315 		    
       
  1316 		case EAspUsername:
       
  1317 			{
       
  1318 			iProfile->GetUserName(iBuf);
       
  1319 			aItem->SetValueL(iBuf);
       
  1320 			aItem->SetDisplayValueL(R_ASP_SETTING_VALUE_NONE);
       
  1321 
       
  1322 			aItem->iMaxLength = KAspMaxUsernameLength;
       
  1323 			aItem->iLatinInput = ETrue;
       
  1324 			aItem->iItemType = CAspListItemData::ETypeText;
       
  1325 			break;
       
  1326 			}
       
  1327 		    
       
  1328 		case EAspPassword:
       
  1329 			{
       
  1330 			iProfile->GetPassword(iBuf);
       
  1331 			aItem->SetValueL(iBuf);
       
  1332 			TUtil::Fill(iBuf, KSecretEditorMask, KSecretEditorMaskLength);
       
  1333 			aItem->SetDisplayValueL(iBuf);
       
  1334 
       
  1335 			aItem->iMaxLength = KAspMaxPasswordLength;
       
  1336 			aItem->iItemType = CAspListItemData::ETypeSecret;
       
  1337 			break;
       
  1338 			}
       
  1339 		
       
  1340 		case EAspHttpsUsername:
       
  1341 			{
       
  1342 			iProfile->GetHttpUserNameL(iBuf);
       
  1343 			aItem->SetValueL(iBuf);
       
  1344 			aItem->SetDisplayValueL(R_ASP_SETTING_VALUE_NONE);
       
  1345 
       
  1346 			aItem->iMaxLength = KAspMaxUsernameLength;
       
  1347 			aItem->iLatinInput = ETrue;
       
  1348 			aItem->iItemType = CAspListItemData::ETypeText;
       
  1349 			break;
       
  1350 			}
       
  1351 
       
  1352 		case EAspHttpsPassword:
       
  1353 			{
       
  1354 			iProfile->GetHttpPasswordL(iBuf);
       
  1355 			aItem->SetValueL(iBuf);
       
  1356 			TUtil::Fill(iBuf, KSecretEditorMask, KSecretEditorMaskLength);
       
  1357 			aItem->SetDisplayValueL(iBuf);
       
  1358 
       
  1359 			aItem->iMaxLength = KAspMaxPasswordLength;
       
  1360 			aItem->iItemType = CAspListItemData::ETypeSecret;
       
  1361 			break;
       
  1362 			}
       
  1363 		
       
  1364 		case EAspServerAlert:
       
  1365 			{
       
  1366 			CDesCArray* arr = iResHandler->ReadDesArrayLC(R_ASP_SERVER_ALERT_TYPE);
       
  1367 
       
  1368             aItem->iNumberData = iProfile->SASyncState();
       
  1369 			aItem->iResource = R_ASP_SERVER_ALERT_TYPE;
       
  1370 			aItem->SetValueL((*arr)[aItem->iNumberData]);
       
  1371 			aItem->iItemType = CAspListItemData::ETypeList;
       
  1372 			
       
  1373 			CleanupStack::PopAndDestroy(arr);
       
  1374 			break;
       
  1375 			}
       
  1376 			
       
  1377 		case EAspSyncDirection:
       
  1378 			{
       
  1379     		CDesCArray* arr;
       
  1380     		TBool isPCSuite = CAspProfile::IsPCSuiteProfile(iProfile);
       
  1381     		if(isPCSuite)
       
  1382 			 {
       
  1383 			 	
       
  1384 			    arr = iResHandler->ReadDesArrayLC(R_ASP_SYNC_PCSUITE_TYPE);
       
  1385     			aItem->iResource = R_ASP_SYNC_PCSUITE_TYPE;
       
  1386     			   		
       
  1387 			 }
       
  1388 			 else
       
  1389 			 {
       
  1390 			 	arr = iResHandler->ReadDesArrayLC(R_ASP_SYNC_TYPE);
       
  1391     			aItem->iResource =R_ASP_SYNC_TYPE ;
       
  1392     			   		
       
  1393 			 }
       
  1394     	
       
  1395     		aItem->iNumberData = iContentList->SyncDirection();
       
  1396 			aItem->SetValueL((*arr)[aItem->iNumberData]);
       
  1397 			aItem->iItemType = CAspListItemData::ETypeList;
       
  1398     		
       
  1399     		CleanupStack::PopAndDestroy(arr);
       
  1400 			break;
       
  1401 			}
       
  1402 			
       
  1403         
       
  1404         case EAspSyncContent:
       
  1405         	{
       
  1406         	break;
       
  1407         	}
       
  1408         	
       
  1409         default:
       
  1410            	__ASSERT_DEBUG(EFalse, TUtil::Panic(KErrGeneral));
       
  1411 			break;
       
  1412 		
       
  1413 		}
       
  1414 	}
       
  1415 
       
  1416 
       
  1417 // ----------------------------------------------------------------------------
       
  1418 // CAspProfileDialog::SaveSettingsL
       
  1419 // 
       
  1420 // ----------------------------------------------------------------------------
       
  1421 //
       
  1422 void CAspProfileDialog::SaveSettingsL()
       
  1423 	{
       
  1424     if (iEditMode == EDialogModeReadOnly || 
       
  1425         iEditMode == EDialogModeSettingEnforcement)
       
  1426     	{
       
  1427     	return;
       
  1428     	}
       
  1429 
       
  1430    	iBuf = KNullDesC;  // reset common buffer
       
  1431    	
       
  1432 	TInt count = iSettingList->Count();
       
  1433 	
       
  1434 	for (TInt i=0; i<count; i++)
       
  1435 		{
       
  1436 		CAspListItemData* item = (*iSettingList)[i];
       
  1437 		
       
  1438 		switch (item->iItemId)
       
  1439 			{
       
  1440 			case EAspProfileName:
       
  1441 			    iProfile->SetNameL(item->Value());
       
  1442 			    break;
       
  1443 
       
  1444 			case EAspProtocolVersion:
       
  1445 				iProfile->SetProtocolVersionL(item->iNumberData);
       
  1446 			    break;
       
  1447 
       
  1448 			case EAspServerId:
       
  1449 			    iProfile->SetServerIdL(item->Value());
       
  1450 			    break;
       
  1451 
       
  1452 			case EAspConnType:
       
  1453 				iProfile->SetBearerTypeL(item->iNumberData);
       
  1454 			    break;
       
  1455 
       
  1456 			case EAspAccessPoint:
       
  1457 				iProfile->SetAccessPointL(item->iNumberData);
       
  1458 			    break;
       
  1459 
       
  1460 			case EAspHostAddress:
       
  1461 				{
       
  1462 				iBuf = item->Value();
       
  1463 				TURIParser parser(iBuf);
       
  1464 				TInt portNumber = parser.Port();
       
  1465 	            if (!parser.IsValidPort(portNumber))
       
  1466 		            {
       
  1467 		            	if ( Item(EAspPort)->iNumberData > TURIParser::EMaxURIPortNumber || Item(EAspPort)->iNumberData < TURIParser::EMinURIPortNumber)
       
  1468   							    Item(EAspPort)->iNumberData = TURIParser::EDefaultHttpPort;	
       
  1469 				 		portNumber = Item(EAspPort)->iNumberData;    	
       
  1470 		            }
       
  1471 
       
  1472 				iProfile->SetHostAddressL(iBuf, portNumber);
       
  1473 				break;
       
  1474 				}
       
  1475 
       
  1476 			case EAspPort:
       
  1477 				break;  // port is included in host address
       
  1478 
       
  1479 			case EAspUsername:
       
  1480 				iProfile->SetUserNameL(item->Value());
       
  1481 			    break;
       
  1482 			
       
  1483 			case EAspPassword:
       
  1484 			    iProfile->SetPasswordL(item->Value());
       
  1485 			    break;
       
  1486 
       
  1487 			case EAspServerAlert:
       
  1488 				{
       
  1489 				iProfile->SetSASyncStateL(item->iNumberData);
       
  1490 			    break;
       
  1491 				}
       
  1492 
       
  1493 			case EAspHttpsUsername:
       
  1494 			    iProfile->SetHttpUserNameL(item->Value());
       
  1495 			    break;
       
  1496 
       
  1497 			case EAspHttpsPassword:
       
  1498 			    iProfile->SetHttpPasswordL(item->Value());
       
  1499 			    break;
       
  1500 			    
       
  1501 			case EAspSyncDirection:
       
  1502 				iContentList->ModifyTaskDirectionsL(item->iNumberData);
       
  1503 				break;
       
  1504 			    
       
  1505 			}
       
  1506 
       
  1507 		}
       
  1508 
       
  1509 	iProfile->Save();
       
  1510 	iContentList->UpdateLocalDatabaseL();
       
  1511 #ifdef RD_DSUI_TIMEDSYNC
       
  1512 	CheckAutoSyncSetttigsL();
       
  1513 #endif
       
  1514 	}
       
  1515 	
       
  1516 	
       
  1517 //------------------------------------------------------------------------------
       
  1518 // CAspProfileDialog::EditSettingItemL
       
  1519 //
       
  1520 // Calls setting editing functions. 
       
  1521 //------------------------------------------------------------------------------
       
  1522 //
       
  1523 TBool CAspProfileDialog::EditSettingItemL(CAspListItemData& aItem)
       
  1524 	{
       
  1525 	TInt ret = EFalse;
       
  1526 
       
  1527 #ifdef RD_DSUI_TIMEDSYNC 
       
  1528 	CAspSchedule* schedule = CAspSchedule::NewLC();
       
  1529 	if (schedule->IsAutoSyncEnabled())
       
  1530 		{
       
  1531 		TInt profileId = schedule->ProfileId();
       
  1532 		if (profileId == iProfile->ProfileId())
       
  1533 			{
       
  1534 			TDialogUtil::ShowInformationQueryL(R_ASP_NOTE_MODIFY_AUTO_SYNC_SETTINGS);
       
  1535 			}
       
  1536 		}
       
  1537     CleanupStack::PopAndDestroy(schedule);
       
  1538 #endif
       
  1539 
       
  1540 	switch (aItem.iItemType)
       
  1541 		{
       
  1542 		case CAspListItemData::ETypeInternetAccessPoint:
       
  1543 		    ret = EditSettingItemAccessPointL(aItem);
       
  1544 		    break;
       
  1545 			
       
  1546 		case CAspListItemData::ETypeText:
       
  1547 			ret = EditSettingItemTextL(aItem);
       
  1548 		    break;
       
  1549 
       
  1550 		case CAspListItemData::ETypeSecret:
       
  1551 			ret = EditSettingItemSecretL(aItem);
       
  1552 		    break;
       
  1553 
       
  1554 		case CAspListItemData::ETypeNumber:
       
  1555 			ret = EditSettingItemNumberL(aItem);
       
  1556 		    break;
       
  1557 
       
  1558 		case CAspListItemData::ETypeList:
       
  1559 			ret = EditSettingItemListL(aItem);
       
  1560 		    break;
       
  1561 		
       
  1562 		case CAspListItemData::ETypeBearerList:
       
  1563 			ret = EditSettingItemBearerListL(aItem);
       
  1564 		    break;
       
  1565 		    
       
  1566 		case CAspListItemData::ETypeProtocolList:
       
  1567 			ret = EditSettingItemProtocolListL(aItem);
       
  1568 		    break;
       
  1569 
       
  1570 		case CAspListItemData::ETypeListYesNo:
       
  1571 			ret = EditSettingItemYesNoL(aItem);
       
  1572 		    break;
       
  1573 
       
  1574 		case CAspListItemData::ETypeHostAddress:
       
  1575 			ret = EditSettingItemHostAddressL(aItem);
       
  1576 			break;
       
  1577 
       
  1578 		case CAspListItemData::ETypeSyncContent:
       
  1579 			ret = EditSettingItemSyncContentL(aItem);
       
  1580 			break;
       
  1581 
       
  1582 		default:
       
  1583 		    break;
       
  1584 		}
       
  1585 	
       
  1586 	return ret;
       
  1587 	}
       
  1588 
       
  1589 
       
  1590 //------------------------------------------------------------------------------
       
  1591 // CAspProfileDialog::EditSettingItemYesNoL
       
  1592 //
       
  1593 // Change Yes/No value without showing radio button editor.
       
  1594 //------------------------------------------------------------------------------
       
  1595 //
       
  1596 TBool CAspProfileDialog::EditSettingItemYesNoL(CAspListItemData& aItem)
       
  1597 	{
       
  1598 	CDesCArray* arr = iResHandler->ReadDesArrayLC(aItem.iResource);
       
  1599 	
       
  1600 	if (aItem.iNumberData == EAspSettingDisabled)
       
  1601 		{
       
  1602 		aItem.iNumberData = EAspSettingEnabled;
       
  1603 		}
       
  1604 	else
       
  1605 		{
       
  1606 		aItem.iNumberData = EAspSettingDisabled;
       
  1607 		}
       
  1608 	
       
  1609 	
       
  1610 	// store localized setting text (Yes/No)
       
  1611 	aItem.SetValueL( (*arr)[aItem.iNumberData] );
       
  1612 
       
  1613 	CleanupStack::PopAndDestroy(arr);
       
  1614 	return ETrue;
       
  1615 	}
       
  1616 
       
  1617 
       
  1618 //------------------------------------------------------------------------------
       
  1619 // CAspProfileDialog::EditSettingItemNumberL
       
  1620 //
       
  1621 //------------------------------------------------------------------------------
       
  1622 //
       
  1623 TBool CAspProfileDialog::EditSettingItemNumberL(CAspListItemData& aItem)
       
  1624 	{
       
  1625 	TBool ret = TDialogUtil::ShowIntegerEditorL(aItem.iNumberData, aItem.Header(), 
       
  1626 	                         aItem.iMinValue, aItem.iMaxValue, aItem.iLatinInput);
       
  1627 
       
  1628 	if (ret)
       
  1629 		{
       
  1630 		aItem.SetValueL(aItem.iNumberData);
       
  1631 		}
       
  1632 
       
  1633 	return ret;
       
  1634 	}
       
  1635 
       
  1636 
       
  1637 //------------------------------------------------------------------------------
       
  1638 // CAspProfileDialog::EditSettingItemSecretL
       
  1639 //
       
  1640 //------------------------------------------------------------------------------
       
  1641 //
       
  1642 TBool CAspProfileDialog::EditSettingItemSecretL(CAspListItemData& aItem)
       
  1643 	{
       
  1644 	TBuf<KBufSize64> newPassword;
       
  1645 	newPassword = aItem.Value();
       
  1646 	
       
  1647 	
       
  1648 	CAspAlphaPasswordSettingPageEditor* pwd = new (ELeave) CAspAlphaPasswordSettingPageEditor(
       
  1649 		                                R_ASP_SETTING_PASSWORD, newPassword, aItem.Value());
       
  1650 	
       
  1651 	CleanupStack::PushL(pwd);
       
  1652 	pwd->SetSettingTextL(aItem.Header()); 
       
  1653 	pwd->ConstructL();
       
  1654 	pwd->AlphaPasswordEditor()->SetMaxLength(aItem.iMaxLength);
       
  1655 	//pwd->AlphaPasswordEditor()->RevealSecretText(ETrue);  // pasi
       
  1656 	CleanupStack::Pop(pwd);
       
  1657 
       
  1658 	if (pwd->ExecuteLD(CAknSettingPage::EUpdateWhenChanged))
       
  1659 		{
       
  1660 		aItem.SetValueL(newPassword);
       
  1661 		return ETrue;
       
  1662 		}
       
  1663 	
       
  1664 	return EFalse;
       
  1665 	}
       
  1666 
       
  1667 
       
  1668 //------------------------------------------------------------------------------
       
  1669 // CAspProfileDialog::EditSettingItemTextL
       
  1670 //
       
  1671 // Edit text setting item.
       
  1672 //------------------------------------------------------------------------------
       
  1673 //
       
  1674 TBool CAspProfileDialog::EditSettingItemTextL(CAspListItemData& aItem)
       
  1675 	{
       
  1676 	TUtil::StrCopy(iBuf, aItem.Value());
       
  1677 	
       
  1678 	TInt len = iBuf.Length();
       
  1679 	if (len > aItem.iMaxLength)
       
  1680 		{
       
  1681 		iBuf.SetLength(aItem.iMaxLength);
       
  1682 		}
       
  1683 	
       
  1684     TBool ret = TDialogUtil::ShowTextEditorL(iBuf, aItem.Header(), 
       
  1685                              aItem.iMandatory, aItem.iLatinInput, aItem.iMaxLength);
       
  1686    	if (ret)
       
  1687 		{
       
  1688 		aItem.SetValueL(iBuf);
       
  1689 		}
       
  1690 		
       
  1691 	return ret;
       
  1692 	}
       
  1693 
       
  1694 
       
  1695 //------------------------------------------------------------------------------
       
  1696 // CAspProfileDialog::EditSettingItemHostAddressL
       
  1697 //
       
  1698 //------------------------------------------------------------------------------
       
  1699 //
       
  1700 TBool CAspProfileDialog::EditSettingItemHostAddressL(CAspListItemData& aItem)
       
  1701 	{
       
  1702 	_LIT(KHttpHeader, "http://");
       
  1703 	
       
  1704 	TBool httpHeaderUsed = EFalse;
       
  1705 	TInt bearer = Item(EAspConnType)->iNumberData;
       
  1706 	HBufC* hBuf = HBufC::NewLC(KBufSize255);
       
  1707 	TPtr ptr = hBuf->Des();
       
  1708 	TUtil::StrCopy(ptr, aItem.Value());
       
  1709 	if (TUtil::IsEmpty(aItem.Value()) && bearer == EAspBearerInternet)
       
  1710 		{
       
  1711 		aItem.SetValueL(KHttpHeader);
       
  1712 		httpHeaderUsed = ETrue;
       
  1713 		}
       
  1714 		
       
  1715 	TBool ret = EFalse;
       
  1716 	for(;;)
       
  1717 	{
       
  1718 	ret = EditSettingItemTextL(aItem);
       
  1719 	
       
  1720 	if (httpHeaderUsed && (aItem.Value().Compare(KHttpHeader) == 0))
       
  1721 		{
       
  1722 		aItem.SetValueL(KNullDesC);
       
  1723 		}
       
  1724 	
       
  1725 	
       
  1726 	if (ret)
       
  1727 		{
       
  1728 		if(bearer == EAspBearerInternet)
       
  1729 		{
       
  1730 			if (!TURIParser::IsValidUri(aItem.Value()))
       
  1731 			{			
       
  1732 			TDialogUtil::ShowInformationNoteL(R_ASP_LOG_ERR_URIINVALID);
       
  1733 			}
       
  1734 		else
       
  1735 			{
       
  1736 			TPtrC ptr = aItem.Value();
       
  1737 			TURIParser parser(ptr);
       
  1738 	        TInt portNumber = parser.Port();
       
  1739 	        if (parser.IsValidPort(portNumber))
       
  1740 		        {
       
  1741 		        Item(EAspPort)->iNumberData = portNumber;
       
  1742 		        Item(EAspPort)->SetValueL(portNumber);
       
  1743 		        }
       
  1744 		    break;    
       
  1745 			}	
       
  1746 		}
       
  1747 		else if(bearer == EAspBearerBlueTooth)
       
  1748 		{
       
  1749 			if (!TURIParser::IsValidBluetoothHostAddress(aItem.Value()))
       
  1750 		    {
       
  1751 		    TDialogUtil::ShowInformationNoteL(R_ASP_NOTE_INCORRECT_HOST_ADDRESS);
       
  1752 		   
       
  1753 		    }
       
  1754 		    else
       
  1755 		    {
       
  1756 		    	break;
       
  1757 		    }
       
  1758 			}
       
  1759 		}
       
  1760 	else if(!ret) 
       
  1761 		{
       
  1762 		aItem.SetValueL(ptr);
       
  1763 		break;	
       
  1764 		}
       
  1765 	else
       
  1766 		{
       
  1767 		 break;	
       
  1768 		}
       
  1769 	}
       
  1770 	CleanupStack::PopAndDestroy(); //hBuf
       
  1771 	return ret;
       
  1772 	}
       
  1773 
       
  1774 
       
  1775 //------------------------------------------------------------------------------
       
  1776 // CAspProfileDialog::EditSettingItemListL
       
  1777 //
       
  1778 //------------------------------------------------------------------------------
       
  1779 //
       
  1780 TBool CAspProfileDialog::EditSettingItemListL(CAspListItemData& aItem)
       
  1781 	{
       
  1782 	TInt curSelection = aItem.iNumberData;
       
  1783 	CDesCArray* arr = CAspResHandler::ReadDesArrayStaticLC(aItem.iResource);
       
  1784 	
       
  1785 	TBool ret = TDialogUtil::ShowListEditorL(arr, aItem.Header(), curSelection);
       
  1786 	if (ret)
       
  1787 		{
       
  1788 		aItem.iNumberData = curSelection; 
       
  1789 		aItem.SetValueL((*arr)[curSelection]);
       
  1790 		}
       
  1791 
       
  1792 	CleanupStack::PopAndDestroy(arr);
       
  1793 	return ret;
       
  1794 	}
       
  1795 
       
  1796 
       
  1797 //------------------------------------------------------------------------------
       
  1798 // CAspProfileDialog::EditSettingItemProtocolListL
       
  1799 //
       
  1800 //------------------------------------------------------------------------------
       
  1801 //
       
  1802 TBool CAspProfileDialog::EditSettingItemProtocolListL(CAspListItemData& aItem)
       
  1803 	{
       
  1804 #ifdef __SYNCML_DS_EMAIL   // KFeatureIdSyncMlDsEmail
       
  1805 	TInt oldSelection = aItem.iNumberData;
       
  1806 #endif
       
  1807 	
       
  1808 	TInt curSelection = aItem.iNumberData;
       
  1809 	CDesCArray* arr2 = iResHandler->ReadDesArrayLC(aItem.iResource);
       
  1810 	CDesCArray* arr = TUtil::NumberConversionLC(arr2);
       
  1811 	
       
  1812 	
       
  1813 	if (TDialogUtil::ShowListEditorL(arr, aItem.Header(), curSelection))
       
  1814 		{
       
  1815 		aItem.iNumberData = curSelection; 
       
  1816 		aItem.SetValueL((*arr)[curSelection]);
       
  1817 		
       
  1818 	    
       
  1819 #ifdef __SYNCML_DS_EMAIL   // KFeatureIdSyncMlDsEmail
       
  1820 
       
  1821 	    TBool emailSync = EFalse;
       
  1822 	    TInt id = iProfile->ApplicationId();
       
  1823 	    if (id == EApplicationIdSync || id == EApplicationIdEmail)
       
  1824 	    	{
       
  1825 	    	emailSync = ETrue;
       
  1826 	    	}
       
  1827 		
       
  1828 
       
  1829 #ifdef RD_DSUI_TIMEDSYNC
       
  1830 		if (curSelection == EAspProtocol_1_1 )
       
  1831 				{
       
  1832 				CAspSchedule* schedule = CAspSchedule::NewLC();
       
  1833 				TInt profileId = schedule->ProfileId();
       
  1834 				if (profileId == iProfile->ProfileId())
       
  1835 					{
       
  1836 					TInt selectedContentCnt = 0;
       
  1837 					TInt selectedContentIndex = 0;
       
  1838 					TInt emailIndex = iContentList->FindProviderIndex(KUidNSmlAdapterEMail.iUid);
       
  1839 					schedule->ContentSelectionInfo(selectedContentCnt, selectedContentIndex);
       
  1840 					if (selectedContentCnt == 1 && selectedContentIndex == emailIndex)
       
  1841 						{
       
  1842 						schedule->SetProfileId(KErrNotFound);
       
  1843 						schedule->SetContentEnabled(emailIndex, EFalse);
       
  1844 						schedule->SetSyncPeakSchedule(CAspSchedule::EIntervalManual);
       
  1845 						schedule->SetSyncOffPeakSchedule(CAspSchedule::EIntervalManual);
       
  1846 						schedule->SetSyncFrequency(CAspSchedule::EIntervalManual);
       
  1847 						schedule->UpdateSyncScheduleL();
       
  1848 						schedule->SaveL();
       
  1849 						}
       
  1850 					}
       
  1851 				CleanupStack::PopAndDestroy(schedule);
       
  1852 				}
       
  1853 #endif
       
  1854 		
       
  1855 #endif
       
  1856 		
       
  1857 		CleanupStack::PopAndDestroy(arr);
       
  1858 		CleanupStack::PopAndDestroy(arr2);
       
  1859 		return ETrue;
       
  1860 		}
       
  1861 
       
  1862 	CleanupStack::PopAndDestroy(arr);
       
  1863 	CleanupStack::PopAndDestroy(arr2);
       
  1864 	return EFalse;
       
  1865 	}
       
  1866 //------------------------------------------------------------------------------
       
  1867 // CAspProfileDialog::EditSettingItemAccessPointL
       
  1868 //
       
  1869 //------------------------------------------------------------------------------
       
  1870 //	
       
  1871 TBool CAspProfileDialog::EditSettingItemAccessPointL(CAspListItemData& aItem)
       
  1872 {
       
  1873 
       
  1874 	TBool ret;
       
  1875 	TInt selection = 0;
       
  1876 	TInt curSelection = aItem.iNumberData;
       
  1877 	CDesCArray* arr = CAspResHandler::ReadDesArrayStaticLC(aItem.iResource);
       
  1878 	if(curSelection < 0)
       
  1879 	{
       
  1880 		curSelection = 0;
       
  1881 	}
       
  1882 	else
       
  1883 	{
       
  1884 		curSelection = 1;
       
  1885 	}
       
  1886 	ret = TDialogUtil::ShowListEditorL(arr, aItem.Header(), curSelection);
       
  1887 	CleanupStack::PopAndDestroy(arr);
       
  1888 	if(!ret)
       
  1889 	{
       
  1890 		return EFalse;
       
  1891 	}
       
  1892 	if (curSelection == 0 )
       
  1893 		{
       
  1894 		aItem.iNumberData = CAspAccessPointHandler::KDefaultConnection;
       
  1895 		aItem.SetValueL(KNullDesC);
       
  1896 		aItem.SetDisplayValueL(R_ASP_DEFAULT_CONNECTION);
       
  1897 		selection = CAspAccessPointHandler::KDefaultConnection;
       
  1898 		}	
       
  1899 	if(selection == CAspAccessPointHandler::KDefaultConnection)
       
  1900 	{
       
  1901 	#ifdef RD_DSUI_TIMEDSYNC
       
  1902    	CAspSchedule* schedule = CAspSchedule::NewLC();
       
  1903 	TInt profileId = schedule->ProfileId();
       
  1904 	TInt enabled = schedule->IsAutoSyncEnabled();
       
  1905 	CleanupStack::PopAndDestroy(schedule);
       
  1906 	if(profileId == iProfile->ProfileId() && enabled)
       
  1907 		{
       
  1908 		TBool showQuery = ETrue;
       
  1909 			RCmManager cmmgr;
       
  1910 			cmmgr.OpenL();
       
  1911 			TCmDefConnValue defConnValue;
       
  1912 			cmmgr.ReadDefConnL(defConnValue);
       
  1913 			cmmgr.Close();
       
  1914 			if(defConnValue.iType == ECmDefConnDestination)
       
  1915 			{
       
  1916 				showQuery = EFalse;
       
  1917 			}
       
  1918 		if(showQuery)
       
  1919 		{
       
  1920 			HBufC* hBuf = CAspResHandler::ReadLC(R_ASP_QUERY_IAP_NO_ASK_ALWAYS);
       
  1921     		if (!TDialogUtil::ShowConfirmationQueryL(hBuf->Des()))
       
  1922 	 		{
       
  1923 	  	  		CleanupStack::PopAndDestroy(hBuf);
       
  1924 				return ETrue;// user selected "Always ask" option 
       
  1925     	}	
       
  1926 			CleanupStack::PopAndDestroy(hBuf);
       
  1927 		}
       
  1928 		else
       
  1929 		{
       
  1930 			return ETrue;
       
  1931 		}
       
  1932 			
       
  1933 		}
       
  1934 		else
       
  1935 		{
       
  1936 			return ETrue;
       
  1937 		}
       
  1938     	   	
       
  1939 	#else
       
  1940 		return ETrue;
       
  1941 	#endif
       
  1942 	}
       
  1943 	TAspAccessPointItem item;
       
  1944 	item.iUid2 = aItem.iNumberData;
       
  1945 	
       
  1946 	ret = iApHandler->ShowApSelectDialogL(item);
       
  1947 	
       
  1948 	if (ret == CAspAccessPointHandler::EAspDialogSelect)
       
  1949 		{
       
  1950 		aItem.iNumberData = item.iUid;
       
  1951 		aItem.SetValueL(item.iName);
       
  1952 		return ETrue;
       
  1953 		}
       
  1954 	else if (ret == CAspAccessPointHandler::EAspDialogExit)
       
  1955 		{
       
  1956 		ProcessCommandL(EAknCmdExit); // user has selected "Exit" from options menu
       
  1957 		}
       
  1958 	else
       
  1959 		{
       
  1960 		// user canceled ap selection
       
  1961 		return EFalse;
       
  1962 		}
       
  1963 		
       
  1964 	return EFalse;
       
  1965 }
       
  1966 
       
  1967 //------------------------------------------------------------------------------
       
  1968 // CAspProfileDialog::EditSettingItemBearerListL
       
  1969 //
       
  1970 //------------------------------------------------------------------------------
       
  1971 //
       
  1972 TBool CAspProfileDialog::EditSettingItemBearerListL(CAspListItemData& aItem)
       
  1973 	{
       
  1974 	CDesCArray* arr = iBearerHandler->BuildBearerListLC();
       
  1975 	if (arr->Count() == 0) 
       
  1976 		{
       
  1977 		User::Leave(KErrNotFound);
       
  1978 		}
       
  1979 
       
  1980 	TInt curSelection = iBearerHandler->ListIndexForBearer(aItem.iNumberData);
       
  1981 	if (curSelection == KErrNotFound)
       
  1982 		{
       
  1983 		User::Leave(KErrNotFound);
       
  1984 		}
       
  1985 
       
  1986 	if (TDialogUtil::ShowListEditorL(arr, aItem.Header(), curSelection))
       
  1987 		{
       
  1988 		aItem.iNumberData = iBearerHandler->BearerForListIndex(curSelection);
       
  1989        	aItem.SetValueL((*arr)[curSelection]);
       
  1990 		CleanupStack::PopAndDestroy(arr);
       
  1991 		return ETrue;
       
  1992 		}
       
  1993 	
       
  1994 	CleanupStack::PopAndDestroy(arr);
       
  1995 	return EFalse;
       
  1996 	}
       
  1997 
       
  1998 
       
  1999 
       
  2000 // -----------------------------------------------------------------------------
       
  2001 // CAspContentListDialog::EditSettingItemSyncContentL
       
  2002 //
       
  2003 // -----------------------------------------------------------------------------
       
  2004 //
       
  2005 TInt CAspProfileDialog::EditSettingItemSyncContentL(CAspListItemData& aItem)
       
  2006 	{
       
  2007  	TAspParam param(iApplicationId, iSyncSession);
       
  2008     param.iProfile = iProfile;
       
  2009     param.iDataProviderId = aItem.iNumberData;
       
  2010     param.iSyncTaskId = KErrNotFound;
       
  2011     param.iContentList = iContentList;
       
  2012 
       
  2013     CAspContentDialog::ShowDialogL(param);
       
  2014      
       
  2015     return ETrue;
       
  2016 	}
       
  2017 
       
  2018 
       
  2019 //-----------------------------------------------------------------------------
       
  2020 // CAspProfileDialog::GetItemForIndex
       
  2021 // 
       
  2022 // Find item in list position aIndex.
       
  2023 //-----------------------------------------------------------------------------
       
  2024 //
       
  2025 CAspListItemData* CAspProfileDialog::GetItemForIndex(TInt aIndex)
       
  2026 	{
       
  2027 	CAspListItemData* item = NULL;
       
  2028 	
       
  2029 	TInt count = iSettingList->Count();
       
  2030 	for (TInt i=0; i<count; i++)
       
  2031 		{
       
  2032 		CAspListItemData* temp = (*iSettingList)[i];
       
  2033 		if (temp->iIndex == aIndex)
       
  2034 			{
       
  2035 			item = temp;
       
  2036 			break;
       
  2037 			}
       
  2038 		}
       
  2039 
       
  2040 	__ASSERT_ALWAYS(item, TUtil::Panic(KErrGeneral));
       
  2041 
       
  2042     return item;
       
  2043 	}
       
  2044 
       
  2045 
       
  2046 //-----------------------------------------------------------------------------
       
  2047 // CAspProfileDialog::Item
       
  2048 // 
       
  2049 // Find item with aItemId (TAspConnectionSettingItem).
       
  2050 //-----------------------------------------------------------------------------
       
  2051 //
       
  2052 CAspListItemData* CAspProfileDialog::Item(TInt aItemId)
       
  2053 	{
       
  2054 	CAspListItemData* item = NULL;
       
  2055 
       
  2056 	TInt count = iSettingList->Count();
       
  2057 	for (TInt i=0; i<count; i++)
       
  2058 		{
       
  2059 		CAspListItemData* temp = (*iSettingList)[i];
       
  2060 		if (temp->iItemId == aItemId)
       
  2061 			{
       
  2062 			item = temp;
       
  2063 			break;
       
  2064 			}
       
  2065 		}
       
  2066 	
       
  2067 	__ASSERT_ALWAYS(item, TUtil::Panic(KErrGeneral));
       
  2068 
       
  2069     return item;
       
  2070 	}
       
  2071 
       
  2072 
       
  2073 // -----------------------------------------------------------------------------
       
  2074 // CAspProfileDialog::ListBox
       
  2075 // 
       
  2076 // -----------------------------------------------------------------------------
       
  2077 //
       
  2078 CAknSettingStyleListBox* CAspProfileDialog::ListBox()
       
  2079 	{
       
  2080 	return iSettingListBox;
       
  2081 	}
       
  2082 
       
  2083 
       
  2084 // -----------------------------------------------------------------------------
       
  2085 // CAspProfileDialog::UpdateCbaL
       
  2086 // 
       
  2087 // -----------------------------------------------------------------------------
       
  2088 //
       
  2089 void CAspProfileDialog::UpdateCbaL(TInt aResourceId)
       
  2090 	{
       
  2091 	CEikButtonGroupContainer& cba = ButtonGroupContainer();
       
  2092 	cba.SetCommandSetL(aResourceId);
       
  2093 	iCommandSetId = aResourceId;
       
  2094 	iMSKEmpty = EFalse;
       
  2095 	cba.DrawDeferred();
       
  2096 	}
       
  2097 
       
  2098 // -----------------------------------------------------------------------------
       
  2099 // CAspProfileDialog::UpdateMenuL
       
  2100 // 
       
  2101 // -----------------------------------------------------------------------------
       
  2102 //
       
  2103 
       
  2104 void CAspProfileDialog::UpdateMenuL(TInt aResource)
       
  2105 	{
       
  2106 	CEikMenuBar* menuBar = iMenuBar; // from CAknDialog
       
  2107 	menuBar->SetMenuTitleResourceId(aResource);
       
  2108 
       
  2109 	TRAPD(err, menuBar->TryDisplayMenuBarL());
       
  2110     		
       
  2111 	User::LeaveIfError(err);
       
  2112 	}
       
  2113 
       
  2114 // -----------------------------------------------------------------------------
       
  2115 // CAspProfileDialog::CheckAutoSyncSetttigsL
       
  2116 // 
       
  2117 // -----------------------------------------------------------------------------
       
  2118 //
       
  2119 void CAspProfileDialog::CheckAutoSyncSetttigsL()
       
  2120 	{
       
  2121 	CAspSchedule* schedule = CAspSchedule::NewLC();
       
  2122 	TInt profileId = schedule->ProfileId();
       
  2123 	if (profileId == iProfile->ProfileId())
       
  2124 			{
       
  2125 			if (iProfile->BearerType() != EAspBearerInternet)
       
  2126 				{
       
  2127 				schedule->SetProfileId(KErrNotFound);
       
  2128 				schedule->SetSyncPeakSchedule(CAspSchedule::EIntervalManual);
       
  2129 				schedule->SetSyncOffPeakSchedule(CAspSchedule::EIntervalManual);
       
  2130 				schedule->SetSyncFrequency(CAspSchedule::EIntervalManual);
       
  2131 				schedule->UpdateSyncScheduleL();
       
  2132 				schedule->SaveL();
       
  2133 				}
       
  2134 			else
       
  2135 				{
       
  2136 				schedule->UpdateProfileSettingsL();
       
  2137 				}
       
  2138 			}
       
  2139 	CleanupStack::PopAndDestroy(schedule);	
       
  2140 	}
       
  2141 	
       
  2142 //  End of File