idlehomescreen/xmluicontroller/src/contentpublisher.cpp
changeset 0 f72a12da539e
child 1 5315654608de
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     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:  Content Publishing Service interface.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "contentpublisher.h"
       
    19 #include "globalqueryhandler.h"
       
    20 
       
    21 #include <LiwServiceHandler.h>
       
    22 #include <LiwVariant.h>
       
    23 #include <LiwGenericParam.h>
       
    24 #include <AknQueryDialog.h>
       
    25 #include <ai3xmlui.rsg>
       
    26 #include "xmluicontroller.h"
       
    27 #include <AknGlobalConfirmationQuery.h>
       
    28 #include <StringLoader.h> // StringLoader
       
    29 
       
    30 using namespace AiXmlUiController;
       
    31 
       
    32 _LIT8( KCPService, "Service.ContentPublishing" );
       
    33 _LIT8( KCPInterface, "IDataSource" );
       
    34 
       
    35 _LIT8( KType, "type" );
       
    36 _LIT( KCpData, "cp_data" );
       
    37 
       
    38 _LIT8( KPublisherId, "publisher" );
       
    39 _LIT8( KContentTypeId, "content_type" );
       
    40 _LIT8( KContentId, "content_id" );
       
    41 _LIT8( KResults, "results" );
       
    42 
       
    43 _LIT(KAI3HSPublisher,"ai3homescreen");
       
    44 _LIT(KContentType,"wideimage");
       
    45 
       
    46 _LIT8( KAPStatus, "apstatus");
       
    47 _LIT(KNetwork, "network");
       
    48 
       
    49 _LIT( KDisConnected, "disconnected");
       
    50 _LIT( KConnected, "connected");
       
    51 
       
    52 _LIT(KPublisher16, "publisher");
       
    53 
       
    54 
       
    55 _LIT8( KRequestNotification, "RequestNotification" );
       
    56 _LIT8( KDataMap, "data_map" );
       
    57 
       
    58 _LIT8( KItem, "item" );
       
    59 _LIT8( KAdd, "Add" );
       
    60 _LIT8( KGetList, "GetList" );
       
    61 _LIT8( KFilter,        "filter" );
       
    62 _LIT8( KWidth, "width");
       
    63 _LIT8( KHeight, "height");
       
    64 _LIT8( KChangeInfo,    "change_info" );
       
    65 // ============================ LOCAL FUNCTIONS ===============================
       
    66 
       
    67 
       
    68 static void DoResetAndDestroy( TAny* aPtr )
       
    69     {
       
    70     __ASSERT_DEBUG( aPtr, User::Invariant() );
       
    71     reinterpret_cast< RCriteriaArray* >( aPtr )->ResetAndDestroy();
       
    72     }
       
    73 
       
    74 // ============================ MEMBER FUNCTIONS ===============================
       
    75 
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // Two-phased constructor. Can leave.
       
    79 // -----------------------------------------------------------------------------
       
    80 // 
       
    81 CContentPublisher* CContentPublisher::NewL(CXmlUiController& aUiController)
       
    82     {
       
    83     CContentPublisher* self = new (ELeave) CContentPublisher(aUiController);
       
    84     CleanupStack::PushL( self );
       
    85     self->ConstructL();
       
    86     CleanupStack::Pop();
       
    87     return self;
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // Destructor
       
    92 // -----------------------------------------------------------------------------
       
    93 //   
       
    94 CContentPublisher::~CContentPublisher()
       
    95     {
       
    96     TRAP_IGNORE(UnRegisterListenerL());
       
    97     if( iCpsInterface )
       
    98         {
       
    99         iCpsInterface->Close();
       
   100         iCpsInterface = NULL;
       
   101         }
       
   102     if( iServiceHandler )
       
   103         {
       
   104         iServiceHandler->Reset();
       
   105         delete iServiceHandler;
       
   106         iServiceHandler = NULL;
       
   107         }
       
   108     delete iGlobalQueryHandler;
       
   109     delete iGlobalConfirmationQuery;    
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // C++ default constructor. Must not leave.
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 CContentPublisher::CContentPublisher(CXmlUiController& aUiController): iUiController( aUiController )
       
   117     {
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // 2nd phase constructor. Can leave.
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void CContentPublisher::ConstructL()
       
   125     {
       
   126     InitCpsInterfaceL();
       
   127     RegisterListenerL();
       
   128     iGlobalQueryHandler = CGlobalQueryHandler::NewL(iUiController);
       
   129     iGlobalConfirmationQuery = CAknGlobalConfirmationQuery::NewL();
       
   130     
       
   131     }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // Publishes a given width and height to Content Publishing Service
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void CContentPublisher::PublishSizeL( const TDesC& aElementName,
       
   138         TInt aWidth, TInt aHeight )
       
   139     {
       
   140     AddDataL( KAI3HSPublisher() ,KContentType(), aElementName,
       
   141             aWidth, KWidth, aHeight, KHeight );
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // Uses the CPS interface to add given data
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 void CContentPublisher::AddDataL( 
       
   149         const TDesC& aPublisherId, const TDesC& aContentType, const TDesC& aContentId,
       
   150         const TInt aData1, const TDesC8& aDataKey1,
       
   151         const TInt aData2, const TDesC8& aDataKey2 )
       
   152     {
       
   153     CLiwGenericParamList& inparam = iServiceHandler->InParamListL();
       
   154     CLiwGenericParamList& outparam = iServiceHandler->OutParamListL();
       
   155 
       
   156     TLiwGenericParam cptype( KType, TLiwVariant( KCpData ));
       
   157     cptype.PushL();
       
   158     
       
   159     inparam.AppendL( cptype );
       
   160     
       
   161     CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC();
       
   162     CLiwDefaultMap* map = CLiwDefaultMap::NewLC();
       
   163     
       
   164     // Add data to data map
       
   165     map->InsertL( aDataKey1,  TLiwVariant( aData1 ));
       
   166     map->InsertL( aDataKey2,  TLiwVariant( aData2 ));
       
   167 
       
   168     // Create content data map
       
   169     cpdatamap->InsertL( KPublisherId, TLiwVariant( aPublisherId ));
       
   170     cpdatamap->InsertL( KContentTypeId, TLiwVariant( aContentType )); 
       
   171     cpdatamap->InsertL( KContentId, TLiwVariant( aContentId ));
       
   172     cpdatamap->InsertL( KDataMap, TLiwVariant(map) );
       
   173             
       
   174     TLiwGenericParam item( KItem, TLiwVariant( cpdatamap ));     
       
   175     item.PushL(); 
       
   176        
       
   177     inparam.AppendL( item );
       
   178     
       
   179     iCpsInterface->ExecuteCmdL( KAdd , inparam, outparam);
       
   180 
       
   181     CleanupStack::PopAndDestroy( &item );
       
   182     CleanupStack::PopAndDestroy( map );
       
   183     CleanupStack::PopAndDestroy( cpdatamap );
       
   184     CleanupStack::PopAndDestroy( &cptype );
       
   185 
       
   186     outparam.Reset();
       
   187     inparam.Reset();
       
   188     }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // Uses the CPS interface to get data
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 void CContentPublisher::GetDataL( 
       
   195         const TDesC& aPublisherId, const TDesC& aContentType, const TDesC& aContentId,
       
   196         CLiwDefaultMap* aOutDataMap)
       
   197     {
       
   198     CLiwGenericParamList& inParamList  = iServiceHandler->InParamListL();
       
   199 	CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
       
   200 	
       
   201 	TLiwGenericParam type( KType, TLiwVariant( KCpData ) );
       
   202 	inParamList.AppendL( type );
       
   203 	
       
   204 	CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC();
       
   205 
       
   206 	// Create content data map
       
   207 	cpdatamap->InsertL( KPublisherId, TLiwVariant( aPublisherId ));
       
   208 	cpdatamap->InsertL( KContentTypeId, TLiwVariant( aContentType )); 
       
   209 	cpdatamap->InsertL( KContentId, TLiwVariant( aContentId ));
       
   210 	  
       
   211 	//append filter to input param
       
   212 	TLiwGenericParam item( KFilter, TLiwVariant( cpdatamap ));
       
   213 	inParamList.AppendL( item );
       
   214     CleanupStack::PopAndDestroy( cpdatamap );
       
   215 	 
       
   216     iCpsInterface->ExecuteCmdL( KGetList, inParamList, outParamList);
       
   217 
       
   218     type.Reset();
       
   219 	item.Reset();
       
   220 	inParamList.Reset();
       
   221 	
       
   222 	//extracts data map
       
   223 	TInt pos = 0;
       
   224 	outParamList.FindFirst( pos, KResults );
       
   225 	if( pos != KErrNotFound )
       
   226 		// results present
       
   227 		{
       
   228 		//extract iterator on results list
       
   229 		TLiwVariant variant = (outParamList)[pos].Value();
       
   230 		variant.PushL();
       
   231 		CLiwIterable* iterable = variant.AsIterable();
       
   232 		iterable->Reset();
       
   233 		//get next result
       
   234 		if( iterable->NextL( variant ) )
       
   235 			{
       
   236 			//extract content map
       
   237 			CLiwDefaultMap *map = CLiwDefaultMap::NewLC();
       
   238 			variant.Get( *map );
       
   239 			if( map->FindL( KDataMap, variant) )
       
   240 				{
       
   241 				 variant.Get( *aOutDataMap );
       
   242 				}
       
   243 			CleanupStack::PopAndDestroy( map );
       
   244 			}
       
   245 		iterable->Reset();
       
   246 		CleanupStack::PopAndDestroy( &variant );
       
   247 		variant.Reset();
       
   248 		}
       
   249 	outParamList.Reset();
       
   250     	
       
   251     }
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // Gets the CPS messaging interface
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 void CContentPublisher::InitCpsInterfaceL()
       
   258     {
       
   259     if( !iServiceHandler )
       
   260         {
       
   261         iServiceHandler = CLiwServiceHandler::NewL();
       
   262         }
       
   263     
       
   264     CLiwGenericParamList& inParam = iServiceHandler->InParamListL();
       
   265     CLiwGenericParamList& outParam = iServiceHandler->OutParamListL();
       
   266     
       
   267     RCriteriaArray a;
       
   268     TCleanupItem item( DoResetAndDestroy, &a );
       
   269     CleanupStack::PushL( item );
       
   270     
       
   271     CLiwCriteriaItem* crit = CLiwCriteriaItem::NewLC( KLiwCmdAsStr, KCPInterface,
       
   272         KCPService  );
       
   273     crit->SetServiceClass( TUid::Uid(KLiwClassBase) );
       
   274     
       
   275     a.AppendL(crit);    
       
   276     
       
   277     CleanupStack::Pop( crit );
       
   278     
       
   279     iServiceHandler->AttachL(a);
       
   280     iServiceHandler->ExecuteServiceCmdL( *crit, inParam, outParam ); 
       
   281     
       
   282     CleanupStack::PopAndDestroy(); // item;
       
   283         
       
   284     // find service interface
       
   285     TInt pos = 0;
       
   286     MLiwInterface* msgInterface = NULL;
       
   287     outParam.FindFirst( pos, KCPInterface );
       
   288     if ( pos != KErrNotFound ) 
       
   289         {
       
   290         msgInterface = (outParam)[pos].Value().AsInterface(); 
       
   291         }
       
   292     outParam.Reset();
       
   293     inParam.Reset();
       
   294     iCpsInterface = msgInterface;
       
   295     }
       
   296 
       
   297 void CContentPublisher::RegisterListenerL()
       
   298 	{
       
   299 	CLiwGenericParamList& inparam = iServiceHandler->InParamListL();
       
   300 	CLiwGenericParamList& outparam =  iServiceHandler->OutParamListL();
       
   301 	CLiwDefaultMap*  reqFilter = CLiwDefaultMap::NewLC();
       
   302 	
       
   303 	// Listen all the information(contentId) from publisher 
       
   304 	reqFilter->InsertL( KPublisherId, TLiwVariant( KAI3HSPublisher ));
       
   305 	reqFilter->InsertL( KContentTypeId, TLiwVariant(KPublisher16 ));
       
   306 	
       
   307 	// Type of the registry  (content registry)
       
   308 	inparam.AppendL(TLiwGenericParam(KType, TLiwVariant(KCpData)));
       
   309 	// fill in input list for RequestNotification command
       
   310 	inparam.AppendL(TLiwGenericParam(KFilter, TLiwVariant(reqFilter)));
       
   311    
       
   312 	TRAP_IGNORE( iCpsInterface->ExecuteCmdL( 
       
   313 			KRequestNotification,
       
   314 				inparam,
       
   315 				outparam,
       
   316 				0,
       
   317 				this ) );
       
   318 	
       
   319 	outparam.Reset();
       
   320 	inparam.Reset();
       
   321 	CleanupStack::PopAndDestroy(reqFilter );  
       
   322 	}
       
   323 
       
   324 void CContentPublisher::UnRegisterListenerL()
       
   325 	{
       
   326 	CLiwGenericParamList& inparam = iServiceHandler->InParamListL();
       
   327 	CLiwGenericParamList& outparam =  iServiceHandler->OutParamListL();
       
   328  
       
   329 	// Unregister the reuqest notification 
       
   330 	TRAP_IGNORE( iCpsInterface->ExecuteCmdL( 
       
   331 			KRequestNotification,
       
   332 				inparam,
       
   333 				outparam,
       
   334 				KLiwOptCancel,
       
   335 				this ) ); 
       
   336 	
       
   337 	outparam.Reset();
       
   338 	inparam.Reset();
       
   339 	}
       
   340 
       
   341 TInt CContentPublisher::HandleNotifyL(
       
   342         TInt aErrorCode,
       
   343         TInt /*aEventId*/,
       
   344         CLiwGenericParamList& aEventParamList,
       
   345         const CLiwGenericParamList& /*aInParamList*/ )
       
   346    {
       
   347    TInt pos( 0 );
       
   348    aEventParamList.FindFirst(pos, KChangeInfo);
       
   349    if (pos != KErrNotFound)
       
   350     {
       
   351     // Get list of maps
       
   352     TLiwVariant variant = (aEventParamList)[pos].Value();
       
   353     variant.PushL();
       
   354     const CLiwList* changeMapsList = variant.AsList();
       
   355     // Iter through list content
       
   356     for (TInt i = 0; i < changeMapsList->Count() ; ++i)
       
   357 	    {
       
   358  		if ( changeMapsList->AtL(i, variant) ) 
       
   359  			{
       
   360 			const CLiwMap* map  = variant.AsMap();
       
   361 			if( map->FindL( KPublisherId, variant) )
       
   362 				 {
       
   363 				 HBufC* publisher = variant.AsDes().AllocLC();
       
   364 				 if ( publisher && ( publisher->Des() == KAI3HSPublisher ) 
       
   365 					  && map->FindL( KContentTypeId, variant) )
       
   366 					{
       
   367 					 HBufC* contentType = variant.AsDes().AllocLC();
       
   368 					 if ( contentType && ( contentType->Des() ==  KPublisher16 )
       
   369 						  && map->FindL( KContentId, variant ) )
       
   370 						 {
       
   371 						 HBufC* contentId = variant.AsDes().AllocLC();
       
   372 						 if ( contentId )
       
   373 							 {
       
   374 							 HandlePublisherInfoL( *contentId );
       
   375 							 }
       
   376 						 CleanupStack::PopAndDestroy( contentId );
       
   377 						 }
       
   378 					 CleanupStack::PopAndDestroy( contentType );
       
   379 					}
       
   380 			  CleanupStack::PopAndDestroy( publisher );
       
   381 				 }
       
   382 			}
       
   383 	   }
       
   384     CleanupStack::PopAndDestroy(&variant); 
       
   385     }
       
   386    return aErrorCode;
       
   387    }
       
   388 
       
   389 void CContentPublisher::HandlePublisherInfoL( const TDesC& aPubInfo)
       
   390 	{
       
   391 	//Currently HS will handle only network status update form publisher
       
   392 	if ( aPubInfo == KNetwork )
       
   393 		{
       
   394 		CLiwDefaultMap *outDataMap = CLiwDefaultMap::NewLC();
       
   395 		GetDataL( KAI3HSPublisher(), KPublisher16, KNetwork(), outDataMap );
       
   396 		TLiwVariant variant;
       
   397 		variant.PushL();
       
   398 		if ( outDataMap->FindL(KAPStatus, variant))
       
   399 			{
       
   400 			HBufC16* netStatus = variant.AsDes().AllocLC();
       
   401             if ( netStatus->Des() == KDisConnected() )
       
   402                 {
       
   403                 ShowGlobalQueryL(R_QTN_HS_DISABLE_NETWORK, EFalse );
       
   404                 }
       
   405             else if ( netStatus->Des() == KConnected() )
       
   406                 {
       
   407                 ShowGlobalQueryL(R_QTN_HS_SWITCH_ONLINE, ETrue );
       
   408                 }
       
   409 			CleanupStack::PopAndDestroy( netStatus );
       
   410 			}
       
   411 		CleanupStack::PopAndDestroy( &variant );
       
   412 		CleanupStack::PopAndDestroy(outDataMap);
       
   413 		}
       
   414     }
       
   415 
       
   416 
       
   417 void CContentPublisher::ShowGlobalQueryL( TInt aResourceId, TBool aSetOnline )
       
   418     {
       
   419     if ( !iGlobalQueryHandler->IsActive() )
       
   420         {
       
   421         HBufC* confirmationText = StringLoader::LoadLC(aResourceId);
       
   422         iGlobalConfirmationQuery->ShowConfirmationQueryL(
       
   423                 iGlobalQueryHandler->iStatus,
       
   424             *confirmationText, 
       
   425             R_AVKON_SOFTKEYS_YES_NO);
       
   426         iGlobalQueryHandler->SetOnlineParamAndActivate(aSetOnline);
       
   427         CleanupStack::PopAndDestroy(); //confirmationText
       
   428         }
       
   429     }
       
   430 // END OF FILE