omads/omadsappui/AspSyncUtil/src/AspAdvanceSettingsDialog.cpp
branchRCL_3
changeset 52 4f0867e42d62
equal deleted inserted replaced
51:8e7494275d3a 52:4f0867e42d62
       
     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 "AspAdvanceSettingsDialog.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 "AspDefines.h" //For enum TRoamingSettings
       
    34 #include <centralrepository.h> //For central Repository
       
    35 #include "CPreSyncPlugin.h"
       
    36 
       
    37 const TInt KMSKControlId( CEikButtonGroupContainer::EMiddleSoftkeyPosition );
       
    38 
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 
       
    41 
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CAspProfileDialog::ShowDialogL
       
    45 // 
       
    46 // -----------------------------------------------------------------------------
       
    47 TBool CAspAdvanceSettingsDialog::ShowDialogL()
       
    48 	{
       
    49 	CAspAdvanceSettingsDialog* dialog = CAspAdvanceSettingsDialog::NewL();
       
    50 
       
    51 	TBool ret = dialog->ExecuteLD(R_ASP_ADVANCE_SETTINGS_DIALOG);
       
    52 
       
    53     return ret;
       
    54 	}
       
    55 
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CAspAdvanceSettingsDialog::NewL
       
    59 //
       
    60 // -----------------------------------------------------------------------------
       
    61 CAspAdvanceSettingsDialog* CAspAdvanceSettingsDialog::NewL()
       
    62     {
       
    63     FLOG( _L("CAspAdvanceSettingsDialog::NewL START") );
       
    64 
       
    65     CAspAdvanceSettingsDialog* self = new ( ELeave ) CAspAdvanceSettingsDialog();
       
    66     CleanupStack::PushL(self);
       
    67     self->ConstructL();
       
    68     CleanupStack::Pop(self);
       
    69 
       
    70     FLOG( _L("CAspAdvanceSettingsDialog::NewL END") );
       
    71     return self;
       
    72     }
       
    73 
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CAspAdvanceSettingsDialog::CAspAdvanceSettingsDialog
       
    77 // 
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 CAspAdvanceSettingsDialog::CAspAdvanceSettingsDialog()
       
    81 	{
       
    82     }
       
    83 
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CAspAdvanceSettingsDialog::ConstructL
       
    87 //
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CAspAdvanceSettingsDialog::ConstructL()
       
    91     {
       
    92     FLOG( _L("CAspAdvanceSettingsDialog::ConstructL START") );
       
    93 	
       
    94 	// contruct menu for our dialog
       
    95 	CAknDialog::ConstructL(R_ADVANCE_SETTINGS_DIALOG_MENU);
       
    96 
       
    97 	iResHandler = CAspResHandler::NewL();
       
    98 
       
    99 	iSettingList = new (ELeave) CArrayPtrFlat<CAspListItemData>(1);
       
   100 	
       
   101 	// get previous title so it can be restored
       
   102 	iStatusPaneHandler = CStatusPaneHandler::NewL(iAvkonAppUi);
       
   103 	iStatusPaneHandler->StoreOriginalTitleL();
       
   104 	
       
   105 	// store current navi pane
       
   106 	iStatusPaneHandler->StoreNavipaneL();
       
   107 
       
   108 	FLOG( _L("CAspAdvanceSettingsDialog::ConstructL END") );
       
   109     } 
       
   110 
       
   111 
       
   112 // ----------------------------------------------------------------------------
       
   113 // Destructor
       
   114 //
       
   115 // ----------------------------------------------------------------------------
       
   116 //
       
   117 CAspAdvanceSettingsDialog::~CAspAdvanceSettingsDialog()
       
   118     {
       
   119     FLOG( _L("CAspAdvanceSettingsDialog::~CAspAdvanceSettingsDialog START") );
       
   120 
       
   121 	delete iResHandler;
       
   122 	
       
   123 	if (iSettingList)
       
   124 		{
       
   125 		iSettingList->ResetAndDestroy();
       
   126 	    delete iSettingList;
       
   127 		}
       
   128 
       
   129 	delete iStatusPaneHandler;
       
   130 	
       
   131     if (iAvkonAppUi)
       
   132     	{
       
   133     	iAvkonAppUi->RemoveFromStack(this);
       
   134     	}
       
   135 
       
   136 	FLOG( _L("CAspAdvanceSettingsDialog::~CAspAdvanceSettingsDialog END") );
       
   137     }
       
   138 
       
   139 
       
   140 //------------------------------------------------------------------------------
       
   141 // CAspAdvanceSettingsDialog::ActivateL
       
   142 //
       
   143 // Called by system when dialog is activated.
       
   144 //------------------------------------------------------------------------------
       
   145 //
       
   146 void CAspAdvanceSettingsDialog::ActivateL()
       
   147 	{
       
   148     CAknDialog::ActivateL();
       
   149 
       
   150 	// this cannot be in ConstructL which is executed before dialog is launched
       
   151 	iAvkonAppUi->AddToStackL(this);
       
   152     }
       
   153 
       
   154 
       
   155 //------------------------------------------------------------------------------
       
   156 // CAspContentListDialog::GetHelpContext
       
   157 //
       
   158 //------------------------------------------------------------------------------
       
   159 //
       
   160 void CAspAdvanceSettingsDialog::GetHelpContext(TCoeHelpContext& aContext) const
       
   161 	{
       
   162 	aContext.iMajor = KUidSmlSyncApp;
       
   163 	aContext.iContext = KDS_HLP_MAIN_VIEW;    
       
   164 	}
       
   165 
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CAspAdvanceSettingsDialog::HandleListBoxEventL
       
   169 // 
       
   170 // -----------------------------------------------------------------------------
       
   171 #ifdef RD_SCALABLE_UI_V2
       
   172 void CAspAdvanceSettingsDialog::HandleListBoxEventL(CEikListBox* /*aListBox*/,
       
   173                                             TListBoxEvent aEventType)
       
   174 	{
       
   175 	if( AknLayoutUtils::PenEnabled() )  
       
   176 	  {
       
   177 	   switch ( aEventType )
       
   178         {
       
   179         case EEventItemSingleClicked:
       
   180               HandleOKL();
       
   181               break;
       
   182          case EEventEnterKeyPressed :
       
   183 
       
   184          case EEventItemDraggingActioned :
       
   185          case EEventPenDownOnItem :
       
   186         	  if(iEditMode != EDialogModeSettingEnforcement)
       
   187 				    {
       
   188 				    TRAPD(err ,CheckContentSettingL());//folder
       
   189 		         	User::LeaveIfError(err);
       
   190 				    }
       
   191               break;
       
   192          default:
       
   193               break;
       
   194         }
       
   195 		
       
   196 	  }
       
   197     
       
   198 	}
       
   199 #else
       
   200 void CAspAdvanceSettingsDialog::HandleListBoxEventL(CEikListBox* /*aListBox*/,
       
   201                                             TListBoxEvent /*aEventType*/)
       
   202 {
       
   203 	
       
   204 }
       
   205 #endif
       
   206 
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CAspAdvanceSettingsDialog::PreLayoutDynInitL
       
   210 // 
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 void CAspAdvanceSettingsDialog::PreLayoutDynInitL()
       
   214     {
       
   215     iSettingListBox = (CAknSettingStyleListBox*) ControlOrNull (EAdvanceSettingsDialogList);
       
   216     
       
   217    	__ASSERT_ALWAYS(iSettingListBox, TUtil::Panic(KErrGeneral));
       
   218     
       
   219 	iSettingListBox->SetListBoxObserver(this);
       
   220 	iSettingListBox->CreateScrollBarFrameL(ETrue);
       
   221 	iSettingListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   222 	                 CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto);
       
   223 	
       
   224 	SetIconsL();
       
   225 	
       
   226 	// create array of setting items (iSettingList)
       
   227 	CreateSettingsListL();
       
   228 
       
   229 	// add setting headers into listbox
       
   230 	UpdateListBoxL(iSettingListBox, iSettingList);
       
   231 		
       
   232 	iStatusPaneHandler->SetNaviPaneTitleL(R_ASP_TITLE_ADVANCED_SETTINGS);
       
   233     }
       
   234 
       
   235 
       
   236 // ----------------------------------------------------------------------------
       
   237 // CAspAdvanceSettingsDialog::SetMiddleSoftKeyLabelL
       
   238 //
       
   239 // ----------------------------------------------------------------------------
       
   240 //
       
   241 void CAspAdvanceSettingsDialog::SetEmptyMiddleSoftKeyLabelL()
       
   242     {
       
   243     ButtonGroupContainer().RemoveCommandFromStack(KMSKControlId,EAknSoftkeyOpen );
       
   244     HBufC* middleSKText = StringLoader::LoadLC( R_TEXT_SOFTKEY_EMPTY );
       
   245 
       
   246     ButtonGroupContainer().AddCommandToStackL(
       
   247         KMSKControlId,
       
   248         EAknSoftkeyEmpty,
       
   249         *middleSKText );
       
   250     iMSKEmpty= ETrue;
       
   251     CleanupStack::PopAndDestroy( middleSKText );
       
   252     }
       
   253 // ----------------------------------------------------------------------------
       
   254 // CAspAdvanceSettingsDialog::SetIconsL
       
   255 //
       
   256 // ----------------------------------------------------------------------------
       
   257 //
       
   258 void CAspAdvanceSettingsDialog::SetIconsL()
       
   259     {
       
   260     if (!iSettingListBox)
       
   261     	{
       
   262     	return;
       
   263     	}
       
   264  
       
   265  	TFileName bitmapName;
       
   266 	CAspResHandler::GetBitmapFileName(bitmapName);
       
   267 	CArrayPtr<CGulIcon>* icons = new (ELeave) CAknIconArray(KDefaultArraySize);
       
   268 	CleanupStack::PushL(icons);
       
   269 	
       
   270 	icons->AppendL(IconL(KAknsIIDQgnIndiSettProtectedAdd, bitmapName,
       
   271 	                     EMbmAspsyncutilQgn_indi_sett_protected_add,
       
   272 	                     EMbmAspsyncutilQgn_indi_sett_protected_add_mask));
       
   273 	
       
   274     // delete old icons
       
   275     CArrayPtr<CGulIcon>* arr =
       
   276     iSettingListBox->ItemDrawer()->FormattedCellData()->IconArray();
       
   277     
       
   278     if (arr)
       
   279     	{
       
   280     	arr->ResetAndDestroy();
       
   281 	    delete arr;
       
   282 	    arr = NULL;
       
   283     	}
       
   284 
       
   285 	iSettingListBox->ItemDrawer()->FormattedCellData()->SetIconArrayL(icons);
       
   286 	CleanupStack::Pop(icons);
       
   287     }
       
   288 
       
   289 
       
   290 // -----------------------------------------------------------------------------
       
   291 // CAspAdvanceSettingsDialog::IconL
       
   292 // 
       
   293 // -----------------------------------------------------------------------------
       
   294 //
       
   295 CGulIcon* CAspAdvanceSettingsDialog::IconL(TAknsItemID aId, const TDesC& aFileName, TInt aFileIndex, TInt aFileMaskIndex)
       
   296 	{
       
   297     return TDialogUtil::CreateIconL(aId, aFileName, aFileIndex, aFileMaskIndex);
       
   298 	}
       
   299 
       
   300 
       
   301 //------------------------------------------------------------------------------
       
   302 // CAspAdvanceSettingsDialog::DynInitMenuPaneL
       
   303 //
       
   304 // Called by system before menu is shown.
       
   305 //------------------------------------------------------------------------------
       
   306 //
       
   307 void CAspAdvanceSettingsDialog::DynInitMenuPaneL(TInt /*aResourceID*/, CEikMenuPane* aMenuPane)
       
   308 	{   
       
   309 	CAspListItemData* item = GetItemForIndex(ListBox()->CurrentItemIndex());
       
   310 	if (item->iHidden == EVisibilityReadOnly)
       
   311 		{
       
   312 		TDialogUtil::DeleteMenuItem(aMenuPane, EAspMenuCmdChange);
       
   313 		}
       
   314 	
       
   315 	if (!FeatureManager::FeatureSupported(KFeatureIdHelp))
       
   316 		{
       
   317 		TDialogUtil::DeleteMenuItem(aMenuPane, EAspMenuCmdHelp);
       
   318 		}
       
   319     }
       
   320 
       
   321 
       
   322 //------------------------------------------------------------------------------
       
   323 // CAspAdvanceSettingsDialog::ProcessCommandL
       
   324 //
       
   325 // Handle commands from menu.
       
   326 //------------------------------------------------------------------------------
       
   327 //
       
   328 void CAspAdvanceSettingsDialog::ProcessCommandL(TInt aCommandId)
       
   329 	{
       
   330 	HideMenu();
       
   331 
       
   332 	switch (aCommandId)
       
   333 		{
       
   334 		case EAspMenuCmdHelp:
       
   335 		case EAknCmdHelp:
       
   336 			{
       
   337 			TUtil::LaunchHelpAppL(iEikonEnv);
       
   338             break;
       
   339 			}
       
   340 
       
   341 		case EAspMenuCmdChange:
       
   342 		case EAspMenuCmdOpen:
       
   343 			{				
       
   344     		CAspListItemData* item = GetItemForIndex(ListBox()->CurrentItemIndex());
       
   345 
       
   346 			if (item->iItemType == CAspListItemData::ETypeListYesNo)
       
   347 				{
       
   348 				// open editor for Yes/No setting
       
   349 				if (EditSettingItemListL(*item))
       
   350 					{
       
   351 					SetVisibility();
       
   352 					UpdateListBoxL(ListBox(), iSettingList);
       
   353 					}
       
   354 				}				
       
   355 			else
       
   356 				{
       
   357 				HandleOKL();
       
   358 				}
       
   359 
       
   360 			break;
       
   361 			}
       
   362 		    
       
   363         case EAspMenuCmdExit:
       
   364         case EAknCmdExit:
       
   365         case EEikCmdExit:
       
   366 			{
       
   367 			// close dialog and exit calling application
       
   368 			iAvkonAppUi->ProcessCommandL(EAknCmdExit);
       
   369 			break;
       
   370 			}
       
   371 
       
   372 		default:			
       
   373 		    break;
       
   374 		}
       
   375 	}
       
   376 
       
   377 
       
   378 //------------------------------------------------------------------------------
       
   379 // CAspAdvanceSettingsDialog::OkToExitL
       
   380 //
       
   381 //------------------------------------------------------------------------------
       
   382 //
       
   383 TBool CAspAdvanceSettingsDialog::OkToExitL(TInt aButtonId)
       
   384 	{
       
   385 	if (aButtonId == EEikBidCancel)
       
   386 		{
       
   387 		// save silently and close dialog
       
   388 		
       
   389 		CheckSettingValues(aButtonId);
       
   390 
       
   391 		return ETrue; // close dialog
       
   392 		}
       
   393 
       
   394 	if (aButtonId == EAknSoftkeyBack)
       
   395         {
       
   396         TBool ret = CheckSettingValues(aButtonId);
       
   397         if (!ret)
       
   398         	{
       
   399         	return EFalse; // leave dialog open
       
   400         	}
       
   401         	
       
   402 		return ETrue; // close dialog
       
   403 		}
       
   404 		
       
   405 	if (aButtonId == EAknSoftkeyOpen || aButtonId == EAknSoftkeyEmpty)  // MSK
       
   406         {
       
   407 		CAspListItemData* item = GetItemForIndex(ListBox()->CurrentItemIndex());
       
   408 		if (item->iHidden == EVisibilityReadOnly)
       
   409 			{
       
   410     		if(iEditMode == EDialogModeSettingEnforcement)
       
   411     		{
       
   412     			TDialogUtil::ShowInformationNoteL(R_ASP_PROTECTED_SETTING);
       
   413     		}
       
   414      		else
       
   415      		{
       
   416 			TDialogUtil::ShowInformationNoteL(R_ASP_NOTE_READ_ONLY);
       
   417      		}
       
   418 			return EFalse;
       
   419 			}
       
   420 
       
   421         HandleOKL();
       
   422 		return EFalse;  // leave dialog open
       
   423 		}
       
   424 		
       
   425 	if (aButtonId == EAknSoftkeyOptions)	
       
   426 		{
       
   427 		if (iCommandSetId == R_ASP_CBA_OPTIONS_BACK_OPEN)
       
   428 			{
       
   429 			UpdateMenuL(R_ADVANCE_SETTINGS_DIALOG_MENU);
       
   430 			}	
       
   431 		else 
       
   432 			{
       
   433 			UpdateMenuL(R_ASP_PROFILE_DIALOG_MENU);	
       
   434 			}
       
   435 		return EFalse;
       
   436 		}
       
   437 	return CAknDialog::OkToExitL(aButtonId);
       
   438 	}
       
   439 
       
   440 
       
   441 //------------------------------------------------------------------------------
       
   442 // CAspAdvanceSettingsDialog::CheckSettingValuesL
       
   443 //
       
   444 //------------------------------------------------------------------------------
       
   445 //
       
   446 TBool CAspAdvanceSettingsDialog::CheckSettingValuesL(TInt /* aButtonId */)
       
   447 	{
       
   448 	
       
   449     if (iEditMode == EDialogModeReadOnly || 
       
   450         iEditMode == EDialogModeSettingEnforcement)
       
   451     	{
       
   452     	return ETrue;
       
   453     	}
       
   454 	
       
   455     return ETrue;
       
   456 	}
       
   457 
       
   458 
       
   459 //------------------------------------------------------------------------------
       
   460 // CAspAdvanceSettingsDialog::CheckSettingValues
       
   461 //
       
   462 //------------------------------------------------------------------------------
       
   463 //
       
   464 TBool CAspAdvanceSettingsDialog::CheckSettingValues(TInt aButtonId)
       
   465 	{
       
   466 	TBool ret = EFalse;
       
   467 	
       
   468 	TRAPD(err, ret = CheckSettingValuesL(aButtonId));
       
   469 	if (err != KErrNone)
       
   470 		{
       
   471 		return ETrue;
       
   472 		}
       
   473 
       
   474 	return ret;
       
   475 	}
       
   476 
       
   477 
       
   478 // ----------------------------------------------------------------------------
       
   479 // CAspAdvanceSettingsDialog::OfferKeyEventL
       
   480 // 
       
   481 // ----------------------------------------------------------------------------
       
   482 //
       
   483 TKeyResponse CAspAdvanceSettingsDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   484 	{
       
   485 	if (aType == EEventKey)
       
   486 		{
       
   487 		switch (aKeyEvent.iCode)
       
   488 			{
       
   489 			case EKeyEnter:
       
   490 			case EKeyOK:
       
   491 				{
       
   492 					OkToExitL(EAknSoftkeyOpen);
       
   493 					return EKeyWasConsumed;
       
   494 				}
       
   495 			case EKeyEscape:  // framework calls this when dialog must shut down
       
   496 				{
       
   497 				return CAknDialog::OfferKeyEventL(aKeyEvent, aType);
       
   498         		}
       
   499 			case EKeyUpArrow:
       
   500 			case EKeyDownArrow:
       
   501 			    {
       
   502 			    	if(iEditMode != EDialogModeSettingEnforcement)
       
   503 				    {
       
   504 				    TRAPD(err ,CheckContentSettingL(aKeyEvent));//folder
       
   505 		         	User::LeaveIfError(err);
       
   506 				    }
       
   507 			    break;
       
   508 			    }
       
   509             default:
       
   510 				{
       
   511 			    break;
       
   512 				}
       
   513 			}
       
   514 		}
       
   515 
       
   516 	return CAknDialog::OfferKeyEventL( aKeyEvent, aType);
       
   517 	}
       
   518 
       
   519 // ---------------------------------------------------------------------------------------------
       
   520 // CAspAdvanceSettingsDialog::CheckContentSetting
       
   521 // modifies MSK and menu item depending on the item in the list box when touch events are handled
       
   522 // ----------------------------------------------------------------------------------------------
       
   523 //
       
   524 
       
   525 void CAspAdvanceSettingsDialog::CheckContentSettingL()
       
   526 {
       
   527 	TInt curIndex = ListBox()->CurrentItemIndex();
       
   528 	TInt count = iSettingList->Count();
       
   529 	CAspListItemData* lastItem = (*iSettingList)[--count];
       
   530 	
       
   531 
       
   532 		
       
   533 	CAspListItemData* curItem = GetItemForIndex(curIndex);
       
   534 	//TBool isPCSuite = CAspProfile::IsPCSuiteProfile(iProfile);
       
   535 	//if(isPCSuite && (curItem->iHidden == EVisibilityReadOnly))
       
   536     if(curItem->iHidden == EVisibilityReadOnly)
       
   537 	{
       
   538    		SetEmptyMiddleSoftKeyLabelL();
       
   539    		return;
       
   540 	}
       
   541 	if(curItem->iItemId != EAspSyncContent)
       
   542 		{
       
   543 		if(iCommandSetId != R_ASP_CBA_OPTIONS_BACK_CHANGE || iMSKEmpty)
       
   544 			{
       
   545 			UpdateCbaL(R_ASP_CBA_OPTIONS_BACK_CHANGE);
       
   546 		
       
   547 			}
       
   548 		return;		
       
   549 		}
       
   550 	UpdateCbaL( R_ASP_CBA_OPTIONS_BACK_OPEN);
       
   551 
       
   552 }
       
   553 
       
   554 // ----------------------------------------------------------------------------
       
   555 // CAspAdvanceSettingsDialog::CheckContentSetting
       
   556 // modifies MSK based on the item
       
   557 // ----------------------------------------------------------------------------
       
   558 //
       
   559 
       
   560 void CAspAdvanceSettingsDialog::CheckContentSettingL(const TKeyEvent& aKeyEvent)
       
   561 	{
       
   562 	
       
   563 	TInt curIndex = ListBox()->CurrentItemIndex();
       
   564 	TInt count = iSettingList->Count();
       
   565 	CAspListItemData* lastItem = (*iSettingList)[--count];
       
   566 	
       
   567 	switch (aKeyEvent.iCode)
       
   568 		{
       
   569 		case EKeyUpArrow:
       
   570 			{
       
   571 				if (curIndex)
       
   572 				{
       
   573 					curIndex--;
       
   574 				}
       
   575 				else
       
   576 				{
       
   577 				    curIndex = lastItem->iIndex;
       
   578 				}
       
   579 			break;
       
   580 			}
       
   581 		case EKeyDownArrow:
       
   582 			{
       
   583 				if (curIndex == lastItem->iIndex)
       
   584 				{
       
   585 				curIndex = 0;
       
   586 				}
       
   587 				else
       
   588 				{
       
   589 				curIndex++;
       
   590 				}
       
   591 			break;
       
   592 			}
       
   593 		}
       
   594 		
       
   595 	CAspListItemData* curItem = GetItemForIndex(curIndex);
       
   596 	//TBool isPCSuite = CAspProfile::IsPCSuiteProfile(iProfile);
       
   597 	//if(isPCSuite && (curItem->iHidden == EVisibilityReadOnly))
       
   598 	if(curItem->iHidden == EVisibilityReadOnly)
       
   599 	{
       
   600    		SetEmptyMiddleSoftKeyLabelL();
       
   601    		return;
       
   602 	}
       
   603 	if(curItem->iItemId != EAspSyncContent)
       
   604 		{
       
   605 		if(iCommandSetId != R_ASP_CBA_OPTIONS_BACK_CHANGE || iMSKEmpty)
       
   606 			{
       
   607 			UpdateCbaL(R_ASP_CBA_OPTIONS_BACK_CHANGE);
       
   608 		
       
   609 			}
       
   610 		return;		
       
   611 		}
       
   612 	UpdateCbaL( R_ASP_CBA_OPTIONS_BACK_OPEN);
       
   613 
       
   614 	}
       
   615 
       
   616 // ----------------------------------------------------------------------------
       
   617 // CAspAdvanceSettingsDialog::HandleResourceChange
       
   618 // 
       
   619 // ----------------------------------------------------------------------------
       
   620 //
       
   621 void CAspAdvanceSettingsDialog::HandleResourceChange(TInt aType)
       
   622     {   
       
   623     if (aType == KEikDynamicLayoutVariantSwitch) //Handle change in layout orientation
       
   624         {
       
   625         TRect mainPaneRect;
       
   626         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
       
   627         SetRect(mainPaneRect);
       
   628         iSettingListBox->SetSize(mainPaneRect.Size());
       
   629         CCoeControl::HandleResourceChange(aType);
       
   630 		DrawDeferred();
       
   631 	    return;
       
   632 		}
       
   633 		
       
   634     if (aType == KAknsMessageSkinChange)
       
   635         {
       
   636         TRAP_IGNORE(SetIconsL());
       
   637         }
       
   638 		
       
   639     CCoeControl::HandleResourceChange(aType);
       
   640     }
       
   641 
       
   642 //------------------------------------------------------------------------------
       
   643 // CAspAdvanceSettingsDialog::HandleOKL
       
   644 //
       
   645 //------------------------------------------------------------------------------
       
   646 //
       
   647 void CAspAdvanceSettingsDialog::HandleOKL()
       
   648 	{
       
   649 	
       
   650 	CAspListItemData* item = GetItemForIndex(ListBox()->CurrentItemIndex());
       
   651 
       
   652 	if (item->iHidden == EVisibilityReadOnly)
       
   653 		{
       
   654 			if(iEditMode == EDialogModeSettingEnforcement)
       
   655       		{
       
   656     			TDialogUtil::ShowInformationNoteL(R_ASP_PROTECTED_SETTING);
       
   657     		}
       
   658      		else
       
   659      		{
       
   660 			TDialogUtil::ShowInformationNoteL(R_ASP_NOTE_READ_ONLY);
       
   661      		}
       
   662 		return;
       
   663 		}
       
   664 
       
   665 	if (EditSettingItemL(*item))
       
   666 		{
       
   667 		SetVisibility();
       
   668 		UpdateListBoxL(ListBox(), iSettingList);
       
   669 		}
       
   670 		
       
   671 	}
       
   672 
       
   673 
       
   674 // ----------------------------------------------------------------------------
       
   675 // CAspAdvanceSettingsDialog::CreateSettingsListL
       
   676 // 
       
   677 // Function creates setting list array (iSettingsList).
       
   678 // Note: enum TAspConnectionSettings must match with string array
       
   679 // (R_ASP_CONNECTION_DIALOG_SETTING_ITEMS).
       
   680 // ----------------------------------------------------------------------------
       
   681 //
       
   682 void CAspAdvanceSettingsDialog::CreateSettingsListL()
       
   683 	{
       
   684 	// read setting headers from resource
       
   685 	CDesCArray* arr = iResHandler->ReadDesArrayLC(R_ADVANCE_SETTINGS_DIALOG_ITEMS);
       
   686 	
       
   687 	// add one CAspListItemData for each setting
       
   688 	AddItemL(ERoamingSettings, arr);
       
   689 
       
   690 	// write setting data into each CAspListItemData
       
   691 	TInt count=iSettingList->Count();
       
   692 	for (TInt i=0; i<count; i++)
       
   693 		{
       
   694 		InitSettingItemL((*iSettingList)[i]);
       
   695 		}
       
   696 
       
   697 	SetVisibility();  // find out what setting appear on UI
       
   698 
       
   699 	CleanupStack::PopAndDestroy(arr);
       
   700 	}
       
   701 
       
   702 
       
   703 // ----------------------------------------------------------------------------
       
   704 // CAspAdvanceSettingsDialog::AddItemL
       
   705 // 
       
   706 // ----------------------------------------------------------------------------
       
   707 //
       
   708 void CAspAdvanceSettingsDialog::AddItemL(TInt aItemId, CDesCArray* aHeaders)
       
   709 	{
       
   710     CAspListItemData* item = CAspListItemData::NewLC();
       
   711 	item->SetHeaderL((*aHeaders)[aItemId]);
       
   712 	item->iItemId = aItemId;
       
   713 	iSettingList->AppendL(item);
       
   714 	CleanupStack::Pop(item);
       
   715 	}
       
   716 // ----------------------------------------------------------------------------
       
   717 // CAspAdvanceSettingsDialog::AddItemL
       
   718 // 
       
   719 // ----------------------------------------------------------------------------
       
   720 //
       
   721 void CAspAdvanceSettingsDialog::AddItemL(TInt aItemId, TInt aResourceId)
       
   722 	{
       
   723     CAspListItemData* item = CAspListItemData::NewLC();
       
   724 	item->SetHeaderL(aResourceId);
       
   725 	item->iItemId = aItemId;
       
   726 	iSettingList->AppendL(item);
       
   727 	CleanupStack::Pop(item);
       
   728 	}
       
   729 
       
   730 // ----------------------------------------------------------------------------
       
   731 // CAspAdvanceSettingsDialog::UpdateListBoxL
       
   732 // 
       
   733 // Add settings headers into listbox.
       
   734 // ----------------------------------------------------------------------------
       
   735 //
       
   736 void CAspAdvanceSettingsDialog::UpdateListBoxL(CEikTextListBox* aListBox,
       
   737                                        CAspSettingList* aItemList)
       
   738 	{
       
   739 	CDesCArray* arr = (CDesCArray*)aListBox->Model()->ItemTextArray();
       
   740 	arr->Reset();
       
   741 
       
   742 	TInt count = aItemList->Count();
       
   743 	for (TInt i=0; i<count; i++ )
       
   744 		{	
       
   745 		CAspListItemData* item = (*aItemList)[i];		
       
   746 		TInt aValue = 0;
       
   747 		ReadRepositoryL(KNSmlRoamingSettingKey, aValue);
       
   748 		if(aValue != ERoamingSettingBlock)
       
   749 		{
       
   750 		WriteRepositoryL(KNSmlRoamingSettingKey, item->iNumberData);
       
   751 		}
       
   752 		else
       
   753 		{
       
   754 		SetEmptyMiddleSoftKeyLabelL();
       
   755 		}
       
   756 		    		
       
   757 		TBool convert = ETrue;
       
   758 		if (item->iHidden != EVisibilityHidden)
       
   759 			{
       
   760 			HBufC* hBuf = item->ListItemTextL(convert);
       
   761 			CleanupStack::PushL(hBuf);
       
   762 			
       
   763 			arr->AppendL(hBuf->Des());
       
   764 			
       
   765 			// store listbox index (from zero up) into setting item 
       
   766 			item->iIndex = arr->Count() - 1;
       
   767 
       
   768 			CleanupStack::PopAndDestroy(hBuf);
       
   769 			}
       
   770 		else
       
   771 			{
       
   772 			item->iIndex = KErrNotFound;
       
   773 			}
       
   774 		}
       
   775 
       
   776 	ListBox()->HandleItemAdditionL();
       
   777 	}
       
   778 
       
   779 
       
   780 // -----------------------------------------------------------------------------
       
   781 // CAspAdvanceSettingsDialog::SetVisibility
       
   782 // 
       
   783 // -----------------------------------------------------------------------------
       
   784 //
       
   785 void CAspAdvanceSettingsDialog::SetVisibility()
       
   786 	{
       
   787     TInt aValue(0);
       
   788     TRAPD(err ,ReadRepositoryL(KNSmlRoamingSettingKey, aValue));
       
   789     if(aValue == ERoamingSettingBlock)
       
   790     {
       
   791 	Item(ERoamingSettings)->iHidden = EVisibilityReadOnly;
       
   792 	}
       
   793 	else
       
   794 	{
       
   795 	Item(ERoamingSettings)->iHidden = EVisibilityNormal;
       
   796 	}
       
   797 	}
       
   798 
       
   799 void CAspAdvanceSettingsDialog::ReadRepositoryL(TInt aKey, TInt& aValue)
       
   800     {
       
   801     CRepository* rep = CRepository::NewLC(KCRUidNSmlDSApp);
       
   802     TInt err = rep->Get(aKey, aValue);
       
   803     User::LeaveIfError(err);
       
   804     
       
   805     CleanupStack::PopAndDestroy(rep);
       
   806     }
       
   807 
       
   808 // -----------------------------------------------------------------------------
       
   809 // CAspAdvanceSettingsDialog::InitSettingItemL
       
   810 // 
       
   811 // Constructs CAspListItemData for one connection setting.
       
   812 // -----------------------------------------------------------------------------
       
   813 //
       
   814 void CAspAdvanceSettingsDialog::InitSettingItemL(CAspListItemData* aItem)
       
   815 	{
       
   816 	__ASSERT_ALWAYS(aItem, TUtil::Panic(KErrGeneral));	
       
   817 	
       
   818 	iBuf = KNullDesC;  // reset common buffer
       
   819 	
       
   820 	switch (aItem->iItemId)
       
   821 		{		
       
   822         case ERoamingSettings:
       
   823             {
       
   824             CDesCArray* arr = iResHandler->ReadDesArrayLC(R_ASP_ROAMING_SETTINGS);
       
   825             TInt aValue(0);
       
   826             ReadRepositoryL(KNSmlRoamingSettingKey, aValue);
       
   827 
       
   828             if(aValue == ERoamingSettingBlock)
       
   829                 {
       
   830                 aItem->iNumberData = ERoamingSettingAlwaysAsk;
       
   831                 }
       
   832             else
       
   833                 {
       
   834                 aItem->iNumberData = aValue;
       
   835                 }
       
   836             //aItem->iNumberData = iProfile->SASyncState();
       
   837             aItem->iResource = R_ASP_ROAMING_SETTINGS;
       
   838             aItem->SetValueL((*arr)[aItem->iNumberData]);
       
   839             aItem->iItemType = CAspListItemData::ETypeList;
       
   840             
       
   841             CleanupStack::PopAndDestroy(arr);
       
   842             break;
       
   843             }
       
   844 			
       
   845         default:
       
   846            	__ASSERT_DEBUG(EFalse, TUtil::Panic(KErrGeneral));
       
   847 			break;
       
   848 		
       
   849 		}
       
   850 	}
       
   851 	
       
   852 //------------------------------------------------------------------------------
       
   853 // CAspAdvanceSettingsDialog::EditSettingItemL
       
   854 //
       
   855 // Calls setting editing functions. 
       
   856 //------------------------------------------------------------------------------
       
   857 //
       
   858 TBool CAspAdvanceSettingsDialog::EditSettingItemL(CAspListItemData& aItem)
       
   859 	{
       
   860 	TInt ret = EFalse;
       
   861 	
       
   862 	switch (aItem.iItemType)
       
   863 		{
       
   864 
       
   865 		case CAspListItemData::ETypeList:
       
   866 			ret = EditSettingItemListL(aItem);
       
   867 		    break;
       
   868 		
       
   869 
       
   870 		default:
       
   871 		    break;
       
   872 		}
       
   873 	
       
   874 	return ret;
       
   875 	}
       
   876 
       
   877 //------------------------------------------------------------------------------
       
   878 // CAspAdvanceSettingsDialog::EditSettingItemListL
       
   879 //
       
   880 //------------------------------------------------------------------------------
       
   881 //
       
   882 TBool CAspAdvanceSettingsDialog::EditSettingItemListL(CAspListItemData& aItem)
       
   883 	{
       
   884 	TInt curSelection = aItem.iNumberData;
       
   885 	CDesCArray* arr = CAspResHandler::ReadDesArrayStaticLC(aItem.iResource);
       
   886 	
       
   887 	TBool ret = TDialogUtil::ShowListEditorL(arr, aItem.Header(), curSelection);
       
   888 	if (ret)
       
   889 		{
       
   890 		aItem.iNumberData = curSelection; 
       
   891 		aItem.SetValueL((*arr)[curSelection]);
       
   892 		}
       
   893 
       
   894 	CleanupStack::PopAndDestroy(arr);
       
   895 	return ret;
       
   896 	}
       
   897 
       
   898 //-----------------------------------------------------------------------------
       
   899 // CAspAdvanceSettingsDialog::GetItemForIndex
       
   900 // 
       
   901 // Find item in list position aIndex.
       
   902 //-----------------------------------------------------------------------------
       
   903 //
       
   904 CAspListItemData* CAspAdvanceSettingsDialog::GetItemForIndex(TInt aIndex)
       
   905 	{
       
   906 	CAspListItemData* item = NULL;
       
   907 	
       
   908 	TInt count = iSettingList->Count();
       
   909 	for (TInt i=0; i<count; i++)
       
   910 		{
       
   911 		CAspListItemData* temp = (*iSettingList)[i];
       
   912 		if (temp->iIndex == aIndex)
       
   913 			{
       
   914 			item = temp;
       
   915 			break;
       
   916 			}
       
   917 		}
       
   918 
       
   919 	__ASSERT_ALWAYS(item, TUtil::Panic(KErrGeneral));
       
   920 
       
   921     return item;
       
   922 	}
       
   923 
       
   924 
       
   925 //-----------------------------------------------------------------------------
       
   926 // CAspAdvanceSettingsDialog::Item
       
   927 // 
       
   928 // Find item with aItemId (TAspConnectionSettingItem).
       
   929 //-----------------------------------------------------------------------------
       
   930 //
       
   931 CAspListItemData* CAspAdvanceSettingsDialog::Item(TInt aItemId)
       
   932 	{
       
   933 	CAspListItemData* item = NULL;
       
   934 
       
   935 	TInt count = iSettingList->Count();
       
   936 	for (TInt i=0; i<count; i++)
       
   937 		{
       
   938 		CAspListItemData* temp = (*iSettingList)[i];
       
   939 		if (temp->iItemId == aItemId)
       
   940 			{
       
   941 			item = temp;
       
   942 			break;
       
   943 			}
       
   944 		}
       
   945 	
       
   946 	__ASSERT_ALWAYS(item, TUtil::Panic(KErrGeneral));
       
   947 
       
   948     return item;
       
   949 	}
       
   950 
       
   951 
       
   952 // -----------------------------------------------------------------------------
       
   953 // CAspAdvanceSettingsDialog::ListBox
       
   954 // 
       
   955 // -----------------------------------------------------------------------------
       
   956 //
       
   957 CAknSettingStyleListBox* CAspAdvanceSettingsDialog::ListBox()
       
   958 	{
       
   959 	return iSettingListBox;
       
   960 	}
       
   961 
       
   962 
       
   963 // -----------------------------------------------------------------------------
       
   964 // CAspAdvanceSettingsDialog::UpdateCbaL
       
   965 // 
       
   966 // -----------------------------------------------------------------------------
       
   967 //
       
   968 void CAspAdvanceSettingsDialog::UpdateCbaL(TInt aResourceId)
       
   969 	{
       
   970 	CEikButtonGroupContainer& cba = ButtonGroupContainer();
       
   971 	cba.SetCommandSetL(aResourceId);
       
   972 	iCommandSetId = aResourceId;
       
   973 	iMSKEmpty = EFalse;
       
   974 	cba.DrawDeferred();
       
   975 	}
       
   976 
       
   977 // -----------------------------------------------------------------------------
       
   978 // CAspAdvanceSettingsDialog::UpdateMenuL
       
   979 // 
       
   980 // -----------------------------------------------------------------------------
       
   981 //
       
   982 
       
   983 void CAspAdvanceSettingsDialog::UpdateMenuL(TInt aResource)
       
   984 	{
       
   985 	CEikMenuBar* menuBar = iMenuBar; // from CAknDialog
       
   986 	menuBar->SetMenuTitleResourceId(aResource);
       
   987 
       
   988 	TRAPD(err, menuBar->TryDisplayMenuBarL());
       
   989     		
       
   990 	User::LeaveIfError(err);
       
   991 	
       
   992 			
       
   993 	}
       
   994 	
       
   995 // -----------------------------------------------------------------------------
       
   996 // CAspAdvanceSettingsDialog::UpdateMenuL
       
   997 // 
       
   998 // -----------------------------------------------------------------------------
       
   999 //
       
  1000 void CAspAdvanceSettingsDialog::WriteRepositoryL(TInt aKey, const TInt& aValue)
       
  1001     {
       
  1002     const TUid KCRRoamingSettingUID = {0x101F9A1D};
       
  1003     const TUid KRepositoryId = KCRRoamingSettingUID;
       
  1004 
       
  1005     CRepository* rep = CRepository::NewLC(KRepositoryId);
       
  1006     TInt err = rep->Set(aKey, aValue);
       
  1007     User::LeaveIfError(err);
       
  1008     
       
  1009     CleanupStack::PopAndDestroy(rep);
       
  1010     }
       
  1011 //  End of File