|
1 /* |
|
2 * Copyright (c) 2006 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: This is NPP PSY Positioning Plug-in ( PSY ). |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32std.h> |
|
22 #include <centralrepository.h> |
|
23 |
|
24 #include "npppsysettinghandler.h" |
|
25 #include "npppsystatushandler.h" |
|
26 #include "npppsyinternalcrkeys.h" |
|
27 #include "npppsylogging.h" |
|
28 #include "npppsypanic.h" |
|
29 #include "npppsy.hrh" |
|
30 |
|
31 // Constants |
|
32 // Sepperator used in setting |
|
33 _LIT( KNppPsySettingSeperator, " " ); |
|
34 |
|
35 // The width of each PSY uid in PSY list |
|
36 const TInt KNppPsyPsyUidWidth = 8; |
|
37 |
|
38 // The length of buffer which is used for logging into file |
|
39 const TInt KBufferSize = 64; |
|
40 |
|
41 // PSY list length when the list is frozen and no fallback |
|
42 const TInt KNppPsyListLengthWhenFrozenNoFallback = 1; |
|
43 |
|
44 const TText KNppPsySpaceCharacter = ' '; |
|
45 |
|
46 // ========================== == MEMBER FUNCTIONS =============================== |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CNppPsySettingHandler::CNppPsySettingHandler |
|
50 // C++default constructor can NOT contain any code, that |
|
51 // might leave. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CNppPsySettingHandler::CNppPsySettingHandler( CNppPsyStatusHandler& aStatusHandler ) |
|
55 : CActive( CActive::EPriorityStandard ), |
|
56 iStatusHandler( aStatusHandler ) |
|
57 { |
|
58 CActiveScheduler::Add( this ); |
|
59 } |
|
60 |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CNppPsySettingHandler::ConstructL |
|
64 // Symbian 2nd phase constructor can leave. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 void CNppPsySettingHandler::ConstructL() |
|
68 { |
|
69 TRACESTRING( "CNppPsySettingHandler::ConstructL start" ) |
|
70 //Central repository |
|
71 iRepository = CRepository::NewL( KCRUidNppPsy ); |
|
72 |
|
73 //Start notification |
|
74 iRepository->NotifyRequest( KNppPsyPsyList, iStatus ); |
|
75 SetActive(); |
|
76 |
|
77 //Parse settings |
|
78 ParseSettingL( iListFrozen, iPsyList ); |
|
79 |
|
80 //Check if key value is changed in ROM key |
|
81 ValidateRomKeyValueL(); |
|
82 |
|
83 //Check if the list is empty |
|
84 iStatusHandler.SetPsyListStatus( iPsyList.Count() != 0 ); |
|
85 |
|
86 TRACESTRING( "CNppPsySettingHandler::ConstructL end" ) |
|
87 } |
|
88 |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CNppPsySettingHandler::NewL |
|
92 // Two - phased constructor. |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 CNppPsySettingHandler* CNppPsySettingHandler::NewL( |
|
96 CNppPsyStatusHandler& aStatusHandler ) |
|
97 { |
|
98 CNppPsySettingHandler* self = new( ELeave ) |
|
99 CNppPsySettingHandler( aStatusHandler ); |
|
100 |
|
101 CleanupStack::PushL( self ); |
|
102 self->ConstructL(); |
|
103 CleanupStack::Pop( self ); |
|
104 |
|
105 return self; |
|
106 } |
|
107 |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CNppPsySettingHandler::~CNppPsySettingHandler |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 CNppPsySettingHandler::~CNppPsySettingHandler() |
|
114 { |
|
115 Cancel(); |
|
116 |
|
117 delete iRepository; |
|
118 |
|
119 iPsyList.Close(); |
|
120 |
|
121 TRACESTRING( "CNppPsySettingHandler:: destructed" ) |
|
122 } |
|
123 |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CNppPsySettingHandler::GetPsyListL |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 void CNppPsySettingHandler::GetPsyListL( RArray < TUid> &aList ) |
|
130 { |
|
131 aList.Reset(); |
|
132 TInt count = iPsyList.Count(); |
|
133 |
|
134 if(iListFrozen == ENppPsyPsyListFrozenNoFallback) |
|
135 { |
|
136 //If list is frozen and no fallback, we return only the first PSY |
|
137 count = ( count == 0 ? 0 : KNppPsyListLengthWhenFrozenNoFallback ); |
|
138 } |
|
139 |
|
140 TBuf<KBufferSize> buffer; |
|
141 buffer.Copy(_L("Get PSY List...")); |
|
142 TRACETEXT(buffer) |
|
143 for ( TInt i = 0; i < count; i++ ) |
|
144 { |
|
145 User::LeaveIfError( aList.Append( iPsyList[i] ) ); |
|
146 |
|
147 buffer.Copy(iPsyList[i].Name()); |
|
148 TRACETEXT(buffer) |
|
149 } |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CNppPsySettingHandler::MovePsyLast |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 void CNppPsySettingHandler::MovePsyLast( TUid aPsy ) |
|
157 { |
|
158 if ( !iListFrozen ) |
|
159 { |
|
160 TInt index = iPsyList.Find( aPsy ); |
|
161 if ( index != KErrNotFound ) |
|
162 { |
|
163 iPsyList.Remove( index ); |
|
164 if ( iPsyList.Append( aPsy ) == KErrNone ) |
|
165 { |
|
166 WriteSetting(); |
|
167 } |
|
168 } |
|
169 } |
|
170 |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CNppPsySettingHandler::RemovePsy |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 void CNppPsySettingHandler::RemovePsy( TUid aPsy ) |
|
178 { |
|
179 TInt index = iPsyList.Find( aPsy ); |
|
180 if ( index != KErrNotFound ) |
|
181 { |
|
182 iPsyList.Remove( index ); |
|
183 WriteSetting(); |
|
184 } |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // CNppPsySettingHandler::RunL |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 void CNppPsySettingHandler::RunL() |
|
192 { |
|
193 ParseSettingL( iListFrozen, iPsyList ); |
|
194 |
|
195 //Check if the list is empty |
|
196 iStatusHandler.SetPsyListStatus( iPsyList.Count() != 0 ); |
|
197 |
|
198 //issue another request |
|
199 iRepository->NotifyRequest( KNppPsyPsyList, iStatus ); |
|
200 SetActive(); |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CNppPsySettingHandler::DoCancel |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 void CNppPsySettingHandler::DoCancel() |
|
208 { |
|
209 if ( iRepository ) |
|
210 { |
|
211 iRepository->NotifyCancelAll(); //error ignored |
|
212 } |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CNppPsySettingHandler::RunError |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 TInt CNppPsySettingHandler::RunError( TInt aError ) |
|
220 { |
|
221 //This function may be called when PSY list is corrupted |
|
222 if ( aError != KErrNoMemory && aError != KErrCancel ) |
|
223 { |
|
224 iStatusHandler.SetPsyListStatus( EFalse ); |
|
225 } |
|
226 |
|
227 //issue another request |
|
228 iRepository->NotifyRequest( KNppPsyPsyList, iStatus ); |
|
229 SetActive(); |
|
230 |
|
231 return KErrNone; |
|
232 } |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // CNppPsySettingHandler::ParseSettingL |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 void CNppPsySettingHandler::ParseSettingL( |
|
239 TInt& aListFrozen, |
|
240 RArray < TUid >& aPsyList ) |
|
241 { |
|
242 TBuf < KNppPsyPsyListMaxLength > setting; |
|
243 User::LeaveIfError( iRepository->Get( KNppPsyPsyList, setting ) ); |
|
244 |
|
245 TRACESTRING("PSY List from CenRep...") |
|
246 TRACETEXT(setting) |
|
247 //Reset list |
|
248 aPsyList.Reset(); |
|
249 |
|
250 TLex lex( setting ); |
|
251 lex.SkipSpace(); |
|
252 TInt frozen; |
|
253 User::LeaveIfError( lex.Val( frozen ) ); //frozen status |
|
254 aListFrozen = frozen; |
|
255 |
|
256 lex.SkipSpace(); |
|
257 TUint32 psyUid; |
|
258 while ( !lex.Eos() ) |
|
259 { |
|
260 User::LeaveIfError( lex.Val( psyUid, EHex ) ); |
|
261 User::LeaveIfError( aPsyList.Append( TUid::Uid( psyUid ) ) ); |
|
262 lex.SkipSpace(); |
|
263 } |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // CNppPsySettingHandler::ValidateRomKeyValueL |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 void CNppPsySettingHandler::ValidateRomKeyValueL() |
|
271 { |
|
272 TInt romListFrozen; |
|
273 RArray < TUid > romPsyList; |
|
274 CleanupClosePushL(romPsyList); |
|
275 |
|
276 TBuf < KNppPsyPsyListMaxLength > setting; |
|
277 User::LeaveIfError( iRepository->Get( KNppPsyPsyList, setting ) ); |
|
278 setting.TrimRight(); |
|
279 setting.Append(KNppPsySpaceCharacter); |
|
280 User::LeaveIfError(iRepository->Set( KNppPsyPsyList,setting )); |
|
281 |
|
282 iRepository->Reset( KNppPsyPsyList ); |
|
283 ParseSettingL( romListFrozen, romPsyList ); |
|
284 |
|
285 RemoveDuplicatePsyUid(iPsyList,romPsyList); |
|
286 iListFrozen = romListFrozen; |
|
287 |
|
288 CleanupStack::PopAndDestroy(&romPsyList); |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // CNppPsySettingHandler::WriteSetting |
|
293 // ----------------------------------------------------------------------------- |
|
294 // |
|
295 void CNppPsySettingHandler::WriteSetting() |
|
296 { |
|
297 TBuf < KNppPsyPsyListMaxLength > setting; |
|
298 |
|
299 //Frozen status |
|
300 setting.AppendNum( iListFrozen ); |
|
301 setting.Append( KNppPsySettingSeperator ); |
|
302 |
|
303 TInt count = iPsyList.Count(); |
|
304 for ( TInt i = 0; i < count; i++ ) |
|
305 { |
|
306 setting.AppendNumFixedWidth( iPsyList[i].iUid, EHex, KNppPsyPsyUidWidth ); |
|
307 setting.Append( KNppPsySettingSeperator ); |
|
308 } |
|
309 |
|
310 TRACESTRING("Writing PSY List...") |
|
311 TRACETEXT(setting) |
|
312 |
|
313 iRepository->Set( KNppPsyPsyList, setting ); //error ignored |
|
314 } |
|
315 |
|
316 // ----------------------------------------------------------------------------- |
|
317 // CNppPsySettingHandler::RemoveDuplicatePsyUid |
|
318 // ----------------------------------------------------------------------------- |
|
319 // |
|
320 void CNppPsySettingHandler::RemoveDuplicatePsyUid( |
|
321 RArray < TUid >& aToPsyList , |
|
322 RArray < TUid >& aFromPsyList ) |
|
323 { |
|
324 |
|
325 TInt count = aFromPsyList.Count(); |
|
326 for ( TInt i = 0; i < count; i++ ) |
|
327 { |
|
328 TInt index = aToPsyList.Find( aFromPsyList[i] ); |
|
329 if ( index == KErrNotFound ) |
|
330 { |
|
331 aToPsyList.Append( aFromPsyList[i] ); |
|
332 } |
|
333 } |
|
334 WriteSetting(); |
|
335 } |
|
336 |
|
337 // End of File |