idlefw/plugins/profileplugin/src/caiprofileplugin.cpp
changeset 0 79c6a41cd166
child 8 d0529222e3f0
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     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:  Profile plug-in publisher
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <ecom/ecom.h>
       
    20 #include <ecom/implementationproxy.h>
       
    21 #include <aicontentobserver.h>
       
    22 #include <aiutility.h>
       
    23 #include <PUAcodes.hrh>
       
    24 #include <AknUtils.h>
       
    25 
       
    26 #include "aiprofileplugincontentmodel.h"
       
    27 #include <aiprofilepluginuids.hrh>
       
    28 #include "caiprofileplugin.h"
       
    29 #include "caiprofileengine.h"
       
    30 #include "aipluginsettings.h"
       
    31 
       
    32 // PUA code for the timed profile, missing from PUAcodes.hrh
       
    33 #define KAiTimedProfilePUA 0xF815
       
    34 #define KAiRTL 0x200F
       
    35 
       
    36 // CONST CLASS VARIABLES
       
    37 const TImplementationProxy KImplementationTable[] =
       
    38     {
       
    39     IMPLEMENTATION_PROXY_ENTRY( KImplUidProfilePlugin, CAiProfilePlugin::NewL ) 
       
    40     };
       
    41 
       
    42 // ======== LOCAL FUNCTIONS ========
       
    43 
       
    44 // ======== MEMBER FUNCTIONS ========
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // Symbian 2nd phase constructor can leave
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CAiProfilePlugin* CAiProfilePlugin::NewL()
       
    51     {
       
    52     CAiProfilePlugin* self = new (ELeave) CAiProfilePlugin;
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL();
       
    55     CleanupStack::Pop( self );
       
    56  
       
    57     return self;
       
    58     }
       
    59     
       
    60 // ---------------------------------------------------------------------------
       
    61 // Default constructor
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 CAiProfilePlugin::CAiProfilePlugin()
       
    65     {
       
    66     }
       
    67     
       
    68 // ---------------------------------------------------------------------------
       
    69 // Symbian 2nd phase constructor can leave
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 void CAiProfilePlugin::ConstructL()
       
    73     { 
       
    74     iInfo.iUid.iUid = AI_UID_ECOM_IMPLEMENTATION_CONTENTPUBLISHER_PROFILEPLUGIN; 
       
    75    
       
    76     iContent = AiUtility::CreateContentItemArrayIteratorL( KAiProfileContent );
       
    77     iEvents = AiUtility::CreateContentItemArrayIteratorL( KAiProfileEvents );
       
    78     iResources = AiUtility::CreateContentItemArrayIteratorL( KAiProfileResources );
       
    79     
       
    80     iIsUpdated = ETrue;
       
    81     iAlive = EFalse;        
       
    82     }
       
    83     
       
    84 // ---------------------------------------------------------------------------
       
    85 // Destructor
       
    86 // Deletes all data created to heap
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 CAiProfilePlugin::~CAiProfilePlugin()
       
    90     {
       
    91     CleanPublishedProfileNames();
       
    92     Release( iContent );
       
    93     Release( iEvents );
       
    94     Release( iResources );   
       
    95     delete iActiveProfileAndChar;
       
    96     delete iPreviousProfileNameAndChar;
       
    97     delete iEngine;
       
    98     iObservers.Close();
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // Publishes the profiles
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 void CAiProfilePlugin::PublishL()
       
   106     {
       
   107     TInt err( KErrNone );
       
   108     TInt observers( iObservers.Count() );        
       
   109     TInt transactionId = reinterpret_cast<TInt>( this );
       
   110 
       
   111     iCurrentCount = iEngine->NumberOfProfiles();
       
   112     for ( int i = 0; i < observers; i++ )
       
   113         {
       
   114         MAiContentObserver* observer = iObservers[i];
       
   115         err = observer->StartTransaction( transactionId );
       
   116 		
       
   117 		if ( err == KErrNotSupported )
       
   118             {
       
   119             // The observer does not support transactions, check for real errors.
       
   120             return;
       
   121             }
       
   122         
       
   123         //Active Profile name    
       
   124         if ( observer->CanPublish( *this, EAiProfileContentActiveProfileName, EAiProfileContentActiveProfileName ) )
       
   125         	{        	
       
   126        		observer->Publish( *this, EAiProfileContentActiveProfileName, iEngine->ActiveProfileName(), EAiProfileContentActiveProfileName );
       
   127         	}
       
   128         
       
   129         if ( observer->CanPublish( *this, EAiProfileActiveProfileNameAndIconChar, 0 ) )
       
   130             {
       
   131             delete iActiveProfileAndChar;
       
   132             iActiveProfileAndChar = NULL;
       
   133             // silent/non-silent icon + timed icon + space + possible RTL*2 = 5
       
   134             TInt maxChars = iEngine->ActiveProfileName().Length() + 5;
       
   135             
       
   136             iActiveProfileAndChar = HBufC::NewL( maxChars );
       
   137             TPtr profileNamePtr = iActiveProfileAndChar->Des();
       
   138            
       
   139             if( AknLayoutUtils::LayoutMirrored() )
       
   140                 {
       
   141                 profileNamePtr.Append( KAiRTL );
       
   142                 }
       
   143 
       
   144             if ( iEngine->IsActiveProfileTimedL() )
       
   145                 {
       
   146                 profileNamePtr.Append( KAiTimedProfilePUA );                
       
   147                 }
       
   148             if( iEngine->IsActiveProfileSilentL() )
       
   149                 {                
       
   150                 profileNamePtr.Append( KPuaCodeSilentSymbol );
       
   151                 }
       
   152             else
       
   153                 {
       
   154                 profileNamePtr.Append( KPuaCodeAprofSound );
       
   155                 }
       
   156             _LIT( KSpace, " " );   
       
   157             profileNamePtr.Append( KSpace );
       
   158             
       
   159             if( AknLayoutUtils::LayoutMirrored() )
       
   160                 {
       
   161                 profileNamePtr.Append( KAiRTL );
       
   162                 }
       
   163             
       
   164             profileNamePtr.Append( iEngine->ActiveProfileName() );
       
   165                         
       
   166             if ( !iPreviousProfileNameAndChar || 
       
   167                     iPreviousProfileNameAndChar->CompareC( *iActiveProfileAndChar ) != 0 )
       
   168                 {
       
   169                 delete iPreviousProfileNameAndChar;
       
   170                 iPreviousProfileNameAndChar = NULL;
       
   171                 observer->Publish( *this, EAiProfileActiveProfileNameAndIconChar, profileNamePtr, 0 );
       
   172                 
       
   173                 iPreviousProfileNameAndChar = iActiveProfileAndChar->AllocL();
       
   174                 }
       
   175             }
       
   176         
       
   177         //Swap Profile name ( 1.phase: General or Silent )
       
   178        	if ( observer->CanPublish( *this, EAiProfileContentSwapProfileName, EAiProfileContentSwapProfileName ) )
       
   179         	{
       
   180         	observer->Publish( *this, EAiProfileContentSwapProfileName, iEngine->SwapProfileName(), EAiProfileContentSwapProfileName );
       
   181         	}      
       
   182           
       
   183 		//All profile names
       
   184        	// clean profiles that are already deleted.
       
   185        	// Cleans the array blindly from the end, because in the next
       
   186        	// step all the profiles are republished
       
   187         if( iPreviousCount > iCurrentCount )
       
   188             {
       
   189             for( TInt k = iCurrentCount; k < iPreviousCount; k++ )
       
   190                 {
       
   191                 observer->Clean( *this, EAiProfileContentProfileName, k + 1 );
       
   192                 }
       
   193             }
       
   194 		for ( TInt j = 0; j < iCurrentCount; j++ )
       
   195 			{
       
   196 			if ( observer->CanPublish( *this, EAiProfileContentProfileName, j + 1 ) )
       
   197 				{
       
   198 				observer->Publish(*this, EAiProfileContentProfileName, iEngine->ProfileNameByIndex( j ), j + 1 );
       
   199 				}
       
   200 			}
       
   201       	
       
   202       	//Active Profile silent indicator char
       
   203         if ( observer->CanPublish( *this, EAiProfileActiveProfileSilentChar, EAiProfileActiveProfileSilentChar ) )
       
   204         	{
       
   205         	if ( iEngine->IsActiveProfileSilentL() )
       
   206         		{
       
   207         		TBuf<1> silent; // one character
       
   208         		silent.Append( KPuaCodeSilentSymbol );
       
   209         		observer->Publish( *this, EAiProfileActiveProfileSilentChar, silent, EAiProfileActiveProfileSilentChar );
       
   210         		}
       
   211         	else
       
   212         		{
       
   213         		observer->Clean( *this, EAiProfileActiveProfileSilentChar, EAiProfileActiveProfileSilentChar );
       
   214         		}
       
   215         	}
       
   216         
       
   217         //Active Profile silent indicator resource
       
   218         if ( observer->CanPublish( *this, EAiProfileActiveProfileIcon, EAiProfileActiveProfileIcon ) )
       
   219         	{
       
   220     		observer->Clean( *this, EAiProfileActiveProfileIcon, EAiProfileActiveProfileSilentIconResource );
       
   221     		observer->Clean( *this, EAiProfileActiveProfileIcon, EAiProfileActiveProfileGeneralIconResource );
       
   222     		observer->Clean( *this, EAiProfileActiveProfileIcon, EAiProfileActiveProfileTimedIconResource );
       
   223         	if ( iEngine->IsActiveProfileTimedL() )
       
   224         		{
       
   225         		observer->Publish( *this, 
       
   226         							EAiProfileActiveProfileIcon, 
       
   227         							EAiProfileActiveProfileTimedIconResource, 
       
   228         							EAiProfileActiveProfileTimedIconResource );
       
   229         		}
       
   230         	else if ( iEngine->IsActiveProfileSilentL() )
       
   231         		{
       
   232         		observer->Publish( *this, 
       
   233         							EAiProfileActiveProfileIcon, 
       
   234         							EAiProfileActiveProfileSilentIconResource, 
       
   235         							EAiProfileActiveProfileSilentIconResource );
       
   236         		}
       
   237         	else
       
   238         		{
       
   239         		observer->Publish( *this, 
       
   240         							EAiProfileActiveProfileIcon, 
       
   241         							EAiProfileActiveProfileGeneralIconResource, 
       
   242         							EAiProfileActiveProfileGeneralIconResource );
       
   243         		}
       
   244         	}
       
   245 
       
   246 		// in case of Offline profile profile indicator is not shown
       
   247         if ( observer->CanPublish( *this, EAiProfileContentActiveProfileName, EAiProfileContentActiveProfileName ) &&
       
   248         		iEngine->IsOffline() )
       
   249         	{
       
   250     		observer->Clean( *this, EAiProfileActiveProfileSilentChar, EAiProfileActiveProfileSilentChar );
       
   251     		observer->Clean( *this, EAiProfileActiveProfileIcon, 1 );
       
   252     		observer->Clean( *this, EAiProfileActiveProfileIcon, 2 );
       
   253             // uncomment also this and respective policy lines in profiles.xml if whole widget needs to be hidden in AI3 
       
   254     		//observer->Clean( *this, EAiProfileContentActiveProfileName, EAiProfileContentActiveProfileName );        		    		
       
   255     		}
       
   256         if ( err == KErrNone )
       
   257             {
       
   258             err = observer->Commit( transactionId );
       
   259             
       
   260             if ( err == KErrNotSupported)
       
   261                 {
       
   262                 return;
       
   263                 }
       
   264             }
       
   265         
       
   266         iIsUpdated = EFalse;
       
   267         }
       
   268     iPreviousCount = iCurrentCount;
       
   269     }
       
   270     
       
   271 // ---------------------------------------------------------------------------
       
   272 // From class CAiContentPublisher
       
   273 // Plug-in is requested to unload its engines due backup operation
       
   274 // ---------------------------------------------------------------------------
       
   275 //
       
   276 void CAiProfilePlugin::Stop( TAiTransitionReason /*aReason*/ )
       
   277     {
       
   278     FreeEngine();
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // From class CAiContentPublisher
       
   283 // Plug-in is instructed that it is allowed to consume CPU resources
       
   284 // ---------------------------------------------------------------------------
       
   285 //
       
   286 void CAiProfilePlugin::Resume( TAiTransitionReason aReason )
       
   287     {
       
   288     TRAP_IGNORE( DoResumeL( aReason ) ); 
       
   289     }
       
   290     
       
   291 // ---------------------------------------------------------------------------
       
   292 // From class CAiContentPublisher
       
   293 // Plug-in is instructed that it is not allowed to consume CPU resources
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 void CAiProfilePlugin::Suspend( TAiTransitionReason /*aReason*/ )
       
   297     {
       
   298     if ( iEngine && iAlive )
       
   299         {
       
   300         iEngine->Suspend();
       
   301         }
       
   302         
       
   303     iAlive = EFalse;
       
   304     }
       
   305 
       
   306 // ---------------------------------------------------------------------------
       
   307 // From class CAiContentPublisher
       
   308 // The plug-in MUST maintain a registry of subscribers and send 
       
   309 // notification to all of them whenever the state changes or new content
       
   310 // is available
       
   311 // ---------------------------------------------------------------------------
       
   312 //
       
   313 void CAiProfilePlugin::SubscribeL( MAiContentObserver& aObserver )
       
   314     { 
       
   315     iObservers.AppendL( &aObserver );
       
   316     }
       
   317     
       
   318 // ---------------------------------------------------------------------------
       
   319 // From class CAiContentPublisher
       
   320 // Plug-ins take ownership of the settings array, so it must either
       
   321 // store it in a member or free it.
       
   322 // ---------------------------------------------------------------------------
       
   323 //
       
   324 void CAiProfilePlugin::ConfigureL( RAiSettingsItemArray& aSettings )
       
   325     {
       
   326     aSettings.ResetAndDestroy();
       
   327     }
       
   328 
       
   329 // ---------------------------------------------------------------------------
       
   330 // From class CAiContentPublisher
       
   331 // Returns the extension interface. Actual type depends on the passed 
       
   332 // aUid argument.
       
   333 // ---------------------------------------------------------------------------
       
   334 //
       
   335 TAny* CAiProfilePlugin::Extension( TUid aUid )
       
   336     {    
       
   337     if (aUid == KExtensionUidProperty)
       
   338    		{
       
   339         return static_cast<MAiPropertyExtension*>(this);
       
   340     	}
       
   341     else if (aUid == KExtensionUidEventHandler)
       
   342     	{
       
   343         return static_cast<MAiEventHandlerExtension*>(this);
       
   344     	}
       
   345     else
       
   346     	{	
       
   347         return NULL;
       
   348     	}
       
   349     }
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // From class MAiPropertyExtension
       
   353 // Read property of publisher plug-in.
       
   354 // ---------------------------------------------------------------------------
       
   355 //
       
   356 TAny* CAiProfilePlugin::GetPropertyL( TInt aProperty )
       
   357     {
       
   358     TAny* property = NULL;
       
   359     
       
   360     switch ( aProperty )
       
   361         {
       
   362     case EAiPublisherInfo:
       
   363         {
       
   364          property = static_cast<TAiPublisherInfo*>( &iInfo );
       
   365         break;  
       
   366         }       
       
   367 
       
   368     case EAiPublisherContent:
       
   369         {
       
   370         property = static_cast<MAiContentItemIterator*>( iContent );
       
   371         break;    
       
   372         }        
       
   373 
       
   374     case EAiPublisherEvents:
       
   375         {
       
   376         property = static_cast<MAiContentItemIterator*>( iEvents );
       
   377         break;
       
   378         }
       
   379     
       
   380     case EAiPublisherResources:
       
   381         property = static_cast<MAiContentItemIterator*>( iResources );
       
   382         break;
       
   383        
       
   384     default:
       
   385         break;
       
   386         }
       
   387 
       
   388     return property;
       
   389     }
       
   390 
       
   391 // ---------------------------------------------------------------------------
       
   392 // From class MAiPropertyExtension
       
   393 // Write property value to optimize the content model.
       
   394 // ---------------------------------------------------------------------------
       
   395 //
       
   396 void CAiProfilePlugin::SetPropertyL( TInt aProperty, TAny* aValue )
       
   397     {  
       
   398     if( aProperty == EAiPublisherInfo )
       
   399         {
       
   400         ASSERT( aValue );
       
   401         
       
   402         const TAiPublisherInfo* info( 
       
   403                 static_cast<const TAiPublisherInfo*>( aValue ) );
       
   404         
       
   405         iInfo = *info;
       
   406         }
       
   407     }
       
   408  
       
   409 // ---------------------------------------------------------------------------
       
   410 // From class MAiEventHandlerExtension.
       
   411 // Handles an event sent by the AI framework.
       
   412 // ---------------------------------------------------------------------------
       
   413 //
       
   414 void CAiProfilePlugin::HandleEvent(TInt aEvent, const TDesC& aParam)
       
   415 	{
       
   416     if ( iEngine )
       
   417     	{
       
   418         // We have no way of reporting errors to framework so just ignore them.
       
   419         TRAP_IGNORE( iEngine->HandleAiEventL( aEvent, aParam ) );
       
   420     	}
       
   421 	} 
       
   422     
       
   423 // ---------------------------------------------------------
       
   424 // This method is called from the engine, when the profile
       
   425 // data content has been changed. Method call is made through
       
   426 // the MAiProfilePluginNotifier interface.
       
   427 // ---------------------------------------------------------
       
   428 //
       
   429 void CAiProfilePlugin::NotifyContentUpdate()
       
   430     {
       
   431     iIsUpdated = ETrue;
       
   432     
       
   433     TRAP_IGNORE( PublishL() );
       
   434     }
       
   435 
       
   436 // ---------------------------------------------------------------------------
       
   437 // From class CAiContentPublisher
       
   438 // framework instructs plug-in that it is allowed to consume CPU resources
       
   439 // ---------------------------------------------------------------------------
       
   440 //
       
   441 void CAiProfilePlugin::DoResumeL( TAiTransitionReason aReason )
       
   442     {
       
   443     if ( !iEngine )
       
   444         {
       
   445         iEngine = CAiProfileEngine::NewL( this );
       
   446         }
       
   447     
       
   448 	//update in startup phase and idle is on foreground.
       
   449     if( aReason != EAiBacklightOff && aReason != EAiIdleBackground )
       
   450     	{
       
   451     	// force republish in case layout has changed
       
   452       if ( aReason == EAiScreenLayoutChanged )
       
   453           {
       
   454           delete iPreviousProfileNameAndChar;
       
   455           iPreviousProfileNameAndChar = NULL;
       
   456           }
       
   457 
       
   458     	if ( !iAlive )
       
   459     	    {
       
   460             iEngine->ResumeL();
       
   461     	    }
       
   462     	
       
   463 	    iEngine->UpdateProfileNamesL();
       
   464 	    
       
   465         PublishL();
       
   466 	    iAlive = ETrue;     
       
   467     	}   
       
   468     }
       
   469     
       
   470 // ---------------------------------------------------------------------------
       
   471 // Frees engine resources
       
   472 // ---------------------------------------------------------------------------
       
   473 //    
       
   474 void CAiProfilePlugin::FreeEngine()
       
   475     {
       
   476     delete iEngine;
       
   477     iEngine = NULL;
       
   478     iAlive = EFalse;   
       
   479     }
       
   480 
       
   481 // ---------------------------------------------------------------------------
       
   482 // Clean profile names from content
       
   483 // ---------------------------------------------------------------------------
       
   484 //    
       
   485 void CAiProfilePlugin::CleanPublishedProfileNames()
       
   486     {
       
   487     TInt obsCount( iObservers.Count() );
       
   488     for ( TInt i( 0 ); i < obsCount; i++ )
       
   489         {
       
   490         MAiContentObserver* observer = iObservers[i];
       
   491         for( TInt j( 0 ); j < iCurrentCount && observer; j++ )
       
   492             {
       
   493             observer->Clean( *this, EAiProfileContentProfileName, j + 1 );
       
   494             }
       
   495         }
       
   496     }
       
   497 
       
   498 // ======== GLOBAL FUNCTIONS ========
       
   499 // ---------------------------------------------------------------------------
       
   500 // Constructs and returns an application object.
       
   501 // ---------------------------------------------------------------------------
       
   502 //
       
   503 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( 
       
   504     TInt& aTableCount )
       
   505     {
       
   506     aTableCount = sizeof( KImplementationTable ) / 
       
   507         sizeof( TImplementationProxy );
       
   508     return KImplementationTable;
       
   509     }