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"
|
85
|
32 |
|
96
|
33 |
|
85
|
34 |
|
|
35 |
// ---------------------------------------------------------------------------
|
|
36 |
// CCaLocalizerScannerProxy::NewL
|
|
37 |
// Two-phased constructor.
|
|
38 |
// ---------------------------------------------------------------------------
|
|
39 |
//
|
|
40 |
CCaLocalizerScannerProxy* CCaLocalizerScannerProxy::NewL(
|
|
41 |
CCaStorageProxy* aStorageProxy )
|
|
42 |
{
|
|
43 |
CCaLocalizerScannerProxy* self = CCaLocalizerScannerProxy::NewLC(
|
|
44 |
aStorageProxy );
|
|
45 |
CleanupStack::Pop( self );
|
|
46 |
return self;
|
|
47 |
}
|
|
48 |
|
|
49 |
// ---------------------------------------------------------------------------
|
|
50 |
// CCaLocalizerScannerProxy::NewLC
|
|
51 |
// Two-phased constructor.
|
|
52 |
// ---------------------------------------------------------------------------
|
|
53 |
//
|
|
54 |
CCaLocalizerScannerProxy* CCaLocalizerScannerProxy::NewLC(
|
|
55 |
CCaStorageProxy* aStorageProxy )
|
|
56 |
{
|
|
57 |
CCaLocalizerScannerProxy* self = new( ELeave ) CCaLocalizerScannerProxy(
|
|
58 |
aStorageProxy );
|
|
59 |
CleanupStack::PushL( self );
|
|
60 |
self->ConstructL();
|
|
61 |
return self;
|
|
62 |
}
|
|
63 |
|
|
64 |
// ---------------------------------------------------------------------------
|
|
65 |
// CCaLocalizerScannerProxy::ConstructL
|
|
66 |
// Symbian 2nd phase constructor can leave.
|
|
67 |
// ---------------------------------------------------------------------------
|
|
68 |
//
|
|
69 |
void CCaLocalizerScannerProxy::ConstructL()
|
|
70 |
{
|
94
|
71 |
iRecentQmFile.CreateL( KCaMaxAttrLenght );
|
93
|
72 |
UpdateLocalNamesL();
|
85
|
73 |
}
|
|
74 |
|
|
75 |
// ---------------------------------------------------------------------------
|
|
76 |
// CCaLocalizerScannerProxy::CCaLocalizerScannerProxy
|
|
77 |
// C++ default constructor can NOT contain any code, that
|
|
78 |
// might leave.
|
|
79 |
// ---------------------------------------------------------------------------
|
|
80 |
//
|
|
81 |
CCaLocalizerScannerProxy::CCaLocalizerScannerProxy(
|
|
82 |
CCaStorageProxy* aStorageProxy ) :
|
|
83 |
iStorageProxy( aStorageProxy )
|
|
84 |
{
|
|
85 |
}
|
|
86 |
|
|
87 |
// ---------------------------------------------------------------------------
|
|
88 |
// CCaLocalizerScannerProxy::~CCaLocalizerScannerProxy
|
|
89 |
// Destructor.
|
|
90 |
// ---------------------------------------------------------------------------
|
|
91 |
//
|
|
92 |
CCaLocalizerScannerProxy::~CCaLocalizerScannerProxy()
|
|
93 |
{
|
94
|
94 |
iRecentQmFile.Close();
|
85
|
95 |
}
|
|
96 |
|
|
97 |
// ---------------------------------------------------------------------------
|
|
98 |
// CCaLocalizerScannerProxy::GetLocalizationRowsL
|
|
99 |
// ---------------------------------------------------------------------------
|
|
100 |
//
|
|
101 |
void CCaLocalizerScannerProxy::GetLocalizationRowsL( RPointerArray<
|
|
102 |
CCaLocalizationEntry>& aLocals )
|
|
103 |
{
|
|
104 |
if( iStorageProxy )
|
|
105 |
{
|
|
106 |
iStorageProxy->GetLocalizationsL( aLocals );
|
|
107 |
}
|
|
108 |
}
|
|
109 |
|
|
110 |
// ---------------------------------------------------------------------------
|
|
111 |
// CCaLocalizerScannerProxy::UpdateLocalNamesL
|
|
112 |
// ---------------------------------------------------------------------------
|
|
113 |
//
|
|
114 |
void CCaLocalizerScannerProxy::UpdateLocalNamesL()
|
|
115 |
{
|
|
116 |
RPointerArray<CCaLocalizationEntry> locals;
|
|
117 |
CleanupResetAndDestroyPushL( locals );
|
93
|
118 |
RPointerArray<CCaInnerEntry> entries;
|
|
119 |
CleanupResetAndDestroyPushL( entries );
|
|
120 |
RArray<TInt> ids;
|
|
121 |
CleanupClosePushL( ids );
|
94
|
122 |
//gets all localizations
|
85
|
123 |
GetLocalizationRowsL( locals );
|
93
|
124 |
TInt locCount = locals.Count();
|
94
|
125 |
for( TInt i = 0; i < locCount; i++ )
|
93
|
126 |
{
|
94
|
127 |
ids.Append( locals[i]->GetRowId() );
|
93
|
128 |
}
|
|
129 |
CCaInnerQuery* query = CCaInnerQuery::NewLC();
|
|
130 |
query->SetIdsL( ids );
|
|
131 |
iStorageProxy->GetEntriesL( query, entries );
|
|
132 |
CleanupStack::PopAndDestroy( query );
|
|
133 |
|
|
134 |
HBufC16* localizedName;
|
|
135 |
for( TInt i = 0; i < locCount; i++ )
|
85
|
136 |
{
|
94
|
137 |
localizedName = GetLocalizedNameLC( locals[i] );
|
|
138 |
|
96
|
139 |
if( locals[i]->GetAttributeName().Compare( KColumnEnText) == 0
|
107
|
140 |
&& localizedName->Compare(
|
|
141 |
GetEntryText( entries, locals[i]->GetRowId() ) ) != 0
|
96
|
142 |
||
|
|
143 |
locals[i]->GetAttributeName().Compare( KColumnEnDescription) == 0
|
107
|
144 |
&& localizedName->Compare(
|
|
145 |
GetEntryDescription( entries, locals[i]->GetRowId() ) ) != 0
|
|
146 |
||
|
|
147 |
( locals[i]->GetAttributeName().Compare( KShortName ) == 0
|
|
148 |
|| locals[i]->GetAttributeName().Compare( KTitleName ) == 0 )
|
|
149 |
&& localizedName->Compare(
|
|
150 |
GetAttributeName( entries,
|
|
151 |
locals[i]->GetRowId(),
|
|
152 |
locals[i]->GetAttributeName() ) ) != 0 )
|
96
|
153 |
// translations different than text
|
93
|
154 |
{
|
|
155 |
locals[i]->SetLocalizedStringL( *localizedName );
|
|
156 |
iStorageProxy->LocalizeEntryL( *( locals[i] ) );
|
|
157 |
}
|
|
158 |
CleanupStack::PopAndDestroy( localizedName );
|
85
|
159 |
}
|
98
|
160 |
HbTextResolverSymbian::Init( _L(""), KLocalizationFilepathZ );
|
93
|
161 |
|
|
162 |
CleanupStack::PopAndDestroy( &ids );
|
|
163 |
CleanupStack::PopAndDestroy( &entries );
|
85
|
164 |
CleanupStack::PopAndDestroy( &locals );
|
|
165 |
}
|
|
166 |
|
93
|
167 |
|
85
|
168 |
// ---------------------------------------------------------------------------
|
94
|
169 |
//
|
|
170 |
// ---------------------------------------------------------------------------
|
|
171 |
//
|
|
172 |
HBufC* CCaLocalizerScannerProxy::GetLocalizedNameLC(
|
|
173 |
const CCaLocalizationEntry* aLocEntry)
|
|
174 |
{
|
|
175 |
if( iRecentQmFile.Compare( aLocEntry->GetQmFilename() ) )
|
|
176 |
{
|
96
|
177 |
|
|
178 |
if( !HbTextResolverSymbian::Init( aLocEntry->GetQmFilename(), KLocalizationFilepathC ) )
|
|
179 |
{
|
|
180 |
if( !HbTextResolverSymbian::Init( aLocEntry->GetQmFilename(), KLocalizationFilepathZ ) )
|
|
181 |
{
|
|
182 |
// this should not be called too often
|
|
183 |
TChar currentDriveLetter;
|
|
184 |
TDriveList driveList;
|
|
185 |
RFs fs;
|
|
186 |
User::LeaveIfError( fs.Connect() );
|
|
187 |
User::LeaveIfError( fs.DriveList( driveList ) );
|
|
188 |
|
|
189 |
RBuf path;
|
|
190 |
path.Create( KLocalizationFilepath().Length() + 1 );
|
|
191 |
CleanupClosePushL( path );
|
|
192 |
|
|
193 |
for ( TInt driveNr=EDriveY; driveNr >= EDriveA; driveNr-- )
|
|
194 |
{
|
|
195 |
if ( driveList[driveNr] )
|
|
196 |
{
|
|
197 |
User::LeaveIfError( fs.DriveToChar( driveNr,
|
|
198 |
currentDriveLetter ) );
|
|
199 |
path.Append( currentDriveLetter );
|
|
200 |
path.Append( KLocalizationFilepath );
|
|
201 |
if( HbTextResolverSymbian::Init( aLocEntry->GetQmFilename(), path ) )
|
|
202 |
{
|
|
203 |
break;
|
|
204 |
}
|
|
205 |
}
|
|
206 |
path.Zero();
|
|
207 |
}
|
|
208 |
CleanupStack::PopAndDestroy( &path );
|
|
209 |
fs.Close();
|
|
210 |
}
|
|
211 |
}
|
|
212 |
|
94
|
213 |
// keeping last qm filename to avoid another initialization
|
|
214 |
iRecentQmFile.Close();
|
|
215 |
iRecentQmFile.Create( aLocEntry->GetQmFilename().Length() );
|
|
216 |
iRecentQmFile.Copy( aLocEntry->GetQmFilename() );
|
|
217 |
}
|
|
218 |
return HbTextResolverSymbian::LoadLC( aLocEntry->GetStringId() );
|
|
219 |
}
|
|
220 |
|
|
221 |
// ---------------------------------------------------------------------------
|
|
222 |
//
|
85
|
223 |
// ---------------------------------------------------------------------------
|
|
224 |
//
|
93
|
225 |
const TDesC& CCaLocalizerScannerProxy::GetEntryText(
|
94
|
226 |
const RPointerArray<CCaInnerEntry>& aEntries, TInt aId )
|
85
|
227 |
{
|
93
|
228 |
TInt entriesCount = aEntries.Count();
|
|
229 |
for( TInt i=0; i < entriesCount; i++ )
|
|
230 |
{
|
|
231 |
if( aEntries[i]->GetId() == aId )
|
|
232 |
{
|
|
233 |
return aEntries[i]->GetText();
|
|
234 |
}
|
|
235 |
}
|
|
236 |
return KNullDesC();
|
85
|
237 |
}
|
96
|
238 |
|
|
239 |
// ---------------------------------------------------------------------------
|
|
240 |
//
|
|
241 |
// ---------------------------------------------------------------------------
|
|
242 |
//
|
|
243 |
const TDesC& CCaLocalizerScannerProxy::GetEntryDescription(
|
|
244 |
const RPointerArray<CCaInnerEntry>& aEntries, TInt aId )
|
|
245 |
{
|
|
246 |
TInt entriesCount = aEntries.Count();
|
|
247 |
for( TInt i=0; i < entriesCount; i++ )
|
|
248 |
{
|
|
249 |
if( aEntries[i]->GetId() == aId )
|
|
250 |
{
|
|
251 |
return aEntries[i]->GetDescription();
|
|
252 |
}
|
|
253 |
}
|
|
254 |
return KNullDesC();
|
|
255 |
}
|
107
|
256 |
|
|
257 |
// ---------------------------------------------------------------------------
|
|
258 |
//
|
|
259 |
// ---------------------------------------------------------------------------
|
|
260 |
//
|
|
261 |
const TPtrC CCaLocalizerScannerProxy::GetAttributeName(
|
|
262 |
const RPointerArray<CCaInnerEntry>& aEntries,
|
|
263 |
TInt aId,
|
|
264 |
const TDesC& aAttrName )
|
|
265 |
{
|
|
266 |
TBool notFound( ETrue );
|
|
267 |
TPtrC attrValue;
|
|
268 |
TInt entriesCount = aEntries.Count();
|
|
269 |
for( TInt i=0; i < entriesCount && notFound; i++ )
|
|
270 |
{
|
|
271 |
if( aEntries[i]->GetId() == aId &&
|
|
272 |
aEntries[i]->GetAttributes().Find(aAttrName, attrValue) )
|
|
273 |
{
|
|
274 |
notFound = EFalse;
|
|
275 |
}
|
|
276 |
}
|
|
277 |
return attrValue;
|
|
278 |
}
|