vpnui/vpnmanagementui/src/vpnmanagementuipolicycontainer.cpp
branchRCL_3
changeset 24 e06095241a65
equal deleted inserted replaced
23:473321461bba 24:e06095241a65
       
     1 /*
       
     2 * Copyright (c) 2003-2009 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: Policy view container
       
    15 *
       
    16 */
       
    17 
       
    18 #include <eikclbd.h>
       
    19 #include <AknIconArray.h>
       
    20 #include <AknQueryDialog.h>
       
    21 #include <aknnotewrappers.h>
       
    22 #include <sysutil.h>
       
    23 #include <ErrorUI.h>
       
    24 #include <vpnmanagementuirsc.rsg>
       
    25 #include "vpnuiloader.h"
       
    26 #include "vpnmanagementuipolicycontainer.h"
       
    27 #include "vpnmanagementui.hrh"
       
    28 #include "vpnextapi.h"
       
    29 
       
    30 #ifdef __SERIES60_HELP
       
    31 #include <csxhelp/vpn.hlp.hrh> // for help context of VPN Management UI
       
    32 #endif //__SERIES60_HELP
       
    33 
       
    34 // ================= MEMBER FUNCTIONS =======================
       
    35 
       
    36 // ---------------------------------------------------------
       
    37 // CVpnManagementUiPolicyContainer::CVpnManagementUiPolicyContainer(
       
    38 // CVpnManagementUiPolicyView& aParent, CVpnUiLoader& aLoader)
       
    39 // Constructor with parent
       
    40 // ---------------------------------------------------------
       
    41 //
       
    42 CVpnManagementUiPolicyContainer::CVpnManagementUiPolicyContainer(
       
    43     CVpnManagementUiPolicyView& aParent, CVpnUiLoader& aLoader ) : 
       
    44     iParent ( aParent ), iLoader ( aLoader )
       
    45     {
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------
       
    49 // CVpnManagementUiPolicyContainer::~CVpnManagementUiPolicyContainer()
       
    50 // Destructor
       
    51 // ---------------------------------------------------------
       
    52 //
       
    53 CVpnManagementUiPolicyContainer::~CVpnManagementUiPolicyContainer()
       
    54     {
       
    55 	delete iListBox;
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------
       
    59 // CVpnManagementUiPolicyContainer::ConstructL(
       
    60 // const TRect& aRect, TInt& aCurrentPosition, TInt& aTopItem)
       
    61 // EPOC two phased constructor
       
    62 // ---------------------------------------------------------
       
    63 //
       
    64 void CVpnManagementUiPolicyContainer::ConstructL(
       
    65     const TRect& aRect, TInt& /*aCurrentPosition*/, TInt& /*aTopItem*/ )
       
    66     {
       
    67 	CreateWindowL();
       
    68     CreateListBoxL();
       
    69     
       
    70     //Initialization
       
    71 
       
    72     
       
    73     ShowPoliciesL();
       
    74 	SetRect( aRect );
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------
       
    78 // CVpnManagementUiPolicyContainer::ActivateL()
       
    79 // called after the dialog is shown
       
    80 // used to handle empty list - query
       
    81 // ---------------------------------------------------------
       
    82 //
       
    83 void CVpnManagementUiPolicyContainer::ActivateL()
       
    84     {
       
    85     CCoeControl::ActivateL();
       
    86 
       
    87     }
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------
       
    91 // CVpnManagementUiPolicyContainer::SizeChanged()
       
    92 // Called by framework when the view size is changed
       
    93 // ---------------------------------------------------------
       
    94 //
       
    95 void CVpnManagementUiPolicyContainer::SizeChanged()
       
    96     {
       
    97     iListBox->SetRect(Rect());
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------
       
   101 // CVpnManagementUiPolicyContainer::FocusChanged(TDrawNow aDrawNow)
       
   102 // ---------------------------------------------------------
       
   103 //
       
   104 void CVpnManagementUiPolicyContainer::FocusChanged(TDrawNow aDrawNow)
       
   105 	{
       
   106 	if ( iListBox ) 
       
   107 		{
       
   108 		iListBox->SetFocus( IsFocused(), aDrawNow );
       
   109 		}
       
   110 	}
       
   111 
       
   112 // ---------------------------------------------------------
       
   113 // CVpnManagementUiPolicyContainer::HandleResourceChangeL
       
   114 // ---------------------------------------------------------
       
   115 //
       
   116 
       
   117 void CVpnManagementUiPolicyContainer::HandleResourceChange( TInt aType )
       
   118     {
       
   119     CCoeControl::HandleResourceChange(aType); 
       
   120      
       
   121     //Handle change in layout orientation
       
   122     if (aType == KEikDynamicLayoutVariantSwitch || aType == KAknsMessageSkinChange )
       
   123         {
       
   124         iListBox->HandleResourceChange(aType);
       
   125         TRect mainPaneRect;
       
   126         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
       
   127         SetRect(mainPaneRect);
       
   128 		DrawNow();
       
   129 		}
       
   130     }    
       
   131     
       
   132 // ---------------------------------------------------------
       
   133 // CVpnManagementUiPolicyContainer::HandleListBoxEventL(
       
   134 // CEikListBox* /*aListBox*/, TListBoxEvent aEventType)
       
   135 // ---------------------------------------------------------
       
   136 //
       
   137 void CVpnManagementUiPolicyContainer::HandleListBoxEventL(
       
   138     CEikListBox* /*aListBox*/, TListBoxEvent aEventType )
       
   139 	{
       
   140     switch(aEventType)
       
   141         {
       
   142         case EEventEnterKeyPressed: 
       
   143         case EEventItemSingleClicked:
       
   144             iParent.HandleCommandL(EVpnUiCmdPolicyDetails);        
       
   145             break;
       
   146         default:  
       
   147             //Do nothing          
       
   148             break;
       
   149         }        
       
   150 	}
       
   151 enum { EListBoxControl, ENumberOfControls };
       
   152 
       
   153 // ---------------------------------------------------------
       
   154 // CVpnManagementUiPolicyContainer::CountComponentControls() const
       
   155 // ---------------------------------------------------------
       
   156 //
       
   157 TInt CVpnManagementUiPolicyContainer::CountComponentControls() const
       
   158     {
       
   159 	// return number of controls inside this container
       
   160     return ENumberOfControls; // return nbr of controls inside this container
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------
       
   164 // CVpnManagementUiPolicyContainer::ComponentControl(TInt aIndex) const
       
   165 // ---------------------------------------------------------
       
   166 //
       
   167 CCoeControl* CVpnManagementUiPolicyContainer::ComponentControl(TInt aIndex) const
       
   168     {
       
   169     switch ( aIndex )
       
   170         {
       
   171         case 0:
       
   172 			return iListBox;
       
   173         default:
       
   174             return NULL;
       
   175         }
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------
       
   179 // CVpnManagementUiPolicyContainer::HandleControlEventL(
       
   180 //    CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
       
   181 // Cannot be changed to non-leaving function. 
       
   182 // L-function is required by the class definition, even if empty.
       
   183 // ---------------------------------------------------------
       
   184 //
       
   185 void CVpnManagementUiPolicyContainer::HandleControlEventL(
       
   186     CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
       
   187     {
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------
       
   191 // CVpnManagementUiPolicyContainer::OfferKeyEventL(
       
   192 // const TKeyEvent& aKeyEvent, TEventCode aType)
       
   193 // Handles the key events OK button, arrow keys, delete key.
       
   194 // OK button functionality is different depending on the number of marked items
       
   195 // in the list; zero marked -> show details view, one or more marked -> show
       
   196 // OKOptions list, list empty -> OK inactive.
       
   197 // Delete active only if list not empty.
       
   198 // ---------------------------------------------------------
       
   199 //
       
   200 TKeyResponse CVpnManagementUiPolicyContainer::OfferKeyEventL(
       
   201     const TKeyEvent& aKeyEvent, TEventCode aType)
       
   202 	{
       
   203 
       
   204     // If operation is currenly onway, do not continue.
       
   205 	TKeyResponse retval = EKeyWasNotConsumed;
       
   206 	if ( aType==EEventKey )
       
   207 		{
       
   208 		if ( (aKeyEvent.iCode == EKeyOK || aKeyEvent.iCode == EKeyEnter) && // select or enter
       
   209             iListBox->CurrentItemIndex() > -1) //This is for empty list
       
   210             {
       
   211 	        // Selection key pressed.
       
   212             iParent.PolicyDetailsL(iListBox->CurrentItemIndex());
       
   213 
       
   214 			retval = EKeyWasConsumed;	
       
   215 			}
       
   216 
       
   217 		else if ( aKeyEvent.iCode == EKeyDelete 
       
   218                   || aKeyEvent.iCode == EKeyBackspace )
       
   219 			{
       
   220 			if ( iListBox->CurrentItemIndex() > -1 )
       
   221 				{
       
   222 				iParent.HandleCommandL( EVpnUiCmdDeletePolicy );
       
   223 				retval = EKeyWasConsumed; 
       
   224 				}
       
   225 			}
       
   226 		else
       
   227 			{
       
   228 			retval = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   229 			}
       
   230 		}
       
   231 	else
       
   232 		{
       
   233 		retval = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   234 		}
       
   235 
       
   236 
       
   237     return retval;
       
   238 	}
       
   239 
       
   240 // ---------------------------------------------------------
       
   241 // CVpnManagementUiPolicyContainer::CreateListBoxL()
       
   242 // Creates listbox, sets empty listbox text.
       
   243 // ---------------------------------------------------------
       
   244 //
       
   245 void CVpnManagementUiPolicyContainer::CreateListBoxL()
       
   246 	{
       
   247 
       
   248 	iListBox = new( ELeave ) CAknSingleStyleListBox;
       
   249 	iListBox->SetContainerWindowL( *this );
       
   250 	iListBox->ConstructL( this, EAknListBoxMarkableList ); 
       
   251 	iListBox->CreateScrollBarFrameL( ETrue );
       
   252 	iListBox->ScrollBarFrame()->
       
   253         SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto );
       
   254 	iListBox->SetListBoxObserver(this);
       
   255 
       
   256 	HBufC* stringHolder = StringLoader::LoadLC( R_VPN_POLICIES_EMPTY );
       
   257 	iListBox->View()->SetListEmptyTextL( *stringHolder );
       
   258 	CleanupStack::PopAndDestroy();  // stringHolder
       
   259 
       
   260 	}
       
   261 
       
   262 // ---------------------------------------------------------
       
   263 // CVpnManagementUiPolicyContainer::DrawListBoxL(TInt aCurrentPosition, TInt aTopItem)
       
   264 // Draws listbox, fetches graphic icons for markable list
       
   265 // ---------------------------------------------------------
       
   266 //
       
   267 void CVpnManagementUiPolicyContainer::DrawListBoxL( 
       
   268     TInt aCurrentPosition, TInt aTopItem )
       
   269 	{
       
   270 
       
   271 	if (aCurrentPosition >= 0)
       
   272 		{
       
   273 		iListBox->SetTopItemIndex( aTopItem );
       
   274 		iListBox->SetCurrentItemIndex( aCurrentPosition );
       
   275 		}
       
   276 	ActivateL();
       
   277 	DrawNow();
       
   278 	}
       
   279 
       
   280 // ---------------------------------------------------------
       
   281 // CVpnManagementUiPolicyContainer::UpdateListBoxL(TInt& aCurrentPosition)
       
   282 // Updates listbox after deletion, sets No VPN policies text 
       
   283 // if deleted policy was a last one.
       
   284 // ---------------------------------------------------------
       
   285 //
       
   286 void CVpnManagementUiPolicyContainer::UpdateListBoxL( TInt& aCurrentPosition )
       
   287 	{ 
       
   288 	MDesCArray* itemList = iListBox->Model()->ItemTextArray();
       
   289 	CDesCArray* itemArray = ( CDesCArray* )itemList;
       
   290 
       
   291     itemArray->Delete(aCurrentPosition);
       
   292     itemArray->Compress();
       
   293 
       
   294     iListBox->HandleItemRemovalL();
       
   295     if(aCurrentPosition > 0)
       
   296         {
       
   297         iListBox->SetCurrentItemIndexAndDraw(aCurrentPosition-1);
       
   298         }
       
   299     if(aCurrentPosition == 0 )
       
   300         {
       
   301         if (iListItemCount > 1 )
       
   302             {
       
   303             iListBox->SetCurrentItemIndexAndDraw(aCurrentPosition);
       
   304             }
       
   305         else
       
   306             {
       
   307             HBufC* stringHolder = StringLoader::LoadLC( R_VPN_POLICIES_EMPTY );
       
   308 	        iListBox->View()->SetListEmptyTextL( *stringHolder );
       
   309 	        CleanupStack::PopAndDestroy();  // stringHolder
       
   310             }
       
   311         }
       
   312     iListItemCount = iListItemCount -1;
       
   313     iParent.SetMiddleSoftKeyL(ETrue);
       
   314     DrawNow();
       
   315 	}
       
   316 
       
   317 void CVpnManagementUiPolicyContainer::ShowPoliciesL() 
       
   318     {
       
   319     CArrayFixFlat<TVpnPolicyInfo>* policyList = 
       
   320         iLoader.VpnApiWrapperL().PolicyListL();
       
   321 
       
   322    	CDesCArrayFlat* itemTextArray = 
       
   323    	    static_cast<CDesCArrayFlat*>(iListBox->Model()->ItemTextArray());
       
   324 
       
   325 	itemTextArray->Reset();
       
   326 	iListBox->Reset();
       
   327 
       
   328     iListItemCount = policyList->Count();
       
   329 
       
   330     for (TInt i = 0; i < iListItemCount; ++i)
       
   331         {
       
   332         TBuf<KMaxNameLength+2> policyName;
       
   333         policyName.Append(_L("\t"));
       
   334         policyName.Append(policyList->At(i).iName);
       
   335         itemTextArray->AppendL(policyName);
       
   336         }
       
   337 
       
   338 	iListBox->HandleItemAdditionL();
       
   339     }
       
   340 
       
   341 
       
   342 
       
   343 // ---------------------------------------------------------
       
   344 // CVpnManagementUiPolicyContainer::GetHelpContext
       
   345 // This function is called when Help application is launched.  
       
   346 // (other items were commented in a header).
       
   347 // ---------------------------------------------------------
       
   348 //
       
   349 #ifdef __SERIES60_HELP
       
   350 void CVpnManagementUiPolicyContainer::GetHelpContext( 
       
   351     TCoeHelpContext& aContext ) const
       
   352     {
       
   353 	aContext.iMajor = KUidVpnManagementUi;
       
   354     aContext.iContext = KSET_HLP_VPN_POLICY_VIEW;
       
   355     }
       
   356 #endif //__SERIES60_HELP
       
   357 
       
   358 // End of File