contentstorage/casrv/cawidgetscanner/src/cawidgetstoragehandler.cpp
changeset 109 e0aa398e6810
parent 104 9b022b1f357c
child 124 e36b2f4799c0
equal deleted inserted replaced
104:9b022b1f357c 109:e0aa398e6810
    38 // -----------------------------------------------------------------------------
    38 // -----------------------------------------------------------------------------
    39 // 
    39 // 
    40 // -----------------------------------------------------------------------------
    40 // -----------------------------------------------------------------------------
    41 //
    41 //
    42 CCaWidgetStorageHandler::CCaWidgetStorageHandler( CCaStorageProxy* aStorage,
    42 CCaWidgetStorageHandler::CCaWidgetStorageHandler( CCaStorageProxy* aStorage,
    43         RFs& aFs )
    43         Usif::RSoftwareComponentRegistry& aSoftwareRegistry, RFs& aFs ) :
       
    44             iSoftwareRegistry(aSoftwareRegistry)
    44     {
    45     {
    45     iStorage = aStorage;
    46     iStorage = aStorage;
    46     iFs = aFs;
    47     iFs = aFs;
    47     }
    48     }
    48 
    49 
    50 // 
    51 // 
    51 // -----------------------------------------------------------------------------
    52 // -----------------------------------------------------------------------------
    52 //
    53 //
    53 void CCaWidgetStorageHandler::ConstructL()
    54 void CCaWidgetStorageHandler::ConstructL()
    54     {
    55     {
    55     User::LeaveIfError( iSoftwareRegistry.Connect() );
       
    56     iParser = CCaWidgetScannerParser::NewL( iFs );
    56     iParser = CCaWidgetScannerParser::NewL( iFs );
    57     }
    57     }
    58 
    58 
    59 // -----------------------------------------------------------------------------
    59 // -----------------------------------------------------------------------------
    60 // 
    60 // 
    61 // -----------------------------------------------------------------------------
    61 // -----------------------------------------------------------------------------
    62 //
    62 //
    63 CCaWidgetStorageHandler* CCaWidgetStorageHandler::NewL(
    63 CCaWidgetStorageHandler* CCaWidgetStorageHandler::NewL(
    64         CCaStorageProxy* aStorage, RFs& aFs )
    64         CCaStorageProxy* aStorage,
    65     {
    65         Usif::RSoftwareComponentRegistry& aSoftwareRegistry, RFs& aFs )
    66     CCaWidgetStorageHandler* self = NewLC( aStorage, aFs );
    66     {
       
    67     CCaWidgetStorageHandler* self = NewLC( aStorage, aSoftwareRegistry, aFs );
    67     CleanupStack::Pop( self );
    68     CleanupStack::Pop( self );
    68     return self;
    69     return self;
    69     }
    70     }
    70 
    71 
    71 // -----------------------------------------------------------------------------
    72 // -----------------------------------------------------------------------------
    72 // 
    73 // 
    73 // -----------------------------------------------------------------------------
    74 // -----------------------------------------------------------------------------
    74 //
    75 //
    75 CCaWidgetStorageHandler* CCaWidgetStorageHandler::NewLC(
    76 CCaWidgetStorageHandler* CCaWidgetStorageHandler::NewLC(
    76         CCaStorageProxy* aStorage, RFs& aFs )
    77         CCaStorageProxy* aStorage,
       
    78         Usif::RSoftwareComponentRegistry& aSoftwareRegistry, RFs& aFs )
    77     {
    79     {
    78     CCaWidgetStorageHandler* self = new ( ELeave ) CCaWidgetStorageHandler(
    80     CCaWidgetStorageHandler* self = new ( ELeave ) CCaWidgetStorageHandler(
    79             aStorage, aFs );
    81             aStorage, aSoftwareRegistry, aFs );
    80     CleanupStack::PushL( self );
    82     CleanupStack::PushL( self );
    81     self->ConstructL();
    83     self->ConstructL();
    82     return self;
    84     return self;
    83     }
    85     }
    84 
    86 
    87 // -----------------------------------------------------------------------------
    89 // -----------------------------------------------------------------------------
    88 //
    90 //
    89 CCaWidgetStorageHandler::~CCaWidgetStorageHandler()
    91 CCaWidgetStorageHandler::~CCaWidgetStorageHandler()
    90     {
    92     {
    91     delete iParser;
    93     delete iParser;
    92     iSoftwareRegistry.Close();
    94     iWidgetDBCache.ResetAndDestroy();
    93     iWidgets.ResetAndDestroy();
       
    94     }
    95     }
    95 
    96 
    96 // ----------------------------------------------------------------------------
    97 // ----------------------------------------------------------------------------
    97 //
    98 //
    98 // ----------------------------------------------------------------------------
    99 // ----------------------------------------------------------------------------
    99 //
   100 //
   100 void CCaWidgetStorageHandler::SynchronizeL()
   101 void CCaWidgetStorageHandler::SynchronizeL()
   101     {
   102     {
   102     FetchWidgetsL();
   103     FetchWidgetsL();
   103     AddWidgetsL( iParser->WidgetsScanL( iWidgets ) );
   104     AddWidgetsL( iParser->WidgetsScanL( iWidgetDBCache ) );
   104     RemoveWidgetsL();
   105     RemoveWidgetsL();
   105     }
   106     }
   106 
   107 
   107 // ----------------------------------------------------------------------------
   108 // ----------------------------------------------------------------------------
   108 //
   109 //
   109 // ----------------------------------------------------------------------------
   110 // ----------------------------------------------------------------------------
   110 //
   111 //
   111 void CCaWidgetStorageHandler::AddL( const CCaWidgetDescription* aWidget )
   112 void CCaWidgetStorageHandler::AddL( const CCaWidgetDescription* aWidget )
   112     {
   113     {
   113     CCaInnerEntry* entry = aWidget->GetEntryLC();
   114     CCaInnerEntry* entry = aWidget->GetEntryLC();
   114     UpdateComponentIdL( aWidget->GetManifestFilePathName(), *entry );
   115     UpdateCompIdAndRemovableFlagL( aWidget->GetManifestFilePathName(), *entry );
   115     iStorage->AddL( entry );
   116     iStorage->AddL( entry );
   116 
   117 
   117     SetLocalizationsL( aWidget, entry->GetId() );
   118     SetLocalizationsL( aWidget, entry->GetId() );
   118 
   119 
   119     if ( entry->GetFlags() & ERemovable )
   120     if ( entry->GetFlags() & ERemovable )
   129 //
   130 //
   130 void CCaWidgetStorageHandler::UpdateL( const CCaWidgetDescription* aWidget,
   131 void CCaWidgetStorageHandler::UpdateL( const CCaWidgetDescription* aWidget,
   131         TUint aEntryId )
   132         TUint aEntryId )
   132     {
   133     {
   133     CCaInnerEntry* entry = aWidget->GetEntryLC();
   134     CCaInnerEntry* entry = aWidget->GetEntryLC();
   134     UpdateComponentIdL( aWidget->GetManifestFilePathName(), *entry );
   135     UpdateCompIdAndRemovableFlagL( aWidget->GetManifestFilePathName(), *entry );
   135     entry->SetId( aEntryId );
   136     entry->SetId( aEntryId );
   136     if ( !aWidget->IsMissing() && aWidget->IsUsed() )
   137     if ( !aWidget->IsMissing() && aWidget->IsUsed() )
   137         {
   138         {
   138         entry->SetFlags( entry->GetFlags() & ~EUsed );
   139         entry->SetFlags( entry->GetFlags() & ~EUsed );
   139         }
   140         }
   145     entry->SetFlags( entry->GetFlags() & ~EMissing | EVisible );
   146     entry->SetFlags( entry->GetFlags() & ~EMissing | EVisible );
   146     iStorage->AddL( entry, EFalse, itemAppearanceChange );
   147     iStorage->AddL( entry, EFalse, itemAppearanceChange );
   147 
   148 
   148     SetLocalizationsL( aWidget, entry->GetId() );
   149     SetLocalizationsL( aWidget, entry->GetId() );
   149 
   150 
   150     if ( !aWidget->IsMissing() )
   151     if ( !aWidget->IsMissing() && ( entry->GetFlags() & ERemovable ) )
   151         {
   152         {
   152         AddWidgetToDownloadCollectionL( entry );
   153         AddWidgetToDownloadCollectionL( entry );
   153         }
   154         }
   154     CleanupStack::PopAndDestroy( entry );
   155     CleanupStack::PopAndDestroy( entry );
   155     }
   156     }
   158 //
   159 //
   159 // ----------------------------------------------------------------------------
   160 // ----------------------------------------------------------------------------
   160 //
   161 //
   161 void CCaWidgetStorageHandler::AddWidgetsL( const RWidgetArray& aWidgets )
   162 void CCaWidgetStorageHandler::AddWidgetsL( const RWidgetArray& aWidgets )
   162     {
   163     {
   163     for ( TInt i = 0; i < aWidgets.Count(); i++ )
   164     const TInt newWidgetsCount = aWidgets.Count();
   164         {
   165     
   165         aWidgets[i]->LocalizeTextsL();
   166     for ( TInt i = 0; i < newWidgetsCount; ++i )
   166         TInt index = iWidgets.Find( aWidgets[i], CCaWidgetDescription::Compare );
   167         {
   167         if ( index != KErrNotFound )
   168         CCaWidgetDescription *const newWidget = aWidgets[i];
   168             {
   169         
   169             iWidgets[index]->SetValid( ETrue );
   170         newWidget->LocalizeTextsL();
   170             if ( !iWidgets[index]->Compare( *aWidgets[i] )
   171         
   171                     || iWidgets[index]->IsMissing() )
   172         const TInt dbCacheIndex = 
       
   173             iWidgetDBCache.Find( 
       
   174                 newWidget, CCaWidgetDescription::CompareUri );
       
   175         
       
   176         if ( dbCacheIndex != KErrNotFound )
       
   177             {
       
   178             CCaWidgetDescription *const cachedWidget = 
       
   179                 iWidgetDBCache[dbCacheIndex];
       
   180             
       
   181             cachedWidget->SetValid( ETrue );
       
   182             
       
   183             const TBool cachedDifferentThanNew = 
       
   184                 !cachedWidget->Compare( *newWidget );
       
   185             
       
   186             if ( cachedDifferentThanNew || cachedWidget->IsMissing() )
   172                 {
   187                 {
   173                 aWidgets[i]->SetFlag( EMissing, iWidgets[index]->IsMissing() );
   188                 newWidget->SetFlag( EMissing, cachedWidget->IsMissing() );
   174                 aWidgets[i]->SetFlag( EUsed, iWidgets[index]->IsUsed() );
   189                 newWidget->SetFlag( EUsed,  cachedWidget->IsUsed() );
   175                 aWidgets[i]->SetFlag( EVisible, iWidgets[index]->IsVisible() );
   190                 newWidget->SetFlag( EVisible, cachedWidget->IsVisible() );
   176                 UpdateL( aWidgets[i], iWidgets[index]->GetEntryId() );
   191                 
       
   192                 UpdateL( newWidget, cachedWidget->GetEntryId() );
   177                 }
   193                 }
   178             }
   194             }
   179         else
   195         else
   180             {
   196             {
   181             AddL( aWidgets[i] );
   197             AddL( newWidget );
   182             }
   198             }
   183         }
   199         }
   184     HbTextResolverSymbian::Init( _L(""), KLocalizationFilepathZ );
   200     HbTextResolverSymbian::Init( _L(""), KLocalizationFilepathZ );
   185     }
   201     }
   186 
   202 
   188 //
   204 //
   189 // ----------------------------------------------------------------------------
   205 // ----------------------------------------------------------------------------
   190 //
   206 //
   191 void CCaWidgetStorageHandler::RemoveWidgetsL()
   207 void CCaWidgetStorageHandler::RemoveWidgetsL()
   192     {
   208     {
   193     for ( TInt i = 0; i < iWidgets.Count(); i++ )
   209     const TInt cacheCount = iWidgetDBCache.Count();
   194         {
   210     for ( TInt i = 0; i < cacheCount; ++i)
   195         if ( !iWidgets[i]->IsValid() )
   211         {
   196             {
   212         CCaWidgetDescription *const cachedWidget = iWidgetDBCache[i];
   197             if ( iWidgets[i]->GetMmcId() != KNullDesC )
   213         if ( !cachedWidget->IsValid() )
       
   214             {
       
   215             if ( cachedWidget->GetMmcId() != KNullDesC )
   198                 {
   216                 {
   199                 RBuf currentMmcId;
   217                 RBuf currentMmcId;
   200                 currentMmcId.CreateL( KMassStorageIdLength );
   218                 currentMmcId.CreateL( KMassStorageIdLength );
   201                 currentMmcId.CleanupClosePushL();
   219                 currentMmcId.CleanupClosePushL();
   202                 WidgetScannerUtils::CurrentMmcId( iFs, currentMmcId );
   220                 WidgetScannerUtils::CurrentMmcId( iFs, currentMmcId );
   203                 if( iWidgets[i]->GetMmcId() == currentMmcId ||
   221                 if( cachedWidget->GetMmcId() == currentMmcId ||
   204                         ( iWidgets[i]->GetMmcId() == KCaMassStorage() &&
   222                         ( cachedWidget->GetMmcId() == KCaMassStorage() &&
   205                         MassStorageNotInUse() ) )
   223                         MassStorageNotInUse() ) )
   206                     {
   224                     {
   207                     //item was uninstalled so we remove its mmc id
   225                     //item was uninstalled so we remove its mmc id
   208                     iWidgets[i]->RemoveMmcId();
   226                     cachedWidget->RemoveMmcId();
   209                     ClearVisibleFlagL( iWidgets[i] );
   227                     ClearVisibleFlagL( cachedWidget );
   210                     }
   228                     }
   211                 else
   229                 else
   212                     {
   230                     {
   213                     SetMissingFlagL( iWidgets[i] );
   231                     SetMissingFlagL( cachedWidget );
   214                     }
   232                     }
   215                 CleanupStack::PopAndDestroy( &currentMmcId );
   233                 CleanupStack::PopAndDestroy( &currentMmcId );
   216                 }
   234                 }
   217             else
   235             else
   218                 {
   236                 {
   219                 //item was uninstalled so we remove its mmc id
   237                 //item was uninstalled so we remove its mmc id
   220                 ClearVisibleFlagL( iWidgets[i] );
   238                 ClearVisibleFlagL( cachedWidget );
   221                 }
   239                 }
   222             }
   240             }
   223         }
   241         }
   224     }
   242     }
   225 
   243 
   274 
   292 
   275     RPointerArray<CCaInnerEntry> entries;
   293     RPointerArray<CCaInnerEntry> entries;
   276     CleanupResetAndDestroyPushL( entries );
   294     CleanupResetAndDestroyPushL( entries );
   277     iStorage->GetEntriesL( query, entries );
   295     iStorage->GetEntriesL( query, entries );
   278 
   296 
   279     iWidgets.ResetAndDestroy();
   297     iWidgetDBCache.ResetAndDestroy();
   280     for ( TInt i = 0; i < entries.Count(); i++ )
   298     for ( TInt i = 0; i < entries.Count(); i++ )
   281         {
   299         {
   282         CCaWidgetDescription* widget = CCaWidgetDescription::NewLC( entries[i] );
   300         CCaWidgetDescription* widget = CCaWidgetDescription::NewLC( entries[i] );
   283         iWidgets.AppendL( widget ); //iWidgets takes ownership
   301         iWidgetDBCache.AppendL( widget ); //iWidgets takes ownership
   284         CleanupStack::Pop( widget );
   302         CleanupStack::Pop( widget );
   285         }
   303         }
   286     CleanupStack::PopAndDestroy( &entries );
   304     CleanupStack::PopAndDestroy( &entries );
   287     CleanupStack::PopAndDestroy( query );
   305     CleanupStack::PopAndDestroy( query );
   288     }
   306     }
   397 // ----------------------------------------------------------------------------
   415 // ----------------------------------------------------------------------------
   398 //
   416 //
   399 // ----------------------------------------------------------------------------
   417 // ----------------------------------------------------------------------------
   400 //
   418 //
   401 
   419 
   402 void CCaWidgetStorageHandler::UpdateComponentIdL(
   420 void CCaWidgetStorageHandler::UpdateCompIdAndRemovableFlagL(
   403         const TDesC& aManifestFilePathName, CCaInnerEntry& aEntry ) const
   421         const TDesC& aManifestFilePathName, CCaInnerEntry& aEntry ) const
   404     {
   422     {
   405     RArray<TComponentId> componentIds;
   423     RArray<TComponentId> componentIds;
   406     CleanupClosePushL( componentIds );
   424     CleanupClosePushL( componentIds );
   407 
   425 
   409     fileNameFilter->SetFileL( aManifestFilePathName );
   427     fileNameFilter->SetFileL( aManifestFilePathName );
   410     iSoftwareRegistry.GetComponentIdsL( componentIds, fileNameFilter );
   428     iSoftwareRegistry.GetComponentIdsL( componentIds, fileNameFilter );
   411 
   429 
   412     CleanupStack::PopAndDestroy( fileNameFilter );
   430     CleanupStack::PopAndDestroy( fileNameFilter );
   413 
   431 
   414     if ( componentIds.Count() == 1 )
   432     if( componentIds.Count() == 1 )
   415         {
   433         {
   416         RBuf newComponentId;
   434         RBuf newComponentId;
   417         newComponentId.CleanupClosePushL();
   435         newComponentId.CleanupClosePushL();
   418         newComponentId.CreateL( sizeof(TComponentId) + 1 );
   436         newComponentId.CreateL( sizeof(TComponentId) + 1 );
   419         newComponentId.AppendNum( componentIds[0] );
   437         newComponentId.AppendNum( componentIds[0] );
   423         oldComponentId.CreateL( KCaMaxAttrValueLen );
   441         oldComponentId.CreateL( KCaMaxAttrValueLen );
   424 
   442 
   425         const TBool componentIdAttributeFound = aEntry.FindAttribute(
   443         const TBool componentIdAttributeFound = aEntry.FindAttribute(
   426                 KCaComponentId, oldComponentId );
   444                 KCaComponentId, oldComponentId );
   427 
   445 
   428         if ( !componentIdAttributeFound || oldComponentId.Compare(
   446         if( !componentIdAttributeFound || oldComponentId.Compare(
   429                 newComponentId ) != 0 )
   447                 newComponentId ) != 0 )
   430             {
   448             {
   431             // 'add' or 'update' the component id attribute value
   449             // 'add' or 'update' the component id attribute value
   432             aEntry.AddAttributeL( KCaComponentId, newComponentId );
   450             aEntry.AddAttributeL( KCaComponentId, newComponentId );
   433             }
   451             }
   434 
   452         CComponentEntry* entry = CComponentEntry::NewLC();
       
   453         iSoftwareRegistry.GetComponentL( componentIds[0] , *entry );
       
   454         if( entry->IsRemovable() )
       
   455             {
       
   456             aEntry.SetFlags( aEntry.GetFlags() | ERemovable );
       
   457             }
       
   458         CleanupStack::PopAndDestroy( entry );
   435         CleanupStack::PopAndDestroy( &oldComponentId );
   459         CleanupStack::PopAndDestroy( &oldComponentId );
   436         CleanupStack::PopAndDestroy( &newComponentId );
   460         CleanupStack::PopAndDestroy( &newComponentId );
   437         }
   461         }
   438 
   462 
   439     CleanupStack::PopAndDestroy( &componentIds );
   463     CleanupStack::PopAndDestroy( &componentIds );