cmmanager/gsconnsettingsplugin/src/gsconnsettingsplugincontainer.cpp
changeset 23 7ec726f93df1
parent 20 9c97ad6591ae
child 25 d840bfde7d40
child 27 489cf6208544
equal deleted inserted replaced
20:9c97ad6591ae 23:7ec726f93df1
     1 /*
       
     2 * Copyright (c) 2005 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:  Container for the Connectivity Settings plugin
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <featmgr.h>
       
    20 #include "gsconnsettingsplugincontainer.h"
       
    21 #include "gsconnsettingspluginmodel.h"
       
    22 #include "gsconnsettingsplugin.h"
       
    23 #include "gsconnsettingsplugin.hrh"
       
    24 #include "gsconnsettingsmskobserver.h"
       
    25 #include <gsconnsettingspluginrsc.rsg>
       
    26 
       
    27 #include <aknlists.h>
       
    28 #include <csxhelp/cp.hlp.hrh>
       
    29 #include <gsfwviewuids.h>     // for KUidGS
       
    30 #include <gslistbox.h>
       
    31 
       
    32 
       
    33 // EXTERNAL DATA STRUCTURES
       
    34 
       
    35 // EXTERNAL FUNCTION PROTOTYPES
       
    36 
       
    37 // CONSTANTS
       
    38 
       
    39 // MACROS
       
    40 
       
    41 // LOCAL CONSTANTS AND MACROS
       
    42 const   TInt    KGSBufSize128 = 128;
       
    43 
       
    44 // MODULE DATA STRUCTURES
       
    45 
       
    46 // LOCAL FUNCTION PROTOTYPES
       
    47 
       
    48 // FORWARD DECLARATIONS
       
    49 
       
    50 // ============================= LOCAL FUNCTIONS ==============================
       
    51 
       
    52 // ========================== MEMBER FUNCTIONS ================================
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CGSDisplayPluginContainer::ConstructL(const TRect& aRect)
       
    56 // Symbian OS two phased constructor
       
    57 //
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 void CGSConnSettingsPluginContainer::ConstructL( const TRect& aRect )
       
    61     {
       
    62     iListBox = new ( ELeave ) CAknSettingStyleListBox;
       
    63     iModel = CGSConnSettingsPluginModel::NewL();
       
    64     iModel->SetOwner( this );
       
    65     
       
    66     //Load saved settings from Connection Settings API
       
    67     //If function leaves it is trapped and ignored as there is nothing that we can do about it
       
    68     TRAP_IGNORE(iModel->LoadSettingsL());
       
    69 
       
    70     if ( iIsWlanSupported )
       
    71         {
       
    72         BaseConstructL( aRect, R_GS_CONN_SETTINGS_PLUGIN_VIEW_TITLE, R_CONN_SETTINGS_LBX );
       
    73         }
       
    74     else
       
    75         {
       
    76         BaseConstructL( aRect, R_GS_CONN_SETTINGS_PLUGIN_VIEW_TITLE, R_CONN_SETTINGS_LBX_NOWLAN );
       
    77         }
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // GSConnSettingsPluginContainer::~GSConnSettingsPluginContainer()
       
    82 //
       
    83 // Destructor
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 CGSConnSettingsPluginContainer::~CGSConnSettingsPluginContainer()
       
    87     {    
       
    88     //Note: iListbox is not deleted here as base class destructor handels it
       
    89     
       
    90     if ( iModel )
       
    91         {        
       
    92         delete iModel;
       
    93         iModel = NULL;
       
    94         }
       
    95 
       
    96     if ( iListboxItemArray )
       
    97         {
       
    98         delete iListboxItemArray;
       
    99         }
       
   100     
       
   101     if ( iListBoxTextArray )
       
   102        {
       
   103        iListBoxTextArray->Reset();
       
   104        delete iListBoxTextArray;
       
   105        }
       
   106     
       
   107     if ( iIsWlanSupported )
       
   108         {
       
   109         if ( iUsageOfWlanItems )
       
   110             {
       
   111             iUsageOfWlanItems->Reset();
       
   112             delete iUsageOfWlanItems;
       
   113             }
       
   114         }
       
   115 
       
   116     if ( iDataUsageAbroadItems )
       
   117         {
       
   118         iDataUsageAbroadItems->Reset();
       
   119         delete iDataUsageAbroadItems;
       
   120         }
       
   121 
       
   122     if ( iDataUsageHomeNwItems )
       
   123         {
       
   124         iDataUsageHomeNwItems->Reset();
       
   125         delete iDataUsageHomeNwItems;
       
   126         }    
       
   127 
       
   128     if ( iListItems )
       
   129         {
       
   130         iListItems->Reset();
       
   131         delete iListItems;
       
   132         }
       
   133     }
       
   134 
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // GSConnSettingsPluginContainer::GSConnSettingsPluginContainer()
       
   138 //
       
   139 // Constructor
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 CGSConnSettingsPluginContainer::CGSConnSettingsPluginContainer( 
       
   143         MGSConnSettingsMskObserver& aMskObserver )
       
   144         : iMskObserver( aMskObserver )
       
   145     {
       
   146     FeatureManager::InitializeLibL();
       
   147     iIsWlanSupported = FeatureManager::FeatureSupported( KFeatureIdProtocolWlan );
       
   148     FeatureManager::UnInitializeLib();
       
   149     }
       
   150 
       
   151 void CGSConnSettingsPluginContainer::SetPluginArray ( 
       
   152                                 CArrayPtrFlat<CGSPluginInterface>* aPluginArray )
       
   153 {
       
   154     iPluginArray = aPluginArray;
       
   155 }
       
   156 
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // GSConnSettingsPluginContainer::ConstructListBoxL()
       
   160 // 
       
   161 //
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 void CGSConnSettingsPluginContainer::ConstructListBoxL( TInt aResLbxId )
       
   165     {
       
   166     iListBox->ConstructL( this, EAknListBoxSelectionList );
       
   167     iListboxItemArray = CGSListBoxItemTextArray::NewL( aResLbxId, *iListBox, *iCoeEnv );
       
   168     iListBoxTextArray = static_cast<CDesCArray*>( iListBox->Model()->ItemTextArray() );
       
   169     iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   170     
       
   171     if ( iIsWlanSupported )
       
   172         {
       
   173         iUsageOfWlanItems = iCoeEnv->ReadDesC16ArrayResourceL(
       
   174                 R_USAGE_OF_WLAN_SETTING_PAGE_LBX );
       
   175 
       
   176         iDataUsageHomeNwItems = iCoeEnv->ReadDesC16ArrayResourceL( 
       
   177                 R_DATA_USAGE_HOME_NW_SETTING_PAGE_LBX );
       
   178     
       
   179         iDataUsageAbroadItems = iCoeEnv->ReadDesC16ArrayResourceL( 
       
   180                 R_DATA_USAGE_ABROAD_SETTING_PAGE_LBX );
       
   181         
       
   182         iListItems = iCoeEnv->ReadDesC16ArrayResourceL( R_CONN_SETTINGS_LBX_TXT );
       
   183         }
       
   184     else
       
   185         {
       
   186         iDataUsageHomeNwItems = iCoeEnv->ReadDesC16ArrayResourceL( 
       
   187                 R_DATA_USAGE_HOME_NW_SETTING_PAGE_LBX_NOWLAN );
       
   188     
       
   189         iDataUsageAbroadItems = iCoeEnv->ReadDesC16ArrayResourceL( 
       
   190                 R_DATA_USAGE_ABROAD_SETTING_PAGE_LBX_NOWLAN );
       
   191         
       
   192         iListItems = iCoeEnv->ReadDesC16ArrayResourceL( R_CONN_SETTINGS_LBX_TXT_NOWLAN );
       
   193         }
       
   194         
       
   195     CreateListBoxItemsL();
       
   196     }
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // GSConnSettingsPluginContainer::CreateListBoxItemsL()
       
   200 //
       
   201 //
       
   202 // ---------------------------------------------------------------------------
       
   203 //
       
   204 void CGSConnSettingsPluginContainer::CreateListBoxItemsL()
       
   205     {   
       
   206     if ( iIsWlanSupported )
       
   207         {
       
   208         MakeUsageOfWlanNetworksItemL();
       
   209         iGeneralItemCount++;
       
   210         }
       
   211 
       
   212     MakeDataUsageHomeNwItemL();
       
   213     iGeneralItemCount++;
       
   214 
       
   215     MakeDataUsageAbroadItemL();
       
   216     iGeneralItemCount++;
       
   217 
       
   218     if ( iPluginArray )
       
   219         {
       
   220         MakeECOMPluginItemL();
       
   221         }
       
   222     iListBox->HandleItemAdditionL();
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // GSConnSettingsPluginContainer::UpdateListBoxL(TInt aFeatureId)
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void CGSConnSettingsPluginContainer::UpdateListBoxL( TInt aFeatureId )
       
   230     {
       
   231     switch ( aFeatureId )
       
   232         {
       
   233         case  EGSSettIdUsageOfWlan:
       
   234             iListBoxTextArray->Delete( EGSSettIdUsageOfWlan );
       
   235             MakeUsageOfWlanNetworksItemL();
       
   236             break;
       
   237 
       
   238         case EGSSettIdDataUsageHomeNw:
       
   239             iListBoxTextArray->Delete( Index( EGSSettIdDataUsageHomeNw ) );
       
   240             MakeDataUsageHomeNwItemL();
       
   241             break;
       
   242             
       
   243         case EGSSettIdDataUsageAbroad:
       
   244             iListBoxTextArray->Delete( Index ( EGSSettIdDataUsageAbroad ) );
       
   245             MakeDataUsageAbroadItemL();
       
   246             break;
       
   247 
       
   248         case EGSExtPluginsListItemId:
       
   249             MakeECOMPluginItemL();
       
   250             break;     
       
   251                         
       
   252         default:
       
   253             break;
       
   254         }
       
   255     iListBox->HandleItemAdditionL();
       
   256     }
       
   257 
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // CGSConnSettingsPluginContainer::AppendListItem
       
   261 // ---------------------------------------------------------------------------
       
   262 //
       
   263 void CGSConnSettingsPluginContainer::AppendListItemL( 
       
   264     const TInt aPos,
       
   265     const TDesC16& aFirstLabel, 
       
   266     const TDesC16& aSecondLabel )
       
   267     {
       
   268     TBuf<KGSBufSize128> itemText;
       
   269     _LIT( KSpaceAndTab, " \t" );
       
   270     _LIT( KTab, "\t" );
       
   271 
       
   272     // The format is: " \tFirstLabel\tSecondLabel\t0\t0"
       
   273     // First, append space and tab
       
   274     itemText.Append( KSpaceAndTab );
       
   275     itemText.Append( aFirstLabel );
       
   276     itemText.Append( KTab );
       
   277     itemText.Append( KTab );
       
   278     // Currently this is used only to show sensors active status (on/off)
       
   279     itemText.Append( aSecondLabel ); 
       
   280 
       
   281     // No need to add last tabs
       
   282     if ( ( KErrNotFound != aPos ) && ( aPos <= iListBoxTextArray->Count() ) )
       
   283         {
       
   284         iListBoxTextArray->InsertL( aPos, itemText );
       
   285         }
       
   286     else
       
   287         {
       
   288         iListBoxTextArray->AppendL( itemText );
       
   289         }
       
   290     }
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // GSConnSettingsPluginContainer::MakeUsageOfNewWlanNetworksItemL()
       
   294 //
       
   295 // 
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 void CGSConnSettingsPluginContainer::MakeUsageOfWlanNetworksItemL()
       
   299     {
       
   300     TInt currValue = iModel->UsageOfWlan();
       
   301     AppendListItemL( EGSSettIdUsageOfWlan, 
       
   302         iListItems->operator[]( EGSSettIdUsageOfWlan ), 
       
   303         ( *iUsageOfWlanItems )[currValue] );
       
   304     }
       
   305 
       
   306 // ---------------------------------------------------------------------------
       
   307 // GSConnSettingsPluginContainer::MakeDataUsageAbroadItemL()
       
   308 //
       
   309 // 
       
   310 // ---------------------------------------------------------------------------
       
   311 //
       
   312 void CGSConnSettingsPluginContainer::MakeDataUsageAbroadItemL()
       
   313 {
       
   314     TInt currValue = iModel->DataUsageAbroad();
       
   315     
       
   316     // We may have to do in this way because EDataUsageAbroadDisabled is equal to 3
       
   317     // and the actual index number should be 2 in this case
       
   318     if( !iIsWlanSupported && currValue == EDataUsageAbroadDisabled )
       
   319         {
       
   320         currValue --;
       
   321         }
       
   322     
       
   323     AppendListItemL( Index( EGSSettIdDataUsageAbroad ),
       
   324         iListItems->operator[]( Index( EGSSettIdDataUsageAbroad ) ),
       
   325         ( *iDataUsageAbroadItems )[currValue] );
       
   326 }
       
   327             
       
   328 // ---------------------------------------------------------------------------
       
   329 // GSConnSettingsPluginContainer::MakeDataUsageAbroadItemL()
       
   330 //
       
   331 // 
       
   332 // ---------------------------------------------------------------------------
       
   333 //
       
   334 void CGSConnSettingsPluginContainer::MakeDataUsageHomeNwItemL()
       
   335 {
       
   336     TInt currValue = iModel->DataUsageInHomeNw();
       
   337     
       
   338     // We may have to do in this way because EDataUsageAbroadDisabled is equal to 3
       
   339     // and the actual index number should be 2 in this case
       
   340     if( !iIsWlanSupported && currValue == EDataUsageAbroadDisabled )
       
   341         {
       
   342         currValue --;
       
   343         }
       
   344     
       
   345     AppendListItemL( Index( EGSSettIdDataUsageHomeNw ),
       
   346         iListItems->operator[]( Index( EGSSettIdDataUsageHomeNw ) ),
       
   347         ( *iDataUsageHomeNwItems )[currValue] );
       
   348 }
       
   349 
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // CGSConnSettingsPluginContainer::MakeExtendedPluginsItemL
       
   353 // ---------------------------------------------------------------------------
       
   354 //
       
   355 void CGSConnSettingsPluginContainer::MakeECOMPluginItemL()
       
   356     {
       
   357 
       
   358     // Create list item for all child plug-ins
       
   359     const TInt pluginCount( iPluginArray->Count() );
       
   360     CGSPluginInterface* plugin = NULL;
       
   361 
       
   362     // 1) Read item descriptor from plugin:
       
   363     TBuf<KGSBufSize128> caption;
       
   364 
       
   365     for ( TInt i = 0; i < pluginCount; i++ )
       
   366         {
       
   367         plugin = iPluginArray->operator[]( i );
       
   368         //Append to list only if plugin is meant to be visible
       
   369         if( ( plugin ) && ( plugin->Visible() ) )
       
   370             {
       
   371             plugin->GetCaptionL( caption );
       
   372 
       
   373             // Append text to list
       
   374             AppendListItemL( KErrNotFound, caption, KNullDesC16 );
       
   375             }
       
   376         }        
       
   377     }
       
   378     
       
   379  
       
   380 // -----------------------------------------------------------------------------
       
   381 // CGSConnSettingsPluginContainer::SelectedPlugin
       
   382 // Returns pointer to selected plugin
       
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 CGSPluginInterface* CGSConnSettingsPluginContainer::SelectedPluginL()
       
   386     {
       
   387     CGSPluginInterface* plugin = NULL;
       
   388 
       
   389     // 1) Decrease index with the count
       
   390     TInt index = iListBox->CurrentItemIndex() - iGeneralItemCount;
       
   391     
       
   392     // 2) Check that new index is in range of plugins
       
   393     if ( index >= 0 && index < iPluginArray->Count() )
       
   394         {
       
   395         // 3) Get correct plugin
       
   396         plugin = iPluginArray->operator[]( index );
       
   397         }
       
   398 
       
   399     // Leave if not found
       
   400     if ( !plugin )
       
   401         {
       
   402         User::Leave( KErrNotFound );
       
   403         }
       
   404 
       
   405     return plugin;
       
   406     }
       
   407 
       
   408 
       
   409 
       
   410 // ---------------------------------------------------------------------------
       
   411 // CGSConnSettingsPluginContainer::OfferKeyEventL
       
   412 // ---------------------------------------------------------------------------
       
   413 //
       
   414 TKeyResponse CGSConnSettingsPluginContainer::OfferKeyEventL( 
       
   415     const TKeyEvent& aKeyEvent, TEventCode aType )
       
   416     {
       
   417 
       
   418     TKeyResponse returnValue( EKeyWasNotConsumed );
       
   419 
       
   420     switch ( aKeyEvent.iCode )
       
   421         {
       
   422         case EKeyUpArrow:
       
   423         case EKeyDownArrow:
       
   424             {
       
   425             // Send key event to Listbox
       
   426             returnValue = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   427             // Change MSK label if needs to changed
       
   428             iMskObserver.CheckMiddleSoftkeyLabelL();
       
   429             break;
       
   430             }
       
   431         case EKeyLeftArrow:
       
   432         case EKeyRightArrow:
       
   433             {
       
   434             // Listbox takes all events even if it doesn't use them.
       
   435             // Stick with the default return value
       
   436             break;
       
   437             }
       
   438         default:
       
   439             {
       
   440             // Forward key event to listbox
       
   441             returnValue = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   442             break;
       
   443             }
       
   444         }
       
   445 
       
   446     return returnValue;
       
   447     }
       
   448 
       
   449 // ---------------------------------------------------------------------------
       
   450 // GSConnSettingsPluginContainer::CurrentFeatureId()
       
   451 //
       
   452 // ---------------------------------------------------------------------------
       
   453 //
       
   454 TInt CGSConnSettingsPluginContainer::CurrentFeatureId( ) const
       
   455     {
       
   456     return iListboxItemArray->CurrentFeature( );
       
   457     }
       
   458 
       
   459 // ---------------------------------------------------------------------------
       
   460 // GSConnSettingsPluginContainer::GetHelpContext() const
       
   461 // Gets Help
       
   462 //
       
   463 // ---------------------------------------------------------------------------
       
   464 //
       
   465 void CGSConnSettingsPluginContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   466     {
       
   467     aContext.iMajor = KUidGS;
       
   468 //    aContext.iContext = KCP_HLP_DISPLAY;
       
   469     }
       
   470 
       
   471 // ---------------------------------------------------------------------------
       
   472 // GSConnSettingsPluginContainer::Model()
       
   473 //
       
   474 // Return its member variable iModel.
       
   475 // ---------------------------------------------------------------------------
       
   476 //
       
   477 CGSConnSettingsPluginModel* CGSConnSettingsPluginContainer::Model()
       
   478     {
       
   479     return iModel;
       
   480     }
       
   481 
       
   482 // ---------------------------------------------------------------------------
       
   483 // GSConnSettingsPluginContainer::Index()
       
   484 //
       
   485 // Return index for the list.
       
   486 // ---------------------------------------------------------------------------
       
   487 //
       
   488 TInt CGSConnSettingsPluginContainer::Index( TInt aIndex )
       
   489     {
       
   490     return ( iIsWlanSupported ? ( aIndex ) : ( aIndex - 1) );
       
   491     }
       
   492     
       
   493 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   494 
       
   495 // End of File