contentstorage/srvsrc/castorageproxy.cpp
changeset 98 d2f833ab7940
parent 94 dbb8300717f7
child 99 7aaf39b772ac
--- a/contentstorage/srvsrc/castorageproxy.cpp	Tue Jun 01 11:30:17 2010 +0300
+++ b/contentstorage/srvsrc/castorageproxy.cpp	Fri Jun 11 16:13:51 2010 +0300
@@ -15,6 +15,9 @@
  *
  */
 
+#include <driveinfo.h>
+#include <hbtextresolversymbian.h>
+
 #include "castorage.h"
 #include "castorageproxy.h"
 #include "castoragefactory.h"
@@ -107,14 +110,23 @@
     TChangeType changeType = EAddChangeType;
     RArray<TInt> parentArray;
     CleanupClosePushL( parentArray );
-
+          
     if( aEntry->GetId() > 0 )
         {
         changeType = EUpdateChangeType;
         RArray<TInt> id;
         CleanupClosePushL( id );
         id.AppendL( aEntry->GetId() );
-        iStorage->GetParentsIdsL( id, parentArray );
+        if (aItemAppearanceChange == EItemUninstallProgressChanged)
+            {
+            // no need to search for parent parents for uninstall 
+            // progress change
+            iStorage->GetParentsIdsL( id, parentArray, EFalse );
+            }
+        else
+            {
+            iStorage->GetParentsIdsL( id, parentArray );
+            }
         CleanupStack::PopAndDestroy( &id );
         }
 
@@ -126,8 +138,47 @@
         {
         changeType = EAddChangeType;
         }
-
-    iStorage->AddL( aEntry, aUpdate );
+    
+    // do not update entry in db with uninstall progress
+    if (aItemAppearanceChange != EItemUninstallProgressChanged)
+        {
+        RPointerArray<CCaLocalizationEntry> localizations;
+	    CleanupResetAndDestroyPushL( localizations );
+        CCaLocalizationEntry* tempLocalization = NULL;
+        if( aEntry->isLocalized( CCaInnerEntry::ENameLocalized ) )		
+            {
+            tempLocalization = LocalizeTextL( aEntry );
+            if( tempLocalization )
+                {
+                localizations.Append( tempLocalization );
+                tempLocalization = NULL;
+                }
+            }
+        if( aEntry->isLocalized( CCaInnerEntry::EDescriptionLocalized ) )
+            {
+            tempLocalization = LocalizeDescriptionL( aEntry );
+            if (tempLocalization)
+                {
+                localizations.Append(tempLocalization);
+                tempLocalization = NULL;
+                }
+            }
+        
+        iStorage->AddL( aEntry, aUpdate );
+        
+        for( TInt j =0; j < localizations.Count(); j++ )
+            {
+            localizations[j]->SetRowId( aEntry->GetId() );
+            AddLocalizationL( *( localizations[j] ) );
+            }
+		if( localizations.Count() > 0 )
+            {
+            HbTextResolverSymbian::Init( _L(""), KLocalizationFilepathZ );
+            }
+		 CleanupStack::PopAndDestroy( &localizations );
+        }
+    
+        
     for( TInt i = 0; i < iHandlerNotifier.Count(); i++ )
         {
         iHandlerNotifier[i]->EntryChanged( aEntry, changeType, parentArray );
@@ -317,6 +368,9 @@
     CleanupStack::PopAndDestroy( &parentArray );
     }
 
+#ifdef COVERAGE_MEASUREMENT
+#pragma CTC SKIP
+#endif //COVERAGE_MEASUREMENT (calls another method)
 // ---------------------------------------------------------------------------
 //
 // ---------------------------------------------------------------------------
@@ -325,6 +379,9 @@
     {
     iStorage->LoadDataBaseFromRomL();
     }
+#ifdef COVERAGE_MEASUREMENT
+#pragma CTC ENDSKIP
+#endif //COVERAGE_MEASUREMENT
 
 // ---------------------------------------------------------
 //
@@ -350,3 +407,147 @@
         iHandlerNotifier.Remove( i );
         }
     }
+
+// ---------------------------------------------------------
+//
+// ---------------------------------------------------------
+//
+CCaLocalizationEntry* CCaStorageProxy::LocalizeTextL( CCaInnerEntry* aEntry )
+    {
+	CCaLocalizationEntry* result = NULL;
+	TInt textLength = aEntry->GetText().Length();
+	if (textLength > 0)
+		{
+		TChar delimiter = '/'; // cannot add it as global
+		RBuf title;
+		CleanupClosePushL( title );
+		title.CreateL( aEntry->GetText() );
+		TInt pos = title.LocateReverse( delimiter );
+		if ( pos > 0 && pos + 1 < textLength )   // 1 is for delimiters
+			{
+			TPtrC16 logString = title.Mid( pos + 1 ); 
+			TInt qmFileNameLength = textLength - charsToFilename - 1 - logString.Length();
+			TPtrC16 qmFile = title.Mid( charsToFilename, qmFileNameLength );
+			if ( InitializeTranslatorL( qmFile ) )
+				{
+			    result = CCaLocalizationEntry::NewLC();			
+				HBufC* translatedString = HbTextResolverSymbian::LoadLC( logString );
+				if ( translatedString->Compare( logString ) )
+					{
+					result->SetStringIdL( logString );
+					aEntry->SetTextL( *translatedString );
+					if( translatedString )
+						{
+					    CleanupStack::PopAndDestroy( translatedString );
+						}
+					result->SetTableNameL( KLocalizationCaEntry );
+					result->SetAttributeNameL( KLocalizationEnText );
+					result->SetQmFilenameL( qmFile );
+					result->SetRowId( aEntry->GetId() ? 0 : aEntry->GetId() ); // must be added when present
+					}
+				else 
+					{
+				    if (translatedString)
+						{
+						CleanupStack::PopAndDestroy(translatedString);
+						}
+					}
+				CleanupStack::Pop( result );
+				}
+			}
+		CleanupStack::PopAndDestroy( &title );
+		}
+	return result;
+	}
+
+// ---------------------------------------------------------
+//
+// ---------------------------------------------------------
+//
+CCaLocalizationEntry* CCaStorageProxy::LocalizeDescriptionL( CCaInnerEntry* aEntry )
+    {
+	CCaLocalizationEntry* result = NULL;
+	TInt dscLength = aEntry->GetDescription().Length();
+	if ( dscLength )
+		{
+		TChar delimiter = '/'; // cannot add it as global
+		RBuf description;
+		CleanupClosePushL( description );
+		description.CreateL( aEntry->GetDescription() );
+		TInt pos = description.LocateReverse( delimiter );
+		if ( pos > 0 && pos + 1 < dscLength )   // 1 is for delimiters
+			{
+			TPtrC16 logString = description.Mid(pos + 1);
+			TInt qmFileNameLength = dscLength - charsToFilename - 1 - logString.Length();
+			TPtrC16 qmFile = description.Mid(charsToFilename, qmFileNameLength);
+			if ( InitializeTranslatorL( qmFile ) )
+				{
+			    result = CCaLocalizationEntry::NewLC();
+				HBufC* translatedString = HbTextResolverSymbian::LoadLC( logString );
+				if ( translatedString->Compare( logString ) )
+					{
+					result->SetStringIdL( logString );
+					aEntry->SetDescriptionL( *translatedString );
+					CleanupStack::PopAndDestroy( translatedString );
+					result->SetTableNameL( KLocalizationCaEntry );
+					result->SetAttributeNameL( KLocalizationEnDescription );
+					result->SetQmFilenameL( qmFile );
+					result->SetRowId( aEntry->GetId() ? 0 : aEntry->GetId() ); // must be added when present
+					}
+				else 
+					{
+				    CleanupStack::PopAndDestroy( translatedString );
+					}
+				CleanupStack::Pop( result );
+				}
+			}
+		CleanupStack::PopAndDestroy( &description );
+		}
+	return result;
+	}
+
+// ---------------------------------------------------------
+//
+// ---------------------------------------------------------
+//
+TBool CCaStorageProxy::InitializeTranslatorL( TDesC& aQmFilename )
+    {
+	TBool result = HbTextResolverSymbian::Init( aQmFilename, KLocalizationFilepathC );
+	if ( !result )
+		{
+		// this should not be called too often 
+		TChar currentDriveLetter;
+		TDriveList driveList;
+		RFs fs;
+		User::LeaveIfError( fs.Connect() );
+		User::LeaveIfError( fs.DriveList( driveList ) );
+
+		RBuf path;
+		CleanupClosePushL( path );
+		path.CreateL( KLocalizationFilepath().Length() + 1 );
+
+		for ( TInt driveNr = EDriveY; driveNr >= EDriveA; driveNr-- )
+			{
+			if ( driveList[driveNr] )
+				{
+				User::LeaveIfError(fs.DriveToChar( driveNr, currentDriveLetter ));
+				path.Append( currentDriveLetter );
+				path.Append( KLocalizationFilepath );
+				if (HbTextResolverSymbian::Init( aQmFilename, path ))
+					{
+				    result = ETrue;
+					break;
+					}
+				}
+			path.Zero();
+			}
+		CleanupStack::PopAndDestroy( &path );
+		fs.Close();
+		
+		if( !result )
+			{
+		    result = HbTextResolverSymbian::Init( aQmFilename, KLocalizationFilepathZ );
+			}
+		}
+	return result;
+	}