contentstorage/srvsrc/castorageproxy.cpp
changeset 127 7b66bc3c6dc9
parent 125 26079c1bb561
equal deleted inserted replaced
126:efda7c0771b9 127:7b66bc3c6dc9
   120     TItemAppearance aItemAppearanceChange )
   120     TItemAppearance aItemAppearanceChange )
   121     {
   121     {
   122     TChangeType changeType = EAddChangeType;
   122     TChangeType changeType = EAddChangeType;
   123     RArray<TInt> parentArray;
   123     RArray<TInt> parentArray;
   124     CleanupClosePushL( parentArray );
   124     CleanupClosePushL( parentArray );
   125           
   125 
   126     if( aEntry->GetId() > 0 )
   126     if( aEntry->GetId() > 0 )
   127         {
   127         {
   128         changeType = EUpdateChangeType;
   128         changeType = EUpdateChangeType;
   129         RArray<TInt> id;
   129         RArray<TInt> id;
   130         CleanupClosePushL( id );
   130         CleanupClosePushL( id );
   131         id.AppendL( aEntry->GetId() );
   131         id.AppendL( aEntry->GetId() );
   132         if (aItemAppearanceChange == EItemUninstallProgressChanged)
   132         if (aItemAppearanceChange == EItemUninstallProgressChanged)
   133             {
   133             {
   134             // no need to search for parent parents for uninstall 
   134             // no need to search for parent parents for uninstall
   135             // progress change
   135             // progress change
   136             iStorage->GetParentsIdsL( id, parentArray, EFalse );
   136             iStorage->GetParentsIdsL( id, parentArray, EFalse );
   137             }
   137             }
   138         else
   138         else
   139             {
   139             {
   148         }
   148         }
   149     else if( aItemAppearanceChange==EItemAppeared )
   149     else if( aItemAppearanceChange==EItemAppeared )
   150         {
   150         {
   151         changeType = EAddChangeType;
   151         changeType = EAddChangeType;
   152         }
   152         }
   153     
   153 
   154     // do not update entry in db with uninstall progress
   154     // do not update entry in db with uninstall progress
   155     if (aItemAppearanceChange != EItemUninstallProgressChanged)
   155     if (aItemAppearanceChange != EItemUninstallProgressChanged)
   156         {
   156         {
   157         RPointerArray<CCaLocalizationEntry> localizations;
   157         RPointerArray<CCaLocalizationEntry> localizations;
   158 	    CleanupResetAndDestroyPushL( localizations );
   158 	    CleanupResetAndDestroyPushL( localizations );
   159         CCaLocalizationEntry* tempLocalization = NULL;
   159         CCaLocalizationEntry* tempLocalization = NULL;
   160         if( aEntry->isLocalized( CCaInnerEntry::ENameLocalized ) )		
   160         if( aEntry->isLocalized( CCaInnerEntry::ENameLocalized ) )
   161             {
   161             {
   162             tempLocalization = LocalizeTextL( aEntry );
   162             tempLocalization = LocalizeTextL( aEntry );
   163             if( tempLocalization )
   163             if( tempLocalization )
   164                 {
   164                 {
   165                 localizations.Append( tempLocalization );
   165                 localizations.Append( tempLocalization );
   173                 {
   173                 {
   174                 localizations.Append(tempLocalization);
   174                 localizations.Append(tempLocalization);
   175                 tempLocalization = NULL;
   175                 tempLocalization = NULL;
   176                 }
   176                 }
   177             }
   177             }
   178         
   178 
   179         iStorage->AddL( aEntry, aUpdate );
   179         iStorage->AddL( aEntry, aUpdate );
   180         
   180 
   181         for( TInt j =0; j < localizations.Count(); j++ )
   181         for( TInt j =0; j < localizations.Count(); j++ )
   182             {
   182             {
   183             localizations[j]->SetRowId( aEntry->GetId() );
   183             localizations[j]->SetRowId( aEntry->GetId() );
   184             AddLocalizationL( *( localizations[j] ) );
   184             AddLocalizationL( *( localizations[j] ) );
   185             }
   185             }
   187             {
   187             {
   188             HbTextResolverSymbian::Init( _L(""), KLocalizationFilepathZ );
   188             HbTextResolverSymbian::Init( _L(""), KLocalizationFilepathZ );
   189             }
   189             }
   190 		 CleanupStack::PopAndDestroy( &localizations );
   190 		 CleanupStack::PopAndDestroy( &localizations );
   191         }
   191         }
   192     
   192     aEntry->SetParentIdsL( parentArray );    
   193         
       
   194     for( TInt i = 0; i < iHandlerNotifier.Count(); i++ )
   193     for( TInt i = 0; i < iHandlerNotifier.Count(); i++ )
   195         {
   194         {
   196         iHandlerNotifier[i]->EntryChanged( aEntry, changeType, parentArray );
   195         iHandlerNotifier[i]->EntryChanged( aEntry, changeType, parentArray );
   197         }
   196         }
   198     CleanupStack::PopAndDestroy( &parentArray );
   197     CleanupStack::PopAndDestroy( &parentArray );
   216         iStorage->GetParentsIdsL( aEntryIds, parentArray );
   215         iStorage->GetParentsIdsL( aEntryIds, parentArray );
   217         }
   216         }
   218     iStorage->RemoveL( aEntryIds );
   217     iStorage->RemoveL( aEntryIds );
   219     for( TInt i( 0 ); i < resultContainer.Count(); i++ )
   218     for( TInt i( 0 ); i < resultContainer.Count(); i++ )
   220         {
   219         {
       
   220         resultContainer[i]->SetParentIdsL( parentArray );
   221         for( TInt j( 0 ); j < iHandlerNotifier.Count(); j++ )
   221         for( TInt j( 0 ); j < iHandlerNotifier.Count(); j++ )
   222             {
   222             {
   223             iHandlerNotifier[j]->EntryChanged( resultContainer[i],
   223             iHandlerNotifier[j]->EntryChanged( resultContainer[i],
   224                     ERemoveChangeType, parentArray );
   224                     ERemoveChangeType, parentArray );
   225             }
   225             }
   252 //
   252 //
   253 // ---------------------------------------------------------------------------
   253 // ---------------------------------------------------------------------------
   254 //
   254 //
   255 EXPORT_C void CCaStorageProxy::TouchL( CCaInnerEntry* aEntry )
   255 EXPORT_C void CCaStorageProxy::TouchL( CCaInnerEntry* aEntry )
   256     {
   256     {
   257     CCaInnerQuery* touchQuery = CCaInnerQuery::NewLC();
   257     if( aEntry->GetId() == 0 && aEntry->GetUid() != 0 )
   258 
   258         {
   259     TInt entryId = aEntry->GetId();
   259         CCaInnerQuery* query = CCaInnerQuery::NewLC();
   260 
   260         query->SetUid( static_cast<TUint>( aEntry->GetUid()) );
   261     if ( entryId == 0 && aEntry->GetUid() != 0)
   261         query->SetFlagsOn( ERemovable );
   262         {
   262         query->SetFlagsOff( EUsed );
   263         CCaInnerQuery* idQuery = CCaInnerQuery::NewLC();
   263 
   264         idQuery->SetUid( static_cast<TUint>( aEntry->GetUid()) );
   264         RPointerArray<CCaInnerEntry> resultArray;
   265 
   265         CleanupClosePushL( resultArray );
   266         RArray<TInt> idArray;
   266         iStorage->GetEntriesL( query, resultArray );
   267         CleanupClosePushL( idArray );
   267         if( resultArray.Count() == 1 )
   268 
   268             {
   269         iStorage->GetEntriesIdsL( idQuery, idArray );
   269             PrivateTouchL( resultArray[0] );
   270 
   270             }
   271         if (idArray.Count() == 1 )
   271         else
   272             {
   272             {
   273             entryId = idArray[0];
   273             User::Leave( KErrNotFound );
   274             aEntry->SetId( entryId );
   274             }
   275             }
   275         CleanupStack::PopAndDestroy( &resultArray );
   276 
   276         CleanupStack::PopAndDestroy( query );
   277         CleanupStack::PopAndDestroy( &idArray );
   277         }
   278         CleanupStack::PopAndDestroy( idQuery );
   278     else if( aEntry->GetId() > 0 )
   279         }
   279         {
   280 
   280         PrivateTouchL( aEntry );
   281     RArray<TInt> id;
   281         }
   282     CleanupClosePushL( id );
   282     else
   283     id.AppendL( entryId );
   283         {
   284     touchQuery->SetIdsL( id );
   284         User::Leave( KErrArgument );
   285     RPointerArray<CCaInnerEntry> resultArray;
   285         }
   286     CleanupResetAndDestroyPushL( resultArray );
       
   287     iStorage->GetEntriesL( touchQuery, resultArray );
       
   288     iStorage->TouchL( entryId, aEntry->GetFlags() & ERemovable );
       
   289     for( TInt i = 0; i < iHandlerNotifier.Count(); i++ )
       
   290         {
       
   291         iHandlerNotifier[i]->EntryTouched( entryId );
       
   292         }
       
   293     if( resultArray.Count() > 0 )
       
   294         {
       
   295         if( !( resultArray[0]->GetFlags() & EUsed ) )
       
   296             {
       
   297             RArray<TInt> parentArray;
       
   298             CleanupClosePushL( parentArray );
       
   299             iStorage->GetParentsIdsL( id, parentArray );
       
   300             for( TInt i = 0; i < iHandlerNotifier.Count(); i++ )
       
   301                 {
       
   302                 resultArray[0]->SetFlags( 
       
   303                         resultArray[0]->GetFlags() | EUsed );
       
   304                 iHandlerNotifier[i]->EntryChanged( resultArray[0],
       
   305                         EUpdateChangeType,
       
   306                         parentArray );
       
   307                 }
       
   308             CleanupStack::PopAndDestroy( &parentArray );
       
   309             }
       
   310         }
       
   311     CleanupStack::PopAndDestroy( &resultArray );
       
   312     CleanupStack::PopAndDestroy( &id );
       
   313     CleanupStack::PopAndDestroy( touchQuery );
       
   314     }
   286     }
   315 
   287 
   316 // ---------------------------------------------------------------------------
   288 // ---------------------------------------------------------------------------
   317 //
   289 //
   318 // ---------------------------------------------------------------------------
   290 // ---------------------------------------------------------------------------
   392 #endif //COVERAGE_MEASUREMENT (calls another method)
   364 #endif //COVERAGE_MEASUREMENT (calls another method)
   393 
   365 
   394 EXPORT_C void CCaStorageProxy::SaveDatabaseL()
   366 EXPORT_C void CCaStorageProxy::SaveDatabaseL()
   395     {
   367     {
   396     iStorage->SaveDatabaseL();
   368     iStorage->SaveDatabaseL();
   397     }
       
   398 #ifdef COVERAGE_MEASUREMENT
       
   399 #pragma CTC ENDSKIP
       
   400 #endif //COVERAGE_MEASUREMENT
       
   401 
       
   402 
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 // ---------------------------------------------------------------------------
       
   406 //
       
   407 #ifdef COVERAGE_MEASUREMENT
       
   408 #pragma CTC SKIP
       
   409 #endif //COVERAGE_MEASUREMENT (calls another method)
       
   410 
       
   411 EXPORT_C void CCaStorageProxy::RestoreDatabaseL()
       
   412     {
       
   413     iStorage->RestoreDatabaseL();
       
   414     }
   369     }
   415 #ifdef COVERAGE_MEASUREMENT
   370 #ifdef COVERAGE_MEASUREMENT
   416 #pragma CTC ENDSKIP
   371 #pragma CTC ENDSKIP
   417 #endif //COVERAGE_MEASUREMENT
   372 #endif //COVERAGE_MEASUREMENT
   418 
   373 
   473 		CleanupClosePushL( title );
   428 		CleanupClosePushL( title );
   474 		title.CreateL( aEntry->GetText() );
   429 		title.CreateL( aEntry->GetText() );
   475 		TInt pos = title.LocateReverse( delimiter );
   430 		TInt pos = title.LocateReverse( delimiter );
   476 		if ( pos > 0 && pos + 1 < textLength )   // 1 is for delimiters
   431 		if ( pos > 0 && pos + 1 < textLength )   // 1 is for delimiters
   477 			{
   432 			{
   478 			TPtrC16 logString = title.Mid( pos + 1 ); 
   433 			TPtrC16 logString = title.Mid( pos + 1 );
   479 			TInt qmFileNameLength = 
   434 			TInt qmFileNameLength = 
   480 			        textLength - charsToFilename - 1 - logString.Length();
   435 			        textLength - charsToFilename - 1 - logString.Length();
   481 			TPtrC16 qmFile = title.Mid( charsToFilename, qmFileNameLength );
   436 			TPtrC16 qmFile = title.Mid( charsToFilename, qmFileNameLength );
   482 			if ( InitializeTranslatorL( qmFile ) )
   437 			if ( InitializeTranslatorL( qmFile ) )
   483 				{
   438 				{
   484 			    result = CCaLocalizationEntry::NewLC();			
   439 			    result = CCaLocalizationEntry::NewLC();
   485 				HBufC* translatedString = 
   440 				HBufC* translatedString = 
   486 				        HbTextResolverSymbian::LoadLC( logString );
   441 				        HbTextResolverSymbian::LoadLC( logString );
   487 				if ( translatedString->Compare( logString ) )
   442 				if ( translatedString->Compare( logString ) )
   488 					{
   443 					{
   489 					result->SetStringIdL( logString );
   444 					result->SetStringIdL( logString );
   496 					result->SetAttributeNameL( KLocalizationEnText );
   451 					result->SetAttributeNameL( KLocalizationEnText );
   497 					result->SetQmFilenameL( qmFile );
   452 					result->SetQmFilenameL( qmFile );
   498 					result->SetRowId( aEntry->GetId() ? 0 : aEntry->GetId() ); // must be added when present
   453 					result->SetRowId( aEntry->GetId() ? 0 : aEntry->GetId() ); // must be added when present
   499 					CleanupStack::Pop( result );
   454 					CleanupStack::Pop( result );
   500 					}
   455 					}
   501 				else 
   456 				else
   502 					{
   457 					{
   503 					CleanupStack::PopAndDestroy(translatedString);
   458 					CleanupStack::PopAndDestroy(translatedString);
   504 					CleanupStack::PopAndDestroy(result);
   459 					CleanupStack::PopAndDestroy(result);
   505 					result = NULL;
   460 					result = NULL;
   506 					}
   461 					}
   544 					result->SetAttributeNameL( KLocalizationEnDescription );
   499 					result->SetAttributeNameL( KLocalizationEnDescription );
   545 					result->SetQmFilenameL( qmFile );
   500 					result->SetQmFilenameL( qmFile );
   546 					result->SetRowId( aEntry->GetId() ? 0 : aEntry->GetId() ); // must be added when present
   501 					result->SetRowId( aEntry->GetId() ? 0 : aEntry->GetId() ); // must be added when present
   547 					CleanupStack::Pop( result );
   502 					CleanupStack::Pop( result );
   548 					}
   503 					}
   549 				else 
   504 				else
   550 					{
   505 					{
   551 				    CleanupStack::PopAndDestroy( translatedString );
   506 				    CleanupStack::PopAndDestroy( translatedString );
   552 				    CleanupStack::PopAndDestroy( result );
   507 				    CleanupStack::PopAndDestroy( result );
   553 				    result = NULL;
   508 				    result = NULL;
   554 					}
   509 					}
   555 				
   510 
   556 				}
   511 				}
   557 			}
   512 			}
   558 		CleanupStack::PopAndDestroy( &description );
   513 		CleanupStack::PopAndDestroy( &description );
   559 		}
   514 		}
   560 	
   515 
   561 	return result;
   516 	return result;
   562 	}
   517 	}
   563 
   518 
   564 // ---------------------------------------------------------
   519 // ---------------------------------------------------------
   565 //
   520 //
   593 TBool CCaStorageProxy::InitializeTranslatorL( const TDesC& aQmFilename )
   548 TBool CCaStorageProxy::InitializeTranslatorL( const TDesC& aQmFilename )
   594     {
   549     {
   595 	TBool result = HbTextResolverSymbian::Init( aQmFilename, KLocalizationFilepathC );
   550 	TBool result = HbTextResolverSymbian::Init( aQmFilename, KLocalizationFilepathC );
   596 	if ( !result )
   551 	if ( !result )
   597 		{
   552 		{
   598 		// this should not be called too often 
   553 		// this should not be called too often
   599 		TChar currentDriveLetter;
   554 		TChar currentDriveLetter;
   600 		TDriveList driveList;
   555 		TDriveList driveList;
   601 		RFs fs;
   556 		RFs fs;
   602 		CleanupClosePushL( fs );
   557 		CleanupClosePushL( fs );
   603 		User::LeaveIfError( fs.Connect() );
   558 		User::LeaveIfError( fs.Connect() );
   622 				}
   577 				}
   623 			path.Zero();
   578 			path.Zero();
   624 			}
   579 			}
   625 		CleanupStack::PopAndDestroy( &path );
   580 		CleanupStack::PopAndDestroy( &path );
   626 		CleanupStack::PopAndDestroy( &fs );
   581 		CleanupStack::PopAndDestroy( &fs );
   627 		
   582 
   628 		if( !result )
   583 		if( !result )
   629 			{
   584 			{
   630 		    result = HbTextResolverSymbian::Init( aQmFilename, KLocalizationFilepathZ );
   585 		    result = HbTextResolverSymbian::Init( aQmFilename, KLocalizationFilepathZ );
   631 			}
   586 			}
   632 		}
   587 		}
   633 	return result;
   588 	return result;
   634 	}
   589 	}
       
   590 
       
   591 // ---------------------------------------------------------
       
   592 //
       
   593 // ---------------------------------------------------------
       
   594 //
       
   595 void CCaStorageProxy::PrivateTouchL( CCaInnerEntry* aEntry )
       
   596     {
       
   597     iStorage->TouchL( aEntry->GetId(), aEntry->GetFlags() & ERemovable );
       
   598     for( TInt i = 0; i < iHandlerNotifier.Count(); i++ )
       
   599         {
       
   600         iHandlerNotifier[i]->EntryTouched( aEntry->GetId() );
       
   601         }
       
   602     if( !( aEntry->GetFlags() & EUsed ) &&
       
   603             ( aEntry->GetFlags() & ERemovable ) )
       
   604         {
       
   605         RArray<TInt> id;
       
   606         CleanupClosePushL( id );
       
   607         id.AppendL( aEntry->GetId() );
       
   608         RArray<TInt> parentArray;
       
   609         CleanupClosePushL( parentArray );
       
   610         iStorage->GetParentsIdsL( id, parentArray );
       
   611         aEntry->SetParentIdsL( parentArray );
       
   612         for( TInt i = 0; i < iHandlerNotifier.Count(); i++ )
       
   613             {
       
   614             aEntry->SetFlags( 
       
   615                     aEntry->GetFlags() | EUsed );
       
   616             iHandlerNotifier[i]->EntryChanged( aEntry,
       
   617                     EUpdateChangeType,
       
   618                     parentArray );
       
   619             }
       
   620         CleanupStack::PopAndDestroy( &parentArray );
       
   621         CleanupStack::PopAndDestroy( &id );
       
   622         }
       
   623     }