webengine/wrtharvester/src/wrtharvester.cpp
changeset 10 a359256acfc6
parent 0 dd21522fd290
child 11 c8a366e56285
equal deleted inserted replaced
5:10e98eab6f85 10:a359256acfc6
    22 #include "wrtharvesterpsnotifier.h"
    22 #include "wrtharvesterpsnotifier.h"
    23 #include "wrtharvesterpublisherobserver.h"
    23 #include "wrtharvesterpublisherobserver.h"
    24 
    24 
    25 #include "wrtharvesterconst.h"
    25 #include "wrtharvesterconst.h"
    26 #include <widgetregistryconstants.h>
    26 #include <widgetregistryconstants.h>
       
    27 #include <wrtharvester.rsg>
    27 
    28 
    28 #include <implementationproxy.h>
    29 #include <implementationproxy.h>
    29 
    30 
    30 #include <LiwServiceHandler.h>
    31 #include <LiwServiceHandler.h>
    31 #include <LiwVariant.h>
    32 #include <LiwVariant.h>
    33 #include <e32property.h>    //Publish & Subscribe
    34 #include <e32property.h>    //Publish & Subscribe
    34 #include <AknTaskList.h>
    35 #include <AknTaskList.h>
    35 #include <apaid.h>
    36 #include <apaid.h>
    36 #include <apacmdln.h>
    37 #include <apacmdln.h>
    37 #include <s32mem.h>
    38 #include <s32mem.h>
    38 
    39 #include <APGTASK.H>
    39 
    40 #include <coemain.h>
    40 // TODO Check these types, should they be definedin sapidatapluginconst.h?
    41 #include <bautils.h>
    41 _LIT( KTemplatedWidget, "ai3templatedwidget");
    42 #include <f32file.h>
    42 _LIT8( KMySelected, "selected");
    43 #include <e32std.h>
    43 _LIT8( KMyActionMap, "action_map" );
    44 #include <AknNotify.h>
    44 _LIT8( KMyItem, "item" );
    45 #include <aknglobalconfirmationquery.h>
    45 _LIT8( KMyAdd, "Add" );
    46 #include <StringLoader.h>
    46 _LIT8( KMyDelete, "Delete" );
    47 #include <data_caging_path_literals.hrh>
    47 _LIT8( KMyItemId, "item_id" );
    48 
    48 _LIT8( KMyImage, "image" ); 
    49 // CONSTANTS
    49 _LIT( KMyContType, "wideimage" );
    50 _LIT( KResourceFileName, "\\resource\\wrtharvester.rsc" );
    50 _LIT8( KMyResultName,"mydata" );
    51 _LIT( KResourceDir, "Z:wrtharvester.rsc" );
    51 _LIT( KMyActionName, "data" );
    52 
       
    53 /**
       
    54 * Utility class to show the prompt for platform security access.
       
    55 *
       
    56 * The class exists only to provide platform security access prompt
       
    57 * for the widgets which are launched in minview 
       
    58 */
       
    59 class CGlobalQueryHandlerAO : public CActive
       
    60     {
       
    61 public:
       
    62     /**
       
    63     * Startup.
       
    64     *
       
    65     * @param aManager Window Manager.
       
    66     * @param aWindow Window.
       
    67     * @param aMessage Message to be prompted.
       
    68     * @param aSoftkeys for prompt.
       
    69     * @param aWrtHarvester for callback
       
    70     */
       
    71     static CGlobalQueryHandlerAO* StartLD (
       
    72                             TUid& aUid,
       
    73                             const TDesC& aMessage, 
       
    74                             TInt aSoftkeys,
       
    75                             CWrtHarvester* aWrtHarvester);
       
    76     /**
       
    77     * ShowGlobalQueryDialogL.
       
    78     *
       
    79     * @param aMessage Message to be prompted.
       
    80     * @param aSoftkeys for prompt.
       
    81     */
       
    82     void ShowGlobalQueryDialogL ( 
       
    83                             const TDesC& aMessage, 
       
    84                             TInt aSoftkeys );
       
    85 protected: // From CActive
       
    86     /**
       
    87     * Execute asynchronous operation.
       
    88     */
       
    89     void RunL();
       
    90     
       
    91     /**
       
    92     * Provide cancellation methods.
       
    93     */
       
    94     void DoCancel();
       
    95     
       
    96 private:
       
    97 
       
    98     /**
       
    99     * Constructor.
       
   100     *
       
   101     * @param aManager Manager.
       
   102     * @param aWindow Window.
       
   103     * @param aMessage Message for prompt.
       
   104     * @param aSoftkeys for prompt.
       
   105     * @param aWrtHarvester for callback    
       
   106     */
       
   107     CGlobalQueryHandlerAO (
       
   108             TUid& aUid,
       
   109             const TDesC& aMessage, 
       
   110             TInt aSoftkeys,
       
   111             CWrtHarvester* aWrtHarvester);
       
   112         
       
   113     /**
       
   114     * Destructor. 
       
   115     *
       
   116     * Private on purpose.
       
   117     */
       
   118     ~CGlobalQueryHandlerAO();
       
   119     
       
   120 private:
       
   121 
       
   122     TUid iWidgetUid;
       
   123     CAknGlobalConfirmationQuery* iGlobalConfirmationQuery ;
       
   124     HBufC* iConfirmationText;
       
   125     CWrtHarvester* iWrtHarvester;
       
   126     };
       
   127 
    52 // ============================= LOCAL FUNCTIONS ===============================
   128 // ============================= LOCAL FUNCTIONS ===============================
    53     
   129     
    54 // ----------------------------------------------------------------------------
   130 // ----------------------------------------------------------------------------
    55 // ta
   131 // Returns the app full name
    56 // ----------------------------------------------------------------------------
   132 // ----------------------------------------------------------------------------
    57 //
   133 //
    58 static HBufC* GetAppNameLC( RApaLsSession& aSession, const TUid& aUid )
   134 static HBufC* GetAppNameLC( RApaLsSession& aSession, const TUid& aUid )
    59     {
   135     {
    60     TApaAppInfo info;
   136     TApaAppInfo info;
    63     return info.iFullName.AllocLC();
   139     return info.iFullName.AllocLC();
    64     }
   140     }
    65     
   141     
    66     
   142     
    67 // ----------------------------------------------------------------------------
   143 // ----------------------------------------------------------------------------
    68 // 
   144 // Sends the command to Widget launcher
    69 // ----------------------------------------------------------------------------
   145 // ----------------------------------------------------------------------------
    70 //
   146 //
    71 static void HandleWidgetCommandL( 
   147 static void HandleWidgetCommandL( 
    72     RApaLsSession& aSession, 
   148     RApaLsSession& aSession, 
    73     const TDesC& aWidget,
   149     const TDesC& aWidget,
   130 // ----------------------------------------------------------------------------
   206 // ----------------------------------------------------------------------------
   131 // Constructor
   207 // Constructor
   132 // ----------------------------------------------------------------------------
   208 // ----------------------------------------------------------------------------
   133 //
   209 //
   134 CWrtHarvester::CWrtHarvester( MLiwInterface* aCPSInterface ):
   210 CWrtHarvester::CWrtHarvester( MLiwInterface* aCPSInterface ):
   135     iCPSInterface( aCPSInterface )
   211     iCPSInterface( aCPSInterface ),
       
   212     iHSCount(0)
   136 	{
   213 	{
   137 	}
   214 	}
   138 
   215 
   139 // ----------------------------------------------------------------------------
   216 // ----------------------------------------------------------------------------
   140 // Symbian 2nd phase constructor can leave.
   217 // Symbian 2nd phase constructor can leave.
   144     {
   221     {
   145     User::LeaveIfError( iApaSession.Connect() );
   222     User::LeaveIfError( iApaSession.Connect() );
   146     iWidgetUIListener = CWrtHarvesterPSNotifier::NewL( this, EWidgetUIState );
   223     iWidgetUIListener = CWrtHarvesterPSNotifier::NewL( this, EWidgetUIState );
   147     iWidgetRegListener = CWrtHarvesterPSNotifier::NewL( this, EWidgetRegAltered );
   224     iWidgetRegListener = CWrtHarvesterPSNotifier::NewL( this, EWidgetRegAltered );
   148     iWidgetMMCListener =  CWrtHarvesterPSNotifier::NewL( this, EWidgetMMCAltered );
   225     iWidgetMMCListener =  CWrtHarvesterPSNotifier::NewL( this, EWidgetMMCAltered );
       
   226     iWidgetUsbListener = CWrtHarvesterPSNotifier::NewL( this, EWidgetMassStorageMode );
       
   227     
       
   228     TFileName resourceFileName;  
       
   229     TParse parse;    
       
   230     Dll::FileName (resourceFileName);           
       
   231     parse.Set(KResourceFileName, &resourceFileName, NULL); 
       
   232     resourceFileName = parse.FullName(); 
       
   233           
       
   234     CCoeEnv* coeEnv = CCoeEnv::Static(); 
       
   235     BaflUtils::NearestLanguageFile(coeEnv->FsSession(), resourceFileName); 
       
   236        
       
   237     if ( !BaflUtils::FileExists( coeEnv->FsSession(), resourceFileName ) )
       
   238         { 
       
   239         // Use resource file on the Z drive instead  
       
   240         parse.Set( KResourceDir, &KDC_RESOURCE_FILES_DIR, NULL ); 
       
   241         resourceFileName = parse.FullName();  
       
   242         BaflUtils::NearestLanguageFile( coeEnv->FsSession(),resourceFileName );            
       
   243         } 
       
   244     iResourceFileOffset = coeEnv->AddResourceFileL(resourceFileName);
   149     }
   245     }
   150 
   246 
   151 // ----------------------------------------------------------------------------
   247 // ----------------------------------------------------------------------------
   152 // Two-phased constructor.
   248 // Two-phased constructor.
   153 // ----------------------------------------------------------------------------
   249 // ----------------------------------------------------------------------------
   165 // Destructor
   261 // Destructor
   166 // ---------------------------------------------------------------------------
   262 // ---------------------------------------------------------------------------
   167 //
   263 //
   168 CWrtHarvester::~CWrtHarvester()
   264 CWrtHarvester::~CWrtHarvester()
   169     {
   265     {
       
   266     if ( iResourceFileOffset )
       
   267         {
       
   268         CCoeEnv::Static()->DeleteResourceFile( iResourceFileOffset );
       
   269         }
   170     iObservers.ResetAll();
   270     iObservers.ResetAll();
       
   271     iWidgetInfo.ResetAll();
       
   272     iWidgetStateArray.ResetAll();
   171     delete iWidgetUIListener;
   273     delete iWidgetUIListener;
   172     delete iWidgetRegListener;
   274     delete iWidgetRegListener;
   173     delete iWidgetMMCListener;
   275     delete iWidgetMMCListener;
   174     iWidgetUids.Close();
   276     delete iWidgetUsbListener;
       
   277     iWidgetOperations.Close();
   175     iApaSession.Close();
   278     iApaSession.Close();
   176     }
   279     }
   177     
   280     
   178 // ----------------------------------------------------------------------------
   281 // ----------------------------------------------------------------------------
   179 // 
   282 // Is called by Content Harvester server
   180 // ----------------------------------------------------------------------------
   283 // ----------------------------------------------------------------------------
   181 //	
   284 //	
   182 void CWrtHarvester::UpdateL() 
   285 void CWrtHarvester::UpdateL() 
   183 	{
   286 	{
   184 	UpdatePublishersL();
   287 	UpdatePublishersL();
   185 	} 
   288 	} 
   186 
   289 
   187 // ----------------------------------------------------------------------------
   290 // ----------------------------------------------------------------------------
   188 // 
   291 // Is called when Homescreen sends events to publisher
   189 // ----------------------------------------------------------------------------
   292 // ----------------------------------------------------------------------------
   190 //  
   293 //  
   191 void CWrtHarvester::HandlePublisherNotificationL( const TDesC& aContentId, const TDesC8& aTrigger )
   294 void CWrtHarvester::HandlePublisherNotificationL( const TDesC& aContentId, const TDesC8& aTrigger )
   192     {
   295     {
   193     TUid uid( iRegistryAccess.WidgetUid( aContentId ) );
   296     TUid uid( WidgetUid( aContentId ) );
   194     if( aTrigger == KActive() )
   297     TWidgetOperations operation( Uninitialized );
   195         {
   298     if( aTrigger == KActive )
   196         StartWidgetL( uid );
   299         {
   197         }
   300         iHSCount++;	
   198     else
   301         // queue the activated state event only for network accessing widgets
   199         {
   302         if ( CheckNetworkAccessL( uid) )
   200         TWidgetOperations operation( Uninitialized );
   303             {
   201         if ( aTrigger == KDeActive )
   304             TWrtState* widgetState = NULL;
   202             {
   305             widgetState = new TWrtState( uid, EActivatedState );
   203             operation = Deactivate;
   306             if ( widgetState )
   204             }
   307                 {
   205         else if( aTrigger == KSuspend )
   308                 iWidgetStateArray.AppendL( widgetState );
   206             {
   309                 }
   207             operation = WidgetSuspend;
   310             }
   208             }
   311         
   209         else if( aTrigger == KResume )
   312         operation = LaunchMiniview;
   210             {
   313         }
   211             operation = WidgetResume;
   314     else if ( aTrigger == KDeActive )
   212             }
   315         {
   213         else if( aTrigger == KMySelected )
   316         iHSCount--;
   214             {
   317         operation = Deactivate;
   215             operation = WidgetSelect;
   318         }
   216             }
   319     else if( aTrigger == KSuspend )
   217         LaunchWidgetL( operation, uid );
   320         {
   218         }
   321         operation = WidgetSuspend;
       
   322         }
       
   323     else if( aTrigger == KResume )
       
   324         {
       
   325         TInt idx = FindWidget( uid );
       
   326         
       
   327         // if unable to find the widget, queue the resume as usual
       
   328         if ( idx == -1 )
       
   329             {
       
   330             QueueResumeL( uid );
       
   331             }
       
   332         else
       
   333             {
       
   334             iWidgetStateArray[idx]->iState = EResumeState;
       
   335             }
       
   336         return;
       
   337         }
       
   338     else if( aTrigger == KSelected )
       
   339         {
       
   340         operation = WidgetSelect;
       
   341         }
       
   342     else if( aTrigger == KHSOnline )
       
   343         {
       
   344         ProcessNetworkModeL( uid, WidgetOnline );
       
   345         return;
       
   346         }
       
   347     else if( aTrigger == KHSOffline )
       
   348         {
       
   349         ProcessNetworkModeL( uid, WidgetOffline );
       
   350         return;
       
   351         }
       
   352     QueueOperationL( operation, uid );
   219     }
   353     }
   220 
   354 
   221 // ----------------------------------------------------------------------------
   355 // ----------------------------------------------------------------------------
   222 // 
   356 // 
   223 // ----------------------------------------------------------------------------
   357 // ----------------------------------------------------------------------------
   224 //
   358 //
   225 void CWrtHarvester::UpdatePublishersL() 
   359 void CWrtHarvester::UpdatePublishersL() 
   226     {
   360     {
   227     RPointerArray< HBufC > bundleNames;
   361     iRegistryAccess.WidgetInfosL( iWidgetInfo );
   228     
   362     RemoveObsoletePublishersL();
   229     // The array contain references.
   363     
   230     CleanupClosePushL( bundleNames );
   364     for( TInt i = iWidgetInfo.Count() - 1; i >= 0; --i )
   231     
   365         {
   232     iRegistryAccess.WidgetBundleNamesL( bundleNames );
   366         // Register the observer first as notification may be
       
   367         // received immediately after registration
       
   368         RequestForNotificationL( *iWidgetInfo[i] );
       
   369         TInt id = RegisterPublisherL( *iWidgetInfo[i] );
       
   370         if( id == KErrNotFound )
       
   371             {
       
   372             // remove the observer as the publisher registration failed
       
   373             RemoveObserver( *iWidgetInfo[i]->iBundleId);
       
   374             }
       
   375         }
       
   376     }
       
   377 
       
   378 // ----------------------------------------------------------------------------
       
   379 // 
       
   380 // ----------------------------------------------------------------------------
       
   381 //
       
   382 void CWrtHarvester::RemoveObsoletePublishersL() 
       
   383     {
       
   384     RWrtArray<HBufC> publishers;
       
   385     publishers.PushL();
       
   386     RegisteredPublishersL( publishers );
   233     
   387     
   234     // Remove observer and CPS registry entry of uninstalled widget
   388     // Remove observer and CPS registry entry of uninstalled widget
   235     for( TInt i = 0; i < iObservers.Count(); i++ )
   389     TInt count = publishers.Count();
       
   390     for( TInt i = count - 1; i >= 0; --i )
   236         {
   391         {
   237         TBool found( EFalse );
   392         TBool found( EFalse );
   238         for( TInt j = 0; j < bundleNames.Count(); j++ )
   393         for( TInt j = 0; j < iWidgetInfo.Count(); j++ )
   239             {
   394             {
   240             if( iObservers[i]->Name() == bundleNames[j] )
   395             if( *publishers[i] == iWidgetInfo[j]->iBundleId )
   241                 {
   396                 {
   242                 found = ETrue;
   397                 found = ETrue;
   243                 break;
   398                 break;
   244                 }
   399                 }
   245             }
   400             }
   246         if( found == EFalse )
   401         if( found == EFalse )
   247             {
   402             {
   248             RemovePublisherL( KTemplatedWidget, iObservers[i]->Name(), KMyContType );
   403             RemovePublisherAndObserverL( *publishers[i] );
   249             delete iObservers[i];
   404             }
   250             iObservers.Remove( i );
   405         }
   251             }
   406     CleanupStack::PopAndDestroy( &publishers );
   252         }
   407     }
   253     
   408 
   254     for( TInt i = bundleNames.Count() - 1; i >= 0; --i )
   409 // ----------------------------------------------------------------------------
   255         {
   410 // 
   256         TInt id = RegisterPublisherL( 
   411 // ----------------------------------------------------------------------------
   257             KTemplatedWidget,
   412 //
   258             *( bundleNames[ i ] ), 
   413 void CWrtHarvester::RegisteredPublishersL( RPointerArray<HBufC>& publishers )
   259             KMyContType, 
   414     {
   260             KMyImage );
   415     publishers.ResetAndDestroy();
       
   416 
       
   417     CLiwGenericParamList* publisherList( CLiwGenericParamList::NewLC() );
       
   418     CLiwGenericParamList* inParamList( CLiwGenericParamList::NewLC() );
       
   419     
       
   420     TLiwGenericParam type( KType, TLiwVariant( KPubData ));
       
   421     inParamList->AppendL( type );
       
   422     
       
   423     CLiwDefaultMap* filter = CLiwDefaultMap::NewLC();
       
   424     
       
   425     filter->InsertL( KPublisherId, TLiwVariant( KWRTPublisher ) );
       
   426     filter->InsertL( KContentType, TLiwVariant( KTemplatedWidget ) );
       
   427      
       
   428     //append filter to input param
       
   429     TLiwGenericParam item( KFilter, TLiwVariant( filter ));
       
   430     inParamList->AppendL( item );
       
   431        
       
   432     // Get all publishers from CPS
       
   433     iCPSInterface->ExecuteCmdL( KGetList, *inParamList, *publisherList ); 
       
   434     CleanupStack::PopAndDestroy( filter );
       
   435     CleanupStack::PopAndDestroy( inParamList );
       
   436     
       
   437     TInt pos = 0;
       
   438     publisherList->FindFirst( pos, KResults );
       
   439     if( pos != KErrNotFound )
       
   440         {
       
   441         //extract iterator on results list
       
   442         TLiwVariant variant = (*publisherList)[pos].Value();
       
   443         CLiwIterable* iterable = variant.AsIterable();
       
   444         iterable->Reset();
       
   445         
       
   446         //get all the templated widget publishers
       
   447         while( iterable->NextL( variant ) )
       
   448             {
       
   449             //extract content map
       
   450             CLiwDefaultMap* publisherMap = CLiwDefaultMap::NewLC();         
       
   451             variant.Get( *publisherMap );
       
   452             variant.Reset();
       
   453              
       
   454             if( publisherMap && publisherMap->FindL( KContentId , variant ))
       
   455                 {
       
   456                  HBufC* bundleId = variant.AsDes().AllocLC();
       
   457                  publishers.AppendL( bundleId );
       
   458                  CleanupStack::Pop( bundleId );
       
   459                  }
       
   460              CleanupStack::PopAndDestroy( publisherMap );     
       
   461              }
   261             
   462             
   262         if( id != KErrNotFound )
   463         variant.Reset();
   263             {
   464         }
   264             RequestForNotificationL( KTemplatedWidget, *( bundleNames[ i ] ), KMyContType );
   465     CleanupStack::PopAndDestroy( publisherList );
   265             }
   466     }
   266         }
   467 
   267         
   468 // ----------------------------------------------------------------------------
   268     CleanupStack::PopAndDestroy( &bundleNames ); 
   469 // 
   269     }
   470 // ----------------------------------------------------------------------------
   270 
   471 //
   271 // ----------------------------------------------------------------------------
   472 TInt CWrtHarvester::RegisterPublisherL( CWrtInfo& wrtInfo )
   272 // 
   473     {
   273 // ----------------------------------------------------------------------------
   474     TBool networkAccess = CheckNetworkAccessL( wrtInfo.iUid );
   274 //
   475     
   275 TInt CWrtHarvester::RegisterPublisherL( 
   476     __UHEAP_MARK;
   276     const TDesC& aPublisherId, 
       
   277     const TDesC& aContentId,
       
   278     const TDesC& aContentType, 
       
   279     const TDesC8& aResultType )
       
   280     {
       
   281     TInt id( KErrNotFound );
   477     TInt id( KErrNotFound );
   282     if( iCPSInterface )
   478     if( iCPSInterface )
   283         {   
   479         {   
   284         CLiwGenericParamList* inparam( CLiwGenericParamList::NewLC() );
   480         CLiwGenericParamList* inparam( CLiwGenericParamList::NewLC() );
   285         CLiwGenericParamList* outparam( CLiwGenericParamList::NewLC() );
   481         CLiwGenericParamList* outparam( CLiwGenericParamList::NewLC() );
   289         CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC();
   485         CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC();
   290         CLiwDefaultMap* datamap = CLiwDefaultMap::NewLC();
   486         CLiwDefaultMap* datamap = CLiwDefaultMap::NewLC();
   291         CLiwDefaultMap* actionmap( NULL );
   487         CLiwDefaultMap* actionmap( NULL );
   292 
   488 
   293         // Create the data map for publisher registry
   489         // Create the data map for publisher registry
   294         cpdatamap->InsertL( KContentType, TLiwVariant( aContentType ));
   490         cpdatamap->InsertL( KPublisherId, TLiwVariant( KWRTPublisher ));
   295         cpdatamap->InsertL( KContentId, TLiwVariant( aContentId ));
   491         cpdatamap->InsertL( KContentType, TLiwVariant( KTemplatedWidget ));
   296         cpdatamap->InsertL( KPublisherId, TLiwVariant( aPublisherId ));
   492         cpdatamap->InsertL( KContentId, TLiwVariant( wrtInfo.iBundleId ));
   297         datamap->InsertL( KMyResultName, TLiwVariant( aResultType ));
   493         // Widget info map
       
   494     	CLiwDefaultMap* widgetInfo = CLiwDefaultMap::NewLC();
       
   495 		widgetInfo->InsertL( KTemplateType, TLiwVariant( KTemplateName ));
       
   496 		widgetInfo->InsertL( KWidgetName, TLiwVariant( wrtInfo.iDisplayName ));
       
   497 		datamap->InsertL( KWidgetInfo , TLiwVariant( widgetInfo ));
       
   498 		CleanupStack::PopAndDestroy( widgetInfo );
       
   499         
       
   500 		// Take dynamic menu items into use
       
   501 		if (networkAccess)
       
   502 		    {
       
   503 		    CLiwDefaultMap* mapMenu = CLiwDefaultMap::NewLC();
       
   504 		    mapMenu->InsertL( KItemOnlineOffline, TLiwVariant( KMyActionName ));
       
   505 		    datamap->InsertL( KMenuItems, TLiwVariant( mapMenu ));
       
   506 		    CleanupStack::PopAndDestroy(mapMenu);
       
   507 		    }
   298 
   508 
   299         cpdatamap->InsertL( KDataMap, TLiwVariant(datamap) );
   509         cpdatamap->InsertL( KDataMap, TLiwVariant(datamap) );
   300         
   510         
   301         // Create the action map for publisher registry
   511         // Create the action map for publisher registry
   302         actionmap = CLiwDefaultMap::NewLC();
   512         actionmap = CLiwDefaultMap::NewLC();
   303         actionmap->InsertL(KActive, TLiwVariant( KMyActionName ));
   513         actionmap->InsertL( KActive, TLiwVariant( KMyActionName ));
   304         actionmap->InsertL(KDeActive, TLiwVariant( KMyActionName ));
   514         actionmap->InsertL( KDeActive, TLiwVariant( KMyActionName ));
   305         actionmap->InsertL(KSuspend, TLiwVariant( KMyActionName ));
   515         actionmap->InsertL( KSuspend, TLiwVariant( KMyActionName ));
   306         actionmap->InsertL(KResume, TLiwVariant( KMyActionName ));
   516         actionmap->InsertL( KResume, TLiwVariant( KMyActionName ));
   307         actionmap->InsertL(KMySelected, TLiwVariant( KMyActionName ));
   517         actionmap->InsertL( KSelected, TLiwVariant( KMyActionName ));
       
   518         if (networkAccess)
       
   519             {
       
   520             actionmap->InsertL( KHSOnline, TLiwVariant( KMyActionName ));
       
   521             actionmap->InsertL( KHSOffline, TLiwVariant( KMyActionName ));
       
   522             }
   308  
   523  
   309         cpdatamap->InsertL( KMyActionMap, TLiwVariant(actionmap));
   524         cpdatamap->InsertL( KMyActionMap, TLiwVariant(actionmap));
   310         CleanupStack::PopAndDestroy( actionmap );
   525         CleanupStack::PopAndDestroy( actionmap );
   311         
   526         
   312         TLiwGenericParam item( KMyItem, TLiwVariant( cpdatamap ));        
   527         TLiwGenericParam item( KMyItem, TLiwVariant( cpdatamap ));        
   319         CleanupStack::PopAndDestroy( cpdatamap );
   534         CleanupStack::PopAndDestroy( cpdatamap );
   320         item.Reset();
   535         item.Reset();
   321         type.Reset();   
   536         type.Reset();   
   322         CleanupStack::PopAndDestroy(outparam);
   537         CleanupStack::PopAndDestroy(outparam);
   323         CleanupStack::PopAndDestroy(inparam);
   538         CleanupStack::PopAndDestroy(inparam);
   324         }   
   539         }
       
   540     __UHEAP_MARKEND;
   325     return id;
   541     return id;
   326     }
   542     }
   327 
   543 
   328 // ----------------------------------------------------------------------------
   544 // ----------------------------------------------------------------------------
   329 // 
   545 // 
   330 // ----------------------------------------------------------------------------
   546 // ----------------------------------------------------------------------------
   331 //
   547 //
   332 void CWrtHarvester::RemovePublisherL( const TDesC& aPublisherId, const TDesC& aContentId,
   548 void CWrtHarvester::RemoveObserver(const TDesC& aBundleId)
   333         const TDesC& aContentType )
   549 	{
   334     {
   550 	TInt count = iObservers.Count();
       
   551 	for( TInt i = 0; i < count; i++ )
       
   552 		{
       
   553 		if( iObservers[i]->BundleId() == aBundleId )
       
   554 			{
       
   555 			delete iObservers[i];
       
   556 			iObservers.Remove( i );
       
   557 			break;
       
   558 			}
       
   559 		}
       
   560 	}
       
   561 // ----------------------------------------------------------------------------
       
   562 // 
       
   563 // ----------------------------------------------------------------------------
       
   564 //
       
   565 void CWrtHarvester::RemovePublisherAndObserverL( const TDesC& aBundleId )
       
   566     {
       
   567     RemoveObserver( aBundleId );
       
   568     
       
   569     __UHEAP_MARK;
   335     if( iCPSInterface )
   570     if( iCPSInterface )
   336         {
   571         {
   337         CLiwGenericParamList* inparam = CLiwGenericParamList::NewLC();
   572         CLiwGenericParamList* inparam = CLiwGenericParamList::NewLC();
   338         CLiwGenericParamList* outparam = CLiwGenericParamList::NewLC();
   573         CLiwGenericParamList* outparam = CLiwGenericParamList::NewLC();
   339         TLiwGenericParam type( KType, TLiwVariant( KPubData ));
   574         TLiwGenericParam type( KType, TLiwVariant( KPubData ));
   340         inparam->AppendL( type );
   575         inparam->AppendL( type );
   341         CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC();
   576         CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC();
   342         CLiwDefaultMap* datamap = CLiwDefaultMap::NewLC();
   577         CLiwDefaultMap* datamap = CLiwDefaultMap::NewLC();
   343 
   578 
   344         // Create data map
   579         // Create data map
   345         cpdatamap->InsertL( KContentType, TLiwVariant( aContentType ));
   580         cpdatamap->InsertL( KPublisherId, TLiwVariant( KWRTPublisher ));
   346         cpdatamap->InsertL( KContentId, TLiwVariant( aContentId ));
   581         cpdatamap->InsertL( KContentType, TLiwVariant( KTemplatedWidget ));
   347         cpdatamap->InsertL( KPublisherId, TLiwVariant( aPublisherId ));
   582         cpdatamap->InsertL( KContentId, TLiwVariant( aBundleId ));
   348         
   583         
   349         cpdatamap->InsertL( KDataMap, TLiwVariant(datamap) );
   584         cpdatamap->InsertL( KDataMap, TLiwVariant(datamap) );
   350         
   585         
   351         TLiwGenericParam item( KMyItem, TLiwVariant( cpdatamap ));        
   586         TLiwGenericParam item( KMyItem, TLiwVariant( cpdatamap ));        
   352         inparam->AppendL( item );
   587         inparam->AppendL( item );
   357         item.Reset();
   592         item.Reset();
   358         type.Reset();
   593         type.Reset();
   359         CleanupStack::PopAndDestroy(outparam);
   594         CleanupStack::PopAndDestroy(outparam);
   360         CleanupStack::PopAndDestroy(inparam);
   595         CleanupStack::PopAndDestroy(inparam);
   361         }
   596         }
   362     }
   597     __UHEAP_MARKEND;
   363 
   598     }
   364 // ----------------------------------------------------------------------------
   599 
   365 // 
   600 // ----------------------------------------------------------------------------
   366 // ----------------------------------------------------------------------------
   601 // 
   367 //
   602 // ----------------------------------------------------------------------------
   368 void CWrtHarvester::RequestForNotificationL( const TDesC& aPublisherId, const TDesC& aContentId,
   603 //
   369         const TDesC& aContentType )
   604 void CWrtHarvester::RequestForNotificationL( CWrtInfo& wrtInfo )
   370     {
   605     {
   371     // Preventing duplicate entries.
   606     // Preventing duplicate entries.
   372     for( TInt i = 0; i < iObservers.Count(); i++ )
   607     for( TInt i = 0; i < iObservers.Count(); i++ )
   373         {
   608         {
   374         if( iObservers[i]->Name() == aContentId )
   609         if( iObservers[i]->BundleId() == wrtInfo.iBundleId )
   375             {
   610             {
   376             return;
   611             return;
   377             }
   612             }
   378         }
   613         }
   379     
   614     
   380     CWrtHarvesterPublisherObserver* observer( NULL );
   615     CWrtHarvesterPublisherObserver* observer( NULL );
   381     CLiwDefaultMap* filter = CLiwDefaultMap::NewLC();
   616     CLiwDefaultMap* filter = CLiwDefaultMap::NewLC();
   382     
   617     
   383     filter->InsertL( KPublisherId, TLiwVariant( aPublisherId ) );
   618     filter->InsertL( KPublisherId, TLiwVariant( KWRTPublisher ) );
   384     filter->InsertL( KContentId, TLiwVariant( aContentId ) );
   619     filter->InsertL( KContentType, TLiwVariant( KTemplatedWidget ) );
   385     filter->InsertL( KContentType, TLiwVariant( aContentType ) );
   620     filter->InsertL( KContentId, TLiwVariant( wrtInfo.iBundleId ) );
   386     filter->InsertL( KOperation, TLiwVariant( KExecute ));
   621     filter->InsertL( KOperation, TLiwVariant( KExecute ));
   387     
   622     
   388     observer = CWrtHarvesterPublisherObserver::NewLC( aContentId, this );
   623     observer = CWrtHarvesterPublisherObserver::NewLC( *wrtInfo.iBundleId, this );
   389     observer->RegisterL(filter);
   624     observer->RegisterL(filter);
   390     
   625     
   391     iObservers.AppendL( observer );
   626     iObservers.AppendL( observer );
   392     
   627     
   393     CleanupStack::Pop( observer );
   628     CleanupStack::Pop( observer );
   397     
   632     
   398 // ----------------------------------------------------------------------------
   633 // ----------------------------------------------------------------------------
   399 // 
   634 // 
   400 // ----------------------------------------------------------------------------
   635 // ----------------------------------------------------------------------------
   401 //
   636 //
   402 void CWrtHarvester::StartWidgetL( TUid aUid )
   637 void CWrtHarvester::QueueOperationL( TWidgetOperations aOperation, TUid aUid )
   403     {
   638     {
   404     iWidgetUids.Append( aUid );
   639     //Hack to find out if WidgetUi exist as Queue keeps filling up
   405     TryLaunchNextWidgetL();
   640     if((iHSCount*3 <= iWidgetOperations.Count() && !CheckTaskExistsL()) || (aOperation == WidgetSelect))
   406     }
   641         {
   407 
   642         ClearAllOperations();
   408 // ----------------------------------------------------------------------------
   643         iWidgetUIListener->SetValue(1);
   409 // 
   644         }        
   410 // ----------------------------------------------------------------------------
   645     SWidgetOperation op = { aOperation, aUid };
   411 //
   646     iWidgetOperations.Append( op );
   412 void CWrtHarvester::TryLaunchNextWidgetL()
   647     TryLaunchNextOperationL();
       
   648     }
       
   649 
       
   650 // ----------------------------------------------------------------------------
       
   651 // 
       
   652 // ----------------------------------------------------------------------------
       
   653 //
       
   654 TBool CWrtHarvester::CheckTaskExistsL()
       
   655     {
       
   656     TUid widgetAppUid( TUid::Uid( KWidgetAppUid ) );
       
   657     RWsSession wsSession;    
       
   658         
       
   659     // Create Window server session
       
   660     User::LeaveIfError( wsSession.Connect() );
       
   661     
       
   662     TApaTaskList taskList( wsSession );
       
   663     TApaTask task = taskList.FindApp( widgetAppUid );
       
   664     return task.Exists()?ETrue:EFalse;
       
   665     }
       
   666     
       
   667 
       
   668 // ----------------------------------------------------------------------------
       
   669 // 
       
   670 // ----------------------------------------------------------------------------
       
   671 //
       
   672 void CWrtHarvester::TryLaunchNextOperationL()
   413     {
   673     {
   414     TInt value = KErrNone;
   674     TInt value = KErrNone;
   415     TInt error = iWidgetUIListener->GetValue(value);
   675     TInt error = iWidgetUIListener->GetValue(value);
   416     if( error == KErrNone && value == 1 && iWidgetUids.Count() != 0 )
   676     if( error == KErrNone && value == 1 && iWidgetOperations.Count() != 0 )
   417         {
   677         {
   418         // Set value to 0 so that next widget is not launched before Widget App sets value to 1.
   678         // Set value to 0 so that next widget is not launched before Widget App sets value to 1.
   419         iWidgetUIListener->SetValue( 0 );
   679         iWidgetUIListener->SetValue( 0 );
   420         //Always launch the first widget
   680         //Always launch the first in operation
   421         LaunchWidgetL( LaunchMiniview, iWidgetUids[0] );
   681         LaunchWidgetOperationL( iWidgetOperations[0] );
   422         iWidgetUids.Remove( 0 );
   682         iWidgetOperations.Remove( 0 );
   423         }
   683         }
       
   684     }
       
   685 
       
   686 void CWrtHarvester::ClearAllOperations()
       
   687     {
       
   688     TInt value = KErrNone;
       
   689     TInt error = iWidgetUIListener->GetValue(value);
       
   690     if( error == KErrNone )
       
   691         {
       
   692         iWidgetOperations.Reset();
       
   693         }
       
   694     }
       
   695 // ----------------------------------------------------------------------------
       
   696 // 
       
   697 // ----------------------------------------------------------------------------
       
   698 //
       
   699 TUid CWrtHarvester::WidgetUid( TPtrC aBundleId )
       
   700     {
       
   701     TInt count( iWidgetInfo.Count());
       
   702     TUid uid = {0};
       
   703     for( TInt i = 0; i < count; i++ )
       
   704         {
       
   705         if( iWidgetInfo[i]->iBundleId == aBundleId )
       
   706             {
       
   707             uid = iWidgetInfo[i]->iUid;
       
   708             break;
       
   709             }
       
   710         }
       
   711     return uid;
   424     }
   712     }
   425 
   713 
   426 // ----------------------------------------------------------------------------
   714 // ----------------------------------------------------------------------------
   427 // 
   715 // 
   428 // ----------------------------------------------------------------------------
   716 // ----------------------------------------------------------------------------
   446 
   734 
   447 // ----------------------------------------------------------------------------
   735 // ----------------------------------------------------------------------------
   448 // 
   736 // 
   449 // ----------------------------------------------------------------------------
   737 // ----------------------------------------------------------------------------
   450 //
   738 //
   451 void CWrtHarvester::LaunchWidgetL( TWidgetOperations aOperation, TUid aUid )
   739 void CWrtHarvester::LaunchWidgetOperationL( SWidgetOperation aOperation )
   452     {
   740     {
   453     HBufC* widgetName( GetAppNameLC( iApaSession, aUid) );
   741     HBufC* widgetName( GetAppNameLC( iApaSession, aOperation.iUid) );
   454     HandleWidgetCommandL( iApaSession, *widgetName, aUid, aOperation );
   742     HandleWidgetCommandL( iApaSession, *widgetName, aOperation.iUid, aOperation.iOperation );
   455     CleanupStack::PopAndDestroy( widgetName );
   743     CleanupStack::PopAndDestroy( widgetName );
   456     }
   744     }
   457 
   745 
       
   746 // ----------------------------------------------------------------------------
       
   747 // 
       
   748 // ----------------------------------------------------------------------------
       
   749 //
       
   750 void CWrtHarvester::QueueResumeL( TUid& aUid )
       
   751     {
       
   752     RWidgetRegistryClientSession session;
       
   753     CleanupClosePushL( session );
       
   754     User::LeaveIfError( session.Connect() );
       
   755     if ( session.IsBlanketPermGranted ( aUid ) == EBlanketUnknown && !iDialogShown )
       
   756         {
       
   757         iDialogShown = ETrue;            
       
   758         AllowPlatformAccessL( aUid );
       
   759         }
       
   760     else if(!iDialogShown)
       
   761         {
       
   762         QueueOperationL( WidgetResume, aUid );
       
   763         }        
       
   764     CleanupStack::PopAndDestroy( &session );
       
   765     }
       
   766 
       
   767 // ----------------------------------------------------------------------------
       
   768 // 
       
   769 // ----------------------------------------------------------------------------
       
   770 //
       
   771 void CWrtHarvester::ProcessNetworkModeL( TUid& aUid, TWidgetOperations aOperation )
       
   772     {
       
   773     // first queue the online/offline event and then the resume event
       
   774     QueueOperationL( aOperation, aUid );
       
   775     
       
   776     // check if there is a resume event to queue
       
   777     TInt idx = FindWidget(aUid, EResumeState);
       
   778     if ( idx != -1 )
       
   779         {
       
   780         QueueResumeL( aUid );          
       
   781         }
       
   782     idx = (idx == -1) ? FindWidget(aUid): idx;
       
   783     if(idx != -1 )
       
   784         {
       
   785         // remove it from the array, no longer needed
       
   786         delete iWidgetStateArray[idx];
       
   787         iWidgetStateArray.Remove(idx);
       
   788         }
       
   789     }
       
   790 
       
   791 // ----------------------------------------------------------------------------
       
   792 // 
       
   793 // ----------------------------------------------------------------------------
       
   794 //
       
   795 TInt CWrtHarvester::FindWidget( TUid& aUid, TWidgetState aState )
       
   796     {
       
   797     TInt idx = -1;
       
   798     for( TInt i( iWidgetStateArray.Count() - 1 ); i >= 0; --i )
       
   799         {
       
   800         if ( ( iWidgetStateArray[i]->iUid == aUid ) && ( iWidgetStateArray[i]->iState == aState ) )
       
   801             {
       
   802             idx = i;
       
   803             }
       
   804         }
       
   805     return idx;
       
   806     }
       
   807 
       
   808 // ----------------------------------------------------------------------------
       
   809 // 
       
   810 // ----------------------------------------------------------------------------
       
   811 //
       
   812 TInt CWrtHarvester::FindWidget( TUid& aUid )
       
   813     {
       
   814     TInt idx = -1;
       
   815     for( TInt i( iWidgetStateArray.Count() - 1 ); i >= 0; --i )
       
   816         {
       
   817         if ( iWidgetStateArray[i]->iUid == aUid )
       
   818             {
       
   819             idx = i;
       
   820             }
       
   821         }
       
   822     return idx;
       
   823     }
       
   824 
       
   825 // ----------------------------------------------------------------------------
       
   826 // 
       
   827 // ----------------------------------------------------------------------------
       
   828 //
       
   829 TBool CWrtHarvester::CheckNetworkAccessL( TUid& aUid )
       
   830     {
       
   831     RWidgetRegistryClientSession session;
       
   832     CleanupClosePushL( session );
       
   833     User::LeaveIfError( session.Connect() );
       
   834     TBool networkAccess = *(session.GetWidgetPropertyValueL( aUid, EAllowNetworkAccess ) );
       
   835     CleanupStack::PopAndDestroy( &session );
       
   836     
       
   837     return networkAccess;
       
   838     }
       
   839 
       
   840 // ----------------------------------------------------------------------------
       
   841 // 
       
   842 // ----------------------------------------------------------------------------
       
   843 //
       
   844 void CWrtHarvester::AllowPlatformAccessL( TUid& aUid )
       
   845     {
       
   846     HBufC* confirmationText = StringLoader::LoadLC(R_WRTHRV_PLATFORM_ACCESS);
       
   847     TInt softKey = R_AVKON_SOFTKEYS_OK_CANCEL;
       
   848     CGlobalQueryHandlerAO* tmp = CGlobalQueryHandlerAO::StartLD( aUid, confirmationText->Des(), softKey, this );
       
   849     CleanupStack::PopAndDestroy(confirmationText);
       
   850     }
       
   851 
       
   852 // ------------------------------------------------------------------------
       
   853 // CGlobalQueryHandlerAO::StartLD
       
   854 //
       
   855 // Initialize AO.
       
   856 // ------------------------------------------------------------------------
       
   857 CGlobalQueryHandlerAO* CGlobalQueryHandlerAO::StartLD(
       
   858     TUid& aUid,
       
   859     const TDesC& aMessage, 
       
   860     TInt aSoftkeys,
       
   861     CWrtHarvester* aWrtHarvester)
       
   862     {
       
   863     CGlobalQueryHandlerAO* self( new( ELeave ) CGlobalQueryHandlerAO( aUid, aMessage, aSoftkeys, aWrtHarvester) );
       
   864     TRAPD(error, self->ShowGlobalQueryDialogL ( aMessage, aSoftkeys ));
       
   865     if ( error )
       
   866         {
       
   867         delete self;
       
   868         User::Leave(error);
       
   869         }
       
   870     self->SetActive();
       
   871     return self;
       
   872     }
       
   873 
       
   874 // ------------------------------------------------------------------------
       
   875 // CGlobalQueryHandlerAO::CGlobalQueryHandlerAO
       
   876 //
       
   877 // Constructor.
       
   878 // ------------------------------------------------------------------------
       
   879 CGlobalQueryHandlerAO::CGlobalQueryHandlerAO(
       
   880     TUid& aUid,
       
   881     const TDesC& aMessage, 
       
   882     TInt /*aSoftkeys*/,
       
   883     CWrtHarvester* aWrtHarvester):CActive( EPriorityHigh ),
       
   884     iWidgetUid(aUid),
       
   885     iConfirmationText(aMessage.AllocL()),
       
   886     iWrtHarvester(aWrtHarvester)
       
   887     {
       
   888     CActiveScheduler::Add( this );
       
   889     }
       
   890 
       
   891 // ------------------------------------------------------------------------
       
   892 // CGlobalQueryHandlerAO::CGlobalQueryHandlerAO
       
   893 //
       
   894 // ISet network and platform access permission based on user response.
       
   895 // ------------------------------------------------------------------------
       
   896 void CGlobalQueryHandlerAO::RunL()
       
   897     {    
       
   898     RWidgetRegistryClientSession session;
       
   899     CleanupClosePushL( session );
       
   900     User::LeaveIfError( session.Connect() );  
       
   901     if (iStatus == EAknSoftkeyOk)
       
   902         {
       
   903         session.SetBlanketPermissionL( iWidgetUid, EBlanketTrue );
       
   904         }
       
   905     else if ( iStatus == EAknSoftkeyCancel)
       
   906         {
       
   907         session.SetBlanketPermissionL( iWidgetUid, EBlanketFalse );
       
   908         }
       
   909     iWrtHarvester->QueueOperationL( WidgetResume, iWidgetUid );
       
   910     iWrtHarvester->DialogShown();
       
   911     CleanupStack::PopAndDestroy( &session );
       
   912     
       
   913     delete this;
       
   914     }
       
   915 
       
   916 // ------------------------------------------------------------------------
       
   917 // CGlobalQueryHandlerAO::DoCancel
       
   918 //
       
   919 // Do nothing.
       
   920 // ------------------------------------------------------------------------
       
   921 void CGlobalQueryHandlerAO::DoCancel()
       
   922     {
       
   923     if ( iGlobalConfirmationQuery )
       
   924         {
       
   925         iGlobalConfirmationQuery->CancelConfirmationQuery();
       
   926         }
       
   927     }
       
   928 
       
   929 // ------------------------------------------------------------------------
       
   930 // CGlobalQueryHandlerAO::~CGlobalQueryHandlerAO
       
   931 //
       
   932 // Destructor.
       
   933 // ------------------------------------------------------------------------
       
   934 CGlobalQueryHandlerAO::~CGlobalQueryHandlerAO()
       
   935     {
       
   936     Cancel();
       
   937     delete iGlobalConfirmationQuery;
       
   938     delete iConfirmationText;
       
   939     }
       
   940 
       
   941 // ---------------------------------------------------------
       
   942 // CGlobalQueryHandlerAO::ShowGlobalQueryDialogL()
       
   943 // ---------------------------------------------------------
       
   944 // 
       
   945 void CGlobalQueryHandlerAO::ShowGlobalQueryDialogL(const TDesC& aMessage, TInt aSoftkeys)
       
   946     {
       
   947     iGlobalConfirmationQuery = CAknGlobalConfirmationQuery::NewL();
       
   948     iGlobalConfirmationQuery->ShowConfirmationQueryL
       
   949                                 (iStatus,
       
   950                                 aMessage,
       
   951                                 aSoftkeys);
       
   952     }
       
   953 
   458  //  End of File
   954  //  End of File
   459 
   955