contentstorage/srvsrc/castorageproxy.cpp
branchGCC_SURGE
changeset 105 e7325f632549
parent 104 9b022b1f357c
child 109 e0aa398e6810
equal deleted inserted replaced
81:5ef31a21fdd5 105:e7325f632549
    13  *
    13  *
    14  * Description:
    14  * Description:
    15  *
    15  *
    16  */
    16  */
    17 
    17 
       
    18 #include <driveinfo.h>
       
    19 #include <hbtextresolversymbian.h>
       
    20 
    18 #include "castorage.h"
    21 #include "castorage.h"
    19 #include "castorageproxy.h"
    22 #include "castorageproxy.h"
    20 #include "castoragefactory.h"
    23 #include "castoragefactory.h"
    21 #include "cainnerentry.h"
    24 #include "cainnerentry.h"
    22 #include "cainnerquery.h"
    25 #include "cainnerquery.h"
   105     TItemAppearance aItemAppearanceChange )
   108     TItemAppearance aItemAppearanceChange )
   106     {
   109     {
   107     TChangeType changeType = EAddChangeType;
   110     TChangeType changeType = EAddChangeType;
   108     RArray<TInt> parentArray;
   111     RArray<TInt> parentArray;
   109     CleanupClosePushL( parentArray );
   112     CleanupClosePushL( parentArray );
   110 
   113           
   111     if( aEntry->GetId() > 0 )
   114     if( aEntry->GetId() > 0 )
   112         {
   115         {
   113         changeType = EUpdateChangeType;
   116         changeType = EUpdateChangeType;
   114         RArray<TInt> id;
   117         RArray<TInt> id;
   115         CleanupClosePushL( id );
   118         CleanupClosePushL( id );
   116         id.AppendL( aEntry->GetId() );
   119         id.AppendL( aEntry->GetId() );
   117         iStorage->GetParentsIdsL( id, parentArray );
   120         if (aItemAppearanceChange == EItemUninstallProgressChanged)
       
   121             {
       
   122             // no need to search for parent parents for uninstall 
       
   123             // progress change
       
   124             iStorage->GetParentsIdsL( id, parentArray, EFalse );
       
   125             }
       
   126         else
       
   127             {
       
   128             iStorage->GetParentsIdsL( id, parentArray );
       
   129             }
   118         CleanupStack::PopAndDestroy( &id );
   130         CleanupStack::PopAndDestroy( &id );
   119         }
   131         }
   120 
   132 
   121     if( aItemAppearanceChange==EItemDisappeared )
   133     if( aItemAppearanceChange==EItemDisappeared )
   122         {
   134         {
   124         }
   136         }
   125     else if( aItemAppearanceChange==EItemAppeared )
   137     else if( aItemAppearanceChange==EItemAppeared )
   126         {
   138         {
   127         changeType = EAddChangeType;
   139         changeType = EAddChangeType;
   128         }
   140         }
   129 
   141     
   130     iStorage->AddL( aEntry, aUpdate );
   142     // do not update entry in db with uninstall progress
       
   143     if (aItemAppearanceChange != EItemUninstallProgressChanged)
       
   144         {
       
   145         RPointerArray<CCaLocalizationEntry> localizations;
       
   146 	    CleanupResetAndDestroyPushL( localizations );
       
   147         CCaLocalizationEntry* tempLocalization = NULL;
       
   148         if( aEntry->isLocalized( CCaInnerEntry::ENameLocalized ) )		
       
   149             {
       
   150             tempLocalization = LocalizeTextL( aEntry );
       
   151             if( tempLocalization )
       
   152                 {
       
   153                 localizations.Append( tempLocalization );
       
   154                 tempLocalization = NULL;
       
   155                 }
       
   156             }
       
   157         if( aEntry->isLocalized( CCaInnerEntry::EDescriptionLocalized ) )
       
   158             {
       
   159             tempLocalization = LocalizeDescriptionL( aEntry );
       
   160             if (tempLocalization)
       
   161                 {
       
   162                 localizations.Append(tempLocalization);
       
   163                 tempLocalization = NULL;
       
   164                 }
       
   165             }
       
   166         
       
   167         iStorage->AddL( aEntry, aUpdate );
       
   168         
       
   169         for( TInt j =0; j < localizations.Count(); j++ )
       
   170             {
       
   171             localizations[j]->SetRowId( aEntry->GetId() );
       
   172             AddLocalizationL( *( localizations[j] ) );
       
   173             }
       
   174 		if( localizations.Count() > 0 )
       
   175             {
       
   176             HbTextResolverSymbian::Init( _L(""), KLocalizationFilepathZ );
       
   177             }
       
   178 		 CleanupStack::PopAndDestroy( &localizations );
       
   179         }
       
   180     
       
   181         
   131     for( TInt i = 0; i < iHandlerNotifier.Count(); i++ )
   182     for( TInt i = 0; i < iHandlerNotifier.Count(); i++ )
   132         {
   183         {
   133         iHandlerNotifier[i]->EntryChanged( aEntry, changeType, parentArray );
   184         iHandlerNotifier[i]->EntryChanged( aEntry, changeType, parentArray );
   134         }
   185         }
   135     CleanupStack::PopAndDestroy( &parentArray );
   186     CleanupStack::PopAndDestroy( &parentArray );
   234             RArray<TInt> parentArray;
   285             RArray<TInt> parentArray;
   235             CleanupClosePushL( parentArray );
   286             CleanupClosePushL( parentArray );
   236             iStorage->GetParentsIdsL( id, parentArray );
   287             iStorage->GetParentsIdsL( id, parentArray );
   237             for( TInt i = 0; i < iHandlerNotifier.Count(); i++ )
   288             for( TInt i = 0; i < iHandlerNotifier.Count(); i++ )
   238                 {
   289                 {
       
   290                 resultArray[0]->SetFlags( 
       
   291                         resultArray[0]->GetFlags() | EUsed );
   239                 iHandlerNotifier[i]->EntryChanged( resultArray[0],
   292                 iHandlerNotifier[i]->EntryChanged( resultArray[0],
   240                         EUpdateChangeType,
   293                         EUpdateChangeType,
   241                         parentArray );
   294                         parentArray );
   242                 }
   295                 }
   243             CleanupStack::PopAndDestroy( &parentArray );
   296             CleanupStack::PopAndDestroy( &parentArray );
   270 
   323 
   271 // ---------------------------------------------------------------------------
   324 // ---------------------------------------------------------------------------
   272 //
   325 //
   273 // ---------------------------------------------------------------------------
   326 // ---------------------------------------------------------------------------
   274 //
   327 //
       
   328 EXPORT_C void CCaStorageProxy::AddLocalizationL(
       
   329 		const CCaLocalizationEntry& aLocalization)
       
   330 	{
       
   331 	iStorage->AddLocalizationL(aLocalization);
       
   332 	}
       
   333 
       
   334 // ---------------------------------------------------------------------------
       
   335 //
       
   336 // ---------------------------------------------------------------------------
       
   337 //
   275 EXPORT_C void CCaStorageProxy::DbPropertyL( const TDesC& aProperty,
   338 EXPORT_C void CCaStorageProxy::DbPropertyL( const TDesC& aProperty,
   276         TDes& aPropertyValue )
   339         TDes& aPropertyValue )
   277     {
   340     {
   278     iStorage->DbPropertyL( aProperty, aPropertyValue );
   341     iStorage->DbPropertyL( aProperty, aPropertyValue );
   279     }
   342     }
   305         iHandlerNotifier[i]->GroupContentChanged( parentArray );
   368         iHandlerNotifier[i]->GroupContentChanged( parentArray );
   306         }
   369         }
   307     CleanupStack::PopAndDestroy( &parentArray );
   370     CleanupStack::PopAndDestroy( &parentArray );
   308     }
   371     }
   309 
   372 
       
   373 #ifdef COVERAGE_MEASUREMENT
       
   374 #pragma CTC SKIP
       
   375 #endif //COVERAGE_MEASUREMENT (calls another method)
   310 // ---------------------------------------------------------------------------
   376 // ---------------------------------------------------------------------------
   311 //
   377 //
   312 // ---------------------------------------------------------------------------
   378 // ---------------------------------------------------------------------------
   313 //
   379 //
   314 EXPORT_C void CCaStorageProxy::LoadDataBaseFromRomL()
   380 EXPORT_C void CCaStorageProxy::LoadDataBaseFromRomL()
   315     {
   381     {
   316     iStorage->LoadDataBaseFromRomL();
   382     iStorage->LoadDataBaseFromRomL();
   317     }
   383     }
       
   384 #ifdef COVERAGE_MEASUREMENT
       
   385 #pragma CTC ENDSKIP
       
   386 #endif //COVERAGE_MEASUREMENT
   318 
   387 
   319 // ---------------------------------------------------------
   388 // ---------------------------------------------------------
   320 //
   389 //
   321 // ---------------------------------------------------------
   390 // ---------------------------------------------------------
   322 //
   391 //
   338     if( i != KErrNotFound )
   407     if( i != KErrNotFound )
   339         {
   408         {
   340         iHandlerNotifier.Remove( i );
   409         iHandlerNotifier.Remove( i );
   341         }
   410         }
   342     }
   411     }
       
   412 
       
   413 // ---------------------------------------------------------
       
   414 //
       
   415 // ---------------------------------------------------------
       
   416 //
       
   417 CCaLocalizationEntry* CCaStorageProxy::LocalizeTextL( CCaInnerEntry* aEntry )
       
   418     {
       
   419 	CCaLocalizationEntry* result = NULL;
       
   420 	TInt textLength = aEntry->GetText().Length();
       
   421 	if (textLength > 0)
       
   422 		{
       
   423 		TChar delimiter = '/'; // cannot add it as global
       
   424 		RBuf title;
       
   425 		CleanupClosePushL( title );
       
   426 		title.CreateL( aEntry->GetText() );
       
   427 		TInt pos = title.LocateReverse( delimiter );
       
   428 		if ( pos > 0 && pos + 1 < textLength )   // 1 is for delimiters
       
   429 			{
       
   430 			TPtrC16 logString = title.Mid( pos + 1 ); 
       
   431 			TInt qmFileNameLength = textLength - charsToFilename - 1 - logString.Length();
       
   432 			TPtrC16 qmFile = title.Mid( charsToFilename, qmFileNameLength );
       
   433 			if ( InitializeTranslatorL( qmFile ) )
       
   434 				{
       
   435 			    result = CCaLocalizationEntry::NewLC();			
       
   436 				HBufC* translatedString = HbTextResolverSymbian::LoadLC( logString );
       
   437 				if ( translatedString->Compare( logString ) )
       
   438 					{
       
   439 					result->SetStringIdL( logString );
       
   440 					aEntry->SetTextL( *translatedString );
       
   441 					if( translatedString )
       
   442 						{
       
   443 					    CleanupStack::PopAndDestroy( translatedString );
       
   444 						}
       
   445 					result->SetTableNameL( KLocalizationCaEntry );
       
   446 					result->SetAttributeNameL( KLocalizationEnText );
       
   447 					result->SetQmFilenameL( qmFile );
       
   448 					result->SetRowId( aEntry->GetId() ? 0 : aEntry->GetId() ); // must be added when present
       
   449 					CleanupStack::Pop( result );
       
   450 					}
       
   451 				else 
       
   452 					{
       
   453 					CleanupStack::PopAndDestroy(translatedString);
       
   454 					CleanupStack::PopAndDestroy(result);
       
   455 					result = NULL;
       
   456 					}
       
   457 				}
       
   458 			}
       
   459 		CleanupStack::PopAndDestroy( &title );
       
   460 		}
       
   461 	return result;
       
   462 	}
       
   463 
       
   464 // ---------------------------------------------------------
       
   465 //
       
   466 // ---------------------------------------------------------
       
   467 //
       
   468 CCaLocalizationEntry* CCaStorageProxy::LocalizeDescriptionL( CCaInnerEntry* aEntry )
       
   469     {
       
   470 	CCaLocalizationEntry* result = NULL;
       
   471 	TInt dscLength = aEntry->GetDescription().Length();
       
   472 	if ( dscLength )
       
   473 		{
       
   474 		TChar delimiter = '/'; // cannot add it as global
       
   475 		RBuf description;
       
   476 		CleanupClosePushL( description );
       
   477 		description.CreateL( aEntry->GetDescription() );
       
   478 		TInt pos = description.LocateReverse( delimiter );
       
   479 		if ( pos > 0 && pos + 1 < dscLength )   // 1 is for delimiters
       
   480 			{
       
   481 			TPtrC16 logString = description.Mid(pos + 1);
       
   482 			TInt qmFileNameLength = dscLength - charsToFilename - 1 - logString.Length();
       
   483 			TPtrC16 qmFile = description.Mid(charsToFilename, qmFileNameLength);
       
   484 			if ( InitializeTranslatorL( qmFile ) )
       
   485 				{
       
   486 			    result = CCaLocalizationEntry::NewLC();
       
   487 				HBufC* translatedString = HbTextResolverSymbian::LoadLC( logString );
       
   488 				if ( translatedString->Compare( logString ) )
       
   489 					{
       
   490 					result->SetStringIdL( logString );
       
   491 					aEntry->SetDescriptionL( *translatedString );
       
   492 					CleanupStack::PopAndDestroy( translatedString );
       
   493 					result->SetTableNameL( KLocalizationCaEntry );
       
   494 					result->SetAttributeNameL( KLocalizationEnDescription );
       
   495 					result->SetQmFilenameL( qmFile );
       
   496 					result->SetRowId( aEntry->GetId() ? 0 : aEntry->GetId() ); // must be added when present
       
   497 					CleanupStack::Pop( result );
       
   498 					}
       
   499 				else 
       
   500 					{
       
   501 				    CleanupStack::PopAndDestroy( translatedString );
       
   502 				    CleanupStack::PopAndDestroy( result );
       
   503 				    result = NULL;
       
   504 					}
       
   505 				
       
   506 				}
       
   507 			}
       
   508 		CleanupStack::PopAndDestroy( &description );
       
   509 		}
       
   510 	
       
   511 	return result;
       
   512 	}
       
   513 
       
   514 // ---------------------------------------------------------
       
   515 //
       
   516 // ---------------------------------------------------------
       
   517 //
       
   518 TBool CCaStorageProxy::InitializeTranslatorL( TDesC& aQmFilename )
       
   519     {
       
   520 	TBool result = HbTextResolverSymbian::Init( aQmFilename, KLocalizationFilepathC );
       
   521 	if ( !result )
       
   522 		{
       
   523 		// this should not be called too often 
       
   524 		TChar currentDriveLetter;
       
   525 		TDriveList driveList;
       
   526 		RFs fs;
       
   527 		User::LeaveIfError( fs.Connect() );
       
   528 		User::LeaveIfError( fs.DriveList( driveList ) );
       
   529 
       
   530 		RBuf path;
       
   531 		CleanupClosePushL( path );
       
   532 		path.CreateL( KLocalizationFilepath().Length() + 1 );
       
   533 
       
   534 		for ( TInt driveNr = EDriveY; driveNr >= EDriveA; driveNr-- )
       
   535 			{
       
   536 			if ( driveList[driveNr] )
       
   537 				{
       
   538 				User::LeaveIfError(fs.DriveToChar( driveNr, currentDriveLetter ));
       
   539 				path.Append( currentDriveLetter );
       
   540 				path.Append( KLocalizationFilepath );
       
   541 				if (HbTextResolverSymbian::Init( aQmFilename, path ))
       
   542 					{
       
   543 				    result = ETrue;
       
   544 					break;
       
   545 					}
       
   546 				}
       
   547 			path.Zero();
       
   548 			}
       
   549 		CleanupStack::PopAndDestroy( &path );
       
   550 		fs.Close();
       
   551 		
       
   552 		if( !result )
       
   553 			{
       
   554 		    result = HbTextResolverSymbian::Init( aQmFilename, KLocalizationFilepathZ );
       
   555 			}
       
   556 		}
       
   557 	return result;
       
   558 	}