1 /* |
|
2 * Copyright (c) 2002 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: Helps retrieving request related information |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 //#include <eikenv.h> |
|
21 #include <StringLoader.h> |
|
22 #include <locverifierdlg.rsg> |
|
23 #include <aknmessagequerydialog.h> |
|
24 #include <epos_csuplsettingsconstants.h> |
|
25 #include <e32math.h> |
|
26 #include <badesca.h> |
|
27 #include <aknconsts.h> |
|
28 #include "lpdperiodicprocessor.h" |
|
29 #include "locverifierdlgdebug.h" |
|
30 #include "lpdverifiersettinglauncher.h" |
|
31 #include "lpdsuplsettingsadapter.h" |
|
32 |
|
33 |
|
34 // CONSTANTS |
|
35 const TInt KRequestorNameSize = 256; |
|
36 const TInt KMinToSecs = 60; |
|
37 const TInt KHrToSecs = 3600; |
|
38 const TInt KdayToSecs = 86400; |
|
39 const TInt KRealWidth = 50; |
|
40 _LIT( KNewLineEntry, "\n" ); |
|
41 |
|
42 |
|
43 // Unnamed namespace for local definitions |
|
44 |
|
45 #ifdef _DEBUG |
|
46 _LIT( KPanicText, "CLpdPeriodicProcessor" ); |
|
47 enum TPanicCode |
|
48 { |
|
49 KLpdErrGeneral = 1 |
|
50 }; |
|
51 #endif |
|
52 |
|
53 // LinkClickedL |
|
54 // (other items were commented in a header). |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 static TInt LinkClickedL(TAny* aPtr) |
|
58 { |
|
59 CLpdPeriodicProcessor* self = static_cast<CLpdPeriodicProcessor*>(aPtr); |
|
60 self->LaunchSettingsL(); |
|
61 return ETrue; |
|
62 } |
|
63 |
|
64 |
|
65 // ============================ MEMBER FUNCTIONS =============================== |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CLpdPeriodicProcessor::CLpdPeriodicProcessor |
|
69 // C++ default constructor can NOT contain any code, that |
|
70 // might leave. |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 CLpdPeriodicProcessor::CLpdPeriodicProcessor( MLpdPeriodicRequestObserver& aObserver ) |
|
74 : iObserver(aObserver), iMessageText( NULL ), iRequestorName( NULL ), iSessionId(-1), iRequestorId(-1) |
|
75 { |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CLpdPeriodicProcessor::NewL |
|
80 // Two-phased constructor. |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 CLpdPeriodicProcessor* CLpdPeriodicProcessor::NewL( MLpdPeriodicRequestObserver& aObserver ) |
|
84 { |
|
85 CLpdPeriodicProcessor* self = CLpdPeriodicProcessor::NewLC( aObserver ); |
|
86 CleanupStack::Pop(); |
|
87 return self; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CLpdPeriodicProcessor::NewL |
|
92 // Two-phased constructor. |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 CLpdPeriodicProcessor* CLpdPeriodicProcessor::NewLC( MLpdPeriodicRequestObserver& aObserver) |
|
96 { |
|
97 CLpdPeriodicProcessor* self = new( ELeave ) CLpdPeriodicProcessor ( aObserver ); |
|
98 CleanupStack::PushL( self ); |
|
99 self->ConstructL(); |
|
100 return self; |
|
101 } |
|
102 |
|
103 // Destructor |
|
104 CLpdPeriodicProcessor::~CLpdPeriodicProcessor() |
|
105 { |
|
106 delete iRequestor; |
|
107 delete iSUPLSettingsAdapter; |
|
108 delete iVerifierSettingsLauncher; |
|
109 delete iMessageText; |
|
110 delete iRequestorName; |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CLpdPeriodicProcessor::ConstructL |
|
115 // (other items were commented in a header). |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CLpdPeriodicProcessor::ConstructL() |
|
119 { |
|
120 iSUPLSettingsAdapter = CLpdSUPLSettingsAdapter::NewL(*this); |
|
121 iVerifierSettingsLauncher = CLpdVerifierSettingsLauncher::NewL(); |
|
122 iRequestorName = HBufC::NewL( KRequestorNameSize ); |
|
123 iEikEnv = CEikonEnv::Static(); |
|
124 |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CLpdPeriodicProcessor::LaunchSettingsL |
|
129 // (other items were commented in a header). |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 void CLpdPeriodicProcessor::LaunchSettingsL( ) |
|
133 { |
|
134 if( iVerifierSettingsLauncher ) |
|
135 { |
|
136 iVerifierSettingsLauncher->LaunchL( iSessionId ); |
|
137 } |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CLpdPeriodicProcessor::GetSessionId |
|
142 // (other items were commented in a header). |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 TInt64 CLpdPeriodicProcessor::GetSessionId( ) |
|
146 { |
|
147 return iSessionId; |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CLpdPeriodicRequestProcessor::SetRequestorId |
|
152 // (other items were commented in a header). |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 void CLpdPeriodicProcessor::SetRequestorIdL( TInt32 aRequestorId ) |
|
156 { |
|
157 __ASSERT_DEBUG( aRequestorId != KPosNullQNRequestId, |
|
158 HandleAssertErrorL() ); |
|
159 |
|
160 iRequestorId = aRequestorId; |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CLpdPeriodicProcessor::SetSessionId |
|
165 // (other items were commented in a header). |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void CLpdPeriodicProcessor::SetSessionIdL( TInt64 aSessionId ) |
|
169 { |
|
170 __ASSERT_DEBUG( iRequestorId != KPosNullQNRequestId, |
|
171 HandleAssertErrorL() ); |
|
172 |
|
173 iSessionId = aSessionId; |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CLpdPeriodicProcessor::SetRequestorIdL |
|
178 // (other items were commented in a header). |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 void CLpdPeriodicProcessor::SetRequestorNameL( HBufC* aRequestorName) |
|
182 { |
|
183 __ASSERT_DEBUG( iRequestorId != KPosNullQNRequestId, |
|
184 HandleAssertErrorL() ); |
|
185 iRequestorName->Des().Copy( aRequestorName->Des() ); |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CLpdPeriodicProcessor::SetRequestTypeL |
|
190 // (other items were commented in a header). |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 void CLpdPeriodicProcessor::SetRequestTypeL( |
|
194 CPosPrivacyNotifier::TRequestType aRequestType ) |
|
195 { |
|
196 __ASSERT_DEBUG( iRequestorId != KPosNullQNRequestId, |
|
197 HandleAssertErrorL() ); |
|
198 iRequestType = aRequestType; |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CLpdPeriodicProcessor::SetRequestorL |
|
203 // (other items were commented in a header). |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 void CLpdPeriodicProcessor::SetRequestorL( CPosRequestor* aRequestor ) |
|
207 { |
|
208 __ASSERT_DEBUG( iRequestorId != KPosNullQNRequestId, |
|
209 HandleAssertErrorL() ); |
|
210 if( iRequestor ) |
|
211 { |
|
212 delete iRequestor; |
|
213 iRequestor = NULL; |
|
214 } |
|
215 |
|
216 iRequestor = aRequestor; |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CLpdPeriodicProcessor::ResetParameters |
|
221 // (other items were commented in a header). |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 void CLpdPeriodicProcessor::ResetParameters() |
|
225 { |
|
226 iRequestorId = -1; |
|
227 iSessionId = -1; |
|
228 if( iRequestor ) |
|
229 { |
|
230 delete iRequestor; |
|
231 iRequestor = NULL; |
|
232 } |
|
233 |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CLpdPeriodicProcessor::NotificationMessageText |
|
238 // Used to prepare notification message text |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 |
|
242 void CLpdPeriodicProcessor::NotificationMessageTextL( HBufC*& aMessageText) |
|
243 { |
|
244 __ASSERT_DEBUG( iRequestorId != KPosNullQNRequestId, |
|
245 HandleAssertErrorL() ); |
|
246 TUint aTimePeriod; |
|
247 |
|
248 TRAPD( ret, iSUPLSettingsAdapter->GetTriggerPeriodL( iSessionId, aTimePeriod)); |
|
249 |
|
250 if(ret != KErrNone) |
|
251 { |
|
252 User::Leave(ret); |
|
253 } |
|
254 |
|
255 if( iMessageText ) |
|
256 { |
|
257 delete iMessageText; |
|
258 iMessageText = NULL; |
|
259 } |
|
260 |
|
261 TInt resourceId; |
|
262 TBuf<KRealWidth> periodString; |
|
263 HBufC* msgText = NULL; |
|
264 |
|
265 GetResourceAndPeriodL( aTimePeriod, resourceId, periodString ); |
|
266 |
|
267 GetMessageStringL(msgText, resourceId, *iRequestorName, periodString ); |
|
268 |
|
269 if( msgText ) |
|
270 { |
|
271 CleanupStack::PushL( msgText ); |
|
272 HBufC* linkText = NULL; |
|
273 linkText = StringLoader::LoadL( R_LOC_NOTIFICATION_SERVICE_LINK, iEikEnv ); |
|
274 CleanupStack::PushL( linkText ); |
|
275 iMessageText = HBufC::NewL( msgText->Length() + KNewLineEntry().Length() + KOpeningLinkTag().Length() + |
|
276 linkText->Length() + KClosingLinkTag().Length() ); |
|
277 iMessageText->Des().Copy( *msgText ); |
|
278 iMessageText->Des().Append( KNewLineEntry ); |
|
279 iMessageText->Des().Append( KOpeningLinkTag ); |
|
280 iMessageText->Des().Append( *linkText ); |
|
281 iMessageText->Des().Append( KClosingLinkTag ); |
|
282 |
|
283 CleanupStack::PopAndDestroy( ); //msgText |
|
284 CleanupStack::PopAndDestroy( ); //linkText |
|
285 //delete msgText; |
|
286 //delete linkText; |
|
287 } |
|
288 else |
|
289 { |
|
290 iMessageText = HBufC::NewL( KMaxTriggerSessionNameLen ); |
|
291 } |
|
292 |
|
293 aMessageText->Des().Copy(iMessageText->Des()); |
|
294 } |
|
295 |
|
296 // ----------------------------------------------------------------------------- |
|
297 // CLpdPeriodicProcessor::LinkCallBack |
|
298 // (other items were commented in a header). |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 TCallBack CLpdPeriodicProcessor::LinkCallBack() |
|
302 { |
|
303 return TCallBack(LinkClickedL, this); |
|
304 } |
|
305 |
|
306 // ----------------------------------------------------------------------------- |
|
307 // CLpdPeriodicRequestProcessor::UpdateSessionL |
|
308 // (other items were commented in a header). |
|
309 // ----------------------------------------------------------------------------- |
|
310 // |
|
311 void CLpdPeriodicProcessor::UpdateSessionL( TInt64 aSessionId ) |
|
312 { |
|
313 if( iSessionId == aSessionId && |
|
314 iRequestType == CPosPrivacyNotifier::ENotification && iRequestor |
|
315 && CPosRequestor::ERequestPeriodic == iRequestor->RequestType()) |
|
316 { |
|
317 iObserver.UpdateCurrentNotifierL(); |
|
318 } |
|
319 } |
|
320 |
|
321 // ----------------------------------------------------------------------------- |
|
322 // CLpdPeriodicProcessor::GetMessageStringL |
|
323 // (other items were commented in a header). |
|
324 // ----------------------------------------------------------------------------- |
|
325 // |
|
326 void CLpdPeriodicProcessor::GetMessageStringL( HBufC*& aMessageString, |
|
327 TInt& aResourceId, TDesC& aNameString, TDesC& aPeriodString ) |
|
328 { |
|
329 |
|
330 switch( aResourceId ) |
|
331 { |
|
332 case R_LOC_NOTIFICATION_ONEHOUR: |
|
333 { |
|
334 aMessageString = StringLoader::LoadL( R_LOC_NOTIFICATION_ONEDAY, aNameString, iEikEnv ); |
|
335 break; |
|
336 } |
|
337 case R_LOC_NOTIFICATION_ONEDAY: |
|
338 { |
|
339 aMessageString = StringLoader::LoadL( R_LOC_NOTIFICATION_ONEDAY, aNameString, iEikEnv ); |
|
340 break; |
|
341 } |
|
342 case R_LOC_NOTIFICATION_MINUTES: |
|
343 case R_LOC_NOTIFICATION_HOURS: |
|
344 case R_LOC_NOTIFICATION_DAYS: |
|
345 default: |
|
346 { |
|
347 CDesCArrayFlat* strings = new CDesCArrayFlat( 2 ); |
|
348 CleanupStack::PushL( strings ); |
|
349 |
|
350 strings->AppendL( aNameString ); // aNameString string |
|
351 strings->AppendL( aPeriodString ); // aPeriodString string |
|
352 |
|
353 aMessageString = StringLoader::LoadL(aResourceId, *strings, iEikEnv ); |
|
354 |
|
355 CleanupStack::PopAndDestroy( ); // strings |
|
356 break; |
|
357 } |
|
358 } |
|
359 } |
|
360 |
|
361 // ----------------------------------------------------------------------------- |
|
362 // CLpdPeriodicProcessor::GetResourceAndPeriodL |
|
363 // (other items were commented in a header). |
|
364 // ----------------------------------------------------------------------------- |
|
365 // |
|
366 void CLpdPeriodicProcessor::GetResourceAndPeriodL( TUint aSeconds, |
|
367 TInt& aResourceId, TDes& aPeriodString ) |
|
368 { |
|
369 TRealFormat fmt(KDefaultRealWidth, 2); |
|
370 |
|
371 if( !aSeconds ) |
|
372 { |
|
373 aResourceId = R_LOC_NOTIFICATION_MINUTES; |
|
374 aPeriodString.Num(aSeconds); |
|
375 return; |
|
376 } |
|
377 |
|
378 TReal hrs = TReal(aSeconds)/KHrToSecs; |
|
379 TReal value; |
|
380 if( hrs < 1 ) |
|
381 { |
|
382 TReal mins = TReal(aSeconds)/KMinToSecs; |
|
383 aResourceId = R_LOC_NOTIFICATION_MINUTES; |
|
384 Math::Round( value, mins, 2 ); |
|
385 aPeriodString.Num(value, fmt); |
|
386 } |
|
387 else if( hrs == 1 ) |
|
388 { |
|
389 aResourceId = R_LOC_NOTIFICATION_ONEHOUR; |
|
390 } |
|
391 else |
|
392 { |
|
393 TReal days = TReal(aSeconds)/KdayToSecs; |
|
394 if( days < 1 ) |
|
395 { |
|
396 aResourceId = R_LOC_NOTIFICATION_HOURS; |
|
397 Math::Round( value, hrs, 2 ); |
|
398 aPeriodString.Num(value, fmt); |
|
399 } |
|
400 else if( days == 1 ) |
|
401 { |
|
402 aResourceId = R_LOC_NOTIFICATION_ONEDAY; |
|
403 } |
|
404 else |
|
405 { |
|
406 aResourceId = R_LOC_NOTIFICATION_DAYS; |
|
407 Math::Round( value, days, 2 ); |
|
408 aPeriodString.Num(value, fmt); |
|
409 } |
|
410 } |
|
411 } |
|
412 |
|
413 // ----------------------------------------------------------------------------- |
|
414 // CLpdPeriodicProcessor::HandleAssertErrorL |
|
415 // (other items were commented in a header). |
|
416 // ----------------------------------------------------------------------------- |
|
417 // |
|
418 void CLpdPeriodicProcessor::HandleAssertErrorL() const |
|
419 { |
|
420 #ifdef _DEBUG |
|
421 User::Panic( KPanicText, KLpdErrGeneral ); |
|
422 #else |
|
423 User::Leave( KErrCorrupt ); |
|
424 #endif |
|
425 } |
|
426 // end of file |
|