contentpublishingsrv/contentharvester/contentharvesterswiplugin/src/chswiplugin.cpp
changeset 73 4bc7b118b3df
parent 66 32469d7d46ff
child 80 397d00875918
child 81 5ef31a21fdd5
equal deleted inserted replaced
66:32469d7d46ff 73:4bc7b118b3df
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15  *
       
    16 */
       
    17 
       
    18 #include "chswiplugin.h"
       
    19 
       
    20 #include <e32std.h>
       
    21 
       
    22 #include <ecom/implementationproxy.h>
       
    23 #include <contentharvesterpluginuids.hrh>
       
    24 #include <liwservicehandler.h>
       
    25 #include "cpglobals.h"
       
    26 
       
    27 _LIT( KHsWidgetPublisher, "hswidgetpublisher");
       
    28 _LIT( KHsPublisher, "ai3templatedwidget" );
       
    29 _LIT8( KWidgetUid, "widget_uid");
       
    30 
       
    31 // Map the interface UIDs to implementation factory functions
       
    32 // ============================= LOCAL FUNCTIONS ===============================
       
    33 
       
    34 // Map the interface UIDs to implementation factory functions
       
    35 const TImplementationProxy ImplementationTable[] = 
       
    36     {
       
    37       {{KCHSwiPluginUidImpl}, (TProxyNewLPtr)CCHSwiPlugin::NewL},
       
    38     };
       
    39 
       
    40 // ----------------------------------------------------------------------------
       
    41 // Exported proxy for instantiation method resolution
       
    42 // ----------------------------------------------------------------------------
       
    43 //
       
    44 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(
       
    45                                                 TInt& aTableCount )
       
    46     {
       
    47     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
    48     return ImplementationTable;
       
    49     }
       
    50 
       
    51 // ============================ MEMBER FUNCTIONS ==============================
       
    52 
       
    53 // ----------------------------------------------------------------------------
       
    54 // CCHSwiPlugin::CCHSwiPlugin
       
    55 // Constructor
       
    56 // ----------------------------------------------------------------------------
       
    57 //
       
    58 CCHSwiPlugin::CCHSwiPlugin( MLiwInterface* aInterface )
       
    59 	{
       
    60 	iCPSInterface = aInterface;
       
    61     }
       
    62 
       
    63 // ----------------------------------------------------------------------------
       
    64 // CADatSwi::ConstructL
       
    65 // Symbian 2nd phase constructor can leave.
       
    66 // ----------------------------------------------------------------------------
       
    67 //
       
    68 void CCHSwiPlugin::ConstructL()
       
    69     {
       
    70     iNotifier = CApaAppListNotifier::NewL( this, CActive::EPriorityStandard );
       
    71     User::LeaveIfError( iApaLsSession.Connect() );
       
    72     }
       
    73 
       
    74 // ----------------------------------------------------------------------------
       
    75 // CADatSwi::NewL
       
    76 // Two-phased constructor.
       
    77 // ----------------------------------------------------------------------------
       
    78 //
       
    79 CCHSwiPlugin* CCHSwiPlugin::NewL(  MLiwInterface* aInterface)
       
    80     {
       
    81     CCHSwiPlugin* self = new (ELeave) CCHSwiPlugin( aInterface );
       
    82     CleanupStack::PushL( self );
       
    83     self->ConstructL();
       
    84     CleanupStack::Pop( self );
       
    85     return self;
       
    86     }
       
    87 
       
    88 // ----------------------------------------------------------------------------
       
    89 // CCHSwiPlugin::~CCHSwiPlugin
       
    90 // Destructor.
       
    91 // ----------------------------------------------------------------------------
       
    92 //
       
    93 CCHSwiPlugin::~CCHSwiPlugin()
       
    94     {
       
    95     iApaLsSession.Close();
       
    96     delete iNotifier;
       
    97     }
       
    98 
       
    99 // ----------------------------------------------------------------------------
       
   100 // CCHSwiPlugin::UpdateL
       
   101 // (other items were commented in a header).
       
   102 // ----------------------------------------------------------------------------
       
   103 //  
       
   104 void CCHSwiPlugin::UpdateL()
       
   105     {
       
   106     UpdateWidgetsL();
       
   107     }
       
   108 
       
   109 // ----------------------------------------------------------------------------
       
   110 // CCHSwiPlugin::HandleAppListEvent
       
   111 // (other items were commented in a header).
       
   112 // ----------------------------------------------------------------------------
       
   113 //  
       
   114 void CCHSwiPlugin::HandleAppListEvent( TInt /*aEvent*/ )
       
   115     {
       
   116     TRAP_IGNORE( UpdateWidgetsL() );
       
   117     }
       
   118 
       
   119 // ----------------------------------------------------------------------------
       
   120 // CCHSwiPlugin::UpdateWidgetsL
       
   121 // MMC watcher callback.
       
   122 // ----------------------------------------------------------------------------
       
   123 //
       
   124 void CCHSwiPlugin::UpdateWidgetsL()
       
   125     {
       
   126     CLiwGenericParamList* inparam = CLiwGenericParamList::NewLC( );
       
   127     CLiwGenericParamList* outparam = CLiwGenericParamList::NewLC( );
       
   128     inparam->AppendL( TLiwGenericParam( KType, TLiwVariant( KPublisher ) ) );
       
   129     CLiwDefaultMap* filter = CLiwDefaultMap::NewLC();
       
   130     
       
   131     filter->InsertL( KPublisherId, TLiwVariant( KHsWidgetPublisher ));
       
   132     filter->InsertL( KContentType, TLiwVariant( KHsPublisher ));
       
   133     inparam->AppendL( TLiwGenericParam( KFilter, TLiwVariant( filter ) ) );
       
   134     
       
   135     iCPSInterface->ExecuteCmdL( KGetList, *inparam, *outparam );
       
   136     
       
   137     RemoveWidgetsL( outparam );
       
   138     
       
   139     CleanupStack::PopAndDestroy( filter );
       
   140     CleanupStack::PopAndDestroy( outparam );
       
   141     CleanupStack::PopAndDestroy( inparam );
       
   142     }
       
   143 
       
   144 // ----------------------------------------------------------------------------
       
   145 // CCHSwiPlugin::RemoveWidgetsL
       
   146 // MMC watcher callback.
       
   147 // ----------------------------------------------------------------------------
       
   148 //
       
   149 void CCHSwiPlugin::RemoveWidgetsL( CLiwGenericParamList* aWidgets )
       
   150     {
       
   151     TInt pos ( 0 );
       
   152     aWidgets->FindFirst( pos, KResults );
       
   153     if( pos != KErrNotFound )
       
   154         {
       
   155         TLiwVariant variant = (*aWidgets)[pos].Value();
       
   156         variant.PushL();
       
   157         CLiwIterable* iterable = variant.AsIterable();
       
   158         iterable->Reset();
       
   159         if( iterable->NextL( variant ) )
       
   160             {
       
   161             CLiwDefaultMap *map = CLiwDefaultMap::NewLC();
       
   162             variant.Get( *map );
       
   163             if ( map->FindL( KDataMap, variant) )
       
   164                 {
       
   165                 CLiwDefaultMap *dataMap = CLiwDefaultMap::NewLC();
       
   166                 variant.Get( *dataMap );
       
   167                 if ( dataMap->FindL( KWidgetUid, variant ) )
       
   168                     {
       
   169                     TApaAppInfo appInfo;
       
   170                     
       
   171                     if( KErrNotFound == iApaLsSession.GetAppInfo( 
       
   172                             appInfo, TUid::Uid( variant.AsTInt32() ) ) )
       
   173                         {
       
   174                         if( map->FindL( KContentId, variant ) )
       
   175                             {
       
   176                             RemoveWidgetL( KPublisher, variant.AsDes() );
       
   177                             RemoveWidgetL( KCpData, variant.AsDes() );
       
   178                             }
       
   179                         }
       
   180                     }
       
   181                 CleanupStack::PopAndDestroy( dataMap );
       
   182                 }
       
   183             CleanupStack::PopAndDestroy( map );
       
   184             }
       
   185         CleanupStack::PopAndDestroy(&variant);
       
   186         }
       
   187     }
       
   188 
       
   189 // ----------------------------------------------------------------------------
       
   190 // CCHSwiPlugin::RemoveWidgetL
       
   191 // MMC watcher callback.
       
   192 // ----------------------------------------------------------------------------
       
   193 //
       
   194 void CCHSwiPlugin::RemoveWidgetL( const TDesC& aType, 
       
   195         const TDesC& aContentId )
       
   196     {
       
   197     CLiwGenericParamList* inparam = CLiwGenericParamList::NewLC( );
       
   198     CLiwGenericParamList* outparam = CLiwGenericParamList::NewLC( );
       
   199     inparam->AppendL( TLiwGenericParam( KType, TLiwVariant( aType ) ) );
       
   200     CLiwDefaultMap* filter = CLiwDefaultMap::NewLC();
       
   201     
       
   202     filter->InsertL( KPublisherId, TLiwVariant( KHsWidgetPublisher ));
       
   203     filter->InsertL( KContentType, TLiwVariant( KHsPublisher ));
       
   204     filter->InsertL( KContentId, TLiwVariant( aContentId ));
       
   205     inparam->AppendL( TLiwGenericParam( KFilter, TLiwVariant( filter ) ) );
       
   206     
       
   207     iCPSInterface->ExecuteCmdL( KDelete, *inparam, *outparam );
       
   208     
       
   209     CleanupStack::PopAndDestroy( filter );
       
   210     CleanupStack::PopAndDestroy( outparam );
       
   211     CleanupStack::PopAndDestroy( inparam );
       
   212     }
       
   213 
       
   214 //  End of File