cmmanager/gsconnsettingsplugin/src/gsconnsettingsplugincontainer.cpp
changeset 0 5a93021fdf25
child 4 77415202bfc8
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     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     iIsWlanSupported = FeatureManager::FeatureSupported( KFeatureIdProtocolWlan );
       
   147     }
       
   148 
       
   149 void CGSConnSettingsPluginContainer::SetPluginArray ( 
       
   150                                 CArrayPtrFlat<CGSPluginInterface>* aPluginArray )
       
   151 {
       
   152     iPluginArray = aPluginArray;
       
   153 }
       
   154 
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // GSConnSettingsPluginContainer::ConstructListBoxL()
       
   158 // 
       
   159 //
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 void CGSConnSettingsPluginContainer::ConstructListBoxL( TInt aResLbxId )
       
   163     {
       
   164     iListBox->ConstructL( this, EAknListBoxSelectionList );
       
   165     iListboxItemArray = CGSListBoxItemTextArray::NewL( aResLbxId, *iListBox, *iCoeEnv );
       
   166     iListBoxTextArray = static_cast<CDesCArray*>( iListBox->Model()->ItemTextArray() );
       
   167     iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   168     
       
   169     if ( iIsWlanSupported )
       
   170         {
       
   171         iUsageOfWlanItems = iCoeEnv->ReadDesC16ArrayResourceL(
       
   172                 R_USAGE_OF_WLAN_SETTING_PAGE_LBX );
       
   173 
       
   174         iDataUsageHomeNwItems = iCoeEnv->ReadDesC16ArrayResourceL( 
       
   175                 R_DATA_USAGE_HOME_NW_SETTING_PAGE_LBX );
       
   176     
       
   177         iDataUsageAbroadItems = iCoeEnv->ReadDesC16ArrayResourceL( 
       
   178                 R_DATA_USAGE_ABROAD_SETTING_PAGE_LBX );
       
   179         
       
   180         iListItems = iCoeEnv->ReadDesC16ArrayResourceL( R_CONN_SETTINGS_LBX_TXT );
       
   181         }
       
   182     else
       
   183         {
       
   184         iDataUsageHomeNwItems = iCoeEnv->ReadDesC16ArrayResourceL( 
       
   185                 R_DATA_USAGE_HOME_NW_SETTING_PAGE_LBX_NOWLAN );
       
   186     
       
   187         iDataUsageAbroadItems = iCoeEnv->ReadDesC16ArrayResourceL( 
       
   188                 R_DATA_USAGE_ABROAD_SETTING_PAGE_LBX_NOWLAN );
       
   189         
       
   190         iListItems = iCoeEnv->ReadDesC16ArrayResourceL( R_CONN_SETTINGS_LBX_TXT_NOWLAN );
       
   191         }
       
   192         
       
   193     CreateListBoxItemsL();
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // GSConnSettingsPluginContainer::CreateListBoxItemsL()
       
   198 //
       
   199 //
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 void CGSConnSettingsPluginContainer::CreateListBoxItemsL()
       
   203     {   
       
   204     if ( iIsWlanSupported )
       
   205         {
       
   206         MakeUsageOfWlanNetworksItemL();
       
   207         iGeneralItemCount++;
       
   208         }
       
   209 
       
   210     MakeDataUsageHomeNwItemL();
       
   211     iGeneralItemCount++;
       
   212 
       
   213     MakeDataUsageAbroadItemL();
       
   214     iGeneralItemCount++;
       
   215 
       
   216     if ( iPluginArray )
       
   217         {
       
   218         MakeECOMPluginItemL();
       
   219         }
       
   220     iListBox->HandleItemAdditionL();
       
   221     }
       
   222 
       
   223 // ---------------------------------------------------------------------------
       
   224 // GSConnSettingsPluginContainer::UpdateListBoxL(TInt aFeatureId)
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 void CGSConnSettingsPluginContainer::UpdateListBoxL( TInt aFeatureId )
       
   228     {
       
   229     switch ( aFeatureId )
       
   230         {
       
   231         case  EGSSettIdUsageOfWlan:
       
   232             iListBoxTextArray->Delete( EGSSettIdUsageOfWlan );
       
   233             MakeUsageOfWlanNetworksItemL();
       
   234             break;
       
   235 
       
   236         case EGSSettIdDataUsageHomeNw:
       
   237             iListBoxTextArray->Delete( Index( EGSSettIdDataUsageHomeNw ) );
       
   238             MakeDataUsageHomeNwItemL();
       
   239             break;
       
   240             
       
   241         case EGSSettIdDataUsageAbroad:
       
   242             iListBoxTextArray->Delete( Index ( EGSSettIdDataUsageAbroad ) );
       
   243             MakeDataUsageAbroadItemL();
       
   244             break;
       
   245 
       
   246         case EGSExtPluginsListItemId:
       
   247             MakeECOMPluginItemL();
       
   248             break;     
       
   249                         
       
   250         default:
       
   251             break;
       
   252         }
       
   253     iListBox->HandleItemAdditionL();
       
   254     }
       
   255 
       
   256 
       
   257 // ---------------------------------------------------------------------------
       
   258 // CGSConnSettingsPluginContainer::AppendListItem
       
   259 // ---------------------------------------------------------------------------
       
   260 //
       
   261 void CGSConnSettingsPluginContainer::AppendListItemL( 
       
   262     const TInt aPos,
       
   263     const TDesC16& aFirstLabel, 
       
   264     const TDesC16& aSecondLabel )
       
   265     {
       
   266     TBuf<KGSBufSize128> itemText;
       
   267     _LIT( KSpaceAndTab, " \t" );
       
   268     _LIT( KTab, "\t" );
       
   269 
       
   270     // The format is: " \tFirstLabel\tSecondLabel\t0\t0"
       
   271     // First, append space and tab
       
   272     itemText.Append( KSpaceAndTab );
       
   273     itemText.Append( aFirstLabel );
       
   274     itemText.Append( KTab );
       
   275     itemText.Append( KTab );
       
   276     // Currently this is used only to show sensors active status (on/off)
       
   277     itemText.Append( aSecondLabel ); 
       
   278 
       
   279     // No need to add last tabs
       
   280     if ( ( KErrNotFound != aPos ) && ( aPos <= iListBoxTextArray->Count() ) )
       
   281         {
       
   282         iListBoxTextArray->InsertL( aPos, itemText );
       
   283         }
       
   284     else
       
   285         {
       
   286         iListBoxTextArray->AppendL( itemText );
       
   287         }
       
   288     }
       
   289 
       
   290 // ---------------------------------------------------------------------------
       
   291 // GSConnSettingsPluginContainer::MakeUsageOfNewWlanNetworksItemL()
       
   292 //
       
   293 // 
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 void CGSConnSettingsPluginContainer::MakeUsageOfWlanNetworksItemL()
       
   297     {
       
   298     TInt currValue = iModel->UsageOfWlan();
       
   299     AppendListItemL( EGSSettIdUsageOfWlan, 
       
   300         iListItems->operator[]( EGSSettIdUsageOfWlan ), 
       
   301         ( *iUsageOfWlanItems )[currValue] );
       
   302     }
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // GSConnSettingsPluginContainer::MakeDataUsageAbroadItemL()
       
   306 //
       
   307 // 
       
   308 // ---------------------------------------------------------------------------
       
   309 //
       
   310 void CGSConnSettingsPluginContainer::MakeDataUsageAbroadItemL()
       
   311 {
       
   312     TInt currValue = iModel->DataUsageAbroad();
       
   313     
       
   314     AppendListItemL( Index( EGSSettIdDataUsageAbroad ),
       
   315         iListItems->operator[]( Index( EGSSettIdDataUsageAbroad ) ),
       
   316         ( *iDataUsageAbroadItems )[currValue] );
       
   317 }
       
   318             
       
   319 // ---------------------------------------------------------------------------
       
   320 // GSConnSettingsPluginContainer::MakeDataUsageAbroadItemL()
       
   321 //
       
   322 // 
       
   323 // ---------------------------------------------------------------------------
       
   324 //
       
   325 void CGSConnSettingsPluginContainer::MakeDataUsageHomeNwItemL()
       
   326 {
       
   327     TInt currValue = iModel->DataUsageInHomeNw();
       
   328     
       
   329     AppendListItemL( Index( EGSSettIdDataUsageHomeNw ),
       
   330         iListItems->operator[]( Index( EGSSettIdDataUsageHomeNw ) ),
       
   331         ( *iDataUsageHomeNwItems )[currValue] );
       
   332 }
       
   333 
       
   334 
       
   335 // ---------------------------------------------------------------------------
       
   336 // CGSConnSettingsPluginContainer::MakeExtendedPluginsItemL
       
   337 // ---------------------------------------------------------------------------
       
   338 //
       
   339 void CGSConnSettingsPluginContainer::MakeECOMPluginItemL()
       
   340     {
       
   341 
       
   342     // Create list item for all child plug-ins
       
   343     const TInt pluginCount( iPluginArray->Count() );
       
   344     CGSPluginInterface* plugin = NULL;
       
   345 
       
   346     // 1) Read item descriptor from plugin:
       
   347     TBuf<KGSBufSize128> caption;
       
   348 
       
   349     for ( TInt i = 0; i < pluginCount; i++ )
       
   350         {
       
   351         plugin = iPluginArray->operator[]( i );
       
   352         //Append to list only if plugin is meant to be visible
       
   353         if( ( plugin ) && ( plugin->Visible() ) )
       
   354             {
       
   355             plugin->GetCaptionL( caption );
       
   356 
       
   357             // Append text to list
       
   358             AppendListItemL( KErrNotFound, caption, KNullDesC16 );
       
   359             }
       
   360         }        
       
   361     }
       
   362     
       
   363  
       
   364 // -----------------------------------------------------------------------------
       
   365 // CGSConnSettingsPluginContainer::SelectedPlugin
       
   366 // Returns pointer to selected plugin
       
   367 // -----------------------------------------------------------------------------
       
   368 //
       
   369 CGSPluginInterface* CGSConnSettingsPluginContainer::SelectedPluginL()
       
   370     {
       
   371     CGSPluginInterface* plugin = NULL;
       
   372 
       
   373     // 1) Decrease index with the count
       
   374     TInt index = iListBox->CurrentItemIndex() - iGeneralItemCount;
       
   375     
       
   376     // 2) Check that new index is in range of plugins
       
   377     if ( index >= 0 && index < iPluginArray->Count() )
       
   378         {
       
   379         // 3) Get correct plugin
       
   380         plugin = iPluginArray->operator[]( index );
       
   381         }
       
   382 
       
   383     // Leave if not found
       
   384     if ( !plugin )
       
   385         {
       
   386         User::Leave( KErrNotFound );
       
   387         }
       
   388 
       
   389     return plugin;
       
   390     }
       
   391 
       
   392 
       
   393 
       
   394 // ---------------------------------------------------------------------------
       
   395 // CGSConnSettingsPluginContainer::OfferKeyEventL
       
   396 // ---------------------------------------------------------------------------
       
   397 //
       
   398 TKeyResponse CGSConnSettingsPluginContainer::OfferKeyEventL( 
       
   399     const TKeyEvent& aKeyEvent, TEventCode aType )
       
   400     {
       
   401 
       
   402     TKeyResponse returnValue( EKeyWasNotConsumed );
       
   403 
       
   404     switch ( aKeyEvent.iCode )
       
   405         {
       
   406         case EKeyUpArrow:
       
   407         case EKeyDownArrow:
       
   408             {
       
   409             // Send key event to Listbox
       
   410             returnValue = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   411             // Change MSK label if needs to changed
       
   412             iMskObserver.CheckMiddleSoftkeyLabelL();
       
   413             break;
       
   414             }
       
   415         case EKeyLeftArrow:
       
   416         case EKeyRightArrow:
       
   417             {
       
   418             // Listbox takes all events even if it doesn't use them.
       
   419             // Stick with the default return value
       
   420             break;
       
   421             }
       
   422         default:
       
   423             {
       
   424             // Forward key event to listbox
       
   425             returnValue = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   426             break;
       
   427             }
       
   428         }
       
   429 
       
   430     return returnValue;
       
   431     }
       
   432 
       
   433 // ---------------------------------------------------------------------------
       
   434 // GSConnSettingsPluginContainer::CurrentFeatureId()
       
   435 //
       
   436 // ---------------------------------------------------------------------------
       
   437 //
       
   438 TInt CGSConnSettingsPluginContainer::CurrentFeatureId( ) const
       
   439     {
       
   440     return iListboxItemArray->CurrentFeature( );
       
   441     }
       
   442 
       
   443 // ---------------------------------------------------------------------------
       
   444 // GSConnSettingsPluginContainer::GetHelpContext() const
       
   445 // Gets Help
       
   446 //
       
   447 // ---------------------------------------------------------------------------
       
   448 //
       
   449 void CGSConnSettingsPluginContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   450     {
       
   451     aContext.iMajor = KUidGS;
       
   452 //    aContext.iContext = KCP_HLP_DISPLAY;
       
   453     }
       
   454 
       
   455 // ---------------------------------------------------------------------------
       
   456 // GSConnSettingsPluginContainer::Model()
       
   457 //
       
   458 // Return its member variable iModel.
       
   459 // ---------------------------------------------------------------------------
       
   460 //
       
   461 CGSConnSettingsPluginModel* CGSConnSettingsPluginContainer::Model()
       
   462     {
       
   463     return iModel;
       
   464     }
       
   465 
       
   466 // ---------------------------------------------------------------------------
       
   467 // GSConnSettingsPluginContainer::Index()
       
   468 //
       
   469 // Return index for the list.
       
   470 // ---------------------------------------------------------------------------
       
   471 //
       
   472 TInt CGSConnSettingsPluginContainer::Index( TInt aIndex )
       
   473     {
       
   474     return ( iIsWlanSupported ? ( aIndex ) : ( aIndex - 1) );
       
   475     }
       
   476     
       
   477 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   478 
       
   479 // End of File