vpnui/vpnmanagementui/src/vpnmanagementuiserversettingscontainer.cpp
branchRCL_3
changeset 41 e06095241a65
child 49 5960d2d03390
equal deleted inserted replaced
40:473321461bba 41: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: The container is responsible of showing policy server details. 
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <akntextsettingpage.h>
       
    20 #include <aknnotewrappers.h>
       
    21 #include <cmmanagerext.h>
       
    22 #include <cmsettingsui.h>
       
    23 #include <cmapplicationsettingsui.h>
       
    24 #include <cmdestinationext.h>
       
    25 #include <cmpluginvpndef.h>
       
    26 #include <commdb.h>
       
    27 #include <e32def.h>
       
    28 
       
    29 #include <vpnmanagementuirsc.rsg>
       
    30 #include "vpnuiloader.h"
       
    31 #include "vpnmanagementuiserversettingscontainer.h"
       
    32 #include "vpnmanagementuidefs.h"
       
    33 #include "serversettingconnectionsettingitem.h"
       
    34 #include "vpnmanagementui.hrh"
       
    35 #include "log_vpnmanagementui.h"
       
    36 
       
    37 
       
    38 #ifdef __SERIES60_HELP
       
    39 #include <csxhelp/vpn.hlp.hrh> // for help context of VPN Management UI
       
    40 #endif //__SERIES60_HELP
       
    41 
       
    42 using namespace CMManager;
       
    43 
       
    44 // ================= MEMBER FUNCTIONS =======================
       
    45 
       
    46 CServerSettingsContainer* CServerSettingsContainer::NewL(
       
    47     CVpnUiLoader& aLoader, TInt aServerIndex )
       
    48     {
       
    49     CServerSettingsContainer* self = new(ELeave) CServerSettingsContainer(
       
    50         aLoader, aServerIndex );
       
    51     CleanupStack::PushL(self);
       
    52     self->ConstructL();
       
    53     CleanupStack::Pop(self);    
       
    54     return self;
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------
       
    58 // CServerSettingsContainer::CServerSettingsContainer()
       
    59 // ---------------------------------------------------------
       
    60 //
       
    61 CServerSettingsContainer::CServerSettingsContainer(
       
    62     CVpnUiLoader& aLoader, TInt aServerIndex )
       
    63     :iLoader(aLoader), iServerIndex(aServerIndex)
       
    64     {
       
    65     ASSERT(aServerIndex >= KErrNotFound);
       
    66 	}
       
    67 
       
    68 // ---------------------------------------------------------
       
    69 // CServerSettingsContainer::~CServerSettingsContainer()
       
    70 // Destructor
       
    71 // ---------------------------------------------------------
       
    72 //
       
    73 CServerSettingsContainer::~CServerSettingsContainer()
       
    74     {
       
    75     }
       
    76 
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CreateSettingItemL
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 CAknSettingItem* CServerSettingsContainer::CreateSettingItemL( 
       
    83     TInt aSettingId )
       
    84     {
       
    85     CAknSettingItem* settingItem(NULL);
       
    86     
       
    87     switch (aSettingId)
       
    88         {
       
    89         case EVpnUiSettingServerName:
       
    90             settingItem = new (ELeave) CAknTextSettingItem(
       
    91                 aSettingId, iServerDetails.iServerNameLocal );
       
    92             break;
       
    93         case EVpnUiSettingServerAddress:
       
    94             if (iServerDetails.iServerUrl.Length() > 0)
       
    95                 {                
       
    96                 iServerAddressBuffer.Copy(iServerDetails.iServerUrl);
       
    97                 }
       
    98             settingItem = new (ELeave) CAknTextSettingItem(
       
    99                 aSettingId, iServerAddressBuffer );
       
   100             break;
       
   101         case EVpnUiSettingIap:              
       
   102             if ( iServerDetails.iSelection.iId <1 )
       
   103                 {
       
   104                  RCmManagerExt cmManagerExt;
       
   105                  cmManagerExt.OpenL();        
       
   106                  CleanupClosePushL( cmManagerExt );     
       
   107 
       
   108                  //Makes sure that Internet Destination Exists
       
   109                  RArray<TUint32> destinationArray;    
       
   110                  cmManagerExt.AllDestinationsL( destinationArray );
       
   111                  CleanupClosePushL(destinationArray);    
       
   112                             
       
   113                  TUint32 internetDestinationId = 0;
       
   114                  for (TInt i = 0; i < destinationArray.Count(); ++i)
       
   115                      {
       
   116                       RCmDestinationExt destination = cmManagerExt.DestinationL( destinationArray[i] );
       
   117                       CleanupClosePushL(destination);
       
   118                             
       
   119                       TUint32 purposeMetaData = destination.MetadataL( ESnapMetadataPurpose );
       
   120                       if ( ESnapPurposeInternet ==  purposeMetaData )
       
   121                            {
       
   122                             internetDestinationId = destinationArray[i];
       
   123                             CleanupStack::PopAndDestroy(); //destination
       
   124                             break;
       
   125                            }                
       
   126                       CleanupStack::PopAndDestroy(); //destination
       
   127                       }
       
   128                               
       
   129                 iServerDetails.iSelection.iId = internetDestinationId;
       
   130                 
       
   131                 iServerDetails.iSelection.iResult=EDestination;
       
   132                 
       
   133                 
       
   134                 settingItem = new (ELeave) CServerSettingConnectionSettingItem(
       
   135                         aSettingId, iServerDetails.iSelection);
       
   136                 CleanupStack::PopAndDestroy(2); //destinationArray,cmManagerExt
       
   137                 
       
   138                 }
       
   139             else
       
   140                 settingItem = new (ELeave) CServerSettingConnectionSettingItem(
       
   141                         aSettingId, iServerDetails.iSelection);
       
   142             break;
       
   143         default:
       
   144             // Do nothing
       
   145             break;
       
   146             }
       
   147    
       
   148     return settingItem;
       
   149     }
       
   150     
       
   151     
       
   152 // ---------------------------------------------------------------------------
       
   153 // CServerSettingsContainer::ConstructL()
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 void CServerSettingsContainer::ConstructL()
       
   157     {
       
   158 	// Server settings view sets iServerIndex to -1 when creating a new 
       
   159 	// server
       
   160 	if ( iServerIndex >= 0 )
       
   161 	    {
       
   162 	    iLoader.VpnApiWrapperL().GetServerDetailsL( iServerDetails );
       
   163 	    UpdateTitleL( iServerDetails.iServerNameLocal );    
       
   164 	    }    
       
   165 	ConstructFromResourceL(R_VPN_SERVER_SETTING_LIST);	
       
   166 	CAknSettingItem* item = SettingItemArray()->At(EVpnUiSettingIap); 
       
   167 	
       
   168 	using namespace CMManager;
       
   169 	    
       
   170 	RCmManagerExt cmManagerExt;
       
   171 	cmManagerExt.OpenL();        
       
   172 	CleanupClosePushL( cmManagerExt );     
       
   173 
       
   174 	//Makes sure that Internet Destination Exists
       
   175 	RArray<TUint32> destinationArray;    
       
   176 	cmManagerExt.AllDestinationsL( destinationArray );
       
   177 	CleanupClosePushL(destinationArray);    
       
   178 	TBool internetIapExist=EFalse;       
       
   179 	TUint32 internetDestinationId = 0;
       
   180 	for (TInt i = 0; i < destinationArray.Count(); ++i)
       
   181 	        {
       
   182 	        RCmDestinationExt destination = cmManagerExt.DestinationL( destinationArray[i] );
       
   183 	        CleanupClosePushL(destination);
       
   184 	        
       
   185 	        TUint32 purposeMetaData = destination.MetadataL( ESnapMetadataPurpose );
       
   186 	        if ( ESnapPurposeInternet ==  purposeMetaData )
       
   187 	            {
       
   188 	            internetDestinationId = destinationArray[i];
       
   189 	            CleanupStack::PopAndDestroy(); //destination
       
   190 	            internetIapExist=ETrue;
       
   191 	            break;
       
   192 	            }                
       
   193 	        CleanupStack::PopAndDestroy(); //destination
       
   194 	        }
       
   195 	
       
   196 	if ( internetIapExist != EFalse)
       
   197 	    {
       
   198         HBufC* defaultConn = GetDestinationNameL(internetDestinationId);
       
   199         CleanupStack::PushL(defaultConn);
       
   200         item->SetEmptyItemTextL(*defaultConn);
       
   201         item->LoadL();
       
   202         item->UpdateListBoxTextL();
       
   203         CleanupStack::PopAndDestroy(defaultConn); 
       
   204 	    }
       
   205 	
       
   206 	CleanupStack::PopAndDestroy(); //destinationArray 
       
   207 	CleanupStack::PopAndDestroy(); //cmManagerExt 
       
   208 	}
       
   209 	
       
   210 	
       
   211 // ---------------------------------------------------------------------------
       
   212 // UpdateTitleL
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 void CServerSettingsContainer::UpdateTitleL( TDes& aText )
       
   216     {
       
   217     iLoader.ActivateTitleL(KViewTitleParametersView,aText);
       
   218     } 
       
   219 
       
   220 
       
   221 void CServerSettingsContainer::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType)
       
   222     {
       
   223     switch(aEventType)
       
   224         {
       
   225         case EEventEnterKeyPressed: 
       
   226         case EEventItemSingleClicked:
       
   227             ChangeSettingValueL();            
       
   228             break;
       
   229         default:
       
   230             CAknSettingItemList::HandleListBoxEventL(aListBox, aEventType);
       
   231         }    
       
   232     }
       
   233 
       
   234 
       
   235 // ---------------------------------------------------------------------------
       
   236 // ChangeSettingValueL
       
   237 // ---------------------------------------------------------------------------
       
   238 //
       
   239 void CServerSettingsContainer::ChangeSettingValueL()
       
   240     {
       
   241   
       
   242     TInt currentItem( ListBox()->CurrentItemIndex() );
       
   243            
       
   244     switch(currentItem)
       
   245         {        
       
   246         case EVpnUiSettingServerName:
       
   247             {
       
   248             EditItemL(EVpnUiSettingServerName, ETrue);   
       
   249             SettingItemArray()->At(EVpnUiSettingServerName)->StoreL(); 
       
   250             }
       
   251             if (iServerDetails.iServerNameLocal.Length() > 0)
       
   252             {                
       
   253             UpdateTitleL( iServerDetails.iServerNameLocal );
       
   254             }
       
   255             
       
   256             break;            
       
   257         case EVpnUiSettingServerAddress:
       
   258             {
       
   259             EditItemL(EVpnUiSettingServerAddress, ETrue);    
       
   260             }
       
   261             break;
       
   262         case EVpnUiSettingIap:
       
   263             {
       
   264             EditItemL(EVpnUiSettingIap, ETrue);    
       
   265             }
       
   266             break;
       
   267         default:            
       
   268             User::Invariant();
       
   269             break;
       
   270         }
       
   271     }
       
   272 
       
   273 
       
   274 
       
   275 const TAgileProvisionApiServerSettings& CServerSettingsContainer::ServerDetailsL()
       
   276     {
       
   277     StoreSettingsL();
       
   278     if (iServerAddressBuffer.Length() > 0)
       
   279         {
       
   280         iServerDetails.iServerUrl.Copy(iServerAddressBuffer);
       
   281         }
       
   282 
       
   283     //If server name is left empty, but we have an address,
       
   284     //set address as a server name.        
       
   285     if (iServerDetails.iServerNameLocal.Length() == 0 &&
       
   286         iServerDetails.iServerUrl.Length() > 0)
       
   287         {         
       
   288 
       
   289         //If the address is already in use as server name, generate
       
   290         //a new unique name.                
       
   291         TUint16 i = 1;
       
   292             static const TInt KSuffixLength = 10;
       
   293             _LIT(KSuffixFormat, "(%d)");
       
   294                         
       
   295             TBuf<KSuffixLength> suffix;                            
       
   296             suffix.Zero();
       
   297             if (i > 1)
       
   298                 {
       
   299                 suffix.Format(KSuffixFormat, i);                
       
   300                 }
       
   301             i++;
       
   302             
       
   303             //First assumes that the address is too long to fit
       
   304             TInt numberOfCharactersCopiedFromAddress =
       
   305                           iServerDetails.iServerNameLocal.MaxLength() - suffix.Length();         
       
   306 
       
   307             //If this is not the case adjust the length                           
       
   308             if (numberOfCharactersCopiedFromAddress > iServerDetails.iServerUrl.Length())
       
   309                 {
       
   310                 numberOfCharactersCopiedFromAddress = iServerDetails.iServerUrl.Length();
       
   311                 }
       
   312             
       
   313             TPtrC8 serverNameAddress = iServerDetails.iServerUrl.Left(numberOfCharactersCopiedFromAddress);
       
   314             iServerDetails.iServerNameLocal.Copy(serverNameAddress);             
       
   315             iServerDetails.iServerNameLocal.Append(suffix);                                                             
       
   316    
       
   317         CAknSettingItem* item = SettingItemArray()->At(EVpnUiSettingServerName); 
       
   318         
       
   319         item->LoadL();
       
   320         item->UpdateListBoxTextL();        
       
   321         }
       
   322     return iServerDetails;
       
   323     }
       
   324 
       
   325 
       
   326 // ---------------------------------------------------------------------------
       
   327 // GetIapNameL
       
   328 // ---------------------------------------------------------------------------
       
   329 //
       
   330 HBufC* CServerSettingsContainer::GetDestinationNameL( TUint aId )
       
   331 	{
       
   332     RCmManagerExt cmManager;    
       
   333 	cmManager.OpenLC();
       
   334 	RCmDestinationExt dest = cmManager.DestinationL( aId );
       
   335 	CleanupClosePushL( dest );
       
   336 	HBufC* name = dest.NameLC();   
       
   337 	CleanupStack::Pop(name);
       
   338 	CleanupStack::PopAndDestroy( 2 ); // dest, cmManager
       
   339 	return name;
       
   340 	}
       
   341 
       
   342 
       
   343 HBufC* CServerSettingsContainer::GetConnectionMethodNameL( TUint aId )
       
   344 	{
       
   345 	RCmManagerExt cmManager;    
       
   346 	cmManager.OpenLC();
       
   347 	RCmConnectionMethodExt conn = cmManager.ConnectionMethodL( aId );
       
   348 	CleanupClosePushL( conn );	
       
   349 	HBufC* name = conn.GetStringAttributeL( ECmName );
       
   350 	CleanupStack::PopAndDestroy( 2 ); // conn, cmManager
       
   351 	return name;
       
   352 	}
       
   353 
       
   354 
       
   355 TInt CServerSettingsContainer::ServerIndex() const
       
   356     {
       
   357     return iServerIndex;
       
   358     }
       
   359 
       
   360 
       
   361 // ---------------------------------------------------------
       
   362 // CServerSettingsContainer::GetHelpContext
       
   363 // ---------------------------------------------------------
       
   364 
       
   365 #ifdef __SERIES60_HELP
       
   366 void CServerSettingsContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   367     {
       
   368 	aContext.iMajor = KUidVpnManagementUi;
       
   369     aContext.iContext = KSET_HLP_VPN_POLICY_SERVER_SET;
       
   370     }
       
   371 #endif //__SERIES60_HELP
       
   372 
       
   373 
       
   374 // End of File