omads/omadsappui/AspSyncUtil/src/AspFilterDialog.cpp
changeset 19 2691f6aa1921
parent 4 e6e896426eac
child 20 e1de7d03f843
equal deleted inserted replaced
4:e6e896426eac 19:2691f6aa1921
     1 /*
       
     2 * Copyright (c) 2002-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 #include "AspFilterDialog.h"
       
    22 #include "AspFilter.h"
       
    23 #include "AspUtil.h"
       
    24 #include "AspDefines.h"
       
    25 #include "AspDialogUtil.h"
       
    26 #include "AspResHandler.h"
       
    27 #include "AspSyncUtil.rh"
       
    28 #include "AspDebug.h"
       
    29 
       
    30 #include <AknRadioButtonSettingPage.h>  // CAknRadioButtonSettingPage
       
    31 #include <AknCheckBoxSettingPage.h>  // CAknRadioButtonSettingPage
       
    32 #include <AknTextSettingPage.h>         // for CAknIntegerSettingPage
       
    33 
       
    34 //#include "ds.hlp.hrh"  // help text ids
       
    35 
       
    36 
       
    37 
       
    38 
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 
       
    41 
       
    42 /*******************************************************************************
       
    43  * class CAspMultiChoiceListSettingPage
       
    44  *******************************************************************************/
       
    45 
       
    46 
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CAspFilterDialog::ShowDialogL
       
    50 // 
       
    51 // -----------------------------------------------------------------------------
       
    52 TBool CAspFilterDialog::ShowDialogL(TAspParam& aParam)
       
    53 	{
       
    54 	CAspFilterDialog* dialog = CAspFilterDialog::NewL(aParam);
       
    55 
       
    56 	TBool ret = dialog->ExecuteLD(R_ASP_FILTER_DIALOG);
       
    57 
       
    58     return ret;
       
    59 	}
       
    60 
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CAspFilterDialog::NewL
       
    64 //
       
    65 // -----------------------------------------------------------------------------
       
    66 CAspFilterDialog* CAspFilterDialog::NewL(TAspParam& aParam)
       
    67     {
       
    68     CAspFilterDialog* self = new (ELeave) CAspFilterDialog(aParam);
       
    69     CleanupStack::PushL(self);
       
    70     self->ConstructL();
       
    71     CleanupStack::Pop(self);
       
    72 
       
    73     return( self );
       
    74     }
       
    75 
       
    76 
       
    77 //------------------------------------------------------------------------------
       
    78 // CAspFilterDialog::CAspFilterDialog
       
    79 //
       
    80 //------------------------------------------------------------------------------
       
    81 //
       
    82 CAspFilterDialog::CAspFilterDialog(TAspParam& aParam)
       
    83 	{
       
    84 	iApplicationId = aParam.iApplicationId;
       
    85 	iDialogParam = &aParam;
       
    86 	iFilter = aParam.iSyncFilter;
       
    87 	
       
    88     __ASSERT_ALWAYS(iFilter, TUtil::Panic(KErrGeneral));	
       
    89 	}
       
    90 
       
    91 
       
    92 //------------------------------------------------------------------------------
       
    93 // Destructor
       
    94 //
       
    95 //------------------------------------------------------------------------------
       
    96 //
       
    97 CAspFilterDialog::~CAspFilterDialog()
       
    98 	{
       
    99 	if (iSettingList)
       
   100 		{
       
   101 		iSettingList->ResetAndDestroy();
       
   102 	    delete iSettingList;
       
   103 		}
       
   104 
       
   105 	delete iStatusPaneHandler;
       
   106 	delete iResHandler;
       
   107 	
       
   108 	if (iAvkonAppUi)
       
   109 		{
       
   110 		iAvkonAppUi->RemoveFromStack(this);
       
   111 		}
       
   112 	}
       
   113 
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CAspFilterDialog::ConstructL
       
   117 //
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CAspFilterDialog::ConstructL()
       
   121     {
       
   122 	CAknDialog::ConstructL(R_ASP_FILTER_DIALOG_MENU);
       
   123 	
       
   124 	iResHandler = CAspResHandler::NewL();
       
   125     iSettingList = new (ELeave) CArrayPtrFlat<CAspListItemData>(10);
       
   126 	
       
   127 	// get previous title so it can be restored
       
   128 	iStatusPaneHandler = CStatusPaneHandler::NewL(iAvkonAppUi);
       
   129 	iStatusPaneHandler->StoreOriginalTitleL();
       
   130     } 
       
   131 
       
   132 
       
   133 //------------------------------------------------------------------------------
       
   134 // CAspFilterDialog::ActivateL (from CCoeControl)
       
   135 //
       
   136 // Called by system when dialog is activated
       
   137 //------------------------------------------------------------------------------
       
   138 //
       
   139 void CAspFilterDialog::ActivateL()
       
   140 	{
       
   141     CAknDialog::ActivateL();
       
   142 
       
   143 	// this cannot be in ConstructL which is executed before dialog is launched
       
   144 	iAvkonAppUi->AddToStackL(this);
       
   145     }
       
   146 
       
   147 
       
   148 //-----------------------------------------------------------------------------
       
   149 // CAspFilterDialog::HandleOKL
       
   150 //
       
   151 // Handle content parameter editing.
       
   152 //-----------------------------------------------------------------------------
       
   153 //
       
   154 void CAspFilterDialog::HandleOKL()
       
   155 	{
       
   156 	CAspListItemData* item = ItemForIndex(ListBox()->CurrentItemIndex());
       
   157 	item->iFilter = iFilter;
       
   158 
       
   159 	if (EditSettingItemL(*item))
       
   160 		{
       
   161 		SetVisibility();
       
   162 		UpdateListBoxL(ListBox(), iSettingList);
       
   163 		}
       
   164 	}
       
   165 
       
   166 
       
   167 //------------------------------------------------------------------------------
       
   168 // CAspFilterDialog::ProcessCommandL
       
   169 //
       
   170 // Handle menu commands.
       
   171 //------------------------------------------------------------------------------
       
   172 //
       
   173 void CAspFilterDialog::ProcessCommandL( TInt aCommandId )
       
   174 	{
       
   175 	HideMenu();
       
   176 
       
   177 	switch (aCommandId)
       
   178 		{
       
   179 		case EAspMenuCmdHelp:
       
   180 			{
       
   181             break;
       
   182 			}
       
   183 
       
   184 		case EAspMenuCmdChange:
       
   185 			{				
       
   186 			CAspListItemData* item = ItemForIndex(ListBox()->CurrentItemIndex());
       
   187 			item->iSelectKeyPressed = EFalse;
       
   188 			HandleOKL();
       
   189 
       
   190 			break;
       
   191 			}
       
   192 
       
   193         case EAspMenuCmdExit:
       
   194         case EAknCmdExit:
       
   195         case EEikCmdExit:
       
   196 			{
       
   197 			// close dialog and exit calling application
       
   198 			iAvkonAppUi->ProcessCommandL(EAknCmdExit);
       
   199 			break;
       
   200 			}
       
   201 
       
   202 
       
   203 		default:
       
   204 		    break;
       
   205 		}
       
   206 	
       
   207 	}
       
   208 
       
   209 
       
   210 //------------------------------------------------------------------------------
       
   211 // CAspFilterDialog::OkToExitL
       
   212 //
       
   213 //------------------------------------------------------------------------------
       
   214 //
       
   215 TBool CAspFilterDialog::OkToExitL(TInt aButtonId)
       
   216 	{
       
   217 	if (aButtonId == EEikBidCancel)
       
   218 		{
       
   219 		// save silently and quit application (= return ETrue)
       
   220 		TRAP_IGNORE(SaveSettingsL());
       
   221 	
       
   222 		return ETrue;
       
   223 		}
       
   224 
       
   225 	if ( aButtonId == EAknSoftkeyBack )
       
   226         {
       
   227 		TInt index = CheckMandatoryFieldsL();
       
   228 		if (index != KErrNotFound)
       
   229 			{
       
   230 			if (!TDialogUtil::ShowConfirmationQueryL(R_ASP_EXIT_ANYWAY))
       
   231 				{
       
   232 				ListBox()->SetCurrentItemIndexAndDraw(index);
       
   233 				return EFalse; // leave dialog open
       
   234 				}
       
   235 			}
       
   236 		
       
   237 		SaveSettingsL();
       
   238 		return ETrue;
       
   239 		}
       
   240 
       
   241 	return CAknDialog::OkToExitL(aButtonId);
       
   242 	}
       
   243 
       
   244 
       
   245 //------------------------------------------------------------------------------
       
   246 // CAspFilterDialog::OfferKeyEventL
       
   247 //
       
   248 // Handle key events.
       
   249 //------------------------------------------------------------------------------
       
   250 //
       
   251 TKeyResponse CAspFilterDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   252 	{
       
   253 
       
   254 	if (aType == EEventKey)
       
   255 		{
       
   256 		switch (aKeyEvent.iCode)
       
   257 			{
       
   258 			case EKeyEscape:  // framework calls this when dialog must shut down
       
   259 				{
       
   260 				return CAknDialog::OfferKeyEventL(aKeyEvent, aType);
       
   261         		}
       
   262 
       
   263 			case EKeyOK: // OK button
       
   264 				{
       
   265 				CAspListItemData* item = ItemForIndex(ListBox()->CurrentItemIndex());
       
   266 			    item->iSelectKeyPressed = ETrue;
       
   267 
       
   268 				HandleOKL();
       
   269 				return EKeyWasConsumed;
       
   270 				}
       
   271 			}
       
   272 		}
       
   273 
       
   274 	return CAknDialog::OfferKeyEventL(aKeyEvent, aType);
       
   275 	}
       
   276 
       
   277 
       
   278 //------------------------------------------------------------------------------
       
   279 // CAspFilterDialog::PreLayoutDynInitL
       
   280 //
       
   281 // Called by system before the dialog is shown.
       
   282 //------------------------------------------------------------------------------
       
   283 //
       
   284 void CAspFilterDialog::PreLayoutDynInitL()
       
   285 	{
       
   286 	iListBox = (CAknSettingStyleListBox*)Control(EAspFilterDialog);
       
   287 	
       
   288 	ListBox()->SetListBoxObserver(this);
       
   289 	ListBox()->CreateScrollBarFrameL( ETrue );
       
   290 	ListBox()->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto ); 
       
   291 	
       
   292     CreateSettingsListL();
       
   293     UpdateListBoxL(ListBox(), iSettingList);
       
   294 	
       
   295 	//Set title pane text
       
   296 	iStatusPaneHandler->SetTitleL(iFilter->DisplayName());
       
   297 	}
       
   298 
       
   299 
       
   300 
       
   301 //------------------------------------------------------------------------------
       
   302 // CAspFilterDialog::DynInitMenuPaneL
       
   303 //
       
   304 // Called by system before menu is shown.
       
   305 //------------------------------------------------------------------------------
       
   306 //
       
   307 void CAspFilterDialog::DynInitMenuPaneL( TInt aResourceID, CEikMenuPane* aMenuPane)
       
   308 	{
       
   309     if (aResourceID != R_ASP_FILTER_DIALOG_MENU_PANE)
       
   310 		{
       
   311 		return;
       
   312 		}
       
   313 
       
   314 	if (ListBox()->Model()->NumberOfItems() == 0)
       
   315 		{
       
   316 		TDialogUtil::DeleteMenuItem(aMenuPane, EAspMenuCmdChange);
       
   317 		}
       
   318 	}
       
   319 
       
   320 
       
   321 //------------------------------------------------------------------------------
       
   322 // CAspFilterDialog::HandleListBoxEventL
       
   323 //
       
   324 // Handle listbox events.
       
   325 //------------------------------------------------------------------------------
       
   326 //
       
   327 void CAspFilterDialog::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aEventType)
       
   328 	{
       
   329 	if (aEventType == EEventEnterKeyPressed || aEventType == EEventItemSingleClicked)
       
   330 		{
       
   331 		HandleOKL();
       
   332 		}
       
   333 	}
       
   334 
       
   335 
       
   336 // ----------------------------------------------------------------------------
       
   337 // CAspFilterDialog::UpdateListBoxL
       
   338 // 
       
   339 // Add settings headers into listbox.
       
   340 // ----------------------------------------------------------------------------
       
   341 //
       
   342 void CAspFilterDialog::UpdateListBoxL(CEikTextListBox* aListBox, CAspSettingList* aItemList)
       
   343 	{
       
   344 	CDesCArray* arr = (CDesCArray*)aListBox->Model()->ItemTextArray();
       
   345 	arr->Reset();
       
   346 
       
   347 	TInt count = aItemList->Count();
       
   348 	for (TInt index=0; index<count; index++ )
       
   349 		{
       
   350 	   	TBool convert = ETrue;
       
   351 
       
   352 		CAspListItemData* item = (*aItemList)[index];
       
   353 		if (item->iHidden != EVisibilityHidden)
       
   354 			{
       
   355 			HBufC* hBuf = item->ListItemTextL(convert);
       
   356 			CleanupStack::PushL(hBuf);
       
   357 
       
   358 			arr->AppendL(hBuf->Des());
       
   359 			
       
   360 			// store listbox index (from zero up) into setting item 
       
   361 			item->iIndex = arr->Count() - 1;
       
   362 
       
   363 			CleanupStack::PopAndDestroy(hBuf);
       
   364 			}
       
   365 		else
       
   366 			{
       
   367 			item->iIndex = KErrNotFound;
       
   368 			}
       
   369 		}
       
   370 
       
   371 	ListBox()->HandleItemAdditionL();
       
   372 	}
       
   373 
       
   374 
       
   375 // ----------------------------------------------------------------------------
       
   376 // CAspFilterDialog::CreateSettingsListL
       
   377 // 
       
   378 // Function creates setting list array (iSettingList).
       
   379 // ----------------------------------------------------------------------------
       
   380 //
       
   381 void CAspFilterDialog::CreateSettingsListL()
       
   382 	{
       
   383     TInt count = iFilter->ItemCount();	
       
   384 	for (TInt i=0; i<count; i++)
       
   385 		{
       
   386 		CAspFilterItem* item = iFilter->Item(i);
       
   387 		AddItemL(item);
       
   388 		}
       
   389 		
       
   390 	// write setting data into each CAspListItemData
       
   391 	count=iSettingList->Count();
       
   392 	for (TInt i=0; i<count; i++)
       
   393 		{
       
   394 		CAspListItemData* item = (*iSettingList)[i];
       
   395 		item->iFilter = iFilter;
       
   396 		
       
   397 		InitSettingItemL(item);
       
   398 		}
       
   399 
       
   400 	SetVisibility();  // find out what setting appear on UI
       
   401 	}
       
   402 
       
   403 
       
   404 // ----------------------------------------------------------------------------
       
   405 // CAspFilterDialog::AddItemL
       
   406 // 
       
   407 // ----------------------------------------------------------------------------
       
   408 //
       
   409 void CAspFilterDialog::AddItemL(CAspFilterItem* aFilterItem)
       
   410 	{
       
   411     CAspListItemData* item = CAspListItemData::NewLC();
       
   412 	item->SetHeaderL(aFilterItem->DisplayName());
       
   413 	item->iItemId =aFilterItem->Id();
       
   414 	item->iItemType = aFilterItem->DataType();
       
   415 	item->iMandatory = aFilterItem->IsMandatory();
       
   416 	
       
   417 	if (item->iMandatory)
       
   418 		{
       
   419 		item->SetDisplayValueL(R_ASP_MUST_BE_DEFINED);
       
   420 		}
       
   421 	else
       
   422 		{
       
   423 		item->SetDisplayValueL(R_ASP_SETTING_VALUE_NONE);
       
   424 		}
       
   425 		
       
   426 	iSettingList->AppendL(item);
       
   427 	CleanupStack::Pop(item);
       
   428 	}
       
   429 
       
   430 
       
   431 // -----------------------------------------------------------------------------
       
   432 // CAspFilterDialog::InitSettingItemL
       
   433 // 
       
   434 // -----------------------------------------------------------------------------
       
   435 //
       
   436 void CAspFilterDialog::InitSettingItemL(CAspListItemData* aItem)
       
   437 	{
       
   438 	__ASSERT_ALWAYS(aItem->iFilter, TUtil::Panic(KErrGeneral));
       
   439 	
       
   440 	CAspFilterItem* filterItem = aItem->iFilter->ItemForId(aItem->iItemId);
       
   441 	
       
   442 	if (filterItem->ListType() != CAspFilterItem::ETypeQuery)
       
   443 		{
       
   444 		aItem->SetValueL(filterItem->DisplayValueL());
       
   445 		return; // this filter item is list, not a single value
       
   446 		}
       
   447 	
       
   448 	
       
   449 	HBufC* hBuf = HBufC::NewLC(KBufSize255);
       
   450 	TPtr ptr = hBuf->Des();
       
   451 	
       
   452     	
       
   453 	switch (aItem->iItemType)
       
   454 		{
       
   455 		case CAspListItemData::ETypeNumber:
       
   456 			{
       
   457 			aItem->SetValueL(filterItem->IntL());
       
   458 		    aItem->iNumberData = filterItem->IntL();
       
   459             break;
       
   460 			}
       
   461 
       
   462 		case CAspListItemData::ETypeText:
       
   463 			{
       
   464 			filterItem->GetText(ptr);
       
   465    			aItem->SetValueL(ptr);
       
   466     		break;
       
   467 			}
       
   468 
       
   469 		case CAspListItemData::ETypeBoolean:
       
   470 			{
       
   471 			CDesCArray* stringData = CAspResHandler::ReadDesArrayStaticLC(R_ASP_FILTER_ITEM_YESNO);
       
   472 			
       
   473 			aItem->iNumberData = EAspSettingEnabled;      // 1;
       
   474 			if (!filterItem->BoolL())
       
   475 				{
       
   476 				aItem->iNumberData = EAspSettingDisabled; // 0;
       
   477 				}
       
   478 			
       
   479          	aItem->SetValueL((*stringData)[aItem->iNumberData]);
       
   480          	aItem->iResource = R_ASP_FILTER_ITEM_YESNO;
       
   481          	
       
   482          	CleanupStack::PopAndDestroy(stringData);
       
   483 			break;
       
   484      		}
       
   485 
       
   486 		case CAspListItemData::ETypeTime:
       
   487 			{
       
   488     		aItem->iTime = filterItem->TimeL();
       
   489     		if (aItem->iTime > 0)
       
   490     			{
       
   491     			TUtil::GetTimeTextL(ptr, aItem->iTime);
       
   492     		    aItem->SetValueL(ptr);
       
   493     			}
       
   494 	
       
   495 			break;
       
   496 			}
       
   497 
       
   498 		case CAspListItemData::ETypeDate:
       
   499 			{
       
   500     		aItem->iDate = filterItem->DateL();
       
   501     		if (aItem->iDate > 0)
       
   502     			{
       
   503     			TUtil::GetDateTextL(ptr, aItem->iDate);
       
   504     		    aItem->SetValueL(ptr);
       
   505     			}
       
   506 	
       
   507 			break;
       
   508 			}
       
   509 
       
   510         default:
       
   511 			TUtil::Panic(KErrArgument);
       
   512 			break;
       
   513 		
       
   514 		}
       
   515 		
       
   516 	CleanupStack::PopAndDestroy(hBuf);
       
   517 	}
       
   518 
       
   519 
       
   520 // -----------------------------------------------------------------------------
       
   521 // CAspFilterDialog::SetVisibility
       
   522 // 
       
   523 // -----------------------------------------------------------------------------
       
   524 //
       
   525 void CAspFilterDialog::SetVisibility()
       
   526 	{
       
   527 	}
       
   528 
       
   529 
       
   530 //------------------------------------------------------------------------------
       
   531 // CAspFilterDialog::SaveSettingsL
       
   532 //
       
   533 //------------------------------------------------------------------------------
       
   534 //
       
   535 void CAspFilterDialog::SaveSettingsL()
       
   536 	{
       
   537     iFilter->SaveL();
       
   538 	}
       
   539 
       
   540 
       
   541 //------------------------------------------------------------------------------
       
   542 // CAspFilterDialog::CheckMandatoryFieldsL
       
   543 //
       
   544 // Check that mandatory fields are filled correctly.
       
   545 //------------------------------------------------------------------------------
       
   546 //
       
   547 TInt CAspFilterDialog::CheckMandatoryFieldsL()
       
   548 	{ 
       
   549     TInt count = iSettingList->Count();
       
   550 	for (TInt i=0; i<count; i++)
       
   551 		{
       
   552 		CAspListItemData* item = (*iSettingList)[i];
       
   553 		if (item->iMandatory && item->IsEmpty())
       
   554 			{
       
   555 			return item->iIndex;
       
   556 			}
       
   557 		}
       
   558 		
       
   559 	return KErrNotFound;
       
   560 	}
       
   561 
       
   562 
       
   563 //------------------------------------------------------------------------------
       
   564 // CAspFilterDialog::EditFilterL
       
   565 //
       
   566 // NOTE: Function is not used by CAspFilterDialog. It can be called from
       
   567 // other dialogs in case filter only contains one filter item.
       
   568 //------------------------------------------------------------------------------
       
   569 //
       
   570 TBool CAspFilterDialog::EditFilterL(CAspListItemData& aItem)
       
   571 	{
       
   572     __ASSERT_ALWAYS(aItem.iFilter, TUtil::Panic(KErrGeneral));
       
   573 	
       
   574 	if (aItem.iFilter->ItemCount() != 1)
       
   575 		{
       
   576 		return EFalse; // this functions edits filter with one filter item
       
   577 		}
       
   578 		
       
   579 	CAspFilterItem* filterItem = aItem.iFilter->Item(0);
       
   580 		
       
   581 	__ASSERT_ALWAYS(filterItem, TUtil::Panic(KErrGeneral));
       
   582 	
       
   583 	
       
   584 	CAspListItemData* item = CAspListItemData::NewLC();
       
   585 	
       
   586 	item->SetHeaderL(filterItem->DisplayName());
       
   587 	item->iItemId = filterItem->Id();
       
   588 	item->iItemType = filterItem->DataType();
       
   589 	item->iMandatory = filterItem->IsMandatory();
       
   590 	
       
   591 	item->iSelectKeyPressed = aItem.iSelectKeyPressed;
       
   592 	item->iFilter = aItem.iFilter;
       
   593 
       
   594 	if (item->iMandatory)
       
   595 		{
       
   596 		item->SetDisplayValueL(R_ASP_MUST_BE_DEFINED);
       
   597 		}
       
   598 	else
       
   599 		{
       
   600 		item->SetDisplayValueL(R_ASP_SETTING_VALUE_NONE);
       
   601 		}
       
   602 	
       
   603 	InitSettingItemL(item);
       
   604 	
       
   605 	TBool ret = EditSettingItemL(*item);
       
   606 	
       
   607     CleanupStack::PopAndDestroy(item);
       
   608 	return ret;
       
   609 	}
       
   610 
       
   611 
       
   612 //------------------------------------------------------------------------------
       
   613 // CAspFilterDialog::EditSettingItemL
       
   614 //
       
   615 // Calls setting editing functions. 
       
   616 //------------------------------------------------------------------------------
       
   617 //
       
   618 TBool CAspFilterDialog::EditSettingItemL(CAspListItemData& aItem)
       
   619 	{
       
   620 	__ASSERT_ALWAYS(aItem.iFilter, TUtil::Panic(KErrGeneral));
       
   621 	
       
   622 	TBool ret = EFalse;
       
   623 
       
   624 	CAspFilterItem* filterItem = aItem.iFilter->ItemForId(aItem.iItemId);
       
   625     TInt type = filterItem->ListType();
       
   626     
       
   627 	switch (type)
       
   628 		{
       
   629 		case CAspFilterItem::ETypeQuery:
       
   630 			ret = EditSettingItemQueryL(aItem);
       
   631 		    break;
       
   632 
       
   633 		case CAspFilterItem::ETypeSingleSelection:
       
   634 			ret = EditSingleChoiceListL(aItem);
       
   635 		    break;
       
   636 		
       
   637 		case CAspFilterItem::ETypeSingleSelectionUserDefined:
       
   638 			ret = EditSingleChoiceListL(aItem);
       
   639 		    break;
       
   640 
       
   641 		case CAspFilterItem::ETypeMultipleSelection:
       
   642 		    ret = EditMultiChoiceListL(aItem);
       
   643 		   	break;
       
   644 
       
   645 		case CAspFilterItem::ETypeMultipleSelectionUserDefined:
       
   646 		    ret = EditMultiChoiceListL(aItem);
       
   647 		   	break;
       
   648 
       
   649 		default:
       
   650 		    break;
       
   651 
       
   652 		}
       
   653 
       
   654 	return ret;
       
   655 	}
       
   656 
       
   657 
       
   658 //------------------------------------------------------------------------------
       
   659 // CAspFilterDialog::EditSettingItemQueryL
       
   660 //
       
   661 //------------------------------------------------------------------------------
       
   662 //
       
   663 TBool CAspFilterDialog::EditSettingItemQueryL(CAspListItemData& aItem)
       
   664 	{
       
   665 	TBool ret = EFalse;
       
   666 	
       
   667 	switch (aItem.iItemType)
       
   668 		{
       
   669 		case CAspListItemData::ETypeText:
       
   670 			ret = EditSettingItemTextL(aItem);
       
   671 		    break;
       
   672 
       
   673 		case CAspListItemData::ETypeNumber:
       
   674 			ret = EditSettingItemNumberL(aItem);
       
   675 		    break;
       
   676 		
       
   677 		case CAspListItemData::ETypeBoolean:
       
   678 		    if (aItem.iSelectKeyPressed)
       
   679 		    	{
       
   680 		    	ret = EditSettingItemBooleanL(aItem);
       
   681 		    	}
       
   682 		    else
       
   683 		    	{
       
   684 		    	ret = EditSettingItemListL(aItem);
       
   685 		    	}
       
   686 		    break;
       
   687 
       
   688 		case CAspListItemData::ETypeTime:
       
   689 		    ret = EditSettingItemTimeL(aItem);
       
   690 		   	break;
       
   691 
       
   692 		case CAspListItemData::ETypeDate:
       
   693 		    ret = EditSettingItemDateL(aItem);
       
   694 		   	break;
       
   695 
       
   696 		default:
       
   697 		    break;
       
   698 
       
   699 		}
       
   700 
       
   701 	return ret;
       
   702 	}
       
   703 
       
   704 
       
   705 //------------------------------------------------------------------------------
       
   706 // CAspFilterDialog::EditSingleChoiceListL
       
   707 //
       
   708 //------------------------------------------------------------------------------
       
   709 //
       
   710 TBool CAspFilterDialog::EditSingleChoiceListL(CAspListItemData& aItem)
       
   711 	{
       
   712 	CAspSelectionItemList*	list = new (ELeave) CAspSelectionItemList(1);
       
   713 	CleanupStack::PushL(TCleanupItem(CAspSelectionItemList::Cleanup, list));
       
   714 
       
   715 	CAspFilterItem* filterItem = (aItem.iFilter)->ItemForId(aItem.iItemId);
       
   716 	TInt listType = filterItem->ListType();
       
   717 	TInt dataType = filterItem->DataType();
       
   718 	
       
   719 	TInt type = CAspChoiceList::ETypeNormal;
       
   720 	if (listType == CAspFilterItem::ETypeSingleSelectionUserDefined &&
       
   721 	    dataType == CAspListItemData::ETypeNumber)
       
   722 		{
       
   723 		type = CAspChoiceList::ETypeIntegerUserDefined;
       
   724 		}
       
   725 	
       
   726 	if (listType == CAspFilterItem::ETypeSingleSelectionUserDefined &&
       
   727 	    dataType == CAspListItemData::ETypeText)
       
   728 		{
       
   729 		type = CAspChoiceList::ETypeTextUserDefined;
       
   730 		}
       
   731 	
       
   732 	filterItem->GetSelectionL(list);
       
   733 	
       
   734 	CAspChoiceList* editor = CAspChoiceList::NewLC(filterItem->DisplayName(), list, type, filterItem->MaxLength());
       
   735 	
       
   736 	TBool ret = editor->ShowListL();
       
   737 	if (ret)
       
   738 		{
       
   739 		filterItem->SetSelectionL(list);
       
   740 		aItem.SetValueL(filterItem->DisplayValueL());
       
   741 		}
       
   742 		
       
   743 	
       
   744 	CleanupStack::PopAndDestroy(editor);
       
   745 	CleanupStack::PopAndDestroy(list);
       
   746 	
       
   747 	return ret;
       
   748 	}
       
   749 
       
   750 
       
   751 //------------------------------------------------------------------------------
       
   752 // CAspFilterDialog::EditMultiChoiceListL
       
   753 //
       
   754 //------------------------------------------------------------------------------
       
   755 //
       
   756 TBool CAspFilterDialog::EditMultiChoiceListL(CAspListItemData& aItem)
       
   757 	{
       
   758 	CAspSelectionItemList*	list = new (ELeave) CAspSelectionItemList(1);
       
   759 	CleanupStack::PushL(TCleanupItem(CAspSelectionItemList::Cleanup, list));
       
   760 	
       
   761 	CAspFilterItem* filterItem = aItem.iFilter->ItemForId(aItem.iItemId);
       
   762 	TInt listType = filterItem->ListType();
       
   763 	TInt dataType = filterItem->DataType();
       
   764 	
       
   765 	TInt type = CAspChoiceList::ETypeNormal;
       
   766 	if (listType == CAspFilterItem::ETypeMultipleSelectionUserDefined &&
       
   767 	    dataType == CAspListItemData::ETypeNumber)
       
   768 		{
       
   769 		type = CAspChoiceList::ETypeIntegerUserDefined;
       
   770 		}
       
   771 	if (listType == CAspFilterItem::ETypeMultipleSelectionUserDefined &&
       
   772 	    dataType == CAspListItemData::ETypeText)
       
   773 		{
       
   774 		type = CAspChoiceList::ETypeTextUserDefined;
       
   775 		}
       
   776 	
       
   777 	filterItem->GetSelectionL(list);
       
   778 	
       
   779 	CAspMultiChoiceList* editor = CAspMultiChoiceList::NewLC(filterItem->DisplayName(), list, type, filterItem->MaxLength());
       
   780 	
       
   781 	TBool ret = editor->ShowListL();
       
   782 	if (ret)
       
   783 		{
       
   784 		filterItem->SetSelectionL(list);
       
   785 		aItem.SetValueL(filterItem->DisplayValueL());
       
   786 		}
       
   787 	
       
   788 	
       
   789 	CleanupStack::PopAndDestroy(editor);
       
   790 	CleanupStack::PopAndDestroy(list);
       
   791 	
       
   792 	return ret;
       
   793 	}
       
   794 
       
   795 
       
   796 //------------------------------------------------------------------------------
       
   797 // CAspFilterDialog::EditSettingItemTextL
       
   798 //
       
   799 //------------------------------------------------------------------------------
       
   800 //
       
   801 TBool CAspFilterDialog::EditSettingItemTextL(CAspListItemData& aItem)
       
   802 	{
       
   803 	CAspFilterItem* filterItem = aItem.iFilter->ItemForId(aItem.iItemId);
       
   804 	
       
   805 	HBufC* hBuf = HBufC::NewLC(KBufSize255);
       
   806 	TPtr ptr = hBuf->Des();
       
   807 	
       
   808 	TUtil::StrCopy(ptr, aItem.Value());
       
   809 	
       
   810 	TBool ret = TDialogUtil::ShowTextEditorL(ptr, aItem.Header(), aItem.iMandatory, aItem.iLatinInput, filterItem->MaxLength());
       
   811 	if (ret)
       
   812 		{
       
   813 		aItem.SetValueL(ptr);
       
   814 		filterItem->SetTextL(ptr);
       
   815 		}
       
   816 		
       
   817 	CleanupStack::PopAndDestroy(hBuf);
       
   818 	return ret;
       
   819 	}
       
   820 
       
   821 
       
   822 //------------------------------------------------------------------------------
       
   823 // CAspFilterDialog::EditSettingItemListL
       
   824 //
       
   825 //------------------------------------------------------------------------------
       
   826 //
       
   827 TBool CAspFilterDialog::EditSettingItemListL(CAspListItemData& aItem)
       
   828 	{
       
   829 	CAspFilterItem* filterItem = aItem.iFilter->ItemForId(aItem.iItemId);
       
   830 	
       
   831 	TInt curSelection = aItem.iNumberData;
       
   832 	CDesCArray* stringData = CAspResHandler::ReadDesArrayStaticLC(aItem.iResource);
       
   833 	
       
   834 	TBool ret = TDialogUtil::ShowListEditorL(stringData, aItem.Header(), curSelection);
       
   835 	if (ret)
       
   836 		{
       
   837 		aItem.iNumberData = curSelection; 
       
   838 		aItem.SetValueL((*stringData)[curSelection]);
       
   839 		filterItem->SetIntL(aItem.iNumberData);
       
   840 		}
       
   841 
       
   842 	CleanupStack::PopAndDestroy(stringData);
       
   843 	return ret;
       
   844 	}
       
   845 
       
   846 
       
   847 //------------------------------------------------------------------------------
       
   848 // CAspFilterDialog::EditSettingItemBooleanL
       
   849 //
       
   850 // Change Yes/No value straight if ok key is pressed
       
   851 //------------------------------------------------------------------------------
       
   852 //
       
   853 TBool CAspFilterDialog::EditSettingItemBooleanL(CAspListItemData& aItem)
       
   854 	{
       
   855 	CAspFilterItem* filterItem = aItem.iFilter->ItemForId(aItem.iItemId);
       
   856 		
       
   857 	CDesCArray* stringData = CAspResHandler::ReadDesArrayStaticLC(R_ASP_FILTER_ITEM_YESNO);
       
   858 	
       
   859 	if (aItem.iNumberData == EAspSettingDisabled)
       
   860 		{
       
   861 		aItem.iNumberData = EAspSettingEnabled;
       
   862 		}
       
   863 	else
       
   864 		{
       
   865 		aItem.iNumberData = EAspSettingDisabled;
       
   866 		}
       
   867 	
       
   868 	aItem.SetValueL( (*stringData)[aItem.iNumberData] );
       
   869 	filterItem->SetIntL(aItem.iNumberData);
       
   870 
       
   871 	CleanupStack::PopAndDestroy(stringData);
       
   872 	return ETrue;
       
   873 	}
       
   874 
       
   875 
       
   876 //------------------------------------------------------------------------------
       
   877 // CAspFilterDialog::EditSettingItemNumberL
       
   878 //
       
   879 //------------------------------------------------------------------------------
       
   880 //
       
   881 TBool CAspFilterDialog::EditSettingItemNumberL(CAspListItemData& aItem)
       
   882 	{
       
   883 	CAspFilterItem* filterItem = aItem.iFilter->ItemForId(aItem.iItemId);
       
   884 		
       
   885 	TBool ret = TDialogUtil::ShowIntegerEditorL(aItem.iNumberData, aItem.Header(), aItem.iMinValue, aItem.iMaxValue);
       
   886 
       
   887 	if (ret)
       
   888 		{
       
   889 		aItem.SetValueL(aItem.iNumberData);
       
   890 		filterItem->SetIntL(aItem.iNumberData);
       
   891 		}
       
   892 
       
   893 	return ret;
       
   894 	}
       
   895 
       
   896 
       
   897 //------------------------------------------------------------------------------
       
   898 // CAspFilterDialog::EditSettingItemDateL
       
   899 //
       
   900 //------------------------------------------------------------------------------
       
   901 //
       
   902 TBool CAspFilterDialog::EditSettingItemDateL(CAspListItemData& aItem)
       
   903 	{
       
   904 	CAspFilterItem* filterItem = aItem.iFilter->ItemForId(aItem.iItemId);
       
   905 	
       
   906 	TBool ret = TDialogUtil::ShowDateEditorL(aItem.iDate, aItem.Header());
       
   907 
       
   908 	if (ret)
       
   909 		{
       
   910 		TBuf<KBufSize> buf;
       
   911 		TUtil::GetDateTextL(buf, aItem.iDate);
       
   912 	    aItem.SetValueL(buf);
       
   913         filterItem->SetDateL(aItem.iDate);
       
   914 		}
       
   915 
       
   916 	return ret;
       
   917 	}
       
   918 
       
   919 
       
   920 //------------------------------------------------------------------------------
       
   921 // CAspFilterDialog::EditSettingItemTimeL
       
   922 //
       
   923 //------------------------------------------------------------------------------
       
   924 //
       
   925 TBool CAspFilterDialog::EditSettingItemTimeL(CAspListItemData& aItem)
       
   926 	{
       
   927 	CAspFilterItem* filterItem = aItem.iFilter->ItemForId(aItem.iItemId);
       
   928 	
       
   929 	TBool ret = TDialogUtil::ShowTimeEditorL(aItem.iTime, aItem.Header());
       
   930 
       
   931 	if (ret)
       
   932 		{
       
   933 		TBuf<KBufSize> buf;
       
   934 		TUtil::GetTimeTextL(buf, aItem.iTime);
       
   935 	    aItem.SetValueL(buf);
       
   936         filterItem->SetTimeL(aItem.iTime);
       
   937 		}
       
   938 
       
   939 	return ret;
       
   940 	}
       
   941 
       
   942 
       
   943 //-----------------------------------------------------------------------------
       
   944 // CAspFilterDialog::ItemForIndex
       
   945 // 
       
   946 // Find item in list position aIndex.
       
   947 //-----------------------------------------------------------------------------
       
   948 //
       
   949 CAspListItemData* CAspFilterDialog::ItemForIndex(TInt aIndex)
       
   950 	{
       
   951 	CAspListItemData* item = NULL;
       
   952 	
       
   953 	TInt count = iSettingList->Count();
       
   954 	for (TInt i=0; i<count; i++)
       
   955 		{
       
   956 		CAspListItemData* temp = (*iSettingList)[i];
       
   957 		if (temp->iIndex == aIndex)
       
   958 			{
       
   959 			item = temp;
       
   960 			break;
       
   961 			}
       
   962 		}
       
   963 
       
   964 	__ASSERT_ALWAYS(item, TUtil::Panic(KErrGeneral));
       
   965 
       
   966     return item;
       
   967 	}
       
   968 
       
   969 
       
   970 //-----------------------------------------------------------------------------
       
   971 // CAspFilterDialog::Item
       
   972 // 
       
   973 // Find item with aItemId (TAspConnectionSettingItem).
       
   974 //-----------------------------------------------------------------------------
       
   975 //
       
   976 CAspListItemData* CAspFilterDialog::Item(TInt aItemId)
       
   977 	{
       
   978 	CAspListItemData* item = NULL;
       
   979 
       
   980 	TInt count = iSettingList->Count();
       
   981 	for (TInt i=0; i<count; i++)
       
   982 		{
       
   983 		CAspListItemData* temp = (*iSettingList)[i];
       
   984 		if (temp->iItemId == aItemId)
       
   985 			{
       
   986 			item = temp;
       
   987 			break;
       
   988 			}
       
   989 		}
       
   990 	
       
   991 	__ASSERT_ALWAYS(item, TUtil::Panic(KErrGeneral));
       
   992 
       
   993     return item;
       
   994 	}
       
   995 
       
   996 
       
   997 // -----------------------------------------------------------------------------
       
   998 // CAspFilterDialog::ResHandler
       
   999 // 
       
  1000 // -----------------------------------------------------------------------------
       
  1001 //
       
  1002 CAspResHandler* CAspFilterDialog::ResHandler()
       
  1003 	{
       
  1004 	__ASSERT_DEBUG(iResHandler, TUtil::Panic(KErrGeneral));
       
  1005 
       
  1006 	return iResHandler;
       
  1007 	}
       
  1008 
       
  1009 
       
  1010 // -----------------------------------------------------------------------------
       
  1011 // CAspFilterDialog::ListBox
       
  1012 // 
       
  1013 // -----------------------------------------------------------------------------
       
  1014 //
       
  1015 CAknSettingStyleListBox* CAspFilterDialog::ListBox()
       
  1016 	{
       
  1017     __ASSERT_DEBUG(iListBox, TUtil::Panic(KErrGeneral));	
       
  1018 	
       
  1019 	return iListBox;
       
  1020 	}
       
  1021 
       
  1022 
       
  1023 //------------------------------------------------------------------------------
       
  1024 // CAspFilterDialog::GetHelpContext
       
  1025 //
       
  1026 //------------------------------------------------------------------------------
       
  1027 //
       
  1028 void CAspFilterDialog::GetHelpContext(TCoeHelpContext& aContext) const
       
  1029 	{
       
  1030 	aContext.iMajor=KUidSmlSyncApp;
       
  1031 	//aContext.iContext=KDS_HLP_APPLICATION;
       
  1032 	}
       
  1033 
       
  1034 
       
  1035 
       
  1036 
       
  1037 
       
  1038 
       
  1039 /*******************************************************************************
       
  1040  * class CAspMultiChoiceListSettingPage
       
  1041  *******************************************************************************/
       
  1042 
       
  1043 
       
  1044 //------------------------------------------------------------------------------
       
  1045 // CAspMultiChoiceListSettingPage::ProcessCommandL
       
  1046 // 
       
  1047 //------------------------------------------------------------------------------
       
  1048 //
       
  1049 void CAspMultiChoiceListSettingPage::ProcessCommandL(TInt aCommandId)
       
  1050 	{
       
  1051 		
       
  1052 	if (iType == ETypeUserDefined && aCommandId == EAknSoftkeySelect)
       
  1053 		{
       
  1054 		CAknSetStyleListBox* listBox = ListBoxControl();
       
  1055 		TInt bottomIndex = listBox->BottomItemIndex();
       
  1056 		TInt currentIndex = listBox->CurrentItemIndex();
       
  1057 		
       
  1058 		TBool itemChecked = (*iSelectionList)[currentIndex]->SelectionStatus();
       
  1059 		
       
  1060 		if (bottomIndex == currentIndex && !itemChecked) //  "User defined" has focus and is checked
       
  1061 			{
       
  1062 			
       
  1063 			if (!iObserver->HandleChoiceListEventL(0, 0))
       
  1064 				{
       
  1065 				return;  // leave editor open if user defined editor is canceled
       
  1066 				}
       
  1067 			}
       
  1068 		}
       
  1069 		
       
  1070 	CAknCheckBoxSettingPage::ProcessCommandL(aCommandId);
       
  1071 	}
       
  1072 
       
  1073 
       
  1074 //------------------------------------------------------------------------------
       
  1075 // CAspMultiChoiceListSettingPage::CAspMultiChoiceListSettingPage
       
  1076 // 
       
  1077 //------------------------------------------------------------------------------
       
  1078 //
       
  1079 CAspMultiChoiceListSettingPage::CAspMultiChoiceListSettingPage(TInt aResourceID, CSelectionItemList* aItemArray,
       
  1080                                                                MAspChoiceListObserver* aObserver, TInt aType)
       
  1081  : CAknCheckBoxSettingPage(aResourceID, aItemArray)
       
  1082 	{
       
  1083 	iObserver = aObserver;
       
  1084 	iType = aType;
       
  1085 	iSelectionList = aItemArray;
       
  1086 	}
       
  1087 
       
  1088 
       
  1089 //------------------------------------------------------------------------------
       
  1090 // Destructor
       
  1091 // 
       
  1092 //------------------------------------------------------------------------------
       
  1093 //
       
  1094 CAspMultiChoiceListSettingPage::~CAspMultiChoiceListSettingPage()
       
  1095 	{
       
  1096 	}
       
  1097 
       
  1098 
       
  1099 
       
  1100 
       
  1101 /*******************************************************************************
       
  1102  * class CAspChoiceListSettingPage
       
  1103  *******************************************************************************/
       
  1104 
       
  1105 
       
  1106 //------------------------------------------------------------------------------
       
  1107 // CAspChoiceListSettingPage::ProcessCommandL
       
  1108 // 
       
  1109 //------------------------------------------------------------------------------
       
  1110 //
       
  1111 void CAspChoiceListSettingPage::ProcessCommandL(TInt aCommandId)
       
  1112 	{
       
  1113 		
       
  1114 	if (iType == ETypeUserDefined && aCommandId == EAknSoftkeySelect)
       
  1115 		{
       
  1116 		CAknSetStyleListBox* listBox = ListBoxControl();
       
  1117 		TInt num1 = listBox->BottomItemIndex();
       
  1118 		TInt num2 = listBox->CurrentItemIndex();
       
  1119 		
       
  1120 		if (num1 == num2)
       
  1121 			{
       
  1122 			if (!iObserver->HandleChoiceListEventL(0, 0))
       
  1123 				{
       
  1124 				return;  // leave editor open if user defined editor is canceled
       
  1125 				}
       
  1126 			}
       
  1127 		}
       
  1128 		
       
  1129 	CAknRadioButtonSettingPage::ProcessCommandL(aCommandId);
       
  1130 	}
       
  1131 
       
  1132 
       
  1133 //------------------------------------------------------------------------------
       
  1134 // CAspChoiceListSettingPage::CAspChoiceListSettingPage
       
  1135 // 
       
  1136 //------------------------------------------------------------------------------
       
  1137 //
       
  1138 CAspChoiceListSettingPage::CAspChoiceListSettingPage(TInt aResourceID, TInt& aCurrentSelectionIndex, 
       
  1139                                                      const MDesCArray* aItemArray,
       
  1140                                                      MAspChoiceListObserver* aObserver, TInt aType)
       
  1141  : CAknRadioButtonSettingPage(aResourceID, aCurrentSelectionIndex, aItemArray)
       
  1142 	{
       
  1143 	iObserver = aObserver;
       
  1144 	iType = aType;
       
  1145 	}
       
  1146 
       
  1147 
       
  1148 //------------------------------------------------------------------------------
       
  1149 // Destructor
       
  1150 // 
       
  1151 //------------------------------------------------------------------------------
       
  1152 //
       
  1153 CAspChoiceListSettingPage::~CAspChoiceListSettingPage()
       
  1154 	{
       
  1155 	}
       
  1156 
       
  1157 
       
  1158 
       
  1159 
       
  1160 	
       
  1161 /*******************************************************************************
       
  1162  * class CAspChoiceList
       
  1163  *******************************************************************************/
       
  1164 	
       
  1165 	
       
  1166 	
       
  1167 // -----------------------------------------------------------------------------
       
  1168 // CAspChoiceList::NewLC
       
  1169 //
       
  1170 // -----------------------------------------------------------------------------
       
  1171 CAspChoiceList* CAspChoiceList::NewLC(const TDesC& aTitle, CSelectionItemList* aList, TInt aType, TInt aMaxLength)
       
  1172     {
       
  1173     CAspChoiceList* self = new (ELeave) CAspChoiceList(aTitle, aList, aType, aMaxLength);
       
  1174     CleanupStack::PushL(self);
       
  1175     self->ConstructL();
       
  1176 
       
  1177     return(self);
       
  1178     }
       
  1179 
       
  1180 
       
  1181 //------------------------------------------------------------------------------
       
  1182 // CAspChoiceList::CAspChoiceList
       
  1183 // 
       
  1184 //------------------------------------------------------------------------------
       
  1185 //
       
  1186 CAspChoiceList::CAspChoiceList(const TDesC& aTitle, CSelectionItemList* aList, TInt aType, TInt aMaxLength)
       
  1187 	{
       
  1188 	__ASSERT_DEBUG(aList, TUtil::Panic(KErrGeneral));
       
  1189 	
       
  1190 	TUtil::StrCopy(iTitle, aTitle);
       
  1191 	iSelectionList = aList;
       
  1192 	iListType = aType;
       
  1193 	iMaxTextLength = aMaxLength;
       
  1194 	}
       
  1195 
       
  1196 
       
  1197 //------------------------------------------------------------------------------
       
  1198 // Destructor
       
  1199 // 
       
  1200 //------------------------------------------------------------------------------
       
  1201 //
       
  1202 CAspChoiceList::~CAspChoiceList()
       
  1203 	{
       
  1204 	}
       
  1205 
       
  1206 	
       
  1207 //------------------------------------------------------------------------------
       
  1208 // CAspChoiceList::ConstructL
       
  1209 // 
       
  1210 //------------------------------------------------------------------------------
       
  1211 //
       
  1212 void CAspChoiceList::ConstructL()
       
  1213 	{
       
  1214 	}
       
  1215 
       
  1216 
       
  1217 //------------------------------------------------------------------------------
       
  1218 // CAspChoiceList::ShowListL
       
  1219 // 
       
  1220 //------------------------------------------------------------------------------
       
  1221 //
       
  1222 TBool CAspChoiceList::ShowListL()
       
  1223 	{
       
  1224 	TInt current = SelectedIndex(iSelectionList);
       
  1225 	TInt listType = CAspChoiceListSettingPage::ETypeNormal;
       
  1226 	if (iListType != CAspChoiceList::ETypeNormal)
       
  1227 		{
       
  1228 		listType = CAspChoiceListSettingPage::ETypeUserDefined;
       
  1229 		AddUserDefinedL(); // replace last item text as "User defined"
       
  1230 		}
       
  1231 		
       
  1232 	CDesCArray* arr = DesArrayLC(iSelectionList);
       
  1233 
       
  1234 	CAspChoiceListSettingPage* dlg = new (ELeave) CAspChoiceListSettingPage(
       
  1235 	                                       R_ASP_SETTING_RADIO, current, arr, this, listType);
       
  1236 	CleanupStack::PushL(dlg);
       
  1237 	dlg->SetSettingTextL(iTitle); 
       
  1238 	CleanupStack::Pop(dlg);
       
  1239 
       
  1240 	TBool ret = dlg->ExecuteLD();
       
  1241 	
       
  1242 	SetSelectedIndex(iSelectionList, current);
       
  1243 	if (iListType != CAspChoiceList::ETypeNormal)
       
  1244 		{
       
  1245 		RemoveUserDefinedL(); // restore original last item text
       
  1246 		}
       
  1247 	
       
  1248 	CleanupStack::PopAndDestroy(arr);
       
  1249 	return ret;
       
  1250 	}
       
  1251 
       
  1252 
       
  1253 //------------------------------------------------------------------------------
       
  1254 // CAspChoiceList::DesArrayLC
       
  1255 // 
       
  1256 //------------------------------------------------------------------------------
       
  1257 //
       
  1258 CDesCArray* CAspChoiceList::DesArrayLC(CSelectionItemList* aList)
       
  1259 	{
       
  1260 	CDesCArray* arr = new (ELeave) CDesCArrayFlat(5);
       
  1261 	CleanupStack::PushL(arr);
       
  1262 	
       
  1263 	TInt count = aList->Count();
       
  1264 	for (TInt i=0; i<count; i++)
       
  1265 		{
       
  1266 		CSelectableItem* item = (*aList)[i];
       
  1267 		TBuf<128> buf(item->ItemText());
       
  1268 		arr->AppendL(item->ItemText());
       
  1269 		}
       
  1270 		
       
  1271 	return arr;
       
  1272 	}
       
  1273 
       
  1274 
       
  1275 //------------------------------------------------------------------------------
       
  1276 // CAspChoiceList::SelectedIndex
       
  1277 // 
       
  1278 //------------------------------------------------------------------------------
       
  1279 //
       
  1280 TInt CAspChoiceList::SelectedIndex(CSelectionItemList* aList)
       
  1281 	{
       
  1282     TInt count = aList->Count();
       
  1283 	for (TInt i=0; i<count; i++)
       
  1284 		{
       
  1285 		CSelectableItem* item = (*aList)[count-1];
       
  1286 		if (item->SelectionStatus())
       
  1287 			{
       
  1288 			return i;
       
  1289 			}
       
  1290 		}
       
  1291 		
       
  1292 	return KErrNotFound;
       
  1293 	}
       
  1294 
       
  1295 
       
  1296 //------------------------------------------------------------------------------
       
  1297 // CAspChoiceList::SetSelectedIndex
       
  1298 // 
       
  1299 //------------------------------------------------------------------------------
       
  1300 //
       
  1301 void CAspChoiceList::SetSelectedIndex(CSelectionItemList* aList, TInt aIndex)
       
  1302 	{
       
  1303     TInt count = aList->Count();
       
  1304     
       
  1305     __ASSERT_DEBUG(aIndex<count, TUtil::Panic(KErrGeneral));
       
  1306     
       
  1307 	for (TInt i=0; i<count; i++)
       
  1308 		{
       
  1309 		CSelectableItem* item = (*aList)[i];
       
  1310 		if (i == aIndex)
       
  1311 			{
       
  1312 			item->SetSelectionStatus(ETrue);
       
  1313 			}
       
  1314 		else
       
  1315 			{
       
  1316 			item->SetSelectionStatus(EFalse);
       
  1317 			}
       
  1318 		}
       
  1319 	}
       
  1320 
       
  1321 
       
  1322 //------------------------------------------------------------------------------
       
  1323 // CAspChoiceList::AddItemL
       
  1324 // 
       
  1325 //------------------------------------------------------------------------------
       
  1326 //
       
  1327 void CAspChoiceList::AddItemL(CSelectionItemList* aList, TDes& aText, TBool aEnable)
       
  1328 	{
       
  1329 	CSelectableItem* item = new (ELeave) CSelectableItem(aText, aEnable);
       
  1330    	CleanupStack::PushL(item);
       
  1331 	item->ConstructL();
       
  1332 	aList->AppendL(item);
       
  1333 	CleanupStack::Pop(item);
       
  1334 	}
       
  1335 	
       
  1336 
       
  1337 //------------------------------------------------------------------------------
       
  1338 // CAspChoiceList::AddUserDefined
       
  1339 // 
       
  1340 //------------------------------------------------------------------------------
       
  1341 //
       
  1342 void CAspChoiceList::AddUserDefinedL()
       
  1343 	{
       
  1344 	TInt count = iSelectionList->Count();
       
  1345 	CSelectableItem* item = (*iSelectionList)[count-1];
       
  1346 	
       
  1347 	TBool selected = item->SelectionStatus();
       
  1348 	iUserDefinedText = item->ItemText();
       
  1349 	if (iListType == CAspChoiceList::ETypeIntegerUserDefined)
       
  1350 		{
       
  1351 		User::LeaveIfError(TUtil::StrToInt(iUserDefinedText, iUserDefinedInt));
       
  1352 		}
       
  1353 
       
  1354 	
       
  1355 	delete item;
       
  1356 	iSelectionList->Delete(count-1);
       
  1357 	iSelectionList->Compress();
       
  1358 
       
  1359 	TBuf<KBufSize> buf;
       
  1360 	CAspResHandler::ReadL(buf, R_ASP_LIST_USER_DEFINED);
       
  1361 	
       
  1362 	
       
  1363 	AddItemL(iSelectionList, buf, selected);
       
  1364 	}
       
  1365 
       
  1366 
       
  1367 //------------------------------------------------------------------------------
       
  1368 // CAspChoiceList::RemoveUserDefined
       
  1369 // 
       
  1370 //------------------------------------------------------------------------------
       
  1371 //
       
  1372 void CAspChoiceList::RemoveUserDefinedL()
       
  1373 	{
       
  1374 	TInt count = iSelectionList->Count();
       
  1375 	CSelectableItem* item = (*iSelectionList)[count-1];
       
  1376     TBool selected = item->SelectionStatus();
       
  1377 
       
  1378 	delete item;
       
  1379 	iSelectionList->Delete(count-1);
       
  1380 	iSelectionList->Compress();
       
  1381 
       
  1382 	if (iListType == CAspChoiceList::ETypeIntegerUserDefined)
       
  1383 		{
       
  1384 		iUserDefinedText.Num(iUserDefinedInt);
       
  1385 		}
       
  1386 	AddItemL(iSelectionList, iUserDefinedText, selected);
       
  1387 	}
       
  1388 
       
  1389 
       
  1390 //------------------------------------------------------------------------------
       
  1391 // CAspChoiceList::EditTextL
       
  1392 //
       
  1393 //------------------------------------------------------------------------------
       
  1394 //
       
  1395 TBool CAspChoiceList::EditTextL(TDes& aText, const TDesC& aTitle)
       
  1396 	{
       
  1397 	TBool mandatory = EFalse;
       
  1398 	TBool latinInput = ETrue;
       
  1399 	TInt maxLength = iMaxTextLength;
       
  1400 	
       
  1401 	return TDialogUtil::ShowTextEditorL(aText, aTitle, mandatory, latinInput, maxLength);
       
  1402 	}
       
  1403 
       
  1404 
       
  1405 //------------------------------------------------------------------------------
       
  1406 // CAspChoiceList::HandleChoiceListEventL
       
  1407 // 
       
  1408 //------------------------------------------------------------------------------
       
  1409 //
       
  1410 TBool CAspChoiceList::HandleChoiceListEventL(TInt /*aEvent*/, TInt /*aListType*/)
       
  1411 	{
       
  1412 	if (iListType == CAspChoiceList::ETypeIntegerUserDefined)
       
  1413 		{
       
  1414 		return TDialogUtil::ShowIntegerEditorL(iUserDefinedInt, iTitle, KErrNotFound, KErrNotFound);
       
  1415 		}
       
  1416 	else if (iListType == CAspChoiceList::ETypeTextUserDefined)
       
  1417 		{
       
  1418 		return EditTextL(iUserDefinedText, iTitle);
       
  1419 		}
       
  1420 		
       
  1421 	return EFalse;
       
  1422 	}
       
  1423 
       
  1424 	
       
  1425 	
       
  1426 	
       
  1427 /*******************************************************************************
       
  1428  * class CAspMultiChoiceList
       
  1429  *******************************************************************************/
       
  1430 	
       
  1431 	
       
  1432 // -----------------------------------------------------------------------------
       
  1433 // CAspMultiChoiceList::NewLC
       
  1434 //
       
  1435 // -----------------------------------------------------------------------------
       
  1436 CAspMultiChoiceList* CAspMultiChoiceList::NewLC(const TDesC& aTitle, CSelectionItemList* aList, TInt aType, TInt aMaxLength)
       
  1437     {
       
  1438     CAspMultiChoiceList* self = new (ELeave) CAspMultiChoiceList(aTitle, aList, aType, aMaxLength);
       
  1439     CleanupStack::PushL(self);
       
  1440     self->ConstructL();
       
  1441 
       
  1442     return(self);
       
  1443     }
       
  1444 
       
  1445 
       
  1446 //------------------------------------------------------------------------------
       
  1447 // CAspMultiChoiceList::CAspMultiChoiceList
       
  1448 // 
       
  1449 //------------------------------------------------------------------------------
       
  1450 //
       
  1451 CAspMultiChoiceList::CAspMultiChoiceList(const TDesC& aTitle, CSelectionItemList* aList, TInt aType, TInt aMaxLength)
       
  1452 	{
       
  1453 	__ASSERT_DEBUG(aList, TUtil::Panic(KErrGeneral));
       
  1454 	
       
  1455 	TUtil::StrCopy(iTitle, aTitle);
       
  1456 	iSelectionList = aList;
       
  1457 	iListType = aType;
       
  1458 	iMaxTextLength = aMaxLength;
       
  1459 	}
       
  1460 
       
  1461 
       
  1462 //------------------------------------------------------------------------------
       
  1463 // Destructor
       
  1464 // 
       
  1465 //------------------------------------------------------------------------------
       
  1466 //
       
  1467 CAspMultiChoiceList::~CAspMultiChoiceList()
       
  1468 	{
       
  1469 	}
       
  1470 	
       
  1471 	
       
  1472 //------------------------------------------------------------------------------
       
  1473 // CAspMultiChoiceList::ConstructL
       
  1474 // 
       
  1475 //------------------------------------------------------------------------------
       
  1476 //
       
  1477 void CAspMultiChoiceList::ConstructL()
       
  1478 	{
       
  1479 	}
       
  1480 
       
  1481 
       
  1482 //------------------------------------------------------------------------------
       
  1483 // CAspMultiChoiceList::ShowListL
       
  1484 // 
       
  1485 //------------------------------------------------------------------------------
       
  1486 //
       
  1487 TBool CAspMultiChoiceList::ShowListL()
       
  1488 	{
       
  1489 	TInt listType = CAspChoiceListSettingPage::ETypeNormal;
       
  1490 	if (iListType != CAspChoiceList::ETypeNormal)
       
  1491 		{
       
  1492 		listType = CAspChoiceListSettingPage::ETypeUserDefined;
       
  1493 		AddUserDefinedL(); // replace last item text as "User defined"
       
  1494 		}
       
  1495 	
       
  1496 
       
  1497 	CAspMultiChoiceListSettingPage* dlg = new (ELeave) CAspMultiChoiceListSettingPage(
       
  1498 	                                       R_ASP_SETTING_RADIO, iSelectionList, this, listType);
       
  1499 	CleanupStack::PushL(dlg);
       
  1500 	dlg->SetSettingTextL(iTitle); 
       
  1501 	CleanupStack::Pop(dlg);
       
  1502 
       
  1503 	TBool ret = dlg->ExecuteLD();
       
  1504 	
       
  1505 	if (iListType != CAspChoiceList::ETypeNormal)
       
  1506 		{
       
  1507 		RemoveUserDefinedL(); // set original last item text
       
  1508 		}
       
  1509 	
       
  1510 	return ret;
       
  1511 	}
       
  1512 
       
  1513 
       
  1514 //------------------------------------------------------------------------------
       
  1515 // CAspMultiChoiceList::AddItemL
       
  1516 // 
       
  1517 //------------------------------------------------------------------------------
       
  1518 //
       
  1519 void CAspMultiChoiceList::AddItemL(CSelectionItemList* aList, TDes& aText, TBool aEnable)
       
  1520 	{
       
  1521 	CSelectableItem* item = new (ELeave) CSelectableItem(aText, aEnable);
       
  1522    	CleanupStack::PushL(item);
       
  1523 	item->ConstructL();
       
  1524 	aList->AppendL(item);
       
  1525 	CleanupStack::Pop(item);
       
  1526 	}
       
  1527 
       
  1528 
       
  1529 //------------------------------------------------------------------------------
       
  1530 // CAspMultiChoiceList::AddItemL
       
  1531 // 
       
  1532 //------------------------------------------------------------------------------
       
  1533 //
       
  1534 void CAspMultiChoiceList::AddItemL(TDes& aText, TBool aEnable)
       
  1535 	{
       
  1536 	AddItemL(iSelectionList, aText, aEnable);
       
  1537 	}
       
  1538 	
       
  1539 	
       
  1540 //------------------------------------------------------------------------------
       
  1541 // CAspMultiChoiceList::AddItemL
       
  1542 // 
       
  1543 //------------------------------------------------------------------------------
       
  1544 //
       
  1545 void CAspMultiChoiceList::AddItemL(TInt aNumber, TBool aEnable)
       
  1546 	{
       
  1547 	TBuf<KBufSize> buf;
       
  1548 	
       
  1549 	buf.Num(aNumber);
       
  1550 	AddItemL(iSelectionList, buf, aEnable);
       
  1551 	}
       
  1552 
       
  1553 
       
  1554 //------------------------------------------------------------------------------
       
  1555 // CAspMultiChoiceList::AddUserDefined
       
  1556 // 
       
  1557 //------------------------------------------------------------------------------
       
  1558 //
       
  1559 void CAspMultiChoiceList::AddUserDefinedL()
       
  1560 	{
       
  1561 	TInt count = iSelectionList->Count();
       
  1562 	CSelectableItem* item = (*iSelectionList)[count-1];
       
  1563 	
       
  1564 	TBool selected = item->SelectionStatus();
       
  1565 	iUserDefinedText = item->ItemText();
       
  1566 	if (iListType == CAspChoiceList::ETypeIntegerUserDefined)
       
  1567 		{
       
  1568 		User::LeaveIfError(TUtil::StrToInt(iUserDefinedText, iUserDefinedInt));
       
  1569 		}
       
  1570 
       
  1571 	
       
  1572 	delete item;
       
  1573 	iSelectionList->Delete(count-1);
       
  1574 	iSelectionList->Compress();
       
  1575 
       
  1576 	TBuf<KBufSize> buf;
       
  1577 	CAspResHandler::ReadL(buf, R_ASP_LIST_USER_DEFINED);
       
  1578 	
       
  1579 	
       
  1580 	AddItemL(iSelectionList, buf, selected);
       
  1581 	}
       
  1582 
       
  1583 
       
  1584 //------------------------------------------------------------------------------
       
  1585 // CAspMultiChoiceList::RemoveUserDefined
       
  1586 // 
       
  1587 //------------------------------------------------------------------------------
       
  1588 //
       
  1589 void CAspMultiChoiceList::RemoveUserDefinedL()
       
  1590 	{
       
  1591 	TInt count = iSelectionList->Count();
       
  1592 	CSelectableItem* item = (*iSelectionList)[count-1];
       
  1593     TBool selected = item->SelectionStatus();
       
  1594 
       
  1595 	delete item;
       
  1596 	iSelectionList->Delete(count-1);
       
  1597 	iSelectionList->Compress();
       
  1598 
       
  1599 	if (iListType == CAspChoiceList::ETypeIntegerUserDefined)
       
  1600 		{
       
  1601 		iUserDefinedText.Num(iUserDefinedInt);
       
  1602 		}
       
  1603 	AddItemL(iSelectionList, iUserDefinedText, selected);
       
  1604 	}
       
  1605 
       
  1606 
       
  1607 //------------------------------------------------------------------------------
       
  1608 // CAspMultiChoiceList::EditTextL
       
  1609 //
       
  1610 //------------------------------------------------------------------------------
       
  1611 //
       
  1612 TBool CAspMultiChoiceList::EditTextL(TDes& aText, const TDesC& aTitle)
       
  1613 	{
       
  1614 	TBool mandatory = ETrue;
       
  1615 	TBool latinInput = ETrue;
       
  1616 	TInt maxLength = iMaxTextLength;
       
  1617 	
       
  1618 	return TDialogUtil::ShowTextEditorL(aText, aTitle, mandatory, latinInput, maxLength);
       
  1619 	}
       
  1620 
       
  1621 
       
  1622 //------------------------------------------------------------------------------
       
  1623 // CAspMultiChoiceList::HandleChoiceListEventL
       
  1624 // 
       
  1625 //------------------------------------------------------------------------------
       
  1626 //
       
  1627 TBool CAspMultiChoiceList::HandleChoiceListEventL(TInt /*aEvent*/, TInt /*aListType*/)
       
  1628 	{
       
  1629 	if (iListType == CAspChoiceList::ETypeIntegerUserDefined)
       
  1630 		{
       
  1631 		return TDialogUtil::ShowIntegerEditorL(iUserDefinedInt, iTitle, KErrNotFound, KErrNotFound);
       
  1632 		}
       
  1633 	else if (iListType == CAspChoiceList::ETypeTextUserDefined)
       
  1634 		{
       
  1635 		return EditTextL(iUserDefinedText, iTitle);
       
  1636 		}
       
  1637 		
       
  1638 	return EFalse;
       
  1639 	}
       
  1640 
       
  1641 
       
  1642 
       
  1643 // End of file