|
1 // Copyright (c) 2010 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 "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 #include "t_logutil3.h" |
|
16 #include <bautils.h> |
|
17 #include <barsc.h> |
|
18 #include <centralrepository.h> |
|
19 #include <logserv.rsg> |
|
20 #include "LOGREPDEFS.H" |
|
21 |
|
22 static void LoadSettingsFromResourceFileL(TInt& aContactMatchCount, TLogContactNameFormat& aContactNameFormat) |
|
23 { |
|
24 _LIT(KLogResourceFile,"z:\\private\\101f401d\\logserv.rsc"); |
|
25 TFileName fileName(KLogResourceFile); |
|
26 |
|
27 RFs fs; |
|
28 CleanupClosePushL(fs); |
|
29 User::LeaveIfError(fs.Connect()); |
|
30 BaflUtils::NearestLanguageFile(fs, fileName); |
|
31 |
|
32 // Open resource file |
|
33 RResourceFile rscFile; |
|
34 CleanupClosePushL(rscFile); |
|
35 rscFile.OpenL(fs, fileName);//OpenL() requires AllFiles capability |
|
36 |
|
37 TResourceReader reader; |
|
38 |
|
39 HBufC8* buf = rscFile.AllocReadLC(R_LOG_CONTACT_MATCH_COUNT); |
|
40 reader.SetBuffer(buf); |
|
41 aContactMatchCount = reader.ReadInt16(); |
|
42 CleanupStack::PopAndDestroy(buf); |
|
43 |
|
44 buf = rscFile.AllocReadLC(R_LOG_CONTACT_NAME_FORMAT); |
|
45 reader.SetBuffer(buf); |
|
46 aContactNameFormat = static_cast <TLogContactNameFormat> (reader.ReadInt16()); |
|
47 CleanupStack::PopAndDestroy(buf); |
|
48 |
|
49 CleanupStack::PopAndDestroy(&rscFile); |
|
50 CleanupStack::PopAndDestroy(&fs); |
|
51 } |
|
52 |
|
53 //This function reads logeng repository file and returns the integer value of the given key. |
|
54 static TInt LogGetRepositoryValueL(CRepository& aRepository, TInt aKey) |
|
55 { |
|
56 TInt val = -1; |
|
57 User::LeaveIfError(aRepository.Get(aKey, val)); |
|
58 return val; |
|
59 } |
|
60 |
|
61 //The function opens the LogEng repository (KUidLogengRepository) and gets the values of |
|
62 //KContactMatchCountRepKey and KContactNameFormatRepKey resources. |
|
63 //If it is impossible to read the values from the repository, then they will be loaded from LogServ resource file. |
|
64 void LogGetContactmatchCountAndNameFormatL(TInt& aContactMatchCount, TLogContactNameFormat& aContactNameFormat) |
|
65 { |
|
66 CRepository* repository = NULL; |
|
67 TRAPD(err, repository = CRepository::NewL(KUidLogengRepository)); |
|
68 if(err == KErrCorrupt) |
|
69 { |
|
70 __ASSERT_DEBUG(!repository, User::Invariant()); |
|
71 User::Leave(err); |
|
72 } |
|
73 else if(err == KErrNone) |
|
74 { |
|
75 CleanupStack::PushL(repository); |
|
76 aContactMatchCount = LogGetRepositoryValueL(*repository, KContactMatchCountRepKey); |
|
77 aContactNameFormat = static_cast <TLogContactNameFormat> (LogGetRepositoryValueL(*repository, KContactNameFormatRepKey)); |
|
78 CleanupStack::PopAndDestroy(repository); |
|
79 } |
|
80 else |
|
81 { |
|
82 __ASSERT_DEBUG(!repository, User::Invariant()); |
|
83 LoadSettingsFromResourceFileL(aContactMatchCount, aContactNameFormat); |
|
84 } |
|
85 } |