|
1 /* |
|
2 * Copyright (c) 2003-2008 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: Exclusion query class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include <f32file.h> |
|
22 #include <txtetext.h> |
|
23 |
|
24 #include "AknsSrvExclusion.h" |
|
25 |
|
26 #include "AknsDebug.h" |
|
27 |
|
28 // CONSTANTS |
|
29 |
|
30 static const TInt KAknsSrvExcludedAlways = 0x01; |
|
31 static const TInt KAknsSrvExcludedInArabic = 0x02; |
|
32 static const TInt KAknsSrvExcludedInHebrew = 0x04; |
|
33 static const TInt KAknsSrvMappedInArabic = 0x08; |
|
34 static const TInt KAknsSrvMappedInHebrew = 0x10; |
|
35 |
|
36 _LIT( KAknsSrvDefaultExclusionListFile, "Z:\\System\\Data\\SkinExclusions.ini" ); |
|
37 |
|
38 enum TAknsSrvExclusionListSection |
|
39 { |
|
40 EAknsSrvExclusionListSectionAlways = 0, |
|
41 EAknsSrvExclusionListSectionArabic = 1, |
|
42 EAknsSrvExclusionListSectionHebrew = 2, |
|
43 }; |
|
44 |
|
45 _LIT( KAknsSrvExclusionListSectionAlways, "[Always]" ); |
|
46 _LIT( KAknsSrvExclusionListSectionArabic, "[Arabic]" ); |
|
47 _LIT( KAknsSrvExclusionListSectionHebrew, "[Hebrew]" ); |
|
48 |
|
49 _LIT( KAknsSrvHexPrefix, "0x" ); |
|
50 |
|
51 // ============================= LOCAL FUNCTIONS =============================== |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // ConvertToIID |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 TInt ConvertToIID( TAknsItemID& aIID, const TDesC& aToken ) |
|
58 { |
|
59 TInt status = KErrNone; |
|
60 |
|
61 TInt commaIndex = aToken.Locate( (TChar)',' ); |
|
62 if( commaIndex == KErrNotFound ) |
|
63 { |
|
64 return KErrArgument; |
|
65 } |
|
66 |
|
67 TPtrC major( aToken.Left( commaIndex ) ); |
|
68 TPtrC minor( aToken.Mid( commaIndex+1 ) ); |
|
69 |
|
70 TUint majorVal, minorVal; |
|
71 |
|
72 // If descriptor begins with 0x it is a hexadecimal number |
|
73 if( (major.Length()>2) && (major.Left(2).CompareF(KAknsSrvHexPrefix)==0) ) |
|
74 { |
|
75 status |= TLex(major.Mid(2)).Val( majorVal, EHex ); |
|
76 } |
|
77 else |
|
78 { |
|
79 status |= TLex(major).Val( majorVal, EDecimal ); |
|
80 } |
|
81 |
|
82 if( (minor.Length()>2) && (minor.Left(2).CompareF(KAknsSrvHexPrefix)==0) ) |
|
83 { |
|
84 status |= TLex(minor.Mid(2)).Val( minorVal, EHex ); |
|
85 } |
|
86 else |
|
87 { |
|
88 status |= TLex(minor).Val( minorVal, EDecimal ); |
|
89 } |
|
90 |
|
91 if( status == KErrNone ) |
|
92 { |
|
93 aIID.iMajor = majorVal; |
|
94 aIID.iMinor = minorVal; |
|
95 } |
|
96 return status; |
|
97 } |
|
98 |
|
99 // ============================ MEMBER FUNCTIONS =============================== |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // TAknsSrvExclusionQuery::TAknsSrvExclusionQuery |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 TAknsSrvExclusionQuery::TAknsSrvExclusionQuery( CAknsSrvExclusionList* aList ): |
|
106 iList( aList ), |
|
107 iArabicEnabled( EFalse ), |
|
108 iHebrewEnabled( EFalse ), |
|
109 iHighlightAnimEnabled( EFalse ) |
|
110 { |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // TAknsSrvExclusionQuery::SetParameters |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 void TAknsSrvExclusionQuery::SetParameters( const TBool aArabic, |
|
118 const TBool aHebrew ) |
|
119 { |
|
120 iArabicEnabled = aArabic; |
|
121 iHebrewEnabled = aHebrew; |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // TAknsSrvExclusionQuery::SetHighlightAnimEnabled |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 void TAknsSrvExclusionQuery::SetHighlightAnimEnabled( const TBool aValue ) |
|
129 { |
|
130 iHighlightAnimEnabled = aValue; |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // TAknsSrvExclusionQuery::IsHighlightAnimEnabled |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 TBool TAknsSrvExclusionQuery::IsHighlightAnimEnabled() const |
|
138 { |
|
139 return iHighlightAnimEnabled; |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // TAknsSrvExclusionQuery::IsExcluded |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 TBool TAknsSrvExclusionQuery::IsExcluded( const TAknsItemID& aIID ) const |
|
147 { |
|
148 if( !iList ) |
|
149 { |
|
150 return EFalse; |
|
151 } |
|
152 |
|
153 const TAknsSrvExclusionListEntry* entry = iList->FindEntry( aIID ); |
|
154 if( !entry ) |
|
155 { |
|
156 return EFalse; |
|
157 } |
|
158 |
|
159 if( entry->iFlags & KAknsSrvExcludedAlways ) |
|
160 { |
|
161 return ETrue; |
|
162 } |
|
163 |
|
164 if( iArabicEnabled ) |
|
165 { |
|
166 if( entry->iFlags & KAknsSrvExcludedInArabic ) |
|
167 { |
|
168 return ETrue; |
|
169 } |
|
170 } |
|
171 |
|
172 if( iHebrewEnabled ) |
|
173 { |
|
174 if( entry->iFlags & KAknsSrvExcludedInHebrew ) |
|
175 { |
|
176 return ETrue; |
|
177 } |
|
178 } |
|
179 |
|
180 return EFalse; |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // TAknsSrvExclusionQuery::MapIID |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 TBool TAknsSrvExclusionQuery::MapIID( TAknsItemID& aIID ) const |
|
188 { |
|
189 if( !iList ) |
|
190 { |
|
191 return EFalse; |
|
192 } |
|
193 |
|
194 const TAknsSrvExclusionListEntry* entry = iList->FindEntry( aIID ); |
|
195 if( !entry ) |
|
196 { |
|
197 return EFalse; |
|
198 } |
|
199 |
|
200 if( iArabicEnabled ) |
|
201 { |
|
202 if( entry->iFlags & KAknsSrvMappedInArabic ) |
|
203 { |
|
204 aIID = entry->iTargetIID; |
|
205 return ETrue; |
|
206 } |
|
207 } |
|
208 |
|
209 if( iHebrewEnabled ) |
|
210 { |
|
211 if( entry->iFlags & KAknsSrvMappedInHebrew ) |
|
212 { |
|
213 aIID = entry->iTargetIID; |
|
214 return ETrue; |
|
215 } |
|
216 } |
|
217 |
|
218 return EFalse; |
|
219 } |
|
220 |
|
221 // ============================ MEMBER FUNCTIONS =============================== |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // TAknsSrvExclusionListEntry::LinearOrder |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 TInt TAknsSrvExclusionListEntry::LinearOrder( |
|
228 const TAknsSrvExclusionListEntry& aFirst, |
|
229 const TAknsSrvExclusionListEntry& aSecond ) |
|
230 { |
|
231 return TAknsItemID::LinearOrder( aFirst.iIID, aSecond.iIID ); |
|
232 } |
|
233 |
|
234 // ============================ MEMBER FUNCTIONS =============================== |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // C++ constructor. |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 CAknsSrvExclusionList::CAknsSrvExclusionList() |
|
241 { |
|
242 } |
|
243 |
|
244 // ----------------------------------------------------------------------------- |
|
245 // Destructor. |
|
246 // ----------------------------------------------------------------------------- |
|
247 // |
|
248 CAknsSrvExclusionList::~CAknsSrvExclusionList() |
|
249 { |
|
250 iArray.Close(); |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // Symbian two-phased constructor. |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 CAknsSrvExclusionList* CAknsSrvExclusionList::NewL() |
|
258 { |
|
259 return new (ELeave) CAknsSrvExclusionList(); |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // CAknsSrvExclusionList::LoadDefaultListFromFileL |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 void CAknsSrvExclusionList::LoadDefaultListFromFileL( RFs& aRFs ) |
|
267 { |
|
268 RFile file; |
|
269 CleanupClosePushL( file ); |
|
270 User::LeaveIfError( file.Open( aRFs, |
|
271 KAknsSrvDefaultExclusionListFile, EFileShareAny|EFileRead ) ); |
|
272 |
|
273 TInt size; |
|
274 User::LeaveIfError( file.Size( size ) ); |
|
275 |
|
276 // Read the whole file to buffer |
|
277 HBufC* buffer = HBufC::NewMaxLC( size / sizeof(TText) ); |
|
278 TPtr8 bufferPtr( (TUint8*)buffer->Ptr(), size, size ); |
|
279 User::LeaveIfError( file.Read( bufferPtr ) ); |
|
280 |
|
281 TPtrC16 dataPtr( *buffer ); |
|
282 if( (buffer->Length()>=2) && |
|
283 ((*(TText*)buffer->Ptr())==CEditableText::EByteOrderMark) ) |
|
284 { |
|
285 // Skip the byte order mark |
|
286 dataPtr.Set( dataPtr.Right( dataPtr.Length()-1 ) ); |
|
287 } |
|
288 |
|
289 // Parse each token (usually delimited by linefeeds) |
|
290 TAknsSrvExclusionListSection currentSection( |
|
291 EAknsSrvExclusionListSectionAlways ); |
|
292 TLex16 lex( dataPtr ); |
|
293 TPtrC16 token( lex.NextToken() ); |
|
294 while( token.Length() ) |
|
295 { |
|
296 if( !token.CompareF( KAknsSrvExclusionListSectionAlways ) ) |
|
297 { |
|
298 currentSection = EAknsSrvExclusionListSectionAlways; |
|
299 } |
|
300 else if( !token.CompareF( KAknsSrvExclusionListSectionArabic ) ) |
|
301 { |
|
302 currentSection = EAknsSrvExclusionListSectionArabic; |
|
303 } |
|
304 else if( !token.CompareF( KAknsSrvExclusionListSectionHebrew ) ) |
|
305 { |
|
306 currentSection = EAknsSrvExclusionListSectionHebrew; |
|
307 } |
|
308 else if( !token.Left(1).CompareF( _L("[") ) ) |
|
309 { |
|
310 // Use "always" if section is unknown |
|
311 currentSection = EAknsSrvExclusionListSectionAlways; |
|
312 } |
|
313 else |
|
314 { |
|
315 TInt equalIndex = token.Locate( (TChar)'=' ); |
|
316 |
|
317 TPtrC leftToken( token ); |
|
318 TPtrC rightToken; |
|
319 |
|
320 if( equalIndex != KErrNotFound ) |
|
321 { |
|
322 leftToken.Set( token.Left( equalIndex ) ); |
|
323 rightToken.Set( token.Mid( equalIndex+1 ) ); |
|
324 } |
|
325 |
|
326 TInt status = KErrNone; |
|
327 |
|
328 TAknsItemID leftIID; |
|
329 status |= ConvertToIID( leftIID, leftToken ); |
|
330 |
|
331 TAknsItemID rightIID; |
|
332 rightIID.Set( 0, 0 ); |
|
333 if( rightToken.Length() > 0 ) |
|
334 { |
|
335 status |= ConvertToIID( rightIID, rightToken ); |
|
336 } |
|
337 |
|
338 if( status == KErrNone ) |
|
339 { |
|
340 TAknsSrvExclusionListEntry newEntry; |
|
341 newEntry.iIID = leftIID; |
|
342 newEntry.iTargetIID = rightIID; |
|
343 newEntry.iFlags = 0; |
|
344 |
|
345 if( rightToken.Length() > 0 ) |
|
346 { |
|
347 // This is a mapping entry |
|
348 switch( currentSection ) |
|
349 { |
|
350 case EAknsSrvExclusionListSectionAlways: |
|
351 // Do nothing |
|
352 break; |
|
353 case EAknsSrvExclusionListSectionArabic: |
|
354 newEntry.iFlags = KAknsSrvMappedInArabic; |
|
355 break; |
|
356 case EAknsSrvExclusionListSectionHebrew: |
|
357 newEntry.iFlags = KAknsSrvMappedInHebrew; |
|
358 break; |
|
359 } |
|
360 } |
|
361 else |
|
362 { |
|
363 // This is an exclusion entry |
|
364 switch( currentSection ) |
|
365 { |
|
366 case EAknsSrvExclusionListSectionAlways: |
|
367 newEntry.iFlags = KAknsSrvExcludedAlways; |
|
368 break; |
|
369 case EAknsSrvExclusionListSectionArabic: |
|
370 newEntry.iFlags = KAknsSrvExcludedInArabic; |
|
371 break; |
|
372 case EAknsSrvExclusionListSectionHebrew: |
|
373 newEntry.iFlags = KAknsSrvExcludedInHebrew; |
|
374 break; |
|
375 } |
|
376 } |
|
377 |
|
378 // Create entries only for valid IIDs in valid sections |
|
379 if( newEntry.iFlags ) |
|
380 { |
|
381 TAknsSrvExclusionListEntry* oldEntry = |
|
382 FindEntry( newEntry.iIID ); |
|
383 if( oldEntry ) |
|
384 { |
|
385 oldEntry->iFlags |= newEntry.iFlags; |
|
386 } |
|
387 else |
|
388 { |
|
389 iArray.InsertInOrder( newEntry, |
|
390 TAknsSrvExclusionListEntry::LinearOrder ); |
|
391 } |
|
392 } |
|
393 } |
|
394 } |
|
395 |
|
396 token.Set( lex.NextToken() ); |
|
397 } |
|
398 |
|
399 CleanupStack::PopAndDestroy( 2 ); // buffer, file |
|
400 } |
|
401 |
|
402 // ----------------------------------------------------------------------------- |
|
403 // CAknsSrvExclusionList::FindEntry |
|
404 // ----------------------------------------------------------------------------- |
|
405 // |
|
406 TAknsSrvExclusionListEntry* CAknsSrvExclusionList::FindEntry( |
|
407 const TAknsItemID& aIID ) |
|
408 { |
|
409 TAknsSrvExclusionListEntry key; |
|
410 key.iIID = aIID; |
|
411 TInt index = iArray.FindInOrder( key, |
|
412 TAknsSrvExclusionListEntry::LinearOrder ); |
|
413 |
|
414 if( index == KErrNotFound ) |
|
415 { |
|
416 return NULL; |
|
417 } |
|
418 |
|
419 return &(iArray[index]); |
|
420 } |
|
421 |
|
422 // End of File |