homescreensrv_plat/hs_widget_publisher_api/src/hswidgetpublisherimpl.cpp
branchRCL_3
changeset 23 ace62b58f4b2
parent 19 edd621764147
child 27 2c7f27287390
equal deleted inserted replaced
22:1b207dd38b72 23:ace62b58f4b2
    94 		throw HsException( KErrNoMemory );
    94 		throw HsException( KErrNoMemory );
    95 		}
    95 		}
    96 	mWidgets.push_back( widget);
    96 	mWidgets.push_back( widget);
    97 	TInt err( KErrNone );
    97 	TInt err( KErrNone );
    98 	TRAP( err, 
    98 	TRAP( err, 
       
    99 	    RegisterNotificationL( *widget );
    99 		PublishWidgetActionsL( *widget );
   100 		PublishWidgetActionsL( *widget );
   100         RegisterNotificationL( *widget );
       
   101 		)
   101 		)
   102 	if( err != KErrNone )
   102 	if( err != KErrNone )
   103 		{
   103 		{
   104 		throw HsException( err );
   104 		throw HsException( err );
   105 		}
   105 		}
   137         for (TInt index = 0; index < changeMapsList->Count(); ++index)
   137         for (TInt index = 0; index < changeMapsList->Count(); ++index)
   138             {
   138             {
   139              if ( changeMapsList->AtL(index, variant) ) 
   139              if ( changeMapsList->AtL(index, variant) ) 
   140             	 {
   140             	 {
   141                  const CLiwMap* map  = variant.AsMap();
   141                  const CLiwMap* map  = variant.AsMap();
   142                  HsWidget* widget = GetWidgetL( map );
   142                  variant.Reset();
   143                  if( !widget )
       
   144                 	 {
       
   145                 	 break;
       
   146                 	 }
       
   147                  if ( map->FindL(KOperation, variant) )
   143                  if ( map->FindL(KOperation, variant) )
   148                      {// Check what triggered a notification
   144                      {// Check what triggered a notification
   149                      variant.Get(operation);
   145                      variant.Get(operation);
   150                      }
   146                      }
   151                  variant.Reset();
   147                  variant.Reset();
   153                 	 {
   149                 	 {
   154                 	 if( map->FindL( KActionTrigger, variant) )
   150                 	 if( map->FindL( KActionTrigger, variant) )
   155 						 {
   151 						 {
   156 						 variant.Get(trigger );
   152 						 variant.Get(trigger );
   157 						 }
   153 						 }
   158                 	 if( !HandleWidgetActionL( trigger, *widget ) )
   154                      HsWidget* widget = GetWidgetL( map );
   159                 		 {
   155                      if( !widget )
   160                 		 break;
   156                          {
   161                 		 }
   157                          break;
   162                 	 HandleWidgetItemActionL( trigger, *widget );
   158                          }
       
   159                       variant.Reset();
       
   160                       if ( !map->FindL( KContentId, variant ) )
       
   161                            {
       
   162                            User::Leave( KErrNotFound );
       
   163                            }
       
   164                 	  HandleWidgetActionL( trigger, variant.AsDes(), *widget );
       
   165                 	  HandleWidgetItemActionL( trigger, *widget );
       
   166                 	  variant.Reset();
   163                 	 }
   167                 	 }
   164                  }
   168                  }
   165             }
   169             }
   166         CleanupStack::PopAndDestroy(1);
   170         CleanupStack::PopAndDestroy(1);
   167         }
   171         }
   170 
   174 
   171 // ---------------------------------------------------------------------------
   175 // ---------------------------------------------------------------------------
   172 // 
   176 // 
   173 // ---------------------------------------------------------------------------
   177 // ---------------------------------------------------------------------------
   174 //
   178 //
   175 int HsWidgetPublisherImpl::HandleWidgetActionL( const TDesC8& aActionDes,
   179 void HsWidgetPublisherImpl::HandleWidgetActionL( const TDesC8& aActionDes, 
   176 	HsWidget& aWidget )
   180         const TDesC& aContentIdDes, HsWidget& aWidget )
   177 	{
   181 	{
   178 	int ret( 1 );//not found
       
   179 	IHsDataObserver::EEvent action( IHsDataObserver::EUnknown );
   182 	IHsDataObserver::EEvent action( IHsDataObserver::EUnknown );
   180 	TranslateObserverAction( aActionDes, action );
   183 	TranslateObserverAction( aActionDes, action );
       
   184 	switch( action )
       
   185 	    {
       
   186 	    case IHsDataObserver::EActivate:
       
   187 	        {
       
   188             // add / update the Instance Id
       
   189             std::wstring contentId( ToWideStringL( aContentIdDes ) );
       
   190             mWidgetContentIds[aWidget.getIdentifier()] = contentId;  
       
   191 	        };
       
   192             break;
       
   193 	    case IHsDataObserver::EDeactivate:
       
   194 	        {
       
   195 	        mWidgetContentIds.erase( aWidget.getIdentifier() );
       
   196 	        };
       
   197             break;
       
   198 	    case IHsDataObserver::EPluginshutdown:
       
   199 	        {
       
   200 	        // remove widget data when widget removed from screen
       
   201             CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC();
       
   202             InsertWidgetDataIdentifiersL( aWidget, cpdatamap );
       
   203             // removal may fail if the client has already removed the data
       
   204             TRAP_IGNORE( RemoveFromCpsL( cpdatamap, KCpData ) );
       
   205             CleanupStack::PopAndDestroy( cpdatamap );
       
   206 	        };
       
   207             break;
       
   208 	    default :
       
   209 	        break;
       
   210 	    };
       
   211 	
   181 	if( action == IHsDataObserver::EActivate ||
   212 	if( action == IHsDataObserver::EActivate ||
   182 		action == IHsDataObserver::EDeactivate ||
   213 		action == IHsDataObserver::EDeactivate ||
   183 		action == IHsDataObserver::EResume ||
   214 		action == IHsDataObserver::EResume ||
   184 		action == IHsDataObserver::ESuspend )
   215 		action == IHsDataObserver::ESuspend )
   185 		{
   216 		{
   191 			}
   222 			}
   192 		catch( HsException& exception )
   223 		catch( HsException& exception )
   193 			{
   224 			{
   194 			observerError = exception.getReason();
   225 			observerError = exception.getReason();
   195 			}
   226 			}
   196 		
       
   197 		if ( action == IHsDataObserver::EDeactivate )
       
   198 		    {
       
   199 		    // remove widget data when widget removed from screen
       
   200 		    CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC();
       
   201 		    InsertWidgetDataIdentifiersL( aWidget, cpdatamap );
       
   202 		    // removal may fail if the client has already removed the data
       
   203 		    TRAP_IGNORE( RemoveFromCpsL( cpdatamap, KCpData ) );
       
   204 		    mWidgetContentIds.erase( aWidget.getIdentifier() );
       
   205 		    CleanupStack::PopAndDestroy( cpdatamap );
       
   206 		    }
       
   207 		
       
   208 		User::LeaveIfError( observerError );
   227 		User::LeaveIfError( observerError );
   209 		ret = 0;
   228 		}
   210 		}
       
   211 	return ret;
       
   212 	}
   229 	}
   213 
   230 
   214 // ---------------------------------------------------------------------------
   231 // ---------------------------------------------------------------------------
   215 // 
   232 // 
   216 // ---------------------------------------------------------------------------
   233 // ---------------------------------------------------------------------------
   220 	{
   237 	{
   221 	if( !aActionDes.Compare( KActive() ) )
   238 	if( !aActionDes.Compare( KActive() ) )
   222 		{
   239 		{
   223 		aAction = IHsDataObserver::EActivate;
   240 		aAction = IHsDataObserver::EActivate;
   224 		}
   241 		}
       
   242 	if( !aActionDes.Compare( KPluginshutdown() ) )
       
   243         {
       
   244         aAction = IHsDataObserver::EPluginshutdown;
       
   245         }
   225 	if( !aActionDes.Compare( KDeActive() ) )
   246 	if( !aActionDes.Compare( KDeActive() ) )
   226 		{
   247 		{
   227 		aAction = IHsDataObserver::EDeactivate;
   248 		aAction = IHsDataObserver::EDeactivate;
   228 		}
   249 		}
   229 	if( !aActionDes.Compare( KSuspend() ) )
   250 	if( !aActionDes.Compare( KSuspend() ) )
   424 	CLiwDefaultMap* datamap = CLiwDefaultMap::NewLC();
   445 	CLiwDefaultMap* datamap = CLiwDefaultMap::NewLC();
   425 	InsertWidgetItemsL( aWidget, datamap );
   446 	InsertWidgetItemsL( aWidget, datamap );
   426 	cpdatamap->InsertL( KDataMap, TLiwVariant( datamap ) );
   447 	cpdatamap->InsertL( KDataMap, TLiwVariant( datamap ) );
   427 	InsertWidgetACLL( cpdatamap );
   448 	InsertWidgetACLL( cpdatamap );
   428 	
   449 	
   429 	int count = aWidget.itemsCount();
   450 	
   430 	if( count > 0 )
   451     // add to CPS
   431 		{
       
   432 		CLiwDefaultMap* triggermap = CLiwDefaultMap::NewLC();
       
   433 		InsertItemsTriggersL( aWidget, triggermap );
       
   434 		cpdatamap->InsertL( KActionMap, TLiwVariant( triggermap ) );
       
   435 		CleanupStack::PopAndDestroy( triggermap );
       
   436 		}
       
   437 
       
   438         // add to CPS
       
   439 	TLiwGenericParam item( KItem, TLiwVariant( cpdatamap ));	    
   452 	TLiwGenericParam item( KItem, TLiwVariant( cpdatamap ));	    
   440 	inParam->AppendL( item );
   453 	inParam->AppendL( item );
   441 	mServiceInterface->ExecuteCmdL( KAdd,
   454 	mServiceInterface->ExecuteCmdL( KAdd,
   442 			*inParam, *outParam);
   455 			*inParam, *outParam);
   443 	TInt ret= ObtainErrorCode( *outParam );
   456 	TInt ret= ObtainErrorCode( *outParam );
   448 	item.Reset();
   461 	item.Reset();
   449 	type.Reset();	
   462 	type.Reset();	
   450 	outParam->Reset();
   463 	outParam->Reset();
   451 	inParam->Reset();
   464 	inParam->Reset();
   452 	User::LeaveIfError( ret );
   465 	User::LeaveIfError( ret );
       
   466     
       
   467     int count = aWidget.itemsCount();
       
   468     for ( TInt itemIndex = 0; itemIndex< count; itemIndex++)
       
   469         {
       
   470         if ( ! aWidget.getWidgetItem(itemIndex)->isTriggerAdded() )
       
   471             {
       
   472             AddItemsActionsL( aWidget, itemIndex );
       
   473             }
       
   474         }
   453     }
   475     }
   454 
   476 
   455 // ---------------------------------------------------------------------------
   477 // ---------------------------------------------------------------------------
   456 // 
   478 // 
   457 // ---------------------------------------------------------------------------
   479 // ---------------------------------------------------------------------------
   664         }
   686         }
   665     variant.Reset();
   687     variant.Reset();
   666     std::string strIdentifier( GetWidgetIdentifierFromPublisherNameL(
   688     std::string strIdentifier( GetWidgetIdentifierFromPublisherNameL(
   667             *publisherName ) );
   689             *publisherName ) );
   668     CleanupStack::PopAndDestroy( publisherName );
   690     CleanupStack::PopAndDestroy( publisherName );
   669     publisherName = 0;
       
   670     
       
   671 	TBuf<KSAPIContentNameMaxLength> contentIdDesc;
       
   672     if ( !aMap->FindL( KContentId, variant ) )
       
   673          {
       
   674          User::Leave( KErrNotFound );
       
   675          }
       
   676     variant.Get( contentIdDesc );
       
   677     CleanupStack::PopAndDestroy( &variant );
   691     CleanupStack::PopAndDestroy( &variant );
   678     std::wstring contentId( ToWideStringL( contentIdDesc ) );
   692     
   679 	
       
   680 	std::string strTemplate;
   693 	std::string strTemplate;
   681 	std::string strWidgetName;
   694 	std::string strWidgetName;
   682 		
       
   683 	if( CheckIfWidgetExist(strTemplate, strWidgetName, strIdentifier, ETrue) )
   695 	if( CheckIfWidgetExist(strTemplate, strWidgetName, strIdentifier, ETrue) )
   684 		{
   696 		{
   685 		ret = &GetWidget( strTemplate, strWidgetName, strIdentifier);
   697 		ret = &GetWidget( strTemplate, strWidgetName, strIdentifier);
   686 		
   698 		}
   687 		// verify that content id does not change
       
   688 		__ASSERT_DEBUG( !mWidgetContentIds.count( ret->getIdentifier() ) ||
       
   689 		        mWidgetContentIds[ret->getIdentifier()] == contentId,
       
   690 		        User::Invariant() );
       
   691 
       
   692 		mWidgetContentIds[ret->getIdentifier()] = contentId;
       
   693 		}
       
   694 	
       
   695 	return ret;
   699 	return ret;
   696 	}
   700 	}
   697 
   701 
   698 // ---------------------------------------------------------------------------
   702 // ---------------------------------------------------------------------------
   699 // 
   703 // 
   772 // ---------------------------------------------------------------------------
   776 // ---------------------------------------------------------------------------
   773 // 
   777 // 
   774 // ---------------------------------------------------------------------------
   778 // ---------------------------------------------------------------------------
   775 //
   779 //
   776 void HsWidgetPublisherImpl::InsertWidgetDataIdentifiersL( HsWidget& aWidget,
   780 void HsWidgetPublisherImpl::InsertWidgetDataIdentifiersL( HsWidget& aWidget,
   777 	CLiwDefaultMap* aDataMap )
   781     CLiwDefaultMap* aDataMap )
       
   782     {
       
   783     InsertWidgetDataIdentifiersL( aWidget, aDataMap, KAll );
       
   784     }
       
   785 	
       
   786 // ---------------------------------------------------------------------------
       
   787 // 
       
   788 // ---------------------------------------------------------------------------
       
   789 //
       
   790 void HsWidgetPublisherImpl::InsertWidgetDataIdentifiersL( HsWidget& aWidget,
       
   791 	CLiwDefaultMap* aDataMap, const TDesC& aContentType )
   778     {
   792     {
   779     WidgetContentIdMapType::const_iterator contentIdIter =
   793     WidgetContentIdMapType::const_iterator contentIdIter =
   780             mWidgetContentIds.find( aWidget.getIdentifier() );
   794             mWidgetContentIds.find( aWidget.getIdentifier() );
   781     if ( contentIdIter == mWidgetContentIds.end() )
   795     if ( contentIdIter == mWidgetContentIds.end() )
   782         {
   796         {
   786             contentIdIter->second.c_str() );
   800             contentIdIter->second.c_str() );
   787     
   801     
   788     HBufC* publisherName = StdStringToUnicodeLC( GetPublisherNameL( aWidget ) );
   802     HBufC* publisherName = StdStringToUnicodeLC( GetPublisherNameL( aWidget ) );
   789     
   803     
   790     aDataMap->InsertL( KPublisherId, TLiwVariant( *publisherName ) );
   804     aDataMap->InsertL( KPublisherId, TLiwVariant( *publisherName ) );
   791     aDataMap->InsertL( KContentType, TLiwVariant( KAll ) );
   805     aDataMap->InsertL( KContentType, TLiwVariant( aContentType ) );
   792     aDataMap->InsertL( KContentId, TLiwVariant( contentId ) );
   806     aDataMap->InsertL( KContentId, TLiwVariant( contentId ) );
   793     
   807     
   794     CleanupStack::PopAndDestroy( publisherName );
   808     CleanupStack::PopAndDestroy( publisherName );
   795     }
   809     }
   796 
   810 
   936 
   950 
   937 // ---------------------------------------------------------------------------
   951 // ---------------------------------------------------------------------------
   938 // 
   952 // 
   939 // ---------------------------------------------------------------------------
   953 // ---------------------------------------------------------------------------
   940 //
   954 //
   941 void HsWidgetPublisherImpl::InsertItemsTriggersL( HsWidget& aWidget,
   955 void HsWidgetPublisherImpl::AddItemsActionsL(HsWidget& aWidget, TInt aItemIndex )
   942 	CLiwDefaultMap* aTriggerMap )
   956 	{
   943 	{
   957     HsWidgetItem* widgetItem = aWidget.getWidgetItem(aItemIndex);
   944 	int count = aWidget.itemsCount();
   958     TPtrC8 itemName = ((TUint8*)widgetItem->getItemName().c_str());
   945 	CLiwDefaultMap* activateAction = CLiwDefaultMap::NewLC();
   959     
   946 	activateAction->InsertL( KPluginId, TLiwVariant( KCASpaAppLauncherPlugin ) );
   960     CLiwGenericParamList* inParam = &(mServiceHandler->InParamListL());
   947 	
   961     CLiwGenericParamList* outParam = &(mServiceHandler->OutParamListL());
       
   962         
       
   963 
       
   964     TLiwGenericParam type(KType, TLiwVariant(KCpData));
       
   965     inParam->AppendL(type);
       
   966     
       
   967     CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC();
       
   968     HBufC* itemName16 = Utf8ToUnicodeLC(itemName );
       
   969     InsertWidgetDataIdentifiersL( aWidget, cpdatamap, itemName16->Des() );
       
   970     CleanupStack::PopAndDestroy( itemName16 );
       
   971     
       
   972     CLiwDefaultMap* mapAction = CLiwDefaultMap::NewLC();
       
   973     CLiwDefaultMap* activateAction = CLiwDefaultMap::NewLC();
   948 	CLiwDefaultMap* activate = CLiwDefaultMap::NewLC();
   974 	CLiwDefaultMap* activate = CLiwDefaultMap::NewLC();
   949 	activate->InsertL( KType, TLiwVariant( KActionValueLaunchApplication ) );
   975 	activate->InsertL( KType, TLiwVariant( KActionValueLaunchApplication ) );
   950 	activate->InsertL( KLaunchMethod, TLiwVariant( KLaunchMethodValueCmdLine ) );
   976 	activate->InsertL( KLaunchMethod, TLiwVariant( KLaunchMethodValueCmdLine ) );
   951 	activate->InsertL( KApplicationUid, TLiwVariant( iWidgetUid ) );
   977 	activate->InsertL( KApplicationUid, TLiwVariant( iWidgetUid ) );
   952 	activate->InsertL( KApaCommand, TLiwVariant( KApaCommandBackground ) );
   978 	activate->InsertL( KApaCommand, TLiwVariant( KApaCommandBackground ) );
   953 	
   979 
       
   980 	activateAction->InsertL( KPluginId, TLiwVariant( KCASpaAppLauncherPlugin ) );
   954 	activateAction->InsertL( KData, TLiwVariant( activate ) );
   981 	activateAction->InsertL( KData, TLiwVariant( activate ) );
   955 	
       
   956 	for (int index = 0; index < count; index++)
       
   957 		{
       
   958 		HsWidgetItem* const item = aWidget.getWidgetItem( index );
       
   959 		TPtrC8 itemName = ((TUint8*)item->getItemName().c_str());
       
   960 		aTriggerMap->InsertL( itemName, TLiwVariant( activateAction ));
       
   961 		}
       
   962 	CleanupStack::PopAndDestroy( activate );
   982 	CleanupStack::PopAndDestroy( activate );
   963 	CleanupStack::PopAndDestroy( activateAction );
   983     
       
   984     mapAction->InsertL(itemName, TLiwVariant( activateAction ));
       
   985     CleanupStack::PopAndDestroy( activateAction );
       
   986     cpdatamap->InsertL( KActionMap, TLiwVariant( mapAction ) );
       
   987     CleanupStack::PopAndDestroy( mapAction );
       
   988     
       
   989     InsertWidgetACLL( cpdatamap );
       
   990     
       
   991     TLiwGenericParam item( KItem, TLiwVariant( cpdatamap ));        
       
   992     inParam->AppendL( item );
       
   993         
       
   994     mServiceInterface->ExecuteCmdL( KAdd, *inParam, *outParam );
       
   995     TInt ret= ObtainErrorCode( *outParam );
       
   996     
       
   997     CleanupStack::PopAndDestroy( cpdatamap );
       
   998     item.Reset();
       
   999     type.Reset();
       
  1000     outParam->Reset();
       
  1001     inParam->Reset();
       
  1002     User::LeaveIfError( ret );
       
  1003     
       
  1004     widgetItem->triggerAdded();
   964 	}
  1005 	}
   965 
  1006 
   966 // ---------------------------------------------------------------------------
  1007 // ---------------------------------------------------------------------------
   967 // 
  1008 // 
   968 // ---------------------------------------------------------------------------
  1009 // ---------------------------------------------------------------------------