contentstorage/casrv/cawidgetscanner/src/cawidgetstoragehandler.cpp
changeset 107 b34d53f6acdf
parent 106 e78d6e055a5b
child 119 50e220be30d1
equal deleted inserted replaced
106:e78d6e055a5b 107:b34d53f6acdf
    89 // -----------------------------------------------------------------------------
    89 // -----------------------------------------------------------------------------
    90 //
    90 //
    91 CCaWidgetStorageHandler::~CCaWidgetStorageHandler()
    91 CCaWidgetStorageHandler::~CCaWidgetStorageHandler()
    92     {
    92     {
    93     delete iParser;
    93     delete iParser;
    94     iWidgets.ResetAndDestroy();
    94     iWidgetDBCache.ResetAndDestroy();
    95     }
    95     }
    96 
    96 
    97 // ----------------------------------------------------------------------------
    97 // ----------------------------------------------------------------------------
    98 //
    98 //
    99 // ----------------------------------------------------------------------------
    99 // ----------------------------------------------------------------------------
   100 //
   100 //
   101 void CCaWidgetStorageHandler::SynchronizeL()
   101 void CCaWidgetStorageHandler::SynchronizeL()
   102     {
   102     {
   103     FetchWidgetsL();
   103     FetchWidgetsL();
   104     AddWidgetsL( iParser->WidgetsScanL( iWidgets ) );
   104     AddWidgetsL( iParser->WidgetsScanL( iWidgetDBCache ) );
   105     RemoveWidgetsL();
   105     RemoveWidgetsL();
   106     }
   106     }
   107 
   107 
   108 // ----------------------------------------------------------------------------
   108 // ----------------------------------------------------------------------------
   109 //
   109 //
   159 //
   159 //
   160 // ----------------------------------------------------------------------------
   160 // ----------------------------------------------------------------------------
   161 //
   161 //
   162 void CCaWidgetStorageHandler::AddWidgetsL( const RWidgetArray& aWidgets )
   162 void CCaWidgetStorageHandler::AddWidgetsL( const RWidgetArray& aWidgets )
   163     {
   163     {
   164     for ( TInt i = 0; i < aWidgets.Count(); i++ )
   164     const TInt newWidgetsCount = aWidgets.Count();
   165         {
   165     
   166         aWidgets[i]->LocalizeTextsL();
   166     for ( TInt i = 0; i < newWidgetsCount; ++i )
   167         TInt index = iWidgets.Find( aWidgets[i], CCaWidgetDescription::Compare );
   167         {
   168         if ( index != KErrNotFound )
   168         CCaWidgetDescription *const newWidget = aWidgets[i];
   169             {
   169         
   170             iWidgets[index]->SetValid( ETrue );
   170         newWidget->LocalizeTextsL();
   171             if ( !iWidgets[index]->Compare( *aWidgets[i] )
   171         
   172                     || 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() )
   173                 {
   187                 {
   174                 aWidgets[i]->SetFlag( EMissing, iWidgets[index]->IsMissing() );
   188                 newWidget->SetFlag( EMissing, cachedWidget->IsMissing() );
   175                 aWidgets[i]->SetFlag( EUsed, iWidgets[index]->IsUsed() );
   189                 newWidget->SetFlag( EUsed,  cachedWidget->IsUsed() );
   176                 aWidgets[i]->SetFlag( EVisible, iWidgets[index]->IsVisible() );
   190                 newWidget->SetFlag( EVisible, cachedWidget->IsVisible() );
   177                 UpdateL( aWidgets[i], iWidgets[index]->GetEntryId() );
   191                 
       
   192                 UpdateL( newWidget, cachedWidget->GetEntryId() );
   178                 }
   193                 }
   179             }
   194             }
   180         else
   195         else
   181             {
   196             {
   182             AddL( aWidgets[i] );
   197             AddL( newWidget );
   183             }
   198             }
   184         }
   199         }
   185     HbTextResolverSymbian::Init( _L(""), KLocalizationFilepathZ );
   200     HbTextResolverSymbian::Init( _L(""), KLocalizationFilepathZ );
   186     }
   201     }
   187 
   202 
   189 //
   204 //
   190 // ----------------------------------------------------------------------------
   205 // ----------------------------------------------------------------------------
   191 //
   206 //
   192 void CCaWidgetStorageHandler::RemoveWidgetsL()
   207 void CCaWidgetStorageHandler::RemoveWidgetsL()
   193     {
   208     {
   194     for ( TInt i = 0; i < iWidgets.Count(); i++ )
   209     const TInt cacheCount = iWidgetDBCache.Count();
   195         {
   210     for ( TInt i = 0; i < cacheCount; ++i)
   196         if ( !iWidgets[i]->IsValid() )
   211         {
   197             {
   212         CCaWidgetDescription *const cachedWidget = iWidgetDBCache[i];
   198             if ( iWidgets[i]->GetMmcId() != KNullDesC )
   213         if ( !cachedWidget->IsValid() )
       
   214             {
       
   215             if ( cachedWidget->GetMmcId() != KNullDesC )
   199                 {
   216                 {
   200                 RBuf currentMmcId;
   217                 RBuf currentMmcId;
   201                 currentMmcId.CreateL( KMassStorageIdLength );
   218                 currentMmcId.CreateL( KMassStorageIdLength );
   202                 currentMmcId.CleanupClosePushL();
   219                 currentMmcId.CleanupClosePushL();
   203                 WidgetScannerUtils::CurrentMmcId( iFs, currentMmcId );
   220                 WidgetScannerUtils::CurrentMmcId( iFs, currentMmcId );
   204                 if( iWidgets[i]->GetMmcId() == currentMmcId ||
   221                 if( cachedWidget->GetMmcId() == currentMmcId ||
   205                         ( iWidgets[i]->GetMmcId() == KCaMassStorage() &&
   222                         ( cachedWidget->GetMmcId() == KCaMassStorage() &&
   206                         MassStorageNotInUse() ) )
   223                         MassStorageNotInUse() ) )
   207                     {
   224                     {
   208                     //item was uninstalled so we remove its mmc id
   225                     //item was uninstalled so we remove its mmc id
   209                     iWidgets[i]->RemoveMmcId();
   226                     cachedWidget->RemoveMmcId();
   210                     ClearVisibleFlagL( iWidgets[i] );
   227                     ClearVisibleFlagL( cachedWidget );
   211                     }
   228                     }
   212                 else
   229                 else
   213                     {
   230                     {
   214                     SetMissingFlagL( iWidgets[i] );
   231                     SetMissingFlagL( cachedWidget );
   215                     }
   232                     }
   216                 CleanupStack::PopAndDestroy( &currentMmcId );
   233                 CleanupStack::PopAndDestroy( &currentMmcId );
   217                 }
   234                 }
   218             else
   235             else
   219                 {
   236                 {
   220                 //item was uninstalled so we remove its mmc id
   237                 //item was uninstalled so we remove its mmc id
   221                 ClearVisibleFlagL( iWidgets[i] );
   238                 ClearVisibleFlagL( cachedWidget );
   222                 }
   239                 }
   223             }
   240             }
   224         }
   241         }
   225     }
   242     }
   226 
   243 
   275 
   292 
   276     RPointerArray<CCaInnerEntry> entries;
   293     RPointerArray<CCaInnerEntry> entries;
   277     CleanupResetAndDestroyPushL( entries );
   294     CleanupResetAndDestroyPushL( entries );
   278     iStorage->GetEntriesL( query, entries );
   295     iStorage->GetEntriesL( query, entries );
   279 
   296 
   280     iWidgets.ResetAndDestroy();
   297     iWidgetDBCache.ResetAndDestroy();
   281     for ( TInt i = 0; i < entries.Count(); i++ )
   298     for ( TInt i = 0; i < entries.Count(); i++ )
   282         {
   299         {
   283         CCaWidgetDescription* widget = CCaWidgetDescription::NewLC( entries[i] );
   300         CCaWidgetDescription* widget = CCaWidgetDescription::NewLC( entries[i] );
   284         iWidgets.AppendL( widget ); //iWidgets takes ownership
   301         iWidgetDBCache.AppendL( widget ); //iWidgets takes ownership
   285         CleanupStack::Pop( widget );
   302         CleanupStack::Pop( widget );
   286         }
   303         }
   287     CleanupStack::PopAndDestroy( &entries );
   304     CleanupStack::PopAndDestroy( &entries );
   288     CleanupStack::PopAndDestroy( query );
   305     CleanupStack::PopAndDestroy( query );
   289     }
   306     }