idlefw/plugins/wrtdataplugin/src/wrtdataplugin.cpp
branchRCL_3
changeset 114 a5a39a295112
child 118 8baec10861af
equal deleted inserted replaced
113:0efa10d348c0 114:a5a39a295112
       
     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: WRT data plug-in publisher
       
    15 * 
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <ecom/ecom.h>
       
    20 #include <ecom/implementationproxy.h>
       
    21 #include <PUAcodes.hrh>
       
    22 #include <badesca.h>
       
    23 #include <fbs.h>
       
    24 #include <gulicon.h>
       
    25 #include <AknsSkinInstance.h> 
       
    26 #include <AknsUtils.h> 
       
    27 #include <AknsConstants.h>
       
    28 #include <e32property.h>
       
    29 
       
    30 // User includes
       
    31 #include <hspublisherinfo.h>
       
    32 #include <aicontentobserver.h>
       
    33 #include <aiutility.h>
       
    34 #include <aipspropertyobserver.h>
       
    35 #include <aipluginsettings.h>
       
    36 #include <activeidle2domainpskeys.h>
       
    37 #include <debug.h>
       
    38 
       
    39 #include "wrtdatapluginconst.h"
       
    40 #include "wrtdatapluginuids.hrh"
       
    41 #include "wrtdataplugin.h"
       
    42 #include "wrtdata.h"
       
    43 
       
    44 // Constants
       
    45 const TImplementationProxy KImplementationTable[] =
       
    46     {
       
    47     IMPLEMENTATION_PROXY_ENTRY( KImplUidDataPlugin, CWrtDataPlugin::NewL ) 
       
    48     };
       
    49 
       
    50 const TInt KTryAgainDelay( 3000000 ); // 3 sec
       
    51 
       
    52 // ======== MEMBER FUNCTIONS ========
       
    53 // ---------------------------------------------------------------------------
       
    54 // ImplementationGroupProxy
       
    55 //
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( 
       
    59     TInt& aTableCount )
       
    60     {
       
    61     aTableCount = sizeof( KImplementationTable ) /
       
    62         sizeof( TImplementationProxy );
       
    63     return KImplementationTable;
       
    64     }
       
    65 
       
    66 // ======== MEMBER FUNCTIONS ========
       
    67 // ----------------------------------------------------------------------------
       
    68 // CWrtDataPlugin::NewL()
       
    69 //
       
    70 // ----------------------------------------------------------------------------
       
    71 //
       
    72 CWrtDataPlugin* CWrtDataPlugin::NewL()
       
    73     {
       
    74     CWrtDataPlugin* self = new (ELeave) CWrtDataPlugin;
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     CleanupStack::Pop( self );
       
    78     return self;
       
    79     }
       
    80     
       
    81 // ----------------------------------------------------------------------------
       
    82 // CWrtDataPlugin::CWrtDataPlugin()
       
    83 //
       
    84 // ----------------------------------------------------------------------------
       
    85 //
       
    86 CWrtDataPlugin::CWrtDataPlugin()
       
    87     : iNetworkStatus( EUnknown ), iPluginState( EStopped ) 
       
    88     {
       
    89     }
       
    90     
       
    91 // ----------------------------------------------------------------------------
       
    92 // CWrtDataPlugin::ConstructL()
       
    93 //
       
    94 // ----------------------------------------------------------------------------
       
    95 //
       
    96 void CWrtDataPlugin::ConstructL()
       
    97     {
       
    98     User::LeaveIfError( iRfs.Connect() );
       
    99     
       
   100     iData = CWrtData::NewL( this );
       
   101     }
       
   102     
       
   103 // ---------------------------------------------------------------------------
       
   104 // Destructor
       
   105 // Deletes all data created to heap
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 CWrtDataPlugin::~CWrtDataPlugin()
       
   109     {
       
   110     if ( iTimer )
       
   111         {
       
   112         iTimer->Cancel();
       
   113         delete iTimer;
       
   114         }
       
   115 
       
   116     delete iData;
       
   117     iObservers.Close();
       
   118     Release( iContent );
       
   119     iDataArray.ResetAndDestroy();
       
   120 
       
   121     if( iContentModel)
       
   122         {
       
   123         for( TInt i = iDataCount-1;i>=0  ; i-- )
       
   124             {
       
   125             User::Free((TAny*)iContentModel[i].cid);   
       
   126             }
       
   127         delete []iContentModel;
       
   128         }
       
   129     iIconArray.Reset();
       
   130     
       
   131     iRfs.Close();
       
   132     }
       
   133 
       
   134 // ----------------------------------------------------------------------------
       
   135 // CWrtDataPlugin::Start
       
   136 //
       
   137 // ----------------------------------------------------------------------------
       
   138 //
       
   139 void CWrtDataPlugin::Start( TStartReason aReason )
       
   140     {
       
   141     iPluginState = EStarted;
       
   142     
       
   143     if( aReason == ESystemStartup || 
       
   144         aReason == EPluginStartup )
       
   145         {
       
   146         // Publish the initial data
       
   147         TRAP_IGNORE( PublishInitialDataL() );
       
   148         }
       
   149     }
       
   150 
       
   151 // ----------------------------------------------------------------------------
       
   152 // CWrtDataPlugin::Stop
       
   153 //
       
   154 // ----------------------------------------------------------------------------
       
   155 //
       
   156 void CWrtDataPlugin::Stop( TStopReason aReason )
       
   157     {
       
   158     iPluginState = EStopped;
       
   159     
       
   160     if( aReason == EPluginShutdown ||
       
   161         aReason == ESystemShutdown )
       
   162         {
       
   163         TRAP_IGNORE(iData->NotifyPublisherL( KDeActive ));
       
   164         }
       
   165     }
       
   166 
       
   167 // ----------------------------------------------------------------------------
       
   168 // CWrtDataPlugin::Resume
       
   169 //
       
   170 // ----------------------------------------------------------------------------
       
   171 //
       
   172 void CWrtDataPlugin::Resume( TResumeReason aReason )
       
   173     {
       
   174     if ( aReason == EForeground && iPluginState != EStopped )
       
   175         {
       
   176         iPluginState = EResume;
       
   177 
       
   178         TRAP_IGNORE( iData->NotifyPublisherL( KResume ));        
       
   179         }    
       
   180     }
       
   181 
       
   182 // ----------------------------------------------------------------------------
       
   183 // CWrtDataPlugin::Suspend
       
   184 //
       
   185 // ----------------------------------------------------------------------------
       
   186 //
       
   187 void CWrtDataPlugin::Suspend( TSuspendReason aReason )
       
   188     {    
       
   189     if ( aReason == EBackground && iPluginState != EStopped )
       
   190         {
       
   191         iPluginState = ESuspend;
       
   192         
       
   193         TRAP_IGNORE ( iData->NotifyPublisherL( KSuspend ));        
       
   194         }        
       
   195     }
       
   196 
       
   197 // ----------------------------------------------------------------------------
       
   198 // CWrtDataPlugin::SetOnline
       
   199 //
       
   200 // ----------------------------------------------------------------------------
       
   201 //
       
   202 void CWrtDataPlugin::SetOnline()
       
   203     {    
       
   204     if ( iPluginState != EStopped )
       
   205         {
       
   206         iNetworkStatus = EOnline;
       
   207         TRAP_IGNORE( iData->NotifyPublisherL( KOnLine ));                
       
   208         }
       
   209     }
       
   210 
       
   211 // ----------------------------------------------------------------------------
       
   212 // CWrtDataPlugin::SetOffline
       
   213 //
       
   214 // ----------------------------------------------------------------------------
       
   215 //
       
   216 void CWrtDataPlugin::SetOffline()
       
   217     {
       
   218     if ( iPluginState != EStopped )
       
   219         {   
       
   220         iNetworkStatus = EOffline;
       
   221         TRAP_IGNORE( iData->NotifyPublisherL( KOffLine ));
       
   222         }
       
   223     }
       
   224 
       
   225 // ----------------------------------------------------------------------------
       
   226 // CWrtDataPlugin::SubscribeL
       
   227 //
       
   228 // ----------------------------------------------------------------------------
       
   229 //
       
   230 void CWrtDataPlugin::SubscribeL( MAiContentObserver& aObserver )
       
   231     {
       
   232     iObservers.AppendL( &aObserver );
       
   233     }
       
   234 
       
   235 // ----------------------------------------------------------------------------
       
   236 // CWrtDataPlugin::ConfigureL
       
   237 //
       
   238 // ----------------------------------------------------------------------------
       
   239 //
       
   240 void CWrtDataPlugin::ConfigureL( RAiSettingsItemArray& aSettings )
       
   241     {
       
   242     RAiSettingsItemArray contentItemsArr;
       
   243     RAiSettingsItemArray configurationItemsArr;
       
   244     TInt count( aSettings.Count() );
       
   245     
       
   246     for ( TInt i = 0; i < count; i++ )
       
   247         {
       
   248         MAiPluginSettings* setting( aSettings[i] );
       
   249         
       
   250         if( setting->AiPluginItemType() == EAiPluginContentItem )
       
   251             {
       
   252             contentItemsArr.Append( setting );
       
   253             }
       
   254         else if( setting->AiPluginItemType() == EAiPluginConfigurationItem )
       
   255             {
       
   256             configurationItemsArr.Append( setting );
       
   257             }
       
   258         }
       
   259     
       
   260     iDataCount = contentItemsArr.Count();
       
   261  
       
   262     // Create the content Model
       
   263     HBufC16* contentId = HBufC16::NewLC( 
       
   264         KAiContentIdMaxLength + KAiPluginNameMaxLength );
       
   265     
       
   266     iContentModel = new TAiContentItem[iDataCount];
       
   267     
       
   268     for( TInt i = 0; i < iDataCount; i++ )
       
   269         {
       
   270         MAiPluginContentItem& contentItem( 
       
   271             contentItemsArr[i]->AiPluginContentItem() );
       
   272         
       
   273         iContentModel[i].id = i;
       
   274         if( contentItem.Type() == KText() )
       
   275             {
       
   276             // text
       
   277             iContentModel[i].type = KAiContentTypeText;
       
   278             }
       
   279         if( contentItem.Type() == KImage() || 
       
   280             contentItem.Type() == KAnimation() )
       
   281             {
       
   282             // image
       
   283             iContentModel[i].type = KAiContentTypeBitmap;
       
   284             }
       
   285         
       
   286         contentId->Des().Copy( contentItem.Name() );
       
   287         contentId->Des().Delete( 0, 
       
   288             contentId->Des().LocateReverse( KPluginNameSeprator ) + 1 );
       
   289 
       
   290         TInt sizeOfContentId( contentId->Des().Size()+sizeof( wchar_t ) );
       
   291         
       
   292         iContentModel[i].cid = 
       
   293             static_cast< const wchar_t* >( User::Alloc( sizeOfContentId ) );
       
   294             
       
   295         Mem::Copy( ( TAny* )iContentModel[i].cid, 
       
   296             contentId->Des().PtrZ(), sizeOfContentId );
       
   297         
       
   298         contentId->Des().Delete( 0, contentId->Des().Length() );
       
   299         }    
       
   300     
       
   301     CleanupStack::PopAndDestroy( contentId );
       
   302     iContent = AiUtility::CreateContentItemArrayIteratorL( 
       
   303             iContentModel, iDataCount );
       
   304                    
       
   305     // Configurations 
       
   306     iData->ConfigureL( configurationItemsArr );
       
   307 
       
   308     // Register for notifications
       
   309     iData->RegisterL();
       
   310     
       
   311     // Activate the publisher 
       
   312     iData->NotifyPublisherL( KActive );
       
   313     
       
   314     contentItemsArr.Reset();
       
   315     configurationItemsArr.Reset();
       
   316     // We own the array so destroy it
       
   317     aSettings.ResetAndDestroy();
       
   318     }
       
   319 
       
   320 // ----------------------------------------------------------------------------
       
   321 // CWrtDataPlugin::SetProperty
       
   322 //
       
   323 // ----------------------------------------------------------------------------
       
   324 //
       
   325 void CWrtDataPlugin::SetProperty( TProperty aProperty, TAny* aAny )
       
   326     {
       
   327     if (aProperty == ECpsCmdBuffer )
       
   328         {   
       
   329         iData->SetCommandBuffer( aAny, PublisherInfo().Namespace() );
       
   330         }
       
   331     }
       
   332 
       
   333 // ----------------------------------------------------------------------------
       
   334 // CWrtDataPlugin::GetProperty
       
   335 //
       
   336 // ----------------------------------------------------------------------------
       
   337 //
       
   338 TAny* CWrtDataPlugin::GetProperty( TProperty aProperty )
       
   339     {
       
   340     if ( aProperty == EPublisherContent )
       
   341         {
       
   342         return static_cast< MAiContentItemIterator* >( iContent );      
       
   343         }
       
   344     
       
   345     return NULL;
       
   346     }
       
   347 
       
   348 // ----------------------------------------------------------------------------
       
   349 // CWrtDataPlugin::HandleEvent
       
   350 //
       
   351 // ----------------------------------------------------------------------------
       
   352 //
       
   353 void CWrtDataPlugin::HandleEvent( const TDesC& aEventName, 
       
   354     const TDesC& aParam )
       
   355     {
       
   356     TRAP_IGNORE( iData->ExecuteActionL( aEventName , aParam ) );    
       
   357     }
       
   358 
       
   359 // ----------------------------------------------------------------------------
       
   360 // CWrtDataPlugin::IsActive
       
   361 //
       
   362 // ----------------------------------------------------------------------------
       
   363 //
       
   364 TBool CWrtDataPlugin::IsActive() const
       
   365     {
       
   366     return iPluginState == EResume;
       
   367     }
       
   368 
       
   369 // ----------------------------------------------------------------------------
       
   370 // CWrtDataPlugin::IsStopped
       
   371 //
       
   372 // ----------------------------------------------------------------------------
       
   373 //
       
   374 TBool CWrtDataPlugin::IsStopped() const
       
   375     {
       
   376     return iPluginState == EStopped;
       
   377     }
       
   378 
       
   379 // ----------------------------------------------------------------------------
       
   380 // CWrtDataPlugin::Data
       
   381 //
       
   382 // ----------------------------------------------------------------------------
       
   383 //
       
   384 CWrtData* CWrtDataPlugin::Data() const
       
   385     {
       
   386     return iData;
       
   387     }
       
   388 
       
   389 // ----------------------------------------------------------------------------
       
   390 // CWrtDataPlugin::NetworkStatus
       
   391 //
       
   392 // ----------------------------------------------------------------------------
       
   393 //
       
   394 CWrtDataPlugin::TPluginNetworkStatus CWrtDataPlugin::NetworkStatus() const
       
   395     {
       
   396     return iNetworkStatus;
       
   397     }
       
   398 
       
   399 // ---------------------------------------------------------------------------
       
   400 // CWrtDataPlugin::GetIdL
       
   401 // Gets the id of a content  
       
   402 // ---------------------------------------------------------------------------
       
   403 //
       
   404 TInt CWrtDataPlugin::GetIdL( TDesC16& aObjectId)
       
   405     {
       
   406     TInt id = KErrNotFound;
       
   407     HBufC16* objectId = HBufC16::NewLC( KAiContentIdMaxLength );
       
   408     for( TInt i = 0;i<  iDataCount; i++ )
       
   409         {
       
   410          objectId->Des().Copy((TUint16*)iContentModel[i].cid);
       
   411          if( aObjectId == objectId->Des() )
       
   412              {
       
   413              id = iContentModel[i].id;
       
   414              break;
       
   415              }
       
   416         }
       
   417     CleanupStack::PopAndDestroy( objectId );
       
   418     return id;
       
   419     }
       
   420  
       
   421 
       
   422 // ---------------------------------------------------------------------------
       
   423 // CWrtDataPlugin::GetTypeL
       
   424 // Gets type of a content
       
   425 // ---------------------------------------------------------------------------
       
   426 //
       
   427 void CWrtDataPlugin::GetTypeL(TDesC16& aObjectId, TDes16& aType )
       
   428     {
       
   429     HBufC16* objectId = HBufC16::NewLC( KAiContentIdMaxLength );
       
   430     for( TInt i = 0;i<  iDataCount; i++ )
       
   431         {
       
   432         objectId->Des().Copy((TUint16*)iContentModel[i].cid);
       
   433          if( aObjectId == objectId->Des() )
       
   434              {
       
   435              if( iContentModel[i].type ==  KAiContentTypeText)
       
   436                  {
       
   437                  aType.Copy( KText );
       
   438                  }
       
   439              else if( iContentModel[i].type == KAiContentTypeBitmap)
       
   440                  {
       
   441                  aType.Copy( KImage );
       
   442                  }
       
   443              break;
       
   444              }
       
   445         }
       
   446     CleanupStack::PopAndDestroy( objectId );
       
   447     }
       
   448 
       
   449 // ---------------------------------------------------------------------------
       
   450 //Refresh a specific image or text in the widget
       
   451 // ---------------------------------------------------------------------------
       
   452 //
       
   453 void CWrtDataPlugin::RefreshL( TDesC16& aOperation, CLiwDefaultMap* aDataMap )
       
   454     {
       
   455     __PRINTS("*** CWrtDataPlugin::RefreshL ***");
       
   456     
       
   457     __PRINT( __DBG_FORMAT( "* Publisher name: %S, uid: 0x%x, operation: %S" ),          
       
   458         &PublisherInfo().Name(), PublisherInfo().Uid().iUid, &aOperation ); 
       
   459     
       
   460     TInt observers( iObservers.Count() );        
       
   461     TInt transactionId = reinterpret_cast<TInt>( this );
       
   462     
       
   463     for ( TInt obsIndex = 0; obsIndex < observers; obsIndex++ )
       
   464         {
       
   465         MAiContentObserver* observer = iObservers[obsIndex];
       
   466  
       
   467         if ( observer->StartTransaction( transactionId ) == KErrNone )       
       
   468             {
       
   469             if( ( aOperation == KOperationUpdate 
       
   470                   || aOperation == KOperationAdd )
       
   471                   && aDataMap )
       
   472                 {
       
   473                 iData->PublishL( observer, aDataMap );
       
   474                 }
       
   475             else if ( aOperation == KOperationDelete )
       
   476                 {
       
   477                 Clean( observer , EImage1 ) ;
       
   478                 }
       
   479             
       
   480             observer->Commit( transactionId );
       
   481             }
       
   482      
       
   483         // Relese memory of the published text
       
   484         iDataArray.ResetAndDestroy();
       
   485         // Release memory of the published icons
       
   486         iIconArray.Reset();
       
   487         }
       
   488     
       
   489     __PRINTS("*** CWrtDataPlugin::RefreshL - done ***");        
       
   490     }
       
   491 
       
   492 // ---------------------------------------------------------------------------
       
   493 // Publish a specific text of the widget  
       
   494 // ---------------------------------------------------------------------------
       
   495 //
       
   496 void CWrtDataPlugin::PublishTextL(MAiContentObserver* aObserver, 
       
   497         TInt aContentId, const TDesC16& aContentValue)
       
   498     {
       
   499     if ( aObserver->CanPublish( *this,  aContentId  ,  aContentId  ) )
       
   500         {
       
   501         if( aContentValue.Length() > 0 )
       
   502             {
       
   503             HBufC* contentText = HBufC::NewLC(aContentValue.Size());
       
   504             TPtr16 cDes = contentText->Des();
       
   505             cDes.Copy(aContentValue);
       
   506             aObserver->Publish( *this, aContentId, cDes, aContentId );  
       
   507             iDataArray.AppendL( contentText );
       
   508             CleanupStack::Pop( contentText );
       
   509             }
       
   510         else
       
   511             {
       
   512             aObserver->Clean( *this, aContentId, aContentId );
       
   513             }
       
   514         }
       
   515     }
       
   516 
       
   517 // ---------------------------------------------------------------------------
       
   518 // Publish a specific image of the widget  
       
   519 // ---------------------------------------------------------------------------
       
   520 //
       
   521 void CWrtDataPlugin::PublishImageL(MAiContentObserver* aObserver,
       
   522 		TContentItem aContentId, const TDesC16& aPath )
       
   523     {
       
   524     TInt err = KErrNone;
       
   525     TAknsItemID iconId;
       
   526     iconId.iMajor=0;
       
   527     iconId.iMinor=0;
       
   528     TInt bitmapId(0);
       
   529     TInt maskId(0);
       
   530     TFileName fileName;
       
   531     CGulIcon* icon = NULL;
       
   532     CFbsBitmap* bitmap = NULL;
       
   533     CFbsBitmap* mask = NULL;
       
   534     
       
   535     if ( aObserver->CanPublish( *this, aContentId , aContentId ) )
       
   536       {
       
   537       TBool inSkin = ResolveSkinIdAndMifId( aPath, iconId, bitmapId, maskId, fileName  );
       
   538       if ( inSkin )
       
   539           {
       
   540           // Load from skin 
       
   541           MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   542           if ( iconId.iMajor != 0 && iconId.iMajor!=0 )
       
   543               {
       
   544               // Create icon with fall back 
       
   545               TRAP_IGNORE(AknsUtils::CreateIconL(
       
   546                       skin,
       
   547                       iconId,
       
   548                       bitmap,
       
   549                       mask,
       
   550                       fileName,  /* backup filename */
       
   551                       bitmapId,  /* backup bit map id */
       
   552                       maskId));   /* backup mask id */
       
   553               }
       
   554           else if( bitmapId !=0 )
       
   555               {
       
   556               if ( maskId!=0 )
       
   557                   {
       
   558                   // Create icon from Mif filename , bitmap id and mask id
       
   559                   TRAP_IGNORE(icon = AknsUtils::CreateGulIconL(
       
   560                           skin,
       
   561                           iconId,
       
   562                           fileName,
       
   563                           bitmapId,
       
   564                           maskId) );
       
   565                   }
       
   566               else
       
   567                   {
       
   568                   TRAP_IGNORE(AknsUtils::CreateIconL(
       
   569                           skin,
       
   570                           iconId,
       
   571                           bitmap,
       
   572                           fileName,  /* backup filename */
       
   573                           bitmapId)); /* backup bit map id */
       
   574                   }
       
   575               }
       
   576           
       
   577           if ( icon == NULL && bitmap !=  NULL )
       
   578               {
       
   579               icon = CGulIcon::NewL( bitmap, mask );
       
   580               }
       
   581 
       
   582           if ( icon != NULL ) // Syntax correct but icon not found
       
   583               {
       
   584               aObserver->PublishPtr( *this, aContentId, icon , aContentId );
       
   585               iIconArray.Append(icon);
       
   586               } 
       
   587           else
       
   588               {
       
   589               err = KErrNotFound;   
       
   590               aObserver->Clean( *this, aContentId, aContentId );
       
   591               }
       
   592           }
       
   593       else  // Interpret as File path
       
   594           {                   
       
   595           RFile iconFile;
       
   596           
       
   597           err = iconFile.Open( iRfs, aPath, EFileShareReadersOnly |  EFileRead );
       
   598           
       
   599           if( err == KErrNone )
       
   600             {
       
   601              aObserver->Publish( *this, aContentId, iconFile, aContentId );
       
   602             }
       
   603           else
       
   604               {
       
   605               aObserver->Clean( *this, aContentId, aContentId );
       
   606               }
       
   607           
       
   608           iconFile.Close();
       
   609           }
       
   610         }
       
   611     }
       
   612 
       
   613 // ---------------------------------------------------------------------------
       
   614 // Publish a image of the widget  
       
   615 // ---------------------------------------------------------------------------
       
   616 //
       
   617 void CWrtDataPlugin::PublishImageL(MAiContentObserver* aObserver, 
       
   618 		TContentItem aContentId, TInt aHandle, TInt aMaskHandle )
       
   619     {
       
   620     if ( aObserver->CanPublish( *this, aContentId , aContentId ) )
       
   621         {
       
   622         if( aHandle != KErrBadHandle  )
       
   623             {
       
   624             CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
       
   625             if( KErrNone == bitmap->Duplicate( aHandle) )
       
   626                 {
       
   627                 // Take the ownership
       
   628                 CGulIcon* icon = CGulIcon::NewL(bitmap);
       
   629                 if( aMaskHandle != KErrBadHandle )
       
   630                     {
       
   631                     CFbsBitmap* mask = new (ELeave) CFbsBitmap();
       
   632                     if (KErrNone == mask->Duplicate( aMaskHandle) )
       
   633                         {
       
   634                         icon->SetMask( mask );            
       
   635                         }
       
   636                     }
       
   637                 aObserver->PublishPtr( *this, aContentId, icon , aContentId );
       
   638                 iIconArray.Append(icon);
       
   639                 }
       
   640             else
       
   641                 {
       
   642                 delete bitmap;
       
   643                 bitmap = NULL;
       
   644                 aObserver->Clean( *this, aContentId, aContentId );
       
   645                 }
       
   646             }
       
   647           }
       
   648     }
       
   649 
       
   650 // ---------------------------------------------------------------------------
       
   651 // Cleans a data from the widget
       
   652 // ---------------------------------------------------------------------------
       
   653 //
       
   654 void CWrtDataPlugin::Clean(MAiContentObserver* aObserver, 
       
   655         TInt aContentId )
       
   656     {
       
   657      if ( aObserver->CanPublish( *this, aContentId, aContentId ) )
       
   658         {
       
   659         aObserver->Clean( *this, aContentId, aContentId );      
       
   660         }
       
   661 
       
   662     }
       
   663 
       
   664 // ---------------------------------------------------------------------------
       
   665 // Show the loading icong animation 
       
   666 // ---------------------------------------------------------------------------
       
   667 //
       
   668 void CWrtDataPlugin::ShowLoadingIcon(MAiContentObserver* aObserver)
       
   669     {
       
   670     aObserver->SetProperty( *this, KElement , KDisplay , KShow );
       
   671     }
       
   672 
       
   673 // ---------------------------------------------------------------------------
       
   674 // Hides the loading icon animation 
       
   675 // ---------------------------------------------------------------------------
       
   676 //
       
   677 void CWrtDataPlugin::HideLoadingIcon(MAiContentObserver* aObserver)
       
   678     {
       
   679     aObserver->SetProperty( *this, KElement , KDisplay , KHide );
       
   680 
       
   681     // Do not try to publish initial data anymore
       
   682     StopTimer();
       
   683     }
       
   684 
       
   685 // ---------------------------------------------------------------------------
       
   686 // Publishes widget's texts and images
       
   687 // ---------------------------------------------------------------------------
       
   688 //
       
   689 void CWrtDataPlugin::PublishInitialDataL()
       
   690     {
       
   691     TInt observers( iObservers.Count() );        
       
   692     TInt transactionId = reinterpret_cast<TInt>( this );
       
   693 
       
   694     for ( int i = 0; i < observers; i++ )
       
   695         {
       
   696         MAiContentObserver* observer = iObservers[i];
       
   697 
       
   698         CleanupStack::PushL( TCleanupItem( CancelTransaction, observer ) );
       
   699 
       
   700         if ( observer->StartTransaction( transactionId ) == KErrNone )           
       
   701             {// Publish default data
       
   702             iData->PublishInitialDataL(observer);
       
   703             observer->Commit( transactionId );
       
   704             }
       
   705 
       
   706 		CleanupStack::Pop( observer );
       
   707 
       
   708         // Release memory of the published text
       
   709         iDataArray.ResetAndDestroy();
       
   710         // Release memory of the published icons
       
   711         iIconArray.Reset();
       
   712         }
       
   713 
       
   714     }
       
   715 
       
   716 // ---------------------------------------------------------------------------
       
   717 // ResolveSkinItemId
       
   718 // ---------------------------------------------------------------------------
       
   719 //
       
   720 TBool CWrtDataPlugin::ResolveSkinIdAndMifId( const TDesC& aPath, TAknsItemID& aItemId,
       
   721         TInt& abitmapId, TInt& aMaskId, TDes& aFilename )
       
   722    {
       
   723    // Syntax: skin( <major> <minor> ):mif(filename bimapId maskId) 
       
   724    TInt error = KErrNotFound;
       
   725    TInt pos = aPath.FindF( KSkin );
       
   726    if( pos != KErrNotFound )
       
   727        {
       
   728        // Skip skin token
       
   729        pos += KSkin().Length();
       
   730        
       
   731        // Initialize lexer
       
   732       TLex lex( aPath.Mid( pos ) );
       
   733       lex.SkipSpace();
       
   734        
       
   735        // Check left parenthesis
       
   736       if (lex.Get() == KLeftParenthesis )
       
   737            {
       
   738            //lex.SkipSpace();
       
   739            
       
   740            TInt majorId( 0 );        
       
   741            TInt minorId( 0 );
       
   742 
       
   743            // Resolve major id        
       
   744            error = lex.Val( majorId );
       
   745            
       
   746            // Resolve minor id
       
   747            lex.SkipSpace();
       
   748            error |= lex.Val( minorId );
       
   749            
       
   750            // initilize skin item id object
       
   751            aItemId.Set( majorId, minorId );
       
   752            }
       
   753        }
       
   754 
       
   755    if( (error == KErrNone && aPath.FindF( KColon ) != KErrNotFound ) 
       
   756          || ( error == KErrNotFound ) )
       
   757        {
       
   758        error = KErrNotFound;
       
   759        pos = aPath.FindF( KMif );
       
   760        if ( pos != KErrNotFound )
       
   761            {
       
   762            pos += KMif().Length();
       
   763            // Initialize lexer
       
   764            TLex lex( aPath.Mid( pos ) );
       
   765            lex.SkipSpace();
       
   766            
       
   767            // Check left parenthesis
       
   768            if (lex.Get() == KLeftParenthesis )
       
   769                {
       
   770                lex.SkipSpaceAndMark();
       
   771                lex.SkipCharacters();
       
   772                // Resolve MifFile name
       
   773                aFilename.Copy(lex.MarkedToken());
       
   774                if( aFilename.Length()!= 0)
       
   775                    {
       
   776                    // Resolve bitmap id  
       
   777                    lex.SkipSpace();
       
   778                    error = lex.Val( abitmapId );
       
   779                    
       
   780                    // Resolve mask id
       
   781                    // dont return error if it is not found, that is ok
       
   782                    lex.SkipSpace();
       
   783                    lex.Val( aMaskId );
       
   784                    }
       
   785                else
       
   786                    {
       
   787                    error = KErrNotFound;
       
   788                    }
       
   789                }
       
   790            }
       
   791        }
       
   792    return (error == KErrNone );
       
   793    }
       
   794 
       
   795 // ---------------------------------------------------------------------------
       
   796 // Cleanup callback for cancelling a transactions in case of leave
       
   797 // ---------------------------------------------------------------------------
       
   798 //
       
   799 void CWrtDataPlugin::CancelTransaction( TAny* aObserver )
       
   800     {
       
   801     if ( aObserver )
       
   802         {
       
   803         MAiContentObserver* obs = reinterpret_cast< MAiContentObserver*>( aObserver );
       
   804         TInt transactionId = reinterpret_cast<TInt>( aObserver );
       
   805         obs->CancelTransaction( transactionId );
       
   806         }
       
   807     }
       
   808 
       
   809 // ---------------------------------------------------------------------------
       
   810 // Create and start republish timer
       
   811 // ---------------------------------------------------------------------------
       
   812 //
       
   813 void CWrtDataPlugin::StartTimer()
       
   814     {
       
   815     TRAP_IGNORE(
       
   816         if ( !iTimer )
       
   817             {
       
   818             iTimer = CPeriodic::NewL( CActive::EPriorityStandard );
       
   819             }
       
   820         
       
   821         if ( iTimer && !iTimer->IsActive() )
       
   822             {
       
   823             TTimeIntervalMicroSeconds32 delay( KTryAgainDelay );
       
   824             iTimer->Start( delay, delay, TCallBack( Timeout, this ) );
       
   825             }
       
   826         );
       
   827     }
       
   828 
       
   829 // ---------------------------------------------------------------------------
       
   830 // Cancel republish timer
       
   831 // ---------------------------------------------------------------------------
       
   832 //
       
   833 void CWrtDataPlugin::CancelTimer()
       
   834     {
       
   835     if ( iTimer )
       
   836         {
       
   837         iTimer->Cancel();
       
   838         }
       
   839     }
       
   840 
       
   841 // ---------------------------------------------------------------------------
       
   842 // Stop and delete republish timer
       
   843 // ---------------------------------------------------------------------------
       
   844 //
       
   845 void CWrtDataPlugin::StopTimer()
       
   846     {
       
   847     if ( iTimer )
       
   848         {
       
   849         iTimer->Cancel();
       
   850         delete iTimer;
       
   851         iTimer = NULL;
       
   852         }
       
   853     }
       
   854 
       
   855 // ---------------------------------------------------------------------------
       
   856 // Initial data republish callback
       
   857 // ---------------------------------------------------------------------------
       
   858 //
       
   859 TInt CWrtDataPlugin::Timeout( TAny* aPtr )
       
   860     {
       
   861     CWrtDataPlugin* self = static_cast<CWrtDataPlugin*>( aPtr );
       
   862 
       
   863     // Cancel timer before publishing
       
   864     self->CancelTimer();
       
   865 
       
   866     TInt observers( self->iObservers.Count() );        
       
   867     TInt transactionId = reinterpret_cast<TInt>( self );
       
   868     TBool success( ETrue );
       
   869 
       
   870     // Publish for each observer
       
   871     for ( int i = 0; i < observers; i++ )
       
   872         {
       
   873         MAiContentObserver* observer = self->iObservers[i];
       
   874 
       
   875         if ( observer->StartTransaction( transactionId ) == KErrNone )           
       
   876             {
       
   877             // Publish default image
       
   878             TRAPD( err, self->iData->PublishDefaultImageL( observer ) );
       
   879             if ( KErrNone != err )
       
   880                 {
       
   881                 observer->CancelTransaction( transactionId );
       
   882                 success = EFalse;
       
   883                 }
       
   884             else
       
   885                 {
       
   886                 // 
       
   887                 observer->Commit( transactionId );
       
   888                 }
       
   889             }
       
   890         }
       
   891 
       
   892     // Start timer again if there is error in publishing
       
   893     if ( !success )
       
   894         {
       
   895         self->StartTimer();
       
   896         }
       
   897     else
       
   898         {
       
   899         self->StopTimer();
       
   900         }
       
   901 
       
   902     // Release memory of the published icons
       
   903     self->iIconArray.Reset();
       
   904 
       
   905     return KErrNone;
       
   906     }
       
   907 
       
   908 
       
   909 
       
   910 // End of file