1 /* |
|
2 * Copyright (c) 2010 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: Implementation of CSsmCollationObserver class. |
|
15 * |
|
16 */ |
|
17 #include "ssmcollationobserversup.h" |
|
18 #include "ssmlocalepskeys.h" |
|
19 #include "ssmmapperutilityinternalpskeys.h" |
|
20 #include "ssmcommonlocale.h" |
|
21 #include "trace.h" |
|
22 #include <centralrepository.h> |
|
23 #include <CommonEngineDomainCRKeys.h> |
|
24 |
|
25 // --------------------------------------------------------------------------- |
|
26 // CSsmCollationObserver::NewL() |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 EXPORT_C MSsmUtility* CSsmCollationObserver::NewL() |
|
30 { |
|
31 FUNC_LOG; |
|
32 CSsmCollationObserver* self = new( ELeave ) CSsmCollationObserver(); |
|
33 return self; |
|
34 } |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // CSsmCollationObserver::InitializeL() |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 void CSsmCollationObserver::InitializeL() |
|
41 { |
|
42 |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // CSsmCollationObserver::StartL() |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 void CSsmCollationObserver::StartL() |
|
50 { |
|
51 FUNC_LOG; |
|
52 TInt errorCode = iCollationProperty.Attach( KPSStarterUid, KSSMCollationPSKey ); |
|
53 ERROR_2( errorCode, "Failed to attach to property 0x%08x::0x%08x", KPSStarterUid.iUid, KSSMCollationPSKey ); |
|
54 Activate(); |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CSsmCollationObserver::Release() |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 void CSsmCollationObserver::Release() |
|
62 { |
|
63 FUNC_LOG; |
|
64 delete this; |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // CSsmCollationObserver::~CSsmCollationObserver() |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 CSsmCollationObserver::~CSsmCollationObserver() |
|
72 { |
|
73 FUNC_LOG; |
|
74 Cancel(); |
|
75 iCollationProperty.Close(); |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // CSsmCollationObserver::DoCancel() |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 void CSsmCollationObserver::DoCancel() |
|
83 { |
|
84 FUNC_LOG; |
|
85 iCollationProperty.Cancel(); |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // CSsmCollationObserver::RunL() |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 void CSsmCollationObserver::RunL() |
|
93 { |
|
94 FUNC_LOG; |
|
95 const TInt errorCode = iStatus.Int(); |
|
96 if (KErrNone == errorCode ) |
|
97 { |
|
98 Activate(); |
|
99 LoadCollation(); |
|
100 } |
|
101 else |
|
102 { |
|
103 INFO_1( "CSsmCollationObserver::RunL()completed with: %d - not reactivating", iStatus.Int() ); |
|
104 } |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // CSsmCollationObserver::LoadCollation() |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 void CSsmCollationObserver::LoadCollation() |
|
112 { |
|
113 FUNC_LOG; |
|
114 TInt collation(0); |
|
115 TInt errorCode = iCollationProperty.Get( collation ); |
|
116 |
|
117 if( KErrNone != errorCode ) |
|
118 { |
|
119 INFO_1( "Failed to get KSSMCollationPSKey value with error %d", errorCode ); |
|
120 return; |
|
121 } |
|
122 |
|
123 // Dot plus three digit locale |
|
124 TBuf<KMaxDllExtensionLength> extension; |
|
125 extension.Format( KDllExtensionFormat, collation ); |
|
126 |
|
127 // Padd ".1" to ".001" for compatibility. |
|
128 for( ; extension.Length() < KMinDllExtensionLength ;) |
|
129 { |
|
130 extension.Insert( KDllExtensionPaddingPosition, |
|
131 KDllExtensionPadding ); |
|
132 } |
|
133 |
|
134 TBuf<KMaxDllNameLength> collationDllName( KCollationDllNameBase ); |
|
135 collationDllName.Append( extension ); |
|
136 INFO_1( "Loading Collation DLL named '%S'", &collationDllName ); |
|
137 |
|
138 TExtendedLocale extLocale; |
|
139 extLocale.LoadSystemSettings(); |
|
140 errorCode = extLocale.LoadLocaleAspect( collationDllName ); |
|
141 |
|
142 if ( KErrNone == errorCode ) |
|
143 { |
|
144 errorCode = extLocale.SaveSystemSettings(); |
|
145 ERROR( errorCode, "Failed to save locale (Collation) settings" ); |
|
146 TLocale().Set(); |
|
147 StoreCollationToCentRep( collation ); |
|
148 } |
|
149 else |
|
150 { |
|
151 INFO_1( "Failed to load locale (Collation) with error %d", errorCode ); |
|
152 } |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // CSsmCollationObserver::StoreCollationToCentRep |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 void CSsmCollationObserver::StoreCollationToCentRep( const TInt aCollation ) |
|
160 { |
|
161 FUNC_LOG; |
|
162 CRepository* cenrep = NULL; |
|
163 TRAPD( errorCode, cenrep = CRepository::NewL( KCRUidCommonEngineKeys ) ); |
|
164 ERROR_1( errorCode, "Failed to initialize cen rep %d", errorCode ); |
|
165 |
|
166 if ( KErrNone == errorCode ) |
|
167 { |
|
168 errorCode = cenrep->Set( KGSCollation, aCollation); |
|
169 ERROR_1( errorCode, "Failed to store collation code to CentRep, %d", |
|
170 errorCode ); |
|
171 delete cenrep; |
|
172 } |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // CSsmCollationObserver::CSsmCollationObserver() |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 CSsmCollationObserver::CSsmCollationObserver() : CActive( EPriorityStandard ) |
|
180 { |
|
181 FUNC_LOG; |
|
182 CActiveScheduler::Add( this ); |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------------------------- |
|
186 // CSsmCollationObserver::Activate() |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 void CSsmCollationObserver::Activate() |
|
190 { |
|
191 FUNC_LOG; |
|
192 ASSERT( !IsActive() ); |
|
193 iCollationProperty.Subscribe( iStatus ); |
|
194 SetActive(); |
|
195 } |
|