contentstorage/casrv/cawidgetscanner/src/cawidgetstoragehandler.cpp
changeset 73 4bc7b118b3df
parent 66 32469d7d46ff
child 80 397d00875918
equal deleted inserted replaced
66:32469d7d46ff 73:4bc7b118b3df
     9  * Initial Contributors:
     9  * Initial Contributors:
    10  * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11  *
    11  *
    12  * Contributors:
    12  * Contributors:
    13  *
    13  *
    14  * Description: 
    14  * Description:
    15  *
    15  *
    16  */
    16  */
    17 // INCLUDE FILES
    17 // INCLUDE FILES
    18 
    18 
    19 #include <badesca.h>
    19 #include <badesca.h>
    86     iWidgets.ResetAndDestroy();
    86     iWidgets.ResetAndDestroy();
    87     iUpdatedIndexes.Close();
    87     iUpdatedIndexes.Close();
    88     }
    88     }
    89 
    89 
    90 // ----------------------------------------------------------------------------
    90 // ----------------------------------------------------------------------------
    91 // 
    91 //
    92 // ----------------------------------------------------------------------------
    92 // ----------------------------------------------------------------------------
    93 //  
    93 //
    94 void CCaWidgetStorageHandler::SynchronizeL( const RWidgetArray& aWidgets )
    94 void CCaWidgetStorageHandler::SynchronizeL( const RWidgetArray& aWidgets )
    95     {
    95     {
    96     FetchWidgetsL();
    96     FetchWidgetsL();
    97     AddWidgetsL( aWidgets );
    97     AddWidgetsL( aWidgets );
    98     RemoveWidgetsL();
    98     RemoveWidgetsL();
    99     }
    99     }
   100 
   100 
   101 // ----------------------------------------------------------------------------
   101 // ----------------------------------------------------------------------------
   102 // 
   102 //
   103 // ----------------------------------------------------------------------------
   103 // ----------------------------------------------------------------------------
   104 //  
   104 //
   105 void CCaWidgetStorageHandler::AddL( const CCaWidgetDescription* aWidget )
   105 void CCaWidgetStorageHandler::AddL( const CCaWidgetDescription* aWidget )
   106     {
   106     {
   107     CCaInnerEntry* entry = aWidget->GetEntryLC();
   107     CCaInnerEntry* entry = aWidget->GetEntryLC();
   108     iStorage->AddL( entry );
   108     iStorage->AddL( entry );
   109     if( ( entry->GetFlags() & ERemovable ) != 0 )
   109     if( entry->GetFlags() & ERemovable )
   110         {
   110         {
   111         AddWidgetToDownloadCollectionL( entry );
   111         AddWidgetToDownloadCollectionL( entry );
   112         }
   112         }
   113     CleanupStack::PopAndDestroy( entry );
   113     CleanupStack::PopAndDestroy( entry );
   114     }
   114     }
   115 
   115 
   116 // ----------------------------------------------------------------------------
   116 // ----------------------------------------------------------------------------
   117 // 
   117 //
   118 // ----------------------------------------------------------------------------
   118 // ----------------------------------------------------------------------------
   119 //  
   119 //
   120 void CCaWidgetStorageHandler::UpdateL( const CCaWidgetDescription* aWidget,
   120 void CCaWidgetStorageHandler::UpdateL( const CCaWidgetDescription* aWidget,
   121         TUint aEntryId )
   121         TUint aEntryId )
   122     {
   122     {
   123     CCaInnerEntry* entry = aWidget->GetEntryLC();
   123     CCaInnerEntry* entry = aWidget->GetEntryLC();
   124     entry->SetId( aEntryId );
   124     entry->SetId( aEntryId );
   125     if( !aWidget->IsMissing() && ( aWidget->GetLibrary() != KNoLibrary ) )
   125     if( !aWidget->IsMissing() && aWidget->IsUsed() )
   126         {
   126         {
   127         entry->SetFlags( entry->GetFlags() & ~EUsed );
   127         entry->SetFlags( entry->GetFlags() & ~EUsed );
   128         }
   128         }
   129     else if(aWidget->IsUsed())
   129     TItemAppearance itemAppearanceChange = EItemAppearanceNotChanged;
   130         {
   130     if( ( entry->GetFlags() & EMissing ) ||
   131         entry->SetFlags( entry->GetFlags() | EUsed );
   131         !( entry->GetFlags() & EVisible ) )
   132         }
   132         {
   133     entry->SetFlags( entry->GetFlags() & ~EMissing );
   133         itemAppearanceChange = EItemAppeared;
   134     iStorage->AddL( entry );
   134         }
       
   135     entry->SetFlags( entry->GetFlags() & ~EMissing | EVisible );
       
   136     iStorage->AddL( entry, EFalse, itemAppearanceChange );
   135     if( !aWidget->IsMissing() )
   137     if( !aWidget->IsMissing() )
   136         {
   138         {
   137         AddWidgetToDownloadCollectionL( entry );
   139         AddWidgetToDownloadCollectionL( entry );
   138         }
   140         }
   139     CleanupStack::PopAndDestroy( entry );
   141     CleanupStack::PopAndDestroy( entry );
   140     }
   142     }
   141 
   143 
   142 // ----------------------------------------------------------------------------
   144 // ----------------------------------------------------------------------------
   143 // 
   145 //
   144 // ----------------------------------------------------------------------------
   146 // ----------------------------------------------------------------------------
   145 //  
   147 //
   146 void CCaWidgetStorageHandler::AddWidgetsL( const RWidgetArray& aWidgets )
   148 void CCaWidgetStorageHandler::AddWidgetsL( const RWidgetArray& aWidgets )
   147     {
   149     {
   148     iUpdatedIndexes.Reset();
   150     iUpdatedIndexes.Reset();
   149     for( TInt i = 0; i < aWidgets.Count(); i++ )
   151     for( TInt i = 0; i < aWidgets.Count(); i++ )
   150         {
   152         {
   151         TInt index = iWidgets.Find( 
   153         TInt index = iWidgets.Find(
   152                 aWidgets[i], CCaWidgetDescription::Compare );
   154                 aWidgets[i], CCaWidgetDescription::Compare );
   153         if( index != KErrNotFound )
   155         if( index != KErrNotFound )
   154             {
   156             {
   155             if( !iWidgets[index]->Compare( *aWidgets[i] ) || 
   157             if( !iWidgets[index]->Compare( *aWidgets[i] ) ||
   156                     iWidgets[index]->IsMissing() )
   158                     iWidgets[index]->IsMissing() )
   157                 {
   159                 {
   158                 aWidgets[i]->SetMissing( iWidgets[index]->IsMissing() );
   160                 aWidgets[i]->SetMissing( iWidgets[index]->IsMissing() );
   159                 aWidgets[i]->SetUsed( iWidgets[index]->IsUsed() );
   161                 aWidgets[i]->SetUsed( iWidgets[index]->IsUsed() );
       
   162                 aWidgets[i]->SetVisible( iWidgets[index]->IsVisible() );
   160                 UpdateL( aWidgets[i], iWidgets[index]->GetEntryId() );
   163                 UpdateL( aWidgets[i], iWidgets[index]->GetEntryId() );
   161                 }
   164                 }
   162             iUpdatedIndexes.AppendL( index );
   165             iUpdatedIndexes.AppendL( index );
   163             }
   166             }
   164         else
   167         else
   167             }
   170             }
   168         }
   171         }
   169     }
   172     }
   170 
   173 
   171 // ----------------------------------------------------------------------------
   174 // ----------------------------------------------------------------------------
   172 // 
   175 //
   173 // ----------------------------------------------------------------------------
   176 // ----------------------------------------------------------------------------
   174 //  
   177 //
   175 void CCaWidgetStorageHandler::RemoveWidgetsL()
   178 void CCaWidgetStorageHandler::RemoveWidgetsL()
   176     {
   179     {
   177     for( TInt i = 0; i < iWidgets.Count(); i++ )
   180     for( TInt i = 0; i < iWidgets.Count(); i++ )
   178         {
   181         {
   179         if( iUpdatedIndexes.Find( i ) == KErrNotFound )
   182         if( iUpdatedIndexes.Find( i ) == KErrNotFound )
   180             {
   183             {
   181             if( iWidgets[i]->GetMmcId() && 
   184             if( iWidgets[i]->GetMmcId() != KNullDesC )
   182                     ( iWidgets[i]->GetMmcId() != 
       
   183                     WidgetScannerUtils::CurrentMmcId( iFs ) ) )
       
   184                 {
   185                 {
   185                 SetMissingFlagL( iWidgets[i] );
   186                 RBuf currentMmcId;
       
   187                 currentMmcId.CreateL( KMassStorageIdLength );
       
   188                 currentMmcId.CleanupClosePushL();
       
   189                 WidgetScannerUtils::CurrentMmcId( iFs, currentMmcId );
       
   190                 if( iWidgets[i]->GetMmcId() == currentMmcId ||
       
   191                         ( iWidgets[i]->GetMmcId() == KCaMassStorage() &&
       
   192                         MassStorageNotInUse() ) )
       
   193                     {
       
   194                     //item was uninstalled so we remove its mmc id
       
   195                     iWidgets[i]->RemoveMmcId();
       
   196                     ClearVisibleFlagL( iWidgets[i] );
       
   197                     }
       
   198                 else
       
   199                     {
       
   200                     SetMissingFlagL( iWidgets[i] );
       
   201                     }
       
   202                 CleanupStack::PopAndDestroy(&currentMmcId);
   186                 }
   203                 }
   187             else
   204             else
   188                 {
   205                 {
   189                 SetMissingFlagL( iWidgets[i] );
   206                 //item was uninstalled so we remove its mmc id
       
   207                 ClearVisibleFlagL( iWidgets[i] );
   190                 }
   208                 }
   191             }
   209             }
   192         }
   210         }
   193     }
   211     }
   194 
   212 
   195 // ----------------------------------------------------------------------------
   213 // ----------------------------------------------------------------------------
   196 // 
   214 //
   197 // ----------------------------------------------------------------------------
   215 // ----------------------------------------------------------------------------
   198 // 
   216 //
   199 void CCaWidgetStorageHandler::AddWidgetToDownloadCollectionL(
   217 void CCaWidgetStorageHandler::AddWidgetToDownloadCollectionL(
   200         const CCaInnerEntry* aEntry )
   218         const CCaInnerEntry* aEntry )
   201     {
   219     {
   202     CCaInnerQuery* queryDownload = CCaInnerQuery::NewLC();
   220     CCaInnerQuery* queryDownload = CCaInnerQuery::NewLC();
   203     CDesC16ArrayFlat* downloadType = new ( ELeave ) CDesC16ArrayFlat(
   221     CDesC16ArrayFlat* downloadType = new ( ELeave ) CDesC16ArrayFlat(
   226     CleanupStack::PopAndDestroy( &idsEntry );
   244     CleanupStack::PopAndDestroy( &idsEntry );
   227     CleanupStack::PopAndDestroy( queryDownload );
   245     CleanupStack::PopAndDestroy( queryDownload );
   228     }
   246     }
   229 
   247 
   230 // ----------------------------------------------------------------------------
   248 // ----------------------------------------------------------------------------
   231 // 
   249 //
   232 // ----------------------------------------------------------------------------
   250 // ----------------------------------------------------------------------------
   233 //  
   251 //
   234 void CCaWidgetStorageHandler::FetchWidgetsL()
   252 void CCaWidgetStorageHandler::FetchWidgetsL()
   235     {
   253     {
   236     CCaInnerQuery* query = CCaInnerQuery::NewLC();
   254     CCaInnerQuery* query = CCaInnerQuery::NewLC();
   237     CDesC16ArrayFlat* widgetType = new ( ELeave ) CDesC16ArrayFlat(
   255     CDesC16ArrayFlat* widgetType = new ( ELeave ) CDesC16ArrayFlat(
   238             KGranularityOne );
   256             KGranularityOne );
   255     CleanupStack::PopAndDestroy( &entries );
   273     CleanupStack::PopAndDestroy( &entries );
   256     CleanupStack::PopAndDestroy( query );
   274     CleanupStack::PopAndDestroy( query );
   257     }
   275     }
   258 
   276 
   259 // ----------------------------------------------------------------------------
   277 // ----------------------------------------------------------------------------
   260 // 
   278 //
   261 // ----------------------------------------------------------------------------
   279 // ----------------------------------------------------------------------------
   262 //  
   280 //
   263 void CCaWidgetStorageHandler::SetMissingFlagL(
   281 void CCaWidgetStorageHandler::SetMissingFlagL(
   264         const CCaWidgetDescription* aWidget )
   282         const CCaWidgetDescription* aWidget )
   265     {
   283     {
   266     CCaInnerEntry* entry = aWidget->GetEntryLC();
   284     if( !aWidget->IsMissing() )
   267     entry->SetFlags( entry->GetFlags() | EMissing );
   285         {
   268     if( aWidget->IsUsed() )
   286         CCaInnerEntry* entry = aWidget->GetEntryLC();
   269         {
   287         entry->SetFlags( entry->GetFlags() | EMissing );
   270         entry->SetFlags( entry->GetFlags() | EUsed );
   288         if( aWidget->IsUsed() )
   271         }
   289             {
   272     iStorage->AddL( entry );
   290             entry->SetFlags( entry->GetFlags() | EUsed );
   273     CleanupStack::PopAndDestroy( entry );
   291             }
   274     }
   292         iStorage->AddL( entry, EFalse, EItemDisappeared );
   275 
   293         CleanupStack::PopAndDestroy( entry );
   276 //  End of File  
   294         }
       
   295     }
       
   296 
       
   297 // ----------------------------------------------------------------------------
       
   298 //
       
   299 // ----------------------------------------------------------------------------
       
   300 //
       
   301 void CCaWidgetStorageHandler::ClearVisibleFlagL(
       
   302         const CCaWidgetDescription* aWidget )
       
   303     {
       
   304     if( aWidget->IsVisible() )
       
   305         {
       
   306         CCaInnerEntry* entry = aWidget->GetEntryLC();
       
   307         entry->SetFlags( entry->GetFlags() & ~EVisible & ~EMissing & ~EUsed );
       
   308         iStorage->AddL( entry, EFalse, EItemDisappeared );
       
   309         CleanupStack::PopAndDestroy( entry );
       
   310         }
       
   311     }
       
   312 
       
   313 // ----------------------------------------------------------------------------
       
   314 //
       
   315 // ----------------------------------------------------------------------------
       
   316 //
       
   317 TBool CCaWidgetStorageHandler::MassStorageNotInUse()
       
   318     {
       
   319     TBool massStorageNotInUse( ETrue );
       
   320     TInt drive;
       
   321     if( DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage, drive ) ==
       
   322         KErrNone )
       
   323         {
       
   324         TUint status;
       
   325         if( DriveInfo::GetDriveStatus( iFs, drive, status ) == KErrNone &&
       
   326             ( status & DriveInfo::EDriveInUse ) )
       
   327             {
       
   328             massStorageNotInUse = EFalse;
       
   329             }
       
   330         }
       
   331     return massStorageNotInUse;
       
   332     }
       
   333 
       
   334 //  End of File