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