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: Location Triggering Management Plugin Engine |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System Include |
|
20 #include <e32keys.h> // Tab Keys |
|
21 #include <StringLoader.h> // String Loader |
|
22 #include <lbtmgmtpluginview.rsg> |
|
23 #include <aknradiobuttonsettingpage.h> |
|
24 #include <aknslidersettingpage.h> |
|
25 #include <aknmessagequerydialog.h> |
|
26 |
|
27 |
|
28 // User Include |
|
29 #include "lbtmgmtpluginengine.h" |
|
30 #include "lbtmgmtengobserver.h" |
|
31 #include "lbtmgmtlbtadapter.h" |
|
32 #include "lbtmgmtdebug.h" |
|
33 |
|
34 // Constant Defintions |
|
35 const TInt KNumberofSettingsItems = 2; |
|
36 const TInt KMaxConversionBufferLength = 0x200; |
|
37 const TInt KNoofTriggerStatus = 2; |
|
38 |
|
39 // ========================= MEMBER FUNCTIONS ================================ |
|
40 |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // CLbtMgmtPluginEngine::CLbtMgmtPluginEngine |
|
44 // Overloaded Constructor |
|
45 // |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CLbtMgmtPluginEngine::CLbtMgmtPluginEngine( |
|
49 MLbtMgmtEngObserver& aEngineObserver ) |
|
50 :iObserver( aEngineObserver ), |
|
51 iSettingsDialogOutstanding( EFalse ) |
|
52 { |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // CLbtMgmtPluginEngine::~CLbtMgmtPluginEngine |
|
57 // Destructor |
|
58 // |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CLbtMgmtPluginEngine::~CLbtMgmtPluginEngine() |
|
62 { |
|
63 // Delete the list box strings |
|
64 delete iTriggeringTitle; |
|
65 |
|
66 delete iActiveTitle; |
|
67 |
|
68 delete iNoActiveTitle; |
|
69 |
|
70 delete iInfoMessage; |
|
71 |
|
72 delete iOnSettings; |
|
73 |
|
74 delete iOffSettings; |
|
75 |
|
76 delete iConversionBuffer; |
|
77 |
|
78 // Delete the Lbt settings handle |
|
79 delete iLbtAdapter; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CLbtMgmtPluginEngine* CLbtMgmtPluginEngine::NewL |
|
84 // Creates new Location Trigger Management plug-in engine instance. |
|
85 // |
|
86 // @param aEngineObserver Observer to the Trigger Management engine |
|
87 // @return CLbtMgmtPluginEngine* Reference to the application view |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 CLbtMgmtPluginEngine* CLbtMgmtPluginEngine::NewL( |
|
91 MLbtMgmtEngObserver& aEngineObserver ) |
|
92 { |
|
93 CLbtMgmtPluginEngine* self = |
|
94 CLbtMgmtPluginEngine::NewLC( aEngineObserver ); |
|
95 CleanupStack::Pop( self ); |
|
96 return self; |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // CLbtMgmtPluginEngine* CLbtMgmtPluginEngine::NewLC |
|
101 // Creates new Location Trigger Management plug-in engine instance. Leaves |
|
102 // the object on the Cleanup stack |
|
103 // |
|
104 // @param aEngineObserver Observer to the Trigger Management engine |
|
105 // @return CLbtMgmtPluginEngine* Reference to the application view |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 CLbtMgmtPluginEngine* CLbtMgmtPluginEngine::NewLC( |
|
109 MLbtMgmtEngObserver& aEngineObserver ) |
|
110 { |
|
111 CLbtMgmtPluginEngine* self = |
|
112 new(ELeave) CLbtMgmtPluginEngine( aEngineObserver ); |
|
113 CleanupStack::PushL( self ); |
|
114 self->ConstructL(); |
|
115 return self; |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // void CLbtMgmtPluginEngine::ConstructL |
|
120 // Second Phase Constructor |
|
121 // |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 void CLbtMgmtPluginEngine::ConstructL() |
|
125 { |
|
126 // Create Lbt Adapter handle |
|
127 iLbtAdapter = CLbtMgmtLbtAdapter::NewL( *this ); |
|
128 |
|
129 // Load the list box strings |
|
130 // Allocate and set the System of measurement heading |
|
131 iTriggeringTitle = StringLoader::LoadL( R_LOCTR_LIST_LBT_TRIGGERING ); |
|
132 |
|
133 // Allocate and set the server ip address title field |
|
134 iActiveTitle = StringLoader::LoadL( R_LOCTR_LIST_ACTIVE_TRIGGER ); |
|
135 |
|
136 // Allocate and set the server ip address title field |
|
137 iNoActiveTitle = StringLoader::LoadL( R_LOCTR_LIST_NO_ACTIVE_TRIGGER ); |
|
138 |
|
139 //Allocate and set the Info message text |
|
140 iInfoMessage = StringLoader::LoadL( R_LOCTR_INFO_POPUP_TEXT ); |
|
141 |
|
142 // Allocate and set the Imperial settings text |
|
143 iOnSettings = StringLoader::LoadL( R_LOCTR_LIST_VALUE_TRIGGER_ON ); |
|
144 |
|
145 // Allocate and set the Metric settings text |
|
146 iOffSettings = StringLoader::LoadL( R_LOCTR_LIST_VALUE_TRIGGER_OFF ); |
|
147 |
|
148 // Allocate the Conversion Buffer |
|
149 iConversionBuffer = HBufC16::NewL( KMaxConversionBufferLength ); |
|
150 } |
|
151 |
|
152 // --------------------------------------------------------------------------- |
|
153 // TInt CLbtMgmtPluginEngine::MdcaCount |
|
154 // Inherited from MDesCArray |
|
155 // |
|
156 // --------------------------------------------------------------------------- |
|
157 // |
|
158 TInt CLbtMgmtPluginEngine::MdcaCount() const |
|
159 { |
|
160 return KNumberofSettingsItems; |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // TInt CLbtMgmtPluginEngine::MdcaPoint |
|
165 // Inherited from MDesCArray |
|
166 // |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 TPtrC16 CLbtMgmtPluginEngine::MdcaPoint( TInt aIndex ) const |
|
170 { |
|
171 // Zero the internal buffer |
|
172 TPtr16 ptr( iConversionBuffer->Des()); |
|
173 ptr.Zero(); |
|
174 |
|
175 // Format "\t%S\t\t%S" |
|
176 |
|
177 // Append the first tab |
|
178 ptr.Append( EKeyTab ); |
|
179 |
|
180 switch( aIndex ) |
|
181 { |
|
182 case ETriggeringStatus: |
|
183 { |
|
184 // Append the Title text |
|
185 ptr.Append( iTriggeringTitle->Des() ); |
|
186 |
|
187 // Append the second tab |
|
188 ptr.Append( EKeyTab ); |
|
189 |
|
190 // Append the third tab |
|
191 ptr.Append( EKeyTab ); |
|
192 |
|
193 // Obtain the current value of system of measurement and append |
|
194 // to the buffer |
|
195 CLbtMgmtLbtAdapter::TTriggeringStatus state = CLbtMgmtLbtAdapter::EOn; |
|
196 TRAPD( err, state = iLbtAdapter->GetCurrentTriggeringStatusL() ); |
|
197 if( !err && state == CLbtMgmtLbtAdapter::EOn ) |
|
198 { |
|
199 ptr.Append( iOnSettings->Des() ); |
|
200 } |
|
201 else if ( state == CLbtMgmtLbtAdapter::EOff ) |
|
202 { |
|
203 ptr.Append( iOffSettings->Des()); |
|
204 } |
|
205 break; |
|
206 } |
|
207 case EActiveTriggers: |
|
208 { |
|
209 // Append the Title text |
|
210 //XXX: Optimization::should be called when there is a change in lbt database |
|
211 TInt activeTriggers = iLbtAdapter->ActiveTriggers(); |
|
212 |
|
213 if( activeTriggers == 0 ) |
|
214 ptr.Append( iNoActiveTitle->Des() ); |
|
215 else |
|
216 { |
|
217 HBufC* activeTriggersString = NULL; |
|
218 if( activeTriggers == 1 ) |
|
219 { |
|
220 TRAP_IGNORE( activeTriggersString = StringLoader::LoadL( R_LOCTR_ONE_ACTIVE_TRIGGER ) ); |
|
221 } |
|
222 else |
|
223 { |
|
224 TRAP_IGNORE( activeTriggersString = StringLoader::LoadL( R_LOCTR_LIST_ACTIVE_TRIGGER, activeTriggers ) ); |
|
225 } |
|
226 if( activeTriggersString ) |
|
227 { |
|
228 ptr.Append( activeTriggersString->Des() ); |
|
229 delete activeTriggersString; |
|
230 } |
|
231 } |
|
232 |
|
233 // Append the second tab |
|
234 ptr.Append( EKeyTab ); |
|
235 |
|
236 // Append the third tab |
|
237 ptr.Append( EKeyTab ); |
|
238 |
|
239 break; |
|
240 } |
|
241 default: |
|
242 { |
|
243 // Append the second tab |
|
244 ptr.Append( EKeyTab ); |
|
245 // Append the third tab |
|
246 ptr.Append( EKeyTab ); |
|
247 break; |
|
248 } |
|
249 } |
|
250 return iConversionBuffer->Des(); |
|
251 } |
|
252 |
|
253 // --------------------------------------------------------------------------- |
|
254 // void CLbtMgmtPluginEngine::HandleSettingsChangeL |
|
255 // Inherited from MLocNotPrefAdapterObserver |
|
256 // |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 void CLbtMgmtPluginEngine::HandleSettingsChangeL() |
|
260 { |
|
261 iObserver.HandleSettingsChangeEventL(); |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------------------------- |
|
265 // void CLbtMgmtPluginEngine::Close |
|
266 // Closes the running Settings UI prematurely. This would result in dismissing |
|
267 // any active dialogs currently running |
|
268 // |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 void CLbtMgmtPluginEngine::Close() |
|
272 { |
|
273 // If any of the dialogs are active then issue a cancel event on the |
|
274 // dialogs |
|
275 if( iSettingsDialogOutstanding ) |
|
276 { |
|
277 TKeyEvent keyEvent; |
|
278 keyEvent.iCode = EKeyCBA2; |
|
279 keyEvent.iScanCode = EStdKeyDevice1; |
|
280 keyEvent.iModifiers = EAllModifiers; |
|
281 keyEvent.iRepeats = 0; |
|
282 CCoeEnv* cCoeEnv = CCoeEnv::Static(); |
|
283 |
|
284 // Simulate a Cancel event on the running dialogs. The Simulated event |
|
285 // is for the Left Soft Key. |
|
286 // Ignore the error incase of a leave |
|
287 |
|
288 TRAP_IGNORE( cCoeEnv->SimulateKeyEventL( keyEvent, EEventKey ) ); |
|
289 } |
|
290 iSettingsDialogOutstanding = EFalse; |
|
291 } |
|
292 |
|
293 // --------------------------------------------------------------------------- |
|
294 // void CLbtMgmtPluginEngine::ChangeTiggerStatusL |
|
295 // Change Trigger settings |
|
296 // |
|
297 // --------------------------------------------------------------------------- |
|
298 // |
|
299 void CLbtMgmtPluginEngine::ChangeTiggerStatusL() |
|
300 { |
|
301 LBTMGMTUIDEBUG("+ CLbtMgmtPluginEngine::ChangeTiggerStatusL()"); |
|
302 if( iSettingsDialogOutstanding ) |
|
303 { |
|
304 User::Leave( KErrInUse ); |
|
305 } |
|
306 // Allocate the descriptor array for Text settings for System |
|
307 // of measurement |
|
308 CDesCArrayFlat* items = new( ELeave ) CDesCArrayFlat( KNoofTriggerStatus ); |
|
309 CleanupStack::PushL( items ); |
|
310 |
|
311 // Append the radio-button list items |
|
312 items->AppendL( iOnSettings->Des()); |
|
313 items->AppendL( iOffSettings->Des()); |
|
314 |
|
315 |
|
316 // Obtain the current value for current system of measurement |
|
317 // This would be used for setting the default value for |
|
318 // the text settings page |
|
319 |
|
320 TInt currentSettings = iLbtAdapter->GetCurrentTriggeringStatusL(); |
|
321 TInt prevSettings = currentSettings; |
|
322 |
|
323 CAknRadioButtonSettingPage* dlg = |
|
324 new ( ELeave )CAknRadioButtonSettingPage( R_LOCTR_LIST_LBT_TRIGGERING_SETTING, |
|
325 currentSettings, |
|
326 items ); |
|
327 // Settings Outstanding flag is marked True to enable dismissal incase |
|
328 // of a Cancel event |
|
329 iSettingsDialogOutstanding = ETrue; |
|
330 if ( dlg->ExecuteLD( CAknSettingPage::EUpdateWhenChanged )) |
|
331 { |
|
332 if(prevSettings != currentSettings) |
|
333 { |
|
334 switch(currentSettings) |
|
335 { |
|
336 case CLbtMgmtLbtAdapter::EOff: //Off |
|
337 { |
|
338 //Confirmation is required if any active trigger exists |
|
339 if( 0 != ActiveTriggers() ) |
|
340 { |
|
341 HBufC* msg = StringLoader::LoadLC( R_LOCTR_NOTE_TURNOFF ); |
|
342 CAknQueryDialog* confirmationQuery = CAknQueryDialog::NewL(); |
|
343 if(confirmationQuery->ExecuteLD(R_LOCTR_CONFIRMATION_QUERY, *msg)) |
|
344 { |
|
345 iLbtAdapter->SetCurrentTriggeringStatusL( CLbtMgmtLbtAdapter::EOff ); |
|
346 } |
|
347 CleanupStack::PopAndDestroy(msg); |
|
348 } |
|
349 else |
|
350 { |
|
351 iLbtAdapter->SetCurrentTriggeringStatusL( CLbtMgmtLbtAdapter::EOff ); |
|
352 } |
|
353 } |
|
354 break; |
|
355 case CLbtMgmtLbtAdapter::EOn: //On |
|
356 { |
|
357 //No Warning note is required. |
|
358 iLbtAdapter->SetCurrentTriggeringStatusL( CLbtMgmtLbtAdapter::EOn ); |
|
359 } |
|
360 break; |
|
361 default: |
|
362 break; |
|
363 } |
|
364 } |
|
365 } |
|
366 iSettingsDialogOutstanding = EFalse; |
|
367 // Free the items resource |
|
368 CleanupStack::PopAndDestroy( items ); |
|
369 |
|
370 LBTMGMTUIDEBUG("- CLbtMgmtPluginEngine::ChangeTiggerStatusL()"); |
|
371 } |
|
372 |
|
373 // --------------------------------------------------------------------------- |
|
374 // void CLbtMgmtPluginEngine::ToggleTiggerStatusL |
|
375 // Toggle Trigger settings |
|
376 // |
|
377 // --------------------------------------------------------------------------- |
|
378 // |
|
379 void CLbtMgmtPluginEngine::ToggleTiggerStatusL() |
|
380 { |
|
381 LBTMGMTUIDEBUG("+ CLbtMgmtPluginEngine::ToggleTiggerStatusL()"); |
|
382 if( iSettingsDialogOutstanding ) |
|
383 { |
|
384 User::Leave( KErrInUse ); |
|
385 } |
|
386 CLbtMgmtLbtAdapter::TTriggeringStatus status = iLbtAdapter->GetCurrentTriggeringStatusL(); |
|
387 |
|
388 if( CLbtMgmtLbtAdapter::EOn == status ) |
|
389 { |
|
390 //Confirmation is required if any active trigger exists |
|
391 if( 0 != ActiveTriggers() ) |
|
392 { |
|
393 HBufC* msg = StringLoader::LoadLC( R_LOCTR_NOTE_TURNOFF ); |
|
394 CAknQueryDialog* confirmationQuery = CAknQueryDialog::NewL(); |
|
395 if(confirmationQuery->ExecuteLD(R_LOCTR_CONFIRMATION_QUERY, *msg)) |
|
396 { |
|
397 iLbtAdapter->SetCurrentTriggeringStatusL( CLbtMgmtLbtAdapter::EOff ); |
|
398 } |
|
399 CleanupStack::PopAndDestroy(msg); |
|
400 } |
|
401 else |
|
402 { |
|
403 //No Warning note is required. |
|
404 iLbtAdapter->SetCurrentTriggeringStatusL( CLbtMgmtLbtAdapter::EOff ); |
|
405 } |
|
406 } |
|
407 else |
|
408 { |
|
409 iLbtAdapter->SetCurrentTriggeringStatusL( CLbtMgmtLbtAdapter::EOn ); |
|
410 } |
|
411 LBTMGMTUIDEBUG("- CLbtMgmtPluginEngine::ToggleTiggerStatusL()"); |
|
412 } |
|
413 |
|
414 |
|
415 // --------------------------------------------------------------------------- |
|
416 // void CLbtMgmtPluginEngine::ShowInfoDialog |
|
417 // Show Info dialog for active triggers |
|
418 // --------------------------------------------------------------------------- |
|
419 // |
|
420 void CLbtMgmtPluginEngine::ShowInfoDialogL() |
|
421 { |
|
422 LBTMGMTUIDEBUG("+ CLbtMgmtPluginEngine::ShowInfoDialogL()"); |
|
423 CAknMessageQueryDialog* info = CAknMessageQueryDialog::NewL(*iInfoMessage); |
|
424 info->ExecuteLD(R_LOCTR_MESSAGE_QUERY_DIALOG); |
|
425 LBTMGMTUIDEBUG("- CLbtMgmtPluginEngine::ShowInfoDialogL()"); |
|
426 } |
|
427 |
|
428 // --------------------------------------------------------------------------- |
|
429 // void CLbtMgmtPluginEngine::ClearAllTriggersL |
|
430 // It will clear all triggers |
|
431 // --------------------------------------------------------------------------- |
|
432 // |
|
433 void CLbtMgmtPluginEngine::ClearAllTriggersL() |
|
434 { |
|
435 LBTMGMTUIDEBUG("+ CLbtMgmtPluginEngine::ClearAllTriggersL()"); |
|
436 HBufC* msg = StringLoader::LoadLC( R_LOCTR_NOTE_CLEARTRIGGERS ); |
|
437 CAknQueryDialog* confirmationQuery = CAknQueryDialog::NewL(); |
|
438 if(confirmationQuery->ExecuteLD(R_LOCTR_CONFIRMATION_QUERY, *msg)) |
|
439 { |
|
440 iLbtAdapter->DeleteActiveTriggersL(); |
|
441 } |
|
442 CleanupStack::PopAndDestroy(msg); |
|
443 LBTMGMTUIDEBUG("- CLbtMgmtPluginEngine::ClearAllTriggersL()"); |
|
444 } |
|
445 |
|
446 // --------------------------------------------------------------------------- |
|
447 // void CLbtMgmtPluginEngine::ShowInfoDialog |
|
448 // It will return total active triggers |
|
449 // --------------------------------------------------------------------------- |
|
450 // |
|
451 TInt CLbtMgmtPluginEngine::ActiveTriggers() |
|
452 { |
|
453 return iLbtAdapter->ActiveTriggers(); |
|
454 } |
|