idlehomescreen/nativeuicontroller/src/nativeuicontroller.cpp
branchRCL_3
changeset 83 5456b4e8b3a8
child 88 3321d3e205b6
equal deleted inserted replaced
82:5f0182e07bfb 83:5456b4e8b3a8
       
     1 /*
       
     2 * Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Native UI controller.
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <startupdomainpskeys.h>
       
    20 #include <bautils.h>
       
    21 #include <e32property.h>
       
    22 #include <ecom/ecom.h>
       
    23 #include <ecom/implementationproxy.h>
       
    24 #include <centralrepository.h>
       
    25 #include <activeidle2domainpskeys.h>
       
    26 #include <aipspropertyobserver.h>
       
    27 #include <eikstart.h>
       
    28 #include <avkondomainpskeys.h>
       
    29 #include <AknDlgShut.h>
       
    30 #include <aidevicestatuscontentmodel.h>
       
    31 
       
    32 // User includes
       
    33 #include <aifwstatehandler.h>
       
    34 #include <aifwpublisherinfo.h>
       
    35 #include <hscontentpublisher.h>
       
    36 #include "nativeuicontroller.h"
       
    37 #include "ainativeui.hrh"
       
    38 #include "application.h"
       
    39 #include "appui.h"
       
    40 #include "aiutility.h"
       
    41 #include "aistrparser.h"
       
    42 #include "aistatuspanel.h"
       
    43 #include "ainativerenderer.h"
       
    44 #include "aititlepanerenderer.h"
       
    45 #include "ainavipanerenderer.h"
       
    46 #include "aidialogrenderer.h"
       
    47 #include "aisoftkeyrenderer.h"
       
    48 #include "ainotifierrenderer.h"
       
    49 #include "ainativeuiplugins.h"
       
    50 #include "activeidle2domaincrkeys.h"
       
    51 #include "aistatuspanetouchui.h"
       
    52 #include "ainativeuistrings.h" // string literals
       
    53 #include "aistrcnv.h"
       
    54 
       
    55 using namespace AiNativeUiController;
       
    56 
       
    57 // Constants
       
    58 _LIT( KResourceDrive, "Z:" );
       
    59 _LIT( KResourceFile, "ainativeui.rsc" );
       
    60 _LIT( KSettingsDummyData, "" );
       
    61 _LIT( KSettingsIdSeparator, "/" );
       
    62 _LIT( KSettings, "Settings" );
       
    63 
       
    64 const TInt KOneSecondInMicroS = 1000*1000;
       
    65 const TInt KAI2CrKeyIncrementBy2 = 2;
       
    66 
       
    67 #define KResourcePath KDC_APP_RESOURCE_DIR
       
    68 
       
    69 const TImplementationProxy KImplementationTable[] =
       
    70     {
       
    71     IMPLEMENTATION_PROXY_ENTRY(KImplementationUidNativeUiController, CNativeUiController::NewL)
       
    72     };
       
    73 
       
    74 // ======== LOCAL FUNCTIONS ========
       
    75 // ----------------------------------------------------------------------------
       
    76 // IsDeviceStatus()
       
    77 //
       
    78 // ----------------------------------------------------------------------------
       
    79 //
       
    80 TBool IsDeviceStatus( const THsPublisherInfo& aInfo )
       
    81     {
       
    82     return ( aInfo.Name() == KDeviceStatusPluginName && 
       
    83         aInfo.Uid() == KDeviceStatusPluginUid );
       
    84     }
       
    85 
       
    86 // ======== MEMBER FUNCTIONS ========
       
    87 // ----------------------------------------------------------------------------
       
    88 // CNativeUiController::NewL()
       
    89 //
       
    90 // ----------------------------------------------------------------------------
       
    91 //
       
    92 CNativeUiController* CNativeUiController::NewL()
       
    93     {
       
    94     CNativeUiController* self = new (ELeave) CNativeUiController;
       
    95 
       
    96     CleanupStack::PushL( self );
       
    97     
       
    98     // Set Native UI Controller object to TLS for access in static
       
    99     // CNativeUiController::NewApplication
       
   100     User::LeaveIfError( Dll::SetTls( self ) );
       
   101     CleanupStack::Pop( self );
       
   102 
       
   103     return self;
       
   104     }
       
   105 
       
   106 // ----------------------------------------------------------------------------
       
   107 // CNativeUiController::Exit()
       
   108 //
       
   109 // ----------------------------------------------------------------------------
       
   110 //
       
   111 void CNativeUiController::Exit()
       
   112     {
       
   113     if ( iExitTimer )
       
   114         {
       
   115         iExitTimer->Cancel();
       
   116         
       
   117         iExitTimer->Start( 0, KOneSecondInMicroS,                       
       
   118            TCallBack( ExitTimerCallBack, this ) );
       
   119         }
       
   120     }
       
   121 
       
   122 // ----------------------------------------------------------------------------
       
   123 // CNativeUiController::ExitTimerCallBack()
       
   124 //
       
   125 // ----------------------------------------------------------------------------
       
   126 //
       
   127 TInt CNativeUiController::ExitTimerCallBack( TAny *aSelf )
       
   128     {
       
   129     CNativeUiController* self =
       
   130         static_cast<CNativeUiController*>( aSelf );
       
   131         
       
   132     if ( self )
       
   133         {
       
   134         self->iExitTimer->Cancel();
       
   135         self->PrepareToExit();
       
   136         self->iAppUi->Exit();
       
   137         }
       
   138     
       
   139     return KErrNone;
       
   140     }
       
   141 
       
   142 // ----------------------------------------------------------------------------
       
   143 // CNativeUiController::~CNativeUiController()
       
   144 //
       
   145 // ----------------------------------------------------------------------------
       
   146 //
       
   147 CNativeUiController::~CNativeUiController()
       
   148     {
       
   149     iPlugins.Reset();
       
   150     
       
   151     delete iExitTimer;
       
   152 
       
   153     PrepareToExit();
       
   154 
       
   155     // Reset TLS pointer to this set in NewL
       
   156     Dll::SetTls( NULL );
       
   157     }
       
   158 
       
   159 // ----------------------------------------------------------------------------
       
   160 // CNativeUiController::PrepareToExit()
       
   161 //
       
   162 // ----------------------------------------------------------------------------
       
   163 //
       
   164 void CNativeUiController::PrepareToExit()
       
   165     {
       
   166     iRenderers.ResetAndDestroy();
       
   167     
       
   168     delete iStatusPanel;
       
   169     iStatusPanel = NULL;
       
   170     
       
   171     Release( iIdleStatusObserver );
       
   172     iIdleStatusObserver = NULL;
       
   173     
       
   174     Release( iKeylockStatusObserver );
       
   175     iKeylockStatusObserver = NULL;
       
   176 	
       
   177     Release( iExtHsPluginConfChange );
       
   178 	iExtHsPluginConfChange = NULL;
       
   179 	
       
   180     //If we are not the
       
   181     if( !iRunningAsMain && iResourceOffset > 0 )
       
   182         {
       
   183         iCoeEnv->DeleteResourceFile( iResourceOffset );
       
   184         iResourceOffset = KErrNotFound;
       
   185         }
       
   186     }
       
   187 
       
   188 // ----------------------------------------------------------------------------
       
   189 // CNativeUiController::CNativeUiController()
       
   190 //
       
   191 // ----------------------------------------------------------------------------
       
   192 //
       
   193 CNativeUiController::CNativeUiController() 
       
   194     : iResourceOffset( KErrNotFound )
       
   195     {
       
   196     }
       
   197 
       
   198 // ----------------------------------------------------------------------------
       
   199 // CNativeUiController::SetAppUi()
       
   200 //
       
   201 // ----------------------------------------------------------------------------
       
   202 //
       
   203 void CNativeUiController::SetAppUi( CAppUi* aAppUi )
       
   204     {
       
   205     iAppUi = aAppUi;
       
   206     }
       
   207 
       
   208 // ----------------------------------------------------------------------------
       
   209 // CNativeUiController::AddRendererL()
       
   210 //
       
   211 // ----------------------------------------------------------------------------
       
   212 //
       
   213 void CNativeUiController::AddRendererL( CAiNativeRenderer* aRenderer )
       
   214     {
       
   215     User::LeaveIfError( iRenderers.Append( aRenderer ) );
       
   216     }
       
   217 
       
   218 // ----------------------------------------------------------------------------
       
   219 // CNativeUiController::RemoveRenderer()
       
   220 //
       
   221 // ----------------------------------------------------------------------------
       
   222 //
       
   223 TBool CNativeUiController::RemoveRenderer( CAiNativeRenderer *aRenderer, 
       
   224     TBool aDelete )
       
   225     {
       
   226     for ( TInt i = 0; i < iRenderers.Count(); i++ )
       
   227         {
       
   228         if ( aRenderer == iRenderers[i] )
       
   229             {
       
   230             if ( aDelete )
       
   231                 {
       
   232                 delete aRenderer;
       
   233                 }
       
   234             iRenderers.Remove(i);
       
   235     
       
   236             return ETrue;
       
   237             }
       
   238         }
       
   239     
       
   240     return EFalse;
       
   241     }
       
   242 
       
   243 // ----------------------------------------------------------------------------
       
   244 // CNativeUiController::DoPublish()
       
   245 //
       
   246 // ----------------------------------------------------------------------------
       
   247 //
       
   248 template<class T>
       
   249 TInt CNativeUiController::DoPublish( CHsContentPublisher& aPlugin,
       
   250     TInt aContent, T& aData, TInt aIndex )
       
   251     {
       
   252     const THsPublisherInfo& info( aPlugin.PublisherInfo() );
       
   253              
       
   254     if ( !IsDeviceStatus( info ) && info.Namespace() != KNativeUiNamespace )
       
   255         {
       
   256         return KErrNotSupported;
       
   257         }
       
   258     
       
   259     const TInt count( iRenderers.Count() );
       
   260     TInt err( KErrNone );
       
   261     
       
   262     for( TInt i( 0 ); i < count; i++ )
       
   263         {
       
   264         err = iRenderers[i]->Publish( aPlugin, aContent, aData, aIndex );
       
   265 
       
   266         if( err == KErrNone )
       
   267             {
       
   268             //data published
       
   269             return KErrNone;
       
   270             }
       
   271 
       
   272         if( err != KErrNotFound )
       
   273             {
       
   274             return err;
       
   275             }
       
   276         }
       
   277     
       
   278     return err;
       
   279     }
       
   280 
       
   281 // ----------------------------------------------------------------------------
       
   282 // CNativeUiController::HandleIdleStateEvent()
       
   283 //
       
   284 // ----------------------------------------------------------------------------
       
   285 //
       
   286 TInt CNativeUiController::HandleIdleStateEvent( TAny* aPtr )
       
   287     {
       
   288     CNativeUiController* self = 
       
   289         reinterpret_cast< CNativeUiController* >( aPtr );
       
   290 
       
   291     if( self )
       
   292         {
       
   293         TInt idleState = EPSAiBackground;
       
   294         self->iIdleStatusObserver->Get( idleState );
       
   295 
       
   296         const TInt count = self->iRenderers.Count();
       
   297 
       
   298         if( idleState == EPSAiForeground )
       
   299             {
       
   300             for( TInt i( 0 ); i < count; i++ )
       
   301                 {
       
   302                 TRAP_IGNORE( self->iRenderers[i]->FocusObtainedL() );
       
   303                 }
       
   304             }
       
   305         else
       
   306             {
       
   307             for( TInt j( 0 ); j < count; j++ )
       
   308                 {
       
   309                 TRAP_IGNORE( self->iRenderers[j]->FocusLostL() );
       
   310                 }
       
   311             }
       
   312         }
       
   313 
       
   314     return KErrNone;
       
   315     }
       
   316 
       
   317 // ----------------------------------------------------------------------------
       
   318 // CNativeUiController::HandleKeylockStateEvent()
       
   319 //
       
   320 // ----------------------------------------------------------------------------
       
   321 //
       
   322 TInt CNativeUiController::HandleKeylockStateEvent( TAny* aPtr )
       
   323     {
       
   324     CNativeUiController* self = 
       
   325         reinterpret_cast< CNativeUiController* >( aPtr );
       
   326 
       
   327     if( self )
       
   328         {
       
   329         TInt keylockState = EKeyguardNotActive;
       
   330         self->iKeylockStatusObserver->Get( keylockState );
       
   331 
       
   332         const TInt count = self->iRenderers.Count();
       
   333 
       
   334         if( keylockState != EKeyguardNotActive )
       
   335             {
       
   336             TRAP_IGNORE(
       
   337                 // Run dialog shutter to shut any open dialogs
       
   338                 AknDialogShutter::ShutDialogsL( 
       
   339                     *static_cast< CEikonEnv* >( CCoeEnv::Static() ) ); 
       
   340                 
       
   341                 TKeyEvent key;
       
   342                 key.iCode = 0;
       
   343                 key.iModifiers = 0;
       
   344                 key.iScanCode = EStdKeyNo;
       
   345                 CCoeEnv::Static()->SimulateKeyEventL( key, EEventKey );
       
   346                 );
       
   347             
       
   348             for( TInt i( 0 ); i < count; i++ )
       
   349                 {
       
   350                 TRAP_IGNORE( self->iRenderers[i]->KeylockEnabledL() );
       
   351                 }
       
   352             }
       
   353         else
       
   354             {
       
   355             for( TInt i( 0 ); i < count; i++ )
       
   356                 {
       
   357                 TRAP_IGNORE( self->iRenderers[i]->KeylockDisabledL() );
       
   358                 }
       
   359             }
       
   360         }
       
   361     
       
   362     return KErrNone;
       
   363 	}
       
   364 
       
   365 // ----------------------------------------------------------------------------
       
   366 // CNativeUiController::HandlePluginConfChange()
       
   367 //
       
   368 // ----------------------------------------------------------------------------
       
   369 //
       
   370 TInt CNativeUiController::HandlePluginConfChange( TAny* aPtr )
       
   371 	{
       
   372 	CNativeUiController* self = 
       
   373         reinterpret_cast< CNativeUiController* >( aPtr );
       
   374 
       
   375     TInt value( 0 );
       
   376     
       
   377     RProperty::Get( KPSUidAiInformation, 
       
   378         KActiveIdleExtHS_PluginConfChange, value );
       
   379     
       
   380     if( self && value )
       
   381         {
       
   382         self->iAppUi->ExtHSThemeChanged();
       
   383         }
       
   384     
       
   385     return KErrNone;
       
   386 	}
       
   387 
       
   388 // ----------------------------------------------------------------------------
       
   389 // CNativeUiController::LoadUIDefinitionL()
       
   390 //
       
   391 // ----------------------------------------------------------------------------
       
   392 //
       
   393 void CNativeUiController::LoadUIDefinitionL()
       
   394     {
       
   395     if ( iUiLoaded )
       
   396         {
       
   397         TInt count( iRenderers.Count() );
       
   398     
       
   399         for( TInt i( 0 ); i < count; i++ )
       
   400             {
       
   401             iRenderers[i]->LoadUIDefinitionL();
       
   402             }
       
   403         return;
       
   404         }
       
   405                      
       
   406     if ( !iExitTimer )
       
   407         {
       
   408         iExitTimer = CPeriodic::NewL( CActive::EPriorityStandard );
       
   409         }
       
   410     
       
   411     // This method is called upon startup. We'll need to:
       
   412     iRenderers.ResetAndDestroy();
       
   413 
       
   414     if( !iStatusPanel )
       
   415         {
       
   416         // 2) Initialize status pane for publishing in general
       
   417         iStatusPanel = CAiStatusPanel::NewL();
       
   418         }
       
   419 
       
   420     // 3) Create renderers that handle publishing to title pane...
       
   421     AddRendererL( CAiTitlePaneRenderer::NewLC( *iStatusPanel ) );
       
   422     CleanupStack::Pop();//CAiTitlePaneRenderer
       
   423 
       
   424     // ...navi pane...
       
   425     AddRendererL( CAiNaviPaneRenderer::NewLC( *iStatusPanel ) );
       
   426     CleanupStack::Pop();//CAiNaviPaneRenderer
       
   427 
       
   428     // ...dialogs and.
       
   429     AddRendererL( CAiDialogRenderer::NewLC() );
       
   430     CleanupStack::Pop();//CAiDialogRenderer
       
   431 
       
   432     AddRendererL( CAiNotifierRenderer::NewLC() );
       
   433     CleanupStack::Pop();//CAiNotifierRenderer
       
   434 
       
   435     // ...touch ui.
       
   436     AddRendererL( CAiStatusPaneTouchUi::NewLC( *iStatusPanel, *iFwEventHandler ) );
       
   437     CleanupStack::Pop();//CAiStatusPaneTouchUi
       
   438 
       
   439     if( iRunningAsMain )
       
   440         {
       
   441         AddRendererL( CAiSoftKeyRenderer::NewLC() );
       
   442         CleanupStack::Pop();//CAiSoftKeyRenderer
       
   443 
       
   444         // Toolbar shown only when we are not the main ui controller
       
   445         //DeleteToolbarRenderer();
       
   446 	            
       
   447         THsPublisherInfo deviceStatus( KDeviceStatusPluginUid, 
       
   448             KDeviceStatusPluginName, KNativeUiNamespace );
       
   449         
       
   450         iPlugins.Append( deviceStatus );
       
   451         
       
   452         TAiFwPublisherInfo devstatInfo( 
       
   453             deviceStatus, TAiFwCallback(), EAiFwSystemStartup );
       
   454         
       
   455         iFwStateHandler->LoadPlugin( devstatInfo ); 
       
   456         
       
   457         THsPublisherInfo profile( KProfilePluginUid, 
       
   458             KProfilePluginName, KNativeUiNamespace );
       
   459 
       
   460         iPlugins.Append( profile );
       
   461 
       
   462         TAiFwPublisherInfo profileInfo( 
       
   463             profile, TAiFwCallback(), EAiFwSystemStartup );
       
   464                 
       
   465         iFwStateHandler->LoadPlugin( profileInfo );                     	       
       
   466         }
       
   467 
       
   468     // We need to load the resource file here if we are not main controller.
       
   469     // If we are the main controller the loading is done in appui
       
   470     // Also the toolbar renderer is loaded here.
       
   471     else
       
   472         {
       
   473         //Load resources file for resource publishing
       
   474         TFullName resourceFile( KResourceDrive );
       
   475         resourceFile.Append( KResourcePath );
       
   476         resourceFile.Append( KResourceFile );
       
   477         BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), resourceFile );
       
   478         if( iCoeEnv && iResourceOffset == KErrNotFound )
       
   479             {
       
   480             iResourceOffset = iCoeEnv->AddResourceFileL( resourceFile );
       
   481             }
       
   482         // Create the toolbar renderer
       
   483         //RecreateToolbarRendererL();
       
   484         }
       
   485 
       
   486     // 4) Add an observer that informs us about the focus transition changes
       
   487     if( !iIdleStatusObserver )
       
   488         {
       
   489         iIdleStatusObserver = AiUtility::CreatePSPropertyObserverL(
       
   490                                     TCallBack( HandleIdleStateEvent, this ),
       
   491                                     KPSUidAiInformation,
       
   492                                     KActiveIdleState );
       
   493         }
       
   494     if( !iKeylockStatusObserver )
       
   495         {
       
   496         iKeylockStatusObserver = AiUtility::CreatePSPropertyObserverL(
       
   497                                     TCallBack( HandleKeylockStateEvent, this ),
       
   498                                     KPSUidAvkonDomain,
       
   499                                     KAknKeyguardStatus );
       
   500         }
       
   501 	if( !iExtHsPluginConfChange )
       
   502 		{
       
   503 		iExtHsPluginConfChange = AiUtility::CreatePSPropertyObserverL( 
       
   504 		                            TCallBack( HandlePluginConfChange, this ),
       
   505        		                    	KPSUidAiInformation, 
       
   506        		                    	KActiveIdleExtHS_PluginConfChange );
       
   507 		}
       
   508 	
       
   509     iUiLoaded = ETrue;
       
   510     }
       
   511 
       
   512 // ----------------------------------------------------------------------------
       
   513 // CNativeUiController::GetSettingsL()
       
   514 //
       
   515 // ----------------------------------------------------------------------------
       
   516 //
       
   517 void CNativeUiController::GetSettingsL( const THsPublisherInfo& aPublisherInfo,
       
   518     RAiSettingsItemArray& aSettings )
       
   519     {
       
   520     if ( aPublisherInfo.Namespace() != KNativeUiNamespace )
       
   521         {
       
   522         return;
       
   523         }
       
   524     
       
   525     if( iRunningAsMain && aPublisherInfo.Uid() == KShortcutPluginUid )        
       
   526         {
       
   527         RProperty::Set( KPSUidAiInformation, KActiveIdleExtHS_PluginConfChange, 0 );
       
   528         
       
   529         MAiPluginSettings* settings = AiUtility::CreatePluginSettingsL();
       
   530         CleanupDeletePushL( settings );
       
   531 
       
   532         MAiPluginSettingsItem& item = settings->AiPluginSettingsItem();
       
   533         item.SetPublisherId( aPublisherInfo.Uid() );
       
   534 
       
   535         HBufC* appBuf;
       
   536         appBuf = HBufC::NewLC( RProperty::KMaxPropertySize );
       
   537         TPtr appPtr = appBuf->Des();
       
   538         RProperty::Get( KPSUidAiInformation, KActiveIdleExtHS_LSKLocked, appPtr );
       
   539         if( appPtr.Length() > 0 )
       
   540             {
       
   541             item.SetKey( KNativeUiKeyIdLockedLSK );
       
   542             item.SetValueL( appPtr, EFalse );
       
   543             }
       
   544         else
       
   545             {
       
   546             item.SetKey( KNativeUiKeyIdLSK );
       
   547             item.SetValueL( KAiLocalAppAppShell, EFalse );
       
   548             }
       
   549 
       
   550         // Append settings into array.
       
   551         // This can not fail because space has been reserved.
       
   552         aSettings.Append( settings );
       
   553 
       
   554         CleanupStack::PopAndDestroy( appBuf );
       
   555         appBuf = NULL;
       
   556 
       
   557         CleanupStack::Pop( settings );
       
   558 
       
   559         settings = AiUtility::CreatePluginSettingsL();
       
   560         CleanupDeletePushL( settings );
       
   561 
       
   562         MAiPluginSettingsItem& item2 = settings->AiPluginSettingsItem();
       
   563         item2.SetPublisherId( aPublisherInfo.Uid() );
       
   564 
       
   565         HBufC* app2Buf;
       
   566         app2Buf = HBufC::NewLC( RProperty::KMaxPropertySize );
       
   567         TPtr app2Ptr = app2Buf->Des();
       
   568         RProperty::Get( KPSUidAiInformation, KActiveIdleExtHS_RSKLocked, app2Ptr );
       
   569         if( app2Ptr.Length() > 0 )
       
   570             {
       
   571             item2.SetKey( KNativeUiKeyIdLockedRSK );
       
   572             item2.SetValueL( app2Ptr, EFalse );
       
   573             }
       
   574         else
       
   575             {
       
   576             item2.SetKey( KNativeUiKeyIdRSK );
       
   577             item2.SetValueL( KAiLocalAppContacts, EFalse );
       
   578             }
       
   579         
       
   580         // Append settings into array.
       
   581         // This can not fail because space has been reserved.
       
   582         aSettings.Append( settings );
       
   583 
       
   584         CleanupStack::PopAndDestroy( app2Buf );
       
   585         app2Buf = NULL;
       
   586         
       
   587         // In case there are settings in the cenrep the settings
       
   588         // here are overwritten by them
       
   589         GetSettingsFromCRL( aPublisherInfo, aSettings );
       
   590         CleanupStack::Pop( settings );
       
   591         }
       
   592     }
       
   593 
       
   594 // ----------------------------------------------------------------------------
       
   595 // CNativeUiController::GetSettingsFromCRL()
       
   596 //
       
   597 // ----------------------------------------------------------------------------
       
   598 //
       
   599 void CNativeUiController::GetSettingsFromCRL( 
       
   600     const THsPublisherInfo& aPublisherInfo, 
       
   601     RAiSettingsItemArray &aPluginSettings )                                
       
   602     {
       
   603     if ( aPublisherInfo.Namespace() != KNativeUiNamespace )
       
   604         {
       
   605         return;
       
   606         }
       
   607     
       
   608     /*
       
   609     * The settings are stored in the cenrep starting from 0x1000.
       
   610     * 0x1000 is the name of the plugin which this setting belongs to (for example Settings/Shortcut)
       
   611     * 0x1001 is the id of the setting (for example 1)
       
   612     * 0x1002 is the value of the setting (for example localapp:0x012345678)
       
   613     *
       
   614     * So three keys per setting.
       
   615     */
       
   616 
       
   617     TUint32 crKey = KAIPluginSettingsKeyRangeStart;
       
   618 
       
   619     TBool moreSettings = ETrue;
       
   620 
       
   621     HBufC* pluginId = HBufC::NewLC(NCentralRepositoryConstants::KMaxUnicodeStringLength);
       
   622     HBufC* settingValue = HBufC::NewLC(NCentralRepositoryConstants::KMaxUnicodeStringLength);
       
   623     HBufC* settingKey = HBufC::NewLC(NCentralRepositoryConstants::KMaxUnicodeStringLength);
       
   624 
       
   625     TPtr pluginIdPtr = pluginId->Des();
       
   626     TPtr settingValuePtr = settingValue->Des();
       
   627     TPtr settingKeyPtr = settingKey->Des();
       
   628 
       
   629     TInt32 settingId = 0;
       
   630 
       
   631     TInt err = KErrNone;
       
   632     //TBool settingFound = EFalse;
       
   633 
       
   634     CRepository *settingsRepository = CRepository::NewLC( TUid::Uid( KCRUidActiveIdleLV ) );
       
   635 
       
   636     while ( moreSettings )
       
   637         {
       
   638         //settingFound = EFalse;
       
   639 
       
   640         pluginIdPtr.Zero();
       
   641         settingValuePtr.Zero();
       
   642         settingKeyPtr.Zero();
       
   643         //Get the name of plugin with the Settings/ prefix
       
   644         err = settingsRepository->Get(crKey++, pluginIdPtr);
       
   645 
       
   646         // remove the Settings/ prefix if it is located at the start of the string
       
   647         if ( pluginIdPtr.FindC(KSettings) == 0 )
       
   648             {
       
   649 
       
   650             pluginIdPtr.Delete(0,
       
   651                 KSettingsIdSeparator().Length() +
       
   652                 KSettings().Length());
       
   653             }
       
   654 
       
   655         // does the setting belong to this plugin
       
   656         if ( err == KErrNone && pluginIdPtr == aPublisherInfo.Name() )
       
   657             {
       
   658             // Get the settings id
       
   659             err = settingsRepository->Get(crKey++, settingKeyPtr);
       
   660             if ( err == KErrNone )
       
   661                 {
       
   662                 err = AiUtility::ParseInt(settingId,settingKeyPtr);
       
   663                 }
       
   664             if ( err == KErrNone )
       
   665                 {
       
   666                 // Get the actual value of the setting
       
   667                 err = settingsRepository->Get(crKey++, settingValuePtr);
       
   668 
       
   669                 // Ignore possible placeholder data in cenrep
       
   670                 if ( err == KErrNone && settingValuePtr.Compare( KSettingsDummyData ) != 0 )
       
   671                     {
       
   672                     // Try to find an existing setting for this
       
   673                     for ( TInt j = 0; j < aPluginSettings.Count(); j++  )
       
   674                         {
       
   675                         MAiPluginSettings *setting = aPluginSettings[j];
       
   676                         MAiPluginSettingsItem& item = setting->AiPluginSettingsItem();
       
   677 
       
   678                         // Existing setting found => replace it
       
   679                         if ( item.Key() == settingId && item.PublisherId() == aPublisherInfo.Uid() )
       
   680                             {
       
   681                             item.SetValueL( settingValuePtr, EFalse );
       
   682                             //settingFound = ETrue;
       
   683                             break;
       
   684                             }
       
   685                         }
       
   686                     // Existing setting not found => append new one ONLY if we
       
   687                     // are dealing with the icon overrides
       
   688                     /* NOTE ai_shortcut_command_api has been removed!
       
   689                     if ( !settingFound && ( settingId & KScutFlagBitIconOverride ) )
       
   690                         {
       
   691                         MAiPluginSettings* settings = AiUtility::CreatePluginSettingsL();
       
   692                         CleanupDeletePushL( settings );
       
   693                         MAiPluginSettingsItem& item = settings->AiPluginSettingsItem();
       
   694 
       
   695                         item.SetPublisherId( aPublisherInfo.Uid() );
       
   696                         item.SetKey( settingId );
       
   697                         item.SetValueL( settingValuePtr, EFalse );
       
   698                         aPluginSettings.Append( settings );
       
   699 
       
   700                         CleanupStack::Pop( settings );
       
   701                         }
       
   702                      */
       
   703                     }
       
   704                 }
       
   705             }
       
   706         // name of the plugin not found => no more settings
       
   707         else if (err != KErrNone )
       
   708             {
       
   709             moreSettings = EFalse;
       
   710 
       
   711             }
       
   712         // not the correct setting for this plugin
       
   713         else
       
   714             {
       
   715             crKey += KAI2CrKeyIncrementBy2;
       
   716             }
       
   717         }
       
   718     
       
   719     CleanupStack::PopAndDestroy(settingsRepository);
       
   720     CleanupStack::PopAndDestroy(settingKey);
       
   721     CleanupStack::PopAndDestroy(settingValue);
       
   722     CleanupStack::PopAndDestroy(pluginId);
       
   723     }
       
   724 
       
   725 // ----------------------------------------------------------------------------
       
   726 // CNativeUiController::ActivateUI()
       
   727 //
       
   728 // ----------------------------------------------------------------------------
       
   729 //
       
   730 void CNativeUiController::ActivateUI()
       
   731     {
       
   732     if( iAppUi && iRunningAsMain )
       
   733         {        
       
   734         TRAP_IGNORE( iAppUi->StartL() );
       
   735         
       
   736         TInt value( EIdlePhase1Ok );
       
   737         
       
   738         RProperty::Get( KPSUidStartup, KPSIdlePhase1Ok, value ); 
       
   739                                                                                               
       
   740         if ( value == EIdlePhase1NOK )
       
   741             {
       
   742             RProperty::Set( KPSUidStartup, KPSIdlePhase1Ok, EIdlePhase1Ok );                                                                                                          
       
   743             }                
       
   744         }
       
   745     }
       
   746 
       
   747 // ----------------------------------------------------------------------------
       
   748 // CNativeUiController::GetContentObserver()
       
   749 //
       
   750 // ----------------------------------------------------------------------------
       
   751 //
       
   752 MAiContentObserver& CNativeUiController::GetContentObserver()
       
   753     {
       
   754     return *this;
       
   755     }
       
   756 
       
   757 // ----------------------------------------------------------------------------
       
   758 // CNativeUiController::SetEventHandler()
       
   759 //
       
   760 // ----------------------------------------------------------------------------
       
   761 //
       
   762 void CNativeUiController::SetEventHandler( MAiFwEventHandler& aEventHandler )
       
   763     {
       
   764     iFwEventHandler = &aEventHandler;
       
   765     }
       
   766 
       
   767 // ----------------------------------------------------------------------------
       
   768 // CNativeUiController::SetStateHandler()
       
   769 //
       
   770 // ----------------------------------------------------------------------------
       
   771 //
       
   772 void CNativeUiController::SetStateHandler( MAiFwStateHandler& aStateHandler )
       
   773     {
       
   774     iFwStateHandler = &aStateHandler;
       
   775     }
       
   776 
       
   777 // ----------------------------------------------------------------------------
       
   778 // CNativeUiController::FwEventHandler()
       
   779 //
       
   780 // ----------------------------------------------------------------------------
       
   781 //
       
   782 MAiFwEventHandler* CNativeUiController::FwEventHandler()
       
   783     {
       
   784     return iFwEventHandler;
       
   785     }
       
   786 
       
   787 // ----------------------------------------------------------------------------
       
   788 // CNativeUiController::MainInterface()
       
   789 //
       
   790 // ----------------------------------------------------------------------------
       
   791 //
       
   792 MAiMainUiController* CNativeUiController::MainInterface()
       
   793     {
       
   794     return this;
       
   795     }
       
   796 
       
   797 // ----------------------------------------------------------------------------
       
   798 // CNativeUiController::SecondaryInterface()
       
   799 //
       
   800 // ----------------------------------------------------------------------------
       
   801 //
       
   802 MAiSecondaryUiController* CNativeUiController::SecondaryInterface()
       
   803     {
       
   804     return this;
       
   805     }
       
   806 
       
   807 // ----------------------------------------------------------------------------
       
   808 // CNativeUiController::RunApplicationL()
       
   809 //
       
   810 // ----------------------------------------------------------------------------
       
   811 //
       
   812 void CNativeUiController::RunApplicationL()
       
   813     {
       
   814     VariateToMainUiController();
       
   815 
       
   816     User::LeaveIfError(
       
   817         EikStart::RunApplication( &CNativeUiController::NewApplication ) );
       
   818     }
       
   819 
       
   820 // ----------------------------------------------------------------------------
       
   821 // CNativeUiController::CoeEnv()
       
   822 //
       
   823 // ----------------------------------------------------------------------------
       
   824 //
       
   825 CCoeEnv& CNativeUiController::CoeEnv()
       
   826     {
       
   827     return *CCoeEnv::Static();
       
   828     }
       
   829 
       
   830 // ----------------------------------------------------------------------------
       
   831 // CNativeUiController::IsMenuOpen()
       
   832 //
       
   833 // ----------------------------------------------------------------------------
       
   834 //
       
   835 TBool CNativeUiController::IsMenuOpen()
       
   836     {
       
   837     return iAppUi->IsDisplayingMenuOrDialog();
       
   838     }
       
   839 
       
   840 // ----------------------------------------------------------------------------
       
   841 // CNativeUiController::SetCoeEnv()
       
   842 //
       
   843 // ----------------------------------------------------------------------------
       
   844 //
       
   845 void CNativeUiController::SetCoeEnv( CCoeEnv& aCoeEnv )
       
   846     {
       
   847     iCoeEnv = &aCoeEnv;
       
   848     }
       
   849 
       
   850 // ----------------------------------------------------------------------------
       
   851 // CNativeUiController::StartTransaction()
       
   852 //
       
   853 // ----------------------------------------------------------------------------
       
   854 //
       
   855 TInt CNativeUiController::StartTransaction( TInt /*aTxId*/ )
       
   856     {
       
   857     return KErrNone;
       
   858     }
       
   859 
       
   860 // ----------------------------------------------------------------------------
       
   861 // CNativeUiController::Commit()
       
   862 //
       
   863 // ----------------------------------------------------------------------------
       
   864 //
       
   865 TInt CNativeUiController::Commit( TInt /*aTxId*/ )
       
   866     {
       
   867     TInt result( KErrNone );
       
   868     const TInt count( iRenderers.Count() );
       
   869     
       
   870     for( TInt i( 0 ); i < count; i++ )
       
   871         {
       
   872         TRAP( result, iRenderers[i]->TransactionCommittedL() );
       
   873         }
       
   874     
       
   875     return result;
       
   876     }
       
   877 
       
   878 // ----------------------------------------------------------------------------
       
   879 // CNativeUiController::CancelTransaction()
       
   880 //
       
   881 // ----------------------------------------------------------------------------
       
   882 //
       
   883 TInt CNativeUiController::CancelTransaction( TInt /*aTxId*/ )
       
   884     {
       
   885     return KErrNone;
       
   886     }
       
   887 
       
   888 // ----------------------------------------------------------------------------
       
   889 // CNativeUiController::CanPublish()
       
   890 //
       
   891 // ----------------------------------------------------------------------------
       
   892 //
       
   893 TBool CNativeUiController::CanPublish( CHsContentPublisher& aPlugin,
       
   894     TInt /*aContent*/, TInt /*aIndex*/ )                                      
       
   895     {    
       
   896     const THsPublisherInfo& info( aPlugin.PublisherInfo() );
       
   897              
       
   898     if ( IsDeviceStatus( info ) )
       
   899         {
       
   900         return ETrue;
       
   901         }
       
   902     
       
   903     if ( info.Namespace() != KNativeUiNamespace )
       
   904         {
       
   905         return EFalse;
       
   906         }
       
   907     
       
   908     for( TInt i = 0; i < iPlugins.Count(); i++ )
       
   909         {               
       
   910         if ( iPlugins[i] == info )
       
   911             {
       
   912             return ETrue;
       
   913             }
       
   914         }
       
   915 
       
   916     return EFalse;
       
   917     }
       
   918 
       
   919 // ----------------------------------------------------------------------------
       
   920 // CNativeUiController::Publish()
       
   921 //
       
   922 // ----------------------------------------------------------------------------
       
   923 //
       
   924 TInt CNativeUiController::Publish( CHsContentPublisher& aPlugin,
       
   925     TInt aContent, TInt aResource, TInt aIndex )
       
   926     {
       
   927     TInt err = DoPublish( aPlugin, aContent, aResource, aIndex );
       
   928     return err;
       
   929     }
       
   930 
       
   931 // ----------------------------------------------------------------------------
       
   932 // CNativeUiController::Publish()
       
   933 //
       
   934 // ----------------------------------------------------------------------------
       
   935 //
       
   936 TInt CNativeUiController::Publish( CHsContentPublisher& aPlugin,
       
   937     TInt aContent, const TDesC16& aText, TInt aIndex )        
       
   938     {
       
   939     TInt err = DoPublish( aPlugin, aContent, aText, aIndex );
       
   940     return err;
       
   941     }
       
   942 
       
   943 // ----------------------------------------------------------------------------
       
   944 // CNativeUiController::Publish()
       
   945 //
       
   946 // ----------------------------------------------------------------------------
       
   947 //
       
   948 TInt CNativeUiController::Publish( CHsContentPublisher& aPlugin,
       
   949     TInt aContent, const TDesC8& aBuf, TInt aIndex )
       
   950     {
       
   951     TInt err = DoPublish( aPlugin, aContent, aBuf, aIndex );
       
   952     return err;
       
   953     }
       
   954 
       
   955 // ----------------------------------------------------------------------------
       
   956 // CNativeUiController::Publish()
       
   957 //
       
   958 // ----------------------------------------------------------------------------
       
   959 //
       
   960 TInt CNativeUiController::Publish( CHsContentPublisher& aPlugin,                                     
       
   961     TInt aContent, RFile& aFile, TInt aIndex )                                   
       
   962     {
       
   963     TInt err = DoPublish( aPlugin, aContent, aFile, aIndex );
       
   964     return err;
       
   965     }
       
   966 
       
   967 // ----------------------------------------------------------------------------
       
   968 // CNativeUiController::Clean()
       
   969 //
       
   970 // ----------------------------------------------------------------------------
       
   971 //
       
   972 TInt CNativeUiController::Clean( CHsContentPublisher& aPlugin, 
       
   973     TInt aContent, TInt /*aIndex*/ )
       
   974     {
       
   975     const TInt count( iRenderers.Count() ); 
       
   976     
       
   977     for( TInt i( 0 ); i < count; i++ )
       
   978         {
       
   979         iRenderers[i]->Clean( aPlugin, aContent );
       
   980         }
       
   981 
       
   982     return KErrNone;
       
   983     }
       
   984 
       
   985 // ----------------------------------------------------------------------------
       
   986 // CNativeUiController::Extension()
       
   987 //
       
   988 // ----------------------------------------------------------------------------
       
   989 //
       
   990 TAny* CNativeUiController::Extension( TUid /*aUid*/ )
       
   991     {
       
   992     return NULL;
       
   993     }
       
   994 
       
   995 // ----------------------------------------------------------------------------
       
   996 // CNativeUiController::RequiresSubscription()
       
   997 //
       
   998 // ----------------------------------------------------------------------------
       
   999 //
       
  1000 TBool CNativeUiController::RequiresSubscription( 
       
  1001     const THsPublisherInfo& aPublisherInfo ) const
       
  1002     {
       
  1003     if ( IsDeviceStatus( aPublisherInfo ) || 
       
  1004         aPublisherInfo.Namespace() == KNativeUiNamespace )
       
  1005         {
       
  1006         // Targeted to this content renderer
       
  1007         return ETrue;
       
  1008         }
       
  1009     
       
  1010     return EFalse;
       
  1011     }
       
  1012 
       
  1013 // ----------------------------------------------------------------------------
       
  1014 // CNativeUiController::SetProperty()
       
  1015 // ----------------------------------------------------------------------------
       
  1016 //
       
  1017 TInt CNativeUiController::SetProperty( CHsContentPublisher& /*aPlugin*/,
       
  1018         const TDesC8& /*aElementId*/,
       
  1019         const TDesC8& /*aPropertyName*/,
       
  1020         const TDesC8& /*aPropertyValue*/ ) 
       
  1021     {   
       
  1022     return KErrNotSupported;
       
  1023     }
       
  1024 
       
  1025 // ----------------------------------------------------------------------------
       
  1026 // CNativeUiController::SetProperty()
       
  1027 // ----------------------------------------------------------------------------
       
  1028 //   
       
  1029 TInt CNativeUiController::SetProperty(CHsContentPublisher& /*aPlugin*/,
       
  1030         const TDesC8& /*aElementId*/,
       
  1031         const TDesC8& /*aPropertyName*/,
       
  1032         const TDesC8& /*aPropertyValue*/,
       
  1033         MAiContentObserver::TValueType /*aValueType*/) 
       
  1034     {
       
  1035     return KErrNotSupported;
       
  1036     }
       
  1037 
       
  1038 // ----------------------------------------------------------------------------
       
  1039 // CNativeUiController::NewApplication()
       
  1040 //
       
  1041 // ----------------------------------------------------------------------------
       
  1042 //
       
  1043 CApaApplication* CNativeUiController::NewApplication()
       
  1044     {
       
  1045     CNativeUiController* self = 
       
  1046         static_cast< CNativeUiController* >( Dll::Tls() );
       
  1047   
       
  1048     return CApplication::New( self );
       
  1049     }
       
  1050 
       
  1051 // ----------------------------------------------------------------------------
       
  1052 // CNativeUiController::VariateToMainUiController()
       
  1053 //
       
  1054 // ----------------------------------------------------------------------------
       
  1055 //
       
  1056 void CNativeUiController::VariateToMainUiController()
       
  1057     {
       
  1058     iRunningAsMain = ETrue;
       
  1059     }
       
  1060 
       
  1061 // ======== GLOBAL FUNCTIONS ========
       
  1062 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
  1063     {
       
  1064     aTableCount = sizeof( KImplementationTable ) / sizeof( TImplementationProxy );
       
  1065     return KImplementationTable;
       
  1066     }
       
  1067 
       
  1068 // End of File.