cmmanager/cmmgr/Plugins/cmpluginvpn/src/cmpvpnpolicyselectiondlg.cpp
changeset 20 9c97ad6591ae
parent 18 fcbbe021d614
child 21 b8e8e15e80f2
child 23 7ec726f93df1
child 28 860702281757
equal deleted inserted replaced
18:fcbbe021d614 20:9c97ad6591ae
     1 /*
       
     2 * Copyright (c) 2006 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:  Displays a radio button selection list of VPN policies
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // includes
       
    20 #include <aknPopup.h>
       
    21 // #include <vpnapidefs.h>
       
    22 #include <aknlists.h>
       
    23 #include <cmmanager.rsg>
       
    24 #include <cmpluginvpnui.rsg>
       
    25 #include <cmcommonui.h>
       
    26 #include <cmpluginbaseeng.h>
       
    27 #include <StringLoader.h>
       
    28 #include <data_caging_path_literals.hrh>
       
    29 #include <aknradiobuttonsettingpage.h>
       
    30 
       
    31 #include "cmlogger.h"
       
    32 #include "cmpvpnpolicyselectiondlg.h"
       
    33 #include "cmvpncommonconstants.h"
       
    34 #include <cmpluginvpndef.h>
       
    35 #include <cmcommonconstants.h>
       
    36 
       
    37 using namespace CMManager;
       
    38 
       
    39 // ----------------------------------------------------------------------------
       
    40 // CmPluginVpnPolicySelectionDlg::NewL
       
    41 // ----------------------------------------------------------------------------
       
    42 //
       
    43 CmPluginVpnPolicySelectionDlg* CmPluginVpnPolicySelectionDlg::NewL( 
       
    44                                         CCmPluginBaseEng& aCmPluginBaseEng )
       
    45     {
       
    46     CmPluginVpnPolicySelectionDlg* self = 
       
    47             new ( ELeave ) CmPluginVpnPolicySelectionDlg( aCmPluginBaseEng );
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL();
       
    50     CleanupStack::Pop( self );
       
    51     return self;
       
    52     }
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // CmPluginVpnPolicySelectionDlg::~CmPluginVpnPolicySelectionDlg
       
    56 // ----------------------------------------------------------------------------
       
    57 //
       
    58 CmPluginVpnPolicySelectionDlg::~CmPluginVpnPolicySelectionDlg()
       
    59     {
       
    60 
       
    61     iVpnServ.Close();
       
    62 
       
    63     delete iPolicyInfoList;
       
    64 
       
    65     iResourceReader.Close();
       
    66     }
       
    67     
       
    68 // ----------------------------------------------------------------------------
       
    69 // CmPluginVpnPolicySelectionDlg::CmPluginVpnPolicySelectionDlg
       
    70 // ----------------------------------------------------------------------------
       
    71 //
       
    72 CmPluginVpnPolicySelectionDlg::CmPluginVpnPolicySelectionDlg(
       
    73                         CCmPluginBaseEng& aCmPluginBaseEng )
       
    74     : iCmPluginBaseEng( aCmPluginBaseEng )
       
    75     , iResourceReader( *CCoeEnv::Static() )
       
    76     , iVpnClientUnaccessible ( EFalse )
       
    77     {
       
    78     }
       
    79     
       
    80 // ----------------------------------------------------------------------------
       
    81 // CmPluginVpnPolicySelectionDlg::ConstructL
       
    82 // ----------------------------------------------------------------------------
       
    83 //
       
    84 void CmPluginVpnPolicySelectionDlg::ConstructL()
       
    85     {
       
    86     LoadResourceL( KPluginVPNResDirAndFileName );
       
    87     
       
    88     // Get the policies
       
    89     iPolicyInfoList = 
       
    90         new (ELeave) CArrayFixFlat<TVpnPolicyInfo>( KCmArrayMediumGranularity );
       
    91     
       
    92     TInt err( iVpnServ.Connect() );
       
    93     
       
    94     // Vpn client is inaccessible
       
    95     if ( err )
       
    96         {
       
    97         VpnClientInaccessibleL();
       
    98         }
       
    99     else
       
   100         {
       
   101         iVpnServ.GetPolicyInfoList( iPolicyInfoList );        
       
   102         iVpnServ.EnumeratePolicies( iNumPolicies );
       
   103         }
       
   104     }
       
   105 
       
   106 // ----------------------------------------------------------------------------
       
   107 // CmPluginVpnPolicySelectionDlg::LoadResourceL
       
   108 // ----------------------------------------------------------------------------
       
   109 //
       
   110 void CmPluginVpnPolicySelectionDlg::LoadResourceL( const TDesC& aResFileName )
       
   111     {
       
   112     TInt err( KErrNone );
       
   113     
       
   114     // Add resource file.
       
   115     TParse* fp = new ( ELeave ) TParse();
       
   116     err = fp->Set( aResFileName, 
       
   117                         &KDC_RESOURCE_FILES_DIR, 
       
   118                         NULL ); 
       
   119     if ( err )
       
   120         {
       
   121         User::Leave( err );
       
   122         }   
       
   123 
       
   124     TFileName resourceFileNameBuf = fp->FullName();
       
   125     delete fp;
       
   126 
       
   127     iResourceReader.OpenL( resourceFileNameBuf );
       
   128     }
       
   129 
       
   130 // ----------------------------------------------------------------------------
       
   131 // CmPluginVpnPolicySelectionDlg::ShowPolicySelectionListL
       
   132 // ----------------------------------------------------------------------------
       
   133 //
       
   134 TBool CmPluginVpnPolicySelectionDlg::ShowPolicySelectionListL()
       
   135     {
       
   136     LOGGER_ENTERFN( "CmPluginVpnPolicySelectionDlg::ShowPolicySelectionListL" );
       
   137     TBool retVal ( EFalse );
       
   138     
       
   139     CEikTextListBox* list = new ( ELeave ) CAknSinglePopupMenuStyleListBox;
       
   140     CleanupStack::PushL( list );
       
   141              
       
   142     // Create popup list
       
   143     CAknPopupList* popupList = CAknPopupList::NewL(
       
   144                                        list, 
       
   145                                        R_AVKON_SOFTKEYS_SELECT_CANCEL__SELECT,
       
   146                                        AknPopupLayouts::EMenuWindow);
       
   147     CleanupStack::PushL( popupList );
       
   148 
       
   149     // initialise listbox.
       
   150     list->ConstructL(popupList, CEikListBox::ELeftDownInViewRect);
       
   151     list->CreateScrollBarFrameL( ETrue );
       
   152     list->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   153                                CEikScrollBarFrame::EOff,
       
   154                                CEikScrollBarFrame::EAuto);
       
   155 
       
   156 
       
   157     MDesCArray* itemList = list->Model()->ItemTextArray();
       
   158 	CDesCArray* items = ( CDesCArray* ) itemList;	
       
   159 	
       
   160     // collect the item texts    
       
   161     if ( iNumPolicies )
       
   162         {
       
   163         for ( TInt i = 0; i < iNumPolicies; i++ )
       
   164             {
       
   165             HBufC* polName = ( iPolicyInfoList->At(i) ).iName.AllocLC();
       
   166             items->AppendL( *polName );
       
   167             CleanupStack::PopAndDestroy( polName );
       
   168             }
       
   169         
       
   170         // title
       
   171         HBufC* title = StringLoader::LoadLC( R_QTN_NETW_CONSET_PRMPT_VPN_POLICY );
       
   172         popupList->SetTitleL( *title );
       
   173         CleanupStack::PopAndDestroy( title );
       
   174         
       
   175         // dislay dialog
       
   176         CleanupStack::Pop( popupList );
       
   177         if ( popupList->ExecuteLD() )
       
   178             {
       
   179             TInt ix = list->CurrentItemIndex();
       
   180             
       
   181             // Set VPN Policy to be used
       
   182             HBufC* polName = ( iPolicyInfoList->At(ix) ).iName.AllocLC();
       
   183             HBufC* polId = ( iPolicyInfoList->At(ix) ).iId.AllocLC();
       
   184             
       
   185             CLOG_WRITE_2( "New policy settings:[%S], [%S]", polName, polId );
       
   186 
       
   187             iCmPluginBaseEng.SetStringAttributeL( EVpnServicePolicyName, *polName );
       
   188             iCmPluginBaseEng.SetStringAttributeL( EVpnServicePolicy, *polId );
       
   189             CleanupStack::PopAndDestroy( polId );
       
   190             CleanupStack::PopAndDestroy( polName );
       
   191             
       
   192             retVal = ETrue;
       
   193             }
       
   194         }
       
   195     else
       
   196         {
       
   197         if (!iVpnClientUnaccessible)
       
   198         	{
       
   199         	// display error note
       
   200         	HBufC* text = StringLoader::LoadLC( R_QTN_VPN_INFO_NO_POLICIES_INSTALLED );
       
   201         	TCmCommonUi::ShowNoteL( *text, TCmCommonUi::ECmInfoNote );
       
   202         	CleanupStack::PopAndDestroy( text );
       
   203         	}
       
   204         CleanupStack::PopAndDestroy( popupList );
       
   205         }
       
   206 
       
   207 
       
   208 	CleanupStack::PopAndDestroy( list );
       
   209     return retVal;
       
   210     }
       
   211 
       
   212 
       
   213 // ----------------------------------------------------------------------------
       
   214 // CmPluginVpnPolicySelectionDlg::ShowPolicySelectionDlgL
       
   215 // ----------------------------------------------------------------------------
       
   216 //
       
   217 TBool CmPluginVpnPolicySelectionDlg::ShowPolicySelectionDlgL()
       
   218     {
       
   219     LOGGER_ENTERFN( "CmPluginVpnPolicySelectionDlg::ShowPolicySelectionDlgL" );
       
   220     TBool retVal ( EFalse );
       
   221     
       
   222     TInt selection(0);
       
   223     
       
   224     // Compile the list items
       
   225     CDesCArrayFlat* items = 
       
   226             new ( ELeave ) CDesCArrayFlat( KCmArraySmallGranularity );
       
   227     CleanupStack::PushL( items );
       
   228     
       
   229     TInt vpnerr;
       
   230     vpnerr = iVpnServ.EnumeratePolicies( iNumPolicies );
       
   231     
       
   232     if ( vpnerr )
       
   233         {
       
   234         VpnClientInaccessibleL();
       
   235         }
       
   236     else
       
   237         {        
       
   238         if ( iNumPolicies )
       
   239             {
       
   240             vpnerr = iVpnServ.GetPolicyInfoList( iPolicyInfoList );
       
   241             if ( vpnerr == 0 )
       
   242                 {
       
   243                 for ( TInt i = 0; i < iNumPolicies; i++ )
       
   244                     {
       
   245                     HBufC* policyName = 
       
   246                             ( iPolicyInfoList->At(i) ).iName.AllocLC();
       
   247                     
       
   248                             
       
   249                     // indicate if this policy is the one in the settings
       
   250                     HBufC* val = iCmPluginBaseEng.GetStringAttributeL( 
       
   251                                                         EVpnServicePolicyName );
       
   252                     
       
   253                     if ( !( val->Compare( policyName->Des() ) ) )
       
   254                         {
       
   255                         selection = i;
       
   256                         }
       
   257                     delete val;
       
   258                     
       
   259                     items->AppendL( *policyName );
       
   260                     CleanupStack::PopAndDestroy( policyName );
       
   261                     }
       
   262                 // Create the dialog
       
   263                 CAknRadioButtonSettingPage* dlg = 
       
   264                                     new ( ELeave ) CAknRadioButtonSettingPage(
       
   265                                             R_RADIO_BUTTON_SETTING_PAGE_OK_CANCEL,
       
   266                                             selection, 
       
   267                                             items );
       
   268                 CleanupStack::PushL( dlg );
       
   269                 
       
   270                 // set title
       
   271                 HBufC* title = StringLoader::LoadLC( 
       
   272                                         R_QTN_VPN_SETT_VPN_IAP_POLICY_REFERENCE );
       
   273                 dlg->SetSettingTextL( *title );
       
   274                 CleanupStack::PopAndDestroy( title );
       
   275 
       
   276                 // display dialog
       
   277                 CleanupStack::Pop();
       
   278                 if ( dlg->ExecuteLD( CAknSettingPage::EUpdateWhenChanged ) )
       
   279                     {
       
   280                     HBufC* polId = 
       
   281                             ( iPolicyInfoList->At( selection ) ).iId.AllocLC();
       
   282                     HBufC* polName = 
       
   283                             ( iPolicyInfoList->At( selection ) ).iName.AllocLC();
       
   284                     iCmPluginBaseEng.SetStringAttributeL( EVpnServicePolicyName,
       
   285                                                           *polName );
       
   286                     
       
   287                     CLOG_WRITE_2( "New policy settings:[%S], [%S]", polName, polId );
       
   288                     
       
   289                     iCmPluginBaseEng.SetStringAttributeL( EVpnServicePolicy, 
       
   290                                                           *polId );
       
   291                     CleanupStack::PopAndDestroy( polName );
       
   292                     CleanupStack::PopAndDestroy( polId );
       
   293                     retVal = ETrue;
       
   294                     }
       
   295                 }
       
   296             }
       
   297         else
       
   298             {
       
   299             // note: no VPN policies installed, reset policy to compulsory
       
   300             CLOG_WRITE("No policy installed, reset policies");
       
   301             
       
   302             HBufC* text = StringLoader::LoadLC( 
       
   303                                         R_QTN_VPN_INFO_NO_POLICIES_INSTALLED );
       
   304             TCmCommonUi::ShowNoteL( *text, TCmCommonUi::ECmInfoNote );
       
   305             CleanupStack::PopAndDestroy( text );
       
   306             vpnerr = -1;
       
   307             }
       
   308         }
       
   309 
       
   310     if ( vpnerr )
       
   311         {
       
   312         // note: no VPN policies installed or any other vpn error,
       
   313         //  reset policy to compulsory
       
   314         CLOG_WRITE("Reset policies");
       
   315         
       
   316         iCmPluginBaseEng.SetStringAttributeL( EVpnServicePolicyName,
       
   317                                               KNullDesC() );
       
   318         iCmPluginBaseEng.SetStringAttributeL( EVpnServicePolicy, 
       
   319                                               KNullDesC() );
       
   320         
       
   321         }
       
   322 
       
   323     CleanupStack::PopAndDestroy( items );
       
   324     return retVal;
       
   325     }
       
   326     
       
   327     
       
   328 // ----------------------------------------------------------------------------
       
   329 // CmPluginVpnPolicySelectionDlg::VpnClientInaccessibleL
       
   330 // ----------------------------------------------------------------------------
       
   331 //
       
   332 void CmPluginVpnPolicySelectionDlg::VpnClientInaccessibleL()
       
   333     {
       
   334     LOGGER_ENTERFN( "CmPluginVpnPolicySelectionDlg::VpnClientInaccessibleL" );
       
   335     HBufC* text = StringLoader::LoadLC( R_QTN_VPN_INFO_MGMT_UI_NOT_ACCESSIBLE );
       
   336     TCmCommonUi::ShowNoteL( *text, TCmCommonUi::ECmInfoNote );
       
   337     CleanupStack::PopAndDestroy( text );
       
   338     iVpnClientUnaccessible = ETrue;
       
   339     }