idlefw/tsrc/framework/mt_aifw/AiFwTestControllerPlugin.cpp
branchRCL_3
changeset 27 2c7f27287390
equal deleted inserted replaced
25:9e077f9a342c 27:2c7f27287390
       
     1 /*
       
     2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // ========== INCLUDE FILES ===================================================
       
    20 
       
    21 #include "AiFwTestControllerPlugin.h"
       
    22 
       
    23 #include <e32std.h>
       
    24 
       
    25 #include "AiFwTestDefines.h"
       
    26 #include "AiFwTestContentModel.h"
       
    27 
       
    28 #include <aipluginsettings.h>
       
    29 #include "aifweventhandler.h"
       
    30 #include <aicontentmodel.h>
       
    31 #include <aiutility.h>
       
    32 #include "aiuiframeworkobserver.h"
       
    33 using namespace AiTestUiController;
       
    34 
       
    35 
       
    36 // ========== MEMBER FUNCTIONS ================================================
       
    37 
       
    38 // ----------------------------------------------------------------------------
       
    39 //
       
    40 //
       
    41 //
       
    42 // ----------------------------------------------------------------------------
       
    43 //
       
    44 CAiFwTestControllerPlugin::CAiFwTestControllerPlugin()
       
    45     {
       
    46     }
       
    47 
       
    48 EXPORT_C CAiFwTestControllerPlugin* CAiFwTestControllerPlugin::Instance()
       
    49     {
       
    50     TAny* ptr = Dll::Tls();
       
    51     
       
    52     if ( ptr )
       
    53         {
       
    54         TAiTestTLSStorage* tlsSet = static_cast<TAiTestTLSStorage*>( ptr );
       
    55         return tlsSet->iControllerPlugin;
       
    56         }
       
    57     return NULL;
       
    58     }
       
    59 
       
    60 // ----------------------------------------------------------------------------
       
    61 //
       
    62 //
       
    63 //
       
    64 // ----------------------------------------------------------------------------
       
    65 //
       
    66 void CAiFwTestControllerPlugin::ConstructL()
       
    67     {
       
    68        TAiTestTLSStorage* tlsSet = TAiTestTLSStorage::CreateInstanceL();
       
    69     tlsSet->iControllerPlugin = this;
       
    70 
       
    71     iContent   = AiUtility::CreateContentItemArrayIteratorL(KTestPluginContent);
       
    72     iResources = AiUtility::CreateContentItemArrayIteratorL(KTestPluginResources);
       
    73     iEvents    = AiUtility::CreateContentItemArrayIteratorL(KTestPluginEvents);
       
    74     }
       
    75 
       
    76 // ----------------------------------------------------------------------------
       
    77 //
       
    78 //
       
    79 //
       
    80 // ----------------------------------------------------------------------------
       
    81 //
       
    82 CAiFwTestControllerPlugin* CAiFwTestControllerPlugin::NewL()
       
    83     {
       
    84     CAiFwTestControllerPlugin* self = new (ELeave) CAiFwTestControllerPlugin();
       
    85     
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL();
       
    88     CleanupStack::Pop();
       
    89     
       
    90     return self;
       
    91     }
       
    92 
       
    93 // ----------------------------------------------------------------------------
       
    94 //
       
    95 //
       
    96 //
       
    97 // ----------------------------------------------------------------------------
       
    98 //
       
    99 CAiFwTestControllerPlugin::~CAiFwTestControllerPlugin()
       
   100     {
       
   101        TAiTestTLSStorage::DestroyInstance();
       
   102     Release( iContent );
       
   103     Release( iResources );
       
   104     Release( iEvents );
       
   105     }
       
   106 
       
   107 // ----------------------------------------------------------------------------
       
   108 //
       
   109 //
       
   110 //
       
   111 // ----------------------------------------------------------------------------
       
   112 //
       
   113 TInt CAiFwTestControllerPlugin::StartTransaction(TInt /*aTxId*/)
       
   114     {
       
   115     return 0;
       
   116     }
       
   117 
       
   118 // ----------------------------------------------------------------------------
       
   119 //
       
   120 //
       
   121 //
       
   122 // ----------------------------------------------------------------------------
       
   123 //
       
   124 TInt CAiFwTestControllerPlugin::Commit(TInt /*aTxId*/)
       
   125     {
       
   126     return 0;
       
   127     }
       
   128 
       
   129 // ----------------------------------------------------------------------------
       
   130 //
       
   131 //
       
   132 //
       
   133 // ----------------------------------------------------------------------------
       
   134 //
       
   135 TInt CAiFwTestControllerPlugin::CancelTransaction(TInt /*aTxId*/)
       
   136     {
       
   137     return 0;
       
   138     }
       
   139 
       
   140 TBool CAiFwTestControllerPlugin::CanPublish( MAiPropertyExtension& /*aPlugin*/,
       
   141                                              TInt /*aContent*/,
       
   142                                              TInt /*aIndex*/ )
       
   143     {
       
   144     return EFalse;
       
   145     }
       
   146 
       
   147 // ----------------------------------------------------------------------------
       
   148 //
       
   149 //
       
   150 //
       
   151 // ----------------------------------------------------------------------------
       
   152 //
       
   153 TInt CAiFwTestControllerPlugin::Publish( MAiPropertyExtension& /*aPlugin*/,
       
   154                               TInt /*aContent*/, TInt /*aResource*/, TInt /*aIndex*/ )
       
   155     {
       
   156     /*  // Read ref value.
       
   157         MAiContentItemIterator* i =
       
   158             (MAiContentItemIterator*) aPlugin->GetPropertyL( EAiPublisherResources );
       
   159 
       
   160         const TAiContentItem& ref = i->ItemL( aResource );
       
   161         
       
   162         const TDesC8& refType = ContentType( ref );
       
   163         const TDesC& refCid = ContentCid( ref );
       
   164         
       
   165         if ( refType.Match( KDataTypeText ) != KErrNotFound )
       
   166             {
       
   167             const TDesC* text = GetText( refCid );
       
   168             
       
   169             if ( text )
       
   170                 {
       
   171                 HBufC8* buf8 = HBufC8::NewLC( text->Length() );
       
   172                 buf8->Des().Copy( *text );
       
   173                 TPtrC8 ptr = buf8->Des();
       
   174                 Publish( aPlugin, aContent, ptr );
       
   175                 CleanupStack::PopAndDestroy(); // buf8
       
   176                 }
       
   177             }
       
   178         
       
   179         // TODO: Support another types.
       
   180         */        
       
   181 
       
   182     
       
   183     return 0;
       
   184     }
       
   185 
       
   186 // ----------------------------------------------------------------------------
       
   187 //
       
   188 //
       
   189 //
       
   190 // ----------------------------------------------------------------------------
       
   191 //
       
   192 TInt CAiFwTestControllerPlugin::Publish( MAiPropertyExtension& /*aPlugin*/,
       
   193                               TInt /*aContent*/, const TDesC16& /*aBuf*/, TInt /*aIndex*/ )
       
   194     {
       
   195     /*
       
   196         MAiContentItemIterator* i =
       
   197             (MAiContentItemIterator*) aPlugin->GetPropertyL( EAiPublisherContent );
       
   198 
       
   199         const TAiContentItem& item = i->ItemL( aContent );
       
   200         
       
   201         const TDesC8& type = ContentType( item );
       
   202         const TDesC& cid = ContentCid( item );
       
   203         
       
   204         if ( type.Match( KDataTypeText ) != KErrNotFound )
       
   205             {
       
   206             SetText( cid, aBuf );
       
   207             }
       
   208         
       
   209         // TODO: Support another types.
       
   210         
       
   211         */
       
   212     
       
   213     return 0;
       
   214     }
       
   215 
       
   216 // ----------------------------------------------------------------------------
       
   217 //
       
   218 //
       
   219 //
       
   220 // ----------------------------------------------------------------------------
       
   221 //
       
   222 TInt CAiFwTestControllerPlugin::Publish( MAiPropertyExtension& /*aPlugin*/,
       
   223                               TInt /*aContent*/, const TDesC8& /*aBuf*/, TInt /*aIndex */)
       
   224     {
       
   225     /*
       
   226         MAiContentItemIterator* i =
       
   227             (MAiContentItemIterator*) aPlugin->GetPropertyL( EAiPublisherContent );
       
   228 
       
   229         const TAiContentItem& item = i->ItemL( aContent );
       
   230         
       
   231         const TDesC8& type = ContentType( item );
       
   232         const TDesC& cid = ContentCid( item );
       
   233         
       
   234         if ( type.Match( KDataTypeText ) != KErrNotFound )
       
   235             {
       
   236             SetText( cid, aBuf );
       
   237             }
       
   238         
       
   239         // TODO: Support another types.
       
   240         
       
   241         */
       
   242     
       
   243     return 0;
       
   244     }
       
   245     
       
   246 // ----------------------------------------------------------------------------
       
   247 //
       
   248 //
       
   249 //
       
   250 // ----------------------------------------------------------------------------
       
   251 //
       
   252 TInt CAiFwTestControllerPlugin::Publish( MAiPropertyExtension& /*aPlugin*/,
       
   253                               TInt /*aContent*/, RFile& /*aFile*/, TInt /*aIndex*/ )
       
   254     {
       
   255     // TODO: get content from aFile.
       
   256 
       
   257     return 0;
       
   258     }
       
   259 
       
   260 // ----------------------------------------------------------------------------
       
   261 //
       
   262 //
       
   263 //
       
   264 // ----------------------------------------------------------------------------
       
   265 //
       
   266 TInt CAiFwTestControllerPlugin::Clean( MAiPropertyExtension& /*aPlugin*/,
       
   267                                        TInt /*aContent*/, TInt /*aIndex*/ )
       
   268     {
       
   269         // TODO: clean content.
       
   270     
       
   271     return 0;
       
   272     }
       
   273 
       
   274 // ----------------------------------------------------------------------------
       
   275 //
       
   276 //
       
   277 //
       
   278 // ----------------------------------------------------------------------------
       
   279 //
       
   280 TAny* CAiFwTestControllerPlugin::Extension( TUid /*aUid*/ )
       
   281     {
       
   282     return NULL;
       
   283     }
       
   284 
       
   285 // ----------------------------------------------------------------------------
       
   286 //
       
   287 //
       
   288 //
       
   289 // ----------------------------------------------------------------------------
       
   290 //
       
   291 TBool CAiFwTestControllerPlugin::RequiresSubscription( 
       
   292                                  const TAiPublisherInfo& aPublisherInfo ) const
       
   293     {
       
   294     return EFalse;
       
   295     }
       
   296 
       
   297 // ----------------------------------------------------------------------------
       
   298 //
       
   299 //
       
   300 //
       
   301 // ----------------------------------------------------------------------------
       
   302 //
       
   303 void CAiFwTestControllerPlugin::LoadUIDefinitionL()
       
   304     {
       
   305     iDefinitionLoaded = ETrue;
       
   306     }
       
   307 
       
   308 // ----------------------------------------------------------------------------
       
   309 //
       
   310 //
       
   311 //
       
   312 // ----------------------------------------------------------------------------
       
   313 //
       
   314 void CAiFwTestControllerPlugin::GetPluginsL( RAiPublisherInfoArray& aPlugins )
       
   315     {
       
   316     TAiPublisherInfo info;
       
   317     info.iUid = TUid::Uid(KImplementationUidAiTestContentPlugin);
       
   318     info.iName = _L( "AiFwTestPlugin" );
       
   319     info.iNamespace = _L8( "AiFw" );
       
   320     User::LeaveIfError( aPlugins.Append( info ) );
       
   321     /*
       
   322     info.iUid = TUid::Uid(KImplementationUidAiTestContentPlugin2);
       
   323     info.iName = _L( "AiFwTestPlugin2" );
       
   324     User::LeaveIfError( aPlugins.Append( info ) );
       
   325     info.iUid = TUid::Uid(KImplementationUidAiTestContentPlugin3);
       
   326     info.iName = _L( "AiFwTestPlugin3" );
       
   327     User::LeaveIfError( aPlugins.Append( info ) );
       
   328     info.iUid = TUid::Uid(KImplementationUidAiTestContentPlugin6);
       
   329     info.iName = _L( "Plurgin" );
       
   330     User::LeaveIfError( aPlugins.Append( info ) );
       
   331     info.iUid = TUid::Uid(KImplementationUidAiTestContentPlugin4);
       
   332     info.iName = _L( "AiFwTestPlugin4" );
       
   333     User::LeaveIfError( aPlugins.Append( info ) );
       
   334     info.iUid = TUid::Uid(KImplementationUidAiTestContentPlugin5);
       
   335     info.iName = _L( "AiFwTestPlugin5" );
       
   336     User::LeaveIfError( aPlugins.Append( info ) );
       
   337     info.iUid = TUid::Uid(KImplementationUidAiTestContentPlugin7);
       
   338     info.iName = _L( "AiFwTestPlugin7" );
       
   339     User::LeaveIfError( aPlugins.Append( info ) );
       
   340     info.iUid = TUid::Uid(KImplementationUidAiTestContentPlugin8);
       
   341     info.iName = _L( "AiFwTestPlugin8" );
       
   342     User::LeaveIfError( aPlugins.Append( info ) );
       
   343     info.iUid = TUid::Uid(KImplementationUidAiTestContentPlugin9);
       
   344     info.iName = _L( "AiFwTestPlugin9" );
       
   345     User::LeaveIfError( aPlugins.Append( info ) );
       
   346     */
       
   347     }
       
   348     
       
   349 void CAiFwTestControllerPlugin::GetSettingsL(
       
   350                                           const TAiPublisherInfo& /*aPubInfo*/,
       
   351                                           RAiSettingsItemArray& aSettings)
       
   352     {
       
   353     MAiPluginSettings* settings = AiUtility::CreatePluginSettingsL();
       
   354     CleanupDeletePushL(settings);
       
   355     MAiPluginSettingsItem& item = settings->AiPluginSettingsItem();
       
   356     item.SetPublisherId( TUid::Uid( 0x10170FFF ) );
       
   357     item.SetValueL( _L("DesValue") );
       
   358     item.SetKey( 1 );
       
   359     
       
   360     // This will fail as no cenrep is setup, -> TRAP it.
       
   361     //TRAP_IGNORE( item.UpdateFromCenRepL() );
       
   362     
       
   363     aSettings.AppendL( settings );
       
   364     CleanupStack::Pop( settings );
       
   365     }
       
   366 
       
   367 // ----------------------------------------------------------------------------
       
   368 //
       
   369 //
       
   370 //
       
   371 // ----------------------------------------------------------------------------
       
   372 //
       
   373 void CAiFwTestControllerPlugin::RunApplicationL()
       
   374     {
       
   375     iRunApplicationCalled = ETrue;
       
   376     SendReadyEventL();
       
   377     }
       
   378 
       
   379 // ----------------------------------------------------------------------------
       
   380 //
       
   381 //
       
   382 //
       
   383 // ----------------------------------------------------------------------------
       
   384 //
       
   385 void CAiFwTestControllerPlugin::ActivateUI()
       
   386     {
       
   387     iUiActivated = ETrue;
       
   388     }
       
   389     
       
   390 // ----------------------------------------------------------------------------
       
   391 //
       
   392 //
       
   393 //
       
   394 // ----------------------------------------------------------------------------
       
   395 //
       
   396 MAiContentObserver& CAiFwTestControllerPlugin::GetContentObserver()
       
   397     {
       
   398     return *this;
       
   399     }
       
   400 
       
   401 // ----------------------------------------------------------------------------
       
   402 //
       
   403 //
       
   404 //
       
   405 // ----------------------------------------------------------------------------
       
   406 //
       
   407 void CAiFwTestControllerPlugin::SetText( const TDesC8& /*aId*/, TPtrC8& /*aBuf*/ )
       
   408     {
       
   409     /*TBuf<KMaxLenContentId> id;
       
   410     id.Copy( aId );
       
   411     HBufC* value = HBufC::NewLC( aBuf.Length() );
       
   412     value->Des().Copy( aBuf );
       
   413     
       
   414     CXnNode* node = UiEngine()->FindNodeByIdL( id );
       
   415     
       
   416     if ( node )
       
   417         {
       
   418         node = node->Parent();
       
   419         MXnTextInterface* textIntr = CXnText::MakeInterfaceL( *node );
       
   420         
       
   421         if ( textIntr )
       
   422             {
       
   423             const TDesC* text = textIntr->Text();
       
   424             textIntr->SetTextL( value->Des() );
       
   425             CXnComponentNodeImpl* nodeImpl = node->ComponentNodeImpl();
       
   426             CXnComponent* component = nodeImpl->Component();
       
   427             CXnControlAdapter* adapter = component->ControlAdapter();
       
   428             adapter->DrawNow();
       
   429             }
       
   430         }
       
   431     
       
   432     CleanupStack::PopAndDestroy(); // value*/
       
   433     }
       
   434 
       
   435 // ----------------------------------------------------------------------------
       
   436 //
       
   437 //
       
   438 //
       
   439 // ----------------------------------------------------------------------------
       
   440 //
       
   441 const TDesC* CAiFwTestControllerPlugin::GetText( const TDesC8& /*aId*/ )
       
   442     {
       
   443     /*TBuf<KMaxLenContentId> id;
       
   444     id.Copy( aId );
       
   445     
       
   446     CXnNode* node = UiEngine()->FindNodeByIdL( id );
       
   447     
       
   448     if ( node )
       
   449         {
       
   450         node = node->Parent();
       
   451         MXnTextInterface* textIntr = CXnText::MakeInterfaceL( *node );
       
   452         
       
   453         if ( textIntr )
       
   454             {
       
   455             return textIntr->Text();
       
   456             }
       
   457         }
       
   458     */
       
   459     return NULL;
       
   460     }
       
   461     
       
   462 void CAiFwTestControllerPlugin::HandleLoadedPlugins( 
       
   463                                       const RAiPublisherInfoArray& aPlugins ) 
       
   464     {
       
   465     for ( int i = 0; i < aPlugins.Count(); ++i )
       
   466         {
       
   467         iFwEventHandler->HandleLoadPluginL( aPlugins[i] );
       
   468         }
       
   469     }
       
   470 
       
   471 void CAiFwTestControllerPlugin::SetEventHandler(MAiFwEventHandler& aEventHandler)
       
   472     {
       
   473     iFwEventHandler = &aEventHandler;
       
   474     }
       
   475 
       
   476 EXPORT_C TBool CAiFwTestControllerPlugin::UiActivated()
       
   477     {
       
   478     return iUiActivated;  
       
   479     }
       
   480 
       
   481 EXPORT_C TBool CAiFwTestControllerPlugin::RunApplicationCalled()
       
   482     {
       
   483     return iRunApplicationCalled;
       
   484     }
       
   485 
       
   486 EXPORT_C TBool CAiFwTestControllerPlugin::DefinitionLoaded()
       
   487     {
       
   488     return iDefinitionLoaded;
       
   489     }
       
   490     
       
   491 EXPORT_C void CAiFwTestControllerPlugin::SendReadyEventL()
       
   492     {
       
   493     if( iFwEventHandler )
       
   494         {
       
   495         iFwEventHandler->HandleUiReadyEventL(*this);
       
   496         }
       
   497     }
       
   498 
       
   499 EXPORT_C void CAiFwTestControllerPlugin::SendTestEventL()
       
   500     {
       
   501     if( iFwEventHandler )
       
   502         {
       
   503         iFwEventHandler->HandlePluginEvent(  KTestEvent );
       
   504         iFwEventHandler->HandlePluginEvent(  _L("AiFwTestPlugin/not_supp") );
       
   505         iFwEventHandler->HandlePluginEvent(  _L("AiFwTestPlugin/not_supp()") );
       
   506         iFwEventHandler->HandlePluginEvent(  _L("AiFwTestPlugin/not_supp(34342fvdsf)") );
       
   507         iFwEventHandler->HandlePluginEvent(  _L("AiFwTestPlugin/test_event(34342fvdsf)") );
       
   508         iFwEventHandler->HandlePluginEvent(  _L("AiFwTestPlugin/test_event)") );
       
   509         iFwEventHandler->HandlePluginEvent(  _L("AiFwTestPlugin/test_event(") );
       
   510         iFwEventHandler->HandlePluginEvent(  _L("AiFwTestPlugin/test_event()") );
       
   511         iFwEventHandler->HandlePluginEvent(  _L("someerrorevent/error") );
       
   512         iFwEventHandler->HandlePluginEvent(  KTestEvent );
       
   513         iFwEventHandler->HandlePluginEvent(  _L("AiFwTestPlugin4/error") );
       
   514         iFwEventHandler->HandlePluginEvent(  _L("AiFwTestPlugin3/error") );
       
   515         iFwEventHandler->HandlePluginEvent(  _L("AiFwTestPlugin7/error") );
       
   516         iFwEventHandler->HandlePluginEvent(  _L("AiFwTestPlugin7/error") );
       
   517         iFwEventHandler->HandlePluginEvent(  _L("AiFwTestPlugin7") );
       
   518         iFwEventHandler->HandlePluginEvent(  _L("AiFwTestPlugin7/test(ehe)") );
       
   519         iFwEventHandler->HandlePluginEvent(  _L("AiFwTestPlugin7/test()") );
       
   520         iFwEventHandler->HandlePluginEvent(  _L("AiFwTestPlu/test(grrraaah)") );
       
   521         iFwEventHandler->HandlePluginEvent(  _L("AiFwTestPlu/test(grrraaah") );
       
   522         iFwEventHandler->HandlePluginEvent(  _L("AiFwTestPlu/test(") );
       
   523         iFwEventHandler->HandlePluginEvent(  _L("AiFwTestPlu/test)") );
       
   524         iFwEventHandler->HandlePluginEvent(  _L("theme_change_noticed") );
       
   525         iFwEventHandler->HandlePluginEvent(  KTestEvent );
       
   526         iFwEventHandler->HandlePluginEvent(  KTestEvent );
       
   527         }
       
   528     }
       
   529 
       
   530 EXPORT_C void CAiFwTestControllerPlugin::SetResourceChangedL( TInt aRes )
       
   531     {
       
   532     iFwObserver->HandleResourceChange( aRes );
       
   533     }
       
   534     
       
   535 EXPORT_C void CAiFwTestControllerPlugin::SetForegroundL( TBool aFore )
       
   536     {
       
   537     iFwObserver->HandleForegroundEvent( aFore );
       
   538     }
       
   539     
       
   540 EXPORT_C void CAiFwTestControllerPlugin::SetAppEnvReadyL()
       
   541     {
       
   542     TRAP_IGNORE( iFwEventHandler->AppEnvReadyL() );
       
   543     }
       
   544 
       
   545 // ========== OTHER EXPORTED FUNCTIONS ========================================
       
   546 
       
   547 // End of File.