systemsettings/gssensorplugin/src/gssensorplugin.cpp
changeset 0 2e3d3ce01487
child 19 924385140d98
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:  Main view for Sensor plug-in.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <aknsettingpage.h>
       
    21 #include <hlplch.h>             // For HlpLauncher
       
    22 #include <bautils.h>
       
    23 #include <featmgr.h>
       
    24 #include <StringLoader.h>
       
    25 #include <AknQueryDialog.h>
       
    26 #include <aknnotedialog.h>
       
    27 #include <aknradiobuttonsettingpage.h>
       
    28 
       
    29 #include <gssensorpluginrsc.rsg>
       
    30 #include <gsprivatepluginproviderids.h>
       
    31 #include <gsfwviewuids.h>
       
    32 #include <gscommon.hrh>
       
    33 
       
    34 #include "gssensorplugin.h"
       
    35 #include "gssensorplugincontainer.h"
       
    36 #include "gssensorplugin.hrh"
       
    37 #include "gssensorpluginlocalviewids.h"
       
    38 #include "gssensorpluginmodel.h"
       
    39 #include "gssensorplugin_debug.h"
       
    40 
       
    41 // Local views
       
    42 #include "gssensensorsview.h"
       
    43 #include "gssentappingctrlview.h"
       
    44 #include "gssenturnctrlview.h"
       
    45 #include "gssenorientationview.h"
       
    46 
       
    47 // LOCAL CONSTANTS AND MACROS
       
    48 _LIT( KGSSensorPluginResourceFileName, "z:gssensorpluginrsc.rsc" );
       
    49 
       
    50 // Panic
       
    51 _LIT( KGSDoActivateError, "DoActivateL" );
       
    52 
       
    53 // Child plugin count
       
    54 const TInt KGSSenPluginCount = 10;
       
    55 
       
    56 #include <gssenplugin.mbg>
       
    57 
       
    58 #ifdef __SCALABLE_ICONS
       
    59 // bitmap
       
    60 _LIT( KGSSenPluginIconFileName, "\\resource\\apps\\gssenplugin.mif");
       
    61 #else //__SCALABLE_ICONS
       
    62 // svg file
       
    63 _LIT( KGSSenPluginIconFileName, "\\resource\\apps\\gssenplugin.mbm");
       
    64 #endif //__SCALABLE_ICONS
       
    65 
       
    66 
       
    67 // ----------------------------------------------------------------------------
       
    68 // CGSSensorPlugin::CGSSensorPlugin
       
    69 // Constructor
       
    70 // ----------------------------------------------------------------------------
       
    71 //
       
    72 CGSSensorPlugin::CGSSensorPlugin()
       
    73   : iResourceLoader( *iCoeEnv )
       
    74     {
       
    75     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::CGSSensorPlugin()" );
       
    76     }
       
    77 
       
    78 // ----------------------------------------------------------------------------
       
    79 // CGSSensorPlugin::NewL
       
    80 // Symbian OS default constructor
       
    81 // ----------------------------------------------------------------------------
       
    82 CGSSensorPlugin* CGSSensorPlugin::NewL( TAny* /*aInitParams*/ )
       
    83     {
       
    84     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::NewL()" );
       
    85     CGSSensorPlugin* self = new( ELeave ) CGSSensorPlugin();
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL();        
       
    88     CleanupStack::Pop( self );
       
    89     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::NewL() - return" );
       
    90     return self;
       
    91     }
       
    92 
       
    93 // ----------------------------------------------------------------------------
       
    94 // CGSSensorPlugin::ConstructL
       
    95 // Symbian OS two-phased constructor
       
    96 // ----------------------------------------------------------------------------
       
    97 void CGSSensorPlugin::ConstructL()
       
    98     {
       
    99     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::ConstructL()" );
       
   100     FeatureManager::InitializeLibL();
       
   101 
       
   102     // Initialize the Model
       
   103     iModel = CGSSensorPluginModel::NewL();
       
   104 
       
   105     // assign view pointers to point to NULL.
       
   106     iTappingCtrlView = NULL;
       
   107     iTurningCtrlView = NULL;
       
   108 
       
   109     // Find the resource file
       
   110     TParse parse;
       
   111     parse.Set( KGSSensorPluginResourceFileName, 
       
   112                &KDC_RESOURCE_FILES_DIR, NULL );
       
   113     TFileName fileName( parse.FullName() );
       
   114     
       
   115     // Get language of resource file
       
   116     BaflUtils::NearestLanguageFile( iCoeEnv->FsSession(), fileName );
       
   117 
       
   118     // Open resource file
       
   119     iResourceLoader.OpenL( fileName );
       
   120 
       
   121     // Load extended plugins if any
       
   122     iPluginArray = new  ( ELeave ) CArrayPtrFlat<CGSPluginInterface>( KGSSenPluginCount );
       
   123     iPluginLoader = CGSPluginLoader::NewL( iAppUi );
       
   124     iPluginLoader->SetObserver( this );
       
   125     iPluginLoader->LoadAsyncL( KGSPluginInterfaceUid, Id(), iPluginArray );
       
   126 
       
   127     BaseConstructL( R_GS_SEN_VIEW );
       
   128     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::ConstructL() - return" );
       
   129     }
       
   130 
       
   131 // ----------------------------------------------------------------------------
       
   132 // CGSSensorPlugin::~CGSSensorPlugin 
       
   133 // Destructor
       
   134 // ----------------------------------------------------------------------------
       
   135 CGSSensorPlugin::~CGSSensorPlugin()
       
   136     {
       
   137     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::~CGSSensorPlugin()" );
       
   138     FeatureManager::UnInitializeLib();
       
   139 
       
   140     // close resource loader
       
   141     iResourceLoader.Close();
       
   142 
       
   143     // delete Model
       
   144     if ( iModel )
       
   145         {
       
   146         delete iModel;
       
   147         }
       
   148 
       
   149     // Delete plugin loader
       
   150     if ( iPluginLoader )
       
   151         {
       
   152         delete iPluginLoader;
       
   153         }
       
   154 
       
   155     // Delete possible plugins
       
   156     if ( iPluginArray )
       
   157         {
       
   158         // Since the plugins are actually avkon views, avkon is responsible
       
   159         // for owning the plugins. This means we do not reset and destroy
       
   160         // the contents of the array in which the plugins reside. We have to
       
   161         // leave it up to avkon to tidy up.
       
   162         delete iPluginArray;
       
   163         }
       
   164 
       
   165     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::~CGSSensorPlugin() - return" );
       
   166     }
       
   167 
       
   168 
       
   169 // ----------------------------------------------------------------------------
       
   170 // TUid CGSSensorPlugin::Id
       
   171 // Returns plug-in's ID.
       
   172 // ----------------------------------------------------------------------------
       
   173 TUid CGSSensorPlugin::Id() const
       
   174     {
       
   175     TRACE_1( "[GSSensorPlugin] CGSSensorPlugin::Id() - ID: %i", KGSSensorPluginUid );
       
   176     return KGSSensorPluginUid;
       
   177     }
       
   178 
       
   179 
       
   180 // ----------------------------------------------------------------------------
       
   181 // CGSSensorPlugin::HandleCommandL 
       
   182 // Handles commands directed to this class.
       
   183 // ----------------------------------------------------------------------------
       
   184 void CGSSensorPlugin::HandleCommandL( TInt aCommand )
       
   185     {
       
   186     TRACE_1( "[GSSensorPlugin] CGSSensorPlugin::HandleCommandL() - command: %i", aCommand );
       
   187 
       
   188     switch ( aCommand )
       
   189         {
       
   190         case EGSSenMskGeneral:  // MSK, this is either 'Change' or 'Open'
       
   191         case EGSSenMenuOpen:    // 'Open' from options menu
       
   192             {
       
   193             SelectLocalViewL();
       
   194             break;
       
   195             }
       
   196         case EGSSenMenuChange:  // 'Change' from options menu
       
   197             {
       
   198             TInt current = iModel->SensorActiveStatusL();
       
   199 
       
   200             CDesCArrayFlat* items =
       
   201 				iCoeEnv->ReadDesC16ArrayResourceL( R_GS_SENSOR_ACTIVE_STATUS );
       
   202 			CleanupStack::PushL( items );
       
   203 
       
   204 			CAknRadioButtonSettingPage* dlg =
       
   205 				new ( ELeave ) CAknRadioButtonSettingPage(
       
   206 					R_GS_SENSOR_ACTIVE_STATUS_SETTING_PAGE,
       
   207 					current,
       
   208 					items );
       
   209 
       
   210 			if ( dlg->ExecuteLD( CAknSettingPage::EUpdateWhenChanged ) )
       
   211 				{
       
   212 				iModel->SetSensorActiveStatusL( current );
       
   213 				UpdateListBoxL( EGSSensorsListItemId );
       
   214 				}
       
   215 		    CleanupStack::PopAndDestroy( items );
       
   216             break;
       
   217             }
       
   218         case EAknSoftkeyBack:
       
   219             // remove views
       
   220             RemoveLocalViews();
       
   221             // check exit status
       
   222             CheckExitStatusL();
       
   223             // Activate parent plugin
       
   224             iAppUi->ActivateLocalViewL( KGSGenPluginUid );
       
   225             break;
       
   226         case EAknCmdHelp:
       
   227             {
       
   228             if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   229                 {
       
   230                 HlpLauncher::LaunchHelpApplicationL(
       
   231                     iEikonEnv->WsSession(), iAppUi->AppHelpContextL() );
       
   232                 }
       
   233             break;
       
   234             }
       
   235         case EGSSenMenuExit:
       
   236             {
       
   237             CheckExitStatusL();
       
   238             // Proceed with the command
       
   239             aCommand = EAknCmdExit;
       
   240             }
       
   241         default:
       
   242             iAppUi->HandleCommandL( aCommand );
       
   243             break;
       
   244         }
       
   245     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::HandleCommandL() - return" );
       
   246     }
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // CGSSensorPlugin::CheckExitStatusL
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 void CGSSensorPlugin::CheckExitStatusL()
       
   253     {
       
   254     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::CheckExitStatusL()" );
       
   255     // Check were there changes
       
   256     if ( iModel->ChangesMade() )
       
   257         {
       
   258         const TBool sensorStatus( iModel->SensorActiveStatusL() );
       
   259         const TBool settingsExists( iModel->SettingsExistsL() );
       
   260 
       
   261         // Check should we show dialog, note or neither
       
   262         if ( !sensorStatus && settingsExists )
       
   263             {
       
   264             // Query to turn sensors on
       
   265             CAknQueryDialog* dialog = CAknQueryDialog::NewL();
       
   266             dialog->PrepareLC( R_GS_SEN_CONFIRM_YES_NO_QUERY );
       
   267             TInt ret = dialog->RunLD();
       
   268 
       
   269             if ( ret == EAknSoftkeyYes )
       
   270                 {
       
   271                 // Set sensor status to active
       
   272                 iModel->SetSensorActiveStatusL( ETrue );
       
   273                 }
       
   274             }
       
   275         else if ( sensorStatus && !settingsExists )
       
   276             {
       
   277             // Set sensors off, as there are no sensor settings...
       
   278             iModel->SetSensorActiveStatusL( EFalse );
       
   279             // ...and inform user
       
   280             CAknNoteDialog* note = new ( ELeave ) CAknNoteDialog(
       
   281                 REINTERPRET_CAST( CEikDialog**, &note ),
       
   282                 CAknNoteDialog::ENoTone,
       
   283                 CAknNoteDialog::ELongTimeout );
       
   284 
       
   285             note->PrepareLC( R_GS_SEN_INFORMATION_NOTE );
       
   286             note->RunLD(); // note will delete itself
       
   287             }
       
   288         else
       
   289             {
       
   290             // Everyting is OK, no need for actions
       
   291             }
       
   292         }
       
   293     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::CheckExitStatusL() - return" );
       
   294     }
       
   295 
       
   296 
       
   297 // -----------------------------------------------------------------------------
       
   298 // CGSSensorPlugin::DynInitMenuPaneL
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 void CGSSensorPlugin::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
       
   302     {
       
   303     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::Container()" );
       
   304     // Check resource
       
   305     if ( R_GS_SEN_MENU_ITEM_OPEN == aResourceId )
       
   306         {
       
   307         // First, resolve current item in listbox
       
   308         const TInt currentItem = Container()->CurrentFeatureId();
       
   309 
       
   310         if ( EGSSensorsListItemId == currentItem )
       
   311             {
       
   312             // Hide menu item 'Open'
       
   313             aMenuPane->SetItemDimmed( EGSSenMenuOpen, ETrue );
       
   314             aMenuPane->SetItemDimmed( EGSSenMenuChange, EFalse );
       
   315             }
       
   316         else
       
   317             {
       
   318             // Hide menu item 'Change'
       
   319             aMenuPane->SetItemDimmed( EGSSenMenuChange, ETrue );
       
   320             aMenuPane->SetItemDimmed( EGSSenMenuOpen, EFalse );
       
   321             }
       
   322         }
       
   323 
       
   324     // Forward to base class
       
   325     CGSBaseView::DynInitMenuPaneL( aResourceId, aMenuPane );
       
   326 
       
   327     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::Container() - return" );
       
   328     }
       
   329 
       
   330 // ----------------------------------------------------------------------------
       
   331 // CGSSensorPlugin::UpdateListBoxL
       
   332 // ----------------------------------------------------------------------------
       
   333 //
       
   334 void CGSSensorPlugin::UpdateListBoxL( TInt aItemId )
       
   335     {
       
   336     TRACE_1( "[GSSensorPlugin] CGSSensorPlugin::UpdateListBoxL() - item: %i", aItemId );
       
   337     Container()->UpdateListBoxL( aItemId );
       
   338     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::UpdateListBoxL() - return" );
       
   339     }
       
   340 
       
   341 // ----------------------------------------------------------------------------
       
   342 // CGSSensorPlugin::Container
       
   343 // Return handle to container class.
       
   344 // ----------------------------------------------------------------------------
       
   345 //
       
   346 CGSSensorPluginContainer* CGSSensorPlugin::Container()
       
   347     {
       
   348     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::Container()" );
       
   349     return static_cast<CGSSensorPluginContainer*>( iContainer );
       
   350     }
       
   351     
       
   352 // ----------------------------------------------------------------------------
       
   353 // CGSSensorPlugin::NewContainerL
       
   354 // Creates new iContainer.
       
   355 // ----------------------------------------------------------------------------
       
   356 //
       
   357 void CGSSensorPlugin::NewContainerL()
       
   358     {
       
   359     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::NewContainerL()" );
       
   360     // container takes a CGSSensorPluginModel pointer
       
   361     iContainer = new( ELeave ) CGSSensorPluginContainer( iModel, *this );
       
   362     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::NewContainerL() - return" );
       
   363     }
       
   364 
       
   365 // ----------------------------------------------------------------------------
       
   366 // CGSSensorPlugin::DoActivateL
       
   367 // First method called by the Avkon framwork to invoke a view.
       
   368 // ----------------------------------------------------------------------------
       
   369 //
       
   370 void CGSSensorPlugin::DoActivateL( const TVwsViewId& aPrevViewId,
       
   371                                     TUid aCustomMessageId,
       
   372                                     const TDesC8& aCustomMessage )
       
   373     {
       
   374     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::DoActivateL()" );
       
   375     CGSBaseView::DoActivateL( aPrevViewId, aCustomMessageId, aCustomMessage );
       
   376     // Update MSK label
       
   377     CheckMiddleSoftkeyLabelL();
       
   378     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::DoActivateL() - return" );
       
   379     }
       
   380 
       
   381 // ----------------------------------------------------------------------------
       
   382 // CGSSensorPlugin::DoDeactivate
       
   383 // Called by the Avkon view framework when closing.
       
   384 // ----------------------------------------------------------------------------
       
   385 //
       
   386 void CGSSensorPlugin::DoDeactivate()
       
   387     {
       
   388     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::DoDeactivateL()" );
       
   389     // Deactivate view
       
   390     CGSBaseView::DoDeactivate();
       
   391     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::DoDeactivateL() - return" );
       
   392     }
       
   393 
       
   394 // ----------------------------------------------------------------------------
       
   395 // CGSSensorPlugin::HandleListBoxSelectionL
       
   396 // Handles events raised through a rocker key
       
   397 // ----------------------------------------------------------------------------
       
   398 void CGSSensorPlugin::HandleListBoxSelectionL()
       
   399     {
       
   400     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::HandleListBoxSelectionL()" );
       
   401     SelectLocalViewL();
       
   402     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::HandleListBoxSelectionL() - return" );
       
   403     }
       
   404 
       
   405 // ----------------------------------------------------------------------------
       
   406 // CGSSensorPlugin::SelectLocalViewL
       
   407 // Selects a particular local view
       
   408 // ----------------------------------------------------------------------------
       
   409 void CGSSensorPlugin:: SelectLocalViewL()
       
   410     {
       
   411     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::SelectLocalViewL()" );
       
   412     const TInt currentFeatureId = Container()->CurrentFeatureId();
       
   413 
       
   414     switch ( currentFeatureId )
       
   415         {
       
   416         case EGSSensorsListItemId:
       
   417             ChangeSensorActiveSettingL();
       
   418             break;
       
   419         case EGSTapCtrlListItemId:
       
   420             CreateLocalViewL( KSenTapCtrlViewId );
       
   421             break;
       
   422         case EGSTurnCtrlListItemId:
       
   423             CreateLocalViewL( KSenTurnCtrlViewId );
       
   424             break;
       
   425         default:
       
   426             {
       
   427             // Not local view, try plugins
       
   428             CGSPluginInterface* selectedPlugin( Container()->SelectedPluginL() );
       
   429 
       
   430             switch( selectedPlugin->ItemType() )
       
   431                 {
       
   432                 // In these cases the plugin is a view:
       
   433                 case EGSItemTypeSingleLarge:
       
   434                 case EGSItemTypeSetting:
       
   435                 case EGSItemTypeSettingIcon:
       
   436                     {
       
   437                     CleanupStack::PushL( selectedPlugin );
       
   438                     iAppUi->ActivateLocalViewL( selectedPlugin->Id() );
       
   439                     CleanupStack::Pop( selectedPlugin );
       
   440                     break;
       
   441                     }
       
   442                     
       
   443                 // In these cases the plugin is a dialog:
       
   444                 case EGSItemTypeSettingDialog:
       
   445                 case EGSItemTypeSingleLargeDialog:
       
   446                      selectedPlugin->HandleSelection( EGSSelectionByMenu );
       
   447                      break;
       
   448                 default:
       
   449                     break;
       
   450                 }
       
   451             break;
       
   452             }
       
   453         }
       
   454     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::SelectLocalViewL() - return" );
       
   455     }
       
   456 
       
   457 // -----------------------------------------------------------------------------
       
   458 // CGSSensorPlugin::ProcessCommandL
       
   459 // -----------------------------------------------------------------------------
       
   460 void CGSSensorPlugin::ProcessCommandL( TInt aCommand )
       
   461     {
       
   462     TRACE_1( "[GSSensorPlugin] CGSSensorPlugin::ProcessCommandL() - command: %i", aCommand );
       
   463     // Call base class
       
   464     CAknView::ProcessCommandL( aCommand );
       
   465     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::ProcessCommandL() - return" );
       
   466     }
       
   467 
       
   468 // ---------------------------------------------------------------------------
       
   469 // CGSSensorPlugin::RemoveLocalViews
       
   470 // ---------------------------------------------------------------------------
       
   471 //
       
   472 void CGSSensorPlugin::RemoveLocalViews()
       
   473     {
       
   474     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::RemoveLocalViews()" );
       
   475     // Remove view from iAppUi -> View is deleted by iAppUi automatically.
       
   476     if ( iTappingCtrlView )
       
   477         {
       
   478         // Also deletes view.
       
   479         iAppUi->RemoveView( KSenTapCtrlViewId );
       
   480         iTappingCtrlView = NULL;
       
   481         }
       
   482     if ( iTurningCtrlView )
       
   483         {
       
   484         // Also deletes view.
       
   485         iAppUi->RemoveView( KSenTurnCtrlViewId );
       
   486         iTurningCtrlView = NULL;
       
   487         }
       
   488     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::RemoveLocalViews() - return" );
       
   489     }
       
   490 
       
   491 // ---------------------------------------------------------------------------
       
   492 // CGSSensorPlugin::CreateLocalViewL
       
   493 // Initializes local views within this plug-in based on the view ID.
       
   494 // ---------------------------------------------------------------------------
       
   495 void CGSSensorPlugin::CreateLocalViewL( TUid aLocalViewId )
       
   496     {
       
   497     TRACE_1( "[GSSensorPlugin] CGSSensorPlugin::CreateLocalViewL() - view: %i", aLocalViewId );
       
   498 
       
   499     // Check if the view exists. If view does not exist:
       
   500     // 1. Create the view
       
   501     // 2. Add view to iAppUi -> iAppUi takes the view ownership.
       
   502     //
       
   503     if ( aLocalViewId == KSenTapCtrlViewId && !iTappingCtrlView )
       
   504         {
       
   505         iTappingCtrlView = CGSSenTappingCtrlView::NewL( iModel );
       
   506         iAppUi->AddViewL( iTappingCtrlView );
       
   507         }
       
   508     else if ( aLocalViewId == KSenTurnCtrlViewId && !iTurningCtrlView )
       
   509         {
       
   510         iTurningCtrlView = CGSSenTurnCtrlView::NewL( iModel );
       
   511         iAppUi->AddViewL( iTurningCtrlView );
       
   512         }
       
   513     else
       
   514         {
       
   515         // View is already created
       
   516         TRACE_( "[GSSensorPlugin] CGSSensorPlugin::CreateLocalViewL() - View already exists" );
       
   517         }
       
   518 
       
   519     iAppUi->ActivateLocalViewL( aLocalViewId );
       
   520 
       
   521     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::CreateLocalViewL() - return" );
       
   522     }
       
   523 
       
   524 // ----------------------------------------------------------------------------
       
   525 // CGSSensorPlugin::GetCaption
       
   526 // Return application/view caption.
       
   527 // ----------------------------------------------------------------------------
       
   528 //
       
   529 void CGSSensorPlugin::GetCaptionL( TDes& aCaption ) const
       
   530     {
       
   531     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::GetCaptionL()" );
       
   532     // the resource file is already opened.
       
   533     HBufC* result = StringLoader::LoadL( R_GS_SENSOR_VIEW_CAPTION );
       
   534     aCaption.Copy( *result );
       
   535     delete result;
       
   536     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::GetCaptionL() - return" );
       
   537     }
       
   538 
       
   539 // ----------------------------------------------------------------------------
       
   540 // CGSSensorPlugin::PluginProviderCategory
       
   541 // A means to identify the location of this plug-in in the framework.
       
   542 // ----------------------------------------------------------------------------
       
   543 //
       
   544 TInt CGSSensorPlugin::PluginProviderCategory() const
       
   545     {
       
   546     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::PluginProviderCategory()" );
       
   547     //To identify internal plug-ins.
       
   548     return KGSPluginProviderInternal;
       
   549     }
       
   550 
       
   551 // ---------------------------------------------------------------------------
       
   552 // CGSSensorPlugin::CreateIconL
       
   553 // Return the icon, if has one.
       
   554 // ---------------------------------------------------------------------------
       
   555 //
       
   556 CGulIcon* CGSSensorPlugin::CreateIconL( const TUid aIconType )
       
   557     {
       
   558     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::CreateIconL()" );
       
   559     CGulIcon* icon;
       
   560        
       
   561     if ( aIconType == KGSIconTypeLbxItem )
       
   562         {
       
   563         icon = AknsUtils::CreateGulIconL(
       
   564         AknsUtils::SkinInstance(), 
       
   565         KAknsIIDQgnPropSetGeneSensor, 
       
   566         KGSSenPluginIconFileName,
       
   567         EMbmGssenpluginQgn_prop_set_gene_sensor,
       
   568         EMbmGssenpluginQgn_prop_set_gene_sensor_mask );
       
   569         }
       
   570      else
       
   571         {
       
   572         icon = CGSPluginInterface::CreateIconL( aIconType );
       
   573         }
       
   574 
       
   575     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::CreateIconL() - return" );
       
   576     return icon;
       
   577     }
       
   578 
       
   579 // ---------------------------------------------------------------------------
       
   580 // CGSSensorPlugin::CreateContainerL
       
   581 // Override function from CGSBaseView
       
   582 // ---------------------------------------------------------------------------
       
   583 //
       
   584 void CGSSensorPlugin::CreateContainerL()
       
   585     {
       
   586     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::CreateContainerL()" );
       
   587     NewContainerL();
       
   588     __ASSERT_ALWAYS( iContainer, User::Panic( KGSDoActivateError, EGSViewPanicNullPtr ) );
       
   589     iContainer->SetMopParent( this );
       
   590 
       
   591     TRAPD( error, Container()->ConstructL( ClientRect(), AppUi(), iPluginArray ) );
       
   592 
       
   593     if ( error )
       
   594         {
       
   595         delete iContainer;
       
   596         iContainer = NULL;
       
   597         User::Leave( error );
       
   598         }
       
   599     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::CreateContainerL() - return" );
       
   600     }
       
   601 
       
   602 // ---------------------------------------------------------------------------
       
   603 // CGSSensorPlugin::CheckMiddleSoftkeyLabelL
       
   604 // ---------------------------------------------------------------------------
       
   605 //
       
   606 void CGSSensorPlugin::CheckMiddleSoftkeyLabelL() 
       
   607     {
       
   608     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::CheckMiddleSoftkeyLabelL()" );
       
   609     // First, resolve current item
       
   610     const TInt currentItem = Container()->CurrentFeatureId();
       
   611 
       
   612     // First, remove current label
       
   613     RemoveCommandFromMSK();
       
   614 
       
   615     if ( EGSSensorsListItemId == currentItem )
       
   616         {
       
   617         // Change MKS to 'Change'
       
   618         SetMiddleSoftKeyLabelL( R_GS_MKS_LABEL_CHANGE, EGSSenMskGeneral );
       
   619         }
       
   620     else
       
   621         {
       
   622         // Change MSK to 'Open'
       
   623         SetMiddleSoftKeyLabelL( R_GS_MKS_LABEL_OPEN, EGSSenMskGeneral );
       
   624         }  
       
   625     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::CheckMiddleSoftkeyLabelL() - return" );
       
   626     }
       
   627 
       
   628 // -----------------------------------------------------------------------------
       
   629 // CGSSensorPlugin::RemoveCommandFromMSK
       
   630 // This method should do nothing but MSK issues.
       
   631 // -----------------------------------------------------------------------------
       
   632 //
       
   633 void CGSSensorPlugin::RemoveCommandFromMSK()
       
   634     {
       
   635     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::RemoveCommandFromMSK()" );
       
   636     CEikButtonGroupContainer* cbaGroup = Cba();
       
   637     if ( cbaGroup )
       
   638         {
       
   639         // Remove command from stack
       
   640         cbaGroup->RemoveCommandFromStack( KGSSenPluginMSKControlID, EGSSenMskGeneral );
       
   641         }
       
   642     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::RemoveCommandFromMSK() - return" );
       
   643     }
       
   644 
       
   645 // ---------------------------------------------------------------------------
       
   646 // Sets middle softkey label.
       
   647 // ---------------------------------------------------------------------------
       
   648 //
       
   649 void CGSSensorPlugin::SetMiddleSoftKeyLabelL( 
       
   650     const TInt aResourceId, const TInt aCommandId )
       
   651     {
       
   652     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::SetMiddleSoftKeyLabelL()" );
       
   653     CEikButtonGroupContainer* cbaGroup = Cba();
       
   654     if ( cbaGroup )
       
   655         {
       
   656         HBufC* middleSKText = StringLoader::LoadLC( aResourceId );
       
   657         TPtr mskPtr = middleSKText->Des();
       
   658         cbaGroup->AddCommandToStackL( 
       
   659             KGSSenPluginMSKControlID, 
       
   660             aCommandId, 
       
   661             mskPtr );
       
   662         CleanupStack::Pop( middleSKText );
       
   663         delete middleSKText;
       
   664         }
       
   665     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::SetMiddleSoftKeyLabelL() - return" );
       
   666     }
       
   667 
       
   668 // ---------------------------------------------------------------------------
       
   669 // CGSSensorPlugin::ChangeSensorActiveSettingL
       
   670 // Change sensors active status setting .
       
   671 // ---------------------------------------------------------------------------
       
   672 //
       
   673 void CGSSensorPlugin::ChangeSensorActiveSettingL()
       
   674     {
       
   675     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::ChangeSensorActiveSettingL()" );
       
   676     TInt currentValue = iModel->SensorActiveStatusL();
       
   677     
       
   678     if( currentValue == KGSSenOff )
       
   679         {
       
   680         currentValue = KGSSenOn;
       
   681         }
       
   682     else
       
   683         {
       
   684         currentValue = KGSSenOff;
       
   685         }
       
   686 
       
   687     iModel->SetSensorActiveStatusL( currentValue );
       
   688     UpdateListBoxL( EGSSensorsListItemId );
       
   689 
       
   690     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::ChangeSensorActiveSettingL() - return" );
       
   691     }
       
   692 
       
   693 // ---------------------------------------------------------------------------
       
   694 // CGSSensorPlugin::HandlePluginLoaded
       
   695 // Called by GSPluginLoader when plugins are loaded or error occured during that
       
   696 // ---------------------------------------------------------------------------
       
   697 //
       
   698 void CGSSensorPlugin::HandlePluginLoaded( KGSPluginLoaderStatus aStatus )
       
   699     {
       
   700     TRACE_1( "[GSSensorPlugin] CGSSensorPlugin::HandlePluginLoaded(): %i", aStatus );
       
   701 
       
   702     if ( iContainer && MGSPluginLoadObserver::EGSFinished == aStatus )
       
   703         {
       
   704         #ifdef __DEBUG
       
   705         TRAPD( ignore, Container()->UpdateListBoxL( EGSExtPluginsListItemId ); );
       
   706         TRACE_1( "[GSSensorPlugin] CGSSensorPlugin::HandlePluginLoaded() - Error: %i", ignore );
       
   707         #else
       
   708         TRAP_IGNORE( Container()->UpdateListBoxL( EGSExtPluginsListItemId ); );
       
   709         #endif // __DEBUG
       
   710         }
       
   711 
       
   712     TRACE_( "[GSSensorPlugin] CGSSensorPlugin::HandlePluginLoaded() - return" );
       
   713     }