systemsettings/gssensorplugin/src/gssensorplugincontainer.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     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:  Container for the sensor settings
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "gssensorplugincontainer.h"
       
    22 #include "gssensormskobserver.h"
       
    23 #include "gssensorpluginmodel.h"
       
    24 #include "gssensorplugin.hrh"
       
    25 #include "gssensorplugin_debug.h"
       
    26 
       
    27 #include <aknlists.h>
       
    28 #include <csxhelp/cp.hlp.hrh>
       
    29 #include <gsfwviewuids.h>     // for KUidGS
       
    30 #include <gssensorpluginrsc.rsg>
       
    31 #include <gslistbox.h>
       
    32 #include <gsplugininterface.h>
       
    33 
       
    34 // ========================== MEMBER FUNCTIONS ================================
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // CGSSensorPluginContainer::ConstructL
       
    38 // This constructL is not used
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 void CGSSensorPluginContainer::ConstructL( const TRect& /*aRect*/ )
       
    42     {
       
    43     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::ConstructL() - deprecated" );
       
    44     User::Leave( KErrArgument );
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CGSSensorPluginContainer::ConstructL
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 void CGSSensorPluginContainer::ConstructL( 
       
    52     const TRect& aRect,
       
    53     CAknViewAppUi* aAppUi,
       
    54     CArrayPtrFlat<CGSPluginInterface>* aPluginArray )
       
    55     {
       
    56     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::ConstructL()" );
       
    57 
       
    58     iAppUi = aAppUi;
       
    59     iPluginArray = aPluginArray;
       
    60 
       
    61     // Create list box and parent container
       
    62     iListBox = new ( ELeave ) CAknSettingStyleListBox;
       
    63     BaseConstructL( aRect, R_GS_SEN_VIEW_TITLE, R_GS_SEN_DOUBLE_LBX );
       
    64 
       
    65     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::ConstructL() - return" );  
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CGSSensorPluginContainer::~CGSSensorPluginContainer
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 CGSSensorPluginContainer::~CGSSensorPluginContainer()
       
    73     {
       
    74     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::~CGSSensorPluginContainer()" );
       
    75 
       
    76     if ( iListboxItemArray )
       
    77         {
       
    78         delete iListboxItemArray;
       
    79         }
       
    80 
       
    81      if ( iListBoxTextArray )
       
    82         {
       
    83         iListBoxTextArray->Reset();
       
    84         delete iListBoxTextArray;
       
    85         }
       
    86     
       
    87     if ( iSensorStatusText )
       
    88         {
       
    89         iSensorStatusText->Reset();
       
    90         delete iSensorStatusText;
       
    91         }
       
    92 
       
    93     if ( iListItems )
       
    94         {
       
    95         iListItems->Reset();
       
    96         delete iListItems;
       
    97         }
       
    98 
       
    99     iModel = NULL;
       
   100     iAppUi = NULL;
       
   101     iPluginArray = NULL;
       
   102 
       
   103     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::~CGSSensorPluginContainer() - return" );
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // CGSSensorPluginContainer::CGSSensorPluginContainer
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 CGSSensorPluginContainer::CGSSensorPluginContainer( 
       
   111     CGSSensorPluginModel* aModel,
       
   112     MGSSensorMskObserver& aMskObserver )
       
   113     : iModel ( aModel ),
       
   114       iMskObserver( aMskObserver )
       
   115     {
       
   116     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::CGSSensorPluginContainer()" );
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CGSSensorPluginContainer::ConstructListBoxL
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CGSSensorPluginContainer::ConstructListBoxL( TInt aResLbxId )
       
   124     {
       
   125     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::ConstructListBoxL()" );
       
   126     iListBox->ConstructL( this, EAknListBoxSelectionList );
       
   127     iListboxItemArray = CGSListBoxItemTextArray::NewL( aResLbxId, *iListBox, *iCoeEnv );
       
   128     iListBoxTextArray = static_cast<CDesCArray*>( iListBox->Model()->ItemTextArray() );
       
   129     iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   130 
       
   131     // Get sensors activation status and set text 'On' or 'Off' to list view below 
       
   132     // Sensors list item
       
   133     iSensorStatusText = iCoeEnv->ReadDesC16ArrayResourceL( R_GS_SENSOR_ACTIVE_STATUS );
       
   134     iListItems = iCoeEnv->ReadDesC16ArrayResourceL( R_GS_SEN_DOUBLE_LBX_TEXT );
       
   135     // Create and make visible list box items
       
   136     CreateListBoxItemsL();
       
   137 
       
   138     iListBox->HandleItemAdditionL();
       
   139     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::ConstructListBoxL() - return" );
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CGSSensorPluginContainer::CreateListBoxItemsL
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CGSSensorPluginContainer::CreateListBoxItemsL()
       
   147     {
       
   148     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::CreateListBoxItemsL()" );
       
   149 
       
   150     iGeneralItemCount = 0;
       
   151 
       
   152     const TUint32 tapVariation = iModel->VariationListL( EGSSenTapping );
       
   153     const TUint32 turnVariation = iModel->VariationListL( EGSSenTurning );
       
   154 
       
   155     if ( tapVariation ||turnVariation )
       
   156         {
       
   157         // Make Sensors active status visible if there is at least one enabled use case
       
   158         MakeSensorsItemL();
       
   159         iGeneralItemCount++;
       
   160         
       
   161         if ( !tapVariation )
       
   162             {
       
   163             iListboxItemArray->SetItemVisibilityL( EGSTapCtrlListItemId,
       
   164                 CGSListBoxItemTextArray::EInvisible );
       
   165             }
       
   166         else
       
   167             {
       
   168             MakeTapCtrlItemL();
       
   169             iGeneralItemCount++;
       
   170             }
       
   171         
       
   172         if ( !turnVariation )
       
   173             {
       
   174             iListboxItemArray->SetItemVisibilityL( EGSTurnCtrlListItemId,
       
   175                 CGSListBoxItemTextArray::EInvisible );
       
   176             }
       
   177         else
       
   178             {
       
   179             MakeTurnCtrlItemL();
       
   180             iGeneralItemCount++;
       
   181             }
       
   182         }
       
   183 
       
   184     if ( iPluginArray )
       
   185         {
       
   186         MakeExtendedPluginsItemL();
       
   187         }
       
   188 
       
   189 
       
   190     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::CreateListBoxItemsL() - return" );
       
   191     }
       
   192 
       
   193 // ---------------------------------------------------------------------------
       
   194 // CGSSensorPluginContainer::UpdateListBoxL
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 void CGSSensorPluginContainer::UpdateListBoxL( TInt aFeatureId )
       
   198     {
       
   199     TRACE_1( "[GSSensorPlugin] CGSSensorPluginContainer::UpdateListBoxL() - feature: %i", 
       
   200         aFeatureId );
       
   201     switch ( aFeatureId )
       
   202         {
       
   203         case EGSSensorsListItemId:
       
   204             {
       
   205             // Delete current text and then create new
       
   206             iListBoxTextArray->Delete( EGSSensorsListItemId );
       
   207             MakeSensorsItemL();
       
   208             break;
       
   209             }
       
   210         case EGSExtPluginsListItemId:
       
   211             MakeExtendedPluginsItemL();
       
   212             break;
       
   213         case EGSTapCtrlListItemId:
       
   214         case EGSTurnCtrlListItemId:
       
   215         case EGSOrientationListItemId:
       
   216         default:
       
   217             break;
       
   218         }
       
   219 
       
   220     // Draw listbox again
       
   221     iListBox->HandleItemAdditionL();
       
   222     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::UpdateListBoxL() - return" );
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // CGSSensorPluginContainer::MakeSensorsItemL
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void CGSSensorPluginContainer::MakeSensorsItemL()
       
   230     {
       
   231     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::MakeSensorsItemL()" );
       
   232     const TInt sensorsStatus = iModel->SensorActiveStatusL();
       
   233     SetSensorStatusTextL( sensorsStatus );
       
   234     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::MakeSensorsItemL() - return" );
       
   235     }
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // CGSSensorPluginContainer::MakeTapCtrlItemL
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CGSSensorPluginContainer::MakeTapCtrlItemL()
       
   242     {
       
   243     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::MakeTapCtrlItemL()" );
       
   244     AppendListItemL( EGSTapCtrlListItemId, 
       
   245                      iListItems->operator[]( EGSTapCtrlListItemId ), 
       
   246                      KNullDesC16 );
       
   247     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::MakeTapCtrlItemL() - return" );
       
   248     }
       
   249 
       
   250 // ---------------------------------------------------------------------------
       
   251 // CGSSensorPluginContainer::MakeTurnCntrItemL
       
   252 // ---------------------------------------------------------------------------
       
   253 //
       
   254 void CGSSensorPluginContainer::MakeTurnCtrlItemL()
       
   255     {
       
   256     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::MakeTurnCtrlItemL()" );
       
   257     AppendListItemL( EGSTurnCtrlListItemId, 
       
   258                      iListItems->operator[]( EGSTurnCtrlListItemId ), 
       
   259                      KNullDesC16 );
       
   260     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::MakeTurnCtrlItemL() - return" );
       
   261     }
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 // CGSSensorPluginContainer::MakeOrientationItemL
       
   265 // ---------------------------------------------------------------------------
       
   266 //
       
   267 void CGSSensorPluginContainer::MakeOrientationItemL()
       
   268     {
       
   269     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::MakeOrientationItemL()" );
       
   270     User::Leave( KErrNotSupported );
       
   271     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::MakeOrientationItemL() - return" );
       
   272     }
       
   273 
       
   274 // ---------------------------------------------------------------------------
       
   275 // CGSSensorPluginContainer::MakeExtendedPluginsItemL
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 void CGSSensorPluginContainer::MakeExtendedPluginsItemL()
       
   279     {
       
   280     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::MakeExtendedPluginsItemL()" );
       
   281     // Create list item for all child plug-ins
       
   282     const TInt pluginCount( iPluginArray->Count() );
       
   283     CGSPluginInterface* plugin = NULL;
       
   284 
       
   285     const TUint32 tapVariation = iModel->VariationListL( EGSSenTapping );
       
   286     const TUint32 turnVariation = iModel->VariationListL( EGSSenTurning );
       
   287 
       
   288     if ( ( pluginCount == 1 ) && ( !tapVariation && !turnVariation ) )
       
   289         {
       
   290         ActivateExtendedPluginL();
       
   291         }
       
   292     else
       
   293         {
       
   294         // 1) Read item descriptor from plugin:
       
   295         TBuf<KGSBufSize128> caption;
       
   296 
       
   297         for ( TInt i = 0; i < pluginCount; i++ )
       
   298             {
       
   299             plugin = iPluginArray->operator[]( i );
       
   300             plugin->GetCaptionL( caption );
       
   301             // Append text to list
       
   302             AppendListItemL( KErrNotFound, caption, KNullDesC16 );
       
   303             }
       
   304         }
       
   305     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::MakeExtendedPluginsItemL() - return" );
       
   306     }
       
   307 
       
   308 // ---------------------------------------------------------------------------
       
   309 // CGSSensorPluginContainer::ActivateExtendedPluginL
       
   310 // ---------------------------------------------------------------------------
       
   311 //
       
   312 void CGSSensorPluginContainer::ActivateExtendedPluginL()
       
   313     {
       
   314     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::ActivateExtendedPluginL()" );
       
   315     // Not local view, try plugins
       
   316     if ( iPluginArray->Count() == 1)
       
   317         {
       
   318         CGSPluginInterface* selectedPlugin = iPluginArray->operator[]( 0 );
       
   319     
       
   320         switch( selectedPlugin->ItemType() )
       
   321             {
       
   322             // In these cases the plugin is a view:
       
   323             case EGSItemTypeSingleLarge:
       
   324             case EGSItemTypeSetting:
       
   325             case EGSItemTypeSettingIcon:
       
   326                 {
       
   327                 CleanupStack::PushL( selectedPlugin );
       
   328                 iAppUi->ActivateLocalViewL( selectedPlugin->Id() );
       
   329                 CleanupStack::Pop( selectedPlugin );
       
   330                 break;
       
   331                 }
       
   332                 
       
   333             // In these cases the plugin is a dialog:
       
   334             case EGSItemTypeSettingDialog:
       
   335             case EGSItemTypeSingleLargeDialog:
       
   336                  selectedPlugin->HandleSelection( EGSSelectionByMenu );
       
   337                  break;
       
   338             default:
       
   339                 break;
       
   340             }
       
   341         }
       
   342     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::ActivateExtendedPluginL() - return" );
       
   343     }
       
   344 
       
   345 
       
   346 // ---------------------------------------------------------------------------
       
   347 // CGSSensorPluginContainer::AppendListItem
       
   348 // ---------------------------------------------------------------------------
       
   349 //
       
   350 void CGSSensorPluginContainer::AppendListItemL( 
       
   351     const TInt aPos,
       
   352     const TDesC16& aFirstLabel, 
       
   353     const TDesC16& aSecondLabel )
       
   354     {
       
   355     TBuf<KGSBufSize128> itemText;
       
   356     _LIT( KSpaceAndTab, " \t" );
       
   357     _LIT( KTab, "\t" );
       
   358 
       
   359     // The format is: " \tFirstLabel\tSecondLabel\t0\t0"
       
   360     // First, append space and tab
       
   361     itemText.Append( KSpaceAndTab );
       
   362     itemText.Append( aFirstLabel );
       
   363     itemText.Append( KTab );
       
   364     itemText.Append( KTab );
       
   365     // Currently this is used only to show sensors active status (on/off)
       
   366     itemText.Append( aSecondLabel ); 
       
   367 
       
   368     // No need to add last tabs
       
   369     if ( ( KErrNotFound != aPos ) && ( aPos <= iListBoxTextArray->Count() ) )
       
   370         {
       
   371         iListBoxTextArray->InsertL( aPos, itemText );
       
   372         }
       
   373     else
       
   374         {
       
   375         iListBoxTextArray->AppendL( itemText );
       
   376         }
       
   377     }
       
   378 
       
   379 // -----------------------------------------------------------------------------
       
   380 // CGSSensorPluginContainer::SelectedPlugin
       
   381 // Returns pointer to selected plugin
       
   382 // -----------------------------------------------------------------------------
       
   383 //
       
   384 CGSPluginInterface* CGSSensorPluginContainer::SelectedPluginL()
       
   385     {
       
   386     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::SelectedPlugin()" );
       
   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     TRACE_1( "[GSSensorPlugin] CGSSensorPluginContainer::SelectedPlugin() - return: 0x%x", plugin );
       
   406     return plugin;
       
   407     }
       
   408 
       
   409 // ---------------------------------------------------------------------------
       
   410 // CGSSensorPluginContainer::CurrentFeatureId
       
   411 // ---------------------------------------------------------------------------
       
   412 //
       
   413 TInt CGSSensorPluginContainer::CurrentFeatureId() const
       
   414     {
       
   415     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::CurrentFeatureId()" );
       
   416     return iListboxItemArray->CurrentFeature();
       
   417     }
       
   418 
       
   419 // ---------------------------------------------------------------------------
       
   420 // CGSSensorPluginContainer::OfferKeyEventL
       
   421 // ---------------------------------------------------------------------------
       
   422 //
       
   423 TKeyResponse CGSSensorPluginContainer::OfferKeyEventL( 
       
   424     const TKeyEvent& aKeyEvent, TEventCode aType )
       
   425     {
       
   426     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::OfferKeyEventL()" );
       
   427 
       
   428     TKeyResponse returnValue( EKeyWasNotConsumed );
       
   429 
       
   430     switch ( aKeyEvent.iCode )
       
   431         {
       
   432         case EKeyUpArrow:
       
   433         case EKeyDownArrow:
       
   434             {
       
   435             // Send key event to Listbox
       
   436             returnValue = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   437             // Change MSK label if needs to changed
       
   438             iMskObserver.CheckMiddleSoftkeyLabelL();
       
   439             break;
       
   440             }
       
   441         case EKeyLeftArrow:
       
   442         case EKeyRightArrow:
       
   443             {
       
   444             // Listbox takes all events even if it doesn't use them.
       
   445             // Stick with the default return value
       
   446             break;
       
   447             }
       
   448         default:
       
   449             {
       
   450             // Forward key event to listbox
       
   451             returnValue = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   452             break;
       
   453             }
       
   454         }
       
   455 
       
   456     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::OfferKeyEventL() - return" );
       
   457     return returnValue;
       
   458     }
       
   459 
       
   460 // ---------------------------------------------------------------------------
       
   461 // CGSSensorPluginContainer::GetHelpContext
       
   462 // ---------------------------------------------------------------------------
       
   463 //
       
   464 void CGSSensorPluginContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   465     {
       
   466     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::GetHelpContext()" );
       
   467     aContext.iMajor = KUidGS;
       
   468     aContext.iContext = KSSET_HLP_MAIN_VIEW;
       
   469     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::GetHelpContext() - return" );
       
   470     }
       
   471 
       
   472 // ---------------------------------------------------------------------------
       
   473 // CGSSensorPluginContainer::SetSensorStatusTextL
       
   474 // Setting Sensors status Text based on the value sent,
       
   475 // '0' meams "Off" & '1' Means 'On'
       
   476 // ---------------------------------------------------------------------------
       
   477 //
       
   478 void CGSSensorPluginContainer::SetSensorStatusTextL( TInt aValue )
       
   479     {
       
   480     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::SetSensorStatusTextL()" );
       
   481     AppendListItemL( 
       
   482         EGSSensorsListItemId, 
       
   483         iListItems->operator[]( EGSSensorsListItemId ), 
       
   484         ( *iSensorStatusText )[aValue] );
       
   485     TRACE_( "[GSSensorPlugin] CGSSensorPluginContainer::SetSensorStatusTextL() - return" );
       
   486     }