1 /* |
|
2 * Copyright (c) 2002, 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: Bluetooth visibility timeout notifier class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include <StringLoader.h> // Localisation stringloader |
|
22 #include <SecondaryDisplay/BTnotifSecondaryDisplayAPI.h> |
|
23 #include <e32cmn.h> |
|
24 #include <BTNotif.rsg> // Own resources |
|
25 #include <btengsettings.h> |
|
26 #include <bluetoothuiutil.h> |
|
27 #include "BTNGenericQueryNotifier.h" // Own class definition |
|
28 #include "btNotifDebug.h" // Debugging macros |
|
29 #include <coreapplicationuisdomainpskeys.h> |
|
30 |
|
31 #ifdef __SERIES60_HELP |
|
32 #include <hlplch.h> |
|
33 #include <csxhelp/bt.hlp.hrh> // The bt hrh info is needed, for help launching |
|
34 #endif |
|
35 |
|
36 const TInt KBTNotifPhonePowerKeyWatcher = 30; |
|
37 |
|
38 // ================= MEMBER FUNCTIONS ======================= |
|
39 |
|
40 // ---------------------------------------------------------- |
|
41 // CBTGenericQueryNotifier::NewL |
|
42 // Two-phased constructor. |
|
43 // ---------------------------------------------------------- |
|
44 // |
|
45 CBTGenericQueryNotifier* CBTGenericQueryNotifier::NewL() |
|
46 { |
|
47 CBTGenericQueryNotifier* self=new (ELeave) CBTGenericQueryNotifier(); |
|
48 CleanupStack::PushL(self); |
|
49 self->ConstructL(); |
|
50 CleanupStack::Pop(); |
|
51 return self; |
|
52 } |
|
53 |
|
54 // ---------------------------------------------------------- |
|
55 // CBTGenericQueryNotifier::CBTGenericQueryNotifier |
|
56 // C++ default constructor can NOT contain any code, that |
|
57 // might leave. |
|
58 // ---------------------------------------------------------- |
|
59 // |
|
60 CBTGenericQueryNotifier::CBTGenericQueryNotifier() |
|
61 { |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------------- |
|
65 // Destructor |
|
66 // ---------------------------------------------------------- |
|
67 // |
|
68 CBTGenericQueryNotifier::~CBTGenericQueryNotifier() |
|
69 { |
|
70 Cancel(); // Free own resources |
|
71 delete iName; |
|
72 iQueryMessage.Close(); |
|
73 delete iQueryHeader; |
|
74 if (iPhonePowerKey.Handle()) |
|
75 { |
|
76 iPhonePowerKey.Cancel(); |
|
77 } |
|
78 delete iPhonePowerKeyWatcher; |
|
79 iPhonePowerKey.Close(); |
|
80 } |
|
81 |
|
82 // ---------------------------------------------------------- |
|
83 // CBTGenericQueryNotifier::ConstructL |
|
84 // Symbian 2nd phase constructor can leave. |
|
85 // Attach to the P&S property and create |
|
86 // ---------------------------------------------------------- |
|
87 // |
|
88 void CBTGenericQueryNotifier::ConstructL() |
|
89 { |
|
90 CBTNotifierBase::ConstructL(); |
|
91 |
|
92 /** |
|
93 * SysAp notifies Alarm UI to hide alarm when powerkey is pressed. |
|
94 * This is called from CSysApAppUi::HandleShortPowerKeyPressedL(), |
|
95 * so it seems to be a better choice than the following keys: |
|
96 * KPSUidAvkonDomain/KAknPowerMenuStatus |
|
97 * KPSUidCoreApplicationUIs/KCoreAppUIsAutolockStatus |
|
98 * KCoreAppUIsAutolockStatus would be ideal, but it comes too late. |
|
99 */ |
|
100 User::LeaveIfError(iPhonePowerKey.Attach(KPSUidCoreApplicationUIs, |
|
101 KCoreAppUIsHideAlarm)); |
|
102 iPhonePowerKeyWatcher = CBTNotifActive::NewL(this, |
|
103 KBTNotifPhonePowerKeyWatcher, CActive::EPriorityStandard); |
|
104 iPhonePowerKey.Subscribe(iPhonePowerKeyWatcher->RequestStatus()); |
|
105 iPhonePowerKeyWatcher->GoActive(); |
|
106 } |
|
107 |
|
108 // ---------------------------------------------------------- |
|
109 // CBTGenericQueryNotifier::RegisterL |
|
110 // Register notifier. |
|
111 // ---------------------------------------------------------- |
|
112 // |
|
113 CBTGenericQueryNotifier::TNotifierInfo CBTGenericQueryNotifier::RegisterL() |
|
114 { |
|
115 iInfo.iUid=KBTGenericQueryNotifierUid; |
|
116 iInfo.iChannel=KBTGenericQueryNotifierUid; |
|
117 iInfo.iPriority=ENotifierPriorityHigh; |
|
118 return iInfo; |
|
119 } |
|
120 |
|
121 |
|
122 // ---------------------------------------------------------- |
|
123 // CBTGenericQueryNotifier::StartL |
|
124 // Synchronic notifier launch. Contructs and shows a global |
|
125 // note, no parameters need here. |
|
126 // ---------------------------------------------------------- |
|
127 // |
|
128 TPtrC8 CBTGenericQueryNotifier::StartL( const TDesC8& /*aBuffer*/ ) |
|
129 { |
|
130 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::StartL()")); |
|
131 |
|
132 TPtrC8 ret(KNullDesC8); |
|
133 return (ret); |
|
134 |
|
135 } |
|
136 |
|
137 // ---------------------------------------------------------- |
|
138 // CBTGenericQueryNotifier::GetParamsL |
|
139 // Mandatory for BT Notifiers when using asynchronous launch. |
|
140 // This notifier is synchronous so no implementation is needed. |
|
141 // ---------------------------------------------------------- |
|
142 // |
|
143 void CBTGenericQueryNotifier::GetParamsL(const TDesC8& aBuffer, |
|
144 TInt aReplySlot, |
|
145 const RMessagePtr2& aMessage) |
|
146 { |
|
147 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::GetParamsL")); |
|
148 |
|
149 if (iMessage.Handle()) |
|
150 { |
|
151 aMessage.Complete(KErrInUse); |
|
152 return; |
|
153 } |
|
154 |
|
155 ProcessParamBufferL(aBuffer); |
|
156 |
|
157 iMessage = aMessage; |
|
158 iReplySlot = aReplySlot; |
|
159 |
|
160 ShowQueryAndCompleteL(); |
|
161 |
|
162 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::GetParamsL Complete")); |
|
163 } |
|
164 |
|
165 // ---------------------------------------------------------- |
|
166 // CBTGenericQueryNotifier::ProcessParamBufferL |
|
167 // Parse the data out of the message that is sent by the |
|
168 // client of the notifier. |
|
169 // ---------------------------------------------------------- |
|
170 void CBTGenericQueryNotifier::ProcessParamBufferL(const TDesC8& aBuffer) |
|
171 { |
|
172 |
|
173 TBTGenericQueryNotifierParams bParams; |
|
174 TPckgC<TBTGenericQueryNotifierParams> bPckg(bParams); |
|
175 bPckg.Set( aBuffer ); |
|
176 |
|
177 if( bPckg().iMessageType == EBTNameQuery ) |
|
178 { |
|
179 iIsNameQuery = ETrue; |
|
180 return; |
|
181 } |
|
182 iSecondaryDisplayCommand = ECmdBTnotifUnavailable; |
|
183 switch (bPckg().iMessageType) |
|
184 { |
|
185 case EBTReceiveMessageQuery: |
|
186 iIsMessageQuery=EFalse; |
|
187 iMessageResourceId=R_BT_RECEIVE_MESSAGE ; |
|
188 iSecondaryDisplayCommand=ECmdShowReceiveMessageFromDeviceDlg; |
|
189 break; |
|
190 case EBTReceiveMessagePairedQuery: |
|
191 iIsMessageQuery=EFalse; |
|
192 iMessageResourceId=R_BT_RECEIVE_MESSAGE_PAIRED; |
|
193 iSecondaryDisplayCommand= ECmdShowReceiveMessageFromPairedDeviceDlg; |
|
194 break; |
|
195 case EBTIsOffQuery: |
|
196 iIsMessageQuery=EFalse; |
|
197 iMessageResourceId=R_BT_POWER_IS_OFF ; |
|
198 iSecondaryDisplayCommand=ECmdShowBtIsOffDlg; |
|
199 break; |
|
200 case EBTActivateOffLineQuery: |
|
201 iIsMessageQuery=EFalse; |
|
202 iMessageResourceId=R_BT_ACTIVATE_IN_OFFLINE; |
|
203 iSecondaryDisplayCommand=ECmdShowBtActivateInOfflineDlg; |
|
204 break; |
|
205 case EBTNoDevicesFoundQuery: |
|
206 iIsMessageQuery=EFalse; |
|
207 iMessageResourceId=R_BT_NO_DEVICES_FOUND; |
|
208 break; |
|
209 case EBTAcceptRequestQuery: |
|
210 iIsMessageQuery=EFalse; |
|
211 iMessageResourceId=R_BT_AUTHORISATION_NAME ; |
|
212 iSecondaryDisplayCommand=ECmdShowAcceptConnRequestDlg; |
|
213 break; |
|
214 |
|
215 case EBTIsOffJavaQuery: |
|
216 iIsMessageQuery=ETrue; |
|
217 if( bPckg().iNameExists ) |
|
218 { |
|
219 iMessageResourceId=R_BT_IS_OFF_JAVA_APPNAME; // when caller provide Java application name. |
|
220 } |
|
221 else |
|
222 { |
|
223 iMessageResourceId=R_BT_IS_OFF_JAVA; //r_bt_is_hidden_java |
|
224 } |
|
225 iSecondaryDisplayCommand=ECmdShowBtBtIsOffJavaDlg; |
|
226 iQueryHeader=StringLoader::LoadL( R_BT_IS_OFF_JAVA_HEADER); |
|
227 break; |
|
228 |
|
229 case EBTIsNotShownQuery: |
|
230 iIsMessageQuery=ETrue; |
|
231 if( bPckg().iNameExists ) |
|
232 { |
|
233 iMessageResourceId=R_BT_IS_HIDDEN_JAVA_APPNAME; // when caller provide Java application name. |
|
234 } |
|
235 else |
|
236 { |
|
237 iMessageResourceId=R_BT_IS_HIDDEN_JAVA; //r_bt_is_hidden_java |
|
238 } |
|
239 iSecondaryDisplayCommand=ECmdShowBtIsNotVisibleDlg; |
|
240 iQueryHeader=StringLoader::LoadL( R_BT_IS_HIDDEN_JAVA_HEADER); |
|
241 break; |
|
242 |
|
243 case EBTBlockConnectionQuery: |
|
244 case EBTBlockPairedConnectionQuery: |
|
245 iIsMessageQuery=ETrue; |
|
246 if( bPckg().iMessageType == EBTBlockConnectionQuery ) |
|
247 iMessageResourceId = R_BT_BLOCK_DEVICE_NOHELP; |
|
248 else |
|
249 iMessageResourceId = R_BT_BLOCK_PAIRED_DEVICE_NOHELP ; |
|
250 |
|
251 iQueryHeader= StringLoader::LoadL( R_BT_BLOCK_DEVICE_HEADER ); |
|
252 break; |
|
253 |
|
254 case EBTSwitchOffAnyway: |
|
255 iIsMessageQuery=EFalse; |
|
256 iMessageResourceId=R_BT_SWITCH_OFF_ANYWAY; |
|
257 break; |
|
258 |
|
259 default: |
|
260 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier:: Unkown messageType! ")); |
|
261 User::Leave(KErrNotFound); |
|
262 } |
|
263 |
|
264 // if the logic string contains substitute indicator "%U", replace it with device name: |
|
265 // |
|
266 HBufC* buf = StringLoader::LoadL( iMessageResourceId); |
|
267 iQueryMessage.Assign( buf ); |
|
268 |
|
269 TInt keyLen; |
|
270 TInt pos = BluetoothUiUtil::GetStringSubstringKeyPos( |
|
271 iQueryMessage, 0, keyLen ); |
|
272 if( pos > KErrNotFound) |
|
273 { |
|
274 //if no device name provided, default name will be used: |
|
275 if( !bPckg().iNameExists ) |
|
276 iName=StringLoader::LoadL(R_BT_DIALOG_DEF_NAME); |
|
277 else |
|
278 { |
|
279 iName=HBufC::NewL(bPckg().iName.Length() ); |
|
280 iName->Des().Copy(bPckg().iName); |
|
281 } |
|
282 BluetoothUiUtil::LoadResourceAndSubstringL( |
|
283 iQueryMessage, iMessageResourceId, *iName, 0); |
|
284 } |
|
285 else |
|
286 { |
|
287 iName=NULL; |
|
288 } |
|
289 } |
|
290 |
|
291 // ---------------------------------------------------------- |
|
292 // CBTGenericQueryNotifier::UpdateL |
|
293 // Update notifier according to new data |
|
294 // ---------------------------------------------------------- |
|
295 // |
|
296 TPtrC8 CBTGenericQueryNotifier::UpdateL(const TDesC8& aBuffer) |
|
297 { |
|
298 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::UpdateL")); |
|
299 ProcessParamBufferL(aBuffer); |
|
300 if( !iNotifUiUtil->IsQueryReleased() ) |
|
301 { |
|
302 if(iIsMessageQuery ) |
|
303 { |
|
304 iNotifUiUtil->UpdateMessageQueryDlgL(iQueryMessage); |
|
305 } |
|
306 else |
|
307 { |
|
308 iNotifUiUtil->UpdateQueryDlgL(iQueryMessage); |
|
309 } |
|
310 } |
|
311 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::UpdateL complete")); |
|
312 |
|
313 TPtrC8 ret(KNullDesC8); |
|
314 return (ret); |
|
315 } |
|
316 |
|
317 // ---------------------------------------------------------- |
|
318 // CBTGenericQueryNotifier::ShowQueryAndCompleteL |
|
319 // Shows the notifier in backround and complete message |
|
320 // ---------------------------------------------------------- |
|
321 // |
|
322 void CBTGenericQueryNotifier::ShowQueryAndCompleteL() |
|
323 { |
|
324 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::ShowQueryAndCompleteL")); |
|
325 |
|
326 // Turn lights on and deactivate apps -key |
|
327 // |
|
328 iNotifUiUtil->TurnLightsOn(); |
|
329 if( iIsNameQuery ) |
|
330 { |
|
331 TBool nameStatus = IsLocalNameModifiedL(); |
|
332 if( !nameStatus ) |
|
333 { |
|
334 (void) AskLocalBTNameQueryL(); |
|
335 } |
|
336 // Check if Local name is set again before turn BT on. |
|
337 // Turn BT on only when there is local name, since user still has chance |
|
338 // to ignore the asking name query - like pressing End-key |
|
339 // |
|
340 TBTDeviceName localName; |
|
341 localName.Zero(); |
|
342 TInt err = iBTEngSettings->GetLocalName(localName); |
|
343 |
|
344 if (localName.Length() <= 0) |
|
345 { |
|
346 err = KErrCancel; |
|
347 } |
|
348 |
|
349 CompleteMessage( (!err) ? ETrue : EFalse, KErrNone ); |
|
350 |
|
351 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::ShowQueryAndCompleteL iIsNameQuery complete")); |
|
352 return; |
|
353 } |
|
354 |
|
355 TInt keypress; |
|
356 TBTDeviceName name(KNullDesC); |
|
357 if( iName ) |
|
358 { |
|
359 name.Copy( *iName ); |
|
360 } |
|
361 if( iIsMessageQuery ) |
|
362 { |
|
363 |
|
364 keypress = iNotifUiUtil->ShowMessageQueryL(iQueryMessage, *iQueryHeader, |
|
365 R_BT_GENERIC_MESSAGE_QUERY, CAknQueryDialog::EConfirmationTone ); |
|
366 } |
|
367 else |
|
368 { |
|
369 keypress = iNotifUiUtil->ShowQueryL( iQueryMessage, R_BT_GENERIC_QUERY, |
|
370 iSecondaryDisplayCommand, name, CAknQueryDialog::EConfirmationTone ); |
|
371 } |
|
372 |
|
373 CompleteMessage( (keypress) ? ETrue: EFalse, KErrNone ); |
|
374 |
|
375 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::ShowQueryAndCompleteL complete")); |
|
376 } |
|
377 |
|
378 // ---------------------------------------------------------- |
|
379 // CBTAuthNotifier::RequestCompletedL |
|
380 // Gets called when P&S key notifies the change |
|
381 // ---------------------------------------------------------- |
|
382 void CBTGenericQueryNotifier::RequestCompletedL(CBTNotifActive* aActive, |
|
383 TInt aId, TInt aStatus) |
|
384 { |
|
385 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::RequestCompletedL()")); |
|
386 switch (aId) |
|
387 { |
|
388 case KBTNotifPhonePowerKeyWatcher: |
|
389 { |
|
390 iPhonePowerKey.Subscribe(aActive->RequestStatus()); |
|
391 aActive->GoActive(); |
|
392 TInt val = 0; |
|
393 // If the Power key is pressed it is likely that he user does not |
|
394 // want to continue with existing query, so we dismiss it to avoid |
|
395 // any clashes with subsequent popups (ie for setting Lock code). |
|
396 // This is probably just a temporary solution to resolve immediate problem, |
|
397 // and the issue is raised with UI Framework team. |
|
398 if (!aStatus && !iPhonePowerKey.Get(val) && val == ECoreAppUIsHideAlarm) |
|
399 { |
|
400 // DismissDialog() internally checks that actual query dialog is NOT NULL, |
|
401 // so it is safe to call it here. |
|
402 iNotifUiUtil->DismissDialog(); |
|
403 } |
|
404 } |
|
405 break; |
|
406 } |
|
407 |
|
408 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::RequestCompletedL() completed")); |
|
409 } |
|
410 |
|
411 // ---------------------------------------------------------- |
|
412 // CBTAuthNotifier::HandleError |
|
413 // ---------------------------------------------------------- |
|
414 void CBTGenericQueryNotifier::HandleError(CBTNotifActive* aActive, TInt aId, |
|
415 TInt aError) |
|
416 { |
|
417 FTRACE(FPrint(_L("[BTNOTIF]\t CBTGenericQueryNotifier::HandleError() error = %d"), aError )); |
|
418 (void) aActive; |
|
419 (void) aId; |
|
420 (void) aError; |
|
421 } |
|
422 |
|
423 // ---------------------------------------------------------- |
|
424 // CBTAuthNotifier::DoCancelRequest |
|
425 // Root caller is CBTNotifActive::CancelRequest(), which calls |
|
426 // CActive::Cancel that calls DoCancel() if request is active. |
|
427 // ---------------------------------------------------------- |
|
428 void CBTGenericQueryNotifier::DoCancelRequest(CBTNotifActive* aActive, TInt aId) |
|
429 { |
|
430 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::DoCancel() >>")); |
|
431 (void) aActive; |
|
432 (void) aId; |
|
433 |
|
434 iPhonePowerKey.Cancel(); |
|
435 |
|
436 FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::DoCancel() <<")); |
|
437 } |
|
438 |
|
439 // End of File |
|