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>
|
|
22 |
#include <QLocale>
|
|
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"
|
85
|
31 |
|
93
|
32 |
_LIT(KPathLoc,"z:/resource/qt/translations");
|
85
|
33 |
|
|
34 |
// ---------------------------------------------------------------------------
|
|
35 |
// CCaLocalizerScannerProxy::NewL
|
|
36 |
// Two-phased constructor.
|
|
37 |
// ---------------------------------------------------------------------------
|
|
38 |
//
|
|
39 |
CCaLocalizerScannerProxy* CCaLocalizerScannerProxy::NewL(
|
|
40 |
CCaStorageProxy* aStorageProxy )
|
|
41 |
{
|
|
42 |
CCaLocalizerScannerProxy* self = CCaLocalizerScannerProxy::NewLC(
|
|
43 |
aStorageProxy );
|
|
44 |
CleanupStack::Pop( self );
|
|
45 |
return self;
|
|
46 |
}
|
|
47 |
|
|
48 |
// ---------------------------------------------------------------------------
|
|
49 |
// CCaLocalizerScannerProxy::NewLC
|
|
50 |
// Two-phased constructor.
|
|
51 |
// ---------------------------------------------------------------------------
|
|
52 |
//
|
|
53 |
CCaLocalizerScannerProxy* CCaLocalizerScannerProxy::NewLC(
|
|
54 |
CCaStorageProxy* aStorageProxy )
|
|
55 |
{
|
|
56 |
CCaLocalizerScannerProxy* self = new( ELeave ) CCaLocalizerScannerProxy(
|
|
57 |
aStorageProxy );
|
|
58 |
CleanupStack::PushL( self );
|
|
59 |
self->ConstructL();
|
|
60 |
return self;
|
|
61 |
}
|
|
62 |
|
|
63 |
// ---------------------------------------------------------------------------
|
|
64 |
// CCaLocalizerScannerProxy::ConstructL
|
|
65 |
// Symbian 2nd phase constructor can leave.
|
|
66 |
// ---------------------------------------------------------------------------
|
|
67 |
//
|
|
68 |
void CCaLocalizerScannerProxy::ConstructL()
|
|
69 |
{
|
93
|
70 |
TBuf<KCaMaxAttrNameLen> filenameDsc;
|
|
71 |
iStorageProxy->DbPropertyL( KCaDbPropQMfile, filenameDsc );
|
|
72 |
iResolver = new (ELeave) HbTextResolverSymbian;
|
|
73 |
iResolver->Init(filenameDsc, KPathLoc);
|
|
74 |
UpdateLocalNamesL();
|
|
75 |
delete iResolver;
|
|
76 |
iResolver = NULL;
|
85
|
77 |
}
|
|
78 |
|
|
79 |
// ---------------------------------------------------------------------------
|
|
80 |
// CCaLocalizerScannerProxy::CCaLocalizerScannerProxy
|
|
81 |
// C++ default constructor can NOT contain any code, that
|
|
82 |
// might leave.
|
|
83 |
// ---------------------------------------------------------------------------
|
|
84 |
//
|
|
85 |
CCaLocalizerScannerProxy::CCaLocalizerScannerProxy(
|
|
86 |
CCaStorageProxy* aStorageProxy ) :
|
|
87 |
iStorageProxy( aStorageProxy )
|
|
88 |
{
|
|
89 |
}
|
|
90 |
|
|
91 |
// ---------------------------------------------------------------------------
|
|
92 |
// CCaLocalizerScannerProxy::~CCaLocalizerScannerProxy
|
|
93 |
// Destructor.
|
|
94 |
// ---------------------------------------------------------------------------
|
|
95 |
//
|
|
96 |
CCaLocalizerScannerProxy::~CCaLocalizerScannerProxy()
|
|
97 |
{
|
93
|
98 |
if (iResolver)
|
|
99 |
{
|
|
100 |
delete iResolver;
|
|
101 |
}
|
85
|
102 |
}
|
|
103 |
|
|
104 |
// ---------------------------------------------------------------------------
|
|
105 |
// CCaLocalizerScannerProxy::GetLocalizationRowsL
|
|
106 |
// ---------------------------------------------------------------------------
|
|
107 |
//
|
|
108 |
void CCaLocalizerScannerProxy::GetLocalizationRowsL( RPointerArray<
|
|
109 |
CCaLocalizationEntry>& aLocals )
|
|
110 |
{
|
|
111 |
if( iStorageProxy )
|
|
112 |
{
|
|
113 |
iStorageProxy->GetLocalizationsL( aLocals );
|
|
114 |
}
|
|
115 |
}
|
|
116 |
|
|
117 |
// ---------------------------------------------------------------------------
|
|
118 |
// CCaLocalizerScannerProxy::UpdateLocalNamesL
|
|
119 |
// ---------------------------------------------------------------------------
|
|
120 |
//
|
|
121 |
void CCaLocalizerScannerProxy::UpdateLocalNamesL()
|
|
122 |
{
|
|
123 |
RPointerArray<CCaLocalizationEntry> locals;
|
|
124 |
CleanupResetAndDestroyPushL( locals );
|
93
|
125 |
RPointerArray<CCaInnerEntry> entries;
|
|
126 |
CleanupResetAndDestroyPushL( entries );
|
|
127 |
RArray<TInt> ids;
|
|
128 |
CleanupClosePushL( ids );
|
|
129 |
|
85
|
130 |
GetLocalizationRowsL( locals );
|
93
|
131 |
|
|
132 |
TInt locCount = locals.Count();
|
|
133 |
for( TInt idx = 0; idx < locCount; idx++ )
|
|
134 |
{
|
|
135 |
ids.Append( locals[idx]->GetRowId() );
|
|
136 |
}
|
|
137 |
CCaInnerQuery* query = CCaInnerQuery::NewLC();
|
|
138 |
query->SetIdsL( ids );
|
|
139 |
iStorageProxy->GetEntriesL( query, entries );
|
|
140 |
CleanupStack::PopAndDestroy( query );
|
|
141 |
|
|
142 |
HBufC16* localizedName;
|
|
143 |
for( TInt i = 0; i < locCount; i++ )
|
85
|
144 |
{
|
93
|
145 |
localizedName = iResolver->LoadLC( locals[i]->GetStringId() );
|
|
146 |
if( localizedName->Compare(
|
|
147 |
GetEntryText( entries, locals[i]->GetRowId() ) ) )
|
|
148 |
// translation different than text
|
|
149 |
{
|
|
150 |
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] ) );
|
|
158 |
}
|
|
159 |
CleanupStack::PopAndDestroy( localizedName );
|
85
|
160 |
}
|
93
|
161 |
|
|
162 |
CleanupStack::PopAndDestroy( &ids );
|
|
163 |
CleanupStack::PopAndDestroy( &entries );
|
85
|
164 |
CleanupStack::PopAndDestroy( &locals );
|
|
165 |
}
|
|
166 |
|
93
|
167 |
|
85
|
168 |
// ---------------------------------------------------------------------------
|
93
|
169 |
// CCaLocalizerScannerProxy::LocalGetEntryById
|
85
|
170 |
// ---------------------------------------------------------------------------
|
|
171 |
//
|
93
|
172 |
const TDesC& CCaLocalizerScannerProxy::GetEntryText(
|
|
173 |
RPointerArray<CCaInnerEntry> aEntries, TInt aId )
|
85
|
174 |
{
|
93
|
175 |
TInt entriesCount = aEntries.Count();
|
|
176 |
for( TInt i=0; i < entriesCount; i++ )
|
|
177 |
{
|
|
178 |
if( aEntries[i]->GetId() == aId )
|
|
179 |
{
|
|
180 |
return aEntries[i]->GetText();
|
|
181 |
}
|
|
182 |
}
|
|
183 |
return KNullDesC();
|
85
|
184 |
}
|