85
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: CCaLocalizerScannerProxy.cpp
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <badesca.h>
|
|
19 |
#include <f32file.h>
|
|
20 |
#include <qtranslator.h>
|
|
21 |
#include <calocalizationentry.h>
|
98
|
22 |
#include <hbtextresolversymbian.h>
|
85
|
23 |
|
|
24 |
//#include "cainternaltypes.h"
|
|
25 |
#include "caarraycleanup.inl"
|
|
26 |
#include "calocalizerscannerproxy.h"
|
|
27 |
#include "castorageproxy.h"
|
|
28 |
#include "cadef.h"
|
93
|
29 |
#include "cainnerquery.h"
|
|
30 |
#include "cainnerentry.h"
|
96
|
31 |
#include "casqlcommands.h"
|
119
|
32 |
#include "cautils.h"
|
85
|
33 |
|
96
|
34 |
|
85
|
35 |
|
|
36 |
// ---------------------------------------------------------------------------
|
|
37 |
// CCaLocalizerScannerProxy::NewL
|
|
38 |
// Two-phased constructor.
|
|
39 |
// ---------------------------------------------------------------------------
|
|
40 |
//
|
|
41 |
CCaLocalizerScannerProxy* CCaLocalizerScannerProxy::NewL(
|
|
42 |
CCaStorageProxy* aStorageProxy )
|
|
43 |
{
|
|
44 |
CCaLocalizerScannerProxy* self = CCaLocalizerScannerProxy::NewLC(
|
|
45 |
aStorageProxy );
|
|
46 |
CleanupStack::Pop( self );
|
|
47 |
return self;
|
|
48 |
}
|
|
49 |
|
|
50 |
// ---------------------------------------------------------------------------
|
|
51 |
// CCaLocalizerScannerProxy::NewLC
|
|
52 |
// Two-phased constructor.
|
|
53 |
// ---------------------------------------------------------------------------
|
|
54 |
//
|
|
55 |
CCaLocalizerScannerProxy* CCaLocalizerScannerProxy::NewLC(
|
|
56 |
CCaStorageProxy* aStorageProxy )
|
|
57 |
{
|
|
58 |
CCaLocalizerScannerProxy* self = new( ELeave ) CCaLocalizerScannerProxy(
|
|
59 |
aStorageProxy );
|
|
60 |
CleanupStack::PushL( self );
|
|
61 |
self->ConstructL();
|
|
62 |
return self;
|
|
63 |
}
|
|
64 |
|
|
65 |
// ---------------------------------------------------------------------------
|
|
66 |
// CCaLocalizerScannerProxy::ConstructL
|
|
67 |
// Symbian 2nd phase constructor can leave.
|
|
68 |
// ---------------------------------------------------------------------------
|
|
69 |
//
|
|
70 |
void CCaLocalizerScannerProxy::ConstructL()
|
|
71 |
{
|
94
|
72 |
iRecentQmFile.CreateL( KCaMaxAttrLenght );
|
93
|
73 |
UpdateLocalNamesL();
|
85
|
74 |
}
|
|
75 |
|
|
76 |
// ---------------------------------------------------------------------------
|
|
77 |
// CCaLocalizerScannerProxy::CCaLocalizerScannerProxy
|
|
78 |
// C++ default constructor can NOT contain any code, that
|
|
79 |
// might leave.
|
|
80 |
// ---------------------------------------------------------------------------
|
|
81 |
//
|
|
82 |
CCaLocalizerScannerProxy::CCaLocalizerScannerProxy(
|
|
83 |
CCaStorageProxy* aStorageProxy ) :
|
|
84 |
iStorageProxy( aStorageProxy )
|
|
85 |
{
|
|
86 |
}
|
|
87 |
|
|
88 |
// ---------------------------------------------------------------------------
|
|
89 |
// CCaLocalizerScannerProxy::~CCaLocalizerScannerProxy
|
|
90 |
// Destructor.
|
|
91 |
// ---------------------------------------------------------------------------
|
|
92 |
//
|
|
93 |
CCaLocalizerScannerProxy::~CCaLocalizerScannerProxy()
|
|
94 |
{
|
94
|
95 |
iRecentQmFile.Close();
|
85
|
96 |
}
|
|
97 |
|
|
98 |
// ---------------------------------------------------------------------------
|
|
99 |
// CCaLocalizerScannerProxy::GetLocalizationRowsL
|
|
100 |
// ---------------------------------------------------------------------------
|
|
101 |
//
|
|
102 |
void CCaLocalizerScannerProxy::GetLocalizationRowsL( RPointerArray<
|
|
103 |
CCaLocalizationEntry>& aLocals )
|
|
104 |
{
|
|
105 |
if( iStorageProxy )
|
|
106 |
{
|
|
107 |
iStorageProxy->GetLocalizationsL( aLocals );
|
|
108 |
}
|
|
109 |
}
|
|
110 |
|
|
111 |
// ---------------------------------------------------------------------------
|
|
112 |
// CCaLocalizerScannerProxy::UpdateLocalNamesL
|
|
113 |
// ---------------------------------------------------------------------------
|
|
114 |
//
|
|
115 |
void CCaLocalizerScannerProxy::UpdateLocalNamesL()
|
|
116 |
{
|
|
117 |
RPointerArray<CCaLocalizationEntry> locals;
|
|
118 |
CleanupResetAndDestroyPushL( locals );
|
93
|
119 |
RPointerArray<CCaInnerEntry> entries;
|
|
120 |
CleanupResetAndDestroyPushL( entries );
|
|
121 |
RArray<TInt> ids;
|
|
122 |
CleanupClosePushL( ids );
|
94
|
123 |
//gets all localizations
|
85
|
124 |
GetLocalizationRowsL( locals );
|
93
|
125 |
TInt locCount = locals.Count();
|
94
|
126 |
for( TInt i = 0; i < locCount; i++ )
|
93
|
127 |
{
|
94
|
128 |
ids.Append( locals[i]->GetRowId() );
|
93
|
129 |
}
|
|
130 |
CCaInnerQuery* query = CCaInnerQuery::NewLC();
|
|
131 |
query->SetIdsL( ids );
|
|
132 |
iStorageProxy->GetEntriesL( query, entries );
|
|
133 |
CleanupStack::PopAndDestroy( query );
|
|
134 |
|
|
135 |
HBufC16* localizedName;
|
|
136 |
for( TInt i = 0; i < locCount; i++ )
|
85
|
137 |
{
|
94
|
138 |
localizedName = GetLocalizedNameLC( locals[i] );
|
|
139 |
|
96
|
140 |
if( locals[i]->GetAttributeName().Compare( KColumnEnText) == 0
|
107
|
141 |
&& localizedName->Compare(
|
|
142 |
GetEntryText( entries, locals[i]->GetRowId() ) ) != 0
|
96
|
143 |
||
|
|
144 |
locals[i]->GetAttributeName().Compare( KColumnEnDescription) == 0
|
107
|
145 |
&& localizedName->Compare(
|
|
146 |
GetEntryDescription( entries, locals[i]->GetRowId() ) ) != 0
|
|
147 |
||
|
|
148 |
( locals[i]->GetAttributeName().Compare( KShortName ) == 0
|
|
149 |
|| locals[i]->GetAttributeName().Compare( KTitleName ) == 0 )
|
|
150 |
&& localizedName->Compare(
|
|
151 |
GetAttributeName( entries,
|
|
152 |
locals[i]->GetRowId(),
|
|
153 |
locals[i]->GetAttributeName() ) ) != 0 )
|
96
|
154 |
// translations different than text
|
93
|
155 |
{
|
|
156 |
locals[i]->SetLocalizedStringL( *localizedName );
|
|
157 |
iStorageProxy->LocalizeEntryL( *( locals[i] ) );
|
|
158 |
}
|
|
159 |
CleanupStack::PopAndDestroy( localizedName );
|
85
|
160 |
}
|
98
|
161 |
HbTextResolverSymbian::Init( _L(""), KLocalizationFilepathZ );
|
93
|
162 |
|
|
163 |
CleanupStack::PopAndDestroy( &ids );
|
|
164 |
CleanupStack::PopAndDestroy( &entries );
|
85
|
165 |
CleanupStack::PopAndDestroy( &locals );
|
|
166 |
}
|
|
167 |
|
93
|
168 |
|
85
|
169 |
// ---------------------------------------------------------------------------
|
94
|
170 |
//
|
|
171 |
// ---------------------------------------------------------------------------
|
|
172 |
//
|
|
173 |
HBufC* CCaLocalizerScannerProxy::GetLocalizedNameLC(
|
|
174 |
const CCaLocalizationEntry* aLocEntry)
|
|
175 |
{
|
|
176 |
if( iRecentQmFile.Compare( aLocEntry->GetQmFilename() ) )
|
|
177 |
{
|
119
|
178 |
MenuUtils::InitTextResolverSymbianL(aLocEntry->GetQmFilename());
|
94
|
179 |
// keeping last qm filename to avoid another initialization
|
|
180 |
iRecentQmFile.Close();
|
119
|
181 |
iRecentQmFile.CreateL( aLocEntry->GetQmFilename().Length() );
|
94
|
182 |
iRecentQmFile.Copy( aLocEntry->GetQmFilename() );
|
|
183 |
}
|
|
184 |
return HbTextResolverSymbian::LoadLC( aLocEntry->GetStringId() );
|
|
185 |
}
|
|
186 |
|
|
187 |
// ---------------------------------------------------------------------------
|
|
188 |
//
|
85
|
189 |
// ---------------------------------------------------------------------------
|
|
190 |
//
|
93
|
191 |
const TDesC& CCaLocalizerScannerProxy::GetEntryText(
|
94
|
192 |
const RPointerArray<CCaInnerEntry>& aEntries, TInt aId )
|
85
|
193 |
{
|
93
|
194 |
TInt entriesCount = aEntries.Count();
|
|
195 |
for( TInt i=0; i < entriesCount; i++ )
|
|
196 |
{
|
|
197 |
if( aEntries[i]->GetId() == aId )
|
|
198 |
{
|
|
199 |
return aEntries[i]->GetText();
|
|
200 |
}
|
|
201 |
}
|
|
202 |
return KNullDesC();
|
85
|
203 |
}
|
96
|
204 |
|
|
205 |
// ---------------------------------------------------------------------------
|
|
206 |
//
|
|
207 |
// ---------------------------------------------------------------------------
|
|
208 |
//
|
|
209 |
const TDesC& CCaLocalizerScannerProxy::GetEntryDescription(
|
|
210 |
const RPointerArray<CCaInnerEntry>& aEntries, TInt aId )
|
|
211 |
{
|
|
212 |
TInt entriesCount = aEntries.Count();
|
|
213 |
for( TInt i=0; i < entriesCount; i++ )
|
|
214 |
{
|
|
215 |
if( aEntries[i]->GetId() == aId )
|
|
216 |
{
|
|
217 |
return aEntries[i]->GetDescription();
|
|
218 |
}
|
|
219 |
}
|
|
220 |
return KNullDesC();
|
|
221 |
}
|
107
|
222 |
|
|
223 |
// ---------------------------------------------------------------------------
|
|
224 |
//
|
|
225 |
// ---------------------------------------------------------------------------
|
|
226 |
//
|
|
227 |
const TPtrC CCaLocalizerScannerProxy::GetAttributeName(
|
|
228 |
const RPointerArray<CCaInnerEntry>& aEntries,
|
|
229 |
TInt aId,
|
|
230 |
const TDesC& aAttrName )
|
|
231 |
{
|
|
232 |
TBool notFound( ETrue );
|
|
233 |
TPtrC attrValue;
|
|
234 |
TInt entriesCount = aEntries.Count();
|
|
235 |
for( TInt i=0; i < entriesCount && notFound; i++ )
|
|
236 |
{
|
|
237 |
if( aEntries[i]->GetId() == aId &&
|
|
238 |
aEntries[i]->GetAttributes().Find(aAttrName, attrValue) )
|
|
239 |
{
|
|
240 |
notFound = EFalse;
|
|
241 |
}
|
|
242 |
}
|
|
243 |
return attrValue;
|
|
244 |
}
|