contentstorage/srvsrc/castorageproxy.cpp
changeset 125 26079c1bb561
parent 107 b34d53f6acdf
child 127 7b66bc3c6dc9
equal deleted inserted replaced
123:d1dadafc5584 125:26079c1bb561
    73 //
    73 //
    74 // ---------------------------------------------------------------------------
    74 // ---------------------------------------------------------------------------
    75 //
    75 //
    76 CCaStorageProxy::~CCaStorageProxy()
    76 CCaStorageProxy::~CCaStorageProxy()
    77     {
    77     {
       
    78     iTitleUserColName.Close();
    78     delete iStorage;
    79     delete iStorage;
    79     iHandlerNotifier.Close();
    80     iHandlerNotifier.Close();
    80     }
    81     }
    81 
    82 
    82 // ---------------------------------------------------------------------------
    83 // ---------------------------------------------------------------------------
    85 //
    86 //
    86 EXPORT_C void CCaStorageProxy::GetEntriesL(const CCaInnerQuery* aQuery,
    87 EXPORT_C void CCaStorageProxy::GetEntriesL(const CCaInnerQuery* aQuery,
    87         RPointerArray<CCaInnerEntry>& aResultContainer )
    88         RPointerArray<CCaInnerEntry>& aResultContainer )
    88     {
    89     {
    89     iStorage->GetEntriesL( aQuery, aResultContainer );
    90     iStorage->GetEntriesL( aQuery, aResultContainer );
       
    91     if( aResultContainer.Count() == 1 
       
    92             && aResultContainer[0]->
       
    93             GetEntryTypeName().Compare( KCaTypeCollection ) == KErrNone )
       
    94         {
       
    95         TPtrC titleName;
       
    96         if( !aResultContainer[0]->FindAttribute( KCaAttrTitleName, titleName ) )
       
    97             {
       
    98             AddTitleNameL( aResultContainer[0] );
       
    99             }
       
   100         }
       
   101     
    90     }
   102     }
    91 
   103 
    92 // ---------------------------------------------------------------------------
   104 // ---------------------------------------------------------------------------
    93 //
   105 //
    94 // ---------------------------------------------------------------------------
   106 // ---------------------------------------------------------------------------
   452 //
   464 //
   453 CCaLocalizationEntry* CCaStorageProxy::LocalizeTextL( CCaInnerEntry* aEntry )
   465 CCaLocalizationEntry* CCaStorageProxy::LocalizeTextL( CCaInnerEntry* aEntry )
   454     {
   466     {
   455 	CCaLocalizationEntry* result = NULL;
   467 	CCaLocalizationEntry* result = NULL;
   456 	TInt textLength = aEntry->GetText().Length();
   468 	TInt textLength = aEntry->GetText().Length();
   457 	if (textLength > 0)
   469 	if( textLength > 0 )
   458 		{
   470 		{
   459 		TChar delimiter = '/'; // cannot add it as global
   471 		TChar delimiter = '/'; // cannot add it as global
   460 		RBuf title;
   472 		RBuf title;
   461 		CleanupClosePushL( title );
   473 		CleanupClosePushL( title );
   462 		title.CreateL( aEntry->GetText() );
   474 		title.CreateL( aEntry->GetText() );
   463 		TInt pos = title.LocateReverse( delimiter );
   475 		TInt pos = title.LocateReverse( delimiter );
   464 		if ( pos > 0 && pos + 1 < textLength )   // 1 is for delimiters
   476 		if ( pos > 0 && pos + 1 < textLength )   // 1 is for delimiters
   465 			{
   477 			{
   466 			TPtrC16 logString = title.Mid( pos + 1 ); 
   478 			TPtrC16 logString = title.Mid( pos + 1 ); 
   467 			TInt qmFileNameLength = textLength - charsToFilename - 1 - logString.Length();
   479 			TInt qmFileNameLength = 
       
   480 			        textLength - charsToFilename - 1 - logString.Length();
   468 			TPtrC16 qmFile = title.Mid( charsToFilename, qmFileNameLength );
   481 			TPtrC16 qmFile = title.Mid( charsToFilename, qmFileNameLength );
   469 			if ( InitializeTranslatorL( qmFile ) )
   482 			if ( InitializeTranslatorL( qmFile ) )
   470 				{
   483 				{
   471 			    result = CCaLocalizationEntry::NewLC();			
   484 			    result = CCaLocalizationEntry::NewLC();			
   472 				HBufC* translatedString = HbTextResolverSymbian::LoadLC( logString );
   485 				HBufC* translatedString = 
       
   486 				        HbTextResolverSymbian::LoadLC( logString );
   473 				if ( translatedString->Compare( logString ) )
   487 				if ( translatedString->Compare( logString ) )
   474 					{
   488 					{
   475 					result->SetStringIdL( logString );
   489 					result->SetStringIdL( logString );
   476 					aEntry->SetTextL( *translatedString );
   490 					aEntry->SetTextL( *translatedString );
   477 					if( translatedString )
   491 					if( translatedString )
   503 //
   517 //
   504 CCaLocalizationEntry* CCaStorageProxy::LocalizeDescriptionL( CCaInnerEntry* aEntry )
   518 CCaLocalizationEntry* CCaStorageProxy::LocalizeDescriptionL( CCaInnerEntry* aEntry )
   505     {
   519     {
   506 	CCaLocalizationEntry* result = NULL;
   520 	CCaLocalizationEntry* result = NULL;
   507 	TInt dscLength = aEntry->GetDescription().Length();
   521 	TInt dscLength = aEntry->GetDescription().Length();
   508 	if ( dscLength )
   522 	if( dscLength )
   509 		{
   523 		{
   510 		TChar delimiter = '/'; // cannot add it as global
   524 		TChar delimiter = '/'; // cannot add it as global
   511 		RBuf description;
   525 		RBuf description;
   512 		CleanupClosePushL( description );
   526 		CleanupClosePushL( description );
   513 		description.CreateL( aEntry->GetDescription() );
   527 		description.CreateL( aEntry->GetDescription() );
   549 
   563 
   550 // ---------------------------------------------------------
   564 // ---------------------------------------------------------
   551 //
   565 //
   552 // ---------------------------------------------------------
   566 // ---------------------------------------------------------
   553 //
   567 //
   554 TBool CCaStorageProxy::InitializeTranslatorL( TDesC& aQmFilename )
   568 void CCaStorageProxy::AddTitleNameL( CCaInnerEntry* aEntry )
       
   569     {
       
   570     if( !iTitleUserColName.Length() )
       
   571         {
       
   572         if ( InitializeTranslatorL( KCaQmFile ) )
       
   573             {
       
   574             HBufC* translatedString = 
       
   575                     HbTextResolverSymbian::LoadLC( KDefaultLocTitleName );
       
   576             if ( translatedString->Compare( KDefaultLocTitleName ) )
       
   577                 {
       
   578                 iTitleUserColName.CreateL( *translatedString );
       
   579                 }
       
   580             CleanupStack::PopAndDestroy( translatedString );
       
   581             }
       
   582         }
       
   583     if( iTitleUserColName.Length() )
       
   584         {
       
   585         aEntry->AddAttributeL( KCaAttrTitleName, iTitleUserColName );
       
   586         }
       
   587     }
       
   588 
       
   589 // ---------------------------------------------------------
       
   590 //
       
   591 // ---------------------------------------------------------
       
   592 //
       
   593 TBool CCaStorageProxy::InitializeTranslatorL( const TDesC& aQmFilename )
   555     {
   594     {
   556 	TBool result = HbTextResolverSymbian::Init( aQmFilename, KLocalizationFilepathC );
   595 	TBool result = HbTextResolverSymbian::Init( aQmFilename, KLocalizationFilepathC );
   557 	if ( !result )
   596 	if ( !result )
   558 		{
   597 		{
   559 		// this should not be called too often 
   598 		// this should not be called too often 
   560 		TChar currentDriveLetter;
   599 		TChar currentDriveLetter;
   561 		TDriveList driveList;
   600 		TDriveList driveList;
   562 		RFs fs;
   601 		RFs fs;
       
   602 		CleanupClosePushL( fs );
   563 		User::LeaveIfError( fs.Connect() );
   603 		User::LeaveIfError( fs.Connect() );
   564 		User::LeaveIfError( fs.DriveList( driveList ) );
   604 		User::LeaveIfError( fs.DriveList( driveList ) );
   565 
   605 
   566 		RBuf path;
   606 		RBuf path;
   567 		CleanupClosePushL( path );
   607 		CleanupClosePushL( path );
   581 					}
   621 					}
   582 				}
   622 				}
   583 			path.Zero();
   623 			path.Zero();
   584 			}
   624 			}
   585 		CleanupStack::PopAndDestroy( &path );
   625 		CleanupStack::PopAndDestroy( &path );
   586 		fs.Close();
   626 		CleanupStack::PopAndDestroy( &fs );
   587 		
   627 		
   588 		if( !result )
   628 		if( !result )
   589 			{
   629 			{
   590 		    result = HbTextResolverSymbian::Init( aQmFilename, KLocalizationFilepathZ );
   630 		    result = HbTextResolverSymbian::Init( aQmFilename, KLocalizationFilepathZ );
   591 			}
   631 			}