vpnui/vpnmanagementui/src/vpnmanagementuiserversettingscontainer.cpp
changeset 0 33413c0669b9
child 22 9f4e37332ce5
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     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 <vpnmanagementuirsc.rsg>
       
    28 #include "vpnuiloader.h"
       
    29 #include "vpnmanagementuiserversettingscontainer.h"
       
    30 #include "vpnmanagementuidefs.h"
       
    31 #include "serversettingconnectionsettingitem.h"
       
    32 #include "vpnmanagementui.hrh"
       
    33 #include "log_vpnmanagementui.h"
       
    34 
       
    35 
       
    36 #ifdef __SERIES60_HELP
       
    37 #include <csxhelp/vpn.hlp.hrh> // for help context of VPN Management UI
       
    38 #endif //__SERIES60_HELP
       
    39 
       
    40 using namespace CMManager;
       
    41 
       
    42 // ================= MEMBER FUNCTIONS =======================
       
    43 
       
    44 CServerSettingsContainer* CServerSettingsContainer::NewL(
       
    45     CVpnUiLoader& aLoader, TInt aServerIndex )
       
    46     {
       
    47     CServerSettingsContainer* self = new(ELeave) CServerSettingsContainer(
       
    48         aLoader, aServerIndex );
       
    49     CleanupStack::PushL(self);
       
    50     self->ConstructL();
       
    51     CleanupStack::Pop(self);    
       
    52     return self;
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------
       
    56 // CServerSettingsContainer::CServerSettingsContainer()
       
    57 // ---------------------------------------------------------
       
    58 //
       
    59 CServerSettingsContainer::CServerSettingsContainer(
       
    60     CVpnUiLoader& aLoader, TInt aServerIndex )
       
    61     :iLoader(aLoader), iServerIndex(aServerIndex)
       
    62     {
       
    63     ASSERT(aServerIndex >= KErrNotFound);
       
    64 	}
       
    65 
       
    66 // ---------------------------------------------------------
       
    67 // CServerSettingsContainer::~CServerSettingsContainer()
       
    68 // Destructor
       
    69 // ---------------------------------------------------------
       
    70 //
       
    71 CServerSettingsContainer::~CServerSettingsContainer()
       
    72     {
       
    73     }
       
    74 
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CreateSettingItemL
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 CAknSettingItem* CServerSettingsContainer::CreateSettingItemL( 
       
    81     TInt /* aSettingId */)
       
    82     {
       
    83     CAknSettingItem* settingItem(NULL);
       
    84     /*** NSSM support is discontinued.
       
    85          Code is kept in comments temporarily because similar UI functionality
       
    86          might be needed for another purpose.
       
    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             settingItem = new (ELeave) CServerSettingConnectionSettingItem(
       
   103                 aSettingId, iServerDetails.iSelection);
       
   104             break;
       
   105         default:
       
   106             // Do nothing
       
   107             break;
       
   108             }
       
   109     ***/
       
   110     return settingItem;
       
   111     }
       
   112     
       
   113     
       
   114 // ---------------------------------------------------------------------------
       
   115 // CServerSettingsContainer::ConstructL()
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 void CServerSettingsContainer::ConstructL()
       
   119     {
       
   120 	// Server settings view sets iServerIndex to -1 when creating a new 
       
   121 	// server
       
   122 	/*** NSSM support is discontinued.
       
   123          Code is kept in comments temporarily because similar UI functionality
       
   124          might be needed for another purpose.
       
   125 	if ( iServerIndex >= 0 )
       
   126 	    {
       
   127 	    iLoader.AcuApiWrapperL().GetServerDetailsL( 
       
   128 	        iServerIndex, iServerDetails );
       
   129 	    UpdateTitleL( iServerDetails.iServerNameLocal );    
       
   130 	    }    
       
   131 	***/  
       
   132     ConstructFromResourceL(R_VPN_SERVER_SETTING_LIST);	    
       
   133 	}
       
   134 	
       
   135 	
       
   136 // ---------------------------------------------------------------------------
       
   137 // UpdateTitleL
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 void CServerSettingsContainer::UpdateTitleL( TDes& aText )
       
   141     {
       
   142     iLoader.ActivateTitleL(KViewTitleParametersView,aText);
       
   143     } 
       
   144 
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // ServerNameExistsL
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 TBool CServerSettingsContainer::ServerNameExistsL( const TDesC& /* aText */) const
       
   151     {
       
   152     /*** NSSM support is discontinued.
       
   153          Code is kept in comments temporarily because similar UI functionality
       
   154          might be needed for another purpose.
       
   155     const CArrayFix<TAcuApiServerListElem>* serverList = iLoader.AcuApiWrapperL().ServerListL();
       
   156     TInt count = serverList->Count();
       
   157 
       
   158     for (TInt i = 0; i < count; ++i)
       
   159         {
       
   160         //If we are editing name, we don't want to compare itself
       
   161         if(i != iServerIndex)
       
   162             {
       
   163             if (serverList->At(i).iServerNameLocal.Compare(aText)==0)
       
   164                 {
       
   165                 //Name is already in use
       
   166                 return ETrue;
       
   167                 }
       
   168             }
       
   169         } ***/
       
   170     return EFalse;
       
   171     }
       
   172 
       
   173 
       
   174 void CServerSettingsContainer::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType)
       
   175     {
       
   176     switch(aEventType)
       
   177         {
       
   178         case EEventEnterKeyPressed: 
       
   179         case EEventItemSingleClicked:
       
   180             ChangeSettingValueL();            
       
   181             break;
       
   182         default:
       
   183             CAknSettingItemList::HandleListBoxEventL(aListBox, aEventType);
       
   184         }    
       
   185     }
       
   186 
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 // ChangeSettingValueL
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 void CServerSettingsContainer::ChangeSettingValueL()
       
   193     {
       
   194     /*** NSSM support is discontinued.
       
   195          Code is kept in comments temporarily because similar UI functionality
       
   196          might be needed for another purpose.
       
   197     TInt currentItem( ListBox()->CurrentItemIndex() );
       
   198            
       
   199     switch(currentItem)
       
   200         {        
       
   201         case EVpnUiSettingServerName:
       
   202             {
       
   203             TBool alreadyInUse = ETrue;
       
   204             while(alreadyInUse)
       
   205                 {
       
   206                 EditItemL(EVpnUiSettingServerName, ETrue);   
       
   207                 SettingItemArray()->At(EVpnUiSettingServerName)->StoreL(); 
       
   208                 alreadyInUse = ServerNameExistsL( iServerDetails.iServerNameLocal );
       
   209                 if(alreadyInUse)
       
   210                     {
       
   211                     //Show an information note that server is currently in use
       
   212                     HBufC* noteText;
       
   213                     noteText = StringLoader::LoadLC( R_FLDR_NAME_ALREADY_USED, iServerDetails.iServerNameLocal );
       
   214                     CAknInformationNote* note = new(ELeave)CAknInformationNote(ETrue);
       
   215                     note->SetTimeout(CAknNoteDialog::ELongTimeout); //3sec
       
   216                     note->ExecuteLD(noteText->Des());
       
   217                     CleanupStack::PopAndDestroy();  // noteText                                
       
   218                     }
       
   219 
       
   220                 }
       
   221             if (iServerDetails.iServerNameLocal.Length() > 0)
       
   222                 {                
       
   223                 UpdateTitleL( iServerDetails.iServerNameLocal );
       
   224                 }
       
   225             }
       
   226             break;            
       
   227         case EVpnUiSettingServerAddress:
       
   228             {
       
   229             if( iServerDetails.iServerUrlReadOnly )
       
   230                 {
       
   231                 //Show an information note that server cannot be
       
   232                 //modified
       
   233                 HBufC* noteText;
       
   234                 noteText = StringLoader::LoadLC( 
       
   235                     R_VPN_INFO_CANNOT_MODIFY_SERVER_DEF );
       
   236                 CAknInformationNote* note = 
       
   237                     new(ELeave) CAknInformationNote(ETrue);
       
   238                 note->SetTimeout(CAknNoteDialog::ELongTimeout); //3sec
       
   239                 note->ExecuteLD(noteText->Des());
       
   240                 CleanupStack::PopAndDestroy();  // noteText
       
   241                 }
       
   242             else
       
   243                 {            
       
   244                 EditItemL(EVpnUiSettingServerAddress, ETrue);    
       
   245                 }
       
   246             }
       
   247             break;
       
   248         case EVpnUiSettingIap:
       
   249             {
       
   250             EditItemL(EVpnUiSettingIap, ETrue);    
       
   251             }
       
   252             break;
       
   253         default:            
       
   254             User::Invariant();
       
   255             break;
       
   256         } ***/
       
   257     }
       
   258 
       
   259 
       
   260 // ---------------------------------------------------------------------------
       
   261 // ServerDetails
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 /*** NSSM support is discontinued.
       
   265          Code is kept in comments temporarily because similar UI functionality
       
   266          might be needed for another purpose.
       
   267 const TAcuApiServerDetails& CServerSettingsContainer::ServerDetailsL()
       
   268     {
       
   269     StoreSettingsL();
       
   270     if (iServerAddressBuffer.Length() > 0)
       
   271         {
       
   272         iServerDetails.iServerUrl.Copy(iServerAddressBuffer);
       
   273         }
       
   274 
       
   275     //If server name is left empty, but we have an address,
       
   276     //set address as a server name.        
       
   277     if (iServerDetails.iServerNameLocal.Length() == 0 &&
       
   278         iServerDetails.iServerUrl.Length() > 0)
       
   279         {         
       
   280 
       
   281         //If the address is already in use as server name, generate
       
   282         //a new unique name.                
       
   283         TUint16 i = 1;
       
   284         do
       
   285             {
       
   286             static const TInt KSuffixLength = 10;
       
   287             _LIT(KSuffixFormat, "(%d)");
       
   288                         
       
   289             TBuf<KSuffixLength> suffix;                            
       
   290             suffix.Zero();
       
   291             if (i > 1)
       
   292                 {
       
   293                 suffix.Format(KSuffixFormat, i);                
       
   294                 }
       
   295             i++;
       
   296             
       
   297             //First assumes that the address is too long to fit
       
   298             TInt numberOfCharactersCopiedFromAddress =
       
   299                           iServerDetails.iServerNameLocal.MaxLength() - suffix.Length();         
       
   300 
       
   301             //If this is not the case adjust the length                           
       
   302             if (numberOfCharactersCopiedFromAddress > iServerDetails.iServerUrl.Length())
       
   303                 {
       
   304                 numberOfCharactersCopiedFromAddress = iServerDetails.iServerUrl.Length();
       
   305                 }
       
   306             
       
   307             TPtrC8 serverNameAddress = iServerDetails.iServerUrl.Left(numberOfCharactersCopiedFromAddress);
       
   308             iServerDetails.iServerNameLocal.Copy(serverNameAddress);             
       
   309             iServerDetails.iServerNameLocal.Append(suffix);                                                             
       
   310                            
       
   311             }while(ServerNameExistsL( iServerDetails.iServerNameLocal) );                                                          
       
   312         
       
   313         CAknSettingItem* item = SettingItemArray()->At(EVpnUiSettingServerName); 
       
   314         item->LoadL();
       
   315         item->UpdateListBoxTextL();        
       
   316         }
       
   317     return iServerDetails;
       
   318     }
       
   319 ***/
       
   320 
       
   321 // ---------------------------------------------------------------------------
       
   322 // GetIapNameL
       
   323 // ---------------------------------------------------------------------------
       
   324 //
       
   325 HBufC* CServerSettingsContainer::GetDestinationNameL( TUint aId )
       
   326 	{
       
   327     RCmManagerExt cmManager;    
       
   328 	cmManager.OpenLC();
       
   329 	RCmDestinationExt dest = cmManager.DestinationL( aId );
       
   330 	CleanupClosePushL( dest );
       
   331 	HBufC* name = dest.NameLC();   
       
   332 	CleanupStack::Pop(name);
       
   333 	CleanupStack::PopAndDestroy( 2 ); // dest, cmManager
       
   334 	return name;
       
   335 	}
       
   336 
       
   337 
       
   338 HBufC* CServerSettingsContainer::GetConnectionMethodNameL( TUint aId )
       
   339 	{
       
   340 	RCmManagerExt cmManager;    
       
   341 	cmManager.OpenLC();
       
   342 	RCmConnectionMethodExt conn = cmManager.ConnectionMethodL( aId );
       
   343 	CleanupClosePushL( conn );	
       
   344 	HBufC* name = conn.GetStringAttributeL( ECmName );
       
   345 	CleanupStack::PopAndDestroy( 2 ); // conn, cmManager
       
   346 	return name;
       
   347 	}
       
   348 
       
   349 
       
   350 TInt CServerSettingsContainer::ServerIndex() const
       
   351     {
       
   352     return iServerIndex;
       
   353     }
       
   354 
       
   355 
       
   356 // ---------------------------------------------------------
       
   357 // CServerSettingsContainer::GetHelpContext
       
   358 // ---------------------------------------------------------
       
   359 
       
   360 #ifdef __SERIES60_HELP
       
   361 void CServerSettingsContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   362     {
       
   363 	aContext.iMajor = KUidVpnManagementUi;
       
   364     aContext.iContext = KSET_HLP_VPN_POLICY_SERVER_SET;
       
   365     }
       
   366 #endif //__SERIES60_HELP
       
   367 
       
   368 
       
   369 // End of File