contentpublishingsrv/contentharvester/contentharvesterswiplugin/src/chswiplugin.cpp
branchRCL_3
changeset 114 a5a39a295112
equal deleted inserted replaced
113:0efa10d348c0 114:a5a39a295112
       
     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 <driveinfo.h>
       
    26 
       
    27 #include "cpglobals.h"
       
    28 #include "chswiusbhandler.h"
       
    29 #include "chswiusbobserver.h"
       
    30 
       
    31 _LIT( KHSTemplate, "hstemplate" );
       
    32 _LIT8( KWidgetUid, "widget_uid");
       
    33 
       
    34 const TInt KWidgetArrayGran = 8;
       
    35 
       
    36 // Map the interface UIDs to implementation factory functions
       
    37 // ============================= LOCAL FUNCTIONS ===============================
       
    38 
       
    39 // Map the interface UIDs to implementation factory functions
       
    40 const TImplementationProxy ImplementationTable[] = 
       
    41     {
       
    42       {{KCHSwiPluginUidImpl}, (TProxyNewLPtr)CCHSwiPlugin::NewL},
       
    43     };
       
    44 
       
    45 // ----------------------------------------------------------------------------
       
    46 // Exported proxy for instantiation method resolution
       
    47 // ----------------------------------------------------------------------------
       
    48 //
       
    49 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(
       
    50                                                 TInt& aTableCount )
       
    51     {
       
    52     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
    53     return ImplementationTable;
       
    54     }
       
    55 
       
    56 // ============================ MEMBER FUNCTIONS ==============================
       
    57 
       
    58 // ----------------------------------------------------------------------------
       
    59 // CCHSwiPlugin::CCHSwiPlugin
       
    60 // Constructor
       
    61 // ----------------------------------------------------------------------------
       
    62 //
       
    63 CCHSwiPlugin::CCHSwiPlugin( MLiwInterface* aInterface )
       
    64 	{
       
    65 	iCPSInterface = aInterface;
       
    66     }
       
    67 
       
    68 // ----------------------------------------------------------------------------
       
    69 // CADatSwi::ConstructL
       
    70 // Symbian 2nd phase constructor can leave.
       
    71 // ----------------------------------------------------------------------------
       
    72 //
       
    73 void CCHSwiPlugin::ConstructL()
       
    74     {
       
    75     iNotifier = CApaAppListNotifier::NewL( this, CActive::EPriorityStandard );
       
    76     User::LeaveIfError( iApaLsSession.Connect() );
       
    77     User::LeaveIfError( iFs.Connect() );
       
    78     
       
    79     iMassMemoryAvailable = InternalMassMemoryAvailable();
       
    80     iUsbHandler = CCHSwiUsbHandler::NewL( this, iFs );
       
    81     
       
    82     iUsbObserver = CCHSwiUsbObserver::NewL( iUsbHandler, iFs );
       
    83     iUsbObserver->Start();
       
    84     }
       
    85 
       
    86 // ----------------------------------------------------------------------------
       
    87 // CADatSwi::NewL
       
    88 // Two-phased constructor.
       
    89 // ----------------------------------------------------------------------------
       
    90 //
       
    91 CCHSwiPlugin* CCHSwiPlugin::NewL(  MLiwInterface* aInterface)
       
    92     {
       
    93     CCHSwiPlugin* self = new (ELeave) CCHSwiPlugin( aInterface );
       
    94     CleanupStack::PushL( self );
       
    95     self->ConstructL();
       
    96     CleanupStack::Pop( self );
       
    97     return self;
       
    98     }
       
    99 
       
   100 // ----------------------------------------------------------------------------
       
   101 // CCHSwiPlugin::~CCHSwiPlugin
       
   102 // Destructor.
       
   103 // ----------------------------------------------------------------------------
       
   104 //
       
   105 CCHSwiPlugin::~CCHSwiPlugin()
       
   106     {
       
   107     delete iNotifier;
       
   108     delete iUsbHandler;
       
   109     delete iUsbObserver;
       
   110     iApaLsSession.Close();
       
   111     iFs.Close();
       
   112     }
       
   113 
       
   114 // ----------------------------------------------------------------------------
       
   115 // CCHSwiPlugin::UpdateL
       
   116 // (other items were commented in a header).
       
   117 // ----------------------------------------------------------------------------
       
   118 //  
       
   119 void CCHSwiPlugin::UpdateL()
       
   120     {
       
   121     UpdateWidgetsL();
       
   122     }
       
   123 
       
   124 // ----------------------------------------------------------------------------
       
   125 // CCHSwiPlugin::HandleAppListEvent
       
   126 // (other items were commented in a header).
       
   127 // ----------------------------------------------------------------------------
       
   128 //  
       
   129 void CCHSwiPlugin::HandleAppListEvent( TInt /*aEvent*/ )
       
   130     {
       
   131     TRAP_IGNORE( UpdateWidgetsL() );
       
   132     }
       
   133 
       
   134 // ----------------------------------------------------------------------------
       
   135 // CCHSwiPlugin::HandleMassStorageModeEndEvent
       
   136 // (refer to MCHSwiMassModeObserver declaration).
       
   137 // ----------------------------------------------------------------------------
       
   138 //  
       
   139 void CCHSwiPlugin::HandleMassStorageModeEndEvent()
       
   140 	{
       
   141 	TRAP_IGNORE( UpdateWidgetsL() );
       
   142 	}
       
   143 
       
   144 // ----------------------------------------------------------------------------
       
   145 // CCHSwiPlugin::HandleSuccessfulAsynchDriveScan
       
   146 // (refer to MCHSwiMassModeObserver declaration).
       
   147 // ----------------------------------------------------------------------------
       
   148 //  
       
   149 void CCHSwiPlugin::HandleSuccessfulAsynchDriveScan()
       
   150 	{
       
   151 	iUsbObserver->Start();
       
   152 	}
       
   153 
       
   154 // ----------------------------------------------------------------------------
       
   155 // CCHSwiPlugin::UpdateWidgetsL
       
   156 // MMC watcher callback.
       
   157 // ----------------------------------------------------------------------------
       
   158 //
       
   159 void CCHSwiPlugin::UpdateWidgetsL()
       
   160     {
       
   161 	CLiwGenericParamList* inparam = CLiwGenericParamList::NewLC( );
       
   162 	CLiwGenericParamList* outparam = CLiwGenericParamList::NewLC( );
       
   163 	inparam->AppendL( TLiwGenericParam( KType, TLiwVariant( KPublisher ) ) );
       
   164 	CLiwDefaultMap* filter = CLiwDefaultMap::NewLC();
       
   165 	
       
   166 	filter->InsertL( KContentType, TLiwVariant( KHSTemplate ));
       
   167 	inparam->AppendL( TLiwGenericParam( KFilter, TLiwVariant( filter ) ) );
       
   168 	
       
   169 	iCPSInterface->ExecuteCmdL( KGetList, *inparam, *outparam );
       
   170 	
       
   171 	RemoveWidgetsL( outparam );
       
   172 	
       
   173 	CleanupStack::PopAndDestroy( filter );
       
   174 	CleanupStack::PopAndDestroy( outparam );
       
   175 	CleanupStack::PopAndDestroy( inparam );  
       
   176     }
       
   177 
       
   178 // ----------------------------------------------------------------------------
       
   179 // CCHSwiPlugin::RemoveWidgetsL
       
   180 // MMC watcher callback.
       
   181 // ----------------------------------------------------------------------------
       
   182 //
       
   183 void CCHSwiPlugin::RemoveWidgetsL( CLiwGenericParamList* aWidgets )
       
   184     {
       
   185     TInt pos ( 0 );
       
   186     aWidgets->FindFirst( pos, KResults ); 	
       
   187     
       
   188     if ( pos != KErrNotFound )
       
   189         {
       
   190         CDesC16ArrayFlat* notFoundWidgets = new (ELeave) CDesC16ArrayFlat( KWidgetArrayGran ); 
       
   191         CleanupStack::PushL( notFoundWidgets );
       
   192         
       
   193         TLiwVariant variant = (*aWidgets)[pos].Value();
       
   194         variant.PushL();
       
   195         CLiwIterable* iterable = variant.AsIterable();
       
   196         iterable->Reset();
       
   197         
       
   198         while ( iterable->NextL( variant ) )
       
   199             {
       
   200             CLiwDefaultMap *map = CLiwDefaultMap::NewLC();
       
   201             variant.Get( *map );
       
   202             if ( map->FindL( KDataMap, variant) )
       
   203                 {
       
   204                 CLiwDefaultMap *dataMap = CLiwDefaultMap::NewLC();
       
   205                 variant.Get( *dataMap );
       
   206                 if ( dataMap->FindL( KWidgetUid, variant ) )
       
   207                     {
       
   208                     TApaAppInfo appInfo;
       
   209                     
       
   210                     if( KErrNotFound == iApaLsSession.GetAppInfo( 
       
   211                             appInfo, TUid::Uid( variant.AsTInt32() ) ) )
       
   212                         {
       
   213                         if( map->FindL( KPublisherId, variant ) )
       
   214                             {
       
   215                             notFoundWidgets->AppendL( variant.AsDes() );
       
   216                             }
       
   217                         }
       
   218                     }
       
   219                 CleanupStack::PopAndDestroy( dataMap );
       
   220                 }
       
   221             CleanupStack::PopAndDestroy( map );
       
   222             }
       
   223         
       
   224         if ( notFoundWidgets->Count() > 0 )
       
   225         	{
       
   226         	iUsbHandler->SynchronousDriveScan();
       
   227         			
       
   228         	if ( !IsMassStorageMode() )
       
   229         		{
       
   230         		for ( TInt i = 0; i < notFoundWidgets->Count(); i++ )
       
   231         			{
       
   232         			RemoveWidgetL( KPublisher, (*notFoundWidgets)[i] );
       
   233         			RemoveWidgetL( KCpData, (*notFoundWidgets)[i] );
       
   234         			}
       
   235         	   	}
       
   236         	}
       
   237         
       
   238         CleanupStack::PopAndDestroy( &variant );
       
   239         CleanupStack::PopAndDestroy( notFoundWidgets );
       
   240         }
       
   241     	
       
   242 
       
   243     }
       
   244 
       
   245 // ----------------------------------------------------------------------------
       
   246 // CCHSwiPlugin::RemoveWidgetL
       
   247 // MMC watcher callback.
       
   248 // ----------------------------------------------------------------------------
       
   249 //
       
   250 void CCHSwiPlugin::RemoveWidgetL( const TDesC& aType, 
       
   251         const TDesC& aPublisherId )
       
   252     {
       
   253     CLiwGenericParamList* inparam = CLiwGenericParamList::NewLC( );
       
   254     CLiwGenericParamList* outparam = CLiwGenericParamList::NewLC( );
       
   255     inparam->AppendL( TLiwGenericParam( KType, TLiwVariant( aType ) ) );
       
   256     CLiwDefaultMap* filter = CLiwDefaultMap::NewLC();
       
   257     
       
   258     filter->InsertL( KPublisherId, TLiwVariant( aPublisherId ));
       
   259     inparam->AppendL( TLiwGenericParam( KFilter, TLiwVariant( filter ) ) );
       
   260     
       
   261     iCPSInterface->ExecuteCmdL( KDelete, *inparam, *outparam );
       
   262     
       
   263     CleanupStack::PopAndDestroy( filter );
       
   264     CleanupStack::PopAndDestroy( outparam );
       
   265     CleanupStack::PopAndDestroy( inparam );
       
   266     }
       
   267 
       
   268 // ----------------------------------------------------------------------------
       
   269 // CCHSwiPlugin::SetMassStorageMode
       
   270 // Sets Mass Storage mode.
       
   271 // ----------------------------------------------------------------------------
       
   272 //
       
   273 void CCHSwiPlugin::SetMassStorageMode( TBool aMode )
       
   274 	{
       
   275 	iMassStorageMode = aMode;
       
   276 	}
       
   277 
       
   278 // ----------------------------------------------------------------------------
       
   279 // CCHSwiPlugin::IsMassStorageMode
       
   280 // Gets Mass Storage mode.
       
   281 // ----------------------------------------------------------------------------
       
   282 //
       
   283 TBool CCHSwiPlugin::IsMassStorageMode()
       
   284 	{
       
   285     if (iMassMemoryAvailable)
       
   286     	{
       
   287     	return iMassStorageMode;
       
   288     	}
       
   289     else
       
   290     	{
       
   291     	return EFalse;
       
   292     	}
       
   293 	}
       
   294 
       
   295 // ----------------------------------------------------------------------------
       
   296 //
       
   297 // ----------------------------------------------------------------------------
       
   298 //
       
   299 TBool CCHSwiPlugin::InternalMassMemoryAvailable( )
       
   300     {
       
   301     TBool result(EFalse);
       
   302     // List all drives in the system
       
   303     TDriveList driveList;
       
   304     TInt error = iFs.DriveList( driveList );
       
   305     
       
   306     if ( KErrNone == error )
       
   307         {
       
   308         for ( TInt driveNumber = EDriveY;
       
   309               driveNumber >= EDriveA;
       
   310               driveNumber-- )
       
   311             {
       
   312             TUint status( 0 );
       
   313             TInt error = DriveInfo::GetDriveStatus( iFs, driveNumber, status );
       
   314             if( (KErrNone == error) && ( status & DriveInfo::EDriveExternallyMountable ) 
       
   315             		&& ( status & DriveInfo::EDriveInternal ) )
       
   316                 {
       
   317                 // Internal Memory
       
   318                 result = ETrue;
       
   319                 break;
       
   320                 }
       
   321             }
       
   322         }
       
   323     return result;
       
   324     }
       
   325 
       
   326 //  End of File