1 /* |
|
2 * Copyright (c) 2007 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: Utility function for the views. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <BtuiViewResources.rsg> // Compiled resource ids |
|
19 #include <aknnotewrappers.h> |
|
20 #include <StringLoader.h> // Series 60 localisation stringloader |
|
21 #include <e32property.h> |
|
22 #include <bt_subscribe.h> |
|
23 #include <featmgr.h> // Feature Manager API |
|
24 #include <AknMediatorFacade.h> |
|
25 #include <btengsettings.h> |
|
26 #include <ctsydomainpskeys.h> |
|
27 #include <CoreApplicationUIsSDKCRKeys.h> |
|
28 #include <secondarydisplay/BtuiSecondaryDisplayAPI.h> |
|
29 |
|
30 #include "BTUIViewsCommonUtils.h" |
|
31 #include "debug.h" |
|
32 |
|
33 |
|
34 // ---------------------------------------------------------- |
|
35 // TBTUIViewsCommonUtils::ShowGeneralErrorNoteL |
|
36 // ---------------------------------------------------------- |
|
37 // |
|
38 void TBTUIViewsCommonUtils::ShowGeneralErrorNoteL() |
|
39 { |
|
40 //TRACE_FUNC_ENTRY |
|
41 |
|
42 CAknNoteDialog* dlg = new (ELeave) CAknNoteDialog( CAknNoteDialog::EErrorTone, |
|
43 CAknNoteDialog::ELongTimeout ); |
|
44 if(FeatureManager::FeatureSupported( KFeatureIdCoverDisplay )) |
|
45 { |
|
46 CleanupStack::PushL(dlg); |
|
47 dlg->PublishDialogL(ECmdShowBtGeneralErrorNote, KUidCoverUiCategoryBtui); // initializes cover support |
|
48 CleanupStack::Pop(dlg); |
|
49 } |
|
50 |
|
51 TRACE_INFO(_L("ShowGeneralErrorNoteL ")) |
|
52 dlg->ExecuteLD( R_BT_GENERAL_ERROR_NOTE ); |
|
53 |
|
54 //TRACE_FUNC_EXIT |
|
55 } |
|
56 |
|
57 // ---------------------------------------------------------- |
|
58 // TBTUIViewsCommonUtils::IsAnyDeviceConnectedL() |
|
59 // ---------------------------------------------------------- |
|
60 TBool TBTUIViewsCommonUtils::IsAnyDeviceConnectedL() |
|
61 { |
|
62 //TRACE_FUNC_ENTRY |
|
63 |
|
64 TInt connNum = 0; |
|
65 TInt retVal = RProperty::Get(KPropertyUidBluetoothCategory, |
|
66 KPropertyKeyBluetoothGetPHYCount, connNum); |
|
67 TRACE_INFO((_L("GetConnectionNumber(): %d"), connNum)) |
|
68 //TRACE_FUNC_EXIT |
|
69 return (connNum > 0); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------- |
|
73 // CBTUIPairedDevicesView::TurnBTOnIfNeededL |
|
74 // ----------------------------------------------- |
|
75 TInt TBTUIViewsCommonUtils::TurnBTOnIfNeededL(CBTEngSettings* aBtEngSettings,TBool aCoverDisplayEnabled ) |
|
76 { |
|
77 //TRACE_FUNC |
|
78 |
|
79 TInt errorCode = KErrNone; |
|
80 TBTPowerStateValue previousPowerMode; |
|
81 |
|
82 errorCode=aBtEngSettings->GetPowerState(previousPowerMode); |
|
83 if(errorCode) |
|
84 return errorCode; |
|
85 |
|
86 if( previousPowerMode==EBTPowerOn ) |
|
87 return KErrNone; |
|
88 |
|
89 if ( previousPowerMode==EBTPowerOff ) // power OFF -> ON |
|
90 { |
|
91 TRACE_INFO(_L("[BTUI]\t power OFF -> ON")) |
|
92 |
|
93 TInt offlineModeOff = 0; // possible values are 0 and 1 |
|
94 TInt activationEnabled = 0; // possible values are 0 and 1 |
|
95 |
|
96 CRepository* repository = CRepository::NewL(KCRUidCoreApplicationUIs); |
|
97 CleanupStack::PushL(repository); |
|
98 repository->Get(KCoreAppUIsNetworkConnectionAllowed, offlineModeOff); |
|
99 // Closing connection: |
|
100 CleanupStack::PopAndDestroy(repository); |
|
101 repository=NULL; |
|
102 |
|
103 repository = CRepository::NewL(KCRUidBluetoothEngine); |
|
104 // Check activation enabled |
|
105 CleanupStack::PushL(repository); |
|
106 repository->Get(KBTEnabledInOffline, activationEnabled); |
|
107 // Closing connection: |
|
108 CleanupStack::PopAndDestroy(repository); |
|
109 |
|
110 |
|
111 TRACE_INFO((_L("power OFF -> ON, offlineModeOff = %d"), offlineModeOff)) |
|
112 TRACE_INFO((_L("power OFF -> ON, activationEnabled = %d"), activationEnabled)) |
|
113 |
|
114 // Choose user interaction |
|
115 // |
|
116 if ( !offlineModeOff && !activationEnabled ) |
|
117 { |
|
118 // Load a string, create and show a note |
|
119 // |
|
120 HBufC* stringHolder = StringLoader::LoadLC( R_BT_OFFLINE_DISABLED ); |
|
121 CAknInformationNote* note = new (ELeave) CAknInformationNote(); |
|
122 |
|
123 if(aCoverDisplayEnabled) |
|
124 { |
|
125 CleanupStack::PushL(note); |
|
126 note->PublishDialogL(ECmdBtuiShowBtOfflineDisableNote, KUidCoverUiCategoryBtui); // initializes cover support |
|
127 CleanupStack::Pop(note); |
|
128 } |
|
129 |
|
130 note->ExecuteLD( *stringHolder ); |
|
131 CleanupStack::PopAndDestroy(stringHolder); //stringHolder |
|
132 } |
|
133 else |
|
134 { |
|
135 // Choose query |
|
136 // |
|
137 TInt resource = 0; |
|
138 |
|
139 TInt coverUiDlgId = 0; |
|
140 |
|
141 if ( offlineModeOff ) |
|
142 { |
|
143 resource = R_BT_IS_OFF_QUERY; |
|
144 if(aCoverDisplayEnabled) |
|
145 { |
|
146 coverUiDlgId = ECmdBtuiShowBtIsOffDlg; |
|
147 } |
|
148 } |
|
149 else |
|
150 { |
|
151 resource = R_BT_ACTIVATE_IN_OFFLINE_QUERY; |
|
152 if(aCoverDisplayEnabled) |
|
153 { |
|
154 coverUiDlgId = ECmdBtuiShowBtActivateInOfflineDlg; |
|
155 } |
|
156 } |
|
157 |
|
158 // Create and show query |
|
159 // |
|
160 CAknQueryDialog* dlg = CAknQueryDialog::NewL(); |
|
161 |
|
162 if(aCoverDisplayEnabled) |
|
163 { |
|
164 CleanupStack::PushL(dlg); |
|
165 dlg->PublishDialogL(coverUiDlgId, KUidCoverUiCategoryBtui); // initializes cover support |
|
166 CleanupStack::Pop(dlg); |
|
167 } |
|
168 |
|
169 TInt keypress = dlg->ExecuteLD( resource ); |
|
170 |
|
171 if( keypress ) |
|
172 { |
|
173 // Switch BT ON |
|
174 // |
|
175 errorCode=aBtEngSettings->SetPowerState(EBTPowerOn ) ; |
|
176 if (errorCode) |
|
177 { |
|
178 ShowGeneralErrorNoteL(); |
|
179 } |
|
180 } else |
|
181 { |
|
182 errorCode=KErrCancel; |
|
183 } |
|
184 |
|
185 |
|
186 } |
|
187 |
|
188 } |
|
189 |
|
190 return errorCode; |
|
191 } |
|
192 |
|
193 |
|
194 |
|