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: Declares Bluetooth device inquiry user interface class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <avkon.hrh> // AVKON components |
|
21 #include <AknIconArray.h> |
|
22 #include <aknlists.h> |
|
23 #include <aknPopup.h> |
|
24 #include <avkon.mbg> |
|
25 #include <wlaninternalpskeys.h> // For WLAN state checking |
|
26 #include <ctsydomainpskeys.h> |
|
27 #include <AknNotiferAppServerApplication.h> |
|
28 #include <barsread.h> // Resource reader |
|
29 #include <BTNotif.rsg> // Own resources |
|
30 #include <bt_subscribe.h> |
|
31 #include <btnotif.mbg> |
|
32 #include <devui_const.h> |
|
33 #include <btengutil.h> |
|
34 #include <bluetoothuiutil.h> |
|
35 #include "btninqui.h" // Own class definition |
|
36 #include "btNotifDebug.h" // Debugging macros |
|
37 #include "btnotifnameutils.h" |
|
38 |
|
39 |
|
40 const TInt KBTAllPurposeBufferLength = 266; |
|
41 const TInt KBTNotifNonPairedUsedDevicesMaxNumber= 5; |
|
42 // RSSI value range: -127dB ~ +20dB |
|
43 const TInt KRssiRangeOffset = 127 + 1; // Offset for getting a non-zero positive value |
|
44 const TInt KMediumStrength = 53; |
|
45 const TInt KHighStrength = 82; |
|
46 const TUint32 ExcludePairedDeviceMask = 0x800000; |
|
47 const TUint32 ResetExcludePairedDeviceMask = 0xFF7FFFFF; |
|
48 _LIT(KBtnotifBmpFileName,"btnotif.mif"); //mif is target file under resource folder |
|
49 |
|
50 // ================= MEMBER FUNCTIONS ======================= |
|
51 |
|
52 // ---------------------------------------------------------- |
|
53 // CBTInqUI::CBTInqUI |
|
54 // C++ default constructor can NOT contain any code, that |
|
55 // might leave. |
|
56 // ---------------------------------------------------------- |
|
57 // |
|
58 CBTInqUI::CBTInqUI( MBTNDeviceSearchObserver* aObserver, |
|
59 CBTNotifUIUtil* aUtil, |
|
60 const TBTDeviceClass& aDesiredDevClass): |
|
61 iUiUtil (aUtil), |
|
62 iEikonEnvRef( iUiUtil->LocalEikonEnv() ), |
|
63 iDevicesFound (EFalse), |
|
64 iBroughtForwards (EFalse), |
|
65 iDesiredDeviceClass (aDesiredDevClass), |
|
66 iSystemCancel (EFalse), |
|
67 iPageForName ( EFalse ), |
|
68 iIndex (0), |
|
69 iDevSearchObserver (aObserver) |
|
70 { |
|
71 iBTRegistryQueryState=ENoQuery; |
|
72 } |
|
73 |
|
74 // ---------------------------------------------------------- |
|
75 // CBTInqUI::ConstructL |
|
76 // Symbian 2nd phase constructor can leave. |
|
77 // Creates first device list (not shown yet) and initializes |
|
78 // couple of member variables with default values. |
|
79 // ---------------------------------------------------------- |
|
80 // |
|
81 void CBTInqUI::ConstructL() |
|
82 { |
|
83 FLOG(_L("[BTNOTIF]\t CBTInqUI::ConstructL()")); |
|
84 |
|
85 // Read default device names to an array |
|
86 iDefaultDeviceNamesArray = iEikonEnvRef.ReadDesCArrayResourceL( R_BT_DEFAULT_DEVICE_NAMES ); |
|
87 |
|
88 // create the timer |
|
89 iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityIdle); |
|
90 |
|
91 // Create device array |
|
92 // |
|
93 iDeviceListRows = new(ELeave) CDesCArrayFlat(1); |
|
94 |
|
95 iPairedDevicesArray = new (ELeave) CBTDeviceArray(1); |
|
96 iLastUsedDevicesArray = new(ELeave) CBTDeviceArray(1); |
|
97 iLastSeenDevicesArray = new(ELeave) CBTDeviceArray(1); |
|
98 iAdjustedUsedDeviceArray = new(ELeave) CBTDeviceArray(1); |
|
99 |
|
100 iDevMan=CBTEngDevMan::NewL(this); |
|
101 |
|
102 iExcludePairedDevices = iDesiredDeviceClass.DeviceClass() & ExcludePairedDeviceMask ? |
|
103 ETrue : EFalse; |
|
104 if ( iExcludePairedDevices ) |
|
105 { |
|
106 FLOG (_L("[BTNOTIF]\t CBTInqUI::ConstrucL Excluding paired devices")); |
|
107 iDesiredDeviceClass = iDesiredDeviceClass.DeviceClass() & ResetExcludePairedDeviceMask; |
|
108 } |
|
109 // Retrieve paired devices to a local array |
|
110 RetrievePairedDevices(); |
|
111 |
|
112 FLOG(_L("[BTNOTIF]\t CBTInqUI::ConstructL() completed")); |
|
113 } |
|
114 |
|
115 // ---------------------------------------------------------- |
|
116 // CBTInqUI::RetrieveUsedDevices- Substitute |
|
117 // ---------------------------------------------------------- |
|
118 // |
|
119 void CBTInqUI::RetrieveUsedDevices() |
|
120 { |
|
121 FLOG(_L("[BTNOTIF]\t CBTInqUI::RetrieveUsedDevicesL()")); |
|
122 |
|
123 TBTRegistrySearch searchPattern; |
|
124 searchPattern.FindAll(); |
|
125 |
|
126 //Ignore this error. Continue device search. |
|
127 TInt err=iDevMan->GetDevices( searchPattern, iLastUsedDevicesArray ); |
|
128 if(err) |
|
129 { |
|
130 TRAP_IGNORE(AdjustDeviceArrayL(iAdjustedUsedDeviceArray)); |
|
131 DoDeviceFrontListSelection(); |
|
132 FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI: get useddevice err %d"), err)); |
|
133 } |
|
134 else |
|
135 { |
|
136 iBTRegistryQueryState=EQueryUsed; |
|
137 } |
|
138 FLOG(_L("[BTNOTIF]\t CBTInqUI::RetrieveUsedDevicesL() returned")); |
|
139 } |
|
140 |
|
141 //--------------------------------------------------------------- |
|
142 // CBTInqUI::RetrievePairedDevices |
|
143 //--------------------------------------------------------------- |
|
144 void CBTInqUI::RetrievePairedDevices() |
|
145 { |
|
146 FLOG(_L("[BTNOTIF]\t CBTInqUI::RetrievePairedDevicesL()")); |
|
147 |
|
148 TBTRegistrySearch searchPattern; |
|
149 searchPattern.FindBonded(); |
|
150 |
|
151 TInt err= iDevMan->GetDevices( searchPattern, iPairedDevicesArray ); |
|
152 FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI: get paireddevice err %d"), err)); |
|
153 if(err) |
|
154 { |
|
155 //Next: try to get used devices |
|
156 RetrieveUsedDevices(); |
|
157 } |
|
158 else |
|
159 { |
|
160 iBTRegistryQueryState=EQueryPaired; |
|
161 } |
|
162 FLOG(_L("[BTNOTIF]\t CBTInqUI::RetrievePairedDevicesL() returned")); |
|
163 } |
|
164 |
|
165 // ---------------------------------------------------------- |
|
166 // CBTInqUI::HandleGetDevicesComplete |
|
167 // ---------------------------------------------------------- |
|
168 // |
|
169 void CBTInqUI::HandleGetDevicesComplete(TInt aErr, CBTDeviceArray* /*aDeviceArray*/) |
|
170 { |
|
171 FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::HandleGetDevicesComplete() err: %d"), aErr)); |
|
172 (void) aErr; |
|
173 switch(iBTRegistryQueryState) |
|
174 { |
|
175 case EQueryPaired: |
|
176 // If a device is paired in Just Works model but without user awareness, |
|
177 // This device won't be shown in UI paired view, so we have to |
|
178 // remove it from this array so that it will be shown to user |
|
179 // in the last used device list. |
|
180 for (int i = iPairedDevicesArray->Count() - 1; i >= 0; --i ) |
|
181 { |
|
182 if ( !IsUserAwarePaired( iPairedDevicesArray->At( i )->AsNamelessDevice() ) ) |
|
183 { |
|
184 delete iPairedDevicesArray->At( i ); |
|
185 iPairedDevicesArray->Delete( i ); |
|
186 } |
|
187 } |
|
188 RetrieveUsedDevices(); |
|
189 break; |
|
190 case EQueryUsed: |
|
191 // fill in the list of last seen devices, so it can be shown |
|
192 TRAP_IGNORE(AdjustDeviceArrayL(iAdjustedUsedDeviceArray)); |
|
193 DoDeviceFrontListSelection(); |
|
194 break; |
|
195 default: |
|
196 break; |
|
197 } |
|
198 |
|
199 FLOG(_L("[BTNOTIF]\t CBTInqUI::HandleGetDevicesComplete() Complete")); |
|
200 } |
|
201 |
|
202 // ---------------------------------------------------------- |
|
203 // Destructor |
|
204 // ---------------------------------------------------------- |
|
205 // |
|
206 CBTInqUI::~CBTInqUI() |
|
207 { |
|
208 FLOG(_L("[BTNOTIF]\t CBTInqUI::~CBTInqUI()")); |
|
209 |
|
210 if( iBroughtForwards ) |
|
211 { |
|
212 iEikonEnvRef.BringForwards(EFalse); |
|
213 iBroughtForwards = EFalse; |
|
214 } |
|
215 |
|
216 if( iPairedDevicesArray ) |
|
217 { |
|
218 iPairedDevicesArray->ResetAndDestroy(); |
|
219 delete iPairedDevicesArray; |
|
220 } |
|
221 if( iLastUsedDevicesArray ) |
|
222 { |
|
223 iLastUsedDevicesArray->ResetAndDestroy(); |
|
224 delete iLastUsedDevicesArray; |
|
225 } |
|
226 if( iLastSeenDevicesArray ) |
|
227 { |
|
228 iLastSeenDevicesArray->ResetAndDestroy(); |
|
229 delete iLastSeenDevicesArray; |
|
230 } |
|
231 if( iAdjustedUsedDeviceArray ) |
|
232 { |
|
233 iAdjustedUsedDeviceArray->ResetAndDestroy(); |
|
234 delete iAdjustedUsedDeviceArray; |
|
235 } |
|
236 if( iDefaultDeviceNamesArray ) |
|
237 { |
|
238 iDefaultDeviceNamesArray->Reset(); |
|
239 delete iDefaultDeviceNamesArray; |
|
240 } |
|
241 |
|
242 delete iDevMan; |
|
243 delete iDeviceListBox; |
|
244 delete iDeviceListRows; |
|
245 delete iPeriodicTimer; |
|
246 |
|
247 FLOG(_L("[BTNOTIF]\t CBTInqUI::~CBTInqUI() completed")); |
|
248 } |
|
249 |
|
250 // ---------------------------------------------------------- |
|
251 // CBTInqUI::Cancel |
|
252 // ---------------------------------------------------------- |
|
253 // |
|
254 void CBTInqUI::Cancel() |
|
255 { |
|
256 FLOG(_L("[BTNOTIF]\t CBTInqUI::Cancel()")); |
|
257 |
|
258 iSystemCancel = ETrue; |
|
259 if(iDevMan) |
|
260 { |
|
261 iDevMan->Cancel(); |
|
262 } |
|
263 |
|
264 if( iSearchFilterPopupList ) |
|
265 { |
|
266 iSearchFilterPopupList->CancelPopup(); |
|
267 } |
|
268 |
|
269 if(iPeriodicTimer) |
|
270 { |
|
271 iPeriodicTimer->Cancel(); |
|
272 } |
|
273 |
|
274 RemoveScanner(); |
|
275 InquiryComplete(KErrCancel); |
|
276 |
|
277 FLOG(_L("[BTNOTIF]\t CBTInqUI::Cancel() completed")); |
|
278 } |
|
279 |
|
280 // ---------------------------------------------------------- |
|
281 // CBTInqUI::DisplayDevicesFrontListL |
|
282 // Display last seen devices popuplist |
|
283 // ---------------------------------------------------------- |
|
284 // |
|
285 void CBTInqUI::DisplayDevicesFrontListL() |
|
286 { |
|
287 FLOG(_L("[BTNOTIF]\t CBTInqUI::DisplayDevicesFrontListL()")); |
|
288 |
|
289 |
|
290 if ( iAdjustedUsedDeviceArray->Count() <= 0 ) |
|
291 { |
|
292 SelectSearchCategoryL(); |
|
293 return; |
|
294 } |
|
295 |
|
296 if( !iBroughtForwards ) |
|
297 { |
|
298 iEikonEnvRef.BringForwards(ETrue); // Destructor will release this later on |
|
299 iBroughtForwards = ETrue; |
|
300 } |
|
301 |
|
302 // Create the devices popuplist |
|
303 CreatePopupListL( R_AVKON_SOFTKEYS_SELECT_CANCEL__SELECT , R_BT_LAST_USED_DEVS_POPUP_TITLE ); |
|
304 |
|
305 // Add devices into device list. |
|
306 for( TInt index = 0; index < iAdjustedUsedDeviceArray->Count(); index++ ) |
|
307 { |
|
308 UpdateDeviceListL ( iAdjustedUsedDeviceArray->At(index) ); |
|
309 } |
|
310 |
|
311 // Add "more devices" command as first item of list |
|
312 HBufC* formatString = HBufC::NewLC( KBTAllPurposeBufferLength ); |
|
313 formatString->Des().Copy( TPtrC(KDeviceIconFormatTable[EDeviceIconBlank].iFormat ) ); |
|
314 HBufC* moreDevicesString = iEikonEnvRef.AllocReadResourceLC( R_BT_MORE_DEVICES_ITEM ); |
|
315 formatString->Des().Append( *moreDevicesString ); |
|
316 CleanupStack::PopAndDestroy(); // moreDevicesString |
|
317 iDeviceListRows->InsertL( 0, *formatString ); |
|
318 CleanupStack::Pop(); // formatString |
|
319 |
|
320 // Launch popup list and wait for user input |
|
321 AllowDialerAndAppKeyPress( EFalse ); |
|
322 TInt popupRetVal = iDevicePopupList->ExecuteLD(); |
|
323 iDevicePopupList = NULL; |
|
324 AllowDialerAndAppKeyPress( ETrue ); |
|
325 |
|
326 if( !popupRetVal ) |
|
327 { |
|
328 // query cancelled by user or system, complete device search: |
|
329 iDevSearchObserver->NotifyDeviceSearchCompleted(KErrCancel); |
|
330 return; |
|
331 } |
|
332 TInt currentDeviceIndex = iDeviceListBox->CurrentItemIndex(); |
|
333 |
|
334 // Delete device list box and reset device items array |
|
335 delete iDeviceListBox; |
|
336 iDeviceListBox = NULL; |
|
337 iDeviceListRows->Reset(); |
|
338 |
|
339 if( currentDeviceIndex > 0 ) // User selected "a used device" |
|
340 { |
|
341 HandleDeviceSelectionL( iAdjustedUsedDeviceArray->At( currentDeviceIndex - 1 ) ); |
|
342 return; |
|
343 } |
|
344 |
|
345 // user selected more devices. |
|
346 SelectSearchCategoryL(); |
|
347 FLOG(_L("[BTNOTIF]\t CBTInqUI::DisplayDevicesFrontListL() completed")); |
|
348 } |
|
349 |
|
350 // ---------------------------------------------------------- |
|
351 // CBTInqUI::DeviceSearchUiL |
|
352 // Execute bluetooth device search/inquiry. |
|
353 // Parameters: |
|
354 // OUT: aDevice - selected device after inquiry |
|
355 // IN: aObexOnly - flag if OBEX capable devices is requested |
|
356 // ---------------------------------------------------------- |
|
357 // |
|
358 void CBTInqUI::DeviceSearchUiL() |
|
359 { |
|
360 FLOG(_L("[BTNOTIF]\t CBTInqUI::DeviceSearchUiL()")); |
|
361 |
|
362 TSearchFlowState searchFlow; |
|
363 TInt err; |
|
364 AllowDialerAndAppKeyPress( EFalse ); |
|
365 do |
|
366 { |
|
367 searchFlow = InitInquiryL(err); |
|
368 } while (searchFlow == ESearchAgain); |
|
369 |
|
370 if (searchFlow == ESearchCompleted) |
|
371 { |
|
372 // search completed caused by either user cancel or failure |
|
373 iDevSearchObserver->NotifyDeviceSearchCompleted(err); |
|
374 AllowDialerAndAppKeyPress( ETrue ); |
|
375 return; |
|
376 } |
|
377 |
|
378 FLOG(_L("[BTNOTIF]\t CBTInqUI, Displaying devices already found")); |
|
379 |
|
380 TInt keypress(0); |
|
381 // Show devices popup list for received devices while |
|
382 // inquiry is still active and list may be updated. |
|
383 if( !iInquiryComplete ) |
|
384 { |
|
385 CreatePopupListL( R_BT_SOFTKEYS_SELECT_STOP, R_BT_SEARCH_DEVS_POPUP_TITLE ); |
|
386 |
|
387 // Set animation |
|
388 iDevicePopupList->Heading()->SetHeaderAnimationL( R_BT_ANIMATION_FOR_POPUPLIST ); |
|
389 |
|
390 // Launch popup list and wait for user input |
|
391 keypress = iDevicePopupList->ExecuteLD(); |
|
392 iDevicePopupList = NULL; |
|
393 } |
|
394 |
|
395 // If Cancel() is called while DoInquery() is still running, |
|
396 // such as taking out MMC while bt devices discovery or user pressed redkey. |
|
397 // In such cases, We need to dismiss anything and function returns immediately. |
|
398 // |
|
399 if (iSystemCancel ) |
|
400 { |
|
401 FLOG(_L("[BTNOTIF]\t inquiry was canncelled by the system!")); |
|
402 iSystemCancel = EFalse; |
|
403 AllowDialerAndAppKeyPress( ETrue ); |
|
404 iDevSearchObserver->NotifyDeviceSearchCompleted(KErrCancel); |
|
405 return; |
|
406 } |
|
407 |
|
408 // Cancel inquiry |
|
409 RemoveScanner(); |
|
410 |
|
411 // Store the highlighted device index and destroy list box |
|
412 iHighLightedItemIndex = 0; |
|
413 if( iDeviceListBox ) |
|
414 { |
|
415 iHighLightedItemIndex = iDeviceListBox->CurrentItemIndex(); |
|
416 delete iDeviceListBox; |
|
417 iDeviceListBox = NULL; |
|
418 } |
|
419 |
|
420 // user selected a device during active inquiry |
|
421 if (keypress) |
|
422 { |
|
423 AllowDialerAndAppKeyPress( ETrue ); |
|
424 HandleDeviceSelectionL( iLastSeenDevicesArray->At( iHighLightedItemIndex ) ); |
|
425 return; |
|
426 } |
|
427 |
|
428 // Error encountered in inquiry |
|
429 if (iInquiryStatus) |
|
430 { |
|
431 AllowDialerAndAppKeyPress( ETrue ); |
|
432 iDevSearchObserver->NotifyDeviceSearchCompleted(iInquiryStatus); |
|
433 return; |
|
434 } |
|
435 |
|
436 // Inquiry completed, show final device list |
|
437 FLOG(_L("[BTNOTIF]\t CBTInqUI::DeviceSearchUiL Displaying final devicelist")); |
|
438 CreatePopupListL( R_AVKON_SOFTKEYS_SELECT_CANCEL__SELECT, R_BT_FOUND_DEVS_POPUP_TITLE ); |
|
439 |
|
440 //cancel iPeriodicTimer after the final list is shown |
|
441 iPeriodicTimer->Cancel(); |
|
442 User::ResetInactivityTime(); |
|
443 // Set highlight on top of same device as it was in previous popuplist |
|
444 if( iHighLightedItemIndex >= 0 ) |
|
445 { |
|
446 iDeviceListBox->HandleItemAdditionL(); |
|
447 iDeviceListBox->SetCurrentItemIndex(iHighLightedItemIndex); |
|
448 } |
|
449 |
|
450 // Launch popup list and wait for user input |
|
451 keypress = iDevicePopupList->ExecuteLD(); |
|
452 iDevicePopupList = NULL; |
|
453 AllowDialerAndAppKeyPress( ETrue ); |
|
454 // If dialog is cancelled by system: |
|
455 if( !keypress) |
|
456 { |
|
457 iDevSearchObserver->NotifyDeviceSearchCompleted(KErrCancel); |
|
458 return; |
|
459 } |
|
460 |
|
461 // Get user selection |
|
462 TInt index = iDeviceListBox->CurrentItemIndex(); |
|
463 delete iDeviceListBox; |
|
464 iDeviceListBox = NULL; |
|
465 |
|
466 HandleDeviceSelectionL( iLastSeenDevicesArray->At( index ) ); |
|
467 |
|
468 FLOG(_L("[BTNOTIF]\t CBTInqUI::DeviceSearchUiL() complete")); |
|
469 } |
|
470 |
|
471 TSearchFlowState CBTInqUI::InitInquiryL(TInt& aReason) |
|
472 { |
|
473 FLOG(_L("[BTNOTIF]\t CBTInqUI::InitInquiryL")); |
|
474 if (IsActiveVoIPOverWLAN()) |
|
475 { |
|
476 iUiUtil->ShowInfoNoteL( R_BT_NO_DEVICE_DISCOVERY_VOIP, ECmdBTnotifUnavailable ); |
|
477 aReason = KErrInUse; |
|
478 return ESearchCompleted; |
|
479 } |
|
480 |
|
481 // starting the timer |
|
482 iPeriodicTimer->Cancel(); |
|
483 iPeriodicTimer->Start(KPeriodicTimerInterval4Sec, KPeriodicTimerInterval4Sec, |
|
484 TCallBack(PeriodicTimerCallBack, this)); |
|
485 |
|
486 // Prepare for using hostresolver to search devices |
|
487 CreateScannerL(); |
|
488 |
|
489 iInquiryStatus = KErrCancel; // Give a initial value (for end key handling) |
|
490 iDevicesFound = EFalse; |
|
491 iInquiryComplete = EFalse; |
|
492 iSystemCancel = EFalse; |
|
493 |
|
494 // Show wait note until dialog is dismissed by inquirey result callbacks or user cancel |
|
495 TInt ret = iUiUtil->ShowWaitDlgL( R_BT_SEARCHING_DEVICES_NOTE ); |
|
496 |
|
497 // If user cancels searching, ret will be KerrNone. |
|
498 // According to Description of Eikdialog, ShowWaitDlgL() returns zero |
|
499 // if it was the cancel button (@c EEikBidCancel). |
|
500 if( ret == KErrNone || iSystemCancel ) |
|
501 { |
|
502 FLOG(_L("[BTNOTIF]\t CBTInqUI, User cancelled waiting note")); |
|
503 RemoveScanner(); |
|
504 aReason = KErrCancel; |
|
505 return ESearchCompleted; |
|
506 } |
|
507 |
|
508 if( !iDevicesFound ) // No devices found at all |
|
509 { |
|
510 FLOG(_L("[BTNOTIF]\t CBTInqUI no devices found at all")); |
|
511 RemoveScanner(); // Cancel inquiry |
|
512 |
|
513 if( iInquiryStatus != KErrNone ) |
|
514 { |
|
515 aReason = iInquiryStatus; |
|
516 return ESearchCompleted; |
|
517 } |
|
518 |
|
519 // Show try again query |
|
520 TBool keypress(0); |
|
521 keypress = iUiUtil->ShowQueryL( KErrNone, R_BT_TRY_AGAIN_QUERY, ECmdBTnotifUnavailable ); |
|
522 if( !keypress ) // User has not requested new inquiry |
|
523 { |
|
524 aReason = KErrCancel; |
|
525 return ESearchCompleted; |
|
526 } |
|
527 else |
|
528 { |
|
529 FLOG(_L("[BTNOTIF]\t CBTInqUI user wanted to try again")); |
|
530 return ESearchAgain; |
|
531 } |
|
532 } |
|
533 return ESearchFirstDeviceFound; |
|
534 } |
|
535 |
|
536 // ---------------------------------------------------------- |
|
537 // CBTInqUI::DeviceAvailableL |
|
538 // Bluetooth device has been received. |
|
539 // ---------------------------------------------------------- |
|
540 // |
|
541 void CBTInqUI::DeviceAvailableL( const TNameRecord& aNameRecord, const TDesC& aDevName ) |
|
542 { |
|
543 FLOG(_L("[BTNOTIF]\t CBTInqUI::DeviceAvailableL()")); |
|
544 |
|
545 if( !iDevicesFound ) |
|
546 { |
|
547 FLOG(_L("[BTNOTIF]\t CBTInqUI::DeviceAvailableL() first found, clear last seen devices array")); |
|
548 iLastSeenDevicesArray->ResetAndDestroy(); // Remove previous inquiry results |
|
549 iDevicesFound = ETrue; |
|
550 iInquiryStatus = KErrNone; |
|
551 } |
|
552 |
|
553 iUiUtil->CompleteWaitDlgL(); |
|
554 |
|
555 TInquirySockAddr& sa = TInquirySockAddr::Cast( aNameRecord.iAddr ); |
|
556 |
|
557 // Create device object with received CoD information |
|
558 CBTDevice* newDevice = CBTDevice::NewLC( sa.BTAddr() ); |
|
559 TBTDeviceClass cod( sa.MajorServiceClass(), sa.MajorClassOfDevice(), sa.MinorClassOfDevice() ); |
|
560 newDevice->SetDeviceClass( cod ); |
|
561 FTRACE(FPrint(_L("[BTNOTIF]\t CoD %b"), cod.DeviceClass() )); |
|
562 TInt rssi = 0; |
|
563 if( sa.ResultFlags() & TInquirySockAddr::ERssiValid ) |
|
564 { |
|
565 rssi = sa.Rssi() + KRssiRangeOffset; |
|
566 } |
|
567 |
|
568 BtNotifNameUtils::SetDeviceNameL(aDevName, *newDevice); |
|
569 |
|
570 // Update device popup list with newDevice |
|
571 UpdateDeviceListL( newDevice, rssi ); |
|
572 |
|
573 // Append newDevice in the bottom of the "last seen" device array. |
|
574 iLastSeenDevicesArray->AppendL(newDevice); |
|
575 CleanupStack::Pop(); // new device is under iLastSeenDevicesArray control now |
|
576 |
|
577 FLOG(_L("[BTNOTIF]\t CBTInqUI::DeviceAvailableL() completed")); |
|
578 } |
|
579 |
|
580 // ---------------------------------------------------------- |
|
581 // CBTInqUI::InquiryComplete |
|
582 // Inquiry has been completed. |
|
583 // ---------------------------------------------------------- |
|
584 // |
|
585 void CBTInqUI::InquiryComplete( TInt aError ) |
|
586 { |
|
587 FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::InquiryComplete() status = %d: %d devices found"), aError, iLastSeenDevicesArray->Count() )); |
|
588 iInquiryComplete = ETrue; |
|
589 // Remove popup list if any devices exists |
|
590 if( iDevicePopupList ) |
|
591 { |
|
592 iDevicePopupList->CancelPopup(); |
|
593 iDevicePopupList = NULL; |
|
594 } |
|
595 |
|
596 TRAP_IGNORE( iUiUtil->CompleteWaitDlgL() ); |
|
597 |
|
598 if ( aError == KErrNone || aError == KErrCancel || aError == KErrEof ) |
|
599 { |
|
600 iInquiryStatus = (aError == KErrEof ) ? KErrNone : aError; |
|
601 } |
|
602 else |
|
603 { |
|
604 iLastSeenDevicesArray->ResetAndDestroy(); // Remove previous inquiry results |
|
605 } |
|
606 |
|
607 FLOG(_L("[BTNOTIF]\t CBTInqUI::InquiryComplete() completed")); |
|
608 } |
|
609 |
|
610 // ---------------------------------------------------------- |
|
611 // CBTInqUI::PeriodicTimerCallBack(TAny* aAny) |
|
612 // The call back function |
|
613 // ---------------------------------------------------------- |
|
614 // |
|
615 TInt CBTInqUI::PeriodicTimerCallBack(TAny* /*aAny*/) |
|
616 { |
|
617 User::ResetInactivityTime(); |
|
618 return KErrNone; // Return value ignored by CPeriodic |
|
619 } |
|
620 |
|
621 // ---------------------------------------------------------- |
|
622 // CBTInqUI::RemoveScanner |
|
623 // Remove scanner active object if still exists. |
|
624 // ---------------------------------------------------------- |
|
625 // |
|
626 void CBTInqUI::RemoveScanner() |
|
627 { |
|
628 FLOG(_L("[BTNOTIF]\t CBTInqUI::RemoveScanner()")); |
|
629 if( iScanner ) |
|
630 { |
|
631 iScanner->CancelRequest(); |
|
632 iHostResolver.Close(); |
|
633 iSocketServer.Close(); |
|
634 delete iScanner; |
|
635 iScanner = NULL; |
|
636 } |
|
637 iDevsWithoutName.Close(); |
|
638 FLOG(_L("[BTNOTIF]\t CBTInqUI::RemoveScanner() completed")); |
|
639 } |
|
640 |
|
641 // ---------------------------------------------------------- |
|
642 // CBTInqUI::CreatePopupListL |
|
643 // ---------------------------------------------------------- |
|
644 // |
|
645 void CBTInqUI::CreatePopupListL(TInt aSoftkeysResourceId, TInt aTitleResourceId ) |
|
646 { |
|
647 FLOG(_L("[BTNOTIF]\t CBTInqUI::CreatePopupListL()")); |
|
648 |
|
649 __ASSERT_DEBUG( !iDeviceListBox, User::Panic(_L("BTNotifInqUI - iDeviceListBox not released!" ), KErrAlreadyExists)); |
|
650 __ASSERT_DEBUG( !iDevicePopupList, User::Panic(_L("BTNotifInqUI - iDevicePopupList not released!"),KErrAlreadyExists)); |
|
651 |
|
652 // Create listbox for devices |
|
653 iDeviceListBox = new(ELeave) CAknSingleGraphicPopupMenuStyleListBox; |
|
654 |
|
655 // Create popup list |
|
656 iDevicePopupList = CAknPopupList::NewL( iDeviceListBox, aSoftkeysResourceId, AknPopupLayouts::EDynMenuWindow ); |
|
657 |
|
658 iDeviceListBox->ConstructL(iDevicePopupList, EAknListBoxMenuList ); |
|
659 iDeviceListBox->CreateScrollBarFrameL(ETrue); |
|
660 iDeviceListBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
661 |
|
662 // Read title from resources |
|
663 HBufC* popupListTitle = iEikonEnvRef.AllocReadResourceLC( aTitleResourceId ); |
|
664 iDevicePopupList->SetTitleL(*popupListTitle); |
|
665 CleanupStack::PopAndDestroy(); // popupListTitle |
|
666 |
|
667 // Create list box model for devices |
|
668 CTextListBoxModel* model = iDeviceListBox->Model(); |
|
669 model->SetItemTextArray(iDeviceListRows); |
|
670 model->SetOwnershipType(ELbmDoesNotOwnItemArray); // Do not destroy items |
|
671 |
|
672 // Set up filename for Avkon bitmap |
|
673 TFileName avkonbmpFilename = AknIconUtils::AvkonIconFileName(); |
|
674 |
|
675 // Setup graphic items list for BT devices listbox |
|
676 CAknIconArray* iconList = new(ELeave) CAknIconArray(KDeviceIconCount); |
|
677 CleanupStack::PushL( iconList ); |
|
678 |
|
679 CreateAndAppendIconL( KAknsIIDQgnPropBtComputer, avkonbmpFilename, |
|
680 EMbmAvkonQgn_prop_bt_computer, |
|
681 EMbmAvkonQgn_prop_bt_computer_mask, iconList); |
|
682 |
|
683 CreateAndAppendIconL( KAknsIIDQgnPropBtPhone, avkonbmpFilename, |
|
684 EMbmAvkonQgn_prop_bt_phone, |
|
685 EMbmAvkonQgn_prop_bt_phone_mask, iconList); |
|
686 |
|
687 CreateAndAppendIconL( KAknsIIDQgnPropBtAudio, avkonbmpFilename, |
|
688 EMbmAvkonQgn_prop_bt_audio, |
|
689 EMbmAvkonQgn_prop_bt_audio_mask, iconList); |
|
690 |
|
691 CreateAndAppendIconL( KAknsIIDQgnPropBtMisc, avkonbmpFilename, |
|
692 EMbmAvkonQgn_prop_bt_misc, |
|
693 EMbmAvkonQgn_prop_bt_misc_mask, iconList); |
|
694 |
|
695 CreateAndAppendIconL( KAknsIIDQgnStatBtBlank, avkonbmpFilename, |
|
696 EMbmAvkonQgn_stat_bt_blank, |
|
697 EMbmAvkonQgn_stat_bt_blank, iconList); |
|
698 |
|
699 CreateAndAppendIconL( KAknsIIDQgnPropBtKeyboard, avkonbmpFilename, |
|
700 EMbmAvkonQgn_prop_bt_keyboard, |
|
701 EMbmAvkonQgn_prop_bt_keyboard_mask, iconList); |
|
702 |
|
703 CreateAndAppendIconL( KAknsIIDQgnPropBtMouse, avkonbmpFilename, |
|
704 EMbmAvkonQgn_prop_bt_mouse, |
|
705 EMbmAvkonQgn_prop_bt_mouse_mask, iconList); |
|
706 |
|
707 CreateAndAppendIconL( KAknsIIDQgnPropBtPrinter, avkonbmpFilename, |
|
708 EMbmAvkonQgn_prop_bt_printer, |
|
709 EMbmAvkonQgn_prop_bt_printer_mask, iconList); |
|
710 |
|
711 CreateAndAppendIconL( KAknsIIDQgnPropBtCarKit, avkonbmpFilename, |
|
712 EMbmAvkonQgn_prop_bt_carkit, |
|
713 EMbmAvkonQgn_prop_bt_carkit_mask, iconList); |
|
714 |
|
715 GetColorIconL( avkonbmpFilename, KAknsIIDQgnIndiBtPairedAdd, |
|
716 EMbmAvkonQgn_indi_bt_paired_add, |
|
717 EMbmAvkonQgn_indi_bt_paired_add_mask, iconList ); |
|
718 |
|
719 |
|
720 TFileName bmpFilename; |
|
721 bmpFilename += KFileDrive; |
|
722 bmpFilename += KDC_BITMAP_DIR; |
|
723 bmpFilename += KBtnotifBmpFileName; |
|
724 |
|
725 GetColorIconL( bmpFilename, KAknsIIDQgnIndiBtBlocked, |
|
726 EMbmBtnotifQgn_indi_bt_blocked, |
|
727 EMbmBtnotifQgn_indi_bt_blocked_mask, iconList ); |
|
728 |
|
729 GetColorIconL( bmpFilename, KAknsIIDQgnIndiBtSignalLowAdd, |
|
730 EMbmBtnotifQgn_indi_bt_signal_low_add, |
|
731 EMbmBtnotifQgn_indi_bt_signal_low_add_mask, iconList); |
|
732 |
|
733 GetColorIconL( bmpFilename, KAknsIIDQgnIndiBtSignalMedAdd, |
|
734 EMbmBtnotifQgn_indi_bt_signal_med_add, |
|
735 EMbmBtnotifQgn_indi_bt_signal_med_add_mask, iconList ); |
|
736 |
|
737 GetColorIconL( bmpFilename, KAknsIIDQgnIndiBtSignalGoodAdd, |
|
738 EMbmBtnotifQgn_indi_bt_signal_good_add, |
|
739 EMbmBtnotifQgn_indi_bt_signal_good_add_mask, iconList ); |
|
740 |
|
741 // Transfer iconlist ownership to the listbox |
|
742 // |
|
743 iDeviceListBox->ItemDrawer()->ColumnData()->SetIconArray(iconList); |
|
744 CleanupStack::Pop(); // iconList |
|
745 |
|
746 FLOG(_L("[BTNOTIF]\t CBTInqUI::CreatePopupListL() completed")); |
|
747 } |
|
748 |
|
749 // ---------------------------------------------------------- |
|
750 // CBTInqUI::UpdateDeviceListL |
|
751 // ---------------------------------------------------------- |
|
752 // |
|
753 void CBTInqUI::UpdateDeviceListL( CBTDevice* aDevice, const TInt aSignalStrength ) |
|
754 { |
|
755 FLOG(_L("[BTNOTIF]\t CBTInqUI::UpdateDeviceListL()")); |
|
756 |
|
757 TInt iconIndex (EDeviceIconDefault); |
|
758 TInt defNameIndex (EBTDeviceNameIndexDefault); |
|
759 |
|
760 HBufC* formatString = HBufC::NewLC( KBTAllPurposeBufferLength ); |
|
761 |
|
762 // Check whether the device is already in registry. |
|
763 TInt index = LookupFromDevicesArray(iPairedDevicesArray, aDevice ); |
|
764 |
|
765 if( index >= 0 ) |
|
766 { |
|
767 // Update device's link key and friendly name |
|
768 // with those found from registry. |
|
769 aDevice->UpdateL( *( iPairedDevicesArray->At( index ) ) ); |
|
770 } |
|
771 |
|
772 for (TInt i = 0; i < KDeviceRowLayoutTableSize; i++) |
|
773 { |
|
774 if ( ( aDevice->DeviceClass().MajorDeviceClass() == KDeviceRowLayoutTable[i].iMajorDevClass ) && |
|
775 ( (aDevice->DeviceClass().MinorDeviceClass() == KDeviceRowLayoutTable[i].iMinorDevClass ) || |
|
776 KDeviceRowLayoutTable[i].iMinorDevClass == 0 ) ) |
|
777 { |
|
778 iconIndex = KDeviceRowLayoutTable[i].iIconIndex; |
|
779 defNameIndex = KDeviceRowLayoutTable[i].iDefaultNameIndex; |
|
780 break; |
|
781 } |
|
782 } |
|
783 |
|
784 if ( !aDevice->IsValidFriendlyName() && !aDevice->IsValidDeviceName() ) |
|
785 { |
|
786 BtNotifNameUtils::SetDeviceNameL(iDefaultDeviceNamesArray->MdcaPoint(defNameIndex), *aDevice); |
|
787 } |
|
788 |
|
789 //Convert device name to Unocode for display |
|
790 if ( aDevice->IsValidFriendlyName() ) |
|
791 { |
|
792 formatString->Des().Copy( aDevice->FriendlyName() ); |
|
793 } |
|
794 else |
|
795 { |
|
796 formatString->Des().Copy( BTDeviceNameConverter::ToUnicodeL(aDevice->DeviceName())); |
|
797 } |
|
798 |
|
799 TPtrC iconFormat (KDeviceIconFormatTable[iconIndex].iFormat); |
|
800 |
|
801 formatString->Des().Insert( 0, iconFormat ); |
|
802 |
|
803 if( aSignalStrength > 0) |
|
804 { |
|
805 if( aSignalStrength <= KMediumStrength ) |
|
806 { |
|
807 formatString->Des().Append( TPtrC(KDeviceIconFormatTable[EDeviceIconRssiLow].iFormat ) ); |
|
808 } |
|
809 else if( aSignalStrength <= KHighStrength ) |
|
810 { |
|
811 formatString->Des().Append( TPtrC(KDeviceIconFormatTable[EDeviceIconRssiMed].iFormat ) ); |
|
812 } |
|
813 else |
|
814 { |
|
815 formatString->Des().Append( TPtrC(KDeviceIconFormatTable[EDeviceIconRssiGood].iFormat ) ); |
|
816 } |
|
817 } |
|
818 |
|
819 // If the device is paired, add paired icon to format list |
|
820 // Paired device using JustWork file transfering mode is not shown as paired here. |
|
821 if( index >= 0 && IsUserAwarePaired ( aDevice->AsNamelessDevice() ) ) |
|
822 { |
|
823 formatString->Des().Append( TPtrC(KDeviceIconFormatTable[EDeviceIconPaired].iFormat ) ); |
|
824 } |
|
825 else |
|
826 { |
|
827 // if device is blocked, add blocked icon to format list |
|
828 |
|
829 TInt indexB = LookupFromDevicesArray(iLastUsedDevicesArray, aDevice ); |
|
830 |
|
831 if ( indexB>=0 && iLastUsedDevicesArray->At( indexB )->GlobalSecurity().Banned()) |
|
832 { |
|
833 formatString->Des().Append( TPtrC(KDeviceIconFormatTable[EDeviceIconBlocked].iFormat ) ); |
|
834 } |
|
835 } |
|
836 |
|
837 // Add device format string into device items |
|
838 // |
|
839 TInt deviceCount = iDeviceListRows->Count(); |
|
840 iDeviceListRows->InsertL( deviceCount, *formatString ); |
|
841 CleanupStack::PopAndDestroy(); // formatString |
|
842 |
|
843 TInt currentItemIndex = 0; |
|
844 if(deviceCount != 0 && iDeviceListBox) |
|
845 { |
|
846 // Store temporarily the highlighted device and destroy list box |
|
847 // |
|
848 currentItemIndex = iDeviceListBox->CurrentItemIndex(); |
|
849 } |
|
850 |
|
851 if( iDeviceListBox ) |
|
852 { |
|
853 iDeviceListBox->HandleItemAdditionL(); |
|
854 |
|
855 if(deviceCount != 0 ) |
|
856 { |
|
857 //set highligh back to user selected one. |
|
858 iDeviceListBox->SetCurrentItemIndex(currentItemIndex); |
|
859 } |
|
860 |
|
861 // Adjust top item index in order to "scroll up" the list. |
|
862 // If current highlight device is not the top one and the listbox's visible slots are full(at least 5 devices are listed), |
|
863 // to make the newly discovered device visible, the list needs to be scrolled up. |
|
864 // |
|
865 TInt topIndex = iDeviceListBox->TopItemIndex(); |
|
866 deviceCount = iDeviceListRows->Count(); |
|
867 |
|
868 if( (currentItemIndex != topIndex && deviceCount > 5 ) && (currentItemIndex+1 < deviceCount ) ) |
|
869 { |
|
870 iDeviceListBox->SetTopItemIndex( topIndex+1 ); //scroll up |
|
871 } |
|
872 } |
|
873 |
|
874 FLOG(_L("[BTNOTIF]\t CBTInqUI::UpdateDeviceListL() completed")); |
|
875 } |
|
876 |
|
877 // ---------------------------------------------------------- |
|
878 // CBTInqUI::LookupFromDevicesArrayL |
|
879 // Check if the BT device is paired devices array |
|
880 // ---------------------------------------------------------- |
|
881 // |
|
882 TInt CBTInqUI::LookupFromDevicesArray(const CBTDeviceArray* aDeviceArray, const CBTDevice* aDevice ) const |
|
883 { |
|
884 FLOG(_L("[BTNOTIF]\t CBTInqUI::LookupFromDevicesArray()")); |
|
885 |
|
886 __ASSERT_DEBUG( aDeviceArray, User::Panic(_L("BTNotifInqUI - aDeviceArray not created"), KErrNotFound )); |
|
887 |
|
888 for( TInt index = 0; index < aDeviceArray->Count(); index++ ) |
|
889 { |
|
890 // Try to find device by its address. |
|
891 if ( aDeviceArray->At( index )->BDAddr() == aDevice->BDAddr() ) |
|
892 { |
|
893 FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::LookupFromDevicesArrayL()idx %d"), index)); |
|
894 return index; // Return index to the device at array |
|
895 } |
|
896 } |
|
897 return KErrNotFound; |
|
898 } |
|
899 |
|
900 // ---------------------------------------------------- |
|
901 // CBTInqUI::CreateAndAppendIconL |
|
902 // ---------------------------------------------------- |
|
903 void CBTInqUI::CreateAndAppendIconL( const TAknsItemID& aID, |
|
904 const TDesC& aFileName, |
|
905 const TInt aBitmapId, |
|
906 const TInt aMaskId, |
|
907 CAknIconArray* aIconList) |
|
908 { |
|
909 CGulIcon* icon = AknsUtils::CreateGulIconL(AknsUtils::SkinInstance(), aID, aFileName, aBitmapId, aMaskId); |
|
910 |
|
911 CleanupStack::PushL(icon); |
|
912 aIconList->AppendL( icon ); |
|
913 CleanupStack::Pop(); // icon |
|
914 } |
|
915 |
|
916 // --------------------------------------------------------- |
|
917 // CBTInqUI::AdjustDeviceArrayL |
|
918 // Applend max 5 lately used non-paird devices plus all the |
|
919 // paired devices to the input parameter by the order of |
|
920 // the last used time stamp. |
|
921 // --------------------------------------------------------- |
|
922 // |
|
923 void CBTInqUI::AdjustDeviceArrayL(CBTDeviceArray* aDeviceArray) |
|
924 { |
|
925 FLOG(_L("[BTNOTIF]\t CBTInqUI::AdjustDeviceArrayL()")); |
|
926 |
|
927 TInt lSize = iLastUsedDevicesArray->Count(); |
|
928 |
|
929 if (lSize <= 0) |
|
930 { |
|
931 return; |
|
932 } |
|
933 |
|
934 TInt pSize = iPairedDevicesArray->Count(); |
|
935 TInt nonPairedUsedDevicesNumber = lSize - pSize; |
|
936 |
|
937 // Pickup 5 latest used devices (paired devices are excluded) |
|
938 // |
|
939 TInt count(0); |
|
940 |
|
941 if (nonPairedUsedDevicesNumber <= KBTNotifNonPairedUsedDevicesMaxNumber) |
|
942 count = nonPairedUsedDevicesNumber; |
|
943 else |
|
944 count = KBTNotifNonPairedUsedDevicesMaxNumber; |
|
945 |
|
946 for(TInt i=0; i < count; i++ ) |
|
947 { |
|
948 TInt targetDeviceIndex = 0; |
|
949 |
|
950 //go through iLastUsedDevicesArray, compare each device's time stamp and, find the latest used one. |
|
951 for(TInt k=0; k < lSize; k++) |
|
952 { |
|
953 if(iLastUsedDevicesArray->At(targetDeviceIndex)->Used() < iLastUsedDevicesArray->At(k)->Used()) |
|
954 { |
|
955 targetDeviceIndex = k; |
|
956 } |
|
957 } |
|
958 |
|
959 //if result is not a paired device, add it to the adjuested device array. |
|
960 if( LookupFromDevicesArray(iPairedDevicesArray, iLastUsedDevicesArray->At(targetDeviceIndex)) == KErrNotFound ) |
|
961 { |
|
962 aDeviceArray->AppendL(iLastUsedDevicesArray->At(targetDeviceIndex)->CopyL()); |
|
963 } |
|
964 //if result is a paired device, ignore this search round and step-back counter i to make sure this |
|
965 //search round won't be count. |
|
966 else |
|
967 { |
|
968 i--; |
|
969 } |
|
970 |
|
971 //set the time stamp to -1, in order to ignore this device during next search round. |
|
972 iLastUsedDevicesArray->At(targetDeviceIndex)->SetUsed(-1); |
|
973 } |
|
974 |
|
975 // Add paired devices to the adjusted list(if paired device exist), |
|
976 // by the order of last used time. |
|
977 // |
|
978 if(pSize > 0) |
|
979 { |
|
980 for( TInt i = 0; i < pSize; i++ ) |
|
981 { |
|
982 //count size in the beginning of each loop, since the size could grow, |
|
983 //if new item has been appended in last loop round. |
|
984 TInt sSize = aDeviceArray->Count(); |
|
985 |
|
986 TInt j = 0; |
|
987 for (; j < sSize ; j++) |
|
988 { |
|
989 //check if this paired device alreay on the list jump out this loop |
|
990 if (iPairedDevicesArray->At(i)->BDAddr() == aDeviceArray->At(j)->BDAddr()) |
|
991 { |
|
992 break; |
|
993 } |
|
994 |
|
995 // We do not add device still valid paired into list if iExcludePairedDevices is set. |
|
996 if ( IsUserAwarePaired( iPairedDevicesArray->At(i)->AsNamelessDevice() ) && |
|
997 iExcludePairedDevices ) |
|
998 { |
|
999 break; |
|
1000 } |
|
1001 |
|
1002 //if this device is not on the list and it is used later then current comparing |
|
1003 //device, insert the paired device to aDeviceArray at suitable position. |
|
1004 TTime pTime = iPairedDevicesArray->At(i)->Used(); |
|
1005 TTime sTime = aDeviceArray->At(j)->Used(); |
|
1006 |
|
1007 if ( pTime > sTime) |
|
1008 { |
|
1009 aDeviceArray->InsertL(j, iPairedDevicesArray->At(i)->CopyL()); |
|
1010 break; |
|
1011 } |
|
1012 } |
|
1013 |
|
1014 //if this paired device is not on the sorted list(it is older then all the devices on the list), |
|
1015 //append it to the end of the list. |
|
1016 if (j == sSize) |
|
1017 { |
|
1018 if ( iExcludePairedDevices ) |
|
1019 { |
|
1020 // Add device to list if device is not paired and iExcludePairedDevices is not set. |
|
1021 if ( !IsUserAwarePaired( iPairedDevicesArray->At(i)->AsNamelessDevice() ) ) |
|
1022 { |
|
1023 aDeviceArray->AppendL(iPairedDevicesArray->At(i)->CopyL()); |
|
1024 } |
|
1025 } |
|
1026 else |
|
1027 { |
|
1028 aDeviceArray->AppendL(iPairedDevicesArray->At(i)->CopyL()); |
|
1029 } |
|
1030 } |
|
1031 } |
|
1032 } |
|
1033 |
|
1034 FLOG(_L("[BTNOTIF]\t CBTInqUI::AdjustDeviceArrayL() Complete.")); |
|
1035 } |
|
1036 |
|
1037 //---------------------------------------------------------- |
|
1038 // CBTInqUI::QueryUnblockDeviceL |
|
1039 //---------------------------------------------------------- |
|
1040 TInt CBTInqUI::QueryUnblockDeviceL(CBTDevice* aDevice) |
|
1041 { |
|
1042 FLOG(_L("[BTNOTIF]\t CBTInqUI::QueryUnblockDeviceL()")); |
|
1043 RBuf stringholder; |
|
1044 stringholder.CleanupClosePushL(); |
|
1045 TBTDeviceName name; |
|
1046 BtNotifNameUtils::GetDeviceDisplayName( name, aDevice ); |
|
1047 BluetoothUiUtil::LoadResourceAndSubstringL( |
|
1048 stringholder, R_BT_UNBLOCK_DEVICE, name, 0 ); |
|
1049 TInt keypress(0); |
|
1050 keypress = iUiUtil->ShowQueryL( stringholder, R_BT_UNBLOCK_QUERY, |
|
1051 ECmdBTnotifUnavailable, name, CAknQueryDialog::EConfirmationTone ); |
|
1052 CleanupStack::PopAndDestroy(); // stringholder |
|
1053 FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::QueryUnblockDeviceL() keypress= %d"),keypress)); |
|
1054 |
|
1055 return keypress; |
|
1056 } |
|
1057 |
|
1058 // ---------------------------------------------------------- |
|
1059 // CBTInqUI::UnblockDevice |
|
1060 // Unblock device by modifying registry |
|
1061 //----------------------------------------------------------- |
|
1062 // |
|
1063 TInt CBTInqUI::UnblockDevice(TInt aIndex) |
|
1064 { |
|
1065 TInt returnValue = KErrNone; |
|
1066 TBTDeviceSecurity deviceSecuritySettings = iLastUsedDevicesArray->At(aIndex)->GlobalSecurity(); |
|
1067 deviceSecuritySettings.SetBanned(EFalse); |
|
1068 iLastUsedDevicesArray->At(aIndex)->DeleteLinkKey(); |
|
1069 //DeleteLinkKey() invalidates the LinkKey and IsPaired entries in Lisbon, so... |
|
1070 iLastUsedDevicesArray->At(aIndex)->SetGlobalSecurity(deviceSecuritySettings); |
|
1071 returnValue = iDevMan->ModifyDevice(*iLastUsedDevicesArray->At(aIndex)); |
|
1072 if (!returnValue) |
|
1073 { |
|
1074 iBTRegistryQueryState = ESetDeviceUnblocked; |
|
1075 } |
|
1076 return returnValue; |
|
1077 } |
|
1078 |
|
1079 // --------------------------------------------------------- |
|
1080 // CBTInqUI::HandleDevManComplete |
|
1081 // CBTEngDevMan callback |
|
1082 // --------------------------------------------------------- |
|
1083 // |
|
1084 void CBTInqUI::HandleDevManComplete(TInt aErr) |
|
1085 { |
|
1086 FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::HandleDevManComplete() aErr= %d"),aErr)); |
|
1087 |
|
1088 switch(iBTRegistryQueryState) |
|
1089 { |
|
1090 case ESetDeviceUnblocked: |
|
1091 FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::HandleDevManComplete() EModifyDevice"))); |
|
1092 iDevSearchObserver->NotifyDeviceSearchCompleted(aErr, iDevParams); |
|
1093 break; |
|
1094 } |
|
1095 |
|
1096 FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::HandleDevManComplete() complete"))); |
|
1097 } |
|
1098 |
|
1099 //---------------------------------------------------------------- |
|
1100 // CBTInqUI: DeviceSearchFilter |
|
1101 //---------------------------------------------------------------- |
|
1102 void CBTInqUI::SelectSearchCategoryL() |
|
1103 { |
|
1104 FLOG(_L("[BTNOTIF]\t CBTInqUI::SelectSearchCategoryL()")); |
|
1105 |
|
1106 if( !(iDesiredDeviceClass == TBTDeviceClass(0)) ) |
|
1107 { |
|
1108 // Notifier caller passed specified COD to search device, not need to show filter query. |
|
1109 DeviceSearchUiL(); |
|
1110 FLOG(_L("[BTNOTIF]\t CBTInqUI::SelectSearchCategoryL() complete: not show filter query")); |
|
1111 return; |
|
1112 } |
|
1113 // Create listbox for devices |
|
1114 // |
|
1115 CEikTextListBox* searchFilterListBox = new(ELeave) CAknSinglePopupMenuStyleListBox; |
|
1116 CleanupStack::PushL(searchFilterListBox); |
|
1117 |
|
1118 // Create popup list |
|
1119 // |
|
1120 iSearchFilterPopupList = CAknPopupList::NewL( |
|
1121 searchFilterListBox, |
|
1122 R_AVKON_SOFTKEYS_SELECT_CANCEL__SELECT, |
|
1123 AknPopupLayouts::EDynMenuWindow ); |
|
1124 |
|
1125 searchFilterListBox->ConstructL(iSearchFilterPopupList, EAknListBoxMenuList ); |
|
1126 searchFilterListBox->CreateScrollBarFrameL(ETrue); |
|
1127 searchFilterListBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
1128 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
1129 |
|
1130 // Read title from resources |
|
1131 // |
|
1132 HBufC* popupListTitle = iEikonEnvRef.AllocReadResourceLC( R_BT_SEARCH_FILTER_POPUP_TITLE ); |
|
1133 iSearchFilterPopupList->SetTitleL(*popupListTitle); |
|
1134 CleanupStack::PopAndDestroy(); // popupListTitle |
|
1135 |
|
1136 // reuse iDeviceListRows for serch filter items |
|
1137 iDeviceListRows->Reset(); |
|
1138 |
|
1139 // Create list box model for devices |
|
1140 // |
|
1141 |
|
1142 CTextListBoxModel* model = searchFilterListBox->Model(); |
|
1143 model->SetItemTextArray(iDeviceListRows); |
|
1144 model->SetOwnershipType(ELbmDoesNotOwnItemArray); // Do not destroy items |
|
1145 |
|
1146 |
|
1147 // Add itms of filter to popuplist |
|
1148 // Order must be same as in enum EBTSerchFilterItem |
|
1149 // |
|
1150 |
|
1151 AddItemToSearchFilterL(R_BT_SEARCH_FOR_ALL); |
|
1152 AddItemToSearchFilterL(R_BT_SEARCH_FOR_AUDIO); |
|
1153 AddItemToSearchFilterL(R_BT_SEARCH_FOR_PHONE); |
|
1154 AddItemToSearchFilterL(R_BT_SEARCH_FOR_COMPUTER); |
|
1155 AddItemToSearchFilterL(R_BT_SEARCH_FOR_INPUT); |
|
1156 |
|
1157 // Launch popup list and wait for user input, disable other Ui key presses first: |
|
1158 AllowDialerAndAppKeyPress( EFalse ); |
|
1159 // After input, destroy popup list |
|
1160 // |
|
1161 TInt popupRetVal = iSearchFilterPopupList->ExecuteLD(); |
|
1162 iSearchFilterPopupList = NULL; |
|
1163 AllowDialerAndAppKeyPress( ETrue ); |
|
1164 |
|
1165 if( popupRetVal ) |
|
1166 { |
|
1167 TInt currentDeviceIndex = searchFilterListBox->CurrentItemIndex(); |
|
1168 switch(currentDeviceIndex) |
|
1169 { |
|
1170 case EBTSearchForAll: |
|
1171 iDesiredDeviceClass = TBTDeviceClass(0,0,0); |
|
1172 break; |
|
1173 case EBTSearchForAudio: |
|
1174 iDesiredDeviceClass = TBTDeviceClass(0,EMajorDeviceAV,0); |
|
1175 break; |
|
1176 |
|
1177 case EBTSearchForPhone: |
|
1178 iDesiredDeviceClass = TBTDeviceClass(0,EMajorDevicePhone,0); |
|
1179 break; |
|
1180 |
|
1181 case EBTSearchForComputer: |
|
1182 iDesiredDeviceClass = TBTDeviceClass(0,EMajorDeviceComputer,0); |
|
1183 break; |
|
1184 |
|
1185 case EBTSearchForInput: |
|
1186 iDesiredDeviceClass = TBTDeviceClass(0,EMajorDevicePeripheral,0); |
|
1187 break; |
|
1188 |
|
1189 default: |
|
1190 break; |
|
1191 } |
|
1192 } |
|
1193 |
|
1194 CleanupStack::PopAndDestroy(); //searchFilterListBox |
|
1195 iDeviceListRows->Reset(); |
|
1196 |
|
1197 if( !popupRetVal ) |
|
1198 { |
|
1199 iDevSearchObserver->NotifyDeviceSearchCompleted(KErrCancel); |
|
1200 } |
|
1201 else |
|
1202 { |
|
1203 DeviceSearchUiL(); |
|
1204 } |
|
1205 |
|
1206 FLOG(_L("[BTNOTIF]\t CBTInqUI::SelectSearchCategoryL() complete")); |
|
1207 } |
|
1208 |
|
1209 //------------------------------------------------------------------------------ |
|
1210 // CBTInqUI: AddItemToSearchFilterL |
|
1211 //------------------------------------------------------------------------------ |
|
1212 void CBTInqUI::AddItemToSearchFilterL ( TInt aResourceId ) |
|
1213 { |
|
1214 HBufC* formatString = HBufC::NewLC( KBTAllPurposeBufferLength ); |
|
1215 HBufC* string = iEikonEnvRef.AllocReadResourceLC( aResourceId ); |
|
1216 formatString->Des().Append( *string ); |
|
1217 CleanupStack::PopAndDestroy(); // string |
|
1218 iDeviceListRows->AppendL( *formatString ); |
|
1219 CleanupStack::Pop(); // formatString |
|
1220 } |
|
1221 |
|
1222 void CBTInqUI::GetColorIconL( TFileName& aFilename, TAknsItemID aItemID, |
|
1223 TInt aPic, TInt aPicmask, CAknIconArray* aIconList ) |
|
1224 { |
|
1225 CFbsBitmap* bitmap = NULL; |
|
1226 CFbsBitmap* mask = NULL; |
|
1227 |
|
1228 AknsUtils::CreateColorIconLC(AknsUtils::SkinInstance(), aItemID, |
|
1229 KAknsIIDQsnIconColors, |
|
1230 EAknsCIQsnIconColorsCG13, |
|
1231 bitmap, mask, aFilename, aPic, aPicmask, KRgbBlack); |
|
1232 |
|
1233 CGulIcon* icon = CGulIcon::NewL(bitmap, mask); |
|
1234 CleanupStack::Pop(2); // bitmap, mask; |
|
1235 CleanupStack::PushL(icon); |
|
1236 aIconList->AppendL( icon ); |
|
1237 CleanupStack::Pop(); // icon |
|
1238 } |
|
1239 |
|
1240 TBool CBTInqUI::IsActiveVoIPOverWLAN() |
|
1241 { |
|
1242 TInt error = KErrNone; |
|
1243 |
|
1244 // check VoIP over WLAN is on going or not: |
|
1245 // |
|
1246 TInt wlanStatus = 0; |
|
1247 error = RProperty::Get(KPSUidWlan, KPSWlanIndicator, wlanStatus); |
|
1248 FTRACE( FPrint( _L( "CBTInqNotifier::CheckActivationOfVoIPOverWLAN() WLAN state: %d (error %d)" ), wlanStatus, error ) ); |
|
1249 if (error) |
|
1250 { |
|
1251 return EFalse; |
|
1252 } |
|
1253 |
|
1254 TInt callState = 0; |
|
1255 error = RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallType, callState ); |
|
1256 FTRACE( FPrint( _L( "CBTInqNotifier::CheckActivationOfVoIPOverWLAN() call state: %d (error %d)" ), callState, error ) ); |
|
1257 if( error == KErrNone && |
|
1258 (wlanStatus == EPSWlanIndicatorActive || wlanStatus == EPSWlanIndicatorActiveSecure)&& |
|
1259 callState == EPSCTsyCallTypeVoIP ) |
|
1260 { |
|
1261 FTRACE( FPrint( _L( " VoIP call ongoing, do not allow inquiry!" ) ) ); |
|
1262 return ETrue; |
|
1263 } |
|
1264 return EFalse; |
|
1265 } |
|
1266 |
|
1267 void CBTInqUI::DoDeviceFrontListSelection() |
|
1268 { |
|
1269 TRAPD(err, DisplayDevicesFrontListL()); |
|
1270 if (err) |
|
1271 { |
|
1272 iDevSearchObserver->NotifyDeviceSearchCompleted(err); |
|
1273 } |
|
1274 } |
|
1275 |
|
1276 void CBTInqUI::HandleDeviceSelectionL(CBTDevice* aDev) |
|
1277 { |
|
1278 iDevParams = TBTDeviceResponseParams(); |
|
1279 iDevParams.SetDeviceAddress( aDev->BDAddr()); |
|
1280 iDevParams.SetDeviceClass( aDev->DeviceClass()); |
|
1281 if( aDev->IsValidFriendlyName()) |
|
1282 { |
|
1283 iDevParams.SetDeviceName( aDev->FriendlyName()); |
|
1284 } |
|
1285 else if( aDev->IsValidDeviceName()) |
|
1286 { |
|
1287 iDevParams.SetDeviceName( BTDeviceNameConverter::ToUnicodeL( aDev->DeviceName() ) ); |
|
1288 } |
|
1289 //check if this device is blocked |
|
1290 TInt index = LookupFromDevicesArray(iLastUsedDevicesArray, aDev); |
|
1291 TBool blocked = ( index >= 0 && iLastUsedDevicesArray->At( index )->GlobalSecurity().Banned() ); |
|
1292 if (!blocked) |
|
1293 { |
|
1294 iDevSearchObserver->NotifyDeviceSearchCompleted(KErrNone, iDevParams); |
|
1295 return; |
|
1296 } |
|
1297 |
|
1298 TInt toUnblk = QueryUnblockDeviceL(aDev); |
|
1299 if (!toUnblk) |
|
1300 { |
|
1301 iDevSearchObserver->NotifyDeviceSearchCompleted(KErrCancel); |
|
1302 return; |
|
1303 } |
|
1304 TInt err = UnblockDevice( index ); |
|
1305 if (err) |
|
1306 { |
|
1307 iDevSearchObserver->NotifyDeviceSearchCompleted(err); |
|
1308 } |
|
1309 // otherwise NotifyDeviceSearchCompleted will be called after unblock is really done. |
|
1310 } |
|
1311 |
|
1312 void CBTInqUI::AllowDialerAndAppKeyPress( TBool aAllow ) |
|
1313 { |
|
1314 CEikAppUi* const eikAppUi = CEikonEnv::Static()->EikAppUi(); |
|
1315 if ( aAllow) |
|
1316 { |
|
1317 // Enable dialer |
|
1318 static_cast<CAknAppUi*>( eikAppUi )->SetKeyEventFlags( 0x00 ); |
|
1319 // Activate apps key. |
|
1320 // Ignore the return error code as we can do nothing if this operation fails |
|
1321 (void) static_cast<CAknNotifierAppServerAppUi*>(eikAppUi)->SuppressAppSwitching(EFalse); |
|
1322 } |
|
1323 else |
|
1324 { |
|
1325 // Disable dialer |
|
1326 static_cast<CAknAppUi*>( eikAppUi )->SetKeyEventFlags( CAknAppUiBase::EDisableSendKeyShort | |
|
1327 CAknAppUiBase::EDisableSendKeyLong); |
|
1328 // Deactivate apps key |
|
1329 (void) static_cast<CAknNotifierAppServerAppUi*>(eikAppUi)->SuppressAppSwitching(ETrue); |
|
1330 } |
|
1331 FTRACE( FPrint( _L( "CBTInqUI::AllowDialerAndAppKeyPress : %d" ), aAllow ) ); |
|
1332 } |
|
1333 |
|
1334 // End of File |
|