24 //#include "cainternaltypes.h" |
24 //#include "cainternaltypes.h" |
25 #include "caarraycleanup.inl" |
25 #include "caarraycleanup.inl" |
26 #include "calocalizerscannerproxy.h" |
26 #include "calocalizerscannerproxy.h" |
27 #include "castorageproxy.h" |
27 #include "castorageproxy.h" |
28 #include "cadef.h" |
28 #include "cadef.h" |
|
29 #include "cainnerquery.h" |
|
30 #include "cainnerentry.h" |
29 |
31 |
30 const char* KEmptyString = ""; |
32 _LIT(KPathLoc,"z:/resource/qt/translations"); |
31 |
33 |
32 // --------------------------------------------------------------------------- |
34 // --------------------------------------------------------------------------- |
33 // CCaLocalizerScannerProxy::NewL |
35 // CCaLocalizerScannerProxy::NewL |
34 // Two-phased constructor. |
36 // Two-phased constructor. |
35 // --------------------------------------------------------------------------- |
37 // --------------------------------------------------------------------------- |
63 // Symbian 2nd phase constructor can leave. |
65 // Symbian 2nd phase constructor can leave. |
64 // --------------------------------------------------------------------------- |
66 // --------------------------------------------------------------------------- |
65 // |
67 // |
66 void CCaLocalizerScannerProxy::ConstructL() |
68 void CCaLocalizerScannerProxy::ConstructL() |
67 { |
69 { |
68 iTranslator = new ( ELeave ) QTranslator(); |
70 TBuf<KCaMaxAttrNameLen> filenameDsc; |
69 PerformL(); |
71 iStorageProxy->DbPropertyL( KCaDbPropQMfile, filenameDsc ); |
|
72 iResolver = new (ELeave) HbTextResolverSymbian; |
|
73 iResolver->Init(filenameDsc, KPathLoc); |
|
74 UpdateLocalNamesL(); |
|
75 delete iResolver; |
|
76 iResolver = NULL; |
70 } |
77 } |
71 |
78 |
72 // --------------------------------------------------------------------------- |
79 // --------------------------------------------------------------------------- |
73 // CCaLocalizerScannerProxy::CCaLocalizerScannerProxy |
80 // CCaLocalizerScannerProxy::CCaLocalizerScannerProxy |
74 // C++ default constructor can NOT contain any code, that |
81 // C++ default constructor can NOT contain any code, that |
86 // Destructor. |
93 // Destructor. |
87 // --------------------------------------------------------------------------- |
94 // --------------------------------------------------------------------------- |
88 // |
95 // |
89 CCaLocalizerScannerProxy::~CCaLocalizerScannerProxy() |
96 CCaLocalizerScannerProxy::~CCaLocalizerScannerProxy() |
90 { |
97 { |
91 delete iTranslator; |
98 if (iResolver) |
92 } |
99 { |
93 |
100 delete iResolver; |
94 // --------------------------------------------------------------------------- |
101 } |
95 // CCaLocalizerScannerProxy::PerformL |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void CCaLocalizerScannerProxy::PerformL() |
|
99 { |
|
100 QString locale = QLocale::system().name(); |
|
101 QString filename = QString( "contentstorage_" ) + locale; |
|
102 LoadTranslator( filename ); |
|
103 TPtrC ptrLocale( reinterpret_cast<const TText*>( locale.constData() ) ); |
|
104 TBuf<KCaMaxAttrNameLen> propertyValue; |
|
105 // trap is here to assure deletion of qtranslator in case code leaves |
|
106 iStorageProxy->DbPropertyL( KCaDbPropLanguage, propertyValue ); |
|
107 if( ptrLocale.CompareC( propertyValue ) ) |
|
108 { |
|
109 // language is changed - update locale names |
|
110 UpdateLocalNamesL(); |
|
111 // remember info about new language in db |
|
112 iStorageProxy->SetDBPropertyL( KCaDbPropLanguage, ptrLocale ); |
|
113 } |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // CCaLocalizerScannerProxy::LoadTranslator |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 TBool CCaLocalizerScannerProxy::LoadTranslator( QString filename ) |
|
121 { |
|
122 TBool loaded( false ); |
|
123 // load from rom or testbase |
|
124 loaded = iTranslator->load( filename, QString( "z:/resource/qt/translations" ) ); |
|
125 if( !loaded ) |
|
126 { |
|
127 loaded = iTranslator->load( filename, QString( "c:/resource/qt/translations" ) ); |
|
128 } |
|
129 |
|
130 return loaded; |
|
131 } |
102 } |
132 |
103 |
133 // --------------------------------------------------------------------------- |
104 // --------------------------------------------------------------------------- |
134 // CCaLocalizerScannerProxy::GetLocalizationRowsL |
105 // CCaLocalizerScannerProxy::GetLocalizationRowsL |
135 // --------------------------------------------------------------------------- |
106 // --------------------------------------------------------------------------- |
149 // |
120 // |
150 void CCaLocalizerScannerProxy::UpdateLocalNamesL() |
121 void CCaLocalizerScannerProxy::UpdateLocalNamesL() |
151 { |
122 { |
152 RPointerArray<CCaLocalizationEntry> locals; |
123 RPointerArray<CCaLocalizationEntry> locals; |
153 CleanupResetAndDestroyPushL( locals ); |
124 CleanupResetAndDestroyPushL( locals ); |
|
125 RPointerArray<CCaInnerEntry> entries; |
|
126 CleanupResetAndDestroyPushL( entries ); |
|
127 RArray<TInt> ids; |
|
128 CleanupClosePushL( ids ); |
|
129 |
154 GetLocalizationRowsL( locals ); |
130 GetLocalizationRowsL( locals ); |
155 QString locName; |
131 |
156 RBuf localizedName; |
132 TInt locCount = locals.Count(); |
157 CleanupClosePushL( localizedName ); |
133 for( TInt idx = 0; idx < locCount; idx++ ) |
158 localizedName.CreateL( KCaMaxAttrValueLen ); |
|
159 |
|
160 for( TInt i = 0; i < locals.Count(); i++ ) |
|
161 { |
134 { |
162 const char* temp = DescriptorToStringL( locals[i]->GetStringId() ); |
135 ids.Append( locals[idx]->GetRowId() ); |
163 // first string is a contex, probably to put in database in future |
136 } |
164 locName = iTranslator->translate( KEmptyString, temp, KEmptyString ); |
137 CCaInnerQuery* query = CCaInnerQuery::NewLC(); |
165 localizedName = reinterpret_cast<const TText*> ( locName.constData() ); |
138 query->SetIdsL( ids ); |
166 if (localizedName.Compare(KNullDesC)) |
139 iStorageProxy->GetEntriesL( query, entries ); |
167 { |
140 CleanupStack::PopAndDestroy( query ); |
168 locals[i]->SetLocalizedStringL( localizedName ); |
141 |
169 } |
142 HBufC16* localizedName; |
170 else |
143 for( TInt i = 0; i < locCount; i++ ) |
171 { |
144 { |
172 locals[i]->SetLocalizedStringL( locals[i]->GetStringId() ); |
145 localizedName = iResolver->LoadLC( locals[i]->GetStringId() ); |
173 } |
146 if( localizedName->Compare( |
174 iStorageProxy->LocalizeEntryL( *( locals[i] ) ); |
147 GetEntryText( entries, locals[i]->GetRowId() ) ) ) |
175 delete[] temp; |
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 ); |
176 } |
160 } |
177 CleanupStack::PopAndDestroy( &localizedName ); |
161 |
|
162 CleanupStack::PopAndDestroy( &ids ); |
|
163 CleanupStack::PopAndDestroy( &entries ); |
178 CleanupStack::PopAndDestroy( &locals ); |
164 CleanupStack::PopAndDestroy( &locals ); |
179 } |
165 } |
180 |
166 |
|
167 |
181 // --------------------------------------------------------------------------- |
168 // --------------------------------------------------------------------------- |
182 // CCaLocalizerScannerProxy::DescriptorToStringL |
169 // CCaLocalizerScannerProxy::LocalGetEntryById |
183 // --------------------------------------------------------------------------- |
170 // --------------------------------------------------------------------------- |
184 // |
171 // |
185 const char* CCaLocalizerScannerProxy::DescriptorToStringL( |
172 const TDesC& CCaLocalizerScannerProxy::GetEntryText( |
186 const TDesC& aDescriptor ) |
173 RPointerArray<CCaInnerEntry> aEntries, TInt aId ) |
187 { |
174 { |
188 TInt length = aDescriptor.Length(); |
175 TInt entriesCount = aEntries.Count(); |
189 HBufC8* buffer = HBufC8::NewLC( length ); |
176 for( TInt i=0; i < entriesCount; i++ ) |
190 buffer->Des().Copy( aDescriptor ); |
177 { |
191 char* str = new ( ELeave ) char[length + 1]; |
178 if( aEntries[i]->GetId() == aId ) |
192 Mem::Copy( str, buffer->Ptr(), length ); |
179 { |
193 str[length] = '\0'; |
180 return aEntries[i]->GetText(); |
194 CleanupStack::PopAndDestroy( buffer ); |
181 } |
195 return str; |
182 } |
|
183 return KNullDesC(); |
196 } |
184 } |
197 |
|