contentstorage/casrv/calocalizerscanner/src/calocalizerscannerproxy.cpp
changeset 94 dbb8300717f7
parent 93 82b66994846c
child 96 5d243a69bdda
equal deleted inserted replaced
93:82b66994846c 94:dbb8300717f7
    65 // Symbian 2nd phase constructor can leave.
    65 // Symbian 2nd phase constructor can leave.
    66 // ---------------------------------------------------------------------------
    66 // ---------------------------------------------------------------------------
    67 //
    67 //
    68 void CCaLocalizerScannerProxy::ConstructL()
    68 void CCaLocalizerScannerProxy::ConstructL()
    69     {
    69     {
    70     TBuf<KCaMaxAttrNameLen> filenameDsc;
    70 	iRecentQmFile.CreateL( KCaMaxAttrLenght );
    71     iStorageProxy->DbPropertyL( KCaDbPropQMfile, filenameDsc );
       
    72     iResolver = new (ELeave) HbTextResolverSymbian;
       
    73     iResolver->Init(filenameDsc, KPathLoc);
       
    74     UpdateLocalNamesL();
    71     UpdateLocalNamesL();
    75     delete iResolver;
       
    76     iResolver = NULL;
       
    77     }
    72     }
    78 
    73 
    79 // ---------------------------------------------------------------------------
    74 // ---------------------------------------------------------------------------
    80 // CCaLocalizerScannerProxy::CCaLocalizerScannerProxy
    75 // CCaLocalizerScannerProxy::CCaLocalizerScannerProxy
    81 // C++ default constructor can NOT contain any code, that
    76 // C++ default constructor can NOT contain any code, that
    93 // Destructor.
    88 // Destructor.
    94 // ---------------------------------------------------------------------------
    89 // ---------------------------------------------------------------------------
    95 //
    90 //
    96 CCaLocalizerScannerProxy::~CCaLocalizerScannerProxy()
    91 CCaLocalizerScannerProxy::~CCaLocalizerScannerProxy()
    97     {
    92     {
    98 	if (iResolver)
    93 	iRecentQmFile.Close();
    99 		{
       
   100 	    delete iResolver;
       
   101 		} 
       
   102     }
    94     }
   103 
    95 
   104 // ---------------------------------------------------------------------------
    96 // ---------------------------------------------------------------------------
   105 // CCaLocalizerScannerProxy::GetLocalizationRowsL
    97 // CCaLocalizerScannerProxy::GetLocalizationRowsL
   106 // ---------------------------------------------------------------------------
    98 // ---------------------------------------------------------------------------
   124     CleanupResetAndDestroyPushL( locals );
   116     CleanupResetAndDestroyPushL( locals );
   125     RPointerArray<CCaInnerEntry> entries;
   117     RPointerArray<CCaInnerEntry> entries;
   126     CleanupResetAndDestroyPushL( entries );
   118     CleanupResetAndDestroyPushL( entries );
   127     RArray<TInt> ids;
   119     RArray<TInt> ids;
   128     CleanupClosePushL( ids );
   120     CleanupClosePushL( ids );
   129     
   121     //gets all localizations
   130     GetLocalizationRowsL( locals );
   122     GetLocalizationRowsL( locals );
   131      
       
   132     TInt locCount = locals.Count();
   123     TInt locCount = locals.Count();
   133     for( TInt idx = 0; idx < locCount; idx++ )
   124     for( TInt i = 0; i < locCount; i++ )
   134         {
   125         {
   135         ids.Append( locals[idx]->GetRowId() );
   126         ids.Append( locals[i]->GetRowId() );
   136         }    
   127         }    
   137     CCaInnerQuery* query = CCaInnerQuery::NewLC();
   128     CCaInnerQuery* query = CCaInnerQuery::NewLC();
   138     query->SetIdsL( ids );
   129     query->SetIdsL( ids );
   139     iStorageProxy->GetEntriesL( query, entries ); 
   130     iStorageProxy->GetEntriesL( query, entries ); 
   140     CleanupStack::PopAndDestroy( query );
   131     CleanupStack::PopAndDestroy( query );
   141     
   132     
   142     HBufC16* localizedName;
   133     HBufC16* localizedName;
   143     for( TInt i = 0; i < locCount; i++ )
   134     for( TInt i = 0; i < locCount; i++ )
   144         {
   135         {
   145         localizedName = iResolver->LoadLC( locals[i]->GetStringId() );
   136         localizedName = GetLocalizedNameLC( locals[i] );
       
   137         
   146         if( localizedName->Compare(
   138         if( localizedName->Compare(
   147             GetEntryText( entries, locals[i]->GetRowId() ) ) )
   139             GetEntryText( entries, locals[i]->GetRowId() ) ) )
   148             // translation different than text
   140             // translation different than text
   149             {
   141             {
   150             locals[i]->SetLocalizedStringL( *localizedName );
   142             locals[i]->SetLocalizedStringL( *localizedName );
   151             iStorageProxy->LocalizeEntryL( *( locals[i] ) );
       
   152             } 
       
   153         else if( !localizedName->Compare(KNullDesC) ) 
       
   154             // no translation, string id as text
       
   155             {
       
   156             locals[i]->SetLocalizedStringL( locals[i]->GetStringId() );
       
   157             iStorageProxy->LocalizeEntryL( *( locals[i] ) );
   143             iStorageProxy->LocalizeEntryL( *( locals[i] ) );
   158             }
   144             }
   159         CleanupStack::PopAndDestroy( localizedName );
   145         CleanupStack::PopAndDestroy( localizedName );
   160         }
   146         }
   161    
   147    
   164     CleanupStack::PopAndDestroy( &locals );
   150     CleanupStack::PopAndDestroy( &locals );
   165     }
   151     }
   166 
   152 
   167 
   153 
   168 // ---------------------------------------------------------------------------
   154 // ---------------------------------------------------------------------------
   169 // CCaLocalizerScannerProxy::LocalGetEntryById
   155 // 
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 HBufC* CCaLocalizerScannerProxy::GetLocalizedNameLC(
       
   159 		const CCaLocalizationEntry* aLocEntry)
       
   160     {
       
   161 	if( iRecentQmFile.Compare( aLocEntry->GetQmFilename() ) )
       
   162 		{
       
   163 	    HbTextResolverSymbian::Init( aLocEntry->GetQmFilename(), KPathLoc );
       
   164         // keeping last qm filename to avoid another initialization
       
   165 	    iRecentQmFile.Close();
       
   166 	    iRecentQmFile.Create( aLocEntry->GetQmFilename().Length() );
       
   167 	    iRecentQmFile.Copy( aLocEntry->GetQmFilename() );
       
   168 		}
       
   169 	return HbTextResolverSymbian::LoadLC( aLocEntry->GetStringId() );
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 //  
   170 // ---------------------------------------------------------------------------
   174 // ---------------------------------------------------------------------------
   171 //
   175 //
   172 const TDesC& CCaLocalizerScannerProxy::GetEntryText(
   176 const TDesC& CCaLocalizerScannerProxy::GetEntryText(
   173         RPointerArray<CCaInnerEntry> aEntries, TInt aId )
   177         const RPointerArray<CCaInnerEntry>& aEntries, TInt aId )
   174     {
   178     {
   175     TInt entriesCount = aEntries.Count();
   179     TInt entriesCount = aEntries.Count();
   176     for( TInt i=0; i < entriesCount; i++ )
   180     for( TInt i=0; i < entriesCount; i++ )
   177         {
   181         {
   178         if( aEntries[i]->GetId() == aId )
   182         if( aEntries[i]->GetId() == aId )