servicewidget/servicewidgetdatapublisher/src/cservicewidgetcontentpublisher.cpp
changeset 0 5e5d6b214f4f
child 11 bef90b82da71
equal deleted inserted replaced
-1:000000000000 0:5e5d6b214f4f
       
     1 /*
       
     2 * Copyright (c) 2008 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:  class to publish the data into widget
       
    15 *                
       
    16 *
       
    17 */
       
    18 
       
    19 #include "cservicewidgetcontentpublisher.h"
       
    20 
       
    21 #include <LiwServiceHandler.h>
       
    22 #include <LiwVariant.h>
       
    23 #include <LiwGenericParam.h>
       
    24 #include <avkon.hrh>
       
    25 #include <aknnotewrappers.h> 
       
    26 #include "swpdebugtrace.h"
       
    27 
       
    28 #include <LiwCommon.h>
       
    29 #include "servicewidgetcpglobals.h"
       
    30 #include <servicewidgetpluginres.rsg>
       
    31 #include <stringloader.h>
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // CServiceWidgetContentPublisher::CServiceWidgetContentPublisher
       
    35 // ---------------------------------------------------------------------------
       
    36 // 
       
    37 CServiceWidgetContentPublisher::CServiceWidgetContentPublisher(MServiceWidgetEventObserver& aObserver )
       
    38    :iObserver( aObserver )
       
    39     {
       
    40    TRACE_SWP(TXT("CServiceWidgetContentPublisher::CServiceWidgetContentPublisher") );
       
    41    }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CServiceWidgetContentPublisher::NewL
       
    45 // ---------------------------------------------------------------------------
       
    46 // 
       
    47 CServiceWidgetContentPublisher* CServiceWidgetContentPublisher::NewL(MServiceWidgetEventObserver& aObserver)
       
    48     {
       
    49     TRACE_SWP(TXT("CServiceWidgetContentPublisher::NewL() start") );
       
    50     CServiceWidgetContentPublisher* self = NewLC(aObserver);
       
    51     CleanupStack::Pop(self);
       
    52     TRACE_SWP(TXT("CServiceWidgetContentPublisher::NewL() End") );
       
    53     return self;
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CServiceWidgetContentPublisher::NewLC
       
    58 // ---------------------------------------------------------------------------
       
    59 // 
       
    60 CServiceWidgetContentPublisher* CServiceWidgetContentPublisher::NewLC(MServiceWidgetEventObserver& aObserver)
       
    61     {
       
    62     TRACE_SWP(TXT("CServiceWidgetContentPublisher::NewLC() start") );
       
    63     CServiceWidgetContentPublisher* self =
       
    64         new (ELeave) CServiceWidgetContentPublisher(aObserver);
       
    65     CleanupStack::PushL(self);
       
    66     self->ConstructL();
       
    67     TRACE_SWP(TXT("CServiceWidgetContentPublisher::NewLC() End") );
       
    68     return self;
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // CServiceWidgetContentPublisher::ConstructL
       
    73 // ---------------------------------------------------------------------------
       
    74 // ConstructL is called by the application framework
       
    75 void CServiceWidgetContentPublisher::ConstructL()
       
    76     {
       
    77     TRACE_SWP(TXT("CServiceWidgetContentPublisher::ConstructL() start") );
       
    78 	iMsgInterface = GetMessagingInterfaceL();
       
    79 	TRACE_SWP(TXT("CServiceWidgetContentPublisher::ConstructL() End") );
       
    80     }
       
    81 // ---------------------------------------------------------------------------
       
    82 // CServiceWidgetContentPublisher::~CServiceWidgetContentPublisher
       
    83 // ---------------------------------------------------------------------------
       
    84 CServiceWidgetContentPublisher::~CServiceWidgetContentPublisher()
       
    85     {
       
    86     TRACE_SWP(TXT("CServiceWidgetContentPublisher::~CServiceWidgetContentPublisher() start") );
       
    87     if( iMsgInterface )
       
    88     	{
       
    89 		iMsgInterface->Close();
       
    90 		iMsgInterface = NULL;
       
    91     	}
       
    92    	if( iServiceHandler )
       
    93     	{
       
    94     	iServiceHandler->Reset();
       
    95     	delete iServiceHandler;
       
    96     	iServiceHandler = NULL;
       
    97     	}
       
    98     TRACE_SWP(TXT("CServiceWidgetContentPublisher::~CServiceWidgetContentPublisher() End") );
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CServiceWidgetContentPublisher::GetMessagingInterfaceL
       
   103 // ---------------------------------------------------------------------------
       
   104 
       
   105 MLiwInterface* CServiceWidgetContentPublisher::GetMessagingInterfaceL( )
       
   106 	{
       
   107 	TRACE_SWP(TXT("CServiceWidgetContentPublisher::GetMessagingInterfaceL() start") );
       
   108 	if( !iServiceHandler )
       
   109 		{
       
   110 		iServiceHandler = CLiwServiceHandler::NewL();
       
   111 		TRACE_SWP(TXT("CServiceWidgetContentPublisher::GetMessagingInterfaceL() CLiwServiceHandler created") );
       
   112 		}
       
   113 	CLiwGenericParamList* inParam = CLiwGenericParamList::NewL();
       
   114 	CleanupStack::PushL( inParam );
       
   115 	CLiwGenericParamList* outParam = CLiwGenericParamList::NewL();
       
   116 	CleanupStack::PushL( outParam );
       
   117 	CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL( KLiwCmdAsStr, KCPContentInterface,
       
   118 		KCPService  );
       
   119 	crit->SetServiceClass( TUid::Uid(KLiwClassBase) );
       
   120 	
       
   121 	RCriteriaArray array;
       
   122 	array.AppendL(crit);    
       
   123 	iServiceHandler->AttachL(array);
       
   124 	iServiceHandler->ExecuteServiceCmdL( *crit, *inParam, *outParam ); 
       
   125 	delete crit;
       
   126 	array.Reset();
       
   127 	
       
   128 	// find service interface
       
   129 	TInt pos = 0;
       
   130 	MLiwInterface* msgInterface = NULL;
       
   131 	outParam->FindFirst( pos, KCPContentInterface );
       
   132 	if ( pos != KErrNotFound ) 
       
   133 	    {
       
   134 	    msgInterface = (*outParam)[pos].Value().AsInterface(); 
       
   135 	    }
       
   136 	outParam->Reset();
       
   137 	inParam->Reset();
       
   138 	CleanupStack::PopAndDestroy( outParam );
       
   139 	CleanupStack::PopAndDestroy( inParam );
       
   140 	TRACE_SWP(TXT("CServiceWidgetContentPublisher::GetMessagingInterfaceL() End") );
       
   141 	return msgInterface;
       
   142 	}
       
   143 // ---------------------------------------------------------------------------
       
   144 // CServiceWidgetContentPublisher::HandleNotifyL
       
   145 // ---------------------------------------------------------------------------
       
   146 //  
       
   147 TInt CServiceWidgetContentPublisher::HandleNotifyL( TInt aCmdId, TInt /*aEventId*/,
       
   148                                                     CLiwGenericParamList& aEventParamList,
       
   149                                                     const CLiwGenericParamList& /*aInParamList*/ 
       
   150                                                    )
       
   151     { 
       
   152     TRACE_SWP( TXT("CServiceWidgetContentPublisher::HandleNotifyL() start") );
       
   153     TInt pos(0);
       
   154     aEventParamList.FindFirst(pos, KChangeInfo);
       
   155 
       
   156     if (pos != KErrNotFound)
       
   157         {
       
   158         TLiwVariant variant = (aEventParamList)[pos].Value();
       
   159         variant.PushL();
       
   160         const CLiwList* changeMapsList = variant.AsList();
       
   161         HBufC16* publisher  = NULL;       
       
   162         HBufC8* trigger = NULL;
       
   163         const TInt KSAPIContentNameMaxLength = 255;
       
   164         TBuf<KSAPIContentNameMaxLength> InstId;
       
   165 
       
   166         for (TInt i = 0; i < changeMapsList->Count(); ++i)
       
   167             {
       
   168             if ( changeMapsList->AtL(i, variant) ) 
       
   169                 {
       
   170                 const CLiwMap* map  = variant.AsMap();
       
   171                 if( map->FindL( KActionTrigger, variant) )
       
   172                     {
       
   173                     trigger = variant.AsData().AllocLC(); // trigger name                      
       
   174                     // In template case trigger name can be 
       
   175                     // active ,  resume , suspend ,inactive, deactive or item names.
       
   176                     }
       
   177                 if( map->FindL( KPublisherId, variant) )
       
   178                     {
       
   179                     publisher = variant.AsDes().AllocLC();  // ai3templatedwidget                                          
       
   180                     }
       
   181                 if( map->FindL( KContentId, variant) )
       
   182                     {
       
   183                     variant.Get( InstId );
       
   184                     }
       
   185                 if( trigger && publisher )
       
   186                     {
       
   187                     iObserver.HandleServiceEventL( *publisher, *trigger, InstId);
       
   188                     }//
       
   189                 if ( publisher )
       
   190                     {
       
   191                     CleanupStack::PopAndDestroy( publisher );
       
   192                     publisher = NULL;
       
   193                     }
       
   194                 if ( trigger )
       
   195                     {
       
   196                     CleanupStack::PopAndDestroy( trigger );
       
   197                     trigger = NULL;
       
   198                     }  
       
   199                 }
       
   200             }// loop
       
   201     CleanupStack::Pop(&variant);    //variant
       
   202     variant.Reset(); 
       
   203     }//if (pos != KErrNotFound)
       
   204   TRACE_SWP(TXT("CServiceWidgetContentPublisher::HandleNotifyL() end") );
       
   205   return aCmdId;
       
   206   }//End HandleNotifyL
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 // CServiceWidgetContentPublisher::RegisterWidgetL
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 void CServiceWidgetContentPublisher::RegisterWidgetL(const TDesC& aPublisherId,
       
   213                                                            TInt aBitmapHandle,
       
   214                                                            TInt aMaskHandle )
       
   215     {
       
   216     TRACE_SWP(TXT("CServiceWidgetContentPublisher::RegisterWidgetL() start") );
       
   217     if( iMsgInterface )
       
   218         {   
       
   219         CLiwGenericParamList* inparam = &(iServiceHandler->InParamListL());
       
   220         CLiwGenericParamList* outparam = &(iServiceHandler->OutParamListL());
       
   221 
       
   222         TLiwGenericParam type( KType, TLiwVariant( KPublisher ));
       
   223         inparam->AppendL( type );
       
   224 
       
   225         CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC();
       
   226         CLiwDefaultMap* datamap = CLiwDefaultMap::NewLC();
       
   227         CLiwDefaultMap* mapAction = CLiwDefaultMap::NewLC(); 
       
   228           
       
   229         cpdatamap->InsertL( KPublisherId, TLiwVariant( aPublisherId )); 
       
   230         cpdatamap->InsertL( KContentType, TLiwVariant( KTemplateWidget ));
       
   231         cpdatamap->InsertL( KContentId, TLiwVariant( KAll ));
       
   232         //Take widget name as "service name"
       
   233         //Give widget name here which will be displayed in HomeScreen Add Content menu
       
   234         datamap->InsertL( KWidgetName, TLiwVariant( aPublisherId ));
       
   235         datamap->InsertL( KTemplateType, TLiwVariant( KServiceWidget )); 
       
   236         
       
   237         //To publish logo and widget description
       
   238         HBufC* text = NULL;
       
   239         text = StringLoader::LoadLC( R_QTN_SERVTAB_WIDGET_SERVDESC );
       
   240         datamap->InsertL(KWidgetDesc, TLiwVariant( *text ));
       
   241         CleanupStack::PopAndDestroy(text);//text
       
   242         datamap->InsertL(KWidgetLogo , TLiwVariant( aBitmapHandle ) ); // key - aKey, value - map (stringsMap)
       
   243         // append mask 
       
   244         // create mask key for the data item. Format is the image key with the '_mask' postfix.
       
   245         HBufC8* maskResult = HBufC8::NewLC( KWidgetLogo().Length() + KMask().Length() );
       
   246         TPtr8 maskResultPtr = maskResult ->Des();
       
   247         maskResultPtr .Append( KWidgetLogo );
       
   248         maskResultPtr .Append( KMask );
       
   249         datamap->InsertL( maskResultPtr,  TLiwVariant( aMaskHandle ) ); // key - aKey, value - map (stringsMap)
       
   250         CleanupStack::PopAndDestroy(maskResult);//maskResult
       
   251         
       
   252         cpdatamap->InsertL( KDataMap, TLiwVariant(datamap) );
       
   253 
       
   254         mapAction->InsertL(KActive, TLiwVariant(KTriggerMap));
       
   255         mapAction->InsertL(KDeActive, TLiwVariant(KTriggerMap));
       
   256         mapAction->InsertL(KSuspend, TLiwVariant(KTriggerMap));
       
   257         mapAction->InsertL(KInactive, TLiwVariant(KTriggerMap));
       
   258         mapAction->InsertL(KResume, TLiwVariant(KTriggerMap));
       
   259         // this will be called after clicking on widget, and generate "selected" event
       
   260         mapAction->InsertL( KSelected, TLiwVariant(  KTriggerMap  ) );
       
   261         cpdatamap->InsertL( KActionMap, TLiwVariant(mapAction) );
       
   262 
       
   263         TLiwGenericParam textItem( KItem, TLiwVariant( cpdatamap ));        
       
   264         inparam->AppendL( textItem );
       
   265         iMsgInterface->ExecuteCmdL( KAdd , *inparam, *outparam);
       
   266         CleanupStack::PopAndDestroy(mapAction);
       
   267         CleanupStack::PopAndDestroy(datamap);
       
   268         CleanupStack::PopAndDestroy(cpdatamap);
       
   269         
       
   270         textItem.Reset();
       
   271         outparam->Reset();
       
   272         inparam->Reset(); 
       
   273         
       
   274         // request for active/deactive/suspend/resume notification 
       
   275         CLiwDefaultMap*  reqFilter = CLiwDefaultMap::NewLC();
       
   276         reqFilter->InsertL(KPublisherId, TLiwVariant( aPublisherId ));
       
   277         reqFilter->InsertL(KContentType, TLiwVariant( KAll ));
       
   278         reqFilter->InsertL( KContentId, TLiwVariant( KAll ));
       
   279         reqFilter->InsertL(KOperation, TLiwVariant(KExecute));
       
   280 
       
   281         // fill in input list for RequestNotification command
       
   282         inparam->AppendL(TLiwGenericParam(KType, TLiwVariant(KPublisher)));
       
   283         inparam->AppendL(TLiwGenericParam(KFilter, TLiwVariant(reqFilter)));
       
   284        
       
   285         iMsgInterface->ExecuteCmdL( KRequestNotification,
       
   286                                     *inparam,
       
   287                                     *outparam,
       
   288                                     0,
       
   289                                     this ) ;
       
   290 
       
   291         CleanupStack::PopAndDestroy(reqFilter );  
       
   292         outparam->Reset();
       
   293         inparam->Reset();
       
   294         TRACE_SWP(TXT("CServiceWidgetContentPublisher::RegisterWidgetL() Registered widget %s"), &aPublisherId );
       
   295         } 
       
   296     TRACE_SWP(TXT("CServiceWidgetContentPublisher::RegisterWidgetL() end") );
       
   297     }
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // CServiceWidgetContentPublisher::UnregisterWidgetL
       
   301 // ---------------------------------------------------------------------------
       
   302 //
       
   303 void CServiceWidgetContentPublisher::UnregisterWidgetL(const TDesC& aPublisherId )
       
   304     {
       
   305     TRACE_SWP(TXT("CServiceWidgetContentPublisher::RegisterForObserverL() start") );
       
   306     
       
   307     CLiwGenericParamList* inparam = &(iServiceHandler->InParamListL()); 
       
   308     CLiwGenericParamList* outparam = &(iServiceHandler->OutParamListL());
       
   309     CLiwDefaultMap*  cpdatamap= CLiwDefaultMap::NewLC();
       
   310 
       
   311     cpdatamap->InsertL( KPublisherId, TLiwVariant( aPublisherId ));
       
   312     cpdatamap->InsertL( KContentType, TLiwVariant( KTemplateWidget ));
       
   313     cpdatamap->InsertL( KContentId, TLiwVariant( KAll ));
       
   314     // fill in input list for RequestNotification command
       
   315     inparam->AppendL(TLiwGenericParam(KType, TLiwVariant(KPublisher)));
       
   316     inparam->AppendL(TLiwGenericParam(KData, TLiwVariant(cpdatamap)));
       
   317 
       
   318     iMsgInterface->ExecuteCmdL(KDelete, *inparam, *outparam, 0, this );
       
   319 
       
   320     CleanupStack::PopAndDestroy(cpdatamap);      
       
   321     outparam->Reset();
       
   322     inparam->Reset();
       
   323     TRACE_SWP(TXT("CServiceWidgetContentPublisher::UnregisterWidget() end") );
       
   324     }//end UnregisterWidget
       
   325 
       
   326 // ---------------------------------------------------------------------------
       
   327 // CServiceWidgetContentPublisher::RemoveWidgetDataL
       
   328 // ---------------------------------------------------------------------------
       
   329 // 
       
   330 void CServiceWidgetContentPublisher::RemoveWidgetDataL(const TDesC& aPublisherId, const TDesC& aInstId)
       
   331     {
       
   332     TRACE_SWP(TXT("CServiceWidgetContentPublisher::RemoveWidgetData() start") );
       
   333     CLiwGenericParamList* inparam = &(iServiceHandler->InParamListL());
       
   334     CLiwGenericParamList* outparam = &(iServiceHandler->OutParamListL());
       
   335 
       
   336     CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC();
       
   337 
       
   338     cpdatamap->InsertL( KPublisherId, TLiwVariant( aPublisherId ));
       
   339     cpdatamap->InsertL( KContentType, TLiwVariant( KAll )); 
       
   340     cpdatamap->InsertL( KContentId, TLiwVariant( aInstId ));
       
   341     
       
   342     // fill in input list for RequestNotification command
       
   343     inparam->AppendL(TLiwGenericParam(KType, TLiwVariant(KCpData)));
       
   344     inparam->AppendL(TLiwGenericParam(KData, TLiwVariant(cpdatamap)));
       
   345 
       
   346     TInt err = KErrNone;
       
   347     // if you have only one combination of publisher,content_type, contenid 
       
   348     // then all the items will be remove from your widget
       
   349     TRAP(err,iMsgInterface->ExecuteCmdL( KDelete , *inparam, *outparam, 0 , this));
       
   350 
       
   351     CleanupStack::PopAndDestroy( cpdatamap );
       
   352     outparam->Reset();
       
   353     inparam->Reset();
       
   354     TRACE_SWP(TXT("CServiceWidgetContentPublisher::RemoveWidgetData() end") );
       
   355     }
       
   356 // ---------------------------------------------------------------------------
       
   357 // CServiceWidgetContentPublisher::PublishDataWithActionL
       
   358 // ---------------------------------------------------------------------------
       
   359 // 
       
   360 void CServiceWidgetContentPublisher::PublishDataWithActionL( const TDesC& aPublisherId,
       
   361                                                              const TDesC& aInstId,
       
   362                                                              const TDesC& aOwnTextToAdd, 
       
   363                                                              const TDesC& aStatusTextToAdd,
       
   364                                                              TInt aBitmapHandle,
       
   365                                                              TInt aMaskHandle,
       
   366                                                              TInt aSericonbitmapHandle, 
       
   367                                                              TInt aSericonmaskHandle
       
   368 													         )
       
   369     {
       
   370     TRACE_SWP(TXT("CServiceWidgetContentPublisher::PublishDataWithActionL() start") );
       
   371 
       
   372     CLiwGenericParamList* inparam = &(iServiceHandler->InParamListL());
       
   373     CLiwGenericParamList* outparam = &(iServiceHandler->OutParamListL());
       
   374     inparam->Reset();
       
   375     outparam->Reset();
       
   376 
       
   377     if( iMsgInterface )
       
   378         {
       
   379          TLiwGenericParam type( KType,TLiwVariant(KCpData));
       
   380          inparam->AppendL( type );
       
   381 
       
   382          CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC();
       
   383          CLiwDefaultMap* datamap = CLiwDefaultMap::NewLC();
       
   384 
       
   385          cpdatamap->InsertL( KPublisherId, TLiwVariant( aPublisherId ));
       
   386          cpdatamap->InsertL( KContentType, TLiwVariant( KAll ));
       
   387          cpdatamap->InsertL( KContentId, TLiwVariant( aInstId ));
       
   388 
       
   389          //adding data to the map
       
   390          //add service icon data
       
   391          datamap->InsertL(KServiceImageKey , TLiwVariant( aSericonbitmapHandle ) ); // key - aKey, value - map (stringsMap)
       
   392          // append mask 
       
   393          // create mask key for the data item. Format is the image key with the '_mask' postfix.
       
   394          HBufC8* maskResult1 = HBufC8::NewLC( KServiceImageKey().Length() + KMask().Length() );
       
   395          TPtr8 maskResultPtr1 = maskResult1 ->Des();
       
   396          maskResultPtr1.Append( KServiceImageKey );
       
   397          maskResultPtr1.Append( KMask );
       
   398          datamap->InsertL( maskResultPtr1,  TLiwVariant( aSericonmaskHandle ) ); // key - aKey, value - map (stringsMap)
       
   399          CleanupStack::PopAndDestroy(maskResult1);//maskResult 
       
   400          //Add status icon data
       
   401          datamap->InsertL(KStatusIconKey , TLiwVariant( aBitmapHandle ) ); // key - aKey, value - map (stringsMap)
       
   402          // append mask 
       
   403          // create mask key for the data item. Format is the image key with the '_mask' postfix.
       
   404          HBufC8* maskResult = HBufC8::NewLC( KStatusIconKey().Length() + KMask().Length() );
       
   405          TPtr8 maskResultPtr = maskResult ->Des();
       
   406          maskResultPtr .Append( KStatusIconKey );
       
   407          maskResultPtr .Append( KMask );
       
   408          datamap->InsertL( maskResultPtr,  TLiwVariant( aMaskHandle ) ); // key - aKey, value - map (stringsMap)
       
   409          CleanupStack::PopAndDestroy(maskResult);//maskResult
       
   410          //add data for first text row and second text row
       
   411          datamap->InsertL(KOwnTextKey, TLiwVariant(aOwnTextToAdd));
       
   412          datamap->InsertL(KMessageTextKey, TLiwVariant(aStatusTextToAdd));
       
   413          cpdatamap->InsertL( KDataMap, TLiwVariant(datamap) );
       
   414 
       
   415          TLiwGenericParam item( KItem, TLiwVariant( cpdatamap ));        
       
   416          inparam->AppendL( item );
       
   417          iMsgInterface->ExecuteCmdL( KAdd,  *inparam, *outparam );
       
   418          item.Reset();
       
   419          type.Reset(); 
       
   420          CleanupStack::PopAndDestroy(datamap); // datamap
       
   421          CleanupStack::PopAndDestroy(cpdatamap);
       
   422          TRACE_SWP(TXT("CServiceWidgetContentPublisher::PublishDataWithActionL() success") );
       
   423         }	
       
   424     }
       
   425 
       
   426 // end of file