gssettingsuis/Gs/GSPDataHSDPAPlugin/src/GSPDataHSDPAPlugin.cpp
branchRCL_3
changeset 24 8ee96d21d9bf
parent 23 8bda91a87a00
child 25 7e0eff37aedb
equal deleted inserted replaced
23:8bda91a87a00 24:8ee96d21d9bf
     1 /*
       
     2 * Copyright (c) 2007 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:  GSPDataHSDPAPlugin implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // User includes
       
    20 #include    "GSPDataHSDPAPlugin.h"
       
    21 #include    "GSPDataHSDPAModel.h"
       
    22 #include    <gsparentplugin.h>
       
    23 #include    <gscommon.hrh>
       
    24 #include    <gspdatahsdpapluginrsc.rsg> // GUI Resource
       
    25 #include    <gsprivatepluginproviderids.h>
       
    26 #include    <gsfwviewuids.h>
       
    27 
       
    28 // System includes
       
    29 #include    <AknWaitDialog.h>
       
    30 #include    <aknnotewrappers.h>
       
    31 #include    <aknradiobuttonsettingpage.h>
       
    32 #include    <akntextsettingpage.h>
       
    33 #include    <aknViewAppUi.h>
       
    34 #include    <bautils.h>
       
    35 #include    <featmgr.h>
       
    36 #include    <hlplch.h> // HlpLauncher
       
    37 #include    <StringLoader.h>
       
    38 #include    <telephonydomainpskeys.h>
       
    39 #include    <apgtask.h>
       
    40 #include    <NetworkHandlingDomainPSKeys.h>
       
    41 #include 	<CoreApplicationUIsSDKCRKeys.h>
       
    42 #include 	<AknWaitDialog.h>
       
    43 #include    <ProEngFactory.h>
       
    44 #ifdef RD_STARTUP_CHANGE
       
    45 #include 	<starterclient.h>
       
    46 #endif
       
    47 #include <centralrepository.h>
       
    48 #include <settingsinternalcrkeys.h>
       
    49 #include "SettingsPrivateCRKeys.h"
       
    50 
       
    51 // Constants
       
    52 
       
    53 // ========================= MEMBER FUNCTIONS ================================
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CGSPDataHSDPAPlugin::CGSPDataHSDPAPlugin()
       
    57 // Constructor
       
    58 //
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 CGSPDataHSDPAPlugin::CGSPDataHSDPAPlugin()
       
    62     : iResources( *iCoeEnv )
       
    63     {
       
    64     }
       
    65 
       
    66     
       
    67 // ---------------------------------------------------------------------------
       
    68 // CGSPDataHSDPAPlugin::~CGSPDataHSDPAPlugin()
       
    69 // Destructor
       
    70 //
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CGSPDataHSDPAPlugin::~CGSPDataHSDPAPlugin()
       
    74     {
       
    75     FeatureManager::UnInitializeLib();
       
    76     if ( iNwModeListener )
       
    77         {
       
    78         delete iNwModeListener;
       
    79         }
       
    80         
       
    81     iResources.Close();
       
    82 
       
    83     if( iModel )
       
    84         {
       
    85         delete iModel;
       
    86         }
       
    87     if( iProfileEngine )
       
    88         {
       
    89         iProfileEngine->Release();
       
    90         iProfileEngine = NULL;        
       
    91         }
       
    92     if( iNotifyHandler )
       
    93         {
       
    94         delete iNotifyHandler;
       
    95         iNotifyHandler = NULL;
       
    96         }
       
    97     }
       
    98 
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // CGSPDataHSDPAPlugin::ConstructL(const TRect& aRect)
       
   102 // Symbian OS two-phased constructor
       
   103 //
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 void CGSPDataHSDPAPlugin::ConstructL()
       
   107     {
       
   108     FeatureManager::InitializeLibL();
       
   109     iModel = CGSPDataHSDPAModel::NewL();
       
   110     OpenLocalizedResourceFileL( KPDataHSDPAResourceFileName, 
       
   111                                 iResources );
       
   112     //PS listener initialization
       
   113     iNwModeListener = CGSPubSubsListener::NewL( 
       
   114                      KPSUidNetworkInfo,
       
   115                      KNWTelephonyNetworkMode, this );
       
   116     iNwModeListener->Get( iNetworkMode );
       
   117     
       
   118     iProfileEngine = CreateProfileEngineL();
       
   119     
       
   120     iNotifyHandler = ProEngFactory::NewNotifyHandlerL();    
       
   121     iNotifyHandler->RequestProfileActivationNotificationsL( *this );
       
   122     
       
   123     //Checking if HSDPA setting is suppose to be visible
       
   124     CRepository* hsdpaRepository = CRepository::NewL( KCRUidNetworkSettings );
       
   125     User::LeaveIfError( hsdpaRepository->Get( KSettingsHSDPAVisbility, 
       
   126                                         iHSDPASettingSupport ) );
       
   127     
       
   128     BaseConstructL( R_GS_PDATAHSDPA_VIEW );
       
   129     
       
   130     delete hsdpaRepository;
       
   131     }
       
   132 
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // CGSPDataHSDPAPlugin::NewL()
       
   136 // Static constructor
       
   137 //
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 CGSPDataHSDPAPlugin* CGSPDataHSDPAPlugin::NewL( TAny* /*aInitParams*/ )
       
   141     {
       
   142     CGSPDataHSDPAPlugin* self = 
       
   143                                    new( ELeave ) CGSPDataHSDPAPlugin();
       
   144     CleanupStack::PushL( self );
       
   145     self->ConstructL();
       
   146     CleanupStack::Pop( self );
       
   147     return self;
       
   148     }
       
   149 
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CGSPDataHSDPAPlugin::Id
       
   153 //
       
   154 //
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 TUid CGSPDataHSDPAPlugin::Id() const
       
   158     {
       
   159     return KGSPDataHSDPAPluginUID;
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CGSPDataHSDPAPlugin::DoActivateL
       
   164 //
       
   165 //
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 void CGSPDataHSDPAPlugin::DoActivateL( const TVwsViewId& /*aPrevViewId*/,
       
   169                                   TUid /*aCustomMessageId*/,
       
   170                                   const TDesC8& /*aCustomMessage*/ )
       
   171     {
       
   172     }
       
   173 
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // CGSPDataHSDPAPlugin::DoDeactivate
       
   177 //
       
   178 //
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CGSPDataHSDPAPlugin::DoDeactivate()
       
   182     {
       
   183     }
       
   184 
       
   185 
       
   186 // ========================= From CGSPluginInterface ==================
       
   187 
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CGSPDataHSDPAPlugin::GetCaptionL
       
   191 //
       
   192 //
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 void CGSPDataHSDPAPlugin::GetCaptionL( TDes& aCaption ) const
       
   196     {
       
   197     HBufC* result = StringLoader::LoadL( R_GS_PDATAHSDPA_PLUGIN_CAPTION );
       
   198     aCaption.Copy( *result );
       
   199     delete result;
       
   200     }
       
   201 
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CGSPDataHSDPAPlugin::PluginProviderCategory
       
   205 //
       
   206 //
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 TInt CGSPDataHSDPAPlugin::PluginProviderCategory() const
       
   210     {
       
   211     return KGSPluginProviderInternal;
       
   212     }
       
   213 
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // CGSPDataHSDPAPlugin::ItemType()
       
   217 //
       
   218 //
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 TGSListboxItemTypes CGSPDataHSDPAPlugin::ItemType()
       
   222     {
       
   223     return EGSItemTypeSettingDialog;
       
   224     }
       
   225 
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CGSPDataHSDPAPlugin::GetValue()
       
   229 //
       
   230 //
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 void CGSPDataHSDPAPlugin::GetValue( const TGSPluginValueKeys aKey,
       
   234                                               TDes& aValue )
       
   235     {
       
   236     TRAPD( err, GetValueL( aValue ) );
       
   237     if ( err != KErrNone )
       
   238         {
       
   239         CGSPluginInterface::GetValue( aKey, aValue );
       
   240         }
       
   241     }
       
   242 
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // CGSPDataHSDPAPlugin::GetValueL()
       
   246 //
       
   247 // Leaving version of GetValue()
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 void CGSPDataHSDPAPlugin::GetValueL( TDes& aValue )
       
   251     {
       
   252     const TInt hsdpaState = iModel->CurrentHSDPAItemL();
       
   253     HBufC* result;
       
   254 
       
   255     switch( hsdpaState )
       
   256         {
       
   257         case KSettingHsdpaEnable:
       
   258             result = StringLoader::LoadL( R_GS_HSDPA_ENABLE_TEXT );
       
   259             aValue.Copy( *result );
       
   260             delete result;
       
   261             break;
       
   262         case KSettingHsdpaDisable:
       
   263             result = StringLoader::LoadL( R_GS_HSDPA_DISABLE_TEXT );
       
   264             aValue.Copy( *result );
       
   265             delete result;
       
   266          default:
       
   267             break;
       
   268         }
       
   269 
       
   270     }
       
   271 
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 // CGSPDataHSDPAPlugin::HandleSelection()
       
   275 //
       
   276 //
       
   277 // -----------------------------------------------------------------------------
       
   278 //
       
   279 void CGSPDataHSDPAPlugin::HandleSelection(
       
   280     const TGSSelectionTypes aSelectionType )
       
   281     {
       
   282     switch( aSelectionType )
       
   283         {
       
   284         // Launch setting page to change value.
       
   285         case EGSSelectionBySelectionKey:
       
   286         case EGSSelectionByMenu:
       
   287             TRAP_IGNORE( SetHSDPAStateL() );  
       
   288             break;
       
   289         default:
       
   290             break;
       
   291         }
       
   292 
       
   293     }
       
   294 
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CGSPDataHSDPAPlugin::ShowHSDPASettingPageL()
       
   298 //
       
   299 // Indexes of HSDPA on/off items in a listbox are not the same as aPDataHSDPAState
       
   300 // value. Therefore matching between these two is required.
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 TBool CGSPDataHSDPAPlugin::ShowHSDPASettingPageL( TInt& aHsdpaState )
       
   304     {
       
   305     TInt prevHsdpaState = aHsdpaState;
       
   306     TInt selectedIndex;
       
   307     TBool isValueUpdated = EFalse;
       
   308 
       
   309     // Match HSDPA state to lbx item index:
       
   310     switch( aHsdpaState )
       
   311         {
       
   312         case KSettingHsdpaEnable:
       
   313             selectedIndex = KSettingHsdpaDisable;
       
   314             break;
       
   315         case KSettingHsdpaDisable:
       
   316             selectedIndex = KSettingHsdpaEnable;
       
   317             break;
       
   318         }
       
   319     CDesCArrayFlat* items = iCoeEnv->ReadDesC16ArrayResourceL( 
       
   320                             R_GS_PDATAHSDPA_SETTING_PAGE_LBX );
       
   321     CleanupStack::PushL( items );
       
   322 
       
   323     CAknRadioButtonSettingPage* dlg =
       
   324         new (ELeave) CAknRadioButtonSettingPage
       
   325                                   ( R_GS_PDATAHSDPA_SETTING_PAGE,
       
   326                                     selectedIndex,
       
   327                                     items );
       
   328     dlg->ExecuteLD( CAknSettingPage::EUpdateWhenChanged );
       
   329     CleanupStack::PopAndDestroy( items );
       
   330 
       
   331     // Match selected lbx item index to HSDPA state:
       
   332     switch( selectedIndex )
       
   333         {
       
   334         case KSettingHsdpaEnable:
       
   335             aHsdpaState = KSettingHsdpaDisable;
       
   336             break;
       
   337         case KSettingHsdpaDisable:
       
   338             aHsdpaState = KSettingHsdpaEnable;
       
   339             break;
       
   340         }
       
   341     // Check if aPDataHSDPAState has been changed:
       
   342     if( prevHsdpaState != aHsdpaState )
       
   343         {
       
   344         TInt connectionErr(KErrNone);
       
   345 		TInt networkStatus;
       
   346 	
       
   347 		CRepository* repository = CRepository::NewL( KCRUidCoreApplicationUIs );
       
   348 		connectionErr = repository->Get( KCoreAppUIsNetworkConnectionAllowed, 
       
   349 		                                 networkStatus );
       
   350 		delete repository;
       
   351 		
       
   352 		if ( connectionErr == KErrNone )
       
   353 			{
       
   354 			CAknQueryDialog* resetNote = CAknQueryDialog::NewL();
       
   355 		    if( resetNote->ExecuteLD( R_CONFIRM_NW_RESET_HSDPA ) )
       
   356             	{
       
   357         		ResetActiveConnectionsL();
       
   358         		isValueUpdated = ETrue;
       
   359 				}
       
   360 			}
       
   361         }
       
   362     return isValueUpdated;
       
   363     }
       
   364 
       
   365 // -----------------------------------------------------------------------------
       
   366 // CGSPDataHSDPAPlugin::SetHSDPAStateL()
       
   367 //
       
   368 //
       
   369 // -----------------------------------------------------------------------------
       
   370 //
       
   371 void CGSPDataHSDPAPlugin::SetHSDPAStateL()
       
   372     {
       
   373     // Get information of if there are open connections
       
   374     TInt hsdpaState = iModel->CurrentHSDPAItemL();
       
   375     const TBool isValueUpdated = ShowHSDPASettingPageL( hsdpaState );
       
   376     if ( isValueUpdated )
       
   377         {
       
   378         // Store updated Active Idle state:
       
   379         iModel->SetHSDPAItemValueL( hsdpaState );
       
   380         // Update HSDPA item's value to lbx:
       
   381         UpdateParentViewL();
       
   382         }
       
   383     }
       
   384 
       
   385 // -----------------------------------------------------------------------------
       
   386 // CGSPDataHSDPAPlugin::OpenLocalizedResourceFileL()
       
   387 //
       
   388 //
       
   389 // -----------------------------------------------------------------------------
       
   390 //
       
   391 void CGSPDataHSDPAPlugin::OpenLocalizedResourceFileL(
       
   392     const TDesC& aResourceFileName,
       
   393     RConeResourceLoader& aResourceLoader )
       
   394     {
       
   395     RFs fsSession;
       
   396     User::LeaveIfError( fsSession.Connect() );
       
   397 
       
   398     // Find the resource file:
       
   399     TParse parse;
       
   400     parse.Set( aResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL );
       
   401     TFileName fileName( parse.FullName() );
       
   402 
       
   403     // Get language of resource file:
       
   404     BaflUtils::NearestLanguageFile( fsSession, fileName );
       
   405 
       
   406     // Open resource file:
       
   407     aResourceLoader.OpenL( fileName );
       
   408 
       
   409     // If leave occurs before this, close is called automatically when the
       
   410     // thread exits.
       
   411     fsSession.Close();
       
   412     }
       
   413 
       
   414 
       
   415 // -----------------------------------------------------------------------------
       
   416 // CGSPDataHSDPAPlugin::TGSMenuActivationItems()
       
   417 //
       
   418 //
       
   419 // -----------------------------------------------------------------------------
       
   420 //
       
   421 TGSMenuActivationItems CGSPDataHSDPAPlugin::MenuActivationItem()
       
   422     {
       
   423     return EGSMenuActivationItemChange;
       
   424     }
       
   425 
       
   426 
       
   427 // ----------------------------------------------------------------------------
       
   428 // CGSPDataHSDPAPlugin
       
   429 //
       
   430 // Provides the visibility status of self to framework.
       
   431 // ----------------------------------------------------------------------------
       
   432 //
       
   433 TBool CGSPDataHSDPAPlugin::Visible() const
       
   434     {
       
   435     // We check for if HSDPA item is supported to make it visble
       
   436     TBool hsdpaVisible = EFalse;
       
   437     if ( FeatureManager::FeatureSupported( KFeatureIdHsxpaSupport ) &&
       
   438          iNetworkMode == ENWNetworkModeWcdma &&
       
   439          iProfileEngine->ActiveProfileId() != EProfileOffLineId &&
       
   440          iHSDPASettingSupport )
       
   441         {
       
   442         hsdpaVisible = ETrue;
       
   443         }
       
   444     return hsdpaVisible;
       
   445     }
       
   446 
       
   447 // ---------------------------------------------------------------------------
       
   448 // CGSPDataHSDPAPlugin::ResetActiveConnectionsL
       
   449 //
       
   450 // All Active connections if any, are reset
       
   451 // instead of rebooting the phone, this is all
       
   452 // to make sure that HSDPA setting item is enabled or disabled
       
   453 // from UI level which now doesnt conflict to exact functionality of CoreUi
       
   454 // ---------------------------------------------------------------------------
       
   455 //  
       
   456 void CGSPDataHSDPAPlugin::ResetActiveConnectionsL()
       
   457 {
       
   458 #ifdef RD_STARTUP_CHANGE
       
   459 	RStarterSession rSession;
       
   460 	
       
   461 	if( iProfileEngine->ActiveProfileId() != EProfileOffLineId )
       
   462 		{	
       
   463 		User::LeaveIfError( rSession.Connect() );	
       
   464 		rSession.ResetNetwork();
       
   465 		rSession.Close();
       
   466 		}
       
   467     
       
   468 #endif
       
   469 }
       
   470 
       
   471 // ---------------------------------------------------------------------------
       
   472 // CGSPDataHSDPAPlugin::HandleNotifyPSL
       
   473 //
       
   474 // Handling PS keys change
       
   475 // ---------------------------------------------------------------------------
       
   476 //  
       
   477 void CGSPDataHSDPAPlugin::HandleNotifyPSL( const TUid aUid, const TInt& aKey,
       
   478                                           const TRequestStatus& /* aStatus */ )
       
   479     {
       
   480     // We check the NW mode value from PS Key
       
   481     if ( aUid == KPSUidNetworkInfo && 
       
   482          aKey == KNWTelephonyNetworkMode )
       
   483         {
       
   484         iNwModeListener->Get( iNetworkMode );
       
   485         }
       
   486 	UpdateParentViewL();     
       
   487     }
       
   488 
       
   489 
       
   490 // ----------------------------------------------------------------------------
       
   491 // CGSPDataHSDPAPlugin::HandleProfileActivatedL
       
   492 // From MProEngProfileActivationObserver
       
   493 //
       
   494 // Callback for device profile change
       
   495 // Used for observing offline mode activation
       
   496 // ----------------------------------------------------------------------------
       
   497 //
       
   498 void CGSPDataHSDPAPlugin::HandleProfileActivatedL( TInt /*aProfileId*/ )
       
   499     {
       
   500     UpdateParentViewL();
       
   501     }
       
   502 
       
   503 // ----------------------------------------------------------------------------
       
   504 // CGSPDataHSDPAPlugin::UpdateParentViewL
       
   505 // 
       
   506 // Updating parent view
       
   507 // ----------------------------------------------------------------------------
       
   508 //
       
   509 void CGSPDataHSDPAPlugin::UpdateParentViewL()
       
   510     {    
       
   511     CGSParentPlugin* parent = static_cast<CGSParentPlugin*>(
       
   512             AppUi()->View( KGSPDataPluginUid ) );// This is the parent plugin
       
   513             
       
   514     // Now let's check if Standby view is active
       
   515     TGSCustomOperationType paramValue = EGSCustomOperationViewActive;
       
   516     TAny* param = &paramValue;
       
   517     TAny* returnValue = parent->CustomOperationL( param, NULL );
       
   518     TBool* ViewActive = static_cast<TBool*> ( returnValue );
       
   519     
       
   520     if ( *ViewActive )
       
   521         {
       
   522         if ( parent )
       
   523             {
       
   524             parent->UpdateView();
       
   525             }
       
   526         }
       
   527     }
       
   528     
       
   529 // End of file