1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 |
|
18 /** |
|
19 @internalComponent |
|
20 */ |
|
21 |
|
22 #include "apsiconcaptionoverride.h" |
|
23 #include <centralrepository.h> |
|
24 #include <apadef.h> |
|
25 |
|
26 //constants defined |
|
27 const TUid KUidIconCaptionRepository = { 0x1028583d }; // Central Repository UID |
|
28 const TUint32 KAppBits = 0xFF000000; // App mask bits |
|
29 const TUint32 KFieldBits = 0x00FF0000; // Field mask bits |
|
30 const TUint32 KUidKey = 0x00FFFFFF; // UID mask bits |
|
31 |
|
32 // Field id values for short caption, caption, icon count, icon file name |
|
33 // of an application. |
|
34 enum TFieldId |
|
35 { |
|
36 EOverrideFieldShortCaption, |
|
37 EOverrideFieldCaption, |
|
38 EOverrideFieldNumIcons, |
|
39 EOverrideFieldIconFileName |
|
40 }; |
|
41 |
|
42 /** |
|
43 Stores the Central Repository configuration details into a Hash table. |
|
44 Two Hash tables defined to store integer and string type data separately. |
|
45 */ |
|
46 NONSHARABLE_CLASS(CApaIconCaptionOverrideStore) : public CBase |
|
47 { |
|
48 public: |
|
49 CApaIconCaptionOverrideStore(); |
|
50 ~CApaIconCaptionOverrideStore(); |
|
51 |
|
52 const TDesC* String(TUint32 aKey) const; |
|
53 void SetStringL(TUint32 aKey, const TDesC& aString); |
|
54 const TInt* Int(TUint32 aKey) const; |
|
55 void SetIntL(TUint32 aKey, TInt aInt); |
|
56 |
|
57 private: |
|
58 typedef RHashMap<TUint32, TInt> RIntMap; |
|
59 RIntMap iIntMap; |
|
60 typedef RHashMap<TUint32, HBufC*> RStringMap; |
|
61 RStringMap iStringMap; |
|
62 }; |
|
63 |
|
64 |
|
65 |
|
66 // Constructor |
|
67 CApaIconCaptionOverrideStore::CApaIconCaptionOverrideStore() |
|
68 { |
|
69 } |
|
70 |
|
71 // Destructor |
|
72 CApaIconCaptionOverrideStore::~CApaIconCaptionOverrideStore() |
|
73 { |
|
74 RStringMap::TIter pString(iStringMap); |
|
75 for (HBufC* const* str = pString.NextValue(); |
|
76 str; |
|
77 str = pString.NextValue()) |
|
78 delete *str; |
|
79 iStringMap.Close(); |
|
80 iIntMap.Close(); |
|
81 } |
|
82 |
|
83 /** |
|
84 Looks up a specified key in the associative array and returns a pointer to the corresponding value. |
|
85 |
|
86 @param aKey The key object of type integer to look up. |
|
87 @return A pointer to the corresponding string value. |
|
88 */ |
|
89 const TDesC* CApaIconCaptionOverrideStore::String(TUint32 aKey) const |
|
90 { |
|
91 HBufC* const * pStr = iStringMap.Find(aKey); |
|
92 if (pStr) |
|
93 return *pStr; |
|
94 else |
|
95 return NULL; |
|
96 } |
|
97 |
|
98 /** |
|
99 Inserts the key-value pair into the array (string Hash table). |
|
100 |
|
101 @param aKey The key object of type integer to add to the array. |
|
102 @param aString The value object of type string to associate with aKey. |
|
103 */ |
|
104 void CApaIconCaptionOverrideStore::SetStringL(TUint32 aKey, const TDesC& aString) |
|
105 { |
|
106 HBufC* newStr = aString.AllocL(); |
|
107 HBufC* const * pStr = iStringMap.Find(aKey); |
|
108 CleanupStack::PushL(newStr); |
|
109 if (pStr) |
|
110 { |
|
111 delete *pStr; |
|
112 } |
|
113 iStringMap.InsertL(aKey, newStr); |
|
114 CleanupStack::Pop(newStr); |
|
115 } |
|
116 |
|
117 /** |
|
118 Looks up a specified key in the associative array and returns a pointer to the corresponding value. |
|
119 |
|
120 @param aKey The key object of type integer to look up |
|
121 @return A pointer to the corresponding integer value. |
|
122 */ |
|
123 const TInt* CApaIconCaptionOverrideStore::Int(TUint32 aKey) const |
|
124 { |
|
125 const TInt * pInt = iIntMap.Find(aKey); |
|
126 return pInt; |
|
127 } |
|
128 |
|
129 /** |
|
130 Inserts the key-value pair into the array (integer Hash table) |
|
131 |
|
132 @param aKey The key object of type integer to add to the array. |
|
133 @param aInt The value object of type integer to associate with aKey. |
|
134 */ |
|
135 void CApaIconCaptionOverrideStore::SetIntL(TUint32 aKey, TInt aInt) |
|
136 { |
|
137 iIntMap.InsertL(aKey, aInt); |
|
138 } |
|
139 |
|
140 /** |
|
141 A utility class used to write information into a store (CApaIconCaptionOverrideStore). |
|
142 */ |
|
143 NONSHARABLE_CLASS(TApaIconCaptionOverrideWriter) |
|
144 { |
|
145 public: |
|
146 TApaIconCaptionOverrideWriter(CApaIconCaptionOverrideStore& aStore); |
|
147 |
|
148 void LoadFieldFromCenRepL(CRepository* aRepository, TUint32 aFullKey); |
|
149 |
|
150 private: |
|
151 CApaIconCaptionOverrideStore& iStore; |
|
152 }; |
|
153 |
|
154 |
|
155 TApaIconCaptionOverrideWriter::TApaIconCaptionOverrideWriter(CApaIconCaptionOverrideStore& aStore) |
|
156 : iStore(aStore) |
|
157 { |
|
158 } |
|
159 |
|
160 /** |
|
161 Reads the Central Repository integer, string settings and inserts the key-value pair into Store. |
|
162 |
|
163 Each setting is enumerated by a 32-bit key. The top 8 bits of the key is for app identification, |
|
164 the next 8 bits is for field (short caption (00), caption (01),total number of icons (02), |
|
165 icon filename (03)) identification and next 16 bits for language identification. |
|
166 |
|
167 It is computed in the following way |
|
168 |
|
169 00XXXXXX - App UID field |
|
170 XX00XXXX - Short Caption field |
|
171 XX01XXXX - Caption field |
|
172 XX02XXXX - Icon count field |
|
173 XX03XXXX - Icon Filename field |
|
174 XXXX0000 - Language field |
|
175 |
|
176 First it performs a bitwise NOT operation on application mask key (KAppBits) and its value is bitwise |
|
177 AND with the 32 bit key of the field. |
|
178 |
|
179 It performs a bitwise AND with the field mask key (KFieldBits) and does a bitwise right shift to 16 bits |
|
180 to extract the field bit value from the 32 bit key. |
|
181 |
|
182 It reads each field's (short caption, caption, total number of icons, icon file name) value from the |
|
183 Central Repository and inserts into a Store (Hash table). |
|
184 |
|
185 @param aRepository The object provides access to Central Repository |
|
186 @param aFullKey The 32-bit field key |
|
187 */ |
|
188 void TApaIconCaptionOverrideWriter::LoadFieldFromCenRepL(CRepository* aRepository, TUint32 aFullKey) |
|
189 { |
|
190 TUint32 key = aFullKey & ~KAppBits; |
|
191 TUint32 fieldId = (key & KFieldBits) >> 16; |
|
192 switch (fieldId) |
|
193 { |
|
194 case EOverrideFieldShortCaption: |
|
195 { |
|
196 TApaAppCaption shortCaption; |
|
197 if (aRepository->Get(aFullKey, shortCaption) == KErrNone) |
|
198 iStore.SetStringL(key, shortCaption); |
|
199 break; |
|
200 } |
|
201 case EOverrideFieldCaption: |
|
202 { |
|
203 TApaAppCaption caption; |
|
204 if (aRepository->Get(aFullKey, caption) == KErrNone) |
|
205 iStore.SetStringL(key, caption); |
|
206 break; |
|
207 } |
|
208 case EOverrideFieldNumIcons: |
|
209 int numIcons; |
|
210 if (aRepository->Get(aFullKey, numIcons) == KErrNone) |
|
211 iStore.SetIntL(key, numIcons); |
|
212 break; |
|
213 case EOverrideFieldIconFileName: |
|
214 { |
|
215 TFileName fileName; |
|
216 if (aRepository->Get(aFullKey, fileName) == KErrNone) |
|
217 iStore.SetStringL(key, fileName); |
|
218 break; |
|
219 } |
|
220 default: |
|
221 break; |
|
222 } |
|
223 } |
|
224 |
|
225 // Constructor |
|
226 TApaIconCaptionOverrideReader::TApaIconCaptionOverrideReader(const CApaIconCaptionOverrideStore& aStore, const RArray<TLanguage>& aLanguageDowngradePath) |
|
227 : iStore(aStore), iLanguageDowngradePath(aLanguageDowngradePath) |
|
228 { |
|
229 } |
|
230 |
|
231 /** |
|
232 Gets the short caption value of the corresponding setting from store. |
|
233 */ |
|
234 const TDesC* TApaIconCaptionOverrideReader::ShortCaption() const |
|
235 { |
|
236 return GetString(EOverrideFieldShortCaption); |
|
237 } |
|
238 |
|
239 /** |
|
240 Gets the caption value of the corresponding setting from store. |
|
241 */ |
|
242 const TDesC* TApaIconCaptionOverrideReader::Caption() const |
|
243 { |
|
244 return GetString(EOverrideFieldCaption); |
|
245 } |
|
246 |
|
247 /** |
|
248 Checks whether the number of icons are set. |
|
249 @return ETrue when the number of icons are set else returns EFalse. |
|
250 */ |
|
251 TBool TApaIconCaptionOverrideReader::NumIconsSet() const |
|
252 { |
|
253 return GetInt(EOverrideFieldNumIcons) != NULL; |
|
254 } |
|
255 |
|
256 /** |
|
257 Gets the total number of icons of the corresponding setting from store. |
|
258 */ |
|
259 TInt TApaIconCaptionOverrideReader::NumIcons() const |
|
260 { |
|
261 const TInt* pInt = GetInt(EOverrideFieldNumIcons); |
|
262 if (pInt) |
|
263 return *pInt; |
|
264 else |
|
265 return 0; |
|
266 } |
|
267 |
|
268 /** |
|
269 Gets the icon file name of the corresponding setting from store. |
|
270 */ |
|
271 const TDesC* TApaIconCaptionOverrideReader::IconFileName() const |
|
272 { |
|
273 return GetString(EOverrideFieldIconFileName); |
|
274 } |
|
275 |
|
276 /** |
|
277 Reads store and retrieves the corresponding string value of the passed field Id. |
|
278 |
|
279 Gets the configuration information with reference to the language downgrade path, with |
|
280 ELangNone as default language, in case there is no match is found. |
|
281 |
|
282 @param aFieldId Field Id values for short caption, caption, icon count, icon file name. |
|
283 @return A pointer to the corresponding string value. |
|
284 */ |
|
285 const TDesC* TApaIconCaptionOverrideReader::GetString(TUint32 aFieldId) const |
|
286 { |
|
287 TInt count = iLanguageDowngradePath.Count(); |
|
288 for (TInt ii=0; ii<count; ii++) |
|
289 { |
|
290 TLanguage language = iLanguageDowngradePath[ii]; |
|
291 TUint32 key = (aFieldId << 16) | language; |
|
292 const TDesC* pString = iStore.String(key); |
|
293 if (pString) |
|
294 return pString; |
|
295 } |
|
296 // default fallback language is ELangNone |
|
297 TUint32 key = (aFieldId << 16) | ELangNone; |
|
298 const TDesC* pString = iStore.String(key); |
|
299 if (pString) |
|
300 return pString; |
|
301 return NULL; |
|
302 } |
|
303 |
|
304 /** |
|
305 Reads store and retrieves the corresponding integer value of the passed field Id. |
|
306 |
|
307 Gets the configuration information with reference to the language downgrade path, with |
|
308 ELangNone as default language, in case there is no match is found. |
|
309 |
|
310 @param aFieldId Field Id values for short caption, caption, icon count, icon file name. |
|
311 @return A pointer to the corresponding integer value. |
|
312 */ |
|
313 const TInt* TApaIconCaptionOverrideReader::GetInt(TUint32 aFieldId) const |
|
314 { |
|
315 TInt count = iLanguageDowngradePath.Count(); |
|
316 for (TInt ii=0; ii<count; ii++) |
|
317 { |
|
318 TLanguage language = iLanguageDowngradePath[ii]; |
|
319 TUint32 key = (aFieldId << 16) | language; |
|
320 const TInt* pInt = iStore.Int(key); |
|
321 if (pInt) |
|
322 return pInt; |
|
323 } |
|
324 // default fallback language is ELangNone |
|
325 TUint32 key = (aFieldId << 16) | ELangNone; |
|
326 const TInt* pInt = iStore.Int(key); |
|
327 if (pInt) |
|
328 return pInt; |
|
329 return NULL; |
|
330 } |
|
331 |
|
332 // Constructor |
|
333 CApaIconCaptionOverridesForApp::CApaIconCaptionOverridesForApp() |
|
334 { |
|
335 } |
|
336 |
|
337 // Destructor |
|
338 CApaIconCaptionOverridesForApp::~CApaIconCaptionOverridesForApp() |
|
339 { |
|
340 delete iStore; |
|
341 } |
|
342 |
|
343 CApaIconCaptionOverridesForApp* CApaIconCaptionOverridesForApp::NewL() |
|
344 { |
|
345 CApaIconCaptionOverridesForApp* self = new (ELeave) CApaIconCaptionOverridesForApp; |
|
346 CleanupStack::PushL(self); |
|
347 self->ConstructL(); |
|
348 CleanupStack::Pop(); // self |
|
349 return self; |
|
350 } |
|
351 |
|
352 /** 2nd phase constructor that creates an object to store the Central Repository configuration |
|
353 details (integer & string values) into separate Hash tables. |
|
354 */ |
|
355 void CApaIconCaptionOverridesForApp::ConstructL() |
|
356 { |
|
357 iStore = new(ELeave) CApaIconCaptionOverrideStore; |
|
358 } |
|
359 |
|
360 /** |
|
361 Finds all the settings that exist and match the specification given by partial key (aAppKey) and |
|
362 application mask key (KAppBits) from the Central Repository. |
|
363 |
|
364 All the 32-bit field keys have been retrieved from the Central Repository and stored into an array. |
|
365 It performs a bitwise NOT operation on application mask key (KAppBits) and its value is bitwise AND |
|
366 with each of the value retrieved from the array. If the new value does not match with the UID mask key, |
|
367 it tries to read each field setting value and stores the information into a store (Hash tables). |
|
368 |
|
369 @param aRepository The object provides access to Central Repository. |
|
370 @param aAppKey partial key. |
|
371 */ |
|
372 void CApaIconCaptionOverridesForApp::LoadFromCenRepL(CRepository* aRepository, TUint32 aAppKey) |
|
373 { |
|
374 TApaIconCaptionOverrideWriter writer(*iStore); |
|
375 RArray<TUint32> appKeys; |
|
376 CleanupClosePushL(appKeys); |
|
377 User::LeaveIfError(aRepository->FindL(aAppKey, KAppBits, appKeys)); |
|
378 TInt count = appKeys.Count(); |
|
379 for (TInt ii=0; ii<count; ii++) |
|
380 { |
|
381 TUint32 key = appKeys[ii]; |
|
382 if ((key & ~KAppBits) == KUidKey) |
|
383 continue; |
|
384 writer.LoadFieldFromCenRepL(aRepository, key); |
|
385 } |
|
386 CleanupStack::PopAndDestroy(&appKeys); |
|
387 } |
|
388 |
|
389 /** |
|
390 Creates an object to read the configuration information with reference to the language downgrade path, |
|
391 with ELangNone used as the default language, if no better match is found. |
|
392 */ |
|
393 TApaIconCaptionOverrideReader CApaIconCaptionOverridesForApp::Reader(const RArray<TLanguage>& aLanguageDowngradePath) const |
|
394 { |
|
395 TApaIconCaptionOverrideReader reader(*iStore, aLanguageDowngradePath); |
|
396 return reader; |
|
397 } |
|
398 |
|
399 // Constructor |
|
400 CApaIconCaptionOverrides::CApaIconCaptionOverrides() |
|
401 { |
|
402 } |
|
403 |
|
404 // Destructor |
|
405 CApaIconCaptionOverrides::~CApaIconCaptionOverrides() |
|
406 { |
|
407 DeleteOverrides(); |
|
408 } |
|
409 |
|
410 void CApaIconCaptionOverrides::LoadFromCenRepL() |
|
411 { |
|
412 CRepository* cenrep = CRepository::NewLC(KUidIconCaptionRepository); |
|
413 LoadFromCenRepL(cenrep); |
|
414 CleanupStack::PopAndDestroy(cenrep); |
|
415 } |
|
416 |
|
417 /** |
|
418 Finds all the settings that exist and match the specification given by partial and mask keys, from the |
|
419 Central Repository. If the settings are found, it reads the values and stores icon, caption details |
|
420 into the store. |
|
421 */ |
|
422 void CApaIconCaptionOverrides::LoadFromCenRepL(CRepository* aRepository) |
|
423 { |
|
424 DeleteOverrides(); |
|
425 |
|
426 RArray<TUint32> appKeys; |
|
427 CleanupClosePushL(appKeys); |
|
428 aRepository->FindL(KUidKey, ~KAppBits, appKeys); // ignore return. if no overrides found, array will be empty |
|
429 TInt count = appKeys.Count(); |
|
430 for (TInt ii=0; ii<count; ii++) |
|
431 { |
|
432 TUint32 key = appKeys[ii]; |
|
433 TInt appUidVal; |
|
434 User::LeaveIfError(aRepository->Get(key, appUidVal)); |
|
435 TUid appUid = { appUidVal }; |
|
436 CApaIconCaptionOverridesForApp* app = CApaIconCaptionOverridesForApp::NewL(); |
|
437 CleanupStack::PushL(app); |
|
438 app->LoadFromCenRepL(aRepository, key); |
|
439 SetOverrideForAppL(appUid, app); |
|
440 CleanupStack::Pop(app); |
|
441 } |
|
442 CleanupStack::PopAndDestroy(&appKeys); |
|
443 } |
|
444 |
|
445 /** |
|
446 Searches Hash table that keeps a map of app UIDs to configuration information for supplied application |
|
447 and returns a pointer to an object that keeps information of icon caption overrides for an application, if |
|
448 any suitable entry is found; otherwise NULL. |
|
449 */ |
|
450 CApaIconCaptionOverridesForApp* CApaIconCaptionOverrides::OverrideForApp(TUid aAppUid) const |
|
451 { |
|
452 CApaIconCaptionOverridesForApp* const * override = iMap.Find(aAppUid.iUid); |
|
453 if (override) |
|
454 return *override; |
|
455 else |
|
456 return NULL; |
|
457 } |
|
458 |
|
459 /** |
|
460 Inserts key-value pair into an array (Hash table), if found, updates it. |
|
461 */ |
|
462 void CApaIconCaptionOverrides::SetOverrideForAppL(TUid aAppUid, CApaIconCaptionOverridesForApp* aOverrides) |
|
463 { |
|
464 //Searches the Hash table with the app UID, if it's found, it returns the corresponding entry; |
|
465 CApaIconCaptionOverridesForApp* prev = OverrideForApp(aAppUid); |
|
466 if (aOverrides) |
|
467 { |
|
468 iMap.InsertL(aAppUid.iUid, aOverrides); |
|
469 } |
|
470 else |
|
471 { |
|
472 iMap.Remove(aAppUid.iUid); |
|
473 } |
|
474 delete prev; // delete the found entry as InsertL() replaces it. |
|
475 } |
|
476 |
|
477 /** |
|
478 Removes all the mapping done with app UIDs in Hash table for the icon caption overrides. |
|
479 */ |
|
480 void CApaIconCaptionOverrides::DeleteOverrides() |
|
481 { |
|
482 RAppOverrideMap::TIter pOverride(iMap); |
|
483 for (CApaIconCaptionOverridesForApp* const* override = pOverride.NextValue(); |
|
484 override; |
|
485 override = pOverride.NextValue()) |
|
486 delete *override; |
|
487 iMap.Close(); |
|
488 } |
|
489 |
|
490 |
|
491 CApaIconCaptionCenrepObserver::CApaIconCaptionCenrepObserver(CApaIconCaptionOverrides& aOverrides) |
|
492 : CActive(EPriorityStandard), iOverrides(aOverrides) |
|
493 { |
|
494 CActiveScheduler::Add(this); |
|
495 } |
|
496 |
|
497 // Creates a Central Repository observer |
|
498 CApaIconCaptionCenrepObserver* CApaIconCaptionCenrepObserver::NewL(CApaIconCaptionOverrides& aOverrides) |
|
499 { |
|
500 CApaIconCaptionCenrepObserver* self = new (ELeave) CApaIconCaptionCenrepObserver(aOverrides); |
|
501 CleanupStack::PushL(self); |
|
502 self->ConstructL(); |
|
503 CleanupStack::Pop(); |
|
504 return self; |
|
505 } |
|
506 |
|
507 // Destructor |
|
508 CApaIconCaptionCenrepObserver::~CApaIconCaptionCenrepObserver() |
|
509 { |
|
510 Cancel(); |
|
511 delete iRepository; |
|
512 } |
|
513 |
|
514 /** 2nd phase constructor that creates a Central Repository object to access the repository with the |
|
515 specified UID and starts notification. |
|
516 */ |
|
517 void CApaIconCaptionCenrepObserver::ConstructL() |
|
518 { |
|
519 TRAP_IGNORE(iRepository = CRepository::NewL(KUidIconCaptionRepository)); |
|
520 Start(); |
|
521 } |
|
522 |
|
523 /** |
|
524 Finds all the settings that exist and match the specification given by partial and mask keys, from the |
|
525 Central Repository, if it exists. |
|
526 */ |
|
527 void CApaIconCaptionCenrepObserver::LoadOverridesL() |
|
528 { |
|
529 if (iRepository) |
|
530 iOverrides.LoadFromCenRepL(iRepository); |
|
531 } |
|
532 |
|
533 /** |
|
534 Requests a notification on any change in the Central Repository. Only one notification can be |
|
535 received per call to NotifyRequest(). |
|
536 */ |
|
537 void CApaIconCaptionCenrepObserver::Start() |
|
538 { |
|
539 if (iRepository) |
|
540 { |
|
541 iRepository->NotifyRequest(0, 0, iStatus); // notify on all key changes |
|
542 SetActive(); |
|
543 } |
|
544 } |
|
545 |
|
546 /** |
|
547 Handles an active object's request completion event. |
|
548 */ |
|
549 void CApaIconCaptionCenrepObserver::RunL() |
|
550 { |
|
551 TInt err = iStatus.Int(); |
|
552 Start(); |
|
553 User::LeaveIfError(err); |
|
554 LoadOverridesL(); |
|
555 } |
|
556 |
|
557 /** |
|
558 Cancels a notification previously requested from NotifyRequest |
|
559 */ |
|
560 void CApaIconCaptionCenrepObserver::DoCancel() |
|
561 { |
|
562 iRepository->NotifyCancel(0, 0); |
|
563 } |
|
564 |
|
565 |
|
566 TInt CApaIconCaptionCenrepObserver::RunError(TInt /*aError*/) |
|
567 { |
|
568 //Return KErrNone if RunL leaves to avoid a E32User-CBase 47 panic. |
|
569 return KErrNone; |
|
570 } |
|