contentstorage/srvsrc/castorageproxy.cpp
changeset 103 b99b84bcd2d1
parent 80 397d00875918
child 104 9b022b1f357c
equal deleted inserted replaced
83:156f692b1687 103:b99b84bcd2d1
    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 );
   315         iHandlerNotifier[i]->GroupContentChanged( parentArray );
   366         iHandlerNotifier[i]->GroupContentChanged( parentArray );
   316         }
   367         }
   317     CleanupStack::PopAndDestroy( &parentArray );
   368     CleanupStack::PopAndDestroy( &parentArray );
   318     }
   369     }
   319 
   370 
       
   371 #ifdef COVERAGE_MEASUREMENT
       
   372 #pragma CTC SKIP
       
   373 #endif //COVERAGE_MEASUREMENT (calls another method)
   320 // ---------------------------------------------------------------------------
   374 // ---------------------------------------------------------------------------
   321 //
   375 //
   322 // ---------------------------------------------------------------------------
   376 // ---------------------------------------------------------------------------
   323 //
   377 //
   324 EXPORT_C void CCaStorageProxy::LoadDataBaseFromRomL()
   378 EXPORT_C void CCaStorageProxy::LoadDataBaseFromRomL()
   325     {
   379     {
   326     iStorage->LoadDataBaseFromRomL();
   380     iStorage->LoadDataBaseFromRomL();
   327     }
   381     }
       
   382 #ifdef COVERAGE_MEASUREMENT
       
   383 #pragma CTC ENDSKIP
       
   384 #endif //COVERAGE_MEASUREMENT
   328 
   385 
   329 // ---------------------------------------------------------
   386 // ---------------------------------------------------------
   330 //
   387 //
   331 // ---------------------------------------------------------
   388 // ---------------------------------------------------------
   332 //
   389 //
   348     if( i != KErrNotFound )
   405     if( i != KErrNotFound )
   349         {
   406         {
   350         iHandlerNotifier.Remove( i );
   407         iHandlerNotifier.Remove( i );
   351         }
   408         }
   352     }
   409     }
       
   410 
       
   411 // ---------------------------------------------------------
       
   412 //
       
   413 // ---------------------------------------------------------
       
   414 //
       
   415 CCaLocalizationEntry* CCaStorageProxy::LocalizeTextL( CCaInnerEntry* aEntry )
       
   416     {
       
   417 	CCaLocalizationEntry* result = NULL;
       
   418 	TInt textLength = aEntry->GetText().Length();
       
   419 	if (textLength > 0)
       
   420 		{
       
   421 		TChar delimiter = '/'; // cannot add it as global
       
   422 		RBuf title;
       
   423 		CleanupClosePushL( title );
       
   424 		title.CreateL( aEntry->GetText() );
       
   425 		TInt pos = title.LocateReverse( delimiter );
       
   426 		if ( pos > 0 && pos + 1 < textLength )   // 1 is for delimiters
       
   427 			{
       
   428 			TPtrC16 logString = title.Mid( pos + 1 ); 
       
   429 			TInt qmFileNameLength = textLength - charsToFilename - 1 - logString.Length();
       
   430 			TPtrC16 qmFile = title.Mid( charsToFilename, qmFileNameLength );
       
   431 			if ( InitializeTranslatorL( qmFile ) )
       
   432 				{
       
   433 			    result = CCaLocalizationEntry::NewLC();			
       
   434 				HBufC* translatedString = HbTextResolverSymbian::LoadLC( logString );
       
   435 				if ( translatedString->Compare( logString ) )
       
   436 					{
       
   437 					result->SetStringIdL( logString );
       
   438 					aEntry->SetTextL( *translatedString );
       
   439 					if( translatedString )
       
   440 						{
       
   441 					    CleanupStack::PopAndDestroy( translatedString );
       
   442 						}
       
   443 					result->SetTableNameL( KLocalizationCaEntry );
       
   444 					result->SetAttributeNameL( KLocalizationEnText );
       
   445 					result->SetQmFilenameL( qmFile );
       
   446 					result->SetRowId( aEntry->GetId() ? 0 : aEntry->GetId() ); // must be added when present
       
   447 					}
       
   448 				else 
       
   449 					{
       
   450 				    if (translatedString)
       
   451 						{
       
   452 						CleanupStack::PopAndDestroy(translatedString);
       
   453 						}
       
   454 					}
       
   455 				CleanupStack::Pop( result );
       
   456 				}
       
   457 			}
       
   458 		CleanupStack::PopAndDestroy( &title );
       
   459 		}
       
   460 	return result;
       
   461 	}
       
   462 
       
   463 // ---------------------------------------------------------
       
   464 //
       
   465 // ---------------------------------------------------------
       
   466 //
       
   467 CCaLocalizationEntry* CCaStorageProxy::LocalizeDescriptionL( CCaInnerEntry* aEntry )
       
   468     {
       
   469 	CCaLocalizationEntry* result = NULL;
       
   470 	TInt dscLength = aEntry->GetDescription().Length();
       
   471 	if ( dscLength )
       
   472 		{
       
   473 		TChar delimiter = '/'; // cannot add it as global
       
   474 		RBuf description;
       
   475 		CleanupClosePushL( description );
       
   476 		description.CreateL( aEntry->GetDescription() );
       
   477 		TInt pos = description.LocateReverse( delimiter );
       
   478 		if ( pos > 0 && pos + 1 < dscLength )   // 1 is for delimiters
       
   479 			{
       
   480 			TPtrC16 logString = description.Mid(pos + 1);
       
   481 			TInt qmFileNameLength = dscLength - charsToFilename - 1 - logString.Length();
       
   482 			TPtrC16 qmFile = description.Mid(charsToFilename, qmFileNameLength);
       
   483 			if ( InitializeTranslatorL( qmFile ) )
       
   484 				{
       
   485 			    result = CCaLocalizationEntry::NewLC();
       
   486 				HBufC* translatedString = HbTextResolverSymbian::LoadLC( logString );
       
   487 				if ( translatedString->Compare( logString ) )
       
   488 					{
       
   489 					result->SetStringIdL( logString );
       
   490 					aEntry->SetDescriptionL( *translatedString );
       
   491 					CleanupStack::PopAndDestroy( translatedString );
       
   492 					result->SetTableNameL( KLocalizationCaEntry );
       
   493 					result->SetAttributeNameL( KLocalizationEnDescription );
       
   494 					result->SetQmFilenameL( qmFile );
       
   495 					result->SetRowId( aEntry->GetId() ? 0 : aEntry->GetId() ); // must be added when present
       
   496 					}
       
   497 				else 
       
   498 					{
       
   499 				    CleanupStack::PopAndDestroy( translatedString );
       
   500 					}
       
   501 				CleanupStack::Pop( result );
       
   502 				}
       
   503 			}
       
   504 		CleanupStack::PopAndDestroy( &description );
       
   505 		}
       
   506 	return result;
       
   507 	}
       
   508 
       
   509 // ---------------------------------------------------------
       
   510 //
       
   511 // ---------------------------------------------------------
       
   512 //
       
   513 TBool CCaStorageProxy::InitializeTranslatorL( TDesC& aQmFilename )
       
   514     {
       
   515 	TBool result = HbTextResolverSymbian::Init( aQmFilename, KLocalizationFilepathC );
       
   516 	if ( !result )
       
   517 		{
       
   518 		// this should not be called too often 
       
   519 		TChar currentDriveLetter;
       
   520 		TDriveList driveList;
       
   521 		RFs fs;
       
   522 		User::LeaveIfError( fs.Connect() );
       
   523 		User::LeaveIfError( fs.DriveList( driveList ) );
       
   524 
       
   525 		RBuf path;
       
   526 		CleanupClosePushL( path );
       
   527 		path.CreateL( KLocalizationFilepath().Length() + 1 );
       
   528 
       
   529 		for ( TInt driveNr = EDriveY; driveNr >= EDriveA; driveNr-- )
       
   530 			{
       
   531 			if ( driveList[driveNr] )
       
   532 				{
       
   533 				User::LeaveIfError(fs.DriveToChar( driveNr, currentDriveLetter ));
       
   534 				path.Append( currentDriveLetter );
       
   535 				path.Append( KLocalizationFilepath );
       
   536 				if (HbTextResolverSymbian::Init( aQmFilename, path ))
       
   537 					{
       
   538 				    result = ETrue;
       
   539 					break;
       
   540 					}
       
   541 				}
       
   542 			path.Zero();
       
   543 			}
       
   544 		CleanupStack::PopAndDestroy( &path );
       
   545 		fs.Close();
       
   546 		
       
   547 		if( !result )
       
   548 			{
       
   549 		    result = HbTextResolverSymbian::Init( aQmFilename, KLocalizationFilepathZ );
       
   550 			}
       
   551 		}
       
   552 	return result;
       
   553 	}